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