blob: 795d206f10e86127ee7e74a28eee73b7b4faf39f [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08003 * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
Zhu Yib481de92007-09-25 17:54:57 -07004 *
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:
Winkler, Tomas759ef892008-12-09 11:28:58 -080022 * Intel Linux Wireless <ilw@linux.intel.com>
Zhu Yib481de92007-09-25 17:54:57 -070023 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 *****************************************************************************/
26
27#include <linux/kernel.h>
28#include <linux/module.h>
Zhu Yib481de92007-09-25 17:54:57 -070029#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/slab.h>
Zhu Yib481de92007-09-25 17:54:57 -070031#include <linux/pci.h>
32#include <linux/dma-mapping.h>
33#include <linux/delay.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040034#include <linux/sched.h>
Zhu Yib481de92007-09-25 17:54:57 -070035#include <linux/skbuff.h>
36#include <linux/netdevice.h>
Zhu Yib481de92007-09-25 17:54:57 -070037#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070038#include <linux/etherdevice.h>
Zhu Yi12342c42007-12-20 11:27:32 +080039#include <asm/unaligned.h>
40#include <net/mac80211.h>
Zhu Yib481de92007-09-25 17:54:57 -070041
Stanislaw Gruszkad4459a92011-08-31 10:59:02 +020042#include "commands.h"
Samuel Ortiz17f841c2009-01-23 13:45:20 -080043#include "iwl-sta.h"
Samuel Ortize6148912009-01-23 13:45:15 -080044#include "iwl-eeprom.h"
Stanislaw Gruszka98613be2011-11-15 14:19:34 +010045#include "common.h"
Reinette Chatre4a6547c2010-02-18 22:03:02 -080046#include "iwl-helpers.h"
Johannes Berge932a602009-10-02 13:44:03 -070047#include "iwl-led.h"
Stanislaw Gruszka6bbb1372011-08-30 14:12:12 +020048#include "3945.h"
Zhu Yib481de92007-09-25 17:54:57 -070049
Stanislaw Gruszkaecce1f02011-08-29 17:05:28 +020050/* Send led command */
51static int il3945_send_led_cmd(struct il_priv *il,
52 struct il_led_cmd *led_cmd)
53{
54 struct il_host_cmd cmd = {
Stanislaw Gruszka4d69c752011-08-30 15:26:35 +020055 .id = C_LEDS,
Stanislaw Gruszkaecce1f02011-08-29 17:05:28 +020056 .len = sizeof(struct il_led_cmd),
57 .data = led_cmd,
58 .flags = CMD_ASYNC,
59 .callback = NULL,
60 };
61
62 return il_send_cmd(il, &cmd);
63}
64
65const struct il_led_ops il3945_led_ops = {
66 .cmd = il3945_send_led_cmd,
67};
68
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +020069#define IL_DECLARE_RATE_INFO(r, ip, in, rp, rn, pp, np) \
Stanislaw Gruszka2d09b062011-08-26 16:10:40 +020070 [RATE_##r##M_IDX] = { RATE_##r##M_PLCP, \
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +020071 RATE_##r##M_IEEE, \
Stanislaw Gruszka2d09b062011-08-26 16:10:40 +020072 RATE_##ip##M_IDX, \
73 RATE_##in##M_IDX, \
74 RATE_##rp##M_IDX, \
75 RATE_##rn##M_IDX, \
76 RATE_##pp##M_IDX, \
77 RATE_##np##M_IDX, \
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +020078 RATE_##r##M_IDX_TBL, \
79 RATE_##ip##M_IDX_TBL }
Zhu Yib481de92007-09-25 17:54:57 -070080
81/*
82 * Parameter order:
83 * rate, prev rate, next rate, prev tgg rate, next tgg rate
84 *
85 * If there isn't a valid next or previous rate then INV is used which
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +020086 * maps to RATE_INVALID
Zhu Yib481de92007-09-25 17:54:57 -070087 *
88 */
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +020089const struct il3945_rate_info il3945_rates[RATE_COUNT_3945] = {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +020090 IL_DECLARE_RATE_INFO(1, INV, 2, INV, 2, INV, 2), /* 1mbps */
91 IL_DECLARE_RATE_INFO(2, 1, 5, 1, 5, 1, 5), /* 2mbps */
92 IL_DECLARE_RATE_INFO(5, 2, 6, 2, 11, 2, 11), /*5.5mbps */
93 IL_DECLARE_RATE_INFO(11, 9, 12, 5, 12, 5, 18), /* 11mbps */
94 IL_DECLARE_RATE_INFO(6, 5, 9, 5, 11, 5, 11), /* 6mbps */
95 IL_DECLARE_RATE_INFO(9, 6, 11, 5, 11, 5, 11), /* 9mbps */
96 IL_DECLARE_RATE_INFO(12, 11, 18, 11, 18, 11, 18), /* 12mbps */
97 IL_DECLARE_RATE_INFO(18, 12, 24, 12, 24, 11, 24), /* 18mbps */
98 IL_DECLARE_RATE_INFO(24, 18, 36, 18, 36, 18, 36), /* 24mbps */
99 IL_DECLARE_RATE_INFO(36, 24, 48, 24, 48, 24, 48), /* 36mbps */
100 IL_DECLARE_RATE_INFO(48, 36, 54, 36, 54, 36, 54), /* 48mbps */
101 IL_DECLARE_RATE_INFO(54, 48, INV, 48, INV, 48, INV),/* 54mbps */
Zhu Yib481de92007-09-25 17:54:57 -0700102};
103
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100104static inline u8 il3945_get_prev_ieee_rate(u8 rate_idx)
Johannes Berg635b85b2010-09-22 18:02:04 +0200105{
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100106 u8 rate = il3945_rates[rate_idx].prev_ieee;
Johannes Berg635b85b2010-09-22 18:02:04 +0200107
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200108 if (rate == RATE_INVALID)
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100109 rate = rate_idx;
Johannes Berg635b85b2010-09-22 18:02:04 +0200110 return rate;
111}
112
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200113/* 1 = enable the il3945_disable_events() function */
114#define IL_EVT_DISABLE (0)
115#define IL_EVT_DISABLE_SIZE (1532/32)
Zhu Yib481de92007-09-25 17:54:57 -0700116
117/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200118 * il3945_disable_events - Disable selected events in uCode event log
Zhu Yib481de92007-09-25 17:54:57 -0700119 *
120 * Disable an event by writing "1"s into "disable"
121 * bitmap in SRAM. Bit position corresponds to Event # (id/type).
122 * Default values of 0 enable uCode events to be logged.
123 * Use for only special debugging. This function is just a placeholder as-is,
124 * you'll need to provide the special bits! ...
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200125 * ... and set IL_EVT_DISABLE to 1. */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200126void il3945_disable_events(struct il_priv *il)
Zhu Yib481de92007-09-25 17:54:57 -0700127{
Zhu Yib481de92007-09-25 17:54:57 -0700128 int i;
129 u32 base; /* SRAM address of event log header */
130 u32 disable_ptr; /* SRAM address of event-disable bitmap array */
131 u32 array_size; /* # of u32 entries in array */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200132 static const u32 evt_disable[IL_EVT_DISABLE_SIZE] = {
Zhu Yib481de92007-09-25 17:54:57 -0700133 0x00000000, /* 31 - 0 Event id numbers */
134 0x00000000, /* 63 - 32 */
135 0x00000000, /* 95 - 64 */
136 0x00000000, /* 127 - 96 */
137 0x00000000, /* 159 - 128 */
138 0x00000000, /* 191 - 160 */
139 0x00000000, /* 223 - 192 */
140 0x00000000, /* 255 - 224 */
141 0x00000000, /* 287 - 256 */
142 0x00000000, /* 319 - 288 */
143 0x00000000, /* 351 - 320 */
144 0x00000000, /* 383 - 352 */
145 0x00000000, /* 415 - 384 */
146 0x00000000, /* 447 - 416 */
147 0x00000000, /* 479 - 448 */
148 0x00000000, /* 511 - 480 */
149 0x00000000, /* 543 - 512 */
150 0x00000000, /* 575 - 544 */
151 0x00000000, /* 607 - 576 */
152 0x00000000, /* 639 - 608 */
153 0x00000000, /* 671 - 640 */
154 0x00000000, /* 703 - 672 */
155 0x00000000, /* 735 - 704 */
156 0x00000000, /* 767 - 736 */
157 0x00000000, /* 799 - 768 */
158 0x00000000, /* 831 - 800 */
159 0x00000000, /* 863 - 832 */
160 0x00000000, /* 895 - 864 */
161 0x00000000, /* 927 - 896 */
162 0x00000000, /* 959 - 928 */
163 0x00000000, /* 991 - 960 */
164 0x00000000, /* 1023 - 992 */
165 0x00000000, /* 1055 - 1024 */
166 0x00000000, /* 1087 - 1056 */
167 0x00000000, /* 1119 - 1088 */
168 0x00000000, /* 1151 - 1120 */
169 0x00000000, /* 1183 - 1152 */
170 0x00000000, /* 1215 - 1184 */
171 0x00000000, /* 1247 - 1216 */
172 0x00000000, /* 1279 - 1248 */
173 0x00000000, /* 1311 - 1280 */
174 0x00000000, /* 1343 - 1312 */
175 0x00000000, /* 1375 - 1344 */
176 0x00000000, /* 1407 - 1376 */
177 0x00000000, /* 1439 - 1408 */
178 0x00000000, /* 1471 - 1440 */
179 0x00000000, /* 1503 - 1472 */
180 };
181
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200182 base = le32_to_cpu(il->card_alive.log_event_table_ptr);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200183 if (!il3945_hw_valid_rtc_data_addr(base)) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200184 IL_ERR("Invalid event log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -0700185 return;
186 }
187
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200188 disable_ptr = il_read_targ_mem(il, base + (4 * sizeof(u32)));
189 array_size = il_read_targ_mem(il, base + (5 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -0700190
Stanislaw Gruszka232913b2011-08-26 10:45:16 +0200191 if (IL_EVT_DISABLE && array_size == IL_EVT_DISABLE_SIZE) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100192 D_INFO("Disabling selected uCode log events at 0x%x\n",
Zhu Yib481de92007-09-25 17:54:57 -0700193 disable_ptr);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200194 for (i = 0; i < IL_EVT_DISABLE_SIZE; i++)
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200195 il_write_targ_mem(il,
Tomas Winkleraf7cca22007-10-25 17:15:36 +0800196 disable_ptr + (i * sizeof(u32)),
197 evt_disable[i]);
Zhu Yib481de92007-09-25 17:54:57 -0700198
Zhu Yib481de92007-09-25 17:54:57 -0700199 } else {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100200 D_INFO("Selected uCode log events may be disabled\n");
201 D_INFO(" by writing \"1\"s into disable bitmap\n");
202 D_INFO(" in SRAM at 0x%x, size %d u32s\n",
Zhu Yib481de92007-09-25 17:54:57 -0700203 disable_ptr, array_size);
204 }
205
206}
207
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200208static int il3945_hwrate_to_plcp_idx(u8 plcp)
Tomas Winkler17744ff2008-03-02 01:52:00 +0200209{
210 int idx;
211
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200212 for (idx = 0; idx < RATE_COUNT_3945; idx++)
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200213 if (il3945_rates[idx].plcp == plcp)
Tomas Winkler17744ff2008-03-02 01:52:00 +0200214 return idx;
215 return -1;
216}
217
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100218#ifdef CONFIG_IWLEGACY_DEBUG
Wey-Yi Guy04569cb2010-03-31 17:57:28 -0700219#define TX_STATUS_ENTRY(x) case TX_3945_STATUS_FAIL_ ## x: return #x
Tomas Winkler91c066f2008-03-06 17:36:55 -0800220
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200221static const char *il3945_get_tx_fail_reason(u32 status)
Tomas Winkler91c066f2008-03-06 17:36:55 -0800222{
223 switch (status & TX_STATUS_MSK) {
Wey-Yi Guy04569cb2010-03-31 17:57:28 -0700224 case TX_3945_STATUS_SUCCESS:
Tomas Winkler91c066f2008-03-06 17:36:55 -0800225 return "SUCCESS";
226 TX_STATUS_ENTRY(SHORT_LIMIT);
227 TX_STATUS_ENTRY(LONG_LIMIT);
228 TX_STATUS_ENTRY(FIFO_UNDERRUN);
229 TX_STATUS_ENTRY(MGMNT_ABORT);
230 TX_STATUS_ENTRY(NEXT_FRAG);
231 TX_STATUS_ENTRY(LIFE_EXPIRE);
232 TX_STATUS_ENTRY(DEST_PS);
233 TX_STATUS_ENTRY(ABORTED);
234 TX_STATUS_ENTRY(BT_RETRY);
235 TX_STATUS_ENTRY(STA_INVALID);
236 TX_STATUS_ENTRY(FRAG_DROPPED);
237 TX_STATUS_ENTRY(TID_DISABLE);
238 TX_STATUS_ENTRY(FRAME_FLUSHED);
239 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
240 TX_STATUS_ENTRY(TX_LOCKED);
241 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
242 }
243
244 return "UNKNOWN";
245}
246#else
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200247static inline const char *il3945_get_tx_fail_reason(u32 status)
Tomas Winkler91c066f2008-03-06 17:36:55 -0800248{
249 return "";
250}
251#endif
252
Johannes Berge6a98542008-10-21 12:40:02 +0200253/*
254 * get ieee prev rate from rate scale table.
255 * for A and B mode we need to overright prev
256 * value
257 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200258int il3945_rs_next_rate(struct il_priv *il, int rate)
Johannes Berge6a98542008-10-21 12:40:02 +0200259{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200260 int next_rate = il3945_get_prev_ieee_rate(rate);
Johannes Berge6a98542008-10-21 12:40:02 +0200261
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200262 switch (il->band) {
Johannes Berge6a98542008-10-21 12:40:02 +0200263 case IEEE80211_BAND_5GHZ:
Stanislaw Gruszka2d09b062011-08-26 16:10:40 +0200264 if (rate == RATE_12M_IDX)
265 next_rate = RATE_9M_IDX;
266 else if (rate == RATE_6M_IDX)
267 next_rate = RATE_6M_IDX;
Johannes Berge6a98542008-10-21 12:40:02 +0200268 break;
Abbas, Mohamed72627962008-12-05 07:58:37 -0800269 case IEEE80211_BAND_2GHZ:
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200270 if (!(il->_3945.sta_supp_rates & IL_OFDM_RATES_MASK) &&
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +0100271 il_is_associated(il)) {
Stanislaw Gruszka2d09b062011-08-26 16:10:40 +0200272 if (rate == RATE_11M_IDX)
273 next_rate = RATE_5M_IDX;
Abbas, Mohamed72627962008-12-05 07:58:37 -0800274 }
Johannes Berge6a98542008-10-21 12:40:02 +0200275 break;
Abbas, Mohamed72627962008-12-05 07:58:37 -0800276
Johannes Berge6a98542008-10-21 12:40:02 +0200277 default:
278 break;
279 }
280
281 return next_rate;
282}
283
Tomas Winkler91c066f2008-03-06 17:36:55 -0800284
285/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200286 * il3945_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
Tomas Winkler91c066f2008-03-06 17:36:55 -0800287 *
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100288 * When FW advances 'R' idx, all entries between old and new 'R' idx
Tomas Winkler91c066f2008-03-06 17:36:55 -0800289 * need to be reclaimed. As result, some free space forms. If there is
290 * enough free space (> low mark), wake the stack that feeds us.
291 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200292static void il3945_tx_queue_reclaim(struct il_priv *il,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100293 int txq_id, int idx)
Tomas Winkler91c066f2008-03-06 17:36:55 -0800294{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200295 struct il_tx_queue *txq = &il->txq[txq_id];
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200296 struct il_queue *q = &txq->q;
297 struct il_tx_info *tx_info;
Tomas Winkler91c066f2008-03-06 17:36:55 -0800298
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100299 BUG_ON(txq_id == IL39_CMD_QUEUE_NUM);
Tomas Winkler91c066f2008-03-06 17:36:55 -0800300
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100301 for (idx = il_queue_inc_wrap(idx, q->n_bd);
302 q->read_ptr != idx;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200303 q->read_ptr = il_queue_inc_wrap(q->read_ptr, q->n_bd)) {
Tomas Winkler91c066f2008-03-06 17:36:55 -0800304
305 tx_info = &txq->txb[txq->q.read_ptr];
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200306 ieee80211_tx_status_irqsafe(il->hw, tx_info->skb);
Johannes Bergff0d91c2010-05-17 02:37:34 -0700307 tx_info->skb = NULL;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200308 il->cfg->ops->lib->txq_free_tfd(il, txq);
Tomas Winkler91c066f2008-03-06 17:36:55 -0800309 }
310
Stanislaw Gruszka232913b2011-08-26 10:45:16 +0200311 if (il_queue_space(q) > q->low_mark && txq_id >= 0 &&
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100312 txq_id != IL39_CMD_QUEUE_NUM && il->mac80211_registered)
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200313 il_wake_queue(il, txq);
Tomas Winkler91c066f2008-03-06 17:36:55 -0800314}
315
316/**
Stanislaw Gruszka6e9848b42011-08-30 15:45:31 +0200317 * il3945_hdl_tx - Handle Tx response
Tomas Winkler91c066f2008-03-06 17:36:55 -0800318 */
Stanislaw Gruszka6e9848b42011-08-30 15:45:31 +0200319static void il3945_hdl_tx(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +0200320 struct il_rx_buf *rxb)
Tomas Winkler91c066f2008-03-06 17:36:55 -0800321{
Stanislaw Gruszkadcae1c62011-08-26 14:36:21 +0200322 struct il_rx_pkt *pkt = rxb_addr(rxb);
Tomas Winkler91c066f2008-03-06 17:36:55 -0800323 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
324 int txq_id = SEQ_TO_QUEUE(sequence);
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100325 int idx = SEQ_TO_IDX(sequence);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200326 struct il_tx_queue *txq = &il->txq[txq_id];
Johannes Berge039fa42008-05-15 12:55:29 +0200327 struct ieee80211_tx_info *info;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200328 struct il3945_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
Tomas Winkler91c066f2008-03-06 17:36:55 -0800329 u32 status = le32_to_cpu(tx_resp->status);
330 int rate_idx;
Abbas, Mohamed74221d02008-12-02 12:14:03 -0800331 int fail;
Tomas Winkler91c066f2008-03-06 17:36:55 -0800332
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100333 if (idx >= txq->q.n_bd || il_queue_used(&txq->q, idx) == 0) {
334 IL_ERR("Read idx for DMA queue txq_id (%d) idx %d "
Tomas Winkler91c066f2008-03-06 17:36:55 -0800335 "is out of range [0-%d] %d %d\n", txq_id,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100336 idx, txq->q.n_bd, txq->q.write_ptr,
Tomas Winkler91c066f2008-03-06 17:36:55 -0800337 txq->q.read_ptr);
338 return;
339 }
340
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +0100341 txq->time_stamp = jiffies;
Johannes Bergff0d91c2010-05-17 02:37:34 -0700342 info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb);
Johannes Berge6a98542008-10-21 12:40:02 +0200343 ieee80211_tx_info_clear_status(info);
Tomas Winkler91c066f2008-03-06 17:36:55 -0800344
Johannes Berge6a98542008-10-21 12:40:02 +0200345 /* Fill the MRR chain with some info about on-chip retransmissions */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200346 rate_idx = il3945_hwrate_to_plcp_idx(tx_resp->rate);
Johannes Berge6a98542008-10-21 12:40:02 +0200347 if (info->band == IEEE80211_BAND_5GHZ)
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200348 rate_idx -= IL_FIRST_OFDM_RATE;
Johannes Berge6a98542008-10-21 12:40:02 +0200349
350 fail = tx_resp->failure_frame;
Johannes Berge6a98542008-10-21 12:40:02 +0200351
Abbas, Mohamed74221d02008-12-02 12:14:03 -0800352 info->status.rates[0].idx = rate_idx;
353 info->status.rates[0].count = fail + 1; /* add final attempt */
Johannes Berge6a98542008-10-21 12:40:02 +0200354
Tomas Winkler91c066f2008-03-06 17:36:55 -0800355 /* tx_status->rts_retry_count = tx_resp->failure_rts; */
Johannes Berge039fa42008-05-15 12:55:29 +0200356 info->flags |= ((status & TX_STATUS_MSK) == TX_STATUS_SUCCESS) ?
357 IEEE80211_TX_STAT_ACK : 0;
Tomas Winkler91c066f2008-03-06 17:36:55 -0800358
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100359 D_TX("Tx queue %d Status %s (0x%08x) plcp rate %d retries %d\n",
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200360 txq_id, il3945_get_tx_fail_reason(status), status,
Tomas Winkler91c066f2008-03-06 17:36:55 -0800361 tx_resp->rate, tx_resp->failure_frame);
362
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100363 D_TX_REPLY("Tx queue reclaim %d\n", idx);
364 il3945_tx_queue_reclaim(il, txq_id, idx);
Tomas Winkler91c066f2008-03-06 17:36:55 -0800365
Johannes Berga313f382010-09-22 18:02:12 +0200366 if (status & TX_ABORT_REQUIRED_MSK)
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200367 IL_ERR("TODO: Implement Tx ABORT REQUIRED!!!\n");
Tomas Winkler91c066f2008-03-06 17:36:55 -0800368}
369
370
371
Zhu Yib481de92007-09-25 17:54:57 -0700372/*****************************************************************************
373 *
374 * Intel PRO/Wireless 3945ABG/BG Network Connection
375 *
376 * RX handler implementations
377 *
Zhu Yib481de92007-09-25 17:54:57 -0700378 *****************************************************************************/
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100379#ifdef CONFIG_IWLEGACY_DEBUGFS
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +0200380static void il3945_accumulative_stats(struct il_priv *il,
Abhijeet Kolekar17f36fc2010-04-16 10:03:54 -0700381 __le32 *stats)
382{
383 int i;
384 __le32 *prev_stats;
385 u32 *accum_stats;
386 u32 *delta, *max_delta;
387
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +0200388 prev_stats = (__le32 *)&il->_3945.stats;
389 accum_stats = (u32 *)&il->_3945.accum_stats;
390 delta = (u32 *)&il->_3945.delta_stats;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200391 max_delta = (u32 *)&il->_3945.max_delta;
Abhijeet Kolekar17f36fc2010-04-16 10:03:54 -0700392
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +0200393 for (i = sizeof(__le32); i < sizeof(struct il3945_notif_stats);
Abhijeet Kolekar17f36fc2010-04-16 10:03:54 -0700394 i += sizeof(__le32), stats++, prev_stats++, delta++,
395 max_delta++, accum_stats++) {
396 if (le32_to_cpu(*stats) > le32_to_cpu(*prev_stats)) {
397 *delta = (le32_to_cpu(*stats) -
398 le32_to_cpu(*prev_stats));
399 *accum_stats += *delta;
400 if (*delta > *max_delta)
401 *max_delta = *delta;
402 }
403 }
404
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +0200405 /* reset accumulative stats for "no-counter" type stats */
406 il->_3945.accum_stats.general.temperature =
407 il->_3945.stats.general.temperature;
408 il->_3945.accum_stats.general.ttl_timestamp =
409 il->_3945.stats.general.ttl_timestamp;
Abhijeet Kolekar17f36fc2010-04-16 10:03:54 -0700410}
411#endif
Zhu Yib481de92007-09-25 17:54:57 -0700412
Stanislaw Gruszkad2dfb332011-11-15 13:16:38 +0100413void il3945_hdl_stats(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +0200414 struct il_rx_buf *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700415{
Stanislaw Gruszkadcae1c62011-08-26 14:36:21 +0200416 struct il_rx_pkt *pkt = rxb_addr(rxb);
Abhijeet Kolekar17f36fc2010-04-16 10:03:54 -0700417
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100418 D_RX("Statistics notification received (%d vs %d).\n",
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +0200419 (int)sizeof(struct il3945_notif_stats),
Daniel C Halperin396887a2009-08-13 13:31:01 -0700420 le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK);
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100421#ifdef CONFIG_IWLEGACY_DEBUGFS
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +0200422 il3945_accumulative_stats(il, (__le32 *)&pkt->u.raw);
Abhijeet Kolekar17f36fc2010-04-16 10:03:54 -0700423#endif
Zhu Yib481de92007-09-25 17:54:57 -0700424
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +0200425 memcpy(&il->_3945.stats, pkt->u.raw, sizeof(il->_3945.stats));
Zhu Yib481de92007-09-25 17:54:57 -0700426}
427
Stanislaw Gruszkad2dfb332011-11-15 13:16:38 +0100428void il3945_hdl_c_stats(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +0200429 struct il_rx_buf *rxb)
Abhijeet Kolekar17f36fc2010-04-16 10:03:54 -0700430{
Stanislaw Gruszkadcae1c62011-08-26 14:36:21 +0200431 struct il_rx_pkt *pkt = rxb_addr(rxb);
Abhijeet Kolekar17f36fc2010-04-16 10:03:54 -0700432 __le32 *flag = (__le32 *)&pkt->u.raw;
433
Stanislaw Gruszkadb7746f2011-11-15 13:11:50 +0100434 if (le32_to_cpu(*flag) & UCODE_STATS_CLEAR_MSK) {
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100435#ifdef CONFIG_IWLEGACY_DEBUGFS
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +0200436 memset(&il->_3945.accum_stats, 0,
437 sizeof(struct il3945_notif_stats));
438 memset(&il->_3945.delta_stats, 0,
439 sizeof(struct il3945_notif_stats));
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200440 memset(&il->_3945.max_delta, 0,
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +0200441 sizeof(struct il3945_notif_stats));
Abhijeet Kolekar17f36fc2010-04-16 10:03:54 -0700442#endif
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100443 D_RX("Statistics have been cleared\n");
Abhijeet Kolekar17f36fc2010-04-16 10:03:54 -0700444 }
Stanislaw Gruszkad2dfb332011-11-15 13:16:38 +0100445 il3945_hdl_stats(il, rxb);
Abhijeet Kolekar17f36fc2010-04-16 10:03:54 -0700446}
447
448
Tomas Winkler17744ff2008-03-02 01:52:00 +0200449/******************************************************************************
450 *
451 * Misc. internal state and helper functions
452 *
453 ******************************************************************************/
Tomas Winkler17744ff2008-03-02 01:52:00 +0200454
Stanislaw Gruszkaebf0d902011-08-26 15:43:47 +0200455/* This is necessary only for a number of stats, see the caller. */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200456static int il3945_is_network_packet(struct il_priv *il,
Adel Gadllah4bd9b4f2008-07-11 11:53:29 +0800457 struct ieee80211_hdr *header)
458{
459 /* Filter incoming packets to determine if they are targeted toward
460 * this network, discarding packets coming from ourselves */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200461 switch (il->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200462 case NL80211_IFTYPE_ADHOC: /* Header: Dest. | Source | BSSID */
Adel Gadllah4bd9b4f2008-07-11 11:53:29 +0800463 /* packets to our IBSS update information */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200464 return !compare_ether_addr(header->addr3, il->bssid);
Johannes Berg05c914f2008-09-11 00:01:58 +0200465 case NL80211_IFTYPE_STATION: /* Header: Dest. | AP{BSSID} | Source */
Adel Gadllah4bd9b4f2008-07-11 11:53:29 +0800466 /* packets to our IBSS update information */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200467 return !compare_ether_addr(header->addr2, il->bssid);
Adel Gadllah4bd9b4f2008-07-11 11:53:29 +0800468 default:
469 return 1;
470 }
471}
Tomas Winkler17744ff2008-03-02 01:52:00 +0200472
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200473static void il3945_pass_packet_to_mac80211(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +0200474 struct il_rx_buf *rxb,
Zhu Yi12342c42007-12-20 11:27:32 +0800475 struct ieee80211_rx_status *stats)
Zhu Yib481de92007-09-25 17:54:57 -0700476{
Stanislaw Gruszkadcae1c62011-08-26 14:36:21 +0200477 struct il_rx_pkt *pkt = rxb_addr(rxb);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200478 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)IL_RX_DATA(pkt);
479 struct il3945_rx_frame_hdr *rx_hdr = IL_RX_HDR(pkt);
480 struct il3945_rx_frame_end *rx_end = IL_RX_END(pkt);
Zhu Yi2f301222009-10-09 17:19:45 +0800481 u16 len = le16_to_cpu(rx_hdr->len);
482 struct sk_buff *skb;
Zhu Yi29b1b262009-10-23 13:42:25 -0700483 __le16 fc = hdr->frame_control;
Zhu Yib481de92007-09-25 17:54:57 -0700484
485 /* We received data from the HW, so stop the watchdog */
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100486 if (unlikely(len + IL39_RX_FRAME_SIZE >
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200487 PAGE_SIZE << il->hw_params.rx_page_order)) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100488 D_DROP("Corruption detected!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700489 return;
490 }
491
492 /* We only process data packets if the interface is open */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200493 if (unlikely(!il->is_open)) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100494 D_DROP(
Tomas Winklere1623442009-01-27 14:27:56 -0800495 "Dropping packet while interface is not open.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700496 return;
497 }
Zhu Yib481de92007-09-25 17:54:57 -0700498
Zhu Yiecdf94b2010-03-29 16:42:26 +0800499 skb = dev_alloc_skb(128);
Zhu Yi2f301222009-10-09 17:19:45 +0800500 if (!skb) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200501 IL_ERR("dev_alloc_skb failed\n");
Zhu Yi2f301222009-10-09 17:19:45 +0800502 return;
503 }
Zhu Yib481de92007-09-25 17:54:57 -0700504
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200505 if (!il3945_mod_params.sw_crypto)
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200506 il_set_decrypted_flag(il,
Zhu Yi2f301222009-10-09 17:19:45 +0800507 (struct ieee80211_hdr *)rxb_addr(rxb),
Zhu Yib481de92007-09-25 17:54:57 -0700508 le32_to_cpu(rx_end->status), stats);
509
Zhu Yi2f301222009-10-09 17:19:45 +0800510 skb_add_rx_frag(skb, 0, rxb->page,
511 (void *)rx_hdr->payload - (void *)pkt, len);
512
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200513 il_update_stats(il, false, fc, len);
Zhu Yi2f301222009-10-09 17:19:45 +0800514 memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats));
Zhu Yi2f301222009-10-09 17:19:45 +0800515
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200516 ieee80211_rx(il->hw, skb);
517 il->alloc_rxb_page--;
Zhu Yi2f301222009-10-09 17:19:45 +0800518 rxb->page = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700519}
520
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200521#define IL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
Mohamed Abbas7878a5a2007-11-29 11:10:13 +0800522
Stanislaw Gruszka6e9848b42011-08-30 15:45:31 +0200523static void il3945_hdl_rx(struct il_priv *il,
Stanislaw Gruszkab73bb5f2011-08-26 14:37:54 +0200524 struct il_rx_buf *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700525{
Tomas Winkler17744ff2008-03-02 01:52:00 +0200526 struct ieee80211_hdr *header;
527 struct ieee80211_rx_status rx_status;
Stanislaw Gruszkadcae1c62011-08-26 14:36:21 +0200528 struct il_rx_pkt *pkt = rxb_addr(rxb);
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200529 struct il3945_rx_frame_stats *rx_stats = IL_RX_STATS(pkt);
530 struct il3945_rx_frame_hdr *rx_hdr = IL_RX_HDR(pkt);
531 struct il3945_rx_frame_end *rx_end = IL_RX_END(pkt);
Reinette Chatref875f512010-04-05 10:43:10 -0700532 u16 rx_stats_sig_avg __maybe_unused = le16_to_cpu(rx_stats->sig_avg);
533 u16 rx_stats_noise_diff __maybe_unused = le16_to_cpu(rx_stats->noise_diff);
Zhu Yib481de92007-09-25 17:54:57 -0700534 u8 network_packet;
Tomas Winkler17744ff2008-03-02 01:52:00 +0200535
Tomas Winkler17744ff2008-03-02 01:52:00 +0200536 rx_status.flag = 0;
537 rx_status.mactime = le64_to_cpu(rx_end->timestamp);
Tomas Winkler17744ff2008-03-02 01:52:00 +0200538 rx_status.band = (rx_hdr->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
539 IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900540 rx_status.freq =
541 ieee80211_channel_to_frequency(le16_to_cpu(rx_hdr->channel),
542 rx_status.band);
Tomas Winkler17744ff2008-03-02 01:52:00 +0200543
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200544 rx_status.rate_idx = il3945_hwrate_to_plcp_idx(rx_hdr->rate);
Tomas Winkler17744ff2008-03-02 01:52:00 +0200545 if (rx_status.band == IEEE80211_BAND_5GHZ)
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200546 rx_status.rate_idx -= IL_FIRST_OFDM_RATE;
Zhu Yib481de92007-09-25 17:54:57 -0700547
Reinette Chatre9024adf2009-10-02 13:43:57 -0700548 rx_status.antenna = (le16_to_cpu(rx_hdr->phy_flags) &
Bruno Randolf6f0a2c42008-07-30 17:20:14 +0200549 RX_RES_PHY_FLAGS_ANTENNA_MSK) >> 4;
550
551 /* set the preamble flag if appropriate */
552 if (rx_hdr->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
553 rx_status.flag |= RX_FLAG_SHORTPRE;
554
Zhu Yib481de92007-09-25 17:54:57 -0700555 if ((unlikely(rx_stats->phy_count > 20))) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100556 D_DROP("dsp size out of range [0,20]: %d/n",
Tomas Winklere1623442009-01-27 14:27:56 -0800557 rx_stats->phy_count);
Zhu Yib481de92007-09-25 17:54:57 -0700558 return;
559 }
560
Stanislaw Gruszka232913b2011-08-26 10:45:16 +0200561 if (!(rx_end->status & RX_RES_STATUS_NO_CRC32_ERROR) ||
562 !(rx_end->status & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100563 D_RX("Bad CRC or FIFO: 0x%08X.\n", rx_end->status);
Zhu Yib481de92007-09-25 17:54:57 -0700564 return;
565 }
566
Maxim Levitsky56decd32008-08-01 12:54:27 +0300567
Zhu Yib481de92007-09-25 17:54:57 -0700568
569 /* Convert 3945's rssi indicator to dBm */
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100570 rx_status.signal = rx_stats->rssi - IL39_RSSI_OFFSET;
Zhu Yib481de92007-09-25 17:54:57 -0700571
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100572 D_STATS("Rssi %d sig_avg %d noise_diff %d\n",
Johannes Berged1b6e92010-03-18 09:58:27 -0700573 rx_status.signal, rx_stats_sig_avg,
574 rx_stats_noise_diff);
Zhu Yib481de92007-09-25 17:54:57 -0700575
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200576 header = (struct ieee80211_hdr *)IL_RX_DATA(pkt);
Zhu Yib481de92007-09-25 17:54:57 -0700577
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200578 network_packet = il3945_is_network_packet(il, header);
Zhu Yib481de92007-09-25 17:54:57 -0700579
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100580 D_STATS("[%c] %d RSSI:%d Signal:%u, Rate:%u\n",
Tomas Winkler17744ff2008-03-02 01:52:00 +0200581 network_packet ? '*' : ' ',
582 le16_to_cpu(rx_hdr->channel),
Bruno Randolf566bfe52008-05-08 19:15:40 +0200583 rx_status.signal, rx_status.signal,
Johannes Berged1b6e92010-03-18 09:58:27 -0700584 rx_status.rate_idx);
Zhu Yib481de92007-09-25 17:54:57 -0700585
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200586 il_dbg_log_rx_data_frame(il, le16_to_cpu(rx_hdr->len),
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800587 header);
Zhu Yib481de92007-09-25 17:54:57 -0700588
589 if (network_packet) {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200590 il->_3945.last_beacon_time =
Johannes Berge99f1682010-01-19 10:04:28 -0800591 le32_to_cpu(rx_end->beacon_timestamp);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200592 il->_3945.last_tsf = le64_to_cpu(rx_end->timestamp);
593 il->_3945.last_rx_rssi = rx_status.signal;
Zhu Yib481de92007-09-25 17:54:57 -0700594 }
595
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200596 il3945_pass_packet_to_mac80211(il, rxb, &rx_status);
Zhu Yib481de92007-09-25 17:54:57 -0700597}
598
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200599int il3945_hw_txq_attach_buf_to_tfd(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200600 struct il_tx_queue *txq,
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800601 dma_addr_t addr, u16 len, u8 reset, u8 pad)
Zhu Yib481de92007-09-25 17:54:57 -0700602{
603 int count;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200604 struct il_queue *q;
605 struct il3945_tfd *tfd, *tfd_tmp;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800606
607 q = &txq->q;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200608 tfd_tmp = (struct il3945_tfd *)txq->tfds;
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800609 tfd = &tfd_tmp[q->write_ptr];
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800610
611 if (reset)
612 memset(tfd, 0, sizeof(*tfd));
Zhu Yib481de92007-09-25 17:54:57 -0700613
614 count = TFD_CTL_COUNT_GET(le32_to_cpu(tfd->control_flags));
Zhu Yib481de92007-09-25 17:54:57 -0700615
Stanislaw Gruszka232913b2011-08-26 10:45:16 +0200616 if (count >= NUM_TFD_CHUNKS || count < 0) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200617 IL_ERR("Error can not send more than %d chunks\n",
Zhu Yib481de92007-09-25 17:54:57 -0700618 NUM_TFD_CHUNKS);
619 return -EINVAL;
620 }
621
Winkler, Tomasdbb66542008-12-22 11:31:14 +0800622 tfd->tbs[count].addr = cpu_to_le32(addr);
623 tfd->tbs[count].len = cpu_to_le32(len);
Zhu Yib481de92007-09-25 17:54:57 -0700624
625 count++;
626
627 tfd->control_flags = cpu_to_le32(TFD_CTL_COUNT_SET(count) |
628 TFD_CTL_PAD_SET(pad));
629
630 return 0;
631}
632
633/**
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100634 * il3945_hw_txq_free_tfd - Free one TFD, those at idx [txq->q.read_ptr]
Zhu Yib481de92007-09-25 17:54:57 -0700635 *
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100636 * Does NOT advance any idxes
Zhu Yib481de92007-09-25 17:54:57 -0700637 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200638void il3945_hw_txq_free_tfd(struct il_priv *il, struct il_tx_queue *txq)
Zhu Yib481de92007-09-25 17:54:57 -0700639{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200640 struct il3945_tfd *tfd_tmp = (struct il3945_tfd *)txq->tfds;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100641 int idx = txq->q.read_ptr;
642 struct il3945_tfd *tfd = &tfd_tmp[idx];
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200643 struct pci_dev *dev = il->pci_dev;
Zhu Yib481de92007-09-25 17:54:57 -0700644 int i;
645 int counter;
646
Zhu Yib481de92007-09-25 17:54:57 -0700647 /* sanity check */
Winkler, Tomasdbb66542008-12-22 11:31:14 +0800648 counter = TFD_CTL_COUNT_GET(le32_to_cpu(tfd->control_flags));
Zhu Yib481de92007-09-25 17:54:57 -0700649 if (counter > NUM_TFD_CHUNKS) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200650 IL_ERR("Too many chunks: %i\n", counter);
Zhu Yib481de92007-09-25 17:54:57 -0700651 /* @todo issue fatal error, it is quite serious situation */
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800652 return;
Zhu Yib481de92007-09-25 17:54:57 -0700653 }
654
Reinette Chatrefd9377e2009-03-11 11:17:58 -0700655 /* Unmap tx_cmd */
656 if (counter)
657 pci_unmap_single(dev,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100658 dma_unmap_addr(&txq->meta[idx], mapping),
659 dma_unmap_len(&txq->meta[idx], len),
Reinette Chatrefd9377e2009-03-11 11:17:58 -0700660 PCI_DMA_TODEVICE);
661
Zhu Yib481de92007-09-25 17:54:57 -0700662 /* unmap chunks if any */
663
Johannes Bergff0d91c2010-05-17 02:37:34 -0700664 for (i = 1; i < counter; i++)
Winkler, Tomasdbb66542008-12-22 11:31:14 +0800665 pci_unmap_single(dev, le32_to_cpu(tfd->tbs[i].addr),
666 le32_to_cpu(tfd->tbs[i].len), PCI_DMA_TODEVICE);
Johannes Berg4f5fa232010-05-17 02:37:31 -0700667
Johannes Bergff0d91c2010-05-17 02:37:34 -0700668 /* free SKB */
669 if (txq->txb) {
670 struct sk_buff *skb;
Johannes Berg4f5fa232010-05-17 02:37:31 -0700671
Johannes Bergff0d91c2010-05-17 02:37:34 -0700672 skb = txq->txb[txq->q.read_ptr].skb;
673
674 /* can be called from irqs-disabled context */
675 if (skb) {
676 dev_kfree_skb_any(skb);
677 txq->txb[txq->q.read_ptr].skb = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700678 }
679 }
Zhu Yib481de92007-09-25 17:54:57 -0700680}
681
Zhu Yib481de92007-09-25 17:54:57 -0700682/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200683 * il3945_hw_build_tx_cmd_rate - Add rate portion to TX_CMD:
Zhu Yib481de92007-09-25 17:54:57 -0700684 *
685*/
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200686void il3945_hw_build_tx_cmd_rate(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200687 struct il_device_cmd *cmd,
Johannes Bergc2acea82009-07-24 11:13:05 -0700688 struct ieee80211_tx_info *info,
689 struct ieee80211_hdr *hdr,
690 int sta_id, int tx_id)
Zhu Yib481de92007-09-25 17:54:57 -0700691{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200692 u16 hw_value = ieee80211_get_tx_rate(il->hw, info)->hw_value;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100693 u16 rate_idx = min(hw_value & 0xffff, RATE_COUNT_3945);
Zhu Yib481de92007-09-25 17:54:57 -0700694 u16 rate_mask;
695 int rate;
696 u8 rts_retry_limit;
697 u8 data_retry_limit;
698 __le32 tx_flags;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700699 __le16 fc = hdr->frame_control;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200700 struct il3945_tx_cmd *tx_cmd = (struct il3945_tx_cmd *)cmd->cmd.payload;
Zhu Yib481de92007-09-25 17:54:57 -0700701
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +0100702 rate = il3945_rates[rate_idx].plcp;
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700703 tx_flags = tx_cmd->tx_flags;
Zhu Yib481de92007-09-25 17:54:57 -0700704
705 /* We need to figure out how to get the sta->supp_rates while
Johannes Berge039fa42008-05-15 12:55:29 +0200706 * in this running context */
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +0200707 rate_mask = RATES_MASK_3945;
Abhijeet Kolekar768db982009-10-09 13:20:33 -0700708
709 /* Set retry limit on DATA packets and Probe Responses*/
710 if (ieee80211_is_probe_resp(fc))
711 data_retry_limit = 3;
712 else
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200713 data_retry_limit = IL_DEFAULT_TX_RETRY;
Abhijeet Kolekar768db982009-10-09 13:20:33 -0700714 tx_cmd->data_retry_limit = data_retry_limit;
715
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100716 if (tx_id >= IL39_CMD_QUEUE_NUM)
Zhu Yib481de92007-09-25 17:54:57 -0700717 rts_retry_limit = 3;
718 else
719 rts_retry_limit = 7;
720
Abhijeet Kolekar768db982009-10-09 13:20:33 -0700721 if (data_retry_limit < rts_retry_limit)
722 rts_retry_limit = data_retry_limit;
723 tx_cmd->rts_retry_limit = rts_retry_limit;
Zhu Yib481de92007-09-25 17:54:57 -0700724
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700725 tx_cmd->rate = rate;
726 tx_cmd->tx_flags = tx_flags;
Zhu Yib481de92007-09-25 17:54:57 -0700727
728 /* OFDM */
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700729 tx_cmd->supp_rates[0] =
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200730 ((rate_mask & IL_OFDM_RATES_MASK) >> IL_FIRST_OFDM_RATE) & 0xFF;
Zhu Yib481de92007-09-25 17:54:57 -0700731
732 /* CCK */
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700733 tx_cmd->supp_rates[1] = (rate_mask & 0xF);
Zhu Yib481de92007-09-25 17:54:57 -0700734
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100735 D_RATE("Tx sta id: %d, rate: %d (plcp), flags: 0x%4X "
Zhu Yib481de92007-09-25 17:54:57 -0700736 "cck/ofdm mask: 0x%x/0x%x\n", sta_id,
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700737 tx_cmd->rate, le32_to_cpu(tx_cmd->tx_flags),
738 tx_cmd->supp_rates[1], tx_cmd->supp_rates[0]);
Zhu Yib481de92007-09-25 17:54:57 -0700739}
740
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200741static u8 il3945_sync_sta(struct il_priv *il, int sta_id, u16 tx_rate)
Zhu Yib481de92007-09-25 17:54:57 -0700742{
743 unsigned long flags_spin;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200744 struct il_station_entry *station;
Zhu Yib481de92007-09-25 17:54:57 -0700745
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200746 if (sta_id == IL_INVALID_STATION)
747 return IL_INVALID_STATION;
Zhu Yib481de92007-09-25 17:54:57 -0700748
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200749 spin_lock_irqsave(&il->sta_lock, flags_spin);
750 station = &il->stations[sta_id];
Zhu Yib481de92007-09-25 17:54:57 -0700751
752 station->sta.sta.modify_mask = STA_MODIFY_TX_RATE_MSK;
753 station->sta.rate_n_flags = cpu_to_le16(tx_rate);
Zhu Yib481de92007-09-25 17:54:57 -0700754 station->sta.mode = STA_CONTROL_MODIFY_MSK;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200755 il_send_add_sta(il, &station->sta, CMD_ASYNC);
756 spin_unlock_irqrestore(&il->sta_lock, flags_spin);
Zhu Yib481de92007-09-25 17:54:57 -0700757
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100758 D_RATE("SCALE sync station %d to rate %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700759 sta_id, tx_rate);
760 return sta_id;
761}
762
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200763static void il3945_set_pwr_vmain(struct il_priv *il)
Zhu Yib481de92007-09-25 17:54:57 -0700764{
Johannes Berg9597eba2010-09-22 18:02:09 +0200765/*
766 * (for documentation purposes)
767 * to set power to V_AUX, do
768
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200769 if (pci_pme_capable(il->pci_dev, PCI_D3cold)) {
770 il_set_bits_mask_prph(il, APMG_PS_CTRL_REG,
Zhu Yib481de92007-09-25 17:54:57 -0700771 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
772 ~APMG_PS_CTRL_MSK_PWR_SRC);
Zhu Yib481de92007-09-25 17:54:57 -0700773
Stanislaw Gruszka142b3432011-08-24 15:22:57 +0200774 _il_poll_bit(il, CSR_GPIO_IN,
Zhu Yib481de92007-09-25 17:54:57 -0700775 CSR_GPIO_IN_VAL_VAUX_PWR_SRC,
776 CSR_GPIO_IN_BIT_AUX_POWER, 5000);
Tomas Winkler3fdb68d2009-02-10 15:19:02 -0800777 }
Johannes Berg9597eba2010-09-22 18:02:09 +0200778 */
Zhu Yib481de92007-09-25 17:54:57 -0700779
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200780 il_set_bits_mask_prph(il, APMG_PS_CTRL_REG,
Johannes Berg9597eba2010-09-22 18:02:09 +0200781 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
782 ~APMG_PS_CTRL_MSK_PWR_SRC);
Zhu Yib481de92007-09-25 17:54:57 -0700783
Stanislaw Gruszka142b3432011-08-24 15:22:57 +0200784 _il_poll_bit(il, CSR_GPIO_IN, CSR_GPIO_IN_VAL_VMAIN_PWR_SRC,
Johannes Berg9597eba2010-09-22 18:02:09 +0200785 CSR_GPIO_IN_BIT_AUX_POWER, 5000); /* uS */
Zhu Yib481de92007-09-25 17:54:57 -0700786}
787
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200788static int il3945_rx_init(struct il_priv *il, struct il_rx_queue *rxq)
Zhu Yib481de92007-09-25 17:54:57 -0700789{
Stanislaw Gruszka0c1a94e2011-08-24 17:37:16 +0200790 il_wr(il, FH39_RCSR_RBD_BASE(0), rxq->bd_dma);
791 il_wr(il, FH39_RCSR_RPTR_ADDR(0),
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800792 rxq->rb_stts_dma);
Stanislaw Gruszka0c1a94e2011-08-24 17:37:16 +0200793 il_wr(il, FH39_RCSR_WPTR(0), 0);
794 il_wr(il, FH39_RCSR_CONFIG(0),
Tomas Winklerbddadf82008-12-19 10:37:01 +0800795 FH39_RCSR_RX_CONFIG_REG_VAL_DMA_CHNL_EN_ENABLE |
796 FH39_RCSR_RX_CONFIG_REG_VAL_RDRBD_EN_ENABLE |
797 FH39_RCSR_RX_CONFIG_REG_BIT_WR_STTS_EN |
798 FH39_RCSR_RX_CONFIG_REG_VAL_MAX_FRAG_SIZE_128 |
799 (RX_QUEUE_SIZE_LOG << FH39_RCSR_RX_CONFIG_REG_POS_RBDC_SIZE) |
800 FH39_RCSR_RX_CONFIG_REG_VAL_IRQ_DEST_INT_HOST |
801 (1 << FH39_RCSR_RX_CONFIG_REG_POS_IRQ_RBTH) |
802 FH39_RCSR_RX_CONFIG_REG_VAL_MSG_MODE_FH);
Zhu Yib481de92007-09-25 17:54:57 -0700803
804 /* fake read to flush all prev I/O */
Stanislaw Gruszka0c1a94e2011-08-24 17:37:16 +0200805 il_rd(il, FH39_RSSR_CTRL);
Zhu Yib481de92007-09-25 17:54:57 -0700806
Zhu Yib481de92007-09-25 17:54:57 -0700807 return 0;
808}
809
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200810static int il3945_tx_reset(struct il_priv *il)
Zhu Yib481de92007-09-25 17:54:57 -0700811{
Zhu Yib481de92007-09-25 17:54:57 -0700812
813 /* bypass mode */
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +0200814 il_wr_prph(il, ALM_SCD_MODE_REG, 0x2);
Zhu Yib481de92007-09-25 17:54:57 -0700815
816 /* RA 0 is active */
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +0200817 il_wr_prph(il, ALM_SCD_ARASTAT_REG, 0x01);
Zhu Yib481de92007-09-25 17:54:57 -0700818
819 /* all 6 fifo are active */
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +0200820 il_wr_prph(il, ALM_SCD_TXFACT_REG, 0x3f);
Zhu Yib481de92007-09-25 17:54:57 -0700821
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +0200822 il_wr_prph(il, ALM_SCD_SBYP_MODE_1_REG, 0x010000);
823 il_wr_prph(il, ALM_SCD_SBYP_MODE_2_REG, 0x030002);
824 il_wr_prph(il, ALM_SCD_TXF4MF_REG, 0x000004);
825 il_wr_prph(il, ALM_SCD_TXF5MF_REG, 0x000005);
Zhu Yib481de92007-09-25 17:54:57 -0700826
Stanislaw Gruszka0c1a94e2011-08-24 17:37:16 +0200827 il_wr(il, FH39_TSSR_CBB_BASE,
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200828 il->_3945.shared_phys);
Zhu Yib481de92007-09-25 17:54:57 -0700829
Stanislaw Gruszka0c1a94e2011-08-24 17:37:16 +0200830 il_wr(il, FH39_TSSR_MSG_CONFIG,
Tomas Winklerbddadf82008-12-19 10:37:01 +0800831 FH39_TSSR_TX_MSG_CONFIG_REG_VAL_SNOOP_RD_TXPD_ON |
832 FH39_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RD_TXPD_ON |
833 FH39_TSSR_TX_MSG_CONFIG_REG_VAL_MAX_FRAG_SIZE_128B |
834 FH39_TSSR_TX_MSG_CONFIG_REG_VAL_SNOOP_RD_TFD_ON |
835 FH39_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RD_CBB_ON |
836 FH39_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RSP_WAIT_TH |
837 FH39_TSSR_TX_MSG_CONFIG_REG_VAL_RSP_WAIT_TH);
Zhu Yib481de92007-09-25 17:54:57 -0700838
Zhu Yib481de92007-09-25 17:54:57 -0700839
840 return 0;
841}
842
843/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200844 * il3945_txq_ctx_reset - Reset TX queue context
Zhu Yib481de92007-09-25 17:54:57 -0700845 *
846 * Destroys all DMA structures and initialize them again
847 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200848static int il3945_txq_ctx_reset(struct il_priv *il)
Zhu Yib481de92007-09-25 17:54:57 -0700849{
850 int rc;
851 int txq_id, slots_num;
852
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200853 il3945_hw_txq_ctx_free(il);
Zhu Yib481de92007-09-25 17:54:57 -0700854
Wey-Yi Guy88804e22009-10-09 13:20:28 -0700855 /* allocate tx queue structure */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200856 rc = il_alloc_txq_mem(il);
Wey-Yi Guy88804e22009-10-09 13:20:28 -0700857 if (rc)
858 return rc;
859
Zhu Yib481de92007-09-25 17:54:57 -0700860 /* Tx CMD queue */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200861 rc = il3945_tx_reset(il);
Zhu Yib481de92007-09-25 17:54:57 -0700862 if (rc)
863 goto error;
864
865 /* Tx queue(s) */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200866 for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++) {
Stanislaw Gruszkad3175162011-11-15 11:25:42 +0100867 slots_num = (txq_id == IL39_CMD_QUEUE_NUM) ?
Zhu Yib481de92007-09-25 17:54:57 -0700868 TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200869 rc = il_tx_queue_init(il, &il->txq[txq_id],
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800870 slots_num, txq_id);
Zhu Yib481de92007-09-25 17:54:57 -0700871 if (rc) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200872 IL_ERR("Tx %d queue init failed\n", txq_id);
Zhu Yib481de92007-09-25 17:54:57 -0700873 goto error;
874 }
875 }
876
877 return rc;
878
879 error:
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200880 il3945_hw_txq_ctx_free(il);
Zhu Yib481de92007-09-25 17:54:57 -0700881 return rc;
882}
883
Ben Cahillfadb3582009-10-23 13:42:21 -0700884
Ben Cahillf33269b2009-10-09 13:20:19 -0700885/*
Ben Cahillfadb3582009-10-23 13:42:21 -0700886 * Start up 3945's basic functionality after it has been reset
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +0200887 * (e.g. after platform boot, or shutdown via il_apm_stop())
Ben Cahillf33269b2009-10-09 13:20:19 -0700888 * NOTE: This does not load uCode nor start the embedded processor
889 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200890static int il3945_apm_init(struct il_priv *il)
Zhu Yib481de92007-09-25 17:54:57 -0700891{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200892 int ret = il_apm_init(il);
Kolekar, Abhijeet01ec6162008-12-19 10:37:38 +0800893
Ben Cahillf33269b2009-10-09 13:20:19 -0700894 /* Clear APMG (NIC's internal power management) interrupts */
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +0200895 il_wr_prph(il, APMG_RTC_INT_MSK_REG, 0x0);
896 il_wr_prph(il, APMG_RTC_INT_STT_REG, 0xFFFFFFFF);
Ben Cahillf33269b2009-10-09 13:20:19 -0700897
898 /* Reset radio chip */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200899 il_set_bits_prph(il, APMG_PS_CTRL_REG,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800900 APMG_PS_CTRL_VAL_RESET_REQ);
Ben Cahillf33269b2009-10-09 13:20:19 -0700901 udelay(5);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200902 il_clear_bits_prph(il, APMG_PS_CTRL_REG,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -0800903 APMG_PS_CTRL_VAL_RESET_REQ);
Ben Cahillf33269b2009-10-09 13:20:19 -0700904
Kolekar, Abhijeet01ec6162008-12-19 10:37:38 +0800905 return ret;
906}
Zhu Yib481de92007-09-25 17:54:57 -0700907
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200908static void il3945_nic_config(struct il_priv *il)
Kolekar, Abhijeet01ec6162008-12-19 10:37:38 +0800909{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200910 struct il3945_eeprom *eeprom = (struct il3945_eeprom *)il->eeprom;
Kolekar, Abhijeet01ec6162008-12-19 10:37:38 +0800911 unsigned long flags;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200912 u8 rev_id = il->pci_dev->revision;
Zhu Yib481de92007-09-25 17:54:57 -0700913
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200914 spin_lock_irqsave(&il->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -0700915
Abhijeet Kolekar43121432009-05-08 13:44:41 -0700916 /* Determine HW type */
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100917 D_INFO("HW Revision ID = 0x%X\n", rev_id);
Abhijeet Kolekar43121432009-05-08 13:44:41 -0700918
Zhu Yib481de92007-09-25 17:54:57 -0700919 if (rev_id & PCI_CFG_REV_ID_BIT_RTP)
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100920 D_INFO("RTP type\n");
Zhu Yib481de92007-09-25 17:54:57 -0700921 else if (rev_id & PCI_CFG_REV_ID_BIT_BASIC_SKU) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100922 D_INFO("3945 RADIO-MB type\n");
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200923 il_set_bit(il, CSR_HW_IF_CONFIG_REG,
Tomas Winkler6f83eaa2008-03-04 18:09:28 -0800924 CSR39_HW_IF_CONFIG_REG_BIT_3945_MB);
Zhu Yib481de92007-09-25 17:54:57 -0700925 } else {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100926 D_INFO("3945 RADIO-MM type\n");
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200927 il_set_bit(il, CSR_HW_IF_CONFIG_REG,
Tomas Winkler6f83eaa2008-03-04 18:09:28 -0800928 CSR39_HW_IF_CONFIG_REG_BIT_3945_MM);
Zhu Yib481de92007-09-25 17:54:57 -0700929 }
930
Samuel Ortize6148912009-01-23 13:45:15 -0800931 if (EEPROM_SKU_CAP_OP_MODE_MRC == eeprom->sku_cap) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100932 D_INFO("SKU OP mode is mrc\n");
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200933 il_set_bit(il, CSR_HW_IF_CONFIG_REG,
Tomas Winkler6f83eaa2008-03-04 18:09:28 -0800934 CSR39_HW_IF_CONFIG_REG_BIT_SKU_MRC);
Zhu Yib481de92007-09-25 17:54:57 -0700935 } else
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100936 D_INFO("SKU OP mode is basic\n");
Zhu Yib481de92007-09-25 17:54:57 -0700937
Samuel Ortize6148912009-01-23 13:45:15 -0800938 if ((eeprom->board_revision & 0xF0) == 0xD0) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100939 D_INFO("3945ABG revision is 0x%X\n",
Samuel Ortize6148912009-01-23 13:45:15 -0800940 eeprom->board_revision);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200941 il_set_bit(il, CSR_HW_IF_CONFIG_REG,
Tomas Winkler6f83eaa2008-03-04 18:09:28 -0800942 CSR39_HW_IF_CONFIG_REG_BIT_BOARD_TYPE);
Zhu Yib481de92007-09-25 17:54:57 -0700943 } else {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100944 D_INFO("3945ABG revision is 0x%X\n",
Samuel Ortize6148912009-01-23 13:45:15 -0800945 eeprom->board_revision);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200946 il_clear_bit(il, CSR_HW_IF_CONFIG_REG,
Tomas Winkler6f83eaa2008-03-04 18:09:28 -0800947 CSR39_HW_IF_CONFIG_REG_BIT_BOARD_TYPE);
Zhu Yib481de92007-09-25 17:54:57 -0700948 }
949
Samuel Ortize6148912009-01-23 13:45:15 -0800950 if (eeprom->almgor_m_version <= 1) {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200951 il_set_bit(il, CSR_HW_IF_CONFIG_REG,
Tomas Winkler6f83eaa2008-03-04 18:09:28 -0800952 CSR39_HW_IF_CONFIG_REG_BITS_SILICON_TYPE_A);
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100953 D_INFO("Card M type A version is 0x%X\n",
Samuel Ortize6148912009-01-23 13:45:15 -0800954 eeprom->almgor_m_version);
Zhu Yib481de92007-09-25 17:54:57 -0700955 } else {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100956 D_INFO("Card M type B version is 0x%X\n",
Samuel Ortize6148912009-01-23 13:45:15 -0800957 eeprom->almgor_m_version);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200958 il_set_bit(il, CSR_HW_IF_CONFIG_REG,
Tomas Winkler6f83eaa2008-03-04 18:09:28 -0800959 CSR39_HW_IF_CONFIG_REG_BITS_SILICON_TYPE_B);
Zhu Yib481de92007-09-25 17:54:57 -0700960 }
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200961 spin_unlock_irqrestore(&il->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -0700962
Samuel Ortize6148912009-01-23 13:45:15 -0800963 if (eeprom->sku_cap & EEPROM_SKU_CAP_SW_RF_KILL_ENABLE)
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100964 D_RF_KILL("SW RF KILL supported in EEPROM.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700965
Samuel Ortize6148912009-01-23 13:45:15 -0800966 if (eeprom->sku_cap & EEPROM_SKU_CAP_HW_RF_KILL_ENABLE)
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +0100967 D_RF_KILL("HW RF KILL supported in EEPROM.\n");
Kolekar, Abhijeet01ec6162008-12-19 10:37:38 +0800968}
969
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200970int il3945_hw_nic_init(struct il_priv *il)
Kolekar, Abhijeet01ec6162008-12-19 10:37:38 +0800971{
Kolekar, Abhijeet01ec6162008-12-19 10:37:38 +0800972 int rc;
973 unsigned long flags;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200974 struct il_rx_queue *rxq = &il->rxq;
Kolekar, Abhijeet01ec6162008-12-19 10:37:38 +0800975
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200976 spin_lock_irqsave(&il->lock, flags);
977 il->cfg->ops->lib->apm_ops.init(il);
978 spin_unlock_irqrestore(&il->lock, flags);
Kolekar, Abhijeet01ec6162008-12-19 10:37:38 +0800979
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200980 il3945_set_pwr_vmain(il);
Kolekar, Abhijeet854682e2008-12-19 10:37:39 +0800981
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200982 il->cfg->ops->lib->apm_ops.config(il);
Zhu Yib481de92007-09-25 17:54:57 -0700983
984 /* Allocate the RX queue, or reset if it is already allocated */
985 if (!rxq->bd) {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200986 rc = il_rx_queue_alloc(il);
Zhu Yib481de92007-09-25 17:54:57 -0700987 if (rc) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +0200988 IL_ERR("Unable to initialize Rx queue\n");
Zhu Yib481de92007-09-25 17:54:57 -0700989 return -ENOMEM;
990 }
991 } else
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200992 il3945_rx_queue_reset(il, rxq);
Zhu Yib481de92007-09-25 17:54:57 -0700993
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200994 il3945_rx_replenish(il);
Zhu Yib481de92007-09-25 17:54:57 -0700995
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +0200996 il3945_rx_init(il, rxq);
Zhu Yib481de92007-09-25 17:54:57 -0700997
Zhu Yib481de92007-09-25 17:54:57 -0700998
999 /* Look at using this instead:
1000 rxq->need_update = 1;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001001 il_rx_queue_update_write_ptr(il, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07001002 */
1003
Stanislaw Gruszka0c1a94e2011-08-24 17:37:16 +02001004 il_wr(il, FH39_RCSR_WPTR(0), rxq->write & ~7);
Zhu Yib481de92007-09-25 17:54:57 -07001005
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001006 rc = il3945_txq_ctx_reset(il);
Zhu Yib481de92007-09-25 17:54:57 -07001007 if (rc)
1008 return rc;
1009
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01001010 set_bit(S_INIT, &il->status);
Zhu Yib481de92007-09-25 17:54:57 -07001011
1012 return 0;
1013}
1014
1015/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001016 * il3945_hw_txq_ctx_free - Free TXQ Context
Zhu Yib481de92007-09-25 17:54:57 -07001017 *
1018 * Destroy all TX DMA queues and structures
1019 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001020void il3945_hw_txq_ctx_free(struct il_priv *il)
Zhu Yib481de92007-09-25 17:54:57 -07001021{
1022 int txq_id;
1023
1024 /* Tx queues */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001025 if (il->txq)
1026 for (txq_id = 0; txq_id < il->hw_params.max_txq_num;
Wey-Yi Guy88804e22009-10-09 13:20:28 -07001027 txq_id++)
Stanislaw Gruszkad3175162011-11-15 11:25:42 +01001028 if (txq_id == IL39_CMD_QUEUE_NUM)
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001029 il_cmd_queue_free(il);
Wey-Yi Guy88804e22009-10-09 13:20:28 -07001030 else
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001031 il_tx_queue_free(il, txq_id);
Abhijeet Kolekar3e5d2382009-03-17 21:51:49 -07001032
Wey-Yi Guy88804e22009-10-09 13:20:28 -07001033 /* free tx queue structure */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001034 il_txq_mem(il);
Zhu Yib481de92007-09-25 17:54:57 -07001035}
1036
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001037void il3945_hw_txq_ctx_stop(struct il_priv *il)
Zhu Yib481de92007-09-25 17:54:57 -07001038{
Tomas Winklerbddadf82008-12-19 10:37:01 +08001039 int txq_id;
Zhu Yib481de92007-09-25 17:54:57 -07001040
1041 /* stop SCD */
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +02001042 il_wr_prph(il, ALM_SCD_MODE_REG, 0);
1043 il_wr_prph(il, ALM_SCD_TXFACT_REG, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001044
1045 /* reset TFD queues */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001046 for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++) {
Stanislaw Gruszka0c1a94e2011-08-24 17:37:16 +02001047 il_wr(il, FH39_TCSR_CONFIG(txq_id), 0x0);
1048 il_poll_bit(il, FH39_TSSR_TX_STATUS,
Tomas Winklerbddadf82008-12-19 10:37:01 +08001049 FH39_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(txq_id),
Zhu Yib481de92007-09-25 17:54:57 -07001050 1000);
1051 }
1052
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001053 il3945_hw_txq_ctx_free(il);
Zhu Yib481de92007-09-25 17:54:57 -07001054}
1055
Zhu Yib481de92007-09-25 17:54:57 -07001056/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001057 * il3945_hw_reg_adjust_power_by_temp
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001058 * return idx delta into power gain settings table
Ian Schrambbc58072007-10-25 17:15:28 +08001059*/
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001060static int il3945_hw_reg_adjust_power_by_temp(int new_reading, int old_reading)
Zhu Yib481de92007-09-25 17:54:57 -07001061{
1062 return (new_reading - old_reading) * (-11) / 100;
1063}
1064
1065/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001066 * il3945_hw_reg_temp_out_of_range - Keep temperature in sane range
Zhu Yib481de92007-09-25 17:54:57 -07001067 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001068static inline int il3945_hw_reg_temp_out_of_range(int temperature)
Zhu Yib481de92007-09-25 17:54:57 -07001069{
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02001070 return (temperature < -260 || temperature > 25) ? 1 : 0;
Zhu Yib481de92007-09-25 17:54:57 -07001071}
1072
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001073int il3945_hw_get_temperature(struct il_priv *il)
Zhu Yib481de92007-09-25 17:54:57 -07001074{
Stanislaw Gruszka841b2cc2011-08-24 15:14:03 +02001075 return _il_rd(il, CSR_UCODE_DRV_GP2);
Zhu Yib481de92007-09-25 17:54:57 -07001076}
1077
1078/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001079 * il3945_hw_reg_txpower_get_temperature
Ian Schrambbc58072007-10-25 17:15:28 +08001080 * get the current temperature by reading from NIC
1081*/
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001082static int il3945_hw_reg_txpower_get_temperature(struct il_priv *il)
Zhu Yib481de92007-09-25 17:54:57 -07001083{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001084 struct il3945_eeprom *eeprom = (struct il3945_eeprom *)il->eeprom;
Zhu Yib481de92007-09-25 17:54:57 -07001085 int temperature;
1086
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001087 temperature = il3945_hw_get_temperature(il);
Zhu Yib481de92007-09-25 17:54:57 -07001088
1089 /* driver's okay range is -260 to +25.
1090 * human readable okay range is 0 to +285 */
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001091 D_INFO("Temperature: %d\n", temperature + IL_TEMP_CONVERT);
Zhu Yib481de92007-09-25 17:54:57 -07001092
1093 /* handle insane temp reading */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001094 if (il3945_hw_reg_temp_out_of_range(temperature)) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001095 IL_ERR("Error bad temperature value %d\n", temperature);
Zhu Yib481de92007-09-25 17:54:57 -07001096
1097 /* if really really hot(?),
1098 * substitute the 3rd band/group's temp measured at factory */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001099 if (il->last_temperature > 100)
Samuel Ortize6148912009-01-23 13:45:15 -08001100 temperature = eeprom->groups[2].temperature;
Zhu Yib481de92007-09-25 17:54:57 -07001101 else /* else use most recent "sane" value from driver */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001102 temperature = il->last_temperature;
Zhu Yib481de92007-09-25 17:54:57 -07001103 }
1104
1105 return temperature; /* raw, not "human readable" */
1106}
1107
1108/* Adjust Txpower only if temperature variance is greater than threshold.
1109 *
1110 * Both are lower than older versions' 9 degrees */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001111#define IL_TEMPERATURE_LIMIT_TIMER 6
Zhu Yib481de92007-09-25 17:54:57 -07001112
1113/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001114 * il3945_is_temp_calib_needed - determines if new calibration is needed
Zhu Yib481de92007-09-25 17:54:57 -07001115 *
1116 * records new temperature in tx_mgr->temperature.
1117 * replaces tx_mgr->last_temperature *only* if calib needed
1118 * (assumes caller will actually do the calibration!). */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001119static int il3945_is_temp_calib_needed(struct il_priv *il)
Zhu Yib481de92007-09-25 17:54:57 -07001120{
1121 int temp_diff;
1122
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001123 il->temperature = il3945_hw_reg_txpower_get_temperature(il);
1124 temp_diff = il->temperature - il->last_temperature;
Zhu Yib481de92007-09-25 17:54:57 -07001125
1126 /* get absolute value */
1127 if (temp_diff < 0) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001128 D_POWER("Getting cooler, delta %d,\n", temp_diff);
Zhu Yib481de92007-09-25 17:54:57 -07001129 temp_diff = -temp_diff;
1130 } else if (temp_diff == 0)
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001131 D_POWER("Same temp,\n");
Zhu Yib481de92007-09-25 17:54:57 -07001132 else
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001133 D_POWER("Getting warmer, delta %d,\n", temp_diff);
Zhu Yib481de92007-09-25 17:54:57 -07001134
1135 /* if we don't need calibration, *don't* update last_temperature */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001136 if (temp_diff < IL_TEMPERATURE_LIMIT_TIMER) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001137 D_POWER("Timed thermal calib not needed\n");
Zhu Yib481de92007-09-25 17:54:57 -07001138 return 0;
1139 }
1140
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001141 D_POWER("Timed thermal calib needed\n");
Zhu Yib481de92007-09-25 17:54:57 -07001142
1143 /* assume that caller will actually do calib ...
1144 * update the "last temperature" value */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001145 il->last_temperature = il->temperature;
Zhu Yib481de92007-09-25 17:54:57 -07001146 return 1;
1147}
1148
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001149#define IL_MAX_GAIN_ENTRIES 78
1150#define IL_CCK_FROM_OFDM_POWER_DIFF -5
Stanislaw Gruszka2d09b062011-08-26 16:10:40 +02001151#define IL_CCK_FROM_OFDM_IDX_DIFF (10)
Zhu Yib481de92007-09-25 17:54:57 -07001152
1153/* radio and DSP power table, each step is 1/2 dB.
1154 * 1st number is for RF analog gain, 2nd number is for DSP pre-DAC gain. */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001155static struct il3945_tx_power power_gain_table[2][IL_MAX_GAIN_ENTRIES] = {
Zhu Yib481de92007-09-25 17:54:57 -07001156 {
1157 {251, 127}, /* 2.4 GHz, highest power */
1158 {251, 127},
1159 {251, 127},
1160 {251, 127},
1161 {251, 125},
1162 {251, 110},
1163 {251, 105},
1164 {251, 98},
1165 {187, 125},
1166 {187, 115},
1167 {187, 108},
1168 {187, 99},
1169 {243, 119},
1170 {243, 111},
1171 {243, 105},
1172 {243, 97},
1173 {243, 92},
1174 {211, 106},
1175 {211, 100},
1176 {179, 120},
1177 {179, 113},
1178 {179, 107},
1179 {147, 125},
1180 {147, 119},
1181 {147, 112},
1182 {147, 106},
1183 {147, 101},
1184 {147, 97},
1185 {147, 91},
1186 {115, 107},
1187 {235, 121},
1188 {235, 115},
1189 {235, 109},
1190 {203, 127},
1191 {203, 121},
1192 {203, 115},
1193 {203, 108},
1194 {203, 102},
1195 {203, 96},
1196 {203, 92},
1197 {171, 110},
1198 {171, 104},
1199 {171, 98},
1200 {139, 116},
1201 {227, 125},
1202 {227, 119},
1203 {227, 113},
1204 {227, 107},
1205 {227, 101},
1206 {227, 96},
1207 {195, 113},
1208 {195, 106},
1209 {195, 102},
1210 {195, 95},
1211 {163, 113},
1212 {163, 106},
1213 {163, 102},
1214 {163, 95},
1215 {131, 113},
1216 {131, 106},
1217 {131, 102},
1218 {131, 95},
1219 {99, 113},
1220 {99, 106},
1221 {99, 102},
1222 {99, 95},
1223 {67, 113},
1224 {67, 106},
1225 {67, 102},
1226 {67, 95},
1227 {35, 113},
1228 {35, 106},
1229 {35, 102},
1230 {35, 95},
1231 {3, 113},
1232 {3, 106},
1233 {3, 102},
1234 {3, 95} }, /* 2.4 GHz, lowest power */
1235 {
1236 {251, 127}, /* 5.x GHz, highest power */
1237 {251, 120},
1238 {251, 114},
1239 {219, 119},
1240 {219, 101},
1241 {187, 113},
1242 {187, 102},
1243 {155, 114},
1244 {155, 103},
1245 {123, 117},
1246 {123, 107},
1247 {123, 99},
1248 {123, 92},
1249 {91, 108},
1250 {59, 125},
1251 {59, 118},
1252 {59, 109},
1253 {59, 102},
1254 {59, 96},
1255 {59, 90},
1256 {27, 104},
1257 {27, 98},
1258 {27, 92},
1259 {115, 118},
1260 {115, 111},
1261 {115, 104},
1262 {83, 126},
1263 {83, 121},
1264 {83, 113},
1265 {83, 105},
1266 {83, 99},
1267 {51, 118},
1268 {51, 111},
1269 {51, 104},
1270 {51, 98},
1271 {19, 116},
1272 {19, 109},
1273 {19, 102},
1274 {19, 98},
1275 {19, 93},
1276 {171, 113},
1277 {171, 107},
1278 {171, 99},
1279 {139, 120},
1280 {139, 113},
1281 {139, 107},
1282 {139, 99},
1283 {107, 120},
1284 {107, 113},
1285 {107, 107},
1286 {107, 99},
1287 {75, 120},
1288 {75, 113},
1289 {75, 107},
1290 {75, 99},
1291 {43, 120},
1292 {43, 113},
1293 {43, 107},
1294 {43, 99},
1295 {11, 120},
1296 {11, 113},
1297 {11, 107},
1298 {11, 99},
1299 {131, 107},
1300 {131, 99},
1301 {99, 120},
1302 {99, 113},
1303 {99, 107},
1304 {99, 99},
1305 {67, 120},
1306 {67, 113},
1307 {67, 107},
1308 {67, 99},
1309 {35, 120},
1310 {35, 113},
1311 {35, 107},
1312 {35, 99},
1313 {3, 120} } /* 5.x GHz, lowest power */
1314};
1315
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001316static inline u8 il3945_hw_reg_fix_power_idx(int idx)
Zhu Yib481de92007-09-25 17:54:57 -07001317{
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001318 if (idx < 0)
Zhu Yib481de92007-09-25 17:54:57 -07001319 return 0;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001320 if (idx >= IL_MAX_GAIN_ENTRIES)
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001321 return IL_MAX_GAIN_ENTRIES - 1;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001322 return (u8) idx;
Zhu Yib481de92007-09-25 17:54:57 -07001323}
1324
1325/* Kick off thermal recalibration check every 60 seconds */
1326#define REG_RECALIB_PERIOD (60)
1327
1328/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001329 * il3945_hw_reg_set_scan_power - Set Tx power for scan probe requests
Zhu Yib481de92007-09-25 17:54:57 -07001330 *
1331 * Set (in our channel info database) the direct scan Tx power for 1 Mbit (CCK)
1332 * or 6 Mbit (OFDM) rates.
1333 */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001334static void il3945_hw_reg_set_scan_power(struct il_priv *il, u32 scan_tbl_idx,
1335 s32 rate_idx, const s8 *clip_pwrs,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001336 struct il_channel_info *ch_info,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001337 int band_idx)
Zhu Yib481de92007-09-25 17:54:57 -07001338{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001339 struct il3945_scan_power_info *scan_power_info;
Zhu Yib481de92007-09-25 17:54:57 -07001340 s8 power;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001341 u8 power_idx;
Zhu Yib481de92007-09-25 17:54:57 -07001342
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001343 scan_power_info = &ch_info->scan_pwr_info[scan_tbl_idx];
Zhu Yib481de92007-09-25 17:54:57 -07001344
1345 /* use this channel group's 6Mbit clipping/saturation pwr,
1346 * but cap at regulatory scan power restriction (set during init
1347 * based on eeprom channel data) for this channel. */
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02001348 power = min(ch_info->scan_power, clip_pwrs[RATE_6M_IDX_TBL]);
Zhu Yib481de92007-09-25 17:54:57 -07001349
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001350 power = min(power, il->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07001351 scan_power_info->requested_power = power;
1352
1353 /* find difference between new scan *power* and current "normal"
1354 * Tx *power* for 6Mb. Use this difference (x2) to adjust the
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001355 * current "normal" temperature-compensated Tx power *idx* for
Zhu Yib481de92007-09-25 17:54:57 -07001356 * this rate (1Mb or 6Mb) to yield new temp-compensated scan power
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001357 * *idx*. */
1358 power_idx = ch_info->power_info[rate_idx].power_table_idx
Zhu Yib481de92007-09-25 17:54:57 -07001359 - (power - ch_info->power_info
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02001360 [RATE_6M_IDX_TBL].requested_power) * 2;
Zhu Yib481de92007-09-25 17:54:57 -07001361
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001362 /* store reference idx that we use when adjusting *all* scan
Zhu Yib481de92007-09-25 17:54:57 -07001363 * powers. So we can accommodate user (all channel) or spectrum
1364 * management (single channel) power changes "between" temperature
1365 * feedback compensation procedures.
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001366 * don't force fit this reference idx into gain table; it may be a
Zhu Yib481de92007-09-25 17:54:57 -07001367 * negative number. This will help avoid errors when we're at
1368 * the lower bounds (highest gains, for warmest temperatures)
1369 * of the table. */
1370
1371 /* don't exceed table bounds for "real" setting */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001372 power_idx = il3945_hw_reg_fix_power_idx(power_idx);
Zhu Yib481de92007-09-25 17:54:57 -07001373
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001374 scan_power_info->power_table_idx = power_idx;
Zhu Yib481de92007-09-25 17:54:57 -07001375 scan_power_info->tpc.tx_gain =
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001376 power_gain_table[band_idx][power_idx].tx_gain;
Zhu Yib481de92007-09-25 17:54:57 -07001377 scan_power_info->tpc.dsp_atten =
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001378 power_gain_table[band_idx][power_idx].dsp_atten;
Zhu Yib481de92007-09-25 17:54:57 -07001379}
1380
1381/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001382 * il3945_send_tx_power - fill in Tx Power command with gain settings
Zhu Yib481de92007-09-25 17:54:57 -07001383 *
1384 * Configures power settings for all rates for the current channel,
1385 * using values from channel info struct, and send to NIC
1386 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001387static int il3945_send_tx_power(struct il_priv *il)
Zhu Yib481de92007-09-25 17:54:57 -07001388{
Mohamed Abbas14577f22007-11-12 11:37:42 +08001389 int rate_idx, i;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001390 const struct il_channel_info *ch_info = NULL;
1391 struct il3945_txpowertable_cmd txpower = {
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +01001392 .channel = il->ctx.active.channel,
Zhu Yib481de92007-09-25 17:54:57 -07001393 };
Johannes Berg246ed352010-08-23 10:46:32 +02001394 u16 chan;
1395
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01001396 if (WARN_ONCE(test_bit(S_SCAN_HW, &il->status),
Stanislaw Gruszka4beeba72010-10-25 10:34:50 +02001397 "TX Power requested while scanning!\n"))
1398 return -EAGAIN;
1399
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +01001400 chan = le16_to_cpu(il->ctx.active.channel);
Zhu Yib481de92007-09-25 17:54:57 -07001401
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001402 txpower.band = (il->band == IEEE80211_BAND_5GHZ) ? 0 : 1;
1403 ch_info = il_get_channel_info(il, il->band, chan);
Zhu Yib481de92007-09-25 17:54:57 -07001404 if (!ch_info) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001405 IL_ERR(
Winkler, Tomas15b16872008-12-19 10:37:33 +08001406 "Failed to get channel info for channel %d [%d]\n",
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001407 chan, il->band);
Zhu Yib481de92007-09-25 17:54:57 -07001408 return -EINVAL;
1409 }
1410
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001411 if (!il_is_channel_valid(ch_info)) {
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02001412 D_POWER("Not calling TX_PWR_TBL_CMD on "
Zhu Yib481de92007-09-25 17:54:57 -07001413 "non-Tx channel.\n");
1414 return 0;
1415 }
1416
1417 /* fill cmd with power settings for all rates for current channel */
Mohamed Abbas14577f22007-11-12 11:37:42 +08001418 /* Fill OFDM rate */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001419 for (rate_idx = IL_FIRST_OFDM_RATE, i = 0;
Stanislaw Gruszkad3175162011-11-15 11:25:42 +01001420 rate_idx <= IL39_LAST_OFDM_RATE; rate_idx++, i++) {
Mohamed Abbas14577f22007-11-12 11:37:42 +08001421
1422 txpower.power[i].tpc = ch_info->power_info[i].tpc;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001423 txpower.power[i].rate = il3945_rates[rate_idx].plcp;
Zhu Yib481de92007-09-25 17:54:57 -07001424
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001425 D_POWER("ch %d:%d rf %d dsp %3d rate code 0x%02x\n",
Zhu Yib481de92007-09-25 17:54:57 -07001426 le16_to_cpu(txpower.channel),
1427 txpower.band,
Mohamed Abbas14577f22007-11-12 11:37:42 +08001428 txpower.power[i].tpc.tx_gain,
1429 txpower.power[i].tpc.dsp_atten,
1430 txpower.power[i].rate);
1431 }
1432 /* Fill CCK rates */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001433 for (rate_idx = IL_FIRST_CCK_RATE;
1434 rate_idx <= IL_LAST_CCK_RATE; rate_idx++, i++) {
Mohamed Abbas14577f22007-11-12 11:37:42 +08001435 txpower.power[i].tpc = ch_info->power_info[i].tpc;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001436 txpower.power[i].rate = il3945_rates[rate_idx].plcp;
Mohamed Abbas14577f22007-11-12 11:37:42 +08001437
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001438 D_POWER("ch %d:%d rf %d dsp %3d rate code 0x%02x\n",
Mohamed Abbas14577f22007-11-12 11:37:42 +08001439 le16_to_cpu(txpower.channel),
1440 txpower.band,
1441 txpower.power[i].tpc.tx_gain,
1442 txpower.power[i].tpc.dsp_atten,
1443 txpower.power[i].rate);
Zhu Yib481de92007-09-25 17:54:57 -07001444 }
1445
Stanislaw Gruszka4d69c752011-08-30 15:26:35 +02001446 return il_send_cmd_pdu(il, C_TX_PWR_TBL,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001447 sizeof(struct il3945_txpowertable_cmd),
Samuel Ortiz518099a2009-01-19 15:30:27 -08001448 &txpower);
Zhu Yib481de92007-09-25 17:54:57 -07001449
1450}
1451
1452/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001453 * il3945_hw_reg_set_new_power - Configures power tables at new levels
Zhu Yib481de92007-09-25 17:54:57 -07001454 * @ch_info: Channel to update. Uses power_info.requested_power.
1455 *
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001456 * Replace requested_power and base_power_idx ch_info fields for
Zhu Yib481de92007-09-25 17:54:57 -07001457 * one channel.
1458 *
1459 * Called if user or spectrum management changes power preferences.
1460 * Takes into account h/w and modulation limitations (clip power).
1461 *
1462 * This does *not* send anything to NIC, just sets up ch_info for one channel.
1463 *
1464 * NOTE: reg_compensate_for_temperature_dif() *must* be run after this to
1465 * properly fill out the scan powers, and actual h/w gain settings,
1466 * and send changes to NIC
1467 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001468static int il3945_hw_reg_set_new_power(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001469 struct il_channel_info *ch_info)
Zhu Yib481de92007-09-25 17:54:57 -07001470{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001471 struct il3945_channel_power_info *power_info;
Zhu Yib481de92007-09-25 17:54:57 -07001472 int power_changed = 0;
1473 int i;
1474 const s8 *clip_pwrs;
1475 int power;
1476
1477 /* Get this chnlgrp's rate-to-max/clip-powers table */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001478 clip_pwrs = il->_3945.clip_groups[ch_info->group_idx].clip_powers;
Zhu Yib481de92007-09-25 17:54:57 -07001479
1480 /* Get this channel's rate-to-current-power settings table */
1481 power_info = ch_info->power_info;
1482
1483 /* update OFDM Txpower settings */
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02001484 for (i = RATE_6M_IDX_TBL; i <= RATE_54M_IDX_TBL;
Zhu Yib481de92007-09-25 17:54:57 -07001485 i++, ++power_info) {
1486 int delta_idx;
1487
1488 /* limit new power to be no more than h/w capability */
1489 power = min(ch_info->curr_txpow, clip_pwrs[i]);
1490 if (power == power_info->requested_power)
1491 continue;
1492
1493 /* find difference between old and new requested powers,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001494 * update base (non-temp-compensated) power idx */
Zhu Yib481de92007-09-25 17:54:57 -07001495 delta_idx = (power - power_info->requested_power) * 2;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001496 power_info->base_power_idx -= delta_idx;
Zhu Yib481de92007-09-25 17:54:57 -07001497
1498 /* save new requested power value */
1499 power_info->requested_power = power;
1500
1501 power_changed = 1;
1502 }
1503
1504 /* update CCK Txpower settings, based on OFDM 12M setting ...
1505 * ... all CCK power settings for a given channel are the *same*. */
1506 if (power_changed) {
1507 power =
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02001508 ch_info->power_info[RATE_12M_IDX_TBL].
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001509 requested_power + IL_CCK_FROM_OFDM_POWER_DIFF;
Zhu Yib481de92007-09-25 17:54:57 -07001510
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001511 /* do all CCK rates' il3945_channel_power_info structures */
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02001512 for (i = RATE_1M_IDX_TBL; i <= RATE_11M_IDX_TBL; i++) {
Zhu Yib481de92007-09-25 17:54:57 -07001513 power_info->requested_power = power;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001514 power_info->base_power_idx =
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02001515 ch_info->power_info[RATE_12M_IDX_TBL].
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001516 base_power_idx + IL_CCK_FROM_OFDM_IDX_DIFF;
Zhu Yib481de92007-09-25 17:54:57 -07001517 ++power_info;
1518 }
1519 }
1520
1521 return 0;
1522}
1523
1524/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001525 * il3945_hw_reg_get_ch_txpower_limit - returns new power limit for channel
Zhu Yib481de92007-09-25 17:54:57 -07001526 *
1527 * NOTE: Returned power limit may be less (but not more) than requested,
1528 * based strictly on regulatory (eeprom and spectrum mgt) limitations
1529 * (no consideration for h/w clipping limitations).
1530 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001531static int il3945_hw_reg_get_ch_txpower_limit(struct il_channel_info *ch_info)
Zhu Yib481de92007-09-25 17:54:57 -07001532{
1533 s8 max_power;
1534
1535#if 0
1536 /* if we're using TGd limits, use lower of TGd or EEPROM */
1537 if (ch_info->tgd_data.max_power != 0)
1538 max_power = min(ch_info->tgd_data.max_power,
1539 ch_info->eeprom.max_power_avg);
1540
1541 /* else just use EEPROM limits */
1542 else
1543#endif
1544 max_power = ch_info->eeprom.max_power_avg;
1545
1546 return min(max_power, ch_info->max_power_avg);
1547}
1548
1549/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001550 * il3945_hw_reg_comp_txpower_temp - Compensate for temperature
Zhu Yib481de92007-09-25 17:54:57 -07001551 *
1552 * Compensate txpower settings of *all* channels for temperature.
1553 * This only accounts for the difference between current temperature
1554 * and the factory calibration temperatures, and bases the new settings
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001555 * on the channel's base_power_idx.
Zhu Yib481de92007-09-25 17:54:57 -07001556 *
1557 * If RxOn is "associated", this sends the new Txpower to NIC!
1558 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001559static int il3945_hw_reg_comp_txpower_temp(struct il_priv *il)
Zhu Yib481de92007-09-25 17:54:57 -07001560{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001561 struct il_channel_info *ch_info = NULL;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001562 struct il3945_eeprom *eeprom = (struct il3945_eeprom *)il->eeprom;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001563 int delta_idx;
Zhu Yib481de92007-09-25 17:54:57 -07001564 const s8 *clip_pwrs; /* array of h/w max power levels for each rate */
1565 u8 a_band;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001566 u8 rate_idx;
1567 u8 scan_tbl_idx;
Zhu Yib481de92007-09-25 17:54:57 -07001568 u8 i;
1569 int ref_temp;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001570 int temperature = il->temperature;
Zhu Yib481de92007-09-25 17:54:57 -07001571
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001572 if (il->disable_tx_power_cal ||
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01001573 test_bit(S_SCANNING, &il->status)) {
Wey-Yi Guy4e7033e2010-04-27 14:33:33 -07001574 /* do not perform tx power calibration */
1575 return 0;
1576 }
Zhu Yib481de92007-09-25 17:54:57 -07001577 /* set up new Tx power info for each and every channel, 2.4 and 5.x */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001578 for (i = 0; i < il->channel_count; i++) {
1579 ch_info = &il->channel_info[i];
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001580 a_band = il_is_channel_a_band(ch_info);
Zhu Yib481de92007-09-25 17:54:57 -07001581
1582 /* Get this chnlgrp's factory calibration temperature */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001583 ref_temp = (s16)eeprom->groups[ch_info->group_idx].
Zhu Yib481de92007-09-25 17:54:57 -07001584 temperature;
1585
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001586 /* get power idx adjustment based on current and factory
Zhu Yib481de92007-09-25 17:54:57 -07001587 * temps */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001588 delta_idx = il3945_hw_reg_adjust_power_by_temp(temperature,
Zhu Yib481de92007-09-25 17:54:57 -07001589 ref_temp);
1590
1591 /* set tx power value for all rates, OFDM and CCK */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001592 for (rate_idx = 0; rate_idx < RATE_COUNT_3945;
1593 rate_idx++) {
Zhu Yib481de92007-09-25 17:54:57 -07001594 int power_idx =
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001595 ch_info->power_info[rate_idx].base_power_idx;
Zhu Yib481de92007-09-25 17:54:57 -07001596
1597 /* temperature compensate */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001598 power_idx += delta_idx;
Zhu Yib481de92007-09-25 17:54:57 -07001599
1600 /* stay within table range */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001601 power_idx = il3945_hw_reg_fix_power_idx(power_idx);
1602 ch_info->power_info[rate_idx].
1603 power_table_idx = (u8) power_idx;
1604 ch_info->power_info[rate_idx].tpc =
Zhu Yib481de92007-09-25 17:54:57 -07001605 power_gain_table[a_band][power_idx];
1606 }
1607
1608 /* Get this chnlgrp's rate-to-max/clip-powers table */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001609 clip_pwrs = il->_3945.clip_groups[ch_info->group_idx].clip_powers;
Zhu Yib481de92007-09-25 17:54:57 -07001610
1611 /* set scan tx power, 1Mbit for CCK, 6Mbit for OFDM */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001612 for (scan_tbl_idx = 0;
1613 scan_tbl_idx < IL_NUM_SCAN_RATES; scan_tbl_idx++) {
1614 s32 actual_idx = (scan_tbl_idx == 0) ?
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02001615 RATE_1M_IDX_TBL : RATE_6M_IDX_TBL;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001616 il3945_hw_reg_set_scan_power(il, scan_tbl_idx,
1617 actual_idx, clip_pwrs,
Zhu Yib481de92007-09-25 17:54:57 -07001618 ch_info, a_band);
1619 }
1620 }
1621
1622 /* send Txpower command for current channel to ucode */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001623 return il->cfg->ops->lib->send_tx_power(il);
Zhu Yib481de92007-09-25 17:54:57 -07001624}
1625
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001626int il3945_hw_reg_set_txpower(struct il_priv *il, s8 power)
Zhu Yib481de92007-09-25 17:54:57 -07001627{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001628 struct il_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07001629 s8 max_power;
1630 u8 a_band;
1631 u8 i;
1632
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001633 if (il->tx_power_user_lmt == power) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001634 D_POWER("Requested Tx power same as current "
Zhu Yib481de92007-09-25 17:54:57 -07001635 "limit: %ddBm.\n", power);
1636 return 0;
1637 }
1638
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001639 D_POWER("Setting upper limit clamp to %ddBm.\n", power);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001640 il->tx_power_user_lmt = power;
Zhu Yib481de92007-09-25 17:54:57 -07001641
1642 /* set up new Tx powers for each and every channel, 2.4 and 5.x */
1643
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001644 for (i = 0; i < il->channel_count; i++) {
1645 ch_info = &il->channel_info[i];
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001646 a_band = il_is_channel_a_band(ch_info);
Zhu Yib481de92007-09-25 17:54:57 -07001647
1648 /* find minimum power of all user and regulatory constraints
1649 * (does not consider h/w clipping limitations) */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001650 max_power = il3945_hw_reg_get_ch_txpower_limit(ch_info);
Zhu Yib481de92007-09-25 17:54:57 -07001651 max_power = min(power, max_power);
1652 if (max_power != ch_info->curr_txpow) {
1653 ch_info->curr_txpow = max_power;
1654
1655 /* this considers the h/w clipping limitations */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001656 il3945_hw_reg_set_new_power(il, ch_info);
Zhu Yib481de92007-09-25 17:54:57 -07001657 }
1658 }
1659
1660 /* update txpower settings for all channels,
1661 * send to NIC if associated. */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001662 il3945_is_temp_calib_needed(il);
1663 il3945_hw_reg_comp_txpower_temp(il);
Zhu Yib481de92007-09-25 17:54:57 -07001664
1665 return 0;
1666}
1667
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001668static int il3945_send_rxon_assoc(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001669 struct il_rxon_context *ctx)
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07001670{
1671 int rc = 0;
Stanislaw Gruszkadcae1c62011-08-26 14:36:21 +02001672 struct il_rx_pkt *pkt;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001673 struct il3945_rxon_assoc_cmd rxon_assoc;
1674 struct il_host_cmd cmd = {
Stanislaw Gruszka4d69c752011-08-30 15:26:35 +02001675 .id = C_RXON_ASSOC,
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07001676 .len = sizeof(rxon_assoc),
Johannes Bergc2acea82009-07-24 11:13:05 -07001677 .flags = CMD_WANT_SKB,
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07001678 .data = &rxon_assoc,
1679 };
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001680 const struct il_rxon_cmd *rxon1 = &ctx->staging;
1681 const struct il_rxon_cmd *rxon2 = &ctx->active;
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07001682
Stanislaw Gruszka232913b2011-08-26 10:45:16 +02001683 if (rxon1->flags == rxon2->flags &&
1684 rxon1->filter_flags == rxon2->filter_flags &&
1685 rxon1->cck_basic_rates == rxon2->cck_basic_rates &&
1686 rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001687 D_INFO("Using current RXON_ASSOC. Not resending.\n");
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07001688 return 0;
1689 }
1690
Johannes Berg246ed352010-08-23 10:46:32 +02001691 rxon_assoc.flags = ctx->staging.flags;
1692 rxon_assoc.filter_flags = ctx->staging.filter_flags;
1693 rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates;
1694 rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates;
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07001695 rxon_assoc.reserved = 0;
1696
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001697 rc = il_send_cmd_sync(il, &cmd);
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07001698 if (rc)
1699 return rc;
1700
Stanislaw Gruszkadcae1c62011-08-26 14:36:21 +02001701 pkt = (struct il_rx_pkt *)cmd.reply_page;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001702 if (pkt->hdr.flags & IL_CMD_FAILED_MSK) {
Stanislaw Gruszka4d69c752011-08-30 15:26:35 +02001703 IL_ERR("Bad return from C_RXON_ASSOC command\n");
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07001704 rc = -EIO;
1705 }
1706
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001707 il_free_pages(il, cmd.reply_page);
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07001708
1709 return rc;
1710}
1711
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001712/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001713 * il3945_commit_rxon - commit staging_rxon to hardware
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001714 *
1715 * The RXON command in staging_rxon is committed to the hardware and
1716 * the active_rxon structure is updated with the new data. This
1717 * function correctly transitions out of the RXON_ASSOC_MSK state if
1718 * a HW tune is required based on the RXON structure changes.
1719 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001720int il3945_commit_rxon(struct il_priv *il, struct il_rxon_context *ctx)
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001721{
1722 /* cast away the const for active_rxon in this function */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001723 struct il3945_rxon_cmd *active_rxon = (void *)&ctx->active;
1724 struct il3945_rxon_cmd *staging_rxon = (void *)&ctx->staging;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001725 int rc = 0;
Johannes Berg246ed352010-08-23 10:46:32 +02001726 bool new_assoc = !!(staging_rxon->filter_flags & RXON_FILTER_ASSOC_MSK);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001727
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01001728 if (test_bit(S_EXIT_PENDING, &il->status))
Wey-Yi Guyadb90a02010-11-26 11:09:42 -08001729 return -EINVAL;
1730
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001731 if (!il_is_alive(il))
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001732 return -1;
1733
1734 /* always get timestamp with Rx frame */
1735 staging_rxon->flags |= RXON_FLG_TSF2HOST_MSK;
1736
1737 /* select antenna */
1738 staging_rxon->flags &=
1739 ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001740 staging_rxon->flags |= il3945_get_antenna_flags(il);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001741
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001742 rc = il_check_rxon_cmd(il, ctx);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001743 if (rc) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001744 IL_ERR("Invalid RXON configuration. Not committing.\n");
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001745 return -EINVAL;
1746 }
1747
1748 /* If we don't need to send a full RXON, we can use
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001749 * il3945_rxon_assoc_cmd which is used to reconfigure filter
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001750 * and other flags for the current radio configuration. */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001751 if (!il_full_rxon_required(il,
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +01001752 &il->ctx)) {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001753 rc = il_send_rxon_assoc(il,
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +01001754 &il->ctx);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001755 if (rc) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001756 IL_ERR("Error setting RXON_ASSOC "
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001757 "configuration (%d).\n", rc);
1758 return rc;
1759 }
1760
1761 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
Stanislaw Gruszka17e859a2011-07-27 15:37:43 +02001762 /*
1763 * We do not commit tx power settings while channel changing,
1764 * do it now if tx power changed.
1765 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001766 il_set_tx_power(il, il->tx_power_next, false);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001767 return 0;
1768 }
1769
1770 /* If we are currently associated and the new config requires
1771 * an RXON_ASSOC and the new config wants the associated mask enabled,
1772 * we must clear the associated from the active configuration
1773 * before we apply the new config */
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +01001774 if (il_is_associated(il) && new_assoc) {
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001775 D_INFO("Toggling associated bit on current RXON\n");
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001776 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1777
1778 /*
1779 * reserved4 and 5 could have been filled by the iwlcore code.
1780 * Let's clear them before pushing to the 3945.
1781 */
1782 active_rxon->reserved4 = 0;
1783 active_rxon->reserved5 = 0;
Stanislaw Gruszka4d69c752011-08-30 15:26:35 +02001784 rc = il_send_cmd_pdu(il, C_RXON,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001785 sizeof(struct il3945_rxon_cmd),
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +01001786 &il->ctx.active);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001787
1788 /* If the mask clearing failed then we set
1789 * active_rxon back to what it was previously */
1790 if (rc) {
1791 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001792 IL_ERR("Error clearing ASSOC_MSK on current "
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001793 "configuration (%d).\n", rc);
1794 return rc;
1795 }
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001796 il_clear_ucode_stations(il,
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +01001797 &il->ctx);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001798 il_restore_stations(il,
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +01001799 &il->ctx);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001800 }
1801
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001802 D_INFO("Sending RXON\n"
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001803 "* with%s RXON_FILTER_ASSOC_MSK\n"
1804 "* channel = %d\n"
1805 "* bssid = %pM\n",
1806 (new_assoc ? "" : "out"),
1807 le16_to_cpu(staging_rxon->channel),
1808 staging_rxon->bssid_addr);
1809
1810 /*
1811 * reserved4 and 5 could have been filled by the iwlcore code.
1812 * Let's clear them before pushing to the 3945.
1813 */
1814 staging_rxon->reserved4 = 0;
1815 staging_rxon->reserved5 = 0;
1816
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001817 il_set_rxon_hwcrypto(il, ctx, !il3945_mod_params.sw_crypto);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001818
1819 /* Apply the new configuration */
Stanislaw Gruszka4d69c752011-08-30 15:26:35 +02001820 rc = il_send_cmd_pdu(il, C_RXON,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001821 sizeof(struct il3945_rxon_cmd),
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001822 staging_rxon);
1823 if (rc) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001824 IL_ERR("Error setting new configuration (%d).\n", rc);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001825 return rc;
1826 }
1827
1828 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
1829
Reinette Chatre7e246192010-02-18 22:58:32 -08001830 if (!new_assoc) {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001831 il_clear_ucode_stations(il,
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +01001832 &il->ctx);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001833 il_restore_stations(il,
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +01001834 &il->ctx);
Reinette Chatre7e246192010-02-18 22:58:32 -08001835 }
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001836
1837 /* If we issue a new RXON command which required a tune then we must
1838 * send a new TXPOWER command or we won't be able to Tx any frames */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001839 rc = il_set_tx_power(il, il->tx_power_next, true);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001840 if (rc) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001841 IL_ERR("Error setting Tx power (%d).\n", rc);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001842 return rc;
1843 }
1844
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001845 /* Init the hardware's rate fallback order based on the band */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001846 rc = il3945_init_hw_rate_table(il);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001847 if (rc) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02001848 IL_ERR("Error setting HW rate table: %02X\n", rc);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001849 return -EIO;
1850 }
1851
1852 return 0;
1853}
1854
Zhu Yib481de92007-09-25 17:54:57 -07001855/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001856 * il3945_reg_txpower_periodic - called when time to check our temperature.
Zhu Yib481de92007-09-25 17:54:57 -07001857 *
1858 * -- reset periodic timer
1859 * -- see if temp has changed enough to warrant re-calibration ... if so:
1860 * -- correct coeffs for temp (can reset temp timer)
1861 * -- save this temp as "last",
1862 * -- send new set of gain settings to NIC
1863 * NOTE: This should continue working, even when we're not associated,
1864 * so we can keep our internal table of scan powers current. */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001865void il3945_reg_txpower_periodic(struct il_priv *il)
Zhu Yib481de92007-09-25 17:54:57 -07001866{
1867 /* This will kick in the "brute force"
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001868 * il3945_hw_reg_comp_txpower_temp() below */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001869 if (!il3945_is_temp_calib_needed(il))
Zhu Yib481de92007-09-25 17:54:57 -07001870 goto reschedule;
1871
1872 /* Set up a new set of temp-adjusted TxPowers, send to NIC.
1873 * This is based *only* on current temperature,
1874 * ignoring any previous power measurements */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001875 il3945_hw_reg_comp_txpower_temp(il);
Zhu Yib481de92007-09-25 17:54:57 -07001876
1877 reschedule:
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001878 queue_delayed_work(il->workqueue,
1879 &il->_3945.thermal_periodic, REG_RECALIB_PERIOD * HZ);
Zhu Yib481de92007-09-25 17:54:57 -07001880}
1881
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001882static void il3945_bg_reg_txpower_periodic(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07001883{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001884 struct il_priv *il = container_of(work, struct il_priv,
Johannes Bergee525d12010-01-21 06:09:28 -08001885 _3945.thermal_periodic.work);
Zhu Yib481de92007-09-25 17:54:57 -07001886
Stanislaw Gruszkaa6766cc2011-11-15 13:09:01 +01001887 if (test_bit(S_EXIT_PENDING, &il->status))
Zhu Yib481de92007-09-25 17:54:57 -07001888 return;
1889
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001890 mutex_lock(&il->mutex);
1891 il3945_reg_txpower_periodic(il);
1892 mutex_unlock(&il->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07001893}
1894
1895/**
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001896 * il3945_hw_reg_get_ch_grp_idx - find the channel-group idx (0-4)
Zhu Yib481de92007-09-25 17:54:57 -07001897 * for the channel.
1898 *
1899 * This function is used when initializing channel-info structs.
1900 *
1901 * NOTE: These channel groups do *NOT* match the bands above!
1902 * These channel groups are based on factory-tested channels;
1903 * on A-band, EEPROM's "group frequency" entries represent the top
1904 * channel in each group 1-4. Group 5 All B/G channels are in group 0.
1905 */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001906static u16 il3945_hw_reg_get_ch_grp_idx(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001907 const struct il_channel_info *ch_info)
Zhu Yib481de92007-09-25 17:54:57 -07001908{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001909 struct il3945_eeprom *eeprom = (struct il3945_eeprom *)il->eeprom;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001910 struct il3945_eeprom_txpower_group *ch_grp = &eeprom->groups[0];
Zhu Yib481de92007-09-25 17:54:57 -07001911 u8 group;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001912 u16 group_idx = 0; /* based on factory calib frequencies */
Zhu Yib481de92007-09-25 17:54:57 -07001913 u8 grp_channel;
1914
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001915 /* Find the group idx for the channel ... don't use idx 1(?) */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001916 if (il_is_channel_a_band(ch_info)) {
Zhu Yib481de92007-09-25 17:54:57 -07001917 for (group = 1; group < 5; group++) {
1918 grp_channel = ch_grp[group].group_channel;
1919 if (ch_info->channel <= grp_channel) {
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001920 group_idx = group;
Zhu Yib481de92007-09-25 17:54:57 -07001921 break;
1922 }
1923 }
1924 /* group 4 has a few channels *above* its factory cal freq */
1925 if (group == 5)
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001926 group_idx = 4;
Zhu Yib481de92007-09-25 17:54:57 -07001927 } else
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001928 group_idx = 0; /* 2.4 GHz, group 0 */
Zhu Yib481de92007-09-25 17:54:57 -07001929
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001930 D_POWER("Chnl %d mapped to grp %d\n", ch_info->channel,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001931 group_idx);
1932 return group_idx;
Zhu Yib481de92007-09-25 17:54:57 -07001933}
1934
1935/**
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001936 * il3945_hw_reg_get_matched_power_idx - Interpolate to get nominal idx
Zhu Yib481de92007-09-25 17:54:57 -07001937 *
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001938 * Interpolate to get nominal (i.e. at factory calibration temperature) idx
Zhu Yib481de92007-09-25 17:54:57 -07001939 * into radio/DSP gain settings table for requested power.
1940 */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001941static int il3945_hw_reg_get_matched_power_idx(struct il_priv *il,
Zhu Yib481de92007-09-25 17:54:57 -07001942 s8 requested_power,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001943 s32 setting_idx, s32 *new_idx)
Zhu Yib481de92007-09-25 17:54:57 -07001944{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001945 const struct il3945_eeprom_txpower_group *chnl_grp = NULL;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001946 struct il3945_eeprom *eeprom = (struct il3945_eeprom *)il->eeprom;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001947 s32 idx0, idx1;
Zhu Yib481de92007-09-25 17:54:57 -07001948 s32 power = 2 * requested_power;
1949 s32 i;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001950 const struct il3945_eeprom_txpower_sample *samples;
Zhu Yib481de92007-09-25 17:54:57 -07001951 s32 gains0, gains1;
1952 s32 res;
1953 s32 denominator;
1954
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001955 chnl_grp = &eeprom->groups[setting_idx];
Zhu Yib481de92007-09-25 17:54:57 -07001956 samples = chnl_grp->samples;
1957 for (i = 0; i < 5; i++) {
1958 if (power == samples[i].power) {
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001959 *new_idx = samples[i].gain_idx;
Zhu Yib481de92007-09-25 17:54:57 -07001960 return 0;
1961 }
1962 }
1963
1964 if (power > samples[1].power) {
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001965 idx0 = 0;
1966 idx1 = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001967 } else if (power > samples[2].power) {
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001968 idx0 = 1;
1969 idx1 = 2;
Zhu Yib481de92007-09-25 17:54:57 -07001970 } else if (power > samples[3].power) {
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001971 idx0 = 2;
1972 idx1 = 3;
Zhu Yib481de92007-09-25 17:54:57 -07001973 } else {
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001974 idx0 = 3;
1975 idx1 = 4;
Zhu Yib481de92007-09-25 17:54:57 -07001976 }
1977
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001978 denominator = (s32) samples[idx1].power - (s32) samples[idx0].power;
Zhu Yib481de92007-09-25 17:54:57 -07001979 if (denominator == 0)
1980 return -EINVAL;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001981 gains0 = (s32) samples[idx0].gain_idx * (1 << 19);
1982 gains1 = (s32) samples[idx1].gain_idx * (1 << 19);
Zhu Yib481de92007-09-25 17:54:57 -07001983 res = gains0 + (gains1 - gains0) *
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001984 ((s32) power - (s32) samples[idx0].power) / denominator +
Zhu Yib481de92007-09-25 17:54:57 -07001985 (1 << 18);
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001986 *new_idx = res >> 19;
Zhu Yib481de92007-09-25 17:54:57 -07001987 return 0;
1988}
1989
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001990static void il3945_hw_reg_init_channel_groups(struct il_priv *il)
Zhu Yib481de92007-09-25 17:54:57 -07001991{
1992 u32 i;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01001993 s32 rate_idx;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02001994 struct il3945_eeprom *eeprom = (struct il3945_eeprom *)il->eeprom;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001995 const struct il3945_eeprom_txpower_group *group;
Zhu Yib481de92007-09-25 17:54:57 -07001996
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01001997 D_POWER("Initializing factory calib info from EEPROM\n");
Zhu Yib481de92007-09-25 17:54:57 -07001998
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02001999 for (i = 0; i < IL_NUM_TX_CALIB_GROUPS; i++) {
Zhu Yib481de92007-09-25 17:54:57 -07002000 s8 *clip_pwrs; /* table of power levels for each rate */
2001 s8 satur_pwr; /* saturation power for each chnl group */
Samuel Ortize6148912009-01-23 13:45:15 -08002002 group = &eeprom->groups[i];
Zhu Yib481de92007-09-25 17:54:57 -07002003
2004 /* sanity check on factory saturation power value */
2005 if (group->saturation_power < 40) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02002006 IL_WARN("Error: saturation power is %d, "
Zhu Yib481de92007-09-25 17:54:57 -07002007 "less than minimum expected 40\n",
2008 group->saturation_power);
2009 return;
2010 }
2011
2012 /*
2013 * Derive requested power levels for each rate, based on
2014 * hardware capabilities (saturation power for band).
2015 * Basic value is 3dB down from saturation, with further
2016 * power reductions for highest 3 data rates. These
2017 * backoffs provide headroom for high rate modulation
2018 * power peaks, without too much distortion (clipping).
2019 */
2020 /* we'll fill in this array with h/w max power levels */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002021 clip_pwrs = (s8 *) il->_3945.clip_groups[i].clip_powers;
Zhu Yib481de92007-09-25 17:54:57 -07002022
2023 /* divide factory saturation power by 2 to find -3dB level */
2024 satur_pwr = (s8) (group->saturation_power >> 1);
2025
2026 /* fill in channel group's nominal powers for each rate */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002027 for (rate_idx = 0;
2028 rate_idx < RATE_COUNT_3945; rate_idx++, clip_pwrs++) {
2029 switch (rate_idx) {
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02002030 case RATE_36M_IDX_TBL:
Zhu Yib481de92007-09-25 17:54:57 -07002031 if (i == 0) /* B/G */
2032 *clip_pwrs = satur_pwr;
2033 else /* A */
2034 *clip_pwrs = satur_pwr - 5;
2035 break;
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02002036 case RATE_48M_IDX_TBL:
Zhu Yib481de92007-09-25 17:54:57 -07002037 if (i == 0)
2038 *clip_pwrs = satur_pwr - 7;
2039 else
2040 *clip_pwrs = satur_pwr - 10;
2041 break;
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02002042 case RATE_54M_IDX_TBL:
Zhu Yib481de92007-09-25 17:54:57 -07002043 if (i == 0)
2044 *clip_pwrs = satur_pwr - 9;
2045 else
2046 *clip_pwrs = satur_pwr - 12;
2047 break;
2048 default:
2049 *clip_pwrs = satur_pwr;
2050 break;
2051 }
2052 }
2053 }
2054}
2055
2056/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002057 * il3945_txpower_set_from_eeprom - Set channel power info based on EEPROM
Zhu Yib481de92007-09-25 17:54:57 -07002058 *
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002059 * Second pass (during init) to set up il->channel_info
Zhu Yib481de92007-09-25 17:54:57 -07002060 *
2061 * Set up Tx-power settings in our channel info database for each VALID
2062 * (for this geo/SKU) channel, at all Tx data rates, based on eeprom values
2063 * and current temperature.
2064 *
2065 * Since this is based on current temperature (at init time), these values may
2066 * not be valid for very long, but it gives us a starting/default point,
2067 * and allows us to active (i.e. using Tx) scan.
2068 *
2069 * This does *not* write values to NIC, just sets up our internal table.
2070 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002071int il3945_txpower_set_from_eeprom(struct il_priv *il)
Zhu Yib481de92007-09-25 17:54:57 -07002072{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002073 struct il_channel_info *ch_info = NULL;
2074 struct il3945_channel_power_info *pwr_info;
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002075 struct il3945_eeprom *eeprom = (struct il3945_eeprom *)il->eeprom;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002076 int delta_idx;
2077 u8 rate_idx;
2078 u8 scan_tbl_idx;
Zhu Yib481de92007-09-25 17:54:57 -07002079 const s8 *clip_pwrs; /* array of power levels for each rate */
2080 u8 gain, dsp_atten;
2081 s8 power;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002082 u8 pwr_idx, base_pwr_idx, a_band;
Zhu Yib481de92007-09-25 17:54:57 -07002083 u8 i;
2084 int temperature;
2085
2086 /* save temperature reference,
2087 * so we can determine next time to calibrate */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002088 temperature = il3945_hw_reg_txpower_get_temperature(il);
2089 il->last_temperature = temperature;
Zhu Yib481de92007-09-25 17:54:57 -07002090
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002091 il3945_hw_reg_init_channel_groups(il);
Zhu Yib481de92007-09-25 17:54:57 -07002092
2093 /* initialize Tx power info for each and every channel, 2.4 and 5.x */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002094 for (i = 0, ch_info = il->channel_info; i < il->channel_count;
Zhu Yib481de92007-09-25 17:54:57 -07002095 i++, ch_info++) {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002096 a_band = il_is_channel_a_band(ch_info);
2097 if (!il_is_channel_valid(ch_info))
Zhu Yib481de92007-09-25 17:54:57 -07002098 continue;
2099
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002100 /* find this channel's channel group (*not* "band") idx */
2101 ch_info->group_idx =
2102 il3945_hw_reg_get_ch_grp_idx(il, ch_info);
Zhu Yib481de92007-09-25 17:54:57 -07002103
2104 /* Get this chnlgrp's rate->max/clip-powers table */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002105 clip_pwrs = il->_3945.clip_groups[ch_info->group_idx].clip_powers;
Zhu Yib481de92007-09-25 17:54:57 -07002106
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002107 /* calculate power idx *adjustment* value according to
Zhu Yib481de92007-09-25 17:54:57 -07002108 * diff between current temperature and factory temperature */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002109 delta_idx = il3945_hw_reg_adjust_power_by_temp(temperature,
2110 eeprom->groups[ch_info->group_idx].
Zhu Yib481de92007-09-25 17:54:57 -07002111 temperature);
2112
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002113 D_POWER("Delta idx for channel %d: %d [%d]\n",
2114 ch_info->channel, delta_idx, temperature +
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002115 IL_TEMP_CONVERT);
Zhu Yib481de92007-09-25 17:54:57 -07002116
2117 /* set tx power value for all OFDM rates */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002118 for (rate_idx = 0; rate_idx < IL_OFDM_RATES;
2119 rate_idx++) {
John W. Linville25a4cce2009-01-12 14:44:52 -05002120 s32 uninitialized_var(power_idx);
Zhu Yib481de92007-09-25 17:54:57 -07002121 int rc;
2122
2123 /* use channel group's clip-power table,
2124 * but don't exceed channel's max power */
2125 s8 pwr = min(ch_info->max_power_avg,
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002126 clip_pwrs[rate_idx]);
Zhu Yib481de92007-09-25 17:54:57 -07002127
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002128 pwr_info = &ch_info->power_info[rate_idx];
Zhu Yib481de92007-09-25 17:54:57 -07002129
2130 /* get base (i.e. at factory-measured temperature)
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002131 * power table idx for this rate's power */
2132 rc = il3945_hw_reg_get_matched_power_idx(il, pwr,
2133 ch_info->group_idx,
Zhu Yib481de92007-09-25 17:54:57 -07002134 &power_idx);
2135 if (rc) {
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002136 IL_ERR("Invalid power idx\n");
Zhu Yib481de92007-09-25 17:54:57 -07002137 return rc;
2138 }
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002139 pwr_info->base_power_idx = (u8) power_idx;
Zhu Yib481de92007-09-25 17:54:57 -07002140
2141 /* temperature compensate */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002142 power_idx += delta_idx;
Zhu Yib481de92007-09-25 17:54:57 -07002143
2144 /* stay within range of gain table */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002145 power_idx = il3945_hw_reg_fix_power_idx(power_idx);
Zhu Yib481de92007-09-25 17:54:57 -07002146
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002147 /* fill 1 OFDM rate's il3945_channel_power_info struct */
Zhu Yib481de92007-09-25 17:54:57 -07002148 pwr_info->requested_power = pwr;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002149 pwr_info->power_table_idx = (u8) power_idx;
Zhu Yib481de92007-09-25 17:54:57 -07002150 pwr_info->tpc.tx_gain =
2151 power_gain_table[a_band][power_idx].tx_gain;
2152 pwr_info->tpc.dsp_atten =
2153 power_gain_table[a_band][power_idx].dsp_atten;
2154 }
2155
2156 /* set tx power for CCK rates, based on OFDM 12 Mbit settings*/
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02002157 pwr_info = &ch_info->power_info[RATE_12M_IDX_TBL];
Zhu Yib481de92007-09-25 17:54:57 -07002158 power = pwr_info->requested_power +
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002159 IL_CCK_FROM_OFDM_POWER_DIFF;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002160 pwr_idx = pwr_info->power_table_idx +
Stanislaw Gruszka2d09b062011-08-26 16:10:40 +02002161 IL_CCK_FROM_OFDM_IDX_DIFF;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002162 base_pwr_idx = pwr_info->base_power_idx +
Stanislaw Gruszka2d09b062011-08-26 16:10:40 +02002163 IL_CCK_FROM_OFDM_IDX_DIFF;
Zhu Yib481de92007-09-25 17:54:57 -07002164
2165 /* stay within table range */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002166 pwr_idx = il3945_hw_reg_fix_power_idx(pwr_idx);
2167 gain = power_gain_table[a_band][pwr_idx].tx_gain;
2168 dsp_atten = power_gain_table[a_band][pwr_idx].dsp_atten;
Zhu Yib481de92007-09-25 17:54:57 -07002169
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002170 /* fill each CCK rate's il3945_channel_power_info structure
Zhu Yib481de92007-09-25 17:54:57 -07002171 * NOTE: All CCK-rate Txpwrs are the same for a given chnl!
2172 * NOTE: CCK rates start at end of OFDM rates! */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002173 for (rate_idx = 0;
2174 rate_idx < IL_CCK_RATES; rate_idx++) {
2175 pwr_info = &ch_info->power_info[rate_idx+IL_OFDM_RATES];
Zhu Yib481de92007-09-25 17:54:57 -07002176 pwr_info->requested_power = power;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002177 pwr_info->power_table_idx = pwr_idx;
2178 pwr_info->base_power_idx = base_pwr_idx;
Zhu Yib481de92007-09-25 17:54:57 -07002179 pwr_info->tpc.tx_gain = gain;
2180 pwr_info->tpc.dsp_atten = dsp_atten;
2181 }
2182
2183 /* set scan tx power, 1Mbit for CCK, 6Mbit for OFDM */
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002184 for (scan_tbl_idx = 0;
2185 scan_tbl_idx < IL_NUM_SCAN_RATES; scan_tbl_idx++) {
2186 s32 actual_idx = (scan_tbl_idx == 0) ?
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02002187 RATE_1M_IDX_TBL : RATE_6M_IDX_TBL;
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002188 il3945_hw_reg_set_scan_power(il, scan_tbl_idx,
2189 actual_idx, clip_pwrs, ch_info, a_band);
Zhu Yib481de92007-09-25 17:54:57 -07002190 }
2191 }
2192
2193 return 0;
2194}
2195
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002196int il3945_hw_rxq_stop(struct il_priv *il)
Zhu Yib481de92007-09-25 17:54:57 -07002197{
2198 int rc;
Zhu Yib481de92007-09-25 17:54:57 -07002199
Stanislaw Gruszka0c1a94e2011-08-24 17:37:16 +02002200 il_wr(il, FH39_RCSR_CONFIG(0), 0);
2201 rc = il_poll_bit(il, FH39_RSSR_STATUS,
Tomas Winklerbddadf82008-12-19 10:37:01 +08002202 FH39_RSSR_CHNL0_RX_STATUS_CHNL_IDLE, 1000);
Zhu Yib481de92007-09-25 17:54:57 -07002203 if (rc < 0)
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02002204 IL_ERR("Can't stop Rx DMA.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002205
Zhu Yib481de92007-09-25 17:54:57 -07002206 return 0;
2207}
2208
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002209int il3945_hw_tx_queue_init(struct il_priv *il, struct il_tx_queue *txq)
Zhu Yib481de92007-09-25 17:54:57 -07002210{
Zhu Yib481de92007-09-25 17:54:57 -07002211 int txq_id = txq->q.id;
2212
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002213 struct il3945_shared *shared_data = il->_3945.shared_virt;
Zhu Yib481de92007-09-25 17:54:57 -07002214
2215 shared_data->tx_base_ptr[txq_id] = cpu_to_le32((u32)txq->q.dma_addr);
2216
Stanislaw Gruszka0c1a94e2011-08-24 17:37:16 +02002217 il_wr(il, FH39_CBCC_CTRL(txq_id), 0);
2218 il_wr(il, FH39_CBCC_BASE(txq_id), 0);
Zhu Yib481de92007-09-25 17:54:57 -07002219
Stanislaw Gruszka0c1a94e2011-08-24 17:37:16 +02002220 il_wr(il, FH39_TCSR_CONFIG(txq_id),
Tomas Winklerbddadf82008-12-19 10:37:01 +08002221 FH39_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_NOINT |
2222 FH39_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_TXF |
2223 FH39_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_IFTFD |
2224 FH39_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL |
2225 FH39_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE);
Zhu Yib481de92007-09-25 17:54:57 -07002226
2227 /* fake read to flush all prev. writes */
Stanislaw Gruszka841b2cc2011-08-24 15:14:03 +02002228 _il_rd(il, FH39_TSSR_CBB_BASE);
Zhu Yib481de92007-09-25 17:54:57 -07002229
2230 return 0;
2231}
2232
Kolekar, Abhijeet42427b42008-12-22 11:31:15 +08002233/*
2234 * HCMD utils
2235 */
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002236static u16 il3945_get_hcmd_size(u8 cmd_id, u16 len)
Kolekar, Abhijeet42427b42008-12-22 11:31:15 +08002237{
2238 switch (cmd_id) {
Stanislaw Gruszka4d69c752011-08-30 15:26:35 +02002239 case C_RXON:
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002240 return sizeof(struct il3945_rxon_cmd);
Stanislaw Gruszka4d69c752011-08-30 15:26:35 +02002241 case C_POWER_TBL:
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002242 return sizeof(struct il3945_powertable_cmd);
Kolekar, Abhijeet42427b42008-12-22 11:31:15 +08002243 default:
2244 return len;
2245 }
2246}
2247
Tomas Winklerc587de02009-06-03 11:44:07 -07002248
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002249static u16 il3945_build_addsta_hcmd(const struct il_addsta_cmd *cmd,
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08002250 u8 *data)
Samuel Ortiz17f841c2009-01-23 13:45:20 -08002251{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002252 struct il3945_addsta_cmd *addsta = (struct il3945_addsta_cmd *)data;
Tomas Winklerc587de02009-06-03 11:44:07 -07002253 addsta->mode = cmd->mode;
2254 memcpy(&addsta->sta, &cmd->sta, sizeof(struct sta_id_modify));
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002255 memcpy(&addsta->key, &cmd->key, sizeof(struct il4965_keyinfo));
Tomas Winklerc587de02009-06-03 11:44:07 -07002256 addsta->station_flags = cmd->station_flags;
2257 addsta->station_flags_msk = cmd->station_flags_msk;
2258 addsta->tid_disable_tx = cpu_to_le16(0);
2259 addsta->rate_n_flags = cmd->rate_n_flags;
2260 addsta->add_immediate_ba_tid = cmd->add_immediate_ba_tid;
2261 addsta->remove_immediate_ba_tid = cmd->remove_immediate_ba_tid;
2262 addsta->add_immediate_ba_ssn = cmd->add_immediate_ba_ssn;
2263
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002264 return (u16)sizeof(struct il3945_addsta_cmd);
Samuel Ortiz17f841c2009-01-23 13:45:20 -08002265}
2266
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002267static int il3945_add_bssid_station(struct il_priv *il,
Johannes Berga30e3112010-09-22 18:02:01 +02002268 const u8 *addr, u8 *sta_id_r)
2269{
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +01002270 struct il_rxon_context *ctx = &il->ctx;
Johannes Berga30e3112010-09-22 18:02:01 +02002271 int ret;
2272 u8 sta_id;
2273 unsigned long flags;
2274
2275 if (sta_id_r)
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002276 *sta_id_r = IL_INVALID_STATION;
Johannes Berga30e3112010-09-22 18:02:01 +02002277
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002278 ret = il_add_station_common(il, ctx, addr, 0, NULL, &sta_id);
Johannes Berga30e3112010-09-22 18:02:01 +02002279 if (ret) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02002280 IL_ERR("Unable to add station %pM\n", addr);
Johannes Berga30e3112010-09-22 18:02:01 +02002281 return ret;
2282 }
2283
2284 if (sta_id_r)
2285 *sta_id_r = sta_id;
2286
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002287 spin_lock_irqsave(&il->sta_lock, flags);
2288 il->stations[sta_id].used |= IL_STA_LOCAL;
2289 spin_unlock_irqrestore(&il->sta_lock, flags);
Johannes Berga30e3112010-09-22 18:02:01 +02002290
2291 return 0;
2292}
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002293static int il3945_manage_ibss_station(struct il_priv *il,
Johannes Berg1fa61b22010-04-28 08:44:52 -07002294 struct ieee80211_vif *vif, bool add)
2295{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002296 struct il_vif_priv *vif_priv = (void *)vif->drv_priv;
Johannes Berg1fa61b22010-04-28 08:44:52 -07002297 int ret;
2298
Johannes Berg1fa61b22010-04-28 08:44:52 -07002299 if (add) {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002300 ret = il3945_add_bssid_station(il, vif->bss_conf.bssid,
Johannes Berga30e3112010-09-22 18:02:01 +02002301 &vif_priv->ibss_bssid_sta_id);
Johannes Berg1fa61b22010-04-28 08:44:52 -07002302 if (ret)
2303 return ret;
2304
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002305 il3945_sync_sta(il, vif_priv->ibss_bssid_sta_id,
2306 (il->band == IEEE80211_BAND_5GHZ) ?
Stanislaw Gruszka2eb05812011-08-26 16:07:43 +02002307 RATE_6M_PLCP : RATE_1M_PLCP);
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002308 il3945_rate_scale_init(il->hw, vif_priv->ibss_bssid_sta_id);
Johannes Berg1fa61b22010-04-28 08:44:52 -07002309
2310 return 0;
2311 }
2312
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002313 return il_remove_station(il, vif_priv->ibss_bssid_sta_id,
Johannes Bergfd1af152010-04-30 11:30:43 -07002314 vif->bss_conf.bssid);
Johannes Berg1fa61b22010-04-28 08:44:52 -07002315}
Tomas Winklerc587de02009-06-03 11:44:07 -07002316
Zhu Yib481de92007-09-25 17:54:57 -07002317/**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002318 * il3945_init_hw_rate_table - Initialize the hardware rate fallback table
Zhu Yib481de92007-09-25 17:54:57 -07002319 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002320int il3945_init_hw_rate_table(struct il_priv *il)
Zhu Yib481de92007-09-25 17:54:57 -07002321{
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002322 int rc, i, idx, prev_idx;
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002323 struct il3945_rate_scaling_cmd rate_cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07002324 .reserved = {0, 0, 0},
2325 };
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002326 struct il3945_rate_scaling_info *table = rate_cmd.table;
Zhu Yib481de92007-09-25 17:54:57 -07002327
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002328 for (i = 0; i < ARRAY_SIZE(il3945_rates); i++) {
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002329 idx = il3945_rates[i].table_rs_idx;
Mohamed Abbas14577f22007-11-12 11:37:42 +08002330
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002331 table[idx].rate_n_flags =
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002332 il3945_hw_set_rate_n_flags(il3945_rates[i].plcp, 0);
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002333 table[idx].try_cnt = il->retry_rate;
2334 prev_idx = il3945_get_prev_ieee_rate(i);
2335 table[idx].next_rate_idx =
2336 il3945_rates[prev_idx].table_rs_idx;
Zhu Yib481de92007-09-25 17:54:57 -07002337 }
2338
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002339 switch (il->band) {
Johannes Berg8318d782008-01-24 19:38:38 +01002340 case IEEE80211_BAND_5GHZ:
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002341 D_RATE("Select A mode rate scale\n");
Zhu Yib481de92007-09-25 17:54:57 -07002342 /* If one of the following CCK rates is used,
2343 * have it fall back to the 6M OFDM rate */
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02002344 for (i = RATE_1M_IDX_TBL;
2345 i <= RATE_11M_IDX_TBL; i++)
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002346 table[i].next_rate_idx =
2347 il3945_rates[IL_FIRST_OFDM_RATE].table_rs_idx;
Zhu Yib481de92007-09-25 17:54:57 -07002348
2349 /* Don't fall back to CCK rates */
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02002350 table[RATE_12M_IDX_TBL].next_rate_idx =
2351 RATE_9M_IDX_TBL;
Zhu Yib481de92007-09-25 17:54:57 -07002352
2353 /* Don't drop out of OFDM rates */
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02002354 table[RATE_6M_IDX_TBL].next_rate_idx =
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002355 il3945_rates[IL_FIRST_OFDM_RATE].table_rs_idx;
Zhu Yib481de92007-09-25 17:54:57 -07002356 break;
2357
Johannes Berg8318d782008-01-24 19:38:38 +01002358 case IEEE80211_BAND_2GHZ:
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002359 D_RATE("Select B/G mode rate scale\n");
Zhu Yib481de92007-09-25 17:54:57 -07002360 /* If an OFDM rate is used, have it fall back to the
2361 * 1M CCK rates */
Zhu Yib481de92007-09-25 17:54:57 -07002362
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002363 if (!(il->_3945.sta_supp_rates & IL_OFDM_RATES_MASK) &&
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +01002364 il_is_associated(il)) {
Abbas, Mohamed72627962008-12-05 07:58:37 -08002365
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002366 idx = IL_FIRST_CCK_RATE;
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02002367 for (i = RATE_6M_IDX_TBL;
2368 i <= RATE_54M_IDX_TBL; i++)
Stanislaw Gruszka0c2c8852011-11-15 12:30:17 +01002369 table[i].next_rate_idx =
2370 il3945_rates[idx].table_rs_idx;
Abbas, Mohamed72627962008-12-05 07:58:37 -08002371
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02002372 idx = RATE_11M_IDX_TBL;
Abbas, Mohamed72627962008-12-05 07:58:37 -08002373 /* CCK shouldn't fall back to OFDM... */
Stanislaw Gruszka3b98c7f2011-08-26 16:29:35 +02002374 table[idx].next_rate_idx = RATE_5M_IDX_TBL;
Abbas, Mohamed72627962008-12-05 07:58:37 -08002375 }
Zhu Yib481de92007-09-25 17:54:57 -07002376 break;
2377
2378 default:
Johannes Berg8318d782008-01-24 19:38:38 +01002379 WARN_ON(1);
Zhu Yib481de92007-09-25 17:54:57 -07002380 break;
2381 }
2382
2383 /* Update the rate scaling for control frame Tx */
2384 rate_cmd.table_id = 0;
Stanislaw Gruszka4d69c752011-08-30 15:26:35 +02002385 rc = il_send_cmd_pdu(il, C_RATE_SCALE, sizeof(rate_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07002386 &rate_cmd);
2387 if (rc)
2388 return rc;
2389
2390 /* Update the rate scaling for data frame Tx */
2391 rate_cmd.table_id = 1;
Stanislaw Gruszka4d69c752011-08-30 15:26:35 +02002392 return il_send_cmd_pdu(il, C_RATE_SCALE, sizeof(rate_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07002393 &rate_cmd);
2394}
2395
Ben Cahill796083c2007-11-29 11:09:45 +08002396/* Called when initializing driver */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002397int il3945_hw_set_hw_params(struct il_priv *il)
Zhu Yib481de92007-09-25 17:54:57 -07002398{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002399 memset((void *)&il->hw_params, 0,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002400 sizeof(struct il_hw_params));
Zhu Yib481de92007-09-25 17:54:57 -07002401
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002402 il->_3945.shared_virt =
2403 dma_alloc_coherent(&il->pci_dev->dev,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002404 sizeof(struct il3945_shared),
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002405 &il->_3945.shared_phys, GFP_KERNEL);
2406 if (!il->_3945.shared_virt) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02002407 IL_ERR("failed to allocate pci memory\n");
Zhu Yib481de92007-09-25 17:54:57 -07002408 return -ENOMEM;
2409 }
2410
Abhijeet Kolekar21c02a12009-03-17 21:51:48 -07002411 /* Assign number of Usable TX queues */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002412 il->hw_params.max_txq_num = il->cfg->base_params->num_of_queues;
Abhijeet Kolekar21c02a12009-03-17 21:51:48 -07002413
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002414 il->hw_params.tfd_size = sizeof(struct il3945_tfd);
2415 il->hw_params.rx_page_order = get_order(IL_RX_BUF_SIZE_3K);
2416 il->hw_params.max_rxq_size = RX_QUEUE_SIZE;
2417 il->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
Stanislaw Gruszkad3175162011-11-15 11:25:42 +01002418 il->hw_params.max_stations = IL3945_STATION_COUNT;
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +01002419 il->ctx.bcast_sta_id = IL3945_BROADCAST_ID;
Tomas Winkler3e82a822008-02-13 11:32:31 -08002420
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002421 il->sta_key_max_num = STA_KEY_MAX_NUM;
Johannes Bergc10afb62010-08-23 10:46:43 +02002422
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002423 il->hw_params.rx_wrt_ptr_reg = FH39_RSCSR_CHNL0_WPTR;
Stanislaw Gruszkad3175162011-11-15 11:25:42 +01002424 il->hw_params.max_beacon_itrvl = IL39_MAX_UCODE_BEACON_INTERVAL;
2425 il->hw_params.beacon_time_tsf_bits = IL3945_EXT_BEACON_TIME_POS;
Winkler, Tomas141c43a2009-01-08 10:19:53 -08002426
Zhu Yib481de92007-09-25 17:54:57 -07002427 return 0;
2428}
2429
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002430unsigned int il3945_hw_get_beacon_cmd(struct il_priv *il,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002431 struct il3945_frame *frame, u8 rate)
Zhu Yib481de92007-09-25 17:54:57 -07002432{
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002433 struct il3945_tx_beacon_cmd *tx_beacon_cmd;
Zhu Yib481de92007-09-25 17:54:57 -07002434 unsigned int frame_size;
2435
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002436 tx_beacon_cmd = (struct il3945_tx_beacon_cmd *)&frame->u;
Zhu Yib481de92007-09-25 17:54:57 -07002437 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
2438
Johannes Berga194e322010-08-27 08:53:46 -07002439 tx_beacon_cmd->tx.sta_id =
Stanislaw Gruszka7c2cde22011-11-15 11:29:04 +01002440 il->ctx.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07002441 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
2442
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002443 frame_size = il3945_fill_beacon_frame(il,
Zhu Yib481de92007-09-25 17:54:57 -07002444 tx_beacon_cmd->frame,
Zhu Yib481de92007-09-25 17:54:57 -07002445 sizeof(frame->u) - sizeof(*tx_beacon_cmd));
2446
2447 BUG_ON(frame_size > MAX_MPDU_SIZE);
2448 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
2449
2450 tx_beacon_cmd->tx.rate = rate;
2451 tx_beacon_cmd->tx.tx_flags = (TX_CMD_FLG_SEQ_CTL_MSK |
2452 TX_CMD_FLG_TSF_MSK);
2453
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002454 /* supp_rates[0] == OFDM start at IL_FIRST_OFDM_RATE*/
Mohamed Abbas14577f22007-11-12 11:37:42 +08002455 tx_beacon_cmd->tx.supp_rates[0] =
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002456 (IL_OFDM_BASIC_RATES_MASK >> IL_FIRST_OFDM_RATE) & 0xFF;
Zhu Yib481de92007-09-25 17:54:57 -07002457
Zhu Yib481de92007-09-25 17:54:57 -07002458 tx_beacon_cmd->tx.supp_rates[1] =
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002459 (IL_CCK_BASIC_RATES_MASK & 0xF);
Zhu Yib481de92007-09-25 17:54:57 -07002460
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002461 return sizeof(struct il3945_tx_beacon_cmd) + frame_size;
Zhu Yib481de92007-09-25 17:54:57 -07002462}
2463
Stanislaw Gruszkad0c72342011-08-30 15:39:42 +02002464void il3945_hw_handler_setup(struct il_priv *il)
Zhu Yib481de92007-09-25 17:54:57 -07002465{
Stanislaw Gruszka6e9848b42011-08-30 15:45:31 +02002466 il->handlers[C_TX] = il3945_hdl_tx;
2467 il->handlers[N_3945_RX] = il3945_hdl_rx;
Zhu Yib481de92007-09-25 17:54:57 -07002468}
2469
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002470void il3945_hw_setup_deferred_work(struct il_priv *il)
Zhu Yib481de92007-09-25 17:54:57 -07002471{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002472 INIT_DELAYED_WORK(&il->_3945.thermal_periodic,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002473 il3945_bg_reg_txpower_periodic);
Zhu Yib481de92007-09-25 17:54:57 -07002474}
2475
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002476void il3945_hw_cancel_deferred_work(struct il_priv *il)
Zhu Yib481de92007-09-25 17:54:57 -07002477{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002478 cancel_delayed_work(&il->_3945.thermal_periodic);
Zhu Yib481de92007-09-25 17:54:57 -07002479}
2480
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002481/* check contents of special bootstrap uCode SRAM */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002482static int il3945_verify_bsm(struct il_priv *il)
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002483 {
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002484 __le32 *image = il->ucode_boot.v_addr;
2485 u32 len = il->ucode_boot.len;
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002486 u32 reg;
2487 u32 val;
2488
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002489 D_INFO("Begin verify bsm\n");
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002490
2491 /* verify BSM SRAM contents */
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +02002492 val = il_rd_prph(il, BSM_WR_DWCOUNT_REG);
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002493 for (reg = BSM_SRAM_LOWER_BOUND;
2494 reg < BSM_SRAM_LOWER_BOUND + len;
2495 reg += sizeof(u32), image++) {
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +02002496 val = il_rd_prph(il, reg);
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002497 if (val != le32_to_cpu(*image)) {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02002498 IL_ERR("BSM uCode verification failed at "
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002499 "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
2500 BSM_SRAM_LOWER_BOUND,
2501 reg - BSM_SRAM_LOWER_BOUND, len,
2502 val, le32_to_cpu(*image));
2503 return -EIO;
2504 }
2505 }
2506
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002507 D_INFO("BSM bootstrap uCode image OK\n");
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002508
2509 return 0;
2510}
2511
Samuel Ortize6148912009-01-23 13:45:15 -08002512
2513/******************************************************************************
2514 *
2515 * EEPROM related functions
2516 *
2517 ******************************************************************************/
2518
2519/*
2520 * Clear the OWNER_MSK, to establish driver (instead of uCode running on
2521 * embedded controller) as EEPROM reader; each read is a series of pulses
2522 * to/from the EEPROM chip, not a single event, so even reads could conflict
2523 * if they weren't arbitrated by some ownership mechanism. Here, the driver
2524 * simply claims ownership, which should be safe when this function is called
2525 * (i.e. before loading uCode!).
2526 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002527static int il3945_eeprom_acquire_semaphore(struct il_priv *il)
Samuel Ortize6148912009-01-23 13:45:15 -08002528{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002529 _il_clear_bit(il, CSR_EEPROM_GP, CSR_EEPROM_GP_IF_OWNER_MSK);
Samuel Ortize6148912009-01-23 13:45:15 -08002530 return 0;
2531}
2532
2533
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002534static void il3945_eeprom_release_semaphore(struct il_priv *il)
Samuel Ortize6148912009-01-23 13:45:15 -08002535{
2536 return;
2537}
2538
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002539 /**
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002540 * il3945_load_bsm - Load bootstrap instructions
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002541 *
2542 * BSM operation:
2543 *
2544 * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
2545 * in special SRAM that does not power down during RFKILL. When powering back
2546 * up after power-saving sleeps (or during initial uCode load), the BSM loads
2547 * the bootstrap program into the on-board processor, and starts it.
2548 *
2549 * The bootstrap program loads (via DMA) instructions and data for a new
2550 * program from host DRAM locations indicated by the host driver in the
2551 * BSM_DRAM_* registers. Once the new program is loaded, it starts
2552 * automatically.
2553 *
2554 * When initializing the NIC, the host driver points the BSM to the
2555 * "initialize" uCode image. This uCode sets up some internal data, then
2556 * notifies host via "initialize alive" that it is complete.
2557 *
2558 * The host then replaces the BSM_DRAM_* pointer values to point to the
2559 * normal runtime uCode instructions and a backup uCode data cache buffer
2560 * (filled initially with starting data values for the on-board processor),
2561 * then triggers the "initialize" uCode to load and launch the runtime uCode,
2562 * which begins normal operation.
2563 *
2564 * When doing a power-save shutdown, runtime uCode saves data SRAM into
2565 * the backup data cache in DRAM before SRAM is powered down.
2566 *
2567 * When powering back up, the BSM loads the bootstrap program. This reloads
2568 * the runtime uCode instructions and the backup data cache into SRAM,
2569 * and re-launches the runtime uCode from where it left off.
2570 */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002571static int il3945_load_bsm(struct il_priv *il)
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002572{
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002573 __le32 *image = il->ucode_boot.v_addr;
2574 u32 len = il->ucode_boot.len;
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002575 dma_addr_t pinst;
2576 dma_addr_t pdata;
2577 u32 inst_len;
2578 u32 data_len;
2579 int rc;
2580 int i;
2581 u32 done;
2582 u32 reg_offset;
2583
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002584 D_INFO("Begin load bsm\n");
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002585
2586 /* make sure bootstrap program is no larger than BSM's SRAM size */
Stanislaw Gruszkad3175162011-11-15 11:25:42 +01002587 if (len > IL39_MAX_BSM_SIZE)
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002588 return -EINVAL;
2589
2590 /* Tell bootstrap uCode where to find the "Initialize" uCode
2591 * in host DRAM ... host DRAM physical address bits 31:0 for 3945.
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002592 * NOTE: il3945_initialize_alive_start() will replace these values,
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002593 * after the "initialize" uCode has run, to point to
2594 * runtime/protocol instructions and backup data cache. */
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002595 pinst = il->ucode_init.p_addr;
2596 pdata = il->ucode_init_data.p_addr;
2597 inst_len = il->ucode_init.len;
2598 data_len = il->ucode_init_data.len;
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002599
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +02002600 il_wr_prph(il, BSM_DRAM_INST_PTR_REG, pinst);
2601 il_wr_prph(il, BSM_DRAM_DATA_PTR_REG, pdata);
2602 il_wr_prph(il, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
2603 il_wr_prph(il, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002604
2605 /* Fill BSM memory with bootstrap instructions */
2606 for (reg_offset = BSM_SRAM_LOWER_BOUND;
2607 reg_offset < BSM_SRAM_LOWER_BOUND + len;
2608 reg_offset += sizeof(u32), image++)
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +02002609 _il_wr_prph(il, reg_offset,
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002610 le32_to_cpu(*image));
2611
Stanislaw Gruszka46bc8d42011-10-24 16:49:25 +02002612 rc = il3945_verify_bsm(il);
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07002613 if (rc)
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002614 return rc;
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002615
2616 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +02002617 il_wr_prph(il, BSM_WR_MEM_SRC_REG, 0x0);
2618 il_wr_prph(il, BSM_WR_MEM_DST_REG,
Stanislaw Gruszkad3175162011-11-15 11:25:42 +01002619 IL39_RTC_INST_LOWER_BOUND);
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +02002620 il_wr_prph(il, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002621
2622 /* Load bootstrap code into instruction SRAM now,
2623 * to prepare to load "initialize" uCode */
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +02002624 il_wr_prph(il, BSM_WR_CTRL_REG,
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002625 BSM_WR_CTRL_REG_BIT_START);
2626
2627 /* Wait for load of bootstrap uCode to finish */
2628 for (i = 0; i < 100; i++) {
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +02002629 done = il_rd_prph(il, BSM_WR_CTRL_REG);
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002630 if (!(done & BSM_WR_CTRL_REG_BIT_START))
2631 break;
2632 udelay(10);
2633 }
2634 if (i < 100)
Stanislaw Gruszka58de00a2011-11-15 11:21:01 +01002635 D_INFO("BSM write complete, poll %d iterations\n", i);
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002636 else {
Stanislaw Gruszka9406f792011-08-18 22:07:57 +02002637 IL_ERR("BSM write did not complete!\n");
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002638 return -EIO;
2639 }
2640
2641 /* Enable future boot loads whenever power management unit triggers it
2642 * (e.g. when powering back up after power-save shutdown) */
Stanislaw Gruszkadb54eb52011-08-24 21:06:33 +02002643 il_wr_prph(il, BSM_WR_CTRL_REG,
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002644 BSM_WR_CTRL_REG_BIT_START_EN);
2645
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002646 return 0;
2647}
2648
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002649static struct il_hcmd_ops il3945_hcmd = {
2650 .rxon_assoc = il3945_send_rxon_assoc,
2651 .commit_rxon = il3945_commit_rxon,
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07002652};
2653
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002654static struct il_lib_ops il3945_lib = {
2655 .txq_attach_buf_to_tfd = il3945_hw_txq_attach_buf_to_tfd,
2656 .txq_free_tfd = il3945_hw_txq_free_tfd,
2657 .txq_init = il3945_hw_tx_queue_init,
2658 .load_ucode = il3945_load_bsm,
2659 .dump_nic_error_log = il3945_dump_nic_error_log,
Kolekar, Abhijeet01ec6162008-12-19 10:37:38 +08002660 .apm_ops = {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002661 .init = il3945_apm_init,
2662 .config = il3945_nic_config,
Kolekar, Abhijeet01ec6162008-12-19 10:37:38 +08002663 },
Samuel Ortize6148912009-01-23 13:45:15 -08002664 .eeprom_ops = {
2665 .regulatory_bands = {
2666 EEPROM_REGULATORY_BAND_1_CHANNELS,
2667 EEPROM_REGULATORY_BAND_2_CHANNELS,
2668 EEPROM_REGULATORY_BAND_3_CHANNELS,
2669 EEPROM_REGULATORY_BAND_4_CHANNELS,
2670 EEPROM_REGULATORY_BAND_5_CHANNELS,
Wey-Yi Guy7aafef12009-08-07 15:41:38 -07002671 EEPROM_REGULATORY_BAND_NO_HT40,
2672 EEPROM_REGULATORY_BAND_NO_HT40,
Samuel Ortize6148912009-01-23 13:45:15 -08002673 },
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002674 .acquire_semaphore = il3945_eeprom_acquire_semaphore,
2675 .release_semaphore = il3945_eeprom_release_semaphore,
Samuel Ortize6148912009-01-23 13:45:15 -08002676 },
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002677 .send_tx_power = il3945_send_tx_power,
2678 .is_valid_rtc_data_addr = il3945_hw_valid_rtc_data_addr,
Abhijeet Kolekar17f36fc2010-04-16 10:03:54 -07002679
2680 .debugfs_ops = {
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002681 .rx_stats_read = il3945_ucode_rx_stats_read,
2682 .tx_stats_read = il3945_ucode_tx_stats_read,
2683 .general_stats_read = il3945_ucode_general_stats_read,
Abhijeet Kolekar17f36fc2010-04-16 10:03:54 -07002684 },
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002685};
2686
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002687static const struct il_legacy_ops il3945_legacy_ops = {
2688 .post_associate = il3945_post_associate,
2689 .config_ap = il3945_config_ap,
2690 .manage_ibss_station = il3945_manage_ibss_station,
Johannes Berg2295c662010-10-23 09:15:41 -07002691};
2692
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002693static struct il_hcmd_utils_ops il3945_hcmd_utils = {
2694 .get_hcmd_size = il3945_get_hcmd_size,
2695 .build_addsta_hcmd = il3945_build_addsta_hcmd,
2696 .request_scan = il3945_request_scan,
2697 .post_scan = il3945_post_scan,
Kolekar, Abhijeet42427b42008-12-22 11:31:15 +08002698};
2699
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002700static const struct il_ops il3945_ops = {
2701 .lib = &il3945_lib,
2702 .hcmd = &il3945_hcmd,
2703 .utils = &il3945_hcmd_utils,
2704 .led = &il3945_led_ops,
2705 .legacy = &il3945_legacy_ops,
2706 .ieee80211_ops = &il3945_hw_ops,
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002707};
2708
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002709static struct il_base_params il3945_base_params = {
Stanislaw Gruszkad3175162011-11-15 11:25:42 +01002710 .eeprom_size = IL3945_EEPROM_IMG_SIZE,
2711 .num_of_queues = IL39_NUM_QUEUES,
Ben Cahillfadb3582009-10-23 13:42:21 -07002712 .pll_cfg_val = CSR39_ANA_PLL_CFG_VAL,
2713 .set_l0s = false,
2714 .use_bsm = true,
Wey-Yi Guyf2d0d0e2009-09-11 10:38:14 -07002715 .led_compensation = 64,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002716 .wd_timeout = IL_DEF_WD_TIMEOUT,
Tomas Winkler82b9a122008-03-04 18:09:30 -08002717};
2718
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002719static struct il_cfg il3945_bg_cfg = {
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002720 .name = "3945BG",
Stanislaw Gruszkad3175162011-11-15 11:25:42 +01002721 .fw_name_pre = IL3945_FW_PRE,
2722 .ucode_api_max = IL3945_UCODE_API_MAX,
2723 .ucode_api_min = IL3945_UCODE_API_MIN,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002724 .sku = IL_SKU_G,
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002725 .eeprom_ver = EEPROM_3945_EEPROM_VERSION,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002726 .ops = &il3945_ops,
2727 .mod_params = &il3945_mod_params,
2728 .base_params = &il3945_base_params,
2729 .led_mode = IL_LED_BLINK,
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002730};
2731
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002732static struct il_cfg il3945_abg_cfg = {
Tomas Winkler82b9a122008-03-04 18:09:30 -08002733 .name = "3945ABG",
Stanislaw Gruszkad3175162011-11-15 11:25:42 +01002734 .fw_name_pre = IL3945_FW_PRE,
2735 .ucode_api_max = IL3945_UCODE_API_MAX,
2736 .ucode_api_min = IL3945_UCODE_API_MIN,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002737 .sku = IL_SKU_A|IL_SKU_G,
Samuel Ortize6148912009-01-23 13:45:15 -08002738 .eeprom_ver = EEPROM_3945_EEPROM_VERSION,
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002739 .ops = &il3945_ops,
2740 .mod_params = &il3945_mod_params,
2741 .base_params = &il3945_base_params,
2742 .led_mode = IL_LED_BLINK,
Tomas Winkler82b9a122008-03-04 18:09:30 -08002743};
2744
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002745DEFINE_PCI_DEVICE_TABLE(il3945_hw_card_ids) = {
2746 {IL_PCI_DEVICE(0x4222, 0x1005, il3945_bg_cfg)},
2747 {IL_PCI_DEVICE(0x4222, 0x1034, il3945_bg_cfg)},
2748 {IL_PCI_DEVICE(0x4222, 0x1044, il3945_bg_cfg)},
2749 {IL_PCI_DEVICE(0x4227, 0x1014, il3945_bg_cfg)},
2750 {IL_PCI_DEVICE(0x4222, PCI_ANY_ID, il3945_abg_cfg)},
2751 {IL_PCI_DEVICE(0x4227, PCI_ANY_ID, il3945_abg_cfg)},
Zhu Yib481de92007-09-25 17:54:57 -07002752 {0}
2753};
2754
Stanislaw Gruszkae2ebc832011-10-24 15:41:30 +02002755MODULE_DEVICE_TABLE(pci, il3945_hw_card_ids);