Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Shared CARL9170 Header
0004  *
0005  * Firmware descriptor format
0006  *
0007  * Copyright 2009-2011 Christian Lamparter <chunkeey@googlemail.com>
0008  */
0009 
0010 #ifndef __CARL9170_SHARED_FWDESC_H
0011 #define __CARL9170_SHARED_FWDESC_H
0012 
0013 /* NOTE: Don't mess with the order of the flags! */
0014 enum carl9170fw_feature_list {
0015     /* Always set */
0016     CARL9170FW_DUMMY_FEATURE,
0017 
0018     /*
0019      * Indicates that this image has special boot block which prevents
0020      * legacy drivers to drive the firmware.
0021      */
0022     CARL9170FW_MINIBOOT,
0023 
0024     /* usb registers are initialized by the firmware */
0025     CARL9170FW_USB_INIT_FIRMWARE,
0026 
0027     /* command traps & notifications are send through EP2 */
0028     CARL9170FW_USB_RESP_EP2,
0029 
0030     /* usb download (app -> fw) stream */
0031     CARL9170FW_USB_DOWN_STREAM,
0032 
0033     /* usb upload (fw -> app) stream */
0034     CARL9170FW_USB_UP_STREAM,
0035 
0036     /* unusable - reserved to flag non-functional debug firmwares */
0037     CARL9170FW_UNUSABLE,
0038 
0039     /* AR9170_CMD_RF_INIT, AR9170_CMD_FREQ_START, AR9170_CMD_FREQUENCY */
0040     CARL9170FW_COMMAND_PHY,
0041 
0042     /* AR9170_CMD_EKEY, AR9170_CMD_DKEY */
0043     CARL9170FW_COMMAND_CAM,
0044 
0045     /* Firmware has a software Content After Beacon Queueing mechanism */
0046     CARL9170FW_WLANTX_CAB,
0047 
0048     /* The firmware is capable of responding to incoming BAR frames */
0049     CARL9170FW_HANDLE_BACK_REQ,
0050 
0051     /* GPIO Interrupt | CARL9170_RSP_GPIO */
0052     CARL9170FW_GPIO_INTERRUPT,
0053 
0054     /* Firmware PSM support | CARL9170_CMD_PSM */
0055     CARL9170FW_PSM,
0056 
0057     /* Firmware RX filter | CARL9170_CMD_RX_FILTER */
0058     CARL9170FW_RX_FILTER,
0059 
0060     /* Wake up on WLAN */
0061     CARL9170FW_WOL,
0062 
0063     /* Firmware supports PSM in the 5GHZ Band */
0064     CARL9170FW_FIXED_5GHZ_PSM,
0065 
0066     /* HW (ANI, CCA, MIB) tally counters */
0067     CARL9170FW_HW_COUNTERS,
0068 
0069     /* Firmware will pass BA when BARs are queued */
0070     CARL9170FW_RX_BA_FILTER,
0071 
0072     /* Firmware has support to write a byte at a time */
0073     CARL9170FW_HAS_WREGB_CMD,
0074 
0075     /* Pattern generator */
0076     CARL9170FW_PATTERN_GENERATOR,
0077 
0078     /* KEEP LAST */
0079     __CARL9170FW_FEATURE_NUM
0080 };
0081 
0082 #define OTUS_MAGIC  "OTAR"
0083 #define MOTD_MAGIC  "MOTD"
0084 #define FIX_MAGIC   "FIX\0"
0085 #define DBG_MAGIC   "DBG\0"
0086 #define CHK_MAGIC   "CHK\0"
0087 #define TXSQ_MAGIC  "TXSQ"
0088 #define WOL_MAGIC   "WOL\0"
0089 #define LAST_MAGIC  "LAST"
0090 
0091 #define CARL9170FW_SET_DAY(d) (((d) - 1) % 31)
0092 #define CARL9170FW_SET_MONTH(m) ((((m) - 1) % 12) * 31)
0093 #define CARL9170FW_SET_YEAR(y) (((y) - 10) * 372)
0094 
0095 #define CARL9170FW_GET_DAY(d) (((d) % 31) + 1)
0096 #define CARL9170FW_GET_MONTH(m) ((((m) / 31) % 12) + 1)
0097 #define CARL9170FW_GET_YEAR(y) ((y) / 372 + 10)
0098 
0099 #define CARL9170FW_MAGIC_SIZE           4
0100 
0101 struct carl9170fw_desc_head {
0102     u8  magic[CARL9170FW_MAGIC_SIZE];
0103     __le16 length;
0104     u8 min_ver;
0105     u8 cur_ver;
0106 } __packed;
0107 #define CARL9170FW_DESC_HEAD_SIZE           \
0108     (sizeof(struct carl9170fw_desc_head))
0109 
0110 #define CARL9170FW_OTUS_DESC_MIN_VER        6
0111 #define CARL9170FW_OTUS_DESC_CUR_VER        7
0112 struct carl9170fw_otus_desc {
0113     struct carl9170fw_desc_head head;
0114     __le32 feature_set;
0115     __le32 fw_address;
0116     __le32 bcn_addr;
0117     __le16 bcn_len;
0118     __le16 miniboot_size;
0119     __le16 tx_frag_len;
0120     __le16 rx_max_frame_len;
0121     u8 tx_descs;
0122     u8 cmd_bufs;
0123     u8 api_ver;
0124     u8 vif_num;
0125 } __packed;
0126 #define CARL9170FW_OTUS_DESC_SIZE           \
0127     (sizeof(struct carl9170fw_otus_desc))
0128 
0129 #define CARL9170FW_MOTD_STRING_LEN          24
0130 #define CARL9170FW_MOTD_RELEASE_LEN         20
0131 #define CARL9170FW_MOTD_DESC_MIN_VER            1
0132 #define CARL9170FW_MOTD_DESC_CUR_VER            2
0133 struct carl9170fw_motd_desc {
0134     struct carl9170fw_desc_head head;
0135     __le32 fw_year_month_day;
0136     char desc[CARL9170FW_MOTD_STRING_LEN];
0137     char release[CARL9170FW_MOTD_RELEASE_LEN];
0138 } __packed;
0139 #define CARL9170FW_MOTD_DESC_SIZE           \
0140     (sizeof(struct carl9170fw_motd_desc))
0141 
0142 #define CARL9170FW_FIX_DESC_MIN_VER         1
0143 #define CARL9170FW_FIX_DESC_CUR_VER         2
0144 struct carl9170fw_fix_entry {
0145     __le32 address;
0146     __le32 mask;
0147     __le32 value;
0148 } __packed;
0149 
0150 struct carl9170fw_fix_desc {
0151     struct carl9170fw_desc_head head;
0152     struct carl9170fw_fix_entry data[];
0153 } __packed;
0154 #define CARL9170FW_FIX_DESC_SIZE            \
0155     (sizeof(struct carl9170fw_fix_desc))
0156 
0157 #define CARL9170FW_DBG_DESC_MIN_VER         1
0158 #define CARL9170FW_DBG_DESC_CUR_VER         3
0159 struct carl9170fw_dbg_desc {
0160     struct carl9170fw_desc_head head;
0161 
0162     __le32 bogoclock_addr;
0163     __le32 counter_addr;
0164     __le32 rx_total_addr;
0165     __le32 rx_overrun_addr;
0166     __le32 rx_filter;
0167 
0168     /* Put your debugging definitions here */
0169 } __packed;
0170 #define CARL9170FW_DBG_DESC_SIZE            \
0171     (sizeof(struct carl9170fw_dbg_desc))
0172 
0173 #define CARL9170FW_CHK_DESC_MIN_VER         1
0174 #define CARL9170FW_CHK_DESC_CUR_VER         2
0175 struct carl9170fw_chk_desc {
0176     struct carl9170fw_desc_head head;
0177     __le32 fw_crc32;
0178     __le32 hdr_crc32;
0179 } __packed;
0180 #define CARL9170FW_CHK_DESC_SIZE            \
0181     (sizeof(struct carl9170fw_chk_desc))
0182 
0183 #define CARL9170FW_TXSQ_DESC_MIN_VER            1
0184 #define CARL9170FW_TXSQ_DESC_CUR_VER            1
0185 struct carl9170fw_txsq_desc {
0186     struct carl9170fw_desc_head head;
0187 
0188     __le32 seq_table_addr;
0189 } __packed;
0190 #define CARL9170FW_TXSQ_DESC_SIZE           \
0191     (sizeof(struct carl9170fw_txsq_desc))
0192 
0193 #define CARL9170FW_WOL_DESC_MIN_VER         1
0194 #define CARL9170FW_WOL_DESC_CUR_VER         1
0195 struct carl9170fw_wol_desc {
0196     struct carl9170fw_desc_head head;
0197 
0198     __le32 supported_triggers;  /* CARL9170_WOL_ */
0199 } __packed;
0200 #define CARL9170FW_WOL_DESC_SIZE            \
0201     (sizeof(struct carl9170fw_wol_desc))
0202 
0203 #define CARL9170FW_LAST_DESC_MIN_VER            1
0204 #define CARL9170FW_LAST_DESC_CUR_VER            2
0205 struct carl9170fw_last_desc {
0206     struct carl9170fw_desc_head head;
0207 } __packed;
0208 #define CARL9170FW_LAST_DESC_SIZE           \
0209     (sizeof(struct carl9170fw_fix_desc))
0210 
0211 #define CARL9170FW_DESC_MAX_LENGTH          8192
0212 
0213 #define CARL9170FW_FILL_DESC(_magic, _length, _min_ver, _cur_ver)   \
0214     .head = {                           \
0215         .magic = _magic,                    \
0216         .length = cpu_to_le16(_length),             \
0217         .min_ver = _min_ver,                    \
0218         .cur_ver = _cur_ver,                    \
0219     }
0220 
0221 static inline void carl9170fw_fill_desc(struct carl9170fw_desc_head *head,
0222                      u8 magic[CARL9170FW_MAGIC_SIZE],
0223                      __le16 length, u8 min_ver, u8 cur_ver)
0224 {
0225     head->magic[0] = magic[0];
0226     head->magic[1] = magic[1];
0227     head->magic[2] = magic[2];
0228     head->magic[3] = magic[3];
0229 
0230     head->length = length;
0231     head->min_ver = min_ver;
0232     head->cur_ver = cur_ver;
0233 }
0234 
0235 #define carl9170fw_for_each_hdr(desc, fw_desc)              \
0236     for (desc = fw_desc;                        \
0237          memcmp(desc->magic, LAST_MAGIC, CARL9170FW_MAGIC_SIZE) &&  \
0238          le16_to_cpu(desc->length) >= CARL9170FW_DESC_HEAD_SIZE &&  \
0239          le16_to_cpu(desc->length) < CARL9170FW_DESC_MAX_LENGTH;    \
0240          desc = (void *)((unsigned long)desc + le16_to_cpu(desc->length)))
0241 
0242 #define CHECK_HDR_VERSION(head, _min_ver)               \
0243     (((head)->cur_ver < _min_ver) || ((head)->min_ver > _min_ver))  \
0244 
0245 static inline bool carl9170fw_supports(__le32 list, u8 feature)
0246 {
0247     return le32_to_cpu(list) & BIT(feature);
0248 }
0249 
0250 static inline bool carl9170fw_desc_cmp(const struct carl9170fw_desc_head *head,
0251                        const u8 descid[CARL9170FW_MAGIC_SIZE],
0252                        u16 min_len, u8 compatible_revision)
0253 {
0254     if (descid[0] == head->magic[0] && descid[1] == head->magic[1] &&
0255         descid[2] == head->magic[2] && descid[3] == head->magic[3] &&
0256         !CHECK_HDR_VERSION(head, compatible_revision) &&
0257         (le16_to_cpu(head->length) >= min_len))
0258         return true;
0259 
0260     return false;
0261 }
0262 
0263 #define CARL9170FW_MIN_SIZE 32
0264 #define CARL9170FW_MAX_SIZE 16384
0265 
0266 static inline bool carl9170fw_size_check(unsigned int len)
0267 {
0268     return (len <= CARL9170FW_MAX_SIZE && len >= CARL9170FW_MIN_SIZE);
0269 }
0270 
0271 #endif /* __CARL9170_SHARED_FWDESC_H */