3945.c 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2011 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. * Intel Linux Wireless <ilw@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/init.h>
  29. #include <linux/slab.h>
  30. #include <linux/pci.h>
  31. #include <linux/dma-mapping.h>
  32. #include <linux/delay.h>
  33. #include <linux/sched.h>
  34. #include <linux/skbuff.h>
  35. #include <linux/netdevice.h>
  36. #include <linux/firmware.h>
  37. #include <linux/etherdevice.h>
  38. #include <asm/unaligned.h>
  39. #include <net/mac80211.h>
  40. #include "iwl-fh.h"
  41. #include "iwl-3945-fh.h"
  42. #include "iwl-commands.h"
  43. #include "iwl-sta.h"
  44. #include "iwl-3945.h"
  45. #include "iwl-eeprom.h"
  46. #include "iwl-core.h"
  47. #include "iwl-helpers.h"
  48. #include "iwl-led.h"
  49. #include "iwl-3945-debugfs.h"
  50. /* Send led command */
  51. static int il3945_send_led_cmd(struct il_priv *il,
  52. struct il_led_cmd *led_cmd)
  53. {
  54. struct il_host_cmd cmd = {
  55. .id = REPLY_LEDS_CMD,
  56. .len = sizeof(struct il_led_cmd),
  57. .data = led_cmd,
  58. .flags = CMD_ASYNC,
  59. .callback = NULL,
  60. };
  61. return il_send_cmd(il, &cmd);
  62. }
  63. const struct il_led_ops il3945_led_ops = {
  64. .cmd = il3945_send_led_cmd,
  65. };
  66. #define IL_DECLARE_RATE_INFO(r, ip, in, rp, rn, pp, np) \
  67. [RATE_##r##M_IDX] = { RATE_##r##M_PLCP, \
  68. RATE_##r##M_IEEE, \
  69. RATE_##ip##M_IDX, \
  70. RATE_##in##M_IDX, \
  71. RATE_##rp##M_IDX, \
  72. RATE_##rn##M_IDX, \
  73. RATE_##pp##M_IDX, \
  74. RATE_##np##M_IDX, \
  75. RATE_##r##M_IDX_TBL, \
  76. RATE_##ip##M_IDX_TBL }
  77. /*
  78. * Parameter order:
  79. * rate, prev rate, next rate, prev tgg rate, next tgg rate
  80. *
  81. * If there isn't a valid next or previous rate then INV is used which
  82. * maps to RATE_INVALID
  83. *
  84. */
  85. const struct il3945_rate_info il3945_rates[RATE_COUNT_3945] = {
  86. IL_DECLARE_RATE_INFO(1, INV, 2, INV, 2, INV, 2), /* 1mbps */
  87. IL_DECLARE_RATE_INFO(2, 1, 5, 1, 5, 1, 5), /* 2mbps */
  88. IL_DECLARE_RATE_INFO(5, 2, 6, 2, 11, 2, 11), /*5.5mbps */
  89. IL_DECLARE_RATE_INFO(11, 9, 12, 5, 12, 5, 18), /* 11mbps */
  90. IL_DECLARE_RATE_INFO(6, 5, 9, 5, 11, 5, 11), /* 6mbps */
  91. IL_DECLARE_RATE_INFO(9, 6, 11, 5, 11, 5, 11), /* 9mbps */
  92. IL_DECLARE_RATE_INFO(12, 11, 18, 11, 18, 11, 18), /* 12mbps */
  93. IL_DECLARE_RATE_INFO(18, 12, 24, 12, 24, 11, 24), /* 18mbps */
  94. IL_DECLARE_RATE_INFO(24, 18, 36, 18, 36, 18, 36), /* 24mbps */
  95. IL_DECLARE_RATE_INFO(36, 24, 48, 24, 48, 24, 48), /* 36mbps */
  96. IL_DECLARE_RATE_INFO(48, 36, 54, 36, 54, 36, 54), /* 48mbps */
  97. IL_DECLARE_RATE_INFO(54, 48, INV, 48, INV, 48, INV),/* 54mbps */
  98. };
  99. static inline u8 il3945_get_prev_ieee_rate(u8 rate_idx)
  100. {
  101. u8 rate = il3945_rates[rate_idx].prev_ieee;
  102. if (rate == RATE_INVALID)
  103. rate = rate_idx;
  104. return rate;
  105. }
  106. /* 1 = enable the il3945_disable_events() function */
  107. #define IL_EVT_DISABLE (0)
  108. #define IL_EVT_DISABLE_SIZE (1532/32)
  109. /**
  110. * il3945_disable_events - Disable selected events in uCode event log
  111. *
  112. * Disable an event by writing "1"s into "disable"
  113. * bitmap in SRAM. Bit position corresponds to Event # (id/type).
  114. * Default values of 0 enable uCode events to be logged.
  115. * Use for only special debugging. This function is just a placeholder as-is,
  116. * you'll need to provide the special bits! ...
  117. * ... and set IL_EVT_DISABLE to 1. */
  118. void il3945_disable_events(struct il_priv *il)
  119. {
  120. int i;
  121. u32 base; /* SRAM address of event log header */
  122. u32 disable_ptr; /* SRAM address of event-disable bitmap array */
  123. u32 array_size; /* # of u32 entries in array */
  124. static const u32 evt_disable[IL_EVT_DISABLE_SIZE] = {
  125. 0x00000000, /* 31 - 0 Event id numbers */
  126. 0x00000000, /* 63 - 32 */
  127. 0x00000000, /* 95 - 64 */
  128. 0x00000000, /* 127 - 96 */
  129. 0x00000000, /* 159 - 128 */
  130. 0x00000000, /* 191 - 160 */
  131. 0x00000000, /* 223 - 192 */
  132. 0x00000000, /* 255 - 224 */
  133. 0x00000000, /* 287 - 256 */
  134. 0x00000000, /* 319 - 288 */
  135. 0x00000000, /* 351 - 320 */
  136. 0x00000000, /* 383 - 352 */
  137. 0x00000000, /* 415 - 384 */
  138. 0x00000000, /* 447 - 416 */
  139. 0x00000000, /* 479 - 448 */
  140. 0x00000000, /* 511 - 480 */
  141. 0x00000000, /* 543 - 512 */
  142. 0x00000000, /* 575 - 544 */
  143. 0x00000000, /* 607 - 576 */
  144. 0x00000000, /* 639 - 608 */
  145. 0x00000000, /* 671 - 640 */
  146. 0x00000000, /* 703 - 672 */
  147. 0x00000000, /* 735 - 704 */
  148. 0x00000000, /* 767 - 736 */
  149. 0x00000000, /* 799 - 768 */
  150. 0x00000000, /* 831 - 800 */
  151. 0x00000000, /* 863 - 832 */
  152. 0x00000000, /* 895 - 864 */
  153. 0x00000000, /* 927 - 896 */
  154. 0x00000000, /* 959 - 928 */
  155. 0x00000000, /* 991 - 960 */
  156. 0x00000000, /* 1023 - 992 */
  157. 0x00000000, /* 1055 - 1024 */
  158. 0x00000000, /* 1087 - 1056 */
  159. 0x00000000, /* 1119 - 1088 */
  160. 0x00000000, /* 1151 - 1120 */
  161. 0x00000000, /* 1183 - 1152 */
  162. 0x00000000, /* 1215 - 1184 */
  163. 0x00000000, /* 1247 - 1216 */
  164. 0x00000000, /* 1279 - 1248 */
  165. 0x00000000, /* 1311 - 1280 */
  166. 0x00000000, /* 1343 - 1312 */
  167. 0x00000000, /* 1375 - 1344 */
  168. 0x00000000, /* 1407 - 1376 */
  169. 0x00000000, /* 1439 - 1408 */
  170. 0x00000000, /* 1471 - 1440 */
  171. 0x00000000, /* 1503 - 1472 */
  172. };
  173. base = le32_to_cpu(il->card_alive.log_event_table_ptr);
  174. if (!il3945_hw_valid_rtc_data_addr(base)) {
  175. IL_ERR("Invalid event log pointer 0x%08X\n", base);
  176. return;
  177. }
  178. disable_ptr = il_read_targ_mem(il, base + (4 * sizeof(u32)));
  179. array_size = il_read_targ_mem(il, base + (5 * sizeof(u32)));
  180. if (IL_EVT_DISABLE && array_size == IL_EVT_DISABLE_SIZE) {
  181. D_INFO("Disabling selected uCode log events at 0x%x\n",
  182. disable_ptr);
  183. for (i = 0; i < IL_EVT_DISABLE_SIZE; i++)
  184. il_write_targ_mem(il,
  185. disable_ptr + (i * sizeof(u32)),
  186. evt_disable[i]);
  187. } else {
  188. D_INFO("Selected uCode log events may be disabled\n");
  189. D_INFO(" by writing \"1\"s into disable bitmap\n");
  190. D_INFO(" in SRAM at 0x%x, size %d u32s\n",
  191. disable_ptr, array_size);
  192. }
  193. }
  194. static int il3945_hwrate_to_plcp_idx(u8 plcp)
  195. {
  196. int idx;
  197. for (idx = 0; idx < RATE_COUNT_3945; idx++)
  198. if (il3945_rates[idx].plcp == plcp)
  199. return idx;
  200. return -1;
  201. }
  202. #ifdef CONFIG_IWLEGACY_DEBUG
  203. #define TX_STATUS_ENTRY(x) case TX_3945_STATUS_FAIL_ ## x: return #x
  204. static const char *il3945_get_tx_fail_reason(u32 status)
  205. {
  206. switch (status & TX_STATUS_MSK) {
  207. case TX_3945_STATUS_SUCCESS:
  208. return "SUCCESS";
  209. TX_STATUS_ENTRY(SHORT_LIMIT);
  210. TX_STATUS_ENTRY(LONG_LIMIT);
  211. TX_STATUS_ENTRY(FIFO_UNDERRUN);
  212. TX_STATUS_ENTRY(MGMNT_ABORT);
  213. TX_STATUS_ENTRY(NEXT_FRAG);
  214. TX_STATUS_ENTRY(LIFE_EXPIRE);
  215. TX_STATUS_ENTRY(DEST_PS);
  216. TX_STATUS_ENTRY(ABORTED);
  217. TX_STATUS_ENTRY(BT_RETRY);
  218. TX_STATUS_ENTRY(STA_INVALID);
  219. TX_STATUS_ENTRY(FRAG_DROPPED);
  220. TX_STATUS_ENTRY(TID_DISABLE);
  221. TX_STATUS_ENTRY(FRAME_FLUSHED);
  222. TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
  223. TX_STATUS_ENTRY(TX_LOCKED);
  224. TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
  225. }
  226. return "UNKNOWN";
  227. }
  228. #else
  229. static inline const char *il3945_get_tx_fail_reason(u32 status)
  230. {
  231. return "";
  232. }
  233. #endif
  234. /*
  235. * get ieee prev rate from rate scale table.
  236. * for A and B mode we need to overright prev
  237. * value
  238. */
  239. int il3945_rs_next_rate(struct il_priv *il, int rate)
  240. {
  241. int next_rate = il3945_get_prev_ieee_rate(rate);
  242. switch (il->band) {
  243. case IEEE80211_BAND_5GHZ:
  244. if (rate == RATE_12M_IDX)
  245. next_rate = RATE_9M_IDX;
  246. else if (rate == RATE_6M_IDX)
  247. next_rate = RATE_6M_IDX;
  248. break;
  249. case IEEE80211_BAND_2GHZ:
  250. if (!(il->_3945.sta_supp_rates & IL_OFDM_RATES_MASK) &&
  251. il_is_associated(il)) {
  252. if (rate == RATE_11M_IDX)
  253. next_rate = RATE_5M_IDX;
  254. }
  255. break;
  256. default:
  257. break;
  258. }
  259. return next_rate;
  260. }
  261. /**
  262. * il3945_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
  263. *
  264. * When FW advances 'R' idx, all entries between old and new 'R' idx
  265. * need to be reclaimed. As result, some free space forms. If there is
  266. * enough free space (> low mark), wake the stack that feeds us.
  267. */
  268. static void il3945_tx_queue_reclaim(struct il_priv *il,
  269. int txq_id, int idx)
  270. {
  271. struct il_tx_queue *txq = &il->txq[txq_id];
  272. struct il_queue *q = &txq->q;
  273. struct il_tx_info *tx_info;
  274. BUG_ON(txq_id == IL39_CMD_QUEUE_NUM);
  275. for (idx = il_queue_inc_wrap(idx, q->n_bd);
  276. q->read_ptr != idx;
  277. q->read_ptr = il_queue_inc_wrap(q->read_ptr, q->n_bd)) {
  278. tx_info = &txq->txb[txq->q.read_ptr];
  279. ieee80211_tx_status_irqsafe(il->hw, tx_info->skb);
  280. tx_info->skb = NULL;
  281. il->cfg->ops->lib->txq_free_tfd(il, txq);
  282. }
  283. if (il_queue_space(q) > q->low_mark && txq_id >= 0 &&
  284. txq_id != IL39_CMD_QUEUE_NUM && il->mac80211_registered)
  285. il_wake_queue(il, txq);
  286. }
  287. /**
  288. * il3945_rx_reply_tx - Handle Tx response
  289. */
  290. static void il3945_rx_reply_tx(struct il_priv *il,
  291. struct il_rx_buf *rxb)
  292. {
  293. struct il_rx_pkt *pkt = rxb_addr(rxb);
  294. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  295. int txq_id = SEQ_TO_QUEUE(sequence);
  296. int idx = SEQ_TO_IDX(sequence);
  297. struct il_tx_queue *txq = &il->txq[txq_id];
  298. struct ieee80211_tx_info *info;
  299. struct il3945_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
  300. u32 status = le32_to_cpu(tx_resp->status);
  301. int rate_idx;
  302. int fail;
  303. if (idx >= txq->q.n_bd || il_queue_used(&txq->q, idx) == 0) {
  304. IL_ERR("Read idx for DMA queue txq_id (%d) idx %d "
  305. "is out of range [0-%d] %d %d\n", txq_id,
  306. idx, txq->q.n_bd, txq->q.write_ptr,
  307. txq->q.read_ptr);
  308. return;
  309. }
  310. txq->time_stamp = jiffies;
  311. info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb);
  312. ieee80211_tx_info_clear_status(info);
  313. /* Fill the MRR chain with some info about on-chip retransmissions */
  314. rate_idx = il3945_hwrate_to_plcp_idx(tx_resp->rate);
  315. if (info->band == IEEE80211_BAND_5GHZ)
  316. rate_idx -= IL_FIRST_OFDM_RATE;
  317. fail = tx_resp->failure_frame;
  318. info->status.rates[0].idx = rate_idx;
  319. info->status.rates[0].count = fail + 1; /* add final attempt */
  320. /* tx_status->rts_retry_count = tx_resp->failure_rts; */
  321. info->flags |= ((status & TX_STATUS_MSK) == TX_STATUS_SUCCESS) ?
  322. IEEE80211_TX_STAT_ACK : 0;
  323. D_TX("Tx queue %d Status %s (0x%08x) plcp rate %d retries %d\n",
  324. txq_id, il3945_get_tx_fail_reason(status), status,
  325. tx_resp->rate, tx_resp->failure_frame);
  326. D_TX_REPLY("Tx queue reclaim %d\n", idx);
  327. il3945_tx_queue_reclaim(il, txq_id, idx);
  328. if (status & TX_ABORT_REQUIRED_MSK)
  329. IL_ERR("TODO: Implement Tx ABORT REQUIRED!!!\n");
  330. }
  331. /*****************************************************************************
  332. *
  333. * Intel PRO/Wireless 3945ABG/BG Network Connection
  334. *
  335. * RX handler implementations
  336. *
  337. *****************************************************************************/
  338. #ifdef CONFIG_IWLEGACY_DEBUGFS
  339. static void il3945_accumulative_stats(struct il_priv *il,
  340. __le32 *stats)
  341. {
  342. int i;
  343. __le32 *prev_stats;
  344. u32 *accum_stats;
  345. u32 *delta, *max_delta;
  346. prev_stats = (__le32 *)&il->_3945.stats;
  347. accum_stats = (u32 *)&il->_3945.accum_stats;
  348. delta = (u32 *)&il->_3945.delta_stats;
  349. max_delta = (u32 *)&il->_3945.max_delta;
  350. for (i = sizeof(__le32); i < sizeof(struct il3945_notif_stats);
  351. i += sizeof(__le32), stats++, prev_stats++, delta++,
  352. max_delta++, accum_stats++) {
  353. if (le32_to_cpu(*stats) > le32_to_cpu(*prev_stats)) {
  354. *delta = (le32_to_cpu(*stats) -
  355. le32_to_cpu(*prev_stats));
  356. *accum_stats += *delta;
  357. if (*delta > *max_delta)
  358. *max_delta = *delta;
  359. }
  360. }
  361. /* reset accumulative stats for "no-counter" type stats */
  362. il->_3945.accum_stats.general.temperature =
  363. il->_3945.stats.general.temperature;
  364. il->_3945.accum_stats.general.ttl_timestamp =
  365. il->_3945.stats.general.ttl_timestamp;
  366. }
  367. #endif
  368. void il3945_hw_rx_stats(struct il_priv *il,
  369. struct il_rx_buf *rxb)
  370. {
  371. struct il_rx_pkt *pkt = rxb_addr(rxb);
  372. D_RX("Statistics notification received (%d vs %d).\n",
  373. (int)sizeof(struct il3945_notif_stats),
  374. le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK);
  375. #ifdef CONFIG_IWLEGACY_DEBUGFS
  376. il3945_accumulative_stats(il, (__le32 *)&pkt->u.raw);
  377. #endif
  378. memcpy(&il->_3945.stats, pkt->u.raw, sizeof(il->_3945.stats));
  379. }
  380. void il3945_reply_stats(struct il_priv *il,
  381. struct il_rx_buf *rxb)
  382. {
  383. struct il_rx_pkt *pkt = rxb_addr(rxb);
  384. __le32 *flag = (__le32 *)&pkt->u.raw;
  385. if (le32_to_cpu(*flag) & UCODE_STATISTICS_CLEAR_MSK) {
  386. #ifdef CONFIG_IWLEGACY_DEBUGFS
  387. memset(&il->_3945.accum_stats, 0,
  388. sizeof(struct il3945_notif_stats));
  389. memset(&il->_3945.delta_stats, 0,
  390. sizeof(struct il3945_notif_stats));
  391. memset(&il->_3945.max_delta, 0,
  392. sizeof(struct il3945_notif_stats));
  393. #endif
  394. D_RX("Statistics have been cleared\n");
  395. }
  396. il3945_hw_rx_stats(il, rxb);
  397. }
  398. /******************************************************************************
  399. *
  400. * Misc. internal state and helper functions
  401. *
  402. ******************************************************************************/
  403. /* This is necessary only for a number of stats, see the caller. */
  404. static int il3945_is_network_packet(struct il_priv *il,
  405. struct ieee80211_hdr *header)
  406. {
  407. /* Filter incoming packets to determine if they are targeted toward
  408. * this network, discarding packets coming from ourselves */
  409. switch (il->iw_mode) {
  410. case NL80211_IFTYPE_ADHOC: /* Header: Dest. | Source | BSSID */
  411. /* packets to our IBSS update information */
  412. return !compare_ether_addr(header->addr3, il->bssid);
  413. case NL80211_IFTYPE_STATION: /* Header: Dest. | AP{BSSID} | Source */
  414. /* packets to our IBSS update information */
  415. return !compare_ether_addr(header->addr2, il->bssid);
  416. default:
  417. return 1;
  418. }
  419. }
  420. static void il3945_pass_packet_to_mac80211(struct il_priv *il,
  421. struct il_rx_buf *rxb,
  422. struct ieee80211_rx_status *stats)
  423. {
  424. struct il_rx_pkt *pkt = rxb_addr(rxb);
  425. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)IL_RX_DATA(pkt);
  426. struct il3945_rx_frame_hdr *rx_hdr = IL_RX_HDR(pkt);
  427. struct il3945_rx_frame_end *rx_end = IL_RX_END(pkt);
  428. u16 len = le16_to_cpu(rx_hdr->len);
  429. struct sk_buff *skb;
  430. __le16 fc = hdr->frame_control;
  431. /* We received data from the HW, so stop the watchdog */
  432. if (unlikely(len + IL39_RX_FRAME_SIZE >
  433. PAGE_SIZE << il->hw_params.rx_page_order)) {
  434. D_DROP("Corruption detected!\n");
  435. return;
  436. }
  437. /* We only process data packets if the interface is open */
  438. if (unlikely(!il->is_open)) {
  439. D_DROP(
  440. "Dropping packet while interface is not open.\n");
  441. return;
  442. }
  443. skb = dev_alloc_skb(128);
  444. if (!skb) {
  445. IL_ERR("dev_alloc_skb failed\n");
  446. return;
  447. }
  448. if (!il3945_mod_params.sw_crypto)
  449. il_set_decrypted_flag(il,
  450. (struct ieee80211_hdr *)rxb_addr(rxb),
  451. le32_to_cpu(rx_end->status), stats);
  452. skb_add_rx_frag(skb, 0, rxb->page,
  453. (void *)rx_hdr->payload - (void *)pkt, len);
  454. il_update_stats(il, false, fc, len);
  455. memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats));
  456. ieee80211_rx(il->hw, skb);
  457. il->alloc_rxb_page--;
  458. rxb->page = NULL;
  459. }
  460. #define IL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
  461. static void il3945_rx_reply_rx(struct il_priv *il,
  462. struct il_rx_buf *rxb)
  463. {
  464. struct ieee80211_hdr *header;
  465. struct ieee80211_rx_status rx_status;
  466. struct il_rx_pkt *pkt = rxb_addr(rxb);
  467. struct il3945_rx_frame_stats *rx_stats = IL_RX_STATS(pkt);
  468. struct il3945_rx_frame_hdr *rx_hdr = IL_RX_HDR(pkt);
  469. struct il3945_rx_frame_end *rx_end = IL_RX_END(pkt);
  470. u16 rx_stats_sig_avg __maybe_unused = le16_to_cpu(rx_stats->sig_avg);
  471. u16 rx_stats_noise_diff __maybe_unused = le16_to_cpu(rx_stats->noise_diff);
  472. u8 network_packet;
  473. rx_status.flag = 0;
  474. rx_status.mactime = le64_to_cpu(rx_end->timestamp);
  475. rx_status.band = (rx_hdr->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
  476. IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
  477. rx_status.freq =
  478. ieee80211_channel_to_frequency(le16_to_cpu(rx_hdr->channel),
  479. rx_status.band);
  480. rx_status.rate_idx = il3945_hwrate_to_plcp_idx(rx_hdr->rate);
  481. if (rx_status.band == IEEE80211_BAND_5GHZ)
  482. rx_status.rate_idx -= IL_FIRST_OFDM_RATE;
  483. rx_status.antenna = (le16_to_cpu(rx_hdr->phy_flags) &
  484. RX_RES_PHY_FLAGS_ANTENNA_MSK) >> 4;
  485. /* set the preamble flag if appropriate */
  486. if (rx_hdr->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
  487. rx_status.flag |= RX_FLAG_SHORTPRE;
  488. if ((unlikely(rx_stats->phy_count > 20))) {
  489. D_DROP("dsp size out of range [0,20]: %d/n",
  490. rx_stats->phy_count);
  491. return;
  492. }
  493. if (!(rx_end->status & RX_RES_STATUS_NO_CRC32_ERROR) ||
  494. !(rx_end->status & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
  495. D_RX("Bad CRC or FIFO: 0x%08X.\n", rx_end->status);
  496. return;
  497. }
  498. /* Convert 3945's rssi indicator to dBm */
  499. rx_status.signal = rx_stats->rssi - IL39_RSSI_OFFSET;
  500. D_STATS("Rssi %d sig_avg %d noise_diff %d\n",
  501. rx_status.signal, rx_stats_sig_avg,
  502. rx_stats_noise_diff);
  503. header = (struct ieee80211_hdr *)IL_RX_DATA(pkt);
  504. network_packet = il3945_is_network_packet(il, header);
  505. D_STATS("[%c] %d RSSI:%d Signal:%u, Rate:%u\n",
  506. network_packet ? '*' : ' ',
  507. le16_to_cpu(rx_hdr->channel),
  508. rx_status.signal, rx_status.signal,
  509. rx_status.rate_idx);
  510. il_dbg_log_rx_data_frame(il, le16_to_cpu(rx_hdr->len),
  511. header);
  512. if (network_packet) {
  513. il->_3945.last_beacon_time =
  514. le32_to_cpu(rx_end->beacon_timestamp);
  515. il->_3945.last_tsf = le64_to_cpu(rx_end->timestamp);
  516. il->_3945.last_rx_rssi = rx_status.signal;
  517. }
  518. il3945_pass_packet_to_mac80211(il, rxb, &rx_status);
  519. }
  520. int il3945_hw_txq_attach_buf_to_tfd(struct il_priv *il,
  521. struct il_tx_queue *txq,
  522. dma_addr_t addr, u16 len, u8 reset, u8 pad)
  523. {
  524. int count;
  525. struct il_queue *q;
  526. struct il3945_tfd *tfd, *tfd_tmp;
  527. q = &txq->q;
  528. tfd_tmp = (struct il3945_tfd *)txq->tfds;
  529. tfd = &tfd_tmp[q->write_ptr];
  530. if (reset)
  531. memset(tfd, 0, sizeof(*tfd));
  532. count = TFD_CTL_COUNT_GET(le32_to_cpu(tfd->control_flags));
  533. if (count >= NUM_TFD_CHUNKS || count < 0) {
  534. IL_ERR("Error can not send more than %d chunks\n",
  535. NUM_TFD_CHUNKS);
  536. return -EINVAL;
  537. }
  538. tfd->tbs[count].addr = cpu_to_le32(addr);
  539. tfd->tbs[count].len = cpu_to_le32(len);
  540. count++;
  541. tfd->control_flags = cpu_to_le32(TFD_CTL_COUNT_SET(count) |
  542. TFD_CTL_PAD_SET(pad));
  543. return 0;
  544. }
  545. /**
  546. * il3945_hw_txq_free_tfd - Free one TFD, those at idx [txq->q.read_ptr]
  547. *
  548. * Does NOT advance any idxes
  549. */
  550. void il3945_hw_txq_free_tfd(struct il_priv *il, struct il_tx_queue *txq)
  551. {
  552. struct il3945_tfd *tfd_tmp = (struct il3945_tfd *)txq->tfds;
  553. int idx = txq->q.read_ptr;
  554. struct il3945_tfd *tfd = &tfd_tmp[idx];
  555. struct pci_dev *dev = il->pci_dev;
  556. int i;
  557. int counter;
  558. /* sanity check */
  559. counter = TFD_CTL_COUNT_GET(le32_to_cpu(tfd->control_flags));
  560. if (counter > NUM_TFD_CHUNKS) {
  561. IL_ERR("Too many chunks: %i\n", counter);
  562. /* @todo issue fatal error, it is quite serious situation */
  563. return;
  564. }
  565. /* Unmap tx_cmd */
  566. if (counter)
  567. pci_unmap_single(dev,
  568. dma_unmap_addr(&txq->meta[idx], mapping),
  569. dma_unmap_len(&txq->meta[idx], len),
  570. PCI_DMA_TODEVICE);
  571. /* unmap chunks if any */
  572. for (i = 1; i < counter; i++)
  573. pci_unmap_single(dev, le32_to_cpu(tfd->tbs[i].addr),
  574. le32_to_cpu(tfd->tbs[i].len), PCI_DMA_TODEVICE);
  575. /* free SKB */
  576. if (txq->txb) {
  577. struct sk_buff *skb;
  578. skb = txq->txb[txq->q.read_ptr].skb;
  579. /* can be called from irqs-disabled context */
  580. if (skb) {
  581. dev_kfree_skb_any(skb);
  582. txq->txb[txq->q.read_ptr].skb = NULL;
  583. }
  584. }
  585. }
  586. /**
  587. * il3945_hw_build_tx_cmd_rate - Add rate portion to TX_CMD:
  588. *
  589. */
  590. void il3945_hw_build_tx_cmd_rate(struct il_priv *il,
  591. struct il_device_cmd *cmd,
  592. struct ieee80211_tx_info *info,
  593. struct ieee80211_hdr *hdr,
  594. int sta_id, int tx_id)
  595. {
  596. u16 hw_value = ieee80211_get_tx_rate(il->hw, info)->hw_value;
  597. u16 rate_idx = min(hw_value & 0xffff, RATE_COUNT_3945);
  598. u16 rate_mask;
  599. int rate;
  600. u8 rts_retry_limit;
  601. u8 data_retry_limit;
  602. __le32 tx_flags;
  603. __le16 fc = hdr->frame_control;
  604. struct il3945_tx_cmd *tx_cmd = (struct il3945_tx_cmd *)cmd->cmd.payload;
  605. rate = il3945_rates[rate_idx].plcp;
  606. tx_flags = tx_cmd->tx_flags;
  607. /* We need to figure out how to get the sta->supp_rates while
  608. * in this running context */
  609. rate_mask = RATES_MASK_3945;
  610. /* Set retry limit on DATA packets and Probe Responses*/
  611. if (ieee80211_is_probe_resp(fc))
  612. data_retry_limit = 3;
  613. else
  614. data_retry_limit = IL_DEFAULT_TX_RETRY;
  615. tx_cmd->data_retry_limit = data_retry_limit;
  616. if (tx_id >= IL39_CMD_QUEUE_NUM)
  617. rts_retry_limit = 3;
  618. else
  619. rts_retry_limit = 7;
  620. if (data_retry_limit < rts_retry_limit)
  621. rts_retry_limit = data_retry_limit;
  622. tx_cmd->rts_retry_limit = rts_retry_limit;
  623. tx_cmd->rate = rate;
  624. tx_cmd->tx_flags = tx_flags;
  625. /* OFDM */
  626. tx_cmd->supp_rates[0] =
  627. ((rate_mask & IL_OFDM_RATES_MASK) >> IL_FIRST_OFDM_RATE) & 0xFF;
  628. /* CCK */
  629. tx_cmd->supp_rates[1] = (rate_mask & 0xF);
  630. D_RATE("Tx sta id: %d, rate: %d (plcp), flags: 0x%4X "
  631. "cck/ofdm mask: 0x%x/0x%x\n", sta_id,
  632. tx_cmd->rate, le32_to_cpu(tx_cmd->tx_flags),
  633. tx_cmd->supp_rates[1], tx_cmd->supp_rates[0]);
  634. }
  635. static u8 il3945_sync_sta(struct il_priv *il, int sta_id, u16 tx_rate)
  636. {
  637. unsigned long flags_spin;
  638. struct il_station_entry *station;
  639. if (sta_id == IL_INVALID_STATION)
  640. return IL_INVALID_STATION;
  641. spin_lock_irqsave(&il->sta_lock, flags_spin);
  642. station = &il->stations[sta_id];
  643. station->sta.sta.modify_mask = STA_MODIFY_TX_RATE_MSK;
  644. station->sta.rate_n_flags = cpu_to_le16(tx_rate);
  645. station->sta.mode = STA_CONTROL_MODIFY_MSK;
  646. il_send_add_sta(il, &station->sta, CMD_ASYNC);
  647. spin_unlock_irqrestore(&il->sta_lock, flags_spin);
  648. D_RATE("SCALE sync station %d to rate %d\n",
  649. sta_id, tx_rate);
  650. return sta_id;
  651. }
  652. static void il3945_set_pwr_vmain(struct il_priv *il)
  653. {
  654. /*
  655. * (for documentation purposes)
  656. * to set power to V_AUX, do
  657. if (pci_pme_capable(il->pci_dev, PCI_D3cold)) {
  658. il_set_bits_mask_prph(il, APMG_PS_CTRL_REG,
  659. APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
  660. ~APMG_PS_CTRL_MSK_PWR_SRC);
  661. _il_poll_bit(il, CSR_GPIO_IN,
  662. CSR_GPIO_IN_VAL_VAUX_PWR_SRC,
  663. CSR_GPIO_IN_BIT_AUX_POWER, 5000);
  664. }
  665. */
  666. il_set_bits_mask_prph(il, APMG_PS_CTRL_REG,
  667. APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
  668. ~APMG_PS_CTRL_MSK_PWR_SRC);
  669. _il_poll_bit(il, CSR_GPIO_IN, CSR_GPIO_IN_VAL_VMAIN_PWR_SRC,
  670. CSR_GPIO_IN_BIT_AUX_POWER, 5000); /* uS */
  671. }
  672. static int il3945_rx_init(struct il_priv *il, struct il_rx_queue *rxq)
  673. {
  674. il_wr(il, FH39_RCSR_RBD_BASE(0), rxq->bd_dma);
  675. il_wr(il, FH39_RCSR_RPTR_ADDR(0),
  676. rxq->rb_stts_dma);
  677. il_wr(il, FH39_RCSR_WPTR(0), 0);
  678. il_wr(il, FH39_RCSR_CONFIG(0),
  679. FH39_RCSR_RX_CONFIG_REG_VAL_DMA_CHNL_EN_ENABLE |
  680. FH39_RCSR_RX_CONFIG_REG_VAL_RDRBD_EN_ENABLE |
  681. FH39_RCSR_RX_CONFIG_REG_BIT_WR_STTS_EN |
  682. FH39_RCSR_RX_CONFIG_REG_VAL_MAX_FRAG_SIZE_128 |
  683. (RX_QUEUE_SIZE_LOG << FH39_RCSR_RX_CONFIG_REG_POS_RBDC_SIZE) |
  684. FH39_RCSR_RX_CONFIG_REG_VAL_IRQ_DEST_INT_HOST |
  685. (1 << FH39_RCSR_RX_CONFIG_REG_POS_IRQ_RBTH) |
  686. FH39_RCSR_RX_CONFIG_REG_VAL_MSG_MODE_FH);
  687. /* fake read to flush all prev I/O */
  688. il_rd(il, FH39_RSSR_CTRL);
  689. return 0;
  690. }
  691. static int il3945_tx_reset(struct il_priv *il)
  692. {
  693. /* bypass mode */
  694. il_wr_prph(il, ALM_SCD_MODE_REG, 0x2);
  695. /* RA 0 is active */
  696. il_wr_prph(il, ALM_SCD_ARASTAT_REG, 0x01);
  697. /* all 6 fifo are active */
  698. il_wr_prph(il, ALM_SCD_TXFACT_REG, 0x3f);
  699. il_wr_prph(il, ALM_SCD_SBYP_MODE_1_REG, 0x010000);
  700. il_wr_prph(il, ALM_SCD_SBYP_MODE_2_REG, 0x030002);
  701. il_wr_prph(il, ALM_SCD_TXF4MF_REG, 0x000004);
  702. il_wr_prph(il, ALM_SCD_TXF5MF_REG, 0x000005);
  703. il_wr(il, FH39_TSSR_CBB_BASE,
  704. il->_3945.shared_phys);
  705. il_wr(il, FH39_TSSR_MSG_CONFIG,
  706. FH39_TSSR_TX_MSG_CONFIG_REG_VAL_SNOOP_RD_TXPD_ON |
  707. FH39_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RD_TXPD_ON |
  708. FH39_TSSR_TX_MSG_CONFIG_REG_VAL_MAX_FRAG_SIZE_128B |
  709. FH39_TSSR_TX_MSG_CONFIG_REG_VAL_SNOOP_RD_TFD_ON |
  710. FH39_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RD_CBB_ON |
  711. FH39_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RSP_WAIT_TH |
  712. FH39_TSSR_TX_MSG_CONFIG_REG_VAL_RSP_WAIT_TH);
  713. return 0;
  714. }
  715. /**
  716. * il3945_txq_ctx_reset - Reset TX queue context
  717. *
  718. * Destroys all DMA structures and initialize them again
  719. */
  720. static int il3945_txq_ctx_reset(struct il_priv *il)
  721. {
  722. int rc;
  723. int txq_id, slots_num;
  724. il3945_hw_txq_ctx_free(il);
  725. /* allocate tx queue structure */
  726. rc = il_alloc_txq_mem(il);
  727. if (rc)
  728. return rc;
  729. /* Tx CMD queue */
  730. rc = il3945_tx_reset(il);
  731. if (rc)
  732. goto error;
  733. /* Tx queue(s) */
  734. for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++) {
  735. slots_num = (txq_id == IL39_CMD_QUEUE_NUM) ?
  736. TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
  737. rc = il_tx_queue_init(il, &il->txq[txq_id],
  738. slots_num, txq_id);
  739. if (rc) {
  740. IL_ERR("Tx %d queue init failed\n", txq_id);
  741. goto error;
  742. }
  743. }
  744. return rc;
  745. error:
  746. il3945_hw_txq_ctx_free(il);
  747. return rc;
  748. }
  749. /*
  750. * Start up 3945's basic functionality after it has been reset
  751. * (e.g. after platform boot, or shutdown via il_apm_stop())
  752. * NOTE: This does not load uCode nor start the embedded processor
  753. */
  754. static int il3945_apm_init(struct il_priv *il)
  755. {
  756. int ret = il_apm_init(il);
  757. /* Clear APMG (NIC's internal power management) interrupts */
  758. il_wr_prph(il, APMG_RTC_INT_MSK_REG, 0x0);
  759. il_wr_prph(il, APMG_RTC_INT_STT_REG, 0xFFFFFFFF);
  760. /* Reset radio chip */
  761. il_set_bits_prph(il, APMG_PS_CTRL_REG,
  762. APMG_PS_CTRL_VAL_RESET_REQ);
  763. udelay(5);
  764. il_clear_bits_prph(il, APMG_PS_CTRL_REG,
  765. APMG_PS_CTRL_VAL_RESET_REQ);
  766. return ret;
  767. }
  768. static void il3945_nic_config(struct il_priv *il)
  769. {
  770. struct il3945_eeprom *eeprom = (struct il3945_eeprom *)il->eeprom;
  771. unsigned long flags;
  772. u8 rev_id = il->pci_dev->revision;
  773. spin_lock_irqsave(&il->lock, flags);
  774. /* Determine HW type */
  775. D_INFO("HW Revision ID = 0x%X\n", rev_id);
  776. if (rev_id & PCI_CFG_REV_ID_BIT_RTP)
  777. D_INFO("RTP type\n");
  778. else if (rev_id & PCI_CFG_REV_ID_BIT_BASIC_SKU) {
  779. D_INFO("3945 RADIO-MB type\n");
  780. il_set_bit(il, CSR_HW_IF_CONFIG_REG,
  781. CSR39_HW_IF_CONFIG_REG_BIT_3945_MB);
  782. } else {
  783. D_INFO("3945 RADIO-MM type\n");
  784. il_set_bit(il, CSR_HW_IF_CONFIG_REG,
  785. CSR39_HW_IF_CONFIG_REG_BIT_3945_MM);
  786. }
  787. if (EEPROM_SKU_CAP_OP_MODE_MRC == eeprom->sku_cap) {
  788. D_INFO("SKU OP mode is mrc\n");
  789. il_set_bit(il, CSR_HW_IF_CONFIG_REG,
  790. CSR39_HW_IF_CONFIG_REG_BIT_SKU_MRC);
  791. } else
  792. D_INFO("SKU OP mode is basic\n");
  793. if ((eeprom->board_revision & 0xF0) == 0xD0) {
  794. D_INFO("3945ABG revision is 0x%X\n",
  795. eeprom->board_revision);
  796. il_set_bit(il, CSR_HW_IF_CONFIG_REG,
  797. CSR39_HW_IF_CONFIG_REG_BIT_BOARD_TYPE);
  798. } else {
  799. D_INFO("3945ABG revision is 0x%X\n",
  800. eeprom->board_revision);
  801. il_clear_bit(il, CSR_HW_IF_CONFIG_REG,
  802. CSR39_HW_IF_CONFIG_REG_BIT_BOARD_TYPE);
  803. }
  804. if (eeprom->almgor_m_version <= 1) {
  805. il_set_bit(il, CSR_HW_IF_CONFIG_REG,
  806. CSR39_HW_IF_CONFIG_REG_BITS_SILICON_TYPE_A);
  807. D_INFO("Card M type A version is 0x%X\n",
  808. eeprom->almgor_m_version);
  809. } else {
  810. D_INFO("Card M type B version is 0x%X\n",
  811. eeprom->almgor_m_version);
  812. il_set_bit(il, CSR_HW_IF_CONFIG_REG,
  813. CSR39_HW_IF_CONFIG_REG_BITS_SILICON_TYPE_B);
  814. }
  815. spin_unlock_irqrestore(&il->lock, flags);
  816. if (eeprom->sku_cap & EEPROM_SKU_CAP_SW_RF_KILL_ENABLE)
  817. D_RF_KILL("SW RF KILL supported in EEPROM.\n");
  818. if (eeprom->sku_cap & EEPROM_SKU_CAP_HW_RF_KILL_ENABLE)
  819. D_RF_KILL("HW RF KILL supported in EEPROM.\n");
  820. }
  821. int il3945_hw_nic_init(struct il_priv *il)
  822. {
  823. int rc;
  824. unsigned long flags;
  825. struct il_rx_queue *rxq = &il->rxq;
  826. spin_lock_irqsave(&il->lock, flags);
  827. il->cfg->ops->lib->apm_ops.init(il);
  828. spin_unlock_irqrestore(&il->lock, flags);
  829. il3945_set_pwr_vmain(il);
  830. il->cfg->ops->lib->apm_ops.config(il);
  831. /* Allocate the RX queue, or reset if it is already allocated */
  832. if (!rxq->bd) {
  833. rc = il_rx_queue_alloc(il);
  834. if (rc) {
  835. IL_ERR("Unable to initialize Rx queue\n");
  836. return -ENOMEM;
  837. }
  838. } else
  839. il3945_rx_queue_reset(il, rxq);
  840. il3945_rx_replenish(il);
  841. il3945_rx_init(il, rxq);
  842. /* Look at using this instead:
  843. rxq->need_update = 1;
  844. il_rx_queue_update_write_ptr(il, rxq);
  845. */
  846. il_wr(il, FH39_RCSR_WPTR(0), rxq->write & ~7);
  847. rc = il3945_txq_ctx_reset(il);
  848. if (rc)
  849. return rc;
  850. set_bit(STATUS_INIT, &il->status);
  851. return 0;
  852. }
  853. /**
  854. * il3945_hw_txq_ctx_free - Free TXQ Context
  855. *
  856. * Destroy all TX DMA queues and structures
  857. */
  858. void il3945_hw_txq_ctx_free(struct il_priv *il)
  859. {
  860. int txq_id;
  861. /* Tx queues */
  862. if (il->txq)
  863. for (txq_id = 0; txq_id < il->hw_params.max_txq_num;
  864. txq_id++)
  865. if (txq_id == IL39_CMD_QUEUE_NUM)
  866. il_cmd_queue_free(il);
  867. else
  868. il_tx_queue_free(il, txq_id);
  869. /* free tx queue structure */
  870. il_txq_mem(il);
  871. }
  872. void il3945_hw_txq_ctx_stop(struct il_priv *il)
  873. {
  874. int txq_id;
  875. /* stop SCD */
  876. il_wr_prph(il, ALM_SCD_MODE_REG, 0);
  877. il_wr_prph(il, ALM_SCD_TXFACT_REG, 0);
  878. /* reset TFD queues */
  879. for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++) {
  880. il_wr(il, FH39_TCSR_CONFIG(txq_id), 0x0);
  881. il_poll_bit(il, FH39_TSSR_TX_STATUS,
  882. FH39_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(txq_id),
  883. 1000);
  884. }
  885. il3945_hw_txq_ctx_free(il);
  886. }
  887. /**
  888. * il3945_hw_reg_adjust_power_by_temp
  889. * return idx delta into power gain settings table
  890. */
  891. static int il3945_hw_reg_adjust_power_by_temp(int new_reading, int old_reading)
  892. {
  893. return (new_reading - old_reading) * (-11) / 100;
  894. }
  895. /**
  896. * il3945_hw_reg_temp_out_of_range - Keep temperature in sane range
  897. */
  898. static inline int il3945_hw_reg_temp_out_of_range(int temperature)
  899. {
  900. return (temperature < -260 || temperature > 25) ? 1 : 0;
  901. }
  902. int il3945_hw_get_temperature(struct il_priv *il)
  903. {
  904. return _il_rd(il, CSR_UCODE_DRV_GP2);
  905. }
  906. /**
  907. * il3945_hw_reg_txpower_get_temperature
  908. * get the current temperature by reading from NIC
  909. */
  910. static int il3945_hw_reg_txpower_get_temperature(struct il_priv *il)
  911. {
  912. struct il3945_eeprom *eeprom = (struct il3945_eeprom *)il->eeprom;
  913. int temperature;
  914. temperature = il3945_hw_get_temperature(il);
  915. /* driver's okay range is -260 to +25.
  916. * human readable okay range is 0 to +285 */
  917. D_INFO("Temperature: %d\n", temperature + IL_TEMP_CONVERT);
  918. /* handle insane temp reading */
  919. if (il3945_hw_reg_temp_out_of_range(temperature)) {
  920. IL_ERR("Error bad temperature value %d\n", temperature);
  921. /* if really really hot(?),
  922. * substitute the 3rd band/group's temp measured at factory */
  923. if (il->last_temperature > 100)
  924. temperature = eeprom->groups[2].temperature;
  925. else /* else use most recent "sane" value from driver */
  926. temperature = il->last_temperature;
  927. }
  928. return temperature; /* raw, not "human readable" */
  929. }
  930. /* Adjust Txpower only if temperature variance is greater than threshold.
  931. *
  932. * Both are lower than older versions' 9 degrees */
  933. #define IL_TEMPERATURE_LIMIT_TIMER 6
  934. /**
  935. * il3945_is_temp_calib_needed - determines if new calibration is needed
  936. *
  937. * records new temperature in tx_mgr->temperature.
  938. * replaces tx_mgr->last_temperature *only* if calib needed
  939. * (assumes caller will actually do the calibration!). */
  940. static int il3945_is_temp_calib_needed(struct il_priv *il)
  941. {
  942. int temp_diff;
  943. il->temperature = il3945_hw_reg_txpower_get_temperature(il);
  944. temp_diff = il->temperature - il->last_temperature;
  945. /* get absolute value */
  946. if (temp_diff < 0) {
  947. D_POWER("Getting cooler, delta %d,\n", temp_diff);
  948. temp_diff = -temp_diff;
  949. } else if (temp_diff == 0)
  950. D_POWER("Same temp,\n");
  951. else
  952. D_POWER("Getting warmer, delta %d,\n", temp_diff);
  953. /* if we don't need calibration, *don't* update last_temperature */
  954. if (temp_diff < IL_TEMPERATURE_LIMIT_TIMER) {
  955. D_POWER("Timed thermal calib not needed\n");
  956. return 0;
  957. }
  958. D_POWER("Timed thermal calib needed\n");
  959. /* assume that caller will actually do calib ...
  960. * update the "last temperature" value */
  961. il->last_temperature = il->temperature;
  962. return 1;
  963. }
  964. #define IL_MAX_GAIN_ENTRIES 78
  965. #define IL_CCK_FROM_OFDM_POWER_DIFF -5
  966. #define IL_CCK_FROM_OFDM_IDX_DIFF (10)
  967. /* radio and DSP power table, each step is 1/2 dB.
  968. * 1st number is for RF analog gain, 2nd number is for DSP pre-DAC gain. */
  969. static struct il3945_tx_power power_gain_table[2][IL_MAX_GAIN_ENTRIES] = {
  970. {
  971. {251, 127}, /* 2.4 GHz, highest power */
  972. {251, 127},
  973. {251, 127},
  974. {251, 127},
  975. {251, 125},
  976. {251, 110},
  977. {251, 105},
  978. {251, 98},
  979. {187, 125},
  980. {187, 115},
  981. {187, 108},
  982. {187, 99},
  983. {243, 119},
  984. {243, 111},
  985. {243, 105},
  986. {243, 97},
  987. {243, 92},
  988. {211, 106},
  989. {211, 100},
  990. {179, 120},
  991. {179, 113},
  992. {179, 107},
  993. {147, 125},
  994. {147, 119},
  995. {147, 112},
  996. {147, 106},
  997. {147, 101},
  998. {147, 97},
  999. {147, 91},
  1000. {115, 107},
  1001. {235, 121},
  1002. {235, 115},
  1003. {235, 109},
  1004. {203, 127},
  1005. {203, 121},
  1006. {203, 115},
  1007. {203, 108},
  1008. {203, 102},
  1009. {203, 96},
  1010. {203, 92},
  1011. {171, 110},
  1012. {171, 104},
  1013. {171, 98},
  1014. {139, 116},
  1015. {227, 125},
  1016. {227, 119},
  1017. {227, 113},
  1018. {227, 107},
  1019. {227, 101},
  1020. {227, 96},
  1021. {195, 113},
  1022. {195, 106},
  1023. {195, 102},
  1024. {195, 95},
  1025. {163, 113},
  1026. {163, 106},
  1027. {163, 102},
  1028. {163, 95},
  1029. {131, 113},
  1030. {131, 106},
  1031. {131, 102},
  1032. {131, 95},
  1033. {99, 113},
  1034. {99, 106},
  1035. {99, 102},
  1036. {99, 95},
  1037. {67, 113},
  1038. {67, 106},
  1039. {67, 102},
  1040. {67, 95},
  1041. {35, 113},
  1042. {35, 106},
  1043. {35, 102},
  1044. {35, 95},
  1045. {3, 113},
  1046. {3, 106},
  1047. {3, 102},
  1048. {3, 95} }, /* 2.4 GHz, lowest power */
  1049. {
  1050. {251, 127}, /* 5.x GHz, highest power */
  1051. {251, 120},
  1052. {251, 114},
  1053. {219, 119},
  1054. {219, 101},
  1055. {187, 113},
  1056. {187, 102},
  1057. {155, 114},
  1058. {155, 103},
  1059. {123, 117},
  1060. {123, 107},
  1061. {123, 99},
  1062. {123, 92},
  1063. {91, 108},
  1064. {59, 125},
  1065. {59, 118},
  1066. {59, 109},
  1067. {59, 102},
  1068. {59, 96},
  1069. {59, 90},
  1070. {27, 104},
  1071. {27, 98},
  1072. {27, 92},
  1073. {115, 118},
  1074. {115, 111},
  1075. {115, 104},
  1076. {83, 126},
  1077. {83, 121},
  1078. {83, 113},
  1079. {83, 105},
  1080. {83, 99},
  1081. {51, 118},
  1082. {51, 111},
  1083. {51, 104},
  1084. {51, 98},
  1085. {19, 116},
  1086. {19, 109},
  1087. {19, 102},
  1088. {19, 98},
  1089. {19, 93},
  1090. {171, 113},
  1091. {171, 107},
  1092. {171, 99},
  1093. {139, 120},
  1094. {139, 113},
  1095. {139, 107},
  1096. {139, 99},
  1097. {107, 120},
  1098. {107, 113},
  1099. {107, 107},
  1100. {107, 99},
  1101. {75, 120},
  1102. {75, 113},
  1103. {75, 107},
  1104. {75, 99},
  1105. {43, 120},
  1106. {43, 113},
  1107. {43, 107},
  1108. {43, 99},
  1109. {11, 120},
  1110. {11, 113},
  1111. {11, 107},
  1112. {11, 99},
  1113. {131, 107},
  1114. {131, 99},
  1115. {99, 120},
  1116. {99, 113},
  1117. {99, 107},
  1118. {99, 99},
  1119. {67, 120},
  1120. {67, 113},
  1121. {67, 107},
  1122. {67, 99},
  1123. {35, 120},
  1124. {35, 113},
  1125. {35, 107},
  1126. {35, 99},
  1127. {3, 120} } /* 5.x GHz, lowest power */
  1128. };
  1129. static inline u8 il3945_hw_reg_fix_power_idx(int idx)
  1130. {
  1131. if (idx < 0)
  1132. return 0;
  1133. if (idx >= IL_MAX_GAIN_ENTRIES)
  1134. return IL_MAX_GAIN_ENTRIES - 1;
  1135. return (u8) idx;
  1136. }
  1137. /* Kick off thermal recalibration check every 60 seconds */
  1138. #define REG_RECALIB_PERIOD (60)
  1139. /**
  1140. * il3945_hw_reg_set_scan_power - Set Tx power for scan probe requests
  1141. *
  1142. * Set (in our channel info database) the direct scan Tx power for 1 Mbit (CCK)
  1143. * or 6 Mbit (OFDM) rates.
  1144. */
  1145. static void il3945_hw_reg_set_scan_power(struct il_priv *il, u32 scan_tbl_idx,
  1146. s32 rate_idx, const s8 *clip_pwrs,
  1147. struct il_channel_info *ch_info,
  1148. int band_idx)
  1149. {
  1150. struct il3945_scan_power_info *scan_power_info;
  1151. s8 power;
  1152. u8 power_idx;
  1153. scan_power_info = &ch_info->scan_pwr_info[scan_tbl_idx];
  1154. /* use this channel group's 6Mbit clipping/saturation pwr,
  1155. * but cap at regulatory scan power restriction (set during init
  1156. * based on eeprom channel data) for this channel. */
  1157. power = min(ch_info->scan_power, clip_pwrs[RATE_6M_IDX_TBL]);
  1158. power = min(power, il->tx_power_user_lmt);
  1159. scan_power_info->requested_power = power;
  1160. /* find difference between new scan *power* and current "normal"
  1161. * Tx *power* for 6Mb. Use this difference (x2) to adjust the
  1162. * current "normal" temperature-compensated Tx power *idx* for
  1163. * this rate (1Mb or 6Mb) to yield new temp-compensated scan power
  1164. * *idx*. */
  1165. power_idx = ch_info->power_info[rate_idx].power_table_idx
  1166. - (power - ch_info->power_info
  1167. [RATE_6M_IDX_TBL].requested_power) * 2;
  1168. /* store reference idx that we use when adjusting *all* scan
  1169. * powers. So we can accommodate user (all channel) or spectrum
  1170. * management (single channel) power changes "between" temperature
  1171. * feedback compensation procedures.
  1172. * don't force fit this reference idx into gain table; it may be a
  1173. * negative number. This will help avoid errors when we're at
  1174. * the lower bounds (highest gains, for warmest temperatures)
  1175. * of the table. */
  1176. /* don't exceed table bounds for "real" setting */
  1177. power_idx = il3945_hw_reg_fix_power_idx(power_idx);
  1178. scan_power_info->power_table_idx = power_idx;
  1179. scan_power_info->tpc.tx_gain =
  1180. power_gain_table[band_idx][power_idx].tx_gain;
  1181. scan_power_info->tpc.dsp_atten =
  1182. power_gain_table[band_idx][power_idx].dsp_atten;
  1183. }
  1184. /**
  1185. * il3945_send_tx_power - fill in Tx Power command with gain settings
  1186. *
  1187. * Configures power settings for all rates for the current channel,
  1188. * using values from channel info struct, and send to NIC
  1189. */
  1190. static int il3945_send_tx_power(struct il_priv *il)
  1191. {
  1192. int rate_idx, i;
  1193. const struct il_channel_info *ch_info = NULL;
  1194. struct il3945_txpowertable_cmd txpower = {
  1195. .channel = il->ctx.active.channel,
  1196. };
  1197. u16 chan;
  1198. if (WARN_ONCE(test_bit(STATUS_SCAN_HW, &il->status),
  1199. "TX Power requested while scanning!\n"))
  1200. return -EAGAIN;
  1201. chan = le16_to_cpu(il->ctx.active.channel);
  1202. txpower.band = (il->band == IEEE80211_BAND_5GHZ) ? 0 : 1;
  1203. ch_info = il_get_channel_info(il, il->band, chan);
  1204. if (!ch_info) {
  1205. IL_ERR(
  1206. "Failed to get channel info for channel %d [%d]\n",
  1207. chan, il->band);
  1208. return -EINVAL;
  1209. }
  1210. if (!il_is_channel_valid(ch_info)) {
  1211. D_POWER("Not calling TX_PWR_TBL_CMD on "
  1212. "non-Tx channel.\n");
  1213. return 0;
  1214. }
  1215. /* fill cmd with power settings for all rates for current channel */
  1216. /* Fill OFDM rate */
  1217. for (rate_idx = IL_FIRST_OFDM_RATE, i = 0;
  1218. rate_idx <= IL39_LAST_OFDM_RATE; rate_idx++, i++) {
  1219. txpower.power[i].tpc = ch_info->power_info[i].tpc;
  1220. txpower.power[i].rate = il3945_rates[rate_idx].plcp;
  1221. D_POWER("ch %d:%d rf %d dsp %3d rate code 0x%02x\n",
  1222. le16_to_cpu(txpower.channel),
  1223. txpower.band,
  1224. txpower.power[i].tpc.tx_gain,
  1225. txpower.power[i].tpc.dsp_atten,
  1226. txpower.power[i].rate);
  1227. }
  1228. /* Fill CCK rates */
  1229. for (rate_idx = IL_FIRST_CCK_RATE;
  1230. rate_idx <= IL_LAST_CCK_RATE; rate_idx++, i++) {
  1231. txpower.power[i].tpc = ch_info->power_info[i].tpc;
  1232. txpower.power[i].rate = il3945_rates[rate_idx].plcp;
  1233. D_POWER("ch %d:%d rf %d dsp %3d rate code 0x%02x\n",
  1234. le16_to_cpu(txpower.channel),
  1235. txpower.band,
  1236. txpower.power[i].tpc.tx_gain,
  1237. txpower.power[i].tpc.dsp_atten,
  1238. txpower.power[i].rate);
  1239. }
  1240. return il_send_cmd_pdu(il, REPLY_TX_PWR_TBL_CMD,
  1241. sizeof(struct il3945_txpowertable_cmd),
  1242. &txpower);
  1243. }
  1244. /**
  1245. * il3945_hw_reg_set_new_power - Configures power tables at new levels
  1246. * @ch_info: Channel to update. Uses power_info.requested_power.
  1247. *
  1248. * Replace requested_power and base_power_idx ch_info fields for
  1249. * one channel.
  1250. *
  1251. * Called if user or spectrum management changes power preferences.
  1252. * Takes into account h/w and modulation limitations (clip power).
  1253. *
  1254. * This does *not* send anything to NIC, just sets up ch_info for one channel.
  1255. *
  1256. * NOTE: reg_compensate_for_temperature_dif() *must* be run after this to
  1257. * properly fill out the scan powers, and actual h/w gain settings,
  1258. * and send changes to NIC
  1259. */
  1260. static int il3945_hw_reg_set_new_power(struct il_priv *il,
  1261. struct il_channel_info *ch_info)
  1262. {
  1263. struct il3945_channel_power_info *power_info;
  1264. int power_changed = 0;
  1265. int i;
  1266. const s8 *clip_pwrs;
  1267. int power;
  1268. /* Get this chnlgrp's rate-to-max/clip-powers table */
  1269. clip_pwrs = il->_3945.clip_groups[ch_info->group_idx].clip_powers;
  1270. /* Get this channel's rate-to-current-power settings table */
  1271. power_info = ch_info->power_info;
  1272. /* update OFDM Txpower settings */
  1273. for (i = RATE_6M_IDX_TBL; i <= RATE_54M_IDX_TBL;
  1274. i++, ++power_info) {
  1275. int delta_idx;
  1276. /* limit new power to be no more than h/w capability */
  1277. power = min(ch_info->curr_txpow, clip_pwrs[i]);
  1278. if (power == power_info->requested_power)
  1279. continue;
  1280. /* find difference between old and new requested powers,
  1281. * update base (non-temp-compensated) power idx */
  1282. delta_idx = (power - power_info->requested_power) * 2;
  1283. power_info->base_power_idx -= delta_idx;
  1284. /* save new requested power value */
  1285. power_info->requested_power = power;
  1286. power_changed = 1;
  1287. }
  1288. /* update CCK Txpower settings, based on OFDM 12M setting ...
  1289. * ... all CCK power settings for a given channel are the *same*. */
  1290. if (power_changed) {
  1291. power =
  1292. ch_info->power_info[RATE_12M_IDX_TBL].
  1293. requested_power + IL_CCK_FROM_OFDM_POWER_DIFF;
  1294. /* do all CCK rates' il3945_channel_power_info structures */
  1295. for (i = RATE_1M_IDX_TBL; i <= RATE_11M_IDX_TBL; i++) {
  1296. power_info->requested_power = power;
  1297. power_info->base_power_idx =
  1298. ch_info->power_info[RATE_12M_IDX_TBL].
  1299. base_power_idx + IL_CCK_FROM_OFDM_IDX_DIFF;
  1300. ++power_info;
  1301. }
  1302. }
  1303. return 0;
  1304. }
  1305. /**
  1306. * il3945_hw_reg_get_ch_txpower_limit - returns new power limit for channel
  1307. *
  1308. * NOTE: Returned power limit may be less (but not more) than requested,
  1309. * based strictly on regulatory (eeprom and spectrum mgt) limitations
  1310. * (no consideration for h/w clipping limitations).
  1311. */
  1312. static int il3945_hw_reg_get_ch_txpower_limit(struct il_channel_info *ch_info)
  1313. {
  1314. s8 max_power;
  1315. #if 0
  1316. /* if we're using TGd limits, use lower of TGd or EEPROM */
  1317. if (ch_info->tgd_data.max_power != 0)
  1318. max_power = min(ch_info->tgd_data.max_power,
  1319. ch_info->eeprom.max_power_avg);
  1320. /* else just use EEPROM limits */
  1321. else
  1322. #endif
  1323. max_power = ch_info->eeprom.max_power_avg;
  1324. return min(max_power, ch_info->max_power_avg);
  1325. }
  1326. /**
  1327. * il3945_hw_reg_comp_txpower_temp - Compensate for temperature
  1328. *
  1329. * Compensate txpower settings of *all* channels for temperature.
  1330. * This only accounts for the difference between current temperature
  1331. * and the factory calibration temperatures, and bases the new settings
  1332. * on the channel's base_power_idx.
  1333. *
  1334. * If RxOn is "associated", this sends the new Txpower to NIC!
  1335. */
  1336. static int il3945_hw_reg_comp_txpower_temp(struct il_priv *il)
  1337. {
  1338. struct il_channel_info *ch_info = NULL;
  1339. struct il3945_eeprom *eeprom = (struct il3945_eeprom *)il->eeprom;
  1340. int delta_idx;
  1341. const s8 *clip_pwrs; /* array of h/w max power levels for each rate */
  1342. u8 a_band;
  1343. u8 rate_idx;
  1344. u8 scan_tbl_idx;
  1345. u8 i;
  1346. int ref_temp;
  1347. int temperature = il->temperature;
  1348. if (il->disable_tx_power_cal ||
  1349. test_bit(STATUS_SCANNING, &il->status)) {
  1350. /* do not perform tx power calibration */
  1351. return 0;
  1352. }
  1353. /* set up new Tx power info for each and every channel, 2.4 and 5.x */
  1354. for (i = 0; i < il->channel_count; i++) {
  1355. ch_info = &il->channel_info[i];
  1356. a_band = il_is_channel_a_band(ch_info);
  1357. /* Get this chnlgrp's factory calibration temperature */
  1358. ref_temp = (s16)eeprom->groups[ch_info->group_idx].
  1359. temperature;
  1360. /* get power idx adjustment based on current and factory
  1361. * temps */
  1362. delta_idx = il3945_hw_reg_adjust_power_by_temp(temperature,
  1363. ref_temp);
  1364. /* set tx power value for all rates, OFDM and CCK */
  1365. for (rate_idx = 0; rate_idx < RATE_COUNT_3945;
  1366. rate_idx++) {
  1367. int power_idx =
  1368. ch_info->power_info[rate_idx].base_power_idx;
  1369. /* temperature compensate */
  1370. power_idx += delta_idx;
  1371. /* stay within table range */
  1372. power_idx = il3945_hw_reg_fix_power_idx(power_idx);
  1373. ch_info->power_info[rate_idx].
  1374. power_table_idx = (u8) power_idx;
  1375. ch_info->power_info[rate_idx].tpc =
  1376. power_gain_table[a_band][power_idx];
  1377. }
  1378. /* Get this chnlgrp's rate-to-max/clip-powers table */
  1379. clip_pwrs = il->_3945.clip_groups[ch_info->group_idx].clip_powers;
  1380. /* set scan tx power, 1Mbit for CCK, 6Mbit for OFDM */
  1381. for (scan_tbl_idx = 0;
  1382. scan_tbl_idx < IL_NUM_SCAN_RATES; scan_tbl_idx++) {
  1383. s32 actual_idx = (scan_tbl_idx == 0) ?
  1384. RATE_1M_IDX_TBL : RATE_6M_IDX_TBL;
  1385. il3945_hw_reg_set_scan_power(il, scan_tbl_idx,
  1386. actual_idx, clip_pwrs,
  1387. ch_info, a_band);
  1388. }
  1389. }
  1390. /* send Txpower command for current channel to ucode */
  1391. return il->cfg->ops->lib->send_tx_power(il);
  1392. }
  1393. int il3945_hw_reg_set_txpower(struct il_priv *il, s8 power)
  1394. {
  1395. struct il_channel_info *ch_info;
  1396. s8 max_power;
  1397. u8 a_band;
  1398. u8 i;
  1399. if (il->tx_power_user_lmt == power) {
  1400. D_POWER("Requested Tx power same as current "
  1401. "limit: %ddBm.\n", power);
  1402. return 0;
  1403. }
  1404. D_POWER("Setting upper limit clamp to %ddBm.\n", power);
  1405. il->tx_power_user_lmt = power;
  1406. /* set up new Tx powers for each and every channel, 2.4 and 5.x */
  1407. for (i = 0; i < il->channel_count; i++) {
  1408. ch_info = &il->channel_info[i];
  1409. a_band = il_is_channel_a_band(ch_info);
  1410. /* find minimum power of all user and regulatory constraints
  1411. * (does not consider h/w clipping limitations) */
  1412. max_power = il3945_hw_reg_get_ch_txpower_limit(ch_info);
  1413. max_power = min(power, max_power);
  1414. if (max_power != ch_info->curr_txpow) {
  1415. ch_info->curr_txpow = max_power;
  1416. /* this considers the h/w clipping limitations */
  1417. il3945_hw_reg_set_new_power(il, ch_info);
  1418. }
  1419. }
  1420. /* update txpower settings for all channels,
  1421. * send to NIC if associated. */
  1422. il3945_is_temp_calib_needed(il);
  1423. il3945_hw_reg_comp_txpower_temp(il);
  1424. return 0;
  1425. }
  1426. static int il3945_send_rxon_assoc(struct il_priv *il,
  1427. struct il_rxon_context *ctx)
  1428. {
  1429. int rc = 0;
  1430. struct il_rx_pkt *pkt;
  1431. struct il3945_rxon_assoc_cmd rxon_assoc;
  1432. struct il_host_cmd cmd = {
  1433. .id = REPLY_RXON_ASSOC,
  1434. .len = sizeof(rxon_assoc),
  1435. .flags = CMD_WANT_SKB,
  1436. .data = &rxon_assoc,
  1437. };
  1438. const struct il_rxon_cmd *rxon1 = &ctx->staging;
  1439. const struct il_rxon_cmd *rxon2 = &ctx->active;
  1440. if (rxon1->flags == rxon2->flags &&
  1441. rxon1->filter_flags == rxon2->filter_flags &&
  1442. rxon1->cck_basic_rates == rxon2->cck_basic_rates &&
  1443. rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates) {
  1444. D_INFO("Using current RXON_ASSOC. Not resending.\n");
  1445. return 0;
  1446. }
  1447. rxon_assoc.flags = ctx->staging.flags;
  1448. rxon_assoc.filter_flags = ctx->staging.filter_flags;
  1449. rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates;
  1450. rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates;
  1451. rxon_assoc.reserved = 0;
  1452. rc = il_send_cmd_sync(il, &cmd);
  1453. if (rc)
  1454. return rc;
  1455. pkt = (struct il_rx_pkt *)cmd.reply_page;
  1456. if (pkt->hdr.flags & IL_CMD_FAILED_MSK) {
  1457. IL_ERR("Bad return from REPLY_RXON_ASSOC command\n");
  1458. rc = -EIO;
  1459. }
  1460. il_free_pages(il, cmd.reply_page);
  1461. return rc;
  1462. }
  1463. /**
  1464. * il3945_commit_rxon - commit staging_rxon to hardware
  1465. *
  1466. * The RXON command in staging_rxon is committed to the hardware and
  1467. * the active_rxon structure is updated with the new data. This
  1468. * function correctly transitions out of the RXON_ASSOC_MSK state if
  1469. * a HW tune is required based on the RXON structure changes.
  1470. */
  1471. int il3945_commit_rxon(struct il_priv *il, struct il_rxon_context *ctx)
  1472. {
  1473. /* cast away the const for active_rxon in this function */
  1474. struct il3945_rxon_cmd *active_rxon = (void *)&ctx->active;
  1475. struct il3945_rxon_cmd *staging_rxon = (void *)&ctx->staging;
  1476. int rc = 0;
  1477. bool new_assoc = !!(staging_rxon->filter_flags & RXON_FILTER_ASSOC_MSK);
  1478. if (test_bit(STATUS_EXIT_PENDING, &il->status))
  1479. return -EINVAL;
  1480. if (!il_is_alive(il))
  1481. return -1;
  1482. /* always get timestamp with Rx frame */
  1483. staging_rxon->flags |= RXON_FLG_TSF2HOST_MSK;
  1484. /* select antenna */
  1485. staging_rxon->flags &=
  1486. ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
  1487. staging_rxon->flags |= il3945_get_antenna_flags(il);
  1488. rc = il_check_rxon_cmd(il, ctx);
  1489. if (rc) {
  1490. IL_ERR("Invalid RXON configuration. Not committing.\n");
  1491. return -EINVAL;
  1492. }
  1493. /* If we don't need to send a full RXON, we can use
  1494. * il3945_rxon_assoc_cmd which is used to reconfigure filter
  1495. * and other flags for the current radio configuration. */
  1496. if (!il_full_rxon_required(il,
  1497. &il->ctx)) {
  1498. rc = il_send_rxon_assoc(il,
  1499. &il->ctx);
  1500. if (rc) {
  1501. IL_ERR("Error setting RXON_ASSOC "
  1502. "configuration (%d).\n", rc);
  1503. return rc;
  1504. }
  1505. memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
  1506. /*
  1507. * We do not commit tx power settings while channel changing,
  1508. * do it now if tx power changed.
  1509. */
  1510. il_set_tx_power(il, il->tx_power_next, false);
  1511. return 0;
  1512. }
  1513. /* If we are currently associated and the new config requires
  1514. * an RXON_ASSOC and the new config wants the associated mask enabled,
  1515. * we must clear the associated from the active configuration
  1516. * before we apply the new config */
  1517. if (il_is_associated(il) && new_assoc) {
  1518. D_INFO("Toggling associated bit on current RXON\n");
  1519. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1520. /*
  1521. * reserved4 and 5 could have been filled by the iwlcore code.
  1522. * Let's clear them before pushing to the 3945.
  1523. */
  1524. active_rxon->reserved4 = 0;
  1525. active_rxon->reserved5 = 0;
  1526. rc = il_send_cmd_pdu(il, REPLY_RXON,
  1527. sizeof(struct il3945_rxon_cmd),
  1528. &il->ctx.active);
  1529. /* If the mask clearing failed then we set
  1530. * active_rxon back to what it was previously */
  1531. if (rc) {
  1532. active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
  1533. IL_ERR("Error clearing ASSOC_MSK on current "
  1534. "configuration (%d).\n", rc);
  1535. return rc;
  1536. }
  1537. il_clear_ucode_stations(il,
  1538. &il->ctx);
  1539. il_restore_stations(il,
  1540. &il->ctx);
  1541. }
  1542. D_INFO("Sending RXON\n"
  1543. "* with%s RXON_FILTER_ASSOC_MSK\n"
  1544. "* channel = %d\n"
  1545. "* bssid = %pM\n",
  1546. (new_assoc ? "" : "out"),
  1547. le16_to_cpu(staging_rxon->channel),
  1548. staging_rxon->bssid_addr);
  1549. /*
  1550. * reserved4 and 5 could have been filled by the iwlcore code.
  1551. * Let's clear them before pushing to the 3945.
  1552. */
  1553. staging_rxon->reserved4 = 0;
  1554. staging_rxon->reserved5 = 0;
  1555. il_set_rxon_hwcrypto(il, ctx, !il3945_mod_params.sw_crypto);
  1556. /* Apply the new configuration */
  1557. rc = il_send_cmd_pdu(il, REPLY_RXON,
  1558. sizeof(struct il3945_rxon_cmd),
  1559. staging_rxon);
  1560. if (rc) {
  1561. IL_ERR("Error setting new configuration (%d).\n", rc);
  1562. return rc;
  1563. }
  1564. memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
  1565. if (!new_assoc) {
  1566. il_clear_ucode_stations(il,
  1567. &il->ctx);
  1568. il_restore_stations(il,
  1569. &il->ctx);
  1570. }
  1571. /* If we issue a new RXON command which required a tune then we must
  1572. * send a new TXPOWER command or we won't be able to Tx any frames */
  1573. rc = il_set_tx_power(il, il->tx_power_next, true);
  1574. if (rc) {
  1575. IL_ERR("Error setting Tx power (%d).\n", rc);
  1576. return rc;
  1577. }
  1578. /* Init the hardware's rate fallback order based on the band */
  1579. rc = il3945_init_hw_rate_table(il);
  1580. if (rc) {
  1581. IL_ERR("Error setting HW rate table: %02X\n", rc);
  1582. return -EIO;
  1583. }
  1584. return 0;
  1585. }
  1586. /**
  1587. * il3945_reg_txpower_periodic - called when time to check our temperature.
  1588. *
  1589. * -- reset periodic timer
  1590. * -- see if temp has changed enough to warrant re-calibration ... if so:
  1591. * -- correct coeffs for temp (can reset temp timer)
  1592. * -- save this temp as "last",
  1593. * -- send new set of gain settings to NIC
  1594. * NOTE: This should continue working, even when we're not associated,
  1595. * so we can keep our internal table of scan powers current. */
  1596. void il3945_reg_txpower_periodic(struct il_priv *il)
  1597. {
  1598. /* This will kick in the "brute force"
  1599. * il3945_hw_reg_comp_txpower_temp() below */
  1600. if (!il3945_is_temp_calib_needed(il))
  1601. goto reschedule;
  1602. /* Set up a new set of temp-adjusted TxPowers, send to NIC.
  1603. * This is based *only* on current temperature,
  1604. * ignoring any previous power measurements */
  1605. il3945_hw_reg_comp_txpower_temp(il);
  1606. reschedule:
  1607. queue_delayed_work(il->workqueue,
  1608. &il->_3945.thermal_periodic, REG_RECALIB_PERIOD * HZ);
  1609. }
  1610. static void il3945_bg_reg_txpower_periodic(struct work_struct *work)
  1611. {
  1612. struct il_priv *il = container_of(work, struct il_priv,
  1613. _3945.thermal_periodic.work);
  1614. if (test_bit(STATUS_EXIT_PENDING, &il->status))
  1615. return;
  1616. mutex_lock(&il->mutex);
  1617. il3945_reg_txpower_periodic(il);
  1618. mutex_unlock(&il->mutex);
  1619. }
  1620. /**
  1621. * il3945_hw_reg_get_ch_grp_idx - find the channel-group idx (0-4)
  1622. * for the channel.
  1623. *
  1624. * This function is used when initializing channel-info structs.
  1625. *
  1626. * NOTE: These channel groups do *NOT* match the bands above!
  1627. * These channel groups are based on factory-tested channels;
  1628. * on A-band, EEPROM's "group frequency" entries represent the top
  1629. * channel in each group 1-4. Group 5 All B/G channels are in group 0.
  1630. */
  1631. static u16 il3945_hw_reg_get_ch_grp_idx(struct il_priv *il,
  1632. const struct il_channel_info *ch_info)
  1633. {
  1634. struct il3945_eeprom *eeprom = (struct il3945_eeprom *)il->eeprom;
  1635. struct il3945_eeprom_txpower_group *ch_grp = &eeprom->groups[0];
  1636. u8 group;
  1637. u16 group_idx = 0; /* based on factory calib frequencies */
  1638. u8 grp_channel;
  1639. /* Find the group idx for the channel ... don't use idx 1(?) */
  1640. if (il_is_channel_a_band(ch_info)) {
  1641. for (group = 1; group < 5; group++) {
  1642. grp_channel = ch_grp[group].group_channel;
  1643. if (ch_info->channel <= grp_channel) {
  1644. group_idx = group;
  1645. break;
  1646. }
  1647. }
  1648. /* group 4 has a few channels *above* its factory cal freq */
  1649. if (group == 5)
  1650. group_idx = 4;
  1651. } else
  1652. group_idx = 0; /* 2.4 GHz, group 0 */
  1653. D_POWER("Chnl %d mapped to grp %d\n", ch_info->channel,
  1654. group_idx);
  1655. return group_idx;
  1656. }
  1657. /**
  1658. * il3945_hw_reg_get_matched_power_idx - Interpolate to get nominal idx
  1659. *
  1660. * Interpolate to get nominal (i.e. at factory calibration temperature) idx
  1661. * into radio/DSP gain settings table for requested power.
  1662. */
  1663. static int il3945_hw_reg_get_matched_power_idx(struct il_priv *il,
  1664. s8 requested_power,
  1665. s32 setting_idx, s32 *new_idx)
  1666. {
  1667. const struct il3945_eeprom_txpower_group *chnl_grp = NULL;
  1668. struct il3945_eeprom *eeprom = (struct il3945_eeprom *)il->eeprom;
  1669. s32 idx0, idx1;
  1670. s32 power = 2 * requested_power;
  1671. s32 i;
  1672. const struct il3945_eeprom_txpower_sample *samples;
  1673. s32 gains0, gains1;
  1674. s32 res;
  1675. s32 denominator;
  1676. chnl_grp = &eeprom->groups[setting_idx];
  1677. samples = chnl_grp->samples;
  1678. for (i = 0; i < 5; i++) {
  1679. if (power == samples[i].power) {
  1680. *new_idx = samples[i].gain_idx;
  1681. return 0;
  1682. }
  1683. }
  1684. if (power > samples[1].power) {
  1685. idx0 = 0;
  1686. idx1 = 1;
  1687. } else if (power > samples[2].power) {
  1688. idx0 = 1;
  1689. idx1 = 2;
  1690. } else if (power > samples[3].power) {
  1691. idx0 = 2;
  1692. idx1 = 3;
  1693. } else {
  1694. idx0 = 3;
  1695. idx1 = 4;
  1696. }
  1697. denominator = (s32) samples[idx1].power - (s32) samples[idx0].power;
  1698. if (denominator == 0)
  1699. return -EINVAL;
  1700. gains0 = (s32) samples[idx0].gain_idx * (1 << 19);
  1701. gains1 = (s32) samples[idx1].gain_idx * (1 << 19);
  1702. res = gains0 + (gains1 - gains0) *
  1703. ((s32) power - (s32) samples[idx0].power) / denominator +
  1704. (1 << 18);
  1705. *new_idx = res >> 19;
  1706. return 0;
  1707. }
  1708. static void il3945_hw_reg_init_channel_groups(struct il_priv *il)
  1709. {
  1710. u32 i;
  1711. s32 rate_idx;
  1712. struct il3945_eeprom *eeprom = (struct il3945_eeprom *)il->eeprom;
  1713. const struct il3945_eeprom_txpower_group *group;
  1714. D_POWER("Initializing factory calib info from EEPROM\n");
  1715. for (i = 0; i < IL_NUM_TX_CALIB_GROUPS; i++) {
  1716. s8 *clip_pwrs; /* table of power levels for each rate */
  1717. s8 satur_pwr; /* saturation power for each chnl group */
  1718. group = &eeprom->groups[i];
  1719. /* sanity check on factory saturation power value */
  1720. if (group->saturation_power < 40) {
  1721. IL_WARN("Error: saturation power is %d, "
  1722. "less than minimum expected 40\n",
  1723. group->saturation_power);
  1724. return;
  1725. }
  1726. /*
  1727. * Derive requested power levels for each rate, based on
  1728. * hardware capabilities (saturation power for band).
  1729. * Basic value is 3dB down from saturation, with further
  1730. * power reductions for highest 3 data rates. These
  1731. * backoffs provide headroom for high rate modulation
  1732. * power peaks, without too much distortion (clipping).
  1733. */
  1734. /* we'll fill in this array with h/w max power levels */
  1735. clip_pwrs = (s8 *) il->_3945.clip_groups[i].clip_powers;
  1736. /* divide factory saturation power by 2 to find -3dB level */
  1737. satur_pwr = (s8) (group->saturation_power >> 1);
  1738. /* fill in channel group's nominal powers for each rate */
  1739. for (rate_idx = 0;
  1740. rate_idx < RATE_COUNT_3945; rate_idx++, clip_pwrs++) {
  1741. switch (rate_idx) {
  1742. case RATE_36M_IDX_TBL:
  1743. if (i == 0) /* B/G */
  1744. *clip_pwrs = satur_pwr;
  1745. else /* A */
  1746. *clip_pwrs = satur_pwr - 5;
  1747. break;
  1748. case RATE_48M_IDX_TBL:
  1749. if (i == 0)
  1750. *clip_pwrs = satur_pwr - 7;
  1751. else
  1752. *clip_pwrs = satur_pwr - 10;
  1753. break;
  1754. case RATE_54M_IDX_TBL:
  1755. if (i == 0)
  1756. *clip_pwrs = satur_pwr - 9;
  1757. else
  1758. *clip_pwrs = satur_pwr - 12;
  1759. break;
  1760. default:
  1761. *clip_pwrs = satur_pwr;
  1762. break;
  1763. }
  1764. }
  1765. }
  1766. }
  1767. /**
  1768. * il3945_txpower_set_from_eeprom - Set channel power info based on EEPROM
  1769. *
  1770. * Second pass (during init) to set up il->channel_info
  1771. *
  1772. * Set up Tx-power settings in our channel info database for each VALID
  1773. * (for this geo/SKU) channel, at all Tx data rates, based on eeprom values
  1774. * and current temperature.
  1775. *
  1776. * Since this is based on current temperature (at init time), these values may
  1777. * not be valid for very long, but it gives us a starting/default point,
  1778. * and allows us to active (i.e. using Tx) scan.
  1779. *
  1780. * This does *not* write values to NIC, just sets up our internal table.
  1781. */
  1782. int il3945_txpower_set_from_eeprom(struct il_priv *il)
  1783. {
  1784. struct il_channel_info *ch_info = NULL;
  1785. struct il3945_channel_power_info *pwr_info;
  1786. struct il3945_eeprom *eeprom = (struct il3945_eeprom *)il->eeprom;
  1787. int delta_idx;
  1788. u8 rate_idx;
  1789. u8 scan_tbl_idx;
  1790. const s8 *clip_pwrs; /* array of power levels for each rate */
  1791. u8 gain, dsp_atten;
  1792. s8 power;
  1793. u8 pwr_idx, base_pwr_idx, a_band;
  1794. u8 i;
  1795. int temperature;
  1796. /* save temperature reference,
  1797. * so we can determine next time to calibrate */
  1798. temperature = il3945_hw_reg_txpower_get_temperature(il);
  1799. il->last_temperature = temperature;
  1800. il3945_hw_reg_init_channel_groups(il);
  1801. /* initialize Tx power info for each and every channel, 2.4 and 5.x */
  1802. for (i = 0, ch_info = il->channel_info; i < il->channel_count;
  1803. i++, ch_info++) {
  1804. a_band = il_is_channel_a_band(ch_info);
  1805. if (!il_is_channel_valid(ch_info))
  1806. continue;
  1807. /* find this channel's channel group (*not* "band") idx */
  1808. ch_info->group_idx =
  1809. il3945_hw_reg_get_ch_grp_idx(il, ch_info);
  1810. /* Get this chnlgrp's rate->max/clip-powers table */
  1811. clip_pwrs = il->_3945.clip_groups[ch_info->group_idx].clip_powers;
  1812. /* calculate power idx *adjustment* value according to
  1813. * diff between current temperature and factory temperature */
  1814. delta_idx = il3945_hw_reg_adjust_power_by_temp(temperature,
  1815. eeprom->groups[ch_info->group_idx].
  1816. temperature);
  1817. D_POWER("Delta idx for channel %d: %d [%d]\n",
  1818. ch_info->channel, delta_idx, temperature +
  1819. IL_TEMP_CONVERT);
  1820. /* set tx power value for all OFDM rates */
  1821. for (rate_idx = 0; rate_idx < IL_OFDM_RATES;
  1822. rate_idx++) {
  1823. s32 uninitialized_var(power_idx);
  1824. int rc;
  1825. /* use channel group's clip-power table,
  1826. * but don't exceed channel's max power */
  1827. s8 pwr = min(ch_info->max_power_avg,
  1828. clip_pwrs[rate_idx]);
  1829. pwr_info = &ch_info->power_info[rate_idx];
  1830. /* get base (i.e. at factory-measured temperature)
  1831. * power table idx for this rate's power */
  1832. rc = il3945_hw_reg_get_matched_power_idx(il, pwr,
  1833. ch_info->group_idx,
  1834. &power_idx);
  1835. if (rc) {
  1836. IL_ERR("Invalid power idx\n");
  1837. return rc;
  1838. }
  1839. pwr_info->base_power_idx = (u8) power_idx;
  1840. /* temperature compensate */
  1841. power_idx += delta_idx;
  1842. /* stay within range of gain table */
  1843. power_idx = il3945_hw_reg_fix_power_idx(power_idx);
  1844. /* fill 1 OFDM rate's il3945_channel_power_info struct */
  1845. pwr_info->requested_power = pwr;
  1846. pwr_info->power_table_idx = (u8) power_idx;
  1847. pwr_info->tpc.tx_gain =
  1848. power_gain_table[a_band][power_idx].tx_gain;
  1849. pwr_info->tpc.dsp_atten =
  1850. power_gain_table[a_band][power_idx].dsp_atten;
  1851. }
  1852. /* set tx power for CCK rates, based on OFDM 12 Mbit settings*/
  1853. pwr_info = &ch_info->power_info[RATE_12M_IDX_TBL];
  1854. power = pwr_info->requested_power +
  1855. IL_CCK_FROM_OFDM_POWER_DIFF;
  1856. pwr_idx = pwr_info->power_table_idx +
  1857. IL_CCK_FROM_OFDM_IDX_DIFF;
  1858. base_pwr_idx = pwr_info->base_power_idx +
  1859. IL_CCK_FROM_OFDM_IDX_DIFF;
  1860. /* stay within table range */
  1861. pwr_idx = il3945_hw_reg_fix_power_idx(pwr_idx);
  1862. gain = power_gain_table[a_band][pwr_idx].tx_gain;
  1863. dsp_atten = power_gain_table[a_band][pwr_idx].dsp_atten;
  1864. /* fill each CCK rate's il3945_channel_power_info structure
  1865. * NOTE: All CCK-rate Txpwrs are the same for a given chnl!
  1866. * NOTE: CCK rates start at end of OFDM rates! */
  1867. for (rate_idx = 0;
  1868. rate_idx < IL_CCK_RATES; rate_idx++) {
  1869. pwr_info = &ch_info->power_info[rate_idx+IL_OFDM_RATES];
  1870. pwr_info->requested_power = power;
  1871. pwr_info->power_table_idx = pwr_idx;
  1872. pwr_info->base_power_idx = base_pwr_idx;
  1873. pwr_info->tpc.tx_gain = gain;
  1874. pwr_info->tpc.dsp_atten = dsp_atten;
  1875. }
  1876. /* set scan tx power, 1Mbit for CCK, 6Mbit for OFDM */
  1877. for (scan_tbl_idx = 0;
  1878. scan_tbl_idx < IL_NUM_SCAN_RATES; scan_tbl_idx++) {
  1879. s32 actual_idx = (scan_tbl_idx == 0) ?
  1880. RATE_1M_IDX_TBL : RATE_6M_IDX_TBL;
  1881. il3945_hw_reg_set_scan_power(il, scan_tbl_idx,
  1882. actual_idx, clip_pwrs, ch_info, a_band);
  1883. }
  1884. }
  1885. return 0;
  1886. }
  1887. int il3945_hw_rxq_stop(struct il_priv *il)
  1888. {
  1889. int rc;
  1890. il_wr(il, FH39_RCSR_CONFIG(0), 0);
  1891. rc = il_poll_bit(il, FH39_RSSR_STATUS,
  1892. FH39_RSSR_CHNL0_RX_STATUS_CHNL_IDLE, 1000);
  1893. if (rc < 0)
  1894. IL_ERR("Can't stop Rx DMA.\n");
  1895. return 0;
  1896. }
  1897. int il3945_hw_tx_queue_init(struct il_priv *il, struct il_tx_queue *txq)
  1898. {
  1899. int txq_id = txq->q.id;
  1900. struct il3945_shared *shared_data = il->_3945.shared_virt;
  1901. shared_data->tx_base_ptr[txq_id] = cpu_to_le32((u32)txq->q.dma_addr);
  1902. il_wr(il, FH39_CBCC_CTRL(txq_id), 0);
  1903. il_wr(il, FH39_CBCC_BASE(txq_id), 0);
  1904. il_wr(il, FH39_TCSR_CONFIG(txq_id),
  1905. FH39_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_NOINT |
  1906. FH39_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_TXF |
  1907. FH39_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_IFTFD |
  1908. FH39_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL |
  1909. FH39_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE);
  1910. /* fake read to flush all prev. writes */
  1911. _il_rd(il, FH39_TSSR_CBB_BASE);
  1912. return 0;
  1913. }
  1914. /*
  1915. * HCMD utils
  1916. */
  1917. static u16 il3945_get_hcmd_size(u8 cmd_id, u16 len)
  1918. {
  1919. switch (cmd_id) {
  1920. case REPLY_RXON:
  1921. return sizeof(struct il3945_rxon_cmd);
  1922. case POWER_TBL_CMD:
  1923. return sizeof(struct il3945_powertable_cmd);
  1924. default:
  1925. return len;
  1926. }
  1927. }
  1928. static u16 il3945_build_addsta_hcmd(const struct il_addsta_cmd *cmd,
  1929. u8 *data)
  1930. {
  1931. struct il3945_addsta_cmd *addsta = (struct il3945_addsta_cmd *)data;
  1932. addsta->mode = cmd->mode;
  1933. memcpy(&addsta->sta, &cmd->sta, sizeof(struct sta_id_modify));
  1934. memcpy(&addsta->key, &cmd->key, sizeof(struct il4965_keyinfo));
  1935. addsta->station_flags = cmd->station_flags;
  1936. addsta->station_flags_msk = cmd->station_flags_msk;
  1937. addsta->tid_disable_tx = cpu_to_le16(0);
  1938. addsta->rate_n_flags = cmd->rate_n_flags;
  1939. addsta->add_immediate_ba_tid = cmd->add_immediate_ba_tid;
  1940. addsta->remove_immediate_ba_tid = cmd->remove_immediate_ba_tid;
  1941. addsta->add_immediate_ba_ssn = cmd->add_immediate_ba_ssn;
  1942. return (u16)sizeof(struct il3945_addsta_cmd);
  1943. }
  1944. static int il3945_add_bssid_station(struct il_priv *il,
  1945. const u8 *addr, u8 *sta_id_r)
  1946. {
  1947. struct il_rxon_context *ctx = &il->ctx;
  1948. int ret;
  1949. u8 sta_id;
  1950. unsigned long flags;
  1951. if (sta_id_r)
  1952. *sta_id_r = IL_INVALID_STATION;
  1953. ret = il_add_station_common(il, ctx, addr, 0, NULL, &sta_id);
  1954. if (ret) {
  1955. IL_ERR("Unable to add station %pM\n", addr);
  1956. return ret;
  1957. }
  1958. if (sta_id_r)
  1959. *sta_id_r = sta_id;
  1960. spin_lock_irqsave(&il->sta_lock, flags);
  1961. il->stations[sta_id].used |= IL_STA_LOCAL;
  1962. spin_unlock_irqrestore(&il->sta_lock, flags);
  1963. return 0;
  1964. }
  1965. static int il3945_manage_ibss_station(struct il_priv *il,
  1966. struct ieee80211_vif *vif, bool add)
  1967. {
  1968. struct il_vif_priv *vif_priv = (void *)vif->drv_priv;
  1969. int ret;
  1970. if (add) {
  1971. ret = il3945_add_bssid_station(il, vif->bss_conf.bssid,
  1972. &vif_priv->ibss_bssid_sta_id);
  1973. if (ret)
  1974. return ret;
  1975. il3945_sync_sta(il, vif_priv->ibss_bssid_sta_id,
  1976. (il->band == IEEE80211_BAND_5GHZ) ?
  1977. RATE_6M_PLCP : RATE_1M_PLCP);
  1978. il3945_rate_scale_init(il->hw, vif_priv->ibss_bssid_sta_id);
  1979. return 0;
  1980. }
  1981. return il_remove_station(il, vif_priv->ibss_bssid_sta_id,
  1982. vif->bss_conf.bssid);
  1983. }
  1984. /**
  1985. * il3945_init_hw_rate_table - Initialize the hardware rate fallback table
  1986. */
  1987. int il3945_init_hw_rate_table(struct il_priv *il)
  1988. {
  1989. int rc, i, idx, prev_idx;
  1990. struct il3945_rate_scaling_cmd rate_cmd = {
  1991. .reserved = {0, 0, 0},
  1992. };
  1993. struct il3945_rate_scaling_info *table = rate_cmd.table;
  1994. for (i = 0; i < ARRAY_SIZE(il3945_rates); i++) {
  1995. idx = il3945_rates[i].table_rs_idx;
  1996. table[idx].rate_n_flags =
  1997. il3945_hw_set_rate_n_flags(il3945_rates[i].plcp, 0);
  1998. table[idx].try_cnt = il->retry_rate;
  1999. prev_idx = il3945_get_prev_ieee_rate(i);
  2000. table[idx].next_rate_idx =
  2001. il3945_rates[prev_idx].table_rs_idx;
  2002. }
  2003. switch (il->band) {
  2004. case IEEE80211_BAND_5GHZ:
  2005. D_RATE("Select A mode rate scale\n");
  2006. /* If one of the following CCK rates is used,
  2007. * have it fall back to the 6M OFDM rate */
  2008. for (i = RATE_1M_IDX_TBL;
  2009. i <= RATE_11M_IDX_TBL; i++)
  2010. table[i].next_rate_idx =
  2011. il3945_rates[IL_FIRST_OFDM_RATE].table_rs_idx;
  2012. /* Don't fall back to CCK rates */
  2013. table[RATE_12M_IDX_TBL].next_rate_idx =
  2014. RATE_9M_IDX_TBL;
  2015. /* Don't drop out of OFDM rates */
  2016. table[RATE_6M_IDX_TBL].next_rate_idx =
  2017. il3945_rates[IL_FIRST_OFDM_RATE].table_rs_idx;
  2018. break;
  2019. case IEEE80211_BAND_2GHZ:
  2020. D_RATE("Select B/G mode rate scale\n");
  2021. /* If an OFDM rate is used, have it fall back to the
  2022. * 1M CCK rates */
  2023. if (!(il->_3945.sta_supp_rates & IL_OFDM_RATES_MASK) &&
  2024. il_is_associated(il)) {
  2025. idx = IL_FIRST_CCK_RATE;
  2026. for (i = RATE_6M_IDX_TBL;
  2027. i <= RATE_54M_IDX_TBL; i++)
  2028. table[i].next_rate_idx =
  2029. il3945_rates[idx].table_rs_idx;
  2030. idx = RATE_11M_IDX_TBL;
  2031. /* CCK shouldn't fall back to OFDM... */
  2032. table[idx].next_rate_idx = RATE_5M_IDX_TBL;
  2033. }
  2034. break;
  2035. default:
  2036. WARN_ON(1);
  2037. break;
  2038. }
  2039. /* Update the rate scaling for control frame Tx */
  2040. rate_cmd.table_id = 0;
  2041. rc = il_send_cmd_pdu(il, REPLY_RATE_SCALE, sizeof(rate_cmd),
  2042. &rate_cmd);
  2043. if (rc)
  2044. return rc;
  2045. /* Update the rate scaling for data frame Tx */
  2046. rate_cmd.table_id = 1;
  2047. return il_send_cmd_pdu(il, REPLY_RATE_SCALE, sizeof(rate_cmd),
  2048. &rate_cmd);
  2049. }
  2050. /* Called when initializing driver */
  2051. int il3945_hw_set_hw_params(struct il_priv *il)
  2052. {
  2053. memset((void *)&il->hw_params, 0,
  2054. sizeof(struct il_hw_params));
  2055. il->_3945.shared_virt =
  2056. dma_alloc_coherent(&il->pci_dev->dev,
  2057. sizeof(struct il3945_shared),
  2058. &il->_3945.shared_phys, GFP_KERNEL);
  2059. if (!il->_3945.shared_virt) {
  2060. IL_ERR("failed to allocate pci memory\n");
  2061. return -ENOMEM;
  2062. }
  2063. /* Assign number of Usable TX queues */
  2064. il->hw_params.max_txq_num = il->cfg->base_params->num_of_queues;
  2065. il->hw_params.tfd_size = sizeof(struct il3945_tfd);
  2066. il->hw_params.rx_page_order = get_order(IL_RX_BUF_SIZE_3K);
  2067. il->hw_params.max_rxq_size = RX_QUEUE_SIZE;
  2068. il->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
  2069. il->hw_params.max_stations = IL3945_STATION_COUNT;
  2070. il->ctx.bcast_sta_id = IL3945_BROADCAST_ID;
  2071. il->sta_key_max_num = STA_KEY_MAX_NUM;
  2072. il->hw_params.rx_wrt_ptr_reg = FH39_RSCSR_CHNL0_WPTR;
  2073. il->hw_params.max_beacon_itrvl = IL39_MAX_UCODE_BEACON_INTERVAL;
  2074. il->hw_params.beacon_time_tsf_bits = IL3945_EXT_BEACON_TIME_POS;
  2075. return 0;
  2076. }
  2077. unsigned int il3945_hw_get_beacon_cmd(struct il_priv *il,
  2078. struct il3945_frame *frame, u8 rate)
  2079. {
  2080. struct il3945_tx_beacon_cmd *tx_beacon_cmd;
  2081. unsigned int frame_size;
  2082. tx_beacon_cmd = (struct il3945_tx_beacon_cmd *)&frame->u;
  2083. memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
  2084. tx_beacon_cmd->tx.sta_id =
  2085. il->ctx.bcast_sta_id;
  2086. tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  2087. frame_size = il3945_fill_beacon_frame(il,
  2088. tx_beacon_cmd->frame,
  2089. sizeof(frame->u) - sizeof(*tx_beacon_cmd));
  2090. BUG_ON(frame_size > MAX_MPDU_SIZE);
  2091. tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
  2092. tx_beacon_cmd->tx.rate = rate;
  2093. tx_beacon_cmd->tx.tx_flags = (TX_CMD_FLG_SEQ_CTL_MSK |
  2094. TX_CMD_FLG_TSF_MSK);
  2095. /* supp_rates[0] == OFDM start at IL_FIRST_OFDM_RATE*/
  2096. tx_beacon_cmd->tx.supp_rates[0] =
  2097. (IL_OFDM_BASIC_RATES_MASK >> IL_FIRST_OFDM_RATE) & 0xFF;
  2098. tx_beacon_cmd->tx.supp_rates[1] =
  2099. (IL_CCK_BASIC_RATES_MASK & 0xF);
  2100. return sizeof(struct il3945_tx_beacon_cmd) + frame_size;
  2101. }
  2102. void il3945_hw_rx_handler_setup(struct il_priv *il)
  2103. {
  2104. il->rx_handlers[REPLY_TX] = il3945_rx_reply_tx;
  2105. il->rx_handlers[REPLY_3945_RX] = il3945_rx_reply_rx;
  2106. }
  2107. void il3945_hw_setup_deferred_work(struct il_priv *il)
  2108. {
  2109. INIT_DELAYED_WORK(&il->_3945.thermal_periodic,
  2110. il3945_bg_reg_txpower_periodic);
  2111. }
  2112. void il3945_hw_cancel_deferred_work(struct il_priv *il)
  2113. {
  2114. cancel_delayed_work(&il->_3945.thermal_periodic);
  2115. }
  2116. /* check contents of special bootstrap uCode SRAM */
  2117. static int il3945_verify_bsm(struct il_priv *il)
  2118. {
  2119. __le32 *image = il->ucode_boot.v_addr;
  2120. u32 len = il->ucode_boot.len;
  2121. u32 reg;
  2122. u32 val;
  2123. D_INFO("Begin verify bsm\n");
  2124. /* verify BSM SRAM contents */
  2125. val = il_rd_prph(il, BSM_WR_DWCOUNT_REG);
  2126. for (reg = BSM_SRAM_LOWER_BOUND;
  2127. reg < BSM_SRAM_LOWER_BOUND + len;
  2128. reg += sizeof(u32), image++) {
  2129. val = il_rd_prph(il, reg);
  2130. if (val != le32_to_cpu(*image)) {
  2131. IL_ERR("BSM uCode verification failed at "
  2132. "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
  2133. BSM_SRAM_LOWER_BOUND,
  2134. reg - BSM_SRAM_LOWER_BOUND, len,
  2135. val, le32_to_cpu(*image));
  2136. return -EIO;
  2137. }
  2138. }
  2139. D_INFO("BSM bootstrap uCode image OK\n");
  2140. return 0;
  2141. }
  2142. /******************************************************************************
  2143. *
  2144. * EEPROM related functions
  2145. *
  2146. ******************************************************************************/
  2147. /*
  2148. * Clear the OWNER_MSK, to establish driver (instead of uCode running on
  2149. * embedded controller) as EEPROM reader; each read is a series of pulses
  2150. * to/from the EEPROM chip, not a single event, so even reads could conflict
  2151. * if they weren't arbitrated by some ownership mechanism. Here, the driver
  2152. * simply claims ownership, which should be safe when this function is called
  2153. * (i.e. before loading uCode!).
  2154. */
  2155. static int il3945_eeprom_acquire_semaphore(struct il_priv *il)
  2156. {
  2157. _il_clear_bit(il, CSR_EEPROM_GP, CSR_EEPROM_GP_IF_OWNER_MSK);
  2158. return 0;
  2159. }
  2160. static void il3945_eeprom_release_semaphore(struct il_priv *il)
  2161. {
  2162. return;
  2163. }
  2164. /**
  2165. * il3945_load_bsm - Load bootstrap instructions
  2166. *
  2167. * BSM operation:
  2168. *
  2169. * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
  2170. * in special SRAM that does not power down during RFKILL. When powering back
  2171. * up after power-saving sleeps (or during initial uCode load), the BSM loads
  2172. * the bootstrap program into the on-board processor, and starts it.
  2173. *
  2174. * The bootstrap program loads (via DMA) instructions and data for a new
  2175. * program from host DRAM locations indicated by the host driver in the
  2176. * BSM_DRAM_* registers. Once the new program is loaded, it starts
  2177. * automatically.
  2178. *
  2179. * When initializing the NIC, the host driver points the BSM to the
  2180. * "initialize" uCode image. This uCode sets up some internal data, then
  2181. * notifies host via "initialize alive" that it is complete.
  2182. *
  2183. * The host then replaces the BSM_DRAM_* pointer values to point to the
  2184. * normal runtime uCode instructions and a backup uCode data cache buffer
  2185. * (filled initially with starting data values for the on-board processor),
  2186. * then triggers the "initialize" uCode to load and launch the runtime uCode,
  2187. * which begins normal operation.
  2188. *
  2189. * When doing a power-save shutdown, runtime uCode saves data SRAM into
  2190. * the backup data cache in DRAM before SRAM is powered down.
  2191. *
  2192. * When powering back up, the BSM loads the bootstrap program. This reloads
  2193. * the runtime uCode instructions and the backup data cache into SRAM,
  2194. * and re-launches the runtime uCode from where it left off.
  2195. */
  2196. static int il3945_load_bsm(struct il_priv *il)
  2197. {
  2198. __le32 *image = il->ucode_boot.v_addr;
  2199. u32 len = il->ucode_boot.len;
  2200. dma_addr_t pinst;
  2201. dma_addr_t pdata;
  2202. u32 inst_len;
  2203. u32 data_len;
  2204. int rc;
  2205. int i;
  2206. u32 done;
  2207. u32 reg_offset;
  2208. D_INFO("Begin load bsm\n");
  2209. /* make sure bootstrap program is no larger than BSM's SRAM size */
  2210. if (len > IL39_MAX_BSM_SIZE)
  2211. return -EINVAL;
  2212. /* Tell bootstrap uCode where to find the "Initialize" uCode
  2213. * in host DRAM ... host DRAM physical address bits 31:0 for 3945.
  2214. * NOTE: il3945_initialize_alive_start() will replace these values,
  2215. * after the "initialize" uCode has run, to point to
  2216. * runtime/protocol instructions and backup data cache. */
  2217. pinst = il->ucode_init.p_addr;
  2218. pdata = il->ucode_init_data.p_addr;
  2219. inst_len = il->ucode_init.len;
  2220. data_len = il->ucode_init_data.len;
  2221. il_wr_prph(il, BSM_DRAM_INST_PTR_REG, pinst);
  2222. il_wr_prph(il, BSM_DRAM_DATA_PTR_REG, pdata);
  2223. il_wr_prph(il, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
  2224. il_wr_prph(il, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
  2225. /* Fill BSM memory with bootstrap instructions */
  2226. for (reg_offset = BSM_SRAM_LOWER_BOUND;
  2227. reg_offset < BSM_SRAM_LOWER_BOUND + len;
  2228. reg_offset += sizeof(u32), image++)
  2229. _il_wr_prph(il, reg_offset,
  2230. le32_to_cpu(*image));
  2231. rc = il3945_verify_bsm(il);
  2232. if (rc)
  2233. return rc;
  2234. /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
  2235. il_wr_prph(il, BSM_WR_MEM_SRC_REG, 0x0);
  2236. il_wr_prph(il, BSM_WR_MEM_DST_REG,
  2237. IL39_RTC_INST_LOWER_BOUND);
  2238. il_wr_prph(il, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
  2239. /* Load bootstrap code into instruction SRAM now,
  2240. * to prepare to load "initialize" uCode */
  2241. il_wr_prph(il, BSM_WR_CTRL_REG,
  2242. BSM_WR_CTRL_REG_BIT_START);
  2243. /* Wait for load of bootstrap uCode to finish */
  2244. for (i = 0; i < 100; i++) {
  2245. done = il_rd_prph(il, BSM_WR_CTRL_REG);
  2246. if (!(done & BSM_WR_CTRL_REG_BIT_START))
  2247. break;
  2248. udelay(10);
  2249. }
  2250. if (i < 100)
  2251. D_INFO("BSM write complete, poll %d iterations\n", i);
  2252. else {
  2253. IL_ERR("BSM write did not complete!\n");
  2254. return -EIO;
  2255. }
  2256. /* Enable future boot loads whenever power management unit triggers it
  2257. * (e.g. when powering back up after power-save shutdown) */
  2258. il_wr_prph(il, BSM_WR_CTRL_REG,
  2259. BSM_WR_CTRL_REG_BIT_START_EN);
  2260. return 0;
  2261. }
  2262. static struct il_hcmd_ops il3945_hcmd = {
  2263. .rxon_assoc = il3945_send_rxon_assoc,
  2264. .commit_rxon = il3945_commit_rxon,
  2265. };
  2266. static struct il_lib_ops il3945_lib = {
  2267. .txq_attach_buf_to_tfd = il3945_hw_txq_attach_buf_to_tfd,
  2268. .txq_free_tfd = il3945_hw_txq_free_tfd,
  2269. .txq_init = il3945_hw_tx_queue_init,
  2270. .load_ucode = il3945_load_bsm,
  2271. .dump_nic_error_log = il3945_dump_nic_error_log,
  2272. .apm_ops = {
  2273. .init = il3945_apm_init,
  2274. .config = il3945_nic_config,
  2275. },
  2276. .eeprom_ops = {
  2277. .regulatory_bands = {
  2278. EEPROM_REGULATORY_BAND_1_CHANNELS,
  2279. EEPROM_REGULATORY_BAND_2_CHANNELS,
  2280. EEPROM_REGULATORY_BAND_3_CHANNELS,
  2281. EEPROM_REGULATORY_BAND_4_CHANNELS,
  2282. EEPROM_REGULATORY_BAND_5_CHANNELS,
  2283. EEPROM_REGULATORY_BAND_NO_HT40,
  2284. EEPROM_REGULATORY_BAND_NO_HT40,
  2285. },
  2286. .acquire_semaphore = il3945_eeprom_acquire_semaphore,
  2287. .release_semaphore = il3945_eeprom_release_semaphore,
  2288. },
  2289. .send_tx_power = il3945_send_tx_power,
  2290. .is_valid_rtc_data_addr = il3945_hw_valid_rtc_data_addr,
  2291. .debugfs_ops = {
  2292. .rx_stats_read = il3945_ucode_rx_stats_read,
  2293. .tx_stats_read = il3945_ucode_tx_stats_read,
  2294. .general_stats_read = il3945_ucode_general_stats_read,
  2295. },
  2296. };
  2297. static const struct il_legacy_ops il3945_legacy_ops = {
  2298. .post_associate = il3945_post_associate,
  2299. .config_ap = il3945_config_ap,
  2300. .manage_ibss_station = il3945_manage_ibss_station,
  2301. };
  2302. static struct il_hcmd_utils_ops il3945_hcmd_utils = {
  2303. .get_hcmd_size = il3945_get_hcmd_size,
  2304. .build_addsta_hcmd = il3945_build_addsta_hcmd,
  2305. .request_scan = il3945_request_scan,
  2306. .post_scan = il3945_post_scan,
  2307. };
  2308. static const struct il_ops il3945_ops = {
  2309. .lib = &il3945_lib,
  2310. .hcmd = &il3945_hcmd,
  2311. .utils = &il3945_hcmd_utils,
  2312. .led = &il3945_led_ops,
  2313. .legacy = &il3945_legacy_ops,
  2314. .ieee80211_ops = &il3945_hw_ops,
  2315. };
  2316. static struct il_base_params il3945_base_params = {
  2317. .eeprom_size = IL3945_EEPROM_IMG_SIZE,
  2318. .num_of_queues = IL39_NUM_QUEUES,
  2319. .pll_cfg_val = CSR39_ANA_PLL_CFG_VAL,
  2320. .set_l0s = false,
  2321. .use_bsm = true,
  2322. .led_compensation = 64,
  2323. .wd_timeout = IL_DEF_WD_TIMEOUT,
  2324. };
  2325. static struct il_cfg il3945_bg_cfg = {
  2326. .name = "3945BG",
  2327. .fw_name_pre = IL3945_FW_PRE,
  2328. .ucode_api_max = IL3945_UCODE_API_MAX,
  2329. .ucode_api_min = IL3945_UCODE_API_MIN,
  2330. .sku = IL_SKU_G,
  2331. .eeprom_ver = EEPROM_3945_EEPROM_VERSION,
  2332. .ops = &il3945_ops,
  2333. .mod_params = &il3945_mod_params,
  2334. .base_params = &il3945_base_params,
  2335. .led_mode = IL_LED_BLINK,
  2336. };
  2337. static struct il_cfg il3945_abg_cfg = {
  2338. .name = "3945ABG",
  2339. .fw_name_pre = IL3945_FW_PRE,
  2340. .ucode_api_max = IL3945_UCODE_API_MAX,
  2341. .ucode_api_min = IL3945_UCODE_API_MIN,
  2342. .sku = IL_SKU_A|IL_SKU_G,
  2343. .eeprom_ver = EEPROM_3945_EEPROM_VERSION,
  2344. .ops = &il3945_ops,
  2345. .mod_params = &il3945_mod_params,
  2346. .base_params = &il3945_base_params,
  2347. .led_mode = IL_LED_BLINK,
  2348. };
  2349. DEFINE_PCI_DEVICE_TABLE(il3945_hw_card_ids) = {
  2350. {IL_PCI_DEVICE(0x4222, 0x1005, il3945_bg_cfg)},
  2351. {IL_PCI_DEVICE(0x4222, 0x1034, il3945_bg_cfg)},
  2352. {IL_PCI_DEVICE(0x4222, 0x1044, il3945_bg_cfg)},
  2353. {IL_PCI_DEVICE(0x4227, 0x1014, il3945_bg_cfg)},
  2354. {IL_PCI_DEVICE(0x4222, PCI_ANY_ID, il3945_abg_cfg)},
  2355. {IL_PCI_DEVICE(0x4227, PCI_ANY_ID, il3945_abg_cfg)},
  2356. {0}
  2357. };
  2358. MODULE_DEVICE_TABLE(pci, il3945_hw_card_ids);