iwl-3945.c 77 KB

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