iwl-3945.c 66 KB

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