You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ath9k_init.c 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /*
  2. * Copyright (c) 2008-2011 Atheros Communications Inc.
  3. *
  4. * Modified for iPXE by Scott K Logan <logans@cottsay.net> July 2011
  5. * Original from Linux kernel 3.0.1
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for any
  8. * purpose with or without fee is hereby granted, provided that the above
  9. * copyright notice and this permission notice appear in all copies.
  10. *
  11. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  12. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  13. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  14. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  15. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  16. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  17. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. FILE_LICENCE ( BSD2 );
  20. #include <ipxe/malloc.h>
  21. #include <ipxe/pci_io.h>
  22. #include <ipxe/pci.h>
  23. #include "ath9k.h"
  24. int is_ath9k_unloaded;
  25. /* We use the hw_value as an index into our private channel structure */
  26. #define CHAN2G(_freq, _idx) { \
  27. .band = NET80211_BAND_2GHZ, \
  28. .center_freq = (_freq), \
  29. .hw_value = (_idx), \
  30. .maxpower = 20, \
  31. }
  32. #define CHAN5G(_freq, _idx) { \
  33. .band = NET80211_BAND_5GHZ, \
  34. .center_freq = (_freq), \
  35. .hw_value = (_idx), \
  36. .maxpower = 20, \
  37. }
  38. /* Some 2 GHz radios are actually tunable on 2312-2732
  39. * on 5 MHz steps, we support the channels which we know
  40. * we have calibration data for all cards though to make
  41. * this static */
  42. static const struct net80211_channel ath9k_2ghz_chantable[] = {
  43. CHAN2G(2412, 0), /* Channel 1 */
  44. CHAN2G(2417, 1), /* Channel 2 */
  45. CHAN2G(2422, 2), /* Channel 3 */
  46. CHAN2G(2427, 3), /* Channel 4 */
  47. CHAN2G(2432, 4), /* Channel 5 */
  48. CHAN2G(2437, 5), /* Channel 6 */
  49. CHAN2G(2442, 6), /* Channel 7 */
  50. CHAN2G(2447, 7), /* Channel 8 */
  51. CHAN2G(2452, 8), /* Channel 9 */
  52. CHAN2G(2457, 9), /* Channel 10 */
  53. CHAN2G(2462, 10), /* Channel 11 */
  54. CHAN2G(2467, 11), /* Channel 12 */
  55. CHAN2G(2472, 12), /* Channel 13 */
  56. CHAN2G(2484, 13), /* Channel 14 */
  57. };
  58. /* Some 5 GHz radios are actually tunable on XXXX-YYYY
  59. * on 5 MHz steps, we support the channels which we know
  60. * we have calibration data for all cards though to make
  61. * this static */
  62. static const struct net80211_channel ath9k_5ghz_chantable[] = {
  63. /* _We_ call this UNII 1 */
  64. CHAN5G(5180, 14), /* Channel 36 */
  65. CHAN5G(5200, 15), /* Channel 40 */
  66. CHAN5G(5220, 16), /* Channel 44 */
  67. CHAN5G(5240, 17), /* Channel 48 */
  68. /* _We_ call this UNII 2 */
  69. CHAN5G(5260, 18), /* Channel 52 */
  70. CHAN5G(5280, 19), /* Channel 56 */
  71. CHAN5G(5300, 20), /* Channel 60 */
  72. CHAN5G(5320, 21), /* Channel 64 */
  73. /* _We_ call this "Middle band" */
  74. CHAN5G(5500, 22), /* Channel 100 */
  75. CHAN5G(5520, 23), /* Channel 104 */
  76. CHAN5G(5540, 24), /* Channel 108 */
  77. CHAN5G(5560, 25), /* Channel 112 */
  78. CHAN5G(5580, 26), /* Channel 116 */
  79. CHAN5G(5600, 27), /* Channel 120 */
  80. CHAN5G(5620, 28), /* Channel 124 */
  81. CHAN5G(5640, 29), /* Channel 128 */
  82. CHAN5G(5660, 30), /* Channel 132 */
  83. CHAN5G(5680, 31), /* Channel 136 */
  84. CHAN5G(5700, 32), /* Channel 140 */
  85. /* _We_ call this UNII 3 */
  86. CHAN5G(5745, 33), /* Channel 149 */
  87. CHAN5G(5765, 34), /* Channel 153 */
  88. CHAN5G(5785, 35), /* Channel 157 */
  89. CHAN5G(5805, 36), /* Channel 161 */
  90. CHAN5G(5825, 37), /* Channel 165 */
  91. };
  92. /* Atheros hardware rate code addition for short premble */
  93. #define SHPCHECK(__hw_rate, __flags) \
  94. ((__flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) ? (__hw_rate | 0x04 ) : 0)
  95. #define RATE(_bitrate, _hw_rate, _flags) { \
  96. .bitrate = (_bitrate), \
  97. .flags = (_flags), \
  98. .hw_value = (_hw_rate), \
  99. .hw_value_short = (SHPCHECK(_hw_rate, _flags)) \
  100. }
  101. static struct ath9k_legacy_rate ath9k_legacy_rates[] = {
  102. RATE(10, 0x1b, 0),
  103. RATE(20, 0x1a, IEEE80211_TX_RC_USE_SHORT_PREAMBLE),
  104. RATE(55, 0x19, IEEE80211_TX_RC_USE_SHORT_PREAMBLE),
  105. RATE(110, 0x18, IEEE80211_TX_RC_USE_SHORT_PREAMBLE),
  106. RATE(60, 0x0b, 0),
  107. RATE(90, 0x0f, 0),
  108. RATE(120, 0x0a, 0),
  109. RATE(180, 0x0e, 0),
  110. RATE(240, 0x09, 0),
  111. RATE(360, 0x0d, 0),
  112. RATE(480, 0x08, 0),
  113. RATE(540, 0x0c, 0),
  114. };
  115. static void ath9k_deinit_softc(struct ath_softc *sc);
  116. /*
  117. * Read and write, they both share the same lock. We do this to serialize
  118. * reads and writes on Atheros 802.11n PCI devices only. This is required
  119. * as the FIFO on these devices can only accept sanely 2 requests.
  120. */
  121. static void ath9k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
  122. {
  123. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  124. struct ath_common *common = ath9k_hw_common(ah);
  125. struct ath_softc *sc = (struct ath_softc *) common->priv;
  126. writel(val, sc->mem + reg_offset);
  127. }
  128. static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset)
  129. {
  130. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  131. struct ath_common *common = ath9k_hw_common(ah);
  132. struct ath_softc *sc = (struct ath_softc *) common->priv;
  133. u32 val;
  134. val = readl(sc->mem + reg_offset);
  135. return val;
  136. }
  137. static unsigned int ath9k_reg_rmw(void *hw_priv, u32 reg_offset, u32 set, u32 clr)
  138. {
  139. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  140. struct ath_common *common = ath9k_hw_common(ah);
  141. struct ath_softc *sc = (struct ath_softc *) common->priv;
  142. u32 val;
  143. val = readl(sc->mem + reg_offset);
  144. val &= ~clr;
  145. val |= set;
  146. writel(val, sc->mem + reg_offset);
  147. return val;
  148. }
  149. /**************************/
  150. /* Initialization */
  151. /**************************/
  152. /*
  153. * This function will allocate both the DMA descriptor structure, and the
  154. * buffers it contains. These are used to contain the descriptors used
  155. * by the system.
  156. */
  157. int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
  158. struct list_head *head, const char *name,
  159. int nbuf, int ndesc, int is_tx)
  160. {
  161. #define DS2PHYS(_dd, _ds) \
  162. ((_dd)->dd_desc_paddr + ((char *)(_ds) - (char *)(_dd)->dd_desc))
  163. #define ATH_DESC_4KB_BOUND_CHECK(_daddr) ((((_daddr) & 0xFFF) > 0xF9F) ? 1 : 0)
  164. u8 *ds;
  165. struct ath_buf *bf;
  166. int i, bsize, error, desc_len;
  167. DBG2("ath9k: %s DMA: %d buffers %d desc/buf\n",
  168. name, nbuf, ndesc);
  169. INIT_LIST_HEAD(head);
  170. if (is_tx)
  171. desc_len = sc->sc_ah->caps.tx_desc_len;
  172. else
  173. desc_len = sizeof(struct ath_desc);
  174. /* ath_desc must be a multiple of DWORDs */
  175. if ((desc_len % 4) != 0) {
  176. DBG("ath9k: ath_desc not DWORD aligned\n");
  177. error = -ENOMEM;
  178. goto fail;
  179. }
  180. dd->dd_desc_len = desc_len * nbuf * ndesc;
  181. /*
  182. * Need additional DMA memory because we can't use
  183. * descriptors that cross the 4K page boundary.
  184. * However, iPXE only utilizes 16 buffers, which
  185. * will never make up more than half of one page,
  186. * so we will only ever skip 1 descriptor, if that.
  187. */
  188. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  189. u32 ndesc_skipped = 1;
  190. u32 dma_len;
  191. dma_len = ndesc_skipped * desc_len;
  192. dd->dd_desc_len += dma_len;
  193. }
  194. /* allocate descriptors */
  195. dd->dd_desc = malloc_dma(dd->dd_desc_len, 16);
  196. if (dd->dd_desc == NULL) {
  197. error = -ENOMEM;
  198. goto fail;
  199. }
  200. dd->dd_desc_paddr = virt_to_bus(dd->dd_desc);
  201. ds = (u8 *) dd->dd_desc;
  202. DBG2("ath9k: %s DMA map: %p (%d) -> %llx (%d)\n",
  203. name, ds, (u32) dd->dd_desc_len,
  204. ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
  205. /* allocate buffers */
  206. bsize = sizeof(struct ath_buf) * nbuf;
  207. bf = zalloc(bsize);
  208. if (bf == NULL) {
  209. error = -ENOMEM;
  210. goto fail2;
  211. }
  212. dd->dd_bufptr = bf;
  213. for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
  214. bf->bf_desc = ds;
  215. bf->bf_daddr = DS2PHYS(dd, ds);
  216. if (!(sc->sc_ah->caps.hw_caps &
  217. ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  218. /*
  219. * Skip descriptor addresses which can cause 4KB
  220. * boundary crossing (addr + length) with a 32 dword
  221. * descriptor fetch.
  222. */
  223. while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
  224. ds += (desc_len * ndesc);
  225. bf->bf_desc = ds;
  226. bf->bf_daddr = DS2PHYS(dd, ds);
  227. }
  228. }
  229. list_add_tail(&bf->list, head);
  230. }
  231. return 0;
  232. fail2:
  233. free_dma(dd->dd_desc, dd->dd_desc_len);
  234. fail:
  235. memset(dd, 0, sizeof(*dd));
  236. return error;
  237. #undef ATH_DESC_4KB_BOUND_CHECK
  238. #undef DS2PHYS
  239. }
  240. void ath9k_init_crypto(struct ath_softc *sc)
  241. {
  242. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  243. unsigned int i = 0;
  244. /* Get the hardware key cache size. */
  245. common->keymax = AR_KEYTABLE_SIZE;
  246. /*
  247. * Reset the key cache since some parts do not
  248. * reset the contents on initial power up.
  249. */
  250. for (i = 0; i < common->keymax; i++)
  251. ath_hw_keyreset(common, (u16) i);
  252. /*
  253. * Check whether the separate key cache entries
  254. * are required to handle both tx+rx MIC keys.
  255. * With split mic keys the number of stations is limited
  256. * to 27 otherwise 59.
  257. */
  258. if (sc->sc_ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA)
  259. common->crypt_caps |= ATH_CRYPT_CAP_MIC_COMBINED;
  260. }
  261. static int ath9k_init_queues(struct ath_softc *sc)
  262. {
  263. int i = 0;
  264. for (i = 0; i < WME_NUM_AC; i++) {
  265. sc->tx.txq_map[i] = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, i);
  266. sc->tx.txq_map[i]->mac80211_qnum = i;
  267. }
  268. return 0;
  269. }
  270. static int ath9k_init_channels_rates(struct ath_softc *sc)
  271. {
  272. unsigned int i;
  273. memcpy(&sc->rates, ath9k_legacy_rates, sizeof(ath9k_legacy_rates));
  274. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ) {
  275. memcpy(&sc->hwinfo->channels[sc->hwinfo->nr_channels], ath9k_2ghz_chantable, sizeof(ath9k_2ghz_chantable));
  276. sc->hwinfo->nr_channels += ARRAY_SIZE(ath9k_2ghz_chantable);
  277. for (i = 0; i < ARRAY_SIZE(ath9k_legacy_rates); i++)
  278. sc->hwinfo->rates[NET80211_BAND_2GHZ][i] = ath9k_legacy_rates[i].bitrate;
  279. sc->hwinfo->nr_rates[NET80211_BAND_2GHZ] = ARRAY_SIZE(ath9k_legacy_rates);
  280. }
  281. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ) {
  282. memcpy(&sc->hwinfo->channels[sc->hwinfo->nr_channels], ath9k_5ghz_chantable, sizeof(ath9k_5ghz_chantable));
  283. sc->hwinfo->nr_channels += ARRAY_SIZE(ath9k_5ghz_chantable);
  284. for (i = 4; i < ARRAY_SIZE(ath9k_legacy_rates); i++)
  285. sc->hwinfo->rates[NET80211_BAND_5GHZ][i - 4] = ath9k_legacy_rates[i].bitrate;
  286. sc->hwinfo->nr_rates[NET80211_BAND_5GHZ] = ARRAY_SIZE(ath9k_legacy_rates) - 4;
  287. }
  288. return 0;
  289. }
  290. static void ath9k_init_misc(struct ath_softc *sc)
  291. {
  292. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  293. common->ani.timer = 0;
  294. sc->config.txpowlimit = ATH_TXPOWER_MAX;
  295. common->tx_chainmask = sc->sc_ah->caps.tx_chainmask;
  296. common->rx_chainmask = sc->sc_ah->caps.rx_chainmask;
  297. ath9k_hw_set_diversity(sc->sc_ah, 1);
  298. sc->rx.defant = ath9k_hw_getdefantenna(sc->sc_ah);
  299. memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
  300. }
  301. static int ath9k_init_softc(u16 devid, struct ath_softc *sc, u16 subsysid,
  302. const struct ath_bus_ops *bus_ops)
  303. {
  304. struct ath_hw *ah = NULL;
  305. struct ath_common *common;
  306. int ret = 0, i;
  307. int csz = 0;
  308. ah = zalloc(sizeof(struct ath_hw));
  309. if (!ah)
  310. return -ENOMEM;
  311. ah->dev = sc->dev;
  312. ah->hw_version.devid = devid;
  313. ah->hw_version.subsysid = subsysid;
  314. ah->reg_ops.read = ath9k_ioread32;
  315. ah->reg_ops.write = ath9k_iowrite32;
  316. ah->reg_ops.rmw = ath9k_reg_rmw;
  317. sc->sc_ah = ah;
  318. sc->hwinfo = zalloc(sizeof(*sc->hwinfo));
  319. if (!sc->hwinfo) {
  320. DBG("ath9k: cannot allocate 802.11 hardware info structure\n");
  321. return -ENOMEM;
  322. }
  323. ah->ah_flags |= AH_USE_EEPROM;
  324. sc->sc_ah->led_pin = -1;
  325. common = ath9k_hw_common(ah);
  326. common->ops = &ah->reg_ops;
  327. common->bus_ops = bus_ops;
  328. common->ah = ah;
  329. common->dev = sc->dev;
  330. common->priv = sc;
  331. sc->intr_tq = ath9k_tasklet;
  332. /*
  333. * Cache line size is used to size and align various
  334. * structures used to communicate with the hardware.
  335. */
  336. ath_read_cachesize(common, &csz);
  337. common->cachelsz = csz << 2; /* convert to bytes */
  338. /* Initializes the hardware for all supported chipsets */
  339. ret = ath9k_hw_init(ah);
  340. if (ret)
  341. goto err_hw;
  342. memcpy(sc->hwinfo->hwaddr, common->macaddr, ETH_ALEN);
  343. ret = ath9k_init_queues(sc);
  344. if (ret)
  345. goto err_queues;
  346. ret = ath9k_init_channels_rates(sc);
  347. if (ret)
  348. goto err_btcoex;
  349. ath9k_init_crypto(sc);
  350. ath9k_init_misc(sc);
  351. return 0;
  352. err_btcoex:
  353. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  354. if (ATH_TXQ_SETUP(sc, i))
  355. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  356. err_queues:
  357. ath9k_hw_deinit(ah);
  358. err_hw:
  359. free(sc->hwinfo);
  360. sc->hwinfo = NULL;
  361. free(ah);
  362. sc->sc_ah = NULL;
  363. return ret;
  364. }
  365. static void ath9k_init_band_txpower(struct ath_softc *sc, int band)
  366. {
  367. struct net80211_channel *chan;
  368. struct ath_hw *ah = sc->sc_ah;
  369. struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
  370. int i;
  371. for (i = 0; i < sc->hwinfo->nr_channels; i++) {
  372. chan = &sc->hwinfo->channels[i];
  373. if(chan->band != band)
  374. continue;
  375. ah->curchan = &ah->channels[chan->hw_value];
  376. ath9k_hw_set_txpowerlimit(ah, MAX_RATE_POWER, 1);
  377. chan->maxpower = reg->max_power_level / 2;
  378. }
  379. }
  380. static void ath9k_init_txpower_limits(struct ath_softc *sc)
  381. {
  382. struct ath_hw *ah = sc->sc_ah;
  383. struct ath9k_channel *curchan = ah->curchan;
  384. if (ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  385. ath9k_init_band_txpower(sc, NET80211_BAND_2GHZ);
  386. if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  387. ath9k_init_band_txpower(sc, NET80211_BAND_5GHZ);
  388. ah->curchan = curchan;
  389. }
  390. void ath9k_set_hw_capab(struct ath_softc *sc, struct net80211_device *dev __unused)
  391. {
  392. sc->hwinfo->flags = NET80211_HW_RX_HAS_FCS;
  393. sc->hwinfo->signal_type = NET80211_SIGNAL_DB;
  394. sc->hwinfo->signal_max = 40; /* 35dB should give perfect 54Mbps */
  395. sc->hwinfo->channel_change_time = 5000;
  396. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  397. {
  398. sc->hwinfo->bands |= NET80211_BAND_BIT_2GHZ;
  399. sc->hwinfo->modes |= NET80211_MODE_B | NET80211_MODE_G;
  400. }
  401. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  402. {
  403. sc->hwinfo->bands |= NET80211_BAND_BIT_5GHZ;
  404. sc->hwinfo->modes |= NET80211_MODE_A;
  405. }
  406. }
  407. int ath9k_init_device(u16 devid, struct ath_softc *sc, u16 subsysid,
  408. const struct ath_bus_ops *bus_ops)
  409. {
  410. struct net80211_device *dev = sc->dev;
  411. /*struct ath_common *common;
  412. struct ath_hw *ah;*/
  413. int error = 0;
  414. /*struct ath_regulatory *reg;*/
  415. /* Bring up device */
  416. error = ath9k_init_softc(devid, sc, subsysid, bus_ops);
  417. if (error != 0)
  418. goto error_init;
  419. /*ah = sc->sc_ah;
  420. common = ath9k_hw_common(ah);*/
  421. ath9k_set_hw_capab(sc, dev);
  422. /* TODO Cottsay: reg */
  423. /* Initialize regulatory */
  424. /*error = ath_regd_init(&common->regulatory, sc->dev->wiphy,
  425. ath9k_reg_notifier);
  426. if (error)
  427. goto error_regd;
  428. reg = &common->regulatory;*/
  429. /* Setup TX DMA */
  430. error = ath_tx_init(sc, ATH_TXBUF);
  431. if (error != 0)
  432. goto error_tx;
  433. /* Setup RX DMA */
  434. error = ath_rx_init(sc, ATH_RXBUF);
  435. if (error != 0)
  436. goto error_rx;
  437. ath9k_init_txpower_limits(sc);
  438. /* Register with mac80211 */
  439. error = net80211_register(dev, &ath9k_ops, sc->hwinfo);
  440. if (error)
  441. goto error_register;
  442. /* TODO Cottsay: reg */
  443. /* Handle world regulatory */
  444. /*if (!ath_is_world_regd(reg)) {
  445. error = regulatory_hint(hw->wiphy, reg->alpha2);
  446. if (error)
  447. goto error_world;
  448. }*/
  449. sc->hw_pll_work = ath_hw_pll_work;
  450. sc->last_rssi = ATH_RSSI_DUMMY_MARKER;
  451. /* TODO Cottsay: rfkill */
  452. /*ath_start_rfkill_poll(sc);*/
  453. return 0;
  454. //error_world:
  455. // net80211_unregister(dev);
  456. error_register:
  457. ath_rx_cleanup(sc);
  458. error_rx:
  459. ath_tx_cleanup(sc);
  460. error_tx:
  461. ath9k_deinit_softc(sc);
  462. error_init:
  463. return error;
  464. }
  465. /*****************************/
  466. /* De-Initialization */
  467. /*****************************/
  468. static void ath9k_deinit_softc(struct ath_softc *sc)
  469. {
  470. int i = 0;
  471. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  472. if (ATH_TXQ_SETUP(sc, i))
  473. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  474. ath9k_hw_deinit(sc->sc_ah);
  475. free(sc->hwinfo);
  476. sc->hwinfo = NULL;
  477. free(sc->sc_ah);
  478. sc->sc_ah = NULL;
  479. }
  480. void ath9k_deinit_device(struct ath_softc *sc)
  481. {
  482. struct net80211_device *dev = sc->dev;
  483. net80211_unregister(dev);
  484. ath_rx_cleanup(sc);
  485. ath_tx_cleanup(sc);
  486. ath9k_deinit_softc(sc);
  487. }
  488. void ath_descdma_cleanup(struct ath_softc *sc __unused,
  489. struct ath_descdma *dd,
  490. struct list_head *head)
  491. {
  492. free_dma(dd->dd_desc, dd->dd_desc_len);
  493. INIT_LIST_HEAD(head);
  494. free(dd->dd_bufptr);
  495. memset(dd, 0, sizeof(*dd));
  496. }