iwl-3945.c 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * James P. Ketrenos <ipw2100-admin@linux.intel.com>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. *****************************************************************************/
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <linux/version.h>
  29. #include <linux/init.h>
  30. #include <linux/pci.h>
  31. #include <linux/dma-mapping.h>
  32. #include <linux/delay.h>
  33. #include <linux/skbuff.h>
  34. #include <linux/netdevice.h>
  35. #include <linux/wireless.h>
  36. #include <linux/firmware.h>
  37. #include <linux/etherdevice.h>
  38. #include <asm/unaligned.h>
  39. #include <net/mac80211.h>
  40. #include "iwl-3945-core.h"
  41. #include "iwl-3945.h"
  42. #include "iwl-helpers.h"
  43. #include "iwl-3945-rs.h"
  44. #define IWL_DECLARE_RATE_INFO(r, ip, in, rp, rn, pp, np) \
  45. [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \
  46. IWL_RATE_##r##M_IEEE, \
  47. IWL_RATE_##ip##M_INDEX, \
  48. IWL_RATE_##in##M_INDEX, \
  49. IWL_RATE_##rp##M_INDEX, \
  50. IWL_RATE_##rn##M_INDEX, \
  51. IWL_RATE_##pp##M_INDEX, \
  52. IWL_RATE_##np##M_INDEX, \
  53. IWL_RATE_##r##M_INDEX_TABLE, \
  54. IWL_RATE_##ip##M_INDEX_TABLE }
  55. /*
  56. * Parameter order:
  57. * rate, prev rate, next rate, prev tgg rate, next tgg rate
  58. *
  59. * If there isn't a valid next or previous rate then INV is used which
  60. * maps to IWL_RATE_INVALID
  61. *
  62. */
  63. const struct iwl3945_rate_info iwl3945_rates[IWL_RATE_COUNT] = {
  64. IWL_DECLARE_RATE_INFO(1, INV, 2, INV, 2, INV, 2), /* 1mbps */
  65. IWL_DECLARE_RATE_INFO(2, 1, 5, 1, 5, 1, 5), /* 2mbps */
  66. IWL_DECLARE_RATE_INFO(5, 2, 6, 2, 11, 2, 11), /*5.5mbps */
  67. IWL_DECLARE_RATE_INFO(11, 9, 12, 5, 12, 5, 18), /* 11mbps */
  68. IWL_DECLARE_RATE_INFO(6, 5, 9, 5, 11, 5, 11), /* 6mbps */
  69. IWL_DECLARE_RATE_INFO(9, 6, 11, 5, 11, 5, 11), /* 9mbps */
  70. IWL_DECLARE_RATE_INFO(12, 11, 18, 11, 18, 11, 18), /* 12mbps */
  71. IWL_DECLARE_RATE_INFO(18, 12, 24, 12, 24, 11, 24), /* 18mbps */
  72. IWL_DECLARE_RATE_INFO(24, 18, 36, 18, 36, 18, 36), /* 24mbps */
  73. IWL_DECLARE_RATE_INFO(36, 24, 48, 24, 48, 24, 48), /* 36mbps */
  74. IWL_DECLARE_RATE_INFO(48, 36, 54, 36, 54, 36, 54), /* 48mbps */
  75. IWL_DECLARE_RATE_INFO(54, 48, INV, 48, INV, 48, INV),/* 54mbps */
  76. };
  77. /* 1 = enable the iwl3945_disable_events() function */
  78. #define IWL_EVT_DISABLE (0)
  79. #define IWL_EVT_DISABLE_SIZE (1532/32)
  80. /**
  81. * iwl3945_disable_events - Disable selected events in uCode event log
  82. *
  83. * Disable an event by writing "1"s into "disable"
  84. * bitmap in SRAM. Bit position corresponds to Event # (id/type).
  85. * Default values of 0 enable uCode events to be logged.
  86. * Use for only special debugging. This function is just a placeholder as-is,
  87. * you'll need to provide the special bits! ...
  88. * ... and set IWL_EVT_DISABLE to 1. */
  89. void iwl3945_disable_events(struct iwl3945_priv *priv)
  90. {
  91. int ret;
  92. int i;
  93. u32 base; /* SRAM address of event log header */
  94. u32 disable_ptr; /* SRAM address of event-disable bitmap array */
  95. u32 array_size; /* # of u32 entries in array */
  96. u32 evt_disable[IWL_EVT_DISABLE_SIZE] = {
  97. 0x00000000, /* 31 - 0 Event id numbers */
  98. 0x00000000, /* 63 - 32 */
  99. 0x00000000, /* 95 - 64 */
  100. 0x00000000, /* 127 - 96 */
  101. 0x00000000, /* 159 - 128 */
  102. 0x00000000, /* 191 - 160 */
  103. 0x00000000, /* 223 - 192 */
  104. 0x00000000, /* 255 - 224 */
  105. 0x00000000, /* 287 - 256 */
  106. 0x00000000, /* 319 - 288 */
  107. 0x00000000, /* 351 - 320 */
  108. 0x00000000, /* 383 - 352 */
  109. 0x00000000, /* 415 - 384 */
  110. 0x00000000, /* 447 - 416 */
  111. 0x00000000, /* 479 - 448 */
  112. 0x00000000, /* 511 - 480 */
  113. 0x00000000, /* 543 - 512 */
  114. 0x00000000, /* 575 - 544 */
  115. 0x00000000, /* 607 - 576 */
  116. 0x00000000, /* 639 - 608 */
  117. 0x00000000, /* 671 - 640 */
  118. 0x00000000, /* 703 - 672 */
  119. 0x00000000, /* 735 - 704 */
  120. 0x00000000, /* 767 - 736 */
  121. 0x00000000, /* 799 - 768 */
  122. 0x00000000, /* 831 - 800 */
  123. 0x00000000, /* 863 - 832 */
  124. 0x00000000, /* 895 - 864 */
  125. 0x00000000, /* 927 - 896 */
  126. 0x00000000, /* 959 - 928 */
  127. 0x00000000, /* 991 - 960 */
  128. 0x00000000, /* 1023 - 992 */
  129. 0x00000000, /* 1055 - 1024 */
  130. 0x00000000, /* 1087 - 1056 */
  131. 0x00000000, /* 1119 - 1088 */
  132. 0x00000000, /* 1151 - 1120 */
  133. 0x00000000, /* 1183 - 1152 */
  134. 0x00000000, /* 1215 - 1184 */
  135. 0x00000000, /* 1247 - 1216 */
  136. 0x00000000, /* 1279 - 1248 */
  137. 0x00000000, /* 1311 - 1280 */
  138. 0x00000000, /* 1343 - 1312 */
  139. 0x00000000, /* 1375 - 1344 */
  140. 0x00000000, /* 1407 - 1376 */
  141. 0x00000000, /* 1439 - 1408 */
  142. 0x00000000, /* 1471 - 1440 */
  143. 0x00000000, /* 1503 - 1472 */
  144. };
  145. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  146. if (!iwl3945_hw_valid_rtc_data_addr(base)) {
  147. IWL_ERROR("Invalid event log pointer 0x%08X\n", base);
  148. return;
  149. }
  150. ret = iwl3945_grab_nic_access(priv);
  151. if (ret) {
  152. IWL_WARNING("Can not read from adapter at this time.\n");
  153. return;
  154. }
  155. disable_ptr = iwl3945_read_targ_mem(priv, base + (4 * sizeof(u32)));
  156. array_size = iwl3945_read_targ_mem(priv, base + (5 * sizeof(u32)));
  157. iwl3945_release_nic_access(priv);
  158. if (IWL_EVT_DISABLE && (array_size == IWL_EVT_DISABLE_SIZE)) {
  159. IWL_DEBUG_INFO("Disabling selected uCode log events at 0x%x\n",
  160. disable_ptr);
  161. ret = iwl3945_grab_nic_access(priv);
  162. for (i = 0; i < IWL_EVT_DISABLE_SIZE; i++)
  163. iwl3945_write_targ_mem(priv,
  164. disable_ptr + (i * sizeof(u32)),
  165. evt_disable[i]);
  166. iwl3945_release_nic_access(priv);
  167. } else {
  168. IWL_DEBUG_INFO("Selected uCode log events may be disabled\n");
  169. IWL_DEBUG_INFO(" by writing \"1\"s into disable bitmap\n");
  170. IWL_DEBUG_INFO(" in SRAM at 0x%x, size %d u32s\n",
  171. disable_ptr, array_size);
  172. }
  173. }
  174. static int iwl3945_hwrate_to_plcp_idx(u8 plcp)
  175. {
  176. int idx;
  177. for (idx = 0; idx < IWL_RATE_COUNT; idx++)
  178. if (iwl3945_rates[idx].plcp == plcp)
  179. return idx;
  180. return -1;
  181. }
  182. /**
  183. * iwl3945_get_antenna_flags - Get antenna flags for RXON command
  184. * @priv: eeprom and antenna fields are used to determine antenna flags
  185. *
  186. * priv->eeprom is used to determine if antenna AUX/MAIN are reversed
  187. * priv->antenna specifies the antenna diversity mode:
  188. *
  189. * IWL_ANTENNA_DIVERISTY - NIC selects best antenna by itself
  190. * IWL_ANTENNA_MAIN - Force MAIN antenna
  191. * IWL_ANTENNA_AUX - Force AUX antenna
  192. */
  193. __le32 iwl3945_get_antenna_flags(const struct iwl3945_priv *priv)
  194. {
  195. switch (priv->antenna) {
  196. case IWL_ANTENNA_DIVERSITY:
  197. return 0;
  198. case IWL_ANTENNA_MAIN:
  199. if (priv->eeprom.antenna_switch_type)
  200. return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
  201. return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
  202. case IWL_ANTENNA_AUX:
  203. if (priv->eeprom.antenna_switch_type)
  204. return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
  205. return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
  206. }
  207. /* bad antenna selector value */
  208. IWL_ERROR("Bad antenna selector value (0x%x)\n", priv->antenna);
  209. return 0; /* "diversity" is default if error */
  210. }
  211. #ifdef CONFIG_IWL3945_DEBUG
  212. #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
  213. static const char *iwl3945_get_tx_fail_reason(u32 status)
  214. {
  215. switch (status & TX_STATUS_MSK) {
  216. case TX_STATUS_SUCCESS:
  217. return "SUCCESS";
  218. TX_STATUS_ENTRY(SHORT_LIMIT);
  219. TX_STATUS_ENTRY(LONG_LIMIT);
  220. TX_STATUS_ENTRY(FIFO_UNDERRUN);
  221. TX_STATUS_ENTRY(MGMNT_ABORT);
  222. TX_STATUS_ENTRY(NEXT_FRAG);
  223. TX_STATUS_ENTRY(LIFE_EXPIRE);
  224. TX_STATUS_ENTRY(DEST_PS);
  225. TX_STATUS_ENTRY(ABORTED);
  226. TX_STATUS_ENTRY(BT_RETRY);
  227. TX_STATUS_ENTRY(STA_INVALID);
  228. TX_STATUS_ENTRY(FRAG_DROPPED);
  229. TX_STATUS_ENTRY(TID_DISABLE);
  230. TX_STATUS_ENTRY(FRAME_FLUSHED);
  231. TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
  232. TX_STATUS_ENTRY(TX_LOCKED);
  233. TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
  234. }
  235. return "UNKNOWN";
  236. }
  237. #else
  238. static inline const char *iwl3945_get_tx_fail_reason(u32 status)
  239. {
  240. return "";
  241. }
  242. #endif
  243. /**
  244. * iwl3945_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
  245. *
  246. * When FW advances 'R' index, all entries between old and new 'R' index
  247. * need to be reclaimed. As result, some free space forms. If there is
  248. * enough free space (> low mark), wake the stack that feeds us.
  249. */
  250. static void iwl3945_tx_queue_reclaim(struct iwl3945_priv *priv,
  251. int txq_id, int index)
  252. {
  253. struct iwl3945_tx_queue *txq = &priv->txq[txq_id];
  254. struct iwl3945_queue *q = &txq->q;
  255. struct iwl3945_tx_info *tx_info;
  256. BUG_ON(txq_id == IWL_CMD_QUEUE_NUM);
  257. for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
  258. q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
  259. tx_info = &txq->txb[txq->q.read_ptr];
  260. ieee80211_tx_status_irqsafe(priv->hw, tx_info->skb[0]);
  261. tx_info->skb[0] = NULL;
  262. iwl3945_hw_txq_free_tfd(priv, txq);
  263. }
  264. if (iwl3945_queue_space(q) > q->low_mark && (txq_id >= 0) &&
  265. (txq_id != IWL_CMD_QUEUE_NUM) &&
  266. priv->mac80211_registered)
  267. ieee80211_wake_queue(priv->hw, txq_id);
  268. }
  269. /**
  270. * iwl3945_rx_reply_tx - Handle Tx response
  271. */
  272. static void iwl3945_rx_reply_tx(struct iwl3945_priv *priv,
  273. struct iwl3945_rx_mem_buffer *rxb)
  274. {
  275. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  276. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  277. int txq_id = SEQ_TO_QUEUE(sequence);
  278. int index = SEQ_TO_INDEX(sequence);
  279. struct iwl3945_tx_queue *txq = &priv->txq[txq_id];
  280. struct ieee80211_tx_info *info;
  281. struct iwl3945_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
  282. u32 status = le32_to_cpu(tx_resp->status);
  283. int rate_idx;
  284. if ((index >= txq->q.n_bd) || (iwl3945_x2_queue_used(&txq->q, index) == 0)) {
  285. IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
  286. "is out of range [0-%d] %d %d\n", txq_id,
  287. index, txq->q.n_bd, txq->q.write_ptr,
  288. txq->q.read_ptr);
  289. return;
  290. }
  291. info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
  292. memset(&info->status, 0, sizeof(info->status));
  293. info->status.retry_count = tx_resp->failure_frame;
  294. /* tx_status->rts_retry_count = tx_resp->failure_rts; */
  295. info->flags |= ((status & TX_STATUS_MSK) == TX_STATUS_SUCCESS) ?
  296. IEEE80211_TX_STAT_ACK : 0;
  297. IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) plcp rate %d retries %d\n",
  298. txq_id, iwl3945_get_tx_fail_reason(status), status,
  299. tx_resp->rate, tx_resp->failure_frame);
  300. rate_idx = iwl3945_hwrate_to_plcp_idx(tx_resp->rate);
  301. if (info->band == IEEE80211_BAND_5GHZ)
  302. rate_idx -= IWL_FIRST_OFDM_RATE;
  303. info->tx_rate_idx = rate_idx;
  304. IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
  305. iwl3945_tx_queue_reclaim(priv, txq_id, index);
  306. if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
  307. IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
  308. }
  309. /*****************************************************************************
  310. *
  311. * Intel PRO/Wireless 3945ABG/BG Network Connection
  312. *
  313. * RX handler implementations
  314. *
  315. *****************************************************************************/
  316. void iwl3945_hw_rx_statistics(struct iwl3945_priv *priv, struct iwl3945_rx_mem_buffer *rxb)
  317. {
  318. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  319. IWL_DEBUG_RX("Statistics notification received (%d vs %d).\n",
  320. (int)sizeof(struct iwl3945_notif_statistics),
  321. le32_to_cpu(pkt->len));
  322. memcpy(&priv->statistics, pkt->u.raw, sizeof(priv->statistics));
  323. iwl3945_led_background(priv);
  324. priv->last_statistics_time = jiffies;
  325. }
  326. /******************************************************************************
  327. *
  328. * Misc. internal state and helper functions
  329. *
  330. ******************************************************************************/
  331. #ifdef CONFIG_IWL3945_DEBUG
  332. /**
  333. * iwl3945_report_frame - dump frame to syslog during debug sessions
  334. *
  335. * You may hack this function to show different aspects of received frames,
  336. * including selective frame dumps.
  337. * group100 parameter selects whether to show 1 out of 100 good frames.
  338. */
  339. static void iwl3945_dbg_report_frame(struct iwl3945_priv *priv,
  340. struct iwl3945_rx_packet *pkt,
  341. struct ieee80211_hdr *header, int group100)
  342. {
  343. u32 to_us;
  344. u32 print_summary = 0;
  345. u32 print_dump = 0; /* set to 1 to dump all frames' contents */
  346. u32 hundred = 0;
  347. u32 dataframe = 0;
  348. __le16 fc;
  349. u16 seq_ctl;
  350. u16 channel;
  351. u16 phy_flags;
  352. u16 length;
  353. u16 status;
  354. u16 bcn_tmr;
  355. u32 tsf_low;
  356. u64 tsf;
  357. u8 rssi;
  358. u8 agc;
  359. u16 sig_avg;
  360. u16 noise_diff;
  361. struct iwl3945_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
  362. struct iwl3945_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
  363. struct iwl3945_rx_frame_end *rx_end = IWL_RX_END(pkt);
  364. u8 *data = IWL_RX_DATA(pkt);
  365. /* MAC header */
  366. fc = header->frame_control;
  367. seq_ctl = le16_to_cpu(header->seq_ctrl);
  368. /* metadata */
  369. channel = le16_to_cpu(rx_hdr->channel);
  370. phy_flags = le16_to_cpu(rx_hdr->phy_flags);
  371. length = le16_to_cpu(rx_hdr->len);
  372. /* end-of-frame status and timestamp */
  373. status = le32_to_cpu(rx_end->status);
  374. bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp);
  375. tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff;
  376. tsf = le64_to_cpu(rx_end->timestamp);
  377. /* signal statistics */
  378. rssi = rx_stats->rssi;
  379. agc = rx_stats->agc;
  380. sig_avg = le16_to_cpu(rx_stats->sig_avg);
  381. noise_diff = le16_to_cpu(rx_stats->noise_diff);
  382. to_us = !compare_ether_addr(header->addr1, priv->mac_addr);
  383. /* if data frame is to us and all is good,
  384. * (optionally) print summary for only 1 out of every 100 */
  385. if (to_us && (fc & ~cpu_to_le16(IEEE80211_FCTL_PROTECTED)) ==
  386. cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
  387. dataframe = 1;
  388. if (!group100)
  389. print_summary = 1; /* print each frame */
  390. else if (priv->framecnt_to_us < 100) {
  391. priv->framecnt_to_us++;
  392. print_summary = 0;
  393. } else {
  394. priv->framecnt_to_us = 0;
  395. print_summary = 1;
  396. hundred = 1;
  397. }
  398. } else {
  399. /* print summary for all other frames */
  400. print_summary = 1;
  401. }
  402. if (print_summary) {
  403. char *title;
  404. int rate;
  405. if (hundred)
  406. title = "100Frames";
  407. else if (ieee80211_has_retry(fc))
  408. title = "Retry";
  409. else if (ieee80211_is_assoc_resp(fc))
  410. title = "AscRsp";
  411. else if (ieee80211_is_reassoc_resp(fc))
  412. title = "RasRsp";
  413. else if (ieee80211_is_probe_resp(fc)) {
  414. title = "PrbRsp";
  415. print_dump = 1; /* dump frame contents */
  416. } else if (ieee80211_is_beacon(fc)) {
  417. title = "Beacon";
  418. print_dump = 1; /* dump frame contents */
  419. } else if (ieee80211_is_atim(fc))
  420. title = "ATIM";
  421. else if (ieee80211_is_auth(fc))
  422. title = "Auth";
  423. else if (ieee80211_is_deauth(fc))
  424. title = "DeAuth";
  425. else if (ieee80211_is_disassoc(fc))
  426. title = "DisAssoc";
  427. else
  428. title = "Frame";
  429. rate = iwl3945_hwrate_to_plcp_idx(rx_hdr->rate);
  430. if (rate == -1)
  431. rate = 0;
  432. else
  433. rate = iwl3945_rates[rate].ieee / 2;
  434. /* print frame summary.
  435. * MAC addresses show just the last byte (for brevity),
  436. * but you can hack it to show more, if you'd like to. */
  437. if (dataframe)
  438. IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
  439. "len=%u, rssi=%d, chnl=%d, rate=%d, \n",
  440. title, le16_to_cpu(fc), header->addr1[5],
  441. length, rssi, channel, rate);
  442. else {
  443. /* src/dst addresses assume managed mode */
  444. IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
  445. "src=0x%02x, rssi=%u, tim=%lu usec, "
  446. "phy=0x%02x, chnl=%d\n",
  447. title, le16_to_cpu(fc), header->addr1[5],
  448. header->addr3[5], rssi,
  449. tsf_low - priv->scan_start_tsf,
  450. phy_flags, channel);
  451. }
  452. }
  453. if (print_dump)
  454. iwl3945_print_hex_dump(IWL_DL_RX, data, length);
  455. }
  456. #else
  457. static inline void iwl3945_dbg_report_frame(struct iwl3945_priv *priv,
  458. struct iwl3945_rx_packet *pkt,
  459. struct ieee80211_hdr *header, int group100)
  460. {
  461. }
  462. #endif
  463. /* This is necessary only for a number of statistics, see the caller. */
  464. static int iwl3945_is_network_packet(struct iwl3945_priv *priv,
  465. struct ieee80211_hdr *header)
  466. {
  467. /* Filter incoming packets to determine if they are targeted toward
  468. * this network, discarding packets coming from ourselves */
  469. switch (priv->iw_mode) {
  470. case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */
  471. /* packets to our IBSS update information */
  472. return !compare_ether_addr(header->addr3, priv->bssid);
  473. case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
  474. /* packets to our IBSS update information */
  475. return !compare_ether_addr(header->addr2, priv->bssid);
  476. default:
  477. return 1;
  478. }
  479. }
  480. static void iwl3945_add_radiotap(struct iwl3945_priv *priv,
  481. struct sk_buff *skb,
  482. struct iwl3945_rx_frame_hdr *rx_hdr,
  483. struct ieee80211_rx_status *stats)
  484. {
  485. /* First cache any information we need before we overwrite
  486. * the information provided in the skb from the hardware */
  487. s8 signal = stats->signal;
  488. s8 noise = 0;
  489. int rate = stats->rate_idx;
  490. u64 tsf = stats->mactime;
  491. __le16 phy_flags_hw = rx_hdr->phy_flags, antenna;
  492. struct iwl3945_rt_rx_hdr {
  493. struct ieee80211_radiotap_header rt_hdr;
  494. __le64 rt_tsf; /* TSF */
  495. u8 rt_flags; /* radiotap packet flags */
  496. u8 rt_rate; /* rate in 500kb/s */
  497. __le16 rt_channelMHz; /* channel in MHz */
  498. __le16 rt_chbitmask; /* channel bitfield */
  499. s8 rt_dbmsignal; /* signal in dBm, kluged to signed */
  500. s8 rt_dbmnoise;
  501. u8 rt_antenna; /* antenna number */
  502. } __attribute__ ((packed)) *iwl3945_rt;
  503. if (skb_headroom(skb) < sizeof(*iwl3945_rt)) {
  504. if (net_ratelimit())
  505. printk(KERN_ERR "not enough headroom [%d] for "
  506. "radiotap head [%zd]\n",
  507. skb_headroom(skb), sizeof(*iwl3945_rt));
  508. return;
  509. }
  510. /* put radiotap header in front of 802.11 header and data */
  511. iwl3945_rt = (void *)skb_push(skb, sizeof(*iwl3945_rt));
  512. /* initialise radiotap header */
  513. iwl3945_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
  514. iwl3945_rt->rt_hdr.it_pad = 0;
  515. /* total header + data */
  516. put_unaligned_le16(sizeof(*iwl3945_rt), &iwl3945_rt->rt_hdr.it_len);
  517. /* Indicate all the fields we add to the radiotap header */
  518. put_unaligned_le32((1 << IEEE80211_RADIOTAP_TSFT) |
  519. (1 << IEEE80211_RADIOTAP_FLAGS) |
  520. (1 << IEEE80211_RADIOTAP_RATE) |
  521. (1 << IEEE80211_RADIOTAP_CHANNEL) |
  522. (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
  523. (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
  524. (1 << IEEE80211_RADIOTAP_ANTENNA),
  525. &iwl3945_rt->rt_hdr.it_present);
  526. /* Zero the flags, we'll add to them as we go */
  527. iwl3945_rt->rt_flags = 0;
  528. put_unaligned_le64(tsf, &iwl3945_rt->rt_tsf);
  529. iwl3945_rt->rt_dbmsignal = signal;
  530. iwl3945_rt->rt_dbmnoise = noise;
  531. /* Convert the channel frequency and set the flags */
  532. put_unaligned_le16(stats->freq, &iwl3945_rt->rt_channelMHz);
  533. if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK))
  534. put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ,
  535. &iwl3945_rt->rt_chbitmask);
  536. else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK)
  537. put_unaligned_le16(IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ,
  538. &iwl3945_rt->rt_chbitmask);
  539. else /* 802.11g */
  540. put_unaligned_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ,
  541. &iwl3945_rt->rt_chbitmask);
  542. if (rate == -1)
  543. iwl3945_rt->rt_rate = 0;
  544. else {
  545. if (stats->band == IEEE80211_BAND_5GHZ)
  546. rate += IWL_FIRST_OFDM_RATE;
  547. iwl3945_rt->rt_rate = iwl3945_rates[rate].ieee;
  548. }
  549. /* antenna number */
  550. antenna = phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK;
  551. iwl3945_rt->rt_antenna = le16_to_cpu(antenna) >> 4;
  552. /* set the preamble flag if we have it */
  553. if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
  554. iwl3945_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
  555. stats->flag |= RX_FLAG_RADIOTAP;
  556. }
  557. static void iwl3945_pass_packet_to_mac80211(struct iwl3945_priv *priv,
  558. struct iwl3945_rx_mem_buffer *rxb,
  559. struct ieee80211_rx_status *stats)
  560. {
  561. struct iwl3945_rx_packet *pkt = (struct iwl3945_rx_packet *)rxb->skb->data;
  562. #ifdef CONFIG_IWL3945_LEDS
  563. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)IWL_RX_DATA(pkt);
  564. #endif
  565. struct iwl3945_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
  566. struct iwl3945_rx_frame_end *rx_end = IWL_RX_END(pkt);
  567. short len = le16_to_cpu(rx_hdr->len);
  568. /* We received data from the HW, so stop the watchdog */
  569. if (unlikely((len + IWL_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) {
  570. IWL_DEBUG_DROP("Corruption detected!\n");
  571. return;
  572. }
  573. /* We only process data packets if the interface is open */
  574. if (unlikely(!priv->is_open)) {
  575. IWL_DEBUG_DROP_LIMIT
  576. ("Dropping packet while interface is not open.\n");
  577. return;
  578. }
  579. skb_reserve(rxb->skb, (void *)rx_hdr->payload - (void *)pkt);
  580. /* Set the size of the skb to the size of the frame */
  581. skb_put(rxb->skb, le16_to_cpu(rx_hdr->len));
  582. if (iwl3945_param_hwcrypto)
  583. iwl3945_set_decrypted_flag(priv, rxb->skb,
  584. le32_to_cpu(rx_end->status), stats);
  585. if (priv->add_radiotap)
  586. iwl3945_add_radiotap(priv, rxb->skb, rx_hdr, stats);
  587. #ifdef CONFIG_IWL3945_LEDS
  588. if (ieee80211_is_data(hdr->frame_control))
  589. priv->rxtxpackets += len;
  590. #endif
  591. ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats);
  592. rxb->skb = NULL;
  593. }
  594. #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
  595. static void iwl3945_rx_reply_rx(struct iwl3945_priv *priv,
  596. struct iwl3945_rx_mem_buffer *rxb)
  597. {
  598. struct ieee80211_hdr *header;
  599. struct ieee80211_rx_status rx_status;
  600. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  601. struct iwl3945_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
  602. struct iwl3945_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
  603. struct iwl3945_rx_frame_end *rx_end = IWL_RX_END(pkt);
  604. int snr;
  605. u16 rx_stats_sig_avg = le16_to_cpu(rx_stats->sig_avg);
  606. u16 rx_stats_noise_diff = le16_to_cpu(rx_stats->noise_diff);
  607. u8 network_packet;
  608. rx_status.antenna = 0;
  609. rx_status.flag = 0;
  610. rx_status.mactime = le64_to_cpu(rx_end->timestamp);
  611. rx_status.freq =
  612. ieee80211_channel_to_frequency(le16_to_cpu(rx_hdr->channel));
  613. rx_status.band = (rx_hdr->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
  614. IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
  615. rx_status.rate_idx = iwl3945_hwrate_to_plcp_idx(rx_hdr->rate);
  616. if (rx_status.band == IEEE80211_BAND_5GHZ)
  617. rx_status.rate_idx -= IWL_FIRST_OFDM_RATE;
  618. if ((unlikely(rx_stats->phy_count > 20))) {
  619. IWL_DEBUG_DROP
  620. ("dsp size out of range [0,20]: "
  621. "%d/n", rx_stats->phy_count);
  622. return;
  623. }
  624. if (!(rx_end->status & RX_RES_STATUS_NO_CRC32_ERROR)
  625. || !(rx_end->status & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
  626. IWL_DEBUG_RX("Bad CRC or FIFO: 0x%08X.\n", rx_end->status);
  627. return;
  628. }
  629. if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
  630. iwl3945_pass_packet_to_mac80211(priv, rxb, &rx_status);
  631. return;
  632. }
  633. /* Convert 3945's rssi indicator to dBm */
  634. rx_status.signal = rx_stats->rssi - IWL_RSSI_OFFSET;
  635. /* Set default noise value to -127 */
  636. if (priv->last_rx_noise == 0)
  637. priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
  638. /* 3945 provides noise info for OFDM frames only.
  639. * sig_avg and noise_diff are measured by the 3945's digital signal
  640. * processor (DSP), and indicate linear levels of signal level and
  641. * distortion/noise within the packet preamble after
  642. * automatic gain control (AGC). sig_avg should stay fairly
  643. * constant if the radio's AGC is working well.
  644. * Since these values are linear (not dB or dBm), linear
  645. * signal-to-noise ratio (SNR) is (sig_avg / noise_diff).
  646. * Convert linear SNR to dB SNR, then subtract that from rssi dBm
  647. * to obtain noise level in dBm.
  648. * Calculate rx_status.signal (quality indicator in %) based on SNR. */
  649. if (rx_stats_noise_diff) {
  650. snr = rx_stats_sig_avg / rx_stats_noise_diff;
  651. rx_status.noise = rx_status.signal -
  652. iwl3945_calc_db_from_ratio(snr);
  653. rx_status.qual = iwl3945_calc_sig_qual(rx_status.signal,
  654. rx_status.noise);
  655. /* If noise info not available, calculate signal quality indicator (%)
  656. * using just the dBm signal level. */
  657. } else {
  658. rx_status.noise = priv->last_rx_noise;
  659. rx_status.qual = iwl3945_calc_sig_qual(rx_status.signal, 0);
  660. }
  661. IWL_DEBUG_STATS("Rssi %d noise %d qual %d sig_avg %d noise_diff %d\n",
  662. rx_status.signal, rx_status.noise, rx_status.qual,
  663. rx_stats_sig_avg, rx_stats_noise_diff);
  664. header = (struct ieee80211_hdr *)IWL_RX_DATA(pkt);
  665. network_packet = iwl3945_is_network_packet(priv, header);
  666. IWL_DEBUG_STATS_LIMIT("[%c] %d RSSI:%d Signal:%u, Noise:%u, Rate:%u\n",
  667. network_packet ? '*' : ' ',
  668. le16_to_cpu(rx_hdr->channel),
  669. rx_status.signal, rx_status.signal,
  670. rx_status.noise, rx_status.rate_idx);
  671. #ifdef CONFIG_IWL3945_DEBUG
  672. if (iwl3945_debug_level & (IWL_DL_RX))
  673. /* Set "1" to report good data frames in groups of 100 */
  674. iwl3945_dbg_report_frame(priv, pkt, header, 1);
  675. #endif
  676. if (network_packet) {
  677. priv->last_beacon_time = le32_to_cpu(rx_end->beacon_timestamp);
  678. priv->last_tsf = le64_to_cpu(rx_end->timestamp);
  679. priv->last_rx_rssi = rx_status.signal;
  680. priv->last_rx_noise = rx_status.noise;
  681. }
  682. switch (le16_to_cpu(header->frame_control) & IEEE80211_FCTL_FTYPE) {
  683. case IEEE80211_FTYPE_MGMT:
  684. switch (le16_to_cpu(header->frame_control) &
  685. IEEE80211_FCTL_STYPE) {
  686. case IEEE80211_STYPE_PROBE_RESP:
  687. case IEEE80211_STYPE_BEACON:{
  688. /* If this is a beacon or probe response for
  689. * our network then cache the beacon
  690. * timestamp */
  691. if ((((priv->iw_mode == IEEE80211_IF_TYPE_STA)
  692. && !compare_ether_addr(header->addr2,
  693. priv->bssid)) ||
  694. ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  695. && !compare_ether_addr(header->addr3,
  696. priv->bssid)))) {
  697. struct ieee80211_mgmt *mgmt =
  698. (struct ieee80211_mgmt *)header;
  699. __le32 *pos;
  700. pos =
  701. (__le32 *) & mgmt->u.beacon.
  702. timestamp;
  703. priv->timestamp0 = le32_to_cpu(pos[0]);
  704. priv->timestamp1 = le32_to_cpu(pos[1]);
  705. priv->beacon_int = le16_to_cpu(
  706. mgmt->u.beacon.beacon_int);
  707. if (priv->call_post_assoc_from_beacon &&
  708. (priv->iw_mode ==
  709. IEEE80211_IF_TYPE_STA))
  710. queue_work(priv->workqueue,
  711. &priv->post_associate.work);
  712. priv->call_post_assoc_from_beacon = 0;
  713. }
  714. break;
  715. }
  716. case IEEE80211_STYPE_ACTION:
  717. /* TODO: Parse 802.11h frames for CSA... */
  718. break;
  719. /*
  720. * TODO: Use the new callback function from
  721. * mac80211 instead of sniffing these packets.
  722. */
  723. case IEEE80211_STYPE_ASSOC_RESP:
  724. case IEEE80211_STYPE_REASSOC_RESP:{
  725. struct ieee80211_mgmt *mgnt =
  726. (struct ieee80211_mgmt *)header;
  727. /* We have just associated, give some
  728. * time for the 4-way handshake if
  729. * any. Don't start scan too early. */
  730. priv->next_scan_jiffies = jiffies +
  731. IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
  732. priv->assoc_id = (~((1 << 15) | (1 << 14)) &
  733. le16_to_cpu(mgnt->u.
  734. assoc_resp.aid));
  735. priv->assoc_capability =
  736. le16_to_cpu(mgnt->u.assoc_resp.capab_info);
  737. if (priv->beacon_int)
  738. queue_work(priv->workqueue,
  739. &priv->post_associate.work);
  740. else
  741. priv->call_post_assoc_from_beacon = 1;
  742. break;
  743. }
  744. case IEEE80211_STYPE_PROBE_REQ:{
  745. DECLARE_MAC_BUF(mac1);
  746. DECLARE_MAC_BUF(mac2);
  747. DECLARE_MAC_BUF(mac3);
  748. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  749. IWL_DEBUG_DROP
  750. ("Dropping (non network): %s"
  751. ", %s, %s\n",
  752. print_mac(mac1, header->addr1),
  753. print_mac(mac2, header->addr2),
  754. print_mac(mac3, header->addr3));
  755. return;
  756. }
  757. }
  758. case IEEE80211_FTYPE_DATA:
  759. /* fall through */
  760. default:
  761. iwl3945_pass_packet_to_mac80211(priv, rxb, &rx_status);
  762. break;
  763. }
  764. }
  765. int iwl3945_hw_txq_attach_buf_to_tfd(struct iwl3945_priv *priv, void *ptr,
  766. dma_addr_t addr, u16 len)
  767. {
  768. int count;
  769. u32 pad;
  770. struct iwl3945_tfd_frame *tfd = (struct iwl3945_tfd_frame *)ptr;
  771. count = TFD_CTL_COUNT_GET(le32_to_cpu(tfd->control_flags));
  772. pad = TFD_CTL_PAD_GET(le32_to_cpu(tfd->control_flags));
  773. if ((count >= NUM_TFD_CHUNKS) || (count < 0)) {
  774. IWL_ERROR("Error can not send more than %d chunks\n",
  775. NUM_TFD_CHUNKS);
  776. return -EINVAL;
  777. }
  778. tfd->pa[count].addr = cpu_to_le32(addr);
  779. tfd->pa[count].len = cpu_to_le32(len);
  780. count++;
  781. tfd->control_flags = cpu_to_le32(TFD_CTL_COUNT_SET(count) |
  782. TFD_CTL_PAD_SET(pad));
  783. return 0;
  784. }
  785. /**
  786. * iwl3945_hw_txq_free_tfd - Free one TFD, those at index [txq->q.read_ptr]
  787. *
  788. * Does NOT advance any indexes
  789. */
  790. int iwl3945_hw_txq_free_tfd(struct iwl3945_priv *priv, struct iwl3945_tx_queue *txq)
  791. {
  792. struct iwl3945_tfd_frame *bd_tmp = (struct iwl3945_tfd_frame *)&txq->bd[0];
  793. struct iwl3945_tfd_frame *bd = &bd_tmp[txq->q.read_ptr];
  794. struct pci_dev *dev = priv->pci_dev;
  795. int i;
  796. int counter;
  797. /* classify bd */
  798. if (txq->q.id == IWL_CMD_QUEUE_NUM)
  799. /* nothing to cleanup after for host commands */
  800. return 0;
  801. /* sanity check */
  802. counter = TFD_CTL_COUNT_GET(le32_to_cpu(bd->control_flags));
  803. if (counter > NUM_TFD_CHUNKS) {
  804. IWL_ERROR("Too many chunks: %i\n", counter);
  805. /* @todo issue fatal error, it is quite serious situation */
  806. return 0;
  807. }
  808. /* unmap chunks if any */
  809. for (i = 1; i < counter; i++) {
  810. pci_unmap_single(dev, le32_to_cpu(bd->pa[i].addr),
  811. le32_to_cpu(bd->pa[i].len), PCI_DMA_TODEVICE);
  812. if (txq->txb[txq->q.read_ptr].skb[0]) {
  813. struct sk_buff *skb = txq->txb[txq->q.read_ptr].skb[0];
  814. if (txq->txb[txq->q.read_ptr].skb[0]) {
  815. /* Can be called from interrupt context */
  816. dev_kfree_skb_any(skb);
  817. txq->txb[txq->q.read_ptr].skb[0] = NULL;
  818. }
  819. }
  820. }
  821. return 0;
  822. }
  823. u8 iwl3945_hw_find_station(struct iwl3945_priv *priv, const u8 *addr)
  824. {
  825. int i;
  826. int ret = IWL_INVALID_STATION;
  827. unsigned long flags;
  828. DECLARE_MAC_BUF(mac);
  829. spin_lock_irqsave(&priv->sta_lock, flags);
  830. for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++)
  831. if ((priv->stations[i].used) &&
  832. (!compare_ether_addr
  833. (priv->stations[i].sta.sta.addr, addr))) {
  834. ret = i;
  835. goto out;
  836. }
  837. IWL_DEBUG_INFO("can not find STA %s (total %d)\n",
  838. print_mac(mac, addr), priv->num_stations);
  839. out:
  840. spin_unlock_irqrestore(&priv->sta_lock, flags);
  841. return ret;
  842. }
  843. /**
  844. * iwl3945_hw_build_tx_cmd_rate - Add rate portion to TX_CMD:
  845. *
  846. */
  847. void iwl3945_hw_build_tx_cmd_rate(struct iwl3945_priv *priv,
  848. struct iwl3945_cmd *cmd,
  849. struct ieee80211_tx_info *info,
  850. struct ieee80211_hdr *hdr, int sta_id, int tx_id)
  851. {
  852. unsigned long flags;
  853. u16 hw_value = ieee80211_get_tx_rate(priv->hw, info)->hw_value;
  854. u16 rate_index = min(hw_value & 0xffff, IWL_RATE_COUNT - 1);
  855. u16 rate_mask;
  856. int rate;
  857. u8 rts_retry_limit;
  858. u8 data_retry_limit;
  859. __le32 tx_flags;
  860. __le16 fc = hdr->frame_control;
  861. rate = iwl3945_rates[rate_index].plcp;
  862. tx_flags = cmd->cmd.tx.tx_flags;
  863. /* We need to figure out how to get the sta->supp_rates while
  864. * in this running context */
  865. rate_mask = IWL_RATES_MASK;
  866. spin_lock_irqsave(&priv->sta_lock, flags);
  867. priv->stations[sta_id].current_rate.rate_n_flags = rate;
  868. if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
  869. (sta_id != priv->hw_setting.bcast_sta_id) &&
  870. (sta_id != IWL_MULTICAST_ID))
  871. priv->stations[IWL_STA_ID].current_rate.rate_n_flags = rate;
  872. spin_unlock_irqrestore(&priv->sta_lock, flags);
  873. if (tx_id >= IWL_CMD_QUEUE_NUM)
  874. rts_retry_limit = 3;
  875. else
  876. rts_retry_limit = 7;
  877. if (ieee80211_is_probe_resp(fc)) {
  878. data_retry_limit = 3;
  879. if (data_retry_limit < rts_retry_limit)
  880. rts_retry_limit = data_retry_limit;
  881. } else
  882. data_retry_limit = IWL_DEFAULT_TX_RETRY;
  883. if (priv->data_retry_limit != -1)
  884. data_retry_limit = priv->data_retry_limit;
  885. if (ieee80211_is_mgmt(fc)) {
  886. switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
  887. case cpu_to_le16(IEEE80211_STYPE_AUTH):
  888. case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
  889. case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
  890. case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
  891. if (tx_flags & TX_CMD_FLG_RTS_MSK) {
  892. tx_flags &= ~TX_CMD_FLG_RTS_MSK;
  893. tx_flags |= TX_CMD_FLG_CTS_MSK;
  894. }
  895. break;
  896. default:
  897. break;
  898. }
  899. }
  900. cmd->cmd.tx.rts_retry_limit = rts_retry_limit;
  901. cmd->cmd.tx.data_retry_limit = data_retry_limit;
  902. cmd->cmd.tx.rate = rate;
  903. cmd->cmd.tx.tx_flags = tx_flags;
  904. /* OFDM */
  905. cmd->cmd.tx.supp_rates[0] =
  906. ((rate_mask & IWL_OFDM_RATES_MASK) >> IWL_FIRST_OFDM_RATE) & 0xFF;
  907. /* CCK */
  908. cmd->cmd.tx.supp_rates[1] = (rate_mask & 0xF);
  909. IWL_DEBUG_RATE("Tx sta id: %d, rate: %d (plcp), flags: 0x%4X "
  910. "cck/ofdm mask: 0x%x/0x%x\n", sta_id,
  911. cmd->cmd.tx.rate, le32_to_cpu(cmd->cmd.tx.tx_flags),
  912. cmd->cmd.tx.supp_rates[1], cmd->cmd.tx.supp_rates[0]);
  913. }
  914. u8 iwl3945_sync_sta(struct iwl3945_priv *priv, int sta_id, u16 tx_rate, u8 flags)
  915. {
  916. unsigned long flags_spin;
  917. struct iwl3945_station_entry *station;
  918. if (sta_id == IWL_INVALID_STATION)
  919. return IWL_INVALID_STATION;
  920. spin_lock_irqsave(&priv->sta_lock, flags_spin);
  921. station = &priv->stations[sta_id];
  922. station->sta.sta.modify_mask = STA_MODIFY_TX_RATE_MSK;
  923. station->sta.rate_n_flags = cpu_to_le16(tx_rate);
  924. station->current_rate.rate_n_flags = tx_rate;
  925. station->sta.mode = STA_CONTROL_MODIFY_MSK;
  926. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  927. iwl3945_send_add_station(priv, &station->sta, flags);
  928. IWL_DEBUG_RATE("SCALE sync station %d to rate %d\n",
  929. sta_id, tx_rate);
  930. return sta_id;
  931. }
  932. static int iwl3945_nic_set_pwr_src(struct iwl3945_priv *priv, int pwr_max)
  933. {
  934. int rc;
  935. unsigned long flags;
  936. spin_lock_irqsave(&priv->lock, flags);
  937. rc = iwl3945_grab_nic_access(priv);
  938. if (rc) {
  939. spin_unlock_irqrestore(&priv->lock, flags);
  940. return rc;
  941. }
  942. if (!pwr_max) {
  943. u32 val;
  944. rc = pci_read_config_dword(priv->pci_dev,
  945. PCI_POWER_SOURCE, &val);
  946. if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT) {
  947. iwl3945_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
  948. APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
  949. ~APMG_PS_CTRL_MSK_PWR_SRC);
  950. iwl3945_release_nic_access(priv);
  951. iwl3945_poll_bit(priv, CSR_GPIO_IN,
  952. CSR_GPIO_IN_VAL_VAUX_PWR_SRC,
  953. CSR_GPIO_IN_BIT_AUX_POWER, 5000);
  954. } else
  955. iwl3945_release_nic_access(priv);
  956. } else {
  957. iwl3945_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
  958. APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
  959. ~APMG_PS_CTRL_MSK_PWR_SRC);
  960. iwl3945_release_nic_access(priv);
  961. iwl3945_poll_bit(priv, CSR_GPIO_IN, CSR_GPIO_IN_VAL_VMAIN_PWR_SRC,
  962. CSR_GPIO_IN_BIT_AUX_POWER, 5000); /* uS */
  963. }
  964. spin_unlock_irqrestore(&priv->lock, flags);
  965. return rc;
  966. }
  967. static int iwl3945_rx_init(struct iwl3945_priv *priv, struct iwl3945_rx_queue *rxq)
  968. {
  969. int rc;
  970. unsigned long flags;
  971. spin_lock_irqsave(&priv->lock, flags);
  972. rc = iwl3945_grab_nic_access(priv);
  973. if (rc) {
  974. spin_unlock_irqrestore(&priv->lock, flags);
  975. return rc;
  976. }
  977. iwl3945_write_direct32(priv, FH_RCSR_RBD_BASE(0), rxq->dma_addr);
  978. iwl3945_write_direct32(priv, FH_RCSR_RPTR_ADDR(0),
  979. priv->hw_setting.shared_phys +
  980. offsetof(struct iwl3945_shared, rx_read_ptr[0]));
  981. iwl3945_write_direct32(priv, FH_RCSR_WPTR(0), 0);
  982. iwl3945_write_direct32(priv, FH_RCSR_CONFIG(0),
  983. ALM_FH_RCSR_RX_CONFIG_REG_VAL_DMA_CHNL_EN_ENABLE |
  984. ALM_FH_RCSR_RX_CONFIG_REG_VAL_RDRBD_EN_ENABLE |
  985. ALM_FH_RCSR_RX_CONFIG_REG_BIT_WR_STTS_EN |
  986. ALM_FH_RCSR_RX_CONFIG_REG_VAL_MAX_FRAG_SIZE_128 |
  987. (RX_QUEUE_SIZE_LOG << ALM_FH_RCSR_RX_CONFIG_REG_POS_RBDC_SIZE) |
  988. ALM_FH_RCSR_RX_CONFIG_REG_VAL_IRQ_DEST_INT_HOST |
  989. (1 << ALM_FH_RCSR_RX_CONFIG_REG_POS_IRQ_RBTH) |
  990. ALM_FH_RCSR_RX_CONFIG_REG_VAL_MSG_MODE_FH);
  991. /* fake read to flush all prev I/O */
  992. iwl3945_read_direct32(priv, FH_RSSR_CTRL);
  993. iwl3945_release_nic_access(priv);
  994. spin_unlock_irqrestore(&priv->lock, flags);
  995. return 0;
  996. }
  997. static int iwl3945_tx_reset(struct iwl3945_priv *priv)
  998. {
  999. int rc;
  1000. unsigned long flags;
  1001. spin_lock_irqsave(&priv->lock, flags);
  1002. rc = iwl3945_grab_nic_access(priv);
  1003. if (rc) {
  1004. spin_unlock_irqrestore(&priv->lock, flags);
  1005. return rc;
  1006. }
  1007. /* bypass mode */
  1008. iwl3945_write_prph(priv, ALM_SCD_MODE_REG, 0x2);
  1009. /* RA 0 is active */
  1010. iwl3945_write_prph(priv, ALM_SCD_ARASTAT_REG, 0x01);
  1011. /* all 6 fifo are active */
  1012. iwl3945_write_prph(priv, ALM_SCD_TXFACT_REG, 0x3f);
  1013. iwl3945_write_prph(priv, ALM_SCD_SBYP_MODE_1_REG, 0x010000);
  1014. iwl3945_write_prph(priv, ALM_SCD_SBYP_MODE_2_REG, 0x030002);
  1015. iwl3945_write_prph(priv, ALM_SCD_TXF4MF_REG, 0x000004);
  1016. iwl3945_write_prph(priv, ALM_SCD_TXF5MF_REG, 0x000005);
  1017. iwl3945_write_direct32(priv, FH_TSSR_CBB_BASE,
  1018. priv->hw_setting.shared_phys);
  1019. iwl3945_write_direct32(priv, FH_TSSR_MSG_CONFIG,
  1020. ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_SNOOP_RD_TXPD_ON |
  1021. ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RD_TXPD_ON |
  1022. ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_MAX_FRAG_SIZE_128B |
  1023. ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_SNOOP_RD_TFD_ON |
  1024. ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RD_CBB_ON |
  1025. ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RSP_WAIT_TH |
  1026. ALM_FH_TSSR_TX_MSG_CONFIG_REG_VAL_RSP_WAIT_TH);
  1027. iwl3945_release_nic_access(priv);
  1028. spin_unlock_irqrestore(&priv->lock, flags);
  1029. return 0;
  1030. }
  1031. /**
  1032. * iwl3945_txq_ctx_reset - Reset TX queue context
  1033. *
  1034. * Destroys all DMA structures and initialize them again
  1035. */
  1036. static int iwl3945_txq_ctx_reset(struct iwl3945_priv *priv)
  1037. {
  1038. int rc;
  1039. int txq_id, slots_num;
  1040. iwl3945_hw_txq_ctx_free(priv);
  1041. /* Tx CMD queue */
  1042. rc = iwl3945_tx_reset(priv);
  1043. if (rc)
  1044. goto error;
  1045. /* Tx queue(s) */
  1046. for (txq_id = 0; txq_id < TFD_QUEUE_MAX; txq_id++) {
  1047. slots_num = (txq_id == IWL_CMD_QUEUE_NUM) ?
  1048. TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
  1049. rc = iwl3945_tx_queue_init(priv, &priv->txq[txq_id], slots_num,
  1050. txq_id);
  1051. if (rc) {
  1052. IWL_ERROR("Tx %d queue init failed\n", txq_id);
  1053. goto error;
  1054. }
  1055. }
  1056. return rc;
  1057. error:
  1058. iwl3945_hw_txq_ctx_free(priv);
  1059. return rc;
  1060. }
  1061. int iwl3945_hw_nic_init(struct iwl3945_priv *priv)
  1062. {
  1063. u8 rev_id;
  1064. int rc;
  1065. unsigned long flags;
  1066. struct iwl3945_rx_queue *rxq = &priv->rxq;
  1067. iwl3945_power_init_handle(priv);
  1068. spin_lock_irqsave(&priv->lock, flags);
  1069. iwl3945_set_bit(priv, CSR_ANA_PLL_CFG, CSR39_ANA_PLL_CFG_VAL);
  1070. iwl3945_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  1071. CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
  1072. iwl3945_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  1073. rc = iwl3945_poll_bit(priv, CSR_GP_CNTRL,
  1074. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  1075. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  1076. if (rc < 0) {
  1077. spin_unlock_irqrestore(&priv->lock, flags);
  1078. IWL_DEBUG_INFO("Failed to init the card\n");
  1079. return rc;
  1080. }
  1081. rc = iwl3945_grab_nic_access(priv);
  1082. if (rc) {
  1083. spin_unlock_irqrestore(&priv->lock, flags);
  1084. return rc;
  1085. }
  1086. iwl3945_write_prph(priv, APMG_CLK_EN_REG,
  1087. APMG_CLK_VAL_DMA_CLK_RQT |
  1088. APMG_CLK_VAL_BSM_CLK_RQT);
  1089. udelay(20);
  1090. iwl3945_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  1091. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  1092. iwl3945_release_nic_access(priv);
  1093. spin_unlock_irqrestore(&priv->lock, flags);
  1094. /* Determine HW type */
  1095. rc = pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &rev_id);
  1096. if (rc)
  1097. return rc;
  1098. IWL_DEBUG_INFO("HW Revision ID = 0x%X\n", rev_id);
  1099. iwl3945_nic_set_pwr_src(priv, 1);
  1100. spin_lock_irqsave(&priv->lock, flags);
  1101. if (rev_id & PCI_CFG_REV_ID_BIT_RTP)
  1102. IWL_DEBUG_INFO("RTP type \n");
  1103. else if (rev_id & PCI_CFG_REV_ID_BIT_BASIC_SKU) {
  1104. IWL_DEBUG_INFO("3945 RADIO-MB type\n");
  1105. iwl3945_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  1106. CSR39_HW_IF_CONFIG_REG_BIT_3945_MB);
  1107. } else {
  1108. IWL_DEBUG_INFO("3945 RADIO-MM type\n");
  1109. iwl3945_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  1110. CSR39_HW_IF_CONFIG_REG_BIT_3945_MM);
  1111. }
  1112. if (EEPROM_SKU_CAP_OP_MODE_MRC == priv->eeprom.sku_cap) {
  1113. IWL_DEBUG_INFO("SKU OP mode is mrc\n");
  1114. iwl3945_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  1115. CSR39_HW_IF_CONFIG_REG_BIT_SKU_MRC);
  1116. } else
  1117. IWL_DEBUG_INFO("SKU OP mode is basic\n");
  1118. if ((priv->eeprom.board_revision & 0xF0) == 0xD0) {
  1119. IWL_DEBUG_INFO("3945ABG revision is 0x%X\n",
  1120. priv->eeprom.board_revision);
  1121. iwl3945_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  1122. CSR39_HW_IF_CONFIG_REG_BIT_BOARD_TYPE);
  1123. } else {
  1124. IWL_DEBUG_INFO("3945ABG revision is 0x%X\n",
  1125. priv->eeprom.board_revision);
  1126. iwl3945_clear_bit(priv, CSR_HW_IF_CONFIG_REG,
  1127. CSR39_HW_IF_CONFIG_REG_BIT_BOARD_TYPE);
  1128. }
  1129. if (priv->eeprom.almgor_m_version <= 1) {
  1130. iwl3945_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  1131. CSR39_HW_IF_CONFIG_REG_BITS_SILICON_TYPE_A);
  1132. IWL_DEBUG_INFO("Card M type A version is 0x%X\n",
  1133. priv->eeprom.almgor_m_version);
  1134. } else {
  1135. IWL_DEBUG_INFO("Card M type B version is 0x%X\n",
  1136. priv->eeprom.almgor_m_version);
  1137. iwl3945_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  1138. CSR39_HW_IF_CONFIG_REG_BITS_SILICON_TYPE_B);
  1139. }
  1140. spin_unlock_irqrestore(&priv->lock, flags);
  1141. if (priv->eeprom.sku_cap & EEPROM_SKU_CAP_SW_RF_KILL_ENABLE)
  1142. IWL_DEBUG_RF_KILL("SW RF KILL supported in EEPROM.\n");
  1143. if (priv->eeprom.sku_cap & EEPROM_SKU_CAP_HW_RF_KILL_ENABLE)
  1144. IWL_DEBUG_RF_KILL("HW RF KILL supported in EEPROM.\n");
  1145. /* Allocate the RX queue, or reset if it is already allocated */
  1146. if (!rxq->bd) {
  1147. rc = iwl3945_rx_queue_alloc(priv);
  1148. if (rc) {
  1149. IWL_ERROR("Unable to initialize Rx queue\n");
  1150. return -ENOMEM;
  1151. }
  1152. } else
  1153. iwl3945_rx_queue_reset(priv, rxq);
  1154. iwl3945_rx_replenish(priv);
  1155. iwl3945_rx_init(priv, rxq);
  1156. spin_lock_irqsave(&priv->lock, flags);
  1157. /* Look at using this instead:
  1158. rxq->need_update = 1;
  1159. iwl3945_rx_queue_update_write_ptr(priv, rxq);
  1160. */
  1161. rc = iwl3945_grab_nic_access(priv);
  1162. if (rc) {
  1163. spin_unlock_irqrestore(&priv->lock, flags);
  1164. return rc;
  1165. }
  1166. iwl3945_write_direct32(priv, FH_RCSR_WPTR(0), rxq->write & ~7);
  1167. iwl3945_release_nic_access(priv);
  1168. spin_unlock_irqrestore(&priv->lock, flags);
  1169. rc = iwl3945_txq_ctx_reset(priv);
  1170. if (rc)
  1171. return rc;
  1172. set_bit(STATUS_INIT, &priv->status);
  1173. return 0;
  1174. }
  1175. /**
  1176. * iwl3945_hw_txq_ctx_free - Free TXQ Context
  1177. *
  1178. * Destroy all TX DMA queues and structures
  1179. */
  1180. void iwl3945_hw_txq_ctx_free(struct iwl3945_priv *priv)
  1181. {
  1182. int txq_id;
  1183. /* Tx queues */
  1184. for (txq_id = 0; txq_id < TFD_QUEUE_MAX; txq_id++)
  1185. iwl3945_tx_queue_free(priv, &priv->txq[txq_id]);
  1186. }
  1187. void iwl3945_hw_txq_ctx_stop(struct iwl3945_priv *priv)
  1188. {
  1189. int queue;
  1190. unsigned long flags;
  1191. spin_lock_irqsave(&priv->lock, flags);
  1192. if (iwl3945_grab_nic_access(priv)) {
  1193. spin_unlock_irqrestore(&priv->lock, flags);
  1194. iwl3945_hw_txq_ctx_free(priv);
  1195. return;
  1196. }
  1197. /* stop SCD */
  1198. iwl3945_write_prph(priv, ALM_SCD_MODE_REG, 0);
  1199. /* reset TFD queues */
  1200. for (queue = TFD_QUEUE_MIN; queue < TFD_QUEUE_MAX; queue++) {
  1201. iwl3945_write_direct32(priv, FH_TCSR_CONFIG(queue), 0x0);
  1202. iwl3945_poll_direct_bit(priv, FH_TSSR_TX_STATUS,
  1203. ALM_FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(queue),
  1204. 1000);
  1205. }
  1206. iwl3945_release_nic_access(priv);
  1207. spin_unlock_irqrestore(&priv->lock, flags);
  1208. iwl3945_hw_txq_ctx_free(priv);
  1209. }
  1210. int iwl3945_hw_nic_stop_master(struct iwl3945_priv *priv)
  1211. {
  1212. int rc = 0;
  1213. u32 reg_val;
  1214. unsigned long flags;
  1215. spin_lock_irqsave(&priv->lock, flags);
  1216. /* set stop master bit */
  1217. iwl3945_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
  1218. reg_val = iwl3945_read32(priv, CSR_GP_CNTRL);
  1219. if (CSR_GP_CNTRL_REG_FLAG_MAC_POWER_SAVE ==
  1220. (reg_val & CSR_GP_CNTRL_REG_MSK_POWER_SAVE_TYPE))
  1221. IWL_DEBUG_INFO("Card in power save, master is already "
  1222. "stopped\n");
  1223. else {
  1224. rc = iwl3945_poll_bit(priv, CSR_RESET,
  1225. CSR_RESET_REG_FLAG_MASTER_DISABLED,
  1226. CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
  1227. if (rc < 0) {
  1228. spin_unlock_irqrestore(&priv->lock, flags);
  1229. return rc;
  1230. }
  1231. }
  1232. spin_unlock_irqrestore(&priv->lock, flags);
  1233. IWL_DEBUG_INFO("stop master\n");
  1234. return rc;
  1235. }
  1236. int iwl3945_hw_nic_reset(struct iwl3945_priv *priv)
  1237. {
  1238. int rc;
  1239. unsigned long flags;
  1240. iwl3945_hw_nic_stop_master(priv);
  1241. spin_lock_irqsave(&priv->lock, flags);
  1242. iwl3945_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  1243. rc = iwl3945_poll_bit(priv, CSR_GP_CNTRL,
  1244. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  1245. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  1246. rc = iwl3945_grab_nic_access(priv);
  1247. if (!rc) {
  1248. iwl3945_write_prph(priv, APMG_CLK_CTRL_REG,
  1249. APMG_CLK_VAL_BSM_CLK_RQT);
  1250. udelay(10);
  1251. iwl3945_set_bit(priv, CSR_GP_CNTRL,
  1252. CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  1253. iwl3945_write_prph(priv, APMG_RTC_INT_MSK_REG, 0x0);
  1254. iwl3945_write_prph(priv, APMG_RTC_INT_STT_REG,
  1255. 0xFFFFFFFF);
  1256. /* enable DMA */
  1257. iwl3945_write_prph(priv, APMG_CLK_EN_REG,
  1258. APMG_CLK_VAL_DMA_CLK_RQT |
  1259. APMG_CLK_VAL_BSM_CLK_RQT);
  1260. udelay(10);
  1261. iwl3945_set_bits_prph(priv, APMG_PS_CTRL_REG,
  1262. APMG_PS_CTRL_VAL_RESET_REQ);
  1263. udelay(5);
  1264. iwl3945_clear_bits_prph(priv, APMG_PS_CTRL_REG,
  1265. APMG_PS_CTRL_VAL_RESET_REQ);
  1266. iwl3945_release_nic_access(priv);
  1267. }
  1268. /* Clear the 'host command active' bit... */
  1269. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  1270. wake_up_interruptible(&priv->wait_command_queue);
  1271. spin_unlock_irqrestore(&priv->lock, flags);
  1272. return rc;
  1273. }
  1274. /**
  1275. * iwl3945_hw_reg_adjust_power_by_temp
  1276. * return index delta into power gain settings table
  1277. */
  1278. static int iwl3945_hw_reg_adjust_power_by_temp(int new_reading, int old_reading)
  1279. {
  1280. return (new_reading - old_reading) * (-11) / 100;
  1281. }
  1282. /**
  1283. * iwl3945_hw_reg_temp_out_of_range - Keep temperature in sane range
  1284. */
  1285. static inline int iwl3945_hw_reg_temp_out_of_range(int temperature)
  1286. {
  1287. return (((temperature < -260) || (temperature > 25)) ? 1 : 0);
  1288. }
  1289. int iwl3945_hw_get_temperature(struct iwl3945_priv *priv)
  1290. {
  1291. return iwl3945_read32(priv, CSR_UCODE_DRV_GP2);
  1292. }
  1293. /**
  1294. * iwl3945_hw_reg_txpower_get_temperature
  1295. * get the current temperature by reading from NIC
  1296. */
  1297. static int iwl3945_hw_reg_txpower_get_temperature(struct iwl3945_priv *priv)
  1298. {
  1299. int temperature;
  1300. temperature = iwl3945_hw_get_temperature(priv);
  1301. /* driver's okay range is -260 to +25.
  1302. * human readable okay range is 0 to +285 */
  1303. IWL_DEBUG_INFO("Temperature: %d\n", temperature + IWL_TEMP_CONVERT);
  1304. /* handle insane temp reading */
  1305. if (iwl3945_hw_reg_temp_out_of_range(temperature)) {
  1306. IWL_ERROR("Error bad temperature value %d\n", temperature);
  1307. /* if really really hot(?),
  1308. * substitute the 3rd band/group's temp measured at factory */
  1309. if (priv->last_temperature > 100)
  1310. temperature = priv->eeprom.groups[2].temperature;
  1311. else /* else use most recent "sane" value from driver */
  1312. temperature = priv->last_temperature;
  1313. }
  1314. return temperature; /* raw, not "human readable" */
  1315. }
  1316. /* Adjust Txpower only if temperature variance is greater than threshold.
  1317. *
  1318. * Both are lower than older versions' 9 degrees */
  1319. #define IWL_TEMPERATURE_LIMIT_TIMER 6
  1320. /**
  1321. * is_temp_calib_needed - determines if new calibration is needed
  1322. *
  1323. * records new temperature in tx_mgr->temperature.
  1324. * replaces tx_mgr->last_temperature *only* if calib needed
  1325. * (assumes caller will actually do the calibration!). */
  1326. static int is_temp_calib_needed(struct iwl3945_priv *priv)
  1327. {
  1328. int temp_diff;
  1329. priv->temperature = iwl3945_hw_reg_txpower_get_temperature(priv);
  1330. temp_diff = priv->temperature - priv->last_temperature;
  1331. /* get absolute value */
  1332. if (temp_diff < 0) {
  1333. IWL_DEBUG_POWER("Getting cooler, delta %d,\n", temp_diff);
  1334. temp_diff = -temp_diff;
  1335. } else if (temp_diff == 0)
  1336. IWL_DEBUG_POWER("Same temp,\n");
  1337. else
  1338. IWL_DEBUG_POWER("Getting warmer, delta %d,\n", temp_diff);
  1339. /* if we don't need calibration, *don't* update last_temperature */
  1340. if (temp_diff < IWL_TEMPERATURE_LIMIT_TIMER) {
  1341. IWL_DEBUG_POWER("Timed thermal calib not needed\n");
  1342. return 0;
  1343. }
  1344. IWL_DEBUG_POWER("Timed thermal calib needed\n");
  1345. /* assume that caller will actually do calib ...
  1346. * update the "last temperature" value */
  1347. priv->last_temperature = priv->temperature;
  1348. return 1;
  1349. }
  1350. #define IWL_MAX_GAIN_ENTRIES 78
  1351. #define IWL_CCK_FROM_OFDM_POWER_DIFF -5
  1352. #define IWL_CCK_FROM_OFDM_INDEX_DIFF (10)
  1353. /* radio and DSP power table, each step is 1/2 dB.
  1354. * 1st number is for RF analog gain, 2nd number is for DSP pre-DAC gain. */
  1355. static struct iwl3945_tx_power power_gain_table[2][IWL_MAX_GAIN_ENTRIES] = {
  1356. {
  1357. {251, 127}, /* 2.4 GHz, highest power */
  1358. {251, 127},
  1359. {251, 127},
  1360. {251, 127},
  1361. {251, 125},
  1362. {251, 110},
  1363. {251, 105},
  1364. {251, 98},
  1365. {187, 125},
  1366. {187, 115},
  1367. {187, 108},
  1368. {187, 99},
  1369. {243, 119},
  1370. {243, 111},
  1371. {243, 105},
  1372. {243, 97},
  1373. {243, 92},
  1374. {211, 106},
  1375. {211, 100},
  1376. {179, 120},
  1377. {179, 113},
  1378. {179, 107},
  1379. {147, 125},
  1380. {147, 119},
  1381. {147, 112},
  1382. {147, 106},
  1383. {147, 101},
  1384. {147, 97},
  1385. {147, 91},
  1386. {115, 107},
  1387. {235, 121},
  1388. {235, 115},
  1389. {235, 109},
  1390. {203, 127},
  1391. {203, 121},
  1392. {203, 115},
  1393. {203, 108},
  1394. {203, 102},
  1395. {203, 96},
  1396. {203, 92},
  1397. {171, 110},
  1398. {171, 104},
  1399. {171, 98},
  1400. {139, 116},
  1401. {227, 125},
  1402. {227, 119},
  1403. {227, 113},
  1404. {227, 107},
  1405. {227, 101},
  1406. {227, 96},
  1407. {195, 113},
  1408. {195, 106},
  1409. {195, 102},
  1410. {195, 95},
  1411. {163, 113},
  1412. {163, 106},
  1413. {163, 102},
  1414. {163, 95},
  1415. {131, 113},
  1416. {131, 106},
  1417. {131, 102},
  1418. {131, 95},
  1419. {99, 113},
  1420. {99, 106},
  1421. {99, 102},
  1422. {99, 95},
  1423. {67, 113},
  1424. {67, 106},
  1425. {67, 102},
  1426. {67, 95},
  1427. {35, 113},
  1428. {35, 106},
  1429. {35, 102},
  1430. {35, 95},
  1431. {3, 113},
  1432. {3, 106},
  1433. {3, 102},
  1434. {3, 95} }, /* 2.4 GHz, lowest power */
  1435. {
  1436. {251, 127}, /* 5.x GHz, highest power */
  1437. {251, 120},
  1438. {251, 114},
  1439. {219, 119},
  1440. {219, 101},
  1441. {187, 113},
  1442. {187, 102},
  1443. {155, 114},
  1444. {155, 103},
  1445. {123, 117},
  1446. {123, 107},
  1447. {123, 99},
  1448. {123, 92},
  1449. {91, 108},
  1450. {59, 125},
  1451. {59, 118},
  1452. {59, 109},
  1453. {59, 102},
  1454. {59, 96},
  1455. {59, 90},
  1456. {27, 104},
  1457. {27, 98},
  1458. {27, 92},
  1459. {115, 118},
  1460. {115, 111},
  1461. {115, 104},
  1462. {83, 126},
  1463. {83, 121},
  1464. {83, 113},
  1465. {83, 105},
  1466. {83, 99},
  1467. {51, 118},
  1468. {51, 111},
  1469. {51, 104},
  1470. {51, 98},
  1471. {19, 116},
  1472. {19, 109},
  1473. {19, 102},
  1474. {19, 98},
  1475. {19, 93},
  1476. {171, 113},
  1477. {171, 107},
  1478. {171, 99},
  1479. {139, 120},
  1480. {139, 113},
  1481. {139, 107},
  1482. {139, 99},
  1483. {107, 120},
  1484. {107, 113},
  1485. {107, 107},
  1486. {107, 99},
  1487. {75, 120},
  1488. {75, 113},
  1489. {75, 107},
  1490. {75, 99},
  1491. {43, 120},
  1492. {43, 113},
  1493. {43, 107},
  1494. {43, 99},
  1495. {11, 120},
  1496. {11, 113},
  1497. {11, 107},
  1498. {11, 99},
  1499. {131, 107},
  1500. {131, 99},
  1501. {99, 120},
  1502. {99, 113},
  1503. {99, 107},
  1504. {99, 99},
  1505. {67, 120},
  1506. {67, 113},
  1507. {67, 107},
  1508. {67, 99},
  1509. {35, 120},
  1510. {35, 113},
  1511. {35, 107},
  1512. {35, 99},
  1513. {3, 120} } /* 5.x GHz, lowest power */
  1514. };
  1515. static inline u8 iwl3945_hw_reg_fix_power_index(int index)
  1516. {
  1517. if (index < 0)
  1518. return 0;
  1519. if (index >= IWL_MAX_GAIN_ENTRIES)
  1520. return IWL_MAX_GAIN_ENTRIES - 1;
  1521. return (u8) index;
  1522. }
  1523. /* Kick off thermal recalibration check every 60 seconds */
  1524. #define REG_RECALIB_PERIOD (60)
  1525. /**
  1526. * iwl3945_hw_reg_set_scan_power - Set Tx power for scan probe requests
  1527. *
  1528. * Set (in our channel info database) the direct scan Tx power for 1 Mbit (CCK)
  1529. * or 6 Mbit (OFDM) rates.
  1530. */
  1531. static void iwl3945_hw_reg_set_scan_power(struct iwl3945_priv *priv, u32 scan_tbl_index,
  1532. s32 rate_index, const s8 *clip_pwrs,
  1533. struct iwl3945_channel_info *ch_info,
  1534. int band_index)
  1535. {
  1536. struct iwl3945_scan_power_info *scan_power_info;
  1537. s8 power;
  1538. u8 power_index;
  1539. scan_power_info = &ch_info->scan_pwr_info[scan_tbl_index];
  1540. /* use this channel group's 6Mbit clipping/saturation pwr,
  1541. * but cap at regulatory scan power restriction (set during init
  1542. * based on eeprom channel data) for this channel. */
  1543. power = min(ch_info->scan_power, clip_pwrs[IWL_RATE_6M_INDEX_TABLE]);
  1544. /* further limit to user's max power preference.
  1545. * FIXME: Other spectrum management power limitations do not
  1546. * seem to apply?? */
  1547. power = min(power, priv->user_txpower_limit);
  1548. scan_power_info->requested_power = power;
  1549. /* find difference between new scan *power* and current "normal"
  1550. * Tx *power* for 6Mb. Use this difference (x2) to adjust the
  1551. * current "normal" temperature-compensated Tx power *index* for
  1552. * this rate (1Mb or 6Mb) to yield new temp-compensated scan power
  1553. * *index*. */
  1554. power_index = ch_info->power_info[rate_index].power_table_index
  1555. - (power - ch_info->power_info
  1556. [IWL_RATE_6M_INDEX_TABLE].requested_power) * 2;
  1557. /* store reference index that we use when adjusting *all* scan
  1558. * powers. So we can accommodate user (all channel) or spectrum
  1559. * management (single channel) power changes "between" temperature
  1560. * feedback compensation procedures.
  1561. * don't force fit this reference index into gain table; it may be a
  1562. * negative number. This will help avoid errors when we're at
  1563. * the lower bounds (highest gains, for warmest temperatures)
  1564. * of the table. */
  1565. /* don't exceed table bounds for "real" setting */
  1566. power_index = iwl3945_hw_reg_fix_power_index(power_index);
  1567. scan_power_info->power_table_index = power_index;
  1568. scan_power_info->tpc.tx_gain =
  1569. power_gain_table[band_index][power_index].tx_gain;
  1570. scan_power_info->tpc.dsp_atten =
  1571. power_gain_table[band_index][power_index].dsp_atten;
  1572. }
  1573. /**
  1574. * iwl3945_hw_reg_send_txpower - fill in Tx Power command with gain settings
  1575. *
  1576. * Configures power settings for all rates for the current channel,
  1577. * using values from channel info struct, and send to NIC
  1578. */
  1579. int iwl3945_hw_reg_send_txpower(struct iwl3945_priv *priv)
  1580. {
  1581. int rate_idx, i;
  1582. const struct iwl3945_channel_info *ch_info = NULL;
  1583. struct iwl3945_txpowertable_cmd txpower = {
  1584. .channel = priv->active_rxon.channel,
  1585. };
  1586. txpower.band = (priv->band == IEEE80211_BAND_5GHZ) ? 0 : 1;
  1587. ch_info = iwl3945_get_channel_info(priv,
  1588. priv->band,
  1589. le16_to_cpu(priv->active_rxon.channel));
  1590. if (!ch_info) {
  1591. IWL_ERROR
  1592. ("Failed to get channel info for channel %d [%d]\n",
  1593. le16_to_cpu(priv->active_rxon.channel), priv->band);
  1594. return -EINVAL;
  1595. }
  1596. if (!is_channel_valid(ch_info)) {
  1597. IWL_DEBUG_POWER("Not calling TX_PWR_TABLE_CMD on "
  1598. "non-Tx channel.\n");
  1599. return 0;
  1600. }
  1601. /* fill cmd with power settings for all rates for current channel */
  1602. /* Fill OFDM rate */
  1603. for (rate_idx = IWL_FIRST_OFDM_RATE, i = 0;
  1604. rate_idx <= IWL_LAST_OFDM_RATE; rate_idx++, i++) {
  1605. txpower.power[i].tpc = ch_info->power_info[i].tpc;
  1606. txpower.power[i].rate = iwl3945_rates[rate_idx].plcp;
  1607. IWL_DEBUG_POWER("ch %d:%d rf %d dsp %3d rate code 0x%02x\n",
  1608. le16_to_cpu(txpower.channel),
  1609. txpower.band,
  1610. txpower.power[i].tpc.tx_gain,
  1611. txpower.power[i].tpc.dsp_atten,
  1612. txpower.power[i].rate);
  1613. }
  1614. /* Fill CCK rates */
  1615. for (rate_idx = IWL_FIRST_CCK_RATE;
  1616. rate_idx <= IWL_LAST_CCK_RATE; rate_idx++, i++) {
  1617. txpower.power[i].tpc = ch_info->power_info[i].tpc;
  1618. txpower.power[i].rate = iwl3945_rates[rate_idx].plcp;
  1619. IWL_DEBUG_POWER("ch %d:%d rf %d dsp %3d rate code 0x%02x\n",
  1620. le16_to_cpu(txpower.channel),
  1621. txpower.band,
  1622. txpower.power[i].tpc.tx_gain,
  1623. txpower.power[i].tpc.dsp_atten,
  1624. txpower.power[i].rate);
  1625. }
  1626. return iwl3945_send_cmd_pdu(priv, REPLY_TX_PWR_TABLE_CMD,
  1627. sizeof(struct iwl3945_txpowertable_cmd), &txpower);
  1628. }
  1629. /**
  1630. * iwl3945_hw_reg_set_new_power - Configures power tables at new levels
  1631. * @ch_info: Channel to update. Uses power_info.requested_power.
  1632. *
  1633. * Replace requested_power and base_power_index ch_info fields for
  1634. * one channel.
  1635. *
  1636. * Called if user or spectrum management changes power preferences.
  1637. * Takes into account h/w and modulation limitations (clip power).
  1638. *
  1639. * This does *not* send anything to NIC, just sets up ch_info for one channel.
  1640. *
  1641. * NOTE: reg_compensate_for_temperature_dif() *must* be run after this to
  1642. * properly fill out the scan powers, and actual h/w gain settings,
  1643. * and send changes to NIC
  1644. */
  1645. static int iwl3945_hw_reg_set_new_power(struct iwl3945_priv *priv,
  1646. struct iwl3945_channel_info *ch_info)
  1647. {
  1648. struct iwl3945_channel_power_info *power_info;
  1649. int power_changed = 0;
  1650. int i;
  1651. const s8 *clip_pwrs;
  1652. int power;
  1653. /* Get this chnlgrp's rate-to-max/clip-powers table */
  1654. clip_pwrs = priv->clip_groups[ch_info->group_index].clip_powers;
  1655. /* Get this channel's rate-to-current-power settings table */
  1656. power_info = ch_info->power_info;
  1657. /* update OFDM Txpower settings */
  1658. for (i = IWL_RATE_6M_INDEX_TABLE; i <= IWL_RATE_54M_INDEX_TABLE;
  1659. i++, ++power_info) {
  1660. int delta_idx;
  1661. /* limit new power to be no more than h/w capability */
  1662. power = min(ch_info->curr_txpow, clip_pwrs[i]);
  1663. if (power == power_info->requested_power)
  1664. continue;
  1665. /* find difference between old and new requested powers,
  1666. * update base (non-temp-compensated) power index */
  1667. delta_idx = (power - power_info->requested_power) * 2;
  1668. power_info->base_power_index -= delta_idx;
  1669. /* save new requested power value */
  1670. power_info->requested_power = power;
  1671. power_changed = 1;
  1672. }
  1673. /* update CCK Txpower settings, based on OFDM 12M setting ...
  1674. * ... all CCK power settings for a given channel are the *same*. */
  1675. if (power_changed) {
  1676. power =
  1677. ch_info->power_info[IWL_RATE_12M_INDEX_TABLE].
  1678. requested_power + IWL_CCK_FROM_OFDM_POWER_DIFF;
  1679. /* do all CCK rates' iwl3945_channel_power_info structures */
  1680. for (i = IWL_RATE_1M_INDEX_TABLE; i <= IWL_RATE_11M_INDEX_TABLE; i++) {
  1681. power_info->requested_power = power;
  1682. power_info->base_power_index =
  1683. ch_info->power_info[IWL_RATE_12M_INDEX_TABLE].
  1684. base_power_index + IWL_CCK_FROM_OFDM_INDEX_DIFF;
  1685. ++power_info;
  1686. }
  1687. }
  1688. return 0;
  1689. }
  1690. /**
  1691. * iwl3945_hw_reg_get_ch_txpower_limit - returns new power limit for channel
  1692. *
  1693. * NOTE: Returned power limit may be less (but not more) than requested,
  1694. * based strictly on regulatory (eeprom and spectrum mgt) limitations
  1695. * (no consideration for h/w clipping limitations).
  1696. */
  1697. static int iwl3945_hw_reg_get_ch_txpower_limit(struct iwl3945_channel_info *ch_info)
  1698. {
  1699. s8 max_power;
  1700. #if 0
  1701. /* if we're using TGd limits, use lower of TGd or EEPROM */
  1702. if (ch_info->tgd_data.max_power != 0)
  1703. max_power = min(ch_info->tgd_data.max_power,
  1704. ch_info->eeprom.max_power_avg);
  1705. /* else just use EEPROM limits */
  1706. else
  1707. #endif
  1708. max_power = ch_info->eeprom.max_power_avg;
  1709. return min(max_power, ch_info->max_power_avg);
  1710. }
  1711. /**
  1712. * iwl3945_hw_reg_comp_txpower_temp - Compensate for temperature
  1713. *
  1714. * Compensate txpower settings of *all* channels for temperature.
  1715. * This only accounts for the difference between current temperature
  1716. * and the factory calibration temperatures, and bases the new settings
  1717. * on the channel's base_power_index.
  1718. *
  1719. * If RxOn is "associated", this sends the new Txpower to NIC!
  1720. */
  1721. static int iwl3945_hw_reg_comp_txpower_temp(struct iwl3945_priv *priv)
  1722. {
  1723. struct iwl3945_channel_info *ch_info = NULL;
  1724. int delta_index;
  1725. const s8 *clip_pwrs; /* array of h/w max power levels for each rate */
  1726. u8 a_band;
  1727. u8 rate_index;
  1728. u8 scan_tbl_index;
  1729. u8 i;
  1730. int ref_temp;
  1731. int temperature = priv->temperature;
  1732. /* set up new Tx power info for each and every channel, 2.4 and 5.x */
  1733. for (i = 0; i < priv->channel_count; i++) {
  1734. ch_info = &priv->channel_info[i];
  1735. a_band = is_channel_a_band(ch_info);
  1736. /* Get this chnlgrp's factory calibration temperature */
  1737. ref_temp = (s16)priv->eeprom.groups[ch_info->group_index].
  1738. temperature;
  1739. /* get power index adjustment based on curr and factory
  1740. * temps */
  1741. delta_index = iwl3945_hw_reg_adjust_power_by_temp(temperature,
  1742. ref_temp);
  1743. /* set tx power value for all rates, OFDM and CCK */
  1744. for (rate_index = 0; rate_index < IWL_RATE_COUNT;
  1745. rate_index++) {
  1746. int power_idx =
  1747. ch_info->power_info[rate_index].base_power_index;
  1748. /* temperature compensate */
  1749. power_idx += delta_index;
  1750. /* stay within table range */
  1751. power_idx = iwl3945_hw_reg_fix_power_index(power_idx);
  1752. ch_info->power_info[rate_index].
  1753. power_table_index = (u8) power_idx;
  1754. ch_info->power_info[rate_index].tpc =
  1755. power_gain_table[a_band][power_idx];
  1756. }
  1757. /* Get this chnlgrp's rate-to-max/clip-powers table */
  1758. clip_pwrs = priv->clip_groups[ch_info->group_index].clip_powers;
  1759. /* set scan tx power, 1Mbit for CCK, 6Mbit for OFDM */
  1760. for (scan_tbl_index = 0;
  1761. scan_tbl_index < IWL_NUM_SCAN_RATES; scan_tbl_index++) {
  1762. s32 actual_index = (scan_tbl_index == 0) ?
  1763. IWL_RATE_1M_INDEX_TABLE : IWL_RATE_6M_INDEX_TABLE;
  1764. iwl3945_hw_reg_set_scan_power(priv, scan_tbl_index,
  1765. actual_index, clip_pwrs,
  1766. ch_info, a_band);
  1767. }
  1768. }
  1769. /* send Txpower command for current channel to ucode */
  1770. return iwl3945_hw_reg_send_txpower(priv);
  1771. }
  1772. int iwl3945_hw_reg_set_txpower(struct iwl3945_priv *priv, s8 power)
  1773. {
  1774. struct iwl3945_channel_info *ch_info;
  1775. s8 max_power;
  1776. u8 a_band;
  1777. u8 i;
  1778. if (priv->user_txpower_limit == power) {
  1779. IWL_DEBUG_POWER("Requested Tx power same as current "
  1780. "limit: %ddBm.\n", power);
  1781. return 0;
  1782. }
  1783. IWL_DEBUG_POWER("Setting upper limit clamp to %ddBm.\n", power);
  1784. priv->user_txpower_limit = power;
  1785. /* set up new Tx powers for each and every channel, 2.4 and 5.x */
  1786. for (i = 0; i < priv->channel_count; i++) {
  1787. ch_info = &priv->channel_info[i];
  1788. a_band = is_channel_a_band(ch_info);
  1789. /* find minimum power of all user and regulatory constraints
  1790. * (does not consider h/w clipping limitations) */
  1791. max_power = iwl3945_hw_reg_get_ch_txpower_limit(ch_info);
  1792. max_power = min(power, max_power);
  1793. if (max_power != ch_info->curr_txpow) {
  1794. ch_info->curr_txpow = max_power;
  1795. /* this considers the h/w clipping limitations */
  1796. iwl3945_hw_reg_set_new_power(priv, ch_info);
  1797. }
  1798. }
  1799. /* update txpower settings for all channels,
  1800. * send to NIC if associated. */
  1801. is_temp_calib_needed(priv);
  1802. iwl3945_hw_reg_comp_txpower_temp(priv);
  1803. return 0;
  1804. }
  1805. /* will add 3945 channel switch cmd handling later */
  1806. int iwl3945_hw_channel_switch(struct iwl3945_priv *priv, u16 channel)
  1807. {
  1808. return 0;
  1809. }
  1810. /**
  1811. * iwl3945_reg_txpower_periodic - called when time to check our temperature.
  1812. *
  1813. * -- reset periodic timer
  1814. * -- see if temp has changed enough to warrant re-calibration ... if so:
  1815. * -- correct coeffs for temp (can reset temp timer)
  1816. * -- save this temp as "last",
  1817. * -- send new set of gain settings to NIC
  1818. * NOTE: This should continue working, even when we're not associated,
  1819. * so we can keep our internal table of scan powers current. */
  1820. void iwl3945_reg_txpower_periodic(struct iwl3945_priv *priv)
  1821. {
  1822. /* This will kick in the "brute force"
  1823. * iwl3945_hw_reg_comp_txpower_temp() below */
  1824. if (!is_temp_calib_needed(priv))
  1825. goto reschedule;
  1826. /* Set up a new set of temp-adjusted TxPowers, send to NIC.
  1827. * This is based *only* on current temperature,
  1828. * ignoring any previous power measurements */
  1829. iwl3945_hw_reg_comp_txpower_temp(priv);
  1830. reschedule:
  1831. queue_delayed_work(priv->workqueue,
  1832. &priv->thermal_periodic, REG_RECALIB_PERIOD * HZ);
  1833. }
  1834. static void iwl3945_bg_reg_txpower_periodic(struct work_struct *work)
  1835. {
  1836. struct iwl3945_priv *priv = container_of(work, struct iwl3945_priv,
  1837. thermal_periodic.work);
  1838. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1839. return;
  1840. mutex_lock(&priv->mutex);
  1841. iwl3945_reg_txpower_periodic(priv);
  1842. mutex_unlock(&priv->mutex);
  1843. }
  1844. /**
  1845. * iwl3945_hw_reg_get_ch_grp_index - find the channel-group index (0-4)
  1846. * for the channel.
  1847. *
  1848. * This function is used when initializing channel-info structs.
  1849. *
  1850. * NOTE: These channel groups do *NOT* match the bands above!
  1851. * These channel groups are based on factory-tested channels;
  1852. * on A-band, EEPROM's "group frequency" entries represent the top
  1853. * channel in each group 1-4. Group 5 All B/G channels are in group 0.
  1854. */
  1855. static u16 iwl3945_hw_reg_get_ch_grp_index(struct iwl3945_priv *priv,
  1856. const struct iwl3945_channel_info *ch_info)
  1857. {
  1858. struct iwl3945_eeprom_txpower_group *ch_grp = &priv->eeprom.groups[0];
  1859. u8 group;
  1860. u16 group_index = 0; /* based on factory calib frequencies */
  1861. u8 grp_channel;
  1862. /* Find the group index for the channel ... don't use index 1(?) */
  1863. if (is_channel_a_band(ch_info)) {
  1864. for (group = 1; group < 5; group++) {
  1865. grp_channel = ch_grp[group].group_channel;
  1866. if (ch_info->channel <= grp_channel) {
  1867. group_index = group;
  1868. break;
  1869. }
  1870. }
  1871. /* group 4 has a few channels *above* its factory cal freq */
  1872. if (group == 5)
  1873. group_index = 4;
  1874. } else
  1875. group_index = 0; /* 2.4 GHz, group 0 */
  1876. IWL_DEBUG_POWER("Chnl %d mapped to grp %d\n", ch_info->channel,
  1877. group_index);
  1878. return group_index;
  1879. }
  1880. /**
  1881. * iwl3945_hw_reg_get_matched_power_index - Interpolate to get nominal index
  1882. *
  1883. * Interpolate to get nominal (i.e. at factory calibration temperature) index
  1884. * into radio/DSP gain settings table for requested power.
  1885. */
  1886. static int iwl3945_hw_reg_get_matched_power_index(struct iwl3945_priv *priv,
  1887. s8 requested_power,
  1888. s32 setting_index, s32 *new_index)
  1889. {
  1890. const struct iwl3945_eeprom_txpower_group *chnl_grp = NULL;
  1891. s32 index0, index1;
  1892. s32 power = 2 * requested_power;
  1893. s32 i;
  1894. const struct iwl3945_eeprom_txpower_sample *samples;
  1895. s32 gains0, gains1;
  1896. s32 res;
  1897. s32 denominator;
  1898. chnl_grp = &priv->eeprom.groups[setting_index];
  1899. samples = chnl_grp->samples;
  1900. for (i = 0; i < 5; i++) {
  1901. if (power == samples[i].power) {
  1902. *new_index = samples[i].gain_index;
  1903. return 0;
  1904. }
  1905. }
  1906. if (power > samples[1].power) {
  1907. index0 = 0;
  1908. index1 = 1;
  1909. } else if (power > samples[2].power) {
  1910. index0 = 1;
  1911. index1 = 2;
  1912. } else if (power > samples[3].power) {
  1913. index0 = 2;
  1914. index1 = 3;
  1915. } else {
  1916. index0 = 3;
  1917. index1 = 4;
  1918. }
  1919. denominator = (s32) samples[index1].power - (s32) samples[index0].power;
  1920. if (denominator == 0)
  1921. return -EINVAL;
  1922. gains0 = (s32) samples[index0].gain_index * (1 << 19);
  1923. gains1 = (s32) samples[index1].gain_index * (1 << 19);
  1924. res = gains0 + (gains1 - gains0) *
  1925. ((s32) power - (s32) samples[index0].power) / denominator +
  1926. (1 << 18);
  1927. *new_index = res >> 19;
  1928. return 0;
  1929. }
  1930. static void iwl3945_hw_reg_init_channel_groups(struct iwl3945_priv *priv)
  1931. {
  1932. u32 i;
  1933. s32 rate_index;
  1934. const struct iwl3945_eeprom_txpower_group *group;
  1935. IWL_DEBUG_POWER("Initializing factory calib info from EEPROM\n");
  1936. for (i = 0; i < IWL_NUM_TX_CALIB_GROUPS; i++) {
  1937. s8 *clip_pwrs; /* table of power levels for each rate */
  1938. s8 satur_pwr; /* saturation power for each chnl group */
  1939. group = &priv->eeprom.groups[i];
  1940. /* sanity check on factory saturation power value */
  1941. if (group->saturation_power < 40) {
  1942. IWL_WARNING("Error: saturation power is %d, "
  1943. "less than minimum expected 40\n",
  1944. group->saturation_power);
  1945. return;
  1946. }
  1947. /*
  1948. * Derive requested power levels for each rate, based on
  1949. * hardware capabilities (saturation power for band).
  1950. * Basic value is 3dB down from saturation, with further
  1951. * power reductions for highest 3 data rates. These
  1952. * backoffs provide headroom for high rate modulation
  1953. * power peaks, without too much distortion (clipping).
  1954. */
  1955. /* we'll fill in this array with h/w max power levels */
  1956. clip_pwrs = (s8 *) priv->clip_groups[i].clip_powers;
  1957. /* divide factory saturation power by 2 to find -3dB level */
  1958. satur_pwr = (s8) (group->saturation_power >> 1);
  1959. /* fill in channel group's nominal powers for each rate */
  1960. for (rate_index = 0;
  1961. rate_index < IWL_RATE_COUNT; rate_index++, clip_pwrs++) {
  1962. switch (rate_index) {
  1963. case IWL_RATE_36M_INDEX_TABLE:
  1964. if (i == 0) /* B/G */
  1965. *clip_pwrs = satur_pwr;
  1966. else /* A */
  1967. *clip_pwrs = satur_pwr - 5;
  1968. break;
  1969. case IWL_RATE_48M_INDEX_TABLE:
  1970. if (i == 0)
  1971. *clip_pwrs = satur_pwr - 7;
  1972. else
  1973. *clip_pwrs = satur_pwr - 10;
  1974. break;
  1975. case IWL_RATE_54M_INDEX_TABLE:
  1976. if (i == 0)
  1977. *clip_pwrs = satur_pwr - 9;
  1978. else
  1979. *clip_pwrs = satur_pwr - 12;
  1980. break;
  1981. default:
  1982. *clip_pwrs = satur_pwr;
  1983. break;
  1984. }
  1985. }
  1986. }
  1987. }
  1988. /**
  1989. * iwl3945_txpower_set_from_eeprom - Set channel power info based on EEPROM
  1990. *
  1991. * Second pass (during init) to set up priv->channel_info
  1992. *
  1993. * Set up Tx-power settings in our channel info database for each VALID
  1994. * (for this geo/SKU) channel, at all Tx data rates, based on eeprom values
  1995. * and current temperature.
  1996. *
  1997. * Since this is based on current temperature (at init time), these values may
  1998. * not be valid for very long, but it gives us a starting/default point,
  1999. * and allows us to active (i.e. using Tx) scan.
  2000. *
  2001. * This does *not* write values to NIC, just sets up our internal table.
  2002. */
  2003. int iwl3945_txpower_set_from_eeprom(struct iwl3945_priv *priv)
  2004. {
  2005. struct iwl3945_channel_info *ch_info = NULL;
  2006. struct iwl3945_channel_power_info *pwr_info;
  2007. int delta_index;
  2008. u8 rate_index;
  2009. u8 scan_tbl_index;
  2010. const s8 *clip_pwrs; /* array of power levels for each rate */
  2011. u8 gain, dsp_atten;
  2012. s8 power;
  2013. u8 pwr_index, base_pwr_index, a_band;
  2014. u8 i;
  2015. int temperature;
  2016. /* save temperature reference,
  2017. * so we can determine next time to calibrate */
  2018. temperature = iwl3945_hw_reg_txpower_get_temperature(priv);
  2019. priv->last_temperature = temperature;
  2020. iwl3945_hw_reg_init_channel_groups(priv);
  2021. /* initialize Tx power info for each and every channel, 2.4 and 5.x */
  2022. for (i = 0, ch_info = priv->channel_info; i < priv->channel_count;
  2023. i++, ch_info++) {
  2024. a_band = is_channel_a_band(ch_info);
  2025. if (!is_channel_valid(ch_info))
  2026. continue;
  2027. /* find this channel's channel group (*not* "band") index */
  2028. ch_info->group_index =
  2029. iwl3945_hw_reg_get_ch_grp_index(priv, ch_info);
  2030. /* Get this chnlgrp's rate->max/clip-powers table */
  2031. clip_pwrs = priv->clip_groups[ch_info->group_index].clip_powers;
  2032. /* calculate power index *adjustment* value according to
  2033. * diff between current temperature and factory temperature */
  2034. delta_index = iwl3945_hw_reg_adjust_power_by_temp(temperature,
  2035. priv->eeprom.groups[ch_info->group_index].
  2036. temperature);
  2037. IWL_DEBUG_POWER("Delta index for channel %d: %d [%d]\n",
  2038. ch_info->channel, delta_index, temperature +
  2039. IWL_TEMP_CONVERT);
  2040. /* set tx power value for all OFDM rates */
  2041. for (rate_index = 0; rate_index < IWL_OFDM_RATES;
  2042. rate_index++) {
  2043. s32 power_idx;
  2044. int rc;
  2045. /* use channel group's clip-power table,
  2046. * but don't exceed channel's max power */
  2047. s8 pwr = min(ch_info->max_power_avg,
  2048. clip_pwrs[rate_index]);
  2049. pwr_info = &ch_info->power_info[rate_index];
  2050. /* get base (i.e. at factory-measured temperature)
  2051. * power table index for this rate's power */
  2052. rc = iwl3945_hw_reg_get_matched_power_index(priv, pwr,
  2053. ch_info->group_index,
  2054. &power_idx);
  2055. if (rc) {
  2056. IWL_ERROR("Invalid power index\n");
  2057. return rc;
  2058. }
  2059. pwr_info->base_power_index = (u8) power_idx;
  2060. /* temperature compensate */
  2061. power_idx += delta_index;
  2062. /* stay within range of gain table */
  2063. power_idx = iwl3945_hw_reg_fix_power_index(power_idx);
  2064. /* fill 1 OFDM rate's iwl3945_channel_power_info struct */
  2065. pwr_info->requested_power = pwr;
  2066. pwr_info->power_table_index = (u8) power_idx;
  2067. pwr_info->tpc.tx_gain =
  2068. power_gain_table[a_band][power_idx].tx_gain;
  2069. pwr_info->tpc.dsp_atten =
  2070. power_gain_table[a_band][power_idx].dsp_atten;
  2071. }
  2072. /* set tx power for CCK rates, based on OFDM 12 Mbit settings*/
  2073. pwr_info = &ch_info->power_info[IWL_RATE_12M_INDEX_TABLE];
  2074. power = pwr_info->requested_power +
  2075. IWL_CCK_FROM_OFDM_POWER_DIFF;
  2076. pwr_index = pwr_info->power_table_index +
  2077. IWL_CCK_FROM_OFDM_INDEX_DIFF;
  2078. base_pwr_index = pwr_info->base_power_index +
  2079. IWL_CCK_FROM_OFDM_INDEX_DIFF;
  2080. /* stay within table range */
  2081. pwr_index = iwl3945_hw_reg_fix_power_index(pwr_index);
  2082. gain = power_gain_table[a_band][pwr_index].tx_gain;
  2083. dsp_atten = power_gain_table[a_band][pwr_index].dsp_atten;
  2084. /* fill each CCK rate's iwl3945_channel_power_info structure
  2085. * NOTE: All CCK-rate Txpwrs are the same for a given chnl!
  2086. * NOTE: CCK rates start at end of OFDM rates! */
  2087. for (rate_index = 0;
  2088. rate_index < IWL_CCK_RATES; rate_index++) {
  2089. pwr_info = &ch_info->power_info[rate_index+IWL_OFDM_RATES];
  2090. pwr_info->requested_power = power;
  2091. pwr_info->power_table_index = pwr_index;
  2092. pwr_info->base_power_index = base_pwr_index;
  2093. pwr_info->tpc.tx_gain = gain;
  2094. pwr_info->tpc.dsp_atten = dsp_atten;
  2095. }
  2096. /* set scan tx power, 1Mbit for CCK, 6Mbit for OFDM */
  2097. for (scan_tbl_index = 0;
  2098. scan_tbl_index < IWL_NUM_SCAN_RATES; scan_tbl_index++) {
  2099. s32 actual_index = (scan_tbl_index == 0) ?
  2100. IWL_RATE_1M_INDEX_TABLE : IWL_RATE_6M_INDEX_TABLE;
  2101. iwl3945_hw_reg_set_scan_power(priv, scan_tbl_index,
  2102. actual_index, clip_pwrs, ch_info, a_band);
  2103. }
  2104. }
  2105. return 0;
  2106. }
  2107. int iwl3945_hw_rxq_stop(struct iwl3945_priv *priv)
  2108. {
  2109. int rc;
  2110. unsigned long flags;
  2111. spin_lock_irqsave(&priv->lock, flags);
  2112. rc = iwl3945_grab_nic_access(priv);
  2113. if (rc) {
  2114. spin_unlock_irqrestore(&priv->lock, flags);
  2115. return rc;
  2116. }
  2117. iwl3945_write_direct32(priv, FH_RCSR_CONFIG(0), 0);
  2118. rc = iwl3945_poll_direct_bit(priv, FH_RSSR_STATUS, (1 << 24), 1000);
  2119. if (rc < 0)
  2120. IWL_ERROR("Can't stop Rx DMA.\n");
  2121. iwl3945_release_nic_access(priv);
  2122. spin_unlock_irqrestore(&priv->lock, flags);
  2123. return 0;
  2124. }
  2125. int iwl3945_hw_tx_queue_init(struct iwl3945_priv *priv, struct iwl3945_tx_queue *txq)
  2126. {
  2127. int rc;
  2128. unsigned long flags;
  2129. int txq_id = txq->q.id;
  2130. struct iwl3945_shared *shared_data = priv->hw_setting.shared_virt;
  2131. shared_data->tx_base_ptr[txq_id] = cpu_to_le32((u32)txq->q.dma_addr);
  2132. spin_lock_irqsave(&priv->lock, flags);
  2133. rc = iwl3945_grab_nic_access(priv);
  2134. if (rc) {
  2135. spin_unlock_irqrestore(&priv->lock, flags);
  2136. return rc;
  2137. }
  2138. iwl3945_write_direct32(priv, FH_CBCC_CTRL(txq_id), 0);
  2139. iwl3945_write_direct32(priv, FH_CBCC_BASE(txq_id), 0);
  2140. iwl3945_write_direct32(priv, FH_TCSR_CONFIG(txq_id),
  2141. ALM_FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_NOINT |
  2142. ALM_FH_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_TXF |
  2143. ALM_FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_IFTFD |
  2144. ALM_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL |
  2145. ALM_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE);
  2146. iwl3945_release_nic_access(priv);
  2147. /* fake read to flush all prev. writes */
  2148. iwl3945_read32(priv, FH_TSSR_CBB_BASE);
  2149. spin_unlock_irqrestore(&priv->lock, flags);
  2150. return 0;
  2151. }
  2152. int iwl3945_hw_get_rx_read(struct iwl3945_priv *priv)
  2153. {
  2154. struct iwl3945_shared *shared_data = priv->hw_setting.shared_virt;
  2155. return le32_to_cpu(shared_data->rx_read_ptr[0]);
  2156. }
  2157. /**
  2158. * iwl3945_init_hw_rate_table - Initialize the hardware rate fallback table
  2159. */
  2160. int iwl3945_init_hw_rate_table(struct iwl3945_priv *priv)
  2161. {
  2162. int rc, i, index, prev_index;
  2163. struct iwl3945_rate_scaling_cmd rate_cmd = {
  2164. .reserved = {0, 0, 0},
  2165. };
  2166. struct iwl3945_rate_scaling_info *table = rate_cmd.table;
  2167. for (i = 0; i < ARRAY_SIZE(iwl3945_rates); i++) {
  2168. index = iwl3945_rates[i].table_rs_index;
  2169. table[index].rate_n_flags =
  2170. iwl3945_hw_set_rate_n_flags(iwl3945_rates[i].plcp, 0);
  2171. table[index].try_cnt = priv->retry_rate;
  2172. prev_index = iwl3945_get_prev_ieee_rate(i);
  2173. table[index].next_rate_index = iwl3945_rates[prev_index].table_rs_index;
  2174. }
  2175. switch (priv->band) {
  2176. case IEEE80211_BAND_5GHZ:
  2177. IWL_DEBUG_RATE("Select A mode rate scale\n");
  2178. /* If one of the following CCK rates is used,
  2179. * have it fall back to the 6M OFDM rate */
  2180. for (i = IWL_RATE_1M_INDEX_TABLE; i <= IWL_RATE_11M_INDEX_TABLE; i++)
  2181. table[i].next_rate_index = iwl3945_rates[IWL_FIRST_OFDM_RATE].table_rs_index;
  2182. /* Don't fall back to CCK rates */
  2183. table[IWL_RATE_12M_INDEX_TABLE].next_rate_index = IWL_RATE_9M_INDEX_TABLE;
  2184. /* Don't drop out of OFDM rates */
  2185. table[IWL_RATE_6M_INDEX_TABLE].next_rate_index =
  2186. iwl3945_rates[IWL_FIRST_OFDM_RATE].table_rs_index;
  2187. break;
  2188. case IEEE80211_BAND_2GHZ:
  2189. IWL_DEBUG_RATE("Select B/G mode rate scale\n");
  2190. /* If an OFDM rate is used, have it fall back to the
  2191. * 1M CCK rates */
  2192. for (i = IWL_RATE_6M_INDEX_TABLE; i <= IWL_RATE_54M_INDEX_TABLE; i++)
  2193. table[i].next_rate_index = iwl3945_rates[IWL_FIRST_CCK_RATE].table_rs_index;
  2194. /* CCK shouldn't fall back to OFDM... */
  2195. table[IWL_RATE_11M_INDEX_TABLE].next_rate_index = IWL_RATE_5M_INDEX_TABLE;
  2196. break;
  2197. default:
  2198. WARN_ON(1);
  2199. break;
  2200. }
  2201. /* Update the rate scaling for control frame Tx */
  2202. rate_cmd.table_id = 0;
  2203. rc = iwl3945_send_cmd_pdu(priv, REPLY_RATE_SCALE, sizeof(rate_cmd),
  2204. &rate_cmd);
  2205. if (rc)
  2206. return rc;
  2207. /* Update the rate scaling for data frame Tx */
  2208. rate_cmd.table_id = 1;
  2209. return iwl3945_send_cmd_pdu(priv, REPLY_RATE_SCALE, sizeof(rate_cmd),
  2210. &rate_cmd);
  2211. }
  2212. /* Called when initializing driver */
  2213. int iwl3945_hw_set_hw_setting(struct iwl3945_priv *priv)
  2214. {
  2215. memset((void *)&priv->hw_setting, 0,
  2216. sizeof(struct iwl3945_driver_hw_info));
  2217. priv->hw_setting.shared_virt =
  2218. pci_alloc_consistent(priv->pci_dev,
  2219. sizeof(struct iwl3945_shared),
  2220. &priv->hw_setting.shared_phys);
  2221. if (!priv->hw_setting.shared_virt) {
  2222. IWL_ERROR("failed to allocate pci memory\n");
  2223. mutex_unlock(&priv->mutex);
  2224. return -ENOMEM;
  2225. }
  2226. priv->hw_setting.rx_buf_size = IWL_RX_BUF_SIZE;
  2227. priv->hw_setting.max_pkt_size = 2342;
  2228. priv->hw_setting.tx_cmd_len = sizeof(struct iwl3945_tx_cmd);
  2229. priv->hw_setting.max_rxq_size = RX_QUEUE_SIZE;
  2230. priv->hw_setting.max_rxq_log = RX_QUEUE_SIZE_LOG;
  2231. priv->hw_setting.max_stations = IWL3945_STATION_COUNT;
  2232. priv->hw_setting.bcast_sta_id = IWL3945_BROADCAST_ID;
  2233. priv->hw_setting.tx_ant_num = 2;
  2234. return 0;
  2235. }
  2236. unsigned int iwl3945_hw_get_beacon_cmd(struct iwl3945_priv *priv,
  2237. struct iwl3945_frame *frame, u8 rate)
  2238. {
  2239. struct iwl3945_tx_beacon_cmd *tx_beacon_cmd;
  2240. unsigned int frame_size;
  2241. tx_beacon_cmd = (struct iwl3945_tx_beacon_cmd *)&frame->u;
  2242. memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
  2243. tx_beacon_cmd->tx.sta_id = priv->hw_setting.bcast_sta_id;
  2244. tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  2245. frame_size = iwl3945_fill_beacon_frame(priv,
  2246. tx_beacon_cmd->frame,
  2247. iwl3945_broadcast_addr,
  2248. sizeof(frame->u) - sizeof(*tx_beacon_cmd));
  2249. BUG_ON(frame_size > MAX_MPDU_SIZE);
  2250. tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
  2251. tx_beacon_cmd->tx.rate = rate;
  2252. tx_beacon_cmd->tx.tx_flags = (TX_CMD_FLG_SEQ_CTL_MSK |
  2253. TX_CMD_FLG_TSF_MSK);
  2254. /* supp_rates[0] == OFDM start at IWL_FIRST_OFDM_RATE*/
  2255. tx_beacon_cmd->tx.supp_rates[0] =
  2256. (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  2257. tx_beacon_cmd->tx.supp_rates[1] =
  2258. (IWL_CCK_BASIC_RATES_MASK & 0xF);
  2259. return (sizeof(struct iwl3945_tx_beacon_cmd) + frame_size);
  2260. }
  2261. void iwl3945_hw_rx_handler_setup(struct iwl3945_priv *priv)
  2262. {
  2263. priv->rx_handlers[REPLY_TX] = iwl3945_rx_reply_tx;
  2264. priv->rx_handlers[REPLY_3945_RX] = iwl3945_rx_reply_rx;
  2265. }
  2266. void iwl3945_hw_setup_deferred_work(struct iwl3945_priv *priv)
  2267. {
  2268. INIT_DELAYED_WORK(&priv->thermal_periodic,
  2269. iwl3945_bg_reg_txpower_periodic);
  2270. }
  2271. void iwl3945_hw_cancel_deferred_work(struct iwl3945_priv *priv)
  2272. {
  2273. cancel_delayed_work(&priv->thermal_periodic);
  2274. }
  2275. static struct iwl_3945_cfg iwl3945_bg_cfg = {
  2276. .name = "3945BG",
  2277. .fw_name = "iwlwifi-3945" IWL3945_UCODE_API ".ucode",
  2278. .sku = IWL_SKU_G,
  2279. };
  2280. static struct iwl_3945_cfg iwl3945_abg_cfg = {
  2281. .name = "3945ABG",
  2282. .fw_name = "iwlwifi-3945" IWL3945_UCODE_API ".ucode",
  2283. .sku = IWL_SKU_A|IWL_SKU_G,
  2284. };
  2285. struct pci_device_id iwl3945_hw_card_ids[] = {
  2286. {IWL_PCI_DEVICE(0x4222, 0x1005, iwl3945_bg_cfg)},
  2287. {IWL_PCI_DEVICE(0x4222, 0x1034, iwl3945_bg_cfg)},
  2288. {IWL_PCI_DEVICE(0x4222, 0x1044, iwl3945_bg_cfg)},
  2289. {IWL_PCI_DEVICE(0x4227, 0x1014, iwl3945_bg_cfg)},
  2290. {IWL_PCI_DEVICE(0x4222, PCI_ANY_ID, iwl3945_abg_cfg)},
  2291. {IWL_PCI_DEVICE(0x4227, PCI_ANY_ID, iwl3945_abg_cfg)},
  2292. {0}
  2293. };
  2294. MODULE_DEVICE_TABLE(pci, iwl3945_hw_card_ids);