1aae9af60SChristian Lamparter /* 2aae9af60SChristian Lamparter * Shared CARL9170 Header 3aae9af60SChristian Lamparter * 4aae9af60SChristian Lamparter * Firmware descriptor format 5aae9af60SChristian Lamparter * 6aae9af60SChristian Lamparter * Copyright 2009, 2010, Christian Lamparter <chunkeey@googlemail.com> 7aae9af60SChristian Lamparter * 8aae9af60SChristian Lamparter * This program is free software; you can redistribute it and/or modify 9aae9af60SChristian Lamparter * it under the terms of the GNU General Public License as published by 10aae9af60SChristian Lamparter * the Free Software Foundation; either version 2 of the License. 11aae9af60SChristian Lamparter * 12aae9af60SChristian Lamparter * This program is distributed in the hope that it will be useful, 13aae9af60SChristian Lamparter * but WITHOUT ANY WARRANTY; without even the implied warranty of 14aae9af60SChristian Lamparter * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15aae9af60SChristian Lamparter * GNU General Public License for more details. 16aae9af60SChristian Lamparter * 17aae9af60SChristian Lamparter * You should have received a copy of the GNU General Public License 18aae9af60SChristian Lamparter * along with this program; see the file COPYING. If not, see 19aae9af60SChristian Lamparter * http://www.gnu.org/licenses/. 20aae9af60SChristian Lamparter */ 21aae9af60SChristian Lamparter 22aae9af60SChristian Lamparter #ifndef __CARL9170_SHARED_FWDESC_H 23aae9af60SChristian Lamparter #define __CARL9170_SHARED_FWDESC_H 24aae9af60SChristian Lamparter 25aae9af60SChristian Lamparter /* NOTE: Don't mess with the order of the flags! */ 26aae9af60SChristian Lamparter enum carl9170fw_feature_list { 27aae9af60SChristian Lamparter /* Always set */ 28aae9af60SChristian Lamparter CARL9170FW_DUMMY_FEATURE, 29aae9af60SChristian Lamparter 30aae9af60SChristian Lamparter /* 31aae9af60SChristian Lamparter * Indicates that this image has special boot block which prevents 32aae9af60SChristian Lamparter * legacy drivers to drive the firmware. 33aae9af60SChristian Lamparter */ 34aae9af60SChristian Lamparter CARL9170FW_MINIBOOT, 35aae9af60SChristian Lamparter 36aae9af60SChristian Lamparter /* usb registers are initialized by the firmware */ 37aae9af60SChristian Lamparter CARL9170FW_USB_INIT_FIRMWARE, 38aae9af60SChristian Lamparter 39aae9af60SChristian Lamparter /* command traps & notifications are send through EP2 */ 40aae9af60SChristian Lamparter CARL9170FW_USB_RESP_EP2, 41aae9af60SChristian Lamparter 42aae9af60SChristian Lamparter /* usb download (app -> fw) stream */ 43aae9af60SChristian Lamparter CARL9170FW_USB_DOWN_STREAM, 44aae9af60SChristian Lamparter 45aae9af60SChristian Lamparter /* usb upload (fw -> app) stream */ 46aae9af60SChristian Lamparter CARL9170FW_USB_UP_STREAM, 47aae9af60SChristian Lamparter 48aae9af60SChristian Lamparter /* unusable - reserved to flag non-functional debug firmwares */ 49aae9af60SChristian Lamparter CARL9170FW_UNUSABLE, 50aae9af60SChristian Lamparter 51aae9af60SChristian Lamparter /* AR9170_CMD_RF_INIT, AR9170_CMD_FREQ_START, AR9170_CMD_FREQUENCY */ 52aae9af60SChristian Lamparter CARL9170FW_COMMAND_PHY, 53aae9af60SChristian Lamparter 54aae9af60SChristian Lamparter /* AR9170_CMD_EKEY, AR9170_CMD_DKEY */ 55aae9af60SChristian Lamparter CARL9170FW_COMMAND_CAM, 56aae9af60SChristian Lamparter 57aae9af60SChristian Lamparter /* Firmware has a software Content After Beacon Queueing mechanism */ 58aae9af60SChristian Lamparter CARL9170FW_WLANTX_CAB, 59aae9af60SChristian Lamparter 60aae9af60SChristian Lamparter /* The firmware is capable of responding to incoming BAR frames */ 61aae9af60SChristian Lamparter CARL9170FW_HANDLE_BACK_REQ, 62aae9af60SChristian Lamparter 63aae9af60SChristian Lamparter /* GPIO Interrupt | CARL9170_RSP_GPIO */ 64aae9af60SChristian Lamparter CARL9170FW_GPIO_INTERRUPT, 65aae9af60SChristian Lamparter 66aae9af60SChristian Lamparter /* Firmware PSM support | CARL9170_CMD_PSM */ 67aae9af60SChristian Lamparter CARL9170FW_PSM, 68aae9af60SChristian Lamparter 695c895691SChristian Lamparter /* Firmware RX filter | CARL9170_CMD_RX_FILTER */ 705c895691SChristian Lamparter CARL9170FW_RX_FILTER, 715c895691SChristian Lamparter 72*9e09b5c9SChristian Lamparter /* Wake up on WLAN */ 73*9e09b5c9SChristian Lamparter CARL9170FW_WOL, 74*9e09b5c9SChristian Lamparter 75aae9af60SChristian Lamparter /* KEEP LAST */ 76aae9af60SChristian Lamparter __CARL9170FW_FEATURE_NUM 77aae9af60SChristian Lamparter }; 78aae9af60SChristian Lamparter 79aae9af60SChristian Lamparter #define OTUS_MAGIC "OTAR" 80aae9af60SChristian Lamparter #define MOTD_MAGIC "MOTD" 81aae9af60SChristian Lamparter #define FIX_MAGIC "FIX\0" 82aae9af60SChristian Lamparter #define DBG_MAGIC "DBG\0" 83aae9af60SChristian Lamparter #define CHK_MAGIC "CHK\0" 84*9e09b5c9SChristian Lamparter #define TXSQ_MAGIC "TXSQ" 85aae9af60SChristian Lamparter #define LAST_MAGIC "LAST" 86aae9af60SChristian Lamparter 87aae9af60SChristian Lamparter #define CARL9170FW_SET_DAY(d) (((d) - 1) % 31) 88aae9af60SChristian Lamparter #define CARL9170FW_SET_MONTH(m) ((((m) - 1) % 12) * 31) 89aae9af60SChristian Lamparter #define CARL9170FW_SET_YEAR(y) (((y) - 10) * 372) 90aae9af60SChristian Lamparter 91aae9af60SChristian Lamparter #define CARL9170FW_GET_DAY(d) (((d) % 31) + 1) 92aae9af60SChristian Lamparter #define CARL9170FW_GET_MONTH(m) ((((m) / 31) % 12) + 1) 93aae9af60SChristian Lamparter #define CARL9170FW_GET_YEAR(y) ((y) / 372 + 10) 94aae9af60SChristian Lamparter 95*9e09b5c9SChristian Lamparter #define CARL9170FW_MAGIC_SIZE 4 96*9e09b5c9SChristian Lamparter 97aae9af60SChristian Lamparter struct carl9170fw_desc_head { 98*9e09b5c9SChristian Lamparter u8 magic[CARL9170FW_MAGIC_SIZE]; 99aae9af60SChristian Lamparter __le16 length; 100aae9af60SChristian Lamparter u8 min_ver; 101aae9af60SChristian Lamparter u8 cur_ver; 102aae9af60SChristian Lamparter } __packed; 103aae9af60SChristian Lamparter #define CARL9170FW_DESC_HEAD_SIZE \ 104aae9af60SChristian Lamparter (sizeof(struct carl9170fw_desc_head)) 105aae9af60SChristian Lamparter 106aae9af60SChristian Lamparter #define CARL9170FW_OTUS_DESC_MIN_VER 6 107aae9af60SChristian Lamparter #define CARL9170FW_OTUS_DESC_CUR_VER 6 108aae9af60SChristian Lamparter struct carl9170fw_otus_desc { 109aae9af60SChristian Lamparter struct carl9170fw_desc_head head; 110aae9af60SChristian Lamparter __le32 feature_set; 111aae9af60SChristian Lamparter __le32 fw_address; 112aae9af60SChristian Lamparter __le32 bcn_addr; 113aae9af60SChristian Lamparter __le16 bcn_len; 114aae9af60SChristian Lamparter __le16 miniboot_size; 115aae9af60SChristian Lamparter __le16 tx_frag_len; 116aae9af60SChristian Lamparter __le16 rx_max_frame_len; 117aae9af60SChristian Lamparter u8 tx_descs; 118aae9af60SChristian Lamparter u8 cmd_bufs; 119aae9af60SChristian Lamparter u8 api_ver; 120aae9af60SChristian Lamparter u8 vif_num; 121aae9af60SChristian Lamparter } __packed; 122aae9af60SChristian Lamparter #define CARL9170FW_OTUS_DESC_SIZE \ 123aae9af60SChristian Lamparter (sizeof(struct carl9170fw_otus_desc)) 124aae9af60SChristian Lamparter 125aae9af60SChristian Lamparter #define CARL9170FW_MOTD_STRING_LEN 24 126aae9af60SChristian Lamparter #define CARL9170FW_MOTD_RELEASE_LEN 20 127aae9af60SChristian Lamparter #define CARL9170FW_MOTD_DESC_MIN_VER 1 128aae9af60SChristian Lamparter #define CARL9170FW_MOTD_DESC_CUR_VER 2 129aae9af60SChristian Lamparter struct carl9170fw_motd_desc { 130aae9af60SChristian Lamparter struct carl9170fw_desc_head head; 131aae9af60SChristian Lamparter __le32 fw_year_month_day; 132aae9af60SChristian Lamparter char desc[CARL9170FW_MOTD_STRING_LEN]; 133aae9af60SChristian Lamparter char release[CARL9170FW_MOTD_RELEASE_LEN]; 134aae9af60SChristian Lamparter } __packed; 135aae9af60SChristian Lamparter #define CARL9170FW_MOTD_DESC_SIZE \ 136aae9af60SChristian Lamparter (sizeof(struct carl9170fw_motd_desc)) 137aae9af60SChristian Lamparter 138aae9af60SChristian Lamparter #define CARL9170FW_FIX_DESC_MIN_VER 1 139aae9af60SChristian Lamparter #define CARL9170FW_FIX_DESC_CUR_VER 2 140aae9af60SChristian Lamparter struct carl9170fw_fix_entry { 141aae9af60SChristian Lamparter __le32 address; 142aae9af60SChristian Lamparter __le32 mask; 143aae9af60SChristian Lamparter __le32 value; 144aae9af60SChristian Lamparter } __packed; 145aae9af60SChristian Lamparter 146aae9af60SChristian Lamparter struct carl9170fw_fix_desc { 147aae9af60SChristian Lamparter struct carl9170fw_desc_head head; 148aae9af60SChristian Lamparter struct carl9170fw_fix_entry data[0]; 149aae9af60SChristian Lamparter } __packed; 150aae9af60SChristian Lamparter #define CARL9170FW_FIX_DESC_SIZE \ 151aae9af60SChristian Lamparter (sizeof(struct carl9170fw_fix_desc)) 152aae9af60SChristian Lamparter 153aae9af60SChristian Lamparter #define CARL9170FW_DBG_DESC_MIN_VER 1 1545c895691SChristian Lamparter #define CARL9170FW_DBG_DESC_CUR_VER 3 155aae9af60SChristian Lamparter struct carl9170fw_dbg_desc { 156aae9af60SChristian Lamparter struct carl9170fw_desc_head head; 157aae9af60SChristian Lamparter 158aae9af60SChristian Lamparter __le32 bogoclock_addr; 159aae9af60SChristian Lamparter __le32 counter_addr; 160aae9af60SChristian Lamparter __le32 rx_total_addr; 161aae9af60SChristian Lamparter __le32 rx_overrun_addr; 1625c895691SChristian Lamparter __le32 rx_filter; 163aae9af60SChristian Lamparter 164aae9af60SChristian Lamparter /* Put your debugging definitions here */ 165aae9af60SChristian Lamparter } __packed; 166aae9af60SChristian Lamparter #define CARL9170FW_DBG_DESC_SIZE \ 167aae9af60SChristian Lamparter (sizeof(struct carl9170fw_dbg_desc)) 168aae9af60SChristian Lamparter 169aae9af60SChristian Lamparter #define CARL9170FW_CHK_DESC_MIN_VER 1 170aae9af60SChristian Lamparter #define CARL9170FW_CHK_DESC_CUR_VER 2 171aae9af60SChristian Lamparter struct carl9170fw_chk_desc { 172aae9af60SChristian Lamparter struct carl9170fw_desc_head head; 173aae9af60SChristian Lamparter __le32 fw_crc32; 174aae9af60SChristian Lamparter __le32 hdr_crc32; 175aae9af60SChristian Lamparter } __packed; 176aae9af60SChristian Lamparter #define CARL9170FW_CHK_DESC_SIZE \ 177aae9af60SChristian Lamparter (sizeof(struct carl9170fw_chk_desc)) 178aae9af60SChristian Lamparter 179*9e09b5c9SChristian Lamparter #define CARL9170FW_TXSQ_DESC_MIN_VER 1 180*9e09b5c9SChristian Lamparter #define CARL9170FW_TXSQ_DESC_CUR_VER 1 181*9e09b5c9SChristian Lamparter struct carl9170fw_txsq_desc { 182*9e09b5c9SChristian Lamparter struct carl9170fw_desc_head head; 183*9e09b5c9SChristian Lamparter 184*9e09b5c9SChristian Lamparter __le32 seq_table_addr; 185*9e09b5c9SChristian Lamparter } __packed; 186*9e09b5c9SChristian Lamparter #define CARL9170FW_TXSQ_DESC_SIZE \ 187*9e09b5c9SChristian Lamparter (sizeof(struct carl9170fw_txsq_desc)) 188*9e09b5c9SChristian Lamparter 189aae9af60SChristian Lamparter #define CARL9170FW_LAST_DESC_MIN_VER 1 190aae9af60SChristian Lamparter #define CARL9170FW_LAST_DESC_CUR_VER 2 191aae9af60SChristian Lamparter struct carl9170fw_last_desc { 192aae9af60SChristian Lamparter struct carl9170fw_desc_head head; 193aae9af60SChristian Lamparter } __packed; 194aae9af60SChristian Lamparter #define CARL9170FW_LAST_DESC_SIZE \ 195aae9af60SChristian Lamparter (sizeof(struct carl9170fw_fix_desc)) 196aae9af60SChristian Lamparter 197aae9af60SChristian Lamparter #define CARL9170FW_DESC_MAX_LENGTH 8192 198aae9af60SChristian Lamparter 199aae9af60SChristian Lamparter #define CARL9170FW_FILL_DESC(_magic, _length, _min_ver, _cur_ver) \ 200aae9af60SChristian Lamparter .head = { \ 201aae9af60SChristian Lamparter .magic = _magic, \ 202aae9af60SChristian Lamparter .length = cpu_to_le16(_length), \ 203aae9af60SChristian Lamparter .min_ver = _min_ver, \ 204aae9af60SChristian Lamparter .cur_ver = _cur_ver, \ 205aae9af60SChristian Lamparter } 206aae9af60SChristian Lamparter 207aae9af60SChristian Lamparter static inline void carl9170fw_fill_desc(struct carl9170fw_desc_head *head, 208*9e09b5c9SChristian Lamparter u8 magic[CARL9170FW_MAGIC_SIZE], 209*9e09b5c9SChristian Lamparter __le16 length, u8 min_ver, u8 cur_ver) 210aae9af60SChristian Lamparter { 211aae9af60SChristian Lamparter head->magic[0] = magic[0]; 212aae9af60SChristian Lamparter head->magic[1] = magic[1]; 213aae9af60SChristian Lamparter head->magic[2] = magic[2]; 214aae9af60SChristian Lamparter head->magic[3] = magic[3]; 215aae9af60SChristian Lamparter 216aae9af60SChristian Lamparter head->length = length; 217aae9af60SChristian Lamparter head->min_ver = min_ver; 218aae9af60SChristian Lamparter head->cur_ver = cur_ver; 219aae9af60SChristian Lamparter } 220aae9af60SChristian Lamparter 221aae9af60SChristian Lamparter #define carl9170fw_for_each_hdr(desc, fw_desc) \ 222aae9af60SChristian Lamparter for (desc = fw_desc; \ 223*9e09b5c9SChristian Lamparter memcmp(desc->magic, LAST_MAGIC, CARL9170FW_MAGIC_SIZE) && \ 224aae9af60SChristian Lamparter le16_to_cpu(desc->length) >= CARL9170FW_DESC_HEAD_SIZE && \ 225aae9af60SChristian Lamparter le16_to_cpu(desc->length) < CARL9170FW_DESC_MAX_LENGTH; \ 226aae9af60SChristian Lamparter desc = (void *)((unsigned long)desc + le16_to_cpu(desc->length))) 227aae9af60SChristian Lamparter 228aae9af60SChristian Lamparter #define CHECK_HDR_VERSION(head, _min_ver) \ 229aae9af60SChristian Lamparter (((head)->cur_ver < _min_ver) || ((head)->min_ver > _min_ver)) \ 230aae9af60SChristian Lamparter 231aae9af60SChristian Lamparter static inline bool carl9170fw_supports(__le32 list, u8 feature) 232aae9af60SChristian Lamparter { 233aae9af60SChristian Lamparter return le32_to_cpu(list) & BIT(feature); 234aae9af60SChristian Lamparter } 235aae9af60SChristian Lamparter 236aae9af60SChristian Lamparter static inline bool carl9170fw_desc_cmp(const struct carl9170fw_desc_head *head, 237*9e09b5c9SChristian Lamparter const u8 descid[CARL9170FW_MAGIC_SIZE], 238*9e09b5c9SChristian Lamparter u16 min_len, u8 compatible_revision) 239aae9af60SChristian Lamparter { 240aae9af60SChristian Lamparter if (descid[0] == head->magic[0] && descid[1] == head->magic[1] && 241aae9af60SChristian Lamparter descid[2] == head->magic[2] && descid[3] == head->magic[3] && 242aae9af60SChristian Lamparter !CHECK_HDR_VERSION(head, compatible_revision) && 243aae9af60SChristian Lamparter (le16_to_cpu(head->length) >= min_len)) 244aae9af60SChristian Lamparter return true; 245aae9af60SChristian Lamparter 246aae9af60SChristian Lamparter return false; 247aae9af60SChristian Lamparter } 248aae9af60SChristian Lamparter 249aae9af60SChristian Lamparter #define CARL9170FW_MIN_SIZE 32 250aae9af60SChristian Lamparter #define CARL9170FW_MAX_SIZE 16384 251aae9af60SChristian Lamparter 252aae9af60SChristian Lamparter static inline bool carl9170fw_size_check(unsigned int len) 253aae9af60SChristian Lamparter { 254aae9af60SChristian Lamparter return (len <= CARL9170FW_MAX_SIZE && len >= CARL9170FW_MIN_SIZE); 255aae9af60SChristian Lamparter } 256aae9af60SChristian Lamparter 257aae9af60SChristian Lamparter #endif /* __CARL9170_SHARED_FWDESC_H */ 258