116da78b7SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
27ac9a364SKalle Valo /******************************************************************************
37ac9a364SKalle Valo *
47ac9a364SKalle Valo * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
57ac9a364SKalle Valo *
67ac9a364SKalle Valo * Contact Information:
77ac9a364SKalle Valo * Intel Linux Wireless <ilw@linux.intel.com>
87ac9a364SKalle Valo * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
97ac9a364SKalle Valo *
107ac9a364SKalle Valo *****************************************************************************/
117ac9a364SKalle Valo
127ac9a364SKalle Valo #include <linux/kernel.h>
137ac9a364SKalle Valo #include <linux/module.h>
147ac9a364SKalle Valo #include <linux/slab.h>
157ac9a364SKalle Valo #include <linux/pci.h>
167ac9a364SKalle Valo #include <linux/dma-mapping.h>
177ac9a364SKalle Valo #include <linux/delay.h>
187ac9a364SKalle Valo #include <linux/sched.h>
197ac9a364SKalle Valo #include <linux/skbuff.h>
207ac9a364SKalle Valo #include <linux/netdevice.h>
217ac9a364SKalle Valo #include <linux/firmware.h>
227ac9a364SKalle Valo #include <linux/etherdevice.h>
237ac9a364SKalle Valo #include <asm/unaligned.h>
247ac9a364SKalle Valo #include <net/mac80211.h>
257ac9a364SKalle Valo
267ac9a364SKalle Valo #include "common.h"
277ac9a364SKalle Valo #include "3945.h"
287ac9a364SKalle Valo
297ac9a364SKalle Valo /* Send led command */
307ac9a364SKalle Valo static int
il3945_send_led_cmd(struct il_priv * il,struct il_led_cmd * led_cmd)317ac9a364SKalle Valo il3945_send_led_cmd(struct il_priv *il, struct il_led_cmd *led_cmd)
327ac9a364SKalle Valo {
337ac9a364SKalle Valo struct il_host_cmd cmd = {
347ac9a364SKalle Valo .id = C_LEDS,
357ac9a364SKalle Valo .len = sizeof(struct il_led_cmd),
367ac9a364SKalle Valo .data = led_cmd,
377ac9a364SKalle Valo .flags = CMD_ASYNC,
387ac9a364SKalle Valo .callback = NULL,
397ac9a364SKalle Valo };
407ac9a364SKalle Valo
417ac9a364SKalle Valo return il_send_cmd(il, &cmd);
427ac9a364SKalle Valo }
437ac9a364SKalle Valo
447ac9a364SKalle Valo #define IL_DECLARE_RATE_INFO(r, ip, in, rp, rn, pp, np) \
457ac9a364SKalle Valo [RATE_##r##M_IDX] = { RATE_##r##M_PLCP, \
467ac9a364SKalle Valo RATE_##r##M_IEEE, \
477ac9a364SKalle Valo RATE_##ip##M_IDX, \
487ac9a364SKalle Valo RATE_##in##M_IDX, \
497ac9a364SKalle Valo RATE_##rp##M_IDX, \
507ac9a364SKalle Valo RATE_##rn##M_IDX, \
517ac9a364SKalle Valo RATE_##pp##M_IDX, \
527ac9a364SKalle Valo RATE_##np##M_IDX, \
537ac9a364SKalle Valo RATE_##r##M_IDX_TBL, \
547ac9a364SKalle Valo RATE_##ip##M_IDX_TBL }
557ac9a364SKalle Valo
567ac9a364SKalle Valo /*
577ac9a364SKalle Valo * Parameter order:
587ac9a364SKalle Valo * rate, prev rate, next rate, prev tgg rate, next tgg rate
597ac9a364SKalle Valo *
607ac9a364SKalle Valo * If there isn't a valid next or previous rate then INV is used which
617ac9a364SKalle Valo * maps to RATE_INVALID
627ac9a364SKalle Valo *
637ac9a364SKalle Valo */
647ac9a364SKalle Valo const struct il3945_rate_info il3945_rates[RATE_COUNT_3945] = {
657ac9a364SKalle Valo IL_DECLARE_RATE_INFO(1, INV, 2, INV, 2, INV, 2), /* 1mbps */
667ac9a364SKalle Valo IL_DECLARE_RATE_INFO(2, 1, 5, 1, 5, 1, 5), /* 2mbps */
677ac9a364SKalle Valo IL_DECLARE_RATE_INFO(5, 2, 6, 2, 11, 2, 11), /*5.5mbps */
687ac9a364SKalle Valo IL_DECLARE_RATE_INFO(11, 9, 12, 5, 12, 5, 18), /* 11mbps */
697ac9a364SKalle Valo IL_DECLARE_RATE_INFO(6, 5, 9, 5, 11, 5, 11), /* 6mbps */
707ac9a364SKalle Valo IL_DECLARE_RATE_INFO(9, 6, 11, 5, 11, 5, 11), /* 9mbps */
717ac9a364SKalle Valo IL_DECLARE_RATE_INFO(12, 11, 18, 11, 18, 11, 18), /* 12mbps */
727ac9a364SKalle Valo IL_DECLARE_RATE_INFO(18, 12, 24, 12, 24, 11, 24), /* 18mbps */
737ac9a364SKalle Valo IL_DECLARE_RATE_INFO(24, 18, 36, 18, 36, 18, 36), /* 24mbps */
747ac9a364SKalle Valo IL_DECLARE_RATE_INFO(36, 24, 48, 24, 48, 24, 48), /* 36mbps */
757ac9a364SKalle Valo IL_DECLARE_RATE_INFO(48, 36, 54, 36, 54, 36, 54), /* 48mbps */
767ac9a364SKalle Valo IL_DECLARE_RATE_INFO(54, 48, INV, 48, INV, 48, INV), /* 54mbps */
777ac9a364SKalle Valo };
787ac9a364SKalle Valo
797ac9a364SKalle Valo static inline u8
il3945_get_prev_ieee_rate(u8 rate_idx)807ac9a364SKalle Valo il3945_get_prev_ieee_rate(u8 rate_idx)
817ac9a364SKalle Valo {
827ac9a364SKalle Valo u8 rate = il3945_rates[rate_idx].prev_ieee;
837ac9a364SKalle Valo
847ac9a364SKalle Valo if (rate == RATE_INVALID)
857ac9a364SKalle Valo rate = rate_idx;
867ac9a364SKalle Valo return rate;
877ac9a364SKalle Valo }
887ac9a364SKalle Valo
897ac9a364SKalle Valo /* 1 = enable the il3945_disable_events() function */
907ac9a364SKalle Valo #define IL_EVT_DISABLE (0)
917ac9a364SKalle Valo #define IL_EVT_DISABLE_SIZE (1532/32)
927ac9a364SKalle Valo
93a60e33afSLee Jones /*
947ac9a364SKalle Valo * il3945_disable_events - Disable selected events in uCode event log
957ac9a364SKalle Valo *
967ac9a364SKalle Valo * Disable an event by writing "1"s into "disable"
977ac9a364SKalle Valo * bitmap in SRAM. Bit position corresponds to Event # (id/type).
987ac9a364SKalle Valo * Default values of 0 enable uCode events to be logged.
997ac9a364SKalle Valo * Use for only special debugging. This function is just a placeholder as-is,
1007ac9a364SKalle Valo * you'll need to provide the special bits! ...
1017ac9a364SKalle Valo * ... and set IL_EVT_DISABLE to 1. */
1027ac9a364SKalle Valo void
il3945_disable_events(struct il_priv * il)1037ac9a364SKalle Valo il3945_disable_events(struct il_priv *il)
1047ac9a364SKalle Valo {
1057ac9a364SKalle Valo int i;
1067ac9a364SKalle Valo u32 base; /* SRAM address of event log header */
1077ac9a364SKalle Valo u32 disable_ptr; /* SRAM address of event-disable bitmap array */
1087ac9a364SKalle Valo u32 array_size; /* # of u32 entries in array */
1097ac9a364SKalle Valo static const u32 evt_disable[IL_EVT_DISABLE_SIZE] = {
1107ac9a364SKalle Valo 0x00000000, /* 31 - 0 Event id numbers */
1117ac9a364SKalle Valo 0x00000000, /* 63 - 32 */
1127ac9a364SKalle Valo 0x00000000, /* 95 - 64 */
1137ac9a364SKalle Valo 0x00000000, /* 127 - 96 */
1147ac9a364SKalle Valo 0x00000000, /* 159 - 128 */
1157ac9a364SKalle Valo 0x00000000, /* 191 - 160 */
1167ac9a364SKalle Valo 0x00000000, /* 223 - 192 */
1177ac9a364SKalle Valo 0x00000000, /* 255 - 224 */
1187ac9a364SKalle Valo 0x00000000, /* 287 - 256 */
1197ac9a364SKalle Valo 0x00000000, /* 319 - 288 */
1207ac9a364SKalle Valo 0x00000000, /* 351 - 320 */
1217ac9a364SKalle Valo 0x00000000, /* 383 - 352 */
1227ac9a364SKalle Valo 0x00000000, /* 415 - 384 */
1237ac9a364SKalle Valo 0x00000000, /* 447 - 416 */
1247ac9a364SKalle Valo 0x00000000, /* 479 - 448 */
1257ac9a364SKalle Valo 0x00000000, /* 511 - 480 */
1267ac9a364SKalle Valo 0x00000000, /* 543 - 512 */
1277ac9a364SKalle Valo 0x00000000, /* 575 - 544 */
1287ac9a364SKalle Valo 0x00000000, /* 607 - 576 */
1297ac9a364SKalle Valo 0x00000000, /* 639 - 608 */
1307ac9a364SKalle Valo 0x00000000, /* 671 - 640 */
1317ac9a364SKalle Valo 0x00000000, /* 703 - 672 */
1327ac9a364SKalle Valo 0x00000000, /* 735 - 704 */
1337ac9a364SKalle Valo 0x00000000, /* 767 - 736 */
1347ac9a364SKalle Valo 0x00000000, /* 799 - 768 */
1357ac9a364SKalle Valo 0x00000000, /* 831 - 800 */
1367ac9a364SKalle Valo 0x00000000, /* 863 - 832 */
1377ac9a364SKalle Valo 0x00000000, /* 895 - 864 */
1387ac9a364SKalle Valo 0x00000000, /* 927 - 896 */
1397ac9a364SKalle Valo 0x00000000, /* 959 - 928 */
1407ac9a364SKalle Valo 0x00000000, /* 991 - 960 */
1417ac9a364SKalle Valo 0x00000000, /* 1023 - 992 */
1427ac9a364SKalle Valo 0x00000000, /* 1055 - 1024 */
1437ac9a364SKalle Valo 0x00000000, /* 1087 - 1056 */
1447ac9a364SKalle Valo 0x00000000, /* 1119 - 1088 */
1457ac9a364SKalle Valo 0x00000000, /* 1151 - 1120 */
1467ac9a364SKalle Valo 0x00000000, /* 1183 - 1152 */
1477ac9a364SKalle Valo 0x00000000, /* 1215 - 1184 */
1487ac9a364SKalle Valo 0x00000000, /* 1247 - 1216 */
1497ac9a364SKalle Valo 0x00000000, /* 1279 - 1248 */
1507ac9a364SKalle Valo 0x00000000, /* 1311 - 1280 */
1517ac9a364SKalle Valo 0x00000000, /* 1343 - 1312 */
1527ac9a364SKalle Valo 0x00000000, /* 1375 - 1344 */
1537ac9a364SKalle Valo 0x00000000, /* 1407 - 1376 */
1547ac9a364SKalle Valo 0x00000000, /* 1439 - 1408 */
1557ac9a364SKalle Valo 0x00000000, /* 1471 - 1440 */
1567ac9a364SKalle Valo 0x00000000, /* 1503 - 1472 */
1577ac9a364SKalle Valo };
1587ac9a364SKalle Valo
1597ac9a364SKalle Valo base = le32_to_cpu(il->card_alive.log_event_table_ptr);
1607ac9a364SKalle Valo if (!il3945_hw_valid_rtc_data_addr(base)) {
1617ac9a364SKalle Valo IL_ERR("Invalid event log pointer 0x%08X\n", base);
1627ac9a364SKalle Valo return;
1637ac9a364SKalle Valo }
1647ac9a364SKalle Valo
1657ac9a364SKalle Valo disable_ptr = il_read_targ_mem(il, base + (4 * sizeof(u32)));
1667ac9a364SKalle Valo array_size = il_read_targ_mem(il, base + (5 * sizeof(u32)));
1677ac9a364SKalle Valo
1687ac9a364SKalle Valo if (IL_EVT_DISABLE && array_size == IL_EVT_DISABLE_SIZE) {
1697ac9a364SKalle Valo D_INFO("Disabling selected uCode log events at 0x%x\n",
1707ac9a364SKalle Valo disable_ptr);
1717ac9a364SKalle Valo for (i = 0; i < IL_EVT_DISABLE_SIZE; i++)
1727ac9a364SKalle Valo il_write_targ_mem(il, disable_ptr + (i * sizeof(u32)),
1737ac9a364SKalle Valo evt_disable[i]);
1747ac9a364SKalle Valo
1757ac9a364SKalle Valo } else {
1767ac9a364SKalle Valo D_INFO("Selected uCode log events may be disabled\n");
1777ac9a364SKalle Valo D_INFO(" by writing \"1\"s into disable bitmap\n");
1787ac9a364SKalle Valo D_INFO(" in SRAM at 0x%x, size %d u32s\n", disable_ptr,
1797ac9a364SKalle Valo array_size);
1807ac9a364SKalle Valo }
1817ac9a364SKalle Valo
1827ac9a364SKalle Valo }
1837ac9a364SKalle Valo
1847ac9a364SKalle Valo static int
il3945_hwrate_to_plcp_idx(u8 plcp)1857ac9a364SKalle Valo il3945_hwrate_to_plcp_idx(u8 plcp)
1867ac9a364SKalle Valo {
1877ac9a364SKalle Valo int idx;
1887ac9a364SKalle Valo
1897ac9a364SKalle Valo for (idx = 0; idx < RATE_COUNT_3945; idx++)
1907ac9a364SKalle Valo if (il3945_rates[idx].plcp == plcp)
1917ac9a364SKalle Valo return idx;
1927ac9a364SKalle Valo return -1;
1937ac9a364SKalle Valo }
1947ac9a364SKalle Valo
1957ac9a364SKalle Valo #ifdef CONFIG_IWLEGACY_DEBUG
1967ac9a364SKalle Valo #define TX_STATUS_ENTRY(x) case TX_3945_STATUS_FAIL_ ## x: return #x
1977ac9a364SKalle Valo
1987ac9a364SKalle Valo static const char *
il3945_get_tx_fail_reason(u32 status)1997ac9a364SKalle Valo il3945_get_tx_fail_reason(u32 status)
2007ac9a364SKalle Valo {
2017ac9a364SKalle Valo switch (status & TX_STATUS_MSK) {
2027ac9a364SKalle Valo case TX_3945_STATUS_SUCCESS:
2037ac9a364SKalle Valo return "SUCCESS";
2047ac9a364SKalle Valo TX_STATUS_ENTRY(SHORT_LIMIT);
2057ac9a364SKalle Valo TX_STATUS_ENTRY(LONG_LIMIT);
2067ac9a364SKalle Valo TX_STATUS_ENTRY(FIFO_UNDERRUN);
2077ac9a364SKalle Valo TX_STATUS_ENTRY(MGMNT_ABORT);
2087ac9a364SKalle Valo TX_STATUS_ENTRY(NEXT_FRAG);
2097ac9a364SKalle Valo TX_STATUS_ENTRY(LIFE_EXPIRE);
2107ac9a364SKalle Valo TX_STATUS_ENTRY(DEST_PS);
2117ac9a364SKalle Valo TX_STATUS_ENTRY(ABORTED);
2127ac9a364SKalle Valo TX_STATUS_ENTRY(BT_RETRY);
2137ac9a364SKalle Valo TX_STATUS_ENTRY(STA_INVALID);
2147ac9a364SKalle Valo TX_STATUS_ENTRY(FRAG_DROPPED);
2157ac9a364SKalle Valo TX_STATUS_ENTRY(TID_DISABLE);
2167ac9a364SKalle Valo TX_STATUS_ENTRY(FRAME_FLUSHED);
2177ac9a364SKalle Valo TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
2187ac9a364SKalle Valo TX_STATUS_ENTRY(TX_LOCKED);
2197ac9a364SKalle Valo TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
2207ac9a364SKalle Valo }
2217ac9a364SKalle Valo
2227ac9a364SKalle Valo return "UNKNOWN";
2237ac9a364SKalle Valo }
2247ac9a364SKalle Valo #else
2257ac9a364SKalle Valo static inline const char *
il3945_get_tx_fail_reason(u32 status)2267ac9a364SKalle Valo il3945_get_tx_fail_reason(u32 status)
2277ac9a364SKalle Valo {
2287ac9a364SKalle Valo return "";
2297ac9a364SKalle Valo }
2307ac9a364SKalle Valo #endif
2317ac9a364SKalle Valo
2327ac9a364SKalle Valo /*
2337ac9a364SKalle Valo * get ieee prev rate from rate scale table.
2347ac9a364SKalle Valo * for A and B mode we need to overright prev
2357ac9a364SKalle Valo * value
2367ac9a364SKalle Valo */
2377ac9a364SKalle Valo int
il3945_rs_next_rate(struct il_priv * il,int rate)2387ac9a364SKalle Valo il3945_rs_next_rate(struct il_priv *il, int rate)
2397ac9a364SKalle Valo {
2407ac9a364SKalle Valo int next_rate = il3945_get_prev_ieee_rate(rate);
2417ac9a364SKalle Valo
2427ac9a364SKalle Valo switch (il->band) {
24357fbcce3SJohannes Berg case NL80211_BAND_5GHZ:
2447ac9a364SKalle Valo if (rate == RATE_12M_IDX)
2457ac9a364SKalle Valo next_rate = RATE_9M_IDX;
2467ac9a364SKalle Valo else if (rate == RATE_6M_IDX)
2477ac9a364SKalle Valo next_rate = RATE_6M_IDX;
2487ac9a364SKalle Valo break;
24957fbcce3SJohannes Berg case NL80211_BAND_2GHZ:
2507ac9a364SKalle Valo if (!(il->_3945.sta_supp_rates & IL_OFDM_RATES_MASK) &&
2517ac9a364SKalle Valo il_is_associated(il)) {
2527ac9a364SKalle Valo if (rate == RATE_11M_IDX)
2537ac9a364SKalle Valo next_rate = RATE_5M_IDX;
2547ac9a364SKalle Valo }
2557ac9a364SKalle Valo break;
2567ac9a364SKalle Valo
2577ac9a364SKalle Valo default:
2587ac9a364SKalle Valo break;
2597ac9a364SKalle Valo }
2607ac9a364SKalle Valo
2617ac9a364SKalle Valo return next_rate;
2627ac9a364SKalle Valo }
2637ac9a364SKalle Valo
264a60e33afSLee Jones /*
2657ac9a364SKalle Valo * il3945_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
2667ac9a364SKalle Valo *
2677ac9a364SKalle Valo * When FW advances 'R' idx, all entries between old and new 'R' idx
2687ac9a364SKalle Valo * need to be reclaimed. As result, some free space forms. If there is
2697ac9a364SKalle Valo * enough free space (> low mark), wake the stack that feeds us.
2707ac9a364SKalle Valo */
2717ac9a364SKalle Valo static void
il3945_tx_queue_reclaim(struct il_priv * il,int txq_id,int idx)2727ac9a364SKalle Valo il3945_tx_queue_reclaim(struct il_priv *il, int txq_id, int idx)
2737ac9a364SKalle Valo {
2747ac9a364SKalle Valo struct il_tx_queue *txq = &il->txq[txq_id];
2757ac9a364SKalle Valo struct il_queue *q = &txq->q;
2767ac9a364SKalle Valo struct sk_buff *skb;
2777ac9a364SKalle Valo
2787ac9a364SKalle Valo BUG_ON(txq_id == IL39_CMD_QUEUE_NUM);
2797ac9a364SKalle Valo
2807ac9a364SKalle Valo for (idx = il_queue_inc_wrap(idx, q->n_bd); q->read_ptr != idx;
2817ac9a364SKalle Valo q->read_ptr = il_queue_inc_wrap(q->read_ptr, q->n_bd)) {
2827ac9a364SKalle Valo
2837ac9a364SKalle Valo skb = txq->skbs[txq->q.read_ptr];
2847ac9a364SKalle Valo ieee80211_tx_status_irqsafe(il->hw, skb);
2857ac9a364SKalle Valo txq->skbs[txq->q.read_ptr] = NULL;
2867ac9a364SKalle Valo il->ops->txq_free_tfd(il, txq);
2877ac9a364SKalle Valo }
2887ac9a364SKalle Valo
2897ac9a364SKalle Valo if (il_queue_space(q) > q->low_mark && txq_id >= 0 &&
2907ac9a364SKalle Valo txq_id != IL39_CMD_QUEUE_NUM && il->mac80211_registered)
2917ac9a364SKalle Valo il_wake_queue(il, txq);
2927ac9a364SKalle Valo }
2937ac9a364SKalle Valo
294a60e33afSLee Jones /*
2957ac9a364SKalle Valo * il3945_hdl_tx - Handle Tx response
2967ac9a364SKalle Valo */
2977ac9a364SKalle Valo static void
il3945_hdl_tx(struct il_priv * il,struct il_rx_buf * rxb)2987ac9a364SKalle Valo il3945_hdl_tx(struct il_priv *il, struct il_rx_buf *rxb)
2997ac9a364SKalle Valo {
3007ac9a364SKalle Valo struct il_rx_pkt *pkt = rxb_addr(rxb);
3017ac9a364SKalle Valo u16 sequence = le16_to_cpu(pkt->hdr.sequence);
3027ac9a364SKalle Valo int txq_id = SEQ_TO_QUEUE(sequence);
3037ac9a364SKalle Valo int idx = SEQ_TO_IDX(sequence);
3047ac9a364SKalle Valo struct il_tx_queue *txq = &il->txq[txq_id];
3057ac9a364SKalle Valo struct ieee80211_tx_info *info;
3067ac9a364SKalle Valo struct il3945_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
3077ac9a364SKalle Valo u32 status = le32_to_cpu(tx_resp->status);
3087ac9a364SKalle Valo int rate_idx;
3097ac9a364SKalle Valo int fail;
3107ac9a364SKalle Valo
3117ac9a364SKalle Valo if (idx >= txq->q.n_bd || il_queue_used(&txq->q, idx) == 0) {
3127ac9a364SKalle Valo IL_ERR("Read idx for DMA queue txq_id (%d) idx %d "
3137ac9a364SKalle Valo "is out of range [0-%d] %d %d\n", txq_id, idx,
3147ac9a364SKalle Valo txq->q.n_bd, txq->q.write_ptr, txq->q.read_ptr);
3157ac9a364SKalle Valo return;
3167ac9a364SKalle Valo }
3177ac9a364SKalle Valo
3187ac9a364SKalle Valo /*
3197ac9a364SKalle Valo * Firmware will not transmit frame on passive channel, if it not yet
3207ac9a364SKalle Valo * received some valid frame on that channel. When this error happen
3217ac9a364SKalle Valo * we have to wait until firmware will unblock itself i.e. when we
3227ac9a364SKalle Valo * note received beacon or other frame. We unblock queues in
3237ac9a364SKalle Valo * il3945_pass_packet_to_mac80211 or in il_mac_bss_info_changed.
3247ac9a364SKalle Valo */
3257ac9a364SKalle Valo if (unlikely((status & TX_STATUS_MSK) == TX_STATUS_FAIL_PASSIVE_NO_RX) &&
3267ac9a364SKalle Valo il->iw_mode == NL80211_IFTYPE_STATION) {
3277ac9a364SKalle Valo il_stop_queues_by_reason(il, IL_STOP_REASON_PASSIVE);
3287ac9a364SKalle Valo D_INFO("Stopped queues - RX waiting on passive channel\n");
3297ac9a364SKalle Valo }
3307ac9a364SKalle Valo
3317ac9a364SKalle Valo txq->time_stamp = jiffies;
3327ac9a364SKalle Valo info = IEEE80211_SKB_CB(txq->skbs[txq->q.read_ptr]);
3337ac9a364SKalle Valo ieee80211_tx_info_clear_status(info);
3347ac9a364SKalle Valo
3357ac9a364SKalle Valo /* Fill the MRR chain with some info about on-chip retransmissions */
3367ac9a364SKalle Valo rate_idx = il3945_hwrate_to_plcp_idx(tx_resp->rate);
33757fbcce3SJohannes Berg if (info->band == NL80211_BAND_5GHZ)
3387ac9a364SKalle Valo rate_idx -= IL_FIRST_OFDM_RATE;
3397ac9a364SKalle Valo
3407ac9a364SKalle Valo fail = tx_resp->failure_frame;
3417ac9a364SKalle Valo
3427ac9a364SKalle Valo info->status.rates[0].idx = rate_idx;
3437ac9a364SKalle Valo info->status.rates[0].count = fail + 1; /* add final attempt */
3447ac9a364SKalle Valo
3457ac9a364SKalle Valo /* tx_status->rts_retry_count = tx_resp->failure_rts; */
3467ac9a364SKalle Valo info->flags |=
3477ac9a364SKalle Valo ((status & TX_STATUS_MSK) ==
3487ac9a364SKalle Valo TX_STATUS_SUCCESS) ? IEEE80211_TX_STAT_ACK : 0;
3497ac9a364SKalle Valo
3507ac9a364SKalle Valo D_TX("Tx queue %d Status %s (0x%08x) plcp rate %d retries %d\n", txq_id,
3517ac9a364SKalle Valo il3945_get_tx_fail_reason(status), status, tx_resp->rate,
3527ac9a364SKalle Valo tx_resp->failure_frame);
3537ac9a364SKalle Valo
3547ac9a364SKalle Valo D_TX_REPLY("Tx queue reclaim %d\n", idx);
3557ac9a364SKalle Valo il3945_tx_queue_reclaim(il, txq_id, idx);
3567ac9a364SKalle Valo
3577ac9a364SKalle Valo if (status & TX_ABORT_REQUIRED_MSK)
3587ac9a364SKalle Valo IL_ERR("TODO: Implement Tx ABORT REQUIRED!!!\n");
3597ac9a364SKalle Valo }
3607ac9a364SKalle Valo
3617ac9a364SKalle Valo /*****************************************************************************
3627ac9a364SKalle Valo *
3637ac9a364SKalle Valo * Intel PRO/Wireless 3945ABG/BG Network Connection
3647ac9a364SKalle Valo *
3657ac9a364SKalle Valo * RX handler implementations
3667ac9a364SKalle Valo *
3677ac9a364SKalle Valo *****************************************************************************/
3687ac9a364SKalle Valo #ifdef CONFIG_IWLEGACY_DEBUGFS
3697ac9a364SKalle Valo static void
il3945_accumulative_stats(struct il_priv * il,__le32 * stats)3707ac9a364SKalle Valo il3945_accumulative_stats(struct il_priv *il, __le32 * stats)
3717ac9a364SKalle Valo {
3727ac9a364SKalle Valo int i;
3737ac9a364SKalle Valo __le32 *prev_stats;
3747ac9a364SKalle Valo u32 *accum_stats;
3757ac9a364SKalle Valo u32 *delta, *max_delta;
3767ac9a364SKalle Valo
3777ac9a364SKalle Valo prev_stats = (__le32 *) &il->_3945.stats;
3787ac9a364SKalle Valo accum_stats = (u32 *) &il->_3945.accum_stats;
3797ac9a364SKalle Valo delta = (u32 *) &il->_3945.delta_stats;
3807ac9a364SKalle Valo max_delta = (u32 *) &il->_3945.max_delta;
3817ac9a364SKalle Valo
3827ac9a364SKalle Valo for (i = sizeof(__le32); i < sizeof(struct il3945_notif_stats);
3837ac9a364SKalle Valo i +=
3847ac9a364SKalle Valo sizeof(__le32), stats++, prev_stats++, delta++, max_delta++,
3857ac9a364SKalle Valo accum_stats++) {
3867ac9a364SKalle Valo if (le32_to_cpu(*stats) > le32_to_cpu(*prev_stats)) {
3877ac9a364SKalle Valo *delta =
3887ac9a364SKalle Valo (le32_to_cpu(*stats) - le32_to_cpu(*prev_stats));
3897ac9a364SKalle Valo *accum_stats += *delta;
3907ac9a364SKalle Valo if (*delta > *max_delta)
3917ac9a364SKalle Valo *max_delta = *delta;
3927ac9a364SKalle Valo }
3937ac9a364SKalle Valo }
3947ac9a364SKalle Valo
3957ac9a364SKalle Valo /* reset accumulative stats for "no-counter" type stats */
3967ac9a364SKalle Valo il->_3945.accum_stats.general.temperature =
3977ac9a364SKalle Valo il->_3945.stats.general.temperature;
3987ac9a364SKalle Valo il->_3945.accum_stats.general.ttl_timestamp =
3997ac9a364SKalle Valo il->_3945.stats.general.ttl_timestamp;
4007ac9a364SKalle Valo }
4017ac9a364SKalle Valo #endif
4027ac9a364SKalle Valo
4037ac9a364SKalle Valo void
il3945_hdl_stats(struct il_priv * il,struct il_rx_buf * rxb)4047ac9a364SKalle Valo il3945_hdl_stats(struct il_priv *il, struct il_rx_buf *rxb)
4057ac9a364SKalle Valo {
4067ac9a364SKalle Valo struct il_rx_pkt *pkt = rxb_addr(rxb);
4077ac9a364SKalle Valo
4087ac9a364SKalle Valo D_RX("Statistics notification received (%d vs %d).\n",
4097ac9a364SKalle Valo (int)sizeof(struct il3945_notif_stats),
4107ac9a364SKalle Valo le32_to_cpu(pkt->len_n_flags) & IL_RX_FRAME_SIZE_MSK);
4117ac9a364SKalle Valo #ifdef CONFIG_IWLEGACY_DEBUGFS
4127ac9a364SKalle Valo il3945_accumulative_stats(il, (__le32 *) &pkt->u.raw);
4137ac9a364SKalle Valo #endif
4147ac9a364SKalle Valo
4157ac9a364SKalle Valo memcpy(&il->_3945.stats, pkt->u.raw, sizeof(il->_3945.stats));
4167ac9a364SKalle Valo }
4177ac9a364SKalle Valo
4187ac9a364SKalle Valo void
il3945_hdl_c_stats(struct il_priv * il,struct il_rx_buf * rxb)4197ac9a364SKalle Valo il3945_hdl_c_stats(struct il_priv *il, struct il_rx_buf *rxb)
4207ac9a364SKalle Valo {
4217ac9a364SKalle Valo struct il_rx_pkt *pkt = rxb_addr(rxb);
4227ac9a364SKalle Valo __le32 *flag = (__le32 *) &pkt->u.raw;
4237ac9a364SKalle Valo
4247ac9a364SKalle Valo if (le32_to_cpu(*flag) & UCODE_STATS_CLEAR_MSK) {
4257ac9a364SKalle Valo #ifdef CONFIG_IWLEGACY_DEBUGFS
4267ac9a364SKalle Valo memset(&il->_3945.accum_stats, 0,
4277ac9a364SKalle Valo sizeof(struct il3945_notif_stats));
4287ac9a364SKalle Valo memset(&il->_3945.delta_stats, 0,
4297ac9a364SKalle Valo sizeof(struct il3945_notif_stats));
4307ac9a364SKalle Valo memset(&il->_3945.max_delta, 0,
4317ac9a364SKalle Valo sizeof(struct il3945_notif_stats));
4327ac9a364SKalle Valo #endif
4337ac9a364SKalle Valo D_RX("Statistics have been cleared\n");
4347ac9a364SKalle Valo }
4357ac9a364SKalle Valo il3945_hdl_stats(il, rxb);
4367ac9a364SKalle Valo }
4377ac9a364SKalle Valo
4387ac9a364SKalle Valo /******************************************************************************
4397ac9a364SKalle Valo *
4407ac9a364SKalle Valo * Misc. internal state and helper functions
4417ac9a364SKalle Valo *
4427ac9a364SKalle Valo ******************************************************************************/
4437ac9a364SKalle Valo
4447ac9a364SKalle Valo /* This is necessary only for a number of stats, see the caller. */
4457ac9a364SKalle Valo static int
il3945_is_network_packet(struct il_priv * il,struct ieee80211_hdr * header)4467ac9a364SKalle Valo il3945_is_network_packet(struct il_priv *il, struct ieee80211_hdr *header)
4477ac9a364SKalle Valo {
4487ac9a364SKalle Valo /* Filter incoming packets to determine if they are targeted toward
4497ac9a364SKalle Valo * this network, discarding packets coming from ourselves */
4507ac9a364SKalle Valo switch (il->iw_mode) {
4517ac9a364SKalle Valo case NL80211_IFTYPE_ADHOC: /* Header: Dest. | Source | BSSID */
4527ac9a364SKalle Valo /* packets to our IBSS update information */
4537ac9a364SKalle Valo return ether_addr_equal_64bits(header->addr3, il->bssid);
4547ac9a364SKalle Valo case NL80211_IFTYPE_STATION: /* Header: Dest. | AP{BSSID} | Source */
4557ac9a364SKalle Valo /* packets to our IBSS update information */
4567ac9a364SKalle Valo return ether_addr_equal_64bits(header->addr2, il->bssid);
4577ac9a364SKalle Valo default:
4587ac9a364SKalle Valo return 1;
4597ac9a364SKalle Valo }
4607ac9a364SKalle Valo }
4617ac9a364SKalle Valo
4627ac9a364SKalle Valo #define SMALL_PACKET_SIZE 256
4637ac9a364SKalle Valo
4647ac9a364SKalle Valo static void
il3945_pass_packet_to_mac80211(struct il_priv * il,struct il_rx_buf * rxb,struct ieee80211_rx_status * stats)4657ac9a364SKalle Valo il3945_pass_packet_to_mac80211(struct il_priv *il, struct il_rx_buf *rxb,
4667ac9a364SKalle Valo struct ieee80211_rx_status *stats)
4677ac9a364SKalle Valo {
4687ac9a364SKalle Valo struct il_rx_pkt *pkt = rxb_addr(rxb);
4697ac9a364SKalle Valo struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)IL_RX_DATA(pkt);
4707ac9a364SKalle Valo struct il3945_rx_frame_hdr *rx_hdr = IL_RX_HDR(pkt);
4717ac9a364SKalle Valo struct il3945_rx_frame_end *rx_end = IL_RX_END(pkt);
4727ac9a364SKalle Valo u32 len = le16_to_cpu(rx_hdr->len);
4737ac9a364SKalle Valo struct sk_buff *skb;
4747ac9a364SKalle Valo __le16 fc = hdr->frame_control;
4757ac9a364SKalle Valo u32 fraglen = PAGE_SIZE << il->hw_params.rx_page_order;
4767ac9a364SKalle Valo
4777ac9a364SKalle Valo /* We received data from the HW, so stop the watchdog */
4787ac9a364SKalle Valo if (unlikely(len + IL39_RX_FRAME_SIZE > fraglen)) {
4797ac9a364SKalle Valo D_DROP("Corruption detected!\n");
4807ac9a364SKalle Valo return;
4817ac9a364SKalle Valo }
4827ac9a364SKalle Valo
4837ac9a364SKalle Valo /* We only process data packets if the interface is open */
4847ac9a364SKalle Valo if (unlikely(!il->is_open)) {
4857ac9a364SKalle Valo D_DROP("Dropping packet while interface is not open.\n");
4867ac9a364SKalle Valo return;
4877ac9a364SKalle Valo }
4887ac9a364SKalle Valo
4897ac9a364SKalle Valo if (unlikely(test_bit(IL_STOP_REASON_PASSIVE, &il->stop_reason))) {
4907ac9a364SKalle Valo il_wake_queues_by_reason(il, IL_STOP_REASON_PASSIVE);
4917ac9a364SKalle Valo D_INFO("Woke queues - frame received on passive channel\n");
4927ac9a364SKalle Valo }
4937ac9a364SKalle Valo
4947ac9a364SKalle Valo skb = dev_alloc_skb(SMALL_PACKET_SIZE);
4957ac9a364SKalle Valo if (!skb) {
4967ac9a364SKalle Valo IL_ERR("dev_alloc_skb failed\n");
4977ac9a364SKalle Valo return;
4987ac9a364SKalle Valo }
4997ac9a364SKalle Valo
5007ac9a364SKalle Valo if (!il3945_mod_params.sw_crypto)
5017ac9a364SKalle Valo il_set_decrypted_flag(il, (struct ieee80211_hdr *)pkt,
5027ac9a364SKalle Valo le32_to_cpu(rx_end->status), stats);
5037ac9a364SKalle Valo
5047ac9a364SKalle Valo /* If frame is small enough to fit into skb->head, copy it
5057ac9a364SKalle Valo * and do not consume a full page
5067ac9a364SKalle Valo */
5077ac9a364SKalle Valo if (len <= SMALL_PACKET_SIZE) {
50859ae1d12SJohannes Berg skb_put_data(skb, rx_hdr->payload, len);
5097ac9a364SKalle Valo } else {
5107ac9a364SKalle Valo skb_add_rx_frag(skb, 0, rxb->page,
5117ac9a364SKalle Valo (void *)rx_hdr->payload - (void *)pkt, len,
5127ac9a364SKalle Valo fraglen);
5137ac9a364SKalle Valo il->alloc_rxb_page--;
5147ac9a364SKalle Valo rxb->page = NULL;
5157ac9a364SKalle Valo }
5167ac9a364SKalle Valo il_update_stats(il, false, fc, len);
5177ac9a364SKalle Valo memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats));
5187ac9a364SKalle Valo
5197ac9a364SKalle Valo ieee80211_rx(il->hw, skb);
5207ac9a364SKalle Valo }
5217ac9a364SKalle Valo
5227ac9a364SKalle Valo #define IL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
5237ac9a364SKalle Valo
5247ac9a364SKalle Valo static void
il3945_hdl_rx(struct il_priv * il,struct il_rx_buf * rxb)5257ac9a364SKalle Valo il3945_hdl_rx(struct il_priv *il, struct il_rx_buf *rxb)
5267ac9a364SKalle Valo {
5277ac9a364SKalle Valo struct ieee80211_hdr *header;
5287ac9a364SKalle Valo struct ieee80211_rx_status rx_status = {};
5297ac9a364SKalle Valo struct il_rx_pkt *pkt = rxb_addr(rxb);
5307ac9a364SKalle Valo struct il3945_rx_frame_stats *rx_stats = IL_RX_STATS(pkt);
5317ac9a364SKalle Valo struct il3945_rx_frame_hdr *rx_hdr = IL_RX_HDR(pkt);
5327ac9a364SKalle Valo struct il3945_rx_frame_end *rx_end = IL_RX_END(pkt);
5337ac9a364SKalle Valo u16 rx_stats_sig_avg __maybe_unused = le16_to_cpu(rx_stats->sig_avg);
5347ac9a364SKalle Valo u16 rx_stats_noise_diff __maybe_unused =
5357ac9a364SKalle Valo le16_to_cpu(rx_stats->noise_diff);
5367ac9a364SKalle Valo u8 network_packet;
5377ac9a364SKalle Valo
5387ac9a364SKalle Valo rx_status.flag = 0;
5397ac9a364SKalle Valo rx_status.mactime = le64_to_cpu(rx_end->timestamp);
5407ac9a364SKalle Valo rx_status.band =
5417ac9a364SKalle Valo (rx_hdr->
54257fbcce3SJohannes Berg phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ? NL80211_BAND_2GHZ :
54357fbcce3SJohannes Berg NL80211_BAND_5GHZ;
5447ac9a364SKalle Valo rx_status.freq =
5457ac9a364SKalle Valo ieee80211_channel_to_frequency(le16_to_cpu(rx_hdr->channel),
5467ac9a364SKalle Valo rx_status.band);
5477ac9a364SKalle Valo
5487ac9a364SKalle Valo rx_status.rate_idx = il3945_hwrate_to_plcp_idx(rx_hdr->rate);
54957fbcce3SJohannes Berg if (rx_status.band == NL80211_BAND_5GHZ)
5507ac9a364SKalle Valo rx_status.rate_idx -= IL_FIRST_OFDM_RATE;
5517ac9a364SKalle Valo
5527ac9a364SKalle Valo rx_status.antenna =
5537ac9a364SKalle Valo (le16_to_cpu(rx_hdr->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK) >>
5547ac9a364SKalle Valo 4;
5557ac9a364SKalle Valo
5567ac9a364SKalle Valo /* set the preamble flag if appropriate */
5577ac9a364SKalle Valo if (rx_hdr->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
5587fdd69c5SJohannes Berg rx_status.enc_flags |= RX_ENC_FLAG_SHORTPRE;
5597ac9a364SKalle Valo
5607ac9a364SKalle Valo if ((unlikely(rx_stats->phy_count > 20))) {
5617ac9a364SKalle Valo D_DROP("dsp size out of range [0,20]: %d\n",
5627ac9a364SKalle Valo rx_stats->phy_count);
5637ac9a364SKalle Valo return;
5647ac9a364SKalle Valo }
5657ac9a364SKalle Valo
5667ac9a364SKalle Valo if (!(rx_end->status & RX_RES_STATUS_NO_CRC32_ERROR) ||
5677ac9a364SKalle Valo !(rx_end->status & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
5687ac9a364SKalle Valo D_RX("Bad CRC or FIFO: 0x%08X.\n", rx_end->status);
5697ac9a364SKalle Valo return;
5707ac9a364SKalle Valo }
5717ac9a364SKalle Valo
5727ac9a364SKalle Valo /* Convert 3945's rssi indicator to dBm */
5737ac9a364SKalle Valo rx_status.signal = rx_stats->rssi - IL39_RSSI_OFFSET;
5747ac9a364SKalle Valo
5757ac9a364SKalle Valo D_STATS("Rssi %d sig_avg %d noise_diff %d\n", rx_status.signal,
5767ac9a364SKalle Valo rx_stats_sig_avg, rx_stats_noise_diff);
5777ac9a364SKalle Valo
5787ac9a364SKalle Valo header = (struct ieee80211_hdr *)IL_RX_DATA(pkt);
5797ac9a364SKalle Valo
5807ac9a364SKalle Valo network_packet = il3945_is_network_packet(il, header);
5817ac9a364SKalle Valo
5827ac9a364SKalle Valo D_STATS("[%c] %d RSSI:%d Signal:%u, Rate:%u\n",
5837ac9a364SKalle Valo network_packet ? '*' : ' ', le16_to_cpu(rx_hdr->channel),
5847ac9a364SKalle Valo rx_status.signal, rx_status.signal, rx_status.rate_idx);
5857ac9a364SKalle Valo
5867ac9a364SKalle Valo if (network_packet) {
5877ac9a364SKalle Valo il->_3945.last_beacon_time =
5887ac9a364SKalle Valo le32_to_cpu(rx_end->beacon_timestamp);
5897ac9a364SKalle Valo il->_3945.last_tsf = le64_to_cpu(rx_end->timestamp);
5907ac9a364SKalle Valo il->_3945.last_rx_rssi = rx_status.signal;
5917ac9a364SKalle Valo }
5927ac9a364SKalle Valo
5937ac9a364SKalle Valo il3945_pass_packet_to_mac80211(il, rxb, &rx_status);
5947ac9a364SKalle Valo }
5957ac9a364SKalle Valo
5967ac9a364SKalle Valo int
il3945_hw_txq_attach_buf_to_tfd(struct il_priv * il,struct il_tx_queue * txq,dma_addr_t addr,u16 len,u8 reset,u8 pad)5977ac9a364SKalle Valo il3945_hw_txq_attach_buf_to_tfd(struct il_priv *il, struct il_tx_queue *txq,
5987ac9a364SKalle Valo dma_addr_t addr, u16 len, u8 reset, u8 pad)
5997ac9a364SKalle Valo {
6007ac9a364SKalle Valo int count;
6017ac9a364SKalle Valo struct il_queue *q;
6027ac9a364SKalle Valo struct il3945_tfd *tfd, *tfd_tmp;
6037ac9a364SKalle Valo
6047ac9a364SKalle Valo q = &txq->q;
6057ac9a364SKalle Valo tfd_tmp = (struct il3945_tfd *)txq->tfds;
6067ac9a364SKalle Valo tfd = &tfd_tmp[q->write_ptr];
6077ac9a364SKalle Valo
6087ac9a364SKalle Valo if (reset)
6097ac9a364SKalle Valo memset(tfd, 0, sizeof(*tfd));
6107ac9a364SKalle Valo
6117ac9a364SKalle Valo count = TFD_CTL_COUNT_GET(le32_to_cpu(tfd->control_flags));
6127ac9a364SKalle Valo
6137ac9a364SKalle Valo if (count >= NUM_TFD_CHUNKS || count < 0) {
6147ac9a364SKalle Valo IL_ERR("Error can not send more than %d chunks\n",
6157ac9a364SKalle Valo NUM_TFD_CHUNKS);
6167ac9a364SKalle Valo return -EINVAL;
6177ac9a364SKalle Valo }
6187ac9a364SKalle Valo
6197ac9a364SKalle Valo tfd->tbs[count].addr = cpu_to_le32(addr);
6207ac9a364SKalle Valo tfd->tbs[count].len = cpu_to_le32(len);
6217ac9a364SKalle Valo
6227ac9a364SKalle Valo count++;
6237ac9a364SKalle Valo
6247ac9a364SKalle Valo tfd->control_flags =
6257ac9a364SKalle Valo cpu_to_le32(TFD_CTL_COUNT_SET(count) | TFD_CTL_PAD_SET(pad));
6267ac9a364SKalle Valo
6277ac9a364SKalle Valo return 0;
6287ac9a364SKalle Valo }
6297ac9a364SKalle Valo
630a60e33afSLee Jones /*
6317ac9a364SKalle Valo * il3945_hw_txq_free_tfd - Free one TFD, those at idx [txq->q.read_ptr]
6327ac9a364SKalle Valo *
6337ac9a364SKalle Valo * Does NOT advance any idxes
6347ac9a364SKalle Valo */
6357ac9a364SKalle Valo void
il3945_hw_txq_free_tfd(struct il_priv * il,struct il_tx_queue * txq)6367ac9a364SKalle Valo il3945_hw_txq_free_tfd(struct il_priv *il, struct il_tx_queue *txq)
6377ac9a364SKalle Valo {
6387ac9a364SKalle Valo struct il3945_tfd *tfd_tmp = (struct il3945_tfd *)txq->tfds;
6397ac9a364SKalle Valo int idx = txq->q.read_ptr;
6407ac9a364SKalle Valo struct il3945_tfd *tfd = &tfd_tmp[idx];
6417ac9a364SKalle Valo struct pci_dev *dev = il->pci_dev;
6427ac9a364SKalle Valo int i;
6437ac9a364SKalle Valo int counter;
6447ac9a364SKalle Valo
6457ac9a364SKalle Valo /* sanity check */
6467ac9a364SKalle Valo counter = TFD_CTL_COUNT_GET(le32_to_cpu(tfd->control_flags));
6477ac9a364SKalle Valo if (counter > NUM_TFD_CHUNKS) {
6487ac9a364SKalle Valo IL_ERR("Too many chunks: %i\n", counter);
6497ac9a364SKalle Valo /* @todo issue fatal error, it is quite serious situation */
6507ac9a364SKalle Valo return;
6517ac9a364SKalle Valo }
6527ac9a364SKalle Valo
6537ac9a364SKalle Valo /* Unmap tx_cmd */
6547ac9a364SKalle Valo if (counter)
655*ebe9e651SChristophe JAILLET dma_unmap_single(&dev->dev,
656*ebe9e651SChristophe JAILLET dma_unmap_addr(&txq->meta[idx], mapping),
6577ac9a364SKalle Valo dma_unmap_len(&txq->meta[idx], len),
658*ebe9e651SChristophe JAILLET DMA_TO_DEVICE);
6597ac9a364SKalle Valo
6607ac9a364SKalle Valo /* unmap chunks if any */
6617ac9a364SKalle Valo
6627ac9a364SKalle Valo for (i = 1; i < counter; i++)
663*ebe9e651SChristophe JAILLET dma_unmap_single(&dev->dev, le32_to_cpu(tfd->tbs[i].addr),
664*ebe9e651SChristophe JAILLET le32_to_cpu(tfd->tbs[i].len), DMA_TO_DEVICE);
6657ac9a364SKalle Valo
6667ac9a364SKalle Valo /* free SKB */
6677ac9a364SKalle Valo if (txq->skbs) {
6687ac9a364SKalle Valo struct sk_buff *skb = txq->skbs[txq->q.read_ptr];
6697ac9a364SKalle Valo
6707ac9a364SKalle Valo /* can be called from irqs-disabled context */
6717ac9a364SKalle Valo if (skb) {
6727ac9a364SKalle Valo dev_kfree_skb_any(skb);
6737ac9a364SKalle Valo txq->skbs[txq->q.read_ptr] = NULL;
6747ac9a364SKalle Valo }
6757ac9a364SKalle Valo }
6767ac9a364SKalle Valo }
6777ac9a364SKalle Valo
678a60e33afSLee Jones /*
6797ac9a364SKalle Valo * il3945_hw_build_tx_cmd_rate - Add rate portion to TX_CMD:
6807ac9a364SKalle Valo *
6817ac9a364SKalle Valo */
6827ac9a364SKalle Valo void
il3945_hw_build_tx_cmd_rate(struct il_priv * il,struct il_device_cmd * cmd,struct ieee80211_tx_info * info,struct ieee80211_hdr * hdr,int sta_id)6837ac9a364SKalle Valo il3945_hw_build_tx_cmd_rate(struct il_priv *il, struct il_device_cmd *cmd,
6847ac9a364SKalle Valo struct ieee80211_tx_info *info,
6857ac9a364SKalle Valo struct ieee80211_hdr *hdr, int sta_id)
6867ac9a364SKalle Valo {
6877ac9a364SKalle Valo u16 hw_value = ieee80211_get_tx_rate(il->hw, info)->hw_value;
6887ac9a364SKalle Valo u16 rate_idx = min(hw_value & 0xffff, RATE_COUNT_3945 - 1);
6897ac9a364SKalle Valo u16 rate_mask;
6907ac9a364SKalle Valo int rate;
6917ac9a364SKalle Valo const u8 rts_retry_limit = 7;
6927ac9a364SKalle Valo u8 data_retry_limit;
6937ac9a364SKalle Valo __le32 tx_flags;
6947ac9a364SKalle Valo __le16 fc = hdr->frame_control;
6957ac9a364SKalle Valo struct il3945_tx_cmd *tx_cmd = (struct il3945_tx_cmd *)cmd->cmd.payload;
6967ac9a364SKalle Valo
6977ac9a364SKalle Valo rate = il3945_rates[rate_idx].plcp;
6987ac9a364SKalle Valo tx_flags = tx_cmd->tx_flags;
6997ac9a364SKalle Valo
7007ac9a364SKalle Valo /* We need to figure out how to get the sta->supp_rates while
7017ac9a364SKalle Valo * in this running context */
7027ac9a364SKalle Valo rate_mask = RATES_MASK_3945;
7037ac9a364SKalle Valo
7047ac9a364SKalle Valo /* Set retry limit on DATA packets and Probe Responses */
7057ac9a364SKalle Valo if (ieee80211_is_probe_resp(fc))
7067ac9a364SKalle Valo data_retry_limit = 3;
7077ac9a364SKalle Valo else
7087ac9a364SKalle Valo data_retry_limit = IL_DEFAULT_TX_RETRY;
7097ac9a364SKalle Valo tx_cmd->data_retry_limit = data_retry_limit;
7107ac9a364SKalle Valo /* Set retry limit on RTS packets */
7117ac9a364SKalle Valo tx_cmd->rts_retry_limit = min(data_retry_limit, rts_retry_limit);
7127ac9a364SKalle Valo
7137ac9a364SKalle Valo tx_cmd->rate = rate;
7147ac9a364SKalle Valo tx_cmd->tx_flags = tx_flags;
7157ac9a364SKalle Valo
7167ac9a364SKalle Valo /* OFDM */
7177ac9a364SKalle Valo tx_cmd->supp_rates[0] =
7187ac9a364SKalle Valo ((rate_mask & IL_OFDM_RATES_MASK) >> IL_FIRST_OFDM_RATE) & 0xFF;
7197ac9a364SKalle Valo
7207ac9a364SKalle Valo /* CCK */
7217ac9a364SKalle Valo tx_cmd->supp_rates[1] = (rate_mask & 0xF);
7227ac9a364SKalle Valo
7237ac9a364SKalle Valo D_RATE("Tx sta id: %d, rate: %d (plcp), flags: 0x%4X "
7247ac9a364SKalle Valo "cck/ofdm mask: 0x%x/0x%x\n", sta_id, tx_cmd->rate,
7257ac9a364SKalle Valo le32_to_cpu(tx_cmd->tx_flags), tx_cmd->supp_rates[1],
7267ac9a364SKalle Valo tx_cmd->supp_rates[0]);
7277ac9a364SKalle Valo }
7287ac9a364SKalle Valo
7297ac9a364SKalle Valo static u8
il3945_sync_sta(struct il_priv * il,int sta_id,u16 tx_rate)7307ac9a364SKalle Valo il3945_sync_sta(struct il_priv *il, int sta_id, u16 tx_rate)
7317ac9a364SKalle Valo {
7327ac9a364SKalle Valo unsigned long flags_spin;
7337ac9a364SKalle Valo struct il_station_entry *station;
7347ac9a364SKalle Valo
7357ac9a364SKalle Valo if (sta_id == IL_INVALID_STATION)
7367ac9a364SKalle Valo return IL_INVALID_STATION;
7377ac9a364SKalle Valo
7387ac9a364SKalle Valo spin_lock_irqsave(&il->sta_lock, flags_spin);
7397ac9a364SKalle Valo station = &il->stations[sta_id];
7407ac9a364SKalle Valo
7417ac9a364SKalle Valo station->sta.sta.modify_mask = STA_MODIFY_TX_RATE_MSK;
7427ac9a364SKalle Valo station->sta.rate_n_flags = cpu_to_le16(tx_rate);
7437ac9a364SKalle Valo station->sta.mode = STA_CONTROL_MODIFY_MSK;
7447ac9a364SKalle Valo il_send_add_sta(il, &station->sta, CMD_ASYNC);
7457ac9a364SKalle Valo spin_unlock_irqrestore(&il->sta_lock, flags_spin);
7467ac9a364SKalle Valo
7477ac9a364SKalle Valo D_RATE("SCALE sync station %d to rate %d\n", sta_id, tx_rate);
7487ac9a364SKalle Valo return sta_id;
7497ac9a364SKalle Valo }
7507ac9a364SKalle Valo
7517ac9a364SKalle Valo static void
il3945_set_pwr_vmain(struct il_priv * il)7527ac9a364SKalle Valo il3945_set_pwr_vmain(struct il_priv *il)
7537ac9a364SKalle Valo {
7547ac9a364SKalle Valo /*
7557ac9a364SKalle Valo * (for documentation purposes)
7567ac9a364SKalle Valo * to set power to V_AUX, do
7577ac9a364SKalle Valo
7587ac9a364SKalle Valo if (pci_pme_capable(il->pci_dev, PCI_D3cold)) {
7597ac9a364SKalle Valo il_set_bits_mask_prph(il, APMG_PS_CTRL_REG,
7607ac9a364SKalle Valo APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
7617ac9a364SKalle Valo ~APMG_PS_CTRL_MSK_PWR_SRC);
7627ac9a364SKalle Valo
7637ac9a364SKalle Valo _il_poll_bit(il, CSR_GPIO_IN,
7647ac9a364SKalle Valo CSR_GPIO_IN_VAL_VAUX_PWR_SRC,
7657ac9a364SKalle Valo CSR_GPIO_IN_BIT_AUX_POWER, 5000);
7667ac9a364SKalle Valo }
7677ac9a364SKalle Valo */
7687ac9a364SKalle Valo
7697ac9a364SKalle Valo il_set_bits_mask_prph(il, APMG_PS_CTRL_REG,
7707ac9a364SKalle Valo APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
7717ac9a364SKalle Valo ~APMG_PS_CTRL_MSK_PWR_SRC);
7727ac9a364SKalle Valo
7737ac9a364SKalle Valo _il_poll_bit(il, CSR_GPIO_IN, CSR_GPIO_IN_VAL_VMAIN_PWR_SRC,
7747ac9a364SKalle Valo CSR_GPIO_IN_BIT_AUX_POWER, 5000);
7757ac9a364SKalle Valo }
7767ac9a364SKalle Valo
7777ac9a364SKalle Valo static int
il3945_rx_init(struct il_priv * il,struct il_rx_queue * rxq)7787ac9a364SKalle Valo il3945_rx_init(struct il_priv *il, struct il_rx_queue *rxq)
7797ac9a364SKalle Valo {
7807ac9a364SKalle Valo il_wr(il, FH39_RCSR_RBD_BASE(0), rxq->bd_dma);
7817ac9a364SKalle Valo il_wr(il, FH39_RCSR_RPTR_ADDR(0), rxq->rb_stts_dma);
7827ac9a364SKalle Valo il_wr(il, FH39_RCSR_WPTR(0), 0);
7837ac9a364SKalle Valo il_wr(il, FH39_RCSR_CONFIG(0),
7847ac9a364SKalle Valo FH39_RCSR_RX_CONFIG_REG_VAL_DMA_CHNL_EN_ENABLE |
7857ac9a364SKalle Valo FH39_RCSR_RX_CONFIG_REG_VAL_RDRBD_EN_ENABLE |
7867ac9a364SKalle Valo FH39_RCSR_RX_CONFIG_REG_BIT_WR_STTS_EN |
7877ac9a364SKalle Valo FH39_RCSR_RX_CONFIG_REG_VAL_MAX_FRAG_SIZE_128 | (RX_QUEUE_SIZE_LOG
7887ac9a364SKalle Valo <<
7897ac9a364SKalle Valo FH39_RCSR_RX_CONFIG_REG_POS_RBDC_SIZE)
7907ac9a364SKalle Valo | FH39_RCSR_RX_CONFIG_REG_VAL_IRQ_DEST_INT_HOST | (1 <<
7917ac9a364SKalle Valo FH39_RCSR_RX_CONFIG_REG_POS_IRQ_RBTH)
7927ac9a364SKalle Valo | FH39_RCSR_RX_CONFIG_REG_VAL_MSG_MODE_FH);
7937ac9a364SKalle Valo
7947ac9a364SKalle Valo /* fake read to flush all prev I/O */
7957ac9a364SKalle Valo il_rd(il, FH39_RSSR_CTRL);
7967ac9a364SKalle Valo
7977ac9a364SKalle Valo return 0;
7987ac9a364SKalle Valo }
7997ac9a364SKalle Valo
8007ac9a364SKalle Valo static int
il3945_tx_reset(struct il_priv * il)8017ac9a364SKalle Valo il3945_tx_reset(struct il_priv *il)
8027ac9a364SKalle Valo {
8037ac9a364SKalle Valo /* bypass mode */
8047ac9a364SKalle Valo il_wr_prph(il, ALM_SCD_MODE_REG, 0x2);
8057ac9a364SKalle Valo
8067ac9a364SKalle Valo /* RA 0 is active */
8077ac9a364SKalle Valo il_wr_prph(il, ALM_SCD_ARASTAT_REG, 0x01);
8087ac9a364SKalle Valo
8097ac9a364SKalle Valo /* all 6 fifo are active */
8107ac9a364SKalle Valo il_wr_prph(il, ALM_SCD_TXFACT_REG, 0x3f);
8117ac9a364SKalle Valo
8127ac9a364SKalle Valo il_wr_prph(il, ALM_SCD_SBYP_MODE_1_REG, 0x010000);
8137ac9a364SKalle Valo il_wr_prph(il, ALM_SCD_SBYP_MODE_2_REG, 0x030002);
8147ac9a364SKalle Valo il_wr_prph(il, ALM_SCD_TXF4MF_REG, 0x000004);
8157ac9a364SKalle Valo il_wr_prph(il, ALM_SCD_TXF5MF_REG, 0x000005);
8167ac9a364SKalle Valo
8177ac9a364SKalle Valo il_wr(il, FH39_TSSR_CBB_BASE, il->_3945.shared_phys);
8187ac9a364SKalle Valo
8197ac9a364SKalle Valo il_wr(il, FH39_TSSR_MSG_CONFIG,
8207ac9a364SKalle Valo FH39_TSSR_TX_MSG_CONFIG_REG_VAL_SNOOP_RD_TXPD_ON |
8217ac9a364SKalle Valo FH39_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RD_TXPD_ON |
8227ac9a364SKalle Valo FH39_TSSR_TX_MSG_CONFIG_REG_VAL_MAX_FRAG_SIZE_128B |
8237ac9a364SKalle Valo FH39_TSSR_TX_MSG_CONFIG_REG_VAL_SNOOP_RD_TFD_ON |
8247ac9a364SKalle Valo FH39_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RD_CBB_ON |
8257ac9a364SKalle Valo FH39_TSSR_TX_MSG_CONFIG_REG_VAL_ORDER_RSP_WAIT_TH |
8267ac9a364SKalle Valo FH39_TSSR_TX_MSG_CONFIG_REG_VAL_RSP_WAIT_TH);
8277ac9a364SKalle Valo
8287ac9a364SKalle Valo return 0;
8297ac9a364SKalle Valo }
8307ac9a364SKalle Valo
831a60e33afSLee Jones /*
8327ac9a364SKalle Valo * il3945_txq_ctx_reset - Reset TX queue context
8337ac9a364SKalle Valo *
8347ac9a364SKalle Valo * Destroys all DMA structures and initialize them again
8357ac9a364SKalle Valo */
8367ac9a364SKalle Valo static int
il3945_txq_ctx_reset(struct il_priv * il)8377ac9a364SKalle Valo il3945_txq_ctx_reset(struct il_priv *il)
8387ac9a364SKalle Valo {
8397ac9a364SKalle Valo int rc, txq_id;
8407ac9a364SKalle Valo
8417ac9a364SKalle Valo il3945_hw_txq_ctx_free(il);
8427ac9a364SKalle Valo
8437ac9a364SKalle Valo /* allocate tx queue structure */
8447ac9a364SKalle Valo rc = il_alloc_txq_mem(il);
8457ac9a364SKalle Valo if (rc)
8467ac9a364SKalle Valo return rc;
8477ac9a364SKalle Valo
8487ac9a364SKalle Valo /* Tx CMD queue */
8497ac9a364SKalle Valo rc = il3945_tx_reset(il);
8507ac9a364SKalle Valo if (rc)
8517ac9a364SKalle Valo goto error;
8527ac9a364SKalle Valo
8537ac9a364SKalle Valo /* Tx queue(s) */
8547ac9a364SKalle Valo for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++) {
8557ac9a364SKalle Valo rc = il_tx_queue_init(il, txq_id);
8567ac9a364SKalle Valo if (rc) {
8577ac9a364SKalle Valo IL_ERR("Tx %d queue init failed\n", txq_id);
8587ac9a364SKalle Valo goto error;
8597ac9a364SKalle Valo }
8607ac9a364SKalle Valo }
8617ac9a364SKalle Valo
8627ac9a364SKalle Valo return rc;
8637ac9a364SKalle Valo
8647ac9a364SKalle Valo error:
8657ac9a364SKalle Valo il3945_hw_txq_ctx_free(il);
8667ac9a364SKalle Valo return rc;
8677ac9a364SKalle Valo }
8687ac9a364SKalle Valo
8697ac9a364SKalle Valo /*
8707ac9a364SKalle Valo * Start up 3945's basic functionality after it has been reset
8717ac9a364SKalle Valo * (e.g. after platform boot, or shutdown via il_apm_stop())
8727ac9a364SKalle Valo * NOTE: This does not load uCode nor start the embedded processor
8737ac9a364SKalle Valo */
8747ac9a364SKalle Valo static int
il3945_apm_init(struct il_priv * il)8757ac9a364SKalle Valo il3945_apm_init(struct il_priv *il)
8767ac9a364SKalle Valo {
8777ac9a364SKalle Valo int ret = il_apm_init(il);
8787ac9a364SKalle Valo
8797ac9a364SKalle Valo /* Clear APMG (NIC's internal power management) interrupts */
8807ac9a364SKalle Valo il_wr_prph(il, APMG_RTC_INT_MSK_REG, 0x0);
8817ac9a364SKalle Valo il_wr_prph(il, APMG_RTC_INT_STT_REG, 0xFFFFFFFF);
8827ac9a364SKalle Valo
8837ac9a364SKalle Valo /* Reset radio chip */
8847ac9a364SKalle Valo il_set_bits_prph(il, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_RESET_REQ);
8857ac9a364SKalle Valo udelay(5);
8867ac9a364SKalle Valo il_clear_bits_prph(il, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_RESET_REQ);
8877ac9a364SKalle Valo
8887ac9a364SKalle Valo return ret;
8897ac9a364SKalle Valo }
8907ac9a364SKalle Valo
8917ac9a364SKalle Valo static void
il3945_nic_config(struct il_priv * il)8927ac9a364SKalle Valo il3945_nic_config(struct il_priv *il)
8937ac9a364SKalle Valo {
8947ac9a364SKalle Valo struct il3945_eeprom *eeprom = (struct il3945_eeprom *)il->eeprom;
8957ac9a364SKalle Valo unsigned long flags;
8967ac9a364SKalle Valo u8 rev_id = il->pci_dev->revision;
8977ac9a364SKalle Valo
8987ac9a364SKalle Valo spin_lock_irqsave(&il->lock, flags);
8997ac9a364SKalle Valo
9007ac9a364SKalle Valo /* Determine HW type */
9017ac9a364SKalle Valo D_INFO("HW Revision ID = 0x%X\n", rev_id);
9027ac9a364SKalle Valo
9037ac9a364SKalle Valo if (rev_id & PCI_CFG_REV_ID_BIT_RTP)
9047ac9a364SKalle Valo D_INFO("RTP type\n");
9057ac9a364SKalle Valo else if (rev_id & PCI_CFG_REV_ID_BIT_BASIC_SKU) {
9067ac9a364SKalle Valo D_INFO("3945 RADIO-MB type\n");
9077ac9a364SKalle Valo il_set_bit(il, CSR_HW_IF_CONFIG_REG,
9087ac9a364SKalle Valo CSR39_HW_IF_CONFIG_REG_BIT_3945_MB);
9097ac9a364SKalle Valo } else {
9107ac9a364SKalle Valo D_INFO("3945 RADIO-MM type\n");
9117ac9a364SKalle Valo il_set_bit(il, CSR_HW_IF_CONFIG_REG,
9127ac9a364SKalle Valo CSR39_HW_IF_CONFIG_REG_BIT_3945_MM);
9137ac9a364SKalle Valo }
9147ac9a364SKalle Valo
9157ac9a364SKalle Valo if (EEPROM_SKU_CAP_OP_MODE_MRC == eeprom->sku_cap) {
9167ac9a364SKalle Valo D_INFO("SKU OP mode is mrc\n");
9177ac9a364SKalle Valo il_set_bit(il, CSR_HW_IF_CONFIG_REG,
9187ac9a364SKalle Valo CSR39_HW_IF_CONFIG_REG_BIT_SKU_MRC);
9197ac9a364SKalle Valo } else
9207ac9a364SKalle Valo D_INFO("SKU OP mode is basic\n");
9217ac9a364SKalle Valo
9227ac9a364SKalle Valo if ((eeprom->board_revision & 0xF0) == 0xD0) {
9237ac9a364SKalle Valo D_INFO("3945ABG revision is 0x%X\n", eeprom->board_revision);
9247ac9a364SKalle Valo il_set_bit(il, CSR_HW_IF_CONFIG_REG,
9257ac9a364SKalle Valo CSR39_HW_IF_CONFIG_REG_BIT_BOARD_TYPE);
9267ac9a364SKalle Valo } else {
9277ac9a364SKalle Valo D_INFO("3945ABG revision is 0x%X\n", eeprom->board_revision);
9287ac9a364SKalle Valo il_clear_bit(il, CSR_HW_IF_CONFIG_REG,
9297ac9a364SKalle Valo CSR39_HW_IF_CONFIG_REG_BIT_BOARD_TYPE);
9307ac9a364SKalle Valo }
9317ac9a364SKalle Valo
9327ac9a364SKalle Valo if (eeprom->almgor_m_version <= 1) {
9337ac9a364SKalle Valo il_set_bit(il, CSR_HW_IF_CONFIG_REG,
9347ac9a364SKalle Valo CSR39_HW_IF_CONFIG_REG_BITS_SILICON_TYPE_A);
9357ac9a364SKalle Valo D_INFO("Card M type A version is 0x%X\n",
9367ac9a364SKalle Valo eeprom->almgor_m_version);
9377ac9a364SKalle Valo } else {
9387ac9a364SKalle Valo D_INFO("Card M type B version is 0x%X\n",
9397ac9a364SKalle Valo eeprom->almgor_m_version);
9407ac9a364SKalle Valo il_set_bit(il, CSR_HW_IF_CONFIG_REG,
9417ac9a364SKalle Valo CSR39_HW_IF_CONFIG_REG_BITS_SILICON_TYPE_B);
9427ac9a364SKalle Valo }
9437ac9a364SKalle Valo spin_unlock_irqrestore(&il->lock, flags);
9447ac9a364SKalle Valo
9457ac9a364SKalle Valo if (eeprom->sku_cap & EEPROM_SKU_CAP_SW_RF_KILL_ENABLE)
9467ac9a364SKalle Valo D_RF_KILL("SW RF KILL supported in EEPROM.\n");
9477ac9a364SKalle Valo
9487ac9a364SKalle Valo if (eeprom->sku_cap & EEPROM_SKU_CAP_HW_RF_KILL_ENABLE)
9497ac9a364SKalle Valo D_RF_KILL("HW RF KILL supported in EEPROM.\n");
9507ac9a364SKalle Valo }
9517ac9a364SKalle Valo
9527ac9a364SKalle Valo int
il3945_hw_nic_init(struct il_priv * il)9537ac9a364SKalle Valo il3945_hw_nic_init(struct il_priv *il)
9547ac9a364SKalle Valo {
9557ac9a364SKalle Valo int rc;
9567ac9a364SKalle Valo unsigned long flags;
9577ac9a364SKalle Valo struct il_rx_queue *rxq = &il->rxq;
9587ac9a364SKalle Valo
9597ac9a364SKalle Valo spin_lock_irqsave(&il->lock, flags);
9607ac9a364SKalle Valo il3945_apm_init(il);
9617ac9a364SKalle Valo spin_unlock_irqrestore(&il->lock, flags);
9627ac9a364SKalle Valo
9637ac9a364SKalle Valo il3945_set_pwr_vmain(il);
9647ac9a364SKalle Valo il3945_nic_config(il);
9657ac9a364SKalle Valo
9667ac9a364SKalle Valo /* Allocate the RX queue, or reset if it is already allocated */
9677ac9a364SKalle Valo if (!rxq->bd) {
9687ac9a364SKalle Valo rc = il_rx_queue_alloc(il);
9697ac9a364SKalle Valo if (rc) {
9707ac9a364SKalle Valo IL_ERR("Unable to initialize Rx queue\n");
9717ac9a364SKalle Valo return -ENOMEM;
9727ac9a364SKalle Valo }
9737ac9a364SKalle Valo } else
9747ac9a364SKalle Valo il3945_rx_queue_reset(il, rxq);
9757ac9a364SKalle Valo
9767ac9a364SKalle Valo il3945_rx_replenish(il);
9777ac9a364SKalle Valo
9787ac9a364SKalle Valo il3945_rx_init(il, rxq);
9797ac9a364SKalle Valo
9807ac9a364SKalle Valo /* Look at using this instead:
9817ac9a364SKalle Valo rxq->need_update = 1;
9827ac9a364SKalle Valo il_rx_queue_update_write_ptr(il, rxq);
9837ac9a364SKalle Valo */
9847ac9a364SKalle Valo
9857ac9a364SKalle Valo il_wr(il, FH39_RCSR_WPTR(0), rxq->write & ~7);
9867ac9a364SKalle Valo
9877ac9a364SKalle Valo rc = il3945_txq_ctx_reset(il);
9887ac9a364SKalle Valo if (rc)
9897ac9a364SKalle Valo return rc;
9907ac9a364SKalle Valo
9917ac9a364SKalle Valo set_bit(S_INIT, &il->status);
9927ac9a364SKalle Valo
9937ac9a364SKalle Valo return 0;
9947ac9a364SKalle Valo }
9957ac9a364SKalle Valo
996a60e33afSLee Jones /*
9977ac9a364SKalle Valo * il3945_hw_txq_ctx_free - Free TXQ Context
9987ac9a364SKalle Valo *
9997ac9a364SKalle Valo * Destroy all TX DMA queues and structures
10007ac9a364SKalle Valo */
10017ac9a364SKalle Valo void
il3945_hw_txq_ctx_free(struct il_priv * il)10027ac9a364SKalle Valo il3945_hw_txq_ctx_free(struct il_priv *il)
10037ac9a364SKalle Valo {
10047ac9a364SKalle Valo int txq_id;
10057ac9a364SKalle Valo
10067ac9a364SKalle Valo /* Tx queues */
10072cce76c3SArnd Bergmann if (il->txq) {
10087ac9a364SKalle Valo for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++)
10097ac9a364SKalle Valo if (txq_id == IL39_CMD_QUEUE_NUM)
10107ac9a364SKalle Valo il_cmd_queue_free(il);
10117ac9a364SKalle Valo else
10127ac9a364SKalle Valo il_tx_queue_free(il, txq_id);
10132cce76c3SArnd Bergmann }
10147ac9a364SKalle Valo
10157ac9a364SKalle Valo /* free tx queue structure */
10167ac9a364SKalle Valo il_free_txq_mem(il);
10177ac9a364SKalle Valo }
10187ac9a364SKalle Valo
10197ac9a364SKalle Valo void
il3945_hw_txq_ctx_stop(struct il_priv * il)10207ac9a364SKalle Valo il3945_hw_txq_ctx_stop(struct il_priv *il)
10217ac9a364SKalle Valo {
10227ac9a364SKalle Valo int txq_id;
10237ac9a364SKalle Valo
10247ac9a364SKalle Valo /* stop SCD */
10257ac9a364SKalle Valo _il_wr_prph(il, ALM_SCD_MODE_REG, 0);
10267ac9a364SKalle Valo _il_wr_prph(il, ALM_SCD_TXFACT_REG, 0);
10277ac9a364SKalle Valo
10287ac9a364SKalle Valo /* reset TFD queues */
10297ac9a364SKalle Valo for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++) {
10307ac9a364SKalle Valo _il_wr(il, FH39_TCSR_CONFIG(txq_id), 0x0);
10317ac9a364SKalle Valo _il_poll_bit(il, FH39_TSSR_TX_STATUS,
10327ac9a364SKalle Valo FH39_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(txq_id),
10337ac9a364SKalle Valo FH39_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(txq_id),
10347ac9a364SKalle Valo 1000);
10357ac9a364SKalle Valo }
10367ac9a364SKalle Valo }
10377ac9a364SKalle Valo
1038a60e33afSLee Jones /*
10397ac9a364SKalle Valo * il3945_hw_reg_adjust_power_by_temp
10407ac9a364SKalle Valo * return idx delta into power gain settings table
10417ac9a364SKalle Valo */
10427ac9a364SKalle Valo static int
il3945_hw_reg_adjust_power_by_temp(int new_reading,int old_reading)10437ac9a364SKalle Valo il3945_hw_reg_adjust_power_by_temp(int new_reading, int old_reading)
10447ac9a364SKalle Valo {
10457ac9a364SKalle Valo return (new_reading - old_reading) * (-11) / 100;
10467ac9a364SKalle Valo }
10477ac9a364SKalle Valo
1048a60e33afSLee Jones /*
10497ac9a364SKalle Valo * il3945_hw_reg_temp_out_of_range - Keep temperature in sane range
10507ac9a364SKalle Valo */
10517ac9a364SKalle Valo static inline int
il3945_hw_reg_temp_out_of_range(int temperature)10527ac9a364SKalle Valo il3945_hw_reg_temp_out_of_range(int temperature)
10537ac9a364SKalle Valo {
10547ac9a364SKalle Valo return (temperature < -260 || temperature > 25) ? 1 : 0;
10557ac9a364SKalle Valo }
10567ac9a364SKalle Valo
10577ac9a364SKalle Valo int
il3945_hw_get_temperature(struct il_priv * il)10587ac9a364SKalle Valo il3945_hw_get_temperature(struct il_priv *il)
10597ac9a364SKalle Valo {
10607ac9a364SKalle Valo return _il_rd(il, CSR_UCODE_DRV_GP2);
10617ac9a364SKalle Valo }
10627ac9a364SKalle Valo
1063a60e33afSLee Jones /*
10647ac9a364SKalle Valo * il3945_hw_reg_txpower_get_temperature
10657ac9a364SKalle Valo * get the current temperature by reading from NIC
10667ac9a364SKalle Valo */
10677ac9a364SKalle Valo static int
il3945_hw_reg_txpower_get_temperature(struct il_priv * il)10687ac9a364SKalle Valo il3945_hw_reg_txpower_get_temperature(struct il_priv *il)
10697ac9a364SKalle Valo {
10707ac9a364SKalle Valo struct il3945_eeprom *eeprom = (struct il3945_eeprom *)il->eeprom;
10717ac9a364SKalle Valo int temperature;
10727ac9a364SKalle Valo
10737ac9a364SKalle Valo temperature = il3945_hw_get_temperature(il);
10747ac9a364SKalle Valo
10757ac9a364SKalle Valo /* driver's okay range is -260 to +25.
10767ac9a364SKalle Valo * human readable okay range is 0 to +285 */
10777ac9a364SKalle Valo D_INFO("Temperature: %d\n", temperature + IL_TEMP_CONVERT);
10787ac9a364SKalle Valo
10797ac9a364SKalle Valo /* handle insane temp reading */
10807ac9a364SKalle Valo if (il3945_hw_reg_temp_out_of_range(temperature)) {
10817ac9a364SKalle Valo IL_ERR("Error bad temperature value %d\n", temperature);
10827ac9a364SKalle Valo
10837ac9a364SKalle Valo /* if really really hot(?),
10847ac9a364SKalle Valo * substitute the 3rd band/group's temp measured at factory */
10857ac9a364SKalle Valo if (il->last_temperature > 100)
10867ac9a364SKalle Valo temperature = eeprom->groups[2].temperature;
10877ac9a364SKalle Valo else /* else use most recent "sane" value from driver */
10887ac9a364SKalle Valo temperature = il->last_temperature;
10897ac9a364SKalle Valo }
10907ac9a364SKalle Valo
10917ac9a364SKalle Valo return temperature; /* raw, not "human readable" */
10927ac9a364SKalle Valo }
10937ac9a364SKalle Valo
10947ac9a364SKalle Valo /* Adjust Txpower only if temperature variance is greater than threshold.
10957ac9a364SKalle Valo *
10967ac9a364SKalle Valo * Both are lower than older versions' 9 degrees */
10977ac9a364SKalle Valo #define IL_TEMPERATURE_LIMIT_TIMER 6
10987ac9a364SKalle Valo
1099a60e33afSLee Jones /*
11007ac9a364SKalle Valo * il3945_is_temp_calib_needed - determines if new calibration is needed
11017ac9a364SKalle Valo *
11027ac9a364SKalle Valo * records new temperature in tx_mgr->temperature.
11037ac9a364SKalle Valo * replaces tx_mgr->last_temperature *only* if calib needed
11047ac9a364SKalle Valo * (assumes caller will actually do the calibration!). */
11057ac9a364SKalle Valo static int
il3945_is_temp_calib_needed(struct il_priv * il)11067ac9a364SKalle Valo il3945_is_temp_calib_needed(struct il_priv *il)
11077ac9a364SKalle Valo {
11087ac9a364SKalle Valo int temp_diff;
11097ac9a364SKalle Valo
11107ac9a364SKalle Valo il->temperature = il3945_hw_reg_txpower_get_temperature(il);
11117ac9a364SKalle Valo temp_diff = il->temperature - il->last_temperature;
11127ac9a364SKalle Valo
11137ac9a364SKalle Valo /* get absolute value */
11147ac9a364SKalle Valo if (temp_diff < 0) {
11157ac9a364SKalle Valo D_POWER("Getting cooler, delta %d,\n", temp_diff);
11167ac9a364SKalle Valo temp_diff = -temp_diff;
11177ac9a364SKalle Valo } else if (temp_diff == 0)
11187ac9a364SKalle Valo D_POWER("Same temp,\n");
11197ac9a364SKalle Valo else
11207ac9a364SKalle Valo D_POWER("Getting warmer, delta %d,\n", temp_diff);
11217ac9a364SKalle Valo
11227ac9a364SKalle Valo /* if we don't need calibration, *don't* update last_temperature */
11237ac9a364SKalle Valo if (temp_diff < IL_TEMPERATURE_LIMIT_TIMER) {
11247ac9a364SKalle Valo D_POWER("Timed thermal calib not needed\n");
11257ac9a364SKalle Valo return 0;
11267ac9a364SKalle Valo }
11277ac9a364SKalle Valo
11287ac9a364SKalle Valo D_POWER("Timed thermal calib needed\n");
11297ac9a364SKalle Valo
11307ac9a364SKalle Valo /* assume that caller will actually do calib ...
11317ac9a364SKalle Valo * update the "last temperature" value */
11327ac9a364SKalle Valo il->last_temperature = il->temperature;
11337ac9a364SKalle Valo return 1;
11347ac9a364SKalle Valo }
11357ac9a364SKalle Valo
11367ac9a364SKalle Valo #define IL_MAX_GAIN_ENTRIES 78
11377ac9a364SKalle Valo #define IL_CCK_FROM_OFDM_POWER_DIFF -5
11387ac9a364SKalle Valo #define IL_CCK_FROM_OFDM_IDX_DIFF (10)
11397ac9a364SKalle Valo
11407ac9a364SKalle Valo /* radio and DSP power table, each step is 1/2 dB.
11417ac9a364SKalle Valo * 1st number is for RF analog gain, 2nd number is for DSP pre-DAC gain. */
11427ac9a364SKalle Valo static struct il3945_tx_power power_gain_table[2][IL_MAX_GAIN_ENTRIES] = {
11437ac9a364SKalle Valo {
11447ac9a364SKalle Valo {251, 127}, /* 2.4 GHz, highest power */
11457ac9a364SKalle Valo {251, 127},
11467ac9a364SKalle Valo {251, 127},
11477ac9a364SKalle Valo {251, 127},
11487ac9a364SKalle Valo {251, 125},
11497ac9a364SKalle Valo {251, 110},
11507ac9a364SKalle Valo {251, 105},
11517ac9a364SKalle Valo {251, 98},
11527ac9a364SKalle Valo {187, 125},
11537ac9a364SKalle Valo {187, 115},
11547ac9a364SKalle Valo {187, 108},
11557ac9a364SKalle Valo {187, 99},
11567ac9a364SKalle Valo {243, 119},
11577ac9a364SKalle Valo {243, 111},
11587ac9a364SKalle Valo {243, 105},
11597ac9a364SKalle Valo {243, 97},
11607ac9a364SKalle Valo {243, 92},
11617ac9a364SKalle Valo {211, 106},
11627ac9a364SKalle Valo {211, 100},
11637ac9a364SKalle Valo {179, 120},
11647ac9a364SKalle Valo {179, 113},
11657ac9a364SKalle Valo {179, 107},
11667ac9a364SKalle Valo {147, 125},
11677ac9a364SKalle Valo {147, 119},
11687ac9a364SKalle Valo {147, 112},
11697ac9a364SKalle Valo {147, 106},
11707ac9a364SKalle Valo {147, 101},
11717ac9a364SKalle Valo {147, 97},
11727ac9a364SKalle Valo {147, 91},
11737ac9a364SKalle Valo {115, 107},
11747ac9a364SKalle Valo {235, 121},
11757ac9a364SKalle Valo {235, 115},
11767ac9a364SKalle Valo {235, 109},
11777ac9a364SKalle Valo {203, 127},
11787ac9a364SKalle Valo {203, 121},
11797ac9a364SKalle Valo {203, 115},
11807ac9a364SKalle Valo {203, 108},
11817ac9a364SKalle Valo {203, 102},
11827ac9a364SKalle Valo {203, 96},
11837ac9a364SKalle Valo {203, 92},
11847ac9a364SKalle Valo {171, 110},
11857ac9a364SKalle Valo {171, 104},
11867ac9a364SKalle Valo {171, 98},
11877ac9a364SKalle Valo {139, 116},
11887ac9a364SKalle Valo {227, 125},
11897ac9a364SKalle Valo {227, 119},
11907ac9a364SKalle Valo {227, 113},
11917ac9a364SKalle Valo {227, 107},
11927ac9a364SKalle Valo {227, 101},
11937ac9a364SKalle Valo {227, 96},
11947ac9a364SKalle Valo {195, 113},
11957ac9a364SKalle Valo {195, 106},
11967ac9a364SKalle Valo {195, 102},
11977ac9a364SKalle Valo {195, 95},
11987ac9a364SKalle Valo {163, 113},
11997ac9a364SKalle Valo {163, 106},
12007ac9a364SKalle Valo {163, 102},
12017ac9a364SKalle Valo {163, 95},
12027ac9a364SKalle Valo {131, 113},
12037ac9a364SKalle Valo {131, 106},
12047ac9a364SKalle Valo {131, 102},
12057ac9a364SKalle Valo {131, 95},
12067ac9a364SKalle Valo {99, 113},
12077ac9a364SKalle Valo {99, 106},
12087ac9a364SKalle Valo {99, 102},
12097ac9a364SKalle Valo {99, 95},
12107ac9a364SKalle Valo {67, 113},
12117ac9a364SKalle Valo {67, 106},
12127ac9a364SKalle Valo {67, 102},
12137ac9a364SKalle Valo {67, 95},
12147ac9a364SKalle Valo {35, 113},
12157ac9a364SKalle Valo {35, 106},
12167ac9a364SKalle Valo {35, 102},
12177ac9a364SKalle Valo {35, 95},
12187ac9a364SKalle Valo {3, 113},
12197ac9a364SKalle Valo {3, 106},
12207ac9a364SKalle Valo {3, 102},
12217ac9a364SKalle Valo {3, 95} /* 2.4 GHz, lowest power */
12227ac9a364SKalle Valo },
12237ac9a364SKalle Valo {
12247ac9a364SKalle Valo {251, 127}, /* 5.x GHz, highest power */
12257ac9a364SKalle Valo {251, 120},
12267ac9a364SKalle Valo {251, 114},
12277ac9a364SKalle Valo {219, 119},
12287ac9a364SKalle Valo {219, 101},
12297ac9a364SKalle Valo {187, 113},
12307ac9a364SKalle Valo {187, 102},
12317ac9a364SKalle Valo {155, 114},
12327ac9a364SKalle Valo {155, 103},
12337ac9a364SKalle Valo {123, 117},
12347ac9a364SKalle Valo {123, 107},
12357ac9a364SKalle Valo {123, 99},
12367ac9a364SKalle Valo {123, 92},
12377ac9a364SKalle Valo {91, 108},
12387ac9a364SKalle Valo {59, 125},
12397ac9a364SKalle Valo {59, 118},
12407ac9a364SKalle Valo {59, 109},
12417ac9a364SKalle Valo {59, 102},
12427ac9a364SKalle Valo {59, 96},
12437ac9a364SKalle Valo {59, 90},
12447ac9a364SKalle Valo {27, 104},
12457ac9a364SKalle Valo {27, 98},
12467ac9a364SKalle Valo {27, 92},
12477ac9a364SKalle Valo {115, 118},
12487ac9a364SKalle Valo {115, 111},
12497ac9a364SKalle Valo {115, 104},
12507ac9a364SKalle Valo {83, 126},
12517ac9a364SKalle Valo {83, 121},
12527ac9a364SKalle Valo {83, 113},
12537ac9a364SKalle Valo {83, 105},
12547ac9a364SKalle Valo {83, 99},
12557ac9a364SKalle Valo {51, 118},
12567ac9a364SKalle Valo {51, 111},
12577ac9a364SKalle Valo {51, 104},
12587ac9a364SKalle Valo {51, 98},
12597ac9a364SKalle Valo {19, 116},
12607ac9a364SKalle Valo {19, 109},
12617ac9a364SKalle Valo {19, 102},
12627ac9a364SKalle Valo {19, 98},
12637ac9a364SKalle Valo {19, 93},
12647ac9a364SKalle Valo {171, 113},
12657ac9a364SKalle Valo {171, 107},
12667ac9a364SKalle Valo {171, 99},
12677ac9a364SKalle Valo {139, 120},
12687ac9a364SKalle Valo {139, 113},
12697ac9a364SKalle Valo {139, 107},
12707ac9a364SKalle Valo {139, 99},
12717ac9a364SKalle Valo {107, 120},
12727ac9a364SKalle Valo {107, 113},
12737ac9a364SKalle Valo {107, 107},
12747ac9a364SKalle Valo {107, 99},
12757ac9a364SKalle Valo {75, 120},
12767ac9a364SKalle Valo {75, 113},
12777ac9a364SKalle Valo {75, 107},
12787ac9a364SKalle Valo {75, 99},
12797ac9a364SKalle Valo {43, 120},
12807ac9a364SKalle Valo {43, 113},
12817ac9a364SKalle Valo {43, 107},
12827ac9a364SKalle Valo {43, 99},
12837ac9a364SKalle Valo {11, 120},
12847ac9a364SKalle Valo {11, 113},
12857ac9a364SKalle Valo {11, 107},
12867ac9a364SKalle Valo {11, 99},
12877ac9a364SKalle Valo {131, 107},
12887ac9a364SKalle Valo {131, 99},
12897ac9a364SKalle Valo {99, 120},
12907ac9a364SKalle Valo {99, 113},
12917ac9a364SKalle Valo {99, 107},
12927ac9a364SKalle Valo {99, 99},
12937ac9a364SKalle Valo {67, 120},
12947ac9a364SKalle Valo {67, 113},
12957ac9a364SKalle Valo {67, 107},
12967ac9a364SKalle Valo {67, 99},
12977ac9a364SKalle Valo {35, 120},
12987ac9a364SKalle Valo {35, 113},
12997ac9a364SKalle Valo {35, 107},
13007ac9a364SKalle Valo {35, 99},
13017ac9a364SKalle Valo {3, 120} /* 5.x GHz, lowest power */
13027ac9a364SKalle Valo }
13037ac9a364SKalle Valo };
13047ac9a364SKalle Valo
13057ac9a364SKalle Valo static inline u8
il3945_hw_reg_fix_power_idx(int idx)13067ac9a364SKalle Valo il3945_hw_reg_fix_power_idx(int idx)
13077ac9a364SKalle Valo {
13087ac9a364SKalle Valo if (idx < 0)
13097ac9a364SKalle Valo return 0;
13107ac9a364SKalle Valo if (idx >= IL_MAX_GAIN_ENTRIES)
13117ac9a364SKalle Valo return IL_MAX_GAIN_ENTRIES - 1;
13127ac9a364SKalle Valo return (u8) idx;
13137ac9a364SKalle Valo }
13147ac9a364SKalle Valo
13157ac9a364SKalle Valo /* Kick off thermal recalibration check every 60 seconds */
13167ac9a364SKalle Valo #define REG_RECALIB_PERIOD (60)
13177ac9a364SKalle Valo
1318a60e33afSLee Jones /*
13197ac9a364SKalle Valo * il3945_hw_reg_set_scan_power - Set Tx power for scan probe requests
13207ac9a364SKalle Valo *
13217ac9a364SKalle Valo * Set (in our channel info database) the direct scan Tx power for 1 Mbit (CCK)
13227ac9a364SKalle Valo * or 6 Mbit (OFDM) rates.
13237ac9a364SKalle Valo */
13247ac9a364SKalle Valo static void
il3945_hw_reg_set_scan_power(struct il_priv * il,u32 scan_tbl_idx,s32 rate_idx,const s8 * clip_pwrs,struct il_channel_info * ch_info,int band_idx)13257ac9a364SKalle Valo il3945_hw_reg_set_scan_power(struct il_priv *il, u32 scan_tbl_idx, s32 rate_idx,
13267ac9a364SKalle Valo const s8 *clip_pwrs,
13277ac9a364SKalle Valo struct il_channel_info *ch_info, int band_idx)
13287ac9a364SKalle Valo {
13297ac9a364SKalle Valo struct il3945_scan_power_info *scan_power_info;
13307ac9a364SKalle Valo s8 power;
13317ac9a364SKalle Valo u8 power_idx;
13327ac9a364SKalle Valo
13337ac9a364SKalle Valo scan_power_info = &ch_info->scan_pwr_info[scan_tbl_idx];
13347ac9a364SKalle Valo
13357ac9a364SKalle Valo /* use this channel group's 6Mbit clipping/saturation pwr,
13367ac9a364SKalle Valo * but cap at regulatory scan power restriction (set during init
13377ac9a364SKalle Valo * based on eeprom channel data) for this channel. */
13387ac9a364SKalle Valo power = min(ch_info->scan_power, clip_pwrs[RATE_6M_IDX_TBL]);
13397ac9a364SKalle Valo
13407ac9a364SKalle Valo power = min(power, il->tx_power_user_lmt);
13417ac9a364SKalle Valo scan_power_info->requested_power = power;
13427ac9a364SKalle Valo
13437ac9a364SKalle Valo /* find difference between new scan *power* and current "normal"
13447ac9a364SKalle Valo * Tx *power* for 6Mb. Use this difference (x2) to adjust the
13457ac9a364SKalle Valo * current "normal" temperature-compensated Tx power *idx* for
13467ac9a364SKalle Valo * this rate (1Mb or 6Mb) to yield new temp-compensated scan power
13477ac9a364SKalle Valo * *idx*. */
13487ac9a364SKalle Valo power_idx =
13497ac9a364SKalle Valo ch_info->power_info[rate_idx].power_table_idx - (power -
13507ac9a364SKalle Valo ch_info->
13517ac9a364SKalle Valo power_info
13527ac9a364SKalle Valo [RATE_6M_IDX_TBL].
13537ac9a364SKalle Valo requested_power) *
13547ac9a364SKalle Valo 2;
13557ac9a364SKalle Valo
13567ac9a364SKalle Valo /* store reference idx that we use when adjusting *all* scan
13577ac9a364SKalle Valo * powers. So we can accommodate user (all channel) or spectrum
13587ac9a364SKalle Valo * management (single channel) power changes "between" temperature
13597ac9a364SKalle Valo * feedback compensation procedures.
13607ac9a364SKalle Valo * don't force fit this reference idx into gain table; it may be a
13617ac9a364SKalle Valo * negative number. This will help avoid errors when we're at
13627ac9a364SKalle Valo * the lower bounds (highest gains, for warmest temperatures)
13637ac9a364SKalle Valo * of the table. */
13647ac9a364SKalle Valo
13657ac9a364SKalle Valo /* don't exceed table bounds for "real" setting */
13667ac9a364SKalle Valo power_idx = il3945_hw_reg_fix_power_idx(power_idx);
13677ac9a364SKalle Valo
13687ac9a364SKalle Valo scan_power_info->power_table_idx = power_idx;
13697ac9a364SKalle Valo scan_power_info->tpc.tx_gain =
13707ac9a364SKalle Valo power_gain_table[band_idx][power_idx].tx_gain;
13717ac9a364SKalle Valo scan_power_info->tpc.dsp_atten =
13727ac9a364SKalle Valo power_gain_table[band_idx][power_idx].dsp_atten;
13737ac9a364SKalle Valo }
13747ac9a364SKalle Valo
1375a60e33afSLee Jones /*
13767ac9a364SKalle Valo * il3945_send_tx_power - fill in Tx Power command with gain settings
13777ac9a364SKalle Valo *
13787ac9a364SKalle Valo * Configures power settings for all rates for the current channel,
13797ac9a364SKalle Valo * using values from channel info struct, and send to NIC
13807ac9a364SKalle Valo */
13817ac9a364SKalle Valo static int
il3945_send_tx_power(struct il_priv * il)13827ac9a364SKalle Valo il3945_send_tx_power(struct il_priv *il)
13837ac9a364SKalle Valo {
13847ac9a364SKalle Valo int rate_idx, i;
13857ac9a364SKalle Valo const struct il_channel_info *ch_info = NULL;
13867ac9a364SKalle Valo struct il3945_txpowertable_cmd txpower = {
13877ac9a364SKalle Valo .channel = il->active.channel,
13887ac9a364SKalle Valo };
13897ac9a364SKalle Valo u16 chan;
13907ac9a364SKalle Valo
13917ac9a364SKalle Valo if (WARN_ONCE
13927ac9a364SKalle Valo (test_bit(S_SCAN_HW, &il->status),
13937ac9a364SKalle Valo "TX Power requested while scanning!\n"))
13947ac9a364SKalle Valo return -EAGAIN;
13957ac9a364SKalle Valo
13967ac9a364SKalle Valo chan = le16_to_cpu(il->active.channel);
13977ac9a364SKalle Valo
139857fbcce3SJohannes Berg txpower.band = (il->band == NL80211_BAND_5GHZ) ? 0 : 1;
13997ac9a364SKalle Valo ch_info = il_get_channel_info(il, il->band, chan);
14007ac9a364SKalle Valo if (!ch_info) {
14017ac9a364SKalle Valo IL_ERR("Failed to get channel info for channel %d [%d]\n", chan,
14027ac9a364SKalle Valo il->band);
14037ac9a364SKalle Valo return -EINVAL;
14047ac9a364SKalle Valo }
14057ac9a364SKalle Valo
14067ac9a364SKalle Valo if (!il_is_channel_valid(ch_info)) {
14077ac9a364SKalle Valo D_POWER("Not calling TX_PWR_TBL_CMD on " "non-Tx channel.\n");
14087ac9a364SKalle Valo return 0;
14097ac9a364SKalle Valo }
14107ac9a364SKalle Valo
14117ac9a364SKalle Valo /* fill cmd with power settings for all rates for current channel */
14127ac9a364SKalle Valo /* Fill OFDM rate */
14137ac9a364SKalle Valo for (rate_idx = IL_FIRST_OFDM_RATE, i = 0;
14147ac9a364SKalle Valo rate_idx <= IL39_LAST_OFDM_RATE; rate_idx++, i++) {
14157ac9a364SKalle Valo
14167ac9a364SKalle Valo txpower.power[i].tpc = ch_info->power_info[i].tpc;
14177ac9a364SKalle Valo txpower.power[i].rate = il3945_rates[rate_idx].plcp;
14187ac9a364SKalle Valo
14197ac9a364SKalle Valo D_POWER("ch %d:%d rf %d dsp %3d rate code 0x%02x\n",
14207ac9a364SKalle Valo le16_to_cpu(txpower.channel), txpower.band,
14217ac9a364SKalle Valo txpower.power[i].tpc.tx_gain,
14227ac9a364SKalle Valo txpower.power[i].tpc.dsp_atten, txpower.power[i].rate);
14237ac9a364SKalle Valo }
14247ac9a364SKalle Valo /* Fill CCK rates */
14257ac9a364SKalle Valo for (rate_idx = IL_FIRST_CCK_RATE; rate_idx <= IL_LAST_CCK_RATE;
14267ac9a364SKalle Valo rate_idx++, i++) {
14277ac9a364SKalle Valo txpower.power[i].tpc = ch_info->power_info[i].tpc;
14287ac9a364SKalle Valo txpower.power[i].rate = il3945_rates[rate_idx].plcp;
14297ac9a364SKalle Valo
14307ac9a364SKalle Valo D_POWER("ch %d:%d rf %d dsp %3d rate code 0x%02x\n",
14317ac9a364SKalle Valo le16_to_cpu(txpower.channel), txpower.band,
14327ac9a364SKalle Valo txpower.power[i].tpc.tx_gain,
14337ac9a364SKalle Valo txpower.power[i].tpc.dsp_atten, txpower.power[i].rate);
14347ac9a364SKalle Valo }
14357ac9a364SKalle Valo
14367ac9a364SKalle Valo return il_send_cmd_pdu(il, C_TX_PWR_TBL,
14377ac9a364SKalle Valo sizeof(struct il3945_txpowertable_cmd),
14387ac9a364SKalle Valo &txpower);
14397ac9a364SKalle Valo
14407ac9a364SKalle Valo }
14417ac9a364SKalle Valo
1442a60e33afSLee Jones /*
14437ac9a364SKalle Valo * il3945_hw_reg_set_new_power - Configures power tables at new levels
14447ac9a364SKalle Valo * @ch_info: Channel to update. Uses power_info.requested_power.
14457ac9a364SKalle Valo *
14467ac9a364SKalle Valo * Replace requested_power and base_power_idx ch_info fields for
14477ac9a364SKalle Valo * one channel.
14487ac9a364SKalle Valo *
14497ac9a364SKalle Valo * Called if user or spectrum management changes power preferences.
14507ac9a364SKalle Valo * Takes into account h/w and modulation limitations (clip power).
14517ac9a364SKalle Valo *
14527ac9a364SKalle Valo * This does *not* send anything to NIC, just sets up ch_info for one channel.
14537ac9a364SKalle Valo *
14547ac9a364SKalle Valo * NOTE: reg_compensate_for_temperature_dif() *must* be run after this to
14557ac9a364SKalle Valo * properly fill out the scan powers, and actual h/w gain settings,
14567ac9a364SKalle Valo * and send changes to NIC
14577ac9a364SKalle Valo */
14587ac9a364SKalle Valo static int
il3945_hw_reg_set_new_power(struct il_priv * il,struct il_channel_info * ch_info)14597ac9a364SKalle Valo il3945_hw_reg_set_new_power(struct il_priv *il, struct il_channel_info *ch_info)
14607ac9a364SKalle Valo {
14617ac9a364SKalle Valo struct il3945_channel_power_info *power_info;
14627ac9a364SKalle Valo int power_changed = 0;
14637ac9a364SKalle Valo int i;
14647ac9a364SKalle Valo const s8 *clip_pwrs;
14657ac9a364SKalle Valo int power;
14667ac9a364SKalle Valo
14677ac9a364SKalle Valo /* Get this chnlgrp's rate-to-max/clip-powers table */
14687ac9a364SKalle Valo clip_pwrs = il->_3945.clip_groups[ch_info->group_idx].clip_powers;
14697ac9a364SKalle Valo
14707ac9a364SKalle Valo /* Get this channel's rate-to-current-power settings table */
14717ac9a364SKalle Valo power_info = ch_info->power_info;
14727ac9a364SKalle Valo
14737ac9a364SKalle Valo /* update OFDM Txpower settings */
14747ac9a364SKalle Valo for (i = RATE_6M_IDX_TBL; i <= RATE_54M_IDX_TBL; i++, ++power_info) {
14757ac9a364SKalle Valo int delta_idx;
14767ac9a364SKalle Valo
14777ac9a364SKalle Valo /* limit new power to be no more than h/w capability */
14787ac9a364SKalle Valo power = min(ch_info->curr_txpow, clip_pwrs[i]);
14797ac9a364SKalle Valo if (power == power_info->requested_power)
14807ac9a364SKalle Valo continue;
14817ac9a364SKalle Valo
14827ac9a364SKalle Valo /* find difference between old and new requested powers,
14837ac9a364SKalle Valo * update base (non-temp-compensated) power idx */
14847ac9a364SKalle Valo delta_idx = (power - power_info->requested_power) * 2;
14857ac9a364SKalle Valo power_info->base_power_idx -= delta_idx;
14867ac9a364SKalle Valo
14877ac9a364SKalle Valo /* save new requested power value */
14887ac9a364SKalle Valo power_info->requested_power = power;
14897ac9a364SKalle Valo
14907ac9a364SKalle Valo power_changed = 1;
14917ac9a364SKalle Valo }
14927ac9a364SKalle Valo
14937ac9a364SKalle Valo /* update CCK Txpower settings, based on OFDM 12M setting ...
14947ac9a364SKalle Valo * ... all CCK power settings for a given channel are the *same*. */
14957ac9a364SKalle Valo if (power_changed) {
14967ac9a364SKalle Valo power =
14977ac9a364SKalle Valo ch_info->power_info[RATE_12M_IDX_TBL].requested_power +
14987ac9a364SKalle Valo IL_CCK_FROM_OFDM_POWER_DIFF;
14997ac9a364SKalle Valo
15007ac9a364SKalle Valo /* do all CCK rates' il3945_channel_power_info structures */
15017ac9a364SKalle Valo for (i = RATE_1M_IDX_TBL; i <= RATE_11M_IDX_TBL; i++) {
15027ac9a364SKalle Valo power_info->requested_power = power;
15037ac9a364SKalle Valo power_info->base_power_idx =
15047ac9a364SKalle Valo ch_info->power_info[RATE_12M_IDX_TBL].
15057ac9a364SKalle Valo base_power_idx + IL_CCK_FROM_OFDM_IDX_DIFF;
15067ac9a364SKalle Valo ++power_info;
15077ac9a364SKalle Valo }
15087ac9a364SKalle Valo }
15097ac9a364SKalle Valo
15107ac9a364SKalle Valo return 0;
15117ac9a364SKalle Valo }
15127ac9a364SKalle Valo
1513a60e33afSLee Jones /*
15147ac9a364SKalle Valo * il3945_hw_reg_get_ch_txpower_limit - returns new power limit for channel
15157ac9a364SKalle Valo *
15167ac9a364SKalle Valo * NOTE: Returned power limit may be less (but not more) than requested,
15177ac9a364SKalle Valo * based strictly on regulatory (eeprom and spectrum mgt) limitations
15187ac9a364SKalle Valo * (no consideration for h/w clipping limitations).
15197ac9a364SKalle Valo */
15207ac9a364SKalle Valo static int
il3945_hw_reg_get_ch_txpower_limit(struct il_channel_info * ch_info)15217ac9a364SKalle Valo il3945_hw_reg_get_ch_txpower_limit(struct il_channel_info *ch_info)
15227ac9a364SKalle Valo {
15237ac9a364SKalle Valo s8 max_power;
15247ac9a364SKalle Valo
15257ac9a364SKalle Valo #if 0
15267ac9a364SKalle Valo /* if we're using TGd limits, use lower of TGd or EEPROM */
15277ac9a364SKalle Valo if (ch_info->tgd_data.max_power != 0)
15287ac9a364SKalle Valo max_power =
15297ac9a364SKalle Valo min(ch_info->tgd_data.max_power,
15307ac9a364SKalle Valo ch_info->eeprom.max_power_avg);
15317ac9a364SKalle Valo
15327ac9a364SKalle Valo /* else just use EEPROM limits */
15337ac9a364SKalle Valo else
15347ac9a364SKalle Valo #endif
15357ac9a364SKalle Valo max_power = ch_info->eeprom.max_power_avg;
15367ac9a364SKalle Valo
15377ac9a364SKalle Valo return min(max_power, ch_info->max_power_avg);
15387ac9a364SKalle Valo }
15397ac9a364SKalle Valo
1540a60e33afSLee Jones /*
15417ac9a364SKalle Valo * il3945_hw_reg_comp_txpower_temp - Compensate for temperature
15427ac9a364SKalle Valo *
15437ac9a364SKalle Valo * Compensate txpower settings of *all* channels for temperature.
15447ac9a364SKalle Valo * This only accounts for the difference between current temperature
15457ac9a364SKalle Valo * and the factory calibration temperatures, and bases the new settings
15467ac9a364SKalle Valo * on the channel's base_power_idx.
15477ac9a364SKalle Valo *
15487ac9a364SKalle Valo * If RxOn is "associated", this sends the new Txpower to NIC!
15497ac9a364SKalle Valo */
15507ac9a364SKalle Valo static int
il3945_hw_reg_comp_txpower_temp(struct il_priv * il)15517ac9a364SKalle Valo il3945_hw_reg_comp_txpower_temp(struct il_priv *il)
15527ac9a364SKalle Valo {
15537ac9a364SKalle Valo struct il_channel_info *ch_info = NULL;
15547ac9a364SKalle Valo struct il3945_eeprom *eeprom = (struct il3945_eeprom *)il->eeprom;
15557ac9a364SKalle Valo int delta_idx;
15567ac9a364SKalle Valo const s8 *clip_pwrs; /* array of h/w max power levels for each rate */
15577ac9a364SKalle Valo u8 a_band;
15587ac9a364SKalle Valo u8 rate_idx;
15597ac9a364SKalle Valo u8 scan_tbl_idx;
15607ac9a364SKalle Valo u8 i;
15617ac9a364SKalle Valo int ref_temp;
15627ac9a364SKalle Valo int temperature = il->temperature;
15637ac9a364SKalle Valo
15647ac9a364SKalle Valo if (il->disable_tx_power_cal || test_bit(S_SCANNING, &il->status)) {
15657ac9a364SKalle Valo /* do not perform tx power calibration */
15667ac9a364SKalle Valo return 0;
15677ac9a364SKalle Valo }
15687ac9a364SKalle Valo /* set up new Tx power info for each and every channel, 2.4 and 5.x */
15697ac9a364SKalle Valo for (i = 0; i < il->channel_count; i++) {
15707ac9a364SKalle Valo ch_info = &il->channel_info[i];
15717ac9a364SKalle Valo a_band = il_is_channel_a_band(ch_info);
15727ac9a364SKalle Valo
15737ac9a364SKalle Valo /* Get this chnlgrp's factory calibration temperature */
15747ac9a364SKalle Valo ref_temp = (s16) eeprom->groups[ch_info->group_idx].temperature;
15757ac9a364SKalle Valo
15767ac9a364SKalle Valo /* get power idx adjustment based on current and factory
15777ac9a364SKalle Valo * temps */
15787ac9a364SKalle Valo delta_idx =
15797ac9a364SKalle Valo il3945_hw_reg_adjust_power_by_temp(temperature, ref_temp);
15807ac9a364SKalle Valo
15817ac9a364SKalle Valo /* set tx power value for all rates, OFDM and CCK */
15827ac9a364SKalle Valo for (rate_idx = 0; rate_idx < RATE_COUNT_3945; rate_idx++) {
15837ac9a364SKalle Valo int power_idx =
15847ac9a364SKalle Valo ch_info->power_info[rate_idx].base_power_idx;
15857ac9a364SKalle Valo
15867ac9a364SKalle Valo /* temperature compensate */
15877ac9a364SKalle Valo power_idx += delta_idx;
15887ac9a364SKalle Valo
15897ac9a364SKalle Valo /* stay within table range */
15907ac9a364SKalle Valo power_idx = il3945_hw_reg_fix_power_idx(power_idx);
15917ac9a364SKalle Valo ch_info->power_info[rate_idx].power_table_idx =
15927ac9a364SKalle Valo (u8) power_idx;
15937ac9a364SKalle Valo ch_info->power_info[rate_idx].tpc =
15947ac9a364SKalle Valo power_gain_table[a_band][power_idx];
15957ac9a364SKalle Valo }
15967ac9a364SKalle Valo
15977ac9a364SKalle Valo /* Get this chnlgrp's rate-to-max/clip-powers table */
15987ac9a364SKalle Valo clip_pwrs =
15997ac9a364SKalle Valo il->_3945.clip_groups[ch_info->group_idx].clip_powers;
16007ac9a364SKalle Valo
16017ac9a364SKalle Valo /* set scan tx power, 1Mbit for CCK, 6Mbit for OFDM */
16027ac9a364SKalle Valo for (scan_tbl_idx = 0; scan_tbl_idx < IL_NUM_SCAN_RATES;
16037ac9a364SKalle Valo scan_tbl_idx++) {
16047ac9a364SKalle Valo s32 actual_idx =
16057ac9a364SKalle Valo (scan_tbl_idx ==
16067ac9a364SKalle Valo 0) ? RATE_1M_IDX_TBL : RATE_6M_IDX_TBL;
16077ac9a364SKalle Valo il3945_hw_reg_set_scan_power(il, scan_tbl_idx,
16087ac9a364SKalle Valo actual_idx, clip_pwrs,
16097ac9a364SKalle Valo ch_info, a_band);
16107ac9a364SKalle Valo }
16117ac9a364SKalle Valo }
16127ac9a364SKalle Valo
16137ac9a364SKalle Valo /* send Txpower command for current channel to ucode */
16147ac9a364SKalle Valo return il->ops->send_tx_power(il);
16157ac9a364SKalle Valo }
16167ac9a364SKalle Valo
16177ac9a364SKalle Valo int
il3945_hw_reg_set_txpower(struct il_priv * il,s8 power)16187ac9a364SKalle Valo il3945_hw_reg_set_txpower(struct il_priv *il, s8 power)
16197ac9a364SKalle Valo {
16207ac9a364SKalle Valo struct il_channel_info *ch_info;
16217ac9a364SKalle Valo s8 max_power;
16227ac9a364SKalle Valo u8 i;
16237ac9a364SKalle Valo
16247ac9a364SKalle Valo if (il->tx_power_user_lmt == power) {
16257ac9a364SKalle Valo D_POWER("Requested Tx power same as current " "limit: %ddBm.\n",
16267ac9a364SKalle Valo power);
16277ac9a364SKalle Valo return 0;
16287ac9a364SKalle Valo }
16297ac9a364SKalle Valo
16307ac9a364SKalle Valo D_POWER("Setting upper limit clamp to %ddBm.\n", power);
16317ac9a364SKalle Valo il->tx_power_user_lmt = power;
16327ac9a364SKalle Valo
16337ac9a364SKalle Valo /* set up new Tx powers for each and every channel, 2.4 and 5.x */
16347ac9a364SKalle Valo
16357ac9a364SKalle Valo for (i = 0; i < il->channel_count; i++) {
16367ac9a364SKalle Valo ch_info = &il->channel_info[i];
16377ac9a364SKalle Valo
16387ac9a364SKalle Valo /* find minimum power of all user and regulatory constraints
16397ac9a364SKalle Valo * (does not consider h/w clipping limitations) */
16407ac9a364SKalle Valo max_power = il3945_hw_reg_get_ch_txpower_limit(ch_info);
16417ac9a364SKalle Valo max_power = min(power, max_power);
16427ac9a364SKalle Valo if (max_power != ch_info->curr_txpow) {
16437ac9a364SKalle Valo ch_info->curr_txpow = max_power;
16447ac9a364SKalle Valo
16457ac9a364SKalle Valo /* this considers the h/w clipping limitations */
16467ac9a364SKalle Valo il3945_hw_reg_set_new_power(il, ch_info);
16477ac9a364SKalle Valo }
16487ac9a364SKalle Valo }
16497ac9a364SKalle Valo
16507ac9a364SKalle Valo /* update txpower settings for all channels,
16517ac9a364SKalle Valo * send to NIC if associated. */
16527ac9a364SKalle Valo il3945_is_temp_calib_needed(il);
16537ac9a364SKalle Valo il3945_hw_reg_comp_txpower_temp(il);
16547ac9a364SKalle Valo
16557ac9a364SKalle Valo return 0;
16567ac9a364SKalle Valo }
16577ac9a364SKalle Valo
16587ac9a364SKalle Valo static int
il3945_send_rxon_assoc(struct il_priv * il)16597ac9a364SKalle Valo il3945_send_rxon_assoc(struct il_priv *il)
16607ac9a364SKalle Valo {
16617ac9a364SKalle Valo int rc = 0;
16627ac9a364SKalle Valo struct il_rx_pkt *pkt;
16637ac9a364SKalle Valo struct il3945_rxon_assoc_cmd rxon_assoc;
16647ac9a364SKalle Valo struct il_host_cmd cmd = {
16657ac9a364SKalle Valo .id = C_RXON_ASSOC,
16667ac9a364SKalle Valo .len = sizeof(rxon_assoc),
16677ac9a364SKalle Valo .flags = CMD_WANT_SKB,
16687ac9a364SKalle Valo .data = &rxon_assoc,
16697ac9a364SKalle Valo };
16707ac9a364SKalle Valo const struct il_rxon_cmd *rxon1 = &il->staging;
16717ac9a364SKalle Valo const struct il_rxon_cmd *rxon2 = &il->active;
16727ac9a364SKalle Valo
16737ac9a364SKalle Valo if (rxon1->flags == rxon2->flags &&
16747ac9a364SKalle Valo rxon1->filter_flags == rxon2->filter_flags &&
16757ac9a364SKalle Valo rxon1->cck_basic_rates == rxon2->cck_basic_rates &&
16767ac9a364SKalle Valo rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates) {
16777ac9a364SKalle Valo D_INFO("Using current RXON_ASSOC. Not resending.\n");
16787ac9a364SKalle Valo return 0;
16797ac9a364SKalle Valo }
16807ac9a364SKalle Valo
16817ac9a364SKalle Valo rxon_assoc.flags = il->staging.flags;
16827ac9a364SKalle Valo rxon_assoc.filter_flags = il->staging.filter_flags;
16837ac9a364SKalle Valo rxon_assoc.ofdm_basic_rates = il->staging.ofdm_basic_rates;
16847ac9a364SKalle Valo rxon_assoc.cck_basic_rates = il->staging.cck_basic_rates;
16857ac9a364SKalle Valo rxon_assoc.reserved = 0;
16867ac9a364SKalle Valo
16877ac9a364SKalle Valo rc = il_send_cmd_sync(il, &cmd);
16887ac9a364SKalle Valo if (rc)
16897ac9a364SKalle Valo return rc;
16907ac9a364SKalle Valo
16917ac9a364SKalle Valo pkt = (struct il_rx_pkt *)cmd.reply_page;
16927ac9a364SKalle Valo if (pkt->hdr.flags & IL_CMD_FAILED_MSK) {
16937ac9a364SKalle Valo IL_ERR("Bad return from C_RXON_ASSOC command\n");
16947ac9a364SKalle Valo rc = -EIO;
16957ac9a364SKalle Valo }
16967ac9a364SKalle Valo
16977ac9a364SKalle Valo il_free_pages(il, cmd.reply_page);
16987ac9a364SKalle Valo
16997ac9a364SKalle Valo return rc;
17007ac9a364SKalle Valo }
17017ac9a364SKalle Valo
1702a60e33afSLee Jones /*
17037ac9a364SKalle Valo * il3945_commit_rxon - commit staging_rxon to hardware
17047ac9a364SKalle Valo *
17057ac9a364SKalle Valo * The RXON command in staging_rxon is committed to the hardware and
17067ac9a364SKalle Valo * the active_rxon structure is updated with the new data. This
17077ac9a364SKalle Valo * function correctly transitions out of the RXON_ASSOC_MSK state if
17087ac9a364SKalle Valo * a HW tune is required based on the RXON structure changes.
17097ac9a364SKalle Valo */
17107ac9a364SKalle Valo int
il3945_commit_rxon(struct il_priv * il)17117ac9a364SKalle Valo il3945_commit_rxon(struct il_priv *il)
17127ac9a364SKalle Valo {
17137ac9a364SKalle Valo /* cast away the const for active_rxon in this function */
17147ac9a364SKalle Valo struct il3945_rxon_cmd *active_rxon = (void *)&il->active;
17157ac9a364SKalle Valo struct il3945_rxon_cmd *staging_rxon = (void *)&il->staging;
17167ac9a364SKalle Valo int rc = 0;
17177ac9a364SKalle Valo bool new_assoc = !!(staging_rxon->filter_flags & RXON_FILTER_ASSOC_MSK);
17187ac9a364SKalle Valo
17197ac9a364SKalle Valo if (test_bit(S_EXIT_PENDING, &il->status))
17207ac9a364SKalle Valo return -EINVAL;
17217ac9a364SKalle Valo
17227ac9a364SKalle Valo if (!il_is_alive(il))
17237ac9a364SKalle Valo return -1;
17247ac9a364SKalle Valo
17257ac9a364SKalle Valo /* always get timestamp with Rx frame */
17267ac9a364SKalle Valo staging_rxon->flags |= RXON_FLG_TSF2HOST_MSK;
17277ac9a364SKalle Valo
17287ac9a364SKalle Valo /* select antenna */
17297ac9a364SKalle Valo staging_rxon->flags &= ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
17307ac9a364SKalle Valo staging_rxon->flags |= il3945_get_antenna_flags(il);
17317ac9a364SKalle Valo
17327ac9a364SKalle Valo rc = il_check_rxon_cmd(il);
17337ac9a364SKalle Valo if (rc) {
17347ac9a364SKalle Valo IL_ERR("Invalid RXON configuration. Not committing.\n");
17357ac9a364SKalle Valo return -EINVAL;
17367ac9a364SKalle Valo }
17377ac9a364SKalle Valo
17387ac9a364SKalle Valo /* If we don't need to send a full RXON, we can use
17397ac9a364SKalle Valo * il3945_rxon_assoc_cmd which is used to reconfigure filter
17407ac9a364SKalle Valo * and other flags for the current radio configuration. */
17417ac9a364SKalle Valo if (!il_full_rxon_required(il)) {
17427ac9a364SKalle Valo rc = il_send_rxon_assoc(il);
17437ac9a364SKalle Valo if (rc) {
17447ac9a364SKalle Valo IL_ERR("Error setting RXON_ASSOC "
17457ac9a364SKalle Valo "configuration (%d).\n", rc);
17467ac9a364SKalle Valo return rc;
17477ac9a364SKalle Valo }
17487ac9a364SKalle Valo
17497ac9a364SKalle Valo memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
17507ac9a364SKalle Valo /*
17517ac9a364SKalle Valo * We do not commit tx power settings while channel changing,
17527ac9a364SKalle Valo * do it now if tx power changed.
17537ac9a364SKalle Valo */
17547ac9a364SKalle Valo il_set_tx_power(il, il->tx_power_next, false);
17557ac9a364SKalle Valo return 0;
17567ac9a364SKalle Valo }
17577ac9a364SKalle Valo
17587ac9a364SKalle Valo /* If we are currently associated and the new config requires
17597ac9a364SKalle Valo * an RXON_ASSOC and the new config wants the associated mask enabled,
17607ac9a364SKalle Valo * we must clear the associated from the active configuration
17617ac9a364SKalle Valo * before we apply the new config */
17627ac9a364SKalle Valo if (il_is_associated(il) && new_assoc) {
17637ac9a364SKalle Valo D_INFO("Toggling associated bit on current RXON\n");
17647ac9a364SKalle Valo active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
17657ac9a364SKalle Valo
17667ac9a364SKalle Valo /*
17677ac9a364SKalle Valo * reserved4 and 5 could have been filled by the iwlcore code.
17687ac9a364SKalle Valo * Let's clear them before pushing to the 3945.
17697ac9a364SKalle Valo */
17707ac9a364SKalle Valo active_rxon->reserved4 = 0;
17717ac9a364SKalle Valo active_rxon->reserved5 = 0;
17727ac9a364SKalle Valo rc = il_send_cmd_pdu(il, C_RXON, sizeof(struct il3945_rxon_cmd),
17737ac9a364SKalle Valo &il->active);
17747ac9a364SKalle Valo
17757ac9a364SKalle Valo /* If the mask clearing failed then we set
17767ac9a364SKalle Valo * active_rxon back to what it was previously */
17777ac9a364SKalle Valo if (rc) {
17787ac9a364SKalle Valo active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
17797ac9a364SKalle Valo IL_ERR("Error clearing ASSOC_MSK on current "
17807ac9a364SKalle Valo "configuration (%d).\n", rc);
17817ac9a364SKalle Valo return rc;
17827ac9a364SKalle Valo }
17837ac9a364SKalle Valo il_clear_ucode_stations(il);
17847ac9a364SKalle Valo il_restore_stations(il);
17857ac9a364SKalle Valo }
17867ac9a364SKalle Valo
17877ac9a364SKalle Valo D_INFO("Sending RXON\n" "* with%s RXON_FILTER_ASSOC_MSK\n"
17887ac9a364SKalle Valo "* channel = %d\n" "* bssid = %pM\n", (new_assoc ? "" : "out"),
17897ac9a364SKalle Valo le16_to_cpu(staging_rxon->channel), staging_rxon->bssid_addr);
17907ac9a364SKalle Valo
17917ac9a364SKalle Valo /*
17927ac9a364SKalle Valo * reserved4 and 5 could have been filled by the iwlcore code.
17937ac9a364SKalle Valo * Let's clear them before pushing to the 3945.
17947ac9a364SKalle Valo */
17957ac9a364SKalle Valo staging_rxon->reserved4 = 0;
17967ac9a364SKalle Valo staging_rxon->reserved5 = 0;
17977ac9a364SKalle Valo
17987ac9a364SKalle Valo il_set_rxon_hwcrypto(il, !il3945_mod_params.sw_crypto);
17997ac9a364SKalle Valo
18007ac9a364SKalle Valo /* Apply the new configuration */
18017ac9a364SKalle Valo rc = il_send_cmd_pdu(il, C_RXON, sizeof(struct il3945_rxon_cmd),
18027ac9a364SKalle Valo staging_rxon);
18037ac9a364SKalle Valo if (rc) {
18047ac9a364SKalle Valo IL_ERR("Error setting new configuration (%d).\n", rc);
18057ac9a364SKalle Valo return rc;
18067ac9a364SKalle Valo }
18077ac9a364SKalle Valo
18087ac9a364SKalle Valo memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
18097ac9a364SKalle Valo
18107ac9a364SKalle Valo if (!new_assoc) {
18117ac9a364SKalle Valo il_clear_ucode_stations(il);
18127ac9a364SKalle Valo il_restore_stations(il);
18137ac9a364SKalle Valo }
18147ac9a364SKalle Valo
18157ac9a364SKalle Valo /* If we issue a new RXON command which required a tune then we must
18167ac9a364SKalle Valo * send a new TXPOWER command or we won't be able to Tx any frames */
18177ac9a364SKalle Valo rc = il_set_tx_power(il, il->tx_power_next, true);
18187ac9a364SKalle Valo if (rc) {
18197ac9a364SKalle Valo IL_ERR("Error setting Tx power (%d).\n", rc);
18207ac9a364SKalle Valo return rc;
18217ac9a364SKalle Valo }
18227ac9a364SKalle Valo
18237ac9a364SKalle Valo /* Init the hardware's rate fallback order based on the band */
18247ac9a364SKalle Valo rc = il3945_init_hw_rate_table(il);
18257ac9a364SKalle Valo if (rc) {
18267ac9a364SKalle Valo IL_ERR("Error setting HW rate table: %02X\n", rc);
18277ac9a364SKalle Valo return -EIO;
18287ac9a364SKalle Valo }
18297ac9a364SKalle Valo
18307ac9a364SKalle Valo return 0;
18317ac9a364SKalle Valo }
18327ac9a364SKalle Valo
1833a60e33afSLee Jones /*
18347ac9a364SKalle Valo * il3945_reg_txpower_periodic - called when time to check our temperature.
18357ac9a364SKalle Valo *
18367ac9a364SKalle Valo * -- reset periodic timer
18377ac9a364SKalle Valo * -- see if temp has changed enough to warrant re-calibration ... if so:
18387ac9a364SKalle Valo * -- correct coeffs for temp (can reset temp timer)
18397ac9a364SKalle Valo * -- save this temp as "last",
18407ac9a364SKalle Valo * -- send new set of gain settings to NIC
18417ac9a364SKalle Valo * NOTE: This should continue working, even when we're not associated,
18427ac9a364SKalle Valo * so we can keep our internal table of scan powers current. */
18437ac9a364SKalle Valo void
il3945_reg_txpower_periodic(struct il_priv * il)18447ac9a364SKalle Valo il3945_reg_txpower_periodic(struct il_priv *il)
18457ac9a364SKalle Valo {
18467ac9a364SKalle Valo /* This will kick in the "brute force"
18477ac9a364SKalle Valo * il3945_hw_reg_comp_txpower_temp() below */
18487ac9a364SKalle Valo if (!il3945_is_temp_calib_needed(il))
18497ac9a364SKalle Valo goto reschedule;
18507ac9a364SKalle Valo
18517ac9a364SKalle Valo /* Set up a new set of temp-adjusted TxPowers, send to NIC.
18527ac9a364SKalle Valo * This is based *only* on current temperature,
18537ac9a364SKalle Valo * ignoring any previous power measurements */
18547ac9a364SKalle Valo il3945_hw_reg_comp_txpower_temp(il);
18557ac9a364SKalle Valo
18567ac9a364SKalle Valo reschedule:
18577ac9a364SKalle Valo queue_delayed_work(il->workqueue, &il->_3945.thermal_periodic,
18587ac9a364SKalle Valo REG_RECALIB_PERIOD * HZ);
18597ac9a364SKalle Valo }
18607ac9a364SKalle Valo
18617ac9a364SKalle Valo static void
il3945_bg_reg_txpower_periodic(struct work_struct * work)18627ac9a364SKalle Valo il3945_bg_reg_txpower_periodic(struct work_struct *work)
18637ac9a364SKalle Valo {
18647ac9a364SKalle Valo struct il_priv *il = container_of(work, struct il_priv,
18657ac9a364SKalle Valo _3945.thermal_periodic.work);
18667ac9a364SKalle Valo
18677ac9a364SKalle Valo mutex_lock(&il->mutex);
18687ac9a364SKalle Valo if (test_bit(S_EXIT_PENDING, &il->status) || il->txq == NULL)
18697ac9a364SKalle Valo goto out;
18707ac9a364SKalle Valo
18717ac9a364SKalle Valo il3945_reg_txpower_periodic(il);
18727ac9a364SKalle Valo out:
18737ac9a364SKalle Valo mutex_unlock(&il->mutex);
18747ac9a364SKalle Valo }
18757ac9a364SKalle Valo
1876a60e33afSLee Jones /*
18777ac9a364SKalle Valo * il3945_hw_reg_get_ch_grp_idx - find the channel-group idx (0-4) for channel.
18787ac9a364SKalle Valo *
18797ac9a364SKalle Valo * This function is used when initializing channel-info structs.
18807ac9a364SKalle Valo *
18817ac9a364SKalle Valo * NOTE: These channel groups do *NOT* match the bands above!
18827ac9a364SKalle Valo * These channel groups are based on factory-tested channels;
18837ac9a364SKalle Valo * on A-band, EEPROM's "group frequency" entries represent the top
18847ac9a364SKalle Valo * channel in each group 1-4. Group 5 All B/G channels are in group 0.
18857ac9a364SKalle Valo */
18867ac9a364SKalle Valo static u16
il3945_hw_reg_get_ch_grp_idx(struct il_priv * il,const struct il_channel_info * ch_info)18877ac9a364SKalle Valo il3945_hw_reg_get_ch_grp_idx(struct il_priv *il,
18887ac9a364SKalle Valo const struct il_channel_info *ch_info)
18897ac9a364SKalle Valo {
18907ac9a364SKalle Valo struct il3945_eeprom *eeprom = (struct il3945_eeprom *)il->eeprom;
18917ac9a364SKalle Valo struct il3945_eeprom_txpower_group *ch_grp = &eeprom->groups[0];
18927ac9a364SKalle Valo u8 group;
18937ac9a364SKalle Valo u16 group_idx = 0; /* based on factory calib frequencies */
18947ac9a364SKalle Valo u8 grp_channel;
18957ac9a364SKalle Valo
18967ac9a364SKalle Valo /* Find the group idx for the channel ... don't use idx 1(?) */
18977ac9a364SKalle Valo if (il_is_channel_a_band(ch_info)) {
18987ac9a364SKalle Valo for (group = 1; group < 5; group++) {
18997ac9a364SKalle Valo grp_channel = ch_grp[group].group_channel;
19007ac9a364SKalle Valo if (ch_info->channel <= grp_channel) {
19017ac9a364SKalle Valo group_idx = group;
19027ac9a364SKalle Valo break;
19037ac9a364SKalle Valo }
19047ac9a364SKalle Valo }
19057ac9a364SKalle Valo /* group 4 has a few channels *above* its factory cal freq */
19067ac9a364SKalle Valo if (group == 5)
19077ac9a364SKalle Valo group_idx = 4;
19087ac9a364SKalle Valo } else
19097ac9a364SKalle Valo group_idx = 0; /* 2.4 GHz, group 0 */
19107ac9a364SKalle Valo
19117ac9a364SKalle Valo D_POWER("Chnl %d mapped to grp %d\n", ch_info->channel, group_idx);
19127ac9a364SKalle Valo return group_idx;
19137ac9a364SKalle Valo }
19147ac9a364SKalle Valo
1915a60e33afSLee Jones /*
19167ac9a364SKalle Valo * il3945_hw_reg_get_matched_power_idx - Interpolate to get nominal idx
19177ac9a364SKalle Valo *
19187ac9a364SKalle Valo * Interpolate to get nominal (i.e. at factory calibration temperature) idx
19197ac9a364SKalle Valo * into radio/DSP gain settings table for requested power.
19207ac9a364SKalle Valo */
19217ac9a364SKalle Valo static int
il3945_hw_reg_get_matched_power_idx(struct il_priv * il,s8 requested_power,s32 setting_idx,s32 * new_idx)19227ac9a364SKalle Valo il3945_hw_reg_get_matched_power_idx(struct il_priv *il, s8 requested_power,
19237ac9a364SKalle Valo s32 setting_idx, s32 *new_idx)
19247ac9a364SKalle Valo {
19257ac9a364SKalle Valo const struct il3945_eeprom_txpower_group *chnl_grp = NULL;
19267ac9a364SKalle Valo struct il3945_eeprom *eeprom = (struct il3945_eeprom *)il->eeprom;
19277ac9a364SKalle Valo s32 idx0, idx1;
19287ac9a364SKalle Valo s32 power = 2 * requested_power;
19297ac9a364SKalle Valo s32 i;
19307ac9a364SKalle Valo const struct il3945_eeprom_txpower_sample *samples;
19317ac9a364SKalle Valo s32 gains0, gains1;
19327ac9a364SKalle Valo s32 res;
19337ac9a364SKalle Valo s32 denominator;
19347ac9a364SKalle Valo
19357ac9a364SKalle Valo chnl_grp = &eeprom->groups[setting_idx];
19367ac9a364SKalle Valo samples = chnl_grp->samples;
19377ac9a364SKalle Valo for (i = 0; i < 5; i++) {
19387ac9a364SKalle Valo if (power == samples[i].power) {
19397ac9a364SKalle Valo *new_idx = samples[i].gain_idx;
19407ac9a364SKalle Valo return 0;
19417ac9a364SKalle Valo }
19427ac9a364SKalle Valo }
19437ac9a364SKalle Valo
19447ac9a364SKalle Valo if (power > samples[1].power) {
19457ac9a364SKalle Valo idx0 = 0;
19467ac9a364SKalle Valo idx1 = 1;
19477ac9a364SKalle Valo } else if (power > samples[2].power) {
19487ac9a364SKalle Valo idx0 = 1;
19497ac9a364SKalle Valo idx1 = 2;
19507ac9a364SKalle Valo } else if (power > samples[3].power) {
19517ac9a364SKalle Valo idx0 = 2;
19527ac9a364SKalle Valo idx1 = 3;
19537ac9a364SKalle Valo } else {
19547ac9a364SKalle Valo idx0 = 3;
19557ac9a364SKalle Valo idx1 = 4;
19567ac9a364SKalle Valo }
19577ac9a364SKalle Valo
19587ac9a364SKalle Valo denominator = (s32) samples[idx1].power - (s32) samples[idx0].power;
19597ac9a364SKalle Valo if (denominator == 0)
19607ac9a364SKalle Valo return -EINVAL;
19617ac9a364SKalle Valo gains0 = (s32) samples[idx0].gain_idx * (1 << 19);
19627ac9a364SKalle Valo gains1 = (s32) samples[idx1].gain_idx * (1 << 19);
19637ac9a364SKalle Valo res =
19647ac9a364SKalle Valo gains0 + (gains1 - gains0) * ((s32) power -
19657ac9a364SKalle Valo (s32) samples[idx0].power) /
19667ac9a364SKalle Valo denominator + (1 << 18);
19677ac9a364SKalle Valo *new_idx = res >> 19;
19687ac9a364SKalle Valo return 0;
19697ac9a364SKalle Valo }
19707ac9a364SKalle Valo
19717ac9a364SKalle Valo static void
il3945_hw_reg_init_channel_groups(struct il_priv * il)19727ac9a364SKalle Valo il3945_hw_reg_init_channel_groups(struct il_priv *il)
19737ac9a364SKalle Valo {
19747ac9a364SKalle Valo u32 i;
19757ac9a364SKalle Valo s32 rate_idx;
19767ac9a364SKalle Valo struct il3945_eeprom *eeprom = (struct il3945_eeprom *)il->eeprom;
19777ac9a364SKalle Valo const struct il3945_eeprom_txpower_group *group;
19787ac9a364SKalle Valo
19797ac9a364SKalle Valo D_POWER("Initializing factory calib info from EEPROM\n");
19807ac9a364SKalle Valo
19817ac9a364SKalle Valo for (i = 0; i < IL_NUM_TX_CALIB_GROUPS; i++) {
19827ac9a364SKalle Valo s8 *clip_pwrs; /* table of power levels for each rate */
19837ac9a364SKalle Valo s8 satur_pwr; /* saturation power for each chnl group */
19847ac9a364SKalle Valo group = &eeprom->groups[i];
19857ac9a364SKalle Valo
19867ac9a364SKalle Valo /* sanity check on factory saturation power value */
19877ac9a364SKalle Valo if (group->saturation_power < 40) {
19887ac9a364SKalle Valo IL_WARN("Error: saturation power is %d, "
19897ac9a364SKalle Valo "less than minimum expected 40\n",
19907ac9a364SKalle Valo group->saturation_power);
19917ac9a364SKalle Valo return;
19927ac9a364SKalle Valo }
19937ac9a364SKalle Valo
19947ac9a364SKalle Valo /*
19957ac9a364SKalle Valo * Derive requested power levels for each rate, based on
19967ac9a364SKalle Valo * hardware capabilities (saturation power for band).
19977ac9a364SKalle Valo * Basic value is 3dB down from saturation, with further
19987ac9a364SKalle Valo * power reductions for highest 3 data rates. These
19997ac9a364SKalle Valo * backoffs provide headroom for high rate modulation
20007ac9a364SKalle Valo * power peaks, without too much distortion (clipping).
20017ac9a364SKalle Valo */
20027ac9a364SKalle Valo /* we'll fill in this array with h/w max power levels */
20037ac9a364SKalle Valo clip_pwrs = (s8 *) il->_3945.clip_groups[i].clip_powers;
20047ac9a364SKalle Valo
20057ac9a364SKalle Valo /* divide factory saturation power by 2 to find -3dB level */
20067ac9a364SKalle Valo satur_pwr = (s8) (group->saturation_power >> 1);
20077ac9a364SKalle Valo
20087ac9a364SKalle Valo /* fill in channel group's nominal powers for each rate */
20097ac9a364SKalle Valo for (rate_idx = 0; rate_idx < RATE_COUNT_3945;
20107ac9a364SKalle Valo rate_idx++, clip_pwrs++) {
20117ac9a364SKalle Valo switch (rate_idx) {
20127ac9a364SKalle Valo case RATE_36M_IDX_TBL:
20137ac9a364SKalle Valo if (i == 0) /* B/G */
20147ac9a364SKalle Valo *clip_pwrs = satur_pwr;
20157ac9a364SKalle Valo else /* A */
20167ac9a364SKalle Valo *clip_pwrs = satur_pwr - 5;
20177ac9a364SKalle Valo break;
20187ac9a364SKalle Valo case RATE_48M_IDX_TBL:
20197ac9a364SKalle Valo if (i == 0)
20207ac9a364SKalle Valo *clip_pwrs = satur_pwr - 7;
20217ac9a364SKalle Valo else
20227ac9a364SKalle Valo *clip_pwrs = satur_pwr - 10;
20237ac9a364SKalle Valo break;
20247ac9a364SKalle Valo case RATE_54M_IDX_TBL:
20257ac9a364SKalle Valo if (i == 0)
20267ac9a364SKalle Valo *clip_pwrs = satur_pwr - 9;
20277ac9a364SKalle Valo else
20287ac9a364SKalle Valo *clip_pwrs = satur_pwr - 12;
20297ac9a364SKalle Valo break;
20307ac9a364SKalle Valo default:
20317ac9a364SKalle Valo *clip_pwrs = satur_pwr;
20327ac9a364SKalle Valo break;
20337ac9a364SKalle Valo }
20347ac9a364SKalle Valo }
20357ac9a364SKalle Valo }
20367ac9a364SKalle Valo }
20377ac9a364SKalle Valo
2038a60e33afSLee Jones /*
20397ac9a364SKalle Valo * il3945_txpower_set_from_eeprom - Set channel power info based on EEPROM
20407ac9a364SKalle Valo *
20417ac9a364SKalle Valo * Second pass (during init) to set up il->channel_info
20427ac9a364SKalle Valo *
20437ac9a364SKalle Valo * Set up Tx-power settings in our channel info database for each VALID
20447ac9a364SKalle Valo * (for this geo/SKU) channel, at all Tx data rates, based on eeprom values
20457ac9a364SKalle Valo * and current temperature.
20467ac9a364SKalle Valo *
20477ac9a364SKalle Valo * Since this is based on current temperature (at init time), these values may
20487ac9a364SKalle Valo * not be valid for very long, but it gives us a starting/default point,
20497ac9a364SKalle Valo * and allows us to active (i.e. using Tx) scan.
20507ac9a364SKalle Valo *
20517ac9a364SKalle Valo * This does *not* write values to NIC, just sets up our internal table.
20527ac9a364SKalle Valo */
20537ac9a364SKalle Valo int
il3945_txpower_set_from_eeprom(struct il_priv * il)20547ac9a364SKalle Valo il3945_txpower_set_from_eeprom(struct il_priv *il)
20557ac9a364SKalle Valo {
20567ac9a364SKalle Valo struct il_channel_info *ch_info = NULL;
20577ac9a364SKalle Valo struct il3945_channel_power_info *pwr_info;
20587ac9a364SKalle Valo struct il3945_eeprom *eeprom = (struct il3945_eeprom *)il->eeprom;
20597ac9a364SKalle Valo int delta_idx;
20607ac9a364SKalle Valo u8 rate_idx;
20617ac9a364SKalle Valo u8 scan_tbl_idx;
20627ac9a364SKalle Valo const s8 *clip_pwrs; /* array of power levels for each rate */
20637ac9a364SKalle Valo u8 gain, dsp_atten;
20647ac9a364SKalle Valo s8 power;
20657ac9a364SKalle Valo u8 pwr_idx, base_pwr_idx, a_band;
20667ac9a364SKalle Valo u8 i;
20677ac9a364SKalle Valo int temperature;
20687ac9a364SKalle Valo
20697ac9a364SKalle Valo /* save temperature reference,
20707ac9a364SKalle Valo * so we can determine next time to calibrate */
20717ac9a364SKalle Valo temperature = il3945_hw_reg_txpower_get_temperature(il);
20727ac9a364SKalle Valo il->last_temperature = temperature;
20737ac9a364SKalle Valo
20747ac9a364SKalle Valo il3945_hw_reg_init_channel_groups(il);
20757ac9a364SKalle Valo
20767ac9a364SKalle Valo /* initialize Tx power info for each and every channel, 2.4 and 5.x */
20777ac9a364SKalle Valo for (i = 0, ch_info = il->channel_info; i < il->channel_count;
20787ac9a364SKalle Valo i++, ch_info++) {
20797ac9a364SKalle Valo a_band = il_is_channel_a_band(ch_info);
20807ac9a364SKalle Valo if (!il_is_channel_valid(ch_info))
20817ac9a364SKalle Valo continue;
20827ac9a364SKalle Valo
20837ac9a364SKalle Valo /* find this channel's channel group (*not* "band") idx */
20847ac9a364SKalle Valo ch_info->group_idx = il3945_hw_reg_get_ch_grp_idx(il, ch_info);
20857ac9a364SKalle Valo
20867ac9a364SKalle Valo /* Get this chnlgrp's rate->max/clip-powers table */
20877ac9a364SKalle Valo clip_pwrs =
20887ac9a364SKalle Valo il->_3945.clip_groups[ch_info->group_idx].clip_powers;
20897ac9a364SKalle Valo
20907ac9a364SKalle Valo /* calculate power idx *adjustment* value according to
20917ac9a364SKalle Valo * diff between current temperature and factory temperature */
20927ac9a364SKalle Valo delta_idx =
20937ac9a364SKalle Valo il3945_hw_reg_adjust_power_by_temp(temperature,
20947ac9a364SKalle Valo eeprom->groups[ch_info->
20957ac9a364SKalle Valo group_idx].
20967ac9a364SKalle Valo temperature);
20977ac9a364SKalle Valo
20987ac9a364SKalle Valo D_POWER("Delta idx for channel %d: %d [%d]\n", ch_info->channel,
20997ac9a364SKalle Valo delta_idx, temperature + IL_TEMP_CONVERT);
21007ac9a364SKalle Valo
21017ac9a364SKalle Valo /* set tx power value for all OFDM rates */
21027ac9a364SKalle Valo for (rate_idx = 0; rate_idx < IL_OFDM_RATES; rate_idx++) {
21033f649ab7SKees Cook s32 power_idx;
21047ac9a364SKalle Valo int rc;
21057ac9a364SKalle Valo
21067ac9a364SKalle Valo /* use channel group's clip-power table,
21077ac9a364SKalle Valo * but don't exceed channel's max power */
21087ac9a364SKalle Valo s8 pwr = min(ch_info->max_power_avg,
21097ac9a364SKalle Valo clip_pwrs[rate_idx]);
21107ac9a364SKalle Valo
21117ac9a364SKalle Valo pwr_info = &ch_info->power_info[rate_idx];
21127ac9a364SKalle Valo
21137ac9a364SKalle Valo /* get base (i.e. at factory-measured temperature)
21147ac9a364SKalle Valo * power table idx for this rate's power */
21157ac9a364SKalle Valo rc = il3945_hw_reg_get_matched_power_idx(il, pwr,
21167ac9a364SKalle Valo ch_info->
21177ac9a364SKalle Valo group_idx,
21187ac9a364SKalle Valo &power_idx);
21197ac9a364SKalle Valo if (rc) {
21207ac9a364SKalle Valo IL_ERR("Invalid power idx\n");
21217ac9a364SKalle Valo return rc;
21227ac9a364SKalle Valo }
21237ac9a364SKalle Valo pwr_info->base_power_idx = (u8) power_idx;
21247ac9a364SKalle Valo
21257ac9a364SKalle Valo /* temperature compensate */
21267ac9a364SKalle Valo power_idx += delta_idx;
21277ac9a364SKalle Valo
21287ac9a364SKalle Valo /* stay within range of gain table */
21297ac9a364SKalle Valo power_idx = il3945_hw_reg_fix_power_idx(power_idx);
21307ac9a364SKalle Valo
21317ac9a364SKalle Valo /* fill 1 OFDM rate's il3945_channel_power_info struct */
21327ac9a364SKalle Valo pwr_info->requested_power = pwr;
21337ac9a364SKalle Valo pwr_info->power_table_idx = (u8) power_idx;
21347ac9a364SKalle Valo pwr_info->tpc.tx_gain =
21357ac9a364SKalle Valo power_gain_table[a_band][power_idx].tx_gain;
21367ac9a364SKalle Valo pwr_info->tpc.dsp_atten =
21377ac9a364SKalle Valo power_gain_table[a_band][power_idx].dsp_atten;
21387ac9a364SKalle Valo }
21397ac9a364SKalle Valo
21407ac9a364SKalle Valo /* set tx power for CCK rates, based on OFDM 12 Mbit settings */
21417ac9a364SKalle Valo pwr_info = &ch_info->power_info[RATE_12M_IDX_TBL];
21427ac9a364SKalle Valo power = pwr_info->requested_power + IL_CCK_FROM_OFDM_POWER_DIFF;
21437ac9a364SKalle Valo pwr_idx = pwr_info->power_table_idx + IL_CCK_FROM_OFDM_IDX_DIFF;
21447ac9a364SKalle Valo base_pwr_idx =
21457ac9a364SKalle Valo pwr_info->base_power_idx + IL_CCK_FROM_OFDM_IDX_DIFF;
21467ac9a364SKalle Valo
21477ac9a364SKalle Valo /* stay within table range */
21487ac9a364SKalle Valo pwr_idx = il3945_hw_reg_fix_power_idx(pwr_idx);
21497ac9a364SKalle Valo gain = power_gain_table[a_band][pwr_idx].tx_gain;
21507ac9a364SKalle Valo dsp_atten = power_gain_table[a_band][pwr_idx].dsp_atten;
21517ac9a364SKalle Valo
21527ac9a364SKalle Valo /* fill each CCK rate's il3945_channel_power_info structure
21537ac9a364SKalle Valo * NOTE: All CCK-rate Txpwrs are the same for a given chnl!
21547ac9a364SKalle Valo * NOTE: CCK rates start at end of OFDM rates! */
21557ac9a364SKalle Valo for (rate_idx = 0; rate_idx < IL_CCK_RATES; rate_idx++) {
21567ac9a364SKalle Valo pwr_info =
21577ac9a364SKalle Valo &ch_info->power_info[rate_idx + IL_OFDM_RATES];
21587ac9a364SKalle Valo pwr_info->requested_power = power;
21597ac9a364SKalle Valo pwr_info->power_table_idx = pwr_idx;
21607ac9a364SKalle Valo pwr_info->base_power_idx = base_pwr_idx;
21617ac9a364SKalle Valo pwr_info->tpc.tx_gain = gain;
21627ac9a364SKalle Valo pwr_info->tpc.dsp_atten = dsp_atten;
21637ac9a364SKalle Valo }
21647ac9a364SKalle Valo
21657ac9a364SKalle Valo /* set scan tx power, 1Mbit for CCK, 6Mbit for OFDM */
21667ac9a364SKalle Valo for (scan_tbl_idx = 0; scan_tbl_idx < IL_NUM_SCAN_RATES;
21677ac9a364SKalle Valo scan_tbl_idx++) {
21687ac9a364SKalle Valo s32 actual_idx =
21697ac9a364SKalle Valo (scan_tbl_idx ==
21707ac9a364SKalle Valo 0) ? RATE_1M_IDX_TBL : RATE_6M_IDX_TBL;
21717ac9a364SKalle Valo il3945_hw_reg_set_scan_power(il, scan_tbl_idx,
21727ac9a364SKalle Valo actual_idx, clip_pwrs,
21737ac9a364SKalle Valo ch_info, a_band);
21747ac9a364SKalle Valo }
21757ac9a364SKalle Valo }
21767ac9a364SKalle Valo
21777ac9a364SKalle Valo return 0;
21787ac9a364SKalle Valo }
21797ac9a364SKalle Valo
21807ac9a364SKalle Valo int
il3945_hw_rxq_stop(struct il_priv * il)21817ac9a364SKalle Valo il3945_hw_rxq_stop(struct il_priv *il)
21827ac9a364SKalle Valo {
21837ac9a364SKalle Valo int ret;
21847ac9a364SKalle Valo
21857ac9a364SKalle Valo _il_wr(il, FH39_RCSR_CONFIG(0), 0);
21867ac9a364SKalle Valo ret = _il_poll_bit(il, FH39_RSSR_STATUS,
21877ac9a364SKalle Valo FH39_RSSR_CHNL0_RX_STATUS_CHNL_IDLE,
21887ac9a364SKalle Valo FH39_RSSR_CHNL0_RX_STATUS_CHNL_IDLE,
21897ac9a364SKalle Valo 1000);
21907ac9a364SKalle Valo if (ret < 0)
21917ac9a364SKalle Valo IL_ERR("Can't stop Rx DMA.\n");
21927ac9a364SKalle Valo
21937ac9a364SKalle Valo return 0;
21947ac9a364SKalle Valo }
21957ac9a364SKalle Valo
21967ac9a364SKalle Valo int
il3945_hw_tx_queue_init(struct il_priv * il,struct il_tx_queue * txq)21977ac9a364SKalle Valo il3945_hw_tx_queue_init(struct il_priv *il, struct il_tx_queue *txq)
21987ac9a364SKalle Valo {
21997ac9a364SKalle Valo int txq_id = txq->q.id;
22007ac9a364SKalle Valo
22017ac9a364SKalle Valo struct il3945_shared *shared_data = il->_3945.shared_virt;
22027ac9a364SKalle Valo
22037ac9a364SKalle Valo shared_data->tx_base_ptr[txq_id] = cpu_to_le32((u32) txq->q.dma_addr);
22047ac9a364SKalle Valo
22057ac9a364SKalle Valo il_wr(il, FH39_CBCC_CTRL(txq_id), 0);
22067ac9a364SKalle Valo il_wr(il, FH39_CBCC_BASE(txq_id), 0);
22077ac9a364SKalle Valo
22087ac9a364SKalle Valo il_wr(il, FH39_TCSR_CONFIG(txq_id),
22097ac9a364SKalle Valo FH39_TCSR_TX_CONFIG_REG_VAL_CIRQ_RTC_NOINT |
22107ac9a364SKalle Valo FH39_TCSR_TX_CONFIG_REG_VAL_MSG_MODE_TXF |
22117ac9a364SKalle Valo FH39_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_IFTFD |
22127ac9a364SKalle Valo FH39_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL |
22137ac9a364SKalle Valo FH39_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE);
22147ac9a364SKalle Valo
22157ac9a364SKalle Valo /* fake read to flush all prev. writes */
22167ac9a364SKalle Valo _il_rd(il, FH39_TSSR_CBB_BASE);
22177ac9a364SKalle Valo
22187ac9a364SKalle Valo return 0;
22197ac9a364SKalle Valo }
22207ac9a364SKalle Valo
22217ac9a364SKalle Valo /*
22227ac9a364SKalle Valo * HCMD utils
22237ac9a364SKalle Valo */
22247ac9a364SKalle Valo static u16
il3945_get_hcmd_size(u8 cmd_id,u16 len)22257ac9a364SKalle Valo il3945_get_hcmd_size(u8 cmd_id, u16 len)
22267ac9a364SKalle Valo {
22277ac9a364SKalle Valo switch (cmd_id) {
22287ac9a364SKalle Valo case C_RXON:
22297ac9a364SKalle Valo return sizeof(struct il3945_rxon_cmd);
22307ac9a364SKalle Valo case C_POWER_TBL:
22317ac9a364SKalle Valo return sizeof(struct il3945_powertable_cmd);
22327ac9a364SKalle Valo default:
22337ac9a364SKalle Valo return len;
22347ac9a364SKalle Valo }
22357ac9a364SKalle Valo }
22367ac9a364SKalle Valo
22377ac9a364SKalle Valo static u16
il3945_build_addsta_hcmd(const struct il_addsta_cmd * cmd,u8 * data)22387ac9a364SKalle Valo il3945_build_addsta_hcmd(const struct il_addsta_cmd *cmd, u8 * data)
22397ac9a364SKalle Valo {
22407ac9a364SKalle Valo struct il3945_addsta_cmd *addsta = (struct il3945_addsta_cmd *)data;
22417ac9a364SKalle Valo addsta->mode = cmd->mode;
22427ac9a364SKalle Valo memcpy(&addsta->sta, &cmd->sta, sizeof(struct sta_id_modify));
22437ac9a364SKalle Valo memcpy(&addsta->key, &cmd->key, sizeof(struct il4965_keyinfo));
22447ac9a364SKalle Valo addsta->station_flags = cmd->station_flags;
22457ac9a364SKalle Valo addsta->station_flags_msk = cmd->station_flags_msk;
22467ac9a364SKalle Valo addsta->tid_disable_tx = cpu_to_le16(0);
22477ac9a364SKalle Valo addsta->rate_n_flags = cmd->rate_n_flags;
22487ac9a364SKalle Valo addsta->add_immediate_ba_tid = cmd->add_immediate_ba_tid;
22497ac9a364SKalle Valo addsta->remove_immediate_ba_tid = cmd->remove_immediate_ba_tid;
22507ac9a364SKalle Valo addsta->add_immediate_ba_ssn = cmd->add_immediate_ba_ssn;
22517ac9a364SKalle Valo
22527ac9a364SKalle Valo return (u16) sizeof(struct il3945_addsta_cmd);
22537ac9a364SKalle Valo }
22547ac9a364SKalle Valo
22557ac9a364SKalle Valo static int
il3945_add_bssid_station(struct il_priv * il,const u8 * addr,u8 * sta_id_r)22567ac9a364SKalle Valo il3945_add_bssid_station(struct il_priv *il, const u8 * addr, u8 * sta_id_r)
22577ac9a364SKalle Valo {
22587ac9a364SKalle Valo int ret;
22597ac9a364SKalle Valo u8 sta_id;
22607ac9a364SKalle Valo unsigned long flags;
22617ac9a364SKalle Valo
22627ac9a364SKalle Valo if (sta_id_r)
22637ac9a364SKalle Valo *sta_id_r = IL_INVALID_STATION;
22647ac9a364SKalle Valo
22657ac9a364SKalle Valo ret = il_add_station_common(il, addr, 0, NULL, &sta_id);
22667ac9a364SKalle Valo if (ret) {
22677ac9a364SKalle Valo IL_ERR("Unable to add station %pM\n", addr);
22687ac9a364SKalle Valo return ret;
22697ac9a364SKalle Valo }
22707ac9a364SKalle Valo
22717ac9a364SKalle Valo if (sta_id_r)
22727ac9a364SKalle Valo *sta_id_r = sta_id;
22737ac9a364SKalle Valo
22747ac9a364SKalle Valo spin_lock_irqsave(&il->sta_lock, flags);
22757ac9a364SKalle Valo il->stations[sta_id].used |= IL_STA_LOCAL;
22767ac9a364SKalle Valo spin_unlock_irqrestore(&il->sta_lock, flags);
22777ac9a364SKalle Valo
22787ac9a364SKalle Valo return 0;
22797ac9a364SKalle Valo }
22807ac9a364SKalle Valo
22817ac9a364SKalle Valo static int
il3945_manage_ibss_station(struct il_priv * il,struct ieee80211_vif * vif,bool add)22827ac9a364SKalle Valo il3945_manage_ibss_station(struct il_priv *il, struct ieee80211_vif *vif,
22837ac9a364SKalle Valo bool add)
22847ac9a364SKalle Valo {
22857ac9a364SKalle Valo struct il_vif_priv *vif_priv = (void *)vif->drv_priv;
22867ac9a364SKalle Valo int ret;
22877ac9a364SKalle Valo
22887ac9a364SKalle Valo if (add) {
22897ac9a364SKalle Valo ret =
22907ac9a364SKalle Valo il3945_add_bssid_station(il, vif->bss_conf.bssid,
22917ac9a364SKalle Valo &vif_priv->ibss_bssid_sta_id);
22927ac9a364SKalle Valo if (ret)
22937ac9a364SKalle Valo return ret;
22947ac9a364SKalle Valo
22957ac9a364SKalle Valo il3945_sync_sta(il, vif_priv->ibss_bssid_sta_id,
22967ac9a364SKalle Valo (il->band ==
229757fbcce3SJohannes Berg NL80211_BAND_5GHZ) ? RATE_6M_PLCP :
22987ac9a364SKalle Valo RATE_1M_PLCP);
22997ac9a364SKalle Valo il3945_rate_scale_init(il->hw, vif_priv->ibss_bssid_sta_id);
23007ac9a364SKalle Valo
23017ac9a364SKalle Valo return 0;
23027ac9a364SKalle Valo }
23037ac9a364SKalle Valo
23047ac9a364SKalle Valo return il_remove_station(il, vif_priv->ibss_bssid_sta_id,
23057ac9a364SKalle Valo vif->bss_conf.bssid);
23067ac9a364SKalle Valo }
23077ac9a364SKalle Valo
2308a60e33afSLee Jones /*
23097ac9a364SKalle Valo * il3945_init_hw_rate_table - Initialize the hardware rate fallback table
23107ac9a364SKalle Valo */
23117ac9a364SKalle Valo int
il3945_init_hw_rate_table(struct il_priv * il)23127ac9a364SKalle Valo il3945_init_hw_rate_table(struct il_priv *il)
23137ac9a364SKalle Valo {
23147ac9a364SKalle Valo int rc, i, idx, prev_idx;
23157ac9a364SKalle Valo struct il3945_rate_scaling_cmd rate_cmd = {
23167ac9a364SKalle Valo .reserved = {0, 0, 0},
23177ac9a364SKalle Valo };
23187ac9a364SKalle Valo struct il3945_rate_scaling_info *table = rate_cmd.table;
23197ac9a364SKalle Valo
23207ac9a364SKalle Valo for (i = 0; i < ARRAY_SIZE(il3945_rates); i++) {
23217ac9a364SKalle Valo idx = il3945_rates[i].table_rs_idx;
23227ac9a364SKalle Valo
23237ac9a364SKalle Valo table[idx].rate_n_flags = cpu_to_le16(il3945_rates[i].plcp);
23247ac9a364SKalle Valo table[idx].try_cnt = il->retry_rate;
23257ac9a364SKalle Valo prev_idx = il3945_get_prev_ieee_rate(i);
23267ac9a364SKalle Valo table[idx].next_rate_idx = il3945_rates[prev_idx].table_rs_idx;
23277ac9a364SKalle Valo }
23287ac9a364SKalle Valo
23297ac9a364SKalle Valo switch (il->band) {
233057fbcce3SJohannes Berg case NL80211_BAND_5GHZ:
23317ac9a364SKalle Valo D_RATE("Select A mode rate scale\n");
23327ac9a364SKalle Valo /* If one of the following CCK rates is used,
23337ac9a364SKalle Valo * have it fall back to the 6M OFDM rate */
23347ac9a364SKalle Valo for (i = RATE_1M_IDX_TBL; i <= RATE_11M_IDX_TBL; i++)
23357ac9a364SKalle Valo table[i].next_rate_idx =
23367ac9a364SKalle Valo il3945_rates[IL_FIRST_OFDM_RATE].table_rs_idx;
23377ac9a364SKalle Valo
23387ac9a364SKalle Valo /* Don't fall back to CCK rates */
23397ac9a364SKalle Valo table[RATE_12M_IDX_TBL].next_rate_idx = RATE_9M_IDX_TBL;
23407ac9a364SKalle Valo
23417ac9a364SKalle Valo /* Don't drop out of OFDM rates */
23427ac9a364SKalle Valo table[RATE_6M_IDX_TBL].next_rate_idx =
23437ac9a364SKalle Valo il3945_rates[IL_FIRST_OFDM_RATE].table_rs_idx;
23447ac9a364SKalle Valo break;
23457ac9a364SKalle Valo
234657fbcce3SJohannes Berg case NL80211_BAND_2GHZ:
23477ac9a364SKalle Valo D_RATE("Select B/G mode rate scale\n");
23487ac9a364SKalle Valo /* If an OFDM rate is used, have it fall back to the
23497ac9a364SKalle Valo * 1M CCK rates */
23507ac9a364SKalle Valo
23517ac9a364SKalle Valo if (!(il->_3945.sta_supp_rates & IL_OFDM_RATES_MASK) &&
23527ac9a364SKalle Valo il_is_associated(il)) {
23537ac9a364SKalle Valo
23547ac9a364SKalle Valo idx = IL_FIRST_CCK_RATE;
23557ac9a364SKalle Valo for (i = RATE_6M_IDX_TBL; i <= RATE_54M_IDX_TBL; i++)
23567ac9a364SKalle Valo table[i].next_rate_idx =
23577ac9a364SKalle Valo il3945_rates[idx].table_rs_idx;
23587ac9a364SKalle Valo
23597ac9a364SKalle Valo idx = RATE_11M_IDX_TBL;
23607ac9a364SKalle Valo /* CCK shouldn't fall back to OFDM... */
23617ac9a364SKalle Valo table[idx].next_rate_idx = RATE_5M_IDX_TBL;
23627ac9a364SKalle Valo }
23637ac9a364SKalle Valo break;
23647ac9a364SKalle Valo
23657ac9a364SKalle Valo default:
23667ac9a364SKalle Valo WARN_ON(1);
23677ac9a364SKalle Valo break;
23687ac9a364SKalle Valo }
23697ac9a364SKalle Valo
23707ac9a364SKalle Valo /* Update the rate scaling for control frame Tx */
23717ac9a364SKalle Valo rate_cmd.table_id = 0;
23727ac9a364SKalle Valo rc = il_send_cmd_pdu(il, C_RATE_SCALE, sizeof(rate_cmd), &rate_cmd);
23737ac9a364SKalle Valo if (rc)
23747ac9a364SKalle Valo return rc;
23757ac9a364SKalle Valo
23767ac9a364SKalle Valo /* Update the rate scaling for data frame Tx */
23777ac9a364SKalle Valo rate_cmd.table_id = 1;
23787ac9a364SKalle Valo return il_send_cmd_pdu(il, C_RATE_SCALE, sizeof(rate_cmd), &rate_cmd);
23797ac9a364SKalle Valo }
23807ac9a364SKalle Valo
23817ac9a364SKalle Valo /* Called when initializing driver */
23827ac9a364SKalle Valo int
il3945_hw_set_hw_params(struct il_priv * il)23837ac9a364SKalle Valo il3945_hw_set_hw_params(struct il_priv *il)
23847ac9a364SKalle Valo {
23857ac9a364SKalle Valo memset((void *)&il->hw_params, 0, sizeof(struct il_hw_params));
23867ac9a364SKalle Valo
23877ac9a364SKalle Valo il->_3945.shared_virt =
23887ac9a364SKalle Valo dma_alloc_coherent(&il->pci_dev->dev, sizeof(struct il3945_shared),
23897ac9a364SKalle Valo &il->_3945.shared_phys, GFP_KERNEL);
23907ac9a364SKalle Valo if (!il->_3945.shared_virt)
23917ac9a364SKalle Valo return -ENOMEM;
23927ac9a364SKalle Valo
23937ac9a364SKalle Valo il->hw_params.bcast_id = IL3945_BROADCAST_ID;
23947ac9a364SKalle Valo
23957ac9a364SKalle Valo /* Assign number of Usable TX queues */
23967ac9a364SKalle Valo il->hw_params.max_txq_num = il->cfg->num_of_queues;
23977ac9a364SKalle Valo
23987ac9a364SKalle Valo il->hw_params.tfd_size = sizeof(struct il3945_tfd);
23997ac9a364SKalle Valo il->hw_params.rx_page_order = get_order(IL_RX_BUF_SIZE_3K);
24007ac9a364SKalle Valo il->hw_params.max_rxq_size = RX_QUEUE_SIZE;
24017ac9a364SKalle Valo il->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
24027ac9a364SKalle Valo il->hw_params.max_stations = IL3945_STATION_COUNT;
24037ac9a364SKalle Valo
24047ac9a364SKalle Valo il->sta_key_max_num = STA_KEY_MAX_NUM;
24057ac9a364SKalle Valo
24067ac9a364SKalle Valo il->hw_params.rx_wrt_ptr_reg = FH39_RSCSR_CHNL0_WPTR;
24077ac9a364SKalle Valo il->hw_params.max_beacon_itrvl = IL39_MAX_UCODE_BEACON_INTERVAL;
24087ac9a364SKalle Valo il->hw_params.beacon_time_tsf_bits = IL3945_EXT_BEACON_TIME_POS;
24097ac9a364SKalle Valo
24107ac9a364SKalle Valo return 0;
24117ac9a364SKalle Valo }
24127ac9a364SKalle Valo
24137ac9a364SKalle Valo unsigned int
il3945_hw_get_beacon_cmd(struct il_priv * il,struct il3945_frame * frame,u8 rate)24147ac9a364SKalle Valo il3945_hw_get_beacon_cmd(struct il_priv *il, struct il3945_frame *frame,
24157ac9a364SKalle Valo u8 rate)
24167ac9a364SKalle Valo {
24177ac9a364SKalle Valo struct il3945_tx_beacon_cmd *tx_beacon_cmd;
24187ac9a364SKalle Valo unsigned int frame_size;
24197ac9a364SKalle Valo
24207ac9a364SKalle Valo tx_beacon_cmd = (struct il3945_tx_beacon_cmd *)&frame->u;
24217ac9a364SKalle Valo memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
24227ac9a364SKalle Valo
24237ac9a364SKalle Valo tx_beacon_cmd->tx.sta_id = il->hw_params.bcast_id;
24247ac9a364SKalle Valo tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
24257ac9a364SKalle Valo
24267ac9a364SKalle Valo frame_size =
24277ac9a364SKalle Valo il3945_fill_beacon_frame(il, tx_beacon_cmd->frame,
24287ac9a364SKalle Valo sizeof(frame->u) - sizeof(*tx_beacon_cmd));
24297ac9a364SKalle Valo
24307ac9a364SKalle Valo BUG_ON(frame_size > MAX_MPDU_SIZE);
24317ac9a364SKalle Valo tx_beacon_cmd->tx.len = cpu_to_le16((u16) frame_size);
24327ac9a364SKalle Valo
24337ac9a364SKalle Valo tx_beacon_cmd->tx.rate = rate;
24347ac9a364SKalle Valo tx_beacon_cmd->tx.tx_flags =
24357ac9a364SKalle Valo (TX_CMD_FLG_SEQ_CTL_MSK | TX_CMD_FLG_TSF_MSK);
24367ac9a364SKalle Valo
24377ac9a364SKalle Valo /* supp_rates[0] == OFDM start at IL_FIRST_OFDM_RATE */
24387ac9a364SKalle Valo tx_beacon_cmd->tx.supp_rates[0] =
24397ac9a364SKalle Valo (IL_OFDM_BASIC_RATES_MASK >> IL_FIRST_OFDM_RATE) & 0xFF;
24407ac9a364SKalle Valo
24417ac9a364SKalle Valo tx_beacon_cmd->tx.supp_rates[1] = (IL_CCK_BASIC_RATES_MASK & 0xF);
24427ac9a364SKalle Valo
24437ac9a364SKalle Valo return sizeof(struct il3945_tx_beacon_cmd) + frame_size;
24447ac9a364SKalle Valo }
24457ac9a364SKalle Valo
24467ac9a364SKalle Valo void
il3945_hw_handler_setup(struct il_priv * il)24477ac9a364SKalle Valo il3945_hw_handler_setup(struct il_priv *il)
24487ac9a364SKalle Valo {
24497ac9a364SKalle Valo il->handlers[C_TX] = il3945_hdl_tx;
24507ac9a364SKalle Valo il->handlers[N_3945_RX] = il3945_hdl_rx;
24517ac9a364SKalle Valo }
24527ac9a364SKalle Valo
24537ac9a364SKalle Valo void
il3945_hw_setup_deferred_work(struct il_priv * il)24547ac9a364SKalle Valo il3945_hw_setup_deferred_work(struct il_priv *il)
24557ac9a364SKalle Valo {
24567ac9a364SKalle Valo INIT_DELAYED_WORK(&il->_3945.thermal_periodic,
24577ac9a364SKalle Valo il3945_bg_reg_txpower_periodic);
24587ac9a364SKalle Valo }
24597ac9a364SKalle Valo
24607ac9a364SKalle Valo void
il3945_hw_cancel_deferred_work(struct il_priv * il)24617ac9a364SKalle Valo il3945_hw_cancel_deferred_work(struct il_priv *il)
24627ac9a364SKalle Valo {
24637ac9a364SKalle Valo cancel_delayed_work(&il->_3945.thermal_periodic);
24647ac9a364SKalle Valo }
24657ac9a364SKalle Valo
24667ac9a364SKalle Valo /* check contents of special bootstrap uCode SRAM */
24677ac9a364SKalle Valo static int
il3945_verify_bsm(struct il_priv * il)24687ac9a364SKalle Valo il3945_verify_bsm(struct il_priv *il)
24697ac9a364SKalle Valo {
24707ac9a364SKalle Valo __le32 *image = il->ucode_boot.v_addr;
24717ac9a364SKalle Valo u32 len = il->ucode_boot.len;
24727ac9a364SKalle Valo u32 reg;
24737ac9a364SKalle Valo u32 val;
24747ac9a364SKalle Valo
24757ac9a364SKalle Valo D_INFO("Begin verify bsm\n");
24767ac9a364SKalle Valo
24777ac9a364SKalle Valo /* verify BSM SRAM contents */
24787ac9a364SKalle Valo val = il_rd_prph(il, BSM_WR_DWCOUNT_REG);
24797ac9a364SKalle Valo for (reg = BSM_SRAM_LOWER_BOUND; reg < BSM_SRAM_LOWER_BOUND + len;
24807ac9a364SKalle Valo reg += sizeof(u32), image++) {
24817ac9a364SKalle Valo val = il_rd_prph(il, reg);
24827ac9a364SKalle Valo if (val != le32_to_cpu(*image)) {
24837ac9a364SKalle Valo IL_ERR("BSM uCode verification failed at "
24847ac9a364SKalle Valo "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
24857ac9a364SKalle Valo BSM_SRAM_LOWER_BOUND, reg - BSM_SRAM_LOWER_BOUND,
24867ac9a364SKalle Valo len, val, le32_to_cpu(*image));
24877ac9a364SKalle Valo return -EIO;
24887ac9a364SKalle Valo }
24897ac9a364SKalle Valo }
24907ac9a364SKalle Valo
24917ac9a364SKalle Valo D_INFO("BSM bootstrap uCode image OK\n");
24927ac9a364SKalle Valo
24937ac9a364SKalle Valo return 0;
24947ac9a364SKalle Valo }
24957ac9a364SKalle Valo
24967ac9a364SKalle Valo /******************************************************************************
24977ac9a364SKalle Valo *
24987ac9a364SKalle Valo * EEPROM related functions
24997ac9a364SKalle Valo *
25007ac9a364SKalle Valo ******************************************************************************/
25017ac9a364SKalle Valo
25027ac9a364SKalle Valo /*
25037ac9a364SKalle Valo * Clear the OWNER_MSK, to establish driver (instead of uCode running on
25047ac9a364SKalle Valo * embedded controller) as EEPROM reader; each read is a series of pulses
25057ac9a364SKalle Valo * to/from the EEPROM chip, not a single event, so even reads could conflict
25067ac9a364SKalle Valo * if they weren't arbitrated by some ownership mechanism. Here, the driver
25077ac9a364SKalle Valo * simply claims ownership, which should be safe when this function is called
25087ac9a364SKalle Valo * (i.e. before loading uCode!).
25097ac9a364SKalle Valo */
25107ac9a364SKalle Valo static int
il3945_eeprom_acquire_semaphore(struct il_priv * il)25117ac9a364SKalle Valo il3945_eeprom_acquire_semaphore(struct il_priv *il)
25127ac9a364SKalle Valo {
25137ac9a364SKalle Valo _il_clear_bit(il, CSR_EEPROM_GP, CSR_EEPROM_GP_IF_OWNER_MSK);
25147ac9a364SKalle Valo return 0;
25157ac9a364SKalle Valo }
25167ac9a364SKalle Valo
25177ac9a364SKalle Valo static void
il3945_eeprom_release_semaphore(struct il_priv * il)25187ac9a364SKalle Valo il3945_eeprom_release_semaphore(struct il_priv *il)
25197ac9a364SKalle Valo {
25207ac9a364SKalle Valo return;
25217ac9a364SKalle Valo }
25227ac9a364SKalle Valo
2523a60e33afSLee Jones /*
25247ac9a364SKalle Valo * il3945_load_bsm - Load bootstrap instructions
25257ac9a364SKalle Valo *
25267ac9a364SKalle Valo * BSM operation:
25277ac9a364SKalle Valo *
25287ac9a364SKalle Valo * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
25297ac9a364SKalle Valo * in special SRAM that does not power down during RFKILL. When powering back
25307ac9a364SKalle Valo * up after power-saving sleeps (or during initial uCode load), the BSM loads
25317ac9a364SKalle Valo * the bootstrap program into the on-board processor, and starts it.
25327ac9a364SKalle Valo *
25337ac9a364SKalle Valo * The bootstrap program loads (via DMA) instructions and data for a new
25347ac9a364SKalle Valo * program from host DRAM locations indicated by the host driver in the
25357ac9a364SKalle Valo * BSM_DRAM_* registers. Once the new program is loaded, it starts
25367ac9a364SKalle Valo * automatically.
25377ac9a364SKalle Valo *
25387ac9a364SKalle Valo * When initializing the NIC, the host driver points the BSM to the
25397ac9a364SKalle Valo * "initialize" uCode image. This uCode sets up some internal data, then
25407ac9a364SKalle Valo * notifies host via "initialize alive" that it is complete.
25417ac9a364SKalle Valo *
25427ac9a364SKalle Valo * The host then replaces the BSM_DRAM_* pointer values to point to the
25437ac9a364SKalle Valo * normal runtime uCode instructions and a backup uCode data cache buffer
25447ac9a364SKalle Valo * (filled initially with starting data values for the on-board processor),
25457ac9a364SKalle Valo * then triggers the "initialize" uCode to load and launch the runtime uCode,
25467ac9a364SKalle Valo * which begins normal operation.
25477ac9a364SKalle Valo *
25487ac9a364SKalle Valo * When doing a power-save shutdown, runtime uCode saves data SRAM into
25497ac9a364SKalle Valo * the backup data cache in DRAM before SRAM is powered down.
25507ac9a364SKalle Valo *
25517ac9a364SKalle Valo * When powering back up, the BSM loads the bootstrap program. This reloads
25527ac9a364SKalle Valo * the runtime uCode instructions and the backup data cache into SRAM,
25537ac9a364SKalle Valo * and re-launches the runtime uCode from where it left off.
25547ac9a364SKalle Valo */
25557ac9a364SKalle Valo static int
il3945_load_bsm(struct il_priv * il)25567ac9a364SKalle Valo il3945_load_bsm(struct il_priv *il)
25577ac9a364SKalle Valo {
25587ac9a364SKalle Valo __le32 *image = il->ucode_boot.v_addr;
25597ac9a364SKalle Valo u32 len = il->ucode_boot.len;
25607ac9a364SKalle Valo dma_addr_t pinst;
25617ac9a364SKalle Valo dma_addr_t pdata;
25627ac9a364SKalle Valo u32 inst_len;
25637ac9a364SKalle Valo u32 data_len;
25647ac9a364SKalle Valo int rc;
25657ac9a364SKalle Valo int i;
25667ac9a364SKalle Valo u32 done;
25677ac9a364SKalle Valo u32 reg_offset;
25687ac9a364SKalle Valo
25697ac9a364SKalle Valo D_INFO("Begin load bsm\n");
25707ac9a364SKalle Valo
25717ac9a364SKalle Valo /* make sure bootstrap program is no larger than BSM's SRAM size */
25727ac9a364SKalle Valo if (len > IL39_MAX_BSM_SIZE)
25737ac9a364SKalle Valo return -EINVAL;
25747ac9a364SKalle Valo
25757ac9a364SKalle Valo /* Tell bootstrap uCode where to find the "Initialize" uCode
25767ac9a364SKalle Valo * in host DRAM ... host DRAM physical address bits 31:0 for 3945.
25777ac9a364SKalle Valo * NOTE: il3945_initialize_alive_start() will replace these values,
25787ac9a364SKalle Valo * after the "initialize" uCode has run, to point to
25797ac9a364SKalle Valo * runtime/protocol instructions and backup data cache. */
25807ac9a364SKalle Valo pinst = il->ucode_init.p_addr;
25817ac9a364SKalle Valo pdata = il->ucode_init_data.p_addr;
25827ac9a364SKalle Valo inst_len = il->ucode_init.len;
25837ac9a364SKalle Valo data_len = il->ucode_init_data.len;
25847ac9a364SKalle Valo
25857ac9a364SKalle Valo il_wr_prph(il, BSM_DRAM_INST_PTR_REG, pinst);
25867ac9a364SKalle Valo il_wr_prph(il, BSM_DRAM_DATA_PTR_REG, pdata);
25877ac9a364SKalle Valo il_wr_prph(il, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
25887ac9a364SKalle Valo il_wr_prph(il, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
25897ac9a364SKalle Valo
25907ac9a364SKalle Valo /* Fill BSM memory with bootstrap instructions */
25917ac9a364SKalle Valo for (reg_offset = BSM_SRAM_LOWER_BOUND;
25927ac9a364SKalle Valo reg_offset < BSM_SRAM_LOWER_BOUND + len;
25937ac9a364SKalle Valo reg_offset += sizeof(u32), image++)
25947ac9a364SKalle Valo _il_wr_prph(il, reg_offset, le32_to_cpu(*image));
25957ac9a364SKalle Valo
25967ac9a364SKalle Valo rc = il3945_verify_bsm(il);
25977ac9a364SKalle Valo if (rc)
25987ac9a364SKalle Valo return rc;
25997ac9a364SKalle Valo
26007ac9a364SKalle Valo /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
26017ac9a364SKalle Valo il_wr_prph(il, BSM_WR_MEM_SRC_REG, 0x0);
26027ac9a364SKalle Valo il_wr_prph(il, BSM_WR_MEM_DST_REG, IL39_RTC_INST_LOWER_BOUND);
26037ac9a364SKalle Valo il_wr_prph(il, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
26047ac9a364SKalle Valo
26057ac9a364SKalle Valo /* Load bootstrap code into instruction SRAM now,
26067ac9a364SKalle Valo * to prepare to load "initialize" uCode */
26077ac9a364SKalle Valo il_wr_prph(il, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START);
26087ac9a364SKalle Valo
26097ac9a364SKalle Valo /* Wait for load of bootstrap uCode to finish */
26107ac9a364SKalle Valo for (i = 0; i < 100; i++) {
26117ac9a364SKalle Valo done = il_rd_prph(il, BSM_WR_CTRL_REG);
26127ac9a364SKalle Valo if (!(done & BSM_WR_CTRL_REG_BIT_START))
26137ac9a364SKalle Valo break;
26147ac9a364SKalle Valo udelay(10);
26157ac9a364SKalle Valo }
26167ac9a364SKalle Valo if (i < 100)
26177ac9a364SKalle Valo D_INFO("BSM write complete, poll %d iterations\n", i);
26187ac9a364SKalle Valo else {
26197ac9a364SKalle Valo IL_ERR("BSM write did not complete!\n");
26207ac9a364SKalle Valo return -EIO;
26217ac9a364SKalle Valo }
26227ac9a364SKalle Valo
26237ac9a364SKalle Valo /* Enable future boot loads whenever power management unit triggers it
26247ac9a364SKalle Valo * (e.g. when powering back up after power-save shutdown) */
26257ac9a364SKalle Valo il_wr_prph(il, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START_EN);
26267ac9a364SKalle Valo
26277ac9a364SKalle Valo return 0;
26287ac9a364SKalle Valo }
26297ac9a364SKalle Valo
26307ac9a364SKalle Valo const struct il_ops il3945_ops = {
26317ac9a364SKalle Valo .txq_attach_buf_to_tfd = il3945_hw_txq_attach_buf_to_tfd,
26327ac9a364SKalle Valo .txq_free_tfd = il3945_hw_txq_free_tfd,
26337ac9a364SKalle Valo .txq_init = il3945_hw_tx_queue_init,
26347ac9a364SKalle Valo .load_ucode = il3945_load_bsm,
26357ac9a364SKalle Valo .dump_nic_error_log = il3945_dump_nic_error_log,
26367ac9a364SKalle Valo .apm_init = il3945_apm_init,
26377ac9a364SKalle Valo .send_tx_power = il3945_send_tx_power,
26387ac9a364SKalle Valo .is_valid_rtc_data_addr = il3945_hw_valid_rtc_data_addr,
26397ac9a364SKalle Valo .eeprom_acquire_semaphore = il3945_eeprom_acquire_semaphore,
26407ac9a364SKalle Valo .eeprom_release_semaphore = il3945_eeprom_release_semaphore,
26417ac9a364SKalle Valo
26427ac9a364SKalle Valo .rxon_assoc = il3945_send_rxon_assoc,
26437ac9a364SKalle Valo .commit_rxon = il3945_commit_rxon,
26447ac9a364SKalle Valo
26457ac9a364SKalle Valo .get_hcmd_size = il3945_get_hcmd_size,
26467ac9a364SKalle Valo .build_addsta_hcmd = il3945_build_addsta_hcmd,
26477ac9a364SKalle Valo .request_scan = il3945_request_scan,
26487ac9a364SKalle Valo .post_scan = il3945_post_scan,
26497ac9a364SKalle Valo
26507ac9a364SKalle Valo .post_associate = il3945_post_associate,
26517ac9a364SKalle Valo .config_ap = il3945_config_ap,
26527ac9a364SKalle Valo .manage_ibss_station = il3945_manage_ibss_station,
26537ac9a364SKalle Valo
26547ac9a364SKalle Valo .send_led_cmd = il3945_send_led_cmd,
26557ac9a364SKalle Valo };
26567ac9a364SKalle Valo
26571dc80798SJulia Lawall static const struct il_cfg il3945_bg_cfg = {
26587ac9a364SKalle Valo .name = "3945BG",
26597ac9a364SKalle Valo .fw_name_pre = IL3945_FW_PRE,
26607ac9a364SKalle Valo .ucode_api_max = IL3945_UCODE_API_MAX,
26617ac9a364SKalle Valo .ucode_api_min = IL3945_UCODE_API_MIN,
26627ac9a364SKalle Valo .sku = IL_SKU_G,
26637ac9a364SKalle Valo .eeprom_ver = EEPROM_3945_EEPROM_VERSION,
26647ac9a364SKalle Valo .mod_params = &il3945_mod_params,
26657ac9a364SKalle Valo .led_mode = IL_LED_BLINK,
26667ac9a364SKalle Valo
26677ac9a364SKalle Valo .eeprom_size = IL3945_EEPROM_IMG_SIZE,
26687ac9a364SKalle Valo .num_of_queues = IL39_NUM_QUEUES,
26697ac9a364SKalle Valo .pll_cfg_val = CSR39_ANA_PLL_CFG_VAL,
26707ac9a364SKalle Valo .set_l0s = false,
26717ac9a364SKalle Valo .use_bsm = true,
26727ac9a364SKalle Valo .led_compensation = 64,
26737ac9a364SKalle Valo .wd_timeout = IL_DEF_WD_TIMEOUT,
26747ac9a364SKalle Valo
26757ac9a364SKalle Valo .regulatory_bands = {
26767ac9a364SKalle Valo EEPROM_REGULATORY_BAND_1_CHANNELS,
26777ac9a364SKalle Valo EEPROM_REGULATORY_BAND_2_CHANNELS,
26787ac9a364SKalle Valo EEPROM_REGULATORY_BAND_3_CHANNELS,
26797ac9a364SKalle Valo EEPROM_REGULATORY_BAND_4_CHANNELS,
26807ac9a364SKalle Valo EEPROM_REGULATORY_BAND_5_CHANNELS,
26817ac9a364SKalle Valo EEPROM_REGULATORY_BAND_NO_HT40,
26827ac9a364SKalle Valo EEPROM_REGULATORY_BAND_NO_HT40,
26837ac9a364SKalle Valo },
26847ac9a364SKalle Valo };
26857ac9a364SKalle Valo
26861dc80798SJulia Lawall static const struct il_cfg il3945_abg_cfg = {
26877ac9a364SKalle Valo .name = "3945ABG",
26887ac9a364SKalle Valo .fw_name_pre = IL3945_FW_PRE,
26897ac9a364SKalle Valo .ucode_api_max = IL3945_UCODE_API_MAX,
26907ac9a364SKalle Valo .ucode_api_min = IL3945_UCODE_API_MIN,
26917ac9a364SKalle Valo .sku = IL_SKU_A | IL_SKU_G,
26927ac9a364SKalle Valo .eeprom_ver = EEPROM_3945_EEPROM_VERSION,
26937ac9a364SKalle Valo .mod_params = &il3945_mod_params,
26947ac9a364SKalle Valo .led_mode = IL_LED_BLINK,
26957ac9a364SKalle Valo
26967ac9a364SKalle Valo .eeprom_size = IL3945_EEPROM_IMG_SIZE,
26977ac9a364SKalle Valo .num_of_queues = IL39_NUM_QUEUES,
26987ac9a364SKalle Valo .pll_cfg_val = CSR39_ANA_PLL_CFG_VAL,
26997ac9a364SKalle Valo .set_l0s = false,
27007ac9a364SKalle Valo .use_bsm = true,
27017ac9a364SKalle Valo .led_compensation = 64,
27027ac9a364SKalle Valo .wd_timeout = IL_DEF_WD_TIMEOUT,
27037ac9a364SKalle Valo
27047ac9a364SKalle Valo .regulatory_bands = {
27057ac9a364SKalle Valo EEPROM_REGULATORY_BAND_1_CHANNELS,
27067ac9a364SKalle Valo EEPROM_REGULATORY_BAND_2_CHANNELS,
27077ac9a364SKalle Valo EEPROM_REGULATORY_BAND_3_CHANNELS,
27087ac9a364SKalle Valo EEPROM_REGULATORY_BAND_4_CHANNELS,
27097ac9a364SKalle Valo EEPROM_REGULATORY_BAND_5_CHANNELS,
27107ac9a364SKalle Valo EEPROM_REGULATORY_BAND_NO_HT40,
27117ac9a364SKalle Valo EEPROM_REGULATORY_BAND_NO_HT40,
27127ac9a364SKalle Valo },
27137ac9a364SKalle Valo };
27147ac9a364SKalle Valo
27157ac9a364SKalle Valo const struct pci_device_id il3945_hw_card_ids[] = {
27167ac9a364SKalle Valo {IL_PCI_DEVICE(0x4222, 0x1005, il3945_bg_cfg)},
27177ac9a364SKalle Valo {IL_PCI_DEVICE(0x4222, 0x1034, il3945_bg_cfg)},
27187ac9a364SKalle Valo {IL_PCI_DEVICE(0x4222, 0x1044, il3945_bg_cfg)},
27197ac9a364SKalle Valo {IL_PCI_DEVICE(0x4227, 0x1014, il3945_bg_cfg)},
27207ac9a364SKalle Valo {IL_PCI_DEVICE(0x4222, PCI_ANY_ID, il3945_abg_cfg)},
27217ac9a364SKalle Valo {IL_PCI_DEVICE(0x4227, PCI_ANY_ID, il3945_abg_cfg)},
27227ac9a364SKalle Valo {0}
27237ac9a364SKalle Valo };
27247ac9a364SKalle Valo
27257ac9a364SKalle Valo MODULE_DEVICE_TABLE(pci, il3945_hw_card_ids);
2726