zd_mac.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214
  1. /* ZD1211 USB-WLAN driver for Linux
  2. *
  3. * Copyright (C) 2005-2007 Ulrich Kunitz <kune@deine-taler.de>
  4. * Copyright (C) 2006-2007 Daniel Drake <dsd@gentoo.org>
  5. * Copyright (C) 2006-2007 Michael Wu <flamingice@sourmilk.net>
  6. * Copyright (C) 2007-2008 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/netdevice.h>
  23. #include <linux/etherdevice.h>
  24. #include <linux/usb.h>
  25. #include <linux/jiffies.h>
  26. #include <net/ieee80211_radiotap.h>
  27. #include "zd_def.h"
  28. #include "zd_chip.h"
  29. #include "zd_mac.h"
  30. #include "zd_rf.h"
  31. struct zd_reg_alpha2_map {
  32. u32 reg;
  33. char alpha2[2];
  34. };
  35. static struct zd_reg_alpha2_map reg_alpha2_map[] = {
  36. { ZD_REGDOMAIN_FCC, "US" },
  37. { ZD_REGDOMAIN_IC, "CA" },
  38. { ZD_REGDOMAIN_ETSI, "DE" }, /* Generic ETSI, use most restrictive */
  39. { ZD_REGDOMAIN_JAPAN, "JP" },
  40. { ZD_REGDOMAIN_JAPAN_ADD, "JP" },
  41. { ZD_REGDOMAIN_SPAIN, "ES" },
  42. { ZD_REGDOMAIN_FRANCE, "FR" },
  43. };
  44. /* This table contains the hardware specific values for the modulation rates. */
  45. static const struct ieee80211_rate zd_rates[] = {
  46. { .bitrate = 10,
  47. .hw_value = ZD_CCK_RATE_1M, },
  48. { .bitrate = 20,
  49. .hw_value = ZD_CCK_RATE_2M,
  50. .hw_value_short = ZD_CCK_RATE_2M | ZD_CCK_PREA_SHORT,
  51. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  52. { .bitrate = 55,
  53. .hw_value = ZD_CCK_RATE_5_5M,
  54. .hw_value_short = ZD_CCK_RATE_5_5M | ZD_CCK_PREA_SHORT,
  55. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  56. { .bitrate = 110,
  57. .hw_value = ZD_CCK_RATE_11M,
  58. .hw_value_short = ZD_CCK_RATE_11M | ZD_CCK_PREA_SHORT,
  59. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  60. { .bitrate = 60,
  61. .hw_value = ZD_OFDM_RATE_6M,
  62. .flags = 0 },
  63. { .bitrate = 90,
  64. .hw_value = ZD_OFDM_RATE_9M,
  65. .flags = 0 },
  66. { .bitrate = 120,
  67. .hw_value = ZD_OFDM_RATE_12M,
  68. .flags = 0 },
  69. { .bitrate = 180,
  70. .hw_value = ZD_OFDM_RATE_18M,
  71. .flags = 0 },
  72. { .bitrate = 240,
  73. .hw_value = ZD_OFDM_RATE_24M,
  74. .flags = 0 },
  75. { .bitrate = 360,
  76. .hw_value = ZD_OFDM_RATE_36M,
  77. .flags = 0 },
  78. { .bitrate = 480,
  79. .hw_value = ZD_OFDM_RATE_48M,
  80. .flags = 0 },
  81. { .bitrate = 540,
  82. .hw_value = ZD_OFDM_RATE_54M,
  83. .flags = 0 },
  84. };
  85. /*
  86. * Zydas retry rates table. Each line is listed in the same order as
  87. * in zd_rates[] and contains all the rate used when a packet is sent
  88. * starting with a given rates. Let's consider an example :
  89. *
  90. * "11 Mbits : 4, 3, 2, 1, 0" means :
  91. * - packet is sent using 4 different rates
  92. * - 1st rate is index 3 (ie 11 Mbits)
  93. * - 2nd rate is index 2 (ie 5.5 Mbits)
  94. * - 3rd rate is index 1 (ie 2 Mbits)
  95. * - 4th rate is index 0 (ie 1 Mbits)
  96. */
  97. static const struct tx_retry_rate zd_retry_rates[] = {
  98. { /* 1 Mbits */ 1, { 0 }},
  99. { /* 2 Mbits */ 2, { 1, 0 }},
  100. { /* 5.5 Mbits */ 3, { 2, 1, 0 }},
  101. { /* 11 Mbits */ 4, { 3, 2, 1, 0 }},
  102. { /* 6 Mbits */ 5, { 4, 3, 2, 1, 0 }},
  103. { /* 9 Mbits */ 6, { 5, 4, 3, 2, 1, 0}},
  104. { /* 12 Mbits */ 5, { 6, 3, 2, 1, 0 }},
  105. { /* 18 Mbits */ 6, { 7, 6, 3, 2, 1, 0 }},
  106. { /* 24 Mbits */ 6, { 8, 6, 3, 2, 1, 0 }},
  107. { /* 36 Mbits */ 7, { 9, 8, 6, 3, 2, 1, 0 }},
  108. { /* 48 Mbits */ 8, {10, 9, 8, 6, 3, 2, 1, 0 }},
  109. { /* 54 Mbits */ 9, {11, 10, 9, 8, 6, 3, 2, 1, 0 }}
  110. };
  111. static const struct ieee80211_channel zd_channels[] = {
  112. { .center_freq = 2412, .hw_value = 1 },
  113. { .center_freq = 2417, .hw_value = 2 },
  114. { .center_freq = 2422, .hw_value = 3 },
  115. { .center_freq = 2427, .hw_value = 4 },
  116. { .center_freq = 2432, .hw_value = 5 },
  117. { .center_freq = 2437, .hw_value = 6 },
  118. { .center_freq = 2442, .hw_value = 7 },
  119. { .center_freq = 2447, .hw_value = 8 },
  120. { .center_freq = 2452, .hw_value = 9 },
  121. { .center_freq = 2457, .hw_value = 10 },
  122. { .center_freq = 2462, .hw_value = 11 },
  123. { .center_freq = 2467, .hw_value = 12 },
  124. { .center_freq = 2472, .hw_value = 13 },
  125. { .center_freq = 2484, .hw_value = 14 },
  126. };
  127. static void housekeeping_init(struct zd_mac *mac);
  128. static void housekeeping_enable(struct zd_mac *mac);
  129. static void housekeeping_disable(struct zd_mac *mac);
  130. static int zd_reg2alpha2(u8 regdomain, char *alpha2)
  131. {
  132. unsigned int i;
  133. struct zd_reg_alpha2_map *reg_map;
  134. for (i = 0; i < ARRAY_SIZE(reg_alpha2_map); i++) {
  135. reg_map = &reg_alpha2_map[i];
  136. if (regdomain == reg_map->reg) {
  137. alpha2[0] = reg_map->alpha2[0];
  138. alpha2[1] = reg_map->alpha2[1];
  139. return 0;
  140. }
  141. }
  142. return 1;
  143. }
  144. int zd_mac_preinit_hw(struct ieee80211_hw *hw)
  145. {
  146. int r;
  147. u8 addr[ETH_ALEN];
  148. struct zd_mac *mac = zd_hw_mac(hw);
  149. r = zd_chip_read_mac_addr_fw(&mac->chip, addr);
  150. if (r)
  151. return r;
  152. SET_IEEE80211_PERM_ADDR(hw, addr);
  153. return 0;
  154. }
  155. int zd_mac_init_hw(struct ieee80211_hw *hw)
  156. {
  157. int r;
  158. struct zd_mac *mac = zd_hw_mac(hw);
  159. struct zd_chip *chip = &mac->chip;
  160. char alpha2[2];
  161. u8 default_regdomain;
  162. r = zd_chip_enable_int(chip);
  163. if (r)
  164. goto out;
  165. r = zd_chip_init_hw(chip);
  166. if (r)
  167. goto disable_int;
  168. ZD_ASSERT(!irqs_disabled());
  169. r = zd_read_regdomain(chip, &default_regdomain);
  170. if (r)
  171. goto disable_int;
  172. spin_lock_irq(&mac->lock);
  173. mac->regdomain = mac->default_regdomain = default_regdomain;
  174. spin_unlock_irq(&mac->lock);
  175. /* We must inform the device that we are doing encryption/decryption in
  176. * software at the moment. */
  177. r = zd_set_encryption_type(chip, ENC_SNIFFER);
  178. if (r)
  179. goto disable_int;
  180. r = zd_reg2alpha2(mac->regdomain, alpha2);
  181. if (r)
  182. goto disable_int;
  183. r = regulatory_hint(hw->wiphy, alpha2);
  184. disable_int:
  185. zd_chip_disable_int(chip);
  186. out:
  187. return r;
  188. }
  189. void zd_mac_clear(struct zd_mac *mac)
  190. {
  191. flush_workqueue(zd_workqueue);
  192. zd_chip_clear(&mac->chip);
  193. ZD_ASSERT(!spin_is_locked(&mac->lock));
  194. ZD_MEMCLEAR(mac, sizeof(struct zd_mac));
  195. }
  196. static int set_rx_filter(struct zd_mac *mac)
  197. {
  198. unsigned long flags;
  199. u32 filter = STA_RX_FILTER;
  200. spin_lock_irqsave(&mac->lock, flags);
  201. if (mac->pass_ctrl)
  202. filter |= RX_FILTER_CTRL;
  203. spin_unlock_irqrestore(&mac->lock, flags);
  204. return zd_iowrite32(&mac->chip, CR_RX_FILTER, filter);
  205. }
  206. static int set_mc_hash(struct zd_mac *mac)
  207. {
  208. struct zd_mc_hash hash;
  209. zd_mc_clear(&hash);
  210. return zd_chip_set_multicast_hash(&mac->chip, &hash);
  211. }
  212. static int zd_op_start(struct ieee80211_hw *hw)
  213. {
  214. struct zd_mac *mac = zd_hw_mac(hw);
  215. struct zd_chip *chip = &mac->chip;
  216. struct zd_usb *usb = &chip->usb;
  217. int r;
  218. if (!usb->initialized) {
  219. r = zd_usb_init_hw(usb);
  220. if (r)
  221. goto out;
  222. }
  223. r = zd_chip_enable_int(chip);
  224. if (r < 0)
  225. goto out;
  226. r = zd_chip_set_basic_rates(chip, CR_RATES_80211B | CR_RATES_80211G);
  227. if (r < 0)
  228. goto disable_int;
  229. r = set_rx_filter(mac);
  230. if (r)
  231. goto disable_int;
  232. r = set_mc_hash(mac);
  233. if (r)
  234. goto disable_int;
  235. r = zd_chip_switch_radio_on(chip);
  236. if (r < 0)
  237. goto disable_int;
  238. r = zd_chip_enable_rxtx(chip);
  239. if (r < 0)
  240. goto disable_radio;
  241. r = zd_chip_enable_hwint(chip);
  242. if (r < 0)
  243. goto disable_rxtx;
  244. housekeeping_enable(mac);
  245. return 0;
  246. disable_rxtx:
  247. zd_chip_disable_rxtx(chip);
  248. disable_radio:
  249. zd_chip_switch_radio_off(chip);
  250. disable_int:
  251. zd_chip_disable_int(chip);
  252. out:
  253. return r;
  254. }
  255. static void zd_op_stop(struct ieee80211_hw *hw)
  256. {
  257. struct zd_mac *mac = zd_hw_mac(hw);
  258. struct zd_chip *chip = &mac->chip;
  259. struct sk_buff *skb;
  260. struct sk_buff_head *ack_wait_queue = &mac->ack_wait_queue;
  261. /* The order here deliberately is a little different from the open()
  262. * method, since we need to make sure there is no opportunity for RX
  263. * frames to be processed by mac80211 after we have stopped it.
  264. */
  265. zd_chip_disable_rxtx(chip);
  266. housekeeping_disable(mac);
  267. flush_workqueue(zd_workqueue);
  268. zd_chip_disable_hwint(chip);
  269. zd_chip_switch_radio_off(chip);
  270. zd_chip_disable_int(chip);
  271. while ((skb = skb_dequeue(ack_wait_queue)))
  272. dev_kfree_skb_any(skb);
  273. }
  274. /**
  275. * zd_mac_tx_status - reports tx status of a packet if required
  276. * @hw - a &struct ieee80211_hw pointer
  277. * @skb - a sk-buffer
  278. * @flags: extra flags to set in the TX status info
  279. * @ackssi: ACK signal strength
  280. * @success - True for successful transmission of the frame
  281. *
  282. * This information calls ieee80211_tx_status_irqsafe() if required by the
  283. * control information. It copies the control information into the status
  284. * information.
  285. *
  286. * If no status information has been requested, the skb is freed.
  287. */
  288. static void zd_mac_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
  289. int ackssi, struct tx_status *tx_status)
  290. {
  291. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  292. int i;
  293. int success = 1, retry = 1;
  294. int first_idx;
  295. const struct tx_retry_rate *retries;
  296. ieee80211_tx_info_clear_status(info);
  297. if (tx_status) {
  298. success = !tx_status->failure;
  299. retry = tx_status->retry + success;
  300. }
  301. if (success) {
  302. /* success */
  303. info->flags |= IEEE80211_TX_STAT_ACK;
  304. } else {
  305. /* failure */
  306. info->flags &= ~IEEE80211_TX_STAT_ACK;
  307. }
  308. first_idx = info->status.rates[0].idx;
  309. ZD_ASSERT(0<=first_idx && first_idx<ARRAY_SIZE(zd_retry_rates));
  310. retries = &zd_retry_rates[first_idx];
  311. ZD_ASSERT(1 <= retry && retry <= retries->count);
  312. info->status.rates[0].idx = retries->rate[0];
  313. info->status.rates[0].count = 1; // (retry > 1 ? 2 : 1);
  314. for (i=1; i<IEEE80211_TX_MAX_RATES-1 && i<retry; i++) {
  315. info->status.rates[i].idx = retries->rate[i];
  316. info->status.rates[i].count = 1; // ((i==retry-1) && success ? 1:2);
  317. }
  318. for (; i<IEEE80211_TX_MAX_RATES && i<retry; i++) {
  319. info->status.rates[i].idx = retries->rate[retry - 1];
  320. info->status.rates[i].count = 1; // (success ? 1:2);
  321. }
  322. if (i<IEEE80211_TX_MAX_RATES)
  323. info->status.rates[i].idx = -1; /* terminate */
  324. info->status.ack_signal = ackssi;
  325. ieee80211_tx_status_irqsafe(hw, skb);
  326. }
  327. /**
  328. * zd_mac_tx_failed - callback for failed frames
  329. * @dev: the mac80211 wireless device
  330. *
  331. * This function is called if a frame couldn't be successfully
  332. * transferred. The first frame from the tx queue, will be selected and
  333. * reported as error to the upper layers.
  334. */
  335. void zd_mac_tx_failed(struct urb *urb)
  336. {
  337. struct ieee80211_hw * hw = zd_usb_to_hw(urb->context);
  338. struct zd_mac *mac = zd_hw_mac(hw);
  339. struct sk_buff_head *q = &mac->ack_wait_queue;
  340. struct sk_buff *skb;
  341. struct tx_status *tx_status = (struct tx_status *)urb->transfer_buffer;
  342. unsigned long flags;
  343. int success = !tx_status->failure;
  344. int retry = tx_status->retry + success;
  345. int found = 0;
  346. int i, position = 0;
  347. q = &mac->ack_wait_queue;
  348. spin_lock_irqsave(&q->lock, flags);
  349. skb_queue_walk(q, skb) {
  350. struct ieee80211_hdr *tx_hdr;
  351. struct ieee80211_tx_info *info;
  352. int first_idx, final_idx;
  353. const struct tx_retry_rate *retries;
  354. u8 final_rate;
  355. position ++;
  356. /* if the hardware reports a failure and we had a 802.11 ACK
  357. * pending, then we skip the first skb when searching for a
  358. * matching frame */
  359. if (tx_status->failure && mac->ack_pending &&
  360. skb_queue_is_first(q, skb)) {
  361. continue;
  362. }
  363. tx_hdr = (struct ieee80211_hdr *)skb->data;
  364. /* we skip all frames not matching the reported destination */
  365. if (unlikely(memcmp(tx_hdr->addr1, tx_status->mac, ETH_ALEN))) {
  366. continue;
  367. }
  368. /* we skip all frames not matching the reported final rate */
  369. info = IEEE80211_SKB_CB(skb);
  370. first_idx = info->status.rates[0].idx;
  371. ZD_ASSERT(0<=first_idx && first_idx<ARRAY_SIZE(zd_retry_rates));
  372. retries = &zd_retry_rates[first_idx];
  373. if (retry <= 0 || retry > retries->count)
  374. continue;
  375. final_idx = retries->rate[retry - 1];
  376. final_rate = zd_rates[final_idx].hw_value;
  377. if (final_rate != tx_status->rate) {
  378. continue;
  379. }
  380. found = 1;
  381. break;
  382. }
  383. if (found) {
  384. for (i=1; i<=position; i++) {
  385. skb = __skb_dequeue(q);
  386. zd_mac_tx_status(hw, skb,
  387. mac->ack_pending ? mac->ack_signal : 0,
  388. i == position ? tx_status : NULL);
  389. mac->ack_pending = 0;
  390. }
  391. }
  392. spin_unlock_irqrestore(&q->lock, flags);
  393. }
  394. /**
  395. * zd_mac_tx_to_dev - callback for USB layer
  396. * @skb: a &sk_buff pointer
  397. * @error: error value, 0 if transmission successful
  398. *
  399. * Informs the MAC layer that the frame has successfully transferred to the
  400. * device. If an ACK is required and the transfer to the device has been
  401. * successful, the packets are put on the @ack_wait_queue with
  402. * the control set removed.
  403. */
  404. void zd_mac_tx_to_dev(struct sk_buff *skb, int error)
  405. {
  406. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  407. struct ieee80211_hw *hw = info->rate_driver_data[0];
  408. struct zd_mac *mac = zd_hw_mac(hw);
  409. ieee80211_tx_info_clear_status(info);
  410. skb_pull(skb, sizeof(struct zd_ctrlset));
  411. if (unlikely(error ||
  412. (info->flags & IEEE80211_TX_CTL_NO_ACK))) {
  413. /*
  414. * FIXME : do we need to fill in anything ?
  415. */
  416. ieee80211_tx_status_irqsafe(hw, skb);
  417. } else {
  418. struct sk_buff_head *q = &mac->ack_wait_queue;
  419. skb_queue_tail(q, skb);
  420. while (skb_queue_len(q) > ZD_MAC_MAX_ACK_WAITERS) {
  421. zd_mac_tx_status(hw, skb_dequeue(q),
  422. mac->ack_pending ? mac->ack_signal : 0,
  423. NULL);
  424. mac->ack_pending = 0;
  425. }
  426. }
  427. }
  428. static int zd_calc_tx_length_us(u8 *service, u8 zd_rate, u16 tx_length)
  429. {
  430. /* ZD_PURE_RATE() must be used to remove the modulation type flag of
  431. * the zd-rate values.
  432. */
  433. static const u8 rate_divisor[] = {
  434. [ZD_PURE_RATE(ZD_CCK_RATE_1M)] = 1,
  435. [ZD_PURE_RATE(ZD_CCK_RATE_2M)] = 2,
  436. /* Bits must be doubled. */
  437. [ZD_PURE_RATE(ZD_CCK_RATE_5_5M)] = 11,
  438. [ZD_PURE_RATE(ZD_CCK_RATE_11M)] = 11,
  439. [ZD_PURE_RATE(ZD_OFDM_RATE_6M)] = 6,
  440. [ZD_PURE_RATE(ZD_OFDM_RATE_9M)] = 9,
  441. [ZD_PURE_RATE(ZD_OFDM_RATE_12M)] = 12,
  442. [ZD_PURE_RATE(ZD_OFDM_RATE_18M)] = 18,
  443. [ZD_PURE_RATE(ZD_OFDM_RATE_24M)] = 24,
  444. [ZD_PURE_RATE(ZD_OFDM_RATE_36M)] = 36,
  445. [ZD_PURE_RATE(ZD_OFDM_RATE_48M)] = 48,
  446. [ZD_PURE_RATE(ZD_OFDM_RATE_54M)] = 54,
  447. };
  448. u32 bits = (u32)tx_length * 8;
  449. u32 divisor;
  450. divisor = rate_divisor[ZD_PURE_RATE(zd_rate)];
  451. if (divisor == 0)
  452. return -EINVAL;
  453. switch (zd_rate) {
  454. case ZD_CCK_RATE_5_5M:
  455. bits = (2*bits) + 10; /* round up to the next integer */
  456. break;
  457. case ZD_CCK_RATE_11M:
  458. if (service) {
  459. u32 t = bits % 11;
  460. *service &= ~ZD_PLCP_SERVICE_LENGTH_EXTENSION;
  461. if (0 < t && t <= 3) {
  462. *service |= ZD_PLCP_SERVICE_LENGTH_EXTENSION;
  463. }
  464. }
  465. bits += 10; /* round up to the next integer */
  466. break;
  467. }
  468. return bits/divisor;
  469. }
  470. static void cs_set_control(struct zd_mac *mac, struct zd_ctrlset *cs,
  471. struct ieee80211_hdr *header,
  472. struct ieee80211_tx_info *info)
  473. {
  474. /*
  475. * CONTROL TODO:
  476. * - if backoff needed, enable bit 0
  477. * - if burst (backoff not needed) disable bit 0
  478. */
  479. cs->control = 0;
  480. /* First fragment */
  481. if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
  482. cs->control |= ZD_CS_NEED_RANDOM_BACKOFF;
  483. /* No ACK expected (multicast, etc.) */
  484. if (info->flags & IEEE80211_TX_CTL_NO_ACK)
  485. cs->control |= ZD_CS_NO_ACK;
  486. /* PS-POLL */
  487. if (ieee80211_is_pspoll(header->frame_control))
  488. cs->control |= ZD_CS_PS_POLL_FRAME;
  489. if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
  490. cs->control |= ZD_CS_RTS;
  491. if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
  492. cs->control |= ZD_CS_SELF_CTS;
  493. /* FIXME: Management frame? */
  494. }
  495. static int zd_mac_config_beacon(struct ieee80211_hw *hw, struct sk_buff *beacon)
  496. {
  497. struct zd_mac *mac = zd_hw_mac(hw);
  498. int r;
  499. u32 tmp, j = 0;
  500. /* 4 more bytes for tail CRC */
  501. u32 full_len = beacon->len + 4;
  502. r = zd_iowrite32(&mac->chip, CR_BCN_FIFO_SEMAPHORE, 0);
  503. if (r < 0)
  504. return r;
  505. r = zd_ioread32(&mac->chip, CR_BCN_FIFO_SEMAPHORE, &tmp);
  506. if (r < 0)
  507. return r;
  508. while (tmp & 0x2) {
  509. r = zd_ioread32(&mac->chip, CR_BCN_FIFO_SEMAPHORE, &tmp);
  510. if (r < 0)
  511. return r;
  512. if ((++j % 100) == 0) {
  513. printk(KERN_ERR "CR_BCN_FIFO_SEMAPHORE not ready\n");
  514. if (j >= 500) {
  515. printk(KERN_ERR "Giving up beacon config.\n");
  516. return -ETIMEDOUT;
  517. }
  518. }
  519. msleep(1);
  520. }
  521. r = zd_iowrite32(&mac->chip, CR_BCN_FIFO, full_len - 1);
  522. if (r < 0)
  523. return r;
  524. if (zd_chip_is_zd1211b(&mac->chip)) {
  525. r = zd_iowrite32(&mac->chip, CR_BCN_LENGTH, full_len - 1);
  526. if (r < 0)
  527. return r;
  528. }
  529. for (j = 0 ; j < beacon->len; j++) {
  530. r = zd_iowrite32(&mac->chip, CR_BCN_FIFO,
  531. *((u8 *)(beacon->data + j)));
  532. if (r < 0)
  533. return r;
  534. }
  535. for (j = 0; j < 4; j++) {
  536. r = zd_iowrite32(&mac->chip, CR_BCN_FIFO, 0x0);
  537. if (r < 0)
  538. return r;
  539. }
  540. r = zd_iowrite32(&mac->chip, CR_BCN_FIFO_SEMAPHORE, 1);
  541. if (r < 0)
  542. return r;
  543. /* 802.11b/g 2.4G CCK 1Mb
  544. * 802.11a, not yet implemented, uses different values (see GPL vendor
  545. * driver)
  546. */
  547. return zd_iowrite32(&mac->chip, CR_BCN_PLCP_CFG, 0x00000400 |
  548. (full_len << 19));
  549. }
  550. static int fill_ctrlset(struct zd_mac *mac,
  551. struct sk_buff *skb)
  552. {
  553. int r;
  554. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  555. unsigned int frag_len = skb->len + FCS_LEN;
  556. unsigned int packet_length;
  557. struct ieee80211_rate *txrate;
  558. struct zd_ctrlset *cs = (struct zd_ctrlset *)
  559. skb_push(skb, sizeof(struct zd_ctrlset));
  560. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  561. ZD_ASSERT(frag_len <= 0xffff);
  562. txrate = ieee80211_get_tx_rate(mac->hw, info);
  563. cs->modulation = txrate->hw_value;
  564. if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
  565. cs->modulation = txrate->hw_value_short;
  566. cs->tx_length = cpu_to_le16(frag_len);
  567. cs_set_control(mac, cs, hdr, info);
  568. packet_length = frag_len + sizeof(struct zd_ctrlset) + 10;
  569. ZD_ASSERT(packet_length <= 0xffff);
  570. /* ZD1211B: Computing the length difference this way, gives us
  571. * flexibility to compute the packet length.
  572. */
  573. cs->packet_length = cpu_to_le16(zd_chip_is_zd1211b(&mac->chip) ?
  574. packet_length - frag_len : packet_length);
  575. /*
  576. * CURRENT LENGTH:
  577. * - transmit frame length in microseconds
  578. * - seems to be derived from frame length
  579. * - see Cal_Us_Service() in zdinlinef.h
  580. * - if macp->bTxBurstEnable is enabled, then multiply by 4
  581. * - bTxBurstEnable is never set in the vendor driver
  582. *
  583. * SERVICE:
  584. * - "for PLCP configuration"
  585. * - always 0 except in some situations at 802.11b 11M
  586. * - see line 53 of zdinlinef.h
  587. */
  588. cs->service = 0;
  589. r = zd_calc_tx_length_us(&cs->service, ZD_RATE(cs->modulation),
  590. le16_to_cpu(cs->tx_length));
  591. if (r < 0)
  592. return r;
  593. cs->current_length = cpu_to_le16(r);
  594. cs->next_frame_length = 0;
  595. return 0;
  596. }
  597. /**
  598. * zd_op_tx - transmits a network frame to the device
  599. *
  600. * @dev: mac80211 hardware device
  601. * @skb: socket buffer
  602. * @control: the control structure
  603. *
  604. * This function transmit an IEEE 802.11 network frame to the device. The
  605. * control block of the skbuff will be initialized. If necessary the incoming
  606. * mac80211 queues will be stopped.
  607. */
  608. static int zd_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  609. {
  610. struct zd_mac *mac = zd_hw_mac(hw);
  611. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  612. int r;
  613. r = fill_ctrlset(mac, skb);
  614. if (r)
  615. goto fail;
  616. info->rate_driver_data[0] = hw;
  617. r = zd_usb_tx(&mac->chip.usb, skb);
  618. if (r)
  619. goto fail;
  620. return 0;
  621. fail:
  622. dev_kfree_skb(skb);
  623. return 0;
  624. }
  625. /**
  626. * filter_ack - filters incoming packets for acknowledgements
  627. * @dev: the mac80211 device
  628. * @rx_hdr: received header
  629. * @stats: the status for the received packet
  630. *
  631. * This functions looks for ACK packets and tries to match them with the
  632. * frames in the tx queue. If a match is found the frame will be dequeued and
  633. * the upper layers is informed about the successful transmission. If
  634. * mac80211 queues have been stopped and the number of frames still to be
  635. * transmitted is low the queues will be opened again.
  636. *
  637. * Returns 1 if the frame was an ACK, 0 if it was ignored.
  638. */
  639. static int filter_ack(struct ieee80211_hw *hw, struct ieee80211_hdr *rx_hdr,
  640. struct ieee80211_rx_status *stats)
  641. {
  642. struct zd_mac *mac = zd_hw_mac(hw);
  643. struct sk_buff *skb;
  644. struct sk_buff_head *q;
  645. unsigned long flags;
  646. int found = 0;
  647. int i, position = 0;
  648. if (!ieee80211_is_ack(rx_hdr->frame_control))
  649. return 0;
  650. q = &mac->ack_wait_queue;
  651. spin_lock_irqsave(&q->lock, flags);
  652. skb_queue_walk(q, skb) {
  653. struct ieee80211_hdr *tx_hdr;
  654. position ++;
  655. if (mac->ack_pending && skb_queue_is_first(q, skb))
  656. continue;
  657. tx_hdr = (struct ieee80211_hdr *)skb->data;
  658. if (likely(!memcmp(tx_hdr->addr2, rx_hdr->addr1, ETH_ALEN)))
  659. {
  660. found = 1;
  661. break;
  662. }
  663. }
  664. if (found) {
  665. for (i=1; i<position; i++) {
  666. skb = __skb_dequeue(q);
  667. zd_mac_tx_status(hw, skb,
  668. mac->ack_pending ? mac->ack_signal : 0,
  669. NULL);
  670. mac->ack_pending = 0;
  671. }
  672. mac->ack_pending = 1;
  673. mac->ack_signal = stats->signal;
  674. }
  675. spin_unlock_irqrestore(&q->lock, flags);
  676. return 1;
  677. }
  678. int zd_mac_rx(struct ieee80211_hw *hw, const u8 *buffer, unsigned int length)
  679. {
  680. struct zd_mac *mac = zd_hw_mac(hw);
  681. struct ieee80211_rx_status stats;
  682. const struct rx_status *status;
  683. struct sk_buff *skb;
  684. int bad_frame = 0;
  685. __le16 fc;
  686. int need_padding;
  687. int i;
  688. u8 rate;
  689. if (length < ZD_PLCP_HEADER_SIZE + 10 /* IEEE80211_1ADDR_LEN */ +
  690. FCS_LEN + sizeof(struct rx_status))
  691. return -EINVAL;
  692. memset(&stats, 0, sizeof(stats));
  693. /* Note about pass_failed_fcs and pass_ctrl access below:
  694. * mac locking intentionally omitted here, as this is the only unlocked
  695. * reader and the only writer is configure_filter. Plus, if there were
  696. * any races accessing these variables, it wouldn't really matter.
  697. * If mac80211 ever provides a way for us to access filter flags
  698. * from outside configure_filter, we could improve on this. Also, this
  699. * situation may change once we implement some kind of DMA-into-skb
  700. * RX path. */
  701. /* Caller has to ensure that length >= sizeof(struct rx_status). */
  702. status = (struct rx_status *)
  703. (buffer + (length - sizeof(struct rx_status)));
  704. if (status->frame_status & ZD_RX_ERROR) {
  705. if (mac->pass_failed_fcs &&
  706. (status->frame_status & ZD_RX_CRC32_ERROR)) {
  707. stats.flag |= RX_FLAG_FAILED_FCS_CRC;
  708. bad_frame = 1;
  709. } else {
  710. return -EINVAL;
  711. }
  712. }
  713. stats.freq = zd_channels[_zd_chip_get_channel(&mac->chip) - 1].center_freq;
  714. stats.band = IEEE80211_BAND_2GHZ;
  715. stats.signal = status->signal_strength;
  716. rate = zd_rx_rate(buffer, status);
  717. /* todo: return index in the big switches in zd_rx_rate instead */
  718. for (i = 0; i < mac->band.n_bitrates; i++)
  719. if (rate == mac->band.bitrates[i].hw_value)
  720. stats.rate_idx = i;
  721. length -= ZD_PLCP_HEADER_SIZE + sizeof(struct rx_status);
  722. buffer += ZD_PLCP_HEADER_SIZE;
  723. /* Except for bad frames, filter each frame to see if it is an ACK, in
  724. * which case our internal TX tracking is updated. Normally we then
  725. * bail here as there's no need to pass ACKs on up to the stack, but
  726. * there is also the case where the stack has requested us to pass
  727. * control frames on up (pass_ctrl) which we must consider. */
  728. if (!bad_frame &&
  729. filter_ack(hw, (struct ieee80211_hdr *)buffer, &stats)
  730. && !mac->pass_ctrl)
  731. return 0;
  732. fc = get_unaligned((__le16*)buffer);
  733. need_padding = ieee80211_is_data_qos(fc) ^ ieee80211_has_a4(fc);
  734. skb = dev_alloc_skb(length + (need_padding ? 2 : 0));
  735. if (skb == NULL)
  736. return -ENOMEM;
  737. if (need_padding) {
  738. /* Make sure the the payload data is 4 byte aligned. */
  739. skb_reserve(skb, 2);
  740. }
  741. /* FIXME : could we avoid this big memcpy ? */
  742. memcpy(skb_put(skb, length), buffer, length);
  743. memcpy(IEEE80211_SKB_RXCB(skb), &stats, sizeof(stats));
  744. ieee80211_rx_irqsafe(hw, skb);
  745. return 0;
  746. }
  747. static int zd_op_add_interface(struct ieee80211_hw *hw,
  748. struct ieee80211_vif *vif)
  749. {
  750. struct zd_mac *mac = zd_hw_mac(hw);
  751. /* using NL80211_IFTYPE_UNSPECIFIED to indicate no mode selected */
  752. if (mac->type != NL80211_IFTYPE_UNSPECIFIED)
  753. return -EOPNOTSUPP;
  754. switch (vif->type) {
  755. case NL80211_IFTYPE_MONITOR:
  756. case NL80211_IFTYPE_MESH_POINT:
  757. case NL80211_IFTYPE_STATION:
  758. case NL80211_IFTYPE_ADHOC:
  759. mac->type = vif->type;
  760. break;
  761. default:
  762. return -EOPNOTSUPP;
  763. }
  764. return zd_write_mac_addr(&mac->chip, vif->addr);
  765. }
  766. static void zd_op_remove_interface(struct ieee80211_hw *hw,
  767. struct ieee80211_vif *vif)
  768. {
  769. struct zd_mac *mac = zd_hw_mac(hw);
  770. mac->type = NL80211_IFTYPE_UNSPECIFIED;
  771. zd_set_beacon_interval(&mac->chip, 0);
  772. zd_write_mac_addr(&mac->chip, NULL);
  773. }
  774. static int zd_op_config(struct ieee80211_hw *hw, u32 changed)
  775. {
  776. struct zd_mac *mac = zd_hw_mac(hw);
  777. struct ieee80211_conf *conf = &hw->conf;
  778. return zd_chip_set_channel(&mac->chip, conf->channel->hw_value);
  779. }
  780. static void zd_process_intr(struct work_struct *work)
  781. {
  782. u16 int_status;
  783. struct zd_mac *mac = container_of(work, struct zd_mac, process_intr);
  784. int_status = le16_to_cpu(*(__le16 *)(mac->intr_buffer+4));
  785. if (int_status & INT_CFG_NEXT_BCN)
  786. dev_dbg_f_limit(zd_mac_dev(mac), "INT_CFG_NEXT_BCN\n");
  787. else
  788. dev_dbg_f(zd_mac_dev(mac), "Unsupported interrupt\n");
  789. zd_chip_enable_hwint(&mac->chip);
  790. }
  791. static void set_multicast_hash_handler(struct work_struct *work)
  792. {
  793. struct zd_mac *mac =
  794. container_of(work, struct zd_mac, set_multicast_hash_work);
  795. struct zd_mc_hash hash;
  796. spin_lock_irq(&mac->lock);
  797. hash = mac->multicast_hash;
  798. spin_unlock_irq(&mac->lock);
  799. zd_chip_set_multicast_hash(&mac->chip, &hash);
  800. }
  801. static void set_rx_filter_handler(struct work_struct *work)
  802. {
  803. struct zd_mac *mac =
  804. container_of(work, struct zd_mac, set_rx_filter_work);
  805. int r;
  806. dev_dbg_f(zd_mac_dev(mac), "\n");
  807. r = set_rx_filter(mac);
  808. if (r)
  809. dev_err(zd_mac_dev(mac), "set_rx_filter_handler error %d\n", r);
  810. }
  811. static u64 zd_op_prepare_multicast(struct ieee80211_hw *hw,
  812. int mc_count, struct dev_addr_list *mclist)
  813. {
  814. struct zd_mac *mac = zd_hw_mac(hw);
  815. struct zd_mc_hash hash;
  816. int i;
  817. zd_mc_clear(&hash);
  818. for (i = 0; i < mc_count; i++) {
  819. if (!mclist)
  820. break;
  821. dev_dbg_f(zd_mac_dev(mac), "mc addr %pM\n", mclist->dmi_addr);
  822. zd_mc_add_addr(&hash, mclist->dmi_addr);
  823. mclist = mclist->next;
  824. }
  825. return hash.low | ((u64)hash.high << 32);
  826. }
  827. #define SUPPORTED_FIF_FLAGS \
  828. (FIF_PROMISC_IN_BSS | FIF_ALLMULTI | FIF_FCSFAIL | FIF_CONTROL | \
  829. FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)
  830. static void zd_op_configure_filter(struct ieee80211_hw *hw,
  831. unsigned int changed_flags,
  832. unsigned int *new_flags,
  833. u64 multicast)
  834. {
  835. struct zd_mc_hash hash = {
  836. .low = multicast,
  837. .high = multicast >> 32,
  838. };
  839. struct zd_mac *mac = zd_hw_mac(hw);
  840. unsigned long flags;
  841. /* Only deal with supported flags */
  842. changed_flags &= SUPPORTED_FIF_FLAGS;
  843. *new_flags &= SUPPORTED_FIF_FLAGS;
  844. /*
  845. * If multicast parameter (as returned by zd_op_prepare_multicast)
  846. * has changed, no bit in changed_flags is set. To handle this
  847. * situation, we do not return if changed_flags is 0. If we do so,
  848. * we will have some issue with IPv6 which uses multicast for link
  849. * layer address resolution.
  850. */
  851. if (*new_flags & (FIF_PROMISC_IN_BSS | FIF_ALLMULTI))
  852. zd_mc_add_all(&hash);
  853. spin_lock_irqsave(&mac->lock, flags);
  854. mac->pass_failed_fcs = !!(*new_flags & FIF_FCSFAIL);
  855. mac->pass_ctrl = !!(*new_flags & FIF_CONTROL);
  856. mac->multicast_hash = hash;
  857. spin_unlock_irqrestore(&mac->lock, flags);
  858. /* XXX: these can be called here now, can sleep now! */
  859. queue_work(zd_workqueue, &mac->set_multicast_hash_work);
  860. if (changed_flags & FIF_CONTROL)
  861. queue_work(zd_workqueue, &mac->set_rx_filter_work);
  862. /* no handling required for FIF_OTHER_BSS as we don't currently
  863. * do BSSID filtering */
  864. /* FIXME: in future it would be nice to enable the probe response
  865. * filter (so that the driver doesn't see them) until
  866. * FIF_BCN_PRBRESP_PROMISC is set. however due to atomicity here, we'd
  867. * have to schedule work to enable prbresp reception, which might
  868. * happen too late. For now we'll just listen and forward them all the
  869. * time. */
  870. }
  871. static void set_rts_cts_work(struct work_struct *work)
  872. {
  873. struct zd_mac *mac =
  874. container_of(work, struct zd_mac, set_rts_cts_work);
  875. unsigned long flags;
  876. unsigned int short_preamble;
  877. mutex_lock(&mac->chip.mutex);
  878. spin_lock_irqsave(&mac->lock, flags);
  879. mac->updating_rts_rate = 0;
  880. short_preamble = mac->short_preamble;
  881. spin_unlock_irqrestore(&mac->lock, flags);
  882. zd_chip_set_rts_cts_rate_locked(&mac->chip, short_preamble);
  883. mutex_unlock(&mac->chip.mutex);
  884. }
  885. static void zd_op_bss_info_changed(struct ieee80211_hw *hw,
  886. struct ieee80211_vif *vif,
  887. struct ieee80211_bss_conf *bss_conf,
  888. u32 changes)
  889. {
  890. struct zd_mac *mac = zd_hw_mac(hw);
  891. unsigned long flags;
  892. int associated;
  893. dev_dbg_f(zd_mac_dev(mac), "changes: %x\n", changes);
  894. if (mac->type == NL80211_IFTYPE_MESH_POINT ||
  895. mac->type == NL80211_IFTYPE_ADHOC) {
  896. associated = true;
  897. if (changes & BSS_CHANGED_BEACON) {
  898. struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
  899. if (beacon) {
  900. zd_mac_config_beacon(hw, beacon);
  901. kfree_skb(beacon);
  902. }
  903. }
  904. if (changes & BSS_CHANGED_BEACON_ENABLED) {
  905. u32 interval;
  906. if (bss_conf->enable_beacon)
  907. interval = BCN_MODE_IBSS |
  908. bss_conf->beacon_int;
  909. else
  910. interval = 0;
  911. zd_set_beacon_interval(&mac->chip, interval);
  912. }
  913. } else
  914. associated = is_valid_ether_addr(bss_conf->bssid);
  915. spin_lock_irq(&mac->lock);
  916. mac->associated = associated;
  917. spin_unlock_irq(&mac->lock);
  918. /* TODO: do hardware bssid filtering */
  919. if (changes & BSS_CHANGED_ERP_PREAMBLE) {
  920. spin_lock_irqsave(&mac->lock, flags);
  921. mac->short_preamble = bss_conf->use_short_preamble;
  922. if (!mac->updating_rts_rate) {
  923. mac->updating_rts_rate = 1;
  924. /* FIXME: should disable TX here, until work has
  925. * completed and RTS_CTS reg is updated */
  926. queue_work(zd_workqueue, &mac->set_rts_cts_work);
  927. }
  928. spin_unlock_irqrestore(&mac->lock, flags);
  929. }
  930. }
  931. static u64 zd_op_get_tsf(struct ieee80211_hw *hw)
  932. {
  933. struct zd_mac *mac = zd_hw_mac(hw);
  934. return zd_chip_get_tsf(&mac->chip);
  935. }
  936. static const struct ieee80211_ops zd_ops = {
  937. .tx = zd_op_tx,
  938. .start = zd_op_start,
  939. .stop = zd_op_stop,
  940. .add_interface = zd_op_add_interface,
  941. .remove_interface = zd_op_remove_interface,
  942. .config = zd_op_config,
  943. .prepare_multicast = zd_op_prepare_multicast,
  944. .configure_filter = zd_op_configure_filter,
  945. .bss_info_changed = zd_op_bss_info_changed,
  946. .get_tsf = zd_op_get_tsf,
  947. };
  948. struct ieee80211_hw *zd_mac_alloc_hw(struct usb_interface *intf)
  949. {
  950. struct zd_mac *mac;
  951. struct ieee80211_hw *hw;
  952. hw = ieee80211_alloc_hw(sizeof(struct zd_mac), &zd_ops);
  953. if (!hw) {
  954. dev_dbg_f(&intf->dev, "out of memory\n");
  955. return NULL;
  956. }
  957. mac = zd_hw_mac(hw);
  958. memset(mac, 0, sizeof(*mac));
  959. spin_lock_init(&mac->lock);
  960. mac->hw = hw;
  961. mac->type = NL80211_IFTYPE_UNSPECIFIED;
  962. memcpy(mac->channels, zd_channels, sizeof(zd_channels));
  963. memcpy(mac->rates, zd_rates, sizeof(zd_rates));
  964. mac->band.n_bitrates = ARRAY_SIZE(zd_rates);
  965. mac->band.bitrates = mac->rates;
  966. mac->band.n_channels = ARRAY_SIZE(zd_channels);
  967. mac->band.channels = mac->channels;
  968. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &mac->band;
  969. hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
  970. IEEE80211_HW_SIGNAL_UNSPEC;
  971. hw->wiphy->interface_modes =
  972. BIT(NL80211_IFTYPE_MESH_POINT) |
  973. BIT(NL80211_IFTYPE_STATION) |
  974. BIT(NL80211_IFTYPE_ADHOC);
  975. hw->max_signal = 100;
  976. hw->queues = 1;
  977. hw->extra_tx_headroom = sizeof(struct zd_ctrlset);
  978. /*
  979. * Tell mac80211 that we support multi rate retries
  980. */
  981. hw->max_rates = IEEE80211_TX_MAX_RATES;
  982. hw->max_rate_tries = 18; /* 9 rates * 2 retries/rate */
  983. skb_queue_head_init(&mac->ack_wait_queue);
  984. mac->ack_pending = 0;
  985. zd_chip_init(&mac->chip, hw, intf);
  986. housekeeping_init(mac);
  987. INIT_WORK(&mac->set_multicast_hash_work, set_multicast_hash_handler);
  988. INIT_WORK(&mac->set_rts_cts_work, set_rts_cts_work);
  989. INIT_WORK(&mac->set_rx_filter_work, set_rx_filter_handler);
  990. INIT_WORK(&mac->process_intr, zd_process_intr);
  991. SET_IEEE80211_DEV(hw, &intf->dev);
  992. return hw;
  993. }
  994. #define LINK_LED_WORK_DELAY HZ
  995. static void link_led_handler(struct work_struct *work)
  996. {
  997. struct zd_mac *mac =
  998. container_of(work, struct zd_mac, housekeeping.link_led_work.work);
  999. struct zd_chip *chip = &mac->chip;
  1000. int is_associated;
  1001. int r;
  1002. spin_lock_irq(&mac->lock);
  1003. is_associated = mac->associated;
  1004. spin_unlock_irq(&mac->lock);
  1005. r = zd_chip_control_leds(chip,
  1006. is_associated ? ZD_LED_ASSOCIATED : ZD_LED_SCANNING);
  1007. if (r)
  1008. dev_dbg_f(zd_mac_dev(mac), "zd_chip_control_leds error %d\n", r);
  1009. queue_delayed_work(zd_workqueue, &mac->housekeeping.link_led_work,
  1010. LINK_LED_WORK_DELAY);
  1011. }
  1012. static void housekeeping_init(struct zd_mac *mac)
  1013. {
  1014. INIT_DELAYED_WORK(&mac->housekeeping.link_led_work, link_led_handler);
  1015. }
  1016. static void housekeeping_enable(struct zd_mac *mac)
  1017. {
  1018. dev_dbg_f(zd_mac_dev(mac), "\n");
  1019. queue_delayed_work(zd_workqueue, &mac->housekeeping.link_led_work,
  1020. 0);
  1021. }
  1022. static void housekeeping_disable(struct zd_mac *mac)
  1023. {
  1024. dev_dbg_f(zd_mac_dev(mac), "\n");
  1025. cancel_rearming_delayed_workqueue(zd_workqueue,
  1026. &mac->housekeeping.link_led_work);
  1027. zd_chip_control_leds(&mac->chip, ZD_LED_OFF);
  1028. }