iwl-3945.c 68 KB

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