4965-mac.c 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/init.h>
  33. #include <linux/pci.h>
  34. #include <linux/pci-aspm.h>
  35. #include <linux/slab.h>
  36. #include <linux/dma-mapping.h>
  37. #include <linux/delay.h>
  38. #include <linux/sched.h>
  39. #include <linux/skbuff.h>
  40. #include <linux/netdevice.h>
  41. #include <linux/firmware.h>
  42. #include <linux/etherdevice.h>
  43. #include <linux/if_arp.h>
  44. #include <net/mac80211.h>
  45. #include <asm/div64.h>
  46. #define DRV_NAME "iwl4965"
  47. #include "iwl-eeprom.h"
  48. #include "iwl-dev.h"
  49. #include "iwl-core.h"
  50. #include "iwl-io.h"
  51. #include "iwl-helpers.h"
  52. #include "iwl-sta.h"
  53. #include "iwl-4965-calib.h"
  54. #include "iwl-4965.h"
  55. /******************************************************************************
  56. *
  57. * module boiler plate
  58. *
  59. ******************************************************************************/
  60. /*
  61. * module name, copyright, version, etc.
  62. */
  63. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi 4965 driver for Linux"
  64. #ifdef CONFIG_IWLEGACY_DEBUG
  65. #define VD "d"
  66. #else
  67. #define VD
  68. #endif
  69. #define DRV_VERSION IWLWIFI_VERSION VD
  70. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  71. MODULE_VERSION(DRV_VERSION);
  72. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  73. MODULE_LICENSE("GPL");
  74. MODULE_ALIAS("iwl4965");
  75. void il4965_update_chain_flags(struct il_priv *il)
  76. {
  77. if (il->cfg->ops->hcmd->set_rxon_chain) {
  78. il->cfg->ops->hcmd->set_rxon_chain(il, &il->ctx);
  79. if (il->ctx.active.rx_chain != il->ctx.staging.rx_chain)
  80. il_commit_rxon(il, &il->ctx);
  81. }
  82. }
  83. static void il4965_clear_free_frames(struct il_priv *il)
  84. {
  85. struct list_head *element;
  86. D_INFO("%d frames on pre-allocated heap on clear.\n",
  87. il->frames_count);
  88. while (!list_empty(&il->free_frames)) {
  89. element = il->free_frames.next;
  90. list_del(element);
  91. kfree(list_entry(element, struct il_frame, list));
  92. il->frames_count--;
  93. }
  94. if (il->frames_count) {
  95. IL_WARN("%d frames still in use. Did we lose one?\n",
  96. il->frames_count);
  97. il->frames_count = 0;
  98. }
  99. }
  100. static struct il_frame *il4965_get_free_frame(struct il_priv *il)
  101. {
  102. struct il_frame *frame;
  103. struct list_head *element;
  104. if (list_empty(&il->free_frames)) {
  105. frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  106. if (!frame) {
  107. IL_ERR("Could not allocate frame!\n");
  108. return NULL;
  109. }
  110. il->frames_count++;
  111. return frame;
  112. }
  113. element = il->free_frames.next;
  114. list_del(element);
  115. return list_entry(element, struct il_frame, list);
  116. }
  117. static void il4965_free_frame(struct il_priv *il, struct il_frame *frame)
  118. {
  119. memset(frame, 0, sizeof(*frame));
  120. list_add(&frame->list, &il->free_frames);
  121. }
  122. static u32 il4965_fill_beacon_frame(struct il_priv *il,
  123. struct ieee80211_hdr *hdr,
  124. int left)
  125. {
  126. lockdep_assert_held(&il->mutex);
  127. if (!il->beacon_skb)
  128. return 0;
  129. if (il->beacon_skb->len > left)
  130. return 0;
  131. memcpy(hdr, il->beacon_skb->data, il->beacon_skb->len);
  132. return il->beacon_skb->len;
  133. }
  134. /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
  135. static void il4965_set_beacon_tim(struct il_priv *il,
  136. struct il_tx_beacon_cmd *tx_beacon_cmd,
  137. u8 *beacon, u32 frame_size)
  138. {
  139. u16 tim_idx;
  140. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
  141. /*
  142. * The idx is relative to frame start but we start looking at the
  143. * variable-length part of the beacon.
  144. */
  145. tim_idx = mgmt->u.beacon.variable - beacon;
  146. /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
  147. while ((tim_idx < (frame_size - 2)) &&
  148. (beacon[tim_idx] != WLAN_EID_TIM))
  149. tim_idx += beacon[tim_idx+1] + 2;
  150. /* If TIM field was found, set variables */
  151. if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
  152. tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
  153. tx_beacon_cmd->tim_size = beacon[tim_idx+1];
  154. } else
  155. IL_WARN("Unable to find TIM Element in beacon\n");
  156. }
  157. static unsigned int il4965_hw_get_beacon_cmd(struct il_priv *il,
  158. struct il_frame *frame)
  159. {
  160. struct il_tx_beacon_cmd *tx_beacon_cmd;
  161. u32 frame_size;
  162. u32 rate_flags;
  163. u32 rate;
  164. /*
  165. * We have to set up the TX command, the TX Beacon command, and the
  166. * beacon contents.
  167. */
  168. lockdep_assert_held(&il->mutex);
  169. if (!il->beacon_ctx) {
  170. IL_ERR("trying to build beacon w/o beacon context!\n");
  171. return 0;
  172. }
  173. /* Initialize memory */
  174. tx_beacon_cmd = &frame->u.beacon;
  175. memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
  176. /* Set up TX beacon contents */
  177. frame_size = il4965_fill_beacon_frame(il, tx_beacon_cmd->frame,
  178. sizeof(frame->u) - sizeof(*tx_beacon_cmd));
  179. if (WARN_ON_ONCE(frame_size > MAX_MPDU_SIZE))
  180. return 0;
  181. if (!frame_size)
  182. return 0;
  183. /* Set up TX command fields */
  184. tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
  185. tx_beacon_cmd->tx.sta_id = il->beacon_ctx->bcast_sta_id;
  186. tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  187. tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
  188. TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
  189. /* Set up TX beacon command fields */
  190. il4965_set_beacon_tim(il, tx_beacon_cmd, (u8 *)tx_beacon_cmd->frame,
  191. frame_size);
  192. /* Set up packet rate and flags */
  193. rate = il_get_lowest_plcp(il, il->beacon_ctx);
  194. il->mgmt_tx_ant = il4965_toggle_tx_ant(il, il->mgmt_tx_ant,
  195. il->hw_params.valid_tx_ant);
  196. rate_flags = il4965_ant_idx_to_flags(il->mgmt_tx_ant);
  197. if ((rate >= IL_FIRST_CCK_RATE) && (rate <= IL_LAST_CCK_RATE))
  198. rate_flags |= RATE_MCS_CCK_MSK;
  199. tx_beacon_cmd->tx.rate_n_flags = il4965_hw_set_rate_n_flags(rate,
  200. rate_flags);
  201. return sizeof(*tx_beacon_cmd) + frame_size;
  202. }
  203. int il4965_send_beacon_cmd(struct il_priv *il)
  204. {
  205. struct il_frame *frame;
  206. unsigned int frame_size;
  207. int rc;
  208. frame = il4965_get_free_frame(il);
  209. if (!frame) {
  210. IL_ERR("Could not obtain free frame buffer for beacon "
  211. "command.\n");
  212. return -ENOMEM;
  213. }
  214. frame_size = il4965_hw_get_beacon_cmd(il, frame);
  215. if (!frame_size) {
  216. IL_ERR("Error configuring the beacon command\n");
  217. il4965_free_frame(il, frame);
  218. return -EINVAL;
  219. }
  220. rc = il_send_cmd_pdu(il, REPLY_TX_BEACON, frame_size,
  221. &frame->u.cmd[0]);
  222. il4965_free_frame(il, frame);
  223. return rc;
  224. }
  225. static inline dma_addr_t il4965_tfd_tb_get_addr(struct il_tfd *tfd, u8 idx)
  226. {
  227. struct il_tfd_tb *tb = &tfd->tbs[idx];
  228. dma_addr_t addr = get_unaligned_le32(&tb->lo);
  229. if (sizeof(dma_addr_t) > sizeof(u32))
  230. addr |=
  231. ((dma_addr_t)(le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << 16;
  232. return addr;
  233. }
  234. static inline u16 il4965_tfd_tb_get_len(struct il_tfd *tfd, u8 idx)
  235. {
  236. struct il_tfd_tb *tb = &tfd->tbs[idx];
  237. return le16_to_cpu(tb->hi_n_len) >> 4;
  238. }
  239. static inline void il4965_tfd_set_tb(struct il_tfd *tfd, u8 idx,
  240. dma_addr_t addr, u16 len)
  241. {
  242. struct il_tfd_tb *tb = &tfd->tbs[idx];
  243. u16 hi_n_len = len << 4;
  244. put_unaligned_le32(addr, &tb->lo);
  245. if (sizeof(dma_addr_t) > sizeof(u32))
  246. hi_n_len |= ((addr >> 16) >> 16) & 0xF;
  247. tb->hi_n_len = cpu_to_le16(hi_n_len);
  248. tfd->num_tbs = idx + 1;
  249. }
  250. static inline u8 il4965_tfd_get_num_tbs(struct il_tfd *tfd)
  251. {
  252. return tfd->num_tbs & 0x1f;
  253. }
  254. /**
  255. * il4965_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
  256. * @il - driver ilate data
  257. * @txq - tx queue
  258. *
  259. * Does NOT advance any TFD circular buffer read/write idxes
  260. * Does NOT free the TFD itself (which is within circular buffer)
  261. */
  262. void il4965_hw_txq_free_tfd(struct il_priv *il, struct il_tx_queue *txq)
  263. {
  264. struct il_tfd *tfd_tmp = (struct il_tfd *)txq->tfds;
  265. struct il_tfd *tfd;
  266. struct pci_dev *dev = il->pci_dev;
  267. int idx = txq->q.read_ptr;
  268. int i;
  269. int num_tbs;
  270. tfd = &tfd_tmp[idx];
  271. /* Sanity check on number of chunks */
  272. num_tbs = il4965_tfd_get_num_tbs(tfd);
  273. if (num_tbs >= IL_NUM_OF_TBS) {
  274. IL_ERR("Too many chunks: %i\n", num_tbs);
  275. /* @todo issue fatal error, it is quite serious situation */
  276. return;
  277. }
  278. /* Unmap tx_cmd */
  279. if (num_tbs)
  280. pci_unmap_single(dev,
  281. dma_unmap_addr(&txq->meta[idx], mapping),
  282. dma_unmap_len(&txq->meta[idx], len),
  283. PCI_DMA_BIDIRECTIONAL);
  284. /* Unmap chunks, if any. */
  285. for (i = 1; i < num_tbs; i++)
  286. pci_unmap_single(dev, il4965_tfd_tb_get_addr(tfd, i),
  287. il4965_tfd_tb_get_len(tfd, i),
  288. PCI_DMA_TODEVICE);
  289. /* free SKB */
  290. if (txq->txb) {
  291. struct sk_buff *skb;
  292. skb = txq->txb[txq->q.read_ptr].skb;
  293. /* can be called from irqs-disabled context */
  294. if (skb) {
  295. dev_kfree_skb_any(skb);
  296. txq->txb[txq->q.read_ptr].skb = NULL;
  297. }
  298. }
  299. }
  300. int il4965_hw_txq_attach_buf_to_tfd(struct il_priv *il,
  301. struct il_tx_queue *txq,
  302. dma_addr_t addr, u16 len,
  303. u8 reset, u8 pad)
  304. {
  305. struct il_queue *q;
  306. struct il_tfd *tfd, *tfd_tmp;
  307. u32 num_tbs;
  308. q = &txq->q;
  309. tfd_tmp = (struct il_tfd *)txq->tfds;
  310. tfd = &tfd_tmp[q->write_ptr];
  311. if (reset)
  312. memset(tfd, 0, sizeof(*tfd));
  313. num_tbs = il4965_tfd_get_num_tbs(tfd);
  314. /* Each TFD can point to a maximum 20 Tx buffers */
  315. if (num_tbs >= IL_NUM_OF_TBS) {
  316. IL_ERR("Error can not send more than %d chunks\n",
  317. IL_NUM_OF_TBS);
  318. return -EINVAL;
  319. }
  320. BUG_ON(addr & ~DMA_BIT_MASK(36));
  321. if (unlikely(addr & ~IL_TX_DMA_MASK))
  322. IL_ERR("Unaligned address = %llx\n",
  323. (unsigned long long)addr);
  324. il4965_tfd_set_tb(tfd, num_tbs, addr, len);
  325. return 0;
  326. }
  327. /*
  328. * Tell nic where to find circular buffer of Tx Frame Descriptors for
  329. * given Tx queue, and enable the DMA channel used for that queue.
  330. *
  331. * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
  332. * channels supported in hardware.
  333. */
  334. int il4965_hw_tx_queue_init(struct il_priv *il,
  335. struct il_tx_queue *txq)
  336. {
  337. int txq_id = txq->q.id;
  338. /* Circular buffer (TFD queue in DRAM) physical base address */
  339. il_wr(il, FH_MEM_CBBC_QUEUE(txq_id),
  340. txq->q.dma_addr >> 8);
  341. return 0;
  342. }
  343. /******************************************************************************
  344. *
  345. * Generic RX handler implementations
  346. *
  347. ******************************************************************************/
  348. static void il4965_rx_reply_alive(struct il_priv *il,
  349. struct il_rx_buf *rxb)
  350. {
  351. struct il_rx_pkt *pkt = rxb_addr(rxb);
  352. struct il_alive_resp *palive;
  353. struct delayed_work *pwork;
  354. palive = &pkt->u.alive_frame;
  355. D_INFO("Alive ucode status 0x%08X revision "
  356. "0x%01X 0x%01X\n",
  357. palive->is_valid, palive->ver_type,
  358. palive->ver_subtype);
  359. if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
  360. D_INFO("Initialization Alive received.\n");
  361. memcpy(&il->card_alive_init,
  362. &pkt->u.alive_frame,
  363. sizeof(struct il_init_alive_resp));
  364. pwork = &il->init_alive_start;
  365. } else {
  366. D_INFO("Runtime Alive received.\n");
  367. memcpy(&il->card_alive, &pkt->u.alive_frame,
  368. sizeof(struct il_alive_resp));
  369. pwork = &il->alive_start;
  370. }
  371. /* We delay the ALIVE response by 5ms to
  372. * give the HW RF Kill time to activate... */
  373. if (palive->is_valid == UCODE_VALID_OK)
  374. queue_delayed_work(il->workqueue, pwork,
  375. msecs_to_jiffies(5));
  376. else
  377. IL_WARN("uCode did not respond OK.\n");
  378. }
  379. /**
  380. * il4965_bg_stats_periodic - Timer callback to queue stats
  381. *
  382. * This callback is provided in order to send a stats request.
  383. *
  384. * This timer function is continually reset to execute within
  385. * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
  386. * was received. We need to ensure we receive the stats in order
  387. * to update the temperature used for calibrating the TXPOWER.
  388. */
  389. static void il4965_bg_stats_periodic(unsigned long data)
  390. {
  391. struct il_priv *il = (struct il_priv *)data;
  392. if (test_bit(STATUS_EXIT_PENDING, &il->status))
  393. return;
  394. /* dont send host command if rf-kill is on */
  395. if (!il_is_ready_rf(il))
  396. return;
  397. il_send_stats_request(il, CMD_ASYNC, false);
  398. }
  399. static void il4965_rx_beacon_notif(struct il_priv *il,
  400. struct il_rx_buf *rxb)
  401. {
  402. struct il_rx_pkt *pkt = rxb_addr(rxb);
  403. struct il4965_beacon_notif *beacon =
  404. (struct il4965_beacon_notif *)pkt->u.raw;
  405. #ifdef CONFIG_IWLEGACY_DEBUG
  406. u8 rate = il4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
  407. D_RX("beacon status %x retries %d iss %d "
  408. "tsf %d %d rate %d\n",
  409. le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
  410. beacon->beacon_notify_hdr.failure_frame,
  411. le32_to_cpu(beacon->ibss_mgr_status),
  412. le32_to_cpu(beacon->high_tsf),
  413. le32_to_cpu(beacon->low_tsf), rate);
  414. #endif
  415. il->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
  416. }
  417. static void il4965_perform_ct_kill_task(struct il_priv *il)
  418. {
  419. unsigned long flags;
  420. D_POWER("Stop all queues\n");
  421. if (il->mac80211_registered)
  422. ieee80211_stop_queues(il->hw);
  423. _il_wr(il, CSR_UCODE_DRV_GP1_SET,
  424. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  425. _il_rd(il, CSR_UCODE_DRV_GP1);
  426. spin_lock_irqsave(&il->reg_lock, flags);
  427. if (!_il_grab_nic_access(il))
  428. _il_release_nic_access(il);
  429. spin_unlock_irqrestore(&il->reg_lock, flags);
  430. }
  431. /* Handle notification from uCode that card's power state is changing
  432. * due to software, hardware, or critical temperature RFKILL */
  433. static void il4965_rx_card_state_notif(struct il_priv *il,
  434. struct il_rx_buf *rxb)
  435. {
  436. struct il_rx_pkt *pkt = rxb_addr(rxb);
  437. u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
  438. unsigned long status = il->status;
  439. D_RF_KILL("Card state received: HW:%s SW:%s CT:%s\n",
  440. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  441. (flags & SW_CARD_DISABLED) ? "Kill" : "On",
  442. (flags & CT_CARD_DISABLED) ?
  443. "Reached" : "Not reached");
  444. if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
  445. CT_CARD_DISABLED)) {
  446. _il_wr(il, CSR_UCODE_DRV_GP1_SET,
  447. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  448. il_wr(il, HBUS_TARG_MBX_C,
  449. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  450. if (!(flags & RXON_CARD_DISABLED)) {
  451. _il_wr(il, CSR_UCODE_DRV_GP1_CLR,
  452. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  453. il_wr(il, HBUS_TARG_MBX_C,
  454. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  455. }
  456. }
  457. if (flags & CT_CARD_DISABLED)
  458. il4965_perform_ct_kill_task(il);
  459. if (flags & HW_CARD_DISABLED)
  460. set_bit(STATUS_RF_KILL_HW, &il->status);
  461. else
  462. clear_bit(STATUS_RF_KILL_HW, &il->status);
  463. if (!(flags & RXON_CARD_DISABLED))
  464. il_scan_cancel(il);
  465. if ((test_bit(STATUS_RF_KILL_HW, &status) !=
  466. test_bit(STATUS_RF_KILL_HW, &il->status)))
  467. wiphy_rfkill_set_hw_state(il->hw->wiphy,
  468. test_bit(STATUS_RF_KILL_HW, &il->status));
  469. else
  470. wake_up(&il->wait_command_queue);
  471. }
  472. /**
  473. * il4965_setup_rx_handlers - Initialize Rx handler callbacks
  474. *
  475. * Setup the RX handlers for each of the reply types sent from the uCode
  476. * to the host.
  477. *
  478. * This function chains into the hardware specific files for them to setup
  479. * any hardware specific handlers as well.
  480. */
  481. static void il4965_setup_rx_handlers(struct il_priv *il)
  482. {
  483. il->rx_handlers[REPLY_ALIVE] = il4965_rx_reply_alive;
  484. il->rx_handlers[REPLY_ERROR] = il_rx_reply_error;
  485. il->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = il_rx_csa;
  486. il->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
  487. il_rx_spectrum_measure_notif;
  488. il->rx_handlers[PM_SLEEP_NOTIFICATION] = il_rx_pm_sleep_notif;
  489. il->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
  490. il_rx_pm_debug_stats_notif;
  491. il->rx_handlers[BEACON_NOTIFICATION] = il4965_rx_beacon_notif;
  492. /*
  493. * The same handler is used for both the REPLY to a discrete
  494. * stats request from the host as well as for the periodic
  495. * stats notifications (after received beacons) from the uCode.
  496. */
  497. il->rx_handlers[REPLY_STATISTICS_CMD] = il4965_reply_stats;
  498. il->rx_handlers[STATISTICS_NOTIFICATION] = il4965_rx_stats;
  499. il_setup_rx_scan_handlers(il);
  500. /* status change handler */
  501. il->rx_handlers[CARD_STATE_NOTIFICATION] =
  502. il4965_rx_card_state_notif;
  503. il->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
  504. il4965_rx_missed_beacon_notif;
  505. /* Rx handlers */
  506. il->rx_handlers[REPLY_RX_PHY_CMD] = il4965_rx_reply_rx_phy;
  507. il->rx_handlers[REPLY_RX_MPDU_CMD] = il4965_rx_reply_rx;
  508. /* block ack */
  509. il->rx_handlers[REPLY_COMPRESSED_BA] = il4965_rx_reply_compressed_ba;
  510. /* Set up hardware specific Rx handlers */
  511. il->cfg->ops->lib->rx_handler_setup(il);
  512. }
  513. /**
  514. * il4965_rx_handle - Main entry function for receiving responses from uCode
  515. *
  516. * Uses the il->rx_handlers callback function array to invoke
  517. * the appropriate handlers, including command responses,
  518. * frame-received notifications, and other notifications.
  519. */
  520. void il4965_rx_handle(struct il_priv *il)
  521. {
  522. struct il_rx_buf *rxb;
  523. struct il_rx_pkt *pkt;
  524. struct il_rx_queue *rxq = &il->rxq;
  525. u32 r, i;
  526. int reclaim;
  527. unsigned long flags;
  528. u8 fill_rx = 0;
  529. u32 count = 8;
  530. int total_empty;
  531. /* uCode's read idx (stored in shared DRAM) indicates the last Rx
  532. * buffer that the driver may process (last buffer filled by ucode). */
  533. r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
  534. i = rxq->read;
  535. /* Rx interrupt, but nothing sent from uCode */
  536. if (i == r)
  537. D_RX("r = %d, i = %d\n", r, i);
  538. /* calculate total frames need to be restock after handling RX */
  539. total_empty = r - rxq->write_actual;
  540. if (total_empty < 0)
  541. total_empty += RX_QUEUE_SIZE;
  542. if (total_empty > (RX_QUEUE_SIZE / 2))
  543. fill_rx = 1;
  544. while (i != r) {
  545. int len;
  546. rxb = rxq->queue[i];
  547. /* If an RXB doesn't have a Rx queue slot associated with it,
  548. * then a bug has been introduced in the queue refilling
  549. * routines -- catch it here */
  550. BUG_ON(rxb == NULL);
  551. rxq->queue[i] = NULL;
  552. pci_unmap_page(il->pci_dev, rxb->page_dma,
  553. PAGE_SIZE << il->hw_params.rx_page_order,
  554. PCI_DMA_FROMDEVICE);
  555. pkt = rxb_addr(rxb);
  556. len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  557. len += sizeof(u32); /* account for status word */
  558. /* Reclaim a command buffer only if this packet is a response
  559. * to a (driver-originated) command.
  560. * If the packet (e.g. Rx frame) originated from uCode,
  561. * there is no command buffer to reclaim.
  562. * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
  563. * but apparently a few don't get set; catch them here. */
  564. reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
  565. (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
  566. (pkt->hdr.cmd != REPLY_RX) &&
  567. (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) &&
  568. (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
  569. (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
  570. (pkt->hdr.cmd != REPLY_TX);
  571. /* Based on type of command response or notification,
  572. * handle those that need handling via function in
  573. * rx_handlers table. See il4965_setup_rx_handlers() */
  574. if (il->rx_handlers[pkt->hdr.cmd]) {
  575. D_RX("r = %d, i = %d, %s, 0x%02x\n", r,
  576. i, il_get_cmd_string(pkt->hdr.cmd),
  577. pkt->hdr.cmd);
  578. il->isr_stats.rx_handlers[pkt->hdr.cmd]++;
  579. il->rx_handlers[pkt->hdr.cmd] (il, rxb);
  580. } else {
  581. /* No handling needed */
  582. D_RX(
  583. "r %d i %d No handler needed for %s, 0x%02x\n",
  584. r, i, il_get_cmd_string(pkt->hdr.cmd),
  585. pkt->hdr.cmd);
  586. }
  587. /*
  588. * XXX: After here, we should always check rxb->page
  589. * against NULL before touching it or its virtual
  590. * memory (pkt). Because some rx_handler might have
  591. * already taken or freed the pages.
  592. */
  593. if (reclaim) {
  594. /* Invoke any callbacks, transfer the buffer to caller,
  595. * and fire off the (possibly) blocking il_send_cmd()
  596. * as we reclaim the driver command queue */
  597. if (rxb->page)
  598. il_tx_cmd_complete(il, rxb);
  599. else
  600. IL_WARN("Claim null rxb?\n");
  601. }
  602. /* Reuse the page if possible. For notification packets and
  603. * SKBs that fail to Rx correctly, add them back into the
  604. * rx_free list for reuse later. */
  605. spin_lock_irqsave(&rxq->lock, flags);
  606. if (rxb->page != NULL) {
  607. rxb->page_dma = pci_map_page(il->pci_dev, rxb->page,
  608. 0, PAGE_SIZE << il->hw_params.rx_page_order,
  609. PCI_DMA_FROMDEVICE);
  610. list_add_tail(&rxb->list, &rxq->rx_free);
  611. rxq->free_count++;
  612. } else
  613. list_add_tail(&rxb->list, &rxq->rx_used);
  614. spin_unlock_irqrestore(&rxq->lock, flags);
  615. i = (i + 1) & RX_QUEUE_MASK;
  616. /* If there are a lot of unused frames,
  617. * restock the Rx queue so ucode wont assert. */
  618. if (fill_rx) {
  619. count++;
  620. if (count >= 8) {
  621. rxq->read = i;
  622. il4965_rx_replenish_now(il);
  623. count = 0;
  624. }
  625. }
  626. }
  627. /* Backtrack one entry */
  628. rxq->read = i;
  629. if (fill_rx)
  630. il4965_rx_replenish_now(il);
  631. else
  632. il4965_rx_queue_restock(il);
  633. }
  634. /* call this function to flush any scheduled tasklet */
  635. static inline void il4965_synchronize_irq(struct il_priv *il)
  636. {
  637. /* wait to make sure we flush pending tasklet*/
  638. synchronize_irq(il->pci_dev->irq);
  639. tasklet_kill(&il->irq_tasklet);
  640. }
  641. static void il4965_irq_tasklet(struct il_priv *il)
  642. {
  643. u32 inta, handled = 0;
  644. u32 inta_fh;
  645. unsigned long flags;
  646. u32 i;
  647. #ifdef CONFIG_IWLEGACY_DEBUG
  648. u32 inta_mask;
  649. #endif
  650. spin_lock_irqsave(&il->lock, flags);
  651. /* Ack/clear/reset pending uCode interrupts.
  652. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  653. * and will clear only when CSR_FH_INT_STATUS gets cleared. */
  654. inta = _il_rd(il, CSR_INT);
  655. _il_wr(il, CSR_INT, inta);
  656. /* Ack/clear/reset pending flow-handler (DMA) interrupts.
  657. * Any new interrupts that happen after this, either while we're
  658. * in this tasklet, or later, will show up in next ISR/tasklet. */
  659. inta_fh = _il_rd(il, CSR_FH_INT_STATUS);
  660. _il_wr(il, CSR_FH_INT_STATUS, inta_fh);
  661. #ifdef CONFIG_IWLEGACY_DEBUG
  662. if (il_get_debug_level(il) & IL_DL_ISR) {
  663. /* just for debug */
  664. inta_mask = _il_rd(il, CSR_INT_MASK);
  665. D_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  666. inta, inta_mask, inta_fh);
  667. }
  668. #endif
  669. spin_unlock_irqrestore(&il->lock, flags);
  670. /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
  671. * atomic, make sure that inta covers all the interrupts that
  672. * we've discovered, even if FH interrupt came in just after
  673. * reading CSR_INT. */
  674. if (inta_fh & CSR49_FH_INT_RX_MASK)
  675. inta |= CSR_INT_BIT_FH_RX;
  676. if (inta_fh & CSR49_FH_INT_TX_MASK)
  677. inta |= CSR_INT_BIT_FH_TX;
  678. /* Now service all interrupt bits discovered above. */
  679. if (inta & CSR_INT_BIT_HW_ERR) {
  680. IL_ERR("Hardware error detected. Restarting.\n");
  681. /* Tell the device to stop sending interrupts */
  682. il_disable_interrupts(il);
  683. il->isr_stats.hw++;
  684. il_irq_handle_error(il);
  685. handled |= CSR_INT_BIT_HW_ERR;
  686. return;
  687. }
  688. #ifdef CONFIG_IWLEGACY_DEBUG
  689. if (il_get_debug_level(il) & (IL_DL_ISR)) {
  690. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  691. if (inta & CSR_INT_BIT_SCD) {
  692. D_ISR("Scheduler finished to transmit "
  693. "the frame/frames.\n");
  694. il->isr_stats.sch++;
  695. }
  696. /* Alive notification via Rx interrupt will do the real work */
  697. if (inta & CSR_INT_BIT_ALIVE) {
  698. D_ISR("Alive interrupt\n");
  699. il->isr_stats.alive++;
  700. }
  701. }
  702. #endif
  703. /* Safely ignore these bits for debug checks below */
  704. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  705. /* HW RF KILL switch toggled */
  706. if (inta & CSR_INT_BIT_RF_KILL) {
  707. int hw_rf_kill = 0;
  708. if (!(_il_rd(il, CSR_GP_CNTRL) &
  709. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  710. hw_rf_kill = 1;
  711. IL_WARN("RF_KILL bit toggled to %s.\n",
  712. hw_rf_kill ? "disable radio" : "enable radio");
  713. il->isr_stats.rfkill++;
  714. /* driver only loads ucode once setting the interface up.
  715. * the driver allows loading the ucode even if the radio
  716. * is killed. Hence update the killswitch state here. The
  717. * rfkill handler will care about restarting if needed.
  718. */
  719. if (!test_bit(STATUS_ALIVE, &il->status)) {
  720. if (hw_rf_kill)
  721. set_bit(STATUS_RF_KILL_HW, &il->status);
  722. else
  723. clear_bit(STATUS_RF_KILL_HW, &il->status);
  724. wiphy_rfkill_set_hw_state(il->hw->wiphy, hw_rf_kill);
  725. }
  726. handled |= CSR_INT_BIT_RF_KILL;
  727. }
  728. /* Chip got too hot and stopped itself */
  729. if (inta & CSR_INT_BIT_CT_KILL) {
  730. IL_ERR("Microcode CT kill error detected.\n");
  731. il->isr_stats.ctkill++;
  732. handled |= CSR_INT_BIT_CT_KILL;
  733. }
  734. /* Error detected by uCode */
  735. if (inta & CSR_INT_BIT_SW_ERR) {
  736. IL_ERR("Microcode SW error detected. "
  737. " Restarting 0x%X.\n", inta);
  738. il->isr_stats.sw++;
  739. il_irq_handle_error(il);
  740. handled |= CSR_INT_BIT_SW_ERR;
  741. }
  742. /*
  743. * uCode wakes up after power-down sleep.
  744. * Tell device about any new tx or host commands enqueued,
  745. * and about any Rx buffers made available while asleep.
  746. */
  747. if (inta & CSR_INT_BIT_WAKEUP) {
  748. D_ISR("Wakeup interrupt\n");
  749. il_rx_queue_update_write_ptr(il, &il->rxq);
  750. for (i = 0; i < il->hw_params.max_txq_num; i++)
  751. il_txq_update_write_ptr(il, &il->txq[i]);
  752. il->isr_stats.wakeup++;
  753. handled |= CSR_INT_BIT_WAKEUP;
  754. }
  755. /* All uCode command responses, including Tx command responses,
  756. * Rx "responses" (frame-received notification), and other
  757. * notifications from uCode come through here*/
  758. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  759. il4965_rx_handle(il);
  760. il->isr_stats.rx++;
  761. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  762. }
  763. /* This "Tx" DMA channel is used only for loading uCode */
  764. if (inta & CSR_INT_BIT_FH_TX) {
  765. D_ISR("uCode load interrupt\n");
  766. il->isr_stats.tx++;
  767. handled |= CSR_INT_BIT_FH_TX;
  768. /* Wake up uCode load routine, now that load is complete */
  769. il->ucode_write_complete = 1;
  770. wake_up(&il->wait_command_queue);
  771. }
  772. if (inta & ~handled) {
  773. IL_ERR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
  774. il->isr_stats.unhandled++;
  775. }
  776. if (inta & ~(il->inta_mask)) {
  777. IL_WARN("Disabled INTA bits 0x%08x were pending\n",
  778. inta & ~il->inta_mask);
  779. IL_WARN(" with FH_INT = 0x%08x\n", inta_fh);
  780. }
  781. /* Re-enable all interrupts */
  782. /* only Re-enable if disabled by irq */
  783. if (test_bit(STATUS_INT_ENABLED, &il->status))
  784. il_enable_interrupts(il);
  785. /* Re-enable RF_KILL if it occurred */
  786. else if (handled & CSR_INT_BIT_RF_KILL)
  787. il_enable_rfkill_int(il);
  788. #ifdef CONFIG_IWLEGACY_DEBUG
  789. if (il_get_debug_level(il) & (IL_DL_ISR)) {
  790. inta = _il_rd(il, CSR_INT);
  791. inta_mask = _il_rd(il, CSR_INT_MASK);
  792. inta_fh = _il_rd(il, CSR_FH_INT_STATUS);
  793. D_ISR(
  794. "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
  795. "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
  796. }
  797. #endif
  798. }
  799. /*****************************************************************************
  800. *
  801. * sysfs attributes
  802. *
  803. *****************************************************************************/
  804. #ifdef CONFIG_IWLEGACY_DEBUG
  805. /*
  806. * The following adds a new attribute to the sysfs representation
  807. * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
  808. * used for controlling the debug level.
  809. *
  810. * See the level definitions in iwl for details.
  811. *
  812. * The debug_level being managed using sysfs below is a per device debug
  813. * level that is used instead of the global debug level if it (the per
  814. * device debug level) is set.
  815. */
  816. static ssize_t il4965_show_debug_level(struct device *d,
  817. struct device_attribute *attr, char *buf)
  818. {
  819. struct il_priv *il = dev_get_drvdata(d);
  820. return sprintf(buf, "0x%08X\n", il_get_debug_level(il));
  821. }
  822. static ssize_t il4965_store_debug_level(struct device *d,
  823. struct device_attribute *attr,
  824. const char *buf, size_t count)
  825. {
  826. struct il_priv *il = dev_get_drvdata(d);
  827. unsigned long val;
  828. int ret;
  829. ret = strict_strtoul(buf, 0, &val);
  830. if (ret)
  831. IL_ERR("%s is not in hex or decimal form.\n", buf);
  832. else {
  833. il->debug_level = val;
  834. if (il_alloc_traffic_mem(il))
  835. IL_ERR(
  836. "Not enough memory to generate traffic log\n");
  837. }
  838. return strnlen(buf, count);
  839. }
  840. static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
  841. il4965_show_debug_level, il4965_store_debug_level);
  842. #endif /* CONFIG_IWLEGACY_DEBUG */
  843. static ssize_t il4965_show_temperature(struct device *d,
  844. struct device_attribute *attr, char *buf)
  845. {
  846. struct il_priv *il = dev_get_drvdata(d);
  847. if (!il_is_alive(il))
  848. return -EAGAIN;
  849. return sprintf(buf, "%d\n", il->temperature);
  850. }
  851. static DEVICE_ATTR(temperature, S_IRUGO, il4965_show_temperature, NULL);
  852. static ssize_t il4965_show_tx_power(struct device *d,
  853. struct device_attribute *attr, char *buf)
  854. {
  855. struct il_priv *il = dev_get_drvdata(d);
  856. if (!il_is_ready_rf(il))
  857. return sprintf(buf, "off\n");
  858. else
  859. return sprintf(buf, "%d\n", il->tx_power_user_lmt);
  860. }
  861. static ssize_t il4965_store_tx_power(struct device *d,
  862. struct device_attribute *attr,
  863. const char *buf, size_t count)
  864. {
  865. struct il_priv *il = dev_get_drvdata(d);
  866. unsigned long val;
  867. int ret;
  868. ret = strict_strtoul(buf, 10, &val);
  869. if (ret)
  870. IL_INFO("%s is not in decimal form.\n", buf);
  871. else {
  872. ret = il_set_tx_power(il, val, false);
  873. if (ret)
  874. IL_ERR("failed setting tx power (0x%d).\n",
  875. ret);
  876. else
  877. ret = count;
  878. }
  879. return ret;
  880. }
  881. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO,
  882. il4965_show_tx_power, il4965_store_tx_power);
  883. static struct attribute *il_sysfs_entries[] = {
  884. &dev_attr_temperature.attr,
  885. &dev_attr_tx_power.attr,
  886. #ifdef CONFIG_IWLEGACY_DEBUG
  887. &dev_attr_debug_level.attr,
  888. #endif
  889. NULL
  890. };
  891. static struct attribute_group il_attribute_group = {
  892. .name = NULL, /* put in device directory */
  893. .attrs = il_sysfs_entries,
  894. };
  895. /******************************************************************************
  896. *
  897. * uCode download functions
  898. *
  899. ******************************************************************************/
  900. static void il4965_dealloc_ucode_pci(struct il_priv *il)
  901. {
  902. il_free_fw_desc(il->pci_dev, &il->ucode_code);
  903. il_free_fw_desc(il->pci_dev, &il->ucode_data);
  904. il_free_fw_desc(il->pci_dev, &il->ucode_data_backup);
  905. il_free_fw_desc(il->pci_dev, &il->ucode_init);
  906. il_free_fw_desc(il->pci_dev, &il->ucode_init_data);
  907. il_free_fw_desc(il->pci_dev, &il->ucode_boot);
  908. }
  909. static void il4965_nic_start(struct il_priv *il)
  910. {
  911. /* Remove all resets to allow NIC to operate */
  912. _il_wr(il, CSR_RESET, 0);
  913. }
  914. static void il4965_ucode_callback(const struct firmware *ucode_raw,
  915. void *context);
  916. static int il4965_mac_setup_register(struct il_priv *il,
  917. u32 max_probe_length);
  918. static int __must_check il4965_request_firmware(struct il_priv *il, bool first)
  919. {
  920. const char *name_pre = il->cfg->fw_name_pre;
  921. char tag[8];
  922. if (first) {
  923. il->fw_idx = il->cfg->ucode_api_max;
  924. sprintf(tag, "%d", il->fw_idx);
  925. } else {
  926. il->fw_idx--;
  927. sprintf(tag, "%d", il->fw_idx);
  928. }
  929. if (il->fw_idx < il->cfg->ucode_api_min) {
  930. IL_ERR("no suitable firmware found!\n");
  931. return -ENOENT;
  932. }
  933. sprintf(il->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
  934. D_INFO("attempting to load firmware '%s'\n",
  935. il->firmware_name);
  936. return request_firmware_nowait(THIS_MODULE, 1, il->firmware_name,
  937. &il->pci_dev->dev, GFP_KERNEL, il,
  938. il4965_ucode_callback);
  939. }
  940. struct il4965_firmware_pieces {
  941. const void *inst, *data, *init, *init_data, *boot;
  942. size_t inst_size, data_size, init_size, init_data_size, boot_size;
  943. };
  944. static int il4965_load_firmware(struct il_priv *il,
  945. const struct firmware *ucode_raw,
  946. struct il4965_firmware_pieces *pieces)
  947. {
  948. struct il_ucode_header *ucode = (void *)ucode_raw->data;
  949. u32 api_ver, hdr_size;
  950. const u8 *src;
  951. il->ucode_ver = le32_to_cpu(ucode->ver);
  952. api_ver = IL_UCODE_API(il->ucode_ver);
  953. switch (api_ver) {
  954. default:
  955. case 0:
  956. case 1:
  957. case 2:
  958. hdr_size = 24;
  959. if (ucode_raw->size < hdr_size) {
  960. IL_ERR("File size too small!\n");
  961. return -EINVAL;
  962. }
  963. pieces->inst_size = le32_to_cpu(ucode->v1.inst_size);
  964. pieces->data_size = le32_to_cpu(ucode->v1.data_size);
  965. pieces->init_size = le32_to_cpu(ucode->v1.init_size);
  966. pieces->init_data_size =
  967. le32_to_cpu(ucode->v1.init_data_size);
  968. pieces->boot_size = le32_to_cpu(ucode->v1.boot_size);
  969. src = ucode->v1.data;
  970. break;
  971. }
  972. /* Verify size of file vs. image size info in file's header */
  973. if (ucode_raw->size != hdr_size + pieces->inst_size +
  974. pieces->data_size + pieces->init_size +
  975. pieces->init_data_size + pieces->boot_size) {
  976. IL_ERR(
  977. "uCode file size %d does not match expected size\n",
  978. (int)ucode_raw->size);
  979. return -EINVAL;
  980. }
  981. pieces->inst = src;
  982. src += pieces->inst_size;
  983. pieces->data = src;
  984. src += pieces->data_size;
  985. pieces->init = src;
  986. src += pieces->init_size;
  987. pieces->init_data = src;
  988. src += pieces->init_data_size;
  989. pieces->boot = src;
  990. src += pieces->boot_size;
  991. return 0;
  992. }
  993. /**
  994. * il4965_ucode_callback - callback when firmware was loaded
  995. *
  996. * If loaded successfully, copies the firmware into buffers
  997. * for the card to fetch (via DMA).
  998. */
  999. static void
  1000. il4965_ucode_callback(const struct firmware *ucode_raw, void *context)
  1001. {
  1002. struct il_priv *il = context;
  1003. struct il_ucode_header *ucode;
  1004. int err;
  1005. struct il4965_firmware_pieces pieces;
  1006. const unsigned int api_max = il->cfg->ucode_api_max;
  1007. const unsigned int api_min = il->cfg->ucode_api_min;
  1008. u32 api_ver;
  1009. u32 max_probe_length = 200;
  1010. u32 standard_phy_calibration_size =
  1011. IL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE;
  1012. memset(&pieces, 0, sizeof(pieces));
  1013. if (!ucode_raw) {
  1014. if (il->fw_idx <= il->cfg->ucode_api_max)
  1015. IL_ERR(
  1016. "request for firmware file '%s' failed.\n",
  1017. il->firmware_name);
  1018. goto try_again;
  1019. }
  1020. D_INFO("Loaded firmware file '%s' (%zd bytes).\n",
  1021. il->firmware_name, ucode_raw->size);
  1022. /* Make sure that we got at least the API version number */
  1023. if (ucode_raw->size < 4) {
  1024. IL_ERR("File size way too small!\n");
  1025. goto try_again;
  1026. }
  1027. /* Data from ucode file: header followed by uCode images */
  1028. ucode = (struct il_ucode_header *)ucode_raw->data;
  1029. err = il4965_load_firmware(il, ucode_raw, &pieces);
  1030. if (err)
  1031. goto try_again;
  1032. api_ver = IL_UCODE_API(il->ucode_ver);
  1033. /*
  1034. * api_ver should match the api version forming part of the
  1035. * firmware filename ... but we don't check for that and only rely
  1036. * on the API version read from firmware header from here on forward
  1037. */
  1038. if (api_ver < api_min || api_ver > api_max) {
  1039. IL_ERR(
  1040. "Driver unable to support your firmware API. "
  1041. "Driver supports v%u, firmware is v%u.\n",
  1042. api_max, api_ver);
  1043. goto try_again;
  1044. }
  1045. if (api_ver != api_max)
  1046. IL_ERR(
  1047. "Firmware has old API version. Expected v%u, "
  1048. "got v%u. New firmware can be obtained "
  1049. "from http://www.intellinuxwireless.org.\n",
  1050. api_max, api_ver);
  1051. IL_INFO("loaded firmware version %u.%u.%u.%u\n",
  1052. IL_UCODE_MAJOR(il->ucode_ver),
  1053. IL_UCODE_MINOR(il->ucode_ver),
  1054. IL_UCODE_API(il->ucode_ver),
  1055. IL_UCODE_SERIAL(il->ucode_ver));
  1056. snprintf(il->hw->wiphy->fw_version,
  1057. sizeof(il->hw->wiphy->fw_version),
  1058. "%u.%u.%u.%u",
  1059. IL_UCODE_MAJOR(il->ucode_ver),
  1060. IL_UCODE_MINOR(il->ucode_ver),
  1061. IL_UCODE_API(il->ucode_ver),
  1062. IL_UCODE_SERIAL(il->ucode_ver));
  1063. /*
  1064. * For any of the failures below (before allocating pci memory)
  1065. * we will try to load a version with a smaller API -- maybe the
  1066. * user just got a corrupted version of the latest API.
  1067. */
  1068. D_INFO("f/w package hdr ucode version raw = 0x%x\n",
  1069. il->ucode_ver);
  1070. D_INFO("f/w package hdr runtime inst size = %Zd\n",
  1071. pieces.inst_size);
  1072. D_INFO("f/w package hdr runtime data size = %Zd\n",
  1073. pieces.data_size);
  1074. D_INFO("f/w package hdr init inst size = %Zd\n",
  1075. pieces.init_size);
  1076. D_INFO("f/w package hdr init data size = %Zd\n",
  1077. pieces.init_data_size);
  1078. D_INFO("f/w package hdr boot inst size = %Zd\n",
  1079. pieces.boot_size);
  1080. /* Verify that uCode images will fit in card's SRAM */
  1081. if (pieces.inst_size > il->hw_params.max_inst_size) {
  1082. IL_ERR("uCode instr len %Zd too large to fit in\n",
  1083. pieces.inst_size);
  1084. goto try_again;
  1085. }
  1086. if (pieces.data_size > il->hw_params.max_data_size) {
  1087. IL_ERR("uCode data len %Zd too large to fit in\n",
  1088. pieces.data_size);
  1089. goto try_again;
  1090. }
  1091. if (pieces.init_size > il->hw_params.max_inst_size) {
  1092. IL_ERR("uCode init instr len %Zd too large to fit in\n",
  1093. pieces.init_size);
  1094. goto try_again;
  1095. }
  1096. if (pieces.init_data_size > il->hw_params.max_data_size) {
  1097. IL_ERR("uCode init data len %Zd too large to fit in\n",
  1098. pieces.init_data_size);
  1099. goto try_again;
  1100. }
  1101. if (pieces.boot_size > il->hw_params.max_bsm_size) {
  1102. IL_ERR("uCode boot instr len %Zd too large to fit in\n",
  1103. pieces.boot_size);
  1104. goto try_again;
  1105. }
  1106. /* Allocate ucode buffers for card's bus-master loading ... */
  1107. /* Runtime instructions and 2 copies of data:
  1108. * 1) unmodified from disk
  1109. * 2) backup cache for save/restore during power-downs */
  1110. il->ucode_code.len = pieces.inst_size;
  1111. il_alloc_fw_desc(il->pci_dev, &il->ucode_code);
  1112. il->ucode_data.len = pieces.data_size;
  1113. il_alloc_fw_desc(il->pci_dev, &il->ucode_data);
  1114. il->ucode_data_backup.len = pieces.data_size;
  1115. il_alloc_fw_desc(il->pci_dev, &il->ucode_data_backup);
  1116. if (!il->ucode_code.v_addr || !il->ucode_data.v_addr ||
  1117. !il->ucode_data_backup.v_addr)
  1118. goto err_pci_alloc;
  1119. /* Initialization instructions and data */
  1120. if (pieces.init_size && pieces.init_data_size) {
  1121. il->ucode_init.len = pieces.init_size;
  1122. il_alloc_fw_desc(il->pci_dev, &il->ucode_init);
  1123. il->ucode_init_data.len = pieces.init_data_size;
  1124. il_alloc_fw_desc(il->pci_dev, &il->ucode_init_data);
  1125. if (!il->ucode_init.v_addr || !il->ucode_init_data.v_addr)
  1126. goto err_pci_alloc;
  1127. }
  1128. /* Bootstrap (instructions only, no data) */
  1129. if (pieces.boot_size) {
  1130. il->ucode_boot.len = pieces.boot_size;
  1131. il_alloc_fw_desc(il->pci_dev, &il->ucode_boot);
  1132. if (!il->ucode_boot.v_addr)
  1133. goto err_pci_alloc;
  1134. }
  1135. /* Now that we can no longer fail, copy information */
  1136. il->sta_key_max_num = STA_KEY_MAX_NUM;
  1137. /* Copy images into buffers for card's bus-master reads ... */
  1138. /* Runtime instructions (first block of data in file) */
  1139. D_INFO("Copying (but not loading) uCode instr len %Zd\n",
  1140. pieces.inst_size);
  1141. memcpy(il->ucode_code.v_addr, pieces.inst, pieces.inst_size);
  1142. D_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
  1143. il->ucode_code.v_addr, (u32)il->ucode_code.p_addr);
  1144. /*
  1145. * Runtime data
  1146. * NOTE: Copy into backup buffer will be done in il_up()
  1147. */
  1148. D_INFO("Copying (but not loading) uCode data len %Zd\n",
  1149. pieces.data_size);
  1150. memcpy(il->ucode_data.v_addr, pieces.data, pieces.data_size);
  1151. memcpy(il->ucode_data_backup.v_addr, pieces.data, pieces.data_size);
  1152. /* Initialization instructions */
  1153. if (pieces.init_size) {
  1154. D_INFO(
  1155. "Copying (but not loading) init instr len %Zd\n",
  1156. pieces.init_size);
  1157. memcpy(il->ucode_init.v_addr, pieces.init, pieces.init_size);
  1158. }
  1159. /* Initialization data */
  1160. if (pieces.init_data_size) {
  1161. D_INFO(
  1162. "Copying (but not loading) init data len %Zd\n",
  1163. pieces.init_data_size);
  1164. memcpy(il->ucode_init_data.v_addr, pieces.init_data,
  1165. pieces.init_data_size);
  1166. }
  1167. /* Bootstrap instructions */
  1168. D_INFO("Copying (but not loading) boot instr len %Zd\n",
  1169. pieces.boot_size);
  1170. memcpy(il->ucode_boot.v_addr, pieces.boot, pieces.boot_size);
  1171. /*
  1172. * figure out the offset of chain noise reset and gain commands
  1173. * base on the size of standard phy calibration commands table size
  1174. */
  1175. il->_4965.phy_calib_chain_noise_reset_cmd =
  1176. standard_phy_calibration_size;
  1177. il->_4965.phy_calib_chain_noise_gain_cmd =
  1178. standard_phy_calibration_size + 1;
  1179. /**************************************************
  1180. * This is still part of probe() in a sense...
  1181. *
  1182. * 9. Setup and register with mac80211 and debugfs
  1183. **************************************************/
  1184. err = il4965_mac_setup_register(il, max_probe_length);
  1185. if (err)
  1186. goto out_unbind;
  1187. err = il_dbgfs_register(il, DRV_NAME);
  1188. if (err)
  1189. IL_ERR(
  1190. "failed to create debugfs files. Ignoring error: %d\n", err);
  1191. err = sysfs_create_group(&il->pci_dev->dev.kobj,
  1192. &il_attribute_group);
  1193. if (err) {
  1194. IL_ERR("failed to create sysfs device attributes\n");
  1195. goto out_unbind;
  1196. }
  1197. /* We have our copies now, allow OS release its copies */
  1198. release_firmware(ucode_raw);
  1199. complete(&il->_4965.firmware_loading_complete);
  1200. return;
  1201. try_again:
  1202. /* try next, if any */
  1203. if (il4965_request_firmware(il, false))
  1204. goto out_unbind;
  1205. release_firmware(ucode_raw);
  1206. return;
  1207. err_pci_alloc:
  1208. IL_ERR("failed to allocate pci memory\n");
  1209. il4965_dealloc_ucode_pci(il);
  1210. out_unbind:
  1211. complete(&il->_4965.firmware_loading_complete);
  1212. device_release_driver(&il->pci_dev->dev);
  1213. release_firmware(ucode_raw);
  1214. }
  1215. static const char * const desc_lookup_text[] = {
  1216. "OK",
  1217. "FAIL",
  1218. "BAD_PARAM",
  1219. "BAD_CHECKSUM",
  1220. "NMI_INTERRUPT_WDG",
  1221. "SYSASSERT",
  1222. "FATAL_ERROR",
  1223. "BAD_COMMAND",
  1224. "HW_ERROR_TUNE_LOCK",
  1225. "HW_ERROR_TEMPERATURE",
  1226. "ILLEGAL_CHAN_FREQ",
  1227. "VCC_NOT_STBL",
  1228. "FH_ERROR",
  1229. "NMI_INTERRUPT_HOST",
  1230. "NMI_INTERRUPT_ACTION_PT",
  1231. "NMI_INTERRUPT_UNKNOWN",
  1232. "UCODE_VERSION_MISMATCH",
  1233. "HW_ERROR_ABS_LOCK",
  1234. "HW_ERROR_CAL_LOCK_FAIL",
  1235. "NMI_INTERRUPT_INST_ACTION_PT",
  1236. "NMI_INTERRUPT_DATA_ACTION_PT",
  1237. "NMI_TRM_HW_ER",
  1238. "NMI_INTERRUPT_TRM",
  1239. "NMI_INTERRUPT_BREAK_POINT",
  1240. "DEBUG_0",
  1241. "DEBUG_1",
  1242. "DEBUG_2",
  1243. "DEBUG_3",
  1244. };
  1245. static struct { char *name; u8 num; } advanced_lookup[] = {
  1246. { "NMI_INTERRUPT_WDG", 0x34 },
  1247. { "SYSASSERT", 0x35 },
  1248. { "UCODE_VERSION_MISMATCH", 0x37 },
  1249. { "BAD_COMMAND", 0x38 },
  1250. { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
  1251. { "FATAL_ERROR", 0x3D },
  1252. { "NMI_TRM_HW_ERR", 0x46 },
  1253. { "NMI_INTERRUPT_TRM", 0x4C },
  1254. { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
  1255. { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
  1256. { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
  1257. { "NMI_INTERRUPT_HOST", 0x66 },
  1258. { "NMI_INTERRUPT_ACTION_PT", 0x7C },
  1259. { "NMI_INTERRUPT_UNKNOWN", 0x84 },
  1260. { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
  1261. { "ADVANCED_SYSASSERT", 0 },
  1262. };
  1263. static const char *il4965_desc_lookup(u32 num)
  1264. {
  1265. int i;
  1266. int max = ARRAY_SIZE(desc_lookup_text);
  1267. if (num < max)
  1268. return desc_lookup_text[num];
  1269. max = ARRAY_SIZE(advanced_lookup) - 1;
  1270. for (i = 0; i < max; i++) {
  1271. if (advanced_lookup[i].num == num)
  1272. break;
  1273. }
  1274. return advanced_lookup[i].name;
  1275. }
  1276. #define ERROR_START_OFFSET (1 * sizeof(u32))
  1277. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  1278. void il4965_dump_nic_error_log(struct il_priv *il)
  1279. {
  1280. u32 data2, line;
  1281. u32 desc, time, count, base, data1;
  1282. u32 blink1, blink2, ilink1, ilink2;
  1283. u32 pc, hcmd;
  1284. if (il->ucode_type == UCODE_INIT) {
  1285. base = le32_to_cpu(il->card_alive_init.error_event_table_ptr);
  1286. } else {
  1287. base = le32_to_cpu(il->card_alive.error_event_table_ptr);
  1288. }
  1289. if (!il->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
  1290. IL_ERR(
  1291. "Not valid error log pointer 0x%08X for %s uCode\n",
  1292. base, (il->ucode_type == UCODE_INIT) ? "Init" : "RT");
  1293. return;
  1294. }
  1295. count = il_read_targ_mem(il, base);
  1296. if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
  1297. IL_ERR("Start IWL Error Log Dump:\n");
  1298. IL_ERR("Status: 0x%08lX, count: %d\n",
  1299. il->status, count);
  1300. }
  1301. desc = il_read_targ_mem(il, base + 1 * sizeof(u32));
  1302. il->isr_stats.err_code = desc;
  1303. pc = il_read_targ_mem(il, base + 2 * sizeof(u32));
  1304. blink1 = il_read_targ_mem(il, base + 3 * sizeof(u32));
  1305. blink2 = il_read_targ_mem(il, base + 4 * sizeof(u32));
  1306. ilink1 = il_read_targ_mem(il, base + 5 * sizeof(u32));
  1307. ilink2 = il_read_targ_mem(il, base + 6 * sizeof(u32));
  1308. data1 = il_read_targ_mem(il, base + 7 * sizeof(u32));
  1309. data2 = il_read_targ_mem(il, base + 8 * sizeof(u32));
  1310. line = il_read_targ_mem(il, base + 9 * sizeof(u32));
  1311. time = il_read_targ_mem(il, base + 11 * sizeof(u32));
  1312. hcmd = il_read_targ_mem(il, base + 22 * sizeof(u32));
  1313. IL_ERR("Desc Time "
  1314. "data1 data2 line\n");
  1315. IL_ERR("%-28s (0x%04X) %010u 0x%08X 0x%08X %u\n",
  1316. il4965_desc_lookup(desc), desc, time, data1, data2, line);
  1317. IL_ERR("pc blink1 blink2 ilink1 ilink2 hcmd\n");
  1318. IL_ERR("0x%05X 0x%05X 0x%05X 0x%05X 0x%05X 0x%05X\n",
  1319. pc, blink1, blink2, ilink1, ilink2, hcmd);
  1320. }
  1321. static void il4965_rf_kill_ct_config(struct il_priv *il)
  1322. {
  1323. struct il_ct_kill_config cmd;
  1324. unsigned long flags;
  1325. int ret = 0;
  1326. spin_lock_irqsave(&il->lock, flags);
  1327. _il_wr(il, CSR_UCODE_DRV_GP1_CLR,
  1328. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  1329. spin_unlock_irqrestore(&il->lock, flags);
  1330. cmd.critical_temperature_R =
  1331. cpu_to_le32(il->hw_params.ct_kill_threshold);
  1332. ret = il_send_cmd_pdu(il, REPLY_CT_KILL_CONFIG_CMD,
  1333. sizeof(cmd), &cmd);
  1334. if (ret)
  1335. IL_ERR("REPLY_CT_KILL_CONFIG_CMD failed\n");
  1336. else
  1337. D_INFO("REPLY_CT_KILL_CONFIG_CMD "
  1338. "succeeded, "
  1339. "critical temperature is %d\n",
  1340. il->hw_params.ct_kill_threshold);
  1341. }
  1342. static const s8 default_queue_to_tx_fifo[] = {
  1343. IL_TX_FIFO_VO,
  1344. IL_TX_FIFO_VI,
  1345. IL_TX_FIFO_BE,
  1346. IL_TX_FIFO_BK,
  1347. IL49_CMD_FIFO_NUM,
  1348. IL_TX_FIFO_UNUSED,
  1349. IL_TX_FIFO_UNUSED,
  1350. };
  1351. static int il4965_alive_notify(struct il_priv *il)
  1352. {
  1353. u32 a;
  1354. unsigned long flags;
  1355. int i, chan;
  1356. u32 reg_val;
  1357. spin_lock_irqsave(&il->lock, flags);
  1358. /* Clear 4965's internal Tx Scheduler data base */
  1359. il->scd_base_addr = il_rd_prph(il,
  1360. IL49_SCD_SRAM_BASE_ADDR);
  1361. a = il->scd_base_addr + IL49_SCD_CONTEXT_DATA_OFFSET;
  1362. for (; a < il->scd_base_addr + IL49_SCD_TX_STTS_BITMAP_OFFSET; a += 4)
  1363. il_write_targ_mem(il, a, 0);
  1364. for (; a < il->scd_base_addr + IL49_SCD_TRANSLATE_TBL_OFFSET; a += 4)
  1365. il_write_targ_mem(il, a, 0);
  1366. for (; a < il->scd_base_addr +
  1367. IL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(il->hw_params.max_txq_num); a += 4)
  1368. il_write_targ_mem(il, a, 0);
  1369. /* Tel 4965 where to find Tx byte count tables */
  1370. il_wr_prph(il, IL49_SCD_DRAM_BASE_ADDR,
  1371. il->scd_bc_tbls.dma >> 10);
  1372. /* Enable DMA channel */
  1373. for (chan = 0; chan < FH49_TCSR_CHNL_NUM ; chan++)
  1374. il_wr(il,
  1375. FH_TCSR_CHNL_TX_CONFIG_REG(chan),
  1376. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  1377. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE);
  1378. /* Update FH chicken bits */
  1379. reg_val = il_rd(il, FH_TX_CHICKEN_BITS_REG);
  1380. il_wr(il, FH_TX_CHICKEN_BITS_REG,
  1381. reg_val | FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN);
  1382. /* Disable chain mode for all queues */
  1383. il_wr_prph(il, IL49_SCD_QUEUECHAIN_SEL, 0);
  1384. /* Initialize each Tx queue (including the command queue) */
  1385. for (i = 0; i < il->hw_params.max_txq_num; i++) {
  1386. /* TFD circular buffer read/write idxes */
  1387. il_wr_prph(il, IL49_SCD_QUEUE_RDPTR(i), 0);
  1388. il_wr(il, HBUS_TARG_WRPTR, 0 | (i << 8));
  1389. /* Max Tx Window size for Scheduler-ACK mode */
  1390. il_write_targ_mem(il, il->scd_base_addr +
  1391. IL49_SCD_CONTEXT_QUEUE_OFFSET(i),
  1392. (SCD_WIN_SIZE <<
  1393. IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
  1394. IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
  1395. /* Frame limit */
  1396. il_write_targ_mem(il, il->scd_base_addr +
  1397. IL49_SCD_CONTEXT_QUEUE_OFFSET(i) +
  1398. sizeof(u32),
  1399. (SCD_FRAME_LIMIT <<
  1400. IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  1401. IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
  1402. }
  1403. il_wr_prph(il, IL49_SCD_INTERRUPT_MASK,
  1404. (1 << il->hw_params.max_txq_num) - 1);
  1405. /* Activate all Tx DMA/FIFO channels */
  1406. il4965_txq_set_sched(il, IL_MASK(0, 6));
  1407. il4965_set_wr_ptrs(il, IL_DEFAULT_CMD_QUEUE_NUM, 0);
  1408. /* make sure all queue are not stopped */
  1409. memset(&il->queue_stopped[0], 0, sizeof(il->queue_stopped));
  1410. for (i = 0; i < 4; i++)
  1411. atomic_set(&il->queue_stop_count[i], 0);
  1412. /* reset to 0 to enable all the queue first */
  1413. il->txq_ctx_active_msk = 0;
  1414. /* Map each Tx/cmd queue to its corresponding fifo */
  1415. BUILD_BUG_ON(ARRAY_SIZE(default_queue_to_tx_fifo) != 7);
  1416. for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) {
  1417. int ac = default_queue_to_tx_fifo[i];
  1418. il_txq_ctx_activate(il, i);
  1419. if (ac == IL_TX_FIFO_UNUSED)
  1420. continue;
  1421. il4965_tx_queue_set_status(il, &il->txq[i], ac, 0);
  1422. }
  1423. spin_unlock_irqrestore(&il->lock, flags);
  1424. return 0;
  1425. }
  1426. /**
  1427. * il4965_alive_start - called after REPLY_ALIVE notification received
  1428. * from protocol/runtime uCode (initialization uCode's
  1429. * Alive gets handled by il_init_alive_start()).
  1430. */
  1431. static void il4965_alive_start(struct il_priv *il)
  1432. {
  1433. int ret = 0;
  1434. struct il_rxon_context *ctx = &il->ctx;
  1435. D_INFO("Runtime Alive received.\n");
  1436. if (il->card_alive.is_valid != UCODE_VALID_OK) {
  1437. /* We had an error bringing up the hardware, so take it
  1438. * all the way back down so we can try again */
  1439. D_INFO("Alive failed.\n");
  1440. goto restart;
  1441. }
  1442. /* Initialize uCode has loaded Runtime uCode ... verify inst image.
  1443. * This is a paranoid check, because we would not have gotten the
  1444. * "runtime" alive if code weren't properly loaded. */
  1445. if (il4965_verify_ucode(il)) {
  1446. /* Runtime instruction load was bad;
  1447. * take it all the way back down so we can try again */
  1448. D_INFO("Bad runtime uCode load.\n");
  1449. goto restart;
  1450. }
  1451. ret = il4965_alive_notify(il);
  1452. if (ret) {
  1453. IL_WARN(
  1454. "Could not complete ALIVE transition [ntf]: %d\n", ret);
  1455. goto restart;
  1456. }
  1457. /* After the ALIVE response, we can send host commands to the uCode */
  1458. set_bit(STATUS_ALIVE, &il->status);
  1459. /* Enable watchdog to monitor the driver tx queues */
  1460. il_setup_watchdog(il);
  1461. if (il_is_rfkill(il))
  1462. return;
  1463. ieee80211_wake_queues(il->hw);
  1464. il->active_rate = RATES_MASK;
  1465. if (il_is_associated_ctx(ctx)) {
  1466. struct il_rxon_cmd *active_rxon =
  1467. (struct il_rxon_cmd *)&ctx->active;
  1468. /* apply any changes in staging */
  1469. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  1470. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1471. } else {
  1472. /* Initialize our rx_config data */
  1473. il_connection_init_rx_config(il, &il->ctx);
  1474. if (il->cfg->ops->hcmd->set_rxon_chain)
  1475. il->cfg->ops->hcmd->set_rxon_chain(il, ctx);
  1476. }
  1477. /* Configure bluetooth coexistence if enabled */
  1478. il_send_bt_config(il);
  1479. il4965_reset_run_time_calib(il);
  1480. set_bit(STATUS_READY, &il->status);
  1481. /* Configure the adapter for unassociated operation */
  1482. il_commit_rxon(il, ctx);
  1483. /* At this point, the NIC is initialized and operational */
  1484. il4965_rf_kill_ct_config(il);
  1485. D_INFO("ALIVE processing complete.\n");
  1486. wake_up(&il->wait_command_queue);
  1487. il_power_update_mode(il, true);
  1488. D_INFO("Updated power mode\n");
  1489. return;
  1490. restart:
  1491. queue_work(il->workqueue, &il->restart);
  1492. }
  1493. static void il4965_cancel_deferred_work(struct il_priv *il);
  1494. static void __il4965_down(struct il_priv *il)
  1495. {
  1496. unsigned long flags;
  1497. int exit_pending;
  1498. D_INFO(DRV_NAME " is going down\n");
  1499. il_scan_cancel_timeout(il, 200);
  1500. exit_pending = test_and_set_bit(STATUS_EXIT_PENDING, &il->status);
  1501. /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
  1502. * to prevent rearm timer */
  1503. del_timer_sync(&il->watchdog);
  1504. il_clear_ucode_stations(il, NULL);
  1505. il_dealloc_bcast_stations(il);
  1506. il_clear_driver_stations(il);
  1507. /* Unblock any waiting calls */
  1508. wake_up_all(&il->wait_command_queue);
  1509. /* Wipe out the EXIT_PENDING status bit if we are not actually
  1510. * exiting the module */
  1511. if (!exit_pending)
  1512. clear_bit(STATUS_EXIT_PENDING, &il->status);
  1513. /* stop and reset the on-board processor */
  1514. _il_wr(il, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  1515. /* tell the device to stop sending interrupts */
  1516. spin_lock_irqsave(&il->lock, flags);
  1517. il_disable_interrupts(il);
  1518. spin_unlock_irqrestore(&il->lock, flags);
  1519. il4965_synchronize_irq(il);
  1520. if (il->mac80211_registered)
  1521. ieee80211_stop_queues(il->hw);
  1522. /* If we have not previously called il_init() then
  1523. * clear all bits but the RF Kill bit and return */
  1524. if (!il_is_init(il)) {
  1525. il->status = test_bit(STATUS_RF_KILL_HW, &il->status) <<
  1526. STATUS_RF_KILL_HW |
  1527. test_bit(STATUS_GEO_CONFIGURED, &il->status) <<
  1528. STATUS_GEO_CONFIGURED |
  1529. test_bit(STATUS_EXIT_PENDING, &il->status) <<
  1530. STATUS_EXIT_PENDING;
  1531. goto exit;
  1532. }
  1533. /* ...otherwise clear out all the status bits but the RF Kill
  1534. * bit and continue taking the NIC down. */
  1535. il->status &= test_bit(STATUS_RF_KILL_HW, &il->status) <<
  1536. STATUS_RF_KILL_HW |
  1537. test_bit(STATUS_GEO_CONFIGURED, &il->status) <<
  1538. STATUS_GEO_CONFIGURED |
  1539. test_bit(STATUS_FW_ERROR, &il->status) <<
  1540. STATUS_FW_ERROR |
  1541. test_bit(STATUS_EXIT_PENDING, &il->status) <<
  1542. STATUS_EXIT_PENDING;
  1543. il4965_txq_ctx_stop(il);
  1544. il4965_rxq_stop(il);
  1545. /* Power-down device's busmaster DMA clocks */
  1546. il_wr_prph(il, APMG_CLK_DIS_REG, APMG_CLK_VAL_DMA_CLK_RQT);
  1547. udelay(5);
  1548. /* Make sure (redundant) we've released our request to stay awake */
  1549. il_clear_bit(il, CSR_GP_CNTRL,
  1550. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  1551. /* Stop the device, and put it in low power state */
  1552. il_apm_stop(il);
  1553. exit:
  1554. memset(&il->card_alive, 0, sizeof(struct il_alive_resp));
  1555. dev_kfree_skb(il->beacon_skb);
  1556. il->beacon_skb = NULL;
  1557. /* clear out any free frames */
  1558. il4965_clear_free_frames(il);
  1559. }
  1560. static void il4965_down(struct il_priv *il)
  1561. {
  1562. mutex_lock(&il->mutex);
  1563. __il4965_down(il);
  1564. mutex_unlock(&il->mutex);
  1565. il4965_cancel_deferred_work(il);
  1566. }
  1567. #define HW_READY_TIMEOUT (50)
  1568. static int il4965_set_hw_ready(struct il_priv *il)
  1569. {
  1570. int ret = 0;
  1571. il_set_bit(il, CSR_HW_IF_CONFIG_REG,
  1572. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
  1573. /* See if we got it */
  1574. ret = _il_poll_bit(il, CSR_HW_IF_CONFIG_REG,
  1575. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  1576. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  1577. HW_READY_TIMEOUT);
  1578. if (ret != -ETIMEDOUT)
  1579. il->hw_ready = true;
  1580. else
  1581. il->hw_ready = false;
  1582. D_INFO("hardware %s\n",
  1583. (il->hw_ready == 1) ? "ready" : "not ready");
  1584. return ret;
  1585. }
  1586. static int il4965_prepare_card_hw(struct il_priv *il)
  1587. {
  1588. int ret = 0;
  1589. D_INFO("il4965_prepare_card_hw enter\n");
  1590. ret = il4965_set_hw_ready(il);
  1591. if (il->hw_ready)
  1592. return ret;
  1593. /* If HW is not ready, prepare the conditions to check again */
  1594. il_set_bit(il, CSR_HW_IF_CONFIG_REG,
  1595. CSR_HW_IF_CONFIG_REG_PREPARE);
  1596. ret = _il_poll_bit(il, CSR_HW_IF_CONFIG_REG,
  1597. ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
  1598. CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
  1599. /* HW should be ready by now, check again. */
  1600. if (ret != -ETIMEDOUT)
  1601. il4965_set_hw_ready(il);
  1602. return ret;
  1603. }
  1604. #define MAX_HW_RESTARTS 5
  1605. static int __il4965_up(struct il_priv *il)
  1606. {
  1607. int i;
  1608. int ret;
  1609. if (test_bit(STATUS_EXIT_PENDING, &il->status)) {
  1610. IL_WARN("Exit pending; will not bring the NIC up\n");
  1611. return -EIO;
  1612. }
  1613. if (!il->ucode_data_backup.v_addr || !il->ucode_data.v_addr) {
  1614. IL_ERR("ucode not available for device bringup\n");
  1615. return -EIO;
  1616. }
  1617. ret = il4965_alloc_bcast_station(il, &il->ctx);
  1618. if (ret) {
  1619. il_dealloc_bcast_stations(il);
  1620. return ret;
  1621. }
  1622. il4965_prepare_card_hw(il);
  1623. if (!il->hw_ready) {
  1624. IL_WARN("Exit HW not ready\n");
  1625. return -EIO;
  1626. }
  1627. /* If platform's RF_KILL switch is NOT set to KILL */
  1628. if (_il_rd(il,
  1629. CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  1630. clear_bit(STATUS_RF_KILL_HW, &il->status);
  1631. else
  1632. set_bit(STATUS_RF_KILL_HW, &il->status);
  1633. if (il_is_rfkill(il)) {
  1634. wiphy_rfkill_set_hw_state(il->hw->wiphy, true);
  1635. il_enable_interrupts(il);
  1636. IL_WARN("Radio disabled by HW RF Kill switch\n");
  1637. return 0;
  1638. }
  1639. _il_wr(il, CSR_INT, 0xFFFFFFFF);
  1640. /* must be initialised before il_hw_nic_init */
  1641. il->cmd_queue = IL_DEFAULT_CMD_QUEUE_NUM;
  1642. ret = il4965_hw_nic_init(il);
  1643. if (ret) {
  1644. IL_ERR("Unable to init nic\n");
  1645. return ret;
  1646. }
  1647. /* make sure rfkill handshake bits are cleared */
  1648. _il_wr(il, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  1649. _il_wr(il, CSR_UCODE_DRV_GP1_CLR,
  1650. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  1651. /* clear (again), then enable host interrupts */
  1652. _il_wr(il, CSR_INT, 0xFFFFFFFF);
  1653. il_enable_interrupts(il);
  1654. /* really make sure rfkill handshake bits are cleared */
  1655. _il_wr(il, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  1656. _il_wr(il, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  1657. /* Copy original ucode data image from disk into backup cache.
  1658. * This will be used to initialize the on-board processor's
  1659. * data SRAM for a clean start when the runtime program first loads. */
  1660. memcpy(il->ucode_data_backup.v_addr, il->ucode_data.v_addr,
  1661. il->ucode_data.len);
  1662. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  1663. /* load bootstrap state machine,
  1664. * load bootstrap program into processor's memory,
  1665. * prepare to load the "initialize" uCode */
  1666. ret = il->cfg->ops->lib->load_ucode(il);
  1667. if (ret) {
  1668. IL_ERR("Unable to set up bootstrap uCode: %d\n",
  1669. ret);
  1670. continue;
  1671. }
  1672. /* start card; "initialize" will load runtime ucode */
  1673. il4965_nic_start(il);
  1674. D_INFO(DRV_NAME " is coming up\n");
  1675. return 0;
  1676. }
  1677. set_bit(STATUS_EXIT_PENDING, &il->status);
  1678. __il4965_down(il);
  1679. clear_bit(STATUS_EXIT_PENDING, &il->status);
  1680. /* tried to restart and config the device for as long as our
  1681. * patience could withstand */
  1682. IL_ERR("Unable to initialize device after %d attempts.\n", i);
  1683. return -EIO;
  1684. }
  1685. /*****************************************************************************
  1686. *
  1687. * Workqueue callbacks
  1688. *
  1689. *****************************************************************************/
  1690. static void il4965_bg_init_alive_start(struct work_struct *data)
  1691. {
  1692. struct il_priv *il =
  1693. container_of(data, struct il_priv, init_alive_start.work);
  1694. mutex_lock(&il->mutex);
  1695. if (test_bit(STATUS_EXIT_PENDING, &il->status))
  1696. goto out;
  1697. il->cfg->ops->lib->init_alive_start(il);
  1698. out:
  1699. mutex_unlock(&il->mutex);
  1700. }
  1701. static void il4965_bg_alive_start(struct work_struct *data)
  1702. {
  1703. struct il_priv *il =
  1704. container_of(data, struct il_priv, alive_start.work);
  1705. mutex_lock(&il->mutex);
  1706. if (test_bit(STATUS_EXIT_PENDING, &il->status))
  1707. goto out;
  1708. il4965_alive_start(il);
  1709. out:
  1710. mutex_unlock(&il->mutex);
  1711. }
  1712. static void il4965_bg_run_time_calib_work(struct work_struct *work)
  1713. {
  1714. struct il_priv *il = container_of(work, struct il_priv,
  1715. run_time_calib_work);
  1716. mutex_lock(&il->mutex);
  1717. if (test_bit(STATUS_EXIT_PENDING, &il->status) ||
  1718. test_bit(STATUS_SCANNING, &il->status)) {
  1719. mutex_unlock(&il->mutex);
  1720. return;
  1721. }
  1722. if (il->start_calib) {
  1723. il4965_chain_noise_calibration(il,
  1724. (void *)&il->_4965.stats);
  1725. il4965_sensitivity_calibration(il,
  1726. (void *)&il->_4965.stats);
  1727. }
  1728. mutex_unlock(&il->mutex);
  1729. }
  1730. static void il4965_bg_restart(struct work_struct *data)
  1731. {
  1732. struct il_priv *il = container_of(data, struct il_priv, restart);
  1733. if (test_bit(STATUS_EXIT_PENDING, &il->status))
  1734. return;
  1735. if (test_and_clear_bit(STATUS_FW_ERROR, &il->status)) {
  1736. mutex_lock(&il->mutex);
  1737. il->ctx.vif = NULL;
  1738. il->is_open = 0;
  1739. __il4965_down(il);
  1740. mutex_unlock(&il->mutex);
  1741. il4965_cancel_deferred_work(il);
  1742. ieee80211_restart_hw(il->hw);
  1743. } else {
  1744. il4965_down(il);
  1745. mutex_lock(&il->mutex);
  1746. if (test_bit(STATUS_EXIT_PENDING, &il->status)) {
  1747. mutex_unlock(&il->mutex);
  1748. return;
  1749. }
  1750. __il4965_up(il);
  1751. mutex_unlock(&il->mutex);
  1752. }
  1753. }
  1754. static void il4965_bg_rx_replenish(struct work_struct *data)
  1755. {
  1756. struct il_priv *il =
  1757. container_of(data, struct il_priv, rx_replenish);
  1758. if (test_bit(STATUS_EXIT_PENDING, &il->status))
  1759. return;
  1760. mutex_lock(&il->mutex);
  1761. il4965_rx_replenish(il);
  1762. mutex_unlock(&il->mutex);
  1763. }
  1764. /*****************************************************************************
  1765. *
  1766. * mac80211 entry point functions
  1767. *
  1768. *****************************************************************************/
  1769. #define UCODE_READY_TIMEOUT (4 * HZ)
  1770. /*
  1771. * Not a mac80211 entry point function, but it fits in with all the
  1772. * other mac80211 functions grouped here.
  1773. */
  1774. static int il4965_mac_setup_register(struct il_priv *il,
  1775. u32 max_probe_length)
  1776. {
  1777. int ret;
  1778. struct ieee80211_hw *hw = il->hw;
  1779. hw->rate_control_algorithm = "iwl-4965-rs";
  1780. /* Tell mac80211 our characteristics */
  1781. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  1782. IEEE80211_HW_AMPDU_AGGREGATION |
  1783. IEEE80211_HW_NEED_DTIM_PERIOD |
  1784. IEEE80211_HW_SPECTRUM_MGMT |
  1785. IEEE80211_HW_REPORTS_TX_ACK_STATUS;
  1786. if (il->cfg->sku & IL_SKU_N)
  1787. hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
  1788. IEEE80211_HW_SUPPORTS_STATIC_SMPS;
  1789. hw->sta_data_size = sizeof(struct il_station_priv);
  1790. hw->vif_data_size = sizeof(struct il_vif_priv);
  1791. hw->wiphy->interface_modes |= il->ctx.interface_modes;
  1792. hw->wiphy->interface_modes |= il->ctx.exclusive_interface_modes;
  1793. hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
  1794. WIPHY_FLAG_DISABLE_BEACON_HINTS;
  1795. /*
  1796. * For now, disable PS by default because it affects
  1797. * RX performance significantly.
  1798. */
  1799. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  1800. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  1801. /* we create the 802.11 header and a zero-length SSID element */
  1802. hw->wiphy->max_scan_ie_len = max_probe_length - 24 - 2;
  1803. /* Default value; 4 EDCA QOS priorities */
  1804. hw->queues = 4;
  1805. hw->max_listen_interval = IL_CONN_MAX_LISTEN_INTERVAL;
  1806. if (il->bands[IEEE80211_BAND_2GHZ].n_channels)
  1807. il->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  1808. &il->bands[IEEE80211_BAND_2GHZ];
  1809. if (il->bands[IEEE80211_BAND_5GHZ].n_channels)
  1810. il->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  1811. &il->bands[IEEE80211_BAND_5GHZ];
  1812. il_leds_init(il);
  1813. ret = ieee80211_register_hw(il->hw);
  1814. if (ret) {
  1815. IL_ERR("Failed to register hw (error %d)\n", ret);
  1816. return ret;
  1817. }
  1818. il->mac80211_registered = 1;
  1819. return 0;
  1820. }
  1821. int il4965_mac_start(struct ieee80211_hw *hw)
  1822. {
  1823. struct il_priv *il = hw->priv;
  1824. int ret;
  1825. D_MAC80211("enter\n");
  1826. /* we should be verifying the device is ready to be opened */
  1827. mutex_lock(&il->mutex);
  1828. ret = __il4965_up(il);
  1829. mutex_unlock(&il->mutex);
  1830. if (ret)
  1831. return ret;
  1832. if (il_is_rfkill(il))
  1833. goto out;
  1834. D_INFO("Start UP work done.\n");
  1835. /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
  1836. * mac80211 will not be run successfully. */
  1837. ret = wait_event_timeout(il->wait_command_queue,
  1838. test_bit(STATUS_READY, &il->status),
  1839. UCODE_READY_TIMEOUT);
  1840. if (!ret) {
  1841. if (!test_bit(STATUS_READY, &il->status)) {
  1842. IL_ERR("START_ALIVE timeout after %dms.\n",
  1843. jiffies_to_msecs(UCODE_READY_TIMEOUT));
  1844. return -ETIMEDOUT;
  1845. }
  1846. }
  1847. il4965_led_enable(il);
  1848. out:
  1849. il->is_open = 1;
  1850. D_MAC80211("leave\n");
  1851. return 0;
  1852. }
  1853. void il4965_mac_stop(struct ieee80211_hw *hw)
  1854. {
  1855. struct il_priv *il = hw->priv;
  1856. D_MAC80211("enter\n");
  1857. if (!il->is_open)
  1858. return;
  1859. il->is_open = 0;
  1860. il4965_down(il);
  1861. flush_workqueue(il->workqueue);
  1862. /* User space software may expect getting rfkill changes
  1863. * even if interface is down */
  1864. _il_wr(il, CSR_INT, 0xFFFFFFFF);
  1865. il_enable_rfkill_int(il);
  1866. D_MAC80211("leave\n");
  1867. }
  1868. void il4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  1869. {
  1870. struct il_priv *il = hw->priv;
  1871. D_MACDUMP("enter\n");
  1872. D_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  1873. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  1874. if (il4965_tx_skb(il, skb))
  1875. dev_kfree_skb_any(skb);
  1876. D_MACDUMP("leave\n");
  1877. }
  1878. void il4965_mac_update_tkip_key(struct ieee80211_hw *hw,
  1879. struct ieee80211_vif *vif,
  1880. struct ieee80211_key_conf *keyconf,
  1881. struct ieee80211_sta *sta,
  1882. u32 iv32, u16 *phase1key)
  1883. {
  1884. struct il_priv *il = hw->priv;
  1885. struct il_vif_priv *vif_priv = (void *)vif->drv_priv;
  1886. D_MAC80211("enter\n");
  1887. il4965_update_tkip_key(il, vif_priv->ctx, keyconf, sta,
  1888. iv32, phase1key);
  1889. D_MAC80211("leave\n");
  1890. }
  1891. int il4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  1892. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  1893. struct ieee80211_key_conf *key)
  1894. {
  1895. struct il_priv *il = hw->priv;
  1896. struct il_vif_priv *vif_priv = (void *)vif->drv_priv;
  1897. struct il_rxon_context *ctx = vif_priv->ctx;
  1898. int ret;
  1899. u8 sta_id;
  1900. bool is_default_wep_key = false;
  1901. D_MAC80211("enter\n");
  1902. if (il->cfg->mod_params->sw_crypto) {
  1903. D_MAC80211("leave - hwcrypto disabled\n");
  1904. return -EOPNOTSUPP;
  1905. }
  1906. sta_id = il_sta_id_or_broadcast(il, vif_priv->ctx, sta);
  1907. if (sta_id == IL_INVALID_STATION)
  1908. return -EINVAL;
  1909. mutex_lock(&il->mutex);
  1910. il_scan_cancel_timeout(il, 100);
  1911. /*
  1912. * If we are getting WEP group key and we didn't receive any key mapping
  1913. * so far, we are in legacy wep mode (group key only), otherwise we are
  1914. * in 1X mode.
  1915. * In legacy wep mode, we use another host command to the uCode.
  1916. */
  1917. if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  1918. key->cipher == WLAN_CIPHER_SUITE_WEP104) &&
  1919. !sta) {
  1920. if (cmd == SET_KEY)
  1921. is_default_wep_key = !ctx->key_mapping_keys;
  1922. else
  1923. is_default_wep_key =
  1924. (key->hw_key_idx == HW_KEY_DEFAULT);
  1925. }
  1926. switch (cmd) {
  1927. case SET_KEY:
  1928. if (is_default_wep_key)
  1929. ret = il4965_set_default_wep_key(il,
  1930. vif_priv->ctx, key);
  1931. else
  1932. ret = il4965_set_dynamic_key(il, vif_priv->ctx,
  1933. key, sta_id);
  1934. D_MAC80211("enable hwcrypto key\n");
  1935. break;
  1936. case DISABLE_KEY:
  1937. if (is_default_wep_key)
  1938. ret = il4965_remove_default_wep_key(il, ctx, key);
  1939. else
  1940. ret = il4965_remove_dynamic_key(il, ctx,
  1941. key, sta_id);
  1942. D_MAC80211("disable hwcrypto key\n");
  1943. break;
  1944. default:
  1945. ret = -EINVAL;
  1946. }
  1947. mutex_unlock(&il->mutex);
  1948. D_MAC80211("leave\n");
  1949. return ret;
  1950. }
  1951. int il4965_mac_ampdu_action(struct ieee80211_hw *hw,
  1952. struct ieee80211_vif *vif,
  1953. enum ieee80211_ampdu_mlme_action action,
  1954. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  1955. u8 buf_size)
  1956. {
  1957. struct il_priv *il = hw->priv;
  1958. int ret = -EINVAL;
  1959. D_HT("A-MPDU action on addr %pM tid %d\n",
  1960. sta->addr, tid);
  1961. if (!(il->cfg->sku & IL_SKU_N))
  1962. return -EACCES;
  1963. mutex_lock(&il->mutex);
  1964. switch (action) {
  1965. case IEEE80211_AMPDU_RX_START:
  1966. D_HT("start Rx\n");
  1967. ret = il4965_sta_rx_agg_start(il, sta, tid, *ssn);
  1968. break;
  1969. case IEEE80211_AMPDU_RX_STOP:
  1970. D_HT("stop Rx\n");
  1971. ret = il4965_sta_rx_agg_stop(il, sta, tid);
  1972. if (test_bit(STATUS_EXIT_PENDING, &il->status))
  1973. ret = 0;
  1974. break;
  1975. case IEEE80211_AMPDU_TX_START:
  1976. D_HT("start Tx\n");
  1977. ret = il4965_tx_agg_start(il, vif, sta, tid, ssn);
  1978. break;
  1979. case IEEE80211_AMPDU_TX_STOP:
  1980. D_HT("stop Tx\n");
  1981. ret = il4965_tx_agg_stop(il, vif, sta, tid);
  1982. if (test_bit(STATUS_EXIT_PENDING, &il->status))
  1983. ret = 0;
  1984. break;
  1985. case IEEE80211_AMPDU_TX_OPERATIONAL:
  1986. ret = 0;
  1987. break;
  1988. }
  1989. mutex_unlock(&il->mutex);
  1990. return ret;
  1991. }
  1992. int il4965_mac_sta_add(struct ieee80211_hw *hw,
  1993. struct ieee80211_vif *vif,
  1994. struct ieee80211_sta *sta)
  1995. {
  1996. struct il_priv *il = hw->priv;
  1997. struct il_station_priv *sta_priv = (void *)sta->drv_priv;
  1998. struct il_vif_priv *vif_priv = (void *)vif->drv_priv;
  1999. bool is_ap = vif->type == NL80211_IFTYPE_STATION;
  2000. int ret;
  2001. u8 sta_id;
  2002. D_INFO("received request to add station %pM\n",
  2003. sta->addr);
  2004. mutex_lock(&il->mutex);
  2005. D_INFO("proceeding to add station %pM\n",
  2006. sta->addr);
  2007. sta_priv->common.sta_id = IL_INVALID_STATION;
  2008. atomic_set(&sta_priv->pending_frames, 0);
  2009. ret = il_add_station_common(il, vif_priv->ctx, sta->addr,
  2010. is_ap, sta, &sta_id);
  2011. if (ret) {
  2012. IL_ERR("Unable to add station %pM (%d)\n",
  2013. sta->addr, ret);
  2014. /* Should we return success if return code is EEXIST ? */
  2015. mutex_unlock(&il->mutex);
  2016. return ret;
  2017. }
  2018. sta_priv->common.sta_id = sta_id;
  2019. /* Initialize rate scaling */
  2020. D_INFO("Initializing rate scaling for station %pM\n",
  2021. sta->addr);
  2022. il4965_rs_rate_init(il, sta, sta_id);
  2023. mutex_unlock(&il->mutex);
  2024. return 0;
  2025. }
  2026. void il4965_mac_channel_switch(struct ieee80211_hw *hw,
  2027. struct ieee80211_channel_switch *ch_switch)
  2028. {
  2029. struct il_priv *il = hw->priv;
  2030. const struct il_channel_info *ch_info;
  2031. struct ieee80211_conf *conf = &hw->conf;
  2032. struct ieee80211_channel *channel = ch_switch->channel;
  2033. struct il_ht_config *ht_conf = &il->current_ht_config;
  2034. struct il_rxon_context *ctx = &il->ctx;
  2035. u16 ch;
  2036. D_MAC80211("enter\n");
  2037. mutex_lock(&il->mutex);
  2038. if (il_is_rfkill(il))
  2039. goto out;
  2040. if (test_bit(STATUS_EXIT_PENDING, &il->status) ||
  2041. test_bit(STATUS_SCANNING, &il->status) ||
  2042. test_bit(STATUS_CHANNEL_SWITCH_PENDING, &il->status))
  2043. goto out;
  2044. if (!il_is_associated_ctx(ctx))
  2045. goto out;
  2046. if (!il->cfg->ops->lib->set_channel_switch)
  2047. goto out;
  2048. ch = channel->hw_value;
  2049. if (le16_to_cpu(ctx->active.channel) == ch)
  2050. goto out;
  2051. ch_info = il_get_channel_info(il, channel->band, ch);
  2052. if (!il_is_channel_valid(ch_info)) {
  2053. D_MAC80211("invalid channel\n");
  2054. goto out;
  2055. }
  2056. spin_lock_irq(&il->lock);
  2057. il->current_ht_config.smps = conf->smps_mode;
  2058. /* Configure HT40 channels */
  2059. ctx->ht.enabled = conf_is_ht(conf);
  2060. if (ctx->ht.enabled) {
  2061. if (conf_is_ht40_minus(conf)) {
  2062. ctx->ht.extension_chan_offset =
  2063. IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  2064. ctx->ht.is_40mhz = true;
  2065. } else if (conf_is_ht40_plus(conf)) {
  2066. ctx->ht.extension_chan_offset =
  2067. IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  2068. ctx->ht.is_40mhz = true;
  2069. } else {
  2070. ctx->ht.extension_chan_offset =
  2071. IEEE80211_HT_PARAM_CHA_SEC_NONE;
  2072. ctx->ht.is_40mhz = false;
  2073. }
  2074. } else
  2075. ctx->ht.is_40mhz = false;
  2076. if ((le16_to_cpu(ctx->staging.channel) != ch))
  2077. ctx->staging.flags = 0;
  2078. il_set_rxon_channel(il, channel, ctx);
  2079. il_set_rxon_ht(il, ht_conf);
  2080. il_set_flags_for_band(il, ctx, channel->band, ctx->vif);
  2081. spin_unlock_irq(&il->lock);
  2082. il_set_rate(il);
  2083. /*
  2084. * at this point, staging_rxon has the
  2085. * configuration for channel switch
  2086. */
  2087. set_bit(STATUS_CHANNEL_SWITCH_PENDING, &il->status);
  2088. il->switch_channel = cpu_to_le16(ch);
  2089. if (il->cfg->ops->lib->set_channel_switch(il, ch_switch)) {
  2090. clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &il->status);
  2091. il->switch_channel = 0;
  2092. ieee80211_chswitch_done(ctx->vif, false);
  2093. }
  2094. out:
  2095. mutex_unlock(&il->mutex);
  2096. D_MAC80211("leave\n");
  2097. }
  2098. void il4965_configure_filter(struct ieee80211_hw *hw,
  2099. unsigned int changed_flags,
  2100. unsigned int *total_flags,
  2101. u64 multicast)
  2102. {
  2103. struct il_priv *il = hw->priv;
  2104. __le32 filter_or = 0, filter_nand = 0;
  2105. #define CHK(test, flag) do { \
  2106. if (*total_flags & (test)) \
  2107. filter_or |= (flag); \
  2108. else \
  2109. filter_nand |= (flag); \
  2110. } while (0)
  2111. D_MAC80211("Enter: changed: 0x%x, total: 0x%x\n",
  2112. changed_flags, *total_flags);
  2113. CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
  2114. /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
  2115. CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
  2116. CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
  2117. #undef CHK
  2118. mutex_lock(&il->mutex);
  2119. il->ctx.staging.filter_flags &= ~filter_nand;
  2120. il->ctx.staging.filter_flags |= filter_or;
  2121. /*
  2122. * Not committing directly because hardware can perform a scan,
  2123. * but we'll eventually commit the filter flags change anyway.
  2124. */
  2125. mutex_unlock(&il->mutex);
  2126. /*
  2127. * Receiving all multicast frames is always enabled by the
  2128. * default flags setup in il_connection_init_rx_config()
  2129. * since we currently do not support programming multicast
  2130. * filters into the device.
  2131. */
  2132. *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
  2133. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
  2134. }
  2135. /*****************************************************************************
  2136. *
  2137. * driver setup and teardown
  2138. *
  2139. *****************************************************************************/
  2140. static void il4965_bg_txpower_work(struct work_struct *work)
  2141. {
  2142. struct il_priv *il = container_of(work, struct il_priv,
  2143. txpower_work);
  2144. mutex_lock(&il->mutex);
  2145. /* If a scan happened to start before we got here
  2146. * then just return; the stats notification will
  2147. * kick off another scheduled work to compensate for
  2148. * any temperature delta we missed here. */
  2149. if (test_bit(STATUS_EXIT_PENDING, &il->status) ||
  2150. test_bit(STATUS_SCANNING, &il->status))
  2151. goto out;
  2152. /* Regardless of if we are associated, we must reconfigure the
  2153. * TX power since frames can be sent on non-radar channels while
  2154. * not associated */
  2155. il->cfg->ops->lib->send_tx_power(il);
  2156. /* Update last_temperature to keep is_calib_needed from running
  2157. * when it isn't needed... */
  2158. il->last_temperature = il->temperature;
  2159. out:
  2160. mutex_unlock(&il->mutex);
  2161. }
  2162. static void il4965_setup_deferred_work(struct il_priv *il)
  2163. {
  2164. il->workqueue = create_singlethread_workqueue(DRV_NAME);
  2165. init_waitqueue_head(&il->wait_command_queue);
  2166. INIT_WORK(&il->restart, il4965_bg_restart);
  2167. INIT_WORK(&il->rx_replenish, il4965_bg_rx_replenish);
  2168. INIT_WORK(&il->run_time_calib_work, il4965_bg_run_time_calib_work);
  2169. INIT_DELAYED_WORK(&il->init_alive_start, il4965_bg_init_alive_start);
  2170. INIT_DELAYED_WORK(&il->alive_start, il4965_bg_alive_start);
  2171. il_setup_scan_deferred_work(il);
  2172. INIT_WORK(&il->txpower_work, il4965_bg_txpower_work);
  2173. init_timer(&il->stats_periodic);
  2174. il->stats_periodic.data = (unsigned long)il;
  2175. il->stats_periodic.function = il4965_bg_stats_periodic;
  2176. init_timer(&il->watchdog);
  2177. il->watchdog.data = (unsigned long)il;
  2178. il->watchdog.function = il_bg_watchdog;
  2179. tasklet_init(&il->irq_tasklet, (void (*)(unsigned long))
  2180. il4965_irq_tasklet, (unsigned long)il);
  2181. }
  2182. static void il4965_cancel_deferred_work(struct il_priv *il)
  2183. {
  2184. cancel_work_sync(&il->txpower_work);
  2185. cancel_delayed_work_sync(&il->init_alive_start);
  2186. cancel_delayed_work(&il->alive_start);
  2187. cancel_work_sync(&il->run_time_calib_work);
  2188. il_cancel_scan_deferred_work(il);
  2189. del_timer_sync(&il->stats_periodic);
  2190. }
  2191. static void il4965_init_hw_rates(struct il_priv *il,
  2192. struct ieee80211_rate *rates)
  2193. {
  2194. int i;
  2195. for (i = 0; i < RATE_COUNT_LEGACY; i++) {
  2196. rates[i].bitrate = il_rates[i].ieee * 5;
  2197. rates[i].hw_value = i; /* Rate scaling will work on idxes */
  2198. rates[i].hw_value_short = i;
  2199. rates[i].flags = 0;
  2200. if ((i >= IL_FIRST_CCK_RATE) && (i <= IL_LAST_CCK_RATE)) {
  2201. /*
  2202. * If CCK != 1M then set short preamble rate flag.
  2203. */
  2204. rates[i].flags |=
  2205. (il_rates[i].plcp == RATE_1M_PLCP) ?
  2206. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  2207. }
  2208. }
  2209. }
  2210. /*
  2211. * Acquire il->lock before calling this function !
  2212. */
  2213. void il4965_set_wr_ptrs(struct il_priv *il, int txq_id, u32 idx)
  2214. {
  2215. il_wr(il, HBUS_TARG_WRPTR,
  2216. (idx & 0xff) | (txq_id << 8));
  2217. il_wr_prph(il, IL49_SCD_QUEUE_RDPTR(txq_id), idx);
  2218. }
  2219. void il4965_tx_queue_set_status(struct il_priv *il,
  2220. struct il_tx_queue *txq,
  2221. int tx_fifo_id, int scd_retry)
  2222. {
  2223. int txq_id = txq->q.id;
  2224. /* Find out whether to activate Tx queue */
  2225. int active = test_bit(txq_id, &il->txq_ctx_active_msk) ? 1 : 0;
  2226. /* Set up and activate */
  2227. il_wr_prph(il, IL49_SCD_QUEUE_STATUS_BITS(txq_id),
  2228. (active << IL49_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
  2229. (tx_fifo_id << IL49_SCD_QUEUE_STTS_REG_POS_TXF) |
  2230. (scd_retry << IL49_SCD_QUEUE_STTS_REG_POS_WSL) |
  2231. (scd_retry << IL49_SCD_QUEUE_STTS_REG_POS_SCD_ACK) |
  2232. IL49_SCD_QUEUE_STTS_REG_MSK);
  2233. txq->sched_retry = scd_retry;
  2234. D_INFO("%s %s Queue %d on AC %d\n",
  2235. active ? "Activate" : "Deactivate",
  2236. scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
  2237. }
  2238. static int il4965_init_drv(struct il_priv *il)
  2239. {
  2240. int ret;
  2241. spin_lock_init(&il->sta_lock);
  2242. spin_lock_init(&il->hcmd_lock);
  2243. INIT_LIST_HEAD(&il->free_frames);
  2244. mutex_init(&il->mutex);
  2245. il->ieee_channels = NULL;
  2246. il->ieee_rates = NULL;
  2247. il->band = IEEE80211_BAND_2GHZ;
  2248. il->iw_mode = NL80211_IFTYPE_STATION;
  2249. il->current_ht_config.smps = IEEE80211_SMPS_STATIC;
  2250. il->missed_beacon_threshold = IL_MISSED_BEACON_THRESHOLD_DEF;
  2251. /* initialize force reset */
  2252. il->force_reset.reset_duration = IL_DELAY_NEXT_FORCE_FW_RELOAD;
  2253. /* Choose which receivers/antennas to use */
  2254. if (il->cfg->ops->hcmd->set_rxon_chain)
  2255. il->cfg->ops->hcmd->set_rxon_chain(il,
  2256. &il->ctx);
  2257. il_init_scan_params(il);
  2258. ret = il_init_channel_map(il);
  2259. if (ret) {
  2260. IL_ERR("initializing regulatory failed: %d\n", ret);
  2261. goto err;
  2262. }
  2263. ret = il_init_geos(il);
  2264. if (ret) {
  2265. IL_ERR("initializing geos failed: %d\n", ret);
  2266. goto err_free_channel_map;
  2267. }
  2268. il4965_init_hw_rates(il, il->ieee_rates);
  2269. return 0;
  2270. err_free_channel_map:
  2271. il_free_channel_map(il);
  2272. err:
  2273. return ret;
  2274. }
  2275. static void il4965_uninit_drv(struct il_priv *il)
  2276. {
  2277. il4965_calib_free_results(il);
  2278. il_free_geos(il);
  2279. il_free_channel_map(il);
  2280. kfree(il->scan_cmd);
  2281. }
  2282. static void il4965_hw_detect(struct il_priv *il)
  2283. {
  2284. il->hw_rev = _il_rd(il, CSR_HW_REV);
  2285. il->hw_wa_rev = _il_rd(il, CSR_HW_REV_WA_REG);
  2286. il->rev_id = il->pci_dev->revision;
  2287. D_INFO("HW Revision ID = 0x%X\n", il->rev_id);
  2288. }
  2289. static int il4965_set_hw_params(struct il_priv *il)
  2290. {
  2291. il->hw_params.max_rxq_size = RX_QUEUE_SIZE;
  2292. il->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
  2293. if (il->cfg->mod_params->amsdu_size_8K)
  2294. il->hw_params.rx_page_order = get_order(IL_RX_BUF_SIZE_8K);
  2295. else
  2296. il->hw_params.rx_page_order = get_order(IL_RX_BUF_SIZE_4K);
  2297. il->hw_params.max_beacon_itrvl = IL_MAX_UCODE_BEACON_INTERVAL;
  2298. if (il->cfg->mod_params->disable_11n)
  2299. il->cfg->sku &= ~IL_SKU_N;
  2300. /* Device-specific setup */
  2301. return il->cfg->ops->lib->set_hw_params(il);
  2302. }
  2303. static const u8 il4965_bss_ac_to_fifo[] = {
  2304. IL_TX_FIFO_VO,
  2305. IL_TX_FIFO_VI,
  2306. IL_TX_FIFO_BE,
  2307. IL_TX_FIFO_BK,
  2308. };
  2309. static const u8 il4965_bss_ac_to_queue[] = {
  2310. 0, 1, 2, 3,
  2311. };
  2312. static int
  2313. il4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  2314. {
  2315. int err = 0;
  2316. struct il_priv *il;
  2317. struct ieee80211_hw *hw;
  2318. struct il_cfg *cfg = (struct il_cfg *)(ent->driver_data);
  2319. unsigned long flags;
  2320. u16 pci_cmd;
  2321. /************************
  2322. * 1. Allocating HW data
  2323. ************************/
  2324. hw = il_alloc_all(cfg);
  2325. if (!hw) {
  2326. err = -ENOMEM;
  2327. goto out;
  2328. }
  2329. il = hw->priv;
  2330. /* At this point both hw and il are allocated. */
  2331. il->ctx.ctxid = 0;
  2332. il->ctx.always_active = true;
  2333. il->ctx.is_active = true;
  2334. il->ctx.rxon_cmd = REPLY_RXON;
  2335. il->ctx.rxon_timing_cmd = REPLY_RXON_TIMING;
  2336. il->ctx.rxon_assoc_cmd = REPLY_RXON_ASSOC;
  2337. il->ctx.qos_cmd = REPLY_QOS_PARAM;
  2338. il->ctx.ap_sta_id = IL_AP_ID;
  2339. il->ctx.wep_key_cmd = REPLY_WEPKEY;
  2340. il->ctx.ac_to_fifo = il4965_bss_ac_to_fifo;
  2341. il->ctx.ac_to_queue = il4965_bss_ac_to_queue;
  2342. il->ctx.exclusive_interface_modes =
  2343. BIT(NL80211_IFTYPE_ADHOC);
  2344. il->ctx.interface_modes =
  2345. BIT(NL80211_IFTYPE_STATION);
  2346. il->ctx.ap_devtype = RXON_DEV_TYPE_AP;
  2347. il->ctx.ibss_devtype = RXON_DEV_TYPE_IBSS;
  2348. il->ctx.station_devtype = RXON_DEV_TYPE_ESS;
  2349. il->ctx.unused_devtype = RXON_DEV_TYPE_ESS;
  2350. SET_IEEE80211_DEV(hw, &pdev->dev);
  2351. D_INFO("*** LOAD DRIVER ***\n");
  2352. il->cfg = cfg;
  2353. il->pci_dev = pdev;
  2354. il->inta_mask = CSR_INI_SET_MASK;
  2355. if (il_alloc_traffic_mem(il))
  2356. IL_ERR("Not enough memory to generate traffic log\n");
  2357. /**************************
  2358. * 2. Initializing PCI bus
  2359. **************************/
  2360. pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
  2361. PCIE_LINK_STATE_CLKPM);
  2362. if (pci_enable_device(pdev)) {
  2363. err = -ENODEV;
  2364. goto out_ieee80211_free_hw;
  2365. }
  2366. pci_set_master(pdev);
  2367. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
  2368. if (!err)
  2369. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
  2370. if (err) {
  2371. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  2372. if (!err)
  2373. err = pci_set_consistent_dma_mask(pdev,
  2374. DMA_BIT_MASK(32));
  2375. /* both attempts failed: */
  2376. if (err) {
  2377. IL_WARN("No suitable DMA available.\n");
  2378. goto out_pci_disable_device;
  2379. }
  2380. }
  2381. err = pci_request_regions(pdev, DRV_NAME);
  2382. if (err)
  2383. goto out_pci_disable_device;
  2384. pci_set_drvdata(pdev, il);
  2385. /***********************
  2386. * 3. Read REV register
  2387. ***********************/
  2388. il->hw_base = pci_iomap(pdev, 0, 0);
  2389. if (!il->hw_base) {
  2390. err = -ENODEV;
  2391. goto out_pci_release_regions;
  2392. }
  2393. D_INFO("pci_resource_len = 0x%08llx\n",
  2394. (unsigned long long) pci_resource_len(pdev, 0));
  2395. D_INFO("pci_resource_base = %p\n", il->hw_base);
  2396. /* these spin locks will be used in apm_ops.init and EEPROM access
  2397. * we should init now
  2398. */
  2399. spin_lock_init(&il->reg_lock);
  2400. spin_lock_init(&il->lock);
  2401. /*
  2402. * stop and reset the on-board processor just in case it is in a
  2403. * strange state ... like being left stranded by a primary kernel
  2404. * and this is now the kdump kernel trying to start up
  2405. */
  2406. _il_wr(il, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  2407. il4965_hw_detect(il);
  2408. IL_INFO("Detected %s, REV=0x%X\n",
  2409. il->cfg->name, il->hw_rev);
  2410. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  2411. * PCI Tx retries from interfering with C3 CPU state */
  2412. pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
  2413. il4965_prepare_card_hw(il);
  2414. if (!il->hw_ready) {
  2415. IL_WARN("Failed, HW not ready\n");
  2416. goto out_iounmap;
  2417. }
  2418. /*****************
  2419. * 4. Read EEPROM
  2420. *****************/
  2421. /* Read the EEPROM */
  2422. err = il_eeprom_init(il);
  2423. if (err) {
  2424. IL_ERR("Unable to init EEPROM\n");
  2425. goto out_iounmap;
  2426. }
  2427. err = il4965_eeprom_check_version(il);
  2428. if (err)
  2429. goto out_free_eeprom;
  2430. if (err)
  2431. goto out_free_eeprom;
  2432. /* extract MAC Address */
  2433. il4965_eeprom_get_mac(il, il->addresses[0].addr);
  2434. D_INFO("MAC address: %pM\n", il->addresses[0].addr);
  2435. il->hw->wiphy->addresses = il->addresses;
  2436. il->hw->wiphy->n_addresses = 1;
  2437. /************************
  2438. * 5. Setup HW constants
  2439. ************************/
  2440. if (il4965_set_hw_params(il)) {
  2441. IL_ERR("failed to set hw parameters\n");
  2442. goto out_free_eeprom;
  2443. }
  2444. /*******************
  2445. * 6. Setup il
  2446. *******************/
  2447. err = il4965_init_drv(il);
  2448. if (err)
  2449. goto out_free_eeprom;
  2450. /* At this point both hw and il are initialized. */
  2451. /********************
  2452. * 7. Setup services
  2453. ********************/
  2454. spin_lock_irqsave(&il->lock, flags);
  2455. il_disable_interrupts(il);
  2456. spin_unlock_irqrestore(&il->lock, flags);
  2457. pci_enable_msi(il->pci_dev);
  2458. err = request_irq(il->pci_dev->irq, il_isr,
  2459. IRQF_SHARED, DRV_NAME, il);
  2460. if (err) {
  2461. IL_ERR("Error allocating IRQ %d\n", il->pci_dev->irq);
  2462. goto out_disable_msi;
  2463. }
  2464. il4965_setup_deferred_work(il);
  2465. il4965_setup_rx_handlers(il);
  2466. /*********************************************
  2467. * 8. Enable interrupts and read RFKILL state
  2468. *********************************************/
  2469. /* enable rfkill interrupt: hw bug w/a */
  2470. pci_read_config_word(il->pci_dev, PCI_COMMAND, &pci_cmd);
  2471. if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
  2472. pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
  2473. pci_write_config_word(il->pci_dev, PCI_COMMAND, pci_cmd);
  2474. }
  2475. il_enable_rfkill_int(il);
  2476. /* If platform's RF_KILL switch is NOT set to KILL */
  2477. if (_il_rd(il, CSR_GP_CNTRL) &
  2478. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  2479. clear_bit(STATUS_RF_KILL_HW, &il->status);
  2480. else
  2481. set_bit(STATUS_RF_KILL_HW, &il->status);
  2482. wiphy_rfkill_set_hw_state(il->hw->wiphy,
  2483. test_bit(STATUS_RF_KILL_HW, &il->status));
  2484. il_power_initialize(il);
  2485. init_completion(&il->_4965.firmware_loading_complete);
  2486. err = il4965_request_firmware(il, true);
  2487. if (err)
  2488. goto out_destroy_workqueue;
  2489. return 0;
  2490. out_destroy_workqueue:
  2491. destroy_workqueue(il->workqueue);
  2492. il->workqueue = NULL;
  2493. free_irq(il->pci_dev->irq, il);
  2494. out_disable_msi:
  2495. pci_disable_msi(il->pci_dev);
  2496. il4965_uninit_drv(il);
  2497. out_free_eeprom:
  2498. il_eeprom_free(il);
  2499. out_iounmap:
  2500. pci_iounmap(pdev, il->hw_base);
  2501. out_pci_release_regions:
  2502. pci_set_drvdata(pdev, NULL);
  2503. pci_release_regions(pdev);
  2504. out_pci_disable_device:
  2505. pci_disable_device(pdev);
  2506. out_ieee80211_free_hw:
  2507. il_free_traffic_mem(il);
  2508. ieee80211_free_hw(il->hw);
  2509. out:
  2510. return err;
  2511. }
  2512. static void __devexit il4965_pci_remove(struct pci_dev *pdev)
  2513. {
  2514. struct il_priv *il = pci_get_drvdata(pdev);
  2515. unsigned long flags;
  2516. if (!il)
  2517. return;
  2518. wait_for_completion(&il->_4965.firmware_loading_complete);
  2519. D_INFO("*** UNLOAD DRIVER ***\n");
  2520. il_dbgfs_unregister(il);
  2521. sysfs_remove_group(&pdev->dev.kobj, &il_attribute_group);
  2522. /* ieee80211_unregister_hw call wil cause il_mac_stop to
  2523. * to be called and il4965_down since we are removing the device
  2524. * we need to set STATUS_EXIT_PENDING bit.
  2525. */
  2526. set_bit(STATUS_EXIT_PENDING, &il->status);
  2527. il_leds_exit(il);
  2528. if (il->mac80211_registered) {
  2529. ieee80211_unregister_hw(il->hw);
  2530. il->mac80211_registered = 0;
  2531. } else {
  2532. il4965_down(il);
  2533. }
  2534. /*
  2535. * Make sure device is reset to low power before unloading driver.
  2536. * This may be redundant with il4965_down(), but there are paths to
  2537. * run il4965_down() without calling apm_ops.stop(), and there are
  2538. * paths to avoid running il4965_down() at all before leaving driver.
  2539. * This (inexpensive) call *makes sure* device is reset.
  2540. */
  2541. il_apm_stop(il);
  2542. /* make sure we flush any pending irq or
  2543. * tasklet for the driver
  2544. */
  2545. spin_lock_irqsave(&il->lock, flags);
  2546. il_disable_interrupts(il);
  2547. spin_unlock_irqrestore(&il->lock, flags);
  2548. il4965_synchronize_irq(il);
  2549. il4965_dealloc_ucode_pci(il);
  2550. if (il->rxq.bd)
  2551. il4965_rx_queue_free(il, &il->rxq);
  2552. il4965_hw_txq_ctx_free(il);
  2553. il_eeprom_free(il);
  2554. /*netif_stop_queue(dev); */
  2555. flush_workqueue(il->workqueue);
  2556. /* ieee80211_unregister_hw calls il_mac_stop, which flushes
  2557. * il->workqueue... so we can't take down the workqueue
  2558. * until now... */
  2559. destroy_workqueue(il->workqueue);
  2560. il->workqueue = NULL;
  2561. il_free_traffic_mem(il);
  2562. free_irq(il->pci_dev->irq, il);
  2563. pci_disable_msi(il->pci_dev);
  2564. pci_iounmap(pdev, il->hw_base);
  2565. pci_release_regions(pdev);
  2566. pci_disable_device(pdev);
  2567. pci_set_drvdata(pdev, NULL);
  2568. il4965_uninit_drv(il);
  2569. dev_kfree_skb(il->beacon_skb);
  2570. ieee80211_free_hw(il->hw);
  2571. }
  2572. /*
  2573. * Activate/Deactivate Tx DMA/FIFO channels according tx fifos mask
  2574. * must be called under il->lock and mac access
  2575. */
  2576. void il4965_txq_set_sched(struct il_priv *il, u32 mask)
  2577. {
  2578. il_wr_prph(il, IL49_SCD_TXFACT, mask);
  2579. }
  2580. /*****************************************************************************
  2581. *
  2582. * driver and module entry point
  2583. *
  2584. *****************************************************************************/
  2585. /* Hardware specific file defines the PCI IDs table for that hardware module */
  2586. static DEFINE_PCI_DEVICE_TABLE(il4965_hw_card_ids) = {
  2587. {IL_PCI_DEVICE(0x4229, PCI_ANY_ID, il4965_cfg)},
  2588. {IL_PCI_DEVICE(0x4230, PCI_ANY_ID, il4965_cfg)},
  2589. {0}
  2590. };
  2591. MODULE_DEVICE_TABLE(pci, il4965_hw_card_ids);
  2592. static struct pci_driver il4965_driver = {
  2593. .name = DRV_NAME,
  2594. .id_table = il4965_hw_card_ids,
  2595. .probe = il4965_pci_probe,
  2596. .remove = __devexit_p(il4965_pci_remove),
  2597. .driver.pm = IL_LEGACY_PM_OPS,
  2598. };
  2599. static int __init il4965_init(void)
  2600. {
  2601. int ret;
  2602. pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
  2603. pr_info(DRV_COPYRIGHT "\n");
  2604. ret = il4965_rate_control_register();
  2605. if (ret) {
  2606. pr_err("Unable to register rate control algorithm: %d\n", ret);
  2607. return ret;
  2608. }
  2609. ret = pci_register_driver(&il4965_driver);
  2610. if (ret) {
  2611. pr_err("Unable to initialize PCI module\n");
  2612. goto error_register;
  2613. }
  2614. return ret;
  2615. error_register:
  2616. il4965_rate_control_unregister();
  2617. return ret;
  2618. }
  2619. static void __exit il4965_exit(void)
  2620. {
  2621. pci_unregister_driver(&il4965_driver);
  2622. il4965_rate_control_unregister();
  2623. }
  2624. module_exit(il4965_exit);
  2625. module_init(il4965_init);
  2626. #ifdef CONFIG_IWLEGACY_DEBUG
  2627. module_param_named(debug, il_debug_level, uint, S_IRUGO | S_IWUSR);
  2628. MODULE_PARM_DESC(debug, "debug output mask");
  2629. #endif
  2630. module_param_named(swcrypto, il4965_mod_params.sw_crypto, int, S_IRUGO);
  2631. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
  2632. module_param_named(queues_num, il4965_mod_params.num_of_queues, int, S_IRUGO);
  2633. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  2634. module_param_named(11n_disable, il4965_mod_params.disable_11n, int, S_IRUGO);
  2635. MODULE_PARM_DESC(11n_disable, "disable 11n functionality");
  2636. module_param_named(amsdu_size_8K, il4965_mod_params.amsdu_size_8K,
  2637. int, S_IRUGO);
  2638. MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
  2639. module_param_named(fw_restart, il4965_mod_params.restart_fw, int, S_IRUGO);
  2640. MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");