iwl-3945.c 65 KB

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