main.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472
  1. /*
  2. * Copyright (c) 2008 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. /* mac80211 and PCI callbacks */
  17. #include <linux/nl80211.h>
  18. #include "core.h"
  19. #define ATH_PCI_VERSION "0.1"
  20. #define IEEE80211_HTCAP_MAXRXAMPDU_FACTOR 13
  21. #define IEEE80211_ACTION_CAT_HT 7
  22. #define IEEE80211_ACTION_HT_TXCHWIDTH 0
  23. static char *dev_info = "ath9k";
  24. MODULE_AUTHOR("Atheros Communications");
  25. MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
  26. MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
  27. MODULE_LICENSE("Dual BSD/GPL");
  28. static struct pci_device_id ath_pci_id_table[] __devinitdata = {
  29. { PCI_VDEVICE(ATHEROS, 0x0023) }, /* PCI */
  30. { PCI_VDEVICE(ATHEROS, 0x0024) }, /* PCI-E */
  31. { PCI_VDEVICE(ATHEROS, 0x0027) }, /* PCI */
  32. { PCI_VDEVICE(ATHEROS, 0x0029) }, /* PCI */
  33. { PCI_VDEVICE(ATHEROS, 0x002A) }, /* PCI-E */
  34. { 0 }
  35. };
  36. static int ath_get_channel(struct ath_softc *sc,
  37. struct ieee80211_channel *chan)
  38. {
  39. int i;
  40. for (i = 0; i < sc->sc_ah->ah_nchan; i++) {
  41. if (sc->sc_ah->ah_channels[i].channel == chan->center_freq)
  42. return i;
  43. }
  44. return -1;
  45. }
  46. static u32 ath_get_extchanmode(struct ath_softc *sc,
  47. struct ieee80211_channel *chan)
  48. {
  49. u32 chanmode = 0;
  50. u8 ext_chan_offset = sc->sc_ht_info.ext_chan_offset;
  51. enum ath9k_ht_macmode tx_chan_width = sc->sc_ht_info.tx_chan_width;
  52. switch (chan->band) {
  53. case IEEE80211_BAND_2GHZ:
  54. if ((ext_chan_offset == IEEE80211_HT_IE_CHA_SEC_NONE) &&
  55. (tx_chan_width == ATH9K_HT_MACMODE_20))
  56. chanmode = CHANNEL_G_HT20;
  57. if ((ext_chan_offset == IEEE80211_HT_IE_CHA_SEC_ABOVE) &&
  58. (tx_chan_width == ATH9K_HT_MACMODE_2040))
  59. chanmode = CHANNEL_G_HT40PLUS;
  60. if ((ext_chan_offset == IEEE80211_HT_IE_CHA_SEC_BELOW) &&
  61. (tx_chan_width == ATH9K_HT_MACMODE_2040))
  62. chanmode = CHANNEL_G_HT40MINUS;
  63. break;
  64. case IEEE80211_BAND_5GHZ:
  65. if ((ext_chan_offset == IEEE80211_HT_IE_CHA_SEC_NONE) &&
  66. (tx_chan_width == ATH9K_HT_MACMODE_20))
  67. chanmode = CHANNEL_A_HT20;
  68. if ((ext_chan_offset == IEEE80211_HT_IE_CHA_SEC_ABOVE) &&
  69. (tx_chan_width == ATH9K_HT_MACMODE_2040))
  70. chanmode = CHANNEL_A_HT40PLUS;
  71. if ((ext_chan_offset == IEEE80211_HT_IE_CHA_SEC_BELOW) &&
  72. (tx_chan_width == ATH9K_HT_MACMODE_2040))
  73. chanmode = CHANNEL_A_HT40MINUS;
  74. break;
  75. default:
  76. break;
  77. }
  78. return chanmode;
  79. }
  80. static int ath_setkey_tkip(struct ath_softc *sc,
  81. struct ieee80211_key_conf *key,
  82. struct ath9k_keyval *hk,
  83. const u8 *addr)
  84. {
  85. u8 *key_rxmic = NULL;
  86. u8 *key_txmic = NULL;
  87. key_txmic = key->key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
  88. key_rxmic = key->key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
  89. if (addr == NULL) {
  90. /* Group key installation */
  91. memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
  92. return ath_keyset(sc, key->keyidx, hk, addr);
  93. }
  94. if (!sc->sc_splitmic) {
  95. /*
  96. * data key goes at first index,
  97. * the hal handles the MIC keys at index+64.
  98. */
  99. memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
  100. memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
  101. return ath_keyset(sc, key->keyidx, hk, addr);
  102. }
  103. /*
  104. * TX key goes at first index, RX key at +32.
  105. * The hal handles the MIC keys at index+64.
  106. */
  107. memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
  108. if (!ath_keyset(sc, key->keyidx, hk, NULL)) {
  109. /* Txmic entry failed. No need to proceed further */
  110. DPRINTF(sc, ATH_DBG_KEYCACHE,
  111. "%s Setting TX MIC Key Failed\n", __func__);
  112. return 0;
  113. }
  114. memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
  115. /* XXX delete tx key on failure? */
  116. return ath_keyset(sc, key->keyidx+32, hk, addr);
  117. }
  118. static int ath_key_config(struct ath_softc *sc,
  119. const u8 *addr,
  120. struct ieee80211_key_conf *key)
  121. {
  122. struct ieee80211_vif *vif;
  123. struct ath9k_keyval hk;
  124. const u8 *mac = NULL;
  125. int ret = 0;
  126. enum ieee80211_if_types opmode;
  127. memset(&hk, 0, sizeof(hk));
  128. switch (key->alg) {
  129. case ALG_WEP:
  130. hk.kv_type = ATH9K_CIPHER_WEP;
  131. break;
  132. case ALG_TKIP:
  133. hk.kv_type = ATH9K_CIPHER_TKIP;
  134. break;
  135. case ALG_CCMP:
  136. hk.kv_type = ATH9K_CIPHER_AES_CCM;
  137. break;
  138. default:
  139. return -EINVAL;
  140. }
  141. hk.kv_len = key->keylen;
  142. memcpy(hk.kv_val, key->key, key->keylen);
  143. if (!sc->sc_vaps[0])
  144. return -EIO;
  145. vif = sc->sc_vaps[0]->av_if_data;
  146. opmode = vif->type;
  147. /*
  148. * Strategy:
  149. * For _M_STA mc tx, we will not setup a key at all since we never
  150. * tx mc.
  151. * _M_STA mc rx, we will use the keyID.
  152. * for _M_IBSS mc tx, we will use the keyID, and no macaddr.
  153. * for _M_IBSS mc rx, we will alloc a slot and plumb the mac of the
  154. * peer node. BUT we will plumb a cleartext key so that we can do
  155. * perSta default key table lookup in software.
  156. */
  157. if (is_broadcast_ether_addr(addr)) {
  158. switch (opmode) {
  159. case IEEE80211_IF_TYPE_STA:
  160. /* default key: could be group WPA key
  161. * or could be static WEP key */
  162. mac = NULL;
  163. break;
  164. case IEEE80211_IF_TYPE_IBSS:
  165. break;
  166. case IEEE80211_IF_TYPE_AP:
  167. break;
  168. default:
  169. ASSERT(0);
  170. break;
  171. }
  172. } else {
  173. mac = addr;
  174. }
  175. if (key->alg == ALG_TKIP)
  176. ret = ath_setkey_tkip(sc, key, &hk, mac);
  177. else
  178. ret = ath_keyset(sc, key->keyidx, &hk, mac);
  179. if (!ret)
  180. return -EIO;
  181. if (mac)
  182. sc->sc_keytype = hk.kv_type;
  183. return 0;
  184. }
  185. static void ath_key_delete(struct ath_softc *sc, struct ieee80211_key_conf *key)
  186. {
  187. #define ATH_MAX_NUM_KEYS 4
  188. int freeslot;
  189. freeslot = (key->keyidx >= ATH_MAX_NUM_KEYS) ? 1 : 0;
  190. ath_key_reset(sc, key->keyidx, freeslot);
  191. #undef ATH_MAX_NUM_KEYS
  192. }
  193. static void setup_ht_cap(struct ieee80211_ht_info *ht_info)
  194. {
  195. /* Until mac80211 includes these fields */
  196. #define IEEE80211_HT_CAP_DSSSCCK40 0x1000
  197. #define IEEE80211_HT_CAP_MAXRXAMPDU_65536 0x3 /* 2 ^ 16 */
  198. #define IEEE80211_HT_CAP_MPDUDENSITY_8 0x6 /* 8 usec */
  199. ht_info->ht_supported = 1;
  200. ht_info->cap = (u16)IEEE80211_HT_CAP_SUP_WIDTH
  201. |(u16)IEEE80211_HT_CAP_MIMO_PS
  202. |(u16)IEEE80211_HT_CAP_SGI_40
  203. |(u16)IEEE80211_HT_CAP_DSSSCCK40;
  204. ht_info->ampdu_factor = IEEE80211_HT_CAP_MAXRXAMPDU_65536;
  205. ht_info->ampdu_density = IEEE80211_HT_CAP_MPDUDENSITY_8;
  206. /* setup supported mcs set */
  207. memset(ht_info->supp_mcs_set, 0, 16);
  208. ht_info->supp_mcs_set[0] = 0xff;
  209. ht_info->supp_mcs_set[1] = 0xff;
  210. ht_info->supp_mcs_set[12] = IEEE80211_HT_CAP_MCS_TX_DEFINED;
  211. }
  212. static int ath_rate2idx(struct ath_softc *sc, int rate)
  213. {
  214. int i = 0, cur_band, n_rates;
  215. struct ieee80211_hw *hw = sc->hw;
  216. cur_band = hw->conf.channel->band;
  217. n_rates = sc->sbands[cur_band].n_bitrates;
  218. for (i = 0; i < n_rates; i++) {
  219. if (sc->sbands[cur_band].bitrates[i].bitrate == rate)
  220. break;
  221. }
  222. /*
  223. * NB:mac80211 validates rx rate index against the supported legacy rate
  224. * index only (should be done against ht rates also), return the highest
  225. * legacy rate index for rx rate which does not match any one of the
  226. * supported basic and extended rates to make mac80211 happy.
  227. * The following hack will be cleaned up once the issue with
  228. * the rx rate index validation in mac80211 is fixed.
  229. */
  230. if (i == n_rates)
  231. return n_rates - 1;
  232. return i;
  233. }
  234. static void ath9k_rx_prepare(struct ath_softc *sc,
  235. struct sk_buff *skb,
  236. struct ath_recv_status *status,
  237. struct ieee80211_rx_status *rx_status)
  238. {
  239. struct ieee80211_hw *hw = sc->hw;
  240. struct ieee80211_channel *curchan = hw->conf.channel;
  241. memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
  242. rx_status->mactime = status->tsf;
  243. rx_status->band = curchan->band;
  244. rx_status->freq = curchan->center_freq;
  245. rx_status->noise = ATH_DEFAULT_NOISE_FLOOR;
  246. rx_status->signal = rx_status->noise + status->rssi;
  247. rx_status->rate_idx = ath_rate2idx(sc, (status->rateKbps / 100));
  248. rx_status->antenna = status->antenna;
  249. rx_status->qual = status->rssi * 100 / 64;
  250. if (status->flags & ATH_RX_MIC_ERROR)
  251. rx_status->flag |= RX_FLAG_MMIC_ERROR;
  252. if (status->flags & ATH_RX_FCS_ERROR)
  253. rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
  254. rx_status->flag |= RX_FLAG_TSFT;
  255. }
  256. static u8 parse_mpdudensity(u8 mpdudensity)
  257. {
  258. /*
  259. * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
  260. * 0 for no restriction
  261. * 1 for 1/4 us
  262. * 2 for 1/2 us
  263. * 3 for 1 us
  264. * 4 for 2 us
  265. * 5 for 4 us
  266. * 6 for 8 us
  267. * 7 for 16 us
  268. */
  269. switch (mpdudensity) {
  270. case 0:
  271. return 0;
  272. case 1:
  273. case 2:
  274. case 3:
  275. /* Our lower layer calculations limit our precision to
  276. 1 microsecond */
  277. return 1;
  278. case 4:
  279. return 2;
  280. case 5:
  281. return 4;
  282. case 6:
  283. return 8;
  284. case 7:
  285. return 16;
  286. default:
  287. return 0;
  288. }
  289. }
  290. static int ath9k_start(struct ieee80211_hw *hw)
  291. {
  292. struct ath_softc *sc = hw->priv;
  293. struct ieee80211_channel *curchan = hw->conf.channel;
  294. int error = 0, pos;
  295. DPRINTF(sc, ATH_DBG_CONFIG, "%s: Starting driver with "
  296. "initial channel: %d MHz\n", __func__, curchan->center_freq);
  297. /* setup initial channel */
  298. pos = ath_get_channel(sc, curchan);
  299. if (pos == -1) {
  300. DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid channel\n", __func__);
  301. return -EINVAL;
  302. }
  303. sc->sc_ah->ah_channels[pos].chanmode =
  304. (curchan->band == IEEE80211_BAND_2GHZ) ? CHANNEL_G : CHANNEL_A;
  305. /* open ath_dev */
  306. error = ath_open(sc, &sc->sc_ah->ah_channels[pos]);
  307. if (error) {
  308. DPRINTF(sc, ATH_DBG_FATAL,
  309. "%s: Unable to complete ath_open\n", __func__);
  310. return error;
  311. }
  312. ieee80211_wake_queues(hw);
  313. return 0;
  314. }
  315. static int ath9k_tx(struct ieee80211_hw *hw,
  316. struct sk_buff *skb)
  317. {
  318. struct ath_softc *sc = hw->priv;
  319. int hdrlen, padsize;
  320. /* Add the padding after the header if this is not already done */
  321. hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  322. if (hdrlen & 3) {
  323. padsize = hdrlen % 4;
  324. if (skb_headroom(skb) < padsize)
  325. return -1;
  326. skb_push(skb, padsize);
  327. memmove(skb->data, skb->data + padsize, hdrlen);
  328. }
  329. DPRINTF(sc, ATH_DBG_XMIT, "%s: transmitting packet, skb: %p\n",
  330. __func__,
  331. skb);
  332. if (ath_tx_start(sc, skb) != 0) {
  333. DPRINTF(sc, ATH_DBG_XMIT, "%s: TX failed\n", __func__);
  334. dev_kfree_skb_any(skb);
  335. /* FIXME: Check for proper return value from ATH_DEV */
  336. return 0;
  337. }
  338. return 0;
  339. }
  340. static void ath9k_stop(struct ieee80211_hw *hw)
  341. {
  342. struct ath_softc *sc = hw->priv;
  343. int error;
  344. DPRINTF(sc, ATH_DBG_CONFIG, "%s: Driver halt\n", __func__);
  345. error = ath_suspend(sc);
  346. if (error)
  347. DPRINTF(sc, ATH_DBG_CONFIG,
  348. "%s: Device is no longer present\n", __func__);
  349. ieee80211_stop_queues(hw);
  350. }
  351. static int ath9k_add_interface(struct ieee80211_hw *hw,
  352. struct ieee80211_if_init_conf *conf)
  353. {
  354. struct ath_softc *sc = hw->priv;
  355. int error, ic_opmode = 0;
  356. /* Support only vap for now */
  357. if (sc->sc_nvaps)
  358. return -ENOBUFS;
  359. switch (conf->type) {
  360. case IEEE80211_IF_TYPE_STA:
  361. ic_opmode = ATH9K_M_STA;
  362. break;
  363. case IEEE80211_IF_TYPE_IBSS:
  364. ic_opmode = ATH9K_M_IBSS;
  365. break;
  366. default:
  367. DPRINTF(sc, ATH_DBG_FATAL,
  368. "%s: Only STA and IBSS are supported currently\n",
  369. __func__);
  370. return -EOPNOTSUPP;
  371. }
  372. DPRINTF(sc, ATH_DBG_CONFIG, "%s: Attach a VAP of type: %d\n",
  373. __func__,
  374. ic_opmode);
  375. error = ath_vap_attach(sc, 0, conf->vif, ic_opmode);
  376. if (error) {
  377. DPRINTF(sc, ATH_DBG_FATAL,
  378. "%s: Unable to attach vap, error: %d\n",
  379. __func__, error);
  380. return error;
  381. }
  382. return 0;
  383. }
  384. static void ath9k_remove_interface(struct ieee80211_hw *hw,
  385. struct ieee80211_if_init_conf *conf)
  386. {
  387. struct ath_softc *sc = hw->priv;
  388. struct ath_vap *avp;
  389. int error;
  390. DPRINTF(sc, ATH_DBG_CONFIG, "%s: Detach VAP\n", __func__);
  391. avp = sc->sc_vaps[0];
  392. if (avp == NULL) {
  393. DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid interface\n",
  394. __func__);
  395. return;
  396. }
  397. #ifdef CONFIG_SLOW_ANT_DIV
  398. ath_slow_ant_div_stop(&sc->sc_antdiv);
  399. #endif
  400. /* Update ratectrl */
  401. ath_rate_newstate(sc, avp);
  402. /* Reclaim beacon resources */
  403. if (sc->sc_opmode == ATH9K_M_HOSTAP || sc->sc_opmode == ATH9K_M_IBSS) {
  404. ath9k_hw_stoptxdma(sc->sc_ah, sc->sc_bhalq);
  405. ath_beacon_return(sc, avp);
  406. }
  407. /* Set interrupt mask */
  408. sc->sc_imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
  409. ath9k_hw_set_interrupts(sc->sc_ah, sc->sc_imask & ~ATH9K_INT_GLOBAL);
  410. sc->sc_beacons = 0;
  411. error = ath_vap_detach(sc, 0);
  412. if (error)
  413. DPRINTF(sc, ATH_DBG_FATAL,
  414. "%s: Unable to detach vap, error: %d\n",
  415. __func__, error);
  416. }
  417. static int ath9k_config(struct ieee80211_hw *hw,
  418. struct ieee80211_conf *conf)
  419. {
  420. struct ath_softc *sc = hw->priv;
  421. struct ieee80211_channel *curchan = hw->conf.channel;
  422. int pos;
  423. DPRINTF(sc, ATH_DBG_CONFIG, "%s: Set channel: %d MHz\n",
  424. __func__,
  425. curchan->center_freq);
  426. pos = ath_get_channel(sc, curchan);
  427. if (pos == -1) {
  428. DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid channel\n", __func__);
  429. return -EINVAL;
  430. }
  431. sc->sc_ah->ah_channels[pos].chanmode =
  432. (curchan->band == IEEE80211_BAND_2GHZ) ?
  433. CHANNEL_G : CHANNEL_A;
  434. if (sc->sc_curaid && hw->conf.ht_conf.ht_supported)
  435. sc->sc_ah->ah_channels[pos].chanmode =
  436. ath_get_extchanmode(sc, curchan);
  437. sc->sc_config.txpowlimit = 2 * conf->power_level;
  438. /* set h/w channel */
  439. if (ath_set_channel(sc, &sc->sc_ah->ah_channels[pos]) < 0)
  440. DPRINTF(sc, ATH_DBG_FATAL, "%s: Unable to set channel\n",
  441. __func__);
  442. return 0;
  443. }
  444. static int ath9k_config_interface(struct ieee80211_hw *hw,
  445. struct ieee80211_vif *vif,
  446. struct ieee80211_if_conf *conf)
  447. {
  448. struct ath_softc *sc = hw->priv;
  449. struct ath_vap *avp;
  450. u32 rfilt = 0;
  451. int error, i;
  452. DECLARE_MAC_BUF(mac);
  453. avp = sc->sc_vaps[0];
  454. if (avp == NULL) {
  455. DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid interface\n",
  456. __func__);
  457. return -EINVAL;
  458. }
  459. if ((conf->changed & IEEE80211_IFCC_BSSID) &&
  460. !is_zero_ether_addr(conf->bssid)) {
  461. switch (vif->type) {
  462. case IEEE80211_IF_TYPE_STA:
  463. case IEEE80211_IF_TYPE_IBSS:
  464. /* Update ratectrl about the new state */
  465. ath_rate_newstate(sc, avp);
  466. /* Set rx filter */
  467. rfilt = ath_calcrxfilter(sc);
  468. ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
  469. /* Set BSSID */
  470. memcpy(sc->sc_curbssid, conf->bssid, ETH_ALEN);
  471. sc->sc_curaid = 0;
  472. ath9k_hw_write_associd(sc->sc_ah, sc->sc_curbssid,
  473. sc->sc_curaid);
  474. /* Set aggregation protection mode parameters */
  475. sc->sc_config.ath_aggr_prot = 0;
  476. /*
  477. * Reset our TSF so that its value is lower than the
  478. * beacon that we are trying to catch.
  479. * Only then hw will update its TSF register with the
  480. * new beacon. Reset the TSF before setting the BSSID
  481. * to avoid allowing in any frames that would update
  482. * our TSF only to have us clear it
  483. * immediately thereafter.
  484. */
  485. ath9k_hw_reset_tsf(sc->sc_ah);
  486. /* Disable BMISS interrupt when we're not associated */
  487. ath9k_hw_set_interrupts(sc->sc_ah,
  488. sc->sc_imask &
  489. ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS));
  490. sc->sc_imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
  491. DPRINTF(sc, ATH_DBG_CONFIG,
  492. "%s: RX filter 0x%x bssid %s aid 0x%x\n",
  493. __func__, rfilt,
  494. print_mac(mac, sc->sc_curbssid), sc->sc_curaid);
  495. /* need to reconfigure the beacon */
  496. sc->sc_beacons = 0;
  497. break;
  498. default:
  499. break;
  500. }
  501. }
  502. if ((conf->changed & IEEE80211_IFCC_BEACON) &&
  503. (vif->type == IEEE80211_IF_TYPE_IBSS)) {
  504. /*
  505. * Allocate and setup the beacon frame.
  506. *
  507. * Stop any previous beacon DMA. This may be
  508. * necessary, for example, when an ibss merge
  509. * causes reconfiguration; we may be called
  510. * with beacon transmission active.
  511. */
  512. ath9k_hw_stoptxdma(sc->sc_ah, sc->sc_bhalq);
  513. error = ath_beacon_alloc(sc, 0);
  514. if (error != 0)
  515. return error;
  516. ath_beacon_sync(sc, 0);
  517. }
  518. /* Check for WLAN_CAPABILITY_PRIVACY ? */
  519. if ((avp->av_opmode != IEEE80211_IF_TYPE_STA)) {
  520. for (i = 0; i < IEEE80211_WEP_NKID; i++)
  521. if (ath9k_hw_keyisvalid(sc->sc_ah, (u16)i))
  522. ath9k_hw_keysetmac(sc->sc_ah,
  523. (u16)i,
  524. sc->sc_curbssid);
  525. }
  526. /* Only legacy IBSS for now */
  527. if (vif->type == IEEE80211_IF_TYPE_IBSS)
  528. ath_update_chainmask(sc, 0);
  529. return 0;
  530. }
  531. #define SUPPORTED_FILTERS \
  532. (FIF_PROMISC_IN_BSS | \
  533. FIF_ALLMULTI | \
  534. FIF_CONTROL | \
  535. FIF_OTHER_BSS | \
  536. FIF_BCN_PRBRESP_PROMISC | \
  537. FIF_FCSFAIL)
  538. /* Accept unicast, bcast and mcast frames */
  539. static void ath9k_configure_filter(struct ieee80211_hw *hw,
  540. unsigned int changed_flags,
  541. unsigned int *total_flags,
  542. int mc_count,
  543. struct dev_mc_list *mclist)
  544. {
  545. struct ath_softc *sc = hw->priv;
  546. changed_flags &= SUPPORTED_FILTERS;
  547. *total_flags &= SUPPORTED_FILTERS;
  548. if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
  549. if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
  550. ath_scan_start(sc);
  551. else
  552. ath_scan_end(sc);
  553. }
  554. }
  555. static void ath9k_sta_notify(struct ieee80211_hw *hw,
  556. struct ieee80211_vif *vif,
  557. enum sta_notify_cmd cmd,
  558. const u8 *addr)
  559. {
  560. struct ath_softc *sc = hw->priv;
  561. struct ath_node *an;
  562. unsigned long flags;
  563. DECLARE_MAC_BUF(mac);
  564. spin_lock_irqsave(&sc->node_lock, flags);
  565. an = ath_node_find(sc, (u8 *) addr);
  566. spin_unlock_irqrestore(&sc->node_lock, flags);
  567. switch (cmd) {
  568. case STA_NOTIFY_ADD:
  569. spin_lock_irqsave(&sc->node_lock, flags);
  570. if (!an) {
  571. ath_node_attach(sc, (u8 *)addr, 0);
  572. DPRINTF(sc, ATH_DBG_CONFIG, "%s: Attach a node: %s\n",
  573. __func__,
  574. print_mac(mac, addr));
  575. } else {
  576. ath_node_get(sc, (u8 *)addr);
  577. }
  578. spin_unlock_irqrestore(&sc->node_lock, flags);
  579. break;
  580. case STA_NOTIFY_REMOVE:
  581. if (!an)
  582. DPRINTF(sc, ATH_DBG_FATAL,
  583. "%s: Removal of a non-existent node\n",
  584. __func__);
  585. else {
  586. ath_node_put(sc, an, ATH9K_BH_STATUS_INTACT);
  587. DPRINTF(sc, ATH_DBG_CONFIG, "%s: Put a node: %s\n",
  588. __func__,
  589. print_mac(mac, addr));
  590. }
  591. break;
  592. default:
  593. break;
  594. }
  595. }
  596. static int ath9k_conf_tx(struct ieee80211_hw *hw,
  597. u16 queue,
  598. const struct ieee80211_tx_queue_params *params)
  599. {
  600. struct ath_softc *sc = hw->priv;
  601. struct ath9k_tx_queue_info qi;
  602. int ret = 0, qnum;
  603. if (queue >= WME_NUM_AC)
  604. return 0;
  605. qi.tqi_aifs = params->aifs;
  606. qi.tqi_cwmin = params->cw_min;
  607. qi.tqi_cwmax = params->cw_max;
  608. qi.tqi_burstTime = params->txop;
  609. qnum = ath_get_hal_qnum(queue, sc);
  610. DPRINTF(sc, ATH_DBG_CONFIG,
  611. "%s: Configure tx [queue/halq] [%d/%d], "
  612. "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
  613. __func__,
  614. queue,
  615. qnum,
  616. params->aifs,
  617. params->cw_min,
  618. params->cw_max,
  619. params->txop);
  620. ret = ath_txq_update(sc, qnum, &qi);
  621. if (ret)
  622. DPRINTF(sc, ATH_DBG_FATAL,
  623. "%s: TXQ Update failed\n", __func__);
  624. return ret;
  625. }
  626. static int ath9k_set_key(struct ieee80211_hw *hw,
  627. enum set_key_cmd cmd,
  628. const u8 *local_addr,
  629. const u8 *addr,
  630. struct ieee80211_key_conf *key)
  631. {
  632. struct ath_softc *sc = hw->priv;
  633. int ret = 0;
  634. DPRINTF(sc, ATH_DBG_KEYCACHE, " %s: Set HW Key\n", __func__);
  635. switch (cmd) {
  636. case SET_KEY:
  637. ret = ath_key_config(sc, addr, key);
  638. if (!ret) {
  639. set_bit(key->keyidx, sc->sc_keymap);
  640. key->hw_key_idx = key->keyidx;
  641. /* push IV and Michael MIC generation to stack */
  642. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  643. if (key->alg == ALG_TKIP)
  644. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  645. }
  646. break;
  647. case DISABLE_KEY:
  648. ath_key_delete(sc, key);
  649. clear_bit(key->keyidx, sc->sc_keymap);
  650. sc->sc_keytype = ATH9K_CIPHER_CLR;
  651. break;
  652. default:
  653. ret = -EINVAL;
  654. }
  655. return ret;
  656. }
  657. static void ath9k_ht_conf(struct ath_softc *sc,
  658. struct ieee80211_bss_conf *bss_conf)
  659. {
  660. #define IEEE80211_HT_CAP_40MHZ_INTOLERANT BIT(14)
  661. struct ath_ht_info *ht_info = &sc->sc_ht_info;
  662. if (bss_conf->assoc_ht) {
  663. ht_info->ext_chan_offset =
  664. bss_conf->ht_bss_conf->bss_cap &
  665. IEEE80211_HT_IE_CHA_SEC_OFFSET;
  666. if (!(bss_conf->ht_conf->cap &
  667. IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
  668. (bss_conf->ht_bss_conf->bss_cap &
  669. IEEE80211_HT_IE_CHA_WIDTH))
  670. ht_info->tx_chan_width = ATH9K_HT_MACMODE_2040;
  671. else
  672. ht_info->tx_chan_width = ATH9K_HT_MACMODE_20;
  673. ath9k_hw_set11nmac2040(sc->sc_ah, ht_info->tx_chan_width);
  674. ht_info->maxampdu = 1 << (IEEE80211_HTCAP_MAXRXAMPDU_FACTOR +
  675. bss_conf->ht_conf->ampdu_factor);
  676. ht_info->mpdudensity =
  677. parse_mpdudensity(bss_conf->ht_conf->ampdu_density);
  678. }
  679. #undef IEEE80211_HT_CAP_40MHZ_INTOLERANT
  680. }
  681. static void ath9k_bss_assoc_info(struct ath_softc *sc,
  682. struct ieee80211_bss_conf *bss_conf)
  683. {
  684. struct ieee80211_hw *hw = sc->hw;
  685. struct ieee80211_channel *curchan = hw->conf.channel;
  686. struct ath_vap *avp;
  687. int pos;
  688. DECLARE_MAC_BUF(mac);
  689. if (bss_conf->assoc) {
  690. DPRINTF(sc, ATH_DBG_CONFIG, "%s: Bss Info ASSOC %d\n",
  691. __func__,
  692. bss_conf->aid);
  693. avp = sc->sc_vaps[0];
  694. if (avp == NULL) {
  695. DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid interface\n",
  696. __func__);
  697. return;
  698. }
  699. /* New association, store aid */
  700. if (avp->av_opmode == ATH9K_M_STA) {
  701. sc->sc_curaid = bss_conf->aid;
  702. ath9k_hw_write_associd(sc->sc_ah, sc->sc_curbssid,
  703. sc->sc_curaid);
  704. }
  705. /* Configure the beacon */
  706. ath_beacon_config(sc, 0);
  707. sc->sc_beacons = 1;
  708. /* Reset rssi stats */
  709. sc->sc_halstats.ns_avgbrssi = ATH_RSSI_DUMMY_MARKER;
  710. sc->sc_halstats.ns_avgrssi = ATH_RSSI_DUMMY_MARKER;
  711. sc->sc_halstats.ns_avgtxrssi = ATH_RSSI_DUMMY_MARKER;
  712. sc->sc_halstats.ns_avgtxrate = ATH_RATE_DUMMY_MARKER;
  713. /* Update chainmask */
  714. ath_update_chainmask(sc, bss_conf->assoc_ht);
  715. DPRINTF(sc, ATH_DBG_CONFIG,
  716. "%s: bssid %s aid 0x%x\n",
  717. __func__,
  718. print_mac(mac, sc->sc_curbssid), sc->sc_curaid);
  719. DPRINTF(sc, ATH_DBG_CONFIG, "%s: Set channel: %d MHz\n",
  720. __func__,
  721. curchan->center_freq);
  722. pos = ath_get_channel(sc, curchan);
  723. if (pos == -1) {
  724. DPRINTF(sc, ATH_DBG_FATAL,
  725. "%s: Invalid channel\n", __func__);
  726. return;
  727. }
  728. if (hw->conf.ht_conf.ht_supported)
  729. sc->sc_ah->ah_channels[pos].chanmode =
  730. ath_get_extchanmode(sc, curchan);
  731. else
  732. sc->sc_ah->ah_channels[pos].chanmode =
  733. (curchan->band == IEEE80211_BAND_2GHZ) ?
  734. CHANNEL_G : CHANNEL_A;
  735. /* set h/w channel */
  736. if (ath_set_channel(sc, &sc->sc_ah->ah_channels[pos]) < 0)
  737. DPRINTF(sc, ATH_DBG_FATAL,
  738. "%s: Unable to set channel\n",
  739. __func__);
  740. ath_rate_newstate(sc, avp);
  741. /* Update ratectrl about the new state */
  742. ath_rc_node_update(hw, avp->rc_node);
  743. } else {
  744. DPRINTF(sc, ATH_DBG_CONFIG,
  745. "%s: Bss Info DISSOC\n", __func__);
  746. sc->sc_curaid = 0;
  747. }
  748. }
  749. static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
  750. struct ieee80211_vif *vif,
  751. struct ieee80211_bss_conf *bss_conf,
  752. u32 changed)
  753. {
  754. struct ath_softc *sc = hw->priv;
  755. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  756. DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed PREAMBLE %d\n",
  757. __func__,
  758. bss_conf->use_short_preamble);
  759. if (bss_conf->use_short_preamble)
  760. sc->sc_flags |= ATH_PREAMBLE_SHORT;
  761. else
  762. sc->sc_flags &= ~ATH_PREAMBLE_SHORT;
  763. }
  764. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  765. DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed CTS PROT %d\n",
  766. __func__,
  767. bss_conf->use_cts_prot);
  768. if (bss_conf->use_cts_prot &&
  769. hw->conf.channel->band != IEEE80211_BAND_5GHZ)
  770. sc->sc_flags |= ATH_PROTECT_ENABLE;
  771. else
  772. sc->sc_flags &= ~ATH_PROTECT_ENABLE;
  773. }
  774. if (changed & BSS_CHANGED_HT) {
  775. DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed HT %d\n",
  776. __func__,
  777. bss_conf->assoc_ht);
  778. ath9k_ht_conf(sc, bss_conf);
  779. }
  780. if (changed & BSS_CHANGED_ASSOC) {
  781. DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed ASSOC %d\n",
  782. __func__,
  783. bss_conf->assoc);
  784. ath9k_bss_assoc_info(sc, bss_conf);
  785. }
  786. }
  787. static u64 ath9k_get_tsf(struct ieee80211_hw *hw)
  788. {
  789. u64 tsf;
  790. struct ath_softc *sc = hw->priv;
  791. struct ath_hal *ah = sc->sc_ah;
  792. tsf = ath9k_hw_gettsf64(ah);
  793. return tsf;
  794. }
  795. static void ath9k_reset_tsf(struct ieee80211_hw *hw)
  796. {
  797. struct ath_softc *sc = hw->priv;
  798. struct ath_hal *ah = sc->sc_ah;
  799. ath9k_hw_reset_tsf(ah);
  800. }
  801. static int ath9k_ampdu_action(struct ieee80211_hw *hw,
  802. enum ieee80211_ampdu_mlme_action action,
  803. const u8 *addr,
  804. u16 tid,
  805. u16 *ssn)
  806. {
  807. struct ath_softc *sc = hw->priv;
  808. int ret = 0;
  809. switch (action) {
  810. case IEEE80211_AMPDU_RX_START:
  811. ret = ath_rx_aggr_start(sc, addr, tid, ssn);
  812. if (ret < 0)
  813. DPRINTF(sc, ATH_DBG_FATAL,
  814. "%s: Unable to start RX aggregation\n",
  815. __func__);
  816. break;
  817. case IEEE80211_AMPDU_RX_STOP:
  818. ret = ath_rx_aggr_stop(sc, addr, tid);
  819. if (ret < 0)
  820. DPRINTF(sc, ATH_DBG_FATAL,
  821. "%s: Unable to stop RX aggregation\n",
  822. __func__);
  823. break;
  824. case IEEE80211_AMPDU_TX_START:
  825. ret = ath_tx_aggr_start(sc, addr, tid, ssn);
  826. if (ret < 0)
  827. DPRINTF(sc, ATH_DBG_FATAL,
  828. "%s: Unable to start TX aggregation\n",
  829. __func__);
  830. else
  831. ieee80211_start_tx_ba_cb_irqsafe(hw, (u8 *)addr, tid);
  832. break;
  833. case IEEE80211_AMPDU_TX_STOP:
  834. ret = ath_tx_aggr_stop(sc, addr, tid);
  835. if (ret < 0)
  836. DPRINTF(sc, ATH_DBG_FATAL,
  837. "%s: Unable to stop TX aggregation\n",
  838. __func__);
  839. ieee80211_stop_tx_ba_cb_irqsafe(hw, (u8 *)addr, tid);
  840. break;
  841. default:
  842. DPRINTF(sc, ATH_DBG_FATAL,
  843. "%s: Unknown AMPDU action\n", __func__);
  844. }
  845. return ret;
  846. }
  847. static struct ieee80211_ops ath9k_ops = {
  848. .tx = ath9k_tx,
  849. .start = ath9k_start,
  850. .stop = ath9k_stop,
  851. .add_interface = ath9k_add_interface,
  852. .remove_interface = ath9k_remove_interface,
  853. .config = ath9k_config,
  854. .config_interface = ath9k_config_interface,
  855. .configure_filter = ath9k_configure_filter,
  856. .get_stats = NULL,
  857. .sta_notify = ath9k_sta_notify,
  858. .conf_tx = ath9k_conf_tx,
  859. .get_tx_stats = NULL,
  860. .bss_info_changed = ath9k_bss_info_changed,
  861. .set_tim = NULL,
  862. .set_key = ath9k_set_key,
  863. .hw_scan = NULL,
  864. .get_tkip_seq = NULL,
  865. .set_rts_threshold = NULL,
  866. .set_frag_threshold = NULL,
  867. .set_retry_limit = NULL,
  868. .get_tsf = ath9k_get_tsf,
  869. .reset_tsf = ath9k_reset_tsf,
  870. .tx_last_beacon = NULL,
  871. .ampdu_action = ath9k_ampdu_action
  872. };
  873. void ath_get_beaconconfig(struct ath_softc *sc,
  874. int if_id,
  875. struct ath_beacon_config *conf)
  876. {
  877. struct ieee80211_hw *hw = sc->hw;
  878. /* fill in beacon config data */
  879. conf->beacon_interval = hw->conf.beacon_int;
  880. conf->listen_interval = 100;
  881. conf->dtim_count = 1;
  882. conf->bmiss_timeout = ATH_DEFAULT_BMISS_LIMIT * conf->listen_interval;
  883. }
  884. int ath_update_beacon(struct ath_softc *sc,
  885. int if_id,
  886. struct ath_beacon_offset *bo,
  887. struct sk_buff *skb,
  888. int mcast)
  889. {
  890. return 0;
  891. }
  892. void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
  893. struct ath_xmit_status *tx_status, struct ath_node *an)
  894. {
  895. struct ieee80211_hw *hw = sc->hw;
  896. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  897. DPRINTF(sc, ATH_DBG_XMIT,
  898. "%s: TX complete: skb: %p\n", __func__, skb);
  899. if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK ||
  900. tx_info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
  901. /* free driver's private data area of tx_info */
  902. if (tx_info->driver_data[0] != NULL)
  903. kfree(tx_info->driver_data[0]);
  904. tx_info->driver_data[0] = NULL;
  905. }
  906. if (tx_status->flags & ATH_TX_BAR) {
  907. tx_info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
  908. tx_status->flags &= ~ATH_TX_BAR;
  909. }
  910. if (tx_status->flags)
  911. tx_info->status.excessive_retries = 1;
  912. tx_info->status.retry_count = tx_status->retries;
  913. ieee80211_tx_status(hw, skb);
  914. if (an)
  915. ath_node_put(sc, an, ATH9K_BH_STATUS_CHANGE);
  916. }
  917. int ath__rx_indicate(struct ath_softc *sc,
  918. struct sk_buff *skb,
  919. struct ath_recv_status *status,
  920. u16 keyix)
  921. {
  922. struct ieee80211_hw *hw = sc->hw;
  923. struct ath_node *an = NULL;
  924. struct ieee80211_rx_status rx_status;
  925. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  926. int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  927. int padsize;
  928. enum ATH_RX_TYPE st;
  929. /* see if any padding is done by the hw and remove it */
  930. if (hdrlen & 3) {
  931. padsize = hdrlen % 4;
  932. memmove(skb->data + padsize, skb->data, hdrlen);
  933. skb_pull(skb, padsize);
  934. }
  935. /* remove FCS before passing up to protocol stack */
  936. skb_trim(skb, (skb->len - FCS_LEN));
  937. /* Prepare rx status */
  938. ath9k_rx_prepare(sc, skb, status, &rx_status);
  939. if (!(keyix == ATH9K_RXKEYIX_INVALID) &&
  940. !(status->flags & ATH_RX_DECRYPT_ERROR)) {
  941. rx_status.flag |= RX_FLAG_DECRYPTED;
  942. } else if ((le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_PROTECTED)
  943. && !(status->flags & ATH_RX_DECRYPT_ERROR)
  944. && skb->len >= hdrlen + 4) {
  945. keyix = skb->data[hdrlen + 3] >> 6;
  946. if (test_bit(keyix, sc->sc_keymap))
  947. rx_status.flag |= RX_FLAG_DECRYPTED;
  948. }
  949. spin_lock_bh(&sc->node_lock);
  950. an = ath_node_find(sc, hdr->addr2);
  951. spin_unlock_bh(&sc->node_lock);
  952. if (an) {
  953. ath_rx_input(sc, an,
  954. hw->conf.ht_conf.ht_supported,
  955. skb, status, &st);
  956. }
  957. if (!an || (st != ATH_RX_CONSUMED))
  958. __ieee80211_rx(hw, skb, &rx_status);
  959. return 0;
  960. }
  961. int ath_rx_subframe(struct ath_node *an,
  962. struct sk_buff *skb,
  963. struct ath_recv_status *status)
  964. {
  965. struct ath_softc *sc = an->an_sc;
  966. struct ieee80211_hw *hw = sc->hw;
  967. struct ieee80211_rx_status rx_status;
  968. /* Prepare rx status */
  969. ath9k_rx_prepare(sc, skb, status, &rx_status);
  970. if (!(status->flags & ATH_RX_DECRYPT_ERROR))
  971. rx_status.flag |= RX_FLAG_DECRYPTED;
  972. __ieee80211_rx(hw, skb, &rx_status);
  973. return 0;
  974. }
  975. enum ath9k_ht_macmode ath_cwm_macmode(struct ath_softc *sc)
  976. {
  977. return sc->sc_ht_info.tx_chan_width;
  978. }
  979. static int ath_detach(struct ath_softc *sc)
  980. {
  981. struct ieee80211_hw *hw = sc->hw;
  982. DPRINTF(sc, ATH_DBG_CONFIG, "%s: Detach ATH hw\n", __func__);
  983. /* Unregister hw */
  984. ieee80211_unregister_hw(hw);
  985. /* unregister Rate control */
  986. ath_rate_control_unregister();
  987. /* tx/rx cleanup */
  988. ath_rx_cleanup(sc);
  989. ath_tx_cleanup(sc);
  990. /* Deinit */
  991. ath_deinit(sc);
  992. return 0;
  993. }
  994. static int ath_attach(u16 devid,
  995. struct ath_softc *sc)
  996. {
  997. struct ieee80211_hw *hw = sc->hw;
  998. int error = 0;
  999. DPRINTF(sc, ATH_DBG_CONFIG, "%s: Attach ATH hw\n", __func__);
  1000. error = ath_init(devid, sc);
  1001. if (error != 0)
  1002. return error;
  1003. /* Init nodes */
  1004. INIT_LIST_HEAD(&sc->node_list);
  1005. spin_lock_init(&sc->node_lock);
  1006. /* get mac address from hardware and set in mac80211 */
  1007. SET_IEEE80211_PERM_ADDR(hw, sc->sc_myaddr);
  1008. /* setup channels and rates */
  1009. sc->sbands[IEEE80211_BAND_2GHZ].channels =
  1010. sc->channels[IEEE80211_BAND_2GHZ];
  1011. sc->sbands[IEEE80211_BAND_2GHZ].bitrates =
  1012. sc->rates[IEEE80211_BAND_2GHZ];
  1013. sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
  1014. if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT)
  1015. /* Setup HT capabilities for 2.4Ghz*/
  1016. setup_ht_cap(&sc->sbands[IEEE80211_BAND_2GHZ].ht_info);
  1017. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  1018. &sc->sbands[IEEE80211_BAND_2GHZ];
  1019. if (test_bit(ATH9K_MODE_11A, sc->sc_ah->ah_caps.wireless_modes)) {
  1020. sc->sbands[IEEE80211_BAND_5GHZ].channels =
  1021. sc->channels[IEEE80211_BAND_5GHZ];
  1022. sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
  1023. sc->rates[IEEE80211_BAND_5GHZ];
  1024. sc->sbands[IEEE80211_BAND_5GHZ].band =
  1025. IEEE80211_BAND_5GHZ;
  1026. if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT)
  1027. /* Setup HT capabilities for 5Ghz*/
  1028. setup_ht_cap(&sc->sbands[IEEE80211_BAND_5GHZ].ht_info);
  1029. hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  1030. &sc->sbands[IEEE80211_BAND_5GHZ];
  1031. }
  1032. /* FIXME: Have to figure out proper hw init values later */
  1033. hw->queues = 4;
  1034. hw->ampdu_queues = 1;
  1035. /* Register rate control */
  1036. hw->rate_control_algorithm = "ath9k_rate_control";
  1037. error = ath_rate_control_register();
  1038. if (error != 0) {
  1039. DPRINTF(sc, ATH_DBG_FATAL,
  1040. "%s: Unable to register rate control "
  1041. "algorithm:%d\n", __func__, error);
  1042. ath_rate_control_unregister();
  1043. goto bad;
  1044. }
  1045. error = ieee80211_register_hw(hw);
  1046. if (error != 0) {
  1047. ath_rate_control_unregister();
  1048. goto bad;
  1049. }
  1050. /* initialize tx/rx engine */
  1051. error = ath_tx_init(sc, ATH_TXBUF);
  1052. if (error != 0)
  1053. goto bad1;
  1054. error = ath_rx_init(sc, ATH_RXBUF);
  1055. if (error != 0)
  1056. goto bad1;
  1057. return 0;
  1058. bad1:
  1059. ath_detach(sc);
  1060. bad:
  1061. return error;
  1062. }
  1063. static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  1064. {
  1065. void __iomem *mem;
  1066. struct ath_softc *sc;
  1067. struct ieee80211_hw *hw;
  1068. const char *athname;
  1069. u8 csz;
  1070. u32 val;
  1071. int ret = 0;
  1072. if (pci_enable_device(pdev))
  1073. return -EIO;
  1074. /* XXX 32-bit addressing only */
  1075. if (pci_set_dma_mask(pdev, 0xffffffff)) {
  1076. printk(KERN_ERR "ath_pci: 32-bit DMA not available\n");
  1077. ret = -ENODEV;
  1078. goto bad;
  1079. }
  1080. /*
  1081. * Cache line size is used to size and align various
  1082. * structures used to communicate with the hardware.
  1083. */
  1084. pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &csz);
  1085. if (csz == 0) {
  1086. /*
  1087. * Linux 2.4.18 (at least) writes the cache line size
  1088. * register as a 16-bit wide register which is wrong.
  1089. * We must have this setup properly for rx buffer
  1090. * DMA to work so force a reasonable value here if it
  1091. * comes up zero.
  1092. */
  1093. csz = L1_CACHE_BYTES / sizeof(u32);
  1094. pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, csz);
  1095. }
  1096. /*
  1097. * The default setting of latency timer yields poor results,
  1098. * set it to the value used by other systems. It may be worth
  1099. * tweaking this setting more.
  1100. */
  1101. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0xa8);
  1102. pci_set_master(pdev);
  1103. /*
  1104. * Disable the RETRY_TIMEOUT register (0x41) to keep
  1105. * PCI Tx retries from interfering with C3 CPU state.
  1106. */
  1107. pci_read_config_dword(pdev, 0x40, &val);
  1108. if ((val & 0x0000ff00) != 0)
  1109. pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
  1110. ret = pci_request_region(pdev, 0, "ath9k");
  1111. if (ret) {
  1112. dev_err(&pdev->dev, "PCI memory region reserve error\n");
  1113. ret = -ENODEV;
  1114. goto bad;
  1115. }
  1116. mem = pci_iomap(pdev, 0, 0);
  1117. if (!mem) {
  1118. printk(KERN_ERR "PCI memory map error\n") ;
  1119. ret = -EIO;
  1120. goto bad1;
  1121. }
  1122. hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
  1123. if (hw == NULL) {
  1124. printk(KERN_ERR "ath_pci: no memory for ieee80211_hw\n");
  1125. goto bad2;
  1126. }
  1127. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  1128. IEEE80211_HW_NOISE_DBM;
  1129. SET_IEEE80211_DEV(hw, &pdev->dev);
  1130. pci_set_drvdata(pdev, hw);
  1131. sc = hw->priv;
  1132. sc->hw = hw;
  1133. sc->pdev = pdev;
  1134. sc->mem = mem;
  1135. if (ath_attach(id->device, sc) != 0) {
  1136. ret = -ENODEV;
  1137. goto bad3;
  1138. }
  1139. /* setup interrupt service routine */
  1140. if (request_irq(pdev->irq, ath_isr, IRQF_SHARED, "ath", sc)) {
  1141. printk(KERN_ERR "%s: request_irq failed\n",
  1142. wiphy_name(hw->wiphy));
  1143. ret = -EIO;
  1144. goto bad4;
  1145. }
  1146. athname = ath9k_hw_probe(id->vendor, id->device);
  1147. printk(KERN_INFO "%s: %s: mem=0x%lx, irq=%d\n",
  1148. wiphy_name(hw->wiphy),
  1149. athname ? athname : "Atheros ???",
  1150. (unsigned long)mem, pdev->irq);
  1151. return 0;
  1152. bad4:
  1153. ath_detach(sc);
  1154. bad3:
  1155. ieee80211_free_hw(hw);
  1156. bad2:
  1157. pci_iounmap(pdev, mem);
  1158. bad1:
  1159. pci_release_region(pdev, 0);
  1160. bad:
  1161. pci_disable_device(pdev);
  1162. return ret;
  1163. }
  1164. static void ath_pci_remove(struct pci_dev *pdev)
  1165. {
  1166. struct ieee80211_hw *hw = pci_get_drvdata(pdev);
  1167. struct ath_softc *sc = hw->priv;
  1168. if (pdev->irq)
  1169. free_irq(pdev->irq, sc);
  1170. ath_detach(sc);
  1171. pci_iounmap(pdev, sc->mem);
  1172. pci_release_region(pdev, 0);
  1173. pci_disable_device(pdev);
  1174. ieee80211_free_hw(hw);
  1175. }
  1176. #ifdef CONFIG_PM
  1177. static int ath_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  1178. {
  1179. pci_save_state(pdev);
  1180. pci_disable_device(pdev);
  1181. pci_set_power_state(pdev, 3);
  1182. return 0;
  1183. }
  1184. static int ath_pci_resume(struct pci_dev *pdev)
  1185. {
  1186. u32 val;
  1187. int err;
  1188. err = pci_enable_device(pdev);
  1189. if (err)
  1190. return err;
  1191. pci_restore_state(pdev);
  1192. /*
  1193. * Suspend/Resume resets the PCI configuration space, so we have to
  1194. * re-disable the RETRY_TIMEOUT register (0x41) to keep
  1195. * PCI Tx retries from interfering with C3 CPU state
  1196. */
  1197. pci_read_config_dword(pdev, 0x40, &val);
  1198. if ((val & 0x0000ff00) != 0)
  1199. pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
  1200. return 0;
  1201. }
  1202. #endif /* CONFIG_PM */
  1203. MODULE_DEVICE_TABLE(pci, ath_pci_id_table);
  1204. static struct pci_driver ath_pci_driver = {
  1205. .name = "ath9k",
  1206. .id_table = ath_pci_id_table,
  1207. .probe = ath_pci_probe,
  1208. .remove = ath_pci_remove,
  1209. #ifdef CONFIG_PM
  1210. .suspend = ath_pci_suspend,
  1211. .resume = ath_pci_resume,
  1212. #endif /* CONFIG_PM */
  1213. };
  1214. static int __init init_ath_pci(void)
  1215. {
  1216. printk(KERN_INFO "%s: %s\n", dev_info, ATH_PCI_VERSION);
  1217. if (pci_register_driver(&ath_pci_driver) < 0) {
  1218. printk(KERN_ERR
  1219. "ath_pci: No devices found, driver not installed.\n");
  1220. pci_unregister_driver(&ath_pci_driver);
  1221. return -ENODEV;
  1222. }
  1223. return 0;
  1224. }
  1225. module_init(init_ath_pci);
  1226. static void __exit exit_ath_pci(void)
  1227. {
  1228. pci_unregister_driver(&ath_pci_driver);
  1229. printk(KERN_INFO "%s: driver unloaded\n", dev_info);
  1230. }
  1231. module_exit(exit_ath_pci);