libertas_tf.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. /*
  2. * Copyright (C) 2008, cozybit Inc.
  3. * Copyright (C) 2007, Red Hat, Inc.
  4. * Copyright (C) 2003-2006, Marvell International Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or (at
  9. * your option) any later version.
  10. */
  11. #include <linux/spinlock.h>
  12. #include <linux/device.h>
  13. #include <linux/kthread.h>
  14. #include <net/mac80211.h>
  15. #include "deb_defs.h"
  16. #ifndef DRV_NAME
  17. #define DRV_NAME "libertas_tf"
  18. #endif
  19. #define MRVL_DEFAULT_RETRIES 9
  20. #define MRVL_PER_PACKET_RATE 0x10
  21. #define MRVL_MAX_BCN_SIZE 440
  22. #define CMD_OPTION_WAITFORRSP 0x0002
  23. /* Return command are almost always the same as the host command, but with
  24. * bit 15 set high. There are a few exceptions, though...
  25. */
  26. #define CMD_RET(cmd) (0x8000 | cmd)
  27. /* Command codes */
  28. #define CMD_GET_HW_SPEC 0x0003
  29. #define CMD_802_11_RESET 0x0005
  30. #define CMD_MAC_MULTICAST_ADR 0x0010
  31. #define CMD_802_11_RADIO_CONTROL 0x001c
  32. #define CMD_802_11_RF_CHANNEL 0x001d
  33. #define CMD_802_11_RF_TX_POWER 0x001e
  34. #define CMD_MAC_CONTROL 0x0028
  35. #define CMD_802_11_MAC_ADDRESS 0x004d
  36. #define CMD_SET_BOOT2_VER 0x00a5
  37. #define CMD_802_11_BEACON_CTRL 0x00b0
  38. #define CMD_802_11_BEACON_SET 0x00cb
  39. #define CMD_802_11_SET_MODE 0x00cc
  40. #define CMD_802_11_SET_BSSID 0x00cd
  41. #define CMD_ACT_GET 0x0000
  42. #define CMD_ACT_SET 0x0001
  43. /* Define action or option for CMD_802_11_RESET */
  44. #define CMD_ACT_HALT 0x0003
  45. /* Define action or option for CMD_MAC_CONTROL */
  46. #define CMD_ACT_MAC_RX_ON 0x0001
  47. #define CMD_ACT_MAC_TX_ON 0x0002
  48. #define CMD_ACT_MAC_MULTICAST_ENABLE 0x0020
  49. #define CMD_ACT_MAC_BROADCAST_ENABLE 0x0040
  50. #define CMD_ACT_MAC_PROMISCUOUS_ENABLE 0x0080
  51. #define CMD_ACT_MAC_ALL_MULTICAST_ENABLE 0x0100
  52. /* Define action or option for CMD_802_11_RADIO_CONTROL */
  53. #define CMD_TYPE_AUTO_PREAMBLE 0x0001
  54. #define CMD_TYPE_SHORT_PREAMBLE 0x0002
  55. #define CMD_TYPE_LONG_PREAMBLE 0x0003
  56. #define TURN_ON_RF 0x01
  57. #define RADIO_ON 0x01
  58. #define RADIO_OFF 0x00
  59. #define SET_AUTO_PREAMBLE 0x05
  60. #define SET_SHORT_PREAMBLE 0x03
  61. #define SET_LONG_PREAMBLE 0x01
  62. /* Define action or option for CMD_802_11_RF_CHANNEL */
  63. #define CMD_OPT_802_11_RF_CHANNEL_GET 0x00
  64. #define CMD_OPT_802_11_RF_CHANNEL_SET 0x01
  65. /* Codes for CMD_802_11_SET_MODE */
  66. enum lbtf_mode {
  67. LBTF_PASSIVE_MODE,
  68. LBTF_STA_MODE,
  69. LBTF_AP_MODE,
  70. };
  71. /** Card Event definition */
  72. #define MACREG_INT_CODE_FIRMWARE_READY 48
  73. /** Buffer Constants */
  74. /* The size of SQ memory PPA, DPA are 8 DWORDs, that keep the physical
  75. * addresses of TxPD buffers. Station has only 8 TxPD available, Whereas
  76. * driver has more local TxPDs. Each TxPD on the host memory is associated
  77. * with a Tx control node. The driver maintains 8 RxPD descriptors for
  78. * station firmware to store Rx packet information.
  79. *
  80. * Current version of MAC has a 32x6 multicast address buffer.
  81. *
  82. * 802.11b can have up to 14 channels, the driver keeps the
  83. * BSSID(MAC address) of each APs or Ad hoc stations it has sensed.
  84. */
  85. #define MRVDRV_MAX_MULTICAST_LIST_SIZE 32
  86. #define LBS_NUM_CMD_BUFFERS 10
  87. #define LBS_CMD_BUFFER_SIZE (2 * 1024)
  88. #define MRVDRV_MAX_CHANNEL_SIZE 14
  89. #define MRVDRV_SNAP_HEADER_LEN 8
  90. #define LBS_UPLD_SIZE 2312
  91. #define DEV_NAME_LEN 32
  92. /** Misc constants */
  93. /* This section defines 802.11 specific contants */
  94. #define MRVDRV_MAX_REGION_CODE 6
  95. /**
  96. * the table to keep region code
  97. */
  98. #define LBTF_REGDOMAIN_US 0x10
  99. #define LBTF_REGDOMAIN_CA 0x20
  100. #define LBTF_REGDOMAIN_EU 0x30
  101. #define LBTF_REGDOMAIN_SP 0x31
  102. #define LBTF_REGDOMAIN_FR 0x32
  103. #define LBTF_REGDOMAIN_JP 0x40
  104. #define SBI_EVENT_CAUSE_SHIFT 3
  105. /** RxPD status */
  106. #define MRVDRV_RXPD_STATUS_OK 0x0001
  107. /* This is for firmware specific length */
  108. #define EXTRA_LEN 36
  109. #define MRVDRV_ETH_TX_PACKET_BUFFER_SIZE \
  110. (ETH_FRAME_LEN + sizeof(struct txpd) + EXTRA_LEN)
  111. #define MRVDRV_ETH_RX_PACKET_BUFFER_SIZE \
  112. (ETH_FRAME_LEN + sizeof(struct rxpd) \
  113. + MRVDRV_SNAP_HEADER_LEN + EXTRA_LEN)
  114. #define CMD_F_HOSTCMD (1 << 0)
  115. #define FW_CAPINFO_WPA (1 << 0)
  116. #define RF_ANTENNA_1 0x1
  117. #define RF_ANTENNA_2 0x2
  118. #define RF_ANTENNA_AUTO 0xFFFF
  119. #define LBTF_EVENT_BCN_SENT 55
  120. /** Global Variable Declaration */
  121. /** mv_ms_type */
  122. enum mv_ms_type {
  123. MVMS_DAT = 0,
  124. MVMS_CMD = 1,
  125. MVMS_TXDONE = 2,
  126. MVMS_EVENT
  127. };
  128. extern struct workqueue_struct *lbtf_wq;
  129. struct lbtf_private;
  130. struct lbtf_offset_value {
  131. u32 offset;
  132. u32 value;
  133. };
  134. struct channel_range {
  135. u8 regdomain;
  136. u8 start;
  137. u8 end; /* exclusive (channel must be less than end) */
  138. };
  139. struct if_usb_card;
  140. /** Private structure for the MV device */
  141. struct lbtf_private {
  142. void *card;
  143. struct ieee80211_hw *hw;
  144. /* Command response buffer */
  145. u8 cmd_resp_buff[LBS_UPLD_SIZE];
  146. /* Download sent:
  147. bit0 1/0=data_sent/data_tx_done,
  148. bit1 1/0=cmd_sent/cmd_tx_done,
  149. all other bits reserved 0 */
  150. struct ieee80211_vif *vif;
  151. struct work_struct cmd_work;
  152. struct work_struct tx_work;
  153. /** Hardware access */
  154. int (*hw_host_to_card) (struct lbtf_private *priv, u8 type, u8 *payload, u16 nb);
  155. int (*hw_prog_firmware) (struct if_usb_card *cardp);
  156. int (*hw_reset_device) (struct if_usb_card *cardp);
  157. /** Wlan adapter data structure*/
  158. /** STATUS variables */
  159. u32 fwrelease;
  160. u32 fwcapinfo;
  161. /* protected with big lock */
  162. struct mutex lock;
  163. /** command-related variables */
  164. u16 seqnum;
  165. /* protected by big lock */
  166. struct cmd_ctrl_node *cmd_array;
  167. /** Current command */
  168. struct cmd_ctrl_node *cur_cmd;
  169. /** command Queues */
  170. /** Free command buffers */
  171. struct list_head cmdfreeq;
  172. /** Pending command buffers */
  173. struct list_head cmdpendingq;
  174. /** spin locks */
  175. spinlock_t driver_lock;
  176. /** Timers */
  177. struct timer_list command_timer;
  178. int nr_retries;
  179. int cmd_timed_out;
  180. u8 cmd_response_rxed;
  181. /** capability Info used in Association, start, join */
  182. u16 capability;
  183. /** MAC address information */
  184. u8 current_addr[ETH_ALEN];
  185. u8 multicastlist[MRVDRV_MAX_MULTICAST_LIST_SIZE][ETH_ALEN];
  186. u32 nr_of_multicastmacaddr;
  187. int cur_freq;
  188. struct sk_buff *skb_to_tx;
  189. struct sk_buff *tx_skb;
  190. /** NIC Operation characteristics */
  191. u16 mac_control;
  192. u16 regioncode;
  193. struct channel_range range;
  194. u8 radioon;
  195. u32 preamble;
  196. struct ieee80211_channel channels[14];
  197. struct ieee80211_rate rates[12];
  198. struct ieee80211_supported_band band;
  199. struct lbtf_offset_value offsetvalue;
  200. u8 fw_ready;
  201. u8 surpriseremoved;
  202. struct sk_buff_head bc_ps_buf;
  203. /* Most recently reported noise in dBm */
  204. s8 noise;
  205. };
  206. /* 802.11-related definitions */
  207. /* TxPD descriptor */
  208. struct txpd {
  209. /* Current Tx packet status */
  210. __le32 tx_status;
  211. /* Tx control */
  212. __le32 tx_control;
  213. __le32 tx_packet_location;
  214. /* Tx packet length */
  215. __le16 tx_packet_length;
  216. /* First 2 byte of destination MAC address */
  217. u8 tx_dest_addr_high[2];
  218. /* Last 4 byte of destination MAC address */
  219. u8 tx_dest_addr_low[4];
  220. /* Pkt Priority */
  221. u8 priority;
  222. /* Pkt Trasnit Power control */
  223. u8 powermgmt;
  224. /* Time the packet has been queued in the driver (units = 2ms) */
  225. u8 pktdelay_2ms;
  226. /* reserved */
  227. u8 reserved1;
  228. };
  229. /* RxPD Descriptor */
  230. struct rxpd {
  231. /* Current Rx packet status */
  232. __le16 status;
  233. /* SNR */
  234. u8 snr;
  235. /* Tx control */
  236. u8 rx_control;
  237. /* Pkt length */
  238. __le16 pkt_len;
  239. /* Noise Floor */
  240. u8 nf;
  241. /* Rx Packet Rate */
  242. u8 rx_rate;
  243. /* Pkt addr */
  244. __le32 pkt_ptr;
  245. /* Next Rx RxPD addr */
  246. __le32 next_rxpd_ptr;
  247. /* Pkt Priority */
  248. u8 priority;
  249. u8 reserved[3];
  250. };
  251. struct cmd_header {
  252. __le16 command;
  253. __le16 size;
  254. __le16 seqnum;
  255. __le16 result;
  256. } __packed;
  257. struct cmd_ctrl_node {
  258. struct list_head list;
  259. int result;
  260. /* command response */
  261. int (*callback)(struct lbtf_private *,
  262. unsigned long, struct cmd_header *);
  263. unsigned long callback_arg;
  264. /* command data */
  265. struct cmd_header *cmdbuf;
  266. /* wait queue */
  267. u16 cmdwaitqwoken;
  268. wait_queue_head_t cmdwait_q;
  269. };
  270. /*
  271. * Define data structure for CMD_GET_HW_SPEC
  272. * This structure defines the response for the GET_HW_SPEC command
  273. */
  274. struct cmd_ds_get_hw_spec {
  275. struct cmd_header hdr;
  276. /* HW Interface version number */
  277. __le16 hwifversion;
  278. /* HW version number */
  279. __le16 version;
  280. /* Max number of TxPD FW can handle */
  281. __le16 nr_txpd;
  282. /* Max no of Multicast address */
  283. __le16 nr_mcast_adr;
  284. /* MAC address */
  285. u8 permanentaddr[6];
  286. /* region Code */
  287. __le16 regioncode;
  288. /* Number of antenna used */
  289. __le16 nr_antenna;
  290. /* FW release number, example 0x01030304 = 2.3.4p1 */
  291. __le32 fwrelease;
  292. /* Base Address of TxPD queue */
  293. __le32 wcb_base;
  294. /* Read Pointer of RxPd queue */
  295. __le32 rxpd_rdptr;
  296. /* Write Pointer of RxPd queue */
  297. __le32 rxpd_wrptr;
  298. /*FW/HW capability */
  299. __le32 fwcapinfo;
  300. } __packed;
  301. struct cmd_ds_mac_control {
  302. struct cmd_header hdr;
  303. __le16 action;
  304. u16 reserved;
  305. };
  306. struct cmd_ds_802_11_mac_address {
  307. struct cmd_header hdr;
  308. __le16 action;
  309. uint8_t macadd[ETH_ALEN];
  310. };
  311. struct cmd_ds_mac_multicast_addr {
  312. struct cmd_header hdr;
  313. __le16 action;
  314. __le16 nr_of_adrs;
  315. u8 maclist[ETH_ALEN * MRVDRV_MAX_MULTICAST_LIST_SIZE];
  316. };
  317. struct cmd_ds_set_mode {
  318. struct cmd_header hdr;
  319. __le16 mode;
  320. };
  321. struct cmd_ds_set_bssid {
  322. struct cmd_header hdr;
  323. u8 bssid[6];
  324. u8 activate;
  325. };
  326. struct cmd_ds_802_11_radio_control {
  327. struct cmd_header hdr;
  328. __le16 action;
  329. __le16 control;
  330. };
  331. struct cmd_ds_802_11_rf_channel {
  332. struct cmd_header hdr;
  333. __le16 action;
  334. __le16 channel;
  335. __le16 rftype; /* unused */
  336. __le16 reserved; /* unused */
  337. u8 channellist[32]; /* unused */
  338. };
  339. struct cmd_ds_set_boot2_ver {
  340. struct cmd_header hdr;
  341. __le16 action;
  342. __le16 version;
  343. };
  344. struct cmd_ds_802_11_reset {
  345. struct cmd_header hdr;
  346. __le16 action;
  347. };
  348. struct cmd_ds_802_11_beacon_control {
  349. struct cmd_header hdr;
  350. __le16 action;
  351. __le16 beacon_enable;
  352. __le16 beacon_period;
  353. };
  354. struct cmd_ds_802_11_beacon_set {
  355. struct cmd_header hdr;
  356. __le16 len;
  357. u8 beacon[MRVL_MAX_BCN_SIZE];
  358. };
  359. struct lbtf_private;
  360. struct cmd_ctrl_node;
  361. /** Function Prototype Declaration */
  362. void lbtf_set_mac_control(struct lbtf_private *priv);
  363. int lbtf_free_cmd_buffer(struct lbtf_private *priv);
  364. int lbtf_allocate_cmd_buffer(struct lbtf_private *priv);
  365. int lbtf_execute_next_command(struct lbtf_private *priv);
  366. int lbtf_set_radio_control(struct lbtf_private *priv);
  367. int lbtf_update_hw_spec(struct lbtf_private *priv);
  368. int lbtf_cmd_set_mac_multicast_addr(struct lbtf_private *priv);
  369. void lbtf_set_mode(struct lbtf_private *priv, enum lbtf_mode mode);
  370. void lbtf_set_bssid(struct lbtf_private *priv, bool activate, const u8 *bssid);
  371. int lbtf_set_mac_address(struct lbtf_private *priv, uint8_t *mac_addr);
  372. int lbtf_set_channel(struct lbtf_private *priv, u8 channel);
  373. int lbtf_beacon_set(struct lbtf_private *priv, struct sk_buff *beacon);
  374. int lbtf_beacon_ctrl(struct lbtf_private *priv, bool beacon_enable,
  375. int beacon_int);
  376. int lbtf_process_rx_command(struct lbtf_private *priv);
  377. void lbtf_complete_command(struct lbtf_private *priv, struct cmd_ctrl_node *cmd,
  378. int result);
  379. void lbtf_cmd_response_rx(struct lbtf_private *priv);
  380. /* main.c */
  381. struct chan_freq_power *lbtf_get_region_cfp_table(u8 region,
  382. int *cfp_no);
  383. struct lbtf_private *lbtf_add_card(void *card, struct device *dmdev);
  384. int lbtf_remove_card(struct lbtf_private *priv);
  385. int lbtf_start_card(struct lbtf_private *priv);
  386. int lbtf_rx(struct lbtf_private *priv, struct sk_buff *skb);
  387. void lbtf_send_tx_feedback(struct lbtf_private *priv, u8 retrycnt, u8 fail);
  388. void lbtf_bcn_sent(struct lbtf_private *priv);
  389. /* support functions for cmd.c */
  390. /* lbtf_cmd() infers the size of the buffer to copy data back into, from
  391. the size of the target of the pointer. Since the command to be sent
  392. may often be smaller, that size is set in cmd->size by the caller.*/
  393. #define lbtf_cmd(priv, cmdnr, cmd, cb, cb_arg) ({ \
  394. uint16_t __sz = le16_to_cpu((cmd)->hdr.size); \
  395. (cmd)->hdr.size = cpu_to_le16(sizeof(*(cmd))); \
  396. __lbtf_cmd(priv, cmdnr, &(cmd)->hdr, __sz, cb, cb_arg); \
  397. })
  398. #define lbtf_cmd_with_response(priv, cmdnr, cmd) \
  399. lbtf_cmd(priv, cmdnr, cmd, lbtf_cmd_copyback, (unsigned long) (cmd))
  400. void lbtf_cmd_async(struct lbtf_private *priv, uint16_t command,
  401. struct cmd_header *in_cmd, int in_cmd_size);
  402. int __lbtf_cmd(struct lbtf_private *priv, uint16_t command,
  403. struct cmd_header *in_cmd, int in_cmd_size,
  404. int (*callback)(struct lbtf_private *, unsigned long,
  405. struct cmd_header *),
  406. unsigned long callback_arg);
  407. int lbtf_cmd_copyback(struct lbtf_private *priv, unsigned long extra,
  408. struct cmd_header *resp);