iwl4965-base.c 85 KB

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