aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/3c523.c37
-rw-r--r--drivers/net/3c527.c45
-rw-r--r--drivers/net/8139cp.c43
-rw-r--r--drivers/net/8139too.c53
-rw-r--r--drivers/net/8390.h1
-rw-r--r--drivers/net/acenic.c21
-rw-r--r--drivers/net/acenic.h1
-rw-r--r--drivers/net/cpmac.c2
-rw-r--r--drivers/net/dm9000.c6
-rw-r--r--drivers/net/gianfar.c2
-rw-r--r--drivers/net/hamradio/6pack.c24
-rw-r--r--drivers/net/lib8390.c96
-rw-r--r--drivers/net/natsemi.c4
-rw-r--r--drivers/net/niu.h2
-rw-r--r--drivers/net/pcmcia/3c574_cs.c47
-rw-r--r--drivers/net/pcmcia/3c589_cs.c49
-rw-r--r--drivers/net/pcmcia/axnet_cs.c70
-rw-r--r--drivers/net/pcnet32.c6
-rw-r--r--drivers/net/qla3xxx.c4
-rw-r--r--drivers/net/s2io.c4
-rw-r--r--drivers/net/s2io.h2
-rw-r--r--drivers/net/sb1250-mac.c2
-rw-r--r--drivers/net/sis190.c2
-rw-r--r--drivers/net/sis900.c2
-rw-r--r--drivers/net/sky2.c2
-rw-r--r--drivers/net/spider_net.c4
-rw-r--r--drivers/net/tokenring/3c359.c20
-rw-r--r--drivers/net/tokenring/3c359.h2
-rw-r--r--drivers/net/tsi108_eth.c4
-rw-r--r--drivers/net/ucc_geth_ethtool.c4
-rw-r--r--drivers/net/wireless/adm8211.c7
-rw-r--r--drivers/net/wireless/ath5k/base.c10
-rw-r--r--drivers/net/wireless/ath5k/base.h3
-rw-r--r--drivers/net/wireless/b43/b43.h3
-rw-r--r--drivers/net/wireless/b43/debugfs.c77
-rw-r--r--drivers/net/wireless/b43/debugfs.h1
-rw-r--r--drivers/net/wireless/b43/dma.c8
-rw-r--r--drivers/net/wireless/b43/lo.c727
-rw-r--r--drivers/net/wireless/b43/lo.h115
-rw-r--r--drivers/net/wireless/b43/main.c42
-rw-r--r--drivers/net/wireless/b43/main.h3
-rw-r--r--drivers/net/wireless/b43/phy.c240
-rw-r--r--drivers/net/wireless/b43/phy.h16
-rw-r--r--drivers/net/wireless/b43/pio.c8
-rw-r--r--drivers/net/wireless/b43/xmit.c2
-rw-r--r--drivers/net/wireless/b43legacy/dma.c8
-rw-r--r--drivers/net/wireless/b43legacy/main.c3
-rw-r--r--drivers/net/wireless/b43legacy/pio.c8
-rw-r--r--drivers/net/wireless/b43legacy/xmit.c2
-rw-r--r--drivers/net/wireless/iwlwifi/Kconfig36
-rw-r--r--drivers/net/wireless/iwlwifi/Makefile8
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945-hw.h13
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945-rs.c1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.h5
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965-hw.h605
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965-rs.c983
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965-rs.h87
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965.c1667
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-5000-hw.h133
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-5000.c519
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-calib.c779
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-calib.h104
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-commands.h (renamed from drivers/net/wireless/iwlwifi/iwl-4965-commands.h)63
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.c562
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.h34
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-csr.h32
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-debugfs.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-dev.h (renamed from drivers/net/wireless/iwlwifi/iwl-4965.h)180
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-eeprom.c118
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-eeprom.h205
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-fh.h391
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-hcmd.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-led.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-power.c423
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-power.h76
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-prph.h310
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-rfkill.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.c92
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.h11
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c21
-rw-r--r--drivers/net/wireless/iwlwifi/iwl4965-base.c1014
-rw-r--r--drivers/net/wireless/libertas/cmd.h2
-rw-r--r--drivers/net/wireless/libertas/decl.h4
-rw-r--r--drivers/net/wireless/libertas/main.c26
-rw-r--r--drivers/net/wireless/p54/p54.h2
-rw-r--r--drivers/net/wireless/p54/p54common.c28
-rw-r--r--drivers/net/wireless/rt2x00/Kconfig55
-rw-r--r--drivers/net/wireless/rt2x00/rt2400pci.c37
-rw-r--r--drivers/net/wireless/rt2x00/rt2500pci.c35
-rw-r--r--drivers/net/wireless/rt2x00/rt2500usb.c20
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00.h20
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00dev.c6
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00mac.c39
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00pci.c2
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00pci.h6
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00queue.c6
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00queue.h37
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00usb.c4
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00usb.h21
-rw-r--r--drivers/net/wireless/rt2x00/rt61pci.c27
-rw-r--r--drivers/net/wireless/rt2x00/rt73usb.c33
102 files changed, 5842 insertions, 4894 deletions
diff --git a/drivers/net/3c523.c b/drivers/net/3c523.c
index 239fc42fb8df..dc6e474229b1 100644
--- a/drivers/net/3c523.c
+++ b/drivers/net/3c523.c
@@ -202,7 +202,6 @@ static void elmc_xmt_int(struct net_device *dev);
202static void elmc_rnr_int(struct net_device *dev); 202static void elmc_rnr_int(struct net_device *dev);
203 203
204struct priv { 204struct priv {
205 struct net_device_stats stats;
206 unsigned long base; 205 unsigned long base;
207 char *memtop; 206 char *memtop;
208 unsigned long mapped_start; /* Start of ioremap */ 207 unsigned long mapped_start; /* Start of ioremap */
@@ -989,18 +988,18 @@ static void elmc_rcv_int(struct net_device *dev)
989 skb->protocol = eth_type_trans(skb, dev); 988 skb->protocol = eth_type_trans(skb, dev);
990 netif_rx(skb); 989 netif_rx(skb);
991 dev->last_rx = jiffies; 990 dev->last_rx = jiffies;
992 p->stats.rx_packets++; 991 dev->stats.rx_packets++;
993 p->stats.rx_bytes += totlen; 992 dev->stats.rx_bytes += totlen;
994 } else { 993 } else {
995 p->stats.rx_dropped++; 994 dev->stats.rx_dropped++;
996 } 995 }
997 } else { 996 } else {
998 printk(KERN_WARNING "%s: received oversized frame.\n", dev->name); 997 printk(KERN_WARNING "%s: received oversized frame.\n", dev->name);
999 p->stats.rx_dropped++; 998 dev->stats.rx_dropped++;
1000 } 999 }
1001 } else { /* frame !(ok), only with 'save-bad-frames' */ 1000 } else { /* frame !(ok), only with 'save-bad-frames' */
1002 printk(KERN_WARNING "%s: oops! rfd-error-status: %04x\n", dev->name, status); 1001 printk(KERN_WARNING "%s: oops! rfd-error-status: %04x\n", dev->name, status);
1003 p->stats.rx_errors++; 1002 dev->stats.rx_errors++;
1004 } 1003 }
1005 p->rfd_top->status = 0; 1004 p->rfd_top->status = 0;
1006 p->rfd_top->last = RFD_SUSP; 1005 p->rfd_top->last = RFD_SUSP;
@@ -1018,7 +1017,7 @@ static void elmc_rnr_int(struct net_device *dev)
1018{ 1017{
1019 struct priv *p = (struct priv *) dev->priv; 1018 struct priv *p = (struct priv *) dev->priv;
1020 1019
1021 p->stats.rx_errors++; 1020 dev->stats.rx_errors++;
1022 1021
1023 WAIT_4_SCB_CMD(); /* wait for the last cmd */ 1022 WAIT_4_SCB_CMD(); /* wait for the last cmd */
1024 p->scb->cmd = RUC_ABORT; /* usually the RU is in the 'no resource'-state .. abort it now. */ 1023 p->scb->cmd = RUC_ABORT; /* usually the RU is in the 'no resource'-state .. abort it now. */
@@ -1046,24 +1045,24 @@ static void elmc_xmt_int(struct net_device *dev)
1046 printk(KERN_WARNING "%s: strange .. xmit-int without a 'COMPLETE'\n", dev->name); 1045 printk(KERN_WARNING "%s: strange .. xmit-int without a 'COMPLETE'\n", dev->name);
1047 } 1046 }
1048 if (status & STAT_OK) { 1047 if (status & STAT_OK) {
1049 p->stats.tx_packets++; 1048 dev->stats.tx_packets++;
1050 p->stats.collisions += (status & TCMD_MAXCOLLMASK); 1049 dev->stats.collisions += (status & TCMD_MAXCOLLMASK);
1051 } else { 1050 } else {
1052 p->stats.tx_errors++; 1051 dev->stats.tx_errors++;
1053 if (status & TCMD_LATECOLL) { 1052 if (status & TCMD_LATECOLL) {
1054 printk(KERN_WARNING "%s: late collision detected.\n", dev->name); 1053 printk(KERN_WARNING "%s: late collision detected.\n", dev->name);
1055 p->stats.collisions++; 1054 dev->stats.collisions++;
1056 } else if (status & TCMD_NOCARRIER) { 1055 } else if (status & TCMD_NOCARRIER) {
1057 p->stats.tx_carrier_errors++; 1056 dev->stats.tx_carrier_errors++;
1058 printk(KERN_WARNING "%s: no carrier detected.\n", dev->name); 1057 printk(KERN_WARNING "%s: no carrier detected.\n", dev->name);
1059 } else if (status & TCMD_LOSTCTS) { 1058 } else if (status & TCMD_LOSTCTS) {
1060 printk(KERN_WARNING "%s: loss of CTS detected.\n", dev->name); 1059 printk(KERN_WARNING "%s: loss of CTS detected.\n", dev->name);
1061 } else if (status & TCMD_UNDERRUN) { 1060 } else if (status & TCMD_UNDERRUN) {
1062 p->stats.tx_fifo_errors++; 1061 dev->stats.tx_fifo_errors++;
1063 printk(KERN_WARNING "%s: DMA underrun detected.\n", dev->name); 1062 printk(KERN_WARNING "%s: DMA underrun detected.\n", dev->name);
1064 } else if (status & TCMD_MAXCOLL) { 1063 } else if (status & TCMD_MAXCOLL) {
1065 printk(KERN_WARNING "%s: Max. collisions exceeded.\n", dev->name); 1064 printk(KERN_WARNING "%s: Max. collisions exceeded.\n", dev->name);
1066 p->stats.collisions += 16; 1065 dev->stats.collisions += 16;
1067 } 1066 }
1068 } 1067 }
1069 1068
@@ -1215,12 +1214,12 @@ static struct net_device_stats *elmc_get_stats(struct net_device *dev)
1215 ovrn = p->scb->ovrn_errs; 1214 ovrn = p->scb->ovrn_errs;
1216 p->scb->ovrn_errs -= ovrn; 1215 p->scb->ovrn_errs -= ovrn;
1217 1216
1218 p->stats.rx_crc_errors += crc; 1217 dev->stats.rx_crc_errors += crc;
1219 p->stats.rx_fifo_errors += ovrn; 1218 dev->stats.rx_fifo_errors += ovrn;
1220 p->stats.rx_frame_errors += aln; 1219 dev->stats.rx_frame_errors += aln;
1221 p->stats.rx_dropped += rsc; 1220 dev->stats.rx_dropped += rsc;
1222 1221
1223 return &p->stats; 1222 return &dev->stats;
1224} 1223}
1225 1224
1226/******************************************************** 1225/********************************************************
diff --git a/drivers/net/3c527.c b/drivers/net/3c527.c
index fae295b6809c..6aca0c640f13 100644
--- a/drivers/net/3c527.c
+++ b/drivers/net/3c527.c
@@ -158,7 +158,6 @@ struct mc32_local
158 int slot; 158 int slot;
159 159
160 u32 base; 160 u32 base;
161 struct net_device_stats net_stats;
162 volatile struct mc32_mailbox *rx_box; 161 volatile struct mc32_mailbox *rx_box;
163 volatile struct mc32_mailbox *tx_box; 162 volatile struct mc32_mailbox *tx_box;
164 volatile struct mc32_mailbox *exec_box; 163 volatile struct mc32_mailbox *exec_box;
@@ -1093,24 +1092,24 @@ static void mc32_update_stats(struct net_device *dev)
1093 1092
1094 u32 rx_errors=0; 1093 u32 rx_errors=0;
1095 1094
1096 rx_errors+=lp->net_stats.rx_crc_errors +=st->rx_crc_errors; 1095 rx_errors+=dev->stats.rx_crc_errors +=st->rx_crc_errors;
1097 st->rx_crc_errors=0; 1096 st->rx_crc_errors=0;
1098 rx_errors+=lp->net_stats.rx_fifo_errors +=st->rx_overrun_errors; 1097 rx_errors+=dev->stats.rx_fifo_errors +=st->rx_overrun_errors;
1099 st->rx_overrun_errors=0; 1098 st->rx_overrun_errors=0;
1100 rx_errors+=lp->net_stats.rx_frame_errors +=st->rx_alignment_errors; 1099 rx_errors+=dev->stats.rx_frame_errors +=st->rx_alignment_errors;
1101 st->rx_alignment_errors=0; 1100 st->rx_alignment_errors=0;
1102 rx_errors+=lp->net_stats.rx_length_errors+=st->rx_tooshort_errors; 1101 rx_errors+=dev->stats.rx_length_errors+=st->rx_tooshort_errors;
1103 st->rx_tooshort_errors=0; 1102 st->rx_tooshort_errors=0;
1104 rx_errors+=lp->net_stats.rx_missed_errors+=st->rx_outofresource_errors; 1103 rx_errors+=dev->stats.rx_missed_errors+=st->rx_outofresource_errors;
1105 st->rx_outofresource_errors=0; 1104 st->rx_outofresource_errors=0;
1106 lp->net_stats.rx_errors=rx_errors; 1105 dev->stats.rx_errors=rx_errors;
1107 1106
1108 /* Number of packets which saw one collision */ 1107 /* Number of packets which saw one collision */
1109 lp->net_stats.collisions+=st->dataC[10]; 1108 dev->stats.collisions+=st->dataC[10];
1110 st->dataC[10]=0; 1109 st->dataC[10]=0;
1111 1110
1112 /* Number of packets which saw 2--15 collisions */ 1111 /* Number of packets which saw 2--15 collisions */
1113 lp->net_stats.collisions+=st->dataC[11]; 1112 dev->stats.collisions+=st->dataC[11];
1114 st->dataC[11]=0; 1113 st->dataC[11]=0;
1115} 1114}
1116 1115
@@ -1178,7 +1177,7 @@ static void mc32_rx_ring(struct net_device *dev)
1178 skb=dev_alloc_skb(length+2); 1177 skb=dev_alloc_skb(length+2);
1179 1178
1180 if(skb==NULL) { 1179 if(skb==NULL) {
1181 lp->net_stats.rx_dropped++; 1180 dev->stats.rx_dropped++;
1182 goto dropped; 1181 goto dropped;
1183 } 1182 }
1184 1183
@@ -1189,8 +1188,8 @@ static void mc32_rx_ring(struct net_device *dev)
1189 1188
1190 skb->protocol=eth_type_trans(skb,dev); 1189 skb->protocol=eth_type_trans(skb,dev);
1191 dev->last_rx = jiffies; 1190 dev->last_rx = jiffies;
1192 lp->net_stats.rx_packets++; 1191 dev->stats.rx_packets++;
1193 lp->net_stats.rx_bytes += length; 1192 dev->stats.rx_bytes += length;
1194 netif_rx(skb); 1193 netif_rx(skb);
1195 } 1194 }
1196 1195
@@ -1253,34 +1252,34 @@ static void mc32_tx_ring(struct net_device *dev)
1253 /* Not COMPLETED */ 1252 /* Not COMPLETED */
1254 break; 1253 break;
1255 } 1254 }
1256 lp->net_stats.tx_packets++; 1255 dev->stats.tx_packets++;
1257 if(!(np->status & (1<<6))) /* Not COMPLETED_OK */ 1256 if(!(np->status & (1<<6))) /* Not COMPLETED_OK */
1258 { 1257 {
1259 lp->net_stats.tx_errors++; 1258 dev->stats.tx_errors++;
1260 1259
1261 switch(np->status&0x0F) 1260 switch(np->status&0x0F)
1262 { 1261 {
1263 case 1: 1262 case 1:
1264 lp->net_stats.tx_aborted_errors++; 1263 dev->stats.tx_aborted_errors++;
1265 break; /* Max collisions */ 1264 break; /* Max collisions */
1266 case 2: 1265 case 2:
1267 lp->net_stats.tx_fifo_errors++; 1266 dev->stats.tx_fifo_errors++;
1268 break; 1267 break;
1269 case 3: 1268 case 3:
1270 lp->net_stats.tx_carrier_errors++; 1269 dev->stats.tx_carrier_errors++;
1271 break; 1270 break;
1272 case 4: 1271 case 4:
1273 lp->net_stats.tx_window_errors++; 1272 dev->stats.tx_window_errors++;
1274 break; /* CTS Lost */ 1273 break; /* CTS Lost */
1275 case 5: 1274 case 5:
1276 lp->net_stats.tx_aborted_errors++; 1275 dev->stats.tx_aborted_errors++;
1277 break; /* Transmit timeout */ 1276 break; /* Transmit timeout */
1278 } 1277 }
1279 } 1278 }
1280 /* Packets are sent in order - this is 1279 /* Packets are sent in order - this is
1281 basically a FIFO queue of buffers matching 1280 basically a FIFO queue of buffers matching
1282 the card ring */ 1281 the card ring */
1283 lp->net_stats.tx_bytes+=lp->tx_ring[t].skb->len; 1282 dev->stats.tx_bytes+=lp->tx_ring[t].skb->len;
1284 dev_kfree_skb_irq(lp->tx_ring[t].skb); 1283 dev_kfree_skb_irq(lp->tx_ring[t].skb);
1285 lp->tx_ring[t].skb=NULL; 1284 lp->tx_ring[t].skb=NULL;
1286 atomic_inc(&lp->tx_count); 1285 atomic_inc(&lp->tx_count);
@@ -1367,7 +1366,7 @@ static irqreturn_t mc32_interrupt(int irq, void *dev_id)
1367 case 6: 1366 case 6:
1368 /* Out of RX buffers stat */ 1367 /* Out of RX buffers stat */
1369 /* Must restart rx */ 1368 /* Must restart rx */
1370 lp->net_stats.rx_dropped++; 1369 dev->stats.rx_dropped++;
1371 mc32_rx_ring(dev); 1370 mc32_rx_ring(dev);
1372 mc32_start_transceiver(dev); 1371 mc32_start_transceiver(dev);
1373 break; 1372 break;
@@ -1489,10 +1488,8 @@ static int mc32_close(struct net_device *dev)
1489 1488
1490static struct net_device_stats *mc32_get_stats(struct net_device *dev) 1489static struct net_device_stats *mc32_get_stats(struct net_device *dev)
1491{ 1490{
1492 struct mc32_local *lp = netdev_priv(dev);
1493
1494 mc32_update_stats(dev); 1491 mc32_update_stats(dev);
1495 return &lp->net_stats; 1492 return &dev->stats;
1496} 1493}
1497 1494
1498 1495
diff --git a/drivers/net/8139cp.c b/drivers/net/8139cp.c
index a453eda834d5..934db350e339 100644
--- a/drivers/net/8139cp.c
+++ b/drivers/net/8139cp.c
@@ -340,7 +340,6 @@ struct cp_private {
340 u32 rx_config; 340 u32 rx_config;
341 u16 cpcmd; 341 u16 cpcmd;
342 342
343 struct net_device_stats net_stats;
344 struct cp_extra_stats cp_stats; 343 struct cp_extra_stats cp_stats;
345 344
346 unsigned rx_head ____cacheline_aligned; 345 unsigned rx_head ____cacheline_aligned;
@@ -457,8 +456,8 @@ static inline void cp_rx_skb (struct cp_private *cp, struct sk_buff *skb,
457{ 456{
458 skb->protocol = eth_type_trans (skb, cp->dev); 457 skb->protocol = eth_type_trans (skb, cp->dev);
459 458
460 cp->net_stats.rx_packets++; 459 cp->dev->stats.rx_packets++;
461 cp->net_stats.rx_bytes += skb->len; 460 cp->dev->stats.rx_bytes += skb->len;
462 cp->dev->last_rx = jiffies; 461 cp->dev->last_rx = jiffies;
463 462
464#if CP_VLAN_TAG_USED 463#if CP_VLAN_TAG_USED
@@ -477,17 +476,17 @@ static void cp_rx_err_acct (struct cp_private *cp, unsigned rx_tail,
477 printk (KERN_DEBUG 476 printk (KERN_DEBUG
478 "%s: rx err, slot %d status 0x%x len %d\n", 477 "%s: rx err, slot %d status 0x%x len %d\n",
479 cp->dev->name, rx_tail, status, len); 478 cp->dev->name, rx_tail, status, len);
480 cp->net_stats.rx_errors++; 479 cp->dev->stats.rx_errors++;
481 if (status & RxErrFrame) 480 if (status & RxErrFrame)
482 cp->net_stats.rx_frame_errors++; 481 cp->dev->stats.rx_frame_errors++;
483 if (status & RxErrCRC) 482 if (status & RxErrCRC)
484 cp->net_stats.rx_crc_errors++; 483 cp->dev->stats.rx_crc_errors++;
485 if ((status & RxErrRunt) || (status & RxErrLong)) 484 if ((status & RxErrRunt) || (status & RxErrLong))
486 cp->net_stats.rx_length_errors++; 485 cp->dev->stats.rx_length_errors++;
487 if ((status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag)) 486 if ((status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag))
488 cp->net_stats.rx_length_errors++; 487 cp->dev->stats.rx_length_errors++;
489 if (status & RxErrFIFO) 488 if (status & RxErrFIFO)
490 cp->net_stats.rx_fifo_errors++; 489 cp->dev->stats.rx_fifo_errors++;
491} 490}
492 491
493static inline unsigned int cp_rx_csum_ok (u32 status) 492static inline unsigned int cp_rx_csum_ok (u32 status)
@@ -539,7 +538,7 @@ rx_status_loop:
539 * that RX fragments are never encountered 538 * that RX fragments are never encountered
540 */ 539 */
541 cp_rx_err_acct(cp, rx_tail, status, len); 540 cp_rx_err_acct(cp, rx_tail, status, len);
542 cp->net_stats.rx_dropped++; 541 dev->stats.rx_dropped++;
543 cp->cp_stats.rx_frags++; 542 cp->cp_stats.rx_frags++;
544 goto rx_next; 543 goto rx_next;
545 } 544 }
@@ -556,7 +555,7 @@ rx_status_loop:
556 buflen = cp->rx_buf_sz + RX_OFFSET; 555 buflen = cp->rx_buf_sz + RX_OFFSET;
557 new_skb = dev_alloc_skb (buflen); 556 new_skb = dev_alloc_skb (buflen);
558 if (!new_skb) { 557 if (!new_skb) {
559 cp->net_stats.rx_dropped++; 558 dev->stats.rx_dropped++;
560 goto rx_next; 559 goto rx_next;
561 } 560 }
562 561
@@ -710,20 +709,20 @@ static void cp_tx (struct cp_private *cp)
710 if (netif_msg_tx_err(cp)) 709 if (netif_msg_tx_err(cp))
711 printk(KERN_DEBUG "%s: tx err, status 0x%x\n", 710 printk(KERN_DEBUG "%s: tx err, status 0x%x\n",
712 cp->dev->name, status); 711 cp->dev->name, status);
713 cp->net_stats.tx_errors++; 712 cp->dev->stats.tx_errors++;
714 if (status & TxOWC) 713 if (status & TxOWC)
715 cp->net_stats.tx_window_errors++; 714 cp->dev->stats.tx_window_errors++;
716 if (status & TxMaxCol) 715 if (status & TxMaxCol)
717 cp->net_stats.tx_aborted_errors++; 716 cp->dev->stats.tx_aborted_errors++;
718 if (status & TxLinkFail) 717 if (status & TxLinkFail)
719 cp->net_stats.tx_carrier_errors++; 718 cp->dev->stats.tx_carrier_errors++;
720 if (status & TxFIFOUnder) 719 if (status & TxFIFOUnder)
721 cp->net_stats.tx_fifo_errors++; 720 cp->dev->stats.tx_fifo_errors++;
722 } else { 721 } else {
723 cp->net_stats.collisions += 722 cp->dev->stats.collisions +=
724 ((status >> TxColCntShift) & TxColCntMask); 723 ((status >> TxColCntShift) & TxColCntMask);
725 cp->net_stats.tx_packets++; 724 cp->dev->stats.tx_packets++;
726 cp->net_stats.tx_bytes += skb->len; 725 cp->dev->stats.tx_bytes += skb->len;
727 if (netif_msg_tx_done(cp)) 726 if (netif_msg_tx_done(cp))
728 printk(KERN_DEBUG "%s: tx done, slot %d\n", cp->dev->name, tx_tail); 727 printk(KERN_DEBUG "%s: tx done, slot %d\n", cp->dev->name, tx_tail);
729 } 728 }
@@ -956,7 +955,7 @@ static void cp_set_rx_mode (struct net_device *dev)
956static void __cp_get_stats(struct cp_private *cp) 955static void __cp_get_stats(struct cp_private *cp)
957{ 956{
958 /* only lower 24 bits valid; write any value to clear */ 957 /* only lower 24 bits valid; write any value to clear */
959 cp->net_stats.rx_missed_errors += (cpr32 (RxMissed) & 0xffffff); 958 cp->dev->stats.rx_missed_errors += (cpr32 (RxMissed) & 0xffffff);
960 cpw32 (RxMissed, 0); 959 cpw32 (RxMissed, 0);
961} 960}
962 961
@@ -971,7 +970,7 @@ static struct net_device_stats *cp_get_stats(struct net_device *dev)
971 __cp_get_stats(cp); 970 __cp_get_stats(cp);
972 spin_unlock_irqrestore(&cp->lock, flags); 971 spin_unlock_irqrestore(&cp->lock, flags);
973 972
974 return &cp->net_stats; 973 return &dev->stats;
975} 974}
976 975
977static void cp_stop_hw (struct cp_private *cp) 976static void cp_stop_hw (struct cp_private *cp)
@@ -1142,7 +1141,7 @@ static void cp_clean_rings (struct cp_private *cp)
1142 PCI_DMA_TODEVICE); 1141 PCI_DMA_TODEVICE);
1143 if (le32_to_cpu(desc->opts1) & LastFrag) 1142 if (le32_to_cpu(desc->opts1) & LastFrag)
1144 dev_kfree_skb(skb); 1143 dev_kfree_skb(skb);
1145 cp->net_stats.tx_dropped++; 1144 cp->dev->stats.tx_dropped++;
1146 } 1145 }
1147 } 1146 }
1148 1147
diff --git a/drivers/net/8139too.c b/drivers/net/8139too.c
index 53bd903d2321..b23a00c5b84f 100644
--- a/drivers/net/8139too.c
+++ b/drivers/net/8139too.c
@@ -574,7 +574,6 @@ struct rtl8139_private {
574 u32 msg_enable; 574 u32 msg_enable;
575 struct napi_struct napi; 575 struct napi_struct napi;
576 struct net_device *dev; 576 struct net_device *dev;
577 struct net_device_stats stats;
578 577
579 unsigned char *rx_ring; 578 unsigned char *rx_ring;
580 unsigned int cur_rx; /* RX buf index of next pkt */ 579 unsigned int cur_rx; /* RX buf index of next pkt */
@@ -1711,7 +1710,7 @@ static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev)
1711 dev_kfree_skb(skb); 1710 dev_kfree_skb(skb);
1712 } else { 1711 } else {
1713 dev_kfree_skb(skb); 1712 dev_kfree_skb(skb);
1714 tp->stats.tx_dropped++; 1713 dev->stats.tx_dropped++;
1715 return 0; 1714 return 0;
1716 } 1715 }
1717 1716
@@ -1762,27 +1761,27 @@ static void rtl8139_tx_interrupt (struct net_device *dev,
1762 if (netif_msg_tx_err(tp)) 1761 if (netif_msg_tx_err(tp))
1763 printk(KERN_DEBUG "%s: Transmit error, Tx status %8.8x.\n", 1762 printk(KERN_DEBUG "%s: Transmit error, Tx status %8.8x.\n",
1764 dev->name, txstatus); 1763 dev->name, txstatus);
1765 tp->stats.tx_errors++; 1764 dev->stats.tx_errors++;
1766 if (txstatus & TxAborted) { 1765 if (txstatus & TxAborted) {
1767 tp->stats.tx_aborted_errors++; 1766 dev->stats.tx_aborted_errors++;
1768 RTL_W32 (TxConfig, TxClearAbt); 1767 RTL_W32 (TxConfig, TxClearAbt);
1769 RTL_W16 (IntrStatus, TxErr); 1768 RTL_W16 (IntrStatus, TxErr);
1770 wmb(); 1769 wmb();
1771 } 1770 }
1772 if (txstatus & TxCarrierLost) 1771 if (txstatus & TxCarrierLost)
1773 tp->stats.tx_carrier_errors++; 1772 dev->stats.tx_carrier_errors++;
1774 if (txstatus & TxOutOfWindow) 1773 if (txstatus & TxOutOfWindow)
1775 tp->stats.tx_window_errors++; 1774 dev->stats.tx_window_errors++;
1776 } else { 1775 } else {
1777 if (txstatus & TxUnderrun) { 1776 if (txstatus & TxUnderrun) {
1778 /* Add 64 to the Tx FIFO threshold. */ 1777 /* Add 64 to the Tx FIFO threshold. */
1779 if (tp->tx_flag < 0x00300000) 1778 if (tp->tx_flag < 0x00300000)
1780 tp->tx_flag += 0x00020000; 1779 tp->tx_flag += 0x00020000;
1781 tp->stats.tx_fifo_errors++; 1780 dev->stats.tx_fifo_errors++;
1782 } 1781 }
1783 tp->stats.collisions += (txstatus >> 24) & 15; 1782 dev->stats.collisions += (txstatus >> 24) & 15;
1784 tp->stats.tx_bytes += txstatus & 0x7ff; 1783 dev->stats.tx_bytes += txstatus & 0x7ff;
1785 tp->stats.tx_packets++; 1784 dev->stats.tx_packets++;
1786 } 1785 }
1787 1786
1788 dirty_tx++; 1787 dirty_tx++;
@@ -1818,7 +1817,7 @@ static void rtl8139_rx_err (u32 rx_status, struct net_device *dev,
1818 if (netif_msg_rx_err (tp)) 1817 if (netif_msg_rx_err (tp))
1819 printk(KERN_DEBUG "%s: Ethernet frame had errors, status %8.8x.\n", 1818 printk(KERN_DEBUG "%s: Ethernet frame had errors, status %8.8x.\n",
1820 dev->name, rx_status); 1819 dev->name, rx_status);
1821 tp->stats.rx_errors++; 1820 dev->stats.rx_errors++;
1822 if (!(rx_status & RxStatusOK)) { 1821 if (!(rx_status & RxStatusOK)) {
1823 if (rx_status & RxTooLong) { 1822 if (rx_status & RxTooLong) {
1824 DPRINTK ("%s: Oversized Ethernet frame, status %4.4x!\n", 1823 DPRINTK ("%s: Oversized Ethernet frame, status %4.4x!\n",
@@ -1826,11 +1825,11 @@ static void rtl8139_rx_err (u32 rx_status, struct net_device *dev,
1826 /* A.C.: The chip hangs here. */ 1825 /* A.C.: The chip hangs here. */
1827 } 1826 }
1828 if (rx_status & (RxBadSymbol | RxBadAlign)) 1827 if (rx_status & (RxBadSymbol | RxBadAlign))
1829 tp->stats.rx_frame_errors++; 1828 dev->stats.rx_frame_errors++;
1830 if (rx_status & (RxRunt | RxTooLong)) 1829 if (rx_status & (RxRunt | RxTooLong))
1831 tp->stats.rx_length_errors++; 1830 dev->stats.rx_length_errors++;
1832 if (rx_status & RxCRCErr) 1831 if (rx_status & RxCRCErr)
1833 tp->stats.rx_crc_errors++; 1832 dev->stats.rx_crc_errors++;
1834 } else { 1833 } else {
1835 tp->xstats.rx_lost_in_ring++; 1834 tp->xstats.rx_lost_in_ring++;
1836 } 1835 }
@@ -1913,9 +1912,9 @@ static void rtl8139_isr_ack(struct rtl8139_private *tp)
1913 /* Clear out errors and receive interrupts */ 1912 /* Clear out errors and receive interrupts */
1914 if (likely(status != 0)) { 1913 if (likely(status != 0)) {
1915 if (unlikely(status & (RxFIFOOver | RxOverflow))) { 1914 if (unlikely(status & (RxFIFOOver | RxOverflow))) {
1916 tp->stats.rx_errors++; 1915 tp->dev->stats.rx_errors++;
1917 if (status & RxFIFOOver) 1916 if (status & RxFIFOOver)
1918 tp->stats.rx_fifo_errors++; 1917 tp->dev->stats.rx_fifo_errors++;
1919 } 1918 }
1920 RTL_W16_F (IntrStatus, RxAckBits); 1919 RTL_W16_F (IntrStatus, RxAckBits);
1921 } 1920 }
@@ -2016,8 +2015,8 @@ no_early_rx:
2016 skb->protocol = eth_type_trans (skb, dev); 2015 skb->protocol = eth_type_trans (skb, dev);
2017 2016
2018 dev->last_rx = jiffies; 2017 dev->last_rx = jiffies;
2019 tp->stats.rx_bytes += pkt_size; 2018 dev->stats.rx_bytes += pkt_size;
2020 tp->stats.rx_packets++; 2019 dev->stats.rx_packets++;
2021 2020
2022 netif_receive_skb (skb); 2021 netif_receive_skb (skb);
2023 } else { 2022 } else {
@@ -2025,7 +2024,7 @@ no_early_rx:
2025 printk (KERN_WARNING 2024 printk (KERN_WARNING
2026 "%s: Memory squeeze, dropping packet.\n", 2025 "%s: Memory squeeze, dropping packet.\n",
2027 dev->name); 2026 dev->name);
2028 tp->stats.rx_dropped++; 2027 dev->stats.rx_dropped++;
2029 } 2028 }
2030 received++; 2029 received++;
2031 2030
@@ -2072,7 +2071,7 @@ static void rtl8139_weird_interrupt (struct net_device *dev,
2072 assert (ioaddr != NULL); 2071 assert (ioaddr != NULL);
2073 2072
2074 /* Update the error count. */ 2073 /* Update the error count. */
2075 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); 2074 dev->stats.rx_missed_errors += RTL_R32 (RxMissed);
2076 RTL_W32 (RxMissed, 0); 2075 RTL_W32 (RxMissed, 0);
2077 2076
2078 if ((status & RxUnderrun) && link_changed && 2077 if ((status & RxUnderrun) && link_changed &&
@@ -2082,12 +2081,12 @@ static void rtl8139_weird_interrupt (struct net_device *dev,
2082 } 2081 }
2083 2082
2084 if (status & (RxUnderrun | RxErr)) 2083 if (status & (RxUnderrun | RxErr))
2085 tp->stats.rx_errors++; 2084 dev->stats.rx_errors++;
2086 2085
2087 if (status & PCSTimeout) 2086 if (status & PCSTimeout)
2088 tp->stats.rx_length_errors++; 2087 dev->stats.rx_length_errors++;
2089 if (status & RxUnderrun) 2088 if (status & RxUnderrun)
2090 tp->stats.rx_fifo_errors++; 2089 dev->stats.rx_fifo_errors++;
2091 if (status & PCIErr) { 2090 if (status & PCIErr) {
2092 u16 pci_cmd_status; 2091 u16 pci_cmd_status;
2093 pci_read_config_word (tp->pci_dev, PCI_STATUS, &pci_cmd_status); 2092 pci_read_config_word (tp->pci_dev, PCI_STATUS, &pci_cmd_status);
@@ -2227,7 +2226,7 @@ static int rtl8139_close (struct net_device *dev)
2227 RTL_W16 (IntrMask, 0); 2226 RTL_W16 (IntrMask, 0);
2228 2227
2229 /* Update the error counts. */ 2228 /* Update the error counts. */
2230 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); 2229 dev->stats.rx_missed_errors += RTL_R32 (RxMissed);
2231 RTL_W32 (RxMissed, 0); 2230 RTL_W32 (RxMissed, 0);
2232 2231
2233 spin_unlock_irqrestore (&tp->lock, flags); 2232 spin_unlock_irqrestore (&tp->lock, flags);
@@ -2472,12 +2471,12 @@ static struct net_device_stats *rtl8139_get_stats (struct net_device *dev)
2472 2471
2473 if (netif_running(dev)) { 2472 if (netif_running(dev)) {
2474 spin_lock_irqsave (&tp->lock, flags); 2473 spin_lock_irqsave (&tp->lock, flags);
2475 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); 2474 dev->stats.rx_missed_errors += RTL_R32 (RxMissed);
2476 RTL_W32 (RxMissed, 0); 2475 RTL_W32 (RxMissed, 0);
2477 spin_unlock_irqrestore (&tp->lock, flags); 2476 spin_unlock_irqrestore (&tp->lock, flags);
2478 } 2477 }
2479 2478
2480 return &tp->stats; 2479 return &dev->stats;
2481} 2480}
2482 2481
2483/* Set or clear the multicast filter for this adaptor. 2482/* Set or clear the multicast filter for this adaptor.
@@ -2561,7 +2560,7 @@ static int rtl8139_suspend (struct pci_dev *pdev, pm_message_t state)
2561 RTL_W8 (ChipCmd, 0); 2560 RTL_W8 (ChipCmd, 0);
2562 2561
2563 /* Update the error counts. */ 2562 /* Update the error counts. */
2564 tp->stats.rx_missed_errors += RTL_R32 (RxMissed); 2563 dev->stats.rx_missed_errors += RTL_R32 (RxMissed);
2565 RTL_W32 (RxMissed, 0); 2564 RTL_W32 (RxMissed, 0);
2566 2565
2567 spin_unlock_irqrestore (&tp->lock, flags); 2566 spin_unlock_irqrestore (&tp->lock, flags);
diff --git a/drivers/net/8390.h b/drivers/net/8390.h
index 04ddec0f4c61..cf020d45aea6 100644
--- a/drivers/net/8390.h
+++ b/drivers/net/8390.h
@@ -69,7 +69,6 @@ struct ei_device {
69 unsigned char reg0; /* Register '0' in a WD8013 */ 69 unsigned char reg0; /* Register '0' in a WD8013 */
70 unsigned char reg5; /* Register '5' in a WD8013 */ 70 unsigned char reg5; /* Register '5' in a WD8013 */
71 unsigned char saved_irq; /* Original dev->irq value. */ 71 unsigned char saved_irq; /* Original dev->irq value. */
72 struct net_device_stats stat; /* The new statistics table. */
73 u32 *reg_offset; /* Register mapping table */ 72 u32 *reg_offset; /* Register mapping table */
74 spinlock_t page_lock; /* Page register locks */ 73 spinlock_t page_lock; /* Page register locks */
75 unsigned long priv; /* Private field to store bus IDs etc. */ 74 unsigned long priv; /* Private field to store bus IDs etc. */
diff --git a/drivers/net/acenic.c b/drivers/net/acenic.c
index 6c192650d349..e4483de84e7f 100644
--- a/drivers/net/acenic.c
+++ b/drivers/net/acenic.c
@@ -1457,11 +1457,6 @@ static int __devinit ace_init(struct net_device *dev)
1457 ace_set_txprd(regs, ap, 0); 1457 ace_set_txprd(regs, ap, 0);
1458 writel(0, &regs->RxRetCsm); 1458 writel(0, &regs->RxRetCsm);
1459 1459
1460 /*
1461 * Zero the stats before starting the interface
1462 */
1463 memset(&ap->stats, 0, sizeof(ap->stats));
1464
1465 /* 1460 /*
1466 * Enable DMA engine now. 1461 * Enable DMA engine now.
1467 * If we do this sooner, Mckinley box pukes. 1462 * If we do this sooner, Mckinley box pukes.
@@ -2041,8 +2036,8 @@ static void ace_rx_int(struct net_device *dev, u32 rxretprd, u32 rxretcsm)
2041 netif_rx(skb); 2036 netif_rx(skb);
2042 2037
2043 dev->last_rx = jiffies; 2038 dev->last_rx = jiffies;
2044 ap->stats.rx_packets++; 2039 dev->stats.rx_packets++;
2045 ap->stats.rx_bytes += retdesc->size; 2040 dev->stats.rx_bytes += retdesc->size;
2046 2041
2047 idx = (idx + 1) % RX_RETURN_RING_ENTRIES; 2042 idx = (idx + 1) % RX_RETURN_RING_ENTRIES;
2048 } 2043 }
@@ -2090,8 +2085,8 @@ static inline void ace_tx_int(struct net_device *dev,
2090 } 2085 }
2091 2086
2092 if (skb) { 2087 if (skb) {
2093 ap->stats.tx_packets++; 2088 dev->stats.tx_packets++;
2094 ap->stats.tx_bytes += skb->len; 2089 dev->stats.tx_bytes += skb->len;
2095 dev_kfree_skb_irq(skb); 2090 dev_kfree_skb_irq(skb);
2096 info->skb = NULL; 2091 info->skb = NULL;
2097 } 2092 }
@@ -2863,11 +2858,11 @@ static struct net_device_stats *ace_get_stats(struct net_device *dev)
2863 struct ace_mac_stats __iomem *mac_stats = 2858 struct ace_mac_stats __iomem *mac_stats =
2864 (struct ace_mac_stats __iomem *)ap->regs->Stats; 2859 (struct ace_mac_stats __iomem *)ap->regs->Stats;
2865 2860
2866 ap->stats.rx_missed_errors = readl(&mac_stats->drop_space); 2861 dev->stats.rx_missed_errors = readl(&mac_stats->drop_space);
2867 ap->stats.multicast = readl(&mac_stats->kept_mc); 2862 dev->stats.multicast = readl(&mac_stats->kept_mc);
2868 ap->stats.collisions = readl(&mac_stats->coll); 2863 dev->stats.collisions = readl(&mac_stats->coll);
2869 2864
2870 return &ap->stats; 2865 return &dev->stats;
2871} 2866}
2872 2867
2873 2868
diff --git a/drivers/net/acenic.h b/drivers/net/acenic.h
index 60ed1837fa8f..4487f32759a4 100644
--- a/drivers/net/acenic.h
+++ b/drivers/net/acenic.h
@@ -693,7 +693,6 @@ struct ace_private
693 __attribute__ ((aligned (SMP_CACHE_BYTES))); 693 __attribute__ ((aligned (SMP_CACHE_BYTES)));
694 u32 last_tx, last_std_rx, last_mini_rx; 694 u32 last_tx, last_std_rx, last_mini_rx;
695#endif 695#endif
696 struct net_device_stats stats;
697 int pci_using_dac; 696 int pci_using_dac;
698}; 697};
699 698
diff --git a/drivers/net/cpmac.c b/drivers/net/cpmac.c
index 2b5740b3d182..ae07100bb935 100644
--- a/drivers/net/cpmac.c
+++ b/drivers/net/cpmac.c
@@ -708,7 +708,7 @@ static void cpmac_tx_timeout(struct net_device *dev)
708 spin_unlock(&priv->lock); 708 spin_unlock(&priv->lock);
709 if (netif_msg_tx_err(priv) && net_ratelimit()) 709 if (netif_msg_tx_err(priv) && net_ratelimit())
710 printk(KERN_WARNING "%s: transmit timeout\n", dev->name); 710 printk(KERN_WARNING "%s: transmit timeout\n", dev->name);
711 /* 711 /*
712 * FIXME: waking up random queue is not the best thing to 712 * FIXME: waking up random queue is not the best thing to
713 * do... on the other hand why we got here at all? 713 * do... on the other hand why we got here at all?
714 */ 714 */
diff --git a/drivers/net/dm9000.c b/drivers/net/dm9000.c
index d45bcd2660af..32a9a922f153 100644
--- a/drivers/net/dm9000.c
+++ b/drivers/net/dm9000.c
@@ -718,7 +718,7 @@ dm9000_probe(struct platform_device *pdev)
718 718
719 if (!is_valid_ether_addr(ndev->dev_addr)) { 719 if (!is_valid_ether_addr(ndev->dev_addr)) {
720 /* try reading from mac */ 720 /* try reading from mac */
721 721
722 mac_src = "chip"; 722 mac_src = "chip";
723 for (i = 0; i < 6; i++) 723 for (i = 0; i < 6; i++)
724 ndev->dev_addr[i] = ior(db, i+DM9000_PAR); 724 ndev->dev_addr[i] = ior(db, i+DM9000_PAR);
@@ -768,7 +768,7 @@ dm9000_open(struct net_device *dev)
768 dev_warn(db->dev, "WARNING: no IRQ resource flags set.\n"); 768 dev_warn(db->dev, "WARNING: no IRQ resource flags set.\n");
769 irqflags = DEFAULT_TRIGGER; 769 irqflags = DEFAULT_TRIGGER;
770 } 770 }
771 771
772 irqflags |= IRQF_SHARED; 772 irqflags |= IRQF_SHARED;
773 773
774 if (request_irq(dev->irq, &dm9000_interrupt, irqflags, dev->name, dev)) 774 if (request_irq(dev->irq, &dm9000_interrupt, irqflags, dev->name, dev))
@@ -1115,7 +1115,7 @@ static int dm9000_wait_eeprom(board_info_t *db)
1115 /* The DM9000 data sheets say we should be able to 1115 /* The DM9000 data sheets say we should be able to
1116 * poll the ERRE bit in EPCR to wait for the EEPROM 1116 * poll the ERRE bit in EPCR to wait for the EEPROM
1117 * operation. From testing several chips, this bit 1117 * operation. From testing several chips, this bit
1118 * does not seem to work. 1118 * does not seem to work.
1119 * 1119 *
1120 * We attempt to use the bit, but fall back to the 1120 * We attempt to use the bit, but fall back to the
1121 * timeout (which is why we do not return an error 1121 * timeout (which is why we do not return an error
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index 25bdd0832df5..393a0f175302 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -928,7 +928,7 @@ rx_irq_fail:
928tx_irq_fail: 928tx_irq_fail:
929 free_irq(priv->interruptError, dev); 929 free_irq(priv->interruptError, dev);
930err_irq_fail: 930err_irq_fail:
931err_rxalloc_fail: 931err_rxalloc_fail:
932rx_skb_fail: 932rx_skb_fail:
933 free_skb_resources(priv); 933 free_skb_resources(priv);
934tx_skb_fail: 934tx_skb_fail:
diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
index 9d5721287d6f..06ad9f302b5a 100644
--- a/drivers/net/hamradio/6pack.c
+++ b/drivers/net/hamradio/6pack.c
@@ -99,9 +99,6 @@ struct sixpack {
99 unsigned int rx_count; 99 unsigned int rx_count;
100 unsigned int rx_count_cooked; 100 unsigned int rx_count_cooked;
101 101
102 /* 6pack interface statistics. */
103 struct net_device_stats stats;
104
105 int mtu; /* Our mtu (to spot changes!) */ 102 int mtu; /* Our mtu (to spot changes!) */
106 int buffsize; /* Max buffers sizes */ 103 int buffsize; /* Max buffers sizes */
107 104
@@ -237,7 +234,7 @@ static void sp_encaps(struct sixpack *sp, unsigned char *icp, int len)
237 return; 234 return;
238 235
239out_drop: 236out_drop:
240 sp->stats.tx_dropped++; 237 sp->dev->stats.tx_dropped++;
241 netif_start_queue(sp->dev); 238 netif_start_queue(sp->dev);
242 if (net_ratelimit()) 239 if (net_ratelimit())
243 printk(KERN_DEBUG "%s: %s - dropped.\n", sp->dev->name, msg); 240 printk(KERN_DEBUG "%s: %s - dropped.\n", sp->dev->name, msg);
@@ -252,7 +249,7 @@ static int sp_xmit(struct sk_buff *skb, struct net_device *dev)
252 spin_lock_bh(&sp->lock); 249 spin_lock_bh(&sp->lock);
253 /* We were not busy, so we are now... :-) */ 250 /* We were not busy, so we are now... :-) */
254 netif_stop_queue(dev); 251 netif_stop_queue(dev);
255 sp->stats.tx_bytes += skb->len; 252 dev->stats.tx_bytes += skb->len;
256 sp_encaps(sp, skb->data, skb->len); 253 sp_encaps(sp, skb->data, skb->len);
257 spin_unlock_bh(&sp->lock); 254 spin_unlock_bh(&sp->lock);
258 255
@@ -298,12 +295,6 @@ static int sp_header(struct sk_buff *skb, struct net_device *dev,
298 return 0; 295 return 0;
299} 296}
300 297
301static struct net_device_stats *sp_get_stats(struct net_device *dev)
302{
303 struct sixpack *sp = netdev_priv(dev);
304 return &sp->stats;
305}
306
307static int sp_set_mac_address(struct net_device *dev, void *addr) 298static int sp_set_mac_address(struct net_device *dev, void *addr)
308{ 299{
309 struct sockaddr_ax25 *sa = addr; 300 struct sockaddr_ax25 *sa = addr;
@@ -338,7 +329,6 @@ static void sp_setup(struct net_device *dev)
338 dev->destructor = free_netdev; 329 dev->destructor = free_netdev;
339 dev->stop = sp_close; 330 dev->stop = sp_close;
340 331
341 dev->get_stats = sp_get_stats;
342 dev->set_mac_address = sp_set_mac_address; 332 dev->set_mac_address = sp_set_mac_address;
343 dev->hard_header_len = AX25_MAX_HEADER_LEN; 333 dev->hard_header_len = AX25_MAX_HEADER_LEN;
344 dev->header_ops = &sp_header_ops; 334 dev->header_ops = &sp_header_ops;
@@ -370,7 +360,7 @@ static void sp_bump(struct sixpack *sp, char cmd)
370 360
371 count = sp->rcount + 1; 361 count = sp->rcount + 1;
372 362
373 sp->stats.rx_bytes += count; 363 sp->dev->stats.rx_bytes += count;
374 364
375 if ((skb = dev_alloc_skb(count)) == NULL) 365 if ((skb = dev_alloc_skb(count)) == NULL)
376 goto out_mem; 366 goto out_mem;
@@ -382,12 +372,12 @@ static void sp_bump(struct sixpack *sp, char cmd)
382 skb->protocol = ax25_type_trans(skb, sp->dev); 372 skb->protocol = ax25_type_trans(skb, sp->dev);
383 netif_rx(skb); 373 netif_rx(skb);
384 sp->dev->last_rx = jiffies; 374 sp->dev->last_rx = jiffies;
385 sp->stats.rx_packets++; 375 sp->dev->stats.rx_packets++;
386 376
387 return; 377 return;
388 378
389out_mem: 379out_mem:
390 sp->stats.rx_dropped++; 380 sp->dev->stats.rx_dropped++;
391} 381}
392 382
393 383
@@ -436,7 +426,7 @@ static void sixpack_write_wakeup(struct tty_struct *tty)
436 if (sp->xleft <= 0) { 426 if (sp->xleft <= 0) {
437 /* Now serial buffer is almost free & we can start 427 /* Now serial buffer is almost free & we can start
438 * transmission of another packet */ 428 * transmission of another packet */
439 sp->stats.tx_packets++; 429 sp->dev->stats.tx_packets++;
440 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 430 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
441 sp->tx_enable = 0; 431 sp->tx_enable = 0;
442 netif_wake_queue(sp->dev); 432 netif_wake_queue(sp->dev);
@@ -484,7 +474,7 @@ static void sixpack_receive_buf(struct tty_struct *tty,
484 count--; 474 count--;
485 if (fp && *fp++) { 475 if (fp && *fp++) {
486 if (!test_and_set_bit(SIXPF_ERROR, &sp->flags)) 476 if (!test_and_set_bit(SIXPF_ERROR, &sp->flags))
487 sp->stats.rx_errors++; 477 sp->dev->stats.rx_errors++;
488 continue; 478 continue;
489 } 479 }
490 } 480 }
diff --git a/drivers/net/lib8390.c b/drivers/net/lib8390.c
index 0c5447dac03b..ed495275b577 100644
--- a/drivers/net/lib8390.c
+++ b/drivers/net/lib8390.c
@@ -150,19 +150,19 @@ static void __NS8390_init(struct net_device *dev, int startp);
150 * card means that approach caused horrible problems like losing serial data 150 * card means that approach caused horrible problems like losing serial data
151 * at 38400 baud on some chips. Remember many 8390 nics on PCI were ISA 151 * at 38400 baud on some chips. Remember many 8390 nics on PCI were ISA
152 * chips with FPGA front ends. 152 * chips with FPGA front ends.
153 * 153 *
154 * Ok the logic behind the 8390 is very simple: 154 * Ok the logic behind the 8390 is very simple:
155 * 155 *
156 * Things to know 156 * Things to know
157 * - IRQ delivery is asynchronous to the PCI bus 157 * - IRQ delivery is asynchronous to the PCI bus
158 * - Blocking the local CPU IRQ via spin locks was too slow 158 * - Blocking the local CPU IRQ via spin locks was too slow
159 * - The chip has register windows needing locking work 159 * - The chip has register windows needing locking work
160 * 160 *
161 * So the path was once (I say once as people appear to have changed it 161 * So the path was once (I say once as people appear to have changed it
162 * in the mean time and it now looks rather bogus if the changes to use 162 * in the mean time and it now looks rather bogus if the changes to use
163 * disable_irq_nosync_irqsave are disabling the local IRQ) 163 * disable_irq_nosync_irqsave are disabling the local IRQ)
164 * 164 *
165 * 165 *
166 * Take the page lock 166 * Take the page lock
167 * Mask the IRQ on chip 167 * Mask the IRQ on chip
168 * Disable the IRQ (but not mask locally- someone seems to have 168 * Disable the IRQ (but not mask locally- someone seems to have
@@ -170,22 +170,22 @@ static void __NS8390_init(struct net_device *dev, int startp);
170 * [This must be _nosync as the page lock may otherwise 170 * [This must be _nosync as the page lock may otherwise
171 * deadlock us] 171 * deadlock us]
172 * Drop the page lock and turn IRQs back on 172 * Drop the page lock and turn IRQs back on
173 * 173 *
174 * At this point an existing IRQ may still be running but we can't 174 * At this point an existing IRQ may still be running but we can't
175 * get a new one 175 * get a new one
176 * 176 *
177 * Take the lock (so we know the IRQ has terminated) but don't mask 177 * Take the lock (so we know the IRQ has terminated) but don't mask
178 * the IRQs on the processor 178 * the IRQs on the processor
179 * Set irqlock [for debug] 179 * Set irqlock [for debug]
180 * 180 *
181 * Transmit (slow as ****) 181 * Transmit (slow as ****)
182 * 182 *
183 * re-enable the IRQ 183 * re-enable the IRQ
184 * 184 *
185 * 185 *
186 * We have to use disable_irq because otherwise you will get delayed 186 * We have to use disable_irq because otherwise you will get delayed
187 * interrupts on the APIC bus deadlocking the transmit path. 187 * interrupts on the APIC bus deadlocking the transmit path.
188 * 188 *
189 * Quite hairy but the chip simply wasn't designed for SMP and you can't 189 * Quite hairy but the chip simply wasn't designed for SMP and you can't
190 * even ACK an interrupt without risking corrupting other parallel 190 * even ACK an interrupt without risking corrupting other parallel
191 * activities on the chip." [lkml, 25 Jul 2007] 191 * activities on the chip." [lkml, 25 Jul 2007]
@@ -265,7 +265,7 @@ static void ei_tx_timeout(struct net_device *dev)
265 int txsr, isr, tickssofar = jiffies - dev->trans_start; 265 int txsr, isr, tickssofar = jiffies - dev->trans_start;
266 unsigned long flags; 266 unsigned long flags;
267 267
268 ei_local->stat.tx_errors++; 268 dev->stats.tx_errors++;
269 269
270 spin_lock_irqsave(&ei_local->page_lock, flags); 270 spin_lock_irqsave(&ei_local->page_lock, flags);
271 txsr = ei_inb(e8390_base+EN0_TSR); 271 txsr = ei_inb(e8390_base+EN0_TSR);
@@ -276,7 +276,7 @@ static void ei_tx_timeout(struct net_device *dev)
276 dev->name, (txsr & ENTSR_ABT) ? "excess collisions." : 276 dev->name, (txsr & ENTSR_ABT) ? "excess collisions." :
277 (isr) ? "lost interrupt?" : "cable problem?", txsr, isr, tickssofar); 277 (isr) ? "lost interrupt?" : "cable problem?", txsr, isr, tickssofar);
278 278
279 if (!isr && !ei_local->stat.tx_packets) 279 if (!isr && !dev->stats.tx_packets)
280 { 280 {
281 /* The 8390 probably hasn't gotten on the cable yet. */ 281 /* The 8390 probably hasn't gotten on the cable yet. */
282 ei_local->interface_num ^= 1; /* Try a different xcvr. */ 282 ei_local->interface_num ^= 1; /* Try a different xcvr. */
@@ -374,7 +374,7 @@ static int ei_start_xmit(struct sk_buff *skb, struct net_device *dev)
374 ei_outb_p(ENISR_ALL, e8390_base + EN0_IMR); 374 ei_outb_p(ENISR_ALL, e8390_base + EN0_IMR);
375 spin_unlock(&ei_local->page_lock); 375 spin_unlock(&ei_local->page_lock);
376 enable_irq_lockdep_irqrestore(dev->irq, &flags); 376 enable_irq_lockdep_irqrestore(dev->irq, &flags);
377 ei_local->stat.tx_errors++; 377 dev->stats.tx_errors++;
378 return 1; 378 return 1;
379 } 379 }
380 380
@@ -417,7 +417,7 @@ static int ei_start_xmit(struct sk_buff *skb, struct net_device *dev)
417 enable_irq_lockdep_irqrestore(dev->irq, &flags); 417 enable_irq_lockdep_irqrestore(dev->irq, &flags);
418 418
419 dev_kfree_skb (skb); 419 dev_kfree_skb (skb);
420 ei_local->stat.tx_bytes += send_length; 420 dev->stats.tx_bytes += send_length;
421 421
422 return 0; 422 return 0;
423} 423}
@@ -493,9 +493,9 @@ static irqreturn_t __ei_interrupt(int irq, void *dev_id)
493 493
494 if (interrupts & ENISR_COUNTERS) 494 if (interrupts & ENISR_COUNTERS)
495 { 495 {
496 ei_local->stat.rx_frame_errors += ei_inb_p(e8390_base + EN0_COUNTER0); 496 dev->stats.rx_frame_errors += ei_inb_p(e8390_base + EN0_COUNTER0);
497 ei_local->stat.rx_crc_errors += ei_inb_p(e8390_base + EN0_COUNTER1); 497 dev->stats.rx_crc_errors += ei_inb_p(e8390_base + EN0_COUNTER1);
498 ei_local->stat.rx_missed_errors+= ei_inb_p(e8390_base + EN0_COUNTER2); 498 dev->stats.rx_missed_errors+= ei_inb_p(e8390_base + EN0_COUNTER2);
499 ei_outb_p(ENISR_COUNTERS, e8390_base + EN0_ISR); /* Ack intr. */ 499 ei_outb_p(ENISR_COUNTERS, e8390_base + EN0_ISR); /* Ack intr. */
500 } 500 }
501 501
@@ -553,7 +553,6 @@ static void __ei_poll(struct net_device *dev)
553static void ei_tx_err(struct net_device *dev) 553static void ei_tx_err(struct net_device *dev)
554{ 554{
555 unsigned long e8390_base = dev->base_addr; 555 unsigned long e8390_base = dev->base_addr;
556 struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
557 unsigned char txsr = ei_inb_p(e8390_base+EN0_TSR); 556 unsigned char txsr = ei_inb_p(e8390_base+EN0_TSR);
558 unsigned char tx_was_aborted = txsr & (ENTSR_ABT+ENTSR_FU); 557 unsigned char tx_was_aborted = txsr & (ENTSR_ABT+ENTSR_FU);
559 558
@@ -578,10 +577,10 @@ static void ei_tx_err(struct net_device *dev)
578 ei_tx_intr(dev); 577 ei_tx_intr(dev);
579 else 578 else
580 { 579 {
581 ei_local->stat.tx_errors++; 580 dev->stats.tx_errors++;
582 if (txsr & ENTSR_CRS) ei_local->stat.tx_carrier_errors++; 581 if (txsr & ENTSR_CRS) dev->stats.tx_carrier_errors++;
583 if (txsr & ENTSR_CDH) ei_local->stat.tx_heartbeat_errors++; 582 if (txsr & ENTSR_CDH) dev->stats.tx_heartbeat_errors++;
584 if (txsr & ENTSR_OWC) ei_local->stat.tx_window_errors++; 583 if (txsr & ENTSR_OWC) dev->stats.tx_window_errors++;
585 } 584 }
586} 585}
587 586
@@ -645,25 +644,25 @@ static void ei_tx_intr(struct net_device *dev)
645 644
646 /* Minimize Tx latency: update the statistics after we restart TXing. */ 645 /* Minimize Tx latency: update the statistics after we restart TXing. */
647 if (status & ENTSR_COL) 646 if (status & ENTSR_COL)
648 ei_local->stat.collisions++; 647 dev->stats.collisions++;
649 if (status & ENTSR_PTX) 648 if (status & ENTSR_PTX)
650 ei_local->stat.tx_packets++; 649 dev->stats.tx_packets++;
651 else 650 else
652 { 651 {
653 ei_local->stat.tx_errors++; 652 dev->stats.tx_errors++;
654 if (status & ENTSR_ABT) 653 if (status & ENTSR_ABT)
655 { 654 {
656 ei_local->stat.tx_aborted_errors++; 655 dev->stats.tx_aborted_errors++;
657 ei_local->stat.collisions += 16; 656 dev->stats.collisions += 16;
658 } 657 }
659 if (status & ENTSR_CRS) 658 if (status & ENTSR_CRS)
660 ei_local->stat.tx_carrier_errors++; 659 dev->stats.tx_carrier_errors++;
661 if (status & ENTSR_FU) 660 if (status & ENTSR_FU)
662 ei_local->stat.tx_fifo_errors++; 661 dev->stats.tx_fifo_errors++;
663 if (status & ENTSR_CDH) 662 if (status & ENTSR_CDH)
664 ei_local->stat.tx_heartbeat_errors++; 663 dev->stats.tx_heartbeat_errors++;
665 if (status & ENTSR_OWC) 664 if (status & ENTSR_OWC)
666 ei_local->stat.tx_window_errors++; 665 dev->stats.tx_window_errors++;
667 } 666 }
668 netif_wake_queue(dev); 667 netif_wake_queue(dev);
669} 668}
@@ -730,7 +729,7 @@ static void ei_receive(struct net_device *dev)
730 && rx_frame.next != next_frame + 1 - num_rx_pages) { 729 && rx_frame.next != next_frame + 1 - num_rx_pages) {
731 ei_local->current_page = rxing_page; 730 ei_local->current_page = rxing_page;
732 ei_outb(ei_local->current_page-1, e8390_base+EN0_BOUNDARY); 731 ei_outb(ei_local->current_page-1, e8390_base+EN0_BOUNDARY);
733 ei_local->stat.rx_errors++; 732 dev->stats.rx_errors++;
734 continue; 733 continue;
735 } 734 }
736 735
@@ -740,8 +739,8 @@ static void ei_receive(struct net_device *dev)
740 printk(KERN_DEBUG "%s: bogus packet size: %d, status=%#2x nxpg=%#2x.\n", 739 printk(KERN_DEBUG "%s: bogus packet size: %d, status=%#2x nxpg=%#2x.\n",
741 dev->name, rx_frame.count, rx_frame.status, 740 dev->name, rx_frame.count, rx_frame.status,
742 rx_frame.next); 741 rx_frame.next);
743 ei_local->stat.rx_errors++; 742 dev->stats.rx_errors++;
744 ei_local->stat.rx_length_errors++; 743 dev->stats.rx_length_errors++;
745 } 744 }
746 else if ((pkt_stat & 0x0F) == ENRSR_RXOK) 745 else if ((pkt_stat & 0x0F) == ENRSR_RXOK)
747 { 746 {
@@ -753,7 +752,7 @@ static void ei_receive(struct net_device *dev)
753 if (ei_debug > 1) 752 if (ei_debug > 1)
754 printk(KERN_DEBUG "%s: Couldn't allocate a sk_buff of size %d.\n", 753 printk(KERN_DEBUG "%s: Couldn't allocate a sk_buff of size %d.\n",
755 dev->name, pkt_len); 754 dev->name, pkt_len);
756 ei_local->stat.rx_dropped++; 755 dev->stats.rx_dropped++;
757 break; 756 break;
758 } 757 }
759 else 758 else
@@ -764,10 +763,10 @@ static void ei_receive(struct net_device *dev)
764 skb->protocol=eth_type_trans(skb,dev); 763 skb->protocol=eth_type_trans(skb,dev);
765 netif_rx(skb); 764 netif_rx(skb);
766 dev->last_rx = jiffies; 765 dev->last_rx = jiffies;
767 ei_local->stat.rx_packets++; 766 dev->stats.rx_packets++;
768 ei_local->stat.rx_bytes += pkt_len; 767 dev->stats.rx_bytes += pkt_len;
769 if (pkt_stat & ENRSR_PHY) 768 if (pkt_stat & ENRSR_PHY)
770 ei_local->stat.multicast++; 769 dev->stats.multicast++;
771 } 770 }
772 } 771 }
773 else 772 else
@@ -776,10 +775,10 @@ static void ei_receive(struct net_device *dev)
776 printk(KERN_DEBUG "%s: bogus packet: status=%#2x nxpg=%#2x size=%d\n", 775 printk(KERN_DEBUG "%s: bogus packet: status=%#2x nxpg=%#2x size=%d\n",
777 dev->name, rx_frame.status, rx_frame.next, 776 dev->name, rx_frame.status, rx_frame.next,
778 rx_frame.count); 777 rx_frame.count);
779 ei_local->stat.rx_errors++; 778 dev->stats.rx_errors++;
780 /* NB: The NIC counts CRC, frame and missed errors. */ 779 /* NB: The NIC counts CRC, frame and missed errors. */
781 if (pkt_stat & ENRSR_FO) 780 if (pkt_stat & ENRSR_FO)
782 ei_local->stat.rx_fifo_errors++; 781 dev->stats.rx_fifo_errors++;
783 } 782 }
784 next_frame = rx_frame.next; 783 next_frame = rx_frame.next;
785 784
@@ -816,7 +815,6 @@ static void ei_rx_overrun(struct net_device *dev)
816{ 815{
817 unsigned long e8390_base = dev->base_addr; 816 unsigned long e8390_base = dev->base_addr;
818 unsigned char was_txing, must_resend = 0; 817 unsigned char was_txing, must_resend = 0;
819 struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
820 818
821 /* 819 /*
822 * Record whether a Tx was in progress and then issue the 820 * Record whether a Tx was in progress and then issue the
@@ -827,7 +825,7 @@ static void ei_rx_overrun(struct net_device *dev)
827 825
828 if (ei_debug > 1) 826 if (ei_debug > 1)
829 printk(KERN_DEBUG "%s: Receiver overrun.\n", dev->name); 827 printk(KERN_DEBUG "%s: Receiver overrun.\n", dev->name);
830 ei_local->stat.rx_over_errors++; 828 dev->stats.rx_over_errors++;
831 829
832 /* 830 /*
833 * Wait a full Tx time (1.2ms) + some guard time, NS says 1.6ms total. 831 * Wait a full Tx time (1.2ms) + some guard time, NS says 1.6ms total.
@@ -889,16 +887,16 @@ static struct net_device_stats *get_stats(struct net_device *dev)
889 887
890 /* If the card is stopped, just return the present stats. */ 888 /* If the card is stopped, just return the present stats. */
891 if (!netif_running(dev)) 889 if (!netif_running(dev))
892 return &ei_local->stat; 890 return &dev->stats;
893 891
894 spin_lock_irqsave(&ei_local->page_lock,flags); 892 spin_lock_irqsave(&ei_local->page_lock,flags);
895 /* Read the counter registers, assuming we are in page 0. */ 893 /* Read the counter registers, assuming we are in page 0. */
896 ei_local->stat.rx_frame_errors += ei_inb_p(ioaddr + EN0_COUNTER0); 894 dev->stats.rx_frame_errors += ei_inb_p(ioaddr + EN0_COUNTER0);
897 ei_local->stat.rx_crc_errors += ei_inb_p(ioaddr + EN0_COUNTER1); 895 dev->stats.rx_crc_errors += ei_inb_p(ioaddr + EN0_COUNTER1);
898 ei_local->stat.rx_missed_errors+= ei_inb_p(ioaddr + EN0_COUNTER2); 896 dev->stats.rx_missed_errors+= ei_inb_p(ioaddr + EN0_COUNTER2);
899 spin_unlock_irqrestore(&ei_local->page_lock, flags); 897 spin_unlock_irqrestore(&ei_local->page_lock, flags);
900 898
901 return &ei_local->stat; 899 return &dev->stats;
902} 900}
903 901
904/* 902/*
diff --git a/drivers/net/natsemi.c b/drivers/net/natsemi.c
index 46119bb3770a..b238ed0e8ace 100644
--- a/drivers/net/natsemi.c
+++ b/drivers/net/natsemi.c
@@ -664,7 +664,7 @@ static ssize_t natsemi_show_##_name(struct device *dev, \
664NATSEMI_ATTR(dspcfg_workaround); 664NATSEMI_ATTR(dspcfg_workaround);
665 665
666static ssize_t natsemi_show_dspcfg_workaround(struct device *dev, 666static ssize_t natsemi_show_dspcfg_workaround(struct device *dev,
667 struct device_attribute *attr, 667 struct device_attribute *attr,
668 char *buf) 668 char *buf)
669{ 669{
670 struct netdev_private *np = netdev_priv(to_net_dev(dev)); 670 struct netdev_private *np = netdev_priv(to_net_dev(dev));
@@ -687,7 +687,7 @@ static ssize_t natsemi_set_dspcfg_workaround(struct device *dev,
687 || !strncmp("0", buf, count - 1)) 687 || !strncmp("0", buf, count - 1))
688 new_setting = 0; 688 new_setting = 0;
689 else 689 else
690 return count; 690 return count;
691 691
692 spin_lock_irqsave(&np->lock, flags); 692 spin_lock_irqsave(&np->lock, flags);
693 693
diff --git a/drivers/net/niu.h b/drivers/net/niu.h
index 12fd570b9423..c6fa883daa22 100644
--- a/drivers/net/niu.h
+++ b/drivers/net/niu.h
@@ -281,7 +281,7 @@
281#define XMAC_ADDR1 0x000a8UL 281#define XMAC_ADDR1 0x000a8UL
282#define XMAC_ADDR1_ADDR1 0x000000000000ffffULL 282#define XMAC_ADDR1_ADDR1 0x000000000000ffffULL
283 283
284#define XMAC_ADDR2 0x000b0UL 284#define XMAC_ADDR2 0x000b0UL
285#define XMAC_ADDR2_ADDR2 0x000000000000ffffULL 285#define XMAC_ADDR2_ADDR2 0x000000000000ffffULL
286 286
287#define XMAC_ADDR_CMPEN 0x00208UL 287#define XMAC_ADDR_CMPEN 0x00208UL
diff --git a/drivers/net/pcmcia/3c574_cs.c b/drivers/net/pcmcia/3c574_cs.c
index 3b78a3819bb3..7112fd5e0e1b 100644
--- a/drivers/net/pcmcia/3c574_cs.c
+++ b/drivers/net/pcmcia/3c574_cs.c
@@ -208,7 +208,6 @@ enum Window4 { /* Window 4: Xcvr/media bits. */
208struct el3_private { 208struct el3_private {
209 struct pcmcia_device *p_dev; 209 struct pcmcia_device *p_dev;
210 dev_node_t node; 210 dev_node_t node;
211 struct net_device_stats stats;
212 u16 advertising, partner; /* NWay media advertisement */ 211 u16 advertising, partner; /* NWay media advertisement */
213 unsigned char phys; /* MII device address */ 212 unsigned char phys; /* MII device address */
214 unsigned int autoselect:1, default_media:3; /* Read from the EEPROM/Wn3_Config. */ 213 unsigned int autoselect:1, default_media:3; /* Read from the EEPROM/Wn3_Config. */
@@ -741,12 +740,11 @@ static int el3_open(struct net_device *dev)
741 740
742static void el3_tx_timeout(struct net_device *dev) 741static void el3_tx_timeout(struct net_device *dev)
743{ 742{
744 struct el3_private *lp = netdev_priv(dev);
745 unsigned int ioaddr = dev->base_addr; 743 unsigned int ioaddr = dev->base_addr;
746 744
747 printk(KERN_NOTICE "%s: Transmit timed out!\n", dev->name); 745 printk(KERN_NOTICE "%s: Transmit timed out!\n", dev->name);
748 dump_status(dev); 746 dump_status(dev);
749 lp->stats.tx_errors++; 747 dev->stats.tx_errors++;
750 dev->trans_start = jiffies; 748 dev->trans_start = jiffies;
751 /* Issue TX_RESET and TX_START commands. */ 749 /* Issue TX_RESET and TX_START commands. */
752 tc574_wait_for_completion(dev, TxReset); 750 tc574_wait_for_completion(dev, TxReset);
@@ -756,7 +754,6 @@ static void el3_tx_timeout(struct net_device *dev)
756 754
757static void pop_tx_status(struct net_device *dev) 755static void pop_tx_status(struct net_device *dev)
758{ 756{
759 struct el3_private *lp = netdev_priv(dev);
760 unsigned int ioaddr = dev->base_addr; 757 unsigned int ioaddr = dev->base_addr;
761 int i; 758 int i;
762 759
@@ -772,7 +769,7 @@ static void pop_tx_status(struct net_device *dev)
772 DEBUG(1, "%s: transmit error: status 0x%02x\n", 769 DEBUG(1, "%s: transmit error: status 0x%02x\n",
773 dev->name, tx_status); 770 dev->name, tx_status);
774 outw(TxEnable, ioaddr + EL3_CMD); 771 outw(TxEnable, ioaddr + EL3_CMD);
775 lp->stats.tx_aborted_errors++; 772 dev->stats.tx_aborted_errors++;
776 } 773 }
777 outb(0x00, ioaddr + TxStatus); /* Pop the status stack. */ 774 outb(0x00, ioaddr + TxStatus); /* Pop the status stack. */
778 } 775 }
@@ -987,7 +984,7 @@ static struct net_device_stats *el3_get_stats(struct net_device *dev)
987 update_stats(dev); 984 update_stats(dev);
988 spin_unlock_irqrestore(&lp->window_lock, flags); 985 spin_unlock_irqrestore(&lp->window_lock, flags);
989 } 986 }
990 return &lp->stats; 987 return &dev->stats;
991} 988}
992 989
993/* Update statistics. 990/* Update statistics.
@@ -996,7 +993,6 @@ static struct net_device_stats *el3_get_stats(struct net_device *dev)
996 */ 993 */
997static void update_stats(struct net_device *dev) 994static void update_stats(struct net_device *dev)
998{ 995{
999 struct el3_private *lp = netdev_priv(dev);
1000 unsigned int ioaddr = dev->base_addr; 996 unsigned int ioaddr = dev->base_addr;
1001 u8 rx, tx, up; 997 u8 rx, tx, up;
1002 998
@@ -1008,15 +1004,15 @@ static void update_stats(struct net_device *dev)
1008 /* Unlike the 3c509 we need not turn off stats updates while reading. */ 1004 /* Unlike the 3c509 we need not turn off stats updates while reading. */
1009 /* Switch to the stats window, and read everything. */ 1005 /* Switch to the stats window, and read everything. */
1010 EL3WINDOW(6); 1006 EL3WINDOW(6);
1011 lp->stats.tx_carrier_errors += inb(ioaddr + 0); 1007 dev->stats.tx_carrier_errors += inb(ioaddr + 0);
1012 lp->stats.tx_heartbeat_errors += inb(ioaddr + 1); 1008 dev->stats.tx_heartbeat_errors += inb(ioaddr + 1);
1013 /* Multiple collisions. */ inb(ioaddr + 2); 1009 /* Multiple collisions. */ inb(ioaddr + 2);
1014 lp->stats.collisions += inb(ioaddr + 3); 1010 dev->stats.collisions += inb(ioaddr + 3);
1015 lp->stats.tx_window_errors += inb(ioaddr + 4); 1011 dev->stats.tx_window_errors += inb(ioaddr + 4);
1016 lp->stats.rx_fifo_errors += inb(ioaddr + 5); 1012 dev->stats.rx_fifo_errors += inb(ioaddr + 5);
1017 lp->stats.tx_packets += inb(ioaddr + 6); 1013 dev->stats.tx_packets += inb(ioaddr + 6);
1018 up = inb(ioaddr + 9); 1014 up = inb(ioaddr + 9);
1019 lp->stats.tx_packets += (up&0x30) << 4; 1015 dev->stats.tx_packets += (up&0x30) << 4;
1020 /* Rx packets */ inb(ioaddr + 7); 1016 /* Rx packets */ inb(ioaddr + 7);
1021 /* Tx deferrals */ inb(ioaddr + 8); 1017 /* Tx deferrals */ inb(ioaddr + 8);
1022 rx = inw(ioaddr + 10); 1018 rx = inw(ioaddr + 10);
@@ -1026,14 +1022,13 @@ static void update_stats(struct net_device *dev)
1026 /* BadSSD */ inb(ioaddr + 12); 1022 /* BadSSD */ inb(ioaddr + 12);
1027 up = inb(ioaddr + 13); 1023 up = inb(ioaddr + 13);
1028 1024
1029 lp->stats.tx_bytes += tx + ((up & 0xf0) << 12); 1025 dev->stats.tx_bytes += tx + ((up & 0xf0) << 12);
1030 1026
1031 EL3WINDOW(1); 1027 EL3WINDOW(1);
1032} 1028}
1033 1029
1034static int el3_rx(struct net_device *dev, int worklimit) 1030static int el3_rx(struct net_device *dev, int worklimit)
1035{ 1031{
1036 struct el3_private *lp = netdev_priv(dev);
1037 unsigned int ioaddr = dev->base_addr; 1032 unsigned int ioaddr = dev->base_addr;
1038 short rx_status; 1033 short rx_status;
1039 1034
@@ -1043,14 +1038,14 @@ static int el3_rx(struct net_device *dev, int worklimit)
1043 (--worklimit >= 0)) { 1038 (--worklimit >= 0)) {
1044 if (rx_status & 0x4000) { /* Error, update stats. */ 1039 if (rx_status & 0x4000) { /* Error, update stats. */
1045 short error = rx_status & 0x3800; 1040 short error = rx_status & 0x3800;
1046 lp->stats.rx_errors++; 1041 dev->stats.rx_errors++;
1047 switch (error) { 1042 switch (error) {
1048 case 0x0000: lp->stats.rx_over_errors++; break; 1043 case 0x0000: dev->stats.rx_over_errors++; break;
1049 case 0x0800: lp->stats.rx_length_errors++; break; 1044 case 0x0800: dev->stats.rx_length_errors++; break;
1050 case 0x1000: lp->stats.rx_frame_errors++; break; 1045 case 0x1000: dev->stats.rx_frame_errors++; break;
1051 case 0x1800: lp->stats.rx_length_errors++; break; 1046 case 0x1800: dev->stats.rx_length_errors++; break;
1052 case 0x2000: lp->stats.rx_frame_errors++; break; 1047 case 0x2000: dev->stats.rx_frame_errors++; break;
1053 case 0x2800: lp->stats.rx_crc_errors++; break; 1048 case 0x2800: dev->stats.rx_crc_errors++; break;
1054 } 1049 }
1055 } else { 1050 } else {
1056 short pkt_len = rx_status & 0x7ff; 1051 short pkt_len = rx_status & 0x7ff;
@@ -1067,12 +1062,12 @@ static int el3_rx(struct net_device *dev, int worklimit)
1067 skb->protocol = eth_type_trans(skb, dev); 1062 skb->protocol = eth_type_trans(skb, dev);
1068 netif_rx(skb); 1063 netif_rx(skb);
1069 dev->last_rx = jiffies; 1064 dev->last_rx = jiffies;
1070 lp->stats.rx_packets++; 1065 dev->stats.rx_packets++;
1071 lp->stats.rx_bytes += pkt_len; 1066 dev->stats.rx_bytes += pkt_len;
1072 } else { 1067 } else {
1073 DEBUG(1, "%s: couldn't allocate a sk_buff of" 1068 DEBUG(1, "%s: couldn't allocate a sk_buff of"
1074 " size %d.\n", dev->name, pkt_len); 1069 " size %d.\n", dev->name, pkt_len);
1075 lp->stats.rx_dropped++; 1070 dev->stats.rx_dropped++;
1076 } 1071 }
1077 } 1072 }
1078 tc574_wait_for_completion(dev, RxDiscard); 1073 tc574_wait_for_completion(dev, RxDiscard);
diff --git a/drivers/net/pcmcia/3c589_cs.c b/drivers/net/pcmcia/3c589_cs.c
index 1b1abb19c911..549a64558420 100644
--- a/drivers/net/pcmcia/3c589_cs.c
+++ b/drivers/net/pcmcia/3c589_cs.c
@@ -107,7 +107,6 @@ enum RxFilter {
107struct el3_private { 107struct el3_private {
108 struct pcmcia_device *p_dev; 108 struct pcmcia_device *p_dev;
109 dev_node_t node; 109 dev_node_t node;
110 struct net_device_stats stats;
111 /* For transceiver monitoring */ 110 /* For transceiver monitoring */
112 struct timer_list media; 111 struct timer_list media;
113 u16 media_status; 112 u16 media_status;
@@ -566,12 +565,11 @@ static int el3_open(struct net_device *dev)
566 565
567static void el3_tx_timeout(struct net_device *dev) 566static void el3_tx_timeout(struct net_device *dev)
568{ 567{
569 struct el3_private *lp = netdev_priv(dev);
570 unsigned int ioaddr = dev->base_addr; 568 unsigned int ioaddr = dev->base_addr;
571 569
572 printk(KERN_WARNING "%s: Transmit timed out!\n", dev->name); 570 printk(KERN_WARNING "%s: Transmit timed out!\n", dev->name);
573 dump_status(dev); 571 dump_status(dev);
574 lp->stats.tx_errors++; 572 dev->stats.tx_errors++;
575 dev->trans_start = jiffies; 573 dev->trans_start = jiffies;
576 /* Issue TX_RESET and TX_START commands. */ 574 /* Issue TX_RESET and TX_START commands. */
577 tc589_wait_for_completion(dev, TxReset); 575 tc589_wait_for_completion(dev, TxReset);
@@ -581,7 +579,6 @@ static void el3_tx_timeout(struct net_device *dev)
581 579
582static void pop_tx_status(struct net_device *dev) 580static void pop_tx_status(struct net_device *dev)
583{ 581{
584 struct el3_private *lp = netdev_priv(dev);
585 unsigned int ioaddr = dev->base_addr; 582 unsigned int ioaddr = dev->base_addr;
586 int i; 583 int i;
587 584
@@ -596,7 +593,7 @@ static void pop_tx_status(struct net_device *dev)
596 DEBUG(1, "%s: transmit error: status 0x%02x\n", 593 DEBUG(1, "%s: transmit error: status 0x%02x\n",
597 dev->name, tx_status); 594 dev->name, tx_status);
598 outw(TxEnable, ioaddr + EL3_CMD); 595 outw(TxEnable, ioaddr + EL3_CMD);
599 lp->stats.tx_aborted_errors++; 596 dev->stats.tx_aborted_errors++;
600 } 597 }
601 outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */ 598 outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */
602 } 599 }
@@ -614,7 +611,7 @@ static int el3_start_xmit(struct sk_buff *skb, struct net_device *dev)
614 611
615 spin_lock_irqsave(&priv->lock, flags); 612 spin_lock_irqsave(&priv->lock, flags);
616 613
617 priv->stats.tx_bytes += skb->len; 614 dev->stats.tx_bytes += skb->len;
618 615
619 /* Put out the doubleword header... */ 616 /* Put out the doubleword header... */
620 outw(skb->len, ioaddr + TX_FIFO); 617 outw(skb->len, ioaddr + TX_FIFO);
@@ -764,7 +761,7 @@ static void media_check(unsigned long arg)
764 outw(StatsDisable, ioaddr + EL3_CMD); 761 outw(StatsDisable, ioaddr + EL3_CMD);
765 errs = inb(ioaddr + 0); 762 errs = inb(ioaddr + 0);
766 outw(StatsEnable, ioaddr + EL3_CMD); 763 outw(StatsEnable, ioaddr + EL3_CMD);
767 lp->stats.tx_carrier_errors += errs; 764 dev->stats.tx_carrier_errors += errs;
768 if (errs || (lp->media_status & 0x0010)) media |= 0x0010; 765 if (errs || (lp->media_status & 0x0010)) media |= 0x0010;
769 } 766 }
770 767
@@ -814,7 +811,7 @@ static struct net_device_stats *el3_get_stats(struct net_device *dev)
814 update_stats(dev); 811 update_stats(dev);
815 spin_unlock_irqrestore(&lp->lock, flags); 812 spin_unlock_irqrestore(&lp->lock, flags);
816 } 813 }
817 return &lp->stats; 814 return &dev->stats;
818} 815}
819 816
820/* 817/*
@@ -827,7 +824,6 @@ static struct net_device_stats *el3_get_stats(struct net_device *dev)
827*/ 824*/
828static void update_stats(struct net_device *dev) 825static void update_stats(struct net_device *dev)
829{ 826{
830 struct el3_private *lp = netdev_priv(dev);
831 unsigned int ioaddr = dev->base_addr; 827 unsigned int ioaddr = dev->base_addr;
832 828
833 DEBUG(2, "%s: updating the statistics.\n", dev->name); 829 DEBUG(2, "%s: updating the statistics.\n", dev->name);
@@ -835,13 +831,13 @@ static void update_stats(struct net_device *dev)
835 outw(StatsDisable, ioaddr + EL3_CMD); 831 outw(StatsDisable, ioaddr + EL3_CMD);
836 /* Switch to the stats window, and read everything. */ 832 /* Switch to the stats window, and read everything. */
837 EL3WINDOW(6); 833 EL3WINDOW(6);
838 lp->stats.tx_carrier_errors += inb(ioaddr + 0); 834 dev->stats.tx_carrier_errors += inb(ioaddr + 0);
839 lp->stats.tx_heartbeat_errors += inb(ioaddr + 1); 835 dev->stats.tx_heartbeat_errors += inb(ioaddr + 1);
840 /* Multiple collisions. */ inb(ioaddr + 2); 836 /* Multiple collisions. */ inb(ioaddr + 2);
841 lp->stats.collisions += inb(ioaddr + 3); 837 dev->stats.collisions += inb(ioaddr + 3);
842 lp->stats.tx_window_errors += inb(ioaddr + 4); 838 dev->stats.tx_window_errors += inb(ioaddr + 4);
843 lp->stats.rx_fifo_errors += inb(ioaddr + 5); 839 dev->stats.rx_fifo_errors += inb(ioaddr + 5);
844 lp->stats.tx_packets += inb(ioaddr + 6); 840 dev->stats.tx_packets += inb(ioaddr + 6);
845 /* Rx packets */ inb(ioaddr + 7); 841 /* Rx packets */ inb(ioaddr + 7);
846 /* Tx deferrals */ inb(ioaddr + 8); 842 /* Tx deferrals */ inb(ioaddr + 8);
847 /* Rx octets */ inw(ioaddr + 10); 843 /* Rx octets */ inw(ioaddr + 10);
@@ -854,7 +850,6 @@ static void update_stats(struct net_device *dev)
854 850
855static int el3_rx(struct net_device *dev) 851static int el3_rx(struct net_device *dev)
856{ 852{
857 struct el3_private *lp = netdev_priv(dev);
858 unsigned int ioaddr = dev->base_addr; 853 unsigned int ioaddr = dev->base_addr;
859 int worklimit = 32; 854 int worklimit = 32;
860 short rx_status; 855 short rx_status;
@@ -865,14 +860,14 @@ static int el3_rx(struct net_device *dev)
865 (--worklimit >= 0)) { 860 (--worklimit >= 0)) {
866 if (rx_status & 0x4000) { /* Error, update stats. */ 861 if (rx_status & 0x4000) { /* Error, update stats. */
867 short error = rx_status & 0x3800; 862 short error = rx_status & 0x3800;
868 lp->stats.rx_errors++; 863 dev->stats.rx_errors++;
869 switch (error) { 864 switch (error) {
870 case 0x0000: lp->stats.rx_over_errors++; break; 865 case 0x0000: dev->stats.rx_over_errors++; break;
871 case 0x0800: lp->stats.rx_length_errors++; break; 866 case 0x0800: dev->stats.rx_length_errors++; break;
872 case 0x1000: lp->stats.rx_frame_errors++; break; 867 case 0x1000: dev->stats.rx_frame_errors++; break;
873 case 0x1800: lp->stats.rx_length_errors++; break; 868 case 0x1800: dev->stats.rx_length_errors++; break;
874 case 0x2000: lp->stats.rx_frame_errors++; break; 869 case 0x2000: dev->stats.rx_frame_errors++; break;
875 case 0x2800: lp->stats.rx_crc_errors++; break; 870 case 0x2800: dev->stats.rx_crc_errors++; break;
876 } 871 }
877 } else { 872 } else {
878 short pkt_len = rx_status & 0x7ff; 873 short pkt_len = rx_status & 0x7ff;
@@ -889,12 +884,12 @@ static int el3_rx(struct net_device *dev)
889 skb->protocol = eth_type_trans(skb, dev); 884 skb->protocol = eth_type_trans(skb, dev);
890 netif_rx(skb); 885 netif_rx(skb);
891 dev->last_rx = jiffies; 886 dev->last_rx = jiffies;
892 lp->stats.rx_packets++; 887 dev->stats.rx_packets++;
893 lp->stats.rx_bytes += pkt_len; 888 dev->stats.rx_bytes += pkt_len;
894 } else { 889 } else {
895 DEBUG(1, "%s: couldn't allocate a sk_buff of" 890 DEBUG(1, "%s: couldn't allocate a sk_buff of"
896 " size %d.\n", dev->name, pkt_len); 891 " size %d.\n", dev->name, pkt_len);
897 lp->stats.rx_dropped++; 892 dev->stats.rx_dropped++;
898 } 893 }
899 } 894 }
900 /* Pop the top of the Rx FIFO */ 895 /* Pop the top of the Rx FIFO */
@@ -929,7 +924,7 @@ static int el3_close(struct net_device *dev)
929 DEBUG(1, "%s: shutting down ethercard.\n", dev->name); 924 DEBUG(1, "%s: shutting down ethercard.\n", dev->name);
930 925
931 if (pcmcia_dev_present(link)) { 926 if (pcmcia_dev_present(link)) {
932 /* Turn off statistics ASAP. We update lp->stats below. */ 927 /* Turn off statistics ASAP. We update dev->stats below. */
933 outw(StatsDisable, ioaddr + EL3_CMD); 928 outw(StatsDisable, ioaddr + EL3_CMD);
934 929
935 /* Disable the receiver and transmitter. */ 930 /* Disable the receiver and transmitter. */
diff --git a/drivers/net/pcmcia/axnet_cs.c b/drivers/net/pcmcia/axnet_cs.c
index ce95c5d168fe..d7018ff9e171 100644
--- a/drivers/net/pcmcia/axnet_cs.c
+++ b/drivers/net/pcmcia/axnet_cs.c
@@ -1021,7 +1021,7 @@ static void ei_tx_timeout(struct net_device *dev)
1021 int txsr, isr, tickssofar = jiffies - dev->trans_start; 1021 int txsr, isr, tickssofar = jiffies - dev->trans_start;
1022 unsigned long flags; 1022 unsigned long flags;
1023 1023
1024 ei_local->stat.tx_errors++; 1024 dev->stats.tx_errors++;
1025 1025
1026 spin_lock_irqsave(&ei_local->page_lock, flags); 1026 spin_lock_irqsave(&ei_local->page_lock, flags);
1027 txsr = inb(e8390_base+EN0_TSR); 1027 txsr = inb(e8390_base+EN0_TSR);
@@ -1032,7 +1032,7 @@ static void ei_tx_timeout(struct net_device *dev)
1032 dev->name, (txsr & ENTSR_ABT) ? "excess collisions." : 1032 dev->name, (txsr & ENTSR_ABT) ? "excess collisions." :
1033 (isr) ? "lost interrupt?" : "cable problem?", txsr, isr, tickssofar); 1033 (isr) ? "lost interrupt?" : "cable problem?", txsr, isr, tickssofar);
1034 1034
1035 if (!isr && !ei_local->stat.tx_packets) 1035 if (!isr && !dev->stats.tx_packets)
1036 { 1036 {
1037 /* The 8390 probably hasn't gotten on the cable yet. */ 1037 /* The 8390 probably hasn't gotten on the cable yet. */
1038 ei_local->interface_num ^= 1; /* Try a different xcvr. */ 1038 ei_local->interface_num ^= 1; /* Try a different xcvr. */
@@ -1122,7 +1122,7 @@ static int ei_start_xmit(struct sk_buff *skb, struct net_device *dev)
1122 netif_stop_queue(dev); 1122 netif_stop_queue(dev);
1123 outb_p(ENISR_ALL, e8390_base + EN0_IMR); 1123 outb_p(ENISR_ALL, e8390_base + EN0_IMR);
1124 spin_unlock_irqrestore(&ei_local->page_lock, flags); 1124 spin_unlock_irqrestore(&ei_local->page_lock, flags);
1125 ei_local->stat.tx_errors++; 1125 dev->stats.tx_errors++;
1126 return 1; 1126 return 1;
1127 } 1127 }
1128 1128
@@ -1170,7 +1170,7 @@ static int ei_start_xmit(struct sk_buff *skb, struct net_device *dev)
1170 spin_unlock_irqrestore(&ei_local->page_lock, flags); 1170 spin_unlock_irqrestore(&ei_local->page_lock, flags);
1171 1171
1172 dev_kfree_skb (skb); 1172 dev_kfree_skb (skb);
1173 ei_local->stat.tx_bytes += send_length; 1173 dev->stats.tx_bytes += send_length;
1174 1174
1175 return 0; 1175 return 0;
1176} 1176}
@@ -1262,9 +1262,9 @@ static irqreturn_t ax_interrupt(int irq, void *dev_id)
1262 1262
1263 if (interrupts & ENISR_COUNTERS) 1263 if (interrupts & ENISR_COUNTERS)
1264 { 1264 {
1265 ei_local->stat.rx_frame_errors += inb_p(e8390_base + EN0_COUNTER0); 1265 dev->stats.rx_frame_errors += inb_p(e8390_base + EN0_COUNTER0);
1266 ei_local->stat.rx_crc_errors += inb_p(e8390_base + EN0_COUNTER1); 1266 dev->stats.rx_crc_errors += inb_p(e8390_base + EN0_COUNTER1);
1267 ei_local->stat.rx_missed_errors+= inb_p(e8390_base + EN0_COUNTER2); 1267 dev->stats.rx_missed_errors+= inb_p(e8390_base + EN0_COUNTER2);
1268 } 1268 }
1269 } 1269 }
1270 1270
@@ -1309,7 +1309,6 @@ static irqreturn_t ax_interrupt(int irq, void *dev_id)
1309static void ei_tx_err(struct net_device *dev) 1309static void ei_tx_err(struct net_device *dev)
1310{ 1310{
1311 long e8390_base = dev->base_addr; 1311 long e8390_base = dev->base_addr;
1312 struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
1313 unsigned char txsr = inb_p(e8390_base+EN0_TSR); 1312 unsigned char txsr = inb_p(e8390_base+EN0_TSR);
1314 unsigned char tx_was_aborted = txsr & (ENTSR_ABT+ENTSR_FU); 1313 unsigned char tx_was_aborted = txsr & (ENTSR_ABT+ENTSR_FU);
1315 1314
@@ -1332,10 +1331,10 @@ static void ei_tx_err(struct net_device *dev)
1332 ei_tx_intr(dev); 1331 ei_tx_intr(dev);
1333 else 1332 else
1334 { 1333 {
1335 ei_local->stat.tx_errors++; 1334 dev->stats.tx_errors++;
1336 if (txsr & ENTSR_CRS) ei_local->stat.tx_carrier_errors++; 1335 if (txsr & ENTSR_CRS) dev->stats.tx_carrier_errors++;
1337 if (txsr & ENTSR_CDH) ei_local->stat.tx_heartbeat_errors++; 1336 if (txsr & ENTSR_CDH) dev->stats.tx_heartbeat_errors++;
1338 if (txsr & ENTSR_OWC) ei_local->stat.tx_window_errors++; 1337 if (txsr & ENTSR_OWC) dev->stats.tx_window_errors++;
1339 } 1338 }
1340} 1339}
1341 1340
@@ -1397,25 +1396,25 @@ static void ei_tx_intr(struct net_device *dev)
1397 1396
1398 /* Minimize Tx latency: update the statistics after we restart TXing. */ 1397 /* Minimize Tx latency: update the statistics after we restart TXing. */
1399 if (status & ENTSR_COL) 1398 if (status & ENTSR_COL)
1400 ei_local->stat.collisions++; 1399 dev->stats.collisions++;
1401 if (status & ENTSR_PTX) 1400 if (status & ENTSR_PTX)
1402 ei_local->stat.tx_packets++; 1401 dev->stats.tx_packets++;
1403 else 1402 else
1404 { 1403 {
1405 ei_local->stat.tx_errors++; 1404 dev->stats.tx_errors++;
1406 if (status & ENTSR_ABT) 1405 if (status & ENTSR_ABT)
1407 { 1406 {
1408 ei_local->stat.tx_aborted_errors++; 1407 dev->stats.tx_aborted_errors++;
1409 ei_local->stat.collisions += 16; 1408 dev->stats.collisions += 16;
1410 } 1409 }
1411 if (status & ENTSR_CRS) 1410 if (status & ENTSR_CRS)
1412 ei_local->stat.tx_carrier_errors++; 1411 dev->stats.tx_carrier_errors++;
1413 if (status & ENTSR_FU) 1412 if (status & ENTSR_FU)
1414 ei_local->stat.tx_fifo_errors++; 1413 dev->stats.tx_fifo_errors++;
1415 if (status & ENTSR_CDH) 1414 if (status & ENTSR_CDH)
1416 ei_local->stat.tx_heartbeat_errors++; 1415 dev->stats.tx_heartbeat_errors++;
1417 if (status & ENTSR_OWC) 1416 if (status & ENTSR_OWC)
1418 ei_local->stat.tx_window_errors++; 1417 dev->stats.tx_window_errors++;
1419 } 1418 }
1420 netif_wake_queue(dev); 1419 netif_wake_queue(dev);
1421} 1420}
@@ -1476,8 +1475,8 @@ static void ei_receive(struct net_device *dev)
1476 printk(KERN_DEBUG "%s: bogus packet size: %d, status=%#2x nxpg=%#2x.\n", 1475 printk(KERN_DEBUG "%s: bogus packet size: %d, status=%#2x nxpg=%#2x.\n",
1477 dev->name, rx_frame.count, rx_frame.status, 1476 dev->name, rx_frame.count, rx_frame.status,
1478 rx_frame.next); 1477 rx_frame.next);
1479 ei_local->stat.rx_errors++; 1478 dev->stats.rx_errors++;
1480 ei_local->stat.rx_length_errors++; 1479 dev->stats.rx_length_errors++;
1481 } 1480 }
1482 else if ((pkt_stat & 0x0F) == ENRSR_RXOK) 1481 else if ((pkt_stat & 0x0F) == ENRSR_RXOK)
1483 { 1482 {
@@ -1489,7 +1488,7 @@ static void ei_receive(struct net_device *dev)
1489 if (ei_debug > 1) 1488 if (ei_debug > 1)
1490 printk(KERN_DEBUG "%s: Couldn't allocate a sk_buff of size %d.\n", 1489 printk(KERN_DEBUG "%s: Couldn't allocate a sk_buff of size %d.\n",
1491 dev->name, pkt_len); 1490 dev->name, pkt_len);
1492 ei_local->stat.rx_dropped++; 1491 dev->stats.rx_dropped++;
1493 break; 1492 break;
1494 } 1493 }
1495 else 1494 else
@@ -1500,10 +1499,10 @@ static void ei_receive(struct net_device *dev)
1500 skb->protocol=eth_type_trans(skb,dev); 1499 skb->protocol=eth_type_trans(skb,dev);
1501 netif_rx(skb); 1500 netif_rx(skb);
1502 dev->last_rx = jiffies; 1501 dev->last_rx = jiffies;
1503 ei_local->stat.rx_packets++; 1502 dev->stats.rx_packets++;
1504 ei_local->stat.rx_bytes += pkt_len; 1503 dev->stats.rx_bytes += pkt_len;
1505 if (pkt_stat & ENRSR_PHY) 1504 if (pkt_stat & ENRSR_PHY)
1506 ei_local->stat.multicast++; 1505 dev->stats.multicast++;
1507 } 1506 }
1508 } 1507 }
1509 else 1508 else
@@ -1512,10 +1511,10 @@ static void ei_receive(struct net_device *dev)
1512 printk(KERN_DEBUG "%s: bogus packet: status=%#2x nxpg=%#2x size=%d\n", 1511 printk(KERN_DEBUG "%s: bogus packet: status=%#2x nxpg=%#2x size=%d\n",
1513 dev->name, rx_frame.status, rx_frame.next, 1512 dev->name, rx_frame.status, rx_frame.next,
1514 rx_frame.count); 1513 rx_frame.count);
1515 ei_local->stat.rx_errors++; 1514 dev->stats.rx_errors++;
1516 /* NB: The NIC counts CRC, frame and missed errors. */ 1515 /* NB: The NIC counts CRC, frame and missed errors. */
1517 if (pkt_stat & ENRSR_FO) 1516 if (pkt_stat & ENRSR_FO)
1518 ei_local->stat.rx_fifo_errors++; 1517 dev->stats.rx_fifo_errors++;
1519 } 1518 }
1520 next_frame = rx_frame.next; 1519 next_frame = rx_frame.next;
1521 1520
@@ -1550,7 +1549,6 @@ static void ei_rx_overrun(struct net_device *dev)
1550 axnet_dev_t *info = PRIV(dev); 1549 axnet_dev_t *info = PRIV(dev);
1551 long e8390_base = dev->base_addr; 1550 long e8390_base = dev->base_addr;
1552 unsigned char was_txing, must_resend = 0; 1551 unsigned char was_txing, must_resend = 0;
1553 struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
1554 1552
1555 /* 1553 /*
1556 * Record whether a Tx was in progress and then issue the 1554 * Record whether a Tx was in progress and then issue the
@@ -1561,7 +1559,7 @@ static void ei_rx_overrun(struct net_device *dev)
1561 1559
1562 if (ei_debug > 1) 1560 if (ei_debug > 1)
1563 printk(KERN_DEBUG "%s: Receiver overrun.\n", dev->name); 1561 printk(KERN_DEBUG "%s: Receiver overrun.\n", dev->name);
1564 ei_local->stat.rx_over_errors++; 1562 dev->stats.rx_over_errors++;
1565 1563
1566 /* 1564 /*
1567 * Wait a full Tx time (1.2ms) + some guard time, NS says 1.6ms total. 1565 * Wait a full Tx time (1.2ms) + some guard time, NS says 1.6ms total.
@@ -1622,16 +1620,16 @@ static struct net_device_stats *get_stats(struct net_device *dev)
1622 1620
1623 /* If the card is stopped, just return the present stats. */ 1621 /* If the card is stopped, just return the present stats. */
1624 if (!netif_running(dev)) 1622 if (!netif_running(dev))
1625 return &ei_local->stat; 1623 return &dev->stats;
1626 1624
1627 spin_lock_irqsave(&ei_local->page_lock,flags); 1625 spin_lock_irqsave(&ei_local->page_lock,flags);
1628 /* Read the counter registers, assuming we are in page 0. */ 1626 /* Read the counter registers, assuming we are in page 0. */
1629 ei_local->stat.rx_frame_errors += inb_p(ioaddr + EN0_COUNTER0); 1627 dev->stats.rx_frame_errors += inb_p(ioaddr + EN0_COUNTER0);
1630 ei_local->stat.rx_crc_errors += inb_p(ioaddr + EN0_COUNTER1); 1628 dev->stats.rx_crc_errors += inb_p(ioaddr + EN0_COUNTER1);
1631 ei_local->stat.rx_missed_errors+= inb_p(ioaddr + EN0_COUNTER2); 1629 dev->stats.rx_missed_errors+= inb_p(ioaddr + EN0_COUNTER2);
1632 spin_unlock_irqrestore(&ei_local->page_lock, flags); 1630 spin_unlock_irqrestore(&ei_local->page_lock, flags);
1633 1631
1634 return &ei_local->stat; 1632 return &dev->stats;
1635} 1633}
1636 1634
1637/* 1635/*
diff --git a/drivers/net/pcnet32.c b/drivers/net/pcnet32.c
index a1c454dbc164..81fd85214b98 100644
--- a/drivers/net/pcnet32.c
+++ b/drivers/net/pcnet32.c
@@ -1973,7 +1973,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
1973 err_free_ring: 1973 err_free_ring:
1974 pcnet32_free_ring(dev); 1974 pcnet32_free_ring(dev);
1975 err_free_consistent: 1975 err_free_consistent:
1976 pci_free_consistent(lp->pci_dev, sizeof(*lp->init_block), 1976 pci_free_consistent(lp->pci_dev, sizeof(*lp->init_block),
1977 lp->init_block, lp->init_dma_addr); 1977 lp->init_block, lp->init_dma_addr);
1978 err_free_netdev: 1978 err_free_netdev:
1979 free_netdev(dev); 1979 free_netdev(dev);
@@ -2953,7 +2953,7 @@ static void __devexit pcnet32_remove_one(struct pci_dev *pdev)
2953 unregister_netdev(dev); 2953 unregister_netdev(dev);
2954 pcnet32_free_ring(dev); 2954 pcnet32_free_ring(dev);
2955 release_region(dev->base_addr, PCNET32_TOTAL_SIZE); 2955 release_region(dev->base_addr, PCNET32_TOTAL_SIZE);
2956 pci_free_consistent(lp->pci_dev, sizeof(*lp->init_block), 2956 pci_free_consistent(lp->pci_dev, sizeof(*lp->init_block),
2957 lp->init_block, lp->init_dma_addr); 2957 lp->init_block, lp->init_dma_addr);
2958 free_netdev(dev); 2958 free_netdev(dev);
2959 pci_disable_device(pdev); 2959 pci_disable_device(pdev);
@@ -3036,7 +3036,7 @@ static void __exit pcnet32_cleanup_module(void)
3036 unregister_netdev(pcnet32_dev); 3036 unregister_netdev(pcnet32_dev);
3037 pcnet32_free_ring(pcnet32_dev); 3037 pcnet32_free_ring(pcnet32_dev);
3038 release_region(pcnet32_dev->base_addr, PCNET32_TOTAL_SIZE); 3038 release_region(pcnet32_dev->base_addr, PCNET32_TOTAL_SIZE);
3039 pci_free_consistent(lp->pci_dev, sizeof(*lp->init_block), 3039 pci_free_consistent(lp->pci_dev, sizeof(*lp->init_block),
3040 lp->init_block, lp->init_dma_addr); 3040 lp->init_block, lp->init_dma_addr);
3041 free_netdev(pcnet32_dev); 3041 free_netdev(pcnet32_dev);
3042 pcnet32_dev = next_dev; 3042 pcnet32_dev = next_dev;
diff --git a/drivers/net/qla3xxx.c b/drivers/net/qla3xxx.c
index b7f7b2227d56..5f608780c3e8 100644
--- a/drivers/net/qla3xxx.c
+++ b/drivers/net/qla3xxx.c
@@ -1437,9 +1437,9 @@ static void ql_phy_start_neg_ex(struct ql3_adapter *qdev)
1437 reg &= ~PHY_GIG_ALL_PARAMS; 1437 reg &= ~PHY_GIG_ALL_PARAMS;
1438 1438
1439 if(portConfiguration & PORT_CONFIG_1000MB_SPEED) { 1439 if(portConfiguration & PORT_CONFIG_1000MB_SPEED) {
1440 if(portConfiguration & PORT_CONFIG_FULL_DUPLEX_ENABLED) 1440 if(portConfiguration & PORT_CONFIG_FULL_DUPLEX_ENABLED)
1441 reg |= PHY_GIG_ADV_1000F; 1441 reg |= PHY_GIG_ADV_1000F;
1442 else 1442 else
1443 reg |= PHY_GIG_ADV_1000H; 1443 reg |= PHY_GIG_ADV_1000H;
1444 } 1444 }
1445 1445
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c
index 523478ebfd69..75bde6475832 100644
--- a/drivers/net/s2io.c
+++ b/drivers/net/s2io.c
@@ -2547,7 +2547,7 @@ static int fill_rx_buffers(struct ring_info *ring)
2547 if (block_no) 2547 if (block_no)
2548 rxd_index += (block_no * ring->rxd_count); 2548 rxd_index += (block_no * ring->rxd_count);
2549 2549
2550 if ((block_no == block_no1) && 2550 if ((block_no == block_no1) &&
2551 (off == ring->rx_curr_get_info.offset) && 2551 (off == ring->rx_curr_get_info.offset) &&
2552 (rxdp->Host_Control)) { 2552 (rxdp->Host_Control)) {
2553 DBG_PRINT(INTR_DBG, "%s: Get and Put", 2553 DBG_PRINT(INTR_DBG, "%s: Get and Put",
@@ -2593,7 +2593,7 @@ static int fill_rx_buffers(struct ring_info *ring)
2593 first_rxdp->Control_1 |= RXD_OWN_XENA; 2593 first_rxdp->Control_1 |= RXD_OWN_XENA;
2594 } 2594 }
2595 stats->mem_alloc_fail_cnt++; 2595 stats->mem_alloc_fail_cnt++;
2596 2596
2597 return -ENOMEM ; 2597 return -ENOMEM ;
2598 } 2598 }
2599 stats->mem_allocated += skb->truesize; 2599 stats->mem_allocated += skb->truesize;
diff --git a/drivers/net/s2io.h b/drivers/net/s2io.h
index 0709ebae9139..58229dcbf5ec 100644
--- a/drivers/net/s2io.h
+++ b/drivers/net/s2io.h
@@ -747,7 +747,7 @@ struct ring_info {
747 747
748 /* interface MTU value */ 748 /* interface MTU value */
749 unsigned mtu; 749 unsigned mtu;
750 750
751 /* Buffer Address store. */ 751 /* Buffer Address store. */
752 struct buffAdd **ba; 752 struct buffAdd **ba;
753 753
diff --git a/drivers/net/sb1250-mac.c b/drivers/net/sb1250-mac.c
index 888b7dec9866..295199025173 100644
--- a/drivers/net/sb1250-mac.c
+++ b/drivers/net/sb1250-mac.c
@@ -1063,7 +1063,7 @@ static void sbmac_netpoll(struct net_device *netdev)
1063 ((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_RX_CH0), 1063 ((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_RX_CH0),
1064 sc->sbm_imr); 1064 sc->sbm_imr);
1065#else 1065#else
1066 __raw_writeq((M_MAC_INT_CHANNEL << S_MAC_TX_CH0) | 1066 __raw_writeq((M_MAC_INT_CHANNEL << S_MAC_TX_CH0) |
1067 (M_MAC_INT_CHANNEL << S_MAC_RX_CH0), sc->sbm_imr); 1067 (M_MAC_INT_CHANNEL << S_MAC_RX_CH0), sc->sbm_imr);
1068#endif 1068#endif
1069} 1069}
diff --git a/drivers/net/sis190.c b/drivers/net/sis190.c
index abc63b0663be..3fe01763760e 100644
--- a/drivers/net/sis190.c
+++ b/drivers/net/sis190.c
@@ -1656,7 +1656,7 @@ static inline void sis190_init_rxfilter(struct net_device *dev)
1656 SIS_PCI_COMMIT(); 1656 SIS_PCI_COMMIT();
1657} 1657}
1658 1658
1659static int __devinit sis190_get_mac_addr(struct pci_dev *pdev, 1659static int __devinit sis190_get_mac_addr(struct pci_dev *pdev,
1660 struct net_device *dev) 1660 struct net_device *dev)
1661{ 1661{
1662 int rc; 1662 int rc;
diff --git a/drivers/net/sis900.c b/drivers/net/sis900.c
index ec95e493ac1c..fa3a460f8e2f 100644
--- a/drivers/net/sis900.c
+++ b/drivers/net/sis900.c
@@ -1766,7 +1766,7 @@ static int sis900_rx(struct net_device *net_dev)
1766 skb = sis_priv->rx_skbuff[entry]; 1766 skb = sis_priv->rx_skbuff[entry];
1767 net_dev->stats.rx_dropped++; 1767 net_dev->stats.rx_dropped++;
1768 goto refill_rx_ring; 1768 goto refill_rx_ring;
1769 } 1769 }
1770 1770
1771 /* This situation should never happen, but due to 1771 /* This situation should never happen, but due to
1772 some unknow bugs, it is possible that 1772 some unknow bugs, it is possible that
diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c
index f226bcac7d17..4b0f03358777 100644
--- a/drivers/net/sky2.c
+++ b/drivers/net/sky2.c
@@ -3369,7 +3369,7 @@ static void sky2_led(struct sky2_port *sky2, enum led_mode mode)
3369 3369
3370 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg); 3370 gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
3371 } else 3371 } else
3372 gm_phy_write(hw, port, PHY_MARV_LED_OVER, 3372 gm_phy_write(hw, port, PHY_MARV_LED_OVER,
3373 PHY_M_LED_MO_DUP(mode) | 3373 PHY_M_LED_MO_DUP(mode) |
3374 PHY_M_LED_MO_10(mode) | 3374 PHY_M_LED_MO_10(mode) |
3375 PHY_M_LED_MO_100(mode) | 3375 PHY_M_LED_MO_100(mode) |
diff --git a/drivers/net/spider_net.c b/drivers/net/spider_net.c
index 477671606273..00aa0b108cb9 100644
--- a/drivers/net/spider_net.c
+++ b/drivers/net/spider_net.c
@@ -1704,7 +1704,7 @@ spider_net_poll_controller(struct net_device *netdev)
1704 * 1704 *
1705 * spider_net_enable_interrupt enables several interrupts 1705 * spider_net_enable_interrupt enables several interrupts
1706 */ 1706 */
1707static void 1707static void
1708spider_net_enable_interrupts(struct spider_net_card *card) 1708spider_net_enable_interrupts(struct spider_net_card *card)
1709{ 1709{
1710 spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, 1710 spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK,
@@ -1721,7 +1721,7 @@ spider_net_enable_interrupts(struct spider_net_card *card)
1721 * 1721 *
1722 * spider_net_disable_interrupts disables all the interrupts 1722 * spider_net_disable_interrupts disables all the interrupts
1723 */ 1723 */
1724static void 1724static void
1725spider_net_disable_interrupts(struct spider_net_card *card) 1725spider_net_disable_interrupts(struct spider_net_card *card)
1726{ 1726{
1727 spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, 0); 1727 spider_net_write_reg(card, SPIDER_NET_GHIINT0MSK, 0);
diff --git a/drivers/net/tokenring/3c359.c b/drivers/net/tokenring/3c359.c
index 45208a0e69a0..7766cde0d63d 100644
--- a/drivers/net/tokenring/3c359.c
+++ b/drivers/net/tokenring/3c359.c
@@ -132,7 +132,6 @@ static void xl_dn_comp(struct net_device *dev);
132static int xl_close(struct net_device *dev); 132static int xl_close(struct net_device *dev);
133static void xl_set_rx_mode(struct net_device *dev); 133static void xl_set_rx_mode(struct net_device *dev);
134static irqreturn_t xl_interrupt(int irq, void *dev_id); 134static irqreturn_t xl_interrupt(int irq, void *dev_id);
135static struct net_device_stats * xl_get_stats(struct net_device *dev);
136static int xl_set_mac_address(struct net_device *dev, void *addr) ; 135static int xl_set_mac_address(struct net_device *dev, void *addr) ;
137static void xl_arb_cmd(struct net_device *dev); 136static void xl_arb_cmd(struct net_device *dev);
138static void xl_asb_cmd(struct net_device *dev) ; 137static void xl_asb_cmd(struct net_device *dev) ;
@@ -343,7 +342,6 @@ static int __devinit xl_probe(struct pci_dev *pdev,
343 dev->stop=&xl_close; 342 dev->stop=&xl_close;
344 dev->do_ioctl=NULL; 343 dev->do_ioctl=NULL;
345 dev->set_multicast_list=&xl_set_rx_mode; 344 dev->set_multicast_list=&xl_set_rx_mode;
346 dev->get_stats=&xl_get_stats ;
347 dev->set_mac_address=&xl_set_mac_address ; 345 dev->set_mac_address=&xl_set_mac_address ;
348 SET_NETDEV_DEV(dev, &pdev->dev); 346 SET_NETDEV_DEV(dev, &pdev->dev);
349 347
@@ -921,7 +919,7 @@ static void xl_rx(struct net_device *dev)
921 adv_rx_ring(dev) ; 919 adv_rx_ring(dev) ;
922 920
923 adv_rx_ring(dev) ; /* One more time just for luck :) */ 921 adv_rx_ring(dev) ; /* One more time just for luck :) */
924 xl_priv->xl_stats.rx_dropped++ ; 922 dev->stats.rx_dropped++ ;
925 923
926 writel(ACK_INTERRUPT | UPCOMPACK | LATCH_ACK , xl_mmio + MMIO_COMMAND) ; 924 writel(ACK_INTERRUPT | UPCOMPACK | LATCH_ACK , xl_mmio + MMIO_COMMAND) ;
927 return ; 925 return ;
@@ -957,7 +955,7 @@ static void xl_rx(struct net_device *dev)
957 if (skb==NULL) { /* Still need to fix the rx ring */ 955 if (skb==NULL) { /* Still need to fix the rx ring */
958 printk(KERN_WARNING "%s: dev_alloc_skb failed in rx, single buffer \n",dev->name) ; 956 printk(KERN_WARNING "%s: dev_alloc_skb failed in rx, single buffer \n",dev->name) ;
959 adv_rx_ring(dev) ; 957 adv_rx_ring(dev) ;
960 xl_priv->xl_stats.rx_dropped++ ; 958 dev->stats.rx_dropped++ ;
961 writel(ACK_INTERRUPT | UPCOMPACK | LATCH_ACK , xl_mmio + MMIO_COMMAND) ; 959 writel(ACK_INTERRUPT | UPCOMPACK | LATCH_ACK , xl_mmio + MMIO_COMMAND) ;
962 return ; 960 return ;
963 } 961 }
@@ -971,8 +969,8 @@ static void xl_rx(struct net_device *dev)
971 xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr = cpu_to_le32(pci_map_single(xl_priv->pdev,skb->data,xl_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE)); 969 xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfragaddr = cpu_to_le32(pci_map_single(xl_priv->pdev,skb->data,xl_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE));
972 xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfraglen = cpu_to_le32(xl_priv->pkt_buf_sz) | RXUPLASTFRAG; 970 xl_priv->xl_rx_ring[xl_priv->rx_ring_tail].upfraglen = cpu_to_le32(xl_priv->pkt_buf_sz) | RXUPLASTFRAG;
973 adv_rx_ring(dev) ; 971 adv_rx_ring(dev) ;
974 xl_priv->xl_stats.rx_packets++ ; 972 dev->stats.rx_packets++ ;
975 xl_priv->xl_stats.rx_bytes += frame_length ; 973 dev->stats.rx_bytes += frame_length ;
976 974
977 netif_rx(skb2) ; 975 netif_rx(skb2) ;
978 } /* if multiple buffers */ 976 } /* if multiple buffers */
@@ -1182,8 +1180,8 @@ static int xl_xmit(struct sk_buff *skb, struct net_device *dev)
1182 txd->buffer = cpu_to_le32(pci_map_single(xl_priv->pdev, skb->data, skb->len, PCI_DMA_TODEVICE)); 1180 txd->buffer = cpu_to_le32(pci_map_single(xl_priv->pdev, skb->data, skb->len, PCI_DMA_TODEVICE));
1183 txd->buffer_length = cpu_to_le32(skb->len) | TXDNFRAGLAST; 1181 txd->buffer_length = cpu_to_le32(skb->len) | TXDNFRAGLAST;
1184 xl_priv->tx_ring_skb[tx_head] = skb ; 1182 xl_priv->tx_ring_skb[tx_head] = skb ;
1185 xl_priv->xl_stats.tx_packets++ ; 1183 dev->stats.tx_packets++ ;
1186 xl_priv->xl_stats.tx_bytes += skb->len ; 1184 dev->stats.tx_bytes += skb->len ;
1187 1185
1188 /* 1186 /*
1189 * Set the nextptr of the previous descriptor equal to this descriptor, add XL_TX_RING_SIZE -1 1187 * Set the nextptr of the previous descriptor equal to this descriptor, add XL_TX_RING_SIZE -1
@@ -1463,12 +1461,6 @@ static void xl_srb_bh(struct net_device *dev)
1463 return ; 1461 return ;
1464} 1462}
1465 1463
1466static struct net_device_stats * xl_get_stats(struct net_device *dev)
1467{
1468 struct xl_private *xl_priv = netdev_priv(dev);
1469 return (struct net_device_stats *) &xl_priv->xl_stats;
1470}
1471
1472static int xl_set_mac_address (struct net_device *dev, void *addr) 1464static int xl_set_mac_address (struct net_device *dev, void *addr)
1473{ 1465{
1474 struct sockaddr *saddr = addr ; 1466 struct sockaddr *saddr = addr ;
diff --git a/drivers/net/tokenring/3c359.h b/drivers/net/tokenring/3c359.h
index b880cba0f6fd..0f8b4ec8695a 100644
--- a/drivers/net/tokenring/3c359.h
+++ b/drivers/net/tokenring/3c359.h
@@ -273,8 +273,6 @@ struct xl_private {
273 struct wait_queue *srb_wait; 273 struct wait_queue *srb_wait;
274 volatile int asb_queued; 274 volatile int asb_queued;
275 275
276 struct net_device_stats xl_stats ;
277
278 u16 mac_buffer ; 276 u16 mac_buffer ;
279 u16 xl_lan_status ; 277 u16 xl_lan_status ;
280 u8 xl_ring_speed ; 278 u8 xl_ring_speed ;
diff --git a/drivers/net/tsi108_eth.c b/drivers/net/tsi108_eth.c
index 6017d5267d08..c028facd9346 100644
--- a/drivers/net/tsi108_eth.c
+++ b/drivers/net/tsi108_eth.c
@@ -1526,7 +1526,7 @@ static int tsi108_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
1526 struct tsi108_prv_data *data = netdev_priv(dev); 1526 struct tsi108_prv_data *data = netdev_priv(dev);
1527 unsigned long flags; 1527 unsigned long flags;
1528 int rc; 1528 int rc;
1529 1529
1530 spin_lock_irqsave(&data->txlock, flags); 1530 spin_lock_irqsave(&data->txlock, flags);
1531 rc = mii_ethtool_gset(&data->mii_if, cmd); 1531 rc = mii_ethtool_gset(&data->mii_if, cmd);
1532 spin_unlock_irqrestore(&data->txlock, flags); 1532 spin_unlock_irqrestore(&data->txlock, flags);
@@ -1543,7 +1543,7 @@ static int tsi108_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
1543 spin_lock_irqsave(&data->txlock, flags); 1543 spin_lock_irqsave(&data->txlock, flags);
1544 rc = mii_ethtool_sset(&data->mii_if, cmd); 1544 rc = mii_ethtool_sset(&data->mii_if, cmd);
1545 spin_unlock_irqrestore(&data->txlock, flags); 1545 spin_unlock_irqrestore(&data->txlock, flags);
1546 1546
1547 return rc; 1547 return rc;
1548} 1548}
1549 1549
diff --git a/drivers/net/ucc_geth_ethtool.c b/drivers/net/ucc_geth_ethtool.c
index 299b7f176950..5f176f2b1c17 100644
--- a/drivers/net/ucc_geth_ethtool.c
+++ b/drivers/net/ucc_geth_ethtool.c
@@ -5,7 +5,7 @@
5 * 5 *
6 * Author: Li Yang <leoli@freescale.com> 6 * Author: Li Yang <leoli@freescale.com>
7 * 7 *
8 * Limitation: 8 * Limitation:
9 * Can only get/set setttings of the first queue. 9 * Can only get/set setttings of the first queue.
10 * Need to re-open the interface manually after changing some paramters. 10 * Need to re-open the interface manually after changing some paramters.
11 * 11 *
@@ -159,7 +159,7 @@ uec_set_pauseparam(struct net_device *netdev,
159 159
160 ugeth->ug_info->receiveFlowControl = pause->rx_pause; 160 ugeth->ug_info->receiveFlowControl = pause->rx_pause;
161 ugeth->ug_info->transmitFlowControl = pause->tx_pause; 161 ugeth->ug_info->transmitFlowControl = pause->tx_pause;
162 162
163 if (ugeth->phydev->autoneg) { 163 if (ugeth->phydev->autoneg) {
164 if (netif_running(netdev)) { 164 if (netif_running(netdev)) {
165 /* FIXME: automatically restart */ 165 /* FIXME: automatically restart */
diff --git a/drivers/net/wireless/adm8211.c b/drivers/net/wireless/adm8211.c
index 5c0d2b082750..d93a1de77eb0 100644
--- a/drivers/net/wireless/adm8211.c
+++ b/drivers/net/wireless/adm8211.c
@@ -306,11 +306,10 @@ static int adm8211_get_tx_stats(struct ieee80211_hw *dev,
306 struct ieee80211_tx_queue_stats *stats) 306 struct ieee80211_tx_queue_stats *stats)
307{ 307{
308 struct adm8211_priv *priv = dev->priv; 308 struct adm8211_priv *priv = dev->priv;
309 struct ieee80211_tx_queue_stats_data *data = &stats->data[0];
310 309
311 data->len = priv->cur_tx - priv->dirty_tx; 310 stats[0].len = priv->cur_tx - priv->dirty_tx;
312 data->limit = priv->tx_ring_size - 2; 311 stats[0].limit = priv->tx_ring_size - 2;
313 data->count = priv->dirty_tx; 312 stats[0].count = priv->dirty_tx;
314 313
315 return 0; 314 return 0;
316} 315}
diff --git a/drivers/net/wireless/ath5k/base.c b/drivers/net/wireless/ath5k/base.c
index 4e5c8fc35200..3201c1604340 100644
--- a/drivers/net/wireless/ath5k/base.c
+++ b/drivers/net/wireless/ath5k/base.c
@@ -1319,7 +1319,7 @@ ath5k_txbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf,
1319 pktlen = skb->len; 1319 pktlen = skb->len;
1320 1320
1321 if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)) { 1321 if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)) {
1322 keyidx = ctl->key_idx; 1322 keyidx = ctl->hw_key->hw_key_idx;
1323 pktlen += ctl->icv_len; 1323 pktlen += ctl->icv_len;
1324 } 1324 }
1325 1325
@@ -1335,7 +1335,7 @@ ath5k_txbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf,
1335 1335
1336 spin_lock_bh(&txq->lock); 1336 spin_lock_bh(&txq->lock);
1337 list_add_tail(&bf->list, &txq->q); 1337 list_add_tail(&bf->list, &txq->q);
1338 sc->tx_stats.data[txq->qnum].len++; 1338 sc->tx_stats[txq->qnum].len++;
1339 if (txq->link == NULL) /* is this first packet? */ 1339 if (txq->link == NULL) /* is this first packet? */
1340 ath5k_hw_put_tx_buf(ah, txq->qnum, bf->daddr); 1340 ath5k_hw_put_tx_buf(ah, txq->qnum, bf->daddr);
1341 else /* no, so only link it */ 1341 else /* no, so only link it */
@@ -1566,7 +1566,7 @@ ath5k_txq_drainq(struct ath5k_softc *sc, struct ath5k_txq *txq)
1566 ath5k_txbuf_free(sc, bf); 1566 ath5k_txbuf_free(sc, bf);
1567 1567
1568 spin_lock_bh(&sc->txbuflock); 1568 spin_lock_bh(&sc->txbuflock);
1569 sc->tx_stats.data[txq->qnum].len--; 1569 sc->tx_stats[txq->qnum].len--;
1570 list_move_tail(&bf->list, &sc->txbuf); 1570 list_move_tail(&bf->list, &sc->txbuf);
1571 sc->txbuf_len++; 1571 sc->txbuf_len++;
1572 spin_unlock_bh(&sc->txbuflock); 1572 spin_unlock_bh(&sc->txbuflock);
@@ -1979,10 +1979,10 @@ ath5k_tx_processq(struct ath5k_softc *sc, struct ath5k_txq *txq)
1979 } 1979 }
1980 1980
1981 ieee80211_tx_status(sc->hw, skb, &txs); 1981 ieee80211_tx_status(sc->hw, skb, &txs);
1982 sc->tx_stats.data[txq->qnum].count++; 1982 sc->tx_stats[txq->qnum].count++;
1983 1983
1984 spin_lock(&sc->txbuflock); 1984 spin_lock(&sc->txbuflock);
1985 sc->tx_stats.data[txq->qnum].len--; 1985 sc->tx_stats[txq->qnum].len--;
1986 list_move_tail(&bf->list, &sc->txbuf); 1986 list_move_tail(&bf->list, &sc->txbuf);
1987 sc->txbuf_len++; 1987 sc->txbuf_len++;
1988 spin_unlock(&sc->txbuflock); 1988 spin_unlock(&sc->txbuflock);
diff --git a/drivers/net/wireless/ath5k/base.h b/drivers/net/wireless/ath5k/base.h
index 3a9755893018..ecb17495488c 100644
--- a/drivers/net/wireless/ath5k/base.h
+++ b/drivers/net/wireless/ath5k/base.h
@@ -92,7 +92,8 @@ struct ath5k_softc {
92 struct pci_dev *pdev; /* for dma mapping */ 92 struct pci_dev *pdev; /* for dma mapping */
93 void __iomem *iobase; /* address of the device */ 93 void __iomem *iobase; /* address of the device */
94 struct mutex lock; /* dev-level lock */ 94 struct mutex lock; /* dev-level lock */
95 struct ieee80211_tx_queue_stats tx_stats; 95 /* FIXME: how many does it really need? */
96 struct ieee80211_tx_queue_stats tx_stats[16];
96 struct ieee80211_low_level_stats ll_stats; 97 struct ieee80211_low_level_stats ll_stats;
97 struct ieee80211_hw *hw; /* IEEE 802.11 common */ 98 struct ieee80211_hw *hw; /* IEEE 802.11 common */
98 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS]; 99 struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
diff --git a/drivers/net/wireless/b43/b43.h b/drivers/net/wireless/b43/b43.h
index 37783cdd301a..7d034df250bd 100644
--- a/drivers/net/wireless/b43/b43.h
+++ b/drivers/net/wireless/b43/b43.h
@@ -410,8 +410,7 @@ enum {
410#define B43_IRQ_TIMEOUT 0x80000000 410#define B43_IRQ_TIMEOUT 0x80000000
411 411
412#define B43_IRQ_ALL 0xFFFFFFFF 412#define B43_IRQ_ALL 0xFFFFFFFF
413#define B43_IRQ_MASKTEMPLATE (B43_IRQ_MAC_SUSPENDED | \ 413#define B43_IRQ_MASKTEMPLATE (B43_IRQ_TBTT_INDI | \
414 B43_IRQ_TBTT_INDI | \
415 B43_IRQ_ATIM_END | \ 414 B43_IRQ_ATIM_END | \
416 B43_IRQ_PMQ | \ 415 B43_IRQ_PMQ | \
417 B43_IRQ_MAC_TXERR | \ 416 B43_IRQ_MAC_TXERR | \
diff --git a/drivers/net/wireless/b43/debugfs.c b/drivers/net/wireless/b43/debugfs.c
index 7fca2ebc747f..210e2789c1c3 100644
--- a/drivers/net/wireless/b43/debugfs.c
+++ b/drivers/net/wireless/b43/debugfs.c
@@ -270,24 +270,22 @@ static int restart_write_file(struct b43_wldev *dev,
270 return err; 270 return err;
271} 271}
272 272
273static ssize_t append_lo_table(ssize_t count, char *buf, const size_t bufsize, 273static unsigned long calc_expire_secs(unsigned long now,
274 struct b43_loctl table[B43_NR_BB][B43_NR_RF]) 274 unsigned long time,
275 unsigned long expire)
275{ 276{
276 unsigned int i, j; 277 expire = time + expire;
277 struct b43_loctl *ctl; 278
278 279 if (time_after(now, expire))
279 for (i = 0; i < B43_NR_BB; i++) { 280 return 0; /* expired */
280 for (j = 0; j < B43_NR_RF; j++) { 281 if (expire < now) {
281 ctl = &(table[i][j]); 282 /* jiffies wrapped */
282 fappend("(bbatt %2u, rfatt %2u) -> " 283 expire -= MAX_JIFFY_OFFSET;
283 "(I %+3d, Q %+3d, Used: %d, Calibrated: %d)\n", 284 now -= MAX_JIFFY_OFFSET;
284 i, j, ctl->i, ctl->q,
285 ctl->used,
286 b43_loctl_is_calibrated(ctl));
287 }
288 } 285 }
286 B43_WARN_ON(expire < now);
289 287
290 return count; 288 return (expire - now) / HZ;
291} 289}
292 290
293static ssize_t loctls_read_file(struct b43_wldev *dev, 291static ssize_t loctls_read_file(struct b43_wldev *dev,
@@ -296,27 +294,45 @@ static ssize_t loctls_read_file(struct b43_wldev *dev,
296 ssize_t count = 0; 294 ssize_t count = 0;
297 struct b43_txpower_lo_control *lo; 295 struct b43_txpower_lo_control *lo;
298 int i, err = 0; 296 int i, err = 0;
297 struct b43_lo_calib *cal;
298 unsigned long now = jiffies;
299 struct b43_phy *phy = &dev->phy;
299 300
300 if (dev->phy.type != B43_PHYTYPE_G) { 301 if (phy->type != B43_PHYTYPE_G) {
301 fappend("Device is not a G-PHY\n"); 302 fappend("Device is not a G-PHY\n");
302 err = -ENODEV; 303 err = -ENODEV;
303 goto out; 304 goto out;
304 } 305 }
305 lo = dev->phy.lo_control; 306 lo = phy->lo_control;
306 fappend("-- Local Oscillator calibration data --\n\n"); 307 fappend("-- Local Oscillator calibration data --\n\n");
307 fappend("Measured: %d, Rebuild: %d, HW-power-control: %d\n", 308 fappend("HW-power-control enabled: %d\n",
308 lo->lo_measured,
309 lo->rebuild,
310 dev->phy.hardware_power_control); 309 dev->phy.hardware_power_control);
311 fappend("TX Bias: 0x%02X, TX Magn: 0x%02X\n", 310 fappend("TX Bias: 0x%02X, TX Magn: 0x%02X (expire in %lu sec)\n",
312 lo->tx_bias, lo->tx_magn); 311 lo->tx_bias, lo->tx_magn,
313 fappend("Power Vector: 0x%08X%08X\n", 312 calc_expire_secs(now, lo->txctl_measured_time,
313 B43_LO_TXCTL_EXPIRE));
314 fappend("Power Vector: 0x%08X%08X (expires in %lu sec)\n",
314 (unsigned int)((lo->power_vector & 0xFFFFFFFF00000000ULL) >> 32), 315 (unsigned int)((lo->power_vector & 0xFFFFFFFF00000000ULL) >> 32),
315 (unsigned int)(lo->power_vector & 0x00000000FFFFFFFFULL)); 316 (unsigned int)(lo->power_vector & 0x00000000FFFFFFFFULL),
316 fappend("\nControl table WITH PADMIX:\n"); 317 calc_expire_secs(now, lo->pwr_vec_read_time,
317 count = append_lo_table(count, buf, bufsize, lo->with_padmix); 318 B43_LO_PWRVEC_EXPIRE));
318 fappend("\nControl table WITHOUT PADMIX:\n"); 319
319 count = append_lo_table(count, buf, bufsize, lo->no_padmix); 320 fappend("\nCalibrated settings:\n");
321 list_for_each_entry(cal, &lo->calib_list, list) {
322 bool active;
323
324 active = (b43_compare_bbatt(&cal->bbatt, &phy->bbatt) &&
325 b43_compare_rfatt(&cal->rfatt, &phy->rfatt));
326 fappend("BB(%d), RF(%d,%d) -> I=%d, Q=%d "
327 "(expires in %lu sec)%s\n",
328 cal->bbatt.att,
329 cal->rfatt.att, cal->rfatt.with_padmix,
330 cal->ctl.i, cal->ctl.q,
331 calc_expire_secs(now, cal->calib_time,
332 B43_LO_CALIB_EXPIRE),
333 active ? " ACTIVE" : "");
334 }
335
320 fappend("\nUsed RF attenuation values: Value(WithPadmix flag)\n"); 336 fappend("\nUsed RF attenuation values: Value(WithPadmix flag)\n");
321 for (i = 0; i < lo->rfatt_list.len; i++) { 337 for (i = 0; i < lo->rfatt_list.len; i++) {
322 fappend("%u(%d), ", 338 fappend("%u(%d), ",
@@ -351,7 +367,7 @@ static ssize_t b43_debugfs_read(struct file *file, char __user *userbuf,
351 struct b43_dfs_file *dfile; 367 struct b43_dfs_file *dfile;
352 ssize_t uninitialized_var(ret); 368 ssize_t uninitialized_var(ret);
353 char *buf; 369 char *buf;
354 const size_t bufsize = 1024 * 128; 370 const size_t bufsize = 1024 * 16; /* 16 kiB buffer */
355 const size_t buforder = get_order(bufsize); 371 const size_t buforder = get_order(bufsize);
356 int err = 0; 372 int err = 0;
357 373
@@ -380,8 +396,6 @@ static ssize_t b43_debugfs_read(struct file *file, char __user *userbuf,
380 err = -ENOMEM; 396 err = -ENOMEM;
381 goto out_unlock; 397 goto out_unlock;
382 } 398 }
383 /* Sparse warns about the following memset, because it has a big
384 * size value. That warning is bogus, so I will ignore it. --mb */
385 memset(buf, 0, bufsize); 399 memset(buf, 0, bufsize);
386 if (dfops->take_irqlock) { 400 if (dfops->take_irqlock) {
387 spin_lock_irq(&dev->wl->irq_lock); 401 spin_lock_irq(&dev->wl->irq_lock);
@@ -523,6 +537,7 @@ static void b43_add_dynamic_debug(struct b43_wldev *dev)
523 add_dyn_dbg("debug_dmaverbose", B43_DBG_DMAVERBOSE, 0); 537 add_dyn_dbg("debug_dmaverbose", B43_DBG_DMAVERBOSE, 0);
524 add_dyn_dbg("debug_pwork_fast", B43_DBG_PWORK_FAST, 0); 538 add_dyn_dbg("debug_pwork_fast", B43_DBG_PWORK_FAST, 0);
525 add_dyn_dbg("debug_pwork_stop", B43_DBG_PWORK_STOP, 0); 539 add_dyn_dbg("debug_pwork_stop", B43_DBG_PWORK_STOP, 0);
540 add_dyn_dbg("debug_lo", B43_DBG_LO, 0);
526 541
527#undef add_dyn_dbg 542#undef add_dyn_dbg
528} 543}
diff --git a/drivers/net/wireless/b43/debugfs.h b/drivers/net/wireless/b43/debugfs.h
index 6eebe858db5a..c75cff4151d9 100644
--- a/drivers/net/wireless/b43/debugfs.h
+++ b/drivers/net/wireless/b43/debugfs.h
@@ -10,6 +10,7 @@ enum b43_dyndbg { /* Dynamic debugging features */
10 B43_DBG_DMAVERBOSE, 10 B43_DBG_DMAVERBOSE,
11 B43_DBG_PWORK_FAST, 11 B43_DBG_PWORK_FAST,
12 B43_DBG_PWORK_STOP, 12 B43_DBG_PWORK_STOP,
13 B43_DBG_LO,
13 __B43_NR_DYNDBG, 14 __B43_NR_DYNDBG,
14}; 15};
15 16
diff --git a/drivers/net/wireless/b43/dma.c b/drivers/net/wireless/b43/dma.c
index 6dcbb3c87e72..f50e2014ffbe 100644
--- a/drivers/net/wireless/b43/dma.c
+++ b/drivers/net/wireless/b43/dma.c
@@ -1427,18 +1427,16 @@ void b43_dma_get_tx_stats(struct b43_wldev *dev,
1427{ 1427{
1428 const int nr_queues = dev->wl->hw->queues; 1428 const int nr_queues = dev->wl->hw->queues;
1429 struct b43_dmaring *ring; 1429 struct b43_dmaring *ring;
1430 struct ieee80211_tx_queue_stats_data *data;
1431 unsigned long flags; 1430 unsigned long flags;
1432 int i; 1431 int i;
1433 1432
1434 for (i = 0; i < nr_queues; i++) { 1433 for (i = 0; i < nr_queues; i++) {
1435 data = &(stats->data[i]);
1436 ring = select_ring_by_priority(dev, i); 1434 ring = select_ring_by_priority(dev, i);
1437 1435
1438 spin_lock_irqsave(&ring->lock, flags); 1436 spin_lock_irqsave(&ring->lock, flags);
1439 data->len = ring->used_slots / SLOTS_PER_PACKET; 1437 stats[i].len = ring->used_slots / SLOTS_PER_PACKET;
1440 data->limit = ring->nr_slots / SLOTS_PER_PACKET; 1438 stats[i].limit = ring->nr_slots / SLOTS_PER_PACKET;
1441 data->count = ring->nr_tx_packets; 1439 stats[i].count = ring->nr_tx_packets;
1442 spin_unlock_irqrestore(&ring->lock, flags); 1440 spin_unlock_irqrestore(&ring->lock, flags);
1443 } 1441 }
1444} 1442}
diff --git a/drivers/net/wireless/b43/lo.c b/drivers/net/wireless/b43/lo.c
index d890f366a23b..4ce1e3561205 100644
--- a/drivers/net/wireless/b43/lo.c
+++ b/drivers/net/wireless/b43/lo.c
@@ -36,17 +36,28 @@
36#include <linux/sched.h> 36#include <linux/sched.h>
37 37
38 38
39/* Define to 1 to always calibrate all possible LO control pairs. 39static struct b43_lo_calib * b43_find_lo_calib(struct b43_txpower_lo_control *lo,
40 * This is a workaround until we fix the partial LO calibration optimization. */ 40 const struct b43_bbatt *bbatt,
41#define B43_CALIB_ALL_LOCTLS 1 41 const struct b43_rfatt *rfatt)
42{
43 struct b43_lo_calib *c;
44
45 list_for_each_entry(c, &lo->calib_list, list) {
46 if (!b43_compare_bbatt(&c->bbatt, bbatt))
47 continue;
48 if (!b43_compare_rfatt(&c->rfatt, rfatt))
49 continue;
50 return c;
51 }
42 52
53 return NULL;
54}
43 55
44/* Write the LocalOscillator Control (adjust) value-pair. */ 56/* Write the LocalOscillator Control (adjust) value-pair. */
45static void b43_lo_write(struct b43_wldev *dev, struct b43_loctl *control) 57static void b43_lo_write(struct b43_wldev *dev, struct b43_loctl *control)
46{ 58{
47 struct b43_phy *phy = &dev->phy; 59 struct b43_phy *phy = &dev->phy;
48 u16 value; 60 u16 value;
49 u16 reg;
50 61
51 if (B43_DEBUG) { 62 if (B43_DEBUG) {
52 if (unlikely(abs(control->i) > 16 || abs(control->q) > 16)) { 63 if (unlikely(abs(control->i) > 16 || abs(control->q) > 16)) {
@@ -56,189 +67,11 @@ static void b43_lo_write(struct b43_wldev *dev, struct b43_loctl *control)
56 return; 67 return;
57 } 68 }
58 } 69 }
70 B43_WARN_ON(phy->type != B43_PHYTYPE_G);
59 71
60 value = (u8) (control->q); 72 value = (u8) (control->q);
61 value |= ((u8) (control->i)) << 8; 73 value |= ((u8) (control->i)) << 8;
62 74 b43_phy_write(dev, B43_PHY_LO_CTL, value);
63 reg = (phy->type == B43_PHYTYPE_B) ? 0x002F : B43_PHY_LO_CTL;
64 b43_phy_write(dev, reg, value);
65}
66
67static int assert_rfatt_and_bbatt(const struct b43_rfatt *rfatt,
68 const struct b43_bbatt *bbatt,
69 struct b43_wldev *dev)
70{
71 int err = 0;
72
73 /* Check the attenuation values against the LO control array sizes. */
74 if (unlikely(rfatt->att >= B43_NR_RF)) {
75 b43err(dev->wl, "rfatt(%u) >= size of LO array\n", rfatt->att);
76 err = -EINVAL;
77 }
78 if (unlikely(bbatt->att >= B43_NR_BB)) {
79 b43err(dev->wl, "bbatt(%u) >= size of LO array\n", bbatt->att);
80 err = -EINVAL;
81 }
82
83 return err;
84}
85
86#if !B43_CALIB_ALL_LOCTLS
87static
88struct b43_loctl *b43_get_lo_g_ctl_nopadmix(struct b43_wldev *dev,
89 const struct b43_rfatt *rfatt,
90 const struct b43_bbatt *bbatt)
91{
92 struct b43_phy *phy = &dev->phy;
93 struct b43_txpower_lo_control *lo = phy->lo_control;
94
95 if (assert_rfatt_and_bbatt(rfatt, bbatt, dev))
96 return &(lo->no_padmix[0][0]); /* Just prevent a crash */
97 return &(lo->no_padmix[bbatt->att][rfatt->att]);
98}
99#endif /* !B43_CALIB_ALL_LOCTLS */
100
101struct b43_loctl *b43_get_lo_g_ctl(struct b43_wldev *dev,
102 const struct b43_rfatt *rfatt,
103 const struct b43_bbatt *bbatt)
104{
105 struct b43_phy *phy = &dev->phy;
106 struct b43_txpower_lo_control *lo = phy->lo_control;
107
108 if (assert_rfatt_and_bbatt(rfatt, bbatt, dev))
109 return &(lo->no_padmix[0][0]); /* Just prevent a crash */
110 if (rfatt->with_padmix)
111 return &(lo->with_padmix[bbatt->att][rfatt->att]);
112 return &(lo->no_padmix[bbatt->att][rfatt->att]);
113}
114
115/* Call a function for every possible LO control value-pair. */
116static void b43_call_for_each_loctl(struct b43_wldev *dev,
117 void (*func) (struct b43_wldev *,
118 struct b43_loctl *))
119{
120 struct b43_phy *phy = &dev->phy;
121 struct b43_txpower_lo_control *ctl = phy->lo_control;
122 int i, j;
123
124 for (i = 0; i < B43_NR_BB; i++) {
125 for (j = 0; j < B43_NR_RF; j++)
126 func(dev, &(ctl->with_padmix[i][j]));
127 }
128 for (i = 0; i < B43_NR_BB; i++) {
129 for (j = 0; j < B43_NR_RF; j++)
130 func(dev, &(ctl->no_padmix[i][j]));
131 }
132}
133
134static u16 lo_b_r15_loop(struct b43_wldev *dev)
135{
136 int i;
137 u16 ret = 0;
138
139 for (i = 0; i < 10; i++) {
140 b43_phy_write(dev, 0x0015, 0xAFA0);
141 udelay(1);
142 b43_phy_write(dev, 0x0015, 0xEFA0);
143 udelay(10);
144 b43_phy_write(dev, 0x0015, 0xFFA0);
145 udelay(40);
146 ret += b43_phy_read(dev, 0x002C);
147 }
148
149 return ret;
150}
151
152void b43_lo_b_measure(struct b43_wldev *dev)
153{
154 struct b43_phy *phy = &dev->phy;
155 u16 regstack[12] = { 0 };
156 u16 mls;
157 u16 fval;
158 int i, j;
159
160 regstack[0] = b43_phy_read(dev, 0x0015);
161 regstack[1] = b43_radio_read16(dev, 0x0052) & 0xFFF0;
162
163 if (phy->radio_ver == 0x2053) {
164 regstack[2] = b43_phy_read(dev, 0x000A);
165 regstack[3] = b43_phy_read(dev, 0x002A);
166 regstack[4] = b43_phy_read(dev, 0x0035);
167 regstack[5] = b43_phy_read(dev, 0x0003);
168 regstack[6] = b43_phy_read(dev, 0x0001);
169 regstack[7] = b43_phy_read(dev, 0x0030);
170
171 regstack[8] = b43_radio_read16(dev, 0x0043);
172 regstack[9] = b43_radio_read16(dev, 0x007A);
173 regstack[10] = b43_read16(dev, 0x03EC);
174 regstack[11] = b43_radio_read16(dev, 0x0052) & 0x00F0;
175
176 b43_phy_write(dev, 0x0030, 0x00FF);
177 b43_write16(dev, 0x03EC, 0x3F3F);
178 b43_phy_write(dev, 0x0035, regstack[4] & 0xFF7F);
179 b43_radio_write16(dev, 0x007A, regstack[9] & 0xFFF0);
180 }
181 b43_phy_write(dev, 0x0015, 0xB000);
182 b43_phy_write(dev, 0x002B, 0x0004);
183
184 if (phy->radio_ver == 0x2053) {
185 b43_phy_write(dev, 0x002B, 0x0203);
186 b43_phy_write(dev, 0x002A, 0x08A3);
187 }
188
189 phy->minlowsig[0] = 0xFFFF;
190
191 for (i = 0; i < 4; i++) {
192 b43_radio_write16(dev, 0x0052, regstack[1] | i);
193 lo_b_r15_loop(dev);
194 }
195 for (i = 0; i < 10; i++) {
196 b43_radio_write16(dev, 0x0052, regstack[1] | i);
197 mls = lo_b_r15_loop(dev) / 10;
198 if (mls < phy->minlowsig[0]) {
199 phy->minlowsig[0] = mls;
200 phy->minlowsigpos[0] = i;
201 }
202 }
203 b43_radio_write16(dev, 0x0052, regstack[1] | phy->minlowsigpos[0]);
204
205 phy->minlowsig[1] = 0xFFFF;
206
207 for (i = -4; i < 5; i += 2) {
208 for (j = -4; j < 5; j += 2) {
209 if (j < 0)
210 fval = (0x0100 * i) + j + 0x0100;
211 else
212 fval = (0x0100 * i) + j;
213 b43_phy_write(dev, 0x002F, fval);
214 mls = lo_b_r15_loop(dev) / 10;
215 if (mls < phy->minlowsig[1]) {
216 phy->minlowsig[1] = mls;
217 phy->minlowsigpos[1] = fval;
218 }
219 }
220 }
221 phy->minlowsigpos[1] += 0x0101;
222
223 b43_phy_write(dev, 0x002F, phy->minlowsigpos[1]);
224 if (phy->radio_ver == 0x2053) {
225 b43_phy_write(dev, 0x000A, regstack[2]);
226 b43_phy_write(dev, 0x002A, regstack[3]);
227 b43_phy_write(dev, 0x0035, regstack[4]);
228 b43_phy_write(dev, 0x0003, regstack[5]);
229 b43_phy_write(dev, 0x0001, regstack[6]);
230 b43_phy_write(dev, 0x0030, regstack[7]);
231
232 b43_radio_write16(dev, 0x0043, regstack[8]);
233 b43_radio_write16(dev, 0x007A, regstack[9]);
234
235 b43_radio_write16(dev, 0x0052,
236 (b43_radio_read16(dev, 0x0052) & 0x000F)
237 | regstack[11]);
238
239 b43_write16(dev, 0x03EC, regstack[10]);
240 }
241 b43_phy_write(dev, 0x0015, regstack[0]);
242} 75}
243 76
244static u16 lo_measure_feedthrough(struct b43_wldev *dev, 77static u16 lo_measure_feedthrough(struct b43_wldev *dev,
@@ -438,48 +271,26 @@ static void lo_measure_txctl_values(struct b43_wldev *dev)
438 b43_radio_write16(dev, 0x52, b43_radio_read16(dev, 0x52) 271 b43_radio_write16(dev, 0x52, b43_radio_read16(dev, 0x52)
439 & 0xFFF0); /* TX bias == 0 */ 272 & 0xFFF0); /* TX bias == 0 */
440 } 273 }
274 lo->txctl_measured_time = jiffies;
441} 275}
442 276
443static void lo_read_power_vector(struct b43_wldev *dev) 277static void lo_read_power_vector(struct b43_wldev *dev)
444{ 278{
445 struct b43_phy *phy = &dev->phy; 279 struct b43_phy *phy = &dev->phy;
446 struct b43_txpower_lo_control *lo = phy->lo_control; 280 struct b43_txpower_lo_control *lo = phy->lo_control;
447 u16 i; 281 int i;
448 u64 tmp; 282 u64 tmp;
449 u64 power_vector = 0; 283 u64 power_vector = 0;
450 int rf_offset, bb_offset;
451 struct b43_loctl *loctl;
452 284
453 for (i = 0; i < 8; i += 2) { 285 for (i = 0; i < 8; i += 2) {
454 tmp = b43_shm_read16(dev, B43_SHM_SHARED, 0x310 + i); 286 tmp = b43_shm_read16(dev, B43_SHM_SHARED, 0x310 + i);
455 /* Clear the top byte. We get holes in the bitmap... */
456 tmp &= 0xFF;
457 power_vector |= (tmp << (i * 8)); 287 power_vector |= (tmp << (i * 8));
458 /* Clear the vector on the device. */ 288 /* Clear the vector on the device. */
459 b43_shm_write16(dev, B43_SHM_SHARED, 0x310 + i, 0); 289 b43_shm_write16(dev, B43_SHM_SHARED, 0x310 + i, 0);
460 } 290 }
461
462 if (power_vector) 291 if (power_vector)
463 lo->power_vector = power_vector; 292 lo->power_vector = power_vector;
464 power_vector = lo->power_vector; 293 lo->pwr_vec_read_time = jiffies;
465
466 for (i = 0; i < 64; i++) {
467 if (power_vector & ((u64) 1ULL << i)) {
468 /* Now figure out which b43_loctl corresponds
469 * to this bit.
470 */
471 rf_offset = i / lo->rfatt_list.len;
472 bb_offset = i % lo->rfatt_list.len; //FIXME?
473 loctl =
474 b43_get_lo_g_ctl(dev,
475 &lo->rfatt_list.list[rf_offset],
476 &lo->bbatt_list.list[bb_offset]);
477 /* And mark it as "used", as the device told us
478 * through the bitmap it is using it.
479 */
480 loctl->used = 1;
481 }
482 }
483} 294}
484 295
485/* 802.11/LO/GPHY/MeasuringGains */ 296/* 802.11/LO/GPHY/MeasuringGains */
@@ -609,8 +420,6 @@ static void lo_measure_setup(struct b43_wldev *dev,
609 b43_phy_write(dev, B43_PHY_CCK(0x16), 0x410); 420 b43_phy_write(dev, B43_PHY_CCK(0x16), 0x410);
610 b43_phy_write(dev, B43_PHY_CCK(0x17), 0x820); 421 b43_phy_write(dev, B43_PHY_CCK(0x17), 0x820);
611 } 422 }
612 if (!lo->rebuild && b43_has_hardware_pctl(phy))
613 lo_read_power_vector(dev);
614 if (phy->rev >= 2) { 423 if (phy->rev >= 2) {
615 sav->phy_analogover = b43_phy_read(dev, B43_PHY_ANALOGOVER); 424 sav->phy_analogover = b43_phy_read(dev, B43_PHY_ANALOGOVER);
616 sav->phy_analogoverval = 425 sav->phy_analogoverval =
@@ -691,8 +500,12 @@ static void lo_measure_setup(struct b43_wldev *dev,
691 b43_radio_read16(dev, 0x51); /* dummy read */ 500 b43_radio_read16(dev, 0x51); /* dummy read */
692 if (phy->type == B43_PHYTYPE_G) 501 if (phy->type == B43_PHYTYPE_G)
693 b43_phy_write(dev, B43_PHY_CCK(0x2F), 0); 502 b43_phy_write(dev, B43_PHY_CCK(0x2F), 0);
694 if (lo->rebuild) 503
504 /* Re-measure the txctl values, if needed. */
505 if (time_before(lo->txctl_measured_time,
506 jiffies - B43_LO_TXCTL_EXPIRE))
695 lo_measure_txctl_values(dev); 507 lo_measure_txctl_values(dev);
508
696 if (phy->type == B43_PHYTYPE_G && phy->rev >= 3) { 509 if (phy->type == B43_PHYTYPE_G && phy->rev >= 3) {
697 b43_phy_write(dev, B43_PHY_LO_MASK, 0xC078); 510 b43_phy_write(dev, B43_PHY_LO_MASK, 0xC078);
698 } else { 511 } else {
@@ -707,7 +520,6 @@ static void lo_measure_restore(struct b43_wldev *dev,
707 struct lo_g_saved_values *sav) 520 struct lo_g_saved_values *sav)
708{ 521{
709 struct b43_phy *phy = &dev->phy; 522 struct b43_phy *phy = &dev->phy;
710 struct b43_txpower_lo_control *lo = phy->lo_control;
711 u16 tmp; 523 u16 tmp;
712 524
713 if (phy->rev >= 2) { 525 if (phy->rev >= 2) {
@@ -722,14 +534,6 @@ static void lo_measure_restore(struct b43_wldev *dev,
722 tmp = (phy->pga_gain | 0xEFA0); 534 tmp = (phy->pga_gain | 0xEFA0);
723 b43_phy_write(dev, B43_PHY_PGACTL, tmp); 535 b43_phy_write(dev, B43_PHY_PGACTL, tmp);
724 } 536 }
725 if (b43_has_hardware_pctl(phy)) {
726 b43_gphy_dc_lt_init(dev);
727 } else {
728 if (lo->rebuild)
729 b43_lo_g_adjust_to(dev, 3, 2, 0);
730 else
731 b43_lo_g_adjust(dev);
732 }
733 if (phy->type == B43_PHYTYPE_G) { 537 if (phy->type == B43_PHYTYPE_G) {
734 if (phy->rev >= 3) 538 if (phy->rev >= 3)
735 b43_phy_write(dev, B43_PHY_CCK(0x2E), 0xC078); 539 b43_phy_write(dev, B43_PHY_CCK(0x2E), 0xC078);
@@ -793,7 +597,6 @@ static int lo_probe_possible_loctls(struct b43_wldev *dev,
793 struct b43_lo_g_statemachine *d) 597 struct b43_lo_g_statemachine *d)
794{ 598{
795 struct b43_phy *phy = &dev->phy; 599 struct b43_phy *phy = &dev->phy;
796 struct b43_txpower_lo_control *lo = phy->lo_control;
797 struct b43_loctl test_loctl; 600 struct b43_loctl test_loctl;
798 struct b43_loctl orig_loctl; 601 struct b43_loctl orig_loctl;
799 struct b43_loctl prev_loctl = { 602 struct b43_loctl prev_loctl = {
@@ -852,7 +655,7 @@ static int lo_probe_possible_loctls(struct b43_wldev *dev,
852 found_lower = 1; 655 found_lower = 1;
853 d->lowest_feedth = feedth; 656 d->lowest_feedth = feedth;
854 if ((d->nr_measured < 2) && 657 if ((d->nr_measured < 2) &&
855 (!has_loopback_gain(phy) || lo->rebuild)) 658 !has_loopback_gain(phy))
856 break; 659 break;
857 } 660 }
858 } 661 }
@@ -874,7 +677,6 @@ static void lo_probe_loctls_statemachine(struct b43_wldev *dev,
874 int *max_rx_gain) 677 int *max_rx_gain)
875{ 678{
876 struct b43_phy *phy = &dev->phy; 679 struct b43_phy *phy = &dev->phy;
877 struct b43_txpower_lo_control *lo = phy->lo_control;
878 struct b43_lo_g_statemachine d; 680 struct b43_lo_g_statemachine d;
879 u16 feedth; 681 u16 feedth;
880 int found_lower; 682 int found_lower;
@@ -883,18 +685,18 @@ static void lo_probe_loctls_statemachine(struct b43_wldev *dev,
883 685
884 d.nr_measured = 0; 686 d.nr_measured = 0;
885 d.state_val_multiplier = 1; 687 d.state_val_multiplier = 1;
886 if (has_loopback_gain(phy) && !lo->rebuild) 688 if (has_loopback_gain(phy))
887 d.state_val_multiplier = 3; 689 d.state_val_multiplier = 3;
888 690
889 memcpy(&d.min_loctl, loctl, sizeof(struct b43_loctl)); 691 memcpy(&d.min_loctl, loctl, sizeof(struct b43_loctl));
890 if (has_loopback_gain(phy) && lo->rebuild) 692 if (has_loopback_gain(phy))
891 max_repeat = 4; 693 max_repeat = 4;
892 do { 694 do {
893 b43_lo_write(dev, &d.min_loctl); 695 b43_lo_write(dev, &d.min_loctl);
894 feedth = lo_measure_feedthrough(dev, phy->lna_gain, 696 feedth = lo_measure_feedthrough(dev, phy->lna_gain,
895 phy->pga_gain, 697 phy->pga_gain,
896 phy->trsw_rx_gain); 698 phy->trsw_rx_gain);
897 if (!lo->rebuild && feedth < 0x258) { 699 if (feedth < 0x258) {
898 if (feedth >= 0x12C) 700 if (feedth >= 0x12C)
899 *max_rx_gain += 6; 701 *max_rx_gain += 6;
900 else 702 else
@@ -944,278 +746,188 @@ static void lo_probe_loctls_statemachine(struct b43_wldev *dev,
944 } while (++repeat_cnt < max_repeat); 746 } while (++repeat_cnt < max_repeat);
945} 747}
946 748
947#if B43_CALIB_ALL_LOCTLS 749static
948static const struct b43_rfatt b43_full_rfatt_list_items[] = { 750struct b43_lo_calib * b43_calibrate_lo_setting(struct b43_wldev *dev,
949 { .att = 0, .with_padmix = 0, }, 751 const struct b43_bbatt *bbatt,
950 { .att = 1, .with_padmix = 0, }, 752 const struct b43_rfatt *rfatt)
951 { .att = 2, .with_padmix = 0, },
952 { .att = 3, .with_padmix = 0, },
953 { .att = 4, .with_padmix = 0, },
954 { .att = 5, .with_padmix = 0, },
955 { .att = 6, .with_padmix = 0, },
956 { .att = 7, .with_padmix = 0, },
957 { .att = 8, .with_padmix = 0, },
958 { .att = 9, .with_padmix = 0, },
959 { .att = 10, .with_padmix = 0, },
960 { .att = 11, .with_padmix = 0, },
961 { .att = 12, .with_padmix = 0, },
962 { .att = 13, .with_padmix = 0, },
963 { .att = 14, .with_padmix = 0, },
964 { .att = 15, .with_padmix = 0, },
965 { .att = 0, .with_padmix = 1, },
966 { .att = 1, .with_padmix = 1, },
967 { .att = 2, .with_padmix = 1, },
968 { .att = 3, .with_padmix = 1, },
969 { .att = 4, .with_padmix = 1, },
970 { .att = 5, .with_padmix = 1, },
971 { .att = 6, .with_padmix = 1, },
972 { .att = 7, .with_padmix = 1, },
973 { .att = 8, .with_padmix = 1, },
974 { .att = 9, .with_padmix = 1, },
975 { .att = 10, .with_padmix = 1, },
976 { .att = 11, .with_padmix = 1, },
977 { .att = 12, .with_padmix = 1, },
978 { .att = 13, .with_padmix = 1, },
979 { .att = 14, .with_padmix = 1, },
980 { .att = 15, .with_padmix = 1, },
981};
982static const struct b43_rfatt_list b43_full_rfatt_list = {
983 .list = b43_full_rfatt_list_items,
984 .len = ARRAY_SIZE(b43_full_rfatt_list_items),
985};
986
987static const struct b43_bbatt b43_full_bbatt_list_items[] = {
988 { .att = 0, },
989 { .att = 1, },
990 { .att = 2, },
991 { .att = 3, },
992 { .att = 4, },
993 { .att = 5, },
994 { .att = 6, },
995 { .att = 7, },
996 { .att = 8, },
997 { .att = 9, },
998 { .att = 10, },
999 { .att = 11, },
1000};
1001static const struct b43_bbatt_list b43_full_bbatt_list = {
1002 .list = b43_full_bbatt_list_items,
1003 .len = ARRAY_SIZE(b43_full_bbatt_list_items),
1004};
1005#endif /* B43_CALIB_ALL_LOCTLS */
1006
1007static void lo_measure(struct b43_wldev *dev)
1008{ 753{
1009 struct b43_phy *phy = &dev->phy; 754 struct b43_phy *phy = &dev->phy;
1010 struct b43_txpower_lo_control *lo = phy->lo_control;
1011 struct b43_loctl loctl = { 755 struct b43_loctl loctl = {
1012 .i = 0, 756 .i = 0,
1013 .q = 0, 757 .q = 0,
1014 }; 758 };
1015 struct b43_loctl *ploctl;
1016 int max_rx_gain; 759 int max_rx_gain;
1017 int rfidx, bbidx; 760 struct b43_lo_calib *cal;
1018 const struct b43_bbatt_list *bbatt_list; 761 struct lo_g_saved_values uninitialized_var(saved_regs);
1019 const struct b43_rfatt_list *rfatt_list;
1020
1021 /* Values from the "TXCTL Register and Value Table" */ 762 /* Values from the "TXCTL Register and Value Table" */
1022 u16 txctl_reg; 763 u16 txctl_reg;
1023 u16 txctl_value; 764 u16 txctl_value;
1024 u16 pad_mix_gain; 765 u16 pad_mix_gain;
1025 766
1026 bbatt_list = &lo->bbatt_list; 767 saved_regs.old_channel = phy->channel;
1027 rfatt_list = &lo->rfatt_list; 768 b43_mac_suspend(dev);
1028#if B43_CALIB_ALL_LOCTLS 769 lo_measure_setup(dev, &saved_regs);
1029 bbatt_list = &b43_full_bbatt_list;
1030 rfatt_list = &b43_full_rfatt_list;
1031#endif
1032 770
1033 txctl_reg = lo_txctl_register_table(dev, &txctl_value, &pad_mix_gain); 771 txctl_reg = lo_txctl_register_table(dev, &txctl_value, &pad_mix_gain);
1034 772
1035 for (rfidx = 0; rfidx < rfatt_list->len; rfidx++) { 773 b43_radio_write16(dev, 0x43,
1036 774 (b43_radio_read16(dev, 0x43) & 0xFFF0)
1037 b43_radio_write16(dev, 0x43, (b43_radio_read16(dev, 0x43) 775 | rfatt->att);
1038 & 0xFFF0) | 776 b43_radio_write16(dev, txctl_reg,
1039 rfatt_list->list[rfidx].att); 777 (b43_radio_read16(dev, txctl_reg) & ~txctl_value)
1040 b43_radio_write16(dev, txctl_reg, 778 | (rfatt->with_padmix) ? txctl_value : 0);
1041 (b43_radio_read16(dev, txctl_reg)
1042 & ~txctl_value)
1043 | (rfatt_list->list[rfidx].with_padmix ?
1044 txctl_value : 0));
1045
1046 for (bbidx = 0; bbidx < bbatt_list->len; bbidx++) {
1047 if (lo->rebuild) {
1048#if B43_CALIB_ALL_LOCTLS
1049 ploctl = b43_get_lo_g_ctl(dev,
1050 &rfatt_list->list[rfidx],
1051 &bbatt_list->list[bbidx]);
1052#else
1053 ploctl = b43_get_lo_g_ctl_nopadmix(dev,
1054 &rfatt_list->
1055 list[rfidx],
1056 &bbatt_list->
1057 list[bbidx]);
1058#endif
1059 } else {
1060 ploctl = b43_get_lo_g_ctl(dev,
1061 &rfatt_list->list[rfidx],
1062 &bbatt_list->list[bbidx]);
1063 if (!ploctl->used)
1064 continue;
1065 }
1066 memcpy(&loctl, ploctl, sizeof(loctl));
1067 loctl.i = 0;
1068 loctl.q = 0;
1069
1070 max_rx_gain = rfatt_list->list[rfidx].att * 2;
1071 max_rx_gain += bbatt_list->list[bbidx].att / 2;
1072 if (rfatt_list->list[rfidx].with_padmix)
1073 max_rx_gain -= pad_mix_gain;
1074 if (has_loopback_gain(phy))
1075 max_rx_gain += phy->max_lb_gain;
1076 lo_measure_gain_values(dev, max_rx_gain,
1077 has_loopback_gain(phy));
1078
1079 b43_phy_set_baseband_attenuation(dev,
1080 bbatt_list->list[bbidx].att);
1081 lo_probe_loctls_statemachine(dev, &loctl, &max_rx_gain);
1082 if (phy->type == B43_PHYTYPE_B) {
1083 loctl.i++;
1084 loctl.q++;
1085 }
1086 b43_loctl_set_calibrated(&loctl, 1);
1087 memcpy(ploctl, &loctl, sizeof(loctl));
1088 }
1089 }
1090}
1091
1092#if B43_DEBUG
1093static void do_validate_loctl(struct b43_wldev *dev, struct b43_loctl *control)
1094{
1095 const int is_initializing = (b43_status(dev) == B43_STAT_UNINIT);
1096 int i = control->i;
1097 int q = control->q;
1098 779
1099 if (b43_loctl_is_calibrated(control)) { 780 max_rx_gain = rfatt->att * 2;
1100 if ((abs(i) > 16) || (abs(q) > 16)) 781 max_rx_gain += bbatt->att / 2;
1101 goto error; 782 if (rfatt->with_padmix)
1102 } else { 783 max_rx_gain -= pad_mix_gain;
1103 if (control->used) 784 if (has_loopback_gain(phy))
1104 goto error; 785 max_rx_gain += phy->max_lb_gain;
1105 if (dev->phy.lo_control->rebuild) { 786 lo_measure_gain_values(dev, max_rx_gain,
1106 control->i = 0; 787 has_loopback_gain(phy));
1107 control->q = 0; 788
1108 if ((i != B43_LOCTL_POISON) || 789 b43_phy_set_baseband_attenuation(dev, bbatt->att);
1109 (q != B43_LOCTL_POISON)) 790 lo_probe_loctls_statemachine(dev, &loctl, &max_rx_gain);
1110 goto error; 791
1111 } 792 lo_measure_restore(dev, &saved_regs);
793 b43_mac_enable(dev);
794
795 if (b43_debug(dev, B43_DBG_LO)) {
796 b43dbg(dev->wl, "LO: Calibrated for BB(%u), RF(%u,%u) "
797 "=> I=%d Q=%d\n",
798 bbatt->att, rfatt->att, rfatt->with_padmix,
799 loctl.i, loctl.q);
1112 } 800 }
1113 if (is_initializing && control->used)
1114 goto error;
1115
1116 return;
1117error:
1118 b43err(dev->wl, "LO control pair validation failed "
1119 "(I: %d, Q: %d, used %u, calib: %u, initing: %d)\n",
1120 i, q, control->used,
1121 b43_loctl_is_calibrated(control),
1122 is_initializing);
1123}
1124 801
1125static void validate_all_loctls(struct b43_wldev *dev) 802 cal = kmalloc(sizeof(*cal), GFP_KERNEL);
1126{ 803 if (!cal) {
1127 b43_call_for_each_loctl(dev, do_validate_loctl); 804 b43warn(dev->wl, "LO calib: out of memory\n");
1128} 805 return NULL;
1129
1130static void do_reset_calib(struct b43_wldev *dev, struct b43_loctl *control)
1131{
1132 if (dev->phy.lo_control->rebuild ||
1133 control->used) {
1134 b43_loctl_set_calibrated(control, 0);
1135 control->i = B43_LOCTL_POISON;
1136 control->q = B43_LOCTL_POISON;
1137 } 806 }
807 memcpy(&cal->bbatt, bbatt, sizeof(*bbatt));
808 memcpy(&cal->rfatt, rfatt, sizeof(*rfatt));
809 memcpy(&cal->ctl, &loctl, sizeof(loctl));
810 cal->calib_time = jiffies;
811 INIT_LIST_HEAD(&cal->list);
812
813 return cal;
1138} 814}
1139 815
1140static void reset_all_loctl_calibration_states(struct b43_wldev *dev) 816/* Get a calibrated LO setting for the given attenuation values.
817 * Might return a NULL pointer under OOM! */
818static
819struct b43_lo_calib * b43_get_calib_lo_settings(struct b43_wldev *dev,
820 const struct b43_bbatt *bbatt,
821 const struct b43_rfatt *rfatt)
1141{ 822{
1142 b43_call_for_each_loctl(dev, do_reset_calib); 823 struct b43_txpower_lo_control *lo = dev->phy.lo_control;
824 struct b43_lo_calib *c;
825
826 c = b43_find_lo_calib(lo, bbatt, rfatt);
827 if (c)
828 return c;
829 /* Not in the list of calibrated LO settings.
830 * Calibrate it now. */
831 c = b43_calibrate_lo_setting(dev, bbatt, rfatt);
832 if (!c)
833 return NULL;
834 list_add(&c->list, &lo->calib_list);
835
836 return c;
1143} 837}
1144 838
1145#else /* B43_DEBUG */ 839void b43_gphy_dc_lt_init(struct b43_wldev *dev, bool update_all)
1146static inline void validate_all_loctls(struct b43_wldev *dev) { }
1147static inline void reset_all_loctl_calibration_states(struct b43_wldev *dev) { }
1148#endif /* B43_DEBUG */
1149
1150void b43_lo_g_measure(struct b43_wldev *dev)
1151{ 840{
1152 struct b43_phy *phy = &dev->phy; 841 struct b43_phy *phy = &dev->phy;
1153 struct lo_g_saved_values uninitialized_var(sav); 842 struct b43_txpower_lo_control *lo = phy->lo_control;
1154 843 int i;
1155 B43_WARN_ON((phy->type != B43_PHYTYPE_B) && 844 int rf_offset, bb_offset;
1156 (phy->type != B43_PHYTYPE_G)); 845 const struct b43_rfatt *rfatt;
1157 846 const struct b43_bbatt *bbatt;
1158 sav.old_channel = phy->channel; 847 u64 power_vector;
1159 lo_measure_setup(dev, &sav); 848 bool table_changed = 0;
1160 reset_all_loctl_calibration_states(dev);
1161 lo_measure(dev);
1162 lo_measure_restore(dev, &sav);
1163
1164 validate_all_loctls(dev);
1165 849
1166 phy->lo_control->lo_measured = 1; 850 BUILD_BUG_ON(B43_DC_LT_SIZE != 32);
1167 phy->lo_control->rebuild = 0; 851 B43_WARN_ON(lo->rfatt_list.len * lo->bbatt_list.len > 64);
1168}
1169 852
1170#if B43_DEBUG 853 power_vector = lo->power_vector;
1171static void validate_loctl_calibration(struct b43_wldev *dev, 854 if (!update_all && !power_vector)
1172 struct b43_loctl *loctl, 855 return; /* Nothing to do. */
1173 struct b43_rfatt *rfatt, 856
1174 struct b43_bbatt *bbatt) 857 /* Suspend the MAC now to avoid continuous suspend/enable
1175{ 858 * cycles in the loop. */
1176 if (b43_loctl_is_calibrated(loctl)) 859 b43_mac_suspend(dev);
1177 return; 860
1178 if (!dev->phy.lo_control->lo_measured) { 861 for (i = 0; i < B43_DC_LT_SIZE * 2; i++) {
1179 /* On init we set the attenuation values before we 862 struct b43_lo_calib *cal;
1180 * calibrated the LO. I guess that's OK. */ 863 int idx;
1181 return; 864 u16 val;
865
866 if (!update_all && !(power_vector & (((u64)1ULL) << i)))
867 continue;
868 /* Update the table entry for this power_vector bit.
869 * The table rows are RFatt entries and columns are BBatt. */
870 bb_offset = i / lo->rfatt_list.len;
871 rf_offset = i % lo->rfatt_list.len;
872 bbatt = &(lo->bbatt_list.list[bb_offset]);
873 rfatt = &(lo->rfatt_list.list[rf_offset]);
874
875 cal = b43_calibrate_lo_setting(dev, bbatt, rfatt);
876 if (!cal) {
877 b43warn(dev->wl, "LO: Could not "
878 "calibrate DC table entry\n");
879 continue;
880 }
881 /*FIXME: Is Q really in the low nibble? */
882 val = (u8)(cal->ctl.q);
883 val |= ((u8)(cal->ctl.i)) << 4;
884 kfree(cal);
885
886 /* Get the index into the hardware DC LT. */
887 idx = i / 2;
888 /* Change the table in memory. */
889 if (i % 2) {
890 /* Change the high byte. */
891 lo->dc_lt[idx] = (lo->dc_lt[idx] & 0x00FF)
892 | ((val & 0x00FF) << 8);
893 } else {
894 /* Change the low byte. */
895 lo->dc_lt[idx] = (lo->dc_lt[idx] & 0xFF00)
896 | (val & 0x00FF);
897 }
898 table_changed = 1;
1182 } 899 }
1183 b43err(dev->wl, "Adjusting Local Oscillator to an uncalibrated " 900 if (table_changed) {
1184 "control pair: rfatt=%u,%spadmix bbatt=%u\n", 901 /* The table changed in memory. Update the hardware table. */
1185 rfatt->att, 902 for (i = 0; i < B43_DC_LT_SIZE; i++)
1186 (rfatt->with_padmix) ? "" : "no-", 903 b43_phy_write(dev, 0x3A0 + i, lo->dc_lt[i]);
1187 bbatt->att); 904 }
1188} 905 b43_mac_enable(dev);
1189#else
1190static inline void validate_loctl_calibration(struct b43_wldev *dev,
1191 struct b43_loctl *loctl,
1192 struct b43_rfatt *rfatt,
1193 struct b43_bbatt *bbatt)
1194{
1195} 906}
1196#endif
1197 907
1198static inline void fixup_rfatt_for_txcontrol(struct b43_rfatt *rf, 908/* Fixup the RF attenuation value for the case where we are
1199 u8 tx_control) 909 * using the PAD mixer. */
910static inline void b43_lo_fixup_rfatt(struct b43_rfatt *rf)
1200{ 911{
1201 if (tx_control & B43_TXCTL_TXMIX) { 912 if (!rf->with_padmix)
1202 if (rf->att < 5) 913 return;
1203 rf->att = 4; 914 if ((rf->att != 1) && (rf->att != 2) && (rf->att != 3))
1204 } 915 rf->att = 4;
1205} 916}
1206 917
1207void b43_lo_g_adjust(struct b43_wldev *dev) 918void b43_lo_g_adjust(struct b43_wldev *dev)
1208{ 919{
1209 struct b43_phy *phy = &dev->phy; 920 struct b43_phy *phy = &dev->phy;
921 struct b43_lo_calib *cal;
1210 struct b43_rfatt rf; 922 struct b43_rfatt rf;
1211 struct b43_loctl *loctl;
1212 923
1213 memcpy(&rf, &phy->rfatt, sizeof(rf)); 924 memcpy(&rf, &phy->rfatt, sizeof(rf));
1214 fixup_rfatt_for_txcontrol(&rf, phy->tx_control); 925 b43_lo_fixup_rfatt(&rf);
1215 926
1216 loctl = b43_get_lo_g_ctl(dev, &rf, &phy->bbatt); 927 cal = b43_get_calib_lo_settings(dev, &phy->bbatt, &rf);
1217 validate_loctl_calibration(dev, loctl, &rf, &phy->bbatt); 928 if (!cal)
1218 b43_lo_write(dev, loctl); 929 return;
930 b43_lo_write(dev, &cal->ctl);
1219} 931}
1220 932
1221void b43_lo_g_adjust_to(struct b43_wldev *dev, 933void b43_lo_g_adjust_to(struct b43_wldev *dev,
@@ -1223,39 +935,102 @@ void b43_lo_g_adjust_to(struct b43_wldev *dev,
1223{ 935{
1224 struct b43_rfatt rf; 936 struct b43_rfatt rf;
1225 struct b43_bbatt bb; 937 struct b43_bbatt bb;
1226 struct b43_loctl *loctl; 938 struct b43_lo_calib *cal;
1227 939
1228 memset(&rf, 0, sizeof(rf)); 940 memset(&rf, 0, sizeof(rf));
1229 memset(&bb, 0, sizeof(bb)); 941 memset(&bb, 0, sizeof(bb));
1230 rf.att = rfatt; 942 rf.att = rfatt;
1231 bb.att = bbatt; 943 bb.att = bbatt;
1232 fixup_rfatt_for_txcontrol(&rf, tx_control); 944 b43_lo_fixup_rfatt(&rf);
1233 loctl = b43_get_lo_g_ctl(dev, &rf, &bb); 945 cal = b43_get_calib_lo_settings(dev, &bb, &rf);
1234 validate_loctl_calibration(dev, loctl, &rf, &bb); 946 if (!cal)
1235 b43_lo_write(dev, loctl); 947 return;
948 b43_lo_write(dev, &cal->ctl);
1236} 949}
1237 950
1238static void do_mark_unused(struct b43_wldev *dev, struct b43_loctl *control) 951/* Periodic LO maintanance work */
952void b43_lo_g_maintanance_work(struct b43_wldev *dev)
1239{ 953{
1240 control->used = 0; 954 struct b43_phy *phy = &dev->phy;
955 struct b43_txpower_lo_control *lo = phy->lo_control;
956 unsigned long now;
957 unsigned long expire;
958 struct b43_lo_calib *cal, *tmp;
959 bool current_item_expired = 0;
960 bool hwpctl;
961
962 if (!lo)
963 return;
964 now = jiffies;
965 hwpctl = b43_has_hardware_pctl(phy);
966
967 if (hwpctl) {
968 /* Read the power vector and update it, if needed. */
969 expire = now - B43_LO_PWRVEC_EXPIRE;
970 if (time_before(lo->pwr_vec_read_time, expire)) {
971 lo_read_power_vector(dev);
972 b43_gphy_dc_lt_init(dev, 0);
973 }
974 //FIXME Recalc the whole DC table from time to time?
975 }
976
977 if (hwpctl)
978 return;
979 /* Search for expired LO settings. Remove them.
980 * Recalibrate the current setting, if expired. */
981 expire = now - B43_LO_CALIB_EXPIRE;
982 list_for_each_entry_safe(cal, tmp, &lo->calib_list, list) {
983 if (!time_before(cal->calib_time, expire))
984 continue;
985 /* This item expired. */
986 if (b43_compare_bbatt(&cal->bbatt, &phy->bbatt) &&
987 b43_compare_rfatt(&cal->rfatt, &phy->rfatt)) {
988 B43_WARN_ON(current_item_expired);
989 current_item_expired = 1;
990 }
991 if (b43_debug(dev, B43_DBG_LO)) {
992 b43dbg(dev->wl, "LO: Item BB(%u), RF(%u,%u), "
993 "I=%d, Q=%d expired\n",
994 cal->bbatt.att, cal->rfatt.att,
995 cal->rfatt.with_padmix,
996 cal->ctl.i, cal->ctl.q);
997 }
998 list_del(&cal->list);
999 kfree(cal);
1000 }
1001 if (current_item_expired || unlikely(list_empty(&lo->calib_list))) {
1002 /* Recalibrate currently used LO setting. */
1003 if (b43_debug(dev, B43_DBG_LO))
1004 b43dbg(dev->wl, "LO: Recalibrating current LO setting\n");
1005 cal = b43_calibrate_lo_setting(dev, &phy->bbatt, &phy->rfatt);
1006 if (cal) {
1007 list_add(&cal->list, &lo->calib_list);
1008 b43_lo_write(dev, &cal->ctl);
1009 } else
1010 b43warn(dev->wl, "Failed to recalibrate current LO setting\n");
1011 }
1241} 1012}
1242 1013
1243void b43_lo_g_ctl_mark_all_unused(struct b43_wldev *dev) 1014void b43_lo_g_cleanup(struct b43_wldev *dev)
1244{ 1015{
1245 struct b43_phy *phy = &dev->phy; 1016 struct b43_txpower_lo_control *lo = dev->phy.lo_control;
1246 struct b43_txpower_lo_control *lo = phy->lo_control; 1017 struct b43_lo_calib *cal, *tmp;
1247 1018
1248 b43_call_for_each_loctl(dev, do_mark_unused); 1019 if (!lo)
1249 lo->rebuild = 1; 1020 return;
1021 list_for_each_entry_safe(cal, tmp, &lo->calib_list, list) {
1022 list_del(&cal->list);
1023 kfree(cal);
1024 }
1250} 1025}
1251 1026
1252void b43_lo_g_ctl_mark_cur_used(struct b43_wldev *dev) 1027/* LO Initialization */
1028void b43_lo_g_init(struct b43_wldev *dev)
1253{ 1029{
1254 struct b43_phy *phy = &dev->phy; 1030 struct b43_phy *phy = &dev->phy;
1255 struct b43_rfatt rf;
1256 1031
1257 memcpy(&rf, &phy->rfatt, sizeof(rf)); 1032 if (b43_has_hardware_pctl(phy)) {
1258 fixup_rfatt_for_txcontrol(&rf, phy->tx_control); 1033 lo_read_power_vector(dev);
1259 1034 b43_gphy_dc_lt_init(dev, 1);
1260 b43_get_lo_g_ctl(dev, &rf, &phy->bbatt)->used = 1; 1035 }
1261} 1036}
diff --git a/drivers/net/wireless/b43/lo.h b/drivers/net/wireless/b43/lo.h
index 455615d1f8c6..1da321cabc12 100644
--- a/drivers/net/wireless/b43/lo.h
+++ b/drivers/net/wireless/b43/lo.h
@@ -10,82 +10,63 @@ struct b43_loctl {
10 /* Control values. */ 10 /* Control values. */
11 s8 i; 11 s8 i;
12 s8 q; 12 s8 q;
13 /* "Used by hardware" flag. */
14 bool used;
15#ifdef CONFIG_B43_DEBUG
16 /* Is this lo-control-array entry calibrated? */
17 bool calibrated;
18#endif
19}; 13};
20
21/* Debugging: Poison value for i and q values. */ 14/* Debugging: Poison value for i and q values. */
22#define B43_LOCTL_POISON 111 15#define B43_LOCTL_POISON 111
23 16
24/* loctl->calibrated debugging mechanism */ 17/* This struct holds calibrated LO settings for a set of
25#ifdef CONFIG_B43_DEBUG 18 * Baseband and RF attenuation settings. */
26static inline void b43_loctl_set_calibrated(struct b43_loctl *loctl, 19struct b43_lo_calib {
27 bool calibrated) 20 /* The set of attenuation values this set of LO
28{ 21 * control values is calibrated for. */
29 loctl->calibrated = calibrated; 22 struct b43_bbatt bbatt;
30} 23 struct b43_rfatt rfatt;
31static inline bool b43_loctl_is_calibrated(struct b43_loctl *loctl) 24 /* The set of control values for the LO. */
32{ 25 struct b43_loctl ctl;
33 return loctl->calibrated; 26 /* The time when these settings were calibrated (in jiffies) */
34} 27 unsigned long calib_time;
35#else 28 /* List. */
36static inline void b43_loctl_set_calibrated(struct b43_loctl *loctl, 29 struct list_head list;
37 bool calibrated) 30};
38{ 31
39} 32/* Size of the DC Lookup Table in 16bit words. */
40static inline bool b43_loctl_is_calibrated(struct b43_loctl *loctl) 33#define B43_DC_LT_SIZE 32
41{ 34
42 return 1; 35/* Local Oscillator calibration information */
43}
44#endif
45
46/* TX Power LO Control Array.
47 * Value-pairs to adjust the LocalOscillator are stored
48 * in this structure.
49 * There are two different set of values. One for "Flag is Set"
50 * and one for "Flag is Unset".
51 * By "Flag" the flag in struct b43_rfatt is meant.
52 * The Value arrays are two-dimensional. The first index
53 * is the baseband attenuation and the second index
54 * is the radio attenuation.
55 * Use b43_get_lo_g_ctl() to retrieve a value from the lists.
56 */
57struct b43_txpower_lo_control { 36struct b43_txpower_lo_control {
58#define B43_NR_BB 12 37 /* Lists of RF and BB attenuation values for this device.
59#define B43_NR_RF 16 38 * Used for building hardware power control tables. */
60 /* LO Control values, with PAD Mixer */
61 struct b43_loctl with_padmix[B43_NR_BB][B43_NR_RF];
62 /* LO Control values, without PAD Mixer */
63 struct b43_loctl no_padmix[B43_NR_BB][B43_NR_RF];
64
65 /* Flag to indicate a complete rebuild of the two tables above
66 * to the LO measuring code. */
67 bool rebuild;
68
69 /* Lists of valid RF and BB attenuation values for this device. */
70 struct b43_rfatt_list rfatt_list; 39 struct b43_rfatt_list rfatt_list;
71 struct b43_bbatt_list bbatt_list; 40 struct b43_bbatt_list bbatt_list;
72 41
42 /* The DC Lookup Table is cached in memory here.
43 * Note that this is only used for Hardware Power Control. */
44 u16 dc_lt[B43_DC_LT_SIZE];
45
46 /* List of calibrated control values (struct b43_lo_calib). */
47 struct list_head calib_list;
48 /* Last time the power vector was read (jiffies). */
49 unsigned long pwr_vec_read_time;
50 /* Last time the txctl values were measured (jiffies). */
51 unsigned long txctl_measured_time;
52
73 /* Current TX Bias value */ 53 /* Current TX Bias value */
74 u8 tx_bias; 54 u8 tx_bias;
75 /* Current TX Magnification Value (if used by the device) */ 55 /* Current TX Magnification Value (if used by the device) */
76 u8 tx_magn; 56 u8 tx_magn;
77 57
78 /* GPHY LO is measured. */
79 bool lo_measured;
80
81 /* Saved device PowerVector */ 58 /* Saved device PowerVector */
82 u64 power_vector; 59 u64 power_vector;
83}; 60};
84 61
85/* Measure the BPHY Local Oscillator. */ 62/* Calibration expire timeouts.
86void b43_lo_b_measure(struct b43_wldev *dev); 63 * Timeouts must be multiple of 15 seconds. To make sure
87/* Measure the BPHY/GPHY Local Oscillator. */ 64 * the item really expired when the 15 second timer hits, we
88void b43_lo_g_measure(struct b43_wldev *dev); 65 * subtract two additional seconds from the timeout. */
66#define B43_LO_CALIB_EXPIRE (HZ * (30 - 2))
67#define B43_LO_PWRVEC_EXPIRE (HZ * (30 - 2))
68#define B43_LO_TXCTL_EXPIRE (HZ * (180 - 4))
69
89 70
90/* Adjust the Local Oscillator to the saved attenuation 71/* Adjust the Local Oscillator to the saved attenuation
91 * and txctl values. 72 * and txctl values.
@@ -95,18 +76,10 @@ void b43_lo_g_adjust(struct b43_wldev *dev);
95void b43_lo_g_adjust_to(struct b43_wldev *dev, 76void b43_lo_g_adjust_to(struct b43_wldev *dev,
96 u16 rfatt, u16 bbatt, u16 tx_control); 77 u16 rfatt, u16 bbatt, u16 tx_control);
97 78
98/* Mark all possible b43_lo_g_ctl as "unused" */ 79void b43_gphy_dc_lt_init(struct b43_wldev *dev, bool update_all);
99void b43_lo_g_ctl_mark_all_unused(struct b43_wldev *dev);
100/* Mark the b43_lo_g_ctl corresponding to the current
101 * attenuation values as used.
102 */
103void b43_lo_g_ctl_mark_cur_used(struct b43_wldev *dev);
104 80
105/* Get a reference to a LO Control value pair in the 81void b43_lo_g_maintanance_work(struct b43_wldev *dev);
106 * TX Power LO Control Array. 82void b43_lo_g_cleanup(struct b43_wldev *dev);
107 */ 83void b43_lo_g_init(struct b43_wldev *dev);
108struct b43_loctl *b43_get_lo_g_ctl(struct b43_wldev *dev,
109 const struct b43_rfatt *rfatt,
110 const struct b43_bbatt *bbatt);
111 84
112#endif /* B43_LO_H_ */ 85#endif /* B43_LO_H_ */
diff --git a/drivers/net/wireless/b43/main.c b/drivers/net/wireless/b43/main.c
index 8fdba9415c04..c6e79a15d3cb 100644
--- a/drivers/net/wireless/b43/main.c
+++ b/drivers/net/wireless/b43/main.c
@@ -2308,7 +2308,7 @@ static void b43_gpio_cleanup(struct b43_wldev *dev)
2308} 2308}
2309 2309
2310/* http://bcm-specs.sipsolutions.net/EnableMac */ 2310/* http://bcm-specs.sipsolutions.net/EnableMac */
2311static void b43_mac_enable(struct b43_wldev *dev) 2311void b43_mac_enable(struct b43_wldev *dev)
2312{ 2312{
2313 dev->mac_suspended--; 2313 dev->mac_suspended--;
2314 B43_WARN_ON(dev->mac_suspended < 0); 2314 B43_WARN_ON(dev->mac_suspended < 0);
@@ -2322,16 +2322,11 @@ static void b43_mac_enable(struct b43_wldev *dev)
2322 b43_read32(dev, B43_MMIO_MACCTL); 2322 b43_read32(dev, B43_MMIO_MACCTL);
2323 b43_read32(dev, B43_MMIO_GEN_IRQ_REASON); 2323 b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
2324 b43_power_saving_ctl_bits(dev, 0); 2324 b43_power_saving_ctl_bits(dev, 0);
2325
2326 /* Re-enable IRQs. */
2327 spin_lock_irq(&dev->wl->irq_lock);
2328 b43_interrupt_enable(dev, dev->irq_savedstate);
2329 spin_unlock_irq(&dev->wl->irq_lock);
2330 } 2325 }
2331} 2326}
2332 2327
2333/* http://bcm-specs.sipsolutions.net/SuspendMAC */ 2328/* http://bcm-specs.sipsolutions.net/SuspendMAC */
2334static void b43_mac_suspend(struct b43_wldev *dev) 2329void b43_mac_suspend(struct b43_wldev *dev)
2335{ 2330{
2336 int i; 2331 int i;
2337 u32 tmp; 2332 u32 tmp;
@@ -2340,14 +2335,6 @@ static void b43_mac_suspend(struct b43_wldev *dev)
2340 B43_WARN_ON(dev->mac_suspended < 0); 2335 B43_WARN_ON(dev->mac_suspended < 0);
2341 2336
2342 if (dev->mac_suspended == 0) { 2337 if (dev->mac_suspended == 0) {
2343 /* Mask IRQs before suspending MAC. Otherwise
2344 * the MAC stays busy and won't suspend. */
2345 spin_lock_irq(&dev->wl->irq_lock);
2346 tmp = b43_interrupt_disable(dev, B43_IRQ_ALL);
2347 spin_unlock_irq(&dev->wl->irq_lock);
2348 b43_synchronize_irq(dev);
2349 dev->irq_savedstate = tmp;
2350
2351 b43_power_saving_ctl_bits(dev, B43_PS_AWAKE); 2338 b43_power_saving_ctl_bits(dev, B43_PS_AWAKE);
2352 b43_write32(dev, B43_MMIO_MACCTL, 2339 b43_write32(dev, B43_MMIO_MACCTL,
2353 b43_read32(dev, B43_MMIO_MACCTL) 2340 b43_read32(dev, B43_MMIO_MACCTL)
@@ -2503,6 +2490,7 @@ static void b43_chip_exit(struct b43_wldev *dev)
2503{ 2490{
2504 b43_radio_turn_off(dev, 1); 2491 b43_radio_turn_off(dev, 1);
2505 b43_gpio_cleanup(dev); 2492 b43_gpio_cleanup(dev);
2493 b43_lo_g_cleanup(dev);
2506 /* firmware is released later */ 2494 /* firmware is released later */
2507} 2495}
2508 2496
@@ -2609,28 +2597,12 @@ err_gpio_clean:
2609 return err; 2597 return err;
2610} 2598}
2611 2599
2612static void b43_periodic_every120sec(struct b43_wldev *dev)
2613{
2614 struct b43_phy *phy = &dev->phy;
2615
2616 if (phy->type != B43_PHYTYPE_G || phy->rev < 2)
2617 return;
2618
2619 b43_mac_suspend(dev);
2620 b43_lo_g_measure(dev);
2621 b43_mac_enable(dev);
2622 if (b43_has_hardware_pctl(phy))
2623 b43_lo_g_ctl_mark_all_unused(dev);
2624}
2625
2626static void b43_periodic_every60sec(struct b43_wldev *dev) 2600static void b43_periodic_every60sec(struct b43_wldev *dev)
2627{ 2601{
2628 struct b43_phy *phy = &dev->phy; 2602 struct b43_phy *phy = &dev->phy;
2629 2603
2630 if (phy->type != B43_PHYTYPE_G) 2604 if (phy->type != B43_PHYTYPE_G)
2631 return; 2605 return;
2632 if (!b43_has_hardware_pctl(phy))
2633 b43_lo_g_ctl_mark_all_unused(dev);
2634 if (dev->dev->bus->sprom.boardflags_lo & B43_BFL_RSSI) { 2606 if (dev->dev->bus->sprom.boardflags_lo & B43_BFL_RSSI) {
2635 b43_mac_suspend(dev); 2607 b43_mac_suspend(dev);
2636 b43_calc_nrssi_slope(dev); 2608 b43_calc_nrssi_slope(dev);
@@ -2682,6 +2654,7 @@ static void b43_periodic_every15sec(struct b43_wldev *dev)
2682 } 2654 }
2683 } 2655 }
2684 b43_phy_xmitpower(dev); //FIXME: unless scanning? 2656 b43_phy_xmitpower(dev); //FIXME: unless scanning?
2657 b43_lo_g_maintanance_work(dev);
2685 //TODO for APHY (temperature?) 2658 //TODO for APHY (temperature?)
2686 2659
2687 atomic_set(&phy->txerr_cnt, B43_PHY_TX_BADNESS_LIMIT); 2660 atomic_set(&phy->txerr_cnt, B43_PHY_TX_BADNESS_LIMIT);
@@ -2693,8 +2666,6 @@ static void do_periodic_work(struct b43_wldev *dev)
2693 unsigned int state; 2666 unsigned int state;
2694 2667
2695 state = dev->periodic_state; 2668 state = dev->periodic_state;
2696 if (state % 8 == 0)
2697 b43_periodic_every120sec(dev);
2698 if (state % 4 == 0) 2669 if (state % 4 == 0)
2699 b43_periodic_every60sec(dev); 2670 b43_periodic_every60sec(dev);
2700 if (state % 2 == 0) 2671 if (state % 2 == 0)
@@ -3025,8 +2996,7 @@ static void b43_qos_update_work(struct work_struct *work)
3025 mutex_unlock(&wl->mutex); 2996 mutex_unlock(&wl->mutex);
3026} 2997}
3027 2998
3028static int b43_op_conf_tx(struct ieee80211_hw *hw, 2999static int b43_op_conf_tx(struct ieee80211_hw *hw, u16 _queue,
3029 int _queue,
3030 const struct ieee80211_tx_queue_params *params) 3000 const struct ieee80211_tx_queue_params *params)
3031{ 3001{
3032 struct b43_wl *wl = hw_to_b43_wl(hw); 3002 struct b43_wl *wl = hw_to_b43_wl(hw);
@@ -3668,8 +3638,8 @@ static void setup_struct_phy_for_init(struct b43_wldev *dev,
3668 lo = phy->lo_control; 3638 lo = phy->lo_control;
3669 if (lo) { 3639 if (lo) {
3670 memset(lo, 0, sizeof(*(phy->lo_control))); 3640 memset(lo, 0, sizeof(*(phy->lo_control)));
3671 lo->rebuild = 1;
3672 lo->tx_bias = 0xFF; 3641 lo->tx_bias = 0xFF;
3642 INIT_LIST_HEAD(&lo->calib_list);
3673 } 3643 }
3674 phy->max_lb_gain = 0; 3644 phy->max_lb_gain = 0;
3675 phy->trsw_rx_gain = 0; 3645 phy->trsw_rx_gain = 0;
diff --git a/drivers/net/wireless/b43/main.h b/drivers/net/wireless/b43/main.h
index 5230aeca78bf..dad23c42b422 100644
--- a/drivers/net/wireless/b43/main.h
+++ b/drivers/net/wireless/b43/main.h
@@ -114,4 +114,7 @@ void b43_controller_restart(struct b43_wldev *dev, const char *reason);
114#define B43_PS_ASLEEP (1 << 3) /* Force device asleep */ 114#define B43_PS_ASLEEP (1 << 3) /* Force device asleep */
115void b43_power_saving_ctl_bits(struct b43_wldev *dev, unsigned int ps_flags); 115void b43_power_saving_ctl_bits(struct b43_wldev *dev, unsigned int ps_flags);
116 116
117void b43_mac_suspend(struct b43_wldev *dev);
118void b43_mac_enable(struct b43_wldev *dev);
119
117#endif /* B43_MAIN_H_ */ 120#endif /* B43_MAIN_H_ */
diff --git a/drivers/net/wireless/b43/phy.c b/drivers/net/wireless/b43/phy.c
index de024dc03718..8b3c24da8db9 100644
--- a/drivers/net/wireless/b43/phy.c
+++ b/drivers/net/wireless/b43/phy.c
@@ -145,8 +145,7 @@ static void generate_rfatt_list(struct b43_wldev *dev,
145 {.att = 9,.with_padmix = 1,}, 145 {.att = 9,.with_padmix = 1,},
146 }; 146 };
147 147
148 if ((phy->type == B43_PHYTYPE_A && phy->rev < 5) || 148 if (!b43_has_hardware_pctl(phy)) {
149 (phy->type == B43_PHYTYPE_G && phy->rev < 6)) {
150 /* Software pctl */ 149 /* Software pctl */
151 list->list = rfatt_0; 150 list->list = rfatt_0;
152 list->len = ARRAY_SIZE(rfatt_0); 151 list->len = ARRAY_SIZE(rfatt_0);
@@ -158,7 +157,7 @@ static void generate_rfatt_list(struct b43_wldev *dev,
158 /* Hardware pctl */ 157 /* Hardware pctl */
159 list->list = rfatt_1; 158 list->list = rfatt_1;
160 list->len = ARRAY_SIZE(rfatt_1); 159 list->len = ARRAY_SIZE(rfatt_1);
161 list->min_val = 2; 160 list->min_val = 0;
162 list->max_val = 14; 161 list->max_val = 14;
163 return; 162 return;
164 } 163 }
@@ -346,6 +345,7 @@ void b43_set_txpower_g(struct b43_wldev *dev,
346 /* Save the values for later */ 345 /* Save the values for later */
347 phy->tx_control = tx_control; 346 phy->tx_control = tx_control;
348 memcpy(&phy->rfatt, rfatt, sizeof(*rfatt)); 347 memcpy(&phy->rfatt, rfatt, sizeof(*rfatt));
348 phy->rfatt.with_padmix = !!(tx_control & B43_TXCTL_TXMIX);
349 memcpy(&phy->bbatt, bbatt, sizeof(*bbatt)); 349 memcpy(&phy->bbatt, bbatt, sizeof(*bbatt));
350 350
351 if (b43_debug(dev, B43_DBG_XMITPOWER)) { 351 if (b43_debug(dev, B43_DBG_XMITPOWER)) {
@@ -559,11 +559,6 @@ static void b43_gphy_gain_lt_init(struct b43_wldev *dev)
559 u16 tmp; 559 u16 tmp;
560 u8 rf, bb; 560 u8 rf, bb;
561 561
562 if (!lo->lo_measured) {
563 b43_phy_write(dev, 0x3FF, 0);
564 return;
565 }
566
567 for (rf = 0; rf < lo->rfatt_list.len; rf++) { 562 for (rf = 0; rf < lo->rfatt_list.len; rf++) {
568 for (bb = 0; bb < lo->bbatt_list.len; bb++) { 563 for (bb = 0; bb < lo->bbatt_list.len; bb++) {
569 if (nr_written >= 0x40) 564 if (nr_written >= 0x40)
@@ -581,42 +576,6 @@ static void b43_gphy_gain_lt_init(struct b43_wldev *dev)
581 } 576 }
582} 577}
583 578
584/* GPHY_DC_Lookup_Table */
585void b43_gphy_dc_lt_init(struct b43_wldev *dev)
586{
587 struct b43_phy *phy = &dev->phy;
588 struct b43_txpower_lo_control *lo = phy->lo_control;
589 struct b43_loctl *loctl0;
590 struct b43_loctl *loctl1;
591 int i;
592 int rf_offset, bb_offset;
593 u16 tmp;
594
595 for (i = 0; i < lo->rfatt_list.len + lo->bbatt_list.len; i += 2) {
596 rf_offset = i / lo->rfatt_list.len;
597 bb_offset = i % lo->rfatt_list.len;
598
599 loctl0 = b43_get_lo_g_ctl(dev, &lo->rfatt_list.list[rf_offset],
600 &lo->bbatt_list.list[bb_offset]);
601 if (i + 1 < lo->rfatt_list.len * lo->bbatt_list.len) {
602 rf_offset = (i + 1) / lo->rfatt_list.len;
603 bb_offset = (i + 1) % lo->rfatt_list.len;
604
605 loctl1 =
606 b43_get_lo_g_ctl(dev,
607 &lo->rfatt_list.list[rf_offset],
608 &lo->bbatt_list.list[bb_offset]);
609 } else
610 loctl1 = loctl0;
611
612 tmp = ((u16) loctl0->q & 0xF);
613 tmp |= ((u16) loctl0->i & 0xF) << 4;
614 tmp |= ((u16) loctl1->q & 0xF) << 8;
615 tmp |= ((u16) loctl1->i & 0xF) << 12; //FIXME?
616 b43_phy_write(dev, 0x3A0 + (i / 2), tmp);
617 }
618}
619
620static void hardware_pctl_init_aphy(struct b43_wldev *dev) 579static void hardware_pctl_init_aphy(struct b43_wldev *dev)
621{ 580{
622 //TODO 581 //TODO
@@ -643,7 +602,7 @@ static void hardware_pctl_init_gphy(struct b43_wldev *dev)
643 b43_phy_write(dev, 0x0801, b43_phy_read(dev, 0x0801) 602 b43_phy_write(dev, 0x0801, b43_phy_read(dev, 0x0801)
644 & 0xFFBF); 603 & 0xFFBF);
645 604
646 b43_gphy_dc_lt_init(dev); 605 b43_gphy_dc_lt_init(dev, 1);
647} 606}
648 607
649/* HardwarePowerControl init for A and G PHY */ 608/* HardwarePowerControl init for A and G PHY */
@@ -931,109 +890,6 @@ static void b43_phy_inita(struct b43_wldev *dev)
931 } 890 }
932} 891}
933 892
934static void b43_phy_initb2(struct b43_wldev *dev)
935{
936 struct b43_phy *phy = &dev->phy;
937 u16 offset, val;
938
939 b43_write16(dev, 0x03EC, 0x3F22);
940 b43_phy_write(dev, 0x0020, 0x301C);
941 b43_phy_write(dev, 0x0026, 0x0000);
942 b43_phy_write(dev, 0x0030, 0x00C6);
943 b43_phy_write(dev, 0x0088, 0x3E00);
944 val = 0x3C3D;
945 for (offset = 0x0089; offset < 0x00A7; offset++) {
946 b43_phy_write(dev, offset, val);
947 val -= 0x0202;
948 }
949 b43_phy_write(dev, 0x03E4, 0x3000);
950 b43_radio_selectchannel(dev, phy->channel, 0);
951 if (phy->radio_ver != 0x2050) {
952 b43_radio_write16(dev, 0x0075, 0x0080);
953 b43_radio_write16(dev, 0x0079, 0x0081);
954 }
955 b43_radio_write16(dev, 0x0050, 0x0020);
956 b43_radio_write16(dev, 0x0050, 0x0023);
957 if (phy->radio_ver == 0x2050) {
958 b43_radio_write16(dev, 0x0050, 0x0020);
959 b43_radio_write16(dev, 0x005A, 0x0070);
960 b43_radio_write16(dev, 0x005B, 0x007B);
961 b43_radio_write16(dev, 0x005C, 0x00B0);
962 b43_radio_write16(dev, 0x007A, 0x000F);
963 b43_phy_write(dev, 0x0038, 0x0677);
964 b43_radio_init2050(dev);
965 }
966 b43_phy_write(dev, 0x0014, 0x0080);
967 b43_phy_write(dev, 0x0032, 0x00CA);
968 b43_phy_write(dev, 0x0032, 0x00CC);
969 b43_phy_write(dev, 0x0035, 0x07C2);
970 b43_lo_b_measure(dev);
971 b43_phy_write(dev, 0x0026, 0xCC00);
972 if (phy->radio_ver != 0x2050)
973 b43_phy_write(dev, 0x0026, 0xCE00);
974 b43_write16(dev, B43_MMIO_CHANNEL_EXT, 0x1000);
975 b43_phy_write(dev, 0x002A, 0x88A3);
976 if (phy->radio_ver != 0x2050)
977 b43_phy_write(dev, 0x002A, 0x88C2);
978 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt, phy->tx_control);
979 b43_phy_init_pctl(dev);
980}
981
982static void b43_phy_initb4(struct b43_wldev *dev)
983{
984 struct b43_phy *phy = &dev->phy;
985 u16 offset, val;
986
987 b43_write16(dev, 0x03EC, 0x3F22);
988 b43_phy_write(dev, 0x0020, 0x301C);
989 b43_phy_write(dev, 0x0026, 0x0000);
990 b43_phy_write(dev, 0x0030, 0x00C6);
991 b43_phy_write(dev, 0x0088, 0x3E00);
992 val = 0x3C3D;
993 for (offset = 0x0089; offset < 0x00A7; offset++) {
994 b43_phy_write(dev, offset, val);
995 val -= 0x0202;
996 }
997 b43_phy_write(dev, 0x03E4, 0x3000);
998 b43_radio_selectchannel(dev, phy->channel, 0);
999 if (phy->radio_ver != 0x2050) {
1000 b43_radio_write16(dev, 0x0075, 0x0080);
1001 b43_radio_write16(dev, 0x0079, 0x0081);
1002 }
1003 b43_radio_write16(dev, 0x0050, 0x0020);
1004 b43_radio_write16(dev, 0x0050, 0x0023);
1005 if (phy->radio_ver == 0x2050) {
1006 b43_radio_write16(dev, 0x0050, 0x0020);
1007 b43_radio_write16(dev, 0x005A, 0x0070);
1008 b43_radio_write16(dev, 0x005B, 0x007B);
1009 b43_radio_write16(dev, 0x005C, 0x00B0);
1010 b43_radio_write16(dev, 0x007A, 0x000F);
1011 b43_phy_write(dev, 0x0038, 0x0677);
1012 b43_radio_init2050(dev);
1013 }
1014 b43_phy_write(dev, 0x0014, 0x0080);
1015 b43_phy_write(dev, 0x0032, 0x00CA);
1016 if (phy->radio_ver == 0x2050)
1017 b43_phy_write(dev, 0x0032, 0x00E0);
1018 b43_phy_write(dev, 0x0035, 0x07C2);
1019
1020 b43_lo_b_measure(dev);
1021
1022 b43_phy_write(dev, 0x0026, 0xCC00);
1023 if (phy->radio_ver == 0x2050)
1024 b43_phy_write(dev, 0x0026, 0xCE00);
1025 b43_write16(dev, B43_MMIO_CHANNEL_EXT, 0x1100);
1026 b43_phy_write(dev, 0x002A, 0x88A3);
1027 if (phy->radio_ver == 0x2050)
1028 b43_phy_write(dev, 0x002A, 0x88C2);
1029 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt, phy->tx_control);
1030 if (dev->dev->bus->sprom.boardflags_lo & B43_BFL_RSSI) {
1031 b43_calc_nrssi_slope(dev);
1032 b43_calc_nrssi_threshold(dev);
1033 }
1034 b43_phy_init_pctl(dev);
1035}
1036
1037static void b43_phy_initb5(struct b43_wldev *dev) 893static void b43_phy_initb5(struct b43_wldev *dev)
1038{ 894{
1039 struct ssb_bus *bus = dev->dev->bus; 895 struct ssb_bus *bus = dev->dev->bus;
@@ -1259,19 +1115,9 @@ static void b43_phy_initb6(struct b43_wldev *dev)
1259 b43_phy_write(dev, 0x0002, (b43_phy_read(dev, 0x0002) & 0xFFC0) 1115 b43_phy_write(dev, 0x0002, (b43_phy_read(dev, 0x0002) & 0xFFC0)
1260 | 0x0004); 1116 | 0x0004);
1261 } 1117 }
1262 if (phy->type == B43_PHYTYPE_B) { 1118 if (phy->type == B43_PHYTYPE_B)
1263 b43_write16(dev, 0x03E6, 0x8140); 1119 B43_WARN_ON(1);
1264 b43_phy_write(dev, 0x0016, 0x0410); 1120 else if (phy->type == B43_PHYTYPE_G)
1265 b43_phy_write(dev, 0x0017, 0x0820);
1266 b43_phy_write(dev, 0x0062, 0x0007);
1267 b43_radio_init2050(dev);
1268 b43_lo_g_measure(dev);
1269 if (dev->dev->bus->sprom.boardflags_lo & B43_BFL_RSSI) {
1270 b43_calc_nrssi_slope(dev);
1271 b43_calc_nrssi_threshold(dev);
1272 }
1273 b43_phy_init_pctl(dev);
1274 } else if (phy->type == B43_PHYTYPE_G)
1275 b43_write16(dev, 0x03E6, 0x0); 1121 b43_write16(dev, 0x03E6, 0x0);
1276} 1122}
1277 1123
@@ -1534,34 +1380,31 @@ static void b43_phy_initg(struct b43_wldev *dev)
1534 else 1380 else
1535 b43_radio_write16(dev, 0x0078, phy->initval); 1381 b43_radio_write16(dev, 0x0078, phy->initval);
1536 } 1382 }
1537 if (phy->lo_control->tx_bias == 0xFF) { 1383 b43_lo_g_init(dev);
1538 b43_lo_g_measure(dev); 1384 if (has_tx_magnification(phy)) {
1385 b43_radio_write16(dev, 0x52,
1386 (b43_radio_read16(dev, 0x52) & 0xFF00)
1387 | phy->lo_control->tx_bias | phy->
1388 lo_control->tx_magn);
1539 } else { 1389 } else {
1540 if (has_tx_magnification(phy)) { 1390 b43_radio_write16(dev, 0x52,
1541 b43_radio_write16(dev, 0x52, 1391 (b43_radio_read16(dev, 0x52) & 0xFFF0)
1542 (b43_radio_read16(dev, 0x52) & 0xFF00) 1392 | phy->lo_control->tx_bias);
1543 | phy->lo_control->tx_bias | phy->
1544 lo_control->tx_magn);
1545 } else {
1546 b43_radio_write16(dev, 0x52,
1547 (b43_radio_read16(dev, 0x52) & 0xFFF0)
1548 | phy->lo_control->tx_bias);
1549 }
1550 if (phy->rev >= 6) {
1551 b43_phy_write(dev, B43_PHY_CCK(0x36),
1552 (b43_phy_read(dev, B43_PHY_CCK(0x36))
1553 & 0x0FFF) | (phy->lo_control->
1554 tx_bias << 12));
1555 }
1556 if (dev->dev->bus->sprom.boardflags_lo & B43_BFL_PACTRL)
1557 b43_phy_write(dev, B43_PHY_CCK(0x2E), 0x8075);
1558 else
1559 b43_phy_write(dev, B43_PHY_CCK(0x2E), 0x807F);
1560 if (phy->rev < 2)
1561 b43_phy_write(dev, B43_PHY_CCK(0x2F), 0x101);
1562 else
1563 b43_phy_write(dev, B43_PHY_CCK(0x2F), 0x202);
1564 } 1393 }
1394 if (phy->rev >= 6) {
1395 b43_phy_write(dev, B43_PHY_CCK(0x36),
1396 (b43_phy_read(dev, B43_PHY_CCK(0x36))
1397 & 0x0FFF) | (phy->lo_control->
1398 tx_bias << 12));
1399 }
1400 if (dev->dev->bus->sprom.boardflags_lo & B43_BFL_PACTRL)
1401 b43_phy_write(dev, B43_PHY_CCK(0x2E), 0x8075);
1402 else
1403 b43_phy_write(dev, B43_PHY_CCK(0x2E), 0x807F);
1404 if (phy->rev < 2)
1405 b43_phy_write(dev, B43_PHY_CCK(0x2F), 0x101);
1406 else
1407 b43_phy_write(dev, B43_PHY_CCK(0x2F), 0x202);
1565 if (phy->gmode || phy->rev >= 2) { 1408 if (phy->gmode || phy->rev >= 2) {
1566 b43_lo_g_adjust(dev); 1409 b43_lo_g_adjust(dev);
1567 b43_phy_write(dev, B43_PHY_LO_MASK, 0x8078); 1410 b43_phy_write(dev, B43_PHY_LO_MASK, 0x8078);
@@ -1821,10 +1664,8 @@ void b43_phy_xmitpower(struct b43_wldev *dev)
1821 bbatt_delta -= 4 * rfatt_delta; 1664 bbatt_delta -= 4 * rfatt_delta;
1822 1665
1823 /* So do we finally need to adjust something? */ 1666 /* So do we finally need to adjust something? */
1824 if ((rfatt_delta == 0) && (bbatt_delta == 0)) { 1667 if ((rfatt_delta == 0) && (bbatt_delta == 0))
1825 b43_lo_g_ctl_mark_cur_used(dev);
1826 return; 1668 return;
1827 }
1828 1669
1829 /* Calculate the new attenuation values. */ 1670 /* Calculate the new attenuation values. */
1830 bbatt = phy->bbatt.att; 1671 bbatt = phy->bbatt.att;
@@ -1870,7 +1711,6 @@ void b43_phy_xmitpower(struct b43_wldev *dev)
1870 b43_radio_lock(dev); 1711 b43_radio_lock(dev);
1871 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt, 1712 b43_set_txpower_g(dev, &phy->bbatt, &phy->rfatt,
1872 phy->tx_control); 1713 phy->tx_control);
1873 b43_lo_g_ctl_mark_cur_used(dev);
1874 b43_radio_unlock(dev); 1714 b43_radio_unlock(dev);
1875 b43_phy_unlock(dev); 1715 b43_phy_unlock(dev);
1876 break; 1716 break;
@@ -2007,24 +1847,6 @@ int b43_phy_init(struct b43_wldev *dev)
2007 else 1847 else
2008 unsupported = 1; 1848 unsupported = 1;
2009 break; 1849 break;
2010 case B43_PHYTYPE_B:
2011 switch (phy->rev) {
2012 case 2:
2013 b43_phy_initb2(dev);
2014 break;
2015 case 4:
2016 b43_phy_initb4(dev);
2017 break;
2018 case 5:
2019 b43_phy_initb5(dev);
2020 break;
2021 case 6:
2022 b43_phy_initb6(dev);
2023 break;
2024 default:
2025 unsupported = 1;
2026 }
2027 break;
2028 case B43_PHYTYPE_G: 1850 case B43_PHYTYPE_G:
2029 b43_phy_initg(dev); 1851 b43_phy_initg(dev);
2030 break; 1852 break;
diff --git a/drivers/net/wireless/b43/phy.h b/drivers/net/wireless/b43/phy.h
index 6d165d822175..4aab10903529 100644
--- a/drivers/net/wireless/b43/phy.h
+++ b/drivers/net/wireless/b43/phy.h
@@ -225,7 +225,6 @@ int b43_phy_init(struct b43_wldev *dev);
225void b43_set_rx_antenna(struct b43_wldev *dev, int antenna); 225void b43_set_rx_antenna(struct b43_wldev *dev, int antenna);
226 226
227void b43_phy_xmitpower(struct b43_wldev *dev); 227void b43_phy_xmitpower(struct b43_wldev *dev);
228void b43_gphy_dc_lt_init(struct b43_wldev *dev);
229 228
230/* Returns the boolean whether the board has HardwarePowerControl */ 229/* Returns the boolean whether the board has HardwarePowerControl */
231bool b43_has_hardware_pctl(struct b43_phy *phy); 230bool b43_has_hardware_pctl(struct b43_phy *phy);
@@ -252,6 +251,14 @@ struct b43_rfatt_list {
252 u8 max_val; 251 u8 max_val;
253}; 252};
254 253
254/* Returns true, if the values are the same. */
255static inline bool b43_compare_rfatt(const struct b43_rfatt *a,
256 const struct b43_rfatt *b)
257{
258 return ((a->att == b->att) &&
259 (a->with_padmix == b->with_padmix));
260}
261
255/* Baseband Attenuation */ 262/* Baseband Attenuation */
256struct b43_bbatt { 263struct b43_bbatt {
257 u8 att; /* Attenuation value */ 264 u8 att; /* Attenuation value */
@@ -265,6 +272,13 @@ struct b43_bbatt_list {
265 u8 max_val; 272 u8 max_val;
266}; 273};
267 274
275/* Returns true, if the values are the same. */
276static inline bool b43_compare_bbatt(const struct b43_bbatt *a,
277 const struct b43_bbatt *b)
278{
279 return (a->att == b->att);
280}
281
268/* tx_control bits. */ 282/* tx_control bits. */
269#define B43_TXCTL_PA3DB 0x40 /* PA Gain 3dB */ 283#define B43_TXCTL_PA3DB 0x40 /* PA Gain 3dB */
270#define B43_TXCTL_PA2DB 0x20 /* PA Gain 2dB */ 284#define B43_TXCTL_PA2DB 0x20 /* PA Gain 2dB */
diff --git a/drivers/net/wireless/b43/pio.c b/drivers/net/wireless/b43/pio.c
index fcacafb04346..08c8a087f30e 100644
--- a/drivers/net/wireless/b43/pio.c
+++ b/drivers/net/wireless/b43/pio.c
@@ -611,18 +611,16 @@ void b43_pio_get_tx_stats(struct b43_wldev *dev,
611{ 611{
612 const int nr_queues = dev->wl->hw->queues; 612 const int nr_queues = dev->wl->hw->queues;
613 struct b43_pio_txqueue *q; 613 struct b43_pio_txqueue *q;
614 struct ieee80211_tx_queue_stats_data *data;
615 unsigned long flags; 614 unsigned long flags;
616 int i; 615 int i;
617 616
618 for (i = 0; i < nr_queues; i++) { 617 for (i = 0; i < nr_queues; i++) {
619 data = &(stats->data[i]);
620 q = select_queue_by_priority(dev, i); 618 q = select_queue_by_priority(dev, i);
621 619
622 spin_lock_irqsave(&q->lock, flags); 620 spin_lock_irqsave(&q->lock, flags);
623 data->len = B43_PIO_MAX_NR_TXPACKETS - q->free_packet_slots; 621 stats[i].len = B43_PIO_MAX_NR_TXPACKETS - q->free_packet_slots;
624 data->limit = B43_PIO_MAX_NR_TXPACKETS; 622 stats[i].limit = B43_PIO_MAX_NR_TXPACKETS;
625 data->count = q->nr_tx_packets; 623 stats[i].count = q->nr_tx_packets;
626 spin_unlock_irqrestore(&q->lock, flags); 624 spin_unlock_irqrestore(&q->lock, flags);
627 } 625 }
628} 626}
diff --git a/drivers/net/wireless/b43/xmit.c b/drivers/net/wireless/b43/xmit.c
index 19aefbfb2c93..88491947a209 100644
--- a/drivers/net/wireless/b43/xmit.c
+++ b/drivers/net/wireless/b43/xmit.c
@@ -235,7 +235,7 @@ int b43_generate_txhdr(struct b43_wldev *dev,
235 235
236 plcp_fragment_len = fragment_len + FCS_LEN; 236 plcp_fragment_len = fragment_len + FCS_LEN;
237 if (use_encryption) { 237 if (use_encryption) {
238 u8 key_idx = (u16) (txctl->key_idx); 238 u8 key_idx = txctl->hw_key->hw_key_idx;
239 struct b43_key *key; 239 struct b43_key *key;
240 int wlhdr_len; 240 int wlhdr_len;
241 size_t iv_len; 241 size_t iv_len;
diff --git a/drivers/net/wireless/b43legacy/dma.c b/drivers/net/wireless/b43legacy/dma.c
index c990f87b107a..d6686f713b6d 100644
--- a/drivers/net/wireless/b43legacy/dma.c
+++ b/drivers/net/wireless/b43legacy/dma.c
@@ -1455,18 +1455,16 @@ void b43legacy_dma_get_tx_stats(struct b43legacy_wldev *dev,
1455{ 1455{
1456 const int nr_queues = dev->wl->hw->queues; 1456 const int nr_queues = dev->wl->hw->queues;
1457 struct b43legacy_dmaring *ring; 1457 struct b43legacy_dmaring *ring;
1458 struct ieee80211_tx_queue_stats_data *data;
1459 unsigned long flags; 1458 unsigned long flags;
1460 int i; 1459 int i;
1461 1460
1462 for (i = 0; i < nr_queues; i++) { 1461 for (i = 0; i < nr_queues; i++) {
1463 data = &(stats->data[i]);
1464 ring = priority_to_txring(dev, i); 1462 ring = priority_to_txring(dev, i);
1465 1463
1466 spin_lock_irqsave(&ring->lock, flags); 1464 spin_lock_irqsave(&ring->lock, flags);
1467 data->len = ring->used_slots / SLOTS_PER_PACKET; 1465 stats[i].len = ring->used_slots / SLOTS_PER_PACKET;
1468 data->limit = ring->nr_slots / SLOTS_PER_PACKET; 1466 stats[i].limit = ring->nr_slots / SLOTS_PER_PACKET;
1469 data->count = ring->nr_tx_packets; 1467 stats[i].count = ring->nr_tx_packets;
1470 spin_unlock_irqrestore(&ring->lock, flags); 1468 spin_unlock_irqrestore(&ring->lock, flags);
1471 } 1469 }
1472} 1470}
diff --git a/drivers/net/wireless/b43legacy/main.c b/drivers/net/wireless/b43legacy/main.c
index 14a5eea2573e..1ccc51e90a8e 100644
--- a/drivers/net/wireless/b43legacy/main.c
+++ b/drivers/net/wireless/b43legacy/main.c
@@ -2383,8 +2383,7 @@ out:
2383 return NETDEV_TX_OK; 2383 return NETDEV_TX_OK;
2384} 2384}
2385 2385
2386static int b43legacy_op_conf_tx(struct ieee80211_hw *hw, 2386static int b43legacy_op_conf_tx(struct ieee80211_hw *hw, u16 queue,
2387 int queue,
2388 const struct ieee80211_tx_queue_params *params) 2387 const struct ieee80211_tx_queue_params *params)
2389{ 2388{
2390 return 0; 2389 return 0;
diff --git a/drivers/net/wireless/b43legacy/pio.c b/drivers/net/wireless/b43legacy/pio.c
index bcdd54eb2edb..8d3d27d3cd67 100644
--- a/drivers/net/wireless/b43legacy/pio.c
+++ b/drivers/net/wireless/b43legacy/pio.c
@@ -525,13 +525,11 @@ void b43legacy_pio_get_tx_stats(struct b43legacy_wldev *dev,
525{ 525{
526 struct b43legacy_pio *pio = &dev->pio; 526 struct b43legacy_pio *pio = &dev->pio;
527 struct b43legacy_pioqueue *queue; 527 struct b43legacy_pioqueue *queue;
528 struct ieee80211_tx_queue_stats_data *data;
529 528
530 queue = pio->queue1; 529 queue = pio->queue1;
531 data = &(stats->data[0]); 530 stats[0].len = B43legacy_PIO_MAXTXPACKETS - queue->nr_txfree;
532 data->len = B43legacy_PIO_MAXTXPACKETS - queue->nr_txfree; 531 stats[0].limit = B43legacy_PIO_MAXTXPACKETS;
533 data->limit = B43legacy_PIO_MAXTXPACKETS; 532 stats[0].count = queue->nr_tx_packets;
534 data->count = queue->nr_tx_packets;
535} 533}
536 534
537static void pio_rx_error(struct b43legacy_pioqueue *queue, 535static void pio_rx_error(struct b43legacy_pioqueue *queue,
diff --git a/drivers/net/wireless/b43legacy/xmit.c b/drivers/net/wireless/b43legacy/xmit.c
index dcad2491a606..fc83dab6e2c7 100644
--- a/drivers/net/wireless/b43legacy/xmit.c
+++ b/drivers/net/wireless/b43legacy/xmit.c
@@ -232,7 +232,7 @@ static int generate_txhdr_fw3(struct b43legacy_wldev *dev,
232 232
233 plcp_fragment_len = fragment_len + FCS_LEN; 233 plcp_fragment_len = fragment_len + FCS_LEN;
234 if (use_encryption) { 234 if (use_encryption) {
235 u8 key_idx = (u16)(txctl->key_idx); 235 u8 key_idx = txctl->hw_key->hw_key_idx;
236 struct b43legacy_key *key; 236 struct b43legacy_key *key;
237 int wlhdr_len; 237 int wlhdr_len;
238 size_t iv_len; 238 size_t iv_len;
diff --git a/drivers/net/wireless/iwlwifi/Kconfig b/drivers/net/wireless/iwlwifi/Kconfig
index 62fb89d82318..995dd537083f 100644
--- a/drivers/net/wireless/iwlwifi/Kconfig
+++ b/drivers/net/wireless/iwlwifi/Kconfig
@@ -14,6 +14,15 @@ config IWLWIFI_LEDS
14 bool 14 bool
15 default n 15 default n
16 16
17config IWLWIFI_RUN_TIME_CALIB
18 bool
19 depends on IWLCORE
20 default n
21 ---help---
22 This option will enable run time calibration for the iwlwifi driver.
23 These calibrations are Sensitivity and Chain Noise.
24
25
17config IWLWIFI_RFKILL 26config IWLWIFI_RFKILL
18 boolean "IWLWIFI RF kill support" 27 boolean "IWLWIFI RF kill support"
19 depends on IWLCORE 28 depends on IWLCORE
@@ -67,12 +76,14 @@ config IWL4965_SPECTRUM_MEASUREMENT
67 ---help--- 76 ---help---
68 This option will enable spectrum measurement for the iwl4965 driver. 77 This option will enable spectrum measurement for the iwl4965 driver.
69 78
70config IWL4965_SENSITIVITY 79config IWL4965_RUN_TIME_CALIB
71 bool "Enable Sensitivity Calibration in iwl4965 driver" 80 bool "Enable run time Calibration for 4965 NIC"
81 select IWLWIFI_RUN_TIME_CALIB
72 depends on IWL4965 82 depends on IWL4965
83 default y
73 ---help--- 84 ---help---
74 This option will enable sensitivity calibration for the iwl4965 85 This option will enable run time calibration for the iwl4965 driver.
75 driver. 86 These calibrations are Sensitivity and Chain Noise. If unsure, say yes
76 87
77config IWLWIFI_DEBUG 88config IWLWIFI_DEBUG
78 bool "Enable full debugging output in iwl4965 driver" 89 bool "Enable full debugging output in iwl4965 driver"
@@ -100,6 +111,23 @@ config IWLWIFI_DEBUG
100 as the debug information can assist others in helping you resolve 111 as the debug information can assist others in helping you resolve
101 any problems you may encounter. 112 any problems you may encounter.
102 113
114config IWL5000
115 bool "Intel Wireless WiFi 5000AGN"
116 depends on IWL4965
117 ---help---
118 This option enables support for Intel Wireless WiFi Link 5000AGN Family
119 Dependency on 4965 is temporary
120
121config IWL5000_RUN_TIME_CALIB
122 bool "Enable run time Calibration for 5000 NIC"
123 select IWLWIFI_RUN_TIME_CALIB
124 depends on IWL5000
125 default y
126 ---help---
127 This option will enable run time calibration for the iwl5000 driver.
128 These calibrations are Sensitivity and Chain Noise. If unsure, say yes
129
130
103config IWLWIFI_DEBUGFS 131config IWLWIFI_DEBUGFS
104 bool "Iwlwifi debugfs support" 132 bool "Iwlwifi debugfs support"
105 depends on IWLCORE && IWLWIFI_DEBUG && MAC80211_DEBUGFS 133 depends on IWLCORE && IWLWIFI_DEBUG && MAC80211_DEBUGFS
diff --git a/drivers/net/wireless/iwlwifi/Makefile b/drivers/net/wireless/iwlwifi/Makefile
index ec6187b75c3b..b0b2b5ebfa61 100644
--- a/drivers/net/wireless/iwlwifi/Makefile
+++ b/drivers/net/wireless/iwlwifi/Makefile
@@ -1,8 +1,9 @@
1obj-$(CONFIG_IWLCORE) += iwlcore.o 1obj-$(CONFIG_IWLCORE) += iwlcore.o
2iwlcore-objs := iwl-core.o iwl-eeprom.o iwl-hcmd.o 2iwlcore-objs := iwl-core.o iwl-eeprom.o iwl-hcmd.o iwl-power.o
3iwlcore-$(CONFIG_IWLWIFI_DEBUGFS) += iwl-debugfs.o 3iwlcore-$(CONFIG_IWLWIFI_DEBUGFS) += iwl-debugfs.o
4iwlcore-$(CONFIG_IWLWIFI_LEDS) += iwl-led.o 4iwlcore-$(CONFIG_IWLWIFI_LEDS) += iwl-led.o
5iwlcore-$(CONFIG_IWLWIFI_RFKILL) += iwl-rfkill.o 5iwlcore-$(CONFIG_IWLWIFI_RFKILL) += iwl-rfkill.o
6iwlcore-$(CONFIG_IWLWIFI_RUN_TIME_CALIB) += iwl-calib.o
6 7
7obj-$(CONFIG_IWL3945) += iwl3945.o 8obj-$(CONFIG_IWL3945) += iwl3945.o
8iwl3945-objs := iwl3945-base.o iwl-3945.o iwl-3945-rs.o 9iwl3945-objs := iwl3945-base.o iwl-3945.o iwl-3945-rs.o
@@ -11,3 +12,8 @@ iwl3945-$(CONFIG_IWL3945_LEDS) += iwl-3945-led.o
11obj-$(CONFIG_IWL4965) += iwl4965.o 12obj-$(CONFIG_IWL4965) += iwl4965.o
12iwl4965-objs := iwl4965-base.o iwl-4965.o iwl-4965-rs.o iwl-sta.o 13iwl4965-objs := iwl4965-base.o iwl-4965.o iwl-4965-rs.o iwl-sta.o
13 14
15ifeq ($(CONFIG_IWL5000),y)
16 iwl4965-objs += iwl-5000.o
17endif
18
19
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-hw.h b/drivers/net/wireless/iwlwifi/iwl-3945-hw.h
index ad612a8719f4..644bd9e08052 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945-hw.h
+++ b/drivers/net/wireless/iwlwifi/iwl-3945-hw.h
@@ -126,7 +126,7 @@ enum {
126 EEPROM_CHANNEL_ACTIVE = (1 << 3), /* active scanning allowed */ 126 EEPROM_CHANNEL_ACTIVE = (1 << 3), /* active scanning allowed */
127 EEPROM_CHANNEL_RADAR = (1 << 4), /* radar detection required */ 127 EEPROM_CHANNEL_RADAR = (1 << 4), /* radar detection required */
128 EEPROM_CHANNEL_WIDE = (1 << 5), /* 20 MHz channel okay */ 128 EEPROM_CHANNEL_WIDE = (1 << 5), /* 20 MHz channel okay */
129 EEPROM_CHANNEL_NARROW = (1 << 6), /* 10 MHz channel (not used) */ 129 /* Bit 6 Reserved (was Narrow Channel) */
130 EEPROM_CHANNEL_DFS = (1 << 7), /* dynamic freq selection candidate */ 130 EEPROM_CHANNEL_DFS = (1 << 7), /* dynamic freq selection candidate */
131}; 131};
132 132
@@ -289,17 +289,6 @@ struct iwl3945_eeprom {
289#define PCI_REG_WUM8 0x0E8 289#define PCI_REG_WUM8 0x0E8
290#define PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT (0x80000000) 290#define PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT (0x80000000)
291 291
292/* SCD (3945 Tx Frame Scheduler) */
293#define SCD_BASE (CSR_BASE + 0x2E00)
294
295#define SCD_MODE_REG (SCD_BASE + 0x000)
296#define SCD_ARASTAT_REG (SCD_BASE + 0x004)
297#define SCD_TXFACT_REG (SCD_BASE + 0x010)
298#define SCD_TXF4MF_REG (SCD_BASE + 0x014)
299#define SCD_TXF5MF_REG (SCD_BASE + 0x020)
300#define SCD_SBYP_MODE_1_REG (SCD_BASE + 0x02C)
301#define SCD_SBYP_MODE_2_REG (SCD_BASE + 0x030)
302
303/*=== FH (data Flow Handler) ===*/ 292/*=== FH (data Flow Handler) ===*/
304#define FH_BASE (0x800) 293#define FH_BASE (0x800)
305 294
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
index 85c22641542d..e51eeeff6992 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
@@ -29,7 +29,6 @@
29#include <linux/skbuff.h> 29#include <linux/skbuff.h>
30#include <linux/wireless.h> 30#include <linux/wireless.h>
31#include <net/mac80211.h> 31#include <net/mac80211.h>
32#include <net/ieee80211.h>
33 32
34#include <linux/netdevice.h> 33#include <linux/netdevice.h>
35#include <linux/etherdevice.h> 34#include <linux/etherdevice.h>
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.c b/drivers/net/wireless/iwlwifi/iwl-3945.c
index 62a3d8f8563e..9df48b33f0ca 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.c
@@ -1229,7 +1229,7 @@ int iwl3945_hw_nic_init(struct iwl3945_priv *priv)
1229 iwl3945_power_init_handle(priv); 1229 iwl3945_power_init_handle(priv);
1230 1230
1231 spin_lock_irqsave(&priv->lock, flags); 1231 spin_lock_irqsave(&priv->lock, flags);
1232 iwl3945_set_bit(priv, CSR_ANA_PLL_CFG, (1 << 24)); 1232 iwl3945_set_bit(priv, CSR_ANA_PLL_CFG, CSR39_ANA_PLL_CFG_VAL);
1233 iwl3945_set_bit(priv, CSR_GIO_CHICKEN_BITS, 1233 iwl3945_set_bit(priv, CSR_GIO_CHICKEN_BITS,
1234 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX); 1234 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
1235 1235
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.h b/drivers/net/wireless/iwlwifi/iwl-3945.h
index c7695a215a39..fb96c62ad0ff 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.h
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.h
@@ -924,11 +924,6 @@ static inline int is_channel_valid(const struct iwl3945_channel_info *ch_info)
924 return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0; 924 return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
925} 925}
926 926
927static inline int is_channel_narrow(const struct iwl3945_channel_info *ch_info)
928{
929 return (ch_info->flags & EEPROM_CHANNEL_NARROW) ? 1 : 0;
930}
931
932static inline int is_channel_radar(const struct iwl3945_channel_info *ch_info) 927static inline int is_channel_radar(const struct iwl3945_channel_info *ch_info)
933{ 928{
934 return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0; 929 return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965-hw.h b/drivers/net/wireless/iwlwifi/iwl-4965-hw.h
index 1a66b508a8ea..29749e2a8ff0 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965-hw.h
+++ b/drivers/net/wireless/iwlwifi/iwl-4965-hw.h
@@ -62,13 +62,18 @@
62 *****************************************************************************/ 62 *****************************************************************************/
63/* 63/*
64 * Please use this file (iwl-4965-hw.h) only for hardware-related definitions. 64 * Please use this file (iwl-4965-hw.h) only for hardware-related definitions.
65 * Use iwl-4965-commands.h for uCode API definitions. 65 * Use iwl-commands.h for uCode API definitions.
66 * Use iwl-4965.h for driver implementation definitions. 66 * Use iwl-dev.h for driver implementation definitions.
67 */ 67 */
68 68
69#ifndef __iwl_4965_hw_h__ 69#ifndef __iwl_4965_hw_h__
70#define __iwl_4965_hw_h__ 70#define __iwl_4965_hw_h__
71 71
72#include "iwl-fh.h"
73
74/* EERPROM */
75#define IWL4965_EEPROM_IMG_SIZE 1024
76
72/* 77/*
73 * uCode queue management definitions ... 78 * uCode queue management definitions ...
74 * Queue #4 is the command queue for 3945 and 4965; map it to Tx FIFO chnl 4. 79 * Queue #4 is the command queue for 3945 and 4965; map it to Tx FIFO chnl 4.
@@ -93,7 +98,7 @@
93#define IWL_RSSI_OFFSET 44 98#define IWL_RSSI_OFFSET 44
94 99
95 100
96#include "iwl-4965-commands.h" 101#include "iwl-commands.h"
97 102
98#define PCI_LINK_CTRL 0x0F0 103#define PCI_LINK_CTRL 0x0F0
99#define PCI_POWER_SOURCE 0x0C8 104#define PCI_POWER_SOURCE 0x0C8
@@ -131,10 +136,8 @@
131#define RTC_DATA_LOWER_BOUND (0x800000) 136#define RTC_DATA_LOWER_BOUND (0x800000)
132#define IWL49_RTC_DATA_UPPER_BOUND (0x80A000) 137#define IWL49_RTC_DATA_UPPER_BOUND (0x80A000)
133 138
134#define IWL49_RTC_INST_SIZE \ 139#define IWL49_RTC_INST_SIZE (IWL49_RTC_INST_UPPER_BOUND - RTC_INST_LOWER_BOUND)
135 (IWL49_RTC_INST_UPPER_BOUND - RTC_INST_LOWER_BOUND) 140#define IWL49_RTC_DATA_SIZE (IWL49_RTC_DATA_UPPER_BOUND - RTC_DATA_LOWER_BOUND)
136#define IWL49_RTC_DATA_SIZE \
137 (IWL49_RTC_DATA_UPPER_BOUND - RTC_DATA_LOWER_BOUND)
138 141
139#define IWL_MAX_INST_SIZE IWL49_RTC_INST_SIZE 142#define IWL_MAX_INST_SIZE IWL49_RTC_INST_SIZE
140#define IWL_MAX_DATA_SIZE IWL49_RTC_DATA_SIZE 143#define IWL_MAX_DATA_SIZE IWL49_RTC_DATA_SIZE
@@ -785,579 +788,13 @@ enum {
785 788
786/********************* END TXPOWER *****************************************/ 789/********************* END TXPOWER *****************************************/
787 790
788/****************************/
789/* Flow Handler Definitions */
790/****************************/
791
792/**
793 * This I/O area is directly read/writable by driver (e.g. Linux uses writel())
794 * Addresses are offsets from device's PCI hardware base address.
795 */
796#define FH_MEM_LOWER_BOUND (0x1000)
797#define FH_MEM_UPPER_BOUND (0x1EF0)
798
799/**
800 * Keep-Warm (KW) buffer base address.
801 *
802 * Driver must allocate a 4KByte buffer that is used by 4965 for keeping the
803 * host DRAM powered on (via dummy accesses to DRAM) to maintain low-latency
804 * DRAM access when 4965 is Txing or Rxing. The dummy accesses prevent host
805 * from going into a power-savings mode that would cause higher DRAM latency,
806 * and possible data over/under-runs, before all Tx/Rx is complete.
807 *
808 * Driver loads IWL_FH_KW_MEM_ADDR_REG with the physical address (bits 35:4)
809 * of the buffer, which must be 4K aligned. Once this is set up, the 4965
810 * automatically invokes keep-warm accesses when normal accesses might not
811 * be sufficient to maintain fast DRAM response.
812 *
813 * Bit fields:
814 * 31-0: Keep-warm buffer physical base address [35:4], must be 4K aligned
815 */
816#define IWL_FH_KW_MEM_ADDR_REG (FH_MEM_LOWER_BOUND + 0x97C)
817
818
819/**
820 * TFD Circular Buffers Base (CBBC) addresses
821 *
822 * 4965 has 16 base pointer registers, one for each of 16 host-DRAM-resident
823 * circular buffers (CBs/queues) containing Transmit Frame Descriptors (TFDs)
824 * (see struct iwl_tfd_frame). These 16 pointer registers are offset by 0x04
825 * bytes from one another. Each TFD circular buffer in DRAM must be 256-byte
826 * aligned (address bits 0-7 must be 0).
827 *
828 * Bit fields in each pointer register:
829 * 27-0: TFD CB physical base address [35:8], must be 256-byte aligned
830 */
831#define FH_MEM_CBBC_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0x9D0)
832#define FH_MEM_CBBC_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xA10)
833
834/* Find TFD CB base pointer for given queue (range 0-15). */
835#define FH_MEM_CBBC_QUEUE(x) (FH_MEM_CBBC_LOWER_BOUND + (x) * 0x4)
836
837
838/**
839 * Rx SRAM Control and Status Registers (RSCSR)
840 *
841 * These registers provide handshake between driver and 4965 for the Rx queue
842 * (this queue handles *all* command responses, notifications, Rx data, etc.
843 * sent from 4965 uCode to host driver). Unlike Tx, there is only one Rx
844 * queue, and only one Rx DMA/FIFO channel. Also unlike Tx, which can
845 * concatenate up to 20 DRAM buffers to form a Tx frame, each Receive Buffer
846 * Descriptor (RBD) points to only one Rx Buffer (RB); there is a 1:1
847 * mapping between RBDs and RBs.
848 *
849 * Driver must allocate host DRAM memory for the following, and set the
850 * physical address of each into 4965 registers:
851 *
852 * 1) Receive Buffer Descriptor (RBD) circular buffer (CB), typically with 256
853 * entries (although any power of 2, up to 4096, is selectable by driver).
854 * Each entry (1 dword) points to a receive buffer (RB) of consistent size
855 * (typically 4K, although 8K or 16K are also selectable by driver).
856 * Driver sets up RB size and number of RBDs in the CB via Rx config
857 * register FH_MEM_RCSR_CHNL0_CONFIG_REG.
858 *
859 * Bit fields within one RBD:
860 * 27-0: Receive Buffer physical address bits [35:8], 256-byte aligned
861 *
862 * Driver sets physical address [35:8] of base of RBD circular buffer
863 * into FH_RSCSR_CHNL0_RBDCB_BASE_REG [27:0].
864 *
865 * 2) Rx status buffer, 8 bytes, in which 4965 indicates which Rx Buffers
866 * (RBs) have been filled, via a "write pointer", actually the index of
867 * the RB's corresponding RBD within the circular buffer. Driver sets
868 * physical address [35:4] into FH_RSCSR_CHNL0_STTS_WPTR_REG [31:0].
869 *
870 * Bit fields in lower dword of Rx status buffer (upper dword not used
871 * by driver; see struct iwl4965_shared, val0):
872 * 31-12: Not used by driver
873 * 11- 0: Index of last filled Rx buffer descriptor
874 * (4965 writes, driver reads this value)
875 *
876 * As the driver prepares Receive Buffers (RBs) for 4965 to fill, driver must
877 * enter pointers to these RBs into contiguous RBD circular buffer entries,
878 * and update the 4965's "write" index register, FH_RSCSR_CHNL0_RBDCB_WPTR_REG.
879 *
880 * This "write" index corresponds to the *next* RBD that the driver will make
881 * available, i.e. one RBD past the tail of the ready-to-fill RBDs within
882 * the circular buffer. This value should initially be 0 (before preparing any
883 * RBs), should be 8 after preparing the first 8 RBs (for example), and must
884 * wrap back to 0 at the end of the circular buffer (but don't wrap before
885 * "read" index has advanced past 1! See below).
886 * NOTE: 4965 EXPECTS THE WRITE INDEX TO BE INCREMENTED IN MULTIPLES OF 8.
887 *
888 * As the 4965 fills RBs (referenced from contiguous RBDs within the circular
889 * buffer), it updates the Rx status buffer in host DRAM, 2) described above,
890 * to tell the driver the index of the latest filled RBD. The driver must
891 * read this "read" index from DRAM after receiving an Rx interrupt from 4965.
892 *
893 * The driver must also internally keep track of a third index, which is the
894 * next RBD to process. When receiving an Rx interrupt, driver should process
895 * all filled but unprocessed RBs up to, but not including, the RB
896 * corresponding to the "read" index. For example, if "read" index becomes "1",
897 * driver may process the RB pointed to by RBD 0. Depending on volume of
898 * traffic, there may be many RBs to process.
899 *
900 * If read index == write index, 4965 thinks there is no room to put new data.
901 * Due to this, the maximum number of filled RBs is 255, instead of 256. To
902 * be safe, make sure that there is a gap of at least 2 RBDs between "write"
903 * and "read" indexes; that is, make sure that there are no more than 254
904 * buffers waiting to be filled.
905 */
906#define FH_MEM_RSCSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xBC0)
907#define FH_MEM_RSCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xC00)
908#define FH_MEM_RSCSR_CHNL0 (FH_MEM_RSCSR_LOWER_BOUND)
909
910/**
911 * Physical base address of 8-byte Rx Status buffer.
912 * Bit fields:
913 * 31-0: Rx status buffer physical base address [35:4], must 16-byte aligned.
914 */
915#define FH_RSCSR_CHNL0_STTS_WPTR_REG (FH_MEM_RSCSR_CHNL0)
916
917/**
918 * Physical base address of Rx Buffer Descriptor Circular Buffer.
919 * Bit fields:
920 * 27-0: RBD CD physical base address [35:8], must be 256-byte aligned.
921 */
922#define FH_RSCSR_CHNL0_RBDCB_BASE_REG (FH_MEM_RSCSR_CHNL0 + 0x004)
923
924/**
925 * Rx write pointer (index, really!).
926 * Bit fields:
927 * 11-0: Index of driver's most recent prepared-to-be-filled RBD, + 1.
928 * NOTE: For 256-entry circular buffer, use only bits [7:0].
929 */
930#define FH_RSCSR_CHNL0_RBDCB_WPTR_REG (FH_MEM_RSCSR_CHNL0 + 0x008)
931#define FH_RSCSR_CHNL0_WPTR (FH_RSCSR_CHNL0_RBDCB_WPTR_REG)
932
933
934/**
935 * Rx Config/Status Registers (RCSR)
936 * Rx Config Reg for channel 0 (only channel used)
937 *
938 * Driver must initialize FH_MEM_RCSR_CHNL0_CONFIG_REG as follows for
939 * normal operation (see bit fields).
940 *
941 * Clearing FH_MEM_RCSR_CHNL0_CONFIG_REG to 0 turns off Rx DMA.
942 * Driver should poll FH_MEM_RSSR_RX_STATUS_REG for
943 * FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE (bit 24) before continuing.
944 *
945 * Bit fields:
946 * 31-30: Rx DMA channel enable: '00' off/pause, '01' pause at end of frame,
947 * '10' operate normally
948 * 29-24: reserved
949 * 23-20: # RBDs in circular buffer = 2^value; use "8" for 256 RBDs (normal),
950 * min "5" for 32 RBDs, max "12" for 4096 RBDs.
951 * 19-18: reserved
952 * 17-16: size of each receive buffer; '00' 4K (normal), '01' 8K,
953 * '10' 12K, '11' 16K.
954 * 15-14: reserved
955 * 13-12: IRQ destination; '00' none, '01' host driver (normal operation)
956 * 11- 4: timeout for closing Rx buffer and interrupting host (units 32 usec)
957 * typical value 0x10 (about 1/2 msec)
958 * 3- 0: reserved
959 */
960#define FH_MEM_RCSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xC00)
961#define FH_MEM_RCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xCC0)
962#define FH_MEM_RCSR_CHNL0 (FH_MEM_RCSR_LOWER_BOUND)
963
964#define FH_MEM_RCSR_CHNL0_CONFIG_REG (FH_MEM_RCSR_CHNL0)
965
966#define FH_RCSR_CHNL0_RX_CONFIG_RB_TIMEOUT_MASK (0x00000FF0) /* bit 4-11 */
967#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_MASK (0x00001000) /* bit 12 */
968#define FH_RCSR_CHNL0_RX_CONFIG_SINGLE_FRAME_MASK (0x00008000) /* bit 15 */
969#define FH_RCSR_CHNL0_RX_CONFIG_RB_SIZE_MASK (0x00030000) /* bits 16-17 */
970#define FH_RCSR_CHNL0_RX_CONFIG_RBDBC_SIZE_MASK (0x00F00000) /* bits 20-23 */
971#define FH_RCSR_CHNL0_RX_CONFIG_DMA_CHNL_EN_MASK (0xC0000000) /* bits 30-31 */
972
973#define FH_RCSR_RX_CONFIG_RBDCB_SIZE_BITSHIFT (20)
974#define FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_BITSHIFT (4)
975#define RX_RB_TIMEOUT (0x10)
976
977#define FH_RCSR_RX_CONFIG_CHNL_EN_PAUSE_VAL (0x00000000)
978#define FH_RCSR_RX_CONFIG_CHNL_EN_PAUSE_EOF_VAL (0x40000000)
979#define FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL (0x80000000)
980
981#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K (0x00000000)
982#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K (0x00010000)
983#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_12K (0x00020000)
984#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_16K (0x00030000)
985
986#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_NO_INT_VAL (0x00000000)
987#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL (0x00001000)
988
989
990/**
991 * Rx Shared Status Registers (RSSR)
992 *
993 * After stopping Rx DMA channel (writing 0 to FH_MEM_RCSR_CHNL0_CONFIG_REG),
994 * driver must poll FH_MEM_RSSR_RX_STATUS_REG until Rx channel is idle.
995 *
996 * Bit fields:
997 * 24: 1 = Channel 0 is idle
998 *
999 * FH_MEM_RSSR_SHARED_CTRL_REG and FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV contain
1000 * default values that should not be altered by the driver.
1001 */
1002#define FH_MEM_RSSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xC40)
1003#define FH_MEM_RSSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xD00)
1004
1005#define FH_MEM_RSSR_SHARED_CTRL_REG (FH_MEM_RSSR_LOWER_BOUND)
1006#define FH_MEM_RSSR_RX_STATUS_REG (FH_MEM_RSSR_LOWER_BOUND + 0x004)
1007#define FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV (FH_MEM_RSSR_LOWER_BOUND + 0x008)
1008
1009#define FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE (0x01000000)
1010
1011
1012/**
1013 * Transmit DMA Channel Control/Status Registers (TCSR)
1014 *
1015 * 4965 has one configuration register for each of 8 Tx DMA/FIFO channels
1016 * supported in hardware (don't confuse these with the 16 Tx queues in DRAM,
1017 * which feed the DMA/FIFO channels); config regs are separated by 0x20 bytes.
1018 *
1019 * To use a Tx DMA channel, driver must initialize its
1020 * IWL_FH_TCSR_CHNL_TX_CONFIG_REG(chnl) with:
1021 *
1022 * IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
1023 * IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL
1024 *
1025 * All other bits should be 0.
1026 *
1027 * Bit fields:
1028 * 31-30: Tx DMA channel enable: '00' off/pause, '01' pause at end of frame,
1029 * '10' operate normally
1030 * 29- 4: Reserved, set to "0"
1031 * 3: Enable internal DMA requests (1, normal operation), disable (0)
1032 * 2- 0: Reserved, set to "0"
1033 */
1034#define IWL_FH_TCSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xD00)
1035#define IWL_FH_TCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xE60)
1036
1037/* Find Control/Status reg for given Tx DMA/FIFO channel */
1038#define IWL_FH_TCSR_CHNL_TX_CONFIG_REG(_chnl) \
1039 (IWL_FH_TCSR_LOWER_BOUND + 0x20 * _chnl)
1040
1041#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE_VAL (0x00000000)
1042#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL (0x00000008)
1043
1044#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE (0x00000000)
1045#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE_EOF (0x40000000)
1046#define IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE (0x80000000)
1047
1048/**
1049 * Tx Shared Status Registers (TSSR)
1050 *
1051 * After stopping Tx DMA channel (writing 0 to
1052 * IWL_FH_TCSR_CHNL_TX_CONFIG_REG(chnl)), driver must poll
1053 * IWL_FH_TSSR_TX_STATUS_REG until selected Tx channel is idle
1054 * (channel's buffers empty | no pending requests).
1055 *
1056 * Bit fields:
1057 * 31-24: 1 = Channel buffers empty (channel 7:0)
1058 * 23-16: 1 = No pending requests (channel 7:0)
1059 */
1060#define IWL_FH_TSSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xEA0)
1061#define IWL_FH_TSSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xEC0)
1062
1063#define IWL_FH_TSSR_TX_STATUS_REG (IWL_FH_TSSR_LOWER_BOUND + 0x010)
1064
1065#define IWL_FH_TSSR_TX_STATUS_REG_BIT_BUFS_EMPTY(_chnl) \
1066 ((1 << (_chnl)) << 24)
1067#define IWL_FH_TSSR_TX_STATUS_REG_BIT_NO_PEND_REQ(_chnl) \
1068 ((1 << (_chnl)) << 16)
1069
1070#define IWL_FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(_chnl) \
1071 (IWL_FH_TSSR_TX_STATUS_REG_BIT_BUFS_EMPTY(_chnl) | \
1072 IWL_FH_TSSR_TX_STATUS_REG_BIT_NO_PEND_REQ(_chnl))
1073
1074
1075/********************* START TX SCHEDULER *************************************/
1076
1077/**
1078 * 4965 Tx Scheduler
1079 *
1080 * The Tx Scheduler selects the next frame to be transmitted, chosing TFDs
1081 * (Transmit Frame Descriptors) from up to 16 circular Tx queues resident in
1082 * host DRAM. It steers each frame's Tx command (which contains the frame
1083 * data) into one of up to 7 prioritized Tx DMA FIFO channels within the
1084 * device. A queue maps to only one (selectable by driver) Tx DMA channel,
1085 * but one DMA channel may take input from several queues.
1086 *
1087 * Tx DMA channels have dedicated purposes. For 4965, they are used as follows:
1088 *
1089 * 0 -- EDCA BK (background) frames, lowest priority
1090 * 1 -- EDCA BE (best effort) frames, normal priority
1091 * 2 -- EDCA VI (video) frames, higher priority
1092 * 3 -- EDCA VO (voice) and management frames, highest priority
1093 * 4 -- Commands (e.g. RXON, etc.)
1094 * 5 -- HCCA short frames
1095 * 6 -- HCCA long frames
1096 * 7 -- not used by driver (device-internal only)
1097 *
1098 * Driver should normally map queues 0-6 to Tx DMA/FIFO channels 0-6.
1099 * In addition, driver can map queues 7-15 to Tx DMA/FIFO channels 0-3 to
1100 * support 11n aggregation via EDCA DMA channels.
1101 *
1102 * The driver sets up each queue to work in one of two modes:
1103 *
1104 * 1) Scheduler-Ack, in which the scheduler automatically supports a
1105 * block-ack (BA) window of up to 64 TFDs. In this mode, each queue
1106 * contains TFDs for a unique combination of Recipient Address (RA)
1107 * and Traffic Identifier (TID), that is, traffic of a given
1108 * Quality-Of-Service (QOS) priority, destined for a single station.
1109 *
1110 * In scheduler-ack mode, the scheduler keeps track of the Tx status of
1111 * each frame within the BA window, including whether it's been transmitted,
1112 * and whether it's been acknowledged by the receiving station. The device
1113 * automatically processes block-acks received from the receiving STA,
1114 * and reschedules un-acked frames to be retransmitted (successful
1115 * Tx completion may end up being out-of-order).
1116 *
1117 * The driver must maintain the queue's Byte Count table in host DRAM
1118 * (struct iwl4965_sched_queue_byte_cnt_tbl) for this mode.
1119 * This mode does not support fragmentation.
1120 *
1121 * 2) FIFO (a.k.a. non-Scheduler-ACK), in which each TFD is processed in order.
1122 * The device may automatically retry Tx, but will retry only one frame
1123 * at a time, until receiving ACK from receiving station, or reaching
1124 * retry limit and giving up.
1125 *
1126 * The command queue (#4) must use this mode!
1127 * This mode does not require use of the Byte Count table in host DRAM.
1128 *
1129 * Driver controls scheduler operation via 3 means:
1130 * 1) Scheduler registers
1131 * 2) Shared scheduler data base in internal 4956 SRAM
1132 * 3) Shared data in host DRAM
1133 *
1134 * Initialization:
1135 *
1136 * When loading, driver should allocate memory for:
1137 * 1) 16 TFD circular buffers, each with space for (typically) 256 TFDs.
1138 * 2) 16 Byte Count circular buffers in 16 KBytes contiguous memory
1139 * (1024 bytes for each queue).
1140 *
1141 * After receiving "Alive" response from uCode, driver must initialize
1142 * the scheduler (especially for queue #4, the command queue, otherwise
1143 * the driver can't issue commands!):
1144 */
1145
1146/**
1147 * Max Tx window size is the max number of contiguous TFDs that the scheduler
1148 * can keep track of at one time when creating block-ack chains of frames.
1149 * Note that "64" matches the number of ack bits in a block-ack packet.
1150 * Driver should use SCD_WIN_SIZE and SCD_FRAME_LIMIT values to initialize
1151 * SCD_CONTEXT_QUEUE_OFFSET(x) values.
1152 */
1153#define SCD_WIN_SIZE 64
1154#define SCD_FRAME_LIMIT 64
1155
1156/* SCD registers are internal, must be accessed via HBUS_TARG_PRPH regs */
1157#define SCD_START_OFFSET 0xa02c00
1158
1159/*
1160 * 4965 tells driver SRAM address for internal scheduler structs via this reg.
1161 * Value is valid only after "Alive" response from uCode.
1162 */
1163#define SCD_SRAM_BASE_ADDR (SCD_START_OFFSET + 0x0)
1164
1165/*
1166 * Driver may need to update queue-empty bits after changing queue's
1167 * write and read pointers (indexes) during (re-)initialization (i.e. when
1168 * scheduler is not tracking what's happening).
1169 * Bit fields:
1170 * 31-16: Write mask -- 1: update empty bit, 0: don't change empty bit
1171 * 15-00: Empty state, one for each queue -- 1: empty, 0: non-empty
1172 * NOTE: This register is not used by Linux driver.
1173 */
1174#define SCD_EMPTY_BITS (SCD_START_OFFSET + 0x4)
1175
1176/*
1177 * Physical base address of array of byte count (BC) circular buffers (CBs).
1178 * Each Tx queue has a BC CB in host DRAM to support Scheduler-ACK mode.
1179 * This register points to BC CB for queue 0, must be on 1024-byte boundary.
1180 * Others are spaced by 1024 bytes.
1181 * Each BC CB is 2 bytes * (256 + 64) = 740 bytes, followed by 384 bytes pad.
1182 * (Index into a queue's BC CB) = (index into queue's TFD CB) = (SSN & 0xff).
1183 * Bit fields:
1184 * 25-00: Byte Count CB physical address [35:10], must be 1024-byte aligned.
1185 */
1186#define SCD_DRAM_BASE_ADDR (SCD_START_OFFSET + 0x10)
1187
1188/*
1189 * Enables any/all Tx DMA/FIFO channels.
1190 * Scheduler generates requests for only the active channels.
1191 * Set this to 0xff to enable all 8 channels (normal usage).
1192 * Bit fields:
1193 * 7- 0: Enable (1), disable (0), one bit for each channel 0-7
1194 */
1195#define SCD_TXFACT (SCD_START_OFFSET + 0x1c)
1196
1197/* Mask to enable contiguous Tx DMA/FIFO channels between "lo" and "hi". */
1198#define SCD_TXFACT_REG_TXFIFO_MASK(lo, hi) \
1199 ((1 << (hi)) | ((1 << (hi)) - (1 << (lo))))
1200
1201/*
1202 * Queue (x) Write Pointers (indexes, really!), one for each Tx queue.
1203 * Initialized and updated by driver as new TFDs are added to queue.
1204 * NOTE: If using Block Ack, index must correspond to frame's
1205 * Start Sequence Number; index = (SSN & 0xff)
1206 * NOTE: Alternative to HBUS_TARG_WRPTR, which is what Linux driver uses?
1207 */
1208#define SCD_QUEUE_WRPTR(x) (SCD_START_OFFSET + 0x24 + (x) * 4)
1209
1210/*
1211 * Queue (x) Read Pointers (indexes, really!), one for each Tx queue.
1212 * For FIFO mode, index indicates next frame to transmit.
1213 * For Scheduler-ACK mode, index indicates first frame in Tx window.
1214 * Initialized by driver, updated by scheduler.
1215 */
1216#define SCD_QUEUE_RDPTR(x) (SCD_START_OFFSET + 0x64 + (x) * 4)
1217
1218/*
1219 * Select which queues work in chain mode (1) vs. not (0).
1220 * Use chain mode to build chains of aggregated frames.
1221 * Bit fields:
1222 * 31-16: Reserved
1223 * 15-00: Mode, one bit for each queue -- 1: Chain mode, 0: one-at-a-time
1224 * NOTE: If driver sets up queue for chain mode, it should be also set up
1225 * Scheduler-ACK mode as well, via SCD_QUEUE_STATUS_BITS(x).
1226 */
1227#define SCD_QUEUECHAIN_SEL (SCD_START_OFFSET + 0xd0)
1228
1229/*
1230 * Select which queues interrupt driver when scheduler increments
1231 * a queue's read pointer (index).
1232 * Bit fields:
1233 * 31-16: Reserved
1234 * 15-00: Interrupt enable, one bit for each queue -- 1: enabled, 0: disabled
1235 * NOTE: This functionality is apparently a no-op; driver relies on interrupts
1236 * from Rx queue to read Tx command responses and update Tx queues.
1237 */
1238#define SCD_INTERRUPT_MASK (SCD_START_OFFSET + 0xe4)
1239
1240/*
1241 * Queue search status registers. One for each queue.
1242 * Sets up queue mode and assigns queue to Tx DMA channel.
1243 * Bit fields:
1244 * 19-10: Write mask/enable bits for bits 0-9
1245 * 9: Driver should init to "0"
1246 * 8: Scheduler-ACK mode (1), non-Scheduler-ACK (i.e. FIFO) mode (0).
1247 * Driver should init to "1" for aggregation mode, or "0" otherwise.
1248 * 7-6: Driver should init to "0"
1249 * 5: Window Size Left; indicates whether scheduler can request
1250 * another TFD, based on window size, etc. Driver should init
1251 * this bit to "1" for aggregation mode, or "0" for non-agg.
1252 * 4-1: Tx FIFO to use (range 0-7).
1253 * 0: Queue is active (1), not active (0).
1254 * Other bits should be written as "0"
1255 *
1256 * NOTE: If enabling Scheduler-ACK mode, chain mode should also be enabled
1257 * via SCD_QUEUECHAIN_SEL.
1258 */
1259#define SCD_QUEUE_STATUS_BITS(x) (SCD_START_OFFSET + 0x104 + (x) * 4)
1260
1261/* Bit field positions */
1262#define SCD_QUEUE_STTS_REG_POS_ACTIVE (0)
1263#define SCD_QUEUE_STTS_REG_POS_TXF (1)
1264#define SCD_QUEUE_STTS_REG_POS_WSL (5)
1265#define SCD_QUEUE_STTS_REG_POS_SCD_ACK (8)
1266
1267/* Write masks */
1268#define SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN (10)
1269#define SCD_QUEUE_STTS_REG_MSK (0x0007FC00)
1270
1271/**
1272 * 4965 internal SRAM structures for scheduler, shared with driver ...
1273 *
1274 * Driver should clear and initialize the following areas after receiving
1275 * "Alive" response from 4965 uCode, i.e. after initial
1276 * uCode load, or after a uCode load done for error recovery:
1277 *
1278 * SCD_CONTEXT_DATA_OFFSET (size 128 bytes)
1279 * SCD_TX_STTS_BITMAP_OFFSET (size 256 bytes)
1280 * SCD_TRANSLATE_TBL_OFFSET (size 32 bytes)
1281 *
1282 * Driver accesses SRAM via HBUS_TARG_MEM_* registers.
1283 * Driver reads base address of this scheduler area from SCD_SRAM_BASE_ADDR.
1284 * All OFFSET values must be added to this base address.
1285 */
1286
1287/*
1288 * Queue context. One 8-byte entry for each of 16 queues.
1289 *
1290 * Driver should clear this entire area (size 0x80) to 0 after receiving
1291 * "Alive" notification from uCode. Additionally, driver should init
1292 * each queue's entry as follows:
1293 *
1294 * LS Dword bit fields:
1295 * 0-06: Max Tx window size for Scheduler-ACK. Driver should init to 64.
1296 *
1297 * MS Dword bit fields:
1298 * 16-22: Frame limit. Driver should init to 10 (0xa).
1299 *
1300 * Driver should init all other bits to 0.
1301 *
1302 * Init must be done after driver receives "Alive" response from 4965 uCode,
1303 * and when setting up queue for aggregation.
1304 */
1305#define SCD_CONTEXT_DATA_OFFSET 0x380
1306#define SCD_CONTEXT_QUEUE_OFFSET(x) (SCD_CONTEXT_DATA_OFFSET + ((x) * 8))
1307
1308#define SCD_QUEUE_CTX_REG1_WIN_SIZE_POS (0)
1309#define SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK (0x0000007F)
1310#define SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS (16)
1311#define SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK (0x007F0000)
1312
1313/*
1314 * Tx Status Bitmap
1315 *
1316 * Driver should clear this entire area (size 0x100) to 0 after receiving
1317 * "Alive" notification from uCode. Area is used only by device itself;
1318 * no other support (besides clearing) is required from driver.
1319 */
1320#define SCD_TX_STTS_BITMAP_OFFSET 0x400
1321
1322/*
1323 * RAxTID to queue translation mapping.
1324 *
1325 * When queue is in Scheduler-ACK mode, frames placed in a that queue must be
1326 * for only one combination of receiver address (RA) and traffic ID (TID), i.e.
1327 * one QOS priority level destined for one station (for this wireless link,
1328 * not final destination). The SCD_TRANSLATE_TABLE area provides 16 16-bit
1329 * mappings, one for each of the 16 queues. If queue is not in Scheduler-ACK
1330 * mode, the device ignores the mapping value.
1331 *
1332 * Bit fields, for each 16-bit map:
1333 * 15-9: Reserved, set to 0
1334 * 8-4: Index into device's station table for recipient station
1335 * 3-0: Traffic ID (tid), range 0-15
1336 *
1337 * Driver should clear this entire area (size 32 bytes) to 0 after receiving
1338 * "Alive" notification from uCode. To update a 16-bit map value, driver
1339 * must read a dword-aligned value from device SRAM, replace the 16-bit map
1340 * value of interest, and write the dword value back into device SRAM.
1341 */
1342#define SCD_TRANSLATE_TBL_OFFSET 0x500
1343
1344/* Find translation table dword to read/write for given queue */
1345#define SCD_TRANSLATE_TBL_OFFSET_QUEUE(x) \
1346 ((SCD_TRANSLATE_TBL_OFFSET + ((x) * 2)) & 0xfffffffc)
1347
1348#define SCD_TXFIFO_POS_TID (0)
1349#define SCD_TXFIFO_POS_RA (4)
1350#define SCD_QUEUE_RA_TID_MAP_RATID_MSK (0x01FF)
1351
1352/*********************** END TX SCHEDULER *************************************/
1353
1354static inline u8 iwl4965_hw_get_rate(__le32 rate_n_flags) 791static inline u8 iwl4965_hw_get_rate(__le32 rate_n_flags)
1355{ 792{
1356 return le32_to_cpu(rate_n_flags) & 0xFF; 793 return le32_to_cpu(rate_n_flags) & 0xFF;
1357} 794}
1358static inline u16 iwl4965_hw_get_rate_n_flags(__le32 rate_n_flags) 795static inline u32 iwl4965_hw_get_rate_n_flags(__le32 rate_n_flags)
1359{ 796{
1360 return le32_to_cpu(rate_n_flags) & 0xFFFF; 797 return le32_to_cpu(rate_n_flags) & 0x1FFFF;
1361} 798}
1362static inline __le32 iwl4965_hw_set_rate_n_flags(u8 rate, u16 flags) 799static inline __le32 iwl4965_hw_set_rate_n_flags(u8 rate, u16 flags)
1363{ 800{
@@ -1385,11 +822,11 @@ static inline __le32 iwl4965_hw_set_rate_n_flags(u8 rate, u16 flags)
1385 * up to 7 DMA channels (FIFOs). Each Tx queue is supported by a circular array 822 * up to 7 DMA channels (FIFOs). Each Tx queue is supported by a circular array
1386 * in DRAM containing 256 Transmit Frame Descriptors (TFDs). 823 * in DRAM containing 256 Transmit Frame Descriptors (TFDs).
1387 */ 824 */
1388#define IWL4965_MAX_WIN_SIZE 64 825#define IWL49_MAX_WIN_SIZE 64
1389#define IWL4965_QUEUE_SIZE 256 826#define IWL49_QUEUE_SIZE 256
1390#define IWL4965_NUM_FIFOS 7 827#define IWL49_NUM_FIFOS 7
1391#define IWL4965_MAX_NUM_QUEUES 16 828#define IWL49_CMD_FIFO_NUM 4
1392 829#define IWL49_NUM_QUEUES 16
1393 830
1394/** 831/**
1395 * struct iwl4965_tfd_frame_data 832 * struct iwl4965_tfd_frame_data
@@ -1520,10 +957,10 @@ struct iwl4965_queue_byte_cnt_entry {
1520 * 4965 assumes tables are separated by 1024 bytes. 957 * 4965 assumes tables are separated by 1024 bytes.
1521 */ 958 */
1522struct iwl4965_sched_queue_byte_cnt_tbl { 959struct iwl4965_sched_queue_byte_cnt_tbl {
1523 struct iwl4965_queue_byte_cnt_entry tfd_offset[IWL4965_QUEUE_SIZE + 960 struct iwl4965_queue_byte_cnt_entry tfd_offset[IWL49_QUEUE_SIZE +
1524 IWL4965_MAX_WIN_SIZE]; 961 IWL49_MAX_WIN_SIZE];
1525 u8 dont_care[1024 - 962 u8 dont_care[1024 -
1526 (IWL4965_QUEUE_SIZE + IWL4965_MAX_WIN_SIZE) * 963 (IWL49_QUEUE_SIZE + IWL49_MAX_WIN_SIZE) *
1527 sizeof(__le16)]; 964 sizeof(__le16)];
1528} __attribute__ ((packed)); 965} __attribute__ ((packed));
1529 966
@@ -1553,7 +990,7 @@ struct iwl4965_sched_queue_byte_cnt_tbl {
1553 */ 990 */
1554struct iwl4965_shared { 991struct iwl4965_shared {
1555 struct iwl4965_sched_queue_byte_cnt_tbl 992 struct iwl4965_sched_queue_byte_cnt_tbl
1556 queues_byte_cnt_tbls[IWL4965_MAX_NUM_QUEUES]; 993 queues_byte_cnt_tbls[IWL49_NUM_QUEUES];
1557 __le32 rb_closed; 994 __le32 rb_closed;
1558 995
1559 /* __le32 rb_closed_stts_rb_num:12; */ 996 /* __le32 rb_closed_stts_rb_num:12; */
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965-rs.c b/drivers/net/wireless/iwlwifi/iwl-4965-rs.c
index c9847b1a67f7..24dee00b0e85 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-4965-rs.c
@@ -28,7 +28,6 @@
28#include <linux/skbuff.h> 28#include <linux/skbuff.h>
29#include <linux/wireless.h> 29#include <linux/wireless.h>
30#include <net/mac80211.h> 30#include <net/mac80211.h>
31#include <net/ieee80211.h>
32 31
33#include <linux/netdevice.h> 32#include <linux/netdevice.h>
34#include <linux/etherdevice.h> 33#include <linux/etherdevice.h>
@@ -38,13 +37,13 @@
38 37
39#include "../net/mac80211/rate.h" 38#include "../net/mac80211/rate.h"
40 39
41#include "iwl-4965.h" 40#include "iwl-dev.h"
42#include "iwl-core.h" 41#include "iwl-core.h"
43#include "iwl-helpers.h" 42#include "iwl-helpers.h"
44 43
45#define RS_NAME "iwl-4965-rs" 44#define RS_NAME "iwl-4965-rs"
46 45
47#define NUM_TRY_BEFORE_ANTENNA_TOGGLE 1 46#define NUM_TRY_BEFORE_ANT_TOGGLE 1
48#define IWL_NUMBER_TRY 1 47#define IWL_NUMBER_TRY 1
49#define IWL_HT_NUMBER_TRY 3 48#define IWL_HT_NUMBER_TRY 3
50 49
@@ -65,9 +64,16 @@ static u8 rs_ht_to_legacy[] = {
65 IWL_RATE_48M_INDEX, IWL_RATE_54M_INDEX 64 IWL_RATE_48M_INDEX, IWL_RATE_54M_INDEX
66}; 65};
67 66
68struct iwl4965_rate { 67static const u8 ant_toggle_lookup[] = {
69 u32 rate_n_flags; 68 /*ANT_NONE -> */ ANT_NONE,
70} __attribute__ ((packed)); 69 /*ANT_A -> */ ANT_B,
70 /*ANT_B -> */ ANT_C,
71 /*ANT_AB -> */ ANT_BC,
72 /*ANT_C -> */ ANT_A,
73 /*ANT_AC -> */ ANT_AB,
74 /*ANT_BC -> */ ANT_AC,
75 /*ANT_ABC -> */ ANT_ABC,
76};
71 77
72/** 78/**
73 * struct iwl4965_rate_scale_data -- tx success history for one rate 79 * struct iwl4965_rate_scale_data -- tx success history for one rate
@@ -88,14 +94,14 @@ struct iwl4965_rate_scale_data {
88 * one for "active", and one for "search". 94 * one for "active", and one for "search".
89 */ 95 */
90struct iwl4965_scale_tbl_info { 96struct iwl4965_scale_tbl_info {
91 enum iwl4965_table_type lq_type; 97 enum iwl_table_type lq_type;
92 enum iwl4965_antenna_type antenna_type; 98 u8 ant_type;
93 u8 is_SGI; /* 1 = short guard interval */ 99 u8 is_SGI; /* 1 = short guard interval */
94 u8 is_fat; /* 1 = 40 MHz channel width */ 100 u8 is_fat; /* 1 = 40 MHz channel width */
95 u8 is_dup; /* 1 = duplicated data streams */ 101 u8 is_dup; /* 1 = duplicated data streams */
96 u8 action; /* change modulation; IWL_[LEGACY/SISO/MIMO]_SWITCH_* */ 102 u8 action; /* change modulation; IWL_[LEGACY/SISO/MIMO]_SWITCH_* */
97 s32 *expected_tpt; /* throughput metrics; expected_tpt_G, etc. */ 103 s32 *expected_tpt; /* throughput metrics; expected_tpt_G, etc. */
98 struct iwl4965_rate current_rate; /* rate_n_flags, uCode API format */ 104 u32 current_rate; /* rate_n_flags, uCode API format */
99 struct iwl4965_rate_scale_data win[IWL_RATE_COUNT]; /* rate histories */ 105 struct iwl4965_rate_scale_data win[IWL_RATE_COUNT]; /* rate histories */
100}; 106};
101 107
@@ -136,8 +142,6 @@ struct iwl4965_lq_sta {
136 u32 flush_timer; /* time staying in mode before new search */ 142 u32 flush_timer; /* time staying in mode before new search */
137 143
138 u8 action_counter; /* # mode-switch actions tried */ 144 u8 action_counter; /* # mode-switch actions tried */
139 u8 antenna;
140 u8 valid_antenna;
141 u8 is_green; 145 u8 is_green;
142 u8 is_dup; 146 u8 is_dup;
143 enum ieee80211_band band; 147 enum ieee80211_band band;
@@ -145,9 +149,10 @@ struct iwl4965_lq_sta {
145 149
146 /* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */ 150 /* The following are bitmaps of rates; IWL_RATE_6M_MASK, etc. */
147 u32 supp_rates; 151 u32 supp_rates;
148 u16 active_rate; 152 u16 active_legacy_rate;
149 u16 active_siso_rate; 153 u16 active_siso_rate;
150 u16 active_mimo_rate; 154 u16 active_mimo2_rate;
155 u16 active_mimo3_rate;
151 u16 active_rate_basic; 156 u16 active_rate_basic;
152 157
153 struct iwl_link_quality_cmd lq; 158 struct iwl_link_quality_cmd lq;
@@ -162,7 +167,7 @@ struct iwl4965_lq_sta {
162#ifdef CONFIG_IWL4965_HT 167#ifdef CONFIG_IWL4965_HT
163 struct dentry *rs_sta_dbgfs_tx_agg_tid_en_file; 168 struct dentry *rs_sta_dbgfs_tx_agg_tid_en_file;
164#endif 169#endif
165 struct iwl4965_rate dbg_fixed; 170 u32 dbg_fixed_rate;
166#endif 171#endif
167 struct iwl_priv *drv; 172 struct iwl_priv *drv;
168}; 173};
@@ -171,17 +176,17 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
171 struct net_device *dev, 176 struct net_device *dev,
172 struct ieee80211_hdr *hdr, 177 struct ieee80211_hdr *hdr,
173 struct sta_info *sta); 178 struct sta_info *sta);
174static void rs_fill_link_cmd(struct iwl4965_lq_sta *lq_sta, 179static void rs_fill_link_cmd(const struct iwl_priv *priv,
175 struct iwl4965_rate *tx_mcs, 180 struct iwl4965_lq_sta *lq_sta,
176 struct iwl_link_quality_cmd *tbl); 181 u32 rate_n_flags);
177 182
178 183
179#ifdef CONFIG_MAC80211_DEBUGFS 184#ifdef CONFIG_MAC80211_DEBUGFS
180static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta, 185static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta,
181 struct iwl4965_rate *mcs, int index); 186 u32 *rate_n_flags, int index);
182#else 187#else
183static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta, 188static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta,
184 struct iwl4965_rate *mcs, int index) 189 u32 *rate_n_flags, int index)
185{} 190{}
186#endif 191#endif
187 192
@@ -190,6 +195,7 @@ static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta,
190 * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits 195 * 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 60 MBits
191 * "G" is the only table that supports CCK (the first 4 rates). 196 * "G" is the only table that supports CCK (the first 4 rates).
192 */ 197 */
198/*FIXME:RS:need to spearate tables for MIMO2/MIMO3*/
193static s32 expected_tpt_A[IWL_RATE_COUNT] = { 199static s32 expected_tpt_A[IWL_RATE_COUNT] = {
194 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186, 186 200 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186, 186
195}; 201};
@@ -230,7 +236,7 @@ static s32 expected_tpt_mimo40MHzSGI[IWL_RATE_COUNT] = {
230 0, 0, 0, 0, 131, 131, 191, 222, 242, 270, 284, 289, 293 236 0, 0, 0, 0, 131, 131, 191, 222, 242, 270, 284, 289, 293
231}; 237};
232 238
233static inline u8 iwl4965_rate_get_rate(u32 rate_n_flags) 239static inline u8 rs_extract_rate(u32 rate_n_flags)
234{ 240{
235 return (u8)(rate_n_flags & 0xFF); 241 return (u8)(rate_n_flags & 0xFF);
236} 242}
@@ -245,6 +251,11 @@ static void rs_rate_scale_clear_window(struct iwl4965_rate_scale_data *window)
245 window->stamp = 0; 251 window->stamp = 0;
246} 252}
247 253
254static inline u8 rs_is_valid_ant(u8 valid_antenna, u8 ant_type)
255{
256 return ((ant_type & valid_antenna) == ant_type);
257}
258
248#ifdef CONFIG_IWL4965_HT 259#ifdef CONFIG_IWL4965_HT
249/* 260/*
250 * removes the old data from the statistics. All data that is older than 261 * removes the old data from the statistics. All data that is older than
@@ -374,6 +385,13 @@ static void rs_tl_turn_on_agg(struct iwl_priv *priv, u8 tid,
374 385
375#endif /* CONFIG_IWLWIFI_HT */ 386#endif /* CONFIG_IWLWIFI_HT */
376 387
388static inline int get_num_of_ant_from_rate(u32 rate_n_flags)
389{
390 return (!!(rate_n_flags & RATE_MCS_ANT_A_MSK) +
391 !!(rate_n_flags & RATE_MCS_ANT_B_MSK) +
392 !!(rate_n_flags & RATE_MCS_ANT_C_MSK));
393}
394
377/** 395/**
378 * rs_collect_tx_data - Update the success/failure sliding window 396 * rs_collect_tx_data - Update the success/failure sliding window
379 * 397 *
@@ -386,8 +404,7 @@ static int rs_collect_tx_data(struct iwl4965_rate_scale_data *windows,
386 int successes) 404 int successes)
387{ 405{
388 struct iwl4965_rate_scale_data *window = NULL; 406 struct iwl4965_rate_scale_data *window = NULL;
389 u64 mask; 407 static const u64 mask = (((u64)1) << (IWL_RATE_MAX_WINDOW - 1));
390 u8 win_size = IWL_RATE_MAX_WINDOW;
391 s32 fail_count; 408 s32 fail_count;
392 409
393 if (scale_index < 0 || scale_index >= IWL_RATE_COUNT) 410 if (scale_index < 0 || scale_index >= IWL_RATE_COUNT)
@@ -405,14 +422,14 @@ static int rs_collect_tx_data(struct iwl4965_rate_scale_data *windows,
405 * we keep these bitmaps!). 422 * we keep these bitmaps!).
406 */ 423 */
407 while (retries > 0) { 424 while (retries > 0) {
408 if (window->counter >= win_size) { 425 if (window->counter >= IWL_RATE_MAX_WINDOW) {
409 window->counter = win_size - 1; 426
410 mask = 1; 427 /* remove earliest */
411 mask = (mask << (win_size - 1)); 428 window->counter = IWL_RATE_MAX_WINDOW - 1;
429
412 if (window->data & mask) { 430 if (window->data & mask) {
413 window->data &= ~mask; 431 window->data &= ~mask;
414 window->success_counter = 432 window->success_counter--;
415 window->success_counter - 1;
416 } 433 }
417 } 434 }
418 435
@@ -422,10 +439,9 @@ static int rs_collect_tx_data(struct iwl4965_rate_scale_data *windows,
422 /* Shift bitmap by one frame (throw away oldest history), 439 /* Shift bitmap by one frame (throw away oldest history),
423 * OR in "1", and increment "success" if this 440 * OR in "1", and increment "success" if this
424 * frame was successful. */ 441 * frame was successful. */
425 mask = window->data; 442 window->data <<= 1;;
426 window->data = (mask << 1);
427 if (successes > 0) { 443 if (successes > 0) {
428 window->success_counter = window->success_counter + 1; 444 window->success_counter++;
429 window->data |= 0x1; 445 window->data |= 0x1;
430 successes--; 446 successes--;
431 } 447 }
@@ -458,170 +474,166 @@ static int rs_collect_tx_data(struct iwl4965_rate_scale_data *windows,
458/* 474/*
459 * Fill uCode API rate_n_flags field, based on "search" or "active" table. 475 * Fill uCode API rate_n_flags field, based on "search" or "active" table.
460 */ 476 */
461static void rs_mcs_from_tbl(struct iwl4965_rate *mcs_rate, 477/* FIXME:RS:remove this function and put the flags statically in the table */
462 struct iwl4965_scale_tbl_info *tbl, 478static u32 rate_n_flags_from_tbl(struct iwl4965_scale_tbl_info *tbl,
463 int index, u8 use_green) 479 int index, u8 use_green)
464{ 480{
481 u32 rate_n_flags = 0;
482
465 if (is_legacy(tbl->lq_type)) { 483 if (is_legacy(tbl->lq_type)) {
466 mcs_rate->rate_n_flags = iwl4965_rates[index].plcp; 484 rate_n_flags = iwl4965_rates[index].plcp;
467 if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE) 485 if (index >= IWL_FIRST_CCK_RATE && index <= IWL_LAST_CCK_RATE)
468 mcs_rate->rate_n_flags |= RATE_MCS_CCK_MSK; 486 rate_n_flags |= RATE_MCS_CCK_MSK;
469 487
470 } else if (is_siso(tbl->lq_type)) { 488 } else if (is_Ht(tbl->lq_type)) {
471 if (index > IWL_LAST_OFDM_RATE) 489 if (index > IWL_LAST_OFDM_RATE) {
472 index = IWL_LAST_OFDM_RATE; 490 IWL_ERROR("invalid HT rate index %d\n", index);
473 mcs_rate->rate_n_flags = iwl4965_rates[index].plcp_siso |
474 RATE_MCS_HT_MSK;
475 } else {
476 if (index > IWL_LAST_OFDM_RATE)
477 index = IWL_LAST_OFDM_RATE; 491 index = IWL_LAST_OFDM_RATE;
478 mcs_rate->rate_n_flags = iwl4965_rates[index].plcp_mimo | 492 }
479 RATE_MCS_HT_MSK; 493 rate_n_flags = RATE_MCS_HT_MSK;
480 }
481
482 switch (tbl->antenna_type) {
483 case ANT_BOTH:
484 mcs_rate->rate_n_flags |= RATE_MCS_ANT_AB_MSK;
485 break;
486 case ANT_MAIN:
487 mcs_rate->rate_n_flags |= RATE_MCS_ANT_A_MSK;
488 break;
489 case ANT_AUX:
490 mcs_rate->rate_n_flags |= RATE_MCS_ANT_B_MSK;
491 break;
492 case ANT_NONE:
493 break;
494 }
495
496 if (is_legacy(tbl->lq_type))
497 return;
498 494
499 if (tbl->is_fat) { 495 if (is_siso(tbl->lq_type))
500 if (tbl->is_dup) 496 rate_n_flags |= iwl4965_rates[index].plcp_siso;
501 mcs_rate->rate_n_flags |= RATE_MCS_DUP_MSK; 497 else if (is_mimo2(tbl->lq_type))
498 rate_n_flags |= iwl4965_rates[index].plcp_mimo2;
502 else 499 else
503 mcs_rate->rate_n_flags |= RATE_MCS_FAT_MSK; 500 rate_n_flags |= iwl4965_rates[index].plcp_mimo3;
501 } else {
502 IWL_ERROR("Invalid tbl->lq_type %d\n", tbl->lq_type);
504 } 503 }
505 if (tbl->is_SGI)
506 mcs_rate->rate_n_flags |= RATE_MCS_SGI_MSK;
507 504
508 if (use_green) { 505 rate_n_flags |= ((tbl->ant_type << RATE_MCS_ANT_POS) &
509 mcs_rate->rate_n_flags |= RATE_MCS_GF_MSK; 506 RATE_MCS_ANT_ABC_MSK);
510 if (is_siso(tbl->lq_type)) 507
511 mcs_rate->rate_n_flags &= ~RATE_MCS_SGI_MSK; 508 if (is_Ht(tbl->lq_type)) {
509 if (tbl->is_fat) {
510 if (tbl->is_dup)
511 rate_n_flags |= RATE_MCS_DUP_MSK;
512 else
513 rate_n_flags |= RATE_MCS_FAT_MSK;
514 }
515 if (tbl->is_SGI)
516 rate_n_flags |= RATE_MCS_SGI_MSK;
517
518 if (use_green) {
519 rate_n_flags |= RATE_MCS_GF_MSK;
520 if (is_siso(tbl->lq_type) && tbl->is_SGI) {
521 rate_n_flags &= ~RATE_MCS_SGI_MSK;
522 IWL_ERROR("GF was set with SGI:SISO\n");
523 }
524 }
512 } 525 }
526 return rate_n_flags;
513} 527}
514 528
515/* 529/*
516 * Interpret uCode API's rate_n_flags format, 530 * Interpret uCode API's rate_n_flags format,
517 * fill "search" or "active" tx mode table. 531 * fill "search" or "active" tx mode table.
518 */ 532 */
519static int rs_get_tbl_info_from_mcs(const struct iwl4965_rate *mcs_rate, 533static int rs_get_tbl_info_from_mcs(const u32 rate_n_flags,
520 enum ieee80211_band band, 534 enum ieee80211_band band,
521 struct iwl4965_scale_tbl_info *tbl, 535 struct iwl4965_scale_tbl_info *tbl,
522 int *rate_idx) 536 int *rate_idx)
523{ 537{
524 int index; 538 u32 ant_msk = (rate_n_flags & RATE_MCS_ANT_ABC_MSK);
525 u32 ant_msk; 539 u8 num_of_ant = get_num_of_ant_from_rate(rate_n_flags);
540 u8 mcs;
526 541
527 index = iwl4965_hwrate_to_plcp_idx(mcs_rate->rate_n_flags); 542 *rate_idx = iwl4965_hwrate_to_plcp_idx(rate_n_flags);
528 543
529 if (index == IWL_RATE_INVALID) { 544 if (*rate_idx == IWL_RATE_INVALID) {
530 *rate_idx = -1; 545 *rate_idx = -1;
531 return -EINVAL; 546 return -EINVAL;
532 } 547 }
533 tbl->is_SGI = 0; /* default legacy setup */ 548 tbl->is_SGI = 0; /* default legacy setup */
534 tbl->is_fat = 0; 549 tbl->is_fat = 0;
535 tbl->is_dup = 0; 550 tbl->is_dup = 0;
536 tbl->antenna_type = ANT_BOTH; /* default MIMO setup */ 551 tbl->ant_type = (ant_msk >> RATE_MCS_ANT_POS);
552 tbl->lq_type = LQ_NONE;
537 553
538 /* legacy rate format */ 554 /* legacy rate format */
539 if (!(mcs_rate->rate_n_flags & RATE_MCS_HT_MSK)) { 555 if (!(rate_n_flags & RATE_MCS_HT_MSK)) {
540 ant_msk = (mcs_rate->rate_n_flags & RATE_MCS_ANT_AB_MSK); 556 if (num_of_ant == 1) {
541
542 if (ant_msk == RATE_MCS_ANT_AB_MSK)
543 tbl->lq_type = LQ_NONE;
544 else {
545
546 if (band == IEEE80211_BAND_5GHZ) 557 if (band == IEEE80211_BAND_5GHZ)
547 tbl->lq_type = LQ_A; 558 tbl->lq_type = LQ_A;
548 else 559 else
549 tbl->lq_type = LQ_G; 560 tbl->lq_type = LQ_G;
550
551 if (mcs_rate->rate_n_flags & RATE_MCS_ANT_A_MSK)
552 tbl->antenna_type = ANT_MAIN;
553 else
554 tbl->antenna_type = ANT_AUX;
555 } 561 }
556 *rate_idx = index; 562 /* HT rate format */
557
558 /* HT rate format, SISO (might be 20 MHz legacy or 40 MHz fat width) */
559 } else if (iwl4965_rate_get_rate(mcs_rate->rate_n_flags)
560 <= IWL_RATE_SISO_60M_PLCP) {
561 tbl->lq_type = LQ_SISO;
562
563 ant_msk = (mcs_rate->rate_n_flags & RATE_MCS_ANT_AB_MSK);
564 if (ant_msk == RATE_MCS_ANT_AB_MSK)
565 tbl->lq_type = LQ_NONE;
566 else {
567 if (mcs_rate->rate_n_flags & RATE_MCS_ANT_A_MSK)
568 tbl->antenna_type = ANT_MAIN;
569 else
570 tbl->antenna_type = ANT_AUX;
571 }
572 if (mcs_rate->rate_n_flags & RATE_MCS_SGI_MSK)
573 tbl->is_SGI = 1;
574
575 if ((mcs_rate->rate_n_flags & RATE_MCS_FAT_MSK) ||
576 (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK))
577 tbl->is_fat = 1;
578
579 if (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK)
580 tbl->is_dup = 1;
581
582 *rate_idx = index;
583
584 /* HT rate format, MIMO (might be 20 MHz legacy or 40 MHz fat width) */
585 } else { 563 } else {
586 tbl->lq_type = LQ_MIMO; 564 if (rate_n_flags & RATE_MCS_SGI_MSK)
587 if (mcs_rate->rate_n_flags & RATE_MCS_SGI_MSK)
588 tbl->is_SGI = 1; 565 tbl->is_SGI = 1;
589 566
590 if ((mcs_rate->rate_n_flags & RATE_MCS_FAT_MSK) || 567 if ((rate_n_flags & RATE_MCS_FAT_MSK) ||
591 (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK)) 568 (rate_n_flags & RATE_MCS_DUP_MSK))
592 tbl->is_fat = 1; 569 tbl->is_fat = 1;
593 570
594 if (mcs_rate->rate_n_flags & RATE_MCS_DUP_MSK) 571 if (rate_n_flags & RATE_MCS_DUP_MSK)
595 tbl->is_dup = 1; 572 tbl->is_dup = 1;
596 *rate_idx = index; 573
574 mcs = rs_extract_rate(rate_n_flags);
575
576 /* SISO */
577 if (mcs <= IWL_RATE_SISO_60M_PLCP) {
578 if (num_of_ant == 1)
579 tbl->lq_type = LQ_SISO; /*else NONE*/
580 /* MIMO2 */
581 } else if (mcs <= IWL_RATE_MIMO2_60M_PLCP) {
582 if (num_of_ant == 2)
583 tbl->lq_type = LQ_MIMO2;
584 /* MIMO3 */
585 } else {
586 if (num_of_ant == 3)
587 tbl->lq_type = LQ_MIMO3;
588 }
597 } 589 }
598 return 0; 590 return 0;
599} 591}
600 592
601static inline void rs_toggle_antenna(struct iwl4965_rate *new_rate, 593/* switch to another antenna/antennas and return 1 */
602 struct iwl4965_scale_tbl_info *tbl) 594/* if no other valid antenna found, return 0 */
595static int rs_toggle_antenna(u32 valid_ant, u32 *rate_n_flags,
596 struct iwl4965_scale_tbl_info *tbl)
603{ 597{
604 if (tbl->antenna_type == ANT_AUX) { 598 u8 new_ant_type;
605 tbl->antenna_type = ANT_MAIN; 599
606 new_rate->rate_n_flags &= ~RATE_MCS_ANT_B_MSK; 600 if (!tbl->ant_type || tbl->ant_type > ANT_ABC)
607 new_rate->rate_n_flags |= RATE_MCS_ANT_A_MSK; 601 return 0;
608 } else { 602
609 tbl->antenna_type = ANT_AUX; 603 if (!rs_is_valid_ant(valid_ant, tbl->ant_type))
610 new_rate->rate_n_flags &= ~RATE_MCS_ANT_A_MSK; 604 return 0;
611 new_rate->rate_n_flags |= RATE_MCS_ANT_B_MSK; 605
612 } 606 new_ant_type = ant_toggle_lookup[tbl->ant_type];
607
608 while ((new_ant_type != tbl->ant_type) &&
609 !rs_is_valid_ant(valid_ant, new_ant_type))
610 new_ant_type = ant_toggle_lookup[new_ant_type];
611
612 if (new_ant_type == tbl->ant_type)
613 return 0;
614
615 tbl->ant_type = new_ant_type;
616 *rate_n_flags &= ~RATE_MCS_ANT_ABC_MSK;
617 *rate_n_flags |= new_ant_type << RATE_MCS_ANT_POS;
618 return 1;
613} 619}
614 620
615static inline u8 rs_use_green(struct iwl_priv *priv, 621/* FIXME:RS: in 4965 we don't use greenfield at all */
616 struct ieee80211_conf *conf) 622/* FIXME:RS: don't use greenfield for now in TX */
623/* #ifdef CONFIG_IWL4965_HT */
624#if 0
625static inline u8 rs_use_green(struct iwl_priv *priv, struct ieee80211_conf *conf)
617{ 626{
618#ifdef CONFIG_IWL4965_HT
619 return ((conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) && 627 return ((conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) &&
620 priv->current_ht_config.is_green_field && 628 priv->current_ht_config.is_green_field &&
621 !priv->current_ht_config.non_GF_STA_present); 629 !priv->current_ht_config.non_GF_STA_present);
622#endif /* CONFIG_IWL4965_HT */ 630}
631#else
632static inline u8 rs_use_green(struct iwl_priv *priv, struct ieee80211_conf *conf)
633{
623 return 0; 634 return 0;
624} 635}
636#endif /* CONFIG_IWL4965_HT */
625 637
626/** 638/**
627 * rs_get_supported_rates - get the available rates 639 * rs_get_supported_rates - get the available rates
@@ -630,23 +642,23 @@ static inline u8 rs_use_green(struct iwl_priv *priv,
630 * basic available rates. 642 * basic available rates.
631 * 643 *
632 */ 644 */
633static void rs_get_supported_rates(struct iwl4965_lq_sta *lq_sta, 645static u16 rs_get_supported_rates(struct iwl4965_lq_sta *lq_sta,
634 struct ieee80211_hdr *hdr, 646 struct ieee80211_hdr *hdr,
635 enum iwl4965_table_type rate_type, 647 enum iwl_table_type rate_type)
636 u16 *data_rate)
637{ 648{
638 if (is_legacy(rate_type)) 649 if (hdr && is_multicast_ether_addr(hdr->addr1) &&
639 *data_rate = lq_sta->active_rate; 650 lq_sta->active_rate_basic)
640 else { 651 return lq_sta->active_rate_basic;
652
653 if (is_legacy(rate_type)) {
654 return lq_sta->active_legacy_rate;
655 } else {
641 if (is_siso(rate_type)) 656 if (is_siso(rate_type))
642 *data_rate = lq_sta->active_siso_rate; 657 return lq_sta->active_siso_rate;
658 else if (is_mimo2(rate_type))
659 return lq_sta->active_mimo2_rate;
643 else 660 else
644 *data_rate = lq_sta->active_mimo_rate; 661 return lq_sta->active_mimo3_rate;
645 }
646
647 if (hdr && is_multicast_ether_addr(hdr->addr1) &&
648 lq_sta->active_rate_basic) {
649 *data_rate = lq_sta->active_rate_basic;
650 } 662 }
651} 663}
652 664
@@ -705,9 +717,9 @@ static u16 rs_get_adjacent_rate(u8 index, u16 rate_mask, int rate_type)
705 return (high << 8) | low; 717 return (high << 8) | low;
706} 718}
707 719
708static void rs_get_lower_rate(struct iwl4965_lq_sta *lq_sta, 720static u32 rs_get_lower_rate(struct iwl4965_lq_sta *lq_sta,
709 struct iwl4965_scale_tbl_info *tbl, u8 scale_index, 721 struct iwl4965_scale_tbl_info *tbl, u8 scale_index,
710 u8 ht_possible, struct iwl4965_rate *mcs_rate) 722 u8 ht_possible)
711{ 723{
712 s32 low; 724 s32 low;
713 u16 rate_mask; 725 u16 rate_mask;
@@ -726,15 +738,14 @@ static void rs_get_lower_rate(struct iwl4965_lq_sta *lq_sta,
726 else 738 else
727 tbl->lq_type = LQ_G; 739 tbl->lq_type = LQ_G;
728 740
729 if ((tbl->antenna_type == ANT_BOTH) || 741 if (num_of_ant(tbl->ant_type) > 1)
730 (tbl->antenna_type == ANT_NONE)) 742 tbl->ant_type = ANT_A;/*FIXME:RS*/
731 tbl->antenna_type = ANT_MAIN;
732 743
733 tbl->is_fat = 0; 744 tbl->is_fat = 0;
734 tbl->is_SGI = 0; 745 tbl->is_SGI = 0;
735 } 746 }
736 747
737 rs_get_supported_rates(lq_sta, NULL, tbl->lq_type, &rate_mask); 748 rate_mask = rs_get_supported_rates(lq_sta, NULL, tbl->lq_type);
738 749
739 /* Mask with station rate restriction */ 750 /* Mask with station rate restriction */
740 if (is_legacy(tbl->lq_type)) { 751 if (is_legacy(tbl->lq_type)) {
@@ -748,17 +759,18 @@ static void rs_get_lower_rate(struct iwl4965_lq_sta *lq_sta,
748 759
749 /* If we switched from HT to legacy, check current rate */ 760 /* If we switched from HT to legacy, check current rate */
750 if (switch_to_legacy && (rate_mask & (1 << scale_index))) { 761 if (switch_to_legacy && (rate_mask & (1 << scale_index))) {
751 rs_mcs_from_tbl(mcs_rate, tbl, scale_index, is_green); 762 low = scale_index;
752 return; 763 goto out;
753 } 764 }
754 765
755 high_low = rs_get_adjacent_rate(scale_index, rate_mask, tbl->lq_type); 766 high_low = rs_get_adjacent_rate(scale_index, rate_mask, tbl->lq_type);
756 low = high_low & 0xff; 767 low = high_low & 0xff;
757 768
758 if (low != IWL_RATE_INVALID) 769 if (low == IWL_RATE_INVALID)
759 rs_mcs_from_tbl(mcs_rate, tbl, low, is_green); 770 low = scale_index;
760 else 771
761 rs_mcs_from_tbl(mcs_rate, tbl, scale_index, is_green); 772out:
773 return rate_n_flags_from_tbl(tbl, low, is_green);
762} 774}
763 775
764/* 776/*
@@ -780,7 +792,7 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
780 struct ieee80211_hw *hw = local_to_hw(local); 792 struct ieee80211_hw *hw = local_to_hw(local);
781 struct iwl4965_rate_scale_data *window = NULL; 793 struct iwl4965_rate_scale_data *window = NULL;
782 struct iwl4965_rate_scale_data *search_win = NULL; 794 struct iwl4965_rate_scale_data *search_win = NULL;
783 struct iwl4965_rate tx_mcs; 795 u32 tx_rate;
784 struct iwl4965_scale_tbl_info tbl_type; 796 struct iwl4965_scale_tbl_info tbl_type;
785 struct iwl4965_scale_tbl_info *curr_tbl, *search_tbl; 797 struct iwl4965_scale_tbl_info *curr_tbl, *search_tbl;
786 u8 active_index = 0; 798 u8 active_index = 0;
@@ -822,15 +834,6 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
822 table = &lq_sta->lq; 834 table = &lq_sta->lq;
823 active_index = lq_sta->active_tbl; 835 active_index = lq_sta->active_tbl;
824 836
825 /* Get mac80211 antenna info */
826 lq_sta->antenna =
827 (lq_sta->valid_antenna & local->hw.conf.antenna_sel_tx);
828 if (!lq_sta->antenna)
829 lq_sta->antenna = lq_sta->valid_antenna;
830
831 /* Ignore mac80211 antenna info for now */
832 lq_sta->antenna = lq_sta->valid_antenna;
833
834 curr_tbl = &(lq_sta->lq_info[active_index]); 837 curr_tbl = &(lq_sta->lq_info[active_index]);
835 search_tbl = &(lq_sta->lq_info[(1 - active_index)]); 838 search_tbl = &(lq_sta->lq_info[(1 - active_index)]);
836 window = (struct iwl4965_rate_scale_data *) 839 window = (struct iwl4965_rate_scale_data *)
@@ -846,8 +849,8 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
846 * to check "search" mode, or a prior "search" mode after we've moved 849 * to check "search" mode, or a prior "search" mode after we've moved
847 * to a new "search" mode (which might become the new "active" mode). 850 * to a new "search" mode (which might become the new "active" mode).
848 */ 851 */
849 tx_mcs.rate_n_flags = le32_to_cpu(table->rs_table[0].rate_n_flags); 852 tx_rate = le32_to_cpu(table->rs_table[0].rate_n_flags);
850 rs_get_tbl_info_from_mcs(&tx_mcs, priv->band, &tbl_type, &rs_index); 853 rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, &rs_index);
851 if (priv->band == IEEE80211_BAND_5GHZ) 854 if (priv->band == IEEE80211_BAND_5GHZ)
852 rs_index -= IWL_FIRST_OFDM_RATE; 855 rs_index -= IWL_FIRST_OFDM_RATE;
853 856
@@ -858,16 +861,14 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
858 !!(tx_resp->control.flags & IEEE80211_TXCTL_40_MHZ_WIDTH)) || 861 !!(tx_resp->control.flags & IEEE80211_TXCTL_40_MHZ_WIDTH)) ||
859 (tbl_type.is_dup ^ 862 (tbl_type.is_dup ^
860 !!(tx_resp->control.flags & IEEE80211_TXCTL_DUP_DATA)) || 863 !!(tx_resp->control.flags & IEEE80211_TXCTL_DUP_DATA)) ||
861 (tbl_type.antenna_type ^ 864 (tbl_type.ant_type ^ tx_resp->control.antenna_sel_tx) ||
862 tx_resp->control.antenna_sel_tx) || 865 (!!(tx_rate & RATE_MCS_HT_MSK) ^
863 (!!(tx_mcs.rate_n_flags & RATE_MCS_HT_MSK) ^
864 !!(tx_resp->control.flags & IEEE80211_TXCTL_OFDM_HT)) || 866 !!(tx_resp->control.flags & IEEE80211_TXCTL_OFDM_HT)) ||
865 (!!(tx_mcs.rate_n_flags & RATE_MCS_GF_MSK) ^ 867 (!!(tx_rate & RATE_MCS_GF_MSK) ^
866 !!(tx_resp->control.flags & IEEE80211_TXCTL_GREEN_FIELD)) || 868 !!(tx_resp->control.flags & IEEE80211_TXCTL_GREEN_FIELD)) ||
867 (hw->wiphy->bands[priv->band]->bitrates[rs_index].bitrate != 869 (hw->wiphy->bands[priv->band]->bitrates[rs_index].bitrate !=
868 tx_resp->control.tx_rate->bitrate)) { 870 tx_resp->control.tx_rate->bitrate)) {
869 IWL_DEBUG_RATE("initial rate does not match 0x%x\n", 871 IWL_DEBUG_RATE("initial rate does not match 0x%x\n", tx_rate);
870 tx_mcs.rate_n_flags);
871 goto out; 872 goto out;
872 } 873 }
873 874
@@ -875,15 +876,14 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
875 while (retries) { 876 while (retries) {
876 /* Look up the rate and other info used for each tx attempt. 877 /* Look up the rate and other info used for each tx attempt.
877 * Each tx attempt steps one entry deeper in the rate table. */ 878 * Each tx attempt steps one entry deeper in the rate table. */
878 tx_mcs.rate_n_flags = 879 tx_rate = le32_to_cpu(table->rs_table[index].rate_n_flags);
879 le32_to_cpu(table->rs_table[index].rate_n_flags); 880 rs_get_tbl_info_from_mcs(tx_rate, priv->band,
880 rs_get_tbl_info_from_mcs(&tx_mcs, priv->band,
881 &tbl_type, &rs_index); 881 &tbl_type, &rs_index);
882 882
883 /* If type matches "search" table, 883 /* If type matches "search" table,
884 * add failure to "search" history */ 884 * add failure to "search" history */
885 if ((tbl_type.lq_type == search_tbl->lq_type) && 885 if ((tbl_type.lq_type == search_tbl->lq_type) &&
886 (tbl_type.antenna_type == search_tbl->antenna_type) && 886 (tbl_type.ant_type == search_tbl->ant_type) &&
887 (tbl_type.is_SGI == search_tbl->is_SGI)) { 887 (tbl_type.is_SGI == search_tbl->is_SGI)) {
888 if (search_tbl->expected_tpt) 888 if (search_tbl->expected_tpt)
889 tpt = search_tbl->expected_tpt[rs_index]; 889 tpt = search_tbl->expected_tpt[rs_index];
@@ -894,7 +894,7 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
894 /* Else if type matches "current/active" table, 894 /* Else if type matches "current/active" table,
895 * add failure to "current/active" history */ 895 * add failure to "current/active" history */
896 } else if ((tbl_type.lq_type == curr_tbl->lq_type) && 896 } else if ((tbl_type.lq_type == curr_tbl->lq_type) &&
897 (tbl_type.antenna_type == curr_tbl->antenna_type) && 897 (tbl_type.ant_type == curr_tbl->ant_type) &&
898 (tbl_type.is_SGI == curr_tbl->is_SGI)) { 898 (tbl_type.is_SGI == curr_tbl->is_SGI)) {
899 if (curr_tbl->expected_tpt) 899 if (curr_tbl->expected_tpt)
900 tpt = curr_tbl->expected_tpt[rs_index]; 900 tpt = curr_tbl->expected_tpt[rs_index];
@@ -917,8 +917,8 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
917 * if Tx was successful first try, use original rate, 917 * if Tx was successful first try, use original rate,
918 * else look up the rate that was, finally, successful. 918 * else look up the rate that was, finally, successful.
919 */ 919 */
920 tx_mcs.rate_n_flags = le32_to_cpu(table->rs_table[index].rate_n_flags); 920 tx_rate = le32_to_cpu(table->rs_table[index].rate_n_flags);
921 rs_get_tbl_info_from_mcs(&tx_mcs, priv->band, &tbl_type, &rs_index); 921 rs_get_tbl_info_from_mcs(tx_rate, priv->band, &tbl_type, &rs_index);
922 922
923 /* Update frame history window with "success" if Tx got ACKed ... */ 923 /* Update frame history window with "success" if Tx got ACKed ... */
924 if (tx_resp->flags & IEEE80211_TX_STATUS_ACK) 924 if (tx_resp->flags & IEEE80211_TX_STATUS_ACK)
@@ -929,7 +929,7 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
929 /* If type matches "search" table, 929 /* If type matches "search" table,
930 * add final tx status to "search" history */ 930 * add final tx status to "search" history */
931 if ((tbl_type.lq_type == search_tbl->lq_type) && 931 if ((tbl_type.lq_type == search_tbl->lq_type) &&
932 (tbl_type.antenna_type == search_tbl->antenna_type) && 932 (tbl_type.ant_type == search_tbl->ant_type) &&
933 (tbl_type.is_SGI == search_tbl->is_SGI)) { 933 (tbl_type.is_SGI == search_tbl->is_SGI)) {
934 if (search_tbl->expected_tpt) 934 if (search_tbl->expected_tpt)
935 tpt = search_tbl->expected_tpt[rs_index]; 935 tpt = search_tbl->expected_tpt[rs_index];
@@ -945,7 +945,7 @@ static void rs_tx_status(void *priv_rate, struct net_device *dev,
945 /* Else if type matches "current/active" table, 945 /* Else if type matches "current/active" table,
946 * add final tx status to "current/active" history */ 946 * add final tx status to "current/active" history */
947 } else if ((tbl_type.lq_type == curr_tbl->lq_type) && 947 } else if ((tbl_type.lq_type == curr_tbl->lq_type) &&
948 (tbl_type.antenna_type == curr_tbl->antenna_type) && 948 (tbl_type.ant_type == curr_tbl->ant_type) &&
949 (tbl_type.is_SGI == curr_tbl->is_SGI)) { 949 (tbl_type.is_SGI == curr_tbl->is_SGI)) {
950 if (curr_tbl->expected_tpt) 950 if (curr_tbl->expected_tpt)
951 tpt = curr_tbl->expected_tpt[rs_index]; 951 tpt = curr_tbl->expected_tpt[rs_index];
@@ -982,30 +982,6 @@ out:
982 return; 982 return;
983} 983}
984 984
985static u8 rs_is_ant_connected(u8 valid_antenna,
986 enum iwl4965_antenna_type antenna_type)
987{
988 if (antenna_type == ANT_AUX)
989 return ((valid_antenna & 0x2) ? 1:0);
990 else if (antenna_type == ANT_MAIN)
991 return ((valid_antenna & 0x1) ? 1:0);
992 else if (antenna_type == ANT_BOTH)
993 return ((valid_antenna & 0x3) == 0x3);
994
995 return 1;
996}
997
998static u8 rs_is_other_ant_connected(u8 valid_antenna,
999 enum iwl4965_antenna_type antenna_type)
1000{
1001 if (antenna_type == ANT_AUX)
1002 return rs_is_ant_connected(valid_antenna, ANT_MAIN);
1003 else
1004 return rs_is_ant_connected(valid_antenna, ANT_AUX);
1005
1006 return 0;
1007}
1008
1009/* 985/*
1010 * Begin a period of staying with a selected modulation mode. 986 * Begin a period of staying with a selected modulation mode.
1011 * Set "stay_in_tbl" flag to prevent any mode switches. 987 * Set "stay_in_tbl" flag to prevent any mode switches.
@@ -1017,7 +993,7 @@ static u8 rs_is_other_ant_connected(u8 valid_antenna,
1017static void rs_set_stay_in_table(u8 is_legacy, 993static void rs_set_stay_in_table(u8 is_legacy,
1018 struct iwl4965_lq_sta *lq_sta) 994 struct iwl4965_lq_sta *lq_sta)
1019{ 995{
1020 IWL_DEBUG_HT("we are staying in the same table\n"); 996 IWL_DEBUG_RATE("we are staying in the same table\n");
1021 lq_sta->stay_in_tbl = 1; /* only place this gets set */ 997 lq_sta->stay_in_tbl = 1; /* only place this gets set */
1022 if (is_legacy) { 998 if (is_legacy) {
1023 lq_sta->table_count_limit = IWL_LEGACY_TABLE_COUNT; 999 lq_sta->table_count_limit = IWL_LEGACY_TABLE_COUNT;
@@ -1036,7 +1012,7 @@ static void rs_set_stay_in_table(u8 is_legacy,
1036/* 1012/*
1037 * Find correct throughput table for given mode of modulation 1013 * Find correct throughput table for given mode of modulation
1038 */ 1014 */
1039static void rs_get_expected_tpt_table(struct iwl4965_lq_sta *lq_sta, 1015static void rs_set_expected_tpt_table(struct iwl4965_lq_sta *lq_sta,
1040 struct iwl4965_scale_tbl_info *tbl) 1016 struct iwl4965_scale_tbl_info *tbl)
1041{ 1017{
1042 if (is_legacy(tbl->lq_type)) { 1018 if (is_legacy(tbl->lq_type)) {
@@ -1055,7 +1031,7 @@ static void rs_get_expected_tpt_table(struct iwl4965_lq_sta *lq_sta,
1055 else 1031 else
1056 tbl->expected_tpt = expected_tpt_siso20MHz; 1032 tbl->expected_tpt = expected_tpt_siso20MHz;
1057 1033
1058 } else if (is_mimo(tbl->lq_type)) { 1034 } else if (is_mimo(tbl->lq_type)) { /* FIXME:need to separate mimo2/3 */
1059 if (tbl->is_fat && !lq_sta->is_dup) 1035 if (tbl->is_fat && !lq_sta->is_dup)
1060 if (tbl->is_SGI) 1036 if (tbl->is_SGI)
1061 tbl->expected_tpt = expected_tpt_mimo40MHzSGI; 1037 tbl->expected_tpt = expected_tpt_mimo40MHzSGI;
@@ -1085,7 +1061,7 @@ static void rs_get_expected_tpt_table(struct iwl4965_lq_sta *lq_sta,
1085static s32 rs_get_best_rate(struct iwl_priv *priv, 1061static s32 rs_get_best_rate(struct iwl_priv *priv,
1086 struct iwl4965_lq_sta *lq_sta, 1062 struct iwl4965_lq_sta *lq_sta,
1087 struct iwl4965_scale_tbl_info *tbl, /* "search" */ 1063 struct iwl4965_scale_tbl_info *tbl, /* "search" */
1088 u16 rate_mask, s8 index, s8 rate) 1064 u16 rate_mask, s8 index)
1089{ 1065{
1090 /* "active" values */ 1066 /* "active" values */
1091 struct iwl4965_scale_tbl_info *active_tbl = 1067 struct iwl4965_scale_tbl_info *active_tbl =
@@ -1098,6 +1074,7 @@ static s32 rs_get_best_rate(struct iwl_priv *priv,
1098 1074
1099 s32 new_rate, high, low, start_hi; 1075 s32 new_rate, high, low, start_hi;
1100 u16 high_low; 1076 u16 high_low;
1077 s8 rate = index;
1101 1078
1102 new_rate = high = low = start_hi = IWL_RATE_INVALID; 1079 new_rate = high = low = start_hi = IWL_RATE_INVALID;
1103 1080
@@ -1172,21 +1149,16 @@ static s32 rs_get_best_rate(struct iwl_priv *priv,
1172} 1149}
1173#endif /* CONFIG_IWL4965_HT */ 1150#endif /* CONFIG_IWL4965_HT */
1174 1151
1175static inline u8 rs_is_both_ant_supp(u8 valid_antenna)
1176{
1177 return (rs_is_ant_connected(valid_antenna, ANT_BOTH));
1178}
1179
1180/* 1152/*
1181 * Set up search table for MIMO 1153 * Set up search table for MIMO
1182 */ 1154 */
1183static int rs_switch_to_mimo(struct iwl_priv *priv, 1155#ifdef CONFIG_IWL4965_HT
1156static int rs_switch_to_mimo2(struct iwl_priv *priv,
1184 struct iwl4965_lq_sta *lq_sta, 1157 struct iwl4965_lq_sta *lq_sta,
1185 struct ieee80211_conf *conf, 1158 struct ieee80211_conf *conf,
1186 struct sta_info *sta, 1159 struct sta_info *sta,
1187 struct iwl4965_scale_tbl_info *tbl, int index) 1160 struct iwl4965_scale_tbl_info *tbl, int index)
1188{ 1161{
1189#ifdef CONFIG_IWL4965_HT
1190 u16 rate_mask; 1162 u16 rate_mask;
1191 s32 rate; 1163 s32 rate;
1192 s8 is_green = lq_sta->is_green; 1164 s8 is_green = lq_sta->is_green;
@@ -1195,26 +1167,27 @@ static int rs_switch_to_mimo(struct iwl_priv *priv,
1195 !sta->ht_info.ht_supported) 1167 !sta->ht_info.ht_supported)
1196 return -1; 1168 return -1;
1197 1169
1198 IWL_DEBUG_HT("LQ: try to switch to MIMO\n");
1199 tbl->lq_type = LQ_MIMO;
1200 rs_get_supported_rates(lq_sta, NULL, tbl->lq_type,
1201 &rate_mask);
1202
1203 if (priv->current_ht_config.tx_mimo_ps_mode == IWL_MIMO_PS_STATIC) 1170 if (priv->current_ht_config.tx_mimo_ps_mode == IWL_MIMO_PS_STATIC)
1204 return -1; 1171 return -1;
1205 1172
1206 /* Need both Tx chains/antennas to support MIMO */ 1173 /* Need both Tx chains/antennas to support MIMO */
1207 if (!rs_is_both_ant_supp(lq_sta->antenna)) 1174 if (priv->hw_params.tx_chains_num < 2)
1208 return -1; 1175 return -1;
1209 1176
1177 IWL_DEBUG_RATE("LQ: try to switch to MIMO2\n");
1178
1179 tbl->lq_type = LQ_MIMO2;
1210 tbl->is_dup = lq_sta->is_dup; 1180 tbl->is_dup = lq_sta->is_dup;
1211 tbl->action = 0; 1181 tbl->action = 0;
1182 rate_mask = lq_sta->active_mimo2_rate;
1183
1212 if (priv->current_ht_config.supported_chan_width 1184 if (priv->current_ht_config.supported_chan_width
1213 == IWL_CHANNEL_WIDTH_40MHZ) 1185 == IWL_CHANNEL_WIDTH_40MHZ)
1214 tbl->is_fat = 1; 1186 tbl->is_fat = 1;
1215 else 1187 else
1216 tbl->is_fat = 0; 1188 tbl->is_fat = 0;
1217 1189
1190 /* FIXME: - don't toggle SGI here
1218 if (tbl->is_fat) { 1191 if (tbl->is_fat) {
1219 if (priv->current_ht_config.sgf & HT_SHORT_GI_40MHZ_ONLY) 1192 if (priv->current_ht_config.sgf & HT_SHORT_GI_40MHZ_ONLY)
1220 tbl->is_SGI = 1; 1193 tbl->is_SGI = 1;
@@ -1224,23 +1197,35 @@ static int rs_switch_to_mimo(struct iwl_priv *priv,
1224 tbl->is_SGI = 1; 1197 tbl->is_SGI = 1;
1225 else 1198 else
1226 tbl->is_SGI = 0; 1199 tbl->is_SGI = 0;
1200 */
1201
1202 rs_set_expected_tpt_table(lq_sta, tbl);
1227 1203
1228 rs_get_expected_tpt_table(lq_sta, tbl); 1204 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index);
1229 1205
1230 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index, index); 1206 IWL_DEBUG_RATE("LQ: MIMO2 best rate %d mask %X\n", rate, rate_mask);
1231 1207
1232 IWL_DEBUG_HT("LQ: MIMO best rate %d mask %X\n", rate, rate_mask); 1208 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
1233 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) 1209 IWL_DEBUG_RATE("Can't switch with index %d rate mask %x\n",
1210 rate, rate_mask);
1234 return -1; 1211 return -1;
1235 rs_mcs_from_tbl(&tbl->current_rate, tbl, rate, is_green); 1212 }
1213 tbl->current_rate = rate_n_flags_from_tbl(tbl, rate, is_green);
1236 1214
1237 IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n", 1215 IWL_DEBUG_RATE("LQ: Switch to new mcs %X index is green %X\n",
1238 tbl->current_rate.rate_n_flags, is_green); 1216 tbl->current_rate, is_green);
1239 return 0; 1217 return 0;
1218}
1240#else 1219#else
1220static int rs_switch_to_mimo2(struct iwl_priv *priv,
1221 struct iwl4965_lq_sta *lq_sta,
1222 struct ieee80211_conf *conf,
1223 struct sta_info *sta,
1224 struct iwl4965_scale_tbl_info *tbl, int index)
1225{
1241 return -1; 1226 return -1;
1242#endif /*CONFIG_IWL4965_HT */
1243} 1227}
1228#endif /*CONFIG_IWL4965_HT */
1244 1229
1245/* 1230/*
1246 * Set up search table for SISO 1231 * Set up search table for SISO
@@ -1256,16 +1241,16 @@ static int rs_switch_to_siso(struct iwl_priv *priv,
1256 u8 is_green = lq_sta->is_green; 1241 u8 is_green = lq_sta->is_green;
1257 s32 rate; 1242 s32 rate;
1258 1243
1259 IWL_DEBUG_HT("LQ: try to switch to SISO\n");
1260 if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) || 1244 if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) ||
1261 !sta->ht_info.ht_supported) 1245 !sta->ht_info.ht_supported)
1262 return -1; 1246 return -1;
1263 1247
1248 IWL_DEBUG_RATE("LQ: try to switch to SISO\n");
1249
1264 tbl->is_dup = lq_sta->is_dup; 1250 tbl->is_dup = lq_sta->is_dup;
1265 tbl->lq_type = LQ_SISO; 1251 tbl->lq_type = LQ_SISO;
1266 tbl->action = 0; 1252 tbl->action = 0;
1267 rs_get_supported_rates(lq_sta, NULL, tbl->lq_type, 1253 rate_mask = lq_sta->active_siso_rate;
1268 &rate_mask);
1269 1254
1270 if (priv->current_ht_config.supported_chan_width 1255 if (priv->current_ht_config.supported_chan_width
1271 == IWL_CHANNEL_WIDTH_40MHZ) 1256 == IWL_CHANNEL_WIDTH_40MHZ)
@@ -1273,6 +1258,7 @@ static int rs_switch_to_siso(struct iwl_priv *priv,
1273 else 1258 else
1274 tbl->is_fat = 0; 1259 tbl->is_fat = 0;
1275 1260
1261 /* FIXME: - don't toggle SGI here
1276 if (tbl->is_fat) { 1262 if (tbl->is_fat) {
1277 if (priv->current_ht_config.sgf & HT_SHORT_GI_40MHZ_ONLY) 1263 if (priv->current_ht_config.sgf & HT_SHORT_GI_40MHZ_ONLY)
1278 tbl->is_SGI = 1; 1264 tbl->is_SGI = 1;
@@ -1282,26 +1268,26 @@ static int rs_switch_to_siso(struct iwl_priv *priv,
1282 tbl->is_SGI = 1; 1268 tbl->is_SGI = 1;
1283 else 1269 else
1284 tbl->is_SGI = 0; 1270 tbl->is_SGI = 0;
1271 */
1285 1272
1286 if (is_green) 1273 if (is_green)
1287 tbl->is_SGI = 0; 1274 tbl->is_SGI = 0; /*11n spec: no SGI in SISO+Greenfield*/
1288 1275
1289 rs_get_expected_tpt_table(lq_sta, tbl); 1276 rs_set_expected_tpt_table(lq_sta, tbl);
1290 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index, index); 1277 rate = rs_get_best_rate(priv, lq_sta, tbl, rate_mask, index);
1291 1278
1292 IWL_DEBUG_HT("LQ: get best rate %d mask %X\n", rate, rate_mask); 1279 IWL_DEBUG_RATE("LQ: get best rate %d mask %X\n", rate, rate_mask);
1293 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) { 1280 if ((rate == IWL_RATE_INVALID) || !((1 << rate) & rate_mask)) {
1294 IWL_DEBUG_HT("can not switch with index %d rate mask %x\n", 1281 IWL_DEBUG_RATE("can not switch with index %d rate mask %x\n",
1295 rate, rate_mask); 1282 rate, rate_mask);
1296 return -1; 1283 return -1;
1297 } 1284 }
1298 rs_mcs_from_tbl(&tbl->current_rate, tbl, rate, is_green); 1285 tbl->current_rate = rate_n_flags_from_tbl(tbl, rate, is_green);
1299 IWL_DEBUG_HT("LQ: Switch to new mcs %X index is green %X\n", 1286 IWL_DEBUG_RATE("LQ: Switch to new mcs %X index is green %X\n",
1300 tbl->current_rate.rate_n_flags, is_green); 1287 tbl->current_rate, is_green);
1301 return 0; 1288 return 0;
1302#else 1289#else
1303 return -1; 1290 return -1;
1304
1305#endif /*CONFIG_IWL4965_HT */ 1291#endif /*CONFIG_IWL4965_HT */
1306} 1292}
1307 1293
@@ -1314,7 +1300,6 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1314 struct sta_info *sta, 1300 struct sta_info *sta,
1315 int index) 1301 int index)
1316{ 1302{
1317 int ret = 0;
1318 struct iwl4965_scale_tbl_info *tbl = 1303 struct iwl4965_scale_tbl_info *tbl =
1319 &(lq_sta->lq_info[lq_sta->active_tbl]); 1304 &(lq_sta->lq_info[lq_sta->active_tbl]);
1320 struct iwl4965_scale_tbl_info *search_tbl = 1305 struct iwl4965_scale_tbl_info *search_tbl =
@@ -1323,41 +1308,35 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1323 u32 sz = (sizeof(struct iwl4965_scale_tbl_info) - 1308 u32 sz = (sizeof(struct iwl4965_scale_tbl_info) -
1324 (sizeof(struct iwl4965_rate_scale_data) * IWL_RATE_COUNT)); 1309 (sizeof(struct iwl4965_rate_scale_data) * IWL_RATE_COUNT));
1325 u8 start_action = tbl->action; 1310 u8 start_action = tbl->action;
1311 u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
1312 int ret = 0;
1326 1313
1327 for (; ;) { 1314 for (; ;) {
1328 switch (tbl->action) { 1315 switch (tbl->action) {
1329 case IWL_LEGACY_SWITCH_ANTENNA: 1316 case IWL_LEGACY_SWITCH_ANTENNA:
1330 IWL_DEBUG_HT("LQ Legacy switch Antenna\n"); 1317 IWL_DEBUG_RATE("LQ: Legacy toggle Antenna\n");
1331 1318
1332 search_tbl->lq_type = LQ_NONE;
1333 lq_sta->action_counter++; 1319 lq_sta->action_counter++;
1334 1320
1335 /* Don't change antenna if success has been great */ 1321 /* Don't change antenna if success has been great */
1336 if (window->success_ratio >= IWL_RS_GOOD_RATIO) 1322 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
1337 break; 1323 break;
1338 1324
1339 /* Don't change antenna if other one is not connected */
1340 if (!rs_is_other_ant_connected(lq_sta->antenna,
1341 tbl->antenna_type))
1342 break;
1343
1344 /* Set up search table to try other antenna */ 1325 /* Set up search table to try other antenna */
1345 memcpy(search_tbl, tbl, sz); 1326 memcpy(search_tbl, tbl, sz);
1346 1327
1347 rs_toggle_antenna(&(search_tbl->current_rate), 1328 if (rs_toggle_antenna(valid_tx_ant,
1348 search_tbl); 1329 &search_tbl->current_rate, search_tbl)) {
1349 rs_get_expected_tpt_table(lq_sta, search_tbl); 1330 lq_sta->search_better_tbl = 1;
1350 lq_sta->search_better_tbl = 1; 1331 goto out;
1351 goto out; 1332 }
1352 1333
1353 case IWL_LEGACY_SWITCH_SISO: 1334 case IWL_LEGACY_SWITCH_SISO:
1354 IWL_DEBUG_HT("LQ: Legacy switch to SISO\n"); 1335 IWL_DEBUG_RATE("LQ: Legacy switch to SISO\n");
1355 1336
1356 /* Set up search table to try SISO */ 1337 /* Set up search table to try SISO */
1357 memcpy(search_tbl, tbl, sz); 1338 memcpy(search_tbl, tbl, sz);
1358 search_tbl->lq_type = LQ_SISO;
1359 search_tbl->is_SGI = 0; 1339 search_tbl->is_SGI = 0;
1360 search_tbl->is_fat = 0;
1361 ret = rs_switch_to_siso(priv, lq_sta, conf, sta, 1340 ret = rs_switch_to_siso(priv, lq_sta, conf, sta,
1362 search_tbl, index); 1341 search_tbl, index);
1363 if (!ret) { 1342 if (!ret) {
@@ -1367,16 +1346,15 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1367 } 1346 }
1368 1347
1369 break; 1348 break;
1370 case IWL_LEGACY_SWITCH_MIMO: 1349 case IWL_LEGACY_SWITCH_MIMO2:
1371 IWL_DEBUG_HT("LQ: Legacy switch MIMO\n"); 1350 IWL_DEBUG_RATE("LQ: Legacy switch to MIMO2\n");
1372 1351
1373 /* Set up search table to try MIMO */ 1352 /* Set up search table to try MIMO */
1374 memcpy(search_tbl, tbl, sz); 1353 memcpy(search_tbl, tbl, sz);
1375 search_tbl->lq_type = LQ_MIMO;
1376 search_tbl->is_SGI = 0; 1354 search_tbl->is_SGI = 0;
1377 search_tbl->is_fat = 0; 1355 search_tbl->ant_type = ANT_AB;/*FIXME:RS*/
1378 search_tbl->antenna_type = ANT_BOTH; 1356 /*FIXME:RS:need to check ant validity*/
1379 ret = rs_switch_to_mimo(priv, lq_sta, conf, sta, 1357 ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta,
1380 search_tbl, index); 1358 search_tbl, index);
1381 if (!ret) { 1359 if (!ret) {
1382 lq_sta->search_better_tbl = 1; 1360 lq_sta->search_better_tbl = 1;
@@ -1386,7 +1364,7 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1386 break; 1364 break;
1387 } 1365 }
1388 tbl->action++; 1366 tbl->action++;
1389 if (tbl->action > IWL_LEGACY_SWITCH_MIMO) 1367 if (tbl->action > IWL_LEGACY_SWITCH_MIMO2)
1390 tbl->action = IWL_LEGACY_SWITCH_ANTENNA; 1368 tbl->action = IWL_LEGACY_SWITCH_ANTENNA;
1391 1369
1392 if (tbl->action == start_action) 1370 if (tbl->action == start_action)
@@ -1397,7 +1375,7 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1397 1375
1398 out: 1376 out:
1399 tbl->action++; 1377 tbl->action++;
1400 if (tbl->action > IWL_LEGACY_SWITCH_MIMO) 1378 if (tbl->action > IWL_LEGACY_SWITCH_MIMO2)
1401 tbl->action = IWL_LEGACY_SWITCH_ANTENNA; 1379 tbl->action = IWL_LEGACY_SWITCH_ANTENNA;
1402 return 0; 1380 return 0;
1403 1381
@@ -1412,7 +1390,6 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
1412 struct sta_info *sta, 1390 struct sta_info *sta,
1413 int index) 1391 int index)
1414{ 1392{
1415 int ret;
1416 u8 is_green = lq_sta->is_green; 1393 u8 is_green = lq_sta->is_green;
1417 struct iwl4965_scale_tbl_info *tbl = 1394 struct iwl4965_scale_tbl_info *tbl =
1418 &(lq_sta->lq_info[lq_sta->active_tbl]); 1395 &(lq_sta->lq_info[lq_sta->active_tbl]);
@@ -1422,35 +1399,30 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
1422 u32 sz = (sizeof(struct iwl4965_scale_tbl_info) - 1399 u32 sz = (sizeof(struct iwl4965_scale_tbl_info) -
1423 (sizeof(struct iwl4965_rate_scale_data) * IWL_RATE_COUNT)); 1400 (sizeof(struct iwl4965_rate_scale_data) * IWL_RATE_COUNT));
1424 u8 start_action = tbl->action; 1401 u8 start_action = tbl->action;
1402 u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
1403 int ret;
1425 1404
1426 for (;;) { 1405 for (;;) {
1427 lq_sta->action_counter++; 1406 lq_sta->action_counter++;
1428 switch (tbl->action) { 1407 switch (tbl->action) {
1429 case IWL_SISO_SWITCH_ANTENNA: 1408 case IWL_SISO_SWITCH_ANTENNA:
1430 IWL_DEBUG_HT("LQ: SISO SWITCH ANTENNA SISO\n"); 1409 IWL_DEBUG_RATE("LQ: SISO toggle Antenna\n");
1431 search_tbl->lq_type = LQ_NONE;
1432 if (window->success_ratio >= IWL_RS_GOOD_RATIO) 1410 if (window->success_ratio >= IWL_RS_GOOD_RATIO)
1433 break; 1411 break;
1434 if (!rs_is_other_ant_connected(lq_sta->antenna,
1435 tbl->antenna_type))
1436 break;
1437 1412
1438 memcpy(search_tbl, tbl, sz); 1413 memcpy(search_tbl, tbl, sz);
1439 search_tbl->action = IWL_SISO_SWITCH_MIMO; 1414 if (rs_toggle_antenna(valid_tx_ant,
1440 rs_toggle_antenna(&(search_tbl->current_rate), 1415 &search_tbl->current_rate, search_tbl)) {
1441 search_tbl); 1416 lq_sta->search_better_tbl = 1;
1442 lq_sta->search_better_tbl = 1; 1417 goto out;
1443 1418 }
1444 goto out;
1445 1419
1446 case IWL_SISO_SWITCH_MIMO: 1420 case IWL_SISO_SWITCH_MIMO2:
1447 IWL_DEBUG_HT("LQ: SISO SWITCH TO MIMO FROM SISO\n"); 1421 IWL_DEBUG_RATE("LQ: SISO switch to MIMO\n");
1448 memcpy(search_tbl, tbl, sz); 1422 memcpy(search_tbl, tbl, sz);
1449 search_tbl->lq_type = LQ_MIMO;
1450 search_tbl->is_SGI = 0; 1423 search_tbl->is_SGI = 0;
1451 search_tbl->is_fat = 0; 1424 search_tbl->ant_type = ANT_AB; /*FIXME:RS*/
1452 search_tbl->antenna_type = ANT_BOTH; 1425 ret = rs_switch_to_mimo2(priv, lq_sta, conf, sta,
1453 ret = rs_switch_to_mimo(priv, lq_sta, conf, sta,
1454 search_tbl, index); 1426 search_tbl, index);
1455 if (!ret) { 1427 if (!ret) {
1456 lq_sta->search_better_tbl = 1; 1428 lq_sta->search_better_tbl = 1;
@@ -1458,29 +1430,25 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
1458 } 1430 }
1459 break; 1431 break;
1460 case IWL_SISO_SWITCH_GI: 1432 case IWL_SISO_SWITCH_GI:
1461 IWL_DEBUG_HT("LQ: SISO SWITCH TO GI\n"); 1433 IWL_DEBUG_RATE("LQ: SISO toggle SGI/NGI\n");
1462 1434
1463 memcpy(search_tbl, tbl, sz); 1435 memcpy(search_tbl, tbl, sz);
1464 search_tbl->action = 0; 1436 if (is_green) {
1465 if (search_tbl->is_SGI) 1437 if (!tbl->is_SGI)
1466 search_tbl->is_SGI = 0; 1438 break;
1467 else if (!is_green) 1439 else
1468 search_tbl->is_SGI = 1; 1440 IWL_ERROR("SGI was set in GF+SISO\n");
1469 else 1441 }
1470 break; 1442 search_tbl->is_SGI = !tbl->is_SGI;
1471 lq_sta->search_better_tbl = 1; 1443 rs_set_expected_tpt_table(lq_sta, search_tbl);
1472 if ((tbl->lq_type == LQ_SISO) && 1444 if (tbl->is_SGI) {
1473 (tbl->is_SGI)) {
1474 s32 tpt = lq_sta->last_tpt / 100; 1445 s32 tpt = lq_sta->last_tpt / 100;
1475 if (((!tbl->is_fat) && 1446 if (tpt >= search_tbl->expected_tpt[index])
1476 (tpt >= expected_tpt_siso20MHz[index])) || 1447 break;
1477 ((tbl->is_fat) &&
1478 (tpt >= expected_tpt_siso40MHz[index])))
1479 lq_sta->search_better_tbl = 0;
1480 } 1448 }
1481 rs_get_expected_tpt_table(lq_sta, search_tbl); 1449 search_tbl->current_rate = rate_n_flags_from_tbl(
1482 rs_mcs_from_tbl(&search_tbl->current_rate, 1450 search_tbl, index, is_green);
1483 search_tbl, index, is_green); 1451 lq_sta->search_better_tbl = 1;
1484 goto out; 1452 goto out;
1485 } 1453 }
1486 tbl->action++; 1454 tbl->action++;
@@ -1508,7 +1476,6 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
1508 struct sta_info *sta, 1476 struct sta_info *sta,
1509 int index) 1477 int index)
1510{ 1478{
1511 int ret;
1512 s8 is_green = lq_sta->is_green; 1479 s8 is_green = lq_sta->is_green;
1513 struct iwl4965_scale_tbl_info *tbl = 1480 struct iwl4965_scale_tbl_info *tbl =
1514 &(lq_sta->lq_info[lq_sta->active_tbl]); 1481 &(lq_sta->lq_info[lq_sta->active_tbl]);
@@ -1517,24 +1484,24 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
1517 u32 sz = (sizeof(struct iwl4965_scale_tbl_info) - 1484 u32 sz = (sizeof(struct iwl4965_scale_tbl_info) -
1518 (sizeof(struct iwl4965_rate_scale_data) * IWL_RATE_COUNT)); 1485 (sizeof(struct iwl4965_rate_scale_data) * IWL_RATE_COUNT));
1519 u8 start_action = tbl->action; 1486 u8 start_action = tbl->action;
1487 /*u8 valid_tx_ant = priv->hw_params.valid_tx_ant;*/
1488 int ret;
1520 1489
1521 for (;;) { 1490 for (;;) {
1522 lq_sta->action_counter++; 1491 lq_sta->action_counter++;
1523 switch (tbl->action) { 1492 switch (tbl->action) {
1524 case IWL_MIMO_SWITCH_ANTENNA_A: 1493 case IWL_MIMO_SWITCH_ANTENNA_A:
1525 case IWL_MIMO_SWITCH_ANTENNA_B: 1494 case IWL_MIMO_SWITCH_ANTENNA_B:
1526 IWL_DEBUG_HT("LQ: MIMO SWITCH TO SISO\n"); 1495 IWL_DEBUG_RATE("LQ: MIMO2 switch to SISO\n");
1527
1528 1496
1529 /* Set up new search table for SISO */ 1497 /* Set up new search table for SISO */
1530 memcpy(search_tbl, tbl, sz); 1498 memcpy(search_tbl, tbl, sz);
1531 search_tbl->lq_type = LQ_SISO; 1499
1532 search_tbl->is_SGI = 0; 1500 /*FIXME:RS:need to check ant validity + C*/
1533 search_tbl->is_fat = 0;
1534 if (tbl->action == IWL_MIMO_SWITCH_ANTENNA_A) 1501 if (tbl->action == IWL_MIMO_SWITCH_ANTENNA_A)
1535 search_tbl->antenna_type = ANT_MAIN; 1502 search_tbl->ant_type = ANT_A;
1536 else 1503 else
1537 search_tbl->antenna_type = ANT_AUX; 1504 search_tbl->ant_type = ANT_B;
1538 1505
1539 ret = rs_switch_to_siso(priv, lq_sta, conf, sta, 1506 ret = rs_switch_to_siso(priv, lq_sta, conf, sta,
1540 search_tbl, index); 1507 search_tbl, index);
@@ -1545,37 +1512,26 @@ static int rs_move_mimo_to_other(struct iwl_priv *priv,
1545 break; 1512 break;
1546 1513
1547 case IWL_MIMO_SWITCH_GI: 1514 case IWL_MIMO_SWITCH_GI:
1548 IWL_DEBUG_HT("LQ: MIMO SWITCH TO GI\n"); 1515 IWL_DEBUG_RATE("LQ: MIMO toggle SGI/NGI\n");
1549 1516
1550 /* Set up new search table for MIMO */ 1517 /* Set up new search table for MIMO */
1551 memcpy(search_tbl, tbl, sz); 1518 memcpy(search_tbl, tbl, sz);
1552 search_tbl->lq_type = LQ_MIMO; 1519 search_tbl->is_SGI = !tbl->is_SGI;
1553 search_tbl->antenna_type = ANT_BOTH; 1520 rs_set_expected_tpt_table(lq_sta, search_tbl);
1554 search_tbl->action = 0;
1555 if (search_tbl->is_SGI)
1556 search_tbl->is_SGI = 0;
1557 else
1558 search_tbl->is_SGI = 1;
1559 lq_sta->search_better_tbl = 1;
1560
1561 /* 1521 /*
1562 * If active table already uses the fastest possible 1522 * If active table already uses the fastest possible
1563 * modulation (dual stream with short guard interval), 1523 * modulation (dual stream with short guard interval),
1564 * and it's working well, there's no need to look 1524 * and it's working well, there's no need to look
1565 * for a better type of modulation! 1525 * for a better type of modulation!
1566 */ 1526 */
1567 if ((tbl->lq_type == LQ_MIMO) && 1527 if (tbl->is_SGI) {
1568 (tbl->is_SGI)) {
1569 s32 tpt = lq_sta->last_tpt / 100; 1528 s32 tpt = lq_sta->last_tpt / 100;
1570 if (((!tbl->is_fat) && 1529 if (tpt >= search_tbl->expected_tpt[index])
1571 (tpt >= expected_tpt_mimo20MHz[index])) || 1530 break;
1572 ((tbl->is_fat) &&
1573 (tpt >= expected_tpt_mimo40MHz[index])))
1574 lq_sta->search_better_tbl = 0;
1575 } 1531 }
1576 rs_get_expected_tpt_table(lq_sta, search_tbl); 1532 search_tbl->current_rate = rate_n_flags_from_tbl(
1577 rs_mcs_from_tbl(&search_tbl->current_rate, 1533 search_tbl, index, is_green);
1578 search_tbl, index, is_green); 1534 lq_sta->search_better_tbl = 1;
1579 goto out; 1535 goto out;
1580 1536
1581 } 1537 }
@@ -1624,9 +1580,6 @@ static void rs_stay_in_table(struct iwl4965_lq_sta *lq_sta)
1624 (unsigned long)(lq_sta->flush_timer + 1580 (unsigned long)(lq_sta->flush_timer +
1625 IWL_RATE_SCALE_FLUSH_INTVL)); 1581 IWL_RATE_SCALE_FLUSH_INTVL));
1626 1582
1627 /* For now, disable the elapsed time criterion */
1628 flush_interval_passed = 0;
1629
1630 /* 1583 /*
1631 * Check if we should allow search for new modulation mode. 1584 * Check if we should allow search for new modulation mode.
1632 * If many frames have failed or succeeded, or we've used 1585 * If many frames have failed or succeeded, or we've used
@@ -1639,7 +1592,7 @@ static void rs_stay_in_table(struct iwl4965_lq_sta *lq_sta)
1639 (lq_sta->total_success > lq_sta->max_success_limit) || 1592 (lq_sta->total_success > lq_sta->max_success_limit) ||
1640 ((!lq_sta->search_better_tbl) && (lq_sta->flush_timer) 1593 ((!lq_sta->search_better_tbl) && (lq_sta->flush_timer)
1641 && (flush_interval_passed))) { 1594 && (flush_interval_passed))) {
1642 IWL_DEBUG_HT("LQ: stay is expired %d %d %d\n:", 1595 IWL_DEBUG_RATE("LQ: stay is expired %d %d %d\n:",
1643 lq_sta->total_failed, 1596 lq_sta->total_failed,
1644 lq_sta->total_success, 1597 lq_sta->total_success,
1645 flush_interval_passed); 1598 flush_interval_passed);
@@ -1662,7 +1615,7 @@ static void rs_stay_in_table(struct iwl4965_lq_sta *lq_sta)
1662 lq_sta->table_count_limit) { 1615 lq_sta->table_count_limit) {
1663 lq_sta->table_count = 0; 1616 lq_sta->table_count = 0;
1664 1617
1665 IWL_DEBUG_HT("LQ: stay in table clear win\n"); 1618 IWL_DEBUG_RATE("LQ: stay in table clear win\n");
1666 for (i = 0; i < IWL_RATE_COUNT; i++) 1619 for (i = 0; i < IWL_RATE_COUNT; i++)
1667 rs_rate_scale_clear_window( 1620 rs_rate_scale_clear_window(
1668 &(tbl->win[i])); 1621 &(tbl->win[i]));
@@ -1705,7 +1658,7 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1705 struct iwl4965_lq_sta *lq_sta; 1658 struct iwl4965_lq_sta *lq_sta;
1706 struct iwl4965_scale_tbl_info *tbl, *tbl1; 1659 struct iwl4965_scale_tbl_info *tbl, *tbl1;
1707 u16 rate_scale_index_msk = 0; 1660 u16 rate_scale_index_msk = 0;
1708 struct iwl4965_rate mcs_rate; 1661 u32 rate;
1709 u8 is_green = 0; 1662 u8 is_green = 0;
1710 u8 active_tbl = 0; 1663 u8 active_tbl = 0;
1711 u8 done_search = 0; 1664 u8 done_search = 0;
@@ -1761,8 +1714,7 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1761 tbl->lq_type); 1714 tbl->lq_type);
1762 1715
1763 /* rates available for this association, and for modulation mode */ 1716 /* rates available for this association, and for modulation mode */
1764 rs_get_supported_rates(lq_sta, hdr, tbl->lq_type, 1717 rate_mask = rs_get_supported_rates(lq_sta, hdr, tbl->lq_type);
1765 &rate_mask);
1766 1718
1767 IWL_DEBUG_RATE("mask 0x%04X \n", rate_mask); 1719 IWL_DEBUG_RATE("mask 0x%04X \n", rate_mask);
1768 1720
@@ -1782,27 +1734,16 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1782 if (!rate_scale_index_msk) 1734 if (!rate_scale_index_msk)
1783 rate_scale_index_msk = rate_mask; 1735 rate_scale_index_msk = rate_mask;
1784 1736
1785 /* If current rate is no longer supported on current association, 1737 if (!((1 << index) & rate_scale_index_msk)) {
1786 * or user changed preferences for rates, find a new supported rate. */ 1738 IWL_ERROR("Current Rate is not valid\n");
1787 if (index < 0 || !((1 << index) & rate_scale_index_msk)) { 1739 return;
1788 index = IWL_INVALID_VALUE;
1789 update_lq = 1;
1790
1791 /* get the highest available rate */
1792 for (i = 0; i <= IWL_RATE_COUNT; i++) {
1793 if ((1 << i) & rate_scale_index_msk)
1794 index = i;
1795 }
1796
1797 if (index == IWL_INVALID_VALUE) {
1798 IWL_WARNING("Can not find a suitable rate\n");
1799 return;
1800 }
1801 } 1740 }
1802 1741
1803 /* Get expected throughput table and history window for current rate */ 1742 /* Get expected throughput table and history window for current rate */
1804 if (!tbl->expected_tpt) 1743 if (!tbl->expected_tpt) {
1805 rs_get_expected_tpt_table(lq_sta, tbl); 1744 IWL_ERROR("tbl->expected_tpt is NULL\n");
1745 return;
1746 }
1806 1747
1807 window = &(tbl->win[index]); 1748 window = &(tbl->win[index]);
1808 1749
@@ -1814,10 +1755,9 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1814 * in current association (use new rate found above). 1755 * in current association (use new rate found above).
1815 */ 1756 */
1816 fail_count = window->counter - window->success_counter; 1757 fail_count = window->counter - window->success_counter;
1817 if (((fail_count < IWL_RATE_MIN_FAILURE_TH) && 1758 if ((fail_count < IWL_RATE_MIN_FAILURE_TH) &&
1818 (window->success_counter < IWL_RATE_MIN_SUCCESS_TH)) 1759 (window->success_counter < IWL_RATE_MIN_SUCCESS_TH)) {
1819 || (tbl->expected_tpt == NULL)) { 1760 IWL_DEBUG_RATE("LQ: still below TH. succ=%d total=%d "
1820 IWL_DEBUG_RATE("LQ: still below TH succ %d total %d "
1821 "for index %d\n", 1761 "for index %d\n",
1822 window->success_counter, window->counter, index); 1762 window->success_counter, window->counter, index);
1823 1763
@@ -1828,44 +1768,51 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1828 * or search for a new one? */ 1768 * or search for a new one? */
1829 rs_stay_in_table(lq_sta); 1769 rs_stay_in_table(lq_sta);
1830 1770
1831 /* Set up new rate table in uCode, if needed */
1832 if (update_lq) {
1833 rs_mcs_from_tbl(&mcs_rate, tbl, index, is_green);
1834 rs_fill_link_cmd(lq_sta, &mcs_rate, &lq_sta->lq);
1835 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC);
1836 }
1837 goto out; 1771 goto out;
1838 1772
1839 /* Else we have enough samples; calculate estimate of 1773 /* Else we have enough samples; calculate estimate of
1840 * actual average throughput */ 1774 * actual average throughput */
1841 } else 1775 } else {
1842 window->average_tpt = ((window->success_ratio * 1776 /*FIXME:RS remove this else if we don't get this error*/
1777 if (window->average_tpt != ((window->success_ratio *
1778 tbl->expected_tpt[index] + 64) / 128)) {
1779 IWL_ERROR("expected_tpt should have been calculated"
1780 " by now\n");
1781 window->average_tpt = ((window->success_ratio *
1843 tbl->expected_tpt[index] + 64) / 128); 1782 tbl->expected_tpt[index] + 64) / 128);
1783 }
1784 }
1844 1785
1845 /* If we are searching for better modulation mode, check success. */ 1786 /* If we are searching for better modulation mode, check success. */
1846 if (lq_sta->search_better_tbl) { 1787 if (lq_sta->search_better_tbl) {
1847 int success_limit = IWL_RATE_SCALE_SWITCH;
1848 1788
1849 /* If good success, continue using the "search" mode; 1789 /* If good success, continue using the "search" mode;
1850 * no need to send new link quality command, since we're 1790 * no need to send new link quality command, since we're
1851 * continuing to use the setup that we've been trying. */ 1791 * continuing to use the setup that we've been trying. */
1852 if ((window->success_ratio > success_limit) || 1792 if (window->average_tpt > lq_sta->last_tpt) {
1853 (window->average_tpt > lq_sta->last_tpt)) { 1793
1854 if (!is_legacy(tbl->lq_type)) { 1794 IWL_DEBUG_RATE("LQ: SWITCHING TO CURRENT TABLE "
1855 IWL_DEBUG_HT("LQ: we are switching to HT" 1795 "suc=%d cur-tpt=%d old-tpt=%d\n",
1856 " rate suc %d current tpt %d" 1796 window->success_ratio,
1857 " old tpt %d\n", 1797 window->average_tpt,
1858 window->success_ratio, 1798 lq_sta->last_tpt);
1859 window->average_tpt, 1799
1860 lq_sta->last_tpt); 1800 if (!is_legacy(tbl->lq_type))
1861 lq_sta->enable_counter = 1; 1801 lq_sta->enable_counter = 1;
1862 } 1802
1863 /* Swap tables; "search" becomes "active" */ 1803 /* Swap tables; "search" becomes "active" */
1864 lq_sta->active_tbl = active_tbl; 1804 lq_sta->active_tbl = active_tbl;
1865 current_tpt = window->average_tpt; 1805 current_tpt = window->average_tpt;
1866 1806
1867 /* Else poor success; go back to mode in "active" table */ 1807 /* Else poor success; go back to mode in "active" table */
1868 } else { 1808 } else {
1809
1810 IWL_DEBUG_RATE("LQ: GOING BACK TO THE OLD TABLE "
1811 "suc=%d cur-tpt=%d old-tpt=%d\n",
1812 window->success_ratio,
1813 window->average_tpt,
1814 lq_sta->last_tpt);
1815
1869 /* Nullify "search" table */ 1816 /* Nullify "search" table */
1870 tbl->lq_type = LQ_NONE; 1817 tbl->lq_type = LQ_NONE;
1871 1818
@@ -1875,12 +1822,11 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1875 1822
1876 /* Revert to "active" rate and throughput info */ 1823 /* Revert to "active" rate and throughput info */
1877 index = iwl4965_hwrate_to_plcp_idx( 1824 index = iwl4965_hwrate_to_plcp_idx(
1878 tbl->current_rate.rate_n_flags); 1825 tbl->current_rate);
1879 current_tpt = lq_sta->last_tpt; 1826 current_tpt = lq_sta->last_tpt;
1880 1827
1881 /* Need to set up a new rate table in uCode */ 1828 /* Need to set up a new rate table in uCode */
1882 update_lq = 1; 1829 update_lq = 1;
1883 IWL_DEBUG_HT("XXY GO BACK TO OLD TABLE\n");
1884 } 1830 }
1885 1831
1886 /* Either way, we've made a decision; modulation mode 1832 /* Either way, we've made a decision; modulation mode
@@ -1988,15 +1934,15 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
1988 break; 1934 break;
1989 } 1935 }
1990 1936
1991 IWL_DEBUG_HT("choose rate scale index %d action %d low %d " 1937 IWL_DEBUG_RATE("choose rate scale index %d action %d low %d "
1992 "high %d type %d\n", 1938 "high %d type %d\n",
1993 index, scale_action, low, high, tbl->lq_type); 1939 index, scale_action, low, high, tbl->lq_type);
1994 1940
1995 lq_update: 1941 lq_update:
1996 /* Replace uCode's rate table for the destination station. */ 1942 /* Replace uCode's rate table for the destination station. */
1997 if (update_lq) { 1943 if (update_lq) {
1998 rs_mcs_from_tbl(&mcs_rate, tbl, index, is_green); 1944 rate = rate_n_flags_from_tbl(tbl, index, is_green);
1999 rs_fill_link_cmd(lq_sta, &mcs_rate, &lq_sta->lq); 1945 rs_fill_link_cmd(priv, lq_sta, rate);
2000 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC); 1946 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC);
2001 } 1947 }
2002 1948
@@ -2031,12 +1977,11 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
2031 1977
2032 /* Use new "search" start rate */ 1978 /* Use new "search" start rate */
2033 index = iwl4965_hwrate_to_plcp_idx( 1979 index = iwl4965_hwrate_to_plcp_idx(
2034 tbl->current_rate.rate_n_flags); 1980 tbl->current_rate);
2035 1981
2036 IWL_DEBUG_HT("Switch current mcs: %X index: %d\n", 1982 IWL_DEBUG_RATE("Switch current mcs: %X index: %d\n",
2037 tbl->current_rate.rate_n_flags, index); 1983 tbl->current_rate, index);
2038 rs_fill_link_cmd(lq_sta, &tbl->current_rate, 1984 rs_fill_link_cmd(priv, lq_sta, tbl->current_rate);
2039 &lq_sta->lq);
2040 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC); 1985 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC);
2041 } 1986 }
2042 1987
@@ -2052,7 +1997,7 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
2052#endif 1997#endif
2053 (lq_sta->action_counter >= 1)) { 1998 (lq_sta->action_counter >= 1)) {
2054 lq_sta->action_counter = 0; 1999 lq_sta->action_counter = 0;
2055 IWL_DEBUG_HT("LQ: STAY in legacy table\n"); 2000 IWL_DEBUG_RATE("LQ: STAY in legacy table\n");
2056 rs_set_stay_in_table(1, lq_sta); 2001 rs_set_stay_in_table(1, lq_sta);
2057 } 2002 }
2058 2003
@@ -2065,7 +2010,7 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
2065 if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) && 2010 if ((lq_sta->last_tpt > IWL_AGG_TPT_THREHOLD) &&
2066 (lq_sta->tx_agg_tid_en & (1 << tid)) && 2011 (lq_sta->tx_agg_tid_en & (1 << tid)) &&
2067 (tid != MAX_TID_COUNT)) { 2012 (tid != MAX_TID_COUNT)) {
2068 IWL_DEBUG_HT("try to aggregate tid %d\n", tid); 2013 IWL_DEBUG_RATE("try to aggregate tid %d\n", tid);
2069 rs_tl_turn_on_agg(priv, tid, lq_sta, sta); 2014 rs_tl_turn_on_agg(priv, tid, lq_sta, sta);
2070 } 2015 }
2071#endif /*CONFIG_IWL4965_HT */ 2016#endif /*CONFIG_IWL4965_HT */
@@ -2086,7 +2031,7 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
2086 } 2031 }
2087 2032
2088out: 2033out:
2089 rs_mcs_from_tbl(&tbl->current_rate, tbl, index, is_green); 2034 tbl->current_rate = rate_n_flags_from_tbl(tbl, index, is_green);
2090 i = index; 2035 i = index;
2091 sta->last_txrate_idx = i; 2036 sta->last_txrate_idx = i;
2092 2037
@@ -2106,13 +2051,14 @@ static void rs_initialize_lq(struct iwl_priv *priv,
2106 struct ieee80211_conf *conf, 2051 struct ieee80211_conf *conf,
2107 struct sta_info *sta) 2052 struct sta_info *sta)
2108{ 2053{
2109 int i;
2110 struct iwl4965_lq_sta *lq_sta; 2054 struct iwl4965_lq_sta *lq_sta;
2111 struct iwl4965_scale_tbl_info *tbl; 2055 struct iwl4965_scale_tbl_info *tbl;
2112 u8 active_tbl = 0;
2113 int rate_idx; 2056 int rate_idx;
2057 int i;
2058 u32 rate;
2114 u8 use_green = rs_use_green(priv, conf); 2059 u8 use_green = rs_use_green(priv, conf);
2115 struct iwl4965_rate mcs_rate; 2060 u8 active_tbl = 0;
2061 u8 valid_tx_ant;
2116 2062
2117 if (!sta || !sta->rate_ctrl_priv) 2063 if (!sta || !sta->rate_ctrl_priv)
2118 goto out; 2064 goto out;
@@ -2124,6 +2070,8 @@ static void rs_initialize_lq(struct iwl_priv *priv,
2124 (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)) 2070 (priv->iw_mode == IEEE80211_IF_TYPE_IBSS))
2125 goto out; 2071 goto out;
2126 2072
2073 valid_tx_ant = priv->hw_params.valid_tx_ant;
2074
2127 if (!lq_sta->search_better_tbl) 2075 if (!lq_sta->search_better_tbl)
2128 active_tbl = lq_sta->active_tbl; 2076 active_tbl = lq_sta->active_tbl;
2129 else 2077 else
@@ -2134,22 +2082,23 @@ static void rs_initialize_lq(struct iwl_priv *priv,
2134 if ((i < 0) || (i >= IWL_RATE_COUNT)) 2082 if ((i < 0) || (i >= IWL_RATE_COUNT))
2135 i = 0; 2083 i = 0;
2136 2084
2137 mcs_rate.rate_n_flags = iwl4965_rates[i].plcp ; 2085 /* FIXME:RS: This is also wrong in 4965 */
2138 mcs_rate.rate_n_flags |= RATE_MCS_ANT_B_MSK; 2086 rate = iwl4965_rates[i].plcp;
2139 mcs_rate.rate_n_flags &= ~RATE_MCS_ANT_A_MSK; 2087 rate |= RATE_MCS_ANT_B_MSK;
2088 rate &= ~RATE_MCS_ANT_A_MSK;
2140 2089
2141 if (i >= IWL_FIRST_CCK_RATE && i <= IWL_LAST_CCK_RATE) 2090 if (i >= IWL_FIRST_CCK_RATE && i <= IWL_LAST_CCK_RATE)
2142 mcs_rate.rate_n_flags |= RATE_MCS_CCK_MSK; 2091 rate |= RATE_MCS_CCK_MSK;
2143 2092
2144 tbl->antenna_type = ANT_AUX; 2093 tbl->ant_type = ANT_B;
2145 rs_get_tbl_info_from_mcs(&mcs_rate, priv->band, tbl, &rate_idx); 2094 rs_get_tbl_info_from_mcs(rate, priv->band, tbl, &rate_idx);
2146 if (!rs_is_ant_connected(priv->valid_antenna, tbl->antenna_type)) 2095 if (!rs_is_valid_ant(valid_tx_ant, tbl->ant_type))
2147 rs_toggle_antenna(&mcs_rate, tbl); 2096 rs_toggle_antenna(valid_tx_ant, &rate, tbl);
2148 2097
2149 rs_mcs_from_tbl(&mcs_rate, tbl, rate_idx, use_green); 2098 rate = rate_n_flags_from_tbl(tbl, rate_idx, use_green);
2150 tbl->current_rate.rate_n_flags = mcs_rate.rate_n_flags; 2099 tbl->current_rate = rate;
2151 rs_get_expected_tpt_table(lq_sta, tbl); 2100 rs_set_expected_tpt_table(lq_sta, tbl);
2152 rs_fill_link_cmd(lq_sta, &mcs_rate, &lq_sta->lq); 2101 rs_fill_link_cmd(NULL, lq_sta, rate);
2153 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC); 2102 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC);
2154 out: 2103 out:
2155 return; 2104 return;
@@ -2190,7 +2139,7 @@ static void rs_get_rate(void *priv_rate, struct net_device *dev,
2190 2139
2191 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && 2140 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
2192 !lq_sta->ibss_sta_added) { 2141 !lq_sta->ibss_sta_added) {
2193 u8 sta_id = iwl4965_hw_find_station(priv, hdr->addr1); 2142 u8 sta_id = iwl_find_station(priv, hdr->addr1);
2194 DECLARE_MAC_BUF(mac); 2143 DECLARE_MAC_BUF(mac);
2195 2144
2196 if (sta_id == IWL_INVALID_STATION) { 2145 if (sta_id == IWL_INVALID_STATION) {
@@ -2260,7 +2209,7 @@ static void rs_rate_init(void *priv_rate, void *priv_sta,
2260 for (i = 0; i < IWL_RATE_COUNT; i++) 2209 for (i = 0; i < IWL_RATE_COUNT; i++)
2261 rs_rate_scale_clear_window(&(lq_sta->lq_info[j].win[i])); 2210 rs_rate_scale_clear_window(&(lq_sta->lq_info[j].win[i]));
2262 2211
2263 IWL_DEBUG_RATE("rate scale global init\n"); 2212 IWL_DEBUG_RATE("LQ: *** rate scale global init ***\n");
2264 /* TODO: what is a good starting rate for STA? About middle? Maybe not 2213 /* TODO: what is a good starting rate for STA? About middle? Maybe not
2265 * the lowest or the highest rate.. Could consider using RSSI from 2214 * the lowest or the highest rate.. Could consider using RSSI from
2266 * previous packets? Need to have IEEE 802.1X auth succeed immediately 2215 * previous packets? Need to have IEEE 802.1X auth succeed immediately
@@ -2268,11 +2217,11 @@ static void rs_rate_init(void *priv_rate, void *priv_sta,
2268 2217
2269 lq_sta->ibss_sta_added = 0; 2218 lq_sta->ibss_sta_added = 0;
2270 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { 2219 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
2271 u8 sta_id = iwl4965_hw_find_station(priv, sta->addr); 2220 u8 sta_id = iwl_find_station(priv, sta->addr);
2272 DECLARE_MAC_BUF(mac); 2221 DECLARE_MAC_BUF(mac);
2273 2222
2274 /* for IBSS the call are from tasklet */ 2223 /* for IBSS the call are from tasklet */
2275 IWL_DEBUG_HT("LQ: ADD station %s\n", 2224 IWL_DEBUG_RATE("LQ: ADD station %s\n",
2276 print_mac(mac, sta->addr)); 2225 print_mac(mac, sta->addr));
2277 2226
2278 if (sta_id == IWL_INVALID_STATION) { 2227 if (sta_id == IWL_INVALID_STATION) {
@@ -2301,11 +2250,8 @@ static void rs_rate_init(void *priv_rate, void *priv_sta,
2301 sta->last_txrate_idx += IWL_FIRST_OFDM_RATE; 2250 sta->last_txrate_idx += IWL_FIRST_OFDM_RATE;
2302 2251
2303 lq_sta->is_dup = 0; 2252 lq_sta->is_dup = 0;
2304 lq_sta->valid_antenna = priv->valid_antenna;
2305 lq_sta->antenna = priv->antenna;
2306 lq_sta->is_green = rs_use_green(priv, conf); 2253 lq_sta->is_green = rs_use_green(priv, conf);
2307 lq_sta->active_rate = priv->active_rate; 2254 lq_sta->active_legacy_rate = priv->active_rate & ~(0x1000);
2308 lq_sta->active_rate &= ~(0x1000);
2309 lq_sta->active_rate_basic = priv->active_rate_basic; 2255 lq_sta->active_rate_basic = priv->active_rate_basic;
2310 lq_sta->band = priv->band; 2256 lq_sta->band = priv->band;
2311#ifdef CONFIG_IWL4965_HT 2257#ifdef CONFIG_IWL4965_HT
@@ -2313,23 +2259,37 @@ static void rs_rate_init(void *priv_rate, void *priv_sta,
2313 * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3), 2259 * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3),
2314 * supp_rates[] does not; shift to convert format, force 9 MBits off. 2260 * supp_rates[] does not; shift to convert format, force 9 MBits off.
2315 */ 2261 */
2316 lq_sta->active_siso_rate = (priv->current_ht_config.supp_mcs_set[0] << 1); 2262 lq_sta->active_siso_rate =
2263 priv->current_ht_config.supp_mcs_set[0] << 1;
2317 lq_sta->active_siso_rate |= 2264 lq_sta->active_siso_rate |=
2318 (priv->current_ht_config.supp_mcs_set[0] & 0x1); 2265 priv->current_ht_config.supp_mcs_set[0] & 0x1;
2319 lq_sta->active_siso_rate &= ~((u16)0x2); 2266 lq_sta->active_siso_rate &= ~((u16)0x2);
2320 lq_sta->active_siso_rate = 2267 lq_sta->active_siso_rate <<= IWL_FIRST_OFDM_RATE;
2321 lq_sta->active_siso_rate << IWL_FIRST_OFDM_RATE;
2322 2268
2323 /* Same here */ 2269 /* Same here */
2324 lq_sta->active_mimo_rate = (priv->current_ht_config.supp_mcs_set[1] << 1); 2270 lq_sta->active_mimo2_rate =
2325 lq_sta->active_mimo_rate |= 2271 priv->current_ht_config.supp_mcs_set[1] << 1;
2326 (priv->current_ht_config.supp_mcs_set[1] & 0x1); 2272 lq_sta->active_mimo2_rate |=
2327 lq_sta->active_mimo_rate &= ~((u16)0x2); 2273 priv->current_ht_config.supp_mcs_set[1] & 0x1;
2328 lq_sta->active_mimo_rate = 2274 lq_sta->active_mimo2_rate &= ~((u16)0x2);
2329 lq_sta->active_mimo_rate << IWL_FIRST_OFDM_RATE; 2275 lq_sta->active_mimo2_rate <<= IWL_FIRST_OFDM_RATE;
2330 IWL_DEBUG_HT("SISO RATE 0x%X MIMO RATE 0x%X\n", 2276
2277 lq_sta->active_mimo3_rate =
2278 priv->current_ht_config.supp_mcs_set[2] << 1;
2279 lq_sta->active_mimo3_rate |=
2280 priv->current_ht_config.supp_mcs_set[2] & 0x1;
2281 lq_sta->active_mimo3_rate &= ~((u16)0x2);
2282 lq_sta->active_mimo3_rate <<= IWL_FIRST_OFDM_RATE;
2283
2284 IWL_DEBUG_RATE("SISO-RATE=%X MIMO2-RATE=%X MIMO3-RATE=%X\n",
2331 lq_sta->active_siso_rate, 2285 lq_sta->active_siso_rate,
2332 lq_sta->active_mimo_rate); 2286 lq_sta->active_mimo2_rate,
2287 lq_sta->active_mimo3_rate);
2288
2289 /* These values will be overriden later */
2290 lq_sta->lq.general_params.single_stream_ant_msk = ANT_A;
2291 lq_sta->lq.general_params.dual_stream_ant_msk = ANT_AB;
2292
2333 /* as default allow aggregation for all tids */ 2293 /* as default allow aggregation for all tids */
2334 lq_sta->tx_agg_tid_en = IWL_AGG_ALL_TID; 2294 lq_sta->tx_agg_tid_en = IWL_AGG_ALL_TID;
2335#endif /*CONFIG_IWL4965_HT*/ 2295#endif /*CONFIG_IWL4965_HT*/
@@ -2343,50 +2303,55 @@ static void rs_rate_init(void *priv_rate, void *priv_sta,
2343 rs_initialize_lq(priv, conf, sta); 2303 rs_initialize_lq(priv, conf, sta);
2344} 2304}
2345 2305
2346static void rs_fill_link_cmd(struct iwl4965_lq_sta *lq_sta, 2306static void rs_fill_link_cmd(const struct iwl_priv *priv,
2347 struct iwl4965_rate *tx_mcs, 2307 struct iwl4965_lq_sta *lq_sta,
2348 struct iwl_link_quality_cmd *lq_cmd) 2308 u32 new_rate)
2349{ 2309{
2310 struct iwl4965_scale_tbl_info tbl_type;
2350 int index = 0; 2311 int index = 0;
2351 int rate_idx; 2312 int rate_idx;
2352 int repeat_rate = 0; 2313 int repeat_rate = 0;
2353 u8 ant_toggle_count = 0; 2314 u8 ant_toggle_cnt = 0;
2354 u8 use_ht_possible = 1; 2315 u8 use_ht_possible = 1;
2355 struct iwl4965_rate new_rate; 2316 u8 valid_tx_ant = 0;
2356 struct iwl4965_scale_tbl_info tbl_type = { 0 }; 2317 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
2357 2318
2358 /* Override starting rate (index 0) if needed for debug purposes */ 2319 /* Override starting rate (index 0) if needed for debug purposes */
2359 rs_dbgfs_set_mcs(lq_sta, tx_mcs, index); 2320 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
2360 2321
2361 /* Interpret rate_n_flags */ 2322 /* Interpret new_rate (rate_n_flags) */
2362 rs_get_tbl_info_from_mcs(tx_mcs, lq_sta->band, 2323 memset(&tbl_type, 0, sizeof(tbl_type));
2324 rs_get_tbl_info_from_mcs(new_rate, lq_sta->band,
2363 &tbl_type, &rate_idx); 2325 &tbl_type, &rate_idx);
2364 2326
2365 /* How many times should we repeat the initial rate? */ 2327 /* How many times should we repeat the initial rate? */
2366 if (is_legacy(tbl_type.lq_type)) { 2328 if (is_legacy(tbl_type.lq_type)) {
2367 ant_toggle_count = 1; 2329 ant_toggle_cnt = 1;
2368 repeat_rate = IWL_NUMBER_TRY; 2330 repeat_rate = IWL_NUMBER_TRY;
2369 } else 2331 } else {
2370 repeat_rate = IWL_HT_NUMBER_TRY; 2332 repeat_rate = IWL_HT_NUMBER_TRY;
2333 }
2371 2334
2372 lq_cmd->general_params.mimo_delimiter = 2335 lq_cmd->general_params.mimo_delimiter =
2373 is_mimo(tbl_type.lq_type) ? 1 : 0; 2336 is_mimo(tbl_type.lq_type) ? 1 : 0;
2374 2337
2375 /* Fill 1st table entry (index 0) */ 2338 /* Fill 1st table entry (index 0) */
2376 lq_cmd->rs_table[index].rate_n_flags = 2339 lq_cmd->rs_table[index].rate_n_flags = cpu_to_le32(new_rate);
2377 cpu_to_le32(tx_mcs->rate_n_flags);
2378 new_rate.rate_n_flags = tx_mcs->rate_n_flags;
2379 2340
2380 if (is_mimo(tbl_type.lq_type) || (tbl_type.antenna_type == ANT_MAIN)) 2341 if (num_of_ant(tbl_type.ant_type) == 1) {
2381 lq_cmd->general_params.single_stream_ant_msk 2342 lq_cmd->general_params.single_stream_ant_msk =
2382 = LINK_QUAL_ANT_A_MSK; 2343 tbl_type.ant_type;
2383 else 2344 } else if (num_of_ant(tbl_type.ant_type) == 2) {
2384 lq_cmd->general_params.single_stream_ant_msk 2345 lq_cmd->general_params.dual_stream_ant_msk =
2385 = LINK_QUAL_ANT_B_MSK; 2346 tbl_type.ant_type;
2347 } /* otherwise we don't modify the existing value */
2386 2348
2387 index++; 2349 index++;
2388 repeat_rate--; 2350 repeat_rate--;
2389 2351
2352 if (priv)
2353 valid_tx_ant = priv->hw_params.valid_tx_ant;
2354
2390 /* Fill rest of rate table */ 2355 /* Fill rest of rate table */
2391 while (index < LINK_QUAL_MAX_RETRY_NUM) { 2356 while (index < LINK_QUAL_MAX_RETRY_NUM) {
2392 /* Repeat initial/next rate. 2357 /* Repeat initial/next rate.
@@ -2394,26 +2359,25 @@ static void rs_fill_link_cmd(struct iwl4965_lq_sta *lq_sta,
2394 * For HT IWL_HT_NUMBER_TRY == 3, this executes twice. */ 2359 * For HT IWL_HT_NUMBER_TRY == 3, this executes twice. */
2395 while (repeat_rate > 0 && (index < LINK_QUAL_MAX_RETRY_NUM)) { 2360 while (repeat_rate > 0 && (index < LINK_QUAL_MAX_RETRY_NUM)) {
2396 if (is_legacy(tbl_type.lq_type)) { 2361 if (is_legacy(tbl_type.lq_type)) {
2397 if (ant_toggle_count < 2362 if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE)
2398 NUM_TRY_BEFORE_ANTENNA_TOGGLE) 2363 ant_toggle_cnt++;
2399 ant_toggle_count++; 2364 else if (priv &&
2400 else { 2365 rs_toggle_antenna(valid_tx_ant,
2401 rs_toggle_antenna(&new_rate, &tbl_type); 2366 &new_rate, &tbl_type))
2402 ant_toggle_count = 1; 2367 ant_toggle_cnt = 1;
2403 } 2368}
2404 }
2405 2369
2406 /* Override next rate if needed for debug purposes */ 2370 /* Override next rate if needed for debug purposes */
2407 rs_dbgfs_set_mcs(lq_sta, &new_rate, index); 2371 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
2408 2372
2409 /* Fill next table entry */ 2373 /* Fill next table entry */
2410 lq_cmd->rs_table[index].rate_n_flags = 2374 lq_cmd->rs_table[index].rate_n_flags =
2411 cpu_to_le32(new_rate.rate_n_flags); 2375 cpu_to_le32(new_rate);
2412 repeat_rate--; 2376 repeat_rate--;
2413 index++; 2377 index++;
2414 } 2378 }
2415 2379
2416 rs_get_tbl_info_from_mcs(&new_rate, lq_sta->band, &tbl_type, 2380 rs_get_tbl_info_from_mcs(new_rate, lq_sta->band, &tbl_type,
2417 &rate_idx); 2381 &rate_idx);
2418 2382
2419 /* Indicate to uCode which entries might be MIMO. 2383 /* Indicate to uCode which entries might be MIMO.
@@ -2423,20 +2387,22 @@ static void rs_fill_link_cmd(struct iwl4965_lq_sta *lq_sta,
2423 lq_cmd->general_params.mimo_delimiter = index; 2387 lq_cmd->general_params.mimo_delimiter = index;
2424 2388
2425 /* Get next rate */ 2389 /* Get next rate */
2426 rs_get_lower_rate(lq_sta, &tbl_type, rate_idx, 2390 new_rate = rs_get_lower_rate(lq_sta, &tbl_type, rate_idx,
2427 use_ht_possible, &new_rate); 2391 use_ht_possible);
2428 2392
2429 /* How many times should we repeat the next rate? */ 2393 /* How many times should we repeat the next rate? */
2430 if (is_legacy(tbl_type.lq_type)) { 2394 if (is_legacy(tbl_type.lq_type)) {
2431 if (ant_toggle_count < NUM_TRY_BEFORE_ANTENNA_TOGGLE) 2395 if (ant_toggle_cnt < NUM_TRY_BEFORE_ANT_TOGGLE)
2432 ant_toggle_count++; 2396 ant_toggle_cnt++;
2433 else { 2397 else if (priv &&
2434 rs_toggle_antenna(&new_rate, &tbl_type); 2398 rs_toggle_antenna(valid_tx_ant,
2435 ant_toggle_count = 1; 2399 &new_rate, &tbl_type))
2436 } 2400 ant_toggle_cnt = 1;
2401
2437 repeat_rate = IWL_NUMBER_TRY; 2402 repeat_rate = IWL_NUMBER_TRY;
2438 } else 2403 } else {
2439 repeat_rate = IWL_HT_NUMBER_TRY; 2404 repeat_rate = IWL_HT_NUMBER_TRY;
2405 }
2440 2406
2441 /* Don't allow HT rates after next pass. 2407 /* Don't allow HT rates after next pass.
2442 * rs_get_lower_rate() will change type to LQ_A or LQ_G. */ 2408 * rs_get_lower_rate() will change type to LQ_A or LQ_G. */
@@ -2446,14 +2412,12 @@ static void rs_fill_link_cmd(struct iwl4965_lq_sta *lq_sta,
2446 rs_dbgfs_set_mcs(lq_sta, &new_rate, index); 2412 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
2447 2413
2448 /* Fill next table entry */ 2414 /* Fill next table entry */
2449 lq_cmd->rs_table[index].rate_n_flags = 2415 lq_cmd->rs_table[index].rate_n_flags = cpu_to_le32(new_rate);
2450 cpu_to_le32(new_rate.rate_n_flags);
2451 2416
2452 index++; 2417 index++;
2453 repeat_rate--; 2418 repeat_rate--;
2454 } 2419 }
2455 2420
2456 lq_cmd->general_params.dual_stream_ant_msk = 3;
2457 lq_cmd->agg_params.agg_dis_start_th = 3; 2421 lq_cmd->agg_params.agg_dis_start_th = 3;
2458 lq_cmd->agg_params.agg_time_limit = cpu_to_le16(4000); 2422 lq_cmd->agg_params.agg_time_limit = cpu_to_le16(4000);
2459} 2423}
@@ -2496,25 +2460,21 @@ static int open_file_generic(struct inode *inode, struct file *file)
2496 return 0; 2460 return 0;
2497} 2461}
2498static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta, 2462static void rs_dbgfs_set_mcs(struct iwl4965_lq_sta *lq_sta,
2499 struct iwl4965_rate *mcs, int index) 2463 u32 *rate_n_flags, int index)
2500{ 2464{
2501 u32 base_rate; 2465 if (lq_sta->dbg_fixed_rate) {
2502 2466 if (index < 12) {
2503 if (lq_sta->band == IEEE80211_BAND_5GHZ) 2467 *rate_n_flags = lq_sta->dbg_fixed_rate;
2504 base_rate = 0x800D; 2468 } else {
2505 else 2469 if (lq_sta->band == IEEE80211_BAND_5GHZ)
2506 base_rate = 0x820A; 2470 *rate_n_flags = 0x800D;
2507 2471 else
2508 if (lq_sta->dbg_fixed.rate_n_flags) { 2472 *rate_n_flags = 0x820A;
2509 if (index < 12) 2473 }
2510 mcs->rate_n_flags = lq_sta->dbg_fixed.rate_n_flags;
2511 else
2512 mcs->rate_n_flags = base_rate;
2513 IWL_DEBUG_RATE("Fixed rate ON\n"); 2474 IWL_DEBUG_RATE("Fixed rate ON\n");
2514 return; 2475 } else {
2476 IWL_DEBUG_RATE("Fixed rate OFF\n");
2515 } 2477 }
2516
2517 IWL_DEBUG_RATE("Fixed rate OFF\n");
2518} 2478}
2519 2479
2520static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file, 2480static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file,
@@ -2531,19 +2491,20 @@ static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file,
2531 return -EFAULT; 2491 return -EFAULT;
2532 2492
2533 if (sscanf(buf, "%x", &parsed_rate) == 1) 2493 if (sscanf(buf, "%x", &parsed_rate) == 1)
2534 lq_sta->dbg_fixed.rate_n_flags = parsed_rate; 2494 lq_sta->dbg_fixed_rate = parsed_rate;
2535 else 2495 else
2536 lq_sta->dbg_fixed.rate_n_flags = 0; 2496 lq_sta->dbg_fixed_rate = 0;
2537 2497
2538 lq_sta->active_rate = 0x0FFF; /* 1 - 54 MBits, includes CCK */ 2498 lq_sta->active_legacy_rate = 0x0FFF; /* 1 - 54 MBits, includes CCK */
2539 lq_sta->active_siso_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */ 2499 lq_sta->active_siso_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
2540 lq_sta->active_mimo_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */ 2500 lq_sta->active_mimo2_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
2501 lq_sta->active_mimo3_rate = 0x1FD0; /* 6 - 60 MBits, no 9, no CCK */
2541 2502
2542 IWL_DEBUG_RATE("sta_id %d rate 0x%X\n", 2503 IWL_DEBUG_RATE("sta_id %d rate 0x%X\n",
2543 lq_sta->lq.sta_id, lq_sta->dbg_fixed.rate_n_flags); 2504 lq_sta->lq.sta_id, lq_sta->dbg_fixed_rate);
2544 2505
2545 if (lq_sta->dbg_fixed.rate_n_flags) { 2506 if (lq_sta->dbg_fixed_rate) {
2546 rs_fill_link_cmd(lq_sta, &lq_sta->dbg_fixed, &lq_sta->lq); 2507 rs_fill_link_cmd(NULL, lq_sta, lq_sta->dbg_fixed_rate);
2547 iwl_send_lq_cmd(lq_sta->drv, &lq_sta->lq, CMD_ASYNC); 2508 iwl_send_lq_cmd(lq_sta->drv, &lq_sta->lq, CMD_ASYNC);
2548 } 2509 }
2549 2510
@@ -2562,9 +2523,9 @@ static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
2562 desc += sprintf(buff+desc, "sta_id %d\n", lq_sta->lq.sta_id); 2523 desc += sprintf(buff+desc, "sta_id %d\n", lq_sta->lq.sta_id);
2563 desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n", 2524 desc += sprintf(buff+desc, "failed=%d success=%d rate=0%X\n",
2564 lq_sta->total_failed, lq_sta->total_success, 2525 lq_sta->total_failed, lq_sta->total_success,
2565 lq_sta->active_rate); 2526 lq_sta->active_legacy_rate);
2566 desc += sprintf(buff+desc, "fixed rate 0x%X\n", 2527 desc += sprintf(buff+desc, "fixed rate 0x%X\n",
2567 lq_sta->dbg_fixed.rate_n_flags); 2528 lq_sta->dbg_fixed_rate);
2568 desc += sprintf(buff+desc, "general:" 2529 desc += sprintf(buff+desc, "general:"
2569 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n", 2530 "flags=0x%X mimo-d=%d s-ant0x%x d-ant=0x%x\n",
2570 lq_sta->lq.general_params.flags, 2531 lq_sta->lq.general_params.flags,
@@ -2614,7 +2575,7 @@ static ssize_t rs_sta_dbgfs_stats_table_read(struct file *file,
2614 lq_sta->lq_info[i].is_SGI, 2575 lq_sta->lq_info[i].is_SGI,
2615 lq_sta->lq_info[i].is_fat, 2576 lq_sta->lq_info[i].is_fat,
2616 lq_sta->lq_info[i].is_dup, 2577 lq_sta->lq_info[i].is_dup,
2617 lq_sta->lq_info[i].current_rate.rate_n_flags); 2578 lq_sta->lq_info[i].current_rate);
2618 for (j = 0; j < IWL_RATE_COUNT; j++) { 2579 for (j = 0; j < IWL_RATE_COUNT; j++) {
2619 desc += sprintf(buff+desc, 2580 desc += sprintf(buff+desc,
2620 "counter=%d success=%d %%=%d\n", 2581 "counter=%d success=%d %%=%d\n",
@@ -2704,7 +2665,7 @@ int iwl4965_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id)
2704 lq_sta = (void *)sta->rate_ctrl_priv; 2665 lq_sta = (void *)sta->rate_ctrl_priv;
2705 2666
2706 lq_type = lq_sta->lq_info[lq_sta->active_tbl].lq_type; 2667 lq_type = lq_sta->lq_info[lq_sta->active_tbl].lq_type;
2707 antenna = lq_sta->lq_info[lq_sta->active_tbl].antenna_type; 2668 antenna = lq_sta->lq_info[lq_sta->active_tbl].ant_type;
2708 2669
2709 if (is_legacy(lq_type)) 2670 if (is_legacy(lq_type))
2710 i = IWL_RATE_54M_INDEX; 2671 i = IWL_RATE_54M_INDEX;
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965-rs.h b/drivers/net/wireless/iwlwifi/iwl-4965-rs.h
index 866e378aa385..7ea2041a22e0 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965-rs.h
+++ b/drivers/net/wireless/iwlwifi/iwl-4965-rs.h
@@ -27,12 +27,13 @@
27#ifndef __iwl_4965_rs_h__ 27#ifndef __iwl_4965_rs_h__
28#define __iwl_4965_rs_h__ 28#define __iwl_4965_rs_h__
29 29
30#include "iwl-4965.h" 30#include "iwl-dev.h"
31 31
32struct iwl4965_rate_info { 32struct iwl4965_rate_info {
33 u8 plcp; /* uCode API: IWL_RATE_6M_PLCP, etc. */ 33 u8 plcp; /* uCode API: IWL_RATE_6M_PLCP, etc. */
34 u8 plcp_siso; /* uCode API: IWL_RATE_SISO_6M_PLCP, etc. */ 34 u8 plcp_siso; /* uCode API: IWL_RATE_SISO_6M_PLCP, etc. */
35 u8 plcp_mimo; /* uCode API: IWL_RATE_MIMO_6M_PLCP, etc. */ 35 u8 plcp_mimo2; /* uCode API: IWL_RATE_MIMO2_6M_PLCP, etc. */
36 u8 plcp_mimo3; /* uCode API: IWL_RATE_MIMO3_6M_PLCP, etc. */
36 u8 ieee; /* MAC header: IWL_RATE_6M_IEEE, etc. */ 37 u8 ieee; /* MAC header: IWL_RATE_6M_IEEE, etc. */
37 u8 prev_ieee; /* previous rate in IEEE speeds */ 38 u8 prev_ieee; /* previous rate in IEEE speeds */
38 u8 next_ieee; /* next rate in IEEE speeds */ 39 u8 next_ieee; /* next rate in IEEE speeds */
@@ -60,9 +61,9 @@ enum {
60 IWL_RATE_48M_INDEX, 61 IWL_RATE_48M_INDEX,
61 IWL_RATE_54M_INDEX, 62 IWL_RATE_54M_INDEX,
62 IWL_RATE_60M_INDEX, 63 IWL_RATE_60M_INDEX,
63 IWL_RATE_COUNT, 64 IWL_RATE_COUNT, /*FIXME:RS:change to IWL_RATE_INDEX_COUNT,*/
64 IWL_RATE_INVM_INDEX = IWL_RATE_COUNT, 65 IWL_RATE_INVM_INDEX = IWL_RATE_COUNT,
65 IWL_RATE_INVALID = IWL_RATE_INVM_INDEX 66 IWL_RATE_INVALID = IWL_RATE_COUNT,
66}; 67};
67 68
68enum { 69enum {
@@ -97,11 +98,13 @@ enum {
97 IWL_RATE_36M_PLCP = 11, 98 IWL_RATE_36M_PLCP = 11,
98 IWL_RATE_48M_PLCP = 1, 99 IWL_RATE_48M_PLCP = 1,
99 IWL_RATE_54M_PLCP = 3, 100 IWL_RATE_54M_PLCP = 3,
100 IWL_RATE_60M_PLCP = 3, 101 IWL_RATE_60M_PLCP = 3,/*FIXME:RS:should be removed*/
101 IWL_RATE_1M_PLCP = 10, 102 IWL_RATE_1M_PLCP = 10,
102 IWL_RATE_2M_PLCP = 20, 103 IWL_RATE_2M_PLCP = 20,
103 IWL_RATE_5M_PLCP = 55, 104 IWL_RATE_5M_PLCP = 55,
104 IWL_RATE_11M_PLCP = 110, 105 IWL_RATE_11M_PLCP = 110,
106 /*FIXME:RS:change to IWL_RATE_LEGACY_??M_PLCP */
107 /*FIXME:RS:add IWL_RATE_LEGACY_INVM_PLCP = 0,*/
105}; 108};
106 109
107/* 4965 uCode API values for OFDM high-throughput (HT) bit rates */ 110/* 4965 uCode API values for OFDM high-throughput (HT) bit rates */
@@ -114,16 +117,25 @@ enum {
114 IWL_RATE_SISO_48M_PLCP = 5, 117 IWL_RATE_SISO_48M_PLCP = 5,
115 IWL_RATE_SISO_54M_PLCP = 6, 118 IWL_RATE_SISO_54M_PLCP = 6,
116 IWL_RATE_SISO_60M_PLCP = 7, 119 IWL_RATE_SISO_60M_PLCP = 7,
117 IWL_RATE_MIMO_6M_PLCP = 0x8, 120 IWL_RATE_MIMO2_6M_PLCP = 0x8,
118 IWL_RATE_MIMO_12M_PLCP = 0x9, 121 IWL_RATE_MIMO2_12M_PLCP = 0x9,
119 IWL_RATE_MIMO_18M_PLCP = 0xa, 122 IWL_RATE_MIMO2_18M_PLCP = 0xa,
120 IWL_RATE_MIMO_24M_PLCP = 0xb, 123 IWL_RATE_MIMO2_24M_PLCP = 0xb,
121 IWL_RATE_MIMO_36M_PLCP = 0xc, 124 IWL_RATE_MIMO2_36M_PLCP = 0xc,
122 IWL_RATE_MIMO_48M_PLCP = 0xd, 125 IWL_RATE_MIMO2_48M_PLCP = 0xd,
123 IWL_RATE_MIMO_54M_PLCP = 0xe, 126 IWL_RATE_MIMO2_54M_PLCP = 0xe,
124 IWL_RATE_MIMO_60M_PLCP = 0xf, 127 IWL_RATE_MIMO2_60M_PLCP = 0xf,
128 IWL_RATE_MIMO3_6M_PLCP = 0x10,
129 IWL_RATE_MIMO3_12M_PLCP = 0x11,
130 IWL_RATE_MIMO3_18M_PLCP = 0x12,
131 IWL_RATE_MIMO3_24M_PLCP = 0x13,
132 IWL_RATE_MIMO3_36M_PLCP = 0x14,
133 IWL_RATE_MIMO3_48M_PLCP = 0x15,
134 IWL_RATE_MIMO3_54M_PLCP = 0x16,
135 IWL_RATE_MIMO3_60M_PLCP = 0x17,
125 IWL_RATE_SISO_INVM_PLCP, 136 IWL_RATE_SISO_INVM_PLCP,
126 IWL_RATE_MIMO_INVM_PLCP = IWL_RATE_SISO_INVM_PLCP, 137 IWL_RATE_MIMO2_INVM_PLCP = IWL_RATE_SISO_INVM_PLCP,
138 IWL_RATE_MIMO3_INVM_PLCP = IWL_RATE_SISO_INVM_PLCP,
127}; 139};
128 140
129/* MAC header values for bit rates */ 141/* MAC header values for bit rates */
@@ -196,11 +208,11 @@ enum {
196/* possible actions when in legacy mode */ 208/* possible actions when in legacy mode */
197#define IWL_LEGACY_SWITCH_ANTENNA 0 209#define IWL_LEGACY_SWITCH_ANTENNA 0
198#define IWL_LEGACY_SWITCH_SISO 1 210#define IWL_LEGACY_SWITCH_SISO 1
199#define IWL_LEGACY_SWITCH_MIMO 2 211#define IWL_LEGACY_SWITCH_MIMO2 2
200 212
201/* possible actions when in siso mode */ 213/* possible actions when in siso mode */
202#define IWL_SISO_SWITCH_ANTENNA 0 214#define IWL_SISO_SWITCH_ANTENNA 0
203#define IWL_SISO_SWITCH_MIMO 1 215#define IWL_SISO_SWITCH_MIMO2 1
204#define IWL_SISO_SWITCH_GI 2 216#define IWL_SISO_SWITCH_GI 2
205 217
206/* possible actions when in mimo mode */ 218/* possible actions when in mimo mode */
@@ -208,6 +220,10 @@ enum {
208#define IWL_MIMO_SWITCH_ANTENNA_B 1 220#define IWL_MIMO_SWITCH_ANTENNA_B 1
209#define IWL_MIMO_SWITCH_GI 2 221#define IWL_MIMO_SWITCH_GI 2
210 222
223/*FIXME:RS:separate MIMO2/3 transitions*/
224
225/*FIXME:RS:add posible acctions for MIMO3*/
226
211#define IWL_ACTION_LIMIT 3 /* # possible actions */ 227#define IWL_ACTION_LIMIT 3 /* # possible actions */
212 228
213#define LQ_SIZE 2 /* 2 mode tables: "Active" and "Search" */ 229#define LQ_SIZE 2 /* 2 mode tables: "Active" and "Search" */
@@ -226,29 +242,40 @@ enum {
226 242
227extern const struct iwl4965_rate_info iwl4965_rates[IWL_RATE_COUNT]; 243extern const struct iwl4965_rate_info iwl4965_rates[IWL_RATE_COUNT];
228 244
229enum iwl4965_table_type { 245enum iwl_table_type {
230 LQ_NONE, 246 LQ_NONE,
231 LQ_G, /* legacy types */ 247 LQ_G, /* legacy types */
232 LQ_A, 248 LQ_A,
233 LQ_SISO, /* high-throughput types */ 249 LQ_SISO, /* high-throughput types */
234 LQ_MIMO, 250 LQ_MIMO2,
251 LQ_MIMO3,
235 LQ_MAX, 252 LQ_MAX,
236}; 253};
237 254
238#define is_legacy(tbl) (((tbl) == LQ_G) || ((tbl) == LQ_A)) 255#define is_legacy(tbl) (((tbl) == LQ_G) || ((tbl) == LQ_A))
239#define is_siso(tbl) (((tbl) == LQ_SISO)) 256#define is_siso(tbl) ((tbl) == LQ_SISO)
240#define is_mimo(tbl) (((tbl) == LQ_MIMO)) 257#define is_mimo2(tbl) ((tbl) == LQ_MIMO2)
258#define is_mimo3(tbl) ((tbl) == LQ_MIMO3)
259#define is_mimo(tbl) (is_mimo2(tbl) || is_mimo3(tbl))
241#define is_Ht(tbl) (is_siso(tbl) || is_mimo(tbl)) 260#define is_Ht(tbl) (is_siso(tbl) || is_mimo(tbl))
242#define is_a_band(tbl) (((tbl) == LQ_A)) 261#define is_a_band(tbl) ((tbl) == LQ_A)
243#define is_g_and(tbl) (((tbl) == LQ_G)) 262#define is_g_and(tbl) ((tbl) == LQ_G)
244 263
245/* 4965 has 2 antennas/chains for Tx (but 3 for Rx) */ 264#define ANT_NONE 0x0
246enum iwl4965_antenna_type { 265#define ANT_A BIT(0)
247 ANT_NONE, 266#define ANT_B BIT(1)
248 ANT_MAIN, 267#define ANT_AB (ANT_A | ANT_B)
249 ANT_AUX, 268#define ANT_C BIT(2)
250 ANT_BOTH, 269#define ANT_AC (ANT_A | ANT_C)
251}; 270#define ANT_BC (ANT_B | ANT_C)
271#define ANT_ABC (ANT_AB | ANT_C)
272
273static inline u8 num_of_ant(u8 mask)
274{
275 return !!((mask) & ANT_A) +
276 !!((mask) & ANT_B) +
277 !!((mask) & ANT_C);
278}
252 279
253static inline u8 iwl4965_get_prev_ieee_rate(u8 rate_index) 280static inline u8 iwl4965_get_prev_ieee_rate(u8 rate_index)
254{ 281{
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c
index bf19eb8aafd0..5d675e39bab8 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965.c
+++ b/drivers/net/wireless/iwlwifi/iwl-4965.c
@@ -39,14 +39,15 @@
39#include <asm/unaligned.h> 39#include <asm/unaligned.h>
40 40
41#include "iwl-eeprom.h" 41#include "iwl-eeprom.h"
42#include "iwl-4965.h" 42#include "iwl-dev.h"
43#include "iwl-core.h" 43#include "iwl-core.h"
44#include "iwl-io.h" 44#include "iwl-io.h"
45#include "iwl-helpers.h" 45#include "iwl-helpers.h"
46#include "iwl-calib.h"
46 47
47/* module parameters */ 48/* module parameters */
48static struct iwl_mod_params iwl4965_mod_params = { 49static struct iwl_mod_params iwl4965_mod_params = {
49 .num_of_queues = IWL4965_MAX_NUM_QUEUES, 50 .num_of_queues = IWL49_NUM_QUEUES,
50 .enable_qos = 1, 51 .enable_qos = 1,
51 .amsdu_size_8K = 1, 52 .amsdu_size_8K = 1,
52 /* the rest are 0 by default */ 53 /* the rest are 0 by default */
@@ -54,42 +55,6 @@ static struct iwl_mod_params iwl4965_mod_params = {
54 55
55static void iwl4965_hw_card_show_info(struct iwl_priv *priv); 56static void iwl4965_hw_card_show_info(struct iwl_priv *priv);
56 57
57#define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \
58 [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \
59 IWL_RATE_SISO_##s##M_PLCP, \
60 IWL_RATE_MIMO_##s##M_PLCP, \
61 IWL_RATE_##r##M_IEEE, \
62 IWL_RATE_##ip##M_INDEX, \
63 IWL_RATE_##in##M_INDEX, \
64 IWL_RATE_##rp##M_INDEX, \
65 IWL_RATE_##rn##M_INDEX, \
66 IWL_RATE_##pp##M_INDEX, \
67 IWL_RATE_##np##M_INDEX }
68
69/*
70 * Parameter order:
71 * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
72 *
73 * If there isn't a valid next or previous rate then INV is used which
74 * maps to IWL_RATE_INVALID
75 *
76 */
77const struct iwl4965_rate_info iwl4965_rates[IWL_RATE_COUNT] = {
78 IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */
79 IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */
80 IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */
81 IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */
82 IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */
83 IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */
84 IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */
85 IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */
86 IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */
87 IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */
88 IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */
89 IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */
90 IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
91};
92
93#ifdef CONFIG_IWL4965_HT 58#ifdef CONFIG_IWL4965_HT
94 59
95static const u16 default_tid_to_tx_fifo[] = { 60static const u16 default_tid_to_tx_fifo[] = {
@@ -259,120 +224,12 @@ static int iwl4965_load_bsm(struct iwl_priv *priv)
259 return 0; 224 return 0;
260} 225}
261 226
262static int iwl4965_init_drv(struct iwl_priv *priv)
263{
264 int ret;
265 int i;
266
267 priv->antenna = (enum iwl4965_antenna)priv->cfg->mod_params->antenna;
268 priv->retry_rate = 1;
269 priv->ibss_beacon = NULL;
270
271 spin_lock_init(&priv->lock);
272 spin_lock_init(&priv->power_data.lock);
273 spin_lock_init(&priv->sta_lock);
274 spin_lock_init(&priv->hcmd_lock);
275 spin_lock_init(&priv->lq_mngr.lock);
276
277 priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
278 sizeof(struct iwl4965_shared),
279 &priv->shared_phys);
280
281 if (!priv->shared_virt) {
282 ret = -ENOMEM;
283 goto err;
284 }
285
286 memset(priv->shared_virt, 0, sizeof(struct iwl4965_shared));
287
288
289 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++)
290 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
291
292 INIT_LIST_HEAD(&priv->free_frames);
293
294 mutex_init(&priv->mutex);
295
296 /* Clear the driver's (not device's) station table */
297 iwlcore_clear_stations_table(priv);
298
299 priv->data_retry_limit = -1;
300 priv->ieee_channels = NULL;
301 priv->ieee_rates = NULL;
302 priv->band = IEEE80211_BAND_2GHZ;
303
304 priv->iw_mode = IEEE80211_IF_TYPE_STA;
305
306 priv->use_ant_b_for_management_frame = 1; /* start with ant B */
307 priv->valid_antenna = 0x7; /* assume all 3 connected */
308 priv->ps_mode = IWL_MIMO_PS_NONE;
309
310 /* Choose which receivers/antennas to use */
311 iwl4965_set_rxon_chain(priv);
312
313 iwlcore_reset_qos(priv);
314
315 priv->qos_data.qos_active = 0;
316 priv->qos_data.qos_cap.val = 0;
317
318 iwlcore_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
319
320 priv->rates_mask = IWL_RATES_MASK;
321 /* If power management is turned on, default to AC mode */
322 priv->power_mode = IWL_POWER_AC;
323 priv->user_txpower_limit = IWL_DEFAULT_TX_POWER;
324
325 ret = iwl_init_channel_map(priv);
326 if (ret) {
327 IWL_ERROR("initializing regulatory failed: %d\n", ret);
328 goto err;
329 }
330
331 ret = iwl4965_init_geos(priv);
332 if (ret) {
333 IWL_ERROR("initializing geos failed: %d\n", ret);
334 goto err_free_channel_map;
335 }
336
337 ret = ieee80211_register_hw(priv->hw);
338 if (ret) {
339 IWL_ERROR("Failed to register network device (error %d)\n",
340 ret);
341 goto err_free_geos;
342 }
343
344 priv->hw->conf.beacon_int = 100;
345 priv->mac80211_registered = 1;
346
347 return 0;
348
349err_free_geos:
350 iwl4965_free_geos(priv);
351err_free_channel_map:
352 iwl_free_channel_map(priv);
353err:
354 return ret;
355}
356
357static int is_fat_channel(__le32 rxon_flags) 227static int is_fat_channel(__le32 rxon_flags)
358{ 228{
359 return (rxon_flags & RXON_FLG_CHANNEL_MODE_PURE_40_MSK) || 229 return (rxon_flags & RXON_FLG_CHANNEL_MODE_PURE_40_MSK) ||
360 (rxon_flags & RXON_FLG_CHANNEL_MODE_MIXED_MSK); 230 (rxon_flags & RXON_FLG_CHANNEL_MODE_MIXED_MSK);
361} 231}
362 232
363static u8 is_single_stream(struct iwl_priv *priv)
364{
365#ifdef CONFIG_IWL4965_HT
366 if (!priv->current_ht_config.is_ht ||
367 (priv->current_ht_config.supp_mcs_set[1] == 0) ||
368 (priv->ps_mode == IWL_MIMO_PS_STATIC))
369 return 1;
370#else
371 return 1;
372#endif /*CONFIG_IWL4965_HT */
373 return 0;
374}
375
376int iwl4965_hwrate_to_plcp_idx(u32 rate_n_flags) 233int iwl4965_hwrate_to_plcp_idx(u32 rate_n_flags)
377{ 234{
378 int idx = 0; 235 int idx = 0;
@@ -381,8 +238,8 @@ int iwl4965_hwrate_to_plcp_idx(u32 rate_n_flags)
381 if (rate_n_flags & RATE_MCS_HT_MSK) { 238 if (rate_n_flags & RATE_MCS_HT_MSK) {
382 idx = (rate_n_flags & 0xff); 239 idx = (rate_n_flags & 0xff);
383 240
384 if (idx >= IWL_RATE_MIMO_6M_PLCP) 241 if (idx >= IWL_RATE_MIMO2_6M_PLCP)
385 idx = idx - IWL_RATE_MIMO_6M_PLCP; 242 idx = idx - IWL_RATE_MIMO2_6M_PLCP;
386 243
387 idx += IWL_FIRST_OFDM_RATE; 244 idx += IWL_FIRST_OFDM_RATE;
388 /* skip 9M not supported in ht*/ 245 /* skip 9M not supported in ht*/
@@ -410,7 +267,7 @@ void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
410 int rate_index; 267 int rate_index;
411 268
412 control->antenna_sel_tx = 269 control->antenna_sel_tx =
413 ((rate_n_flags & RATE_MCS_ANT_AB_MSK) >> RATE_MCS_ANT_POS); 270 ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
414 if (rate_n_flags & RATE_MCS_HT_MSK) 271 if (rate_n_flags & RATE_MCS_HT_MSK)
415 control->flags |= IEEE80211_TXCTL_OFDM_HT; 272 control->flags |= IEEE80211_TXCTL_OFDM_HT;
416 if (rate_n_flags & RATE_MCS_GF_MSK) 273 if (rate_n_flags & RATE_MCS_GF_MSK)
@@ -431,41 +288,6 @@ void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
431 &priv->bands[IEEE80211_BAND_2GHZ].bitrates[rate_index]; 288 &priv->bands[IEEE80211_BAND_2GHZ].bitrates[rate_index];
432} 289}
433 290
434/*
435 * Determine how many receiver/antenna chains to use.
436 * More provides better reception via diversity. Fewer saves power.
437 * MIMO (dual stream) requires at least 2, but works better with 3.
438 * This does not determine *which* chains to use, just how many.
439 */
440static int iwl4965_get_rx_chain_counter(struct iwl_priv *priv,
441 u8 *idle_state, u8 *rx_state)
442{
443 u8 is_single = is_single_stream(priv);
444 u8 is_cam = test_bit(STATUS_POWER_PMI, &priv->status) ? 0 : 1;
445
446 /* # of Rx chains to use when expecting MIMO. */
447 if (is_single || (!is_cam && (priv->ps_mode == IWL_MIMO_PS_STATIC)))
448 *rx_state = 2;
449 else
450 *rx_state = 3;
451
452 /* # Rx chains when idling and maybe trying to save power */
453 switch (priv->ps_mode) {
454 case IWL_MIMO_PS_STATIC:
455 case IWL_MIMO_PS_DYNAMIC:
456 *idle_state = (is_cam) ? 2 : 1;
457 break;
458 case IWL_MIMO_PS_NONE:
459 *idle_state = (is_cam) ? *rx_state : 1;
460 break;
461 default:
462 *idle_state = 1;
463 break;
464 }
465
466 return 0;
467}
468
469int iwl4965_hw_rxq_stop(struct iwl_priv *priv) 291int iwl4965_hw_rxq_stop(struct iwl_priv *priv)
470{ 292{
471 int rc; 293 int rc;
@@ -491,39 +313,32 @@ int iwl4965_hw_rxq_stop(struct iwl_priv *priv)
491 return 0; 313 return 0;
492} 314}
493 315
494u8 iwl4965_hw_find_station(struct iwl_priv *priv, const u8 *addr) 316/*
317 * EEPROM handlers
318 */
319
320static int iwl4965_eeprom_check_version(struct iwl_priv *priv)
495{ 321{
496 int i; 322 u16 eeprom_ver;
497 int start = 0; 323 u16 calib_ver;
498 int ret = IWL_INVALID_STATION;
499 unsigned long flags;
500 DECLARE_MAC_BUF(mac);
501 324
502 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) || 325 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
503 (priv->iw_mode == IEEE80211_IF_TYPE_AP))
504 start = IWL_STA_ID;
505 326
506 if (is_broadcast_ether_addr(addr)) 327 calib_ver = iwl_eeprom_query16(priv, EEPROM_4965_CALIB_VERSION_OFFSET);
507 return priv->hw_params.bcast_sta_id;
508 328
509 spin_lock_irqsave(&priv->sta_lock, flags); 329 if (eeprom_ver < EEPROM_4965_EEPROM_VERSION ||
510 for (i = start; i < priv->hw_params.max_stations; i++) 330 calib_ver < EEPROM_4965_TX_POWER_VERSION)
511 if ((priv->stations[i].used) && 331 goto err;
512 (!compare_ether_addr
513 (priv->stations[i].sta.sta.addr, addr))) {
514 ret = i;
515 goto out;
516 }
517 332
518 IWL_DEBUG_ASSOC_LIMIT("can not find STA %s total %d\n", 333 return 0;
519 print_mac(mac, addr), priv->num_stations); 334err:
335 IWL_ERROR("Unsuported EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
336 eeprom_ver, EEPROM_4965_EEPROM_VERSION,
337 calib_ver, EEPROM_4965_TX_POWER_VERSION);
338 return -EINVAL;
520 339
521 out:
522 spin_unlock_irqrestore(&priv->sta_lock, flags);
523 return ret;
524} 340}
525 341int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
526static int iwl4965_nic_set_pwr_src(struct iwl_priv *priv, int pwr_max)
527{ 342{
528 int ret; 343 int ret;
529 unsigned long flags; 344 unsigned long flags;
@@ -535,20 +350,21 @@ static int iwl4965_nic_set_pwr_src(struct iwl_priv *priv, int pwr_max)
535 return ret; 350 return ret;
536 } 351 }
537 352
538 if (!pwr_max) { 353 if (src == IWL_PWR_SRC_VAUX) {
539 u32 val; 354 u32 val;
540
541 ret = pci_read_config_dword(priv->pci_dev, PCI_POWER_SOURCE, 355 ret = pci_read_config_dword(priv->pci_dev, PCI_POWER_SOURCE,
542 &val); 356 &val);
543 357
544 if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT) 358 if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT) {
545 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG, 359 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
546 APMG_PS_CTRL_VAL_PWR_SRC_VAUX, 360 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
547 ~APMG_PS_CTRL_MSK_PWR_SRC); 361 ~APMG_PS_CTRL_MSK_PWR_SRC);
548 } else 362 }
363 } else {
549 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG, 364 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
550 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN, 365 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
551 ~APMG_PS_CTRL_MSK_PWR_SRC); 366 ~APMG_PS_CTRL_MSK_PWR_SRC);
367 }
552 368
553 iwl_release_nic_access(priv); 369 iwl_release_nic_access(priv);
554 spin_unlock_irqrestore(&priv->lock, flags); 370 spin_unlock_irqrestore(&priv->lock, flags);
@@ -619,7 +435,7 @@ static int iwl4965_kw_init(struct iwl_priv *priv)
619 if (rc) 435 if (rc)
620 goto out; 436 goto out;
621 437
622 iwl_write_direct32(priv, IWL_FH_KW_MEM_ADDR_REG, 438 iwl_write_direct32(priv, FH_KW_MEM_ADDR_REG,
623 priv->kw.dma_addr >> 4); 439 priv->kw.dma_addr >> 4);
624 iwl_release_nic_access(priv); 440 iwl_release_nic_access(priv);
625out: 441out:
@@ -722,116 +538,115 @@ static int iwl4965_txq_ctx_reset(struct iwl_priv *priv)
722 error_kw: 538 error_kw:
723 return rc; 539 return rc;
724} 540}
725 541static int iwl4965_apm_init(struct iwl_priv *priv)
726int iwl4965_hw_nic_init(struct iwl_priv *priv)
727{ 542{
728 int rc;
729 unsigned long flags; 543 unsigned long flags;
730 struct iwl4965_rx_queue *rxq = &priv->rxq; 544 int ret = 0;
731 u8 rev_id;
732 u32 val;
733 u8 val_link;
734
735 iwl4965_power_init_handle(priv);
736 545
737 /* nic_init */
738 spin_lock_irqsave(&priv->lock, flags); 546 spin_lock_irqsave(&priv->lock, flags);
739
740 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS, 547 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
741 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); 548 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
742 549
550 /* set "initialization complete" bit to move adapter
551 * D0U* --> D0A* state */
743 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); 552 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
744 rc = iwl_poll_bit(priv, CSR_GP_CNTRL,
745 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
746 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
747 if (rc < 0) {
748 spin_unlock_irqrestore(&priv->lock, flags);
749 IWL_DEBUG_INFO("Failed to init the card\n");
750 return rc;
751 }
752 553
753 rc = iwl_grab_nic_access(priv); 554 /* wait for clock stabilization */
754 if (rc) { 555 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
755 spin_unlock_irqrestore(&priv->lock, flags); 556 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
756 return rc; 557 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
558 if (ret < 0) {
559 IWL_DEBUG_INFO("Failed to init the card\n");
560 goto out;
757 } 561 }
758 562
759 iwl_read_prph(priv, APMG_CLK_CTRL_REG); 563 ret = iwl_grab_nic_access(priv);
564 if (ret)
565 goto out;
760 566
567 /* enable DMA */
761 iwl_write_prph(priv, APMG_CLK_CTRL_REG, 568 iwl_write_prph(priv, APMG_CLK_CTRL_REG,
762 APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT); 569 APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT);
763 iwl_read_prph(priv, APMG_CLK_CTRL_REG);
764 570
765 udelay(20); 571 udelay(20);
766 572
767 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG, 573 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
768 APMG_PCIDEV_STT_VAL_L1_ACT_DIS); 574 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
769 575
770 iwl_release_nic_access(priv); 576 iwl_release_nic_access(priv);
771 iwl_write32(priv, CSR_INT_COALESCING, 512 / 32); 577out:
772 spin_unlock_irqrestore(&priv->lock, flags); 578 spin_unlock_irqrestore(&priv->lock, flags);
579 return ret;
580}
773 581
774 /* Determine HW type */
775 rc = pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &rev_id);
776 if (rc)
777 return rc;
778 582
779 IWL_DEBUG_INFO("HW Revision ID = 0x%X\n", rev_id); 583static void iwl4965_nic_config(struct iwl_priv *priv)
584{
585 unsigned long flags;
586 u32 val;
587 u16 radio_cfg;
588 u8 val_link;
780 589
781 iwl4965_nic_set_pwr_src(priv, 1);
782 spin_lock_irqsave(&priv->lock, flags); 590 spin_lock_irqsave(&priv->lock, flags);
783 591
784 if ((rev_id & 0x80) == 0x80 && (rev_id & 0x7f) < 8) { 592 if ((priv->rev_id & 0x80) == 0x80 && (priv->rev_id & 0x7f) < 8) {
785 pci_read_config_dword(priv->pci_dev, PCI_REG_WUM8, &val); 593 pci_read_config_dword(priv->pci_dev, PCI_REG_WUM8, &val);
786 /* Enable No Snoop field */ 594 /* Enable No Snoop field */
787 pci_write_config_dword(priv->pci_dev, PCI_REG_WUM8, 595 pci_write_config_dword(priv->pci_dev, PCI_REG_WUM8,
788 val & ~(1 << 11)); 596 val & ~(1 << 11));
789 } 597 }
790 598
791 spin_unlock_irqrestore(&priv->lock, flags);
792
793 if (priv->eeprom.calib_version < EEPROM_TX_POWER_VERSION_NEW) {
794 IWL_ERROR("Older EEPROM detected! Aborting.\n");
795 return -EINVAL;
796 }
797
798 pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link); 599 pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link);
799 600
800 /* disable L1 entry -- workaround for pre-B1 */ 601 /* disable L1 entry -- workaround for pre-B1 */
801 pci_write_config_byte(priv->pci_dev, PCI_LINK_CTRL, val_link & ~0x02); 602 pci_write_config_byte(priv->pci_dev, PCI_LINK_CTRL, val_link & ~0x02);
802 603
803 spin_lock_irqsave(&priv->lock, flags); 604 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
804 605
805 /* set CSR_HW_CONFIG_REG for uCode use */ 606 /* write radio config values to register */
607 if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) == EEPROM_4965_RF_CFG_TYPE_MAX)
608 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
609 EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
610 EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
611 EEPROM_RF_CFG_DASH_MSK(radio_cfg));
806 612
613 /* set CSR_HW_CONFIG_REG for uCode use */
807 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG, 614 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
808 CSR49_HW_IF_CONFIG_REG_BIT_4965_R | 615 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
809 CSR49_HW_IF_CONFIG_REG_BIT_RADIO_SI | 616 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
810 CSR49_HW_IF_CONFIG_REG_BIT_MAC_SI);
811 617
812 rc = iwl_grab_nic_access(priv); 618 priv->calib_info = (struct iwl_eeprom_calib_info *)
813 if (rc < 0) { 619 iwl_eeprom_query_addr(priv, EEPROM_4965_CALIB_TXPOWER_OFFSET);
814 spin_unlock_irqrestore(&priv->lock, flags);
815 IWL_DEBUG_INFO("Failed to init the card\n");
816 return rc;
817 }
818 620
819 iwl_read_prph(priv, APMG_PS_CTRL_REG); 621 spin_unlock_irqrestore(&priv->lock, flags);
820 iwl_set_bits_prph(priv, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_RESET_REQ); 622}
821 udelay(5);
822 iwl_clear_bits_prph(priv, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_RESET_REQ);
823 623
824 iwl_release_nic_access(priv); 624
625int iwl4965_hw_nic_init(struct iwl_priv *priv)
626{
627 unsigned long flags;
628 struct iwl4965_rx_queue *rxq = &priv->rxq;
629 int ret;
630
631 /* nic_init */
632 priv->cfg->ops->lib->apm_ops.init(priv);
633
634 spin_lock_irqsave(&priv->lock, flags);
635 iwl_write32(priv, CSR_INT_COALESCING, 512 / 32);
825 spin_unlock_irqrestore(&priv->lock, flags); 636 spin_unlock_irqrestore(&priv->lock, flags);
826 637
638 ret = priv->cfg->ops->lib->apm_ops.set_pwr_src(priv, IWL_PWR_SRC_VMAIN);
639
640 priv->cfg->ops->lib->apm_ops.config(priv);
641
827 iwl4965_hw_card_show_info(priv); 642 iwl4965_hw_card_show_info(priv);
828 643
829 /* end nic_init */ 644 /* end nic_init */
830 645
831 /* Allocate the RX queue, or reset if it is already allocated */ 646 /* Allocate the RX queue, or reset if it is already allocated */
832 if (!rxq->bd) { 647 if (!rxq->bd) {
833 rc = iwl4965_rx_queue_alloc(priv); 648 ret = iwl4965_rx_queue_alloc(priv);
834 if (rc) { 649 if (ret) {
835 IWL_ERROR("Unable to initialize Rx queue\n"); 650 IWL_ERROR("Unable to initialize Rx queue\n");
836 return -ENOMEM; 651 return -ENOMEM;
837 } 652 }
@@ -850,15 +665,9 @@ int iwl4965_hw_nic_init(struct iwl_priv *priv)
850 spin_unlock_irqrestore(&priv->lock, flags); 665 spin_unlock_irqrestore(&priv->lock, flags);
851 666
852 /* Allocate and init all Tx and Command queues */ 667 /* Allocate and init all Tx and Command queues */
853 rc = iwl4965_txq_ctx_reset(priv); 668 ret = iwl4965_txq_ctx_reset(priv);
854 if (rc) 669 if (ret)
855 return rc; 670 return ret;
856
857 if (priv->eeprom.sku_cap & EEPROM_SKU_CAP_SW_RF_KILL_ENABLE)
858 IWL_DEBUG_RF_KILL("SW RF KILL supported in EEPROM.\n");
859
860 if (priv->eeprom.sku_cap & EEPROM_SKU_CAP_HW_RF_KILL_ENABLE)
861 IWL_DEBUG_RF_KILL("HW RF KILL supported in EEPROM.\n");
862 671
863 set_bit(STATUS_INIT, &priv->status); 672 set_bit(STATUS_INIT, &priv->status);
864 673
@@ -916,9 +725,9 @@ void iwl4965_hw_txq_ctx_stop(struct iwl_priv *priv)
916 } 725 }
917 726
918 iwl_write_direct32(priv, 727 iwl_write_direct32(priv,
919 IWL_FH_TCSR_CHNL_TX_CONFIG_REG(txq_id), 0x0); 728 FH_TCSR_CHNL_TX_CONFIG_REG(txq_id), 0x0);
920 iwl_poll_direct_bit(priv, IWL_FH_TSSR_TX_STATUS_REG, 729 iwl_poll_direct_bit(priv, FH_TSSR_TX_STATUS_REG,
921 IWL_FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE 730 FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE
922 (txq_id), 200); 731 (txq_id), 200);
923 iwl_release_nic_access(priv); 732 iwl_release_nic_access(priv);
924 spin_unlock_irqrestore(&priv->lock, flags); 733 spin_unlock_irqrestore(&priv->lock, flags);
@@ -993,15 +802,9 @@ static void iwl4965_bg_statistics_periodic(unsigned long data)
993 iwl_send_statistics_request(priv, CMD_ASYNC); 802 iwl_send_statistics_request(priv, CMD_ASYNC);
994} 803}
995 804
996#define CT_LIMIT_CONST 259
997#define TM_CT_KILL_THRESHOLD 110
998
999void iwl4965_rf_kill_ct_config(struct iwl_priv *priv) 805void iwl4965_rf_kill_ct_config(struct iwl_priv *priv)
1000{ 806{
1001 struct iwl4965_ct_kill_config cmd; 807 struct iwl4965_ct_kill_config cmd;
1002 u32 R1, R2, R3;
1003 u32 temp_th;
1004 u32 crit_temperature;
1005 unsigned long flags; 808 unsigned long flags;
1006 int ret = 0; 809 int ret = 0;
1007 810
@@ -1010,440 +813,28 @@ void iwl4965_rf_kill_ct_config(struct iwl_priv *priv)
1010 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); 813 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
1011 spin_unlock_irqrestore(&priv->lock, flags); 814 spin_unlock_irqrestore(&priv->lock, flags);
1012 815
1013 if (priv->statistics.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK) { 816 cmd.critical_temperature_R =
1014 R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[1]); 817 cpu_to_le32(priv->hw_params.ct_kill_threshold);
1015 R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[1]);
1016 R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[1]);
1017 } else {
1018 R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[0]);
1019 R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[0]);
1020 R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[0]);
1021 }
1022
1023 temp_th = CELSIUS_TO_KELVIN(TM_CT_KILL_THRESHOLD);
1024 818
1025 crit_temperature = ((temp_th * (R3-R1))/CT_LIMIT_CONST) + R2;
1026 cmd.critical_temperature_R = cpu_to_le32(crit_temperature);
1027 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD, 819 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
1028 sizeof(cmd), &cmd); 820 sizeof(cmd), &cmd);
1029 if (ret) 821 if (ret)
1030 IWL_ERROR("REPLY_CT_KILL_CONFIG_CMD failed\n"); 822 IWL_ERROR("REPLY_CT_KILL_CONFIG_CMD failed\n");
1031 else 823 else
1032 IWL_DEBUG_INFO("REPLY_CT_KILL_CONFIG_CMD succeeded\n"); 824 IWL_DEBUG_INFO("REPLY_CT_KILL_CONFIG_CMD succeeded, "
1033} 825 "critical temperature is %d\n",
1034 826 cmd.critical_temperature_R);
1035#ifdef CONFIG_IWL4965_SENSITIVITY
1036
1037/* "false alarms" are signals that our DSP tries to lock onto,
1038 * but then determines that they are either noise, or transmissions
1039 * from a distant wireless network (also "noise", really) that get
1040 * "stepped on" by stronger transmissions within our own network.
1041 * This algorithm attempts to set a sensitivity level that is high
1042 * enough to receive all of our own network traffic, but not so
1043 * high that our DSP gets too busy trying to lock onto non-network
1044 * activity/noise. */
1045static int iwl4965_sens_energy_cck(struct iwl_priv *priv,
1046 u32 norm_fa,
1047 u32 rx_enable_time,
1048 struct statistics_general_data *rx_info)
1049{
1050 u32 max_nrg_cck = 0;
1051 int i = 0;
1052 u8 max_silence_rssi = 0;
1053 u32 silence_ref = 0;
1054 u8 silence_rssi_a = 0;
1055 u8 silence_rssi_b = 0;
1056 u8 silence_rssi_c = 0;
1057 u32 val;
1058
1059 /* "false_alarms" values below are cross-multiplications to assess the
1060 * numbers of false alarms within the measured period of actual Rx
1061 * (Rx is off when we're txing), vs the min/max expected false alarms
1062 * (some should be expected if rx is sensitive enough) in a
1063 * hypothetical listening period of 200 time units (TU), 204.8 msec:
1064 *
1065 * MIN_FA/fixed-time < false_alarms/actual-rx-time < MAX_FA/beacon-time
1066 *
1067 * */
1068 u32 false_alarms = norm_fa * 200 * 1024;
1069 u32 max_false_alarms = MAX_FA_CCK * rx_enable_time;
1070 u32 min_false_alarms = MIN_FA_CCK * rx_enable_time;
1071 struct iwl4965_sensitivity_data *data = NULL;
1072
1073 data = &(priv->sensitivity_data);
1074
1075 data->nrg_auto_corr_silence_diff = 0;
1076
1077 /* Find max silence rssi among all 3 receivers.
1078 * This is background noise, which may include transmissions from other
1079 * networks, measured during silence before our network's beacon */
1080 silence_rssi_a = (u8)((rx_info->beacon_silence_rssi_a &
1081 ALL_BAND_FILTER) >> 8);
1082 silence_rssi_b = (u8)((rx_info->beacon_silence_rssi_b &
1083 ALL_BAND_FILTER) >> 8);
1084 silence_rssi_c = (u8)((rx_info->beacon_silence_rssi_c &
1085 ALL_BAND_FILTER) >> 8);
1086
1087 val = max(silence_rssi_b, silence_rssi_c);
1088 max_silence_rssi = max(silence_rssi_a, (u8) val);
1089
1090 /* Store silence rssi in 20-beacon history table */
1091 data->nrg_silence_rssi[data->nrg_silence_idx] = max_silence_rssi;
1092 data->nrg_silence_idx++;
1093 if (data->nrg_silence_idx >= NRG_NUM_PREV_STAT_L)
1094 data->nrg_silence_idx = 0;
1095
1096 /* Find max silence rssi across 20 beacon history */
1097 for (i = 0; i < NRG_NUM_PREV_STAT_L; i++) {
1098 val = data->nrg_silence_rssi[i];
1099 silence_ref = max(silence_ref, val);
1100 }
1101 IWL_DEBUG_CALIB("silence a %u, b %u, c %u, 20-bcn max %u\n",
1102 silence_rssi_a, silence_rssi_b, silence_rssi_c,
1103 silence_ref);
1104
1105 /* Find max rx energy (min value!) among all 3 receivers,
1106 * measured during beacon frame.
1107 * Save it in 10-beacon history table. */
1108 i = data->nrg_energy_idx;
1109 val = min(rx_info->beacon_energy_b, rx_info->beacon_energy_c);
1110 data->nrg_value[i] = min(rx_info->beacon_energy_a, val);
1111
1112 data->nrg_energy_idx++;
1113 if (data->nrg_energy_idx >= 10)
1114 data->nrg_energy_idx = 0;
1115
1116 /* Find min rx energy (max value) across 10 beacon history.
1117 * This is the minimum signal level that we want to receive well.
1118 * Add backoff (margin so we don't miss slightly lower energy frames).
1119 * This establishes an upper bound (min value) for energy threshold. */
1120 max_nrg_cck = data->nrg_value[0];
1121 for (i = 1; i < 10; i++)
1122 max_nrg_cck = (u32) max(max_nrg_cck, (data->nrg_value[i]));
1123 max_nrg_cck += 6;
1124
1125 IWL_DEBUG_CALIB("rx energy a %u, b %u, c %u, 10-bcn max/min %u\n",
1126 rx_info->beacon_energy_a, rx_info->beacon_energy_b,
1127 rx_info->beacon_energy_c, max_nrg_cck - 6);
1128
1129 /* Count number of consecutive beacons with fewer-than-desired
1130 * false alarms. */
1131 if (false_alarms < min_false_alarms)
1132 data->num_in_cck_no_fa++;
1133 else
1134 data->num_in_cck_no_fa = 0;
1135 IWL_DEBUG_CALIB("consecutive bcns with few false alarms = %u\n",
1136 data->num_in_cck_no_fa);
1137
1138 /* If we got too many false alarms this time, reduce sensitivity */
1139 if (false_alarms > max_false_alarms) {
1140 IWL_DEBUG_CALIB("norm FA %u > max FA %u\n",
1141 false_alarms, max_false_alarms);
1142 IWL_DEBUG_CALIB("... reducing sensitivity\n");
1143 data->nrg_curr_state = IWL_FA_TOO_MANY;
1144
1145 if (data->auto_corr_cck > AUTO_CORR_MAX_TH_CCK) {
1146 /* Store for "fewer than desired" on later beacon */
1147 data->nrg_silence_ref = silence_ref;
1148
1149 /* increase energy threshold (reduce nrg value)
1150 * to decrease sensitivity */
1151 if (data->nrg_th_cck > (NRG_MAX_CCK + NRG_STEP_CCK))
1152 data->nrg_th_cck = data->nrg_th_cck
1153 - NRG_STEP_CCK;
1154 }
1155
1156 /* increase auto_corr values to decrease sensitivity */
1157 if (data->auto_corr_cck < AUTO_CORR_MAX_TH_CCK)
1158 data->auto_corr_cck = AUTO_CORR_MAX_TH_CCK + 1;
1159 else {
1160 val = data->auto_corr_cck + AUTO_CORR_STEP_CCK;
1161 data->auto_corr_cck = min((u32)AUTO_CORR_MAX_CCK, val);
1162 }
1163 val = data->auto_corr_cck_mrc + AUTO_CORR_STEP_CCK;
1164 data->auto_corr_cck_mrc = min((u32)AUTO_CORR_MAX_CCK_MRC, val);
1165
1166 /* Else if we got fewer than desired, increase sensitivity */
1167 } else if (false_alarms < min_false_alarms) {
1168 data->nrg_curr_state = IWL_FA_TOO_FEW;
1169
1170 /* Compare silence level with silence level for most recent
1171 * healthy number or too many false alarms */
1172 data->nrg_auto_corr_silence_diff = (s32)data->nrg_silence_ref -
1173 (s32)silence_ref;
1174
1175 IWL_DEBUG_CALIB("norm FA %u < min FA %u, silence diff %d\n",
1176 false_alarms, min_false_alarms,
1177 data->nrg_auto_corr_silence_diff);
1178
1179 /* Increase value to increase sensitivity, but only if:
1180 * 1a) previous beacon did *not* have *too many* false alarms
1181 * 1b) AND there's a significant difference in Rx levels
1182 * from a previous beacon with too many, or healthy # FAs
1183 * OR 2) We've seen a lot of beacons (100) with too few
1184 * false alarms */
1185 if ((data->nrg_prev_state != IWL_FA_TOO_MANY) &&
1186 ((data->nrg_auto_corr_silence_diff > NRG_DIFF) ||
1187 (data->num_in_cck_no_fa > MAX_NUMBER_CCK_NO_FA))) {
1188
1189 IWL_DEBUG_CALIB("... increasing sensitivity\n");
1190 /* Increase nrg value to increase sensitivity */
1191 val = data->nrg_th_cck + NRG_STEP_CCK;
1192 data->nrg_th_cck = min((u32)NRG_MIN_CCK, val);
1193
1194 /* Decrease auto_corr values to increase sensitivity */
1195 val = data->auto_corr_cck - AUTO_CORR_STEP_CCK;
1196 data->auto_corr_cck = max((u32)AUTO_CORR_MIN_CCK, val);
1197
1198 val = data->auto_corr_cck_mrc - AUTO_CORR_STEP_CCK;
1199 data->auto_corr_cck_mrc =
1200 max((u32)AUTO_CORR_MIN_CCK_MRC, val);
1201
1202 } else
1203 IWL_DEBUG_CALIB("... but not changing sensitivity\n");
1204
1205 /* Else we got a healthy number of false alarms, keep status quo */
1206 } else {
1207 IWL_DEBUG_CALIB(" FA in safe zone\n");
1208 data->nrg_curr_state = IWL_FA_GOOD_RANGE;
1209
1210 /* Store for use in "fewer than desired" with later beacon */
1211 data->nrg_silence_ref = silence_ref;
1212
1213 /* If previous beacon had too many false alarms,
1214 * give it some extra margin by reducing sensitivity again
1215 * (but don't go below measured energy of desired Rx) */
1216 if (IWL_FA_TOO_MANY == data->nrg_prev_state) {
1217 IWL_DEBUG_CALIB("... increasing margin\n");
1218 data->nrg_th_cck -= NRG_MARGIN;
1219 }
1220 }
1221
1222 /* Make sure the energy threshold does not go above the measured
1223 * energy of the desired Rx signals (reduced by backoff margin),
1224 * or else we might start missing Rx frames.
1225 * Lower value is higher energy, so we use max()!
1226 */
1227 data->nrg_th_cck = max(max_nrg_cck, data->nrg_th_cck);
1228 IWL_DEBUG_CALIB("new nrg_th_cck %u\n", data->nrg_th_cck);
1229
1230 data->nrg_prev_state = data->nrg_curr_state;
1231
1232 return 0;
1233}
1234
1235
1236static int iwl4965_sens_auto_corr_ofdm(struct iwl_priv *priv,
1237 u32 norm_fa,
1238 u32 rx_enable_time)
1239{
1240 u32 val;
1241 u32 false_alarms = norm_fa * 200 * 1024;
1242 u32 max_false_alarms = MAX_FA_OFDM * rx_enable_time;
1243 u32 min_false_alarms = MIN_FA_OFDM * rx_enable_time;
1244 struct iwl4965_sensitivity_data *data = NULL;
1245
1246 data = &(priv->sensitivity_data);
1247
1248 /* If we got too many false alarms this time, reduce sensitivity */
1249 if (false_alarms > max_false_alarms) {
1250
1251 IWL_DEBUG_CALIB("norm FA %u > max FA %u)\n",
1252 false_alarms, max_false_alarms);
1253
1254 val = data->auto_corr_ofdm + AUTO_CORR_STEP_OFDM;
1255 data->auto_corr_ofdm =
1256 min((u32)AUTO_CORR_MAX_OFDM, val);
1257
1258 val = data->auto_corr_ofdm_mrc + AUTO_CORR_STEP_OFDM;
1259 data->auto_corr_ofdm_mrc =
1260 min((u32)AUTO_CORR_MAX_OFDM_MRC, val);
1261
1262 val = data->auto_corr_ofdm_x1 + AUTO_CORR_STEP_OFDM;
1263 data->auto_corr_ofdm_x1 =
1264 min((u32)AUTO_CORR_MAX_OFDM_X1, val);
1265
1266 val = data->auto_corr_ofdm_mrc_x1 + AUTO_CORR_STEP_OFDM;
1267 data->auto_corr_ofdm_mrc_x1 =
1268 min((u32)AUTO_CORR_MAX_OFDM_MRC_X1, val);
1269 }
1270
1271 /* Else if we got fewer than desired, increase sensitivity */
1272 else if (false_alarms < min_false_alarms) {
1273
1274 IWL_DEBUG_CALIB("norm FA %u < min FA %u\n",
1275 false_alarms, min_false_alarms);
1276
1277 val = data->auto_corr_ofdm - AUTO_CORR_STEP_OFDM;
1278 data->auto_corr_ofdm =
1279 max((u32)AUTO_CORR_MIN_OFDM, val);
1280
1281 val = data->auto_corr_ofdm_mrc - AUTO_CORR_STEP_OFDM;
1282 data->auto_corr_ofdm_mrc =
1283 max((u32)AUTO_CORR_MIN_OFDM_MRC, val);
1284
1285 val = data->auto_corr_ofdm_x1 - AUTO_CORR_STEP_OFDM;
1286 data->auto_corr_ofdm_x1 =
1287 max((u32)AUTO_CORR_MIN_OFDM_X1, val);
1288
1289 val = data->auto_corr_ofdm_mrc_x1 - AUTO_CORR_STEP_OFDM;
1290 data->auto_corr_ofdm_mrc_x1 =
1291 max((u32)AUTO_CORR_MIN_OFDM_MRC_X1, val);
1292 }
1293
1294 else
1295 IWL_DEBUG_CALIB("min FA %u < norm FA %u < max FA %u OK\n",
1296 min_false_alarms, false_alarms, max_false_alarms);
1297
1298 return 0;
1299}
1300
1301static int iwl4965_sensitivity_callback(struct iwl_priv *priv,
1302 struct iwl_cmd *cmd, struct sk_buff *skb)
1303{
1304 /* We didn't cache the SKB; let the caller free it */
1305 return 1;
1306}
1307
1308/* Prepare a SENSITIVITY_CMD, send to uCode if values have changed */
1309static int iwl4965_sensitivity_write(struct iwl_priv *priv, u8 flags)
1310{
1311 struct iwl4965_sensitivity_cmd cmd ;
1312 struct iwl4965_sensitivity_data *data = NULL;
1313 struct iwl_host_cmd cmd_out = {
1314 .id = SENSITIVITY_CMD,
1315 .len = sizeof(struct iwl4965_sensitivity_cmd),
1316 .meta.flags = flags,
1317 .data = &cmd,
1318 };
1319 int ret;
1320
1321 data = &(priv->sensitivity_data);
1322
1323 memset(&cmd, 0, sizeof(cmd));
1324
1325 cmd.table[HD_AUTO_CORR32_X4_TH_ADD_MIN_INDEX] =
1326 cpu_to_le16((u16)data->auto_corr_ofdm);
1327 cmd.table[HD_AUTO_CORR32_X4_TH_ADD_MIN_MRC_INDEX] =
1328 cpu_to_le16((u16)data->auto_corr_ofdm_mrc);
1329 cmd.table[HD_AUTO_CORR32_X1_TH_ADD_MIN_INDEX] =
1330 cpu_to_le16((u16)data->auto_corr_ofdm_x1);
1331 cmd.table[HD_AUTO_CORR32_X1_TH_ADD_MIN_MRC_INDEX] =
1332 cpu_to_le16((u16)data->auto_corr_ofdm_mrc_x1);
1333
1334 cmd.table[HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX] =
1335 cpu_to_le16((u16)data->auto_corr_cck);
1336 cmd.table[HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX] =
1337 cpu_to_le16((u16)data->auto_corr_cck_mrc);
1338
1339 cmd.table[HD_MIN_ENERGY_CCK_DET_INDEX] =
1340 cpu_to_le16((u16)data->nrg_th_cck);
1341 cmd.table[HD_MIN_ENERGY_OFDM_DET_INDEX] =
1342 cpu_to_le16((u16)data->nrg_th_ofdm);
1343
1344 cmd.table[HD_BARKER_CORR_TH_ADD_MIN_INDEX] =
1345 __constant_cpu_to_le16(190);
1346 cmd.table[HD_BARKER_CORR_TH_ADD_MIN_MRC_INDEX] =
1347 __constant_cpu_to_le16(390);
1348 cmd.table[HD_OFDM_ENERGY_TH_IN_INDEX] =
1349 __constant_cpu_to_le16(62);
1350
1351 IWL_DEBUG_CALIB("ofdm: ac %u mrc %u x1 %u mrc_x1 %u thresh %u\n",
1352 data->auto_corr_ofdm, data->auto_corr_ofdm_mrc,
1353 data->auto_corr_ofdm_x1, data->auto_corr_ofdm_mrc_x1,
1354 data->nrg_th_ofdm);
1355
1356 IWL_DEBUG_CALIB("cck: ac %u mrc %u thresh %u\n",
1357 data->auto_corr_cck, data->auto_corr_cck_mrc,
1358 data->nrg_th_cck);
1359
1360 /* Update uCode's "work" table, and copy it to DSP */
1361 cmd.control = SENSITIVITY_CMD_CONTROL_WORK_TABLE;
1362
1363 if (flags & CMD_ASYNC)
1364 cmd_out.meta.u.callback = iwl4965_sensitivity_callback;
1365
1366 /* Don't send command to uCode if nothing has changed */
1367 if (!memcmp(&cmd.table[0], &(priv->sensitivity_tbl[0]),
1368 sizeof(u16)*HD_TABLE_SIZE)) {
1369 IWL_DEBUG_CALIB("No change in SENSITIVITY_CMD\n");
1370 return 0;
1371 }
1372
1373 /* Copy table for comparison next time */
1374 memcpy(&(priv->sensitivity_tbl[0]), &(cmd.table[0]),
1375 sizeof(u16)*HD_TABLE_SIZE);
1376
1377 ret = iwl_send_cmd(priv, &cmd_out);
1378 if (ret)
1379 IWL_ERROR("SENSITIVITY_CMD failed\n");
1380
1381 return ret;
1382}
1383
1384void iwl4965_init_sensitivity(struct iwl_priv *priv, u8 flags, u8 force)
1385{
1386 struct iwl4965_sensitivity_data *data = NULL;
1387 int i;
1388 int ret = 0;
1389
1390 IWL_DEBUG_CALIB("Start iwl4965_init_sensitivity\n");
1391
1392 if (force)
1393 memset(&(priv->sensitivity_tbl[0]), 0,
1394 sizeof(u16)*HD_TABLE_SIZE);
1395
1396 /* Clear driver's sensitivity algo data */
1397 data = &(priv->sensitivity_data);
1398 memset(data, 0, sizeof(struct iwl4965_sensitivity_data));
1399
1400 data->num_in_cck_no_fa = 0;
1401 data->nrg_curr_state = IWL_FA_TOO_MANY;
1402 data->nrg_prev_state = IWL_FA_TOO_MANY;
1403 data->nrg_silence_ref = 0;
1404 data->nrg_silence_idx = 0;
1405 data->nrg_energy_idx = 0;
1406
1407 for (i = 0; i < 10; i++)
1408 data->nrg_value[i] = 0;
1409
1410 for (i = 0; i < NRG_NUM_PREV_STAT_L; i++)
1411 data->nrg_silence_rssi[i] = 0;
1412
1413 data->auto_corr_ofdm = 90;
1414 data->auto_corr_ofdm_mrc = 170;
1415 data->auto_corr_ofdm_x1 = 105;
1416 data->auto_corr_ofdm_mrc_x1 = 220;
1417 data->auto_corr_cck = AUTO_CORR_CCK_MIN_VAL_DEF;
1418 data->auto_corr_cck_mrc = 200;
1419 data->nrg_th_cck = 100;
1420 data->nrg_th_ofdm = 100;
1421
1422 data->last_bad_plcp_cnt_ofdm = 0;
1423 data->last_fa_cnt_ofdm = 0;
1424 data->last_bad_plcp_cnt_cck = 0;
1425 data->last_fa_cnt_cck = 0;
1426
1427 /* Clear prior Sensitivity command data to force send to uCode */
1428 if (force)
1429 memset(&(priv->sensitivity_tbl[0]), 0,
1430 sizeof(u16)*HD_TABLE_SIZE);
1431
1432 ret |= iwl4965_sensitivity_write(priv, flags);
1433 IWL_DEBUG_CALIB("<<return 0x%X\n", ret);
1434
1435 return;
1436} 827}
1437 828
829#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
1438 830
1439/* Reset differential Rx gains in NIC to prepare for chain noise calibration. 831/* Reset differential Rx gains in NIC to prepare for chain noise calibration.
1440 * Called after every association, but this runs only once! 832 * Called after every association, but this runs only once!
1441 * ... once chain noise is calibrated the first time, it's good forever. */ 833 * ... once chain noise is calibrated the first time, it's good forever. */
1442void iwl4965_chain_noise_reset(struct iwl_priv *priv) 834static void iwl4965_chain_noise_reset(struct iwl_priv *priv)
1443{ 835{
1444 struct iwl4965_chain_noise_data *data = NULL; 836 struct iwl_chain_noise_data *data = &(priv->chain_noise_data);
1445 837
1446 data = &(priv->chain_noise_data);
1447 if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) { 838 if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
1448 struct iwl4965_calibration_cmd cmd; 839 struct iwl4965_calibration_cmd cmd;
1449 840
@@ -1452,357 +843,76 @@ void iwl4965_chain_noise_reset(struct iwl_priv *priv)
1452 cmd.diff_gain_a = 0; 843 cmd.diff_gain_a = 0;
1453 cmd.diff_gain_b = 0; 844 cmd.diff_gain_b = 0;
1454 cmd.diff_gain_c = 0; 845 cmd.diff_gain_c = 0;
1455 iwl_send_cmd_pdu_async(priv, REPLY_PHY_CALIBRATION_CMD, 846 if (iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
1456 sizeof(cmd), &cmd, NULL); 847 sizeof(cmd), &cmd))
1457 msleep(4); 848 IWL_ERROR("Could not send REPLY_PHY_CALIBRATION_CMD\n");
1458 data->state = IWL_CHAIN_NOISE_ACCUMULATE; 849 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
1459 IWL_DEBUG_CALIB("Run chain_noise_calibrate\n"); 850 IWL_DEBUG_CALIB("Run chain_noise_calibrate\n");
1460 } 851 }
1461 return;
1462} 852}
1463 853
1464/* 854static void iwl4965_gain_computation(struct iwl_priv *priv,
1465 * Accumulate 20 beacons of signal and noise statistics for each of 855 u32 *average_noise,
1466 * 3 receivers/antennas/rx-chains, then figure out: 856 u16 min_average_noise_antenna_i,
1467 * 1) Which antennas are connected. 857 u32 min_average_noise)
1468 * 2) Differential rx gain settings to balance the 3 receivers.
1469 */
1470static void iwl4965_noise_calibration(struct iwl_priv *priv,
1471 struct iwl4965_notif_statistics *stat_resp)
1472{ 858{
1473 struct iwl4965_chain_noise_data *data = NULL; 859 int i, ret;
1474 int ret = 0; 860 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
1475
1476 u32 chain_noise_a;
1477 u32 chain_noise_b;
1478 u32 chain_noise_c;
1479 u32 chain_sig_a;
1480 u32 chain_sig_b;
1481 u32 chain_sig_c;
1482 u32 average_sig[NUM_RX_CHAINS] = {INITIALIZATION_VALUE};
1483 u32 average_noise[NUM_RX_CHAINS] = {INITIALIZATION_VALUE};
1484 u32 max_average_sig;
1485 u16 max_average_sig_antenna_i;
1486 u32 min_average_noise = MIN_AVERAGE_NOISE_MAX_VALUE;
1487 u16 min_average_noise_antenna_i = INITIALIZATION_VALUE;
1488 u16 i = 0;
1489 u16 chan_num = INITIALIZATION_VALUE;
1490 u32 band = INITIALIZATION_VALUE;
1491 u32 active_chains = 0;
1492 unsigned long flags;
1493 struct statistics_rx_non_phy *rx_info = &(stat_resp->rx.general);
1494
1495 data = &(priv->chain_noise_data);
1496
1497 /* Accumulate just the first 20 beacons after the first association,
1498 * then we're done forever. */
1499 if (data->state != IWL_CHAIN_NOISE_ACCUMULATE) {
1500 if (data->state == IWL_CHAIN_NOISE_ALIVE)
1501 IWL_DEBUG_CALIB("Wait for noise calib reset\n");
1502 return;
1503 }
1504
1505 spin_lock_irqsave(&priv->lock, flags);
1506 if (rx_info->interference_data_flag != INTERFERENCE_DATA_AVAILABLE) {
1507 IWL_DEBUG_CALIB(" << Interference data unavailable\n");
1508 spin_unlock_irqrestore(&priv->lock, flags);
1509 return;
1510 }
1511
1512 band = (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) ? 0 : 1;
1513 chan_num = le16_to_cpu(priv->staging_rxon.channel);
1514
1515 /* Make sure we accumulate data for just the associated channel
1516 * (even if scanning). */
1517 if ((chan_num != (le32_to_cpu(stat_resp->flag) >> 16)) ||
1518 ((STATISTICS_REPLY_FLG_BAND_24G_MSK ==
1519 (stat_resp->flag & STATISTICS_REPLY_FLG_BAND_24G_MSK)) && band)) {
1520 IWL_DEBUG_CALIB("Stats not from chan=%d, band=%d\n",
1521 chan_num, band);
1522 spin_unlock_irqrestore(&priv->lock, flags);
1523 return;
1524 }
1525
1526 /* Accumulate beacon statistics values across 20 beacons */
1527 chain_noise_a = le32_to_cpu(rx_info->beacon_silence_rssi_a) &
1528 IN_BAND_FILTER;
1529 chain_noise_b = le32_to_cpu(rx_info->beacon_silence_rssi_b) &
1530 IN_BAND_FILTER;
1531 chain_noise_c = le32_to_cpu(rx_info->beacon_silence_rssi_c) &
1532 IN_BAND_FILTER;
1533
1534 chain_sig_a = le32_to_cpu(rx_info->beacon_rssi_a) & IN_BAND_FILTER;
1535 chain_sig_b = le32_to_cpu(rx_info->beacon_rssi_b) & IN_BAND_FILTER;
1536 chain_sig_c = le32_to_cpu(rx_info->beacon_rssi_c) & IN_BAND_FILTER;
1537
1538 spin_unlock_irqrestore(&priv->lock, flags);
1539
1540 data->beacon_count++;
1541
1542 data->chain_noise_a = (chain_noise_a + data->chain_noise_a);
1543 data->chain_noise_b = (chain_noise_b + data->chain_noise_b);
1544 data->chain_noise_c = (chain_noise_c + data->chain_noise_c);
1545
1546 data->chain_signal_a = (chain_sig_a + data->chain_signal_a);
1547 data->chain_signal_b = (chain_sig_b + data->chain_signal_b);
1548 data->chain_signal_c = (chain_sig_c + data->chain_signal_c);
1549
1550 IWL_DEBUG_CALIB("chan=%d, band=%d, beacon=%d\n", chan_num, band,
1551 data->beacon_count);
1552 IWL_DEBUG_CALIB("chain_sig: a %d b %d c %d\n",
1553 chain_sig_a, chain_sig_b, chain_sig_c);
1554 IWL_DEBUG_CALIB("chain_noise: a %d b %d c %d\n",
1555 chain_noise_a, chain_noise_b, chain_noise_c);
1556
1557 /* If this is the 20th beacon, determine:
1558 * 1) Disconnected antennas (using signal strengths)
1559 * 2) Differential gain (using silence noise) to balance receivers */
1560 if (data->beacon_count == CAL_NUM_OF_BEACONS) {
1561
1562 /* Analyze signal for disconnected antenna */
1563 average_sig[0] = (data->chain_signal_a) / CAL_NUM_OF_BEACONS;
1564 average_sig[1] = (data->chain_signal_b) / CAL_NUM_OF_BEACONS;
1565 average_sig[2] = (data->chain_signal_c) / CAL_NUM_OF_BEACONS;
1566
1567 if (average_sig[0] >= average_sig[1]) {
1568 max_average_sig = average_sig[0];
1569 max_average_sig_antenna_i = 0;
1570 active_chains = (1 << max_average_sig_antenna_i);
1571 } else {
1572 max_average_sig = average_sig[1];
1573 max_average_sig_antenna_i = 1;
1574 active_chains = (1 << max_average_sig_antenna_i);
1575 }
1576
1577 if (average_sig[2] >= max_average_sig) {
1578 max_average_sig = average_sig[2];
1579 max_average_sig_antenna_i = 2;
1580 active_chains = (1 << max_average_sig_antenna_i);
1581 }
1582
1583 IWL_DEBUG_CALIB("average_sig: a %d b %d c %d\n",
1584 average_sig[0], average_sig[1], average_sig[2]);
1585 IWL_DEBUG_CALIB("max_average_sig = %d, antenna %d\n",
1586 max_average_sig, max_average_sig_antenna_i);
1587
1588 /* Compare signal strengths for all 3 receivers. */
1589 for (i = 0; i < NUM_RX_CHAINS; i++) {
1590 if (i != max_average_sig_antenna_i) {
1591 s32 rssi_delta = (max_average_sig -
1592 average_sig[i]);
1593
1594 /* If signal is very weak, compared with
1595 * strongest, mark it as disconnected. */
1596 if (rssi_delta > MAXIMUM_ALLOWED_PATHLOSS)
1597 data->disconn_array[i] = 1;
1598 else
1599 active_chains |= (1 << i);
1600 IWL_DEBUG_CALIB("i = %d rssiDelta = %d "
1601 "disconn_array[i] = %d\n",
1602 i, rssi_delta, data->disconn_array[i]);
1603 }
1604 }
1605
1606 /*If both chains A & B are disconnected -
1607 * connect B and leave A as is */
1608 if (data->disconn_array[CHAIN_A] &&
1609 data->disconn_array[CHAIN_B]) {
1610 data->disconn_array[CHAIN_B] = 0;
1611 active_chains |= (1 << CHAIN_B);
1612 IWL_DEBUG_CALIB("both A & B chains are disconnected! "
1613 "W/A - declare B as connected\n");
1614 }
1615
1616 IWL_DEBUG_CALIB("active_chains (bitwise) = 0x%x\n",
1617 active_chains);
1618
1619 /* Save for use within RXON, TX, SCAN commands, etc. */
1620 priv->valid_antenna = active_chains;
1621
1622 /* Analyze noise for rx balance */
1623 average_noise[0] = ((data->chain_noise_a)/CAL_NUM_OF_BEACONS);
1624 average_noise[1] = ((data->chain_noise_b)/CAL_NUM_OF_BEACONS);
1625 average_noise[2] = ((data->chain_noise_c)/CAL_NUM_OF_BEACONS);
1626
1627 for (i = 0; i < NUM_RX_CHAINS; i++) {
1628 if (!(data->disconn_array[i]) &&
1629 (average_noise[i] <= min_average_noise)) {
1630 /* This means that chain i is active and has
1631 * lower noise values so far: */
1632 min_average_noise = average_noise[i];
1633 min_average_noise_antenna_i = i;
1634 }
1635 }
1636
1637 data->delta_gain_code[min_average_noise_antenna_i] = 0;
1638 861
1639 IWL_DEBUG_CALIB("average_noise: a %d b %d c %d\n", 862 data->delta_gain_code[min_average_noise_antenna_i] = 0;
1640 average_noise[0], average_noise[1],
1641 average_noise[2]);
1642 863
1643 IWL_DEBUG_CALIB("min_average_noise = %d, antenna %d\n", 864 for (i = 0; i < NUM_RX_CHAINS; i++) {
1644 min_average_noise, min_average_noise_antenna_i); 865 s32 delta_g = 0;
1645 866
1646 for (i = 0; i < NUM_RX_CHAINS; i++) { 867 if (!(data->disconn_array[i]) &&
1647 s32 delta_g = 0; 868 (data->delta_gain_code[i] ==
1648
1649 if (!(data->disconn_array[i]) &&
1650 (data->delta_gain_code[i] ==
1651 CHAIN_NOISE_DELTA_GAIN_INIT_VAL)) { 869 CHAIN_NOISE_DELTA_GAIN_INIT_VAL)) {
1652 delta_g = average_noise[i] - min_average_noise; 870 delta_g = average_noise[i] - min_average_noise;
1653 data->delta_gain_code[i] = (u8)((delta_g * 871 data->delta_gain_code[i] = (u8)((delta_g * 10) / 15);
1654 10) / 15); 872 data->delta_gain_code[i] =
1655 if (CHAIN_NOISE_MAX_DELTA_GAIN_CODE < 873 min(data->delta_gain_code[i],
1656 data->delta_gain_code[i]) 874 (u8) CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
1657 data->delta_gain_code[i] = 875
1658 CHAIN_NOISE_MAX_DELTA_GAIN_CODE; 876 data->delta_gain_code[i] =
1659 877 (data->delta_gain_code[i] | (1 << 2));
1660 data->delta_gain_code[i] = 878 } else {
1661 (data->delta_gain_code[i] | (1 << 2)); 879 data->delta_gain_code[i] = 0;
1662 } else
1663 data->delta_gain_code[i] = 0;
1664 }
1665 IWL_DEBUG_CALIB("delta_gain_codes: a %d b %d c %d\n",
1666 data->delta_gain_code[0],
1667 data->delta_gain_code[1],
1668 data->delta_gain_code[2]);
1669
1670 /* Differential gain gets sent to uCode only once */
1671 if (!data->radio_write) {
1672 struct iwl4965_calibration_cmd cmd;
1673 data->radio_write = 1;
1674
1675 memset(&cmd, 0, sizeof(cmd));
1676 cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD;
1677 cmd.diff_gain_a = data->delta_gain_code[0];
1678 cmd.diff_gain_b = data->delta_gain_code[1];
1679 cmd.diff_gain_c = data->delta_gain_code[2];
1680 ret = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
1681 sizeof(cmd), &cmd);
1682 if (ret)
1683 IWL_DEBUG_CALIB("fail sending cmd "
1684 "REPLY_PHY_CALIBRATION_CMD \n");
1685
1686 /* TODO we might want recalculate
1687 * rx_chain in rxon cmd */
1688
1689 /* Mark so we run this algo only once! */
1690 data->state = IWL_CHAIN_NOISE_CALIBRATED;
1691 } 880 }
1692 data->chain_noise_a = 0;
1693 data->chain_noise_b = 0;
1694 data->chain_noise_c = 0;
1695 data->chain_signal_a = 0;
1696 data->chain_signal_b = 0;
1697 data->chain_signal_c = 0;
1698 data->beacon_count = 0;
1699 }
1700 return;
1701}
1702
1703static void iwl4965_sensitivity_calibration(struct iwl_priv *priv,
1704 struct iwl4965_notif_statistics *resp)
1705{
1706 u32 rx_enable_time;
1707 u32 fa_cck;
1708 u32 fa_ofdm;
1709 u32 bad_plcp_cck;
1710 u32 bad_plcp_ofdm;
1711 u32 norm_fa_ofdm;
1712 u32 norm_fa_cck;
1713 struct iwl4965_sensitivity_data *data = NULL;
1714 struct statistics_rx_non_phy *rx_info = &(resp->rx.general);
1715 struct statistics_rx *statistics = &(resp->rx);
1716 unsigned long flags;
1717 struct statistics_general_data statis;
1718 int ret;
1719
1720 data = &(priv->sensitivity_data);
1721
1722 if (!iwl_is_associated(priv)) {
1723 IWL_DEBUG_CALIB("<< - not associated\n");
1724 return;
1725 } 881 }
882 IWL_DEBUG_CALIB("delta_gain_codes: a %d b %d c %d\n",
883 data->delta_gain_code[0],
884 data->delta_gain_code[1],
885 data->delta_gain_code[2]);
1726 886
1727 spin_lock_irqsave(&priv->lock, flags); 887 /* Differential gain gets sent to uCode only once */
1728 if (rx_info->interference_data_flag != INTERFERENCE_DATA_AVAILABLE) { 888 if (!data->radio_write) {
1729 IWL_DEBUG_CALIB("<< invalid data.\n"); 889 struct iwl4965_calibration_cmd cmd;
1730 spin_unlock_irqrestore(&priv->lock, flags); 890 data->radio_write = 1;
1731 return;
1732 }
1733
1734 /* Extract Statistics: */
1735 rx_enable_time = le32_to_cpu(rx_info->channel_load);
1736 fa_cck = le32_to_cpu(statistics->cck.false_alarm_cnt);
1737 fa_ofdm = le32_to_cpu(statistics->ofdm.false_alarm_cnt);
1738 bad_plcp_cck = le32_to_cpu(statistics->cck.plcp_err);
1739 bad_plcp_ofdm = le32_to_cpu(statistics->ofdm.plcp_err);
1740
1741 statis.beacon_silence_rssi_a =
1742 le32_to_cpu(statistics->general.beacon_silence_rssi_a);
1743 statis.beacon_silence_rssi_b =
1744 le32_to_cpu(statistics->general.beacon_silence_rssi_b);
1745 statis.beacon_silence_rssi_c =
1746 le32_to_cpu(statistics->general.beacon_silence_rssi_c);
1747 statis.beacon_energy_a =
1748 le32_to_cpu(statistics->general.beacon_energy_a);
1749 statis.beacon_energy_b =
1750 le32_to_cpu(statistics->general.beacon_energy_b);
1751 statis.beacon_energy_c =
1752 le32_to_cpu(statistics->general.beacon_energy_c);
1753
1754 spin_unlock_irqrestore(&priv->lock, flags);
1755
1756 IWL_DEBUG_CALIB("rx_enable_time = %u usecs\n", rx_enable_time);
1757
1758 if (!rx_enable_time) {
1759 IWL_DEBUG_CALIB("<< RX Enable Time == 0! \n");
1760 return;
1761 }
1762
1763 /* These statistics increase monotonically, and do not reset
1764 * at each beacon. Calculate difference from last value, or just
1765 * use the new statistics value if it has reset or wrapped around. */
1766 if (data->last_bad_plcp_cnt_cck > bad_plcp_cck)
1767 data->last_bad_plcp_cnt_cck = bad_plcp_cck;
1768 else {
1769 bad_plcp_cck -= data->last_bad_plcp_cnt_cck;
1770 data->last_bad_plcp_cnt_cck += bad_plcp_cck;
1771 }
1772
1773 if (data->last_bad_plcp_cnt_ofdm > bad_plcp_ofdm)
1774 data->last_bad_plcp_cnt_ofdm = bad_plcp_ofdm;
1775 else {
1776 bad_plcp_ofdm -= data->last_bad_plcp_cnt_ofdm;
1777 data->last_bad_plcp_cnt_ofdm += bad_plcp_ofdm;
1778 }
1779
1780 if (data->last_fa_cnt_ofdm > fa_ofdm)
1781 data->last_fa_cnt_ofdm = fa_ofdm;
1782 else {
1783 fa_ofdm -= data->last_fa_cnt_ofdm;
1784 data->last_fa_cnt_ofdm += fa_ofdm;
1785 }
1786 891
1787 if (data->last_fa_cnt_cck > fa_cck) 892 memset(&cmd, 0, sizeof(cmd));
1788 data->last_fa_cnt_cck = fa_cck; 893 cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD;
1789 else { 894 cmd.diff_gain_a = data->delta_gain_code[0];
1790 fa_cck -= data->last_fa_cnt_cck; 895 cmd.diff_gain_b = data->delta_gain_code[1];
1791 data->last_fa_cnt_cck += fa_cck; 896 cmd.diff_gain_c = data->delta_gain_code[2];
897 ret = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
898 sizeof(cmd), &cmd);
899 if (ret)
900 IWL_DEBUG_CALIB("fail sending cmd "
901 "REPLY_PHY_CALIBRATION_CMD \n");
902
903 /* TODO we might want recalculate
904 * rx_chain in rxon cmd */
905
906 /* Mark so we run this algo only once! */
907 data->state = IWL_CHAIN_NOISE_CALIBRATED;
1792 } 908 }
1793 909 data->chain_noise_a = 0;
1794 /* Total aborted signal locks */ 910 data->chain_noise_b = 0;
1795 norm_fa_ofdm = fa_ofdm + bad_plcp_ofdm; 911 data->chain_noise_c = 0;
1796 norm_fa_cck = fa_cck + bad_plcp_cck; 912 data->chain_signal_a = 0;
1797 913 data->chain_signal_b = 0;
1798 IWL_DEBUG_CALIB("cck: fa %u badp %u ofdm: fa %u badp %u\n", fa_cck, 914 data->chain_signal_c = 0;
1799 bad_plcp_cck, fa_ofdm, bad_plcp_ofdm); 915 data->beacon_count = 0;
1800
1801 iwl4965_sens_auto_corr_ofdm(priv, norm_fa_ofdm, rx_enable_time);
1802 iwl4965_sens_energy_cck(priv, norm_fa_cck, rx_enable_time, &statis);
1803 ret = iwl4965_sensitivity_write(priv, CMD_ASYNC);
1804
1805 return;
1806} 916}
1807 917
1808static void iwl4965_bg_sensitivity_work(struct work_struct *work) 918static void iwl4965_bg_sensitivity_work(struct work_struct *work)
@@ -1819,21 +929,15 @@ static void iwl4965_bg_sensitivity_work(struct work_struct *work)
1819 } 929 }
1820 930
1821 if (priv->start_calib) { 931 if (priv->start_calib) {
1822 iwl4965_noise_calibration(priv, &priv->statistics); 932 iwl_chain_noise_calibration(priv, &priv->statistics);
1823 933
1824 if (priv->sensitivity_data.state == 934 iwl_sensitivity_calibration(priv, &priv->statistics);
1825 IWL_SENS_CALIB_NEED_REINIT) {
1826 iwl4965_init_sensitivity(priv, CMD_ASYNC, 0);
1827 priv->sensitivity_data.state = IWL_SENS_CALIB_ALLOWED;
1828 } else
1829 iwl4965_sensitivity_calibration(priv,
1830 &priv->statistics);
1831 } 935 }
1832 936
1833 mutex_unlock(&priv->mutex); 937 mutex_unlock(&priv->mutex);
1834 return; 938 return;
1835} 939}
1836#endif /*CONFIG_IWL4965_SENSITIVITY*/ 940#endif /*CONFIG_IWL4965_RUN_TIME_CALIB*/
1837 941
1838static void iwl4965_bg_txpower_work(struct work_struct *work) 942static void iwl4965_bg_txpower_work(struct work_struct *work)
1839{ 943{
@@ -1890,11 +994,11 @@ static void iwl4965_tx_queue_set_status(struct iwl_priv *priv,
1890 994
1891 /* Set up and activate */ 995 /* Set up and activate */
1892 iwl_write_prph(priv, IWL49_SCD_QUEUE_STATUS_BITS(txq_id), 996 iwl_write_prph(priv, IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
1893 (active << SCD_QUEUE_STTS_REG_POS_ACTIVE) | 997 (active << IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
1894 (tx_fifo_id << SCD_QUEUE_STTS_REG_POS_TXF) | 998 (tx_fifo_id << IWL49_SCD_QUEUE_STTS_REG_POS_TXF) |
1895 (scd_retry << SCD_QUEUE_STTS_REG_POS_WSL) | 999 (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_WSL) |
1896 (scd_retry << SCD_QUEUE_STTS_REG_POS_SCD_ACK) | 1000 (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACK) |
1897 SCD_QUEUE_STTS_REG_MSK); 1001 IWL49_SCD_QUEUE_STTS_REG_MSK);
1898 1002
1899 txq->sched_retry = scd_retry; 1003 txq->sched_retry = scd_retry;
1900 1004
@@ -1908,7 +1012,7 @@ static const u16 default_queue_to_tx_fifo[] = {
1908 IWL_TX_FIFO_AC2, 1012 IWL_TX_FIFO_AC2,
1909 IWL_TX_FIFO_AC1, 1013 IWL_TX_FIFO_AC1,
1910 IWL_TX_FIFO_AC0, 1014 IWL_TX_FIFO_AC0,
1911 IWL_CMD_FIFO_NUM, 1015 IWL49_CMD_FIFO_NUM,
1912 IWL_TX_FIFO_HCCA_1, 1016 IWL_TX_FIFO_HCCA_1,
1913 IWL_TX_FIFO_HCCA_2 1017 IWL_TX_FIFO_HCCA_2
1914}; 1018};
@@ -1932,15 +1036,15 @@ int iwl4965_alive_notify(struct iwl_priv *priv)
1932 1036
1933 spin_lock_irqsave(&priv->lock, flags); 1037 spin_lock_irqsave(&priv->lock, flags);
1934 1038
1935#ifdef CONFIG_IWL4965_SENSITIVITY 1039#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
1936 memset(&(priv->sensitivity_data), 0, 1040 memset(&(priv->sensitivity_data), 0,
1937 sizeof(struct iwl4965_sensitivity_data)); 1041 sizeof(struct iwl_sensitivity_data));
1938 memset(&(priv->chain_noise_data), 0, 1042 memset(&(priv->chain_noise_data), 0,
1939 sizeof(struct iwl4965_chain_noise_data)); 1043 sizeof(struct iwl_chain_noise_data));
1940 for (i = 0; i < NUM_RX_CHAINS; i++) 1044 for (i = 0; i < NUM_RX_CHAINS; i++)
1941 priv->chain_noise_data.delta_gain_code[i] = 1045 priv->chain_noise_data.delta_gain_code[i] =
1942 CHAIN_NOISE_DELTA_GAIN_INIT_VAL; 1046 CHAIN_NOISE_DELTA_GAIN_INIT_VAL;
1943#endif /* CONFIG_IWL4965_SENSITIVITY*/ 1047#endif /* CONFIG_IWL4965_RUN_TIME_CALIB*/
1944 ret = iwl_grab_nic_access(priv); 1048 ret = iwl_grab_nic_access(priv);
1945 if (ret) { 1049 if (ret) {
1946 spin_unlock_irqrestore(&priv->lock, flags); 1050 spin_unlock_irqrestore(&priv->lock, flags);
@@ -1949,10 +1053,10 @@ int iwl4965_alive_notify(struct iwl_priv *priv)
1949 1053
1950 /* Clear 4965's internal Tx Scheduler data base */ 1054 /* Clear 4965's internal Tx Scheduler data base */
1951 priv->scd_base_addr = iwl_read_prph(priv, IWL49_SCD_SRAM_BASE_ADDR); 1055 priv->scd_base_addr = iwl_read_prph(priv, IWL49_SCD_SRAM_BASE_ADDR);
1952 a = priv->scd_base_addr + SCD_CONTEXT_DATA_OFFSET; 1056 a = priv->scd_base_addr + IWL49_SCD_CONTEXT_DATA_OFFSET;
1953 for (; a < priv->scd_base_addr + SCD_TX_STTS_BITMAP_OFFSET; a += 4) 1057 for (; a < priv->scd_base_addr + IWL49_SCD_TX_STTS_BITMAP_OFFSET; a += 4)
1954 iwl_write_targ_mem(priv, a, 0); 1058 iwl_write_targ_mem(priv, a, 0);
1955 for (; a < priv->scd_base_addr + SCD_TRANSLATE_TBL_OFFSET; a += 4) 1059 for (; a < priv->scd_base_addr + IWL49_SCD_TRANSLATE_TBL_OFFSET; a += 4)
1956 iwl_write_targ_mem(priv, a, 0); 1060 iwl_write_targ_mem(priv, a, 0);
1957 for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4) 1061 for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4)
1958 iwl_write_targ_mem(priv, a, 0); 1062 iwl_write_targ_mem(priv, a, 0);
@@ -1974,18 +1078,18 @@ int iwl4965_alive_notify(struct iwl_priv *priv)
1974 1078
1975 /* Max Tx Window size for Scheduler-ACK mode */ 1079 /* Max Tx Window size for Scheduler-ACK mode */
1976 iwl_write_targ_mem(priv, priv->scd_base_addr + 1080 iwl_write_targ_mem(priv, priv->scd_base_addr +
1977 SCD_CONTEXT_QUEUE_OFFSET(i), 1081 IWL49_SCD_CONTEXT_QUEUE_OFFSET(i),
1978 (SCD_WIN_SIZE << 1082 (SCD_WIN_SIZE <<
1979 SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) & 1083 IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
1980 SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK); 1084 IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
1981 1085
1982 /* Frame limit */ 1086 /* Frame limit */
1983 iwl_write_targ_mem(priv, priv->scd_base_addr + 1087 iwl_write_targ_mem(priv, priv->scd_base_addr +
1984 SCD_CONTEXT_QUEUE_OFFSET(i) + 1088 IWL49_SCD_CONTEXT_QUEUE_OFFSET(i) +
1985 sizeof(u32), 1089 sizeof(u32),
1986 (SCD_FRAME_LIMIT << 1090 (SCD_FRAME_LIMIT <<
1987 SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) & 1091 IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
1988 SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK); 1092 IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
1989 1093
1990 } 1094 }
1991 iwl_write_prph(priv, IWL49_SCD_INTERRUPT_MASK, 1095 iwl_write_prph(priv, IWL49_SCD_INTERRUPT_MASK,
@@ -2013,6 +1117,31 @@ int iwl4965_alive_notify(struct iwl_priv *priv)
2013 return ret; 1117 return ret;
2014} 1118}
2015 1119
1120#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
1121static struct iwl_sensitivity_ranges iwl4965_sensitivity = {
1122 .min_nrg_cck = 97,
1123 .max_nrg_cck = 0,
1124
1125 .auto_corr_min_ofdm = 85,
1126 .auto_corr_min_ofdm_mrc = 170,
1127 .auto_corr_min_ofdm_x1 = 105,
1128 .auto_corr_min_ofdm_mrc_x1 = 220,
1129
1130 .auto_corr_max_ofdm = 120,
1131 .auto_corr_max_ofdm_mrc = 210,
1132 .auto_corr_max_ofdm_x1 = 140,
1133 .auto_corr_max_ofdm_mrc_x1 = 270,
1134
1135 .auto_corr_min_cck = 125,
1136 .auto_corr_max_cck = 200,
1137 .auto_corr_min_cck_mrc = 200,
1138 .auto_corr_max_cck_mrc = 400,
1139
1140 .nrg_th_cck = 100,
1141 .nrg_th_ofdm = 100,
1142};
1143#endif
1144
2016/** 1145/**
2017 * iwl4965_hw_set_hw_params 1146 * iwl4965_hw_set_hw_params
2018 * 1147 *
@@ -2021,14 +1150,15 @@ int iwl4965_alive_notify(struct iwl_priv *priv)
2021int iwl4965_hw_set_hw_params(struct iwl_priv *priv) 1150int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
2022{ 1151{
2023 1152
2024 if ((priv->cfg->mod_params->num_of_queues > IWL4965_MAX_NUM_QUEUES) || 1153 if ((priv->cfg->mod_params->num_of_queues > IWL49_NUM_QUEUES) ||
2025 (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) { 1154 (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
2026 IWL_ERROR("invalid queues_num, should be between %d and %d\n", 1155 IWL_ERROR("invalid queues_num, should be between %d and %d\n",
2027 IWL_MIN_NUM_QUEUES, IWL4965_MAX_NUM_QUEUES); 1156 IWL_MIN_NUM_QUEUES, IWL49_NUM_QUEUES);
2028 return -EINVAL; 1157 return -EINVAL;
2029 } 1158 }
2030 1159
2031 priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues; 1160 priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
1161 priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto;
2032 priv->hw_params.tx_cmd_len = sizeof(struct iwl4965_tx_cmd); 1162 priv->hw_params.tx_cmd_len = sizeof(struct iwl4965_tx_cmd);
2033 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE; 1163 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
2034 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG; 1164 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
@@ -2040,10 +1170,20 @@ int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
2040 priv->hw_params.max_stations = IWL4965_STATION_COUNT; 1170 priv->hw_params.max_stations = IWL4965_STATION_COUNT;
2041 priv->hw_params.bcast_sta_id = IWL4965_BROADCAST_ID; 1171 priv->hw_params.bcast_sta_id = IWL4965_BROADCAST_ID;
2042 1172
1173 priv->hw_params.max_data_size = IWL49_RTC_DATA_SIZE;
1174 priv->hw_params.max_inst_size = IWL49_RTC_INST_SIZE;
1175 priv->hw_params.max_bsm_size = BSM_SRAM_SIZE;
1176 priv->hw_params.fat_channel = BIT(IEEE80211_BAND_5GHZ);
1177
2043 priv->hw_params.tx_chains_num = 2; 1178 priv->hw_params.tx_chains_num = 2;
2044 priv->hw_params.rx_chains_num = 2; 1179 priv->hw_params.rx_chains_num = 2;
2045 priv->hw_params.valid_tx_ant = (IWL_ANTENNA_MAIN | IWL_ANTENNA_AUX); 1180 priv->hw_params.valid_tx_ant = ANT_A | ANT_B;
2046 priv->hw_params.valid_rx_ant = (IWL_ANTENNA_MAIN | IWL_ANTENNA_AUX); 1181 priv->hw_params.valid_rx_ant = ANT_A | ANT_B;
1182 priv->hw_params.ct_kill_threshold = CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
1183
1184#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
1185 priv->hw_params.sens = &iwl4965_sensitivity;
1186#endif
2047 1187
2048 return 0; 1188 return 0;
2049} 1189}
@@ -2124,6 +1264,17 @@ int iwl4965_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl4965_tx_queue *txq)
2124 return 0; 1264 return 0;
2125} 1265}
2126 1266
1267/* set card power command */
1268static int iwl4965_set_power(struct iwl_priv *priv,
1269 void *cmd)
1270{
1271 int ret = 0;
1272
1273 ret = iwl_send_cmd_pdu_async(priv, POWER_TABLE_CMD,
1274 sizeof(struct iwl4965_powertable_cmd),
1275 cmd, NULL);
1276 return ret;
1277}
2127int iwl4965_hw_reg_set_txpower(struct iwl_priv *priv, s8 power) 1278int iwl4965_hw_reg_set_txpower(struct iwl_priv *priv, s8 power)
2128{ 1279{
2129 IWL_ERROR("TODO: Implement iwl4965_hw_reg_set_txpower!\n"); 1280 IWL_ERROR("TODO: Implement iwl4965_hw_reg_set_txpower!\n");
@@ -2224,11 +1375,11 @@ static u32 iwl4965_get_sub_band(const struct iwl_priv *priv, u32 channel)
2224 s32 b = -1; 1375 s32 b = -1;
2225 1376
2226 for (b = 0; b < EEPROM_TX_POWER_BANDS; b++) { 1377 for (b = 0; b < EEPROM_TX_POWER_BANDS; b++) {
2227 if (priv->eeprom.calib_info.band_info[b].ch_from == 0) 1378 if (priv->calib_info->band_info[b].ch_from == 0)
2228 continue; 1379 continue;
2229 1380
2230 if ((channel >= priv->eeprom.calib_info.band_info[b].ch_from) 1381 if ((channel >= priv->calib_info->band_info[b].ch_from)
2231 && (channel <= priv->eeprom.calib_info.band_info[b].ch_to)) 1382 && (channel <= priv->calib_info->band_info[b].ch_to))
2232 break; 1383 break;
2233 } 1384 }
2234 1385
@@ -2256,14 +1407,14 @@ static s32 iwl4965_interpolate_value(s32 x, s32 x1, s32 y1, s32 x2, s32 y2)
2256 * in channel number. 1407 * in channel number.
2257 */ 1408 */
2258static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel, 1409static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel,
2259 struct iwl4965_eeprom_calib_ch_info *chan_info) 1410 struct iwl_eeprom_calib_ch_info *chan_info)
2260{ 1411{
2261 s32 s = -1; 1412 s32 s = -1;
2262 u32 c; 1413 u32 c;
2263 u32 m; 1414 u32 m;
2264 const struct iwl4965_eeprom_calib_measure *m1; 1415 const struct iwl_eeprom_calib_measure *m1;
2265 const struct iwl4965_eeprom_calib_measure *m2; 1416 const struct iwl_eeprom_calib_measure *m2;
2266 struct iwl4965_eeprom_calib_measure *omeas; 1417 struct iwl_eeprom_calib_measure *omeas;
2267 u32 ch_i1; 1418 u32 ch_i1;
2268 u32 ch_i2; 1419 u32 ch_i2;
2269 1420
@@ -2273,8 +1424,8 @@ static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel,
2273 return -1; 1424 return -1;
2274 } 1425 }
2275 1426
2276 ch_i1 = priv->eeprom.calib_info.band_info[s].ch1.ch_num; 1427 ch_i1 = priv->calib_info->band_info[s].ch1.ch_num;
2277 ch_i2 = priv->eeprom.calib_info.band_info[s].ch2.ch_num; 1428 ch_i2 = priv->calib_info->band_info[s].ch2.ch_num;
2278 chan_info->ch_num = (u8) channel; 1429 chan_info->ch_num = (u8) channel;
2279 1430
2280 IWL_DEBUG_TXPOWER("channel %d subband %d factory cal ch %d & %d\n", 1431 IWL_DEBUG_TXPOWER("channel %d subband %d factory cal ch %d & %d\n",
@@ -2282,9 +1433,9 @@ static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel,
2282 1433
2283 for (c = 0; c < EEPROM_TX_POWER_TX_CHAINS; c++) { 1434 for (c = 0; c < EEPROM_TX_POWER_TX_CHAINS; c++) {
2284 for (m = 0; m < EEPROM_TX_POWER_MEASUREMENTS; m++) { 1435 for (m = 0; m < EEPROM_TX_POWER_MEASUREMENTS; m++) {
2285 m1 = &(priv->eeprom.calib_info.band_info[s].ch1. 1436 m1 = &(priv->calib_info->band_info[s].ch1.
2286 measurements[c][m]); 1437 measurements[c][m]);
2287 m2 = &(priv->eeprom.calib_info.band_info[s].ch2. 1438 m2 = &(priv->calib_info->band_info[s].ch2.
2288 measurements[c][m]); 1439 measurements[c][m]);
2289 omeas = &(chan_info->measurements[c][m]); 1440 omeas = &(chan_info->measurements[c][m]);
2290 1441
@@ -2603,8 +1754,8 @@ static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
2603 int i; 1754 int i;
2604 int c; 1755 int c;
2605 const struct iwl_channel_info *ch_info = NULL; 1756 const struct iwl_channel_info *ch_info = NULL;
2606 struct iwl4965_eeprom_calib_ch_info ch_eeprom_info; 1757 struct iwl_eeprom_calib_ch_info ch_eeprom_info;
2607 const struct iwl4965_eeprom_calib_measure *measurement; 1758 const struct iwl_eeprom_calib_measure *measurement;
2608 s16 voltage; 1759 s16 voltage;
2609 s32 init_voltage; 1760 s32 init_voltage;
2610 s32 voltage_compensation; 1761 s32 voltage_compensation;
@@ -2661,9 +1812,9 @@ static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
2661 /* hardware txpower limits ... 1812 /* hardware txpower limits ...
2662 * saturation (clipping distortion) txpowers are in half-dBm */ 1813 * saturation (clipping distortion) txpowers are in half-dBm */
2663 if (band) 1814 if (band)
2664 saturation_power = priv->eeprom.calib_info.saturation_power24; 1815 saturation_power = priv->calib_info->saturation_power24;
2665 else 1816 else
2666 saturation_power = priv->eeprom.calib_info.saturation_power52; 1817 saturation_power = priv->calib_info->saturation_power52;
2667 1818
2668 if (saturation_power < IWL_TX_POWER_SATURATION_MIN || 1819 if (saturation_power < IWL_TX_POWER_SATURATION_MIN ||
2669 saturation_power > IWL_TX_POWER_SATURATION_MAX) { 1820 saturation_power > IWL_TX_POWER_SATURATION_MAX) {
@@ -2693,7 +1844,7 @@ static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
2693 iwl4965_interpolate_chan(priv, channel, &ch_eeprom_info); 1844 iwl4965_interpolate_chan(priv, channel, &ch_eeprom_info);
2694 1845
2695 /* calculate tx gain adjustment based on power supply voltage */ 1846 /* calculate tx gain adjustment based on power supply voltage */
2696 voltage = priv->eeprom.calib_info.voltage; 1847 voltage = priv->calib_info->voltage;
2697 init_voltage = (s32)le32_to_cpu(priv->card_alive_init.voltage); 1848 init_voltage = (s32)le32_to_cpu(priv->card_alive_init.voltage);
2698 voltage_compensation = 1849 voltage_compensation =
2699 iwl4965_get_voltage_compensation(voltage, init_voltage); 1850 iwl4965_get_voltage_compensation(voltage, init_voltage);
@@ -3104,9 +2255,9 @@ int iwl4965_hw_tx_queue_init(struct iwl_priv *priv, struct iwl4965_tx_queue *txq
3104 2255
3105 /* Enable DMA channel, using same id as for TFD queue */ 2256 /* Enable DMA channel, using same id as for TFD queue */
3106 iwl_write_direct32( 2257 iwl_write_direct32(
3107 priv, IWL_FH_TCSR_CHNL_TX_CONFIG_REG(txq_id), 2258 priv, FH_TCSR_CHNL_TX_CONFIG_REG(txq_id),
3108 IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE | 2259 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
3109 IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL); 2260 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL);
3110 iwl_release_nic_access(priv); 2261 iwl_release_nic_access(priv);
3111 spin_unlock_irqrestore(&priv->lock, flags); 2262 spin_unlock_irqrestore(&priv->lock, flags);
3112 2263
@@ -3149,18 +2300,37 @@ int iwl4965_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *ptr,
3149 2300
3150static void iwl4965_hw_card_show_info(struct iwl_priv *priv) 2301static void iwl4965_hw_card_show_info(struct iwl_priv *priv)
3151{ 2302{
3152 u16 hw_version = priv->eeprom.board_revision_4965; 2303 u16 hw_version = iwl_eeprom_query16(priv, EEPROM_4965_BOARD_REVISION);
3153 2304
3154 IWL_DEBUG_INFO("4965ABGN HW Version %u.%u.%u\n", 2305 IWL_DEBUG_INFO("4965ABGN HW Version %u.%u.%u\n",
3155 ((hw_version >> 8) & 0x0F), 2306 ((hw_version >> 8) & 0x0F),
3156 ((hw_version >> 8) >> 4), (hw_version & 0x00FF)); 2307 ((hw_version >> 8) >> 4), (hw_version & 0x00FF));
3157 2308
3158 IWL_DEBUG_INFO("4965ABGN PBA Number %.16s\n", 2309 IWL_DEBUG_INFO("4965ABGN PBA Number %.16s\n",
3159 priv->eeprom.board_pba_number_4965); 2310 &priv->eeprom[EEPROM_4965_BOARD_PBA]);
3160} 2311}
3161 2312
3162#define IWL_TX_CRC_SIZE 4 2313static int iwl4965_alloc_shared_mem(struct iwl_priv *priv)
3163#define IWL_TX_DELIMITER_SIZE 4 2314{
2315 priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
2316 sizeof(struct iwl4965_shared),
2317 &priv->shared_phys);
2318 if (!priv->shared_virt)
2319 return -ENOMEM;
2320
2321 memset(priv->shared_virt, 0, sizeof(struct iwl4965_shared));
2322
2323 return 0;
2324}
2325
2326static void iwl4965_free_shared_mem(struct iwl_priv *priv)
2327{
2328 if (priv->shared_virt)
2329 pci_free_consistent(priv->pci_dev,
2330 sizeof(struct iwl4965_shared),
2331 priv->shared_virt,
2332 priv->shared_phys);
2333}
3164 2334
3165/** 2335/**
3166 * iwl4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array 2336 * iwl4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
@@ -3180,50 +2350,13 @@ static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
3180 tfd_offset[txq->q.write_ptr], byte_cnt, len); 2350 tfd_offset[txq->q.write_ptr], byte_cnt, len);
3181 2351
3182 /* If within first 64 entries, duplicate at end */ 2352 /* If within first 64 entries, duplicate at end */
3183 if (txq->q.write_ptr < IWL4965_MAX_WIN_SIZE) 2353 if (txq->q.write_ptr < IWL49_MAX_WIN_SIZE)
3184 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id]. 2354 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
3185 tfd_offset[IWL4965_QUEUE_SIZE + txq->q.write_ptr], 2355 tfd_offset[IWL49_QUEUE_SIZE + txq->q.write_ptr],
3186 byte_cnt, len); 2356 byte_cnt, len);
3187} 2357}
3188 2358
3189/** 2359/**
3190 * iwl4965_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
3191 *
3192 * Selects how many and which Rx receivers/antennas/chains to use.
3193 * This should not be used for scan command ... it puts data in wrong place.
3194 */
3195void iwl4965_set_rxon_chain(struct iwl_priv *priv)
3196{
3197 u8 is_single = is_single_stream(priv);
3198 u8 idle_state, rx_state;
3199
3200 priv->staging_rxon.rx_chain = 0;
3201 rx_state = idle_state = 3;
3202
3203 /* Tell uCode which antennas are actually connected.
3204 * Before first association, we assume all antennas are connected.
3205 * Just after first association, iwl4965_noise_calibration()
3206 * checks which antennas actually *are* connected. */
3207 priv->staging_rxon.rx_chain |=
3208 cpu_to_le16(priv->valid_antenna << RXON_RX_CHAIN_VALID_POS);
3209
3210 /* How many receivers should we use? */
3211 iwl4965_get_rx_chain_counter(priv, &idle_state, &rx_state);
3212 priv->staging_rxon.rx_chain |=
3213 cpu_to_le16(rx_state << RXON_RX_CHAIN_MIMO_CNT_POS);
3214 priv->staging_rxon.rx_chain |=
3215 cpu_to_le16(idle_state << RXON_RX_CHAIN_CNT_POS);
3216
3217 if (!is_single && (rx_state >= 2) &&
3218 !test_bit(STATUS_POWER_PMI, &priv->status))
3219 priv->staging_rxon.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
3220 else
3221 priv->staging_rxon.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
3222
3223 IWL_DEBUG_ASSOC("rx chain %X\n", priv->staging_rxon.rx_chain);
3224}
3225
3226/**
3227 * sign_extend - Sign extend a value using specified bit as sign-bit 2360 * sign_extend - Sign extend a value using specified bit as sign-bit
3228 * 2361 *
3229 * Example: sign_extend(9, 3) would return -7 as bit3 of 1001b is 1 2362 * Example: sign_extend(9, 3) would return -7 as bit3 of 1001b is 1
@@ -3412,7 +2545,7 @@ void iwl4965_hw_rx_statistics(struct iwl_priv *priv, struct iwl4965_rx_mem_buffe
3412 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) && 2545 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
3413 (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) { 2546 (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
3414 iwl4965_rx_calc_noise(priv); 2547 iwl4965_rx_calc_noise(priv);
3415#ifdef CONFIG_IWL4965_SENSITIVITY 2548#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
3416 queue_work(priv->workqueue, &priv->sensitivity_work); 2549 queue_work(priv->workqueue, &priv->sensitivity_work);
3417#endif 2550#endif
3418 } 2551 }
@@ -3562,6 +2695,53 @@ static void iwl_update_rx_stats(struct iwl_priv *priv, u16 fc, u16 len)
3562 priv->rx_stats[idx].bytes += len; 2695 priv->rx_stats[idx].bytes += len;
3563} 2696}
3564 2697
2698/*
2699 * returns non-zero if packet should be dropped
2700 */
2701static int iwl4965_set_decrypted_flag(struct iwl_priv *priv,
2702 struct ieee80211_hdr *hdr,
2703 u32 decrypt_res,
2704 struct ieee80211_rx_status *stats)
2705{
2706 u16 fc = le16_to_cpu(hdr->frame_control);
2707
2708 if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
2709 return 0;
2710
2711 if (!(fc & IEEE80211_FCTL_PROTECTED))
2712 return 0;
2713
2714 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
2715 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
2716 case RX_RES_STATUS_SEC_TYPE_TKIP:
2717 /* The uCode has got a bad phase 1 Key, pushes the packet.
2718 * Decryption will be done in SW. */
2719 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2720 RX_RES_STATUS_BAD_KEY_TTAK)
2721 break;
2722
2723 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2724 RX_RES_STATUS_BAD_ICV_MIC) {
2725 /* bad ICV, the packet is destroyed since the
2726 * decryption is inplace, drop it */
2727 IWL_DEBUG_RX("Packet destroyed\n");
2728 return -1;
2729 }
2730 case RX_RES_STATUS_SEC_TYPE_WEP:
2731 case RX_RES_STATUS_SEC_TYPE_CCMP:
2732 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2733 RX_RES_STATUS_DECRYPT_OK) {
2734 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2735 stats->flag |= RX_FLAG_DECRYPTED;
2736 }
2737 break;
2738
2739 default:
2740 break;
2741 }
2742 return 0;
2743}
2744
3565static u32 iwl4965_translate_rx_status(u32 decrypt_in) 2745static u32 iwl4965_translate_rx_status(u32 decrypt_in)
3566{ 2746{
3567 u32 decrypt_out = 0; 2747 u32 decrypt_out = 0;
@@ -3691,8 +2871,10 @@ static void iwl4965_handle_data_packet(struct iwl_priv *priv, int is_data,
3691 stats->flag = 0; 2871 stats->flag = 0;
3692 hdr = (struct ieee80211_hdr *)rxb->skb->data; 2872 hdr = (struct ieee80211_hdr *)rxb->skb->data;
3693 2873
3694 if (!priv->cfg->mod_params->sw_crypto) 2874 /* in case of HW accelerated crypto and bad decryption, drop */
3695 iwl4965_set_decrypted_flag(priv, rxb->skb, ampdu_status, stats); 2875 if (!priv->hw_params.sw_crypto &&
2876 iwl4965_set_decrypted_flag(priv, hdr, ampdu_status, stats))
2877 return;
3696 2878
3697 if (priv->add_radiotap) 2879 if (priv->add_radiotap)
3698 iwl4965_add_radiotap(priv, rxb->skb, rx_start, stats, ampdu_status); 2880 iwl4965_add_radiotap(priv, rxb->skb, rx_start, stats, ampdu_status);
@@ -3737,38 +2919,6 @@ static int iwl4965_calc_rssi(struct iwl4965_rx_phy_res *rx_resp)
3737 return (max_rssi - agc - IWL_RSSI_OFFSET); 2919 return (max_rssi - agc - IWL_RSSI_OFFSET);
3738} 2920}
3739 2921
3740#ifdef CONFIG_IWL4965_HT
3741
3742void iwl4965_init_ht_hw_capab(struct iwl_priv *priv,
3743 struct ieee80211_ht_info *ht_info,
3744 enum ieee80211_band band)
3745{
3746 ht_info->cap = 0;
3747 memset(ht_info->supp_mcs_set, 0, 16);
3748
3749 ht_info->ht_supported = 1;
3750
3751 if (band == IEEE80211_BAND_5GHZ) {
3752 ht_info->cap |= (u16)IEEE80211_HT_CAP_SUP_WIDTH;
3753 ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_40;
3754 ht_info->supp_mcs_set[4] = 0x01;
3755 }
3756 ht_info->cap |= (u16)IEEE80211_HT_CAP_GRN_FLD;
3757 ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_20;
3758 ht_info->cap |= (u16)(IEEE80211_HT_CAP_MIMO_PS &
3759 (IWL_MIMO_PS_NONE << 2));
3760
3761 if (priv->cfg->mod_params->amsdu_size_8K)
3762 ht_info->cap |= (u16)IEEE80211_HT_CAP_MAX_AMSDU;
3763
3764 ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
3765 ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
3766
3767 ht_info->supp_mcs_set[0] = 0xFF;
3768 ht_info->supp_mcs_set[1] = 0xFF;
3769}
3770#endif /* CONFIG_IWL4965_HT */
3771
3772static void iwl4965_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id) 2922static void iwl4965_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
3773{ 2923{
3774 unsigned long flags; 2924 unsigned long flags;
@@ -3786,7 +2936,7 @@ static void iwl4965_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
3786static void iwl4965_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr) 2936static void iwl4965_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr)
3787{ 2937{
3788 /* FIXME: need locking over ps_status ??? */ 2938 /* FIXME: need locking over ps_status ??? */
3789 u8 sta_id = iwl4965_hw_find_station(priv, addr); 2939 u8 sta_id = iwl_find_station(priv, addr);
3790 2940
3791 if (sta_id != IWL_INVALID_STATION) { 2941 if (sta_id != IWL_INVALID_STATION) {
3792 u8 sta_awake = priv->stations[sta_id]. 2942 u8 sta_awake = priv->stations[sta_id].
@@ -4139,7 +3289,7 @@ static void iwl4965_rx_missed_beacon_notif(struct iwl_priv *priv,
4139 struct iwl4965_rx_mem_buffer *rxb) 3289 struct iwl4965_rx_mem_buffer *rxb)
4140 3290
4141{ 3291{
4142#ifdef CONFIG_IWL4965_SENSITIVITY 3292#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
4143 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; 3293 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
4144 struct iwl4965_missed_beacon_notif *missed_beacon; 3294 struct iwl4965_missed_beacon_notif *missed_beacon;
4145 3295
@@ -4150,11 +3300,10 @@ static void iwl4965_rx_missed_beacon_notif(struct iwl_priv *priv,
4150 le32_to_cpu(missed_beacon->total_missed_becons), 3300 le32_to_cpu(missed_beacon->total_missed_becons),
4151 le32_to_cpu(missed_beacon->num_recvd_beacons), 3301 le32_to_cpu(missed_beacon->num_recvd_beacons),
4152 le32_to_cpu(missed_beacon->num_expected_beacons)); 3302 le32_to_cpu(missed_beacon->num_expected_beacons));
4153 priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT; 3303 if (!test_bit(STATUS_SCANNING, &priv->status))
4154 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status))) 3304 iwl_init_sensitivity(priv);
4155 queue_work(priv->workqueue, &priv->sensitivity_work);
4156 } 3305 }
4157#endif /*CONFIG_IWL4965_SENSITIVITY*/ 3306#endif /*CONFIG_IWL4965_RUN_TIME_CALIB*/
4158} 3307}
4159#ifdef CONFIG_IWL4965_HT 3308#ifdef CONFIG_IWL4965_HT
4160 3309
@@ -4254,8 +3403,8 @@ static void iwl4965_tx_queue_stop_scheduler(struct iwl_priv *priv,
4254 * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */ 3403 * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
4255 iwl_write_prph(priv, 3404 iwl_write_prph(priv,
4256 IWL49_SCD_QUEUE_STATUS_BITS(txq_id), 3405 IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
4257 (0 << SCD_QUEUE_STTS_REG_POS_ACTIVE)| 3406 (0 << IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE)|
4258 (1 << SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN)); 3407 (1 << IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
4259} 3408}
4260 3409
4261/** 3410/**
@@ -4420,10 +3569,10 @@ static int iwl4965_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
4420 u32 tbl_dw; 3569 u32 tbl_dw;
4421 u16 scd_q2ratid; 3570 u16 scd_q2ratid;
4422 3571
4423 scd_q2ratid = ra_tid & SCD_QUEUE_RA_TID_MAP_RATID_MSK; 3572 scd_q2ratid = ra_tid & IWL49_SCD_QUEUE_RA_TID_MAP_RATID_MSK;
4424 3573
4425 tbl_dw_addr = priv->scd_base_addr + 3574 tbl_dw_addr = priv->scd_base_addr +
4426 SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id); 3575 IWL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
4427 3576
4428 tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr); 3577 tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr);
4429 3578
@@ -4485,14 +3634,14 @@ static int iwl4965_tx_queue_agg_enable(struct iwl_priv *priv, int txq_id,
4485 3634
4486 /* Set up Tx window size and frame limit for this queue */ 3635 /* Set up Tx window size and frame limit for this queue */
4487 iwl_write_targ_mem(priv, 3636 iwl_write_targ_mem(priv,
4488 priv->scd_base_addr + SCD_CONTEXT_QUEUE_OFFSET(txq_id), 3637 priv->scd_base_addr + IWL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id),
4489 (SCD_WIN_SIZE << SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) & 3638 (SCD_WIN_SIZE << IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
4490 SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK); 3639 IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
4491 3640
4492 iwl_write_targ_mem(priv, priv->scd_base_addr + 3641 iwl_write_targ_mem(priv, priv->scd_base_addr +
4493 SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32), 3642 IWL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32),
4494 (SCD_FRAME_LIMIT << SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) 3643 (SCD_FRAME_LIMIT << IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS)
4495 & SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK); 3644 & IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
4496 3645
4497 iwl_set_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id)); 3646 iwl_set_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
4498 3647
@@ -4544,8 +3693,7 @@ void iwl4965_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
4544 rate_flags |= RATE_MCS_CCK_MSK; 3693 rate_flags |= RATE_MCS_CCK_MSK;
4545 3694
4546 /* Use Tx antenna B only */ 3695 /* Use Tx antenna B only */
4547 rate_flags |= RATE_MCS_ANT_B_MSK; 3696 rate_flags |= RATE_MCS_ANT_B_MSK; /*FIXME:RS*/
4548 rate_flags &= ~RATE_MCS_ANT_A_MSK;
4549 3697
4550 link_cmd.rs_table[i].rate_n_flags = 3698 link_cmd.rs_table[i].rate_n_flags =
4551 iwl4965_hw_set_rate_n_flags(iwl4965_rates[r].plcp, rate_flags); 3699 iwl4965_hw_set_rate_n_flags(iwl4965_rates[r].plcp, rate_flags);
@@ -4648,13 +3796,15 @@ void iwl4965_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_info *ht_info)
4648 3796
4649 rxon->flags |= cpu_to_le32(val << RXON_FLG_HT_OPERATING_MODE_POS); 3797 rxon->flags |= cpu_to_le32(val << RXON_FLG_HT_OPERATING_MODE_POS);
4650 3798
4651 iwl4965_set_rxon_chain(priv); 3799 iwl_set_rxon_chain(priv);
4652 3800
4653 IWL_DEBUG_ASSOC("supported HT rate 0x%X %X " 3801 IWL_DEBUG_ASSOC("supported HT rate 0x%X 0x%X 0x%X "
4654 "rxon flags 0x%X operation mode :0x%X " 3802 "rxon flags 0x%X operation mode :0x%X "
4655 "extension channel offset 0x%x " 3803 "extension channel offset 0x%x "
4656 "control chan %d\n", 3804 "control chan %d\n",
4657 ht_info->supp_mcs_set[0], ht_info->supp_mcs_set[1], 3805 ht_info->supp_mcs_set[0],
3806 ht_info->supp_mcs_set[1],
3807 ht_info->supp_mcs_set[2],
4658 le32_to_cpu(rxon->flags), ht_info->ht_protection, 3808 le32_to_cpu(rxon->flags), ht_info->ht_protection,
4659 ht_info->extension_chan_offset, 3809 ht_info->extension_chan_offset,
4660 ht_info->control_channel); 3810 ht_info->control_channel);
@@ -4706,10 +3856,15 @@ void iwl4965_set_ht_add_station(struct iwl_priv *priv, u8 index,
4706 return; 3856 return;
4707} 3857}
4708 3858
4709static void iwl4965_sta_modify_add_ba_tid(struct iwl_priv *priv, 3859static int iwl4965_rx_agg_start(struct iwl_priv *priv,
4710 int sta_id, int tid, u16 ssn) 3860 const u8 *addr, int tid, u16 ssn)
4711{ 3861{
4712 unsigned long flags; 3862 unsigned long flags;
3863 int sta_id;
3864
3865 sta_id = iwl_find_station(priv, addr);
3866 if (sta_id == IWL_INVALID_STATION)
3867 return -ENXIO;
4713 3868
4714 spin_lock_irqsave(&priv->sta_lock, flags); 3869 spin_lock_irqsave(&priv->sta_lock, flags);
4715 priv->stations[sta_id].sta.station_flags_msk = 0; 3870 priv->stations[sta_id].sta.station_flags_msk = 0;
@@ -4719,13 +3874,19 @@ static void iwl4965_sta_modify_add_ba_tid(struct iwl_priv *priv,
4719 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; 3874 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
4720 spin_unlock_irqrestore(&priv->sta_lock, flags); 3875 spin_unlock_irqrestore(&priv->sta_lock, flags);
4721 3876
4722 iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC); 3877 return iwl4965_send_add_station(priv, &priv->stations[sta_id].sta,
3878 CMD_ASYNC);
4723} 3879}
4724 3880
4725static void iwl4965_sta_modify_del_ba_tid(struct iwl_priv *priv, 3881static int iwl4965_rx_agg_stop(struct iwl_priv *priv,
4726 int sta_id, int tid) 3882 const u8 *addr, int tid)
4727{ 3883{
4728 unsigned long flags; 3884 unsigned long flags;
3885 int sta_id;
3886
3887 sta_id = iwl_find_station(priv, addr);
3888 if (sta_id == IWL_INVALID_STATION)
3889 return -ENXIO;
4729 3890
4730 spin_lock_irqsave(&priv->sta_lock, flags); 3891 spin_lock_irqsave(&priv->sta_lock, flags);
4731 priv->stations[sta_id].sta.station_flags_msk = 0; 3892 priv->stations[sta_id].sta.station_flags_msk = 0;
@@ -4734,7 +3895,8 @@ static void iwl4965_sta_modify_del_ba_tid(struct iwl_priv *priv,
4734 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; 3895 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
4735 spin_unlock_irqrestore(&priv->sta_lock, flags); 3896 spin_unlock_irqrestore(&priv->sta_lock, flags);
4736 3897
4737 iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC); 3898 return iwl4965_send_add_station(priv, &priv->stations[sta_id].sta,
3899 CMD_ASYNC);
4738} 3900}
4739 3901
4740/* 3902/*
@@ -4753,8 +3915,8 @@ static int iwl4965_txq_ctx_activate_free(struct iwl_priv *priv)
4753 return -1; 3915 return -1;
4754} 3916}
4755 3917
4756static int iwl4965_mac_ht_tx_agg_start(struct ieee80211_hw *hw, const u8 *da, 3918static int iwl4965_tx_agg_start(struct ieee80211_hw *hw, const u8 *ra,
4757 u16 tid, u16 *start_seq_num) 3919 u16 tid, u16 *start_seq_num)
4758{ 3920{
4759 struct iwl_priv *priv = hw->priv; 3921 struct iwl_priv *priv = hw->priv;
4760 int sta_id; 3922 int sta_id;
@@ -4771,10 +3933,10 @@ static int iwl4965_mac_ht_tx_agg_start(struct ieee80211_hw *hw, const u8 *da,
4771 else 3933 else
4772 return -EINVAL; 3934 return -EINVAL;
4773 3935
4774 IWL_WARNING("%s on da = %s tid = %d\n", 3936 IWL_WARNING("%s on ra = %s tid = %d\n",
4775 __func__, print_mac(mac, da), tid); 3937 __func__, print_mac(mac, ra), tid);
4776 3938
4777 sta_id = iwl4965_hw_find_station(priv, da); 3939 sta_id = iwl_find_station(priv, ra);
4778 if (sta_id == IWL_INVALID_STATION) 3940 if (sta_id == IWL_INVALID_STATION)
4779 return -ENXIO; 3941 return -ENXIO;
4780 3942
@@ -4803,7 +3965,7 @@ static int iwl4965_mac_ht_tx_agg_start(struct ieee80211_hw *hw, const u8 *da,
4803 if (tid_data->tfds_in_queue == 0) { 3965 if (tid_data->tfds_in_queue == 0) {
4804 printk(KERN_ERR "HW queue is empty\n"); 3966 printk(KERN_ERR "HW queue is empty\n");
4805 tid_data->agg.state = IWL_AGG_ON; 3967 tid_data->agg.state = IWL_AGG_ON;
4806 ieee80211_start_tx_ba_cb_irqsafe(hw, da, tid); 3968 ieee80211_start_tx_ba_cb_irqsafe(hw, ra, tid);
4807 } else { 3969 } else {
4808 IWL_DEBUG_HT("HW queue is NOT empty: %d packets in HW queue\n", 3970 IWL_DEBUG_HT("HW queue is NOT empty: %d packets in HW queue\n",
4809 tid_data->tfds_in_queue); 3971 tid_data->tfds_in_queue);
@@ -4812,10 +3974,8 @@ static int iwl4965_mac_ht_tx_agg_start(struct ieee80211_hw *hw, const u8 *da,
4812 return ret; 3974 return ret;
4813} 3975}
4814 3976
4815static int iwl4965_mac_ht_tx_agg_stop(struct ieee80211_hw *hw, const u8 *da, 3977static int iwl4965_tx_agg_stop(struct ieee80211_hw *hw, const u8 *ra, u16 tid)
4816 u16 tid)
4817{ 3978{
4818
4819 struct iwl_priv *priv = hw->priv; 3979 struct iwl_priv *priv = hw->priv;
4820 int tx_fifo_id, txq_id, sta_id, ssn = -1; 3980 int tx_fifo_id, txq_id, sta_id, ssn = -1;
4821 struct iwl4965_tid_data *tid_data; 3981 struct iwl4965_tid_data *tid_data;
@@ -4823,8 +3983,8 @@ static int iwl4965_mac_ht_tx_agg_stop(struct ieee80211_hw *hw, const u8 *da,
4823 unsigned long flags; 3983 unsigned long flags;
4824 DECLARE_MAC_BUF(mac); 3984 DECLARE_MAC_BUF(mac);
4825 3985
4826 if (!da) { 3986 if (!ra) {
4827 IWL_ERROR("da = NULL\n"); 3987 IWL_ERROR("ra = NULL\n");
4828 return -EINVAL; 3988 return -EINVAL;
4829 } 3989 }
4830 3990
@@ -4833,7 +3993,7 @@ static int iwl4965_mac_ht_tx_agg_stop(struct ieee80211_hw *hw, const u8 *da,
4833 else 3993 else
4834 return -EINVAL; 3994 return -EINVAL;
4835 3995
4836 sta_id = iwl4965_hw_find_station(priv, da); 3996 sta_id = iwl_find_station(priv, ra);
4837 3997
4838 if (sta_id == IWL_INVALID_STATION) 3998 if (sta_id == IWL_INVALID_STATION)
4839 return -ENXIO; 3999 return -ENXIO;
@@ -4855,7 +4015,7 @@ static int iwl4965_mac_ht_tx_agg_stop(struct ieee80211_hw *hw, const u8 *da,
4855 return 0; 4015 return 0;
4856 } 4016 }
4857 4017
4858 IWL_DEBUG_HT("HW queue empty\n");; 4018 IWL_DEBUG_HT("HW queue is empty\n");
4859 priv->stations[sta_id].tid[tid].agg.state = IWL_AGG_OFF; 4019 priv->stations[sta_id].tid[tid].agg.state = IWL_AGG_OFF;
4860 4020
4861 spin_lock_irqsave(&priv->lock, flags); 4021 spin_lock_irqsave(&priv->lock, flags);
@@ -4865,10 +4025,7 @@ static int iwl4965_mac_ht_tx_agg_stop(struct ieee80211_hw *hw, const u8 *da,
4865 if (ret) 4025 if (ret)
4866 return ret; 4026 return ret;
4867 4027
4868 ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, da, tid); 4028 ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, ra, tid);
4869
4870 IWL_DEBUG_INFO("iwl4965_mac_ht_tx_agg_stop on da=%s tid=%d\n",
4871 print_mac(mac, da), tid);
4872 4029
4873 return 0; 4030 return 0;
4874} 4031}
@@ -4878,27 +4035,24 @@ int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
4878 const u8 *addr, u16 tid, u16 *ssn) 4035 const u8 *addr, u16 tid, u16 *ssn)
4879{ 4036{
4880 struct iwl_priv *priv = hw->priv; 4037 struct iwl_priv *priv = hw->priv;
4881 int sta_id;
4882 DECLARE_MAC_BUF(mac); 4038 DECLARE_MAC_BUF(mac);
4883 4039
4884 IWL_DEBUG_HT("A-MPDU action on da=%s tid=%d ", 4040 IWL_DEBUG_HT("A-MPDU action on addr %s tid %d\n",
4885 print_mac(mac, addr), tid); 4041 print_mac(mac, addr), tid);
4886 sta_id = iwl4965_hw_find_station(priv, addr); 4042
4887 switch (action) { 4043 switch (action) {
4888 case IEEE80211_AMPDU_RX_START: 4044 case IEEE80211_AMPDU_RX_START:
4889 IWL_DEBUG_HT("start Rx\n"); 4045 IWL_DEBUG_HT("start Rx\n");
4890 iwl4965_sta_modify_add_ba_tid(priv, sta_id, tid, *ssn); 4046 return iwl4965_rx_agg_start(priv, addr, tid, *ssn);
4891 break;
4892 case IEEE80211_AMPDU_RX_STOP: 4047 case IEEE80211_AMPDU_RX_STOP:
4893 IWL_DEBUG_HT("stop Rx\n"); 4048 IWL_DEBUG_HT("stop Rx\n");
4894 iwl4965_sta_modify_del_ba_tid(priv, sta_id, tid); 4049 return iwl4965_rx_agg_stop(priv, addr, tid);
4895 break;
4896 case IEEE80211_AMPDU_TX_START: 4050 case IEEE80211_AMPDU_TX_START:
4897 IWL_DEBUG_HT("start Tx\n"); 4051 IWL_DEBUG_HT("start Tx\n");
4898 return iwl4965_mac_ht_tx_agg_start(hw, addr, tid, ssn); 4052 return iwl4965_tx_agg_start(hw, addr, tid, ssn);
4899 case IEEE80211_AMPDU_TX_STOP: 4053 case IEEE80211_AMPDU_TX_STOP:
4900 IWL_DEBUG_HT("stop Tx\n"); 4054 IWL_DEBUG_HT("stop Tx\n");
4901 return iwl4965_mac_ht_tx_agg_stop(hw, addr, tid); 4055 return iwl4965_tx_agg_stop(hw, addr, tid);
4902 default: 4056 default:
4903 IWL_DEBUG_HT("unknown\n"); 4057 IWL_DEBUG_HT("unknown\n");
4904 return -EINVAL; 4058 return -EINVAL;
@@ -4910,7 +4064,7 @@ int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
4910#endif /* CONFIG_IWL4965_HT */ 4064#endif /* CONFIG_IWL4965_HT */
4911 4065
4912/* Set up 4965-specific Rx frame reply handlers */ 4066/* Set up 4965-specific Rx frame reply handlers */
4913void iwl4965_hw_rx_handler_setup(struct iwl_priv *priv) 4067static void iwl4965_rx_handler_setup(struct iwl_priv *priv)
4914{ 4068{
4915 /* Legacy Rx frames */ 4069 /* Legacy Rx frames */
4916 priv->rx_handlers[REPLY_RX] = iwl4965_rx_reply_rx; 4070 priv->rx_handlers[REPLY_RX] = iwl4965_rx_reply_rx;
@@ -4930,7 +4084,7 @@ void iwl4965_hw_rx_handler_setup(struct iwl_priv *priv)
4930void iwl4965_hw_setup_deferred_work(struct iwl_priv *priv) 4084void iwl4965_hw_setup_deferred_work(struct iwl_priv *priv)
4931{ 4085{
4932 INIT_WORK(&priv->txpower_work, iwl4965_bg_txpower_work); 4086 INIT_WORK(&priv->txpower_work, iwl4965_bg_txpower_work);
4933#ifdef CONFIG_IWL4965_SENSITIVITY 4087#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
4934 INIT_WORK(&priv->sensitivity_work, iwl4965_bg_sensitivity_work); 4088 INIT_WORK(&priv->sensitivity_work, iwl4965_bg_sensitivity_work);
4935#endif 4089#endif
4936 init_timer(&priv->statistics_periodic); 4090 init_timer(&priv->statistics_periodic);
@@ -4952,22 +4106,46 @@ static struct iwl_hcmd_ops iwl4965_hcmd = {
4952 4106
4953static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = { 4107static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
4954 .enqueue_hcmd = iwl4965_enqueue_hcmd, 4108 .enqueue_hcmd = iwl4965_enqueue_hcmd,
4109#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
4110 .chain_noise_reset = iwl4965_chain_noise_reset,
4111 .gain_computation = iwl4965_gain_computation,
4112#endif
4955}; 4113};
4956 4114
4957static struct iwl_lib_ops iwl4965_lib = { 4115static struct iwl_lib_ops iwl4965_lib = {
4958 .init_drv = iwl4965_init_drv,
4959 .set_hw_params = iwl4965_hw_set_hw_params, 4116 .set_hw_params = iwl4965_hw_set_hw_params,
4117 .alloc_shared_mem = iwl4965_alloc_shared_mem,
4118 .free_shared_mem = iwl4965_free_shared_mem,
4960 .txq_update_byte_cnt_tbl = iwl4965_txq_update_byte_cnt_tbl, 4119 .txq_update_byte_cnt_tbl = iwl4965_txq_update_byte_cnt_tbl,
4961 .hw_nic_init = iwl4965_hw_nic_init, 4120 .hw_nic_init = iwl4965_hw_nic_init,
4121 .rx_handler_setup = iwl4965_rx_handler_setup,
4962 .is_valid_rtc_data_addr = iwl4965_hw_valid_rtc_data_addr, 4122 .is_valid_rtc_data_addr = iwl4965_hw_valid_rtc_data_addr,
4963 .alive_notify = iwl4965_alive_notify, 4123 .alive_notify = iwl4965_alive_notify,
4964 .load_ucode = iwl4965_load_bsm, 4124 .load_ucode = iwl4965_load_bsm,
4125 .apm_ops = {
4126 .init = iwl4965_apm_init,
4127 .config = iwl4965_nic_config,
4128 .set_pwr_src = iwl4965_set_pwr_src,
4129 },
4965 .eeprom_ops = { 4130 .eeprom_ops = {
4131 .regulatory_bands = {
4132 EEPROM_REGULATORY_BAND_1_CHANNELS,
4133 EEPROM_REGULATORY_BAND_2_CHANNELS,
4134 EEPROM_REGULATORY_BAND_3_CHANNELS,
4135 EEPROM_REGULATORY_BAND_4_CHANNELS,
4136 EEPROM_REGULATORY_BAND_5_CHANNELS,
4137 EEPROM_4965_REGULATORY_BAND_24_FAT_CHANNELS,
4138 EEPROM_4965_REGULATORY_BAND_52_FAT_CHANNELS
4139 },
4966 .verify_signature = iwlcore_eeprom_verify_signature, 4140 .verify_signature = iwlcore_eeprom_verify_signature,
4967 .acquire_semaphore = iwlcore_eeprom_acquire_semaphore, 4141 .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
4968 .release_semaphore = iwlcore_eeprom_release_semaphore, 4142 .release_semaphore = iwlcore_eeprom_release_semaphore,
4143 .check_version = iwl4965_eeprom_check_version,
4144 .query_addr = iwlcore_eeprom_query_addr,
4969 }, 4145 },
4970 .radio_kill_sw = iwl4965_radio_kill_sw, 4146 .radio_kill_sw = iwl4965_radio_kill_sw,
4147 .set_power = iwl4965_set_power,
4148 .update_chain_flags = iwl4965_update_chain_flags,
4971}; 4149};
4972 4150
4973static struct iwl_ops iwl4965_ops = { 4151static struct iwl_ops iwl4965_ops = {
@@ -4980,6 +4158,7 @@ struct iwl_cfg iwl4965_agn_cfg = {
4980 .name = "4965AGN", 4158 .name = "4965AGN",
4981 .fw_name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode", 4159 .fw_name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode",
4982 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N, 4160 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
4161 .eeprom_size = IWL4965_EEPROM_IMG_SIZE,
4983 .ops = &iwl4965_ops, 4162 .ops = &iwl4965_ops,
4984 .mod_params = &iwl4965_mod_params, 4163 .mod_params = &iwl4965_mod_params,
4985}; 4164};
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000-hw.h b/drivers/net/wireless/iwlwifi/iwl-5000-hw.h
new file mode 100644
index 000000000000..9e557ce315b7
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-5000-hw.h
@@ -0,0 +1,133 @@
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
26 *
27 * Contact Information:
28 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2005 - 2008 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63/*
64 * Please use this file (iwl-5000-hw.h) only for hardware-related definitions.
65 * Use iwl-5000-commands.h for uCode API definitions.
66 */
67
68#ifndef __iwl_5000_hw_h__
69#define __iwl_5000_hw_h__
70
71#define IWL50_RTC_INST_UPPER_BOUND (0x020000)
72#define IWL50_RTC_DATA_UPPER_BOUND (0x80C000)
73#define IWL50_RTC_INST_SIZE (IWL50_RTC_INST_UPPER_BOUND - RTC_INST_LOWER_BOUND)
74#define IWL50_RTC_DATA_SIZE (IWL50_RTC_DATA_UPPER_BOUND - RTC_DATA_LOWER_BOUND)
75
76/* EERPROM */
77#define IWL_5000_EEPROM_IMG_SIZE 2048
78
79
80#define IWL50_MAX_WIN_SIZE 64
81#define IWL50_QUEUE_SIZE 256
82#define IWL50_CMD_FIFO_NUM 7
83#define IWL50_NUM_QUEUES 20
84#define IWL50_BACK_QUEUE_FIRST_ID 10
85
86#define IWL_sta_id_POS 12
87#define IWL_sta_id_LEN 4
88#define IWL_sta_id_SYM val
89
90/* Fixed (non-configurable) rx data from phy */
91
92/* Base physical address of iwl5000_shared is provided to SCD_DRAM_BASE_ADDR
93 * and &iwl5000_shared.val0 is provided to FH_RSCSR_CHNL0_STTS_WPTR_REG */
94struct iwl5000_sched_queue_byte_cnt_tbl {
95 struct iwl4965_queue_byte_cnt_entry tfd_offset[IWL50_QUEUE_SIZE +
96 IWL50_MAX_WIN_SIZE];
97} __attribute__ ((packed));
98
99struct iwl5000_shared {
100 struct iwl5000_sched_queue_byte_cnt_tbl
101 queues_byte_cnt_tbls[IWL50_NUM_QUEUES];
102 __le32 rb_closed;
103
104 /* __le32 rb_closed_stts_rb_num:12; */
105#define IWL_rb_closed_stts_rb_num_POS 0
106#define IWL_rb_closed_stts_rb_num_LEN 12
107#define IWL_rb_closed_stts_rb_num_SYM rb_closed
108 /* __le32 rsrv1:4; */
109 /* __le32 rb_closed_stts_rx_frame_num:12; */
110#define IWL_rb_closed_stts_rx_frame_num_POS 16
111#define IWL_rb_closed_stts_rx_frame_num_LEN 12
112#define IWL_rb_closed_stts_rx_frame_num_SYM rb_closed
113 /* __le32 rsrv2:4; */
114
115 __le32 frm_finished;
116 /* __le32 frame_finished_stts_rb_num:12; */
117#define IWL_frame_finished_stts_rb_num_POS 0
118#define IWL_frame_finished_stts_rb_num_LEN 12
119#define IWL_frame_finished_stts_rb_num_SYM frm_finished
120 /* __le32 rsrv3:4; */
121 /* __le32 frame_finished_stts_rx_frame_num:12; */
122#define IWL_frame_finished_stts_rx_frame_num_POS 16
123#define IWL_frame_finished_stts_rx_frame_num_LEN 12
124#define IWL_frame_finished_stts_rx_frame_num_SYM frm_finished
125 /* __le32 rsrv4:4; */
126
127 __le32 padding1; /* so that allocation will be aligned to 16B */
128 __le32 padding2;
129} __attribute__ ((packed));
130
131
132#endif /* __iwl_5000_hw_h__ */
133
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
new file mode 100644
index 000000000000..0d8ef63f8713
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
@@ -0,0 +1,519 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007-2008 Intel Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
21 * Contact Information:
22 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
23 *
24 *****************************************************************************/
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/version.h>
29#include <linux/init.h>
30#include <linux/pci.h>
31#include <linux/dma-mapping.h>
32#include <linux/delay.h>
33#include <linux/skbuff.h>
34#include <linux/netdevice.h>
35#include <linux/wireless.h>
36#include <net/mac80211.h>
37#include <linux/etherdevice.h>
38#include <asm/unaligned.h>
39
40#include "iwl-eeprom.h"
41#include "iwl-dev.h"
42#include "iwl-core.h"
43#include "iwl-io.h"
44#include "iwl-helpers.h"
45#include "iwl-5000-hw.h"
46
47#define IWL5000_UCODE_API "-1"
48
49static int iwl5000_apm_init(struct iwl_priv *priv)
50{
51 int ret = 0;
52
53 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
54 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
55
56 iwl_set_bit(priv, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL);
57
58 /* set "initialization complete" bit to move adapter
59 * D0U* --> D0A* state */
60 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
61
62 /* wait for clock stabilization */
63 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
64 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
65 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
66 if (ret < 0) {
67 IWL_DEBUG_INFO("Failed to init the card\n");
68 return ret;
69 }
70
71 ret = iwl_grab_nic_access(priv);
72 if (ret)
73 return ret;
74
75 /* enable DMA */
76 iwl_write_prph(priv, APMG_CLK_EN_REG,
77 APMG_CLK_VAL_DMA_CLK_RQT);
78
79 udelay(20);
80
81 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
82 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
83
84 iwl_release_nic_access(priv);
85
86 return ret;
87}
88
89static void iwl5000_nic_init(struct iwl_priv *priv)
90{
91 unsigned long flags;
92 u16 radio_cfg;
93 u8 val_link;
94
95 spin_lock_irqsave(&priv->lock, flags);
96
97 pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link);
98
99 /* disable L1 entry -- workaround for pre-B1 */
100 pci_write_config_byte(priv->pci_dev, PCI_LINK_CTRL, val_link & ~0x02);
101
102 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
103
104 /* write radio config values to register */
105 if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) < EEPROM_5000_RF_CFG_TYPE_MAX)
106 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
107 EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
108 EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
109 EEPROM_RF_CFG_DASH_MSK(radio_cfg));
110
111 /* set CSR_HW_CONFIG_REG for uCode use */
112 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
113 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
114 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
115
116 spin_unlock_irqrestore(&priv->lock, flags);
117}
118
119
120
121/*
122 * EEPROM
123 */
124static u32 eeprom_indirect_address(const struct iwl_priv *priv, u32 address)
125{
126 u16 offset = 0;
127
128 if ((address & INDIRECT_ADDRESS) == 0)
129 return address;
130
131 switch (address & INDIRECT_TYPE_MSK) {
132 case INDIRECT_HOST:
133 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_HOST);
134 break;
135 case INDIRECT_GENERAL:
136 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_GENERAL);
137 break;
138 case INDIRECT_REGULATORY:
139 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_REGULATORY);
140 break;
141 case INDIRECT_CALIBRATION:
142 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_CALIBRATION);
143 break;
144 case INDIRECT_PROCESS_ADJST:
145 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_PROCESS_ADJST);
146 break;
147 case INDIRECT_OTHERS:
148 offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_OTHERS);
149 break;
150 default:
151 IWL_ERROR("illegal indirect type: 0x%X\n",
152 address & INDIRECT_TYPE_MSK);
153 break;
154 }
155
156 /* translate the offset from words to byte */
157 return (address & ADDRESS_MSK) + (offset << 1);
158}
159
160static int iwl5000_eeprom_check_version(struct iwl_priv *priv)
161{
162 u16 eeprom_ver;
163 struct iwl_eeprom_calib_hdr {
164 u8 version;
165 u8 pa_type;
166 u16 voltage;
167 } *hdr;
168
169 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
170
171 hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
172 EEPROM_5000_CALIB_ALL);
173
174 if (eeprom_ver < EEPROM_5000_EEPROM_VERSION ||
175 hdr->version < EEPROM_5000_TX_POWER_VERSION)
176 goto err;
177
178 return 0;
179err:
180 IWL_ERROR("Unsuported EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
181 eeprom_ver, EEPROM_5000_EEPROM_VERSION,
182 hdr->version, EEPROM_5000_TX_POWER_VERSION);
183 return -EINVAL;
184
185}
186
187#ifdef CONFIG_IWL5000_RUN_TIME_CALIB
188
189static void iwl5000_gain_computation(struct iwl_priv *priv,
190 u32 average_noise[NUM_RX_CHAINS],
191 u16 min_average_noise_antenna_i,
192 u32 min_average_noise)
193{
194 int i;
195 s32 delta_g;
196 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
197
198 /* Find Gain Code for the antennas B and C */
199 for (i = 1; i < NUM_RX_CHAINS; i++) {
200 if ((data->disconn_array[i])) {
201 data->delta_gain_code[i] = 0;
202 continue;
203 }
204 delta_g = (1000 * ((s32)average_noise[0] -
205 (s32)average_noise[i])) / 1500;
206 /* bound gain by 2 bits value max, 3rd bit is sign */
207 data->delta_gain_code[i] =
208 min(abs(delta_g), CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
209
210 if (delta_g < 0)
211 /* set negative sign */
212 data->delta_gain_code[i] |= (1 << 2);
213 }
214
215 IWL_DEBUG_CALIB("Delta gains: ANT_B = %d ANT_C = %d\n",
216 data->delta_gain_code[1], data->delta_gain_code[2]);
217
218 if (!data->radio_write) {
219 struct iwl5000_calibration_chain_noise_gain_cmd cmd;
220 memset(&cmd, 0, sizeof(cmd));
221
222 cmd.op_code = IWL5000_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD;
223 cmd.delta_gain_1 = data->delta_gain_code[1];
224 cmd.delta_gain_2 = data->delta_gain_code[2];
225 iwl_send_cmd_pdu_async(priv, REPLY_PHY_CALIBRATION_CMD,
226 sizeof(cmd), &cmd, NULL);
227
228 data->radio_write = 1;
229 data->state = IWL_CHAIN_NOISE_CALIBRATED;
230 }
231
232 data->chain_noise_a = 0;
233 data->chain_noise_b = 0;
234 data->chain_noise_c = 0;
235 data->chain_signal_a = 0;
236 data->chain_signal_b = 0;
237 data->chain_signal_c = 0;
238 data->beacon_count = 0;
239}
240
241
242static void iwl5000_chain_noise_reset(struct iwl_priv *priv)
243{
244 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
245
246 if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
247 struct iwl5000_calibration_chain_noise_reset_cmd cmd;
248
249 memset(&cmd, 0, sizeof(cmd));
250 cmd.op_code = IWL5000_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD;
251 if (iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
252 sizeof(cmd), &cmd))
253 IWL_ERROR("Could not send REPLY_PHY_CALIBRATION_CMD\n");
254 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
255 IWL_DEBUG_CALIB("Run chain_noise_calibrate\n");
256 }
257}
258
259static struct iwl_sensitivity_ranges iwl5000_sensitivity = {
260 .min_nrg_cck = 95,
261 .max_nrg_cck = 0,
262 .auto_corr_min_ofdm = 90,
263 .auto_corr_min_ofdm_mrc = 170,
264 .auto_corr_min_ofdm_x1 = 120,
265 .auto_corr_min_ofdm_mrc_x1 = 240,
266
267 .auto_corr_max_ofdm = 120,
268 .auto_corr_max_ofdm_mrc = 210,
269 .auto_corr_max_ofdm_x1 = 155,
270 .auto_corr_max_ofdm_mrc_x1 = 290,
271
272 .auto_corr_min_cck = 125,
273 .auto_corr_max_cck = 200,
274 .auto_corr_min_cck_mrc = 170,
275 .auto_corr_max_cck_mrc = 400,
276 .nrg_th_cck = 95,
277 .nrg_th_ofdm = 95,
278};
279
280#endif /* CONFIG_IWL5000_RUN_TIME_CALIB */
281
282static const u8 *iwl5000_eeprom_query_addr(const struct iwl_priv *priv,
283 size_t offset)
284{
285 u32 address = eeprom_indirect_address(priv, offset);
286 BUG_ON(address >= priv->cfg->eeprom_size);
287 return &priv->eeprom[address];
288}
289
290static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
291{
292 if ((priv->cfg->mod_params->num_of_queues > IWL50_NUM_QUEUES) ||
293 (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
294 IWL_ERROR("invalid queues_num, should be between %d and %d\n",
295 IWL_MIN_NUM_QUEUES, IWL50_NUM_QUEUES);
296 return -EINVAL;
297 }
298
299 priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
300 priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto;
301 priv->hw_params.tx_cmd_len = sizeof(struct iwl4965_tx_cmd);
302 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
303 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
304 if (priv->cfg->mod_params->amsdu_size_8K)
305 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K;
306 else
307 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K;
308 priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256;
309 priv->hw_params.max_stations = IWL5000_STATION_COUNT;
310 priv->hw_params.bcast_sta_id = IWL5000_BROADCAST_ID;
311 priv->hw_params.max_data_size = IWL50_RTC_DATA_SIZE;
312 priv->hw_params.max_inst_size = IWL50_RTC_INST_SIZE;
313 priv->hw_params.max_bsm_size = BSM_SRAM_SIZE;
314 priv->hw_params.fat_channel = BIT(IEEE80211_BAND_2GHZ) |
315 BIT(IEEE80211_BAND_5GHZ);
316#ifdef CONFIG_IWL5000_RUN_TIME_CALIB
317 priv->hw_params.sens = &iwl5000_sensitivity;
318#endif
319
320 switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
321 case CSR_HW_REV_TYPE_5100:
322 case CSR_HW_REV_TYPE_5150:
323 priv->hw_params.tx_chains_num = 1;
324 priv->hw_params.rx_chains_num = 2;
325 /* FIXME: move to ANT_A, ANT_B, ANT_C enum */
326 priv->hw_params.valid_tx_ant = ANT_A;
327 priv->hw_params.valid_rx_ant = ANT_AB;
328 break;
329 case CSR_HW_REV_TYPE_5300:
330 case CSR_HW_REV_TYPE_5350:
331 priv->hw_params.tx_chains_num = 3;
332 priv->hw_params.rx_chains_num = 3;
333 priv->hw_params.valid_tx_ant = ANT_ABC;
334 priv->hw_params.valid_rx_ant = ANT_ABC;
335 break;
336 }
337
338 switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
339 case CSR_HW_REV_TYPE_5100:
340 case CSR_HW_REV_TYPE_5300:
341 /* 5X00 wants in Celsius */
342 priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD;
343 break;
344 case CSR_HW_REV_TYPE_5150:
345 case CSR_HW_REV_TYPE_5350:
346 /* 5X50 wants in Kelvin */
347 priv->hw_params.ct_kill_threshold =
348 CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
349 break;
350 }
351
352 return 0;
353}
354
355static int iwl5000_alloc_shared_mem(struct iwl_priv *priv)
356{
357 priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
358 sizeof(struct iwl5000_shared),
359 &priv->shared_phys);
360 if (!priv->shared_virt)
361 return -ENOMEM;
362
363 memset(priv->shared_virt, 0, sizeof(struct iwl5000_shared));
364
365 return 0;
366}
367
368static void iwl5000_free_shared_mem(struct iwl_priv *priv)
369{
370 if (priv->shared_virt)
371 pci_free_consistent(priv->pci_dev,
372 sizeof(struct iwl5000_shared),
373 priv->shared_virt,
374 priv->shared_phys);
375}
376
377/**
378 * iwl5000_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
379 */
380static void iwl5000_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
381 struct iwl4965_tx_queue *txq,
382 u16 byte_cnt)
383{
384 struct iwl5000_shared *shared_data = priv->shared_virt;
385 int txq_id = txq->q.id;
386 u8 sec_ctl = 0;
387 u8 sta = 0;
388 int len;
389
390 len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
391
392 if (txq_id != IWL_CMD_QUEUE_NUM) {
393 sta = txq->cmd[txq->q.write_ptr].cmd.tx.sta_id;
394 sec_ctl = txq->cmd[txq->q.write_ptr].cmd.tx.sec_ctl;
395
396 switch (sec_ctl & TX_CMD_SEC_MSK) {
397 case TX_CMD_SEC_CCM:
398 len += CCMP_MIC_LEN;
399 break;
400 case TX_CMD_SEC_TKIP:
401 len += TKIP_ICV_LEN;
402 break;
403 case TX_CMD_SEC_WEP:
404 len += WEP_IV_LEN + WEP_ICV_LEN;
405 break;
406 }
407 }
408
409 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
410 tfd_offset[txq->q.write_ptr], byte_cnt, len);
411
412 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
413 tfd_offset[txq->q.write_ptr], sta_id, sta);
414
415 if (txq->q.write_ptr < IWL50_MAX_WIN_SIZE) {
416 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
417 tfd_offset[IWL50_QUEUE_SIZE + txq->q.write_ptr],
418 byte_cnt, len);
419 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
420 tfd_offset[IWL50_QUEUE_SIZE + txq->q.write_ptr],
421 sta_id, sta);
422 }
423}
424
425static struct iwl_hcmd_ops iwl5000_hcmd = {
426};
427
428static struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = {
429#ifdef CONFIG_IWL5000_RUN_TIME_CALIB
430 .gain_computation = iwl5000_gain_computation,
431 .chain_noise_reset = iwl5000_chain_noise_reset,
432#endif
433};
434
435static struct iwl_lib_ops iwl5000_lib = {
436 .set_hw_params = iwl5000_hw_set_hw_params,
437 .alloc_shared_mem = iwl5000_alloc_shared_mem,
438 .free_shared_mem = iwl5000_free_shared_mem,
439 .txq_update_byte_cnt_tbl = iwl5000_txq_update_byte_cnt_tbl,
440 .apm_ops = {
441 .init = iwl5000_apm_init,
442 .config = iwl5000_nic_init,
443 .set_pwr_src = iwl4965_set_pwr_src,
444 },
445 .eeprom_ops = {
446 .regulatory_bands = {
447 EEPROM_5000_REG_BAND_1_CHANNELS,
448 EEPROM_5000_REG_BAND_2_CHANNELS,
449 EEPROM_5000_REG_BAND_3_CHANNELS,
450 EEPROM_5000_REG_BAND_4_CHANNELS,
451 EEPROM_5000_REG_BAND_5_CHANNELS,
452 EEPROM_5000_REG_BAND_24_FAT_CHANNELS,
453 EEPROM_5000_REG_BAND_52_FAT_CHANNELS
454 },
455 .verify_signature = iwlcore_eeprom_verify_signature,
456 .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
457 .release_semaphore = iwlcore_eeprom_release_semaphore,
458 .check_version = iwl5000_eeprom_check_version,
459 .query_addr = iwl5000_eeprom_query_addr,
460 },
461};
462
463static struct iwl_ops iwl5000_ops = {
464 .lib = &iwl5000_lib,
465 .hcmd = &iwl5000_hcmd,
466 .utils = &iwl5000_hcmd_utils,
467};
468
469static struct iwl_mod_params iwl50_mod_params = {
470 .num_of_queues = IWL50_NUM_QUEUES,
471 .enable_qos = 1,
472 .amsdu_size_8K = 1,
473 /* the rest are 0 by default */
474};
475
476
477struct iwl_cfg iwl5300_agn_cfg = {
478 .name = "5300AGN",
479 .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
480 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
481 .ops = &iwl5000_ops,
482 .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
483 .mod_params = &iwl50_mod_params,
484};
485
486struct iwl_cfg iwl5100_agn_cfg = {
487 .name = "5100AGN",
488 .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
489 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
490 .ops = &iwl5000_ops,
491 .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
492 .mod_params = &iwl50_mod_params,
493};
494
495struct iwl_cfg iwl5350_agn_cfg = {
496 .name = "5350AGN",
497 .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
498 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
499 .ops = &iwl5000_ops,
500 .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
501 .mod_params = &iwl50_mod_params,
502};
503
504module_param_named(disable50, iwl50_mod_params.disable, int, 0444);
505MODULE_PARM_DESC(disable50,
506 "manually disable the 50XX radio (default 0 [radio on])");
507module_param_named(swcrypto50, iwl50_mod_params.sw_crypto, bool, 0444);
508MODULE_PARM_DESC(swcrypto50,
509 "using software crypto engine (default 0 [hardware])\n");
510module_param_named(debug50, iwl50_mod_params.debug, int, 0444);
511MODULE_PARM_DESC(debug50, "50XX debug output mask");
512module_param_named(queues_num50, iwl50_mod_params.num_of_queues, int, 0444);
513MODULE_PARM_DESC(queues_num50, "number of hw queues in 50xx series");
514module_param_named(qos_enable50, iwl50_mod_params.enable_qos, int, 0444);
515MODULE_PARM_DESC(qos_enable50, "enable all 50XX QoS functionality");
516module_param_named(amsdu_size_8K50, iwl50_mod_params.amsdu_size_8K, int, 0444);
517MODULE_PARM_DESC(amsdu_size_8K50, "enable 8K amsdu size in 50XX series");
518
519
diff --git a/drivers/net/wireless/iwlwifi/iwl-calib.c b/drivers/net/wireless/iwlwifi/iwl-calib.c
new file mode 100644
index 000000000000..1289d4c91abe
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-calib.c
@@ -0,0 +1,779 @@
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2008 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
26 *
27 * Contact Information:
28 * Tomas Winkler <tomas.winkler@intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2005 - 2008 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *****************************************************************************/
62
63#include <linux/kernel.h>
64#include <net/mac80211.h>
65
66#include "iwl-dev.h"
67#include "iwl-core.h"
68#include "iwl-calib.h"
69#include "iwl-eeprom.h"
70
71/* "false alarms" are signals that our DSP tries to lock onto,
72 * but then determines that they are either noise, or transmissions
73 * from a distant wireless network (also "noise", really) that get
74 * "stepped on" by stronger transmissions within our own network.
75 * This algorithm attempts to set a sensitivity level that is high
76 * enough to receive all of our own network traffic, but not so
77 * high that our DSP gets too busy trying to lock onto non-network
78 * activity/noise. */
79static int iwl_sens_energy_cck(struct iwl_priv *priv,
80 u32 norm_fa,
81 u32 rx_enable_time,
82 struct statistics_general_data *rx_info)
83{
84 u32 max_nrg_cck = 0;
85 int i = 0;
86 u8 max_silence_rssi = 0;
87 u32 silence_ref = 0;
88 u8 silence_rssi_a = 0;
89 u8 silence_rssi_b = 0;
90 u8 silence_rssi_c = 0;
91 u32 val;
92
93 /* "false_alarms" values below are cross-multiplications to assess the
94 * numbers of false alarms within the measured period of actual Rx
95 * (Rx is off when we're txing), vs the min/max expected false alarms
96 * (some should be expected if rx is sensitive enough) in a
97 * hypothetical listening period of 200 time units (TU), 204.8 msec:
98 *
99 * MIN_FA/fixed-time < false_alarms/actual-rx-time < MAX_FA/beacon-time
100 *
101 * */
102 u32 false_alarms = norm_fa * 200 * 1024;
103 u32 max_false_alarms = MAX_FA_CCK * rx_enable_time;
104 u32 min_false_alarms = MIN_FA_CCK * rx_enable_time;
105 struct iwl_sensitivity_data *data = NULL;
106 const struct iwl_sensitivity_ranges *ranges = priv->hw_params.sens;
107
108 data = &(priv->sensitivity_data);
109
110 data->nrg_auto_corr_silence_diff = 0;
111
112 /* Find max silence rssi among all 3 receivers.
113 * This is background noise, which may include transmissions from other
114 * networks, measured during silence before our network's beacon */
115 silence_rssi_a = (u8)((rx_info->beacon_silence_rssi_a &
116 ALL_BAND_FILTER) >> 8);
117 silence_rssi_b = (u8)((rx_info->beacon_silence_rssi_b &
118 ALL_BAND_FILTER) >> 8);
119 silence_rssi_c = (u8)((rx_info->beacon_silence_rssi_c &
120 ALL_BAND_FILTER) >> 8);
121
122 val = max(silence_rssi_b, silence_rssi_c);
123 max_silence_rssi = max(silence_rssi_a, (u8) val);
124
125 /* Store silence rssi in 20-beacon history table */
126 data->nrg_silence_rssi[data->nrg_silence_idx] = max_silence_rssi;
127 data->nrg_silence_idx++;
128 if (data->nrg_silence_idx >= NRG_NUM_PREV_STAT_L)
129 data->nrg_silence_idx = 0;
130
131 /* Find max silence rssi across 20 beacon history */
132 for (i = 0; i < NRG_NUM_PREV_STAT_L; i++) {
133 val = data->nrg_silence_rssi[i];
134 silence_ref = max(silence_ref, val);
135 }
136 IWL_DEBUG_CALIB("silence a %u, b %u, c %u, 20-bcn max %u\n",
137 silence_rssi_a, silence_rssi_b, silence_rssi_c,
138 silence_ref);
139
140 /* Find max rx energy (min value!) among all 3 receivers,
141 * measured during beacon frame.
142 * Save it in 10-beacon history table. */
143 i = data->nrg_energy_idx;
144 val = min(rx_info->beacon_energy_b, rx_info->beacon_energy_c);
145 data->nrg_value[i] = min(rx_info->beacon_energy_a, val);
146
147 data->nrg_energy_idx++;
148 if (data->nrg_energy_idx >= 10)
149 data->nrg_energy_idx = 0;
150
151 /* Find min rx energy (max value) across 10 beacon history.
152 * This is the minimum signal level that we want to receive well.
153 * Add backoff (margin so we don't miss slightly lower energy frames).
154 * This establishes an upper bound (min value) for energy threshold. */
155 max_nrg_cck = data->nrg_value[0];
156 for (i = 1; i < 10; i++)
157 max_nrg_cck = (u32) max(max_nrg_cck, (data->nrg_value[i]));
158 max_nrg_cck += 6;
159
160 IWL_DEBUG_CALIB("rx energy a %u, b %u, c %u, 10-bcn max/min %u\n",
161 rx_info->beacon_energy_a, rx_info->beacon_energy_b,
162 rx_info->beacon_energy_c, max_nrg_cck - 6);
163
164 /* Count number of consecutive beacons with fewer-than-desired
165 * false alarms. */
166 if (false_alarms < min_false_alarms)
167 data->num_in_cck_no_fa++;
168 else
169 data->num_in_cck_no_fa = 0;
170 IWL_DEBUG_CALIB("consecutive bcns with few false alarms = %u\n",
171 data->num_in_cck_no_fa);
172
173 /* If we got too many false alarms this time, reduce sensitivity */
174 if ((false_alarms > max_false_alarms) &&
175 (data->auto_corr_cck > AUTO_CORR_MAX_TH_CCK)) {
176 IWL_DEBUG_CALIB("norm FA %u > max FA %u\n",
177 false_alarms, max_false_alarms);
178 IWL_DEBUG_CALIB("... reducing sensitivity\n");
179 data->nrg_curr_state = IWL_FA_TOO_MANY;
180 /* Store for "fewer than desired" on later beacon */
181 data->nrg_silence_ref = silence_ref;
182
183 /* increase energy threshold (reduce nrg value)
184 * to decrease sensitivity */
185 if (data->nrg_th_cck >
186 (ranges->max_nrg_cck + NRG_STEP_CCK))
187 data->nrg_th_cck = data->nrg_th_cck
188 - NRG_STEP_CCK;
189 else
190 data->nrg_th_cck = ranges->max_nrg_cck;
191 /* Else if we got fewer than desired, increase sensitivity */
192 } else if (false_alarms < min_false_alarms) {
193 data->nrg_curr_state = IWL_FA_TOO_FEW;
194
195 /* Compare silence level with silence level for most recent
196 * healthy number or too many false alarms */
197 data->nrg_auto_corr_silence_diff = (s32)data->nrg_silence_ref -
198 (s32)silence_ref;
199
200 IWL_DEBUG_CALIB("norm FA %u < min FA %u, silence diff %d\n",
201 false_alarms, min_false_alarms,
202 data->nrg_auto_corr_silence_diff);
203
204 /* Increase value to increase sensitivity, but only if:
205 * 1a) previous beacon did *not* have *too many* false alarms
206 * 1b) AND there's a significant difference in Rx levels
207 * from a previous beacon with too many, or healthy # FAs
208 * OR 2) We've seen a lot of beacons (100) with too few
209 * false alarms */
210 if ((data->nrg_prev_state != IWL_FA_TOO_MANY) &&
211 ((data->nrg_auto_corr_silence_diff > NRG_DIFF) ||
212 (data->num_in_cck_no_fa > MAX_NUMBER_CCK_NO_FA))) {
213
214 IWL_DEBUG_CALIB("... increasing sensitivity\n");
215 /* Increase nrg value to increase sensitivity */
216 val = data->nrg_th_cck + NRG_STEP_CCK;
217 data->nrg_th_cck = min((u32)ranges->min_nrg_cck, val);
218 } else {
219 IWL_DEBUG_CALIB("... but not changing sensitivity\n");
220 }
221
222 /* Else we got a healthy number of false alarms, keep status quo */
223 } else {
224 IWL_DEBUG_CALIB(" FA in safe zone\n");
225 data->nrg_curr_state = IWL_FA_GOOD_RANGE;
226
227 /* Store for use in "fewer than desired" with later beacon */
228 data->nrg_silence_ref = silence_ref;
229
230 /* If previous beacon had too many false alarms,
231 * give it some extra margin by reducing sensitivity again
232 * (but don't go below measured energy of desired Rx) */
233 if (IWL_FA_TOO_MANY == data->nrg_prev_state) {
234 IWL_DEBUG_CALIB("... increasing margin\n");
235 if (data->nrg_th_cck > (max_nrg_cck + NRG_MARGIN))
236 data->nrg_th_cck -= NRG_MARGIN;
237 else
238 data->nrg_th_cck = max_nrg_cck;
239 }
240 }
241
242 /* Make sure the energy threshold does not go above the measured
243 * energy of the desired Rx signals (reduced by backoff margin),
244 * or else we might start missing Rx frames.
245 * Lower value is higher energy, so we use max()!
246 */
247 data->nrg_th_cck = max(max_nrg_cck, data->nrg_th_cck);
248 IWL_DEBUG_CALIB("new nrg_th_cck %u\n", data->nrg_th_cck);
249
250 data->nrg_prev_state = data->nrg_curr_state;
251
252 /* Auto-correlation CCK algorithm */
253 if (false_alarms > min_false_alarms) {
254
255 /* increase auto_corr values to decrease sensitivity
256 * so the DSP won't be disturbed by the noise
257 */
258 if (data->auto_corr_cck < AUTO_CORR_MAX_TH_CCK)
259 data->auto_corr_cck = AUTO_CORR_MAX_TH_CCK + 1;
260 else {
261 val = data->auto_corr_cck + AUTO_CORR_STEP_CCK;
262 data->auto_corr_cck =
263 min((u32)ranges->auto_corr_max_cck, val);
264 }
265 val = data->auto_corr_cck_mrc + AUTO_CORR_STEP_CCK;
266 data->auto_corr_cck_mrc =
267 min((u32)ranges->auto_corr_max_cck_mrc, val);
268 } else if ((false_alarms < min_false_alarms) &&
269 ((data->nrg_auto_corr_silence_diff > NRG_DIFF) ||
270 (data->num_in_cck_no_fa > MAX_NUMBER_CCK_NO_FA))) {
271
272 /* Decrease auto_corr values to increase sensitivity */
273 val = data->auto_corr_cck - AUTO_CORR_STEP_CCK;
274 data->auto_corr_cck =
275 max((u32)ranges->auto_corr_min_cck, val);
276 val = data->auto_corr_cck_mrc - AUTO_CORR_STEP_CCK;
277 data->auto_corr_cck_mrc =
278 max((u32)ranges->auto_corr_min_cck_mrc, val);
279 }
280
281 return 0;
282}
283
284
285static int iwl_sens_auto_corr_ofdm(struct iwl_priv *priv,
286 u32 norm_fa,
287 u32 rx_enable_time)
288{
289 u32 val;
290 u32 false_alarms = norm_fa * 200 * 1024;
291 u32 max_false_alarms = MAX_FA_OFDM * rx_enable_time;
292 u32 min_false_alarms = MIN_FA_OFDM * rx_enable_time;
293 struct iwl_sensitivity_data *data = NULL;
294 const struct iwl_sensitivity_ranges *ranges = priv->hw_params.sens;
295
296 data = &(priv->sensitivity_data);
297
298 /* If we got too many false alarms this time, reduce sensitivity */
299 if (false_alarms > max_false_alarms) {
300
301 IWL_DEBUG_CALIB("norm FA %u > max FA %u)\n",
302 false_alarms, max_false_alarms);
303
304 val = data->auto_corr_ofdm + AUTO_CORR_STEP_OFDM;
305 data->auto_corr_ofdm =
306 min((u32)ranges->auto_corr_max_ofdm, val);
307
308 val = data->auto_corr_ofdm_mrc + AUTO_CORR_STEP_OFDM;
309 data->auto_corr_ofdm_mrc =
310 min((u32)ranges->auto_corr_max_ofdm_mrc, val);
311
312 val = data->auto_corr_ofdm_x1 + AUTO_CORR_STEP_OFDM;
313 data->auto_corr_ofdm_x1 =
314 min((u32)ranges->auto_corr_max_ofdm_x1, val);
315
316 val = data->auto_corr_ofdm_mrc_x1 + AUTO_CORR_STEP_OFDM;
317 data->auto_corr_ofdm_mrc_x1 =
318 min((u32)ranges->auto_corr_max_ofdm_mrc_x1, val);
319 }
320
321 /* Else if we got fewer than desired, increase sensitivity */
322 else if (false_alarms < min_false_alarms) {
323
324 IWL_DEBUG_CALIB("norm FA %u < min FA %u\n",
325 false_alarms, min_false_alarms);
326
327 val = data->auto_corr_ofdm - AUTO_CORR_STEP_OFDM;
328 data->auto_corr_ofdm =
329 max((u32)ranges->auto_corr_min_ofdm, val);
330
331 val = data->auto_corr_ofdm_mrc - AUTO_CORR_STEP_OFDM;
332 data->auto_corr_ofdm_mrc =
333 max((u32)ranges->auto_corr_min_ofdm_mrc, val);
334
335 val = data->auto_corr_ofdm_x1 - AUTO_CORR_STEP_OFDM;
336 data->auto_corr_ofdm_x1 =
337 max((u32)ranges->auto_corr_min_ofdm_x1, val);
338
339 val = data->auto_corr_ofdm_mrc_x1 - AUTO_CORR_STEP_OFDM;
340 data->auto_corr_ofdm_mrc_x1 =
341 max((u32)ranges->auto_corr_min_ofdm_mrc_x1, val);
342 } else {
343 IWL_DEBUG_CALIB("min FA %u < norm FA %u < max FA %u OK\n",
344 min_false_alarms, false_alarms, max_false_alarms);
345 }
346 return 0;
347}
348
349/* Prepare a SENSITIVITY_CMD, send to uCode if values have changed */
350static int iwl_sensitivity_write(struct iwl_priv *priv)
351{
352 int ret = 0;
353 struct iwl_sensitivity_cmd cmd ;
354 struct iwl_sensitivity_data *data = NULL;
355 struct iwl_host_cmd cmd_out = {
356 .id = SENSITIVITY_CMD,
357 .len = sizeof(struct iwl_sensitivity_cmd),
358 .meta.flags = CMD_ASYNC,
359 .data = &cmd,
360 };
361
362 data = &(priv->sensitivity_data);
363
364 memset(&cmd, 0, sizeof(cmd));
365
366 cmd.table[HD_AUTO_CORR32_X4_TH_ADD_MIN_INDEX] =
367 cpu_to_le16((u16)data->auto_corr_ofdm);
368 cmd.table[HD_AUTO_CORR32_X4_TH_ADD_MIN_MRC_INDEX] =
369 cpu_to_le16((u16)data->auto_corr_ofdm_mrc);
370 cmd.table[HD_AUTO_CORR32_X1_TH_ADD_MIN_INDEX] =
371 cpu_to_le16((u16)data->auto_corr_ofdm_x1);
372 cmd.table[HD_AUTO_CORR32_X1_TH_ADD_MIN_MRC_INDEX] =
373 cpu_to_le16((u16)data->auto_corr_ofdm_mrc_x1);
374
375 cmd.table[HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX] =
376 cpu_to_le16((u16)data->auto_corr_cck);
377 cmd.table[HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX] =
378 cpu_to_le16((u16)data->auto_corr_cck_mrc);
379
380 cmd.table[HD_MIN_ENERGY_CCK_DET_INDEX] =
381 cpu_to_le16((u16)data->nrg_th_cck);
382 cmd.table[HD_MIN_ENERGY_OFDM_DET_INDEX] =
383 cpu_to_le16((u16)data->nrg_th_ofdm);
384
385 cmd.table[HD_BARKER_CORR_TH_ADD_MIN_INDEX] =
386 __constant_cpu_to_le16(190);
387 cmd.table[HD_BARKER_CORR_TH_ADD_MIN_MRC_INDEX] =
388 __constant_cpu_to_le16(390);
389 cmd.table[HD_OFDM_ENERGY_TH_IN_INDEX] =
390 __constant_cpu_to_le16(62);
391
392 IWL_DEBUG_CALIB("ofdm: ac %u mrc %u x1 %u mrc_x1 %u thresh %u\n",
393 data->auto_corr_ofdm, data->auto_corr_ofdm_mrc,
394 data->auto_corr_ofdm_x1, data->auto_corr_ofdm_mrc_x1,
395 data->nrg_th_ofdm);
396
397 IWL_DEBUG_CALIB("cck: ac %u mrc %u thresh %u\n",
398 data->auto_corr_cck, data->auto_corr_cck_mrc,
399 data->nrg_th_cck);
400
401 /* Update uCode's "work" table, and copy it to DSP */
402 cmd.control = SENSITIVITY_CMD_CONTROL_WORK_TABLE;
403
404 /* Don't send command to uCode if nothing has changed */
405 if (!memcmp(&cmd.table[0], &(priv->sensitivity_tbl[0]),
406 sizeof(u16)*HD_TABLE_SIZE)) {
407 IWL_DEBUG_CALIB("No change in SENSITIVITY_CMD\n");
408 return 0;
409 }
410
411 /* Copy table for comparison next time */
412 memcpy(&(priv->sensitivity_tbl[0]), &(cmd.table[0]),
413 sizeof(u16)*HD_TABLE_SIZE);
414
415 ret = iwl_send_cmd(priv, &cmd_out);
416 if (ret)
417 IWL_ERROR("SENSITIVITY_CMD failed\n");
418
419 return ret;
420}
421
422void iwl_init_sensitivity(struct iwl_priv *priv)
423{
424 int ret = 0;
425 int i;
426 struct iwl_sensitivity_data *data = NULL;
427 const struct iwl_sensitivity_ranges *ranges = priv->hw_params.sens;
428
429 IWL_DEBUG_CALIB("Start iwl_init_sensitivity\n");
430
431 /* Clear driver's sensitivity algo data */
432 data = &(priv->sensitivity_data);
433
434 if (ranges == NULL)
435 /* can happen if IWLWIFI_RUN_TIME_CALIB is selected
436 * but no IWLXXXX_RUN_TIME_CALIB for specific is selected */
437 return;
438
439 memset(data, 0, sizeof(struct iwl_sensitivity_data));
440
441 data->num_in_cck_no_fa = 0;
442 data->nrg_curr_state = IWL_FA_TOO_MANY;
443 data->nrg_prev_state = IWL_FA_TOO_MANY;
444 data->nrg_silence_ref = 0;
445 data->nrg_silence_idx = 0;
446 data->nrg_energy_idx = 0;
447
448 for (i = 0; i < 10; i++)
449 data->nrg_value[i] = 0;
450
451 for (i = 0; i < NRG_NUM_PREV_STAT_L; i++)
452 data->nrg_silence_rssi[i] = 0;
453
454 data->auto_corr_ofdm = 90;
455 data->auto_corr_ofdm_mrc = ranges->auto_corr_min_ofdm_mrc;
456 data->auto_corr_ofdm_x1 = ranges->auto_corr_min_ofdm_x1;
457 data->auto_corr_ofdm_mrc_x1 = ranges->auto_corr_min_ofdm_mrc_x1;
458 data->auto_corr_cck = AUTO_CORR_CCK_MIN_VAL_DEF;
459 data->auto_corr_cck_mrc = ranges->auto_corr_min_cck_mrc;
460 data->nrg_th_cck = ranges->nrg_th_cck;
461 data->nrg_th_ofdm = ranges->nrg_th_ofdm;
462
463 data->last_bad_plcp_cnt_ofdm = 0;
464 data->last_fa_cnt_ofdm = 0;
465 data->last_bad_plcp_cnt_cck = 0;
466 data->last_fa_cnt_cck = 0;
467
468 ret |= iwl_sensitivity_write(priv);
469 IWL_DEBUG_CALIB("<<return 0x%X\n", ret);
470}
471EXPORT_SYMBOL(iwl_init_sensitivity);
472
473void iwl_sensitivity_calibration(struct iwl_priv *priv,
474 struct iwl4965_notif_statistics *resp)
475{
476 u32 rx_enable_time;
477 u32 fa_cck;
478 u32 fa_ofdm;
479 u32 bad_plcp_cck;
480 u32 bad_plcp_ofdm;
481 u32 norm_fa_ofdm;
482 u32 norm_fa_cck;
483 struct iwl_sensitivity_data *data = NULL;
484 struct statistics_rx_non_phy *rx_info = &(resp->rx.general);
485 struct statistics_rx *statistics = &(resp->rx);
486 unsigned long flags;
487 struct statistics_general_data statis;
488
489 data = &(priv->sensitivity_data);
490
491 if (!iwl_is_associated(priv)) {
492 IWL_DEBUG_CALIB("<< - not associated\n");
493 return;
494 }
495
496 spin_lock_irqsave(&priv->lock, flags);
497 if (rx_info->interference_data_flag != INTERFERENCE_DATA_AVAILABLE) {
498 IWL_DEBUG_CALIB("<< invalid data.\n");
499 spin_unlock_irqrestore(&priv->lock, flags);
500 return;
501 }
502
503 /* Extract Statistics: */
504 rx_enable_time = le32_to_cpu(rx_info->channel_load);
505 fa_cck = le32_to_cpu(statistics->cck.false_alarm_cnt);
506 fa_ofdm = le32_to_cpu(statistics->ofdm.false_alarm_cnt);
507 bad_plcp_cck = le32_to_cpu(statistics->cck.plcp_err);
508 bad_plcp_ofdm = le32_to_cpu(statistics->ofdm.plcp_err);
509
510 statis.beacon_silence_rssi_a =
511 le32_to_cpu(statistics->general.beacon_silence_rssi_a);
512 statis.beacon_silence_rssi_b =
513 le32_to_cpu(statistics->general.beacon_silence_rssi_b);
514 statis.beacon_silence_rssi_c =
515 le32_to_cpu(statistics->general.beacon_silence_rssi_c);
516 statis.beacon_energy_a =
517 le32_to_cpu(statistics->general.beacon_energy_a);
518 statis.beacon_energy_b =
519 le32_to_cpu(statistics->general.beacon_energy_b);
520 statis.beacon_energy_c =
521 le32_to_cpu(statistics->general.beacon_energy_c);
522
523 spin_unlock_irqrestore(&priv->lock, flags);
524
525 IWL_DEBUG_CALIB("rx_enable_time = %u usecs\n", rx_enable_time);
526
527 if (!rx_enable_time) {
528 IWL_DEBUG_CALIB("<< RX Enable Time == 0! \n");
529 return;
530 }
531
532 /* These statistics increase monotonically, and do not reset
533 * at each beacon. Calculate difference from last value, or just
534 * use the new statistics value if it has reset or wrapped around. */
535 if (data->last_bad_plcp_cnt_cck > bad_plcp_cck)
536 data->last_bad_plcp_cnt_cck = bad_plcp_cck;
537 else {
538 bad_plcp_cck -= data->last_bad_plcp_cnt_cck;
539 data->last_bad_plcp_cnt_cck += bad_plcp_cck;
540 }
541
542 if (data->last_bad_plcp_cnt_ofdm > bad_plcp_ofdm)
543 data->last_bad_plcp_cnt_ofdm = bad_plcp_ofdm;
544 else {
545 bad_plcp_ofdm -= data->last_bad_plcp_cnt_ofdm;
546 data->last_bad_plcp_cnt_ofdm += bad_plcp_ofdm;
547 }
548
549 if (data->last_fa_cnt_ofdm > fa_ofdm)
550 data->last_fa_cnt_ofdm = fa_ofdm;
551 else {
552 fa_ofdm -= data->last_fa_cnt_ofdm;
553 data->last_fa_cnt_ofdm += fa_ofdm;
554 }
555
556 if (data->last_fa_cnt_cck > fa_cck)
557 data->last_fa_cnt_cck = fa_cck;
558 else {
559 fa_cck -= data->last_fa_cnt_cck;
560 data->last_fa_cnt_cck += fa_cck;
561 }
562
563 /* Total aborted signal locks */
564 norm_fa_ofdm = fa_ofdm + bad_plcp_ofdm;
565 norm_fa_cck = fa_cck + bad_plcp_cck;
566
567 IWL_DEBUG_CALIB("cck: fa %u badp %u ofdm: fa %u badp %u\n", fa_cck,
568 bad_plcp_cck, fa_ofdm, bad_plcp_ofdm);
569
570 iwl_sens_auto_corr_ofdm(priv, norm_fa_ofdm, rx_enable_time);
571 iwl_sens_energy_cck(priv, norm_fa_cck, rx_enable_time, &statis);
572 iwl_sensitivity_write(priv);
573
574 return;
575}
576EXPORT_SYMBOL(iwl_sensitivity_calibration);
577
578/*
579 * Accumulate 20 beacons of signal and noise statistics for each of
580 * 3 receivers/antennas/rx-chains, then figure out:
581 * 1) Which antennas are connected.
582 * 2) Differential rx gain settings to balance the 3 receivers.
583 */
584void iwl_chain_noise_calibration(struct iwl_priv *priv,
585 struct iwl4965_notif_statistics *stat_resp)
586{
587 struct iwl_chain_noise_data *data = NULL;
588
589 u32 chain_noise_a;
590 u32 chain_noise_b;
591 u32 chain_noise_c;
592 u32 chain_sig_a;
593 u32 chain_sig_b;
594 u32 chain_sig_c;
595 u32 average_sig[NUM_RX_CHAINS] = {INITIALIZATION_VALUE};
596 u32 average_noise[NUM_RX_CHAINS] = {INITIALIZATION_VALUE};
597 u32 max_average_sig;
598 u16 max_average_sig_antenna_i;
599 u32 min_average_noise = MIN_AVERAGE_NOISE_MAX_VALUE;
600 u16 min_average_noise_antenna_i = INITIALIZATION_VALUE;
601 u16 i = 0;
602 u16 rxon_chnum = INITIALIZATION_VALUE;
603 u16 stat_chnum = INITIALIZATION_VALUE;
604 u8 rxon_band24;
605 u8 stat_band24;
606 u32 active_chains = 0;
607 u8 num_tx_chains;
608 unsigned long flags;
609 struct statistics_rx_non_phy *rx_info = &(stat_resp->rx.general);
610
611 data = &(priv->chain_noise_data);
612
613 /* Accumulate just the first 20 beacons after the first association,
614 * then we're done forever. */
615 if (data->state != IWL_CHAIN_NOISE_ACCUMULATE) {
616 if (data->state == IWL_CHAIN_NOISE_ALIVE)
617 IWL_DEBUG_CALIB("Wait for noise calib reset\n");
618 return;
619 }
620
621 spin_lock_irqsave(&priv->lock, flags);
622 if (rx_info->interference_data_flag != INTERFERENCE_DATA_AVAILABLE) {
623 IWL_DEBUG_CALIB(" << Interference data unavailable\n");
624 spin_unlock_irqrestore(&priv->lock, flags);
625 return;
626 }
627
628 rxon_band24 = !!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK);
629 rxon_chnum = le16_to_cpu(priv->staging_rxon.channel);
630 stat_band24 = !!(stat_resp->flag & STATISTICS_REPLY_FLG_BAND_24G_MSK);
631 stat_chnum = le32_to_cpu(stat_resp->flag) >> 16;
632
633 /* Make sure we accumulate data for just the associated channel
634 * (even if scanning). */
635 if ((rxon_chnum != stat_chnum) || (rxon_band24 != stat_band24)) {
636 IWL_DEBUG_CALIB("Stats not from chan=%d, band24=%d\n",
637 rxon_chnum, rxon_band24);
638 spin_unlock_irqrestore(&priv->lock, flags);
639 return;
640 }
641
642 /* Accumulate beacon statistics values across 20 beacons */
643 chain_noise_a = le32_to_cpu(rx_info->beacon_silence_rssi_a) &
644 IN_BAND_FILTER;
645 chain_noise_b = le32_to_cpu(rx_info->beacon_silence_rssi_b) &
646 IN_BAND_FILTER;
647 chain_noise_c = le32_to_cpu(rx_info->beacon_silence_rssi_c) &
648 IN_BAND_FILTER;
649
650 chain_sig_a = le32_to_cpu(rx_info->beacon_rssi_a) & IN_BAND_FILTER;
651 chain_sig_b = le32_to_cpu(rx_info->beacon_rssi_b) & IN_BAND_FILTER;
652 chain_sig_c = le32_to_cpu(rx_info->beacon_rssi_c) & IN_BAND_FILTER;
653
654 spin_unlock_irqrestore(&priv->lock, flags);
655
656 data->beacon_count++;
657
658 data->chain_noise_a = (chain_noise_a + data->chain_noise_a);
659 data->chain_noise_b = (chain_noise_b + data->chain_noise_b);
660 data->chain_noise_c = (chain_noise_c + data->chain_noise_c);
661
662 data->chain_signal_a = (chain_sig_a + data->chain_signal_a);
663 data->chain_signal_b = (chain_sig_b + data->chain_signal_b);
664 data->chain_signal_c = (chain_sig_c + data->chain_signal_c);
665
666 IWL_DEBUG_CALIB("chan=%d, band24=%d, beacon=%d\n",
667 rxon_chnum, rxon_band24, data->beacon_count);
668 IWL_DEBUG_CALIB("chain_sig: a %d b %d c %d\n",
669 chain_sig_a, chain_sig_b, chain_sig_c);
670 IWL_DEBUG_CALIB("chain_noise: a %d b %d c %d\n",
671 chain_noise_a, chain_noise_b, chain_noise_c);
672
673 /* If this is the 20th beacon, determine:
674 * 1) Disconnected antennas (using signal strengths)
675 * 2) Differential gain (using silence noise) to balance receivers */
676 if (data->beacon_count != CAL_NUM_OF_BEACONS)
677 return;
678
679 /* Analyze signal for disconnected antenna */
680 average_sig[0] = (data->chain_signal_a) / CAL_NUM_OF_BEACONS;
681 average_sig[1] = (data->chain_signal_b) / CAL_NUM_OF_BEACONS;
682 average_sig[2] = (data->chain_signal_c) / CAL_NUM_OF_BEACONS;
683
684 if (average_sig[0] >= average_sig[1]) {
685 max_average_sig = average_sig[0];
686 max_average_sig_antenna_i = 0;
687 active_chains = (1 << max_average_sig_antenna_i);
688 } else {
689 max_average_sig = average_sig[1];
690 max_average_sig_antenna_i = 1;
691 active_chains = (1 << max_average_sig_antenna_i);
692 }
693
694 if (average_sig[2] >= max_average_sig) {
695 max_average_sig = average_sig[2];
696 max_average_sig_antenna_i = 2;
697 active_chains = (1 << max_average_sig_antenna_i);
698 }
699
700 IWL_DEBUG_CALIB("average_sig: a %d b %d c %d\n",
701 average_sig[0], average_sig[1], average_sig[2]);
702 IWL_DEBUG_CALIB("max_average_sig = %d, antenna %d\n",
703 max_average_sig, max_average_sig_antenna_i);
704
705 /* Compare signal strengths for all 3 receivers. */
706 for (i = 0; i < NUM_RX_CHAINS; i++) {
707 if (i != max_average_sig_antenna_i) {
708 s32 rssi_delta = (max_average_sig - average_sig[i]);
709
710 /* If signal is very weak, compared with
711 * strongest, mark it as disconnected. */
712 if (rssi_delta > MAXIMUM_ALLOWED_PATHLOSS)
713 data->disconn_array[i] = 1;
714 else
715 active_chains |= (1 << i);
716 IWL_DEBUG_CALIB("i = %d rssiDelta = %d "
717 "disconn_array[i] = %d\n",
718 i, rssi_delta, data->disconn_array[i]);
719 }
720 }
721
722 num_tx_chains = 0;
723 for (i = 0; i < NUM_RX_CHAINS; i++) {
724 /* loops on all the bits of
725 * priv->hw_setting.valid_tx_ant */
726 u8 ant_msk = (1 << i);
727 if (!(priv->hw_params.valid_tx_ant & ant_msk))
728 continue;
729
730 num_tx_chains++;
731 if (data->disconn_array[i] == 0)
732 /* there is a Tx antenna connected */
733 break;
734 if (num_tx_chains == priv->hw_params.tx_chains_num &&
735 data->disconn_array[i]) {
736 /* This is the last TX antenna and is also
737 * disconnected connect it anyway */
738 data->disconn_array[i] = 0;
739 active_chains |= ant_msk;
740 IWL_DEBUG_CALIB("All Tx chains are disconnected W/A - "
741 "declare %d as connected\n", i);
742 break;
743 }
744 }
745
746 IWL_DEBUG_CALIB("active_chains (bitwise) = 0x%x\n",
747 active_chains);
748
749 /* Save for use within RXON, TX, SCAN commands, etc. */
750 /*priv->valid_antenna = active_chains;*/
751 /*FIXME: should be reflected in RX chains in RXON */
752
753 /* Analyze noise for rx balance */
754 average_noise[0] = ((data->chain_noise_a)/CAL_NUM_OF_BEACONS);
755 average_noise[1] = ((data->chain_noise_b)/CAL_NUM_OF_BEACONS);
756 average_noise[2] = ((data->chain_noise_c)/CAL_NUM_OF_BEACONS);
757
758 for (i = 0; i < NUM_RX_CHAINS; i++) {
759 if (!(data->disconn_array[i]) &&
760 (average_noise[i] <= min_average_noise)) {
761 /* This means that chain i is active and has
762 * lower noise values so far: */
763 min_average_noise = average_noise[i];
764 min_average_noise_antenna_i = i;
765 }
766 }
767
768 IWL_DEBUG_CALIB("average_noise: a %d b %d c %d\n",
769 average_noise[0], average_noise[1],
770 average_noise[2]);
771
772 IWL_DEBUG_CALIB("min_average_noise = %d, antenna %d\n",
773 min_average_noise, min_average_noise_antenna_i);
774
775 priv->cfg->ops->utils->gain_computation(priv, average_noise,
776 min_average_noise_antenna_i, min_average_noise);
777}
778EXPORT_SYMBOL(iwl_chain_noise_calibration);
779
diff --git a/drivers/net/wireless/iwlwifi/iwl-calib.h b/drivers/net/wireless/iwlwifi/iwl-calib.h
new file mode 100644
index 000000000000..933b0b0a797b
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-calib.h
@@ -0,0 +1,104 @@
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2008 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
26 *
27 * Contact Information:
28 * Tomas Winkler <tomas.winkler@intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2005 - 2008 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *****************************************************************************/
62#ifndef __iwl_calib_h__
63#define __iwl_calib_h__
64
65#include <linux/kernel.h>
66#include <linux/module.h>
67#include <linux/version.h>
68
69#include <net/mac80211.h>
70#include "iwl-eeprom.h"
71#include "iwl-core.h"
72#include "iwl-dev.h"
73
74#ifdef CONFIG_IWLWIFI_RUN_TIME_CALIB
75void iwl_chain_noise_calibration(struct iwl_priv *priv,
76 struct iwl4965_notif_statistics *stat_resp);
77void iwl_sensitivity_calibration(struct iwl_priv *priv,
78 struct iwl4965_notif_statistics *resp);
79
80void iwl_init_sensitivity(struct iwl_priv *priv);
81
82static inline void iwl_chain_noise_reset(struct iwl_priv *priv)
83{
84 if (priv->cfg->ops->utils->chain_noise_reset)
85 priv->cfg->ops->utils->chain_noise_reset(priv);
86}
87#else
88static inline void iwl_chain_noise_calibration(struct iwl_priv *priv,
89 struct iwl4965_notif_statistics *stat_resp)
90{
91}
92static inline void iwl_sensitivity_calibration(struct iwl_priv *priv,
93 struct iwl4965_notif_statistics *resp)
94{
95}
96static inline void iwl_init_sensitivity(struct iwl_priv *priv)
97{
98}
99static inline void iwl_chain_noise_reset(struct iwl_priv *priv)
100{
101}
102#endif
103
104#endif /* __iwl_calib_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965-commands.h b/drivers/net/wireless/iwlwifi/iwl-commands.h
index 3bcd107e2d71..5afa7b79b59d 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965-commands.h
+++ b/drivers/net/wireless/iwlwifi/iwl-commands.h
@@ -61,9 +61,9 @@
61 * 61 *
62 *****************************************************************************/ 62 *****************************************************************************/
63/* 63/*
64 * Please use this file (iwl-4965-commands.h) only for uCode API definitions. 64 * Please use this file (iwl-commands.h) only for uCode API definitions.
65 * Please use iwl-4965-hw.h for hardware-related definitions. 65 * Please use iwl-4965-hw.h for hardware-related definitions.
66 * Please use iwl-4965.h for driver implementation definitions. 66 * Please use iwl-dev.h for driver implementation definitions.
67 */ 67 */
68 68
69#ifndef __iwl4965_commands_h__ 69#ifndef __iwl4965_commands_h__
@@ -269,10 +269,11 @@ struct iwl_cmd_header {
269 * 10 B active, A inactive 269 * 10 B active, A inactive
270 * 11 Both active 270 * 11 Both active
271 */ 271 */
272#define RATE_MCS_ANT_POS 14 272#define RATE_MCS_ANT_POS 14
273#define RATE_MCS_ANT_A_MSK 0x04000 273#define RATE_MCS_ANT_A_MSK 0x04000
274#define RATE_MCS_ANT_B_MSK 0x08000 274#define RATE_MCS_ANT_B_MSK 0x08000
275#define RATE_MCS_ANT_AB_MSK 0x0C000 275#define RATE_MCS_ANT_C_MSK 0x10000
276#define RATE_MCS_ANT_ABC_MSK 0x1C000
276 277
277 278
278/** 279/**
@@ -711,6 +712,8 @@ struct iwl4965_qosparam_cmd {
711#define IWL_STA_ID 2 712#define IWL_STA_ID 2
712#define IWL4965_BROADCAST_ID 31 713#define IWL4965_BROADCAST_ID 31
713#define IWL4965_STATION_COUNT 32 714#define IWL4965_STATION_COUNT 32
715#define IWL5000_BROADCAST_ID 15
716#define IWL5000_STATION_COUNT 16
714 717
715#define IWL_STATION_COUNT 32 /* MAX(3945,4965)*/ 718#define IWL_STATION_COUNT 32 /* MAX(3945,4965)*/
716#define IWL_INVALID_STATION 255 719#define IWL_INVALID_STATION 255
@@ -1100,6 +1103,14 @@ struct iwl4965_rx_mpdu_res_start {
1100#define TX_CMD_SEC_KEY128 0x08 1103#define TX_CMD_SEC_KEY128 0x08
1101 1104
1102/* 1105/*
1106 * security overhead sizes
1107 */
1108#define WEP_IV_LEN 4
1109#define WEP_ICV_LEN 4
1110#define CCMP_MIC_LEN 8
1111#define TKIP_ICV_LEN 4
1112
1113/*
1103 * 4965 uCode updates these Tx attempt count values in host DRAM. 1114 * 4965 uCode updates these Tx attempt count values in host DRAM.
1104 * Used for managing Tx retries when expecting block-acks. 1115 * Used for managing Tx retries when expecting block-acks.
1105 * Driver should set these fields to 0. 1116 * Driver should set these fields to 0.
@@ -1853,6 +1864,7 @@ struct iwl4965_spectrum_notification {
1853#define IWL_POWER_DRIVER_ALLOW_SLEEP_MSK __constant_cpu_to_le16(1 << 0) 1864#define IWL_POWER_DRIVER_ALLOW_SLEEP_MSK __constant_cpu_to_le16(1 << 0)
1854#define IWL_POWER_SLEEP_OVER_DTIM_MSK __constant_cpu_to_le16(1 << 2) 1865#define IWL_POWER_SLEEP_OVER_DTIM_MSK __constant_cpu_to_le16(1 << 2)
1855#define IWL_POWER_PCI_PM_MSK __constant_cpu_to_le16(1 << 3) 1866#define IWL_POWER_PCI_PM_MSK __constant_cpu_to_le16(1 << 3)
1867#define IWL_POWER_FAST_PD __constant_cpu_to_le16(1 << 4)
1856 1868
1857struct iwl4965_powertable_cmd { 1869struct iwl4965_powertable_cmd {
1858 __le16 flags; 1870 __le16 flags;
@@ -2559,7 +2571,7 @@ struct iwl4965_missed_beacon_notif {
2559 */ 2571 */
2560 2572
2561/* 2573/*
2562 * Table entries in SENSITIVITY_CMD (struct iwl4965_sensitivity_cmd) 2574 * Table entries in SENSITIVITY_CMD (struct iwl_sensitivity_cmd)
2563 */ 2575 */
2564#define HD_TABLE_SIZE (11) /* number of entries */ 2576#define HD_TABLE_SIZE (11) /* number of entries */
2565#define HD_MIN_ENERGY_CCK_DET_INDEX (0) /* table indexes */ 2577#define HD_MIN_ENERGY_CCK_DET_INDEX (0) /* table indexes */
@@ -2574,18 +2586,18 @@ struct iwl4965_missed_beacon_notif {
2574#define HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX (9) 2586#define HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX (9)
2575#define HD_OFDM_ENERGY_TH_IN_INDEX (10) 2587#define HD_OFDM_ENERGY_TH_IN_INDEX (10)
2576 2588
2577/* Control field in struct iwl4965_sensitivity_cmd */ 2589/* Control field in struct iwl_sensitivity_cmd */
2578#define SENSITIVITY_CMD_CONTROL_DEFAULT_TABLE __constant_cpu_to_le16(0) 2590#define SENSITIVITY_CMD_CONTROL_DEFAULT_TABLE __constant_cpu_to_le16(0)
2579#define SENSITIVITY_CMD_CONTROL_WORK_TABLE __constant_cpu_to_le16(1) 2591#define SENSITIVITY_CMD_CONTROL_WORK_TABLE __constant_cpu_to_le16(1)
2580 2592
2581/** 2593/**
2582 * struct iwl4965_sensitivity_cmd 2594 * struct iwl_sensitivity_cmd
2583 * @control: (1) updates working table, (0) updates default table 2595 * @control: (1) updates working table, (0) updates default table
2584 * @table: energy threshold values, use HD_* as index into table 2596 * @table: energy threshold values, use HD_* as index into table
2585 * 2597 *
2586 * Always use "1" in "control" to update uCode's working table and DSP. 2598 * Always use "1" in "control" to update uCode's working table and DSP.
2587 */ 2599 */
2588struct iwl4965_sensitivity_cmd { 2600struct iwl_sensitivity_cmd {
2589 __le16 control; /* always use "1" */ 2601 __le16 control; /* always use "1" */
2590 __le16 table[HD_TABLE_SIZE]; /* use HD_* as index */ 2602 __le16 table[HD_TABLE_SIZE]; /* use HD_* as index */
2591} __attribute__ ((packed)); 2603} __attribute__ ((packed));
@@ -2659,6 +2671,37 @@ struct iwl4965_calibration_cmd {
2659 u8 reserved1; 2671 u8 reserved1;
2660} __attribute__ ((packed)); 2672} __attribute__ ((packed));
2661 2673
2674/* Phy calibration command for 5000 series */
2675
2676enum {
2677 IWL5000_PHY_CALIBRATE_DC_CMD = 8,
2678 IWL5000_PHY_CALIBRATE_LO_CMD = 9,
2679 IWL5000_PHY_CALIBRATE_RX_BB_CMD = 10,
2680 IWL5000_PHY_CALIBRATE_TX_IQ_CMD = 11,
2681 IWL5000_PHY_CALIBRATE_RX_IQ_CMD = 12,
2682 IWL5000_PHY_CALIBRATION_NOISE_CMD = 13,
2683 IWL5000_PHY_CALIBRATE_AGC_TABLE_CMD = 14,
2684 IWL5000_PHY_CALIBRATE_CRYSTAL_FRQ_CMD = 15,
2685 IWL5000_PHY_CALIBRATE_BASE_BAND_CMD = 16,
2686 IWL5000_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD = 18,
2687 IWL5000_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD = 19,
2688};
2689
2690struct iwl5000_calibration_chain_noise_reset_cmd {
2691 u8 op_code; /* IWL5000_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD */
2692 u8 flags; /* not used */
2693 __le16 reserved;
2694} __attribute__ ((packed));
2695
2696struct iwl5000_calibration_chain_noise_gain_cmd {
2697 u8 op_code; /* IWL5000_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD */
2698 u8 flags; /* not used */
2699 __le16 reserved;
2700 u8 delta_gain_1;
2701 u8 delta_gain_2;
2702 __le16 reserved1;
2703} __attribute__ ((packed));
2704
2662/****************************************************************************** 2705/******************************************************************************
2663 * (12) 2706 * (12)
2664 * Miscellaneous Commands: 2707 * Miscellaneous Commands:
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.c b/drivers/net/wireless/iwlwifi/iwl-core.c
index 2dfd982d7d1f..c4b5c1a100f2 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.c
+++ b/drivers/net/wireless/iwlwifi/iwl-core.c
@@ -34,9 +34,11 @@
34struct iwl_priv; /* FIXME: remove */ 34struct iwl_priv; /* FIXME: remove */
35#include "iwl-debug.h" 35#include "iwl-debug.h"
36#include "iwl-eeprom.h" 36#include "iwl-eeprom.h"
37#include "iwl-4965.h" /* FIXME: remove */ 37#include "iwl-dev.h" /* FIXME: remove */
38#include "iwl-core.h" 38#include "iwl-core.h"
39#include "iwl-io.h"
39#include "iwl-rfkill.h" 40#include "iwl-rfkill.h"
41#include "iwl-power.h"
40 42
41 43
42MODULE_DESCRIPTION("iwl core"); 44MODULE_DESCRIPTION("iwl core");
@@ -49,6 +51,45 @@ u32 iwl_debug_level;
49EXPORT_SYMBOL(iwl_debug_level); 51EXPORT_SYMBOL(iwl_debug_level);
50#endif 52#endif
51 53
54#define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \
55 [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \
56 IWL_RATE_SISO_##s##M_PLCP, \
57 IWL_RATE_MIMO2_##s##M_PLCP,\
58 IWL_RATE_MIMO3_##s##M_PLCP,\
59 IWL_RATE_##r##M_IEEE, \
60 IWL_RATE_##ip##M_INDEX, \
61 IWL_RATE_##in##M_INDEX, \
62 IWL_RATE_##rp##M_INDEX, \
63 IWL_RATE_##rn##M_INDEX, \
64 IWL_RATE_##pp##M_INDEX, \
65 IWL_RATE_##np##M_INDEX }
66
67/*
68 * Parameter order:
69 * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
70 *
71 * If there isn't a valid next or previous rate then INV is used which
72 * maps to IWL_RATE_INVALID
73 *
74 */
75const struct iwl4965_rate_info iwl4965_rates[IWL_RATE_COUNT] = {
76 IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */
77 IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */
78 IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */
79 IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */
80 IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */
81 IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */
82 IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */
83 IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */
84 IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */
85 IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */
86 IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */
87 IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */
88 IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
89 /* FIXME:RS: ^^ should be INV (legacy) */
90};
91EXPORT_SYMBOL(iwl4965_rates);
92
52/* This function both allocates and initializes hw and priv. */ 93/* This function both allocates and initializes hw and priv. */
53struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg, 94struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg,
54 struct ieee80211_ops *hw_ops) 95 struct ieee80211_ops *hw_ops)
@@ -72,6 +113,14 @@ out:
72} 113}
73EXPORT_SYMBOL(iwl_alloc_all); 114EXPORT_SYMBOL(iwl_alloc_all);
74 115
116void iwl_hw_detect(struct iwl_priv *priv)
117{
118 priv->hw_rev = _iwl_read32(priv, CSR_HW_REV);
119 priv->hw_wa_rev = _iwl_read32(priv, CSR_HW_REV_WA_REG);
120 pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &priv->rev_id);
121}
122EXPORT_SYMBOL(iwl_hw_detect);
123
75/** 124/**
76 * iwlcore_clear_stations_table - Clear the driver's station table 125 * iwlcore_clear_stations_table - Clear the driver's station table
77 * 126 *
@@ -90,7 +139,7 @@ void iwlcore_clear_stations_table(struct iwl_priv *priv)
90} 139}
91EXPORT_SYMBOL(iwlcore_clear_stations_table); 140EXPORT_SYMBOL(iwlcore_clear_stations_table);
92 141
93void iwlcore_reset_qos(struct iwl_priv *priv) 142void iwl_reset_qos(struct iwl_priv *priv)
94{ 143{
95 u16 cw_min = 15; 144 u16 cw_min = 15;
96 u16 cw_max = 1023; 145 u16 cw_max = 1023;
@@ -176,7 +225,289 @@ void iwlcore_reset_qos(struct iwl_priv *priv)
176 225
177 spin_unlock_irqrestore(&priv->lock, flags); 226 spin_unlock_irqrestore(&priv->lock, flags);
178} 227}
179EXPORT_SYMBOL(iwlcore_reset_qos); 228EXPORT_SYMBOL(iwl_reset_qos);
229
230#ifdef CONFIG_IWL4965_HT
231static void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
232 struct ieee80211_ht_info *ht_info,
233 enum ieee80211_band band)
234{
235 ht_info->cap = 0;
236 memset(ht_info->supp_mcs_set, 0, 16);
237
238 ht_info->ht_supported = 1;
239
240 if (priv->hw_params.fat_channel & BIT(band)) {
241 ht_info->cap |= (u16)IEEE80211_HT_CAP_SUP_WIDTH;
242 ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_40;
243 ht_info->supp_mcs_set[4] = 0x01;
244 }
245 ht_info->cap |= (u16)IEEE80211_HT_CAP_GRN_FLD;
246 ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_20;
247 ht_info->cap |= (u16)(IEEE80211_HT_CAP_MIMO_PS &
248 (IWL_MIMO_PS_NONE << 2));
249
250 if (priv->cfg->mod_params->amsdu_size_8K)
251 ht_info->cap |= (u16)IEEE80211_HT_CAP_MAX_AMSDU;
252
253 ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
254 ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
255
256 ht_info->supp_mcs_set[0] = 0xFF;
257 if (priv->hw_params.tx_chains_num >= 2)
258 ht_info->supp_mcs_set[1] = 0xFF;
259 if (priv->hw_params.tx_chains_num >= 3)
260 ht_info->supp_mcs_set[2] = 0xFF;
261}
262#endif /* CONFIG_IWL4965_HT */
263
264static void iwlcore_init_hw_rates(struct iwl_priv *priv,
265 struct ieee80211_rate *rates)
266{
267 int i;
268
269 for (i = 0; i < IWL_RATE_COUNT; i++) {
270 rates[i].bitrate = iwl4965_rates[i].ieee * 5;
271 rates[i].hw_value = i; /* Rate scaling will work on indexes */
272 rates[i].hw_value_short = i;
273 rates[i].flags = 0;
274 if ((i > IWL_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
275 /*
276 * If CCK != 1M then set short preamble rate flag.
277 */
278 rates[i].flags |=
279 (iwl4965_rates[i].plcp == IWL_RATE_1M_PLCP) ?
280 0 : IEEE80211_RATE_SHORT_PREAMBLE;
281 }
282 }
283}
284
285/**
286 * iwlcore_init_geos - Initialize mac80211's geo/channel info based from eeprom
287 */
288static int iwlcore_init_geos(struct iwl_priv *priv)
289{
290 struct iwl_channel_info *ch;
291 struct ieee80211_supported_band *sband;
292 struct ieee80211_channel *channels;
293 struct ieee80211_channel *geo_ch;
294 struct ieee80211_rate *rates;
295 int i = 0;
296
297 if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
298 priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
299 IWL_DEBUG_INFO("Geography modes already initialized.\n");
300 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
301 return 0;
302 }
303
304 channels = kzalloc(sizeof(struct ieee80211_channel) *
305 priv->channel_count, GFP_KERNEL);
306 if (!channels)
307 return -ENOMEM;
308
309 rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)),
310 GFP_KERNEL);
311 if (!rates) {
312 kfree(channels);
313 return -ENOMEM;
314 }
315
316 /* 5.2GHz channels start after the 2.4GHz channels */
317 sband = &priv->bands[IEEE80211_BAND_5GHZ];
318 sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
319 /* just OFDM */
320 sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
321 sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE;
322
323 iwlcore_init_ht_hw_capab(priv, &sband->ht_info, IEEE80211_BAND_5GHZ);
324
325 sband = &priv->bands[IEEE80211_BAND_2GHZ];
326 sband->channels = channels;
327 /* OFDM & CCK */
328 sband->bitrates = rates;
329 sband->n_bitrates = IWL_RATE_COUNT;
330
331 iwlcore_init_ht_hw_capab(priv, &sband->ht_info, IEEE80211_BAND_2GHZ);
332
333 priv->ieee_channels = channels;
334 priv->ieee_rates = rates;
335
336 iwlcore_init_hw_rates(priv, rates);
337
338 for (i = 0; i < priv->channel_count; i++) {
339 ch = &priv->channel_info[i];
340
341 /* FIXME: might be removed if scan is OK */
342 if (!is_channel_valid(ch))
343 continue;
344
345 if (is_channel_a_band(ch))
346 sband = &priv->bands[IEEE80211_BAND_5GHZ];
347 else
348 sband = &priv->bands[IEEE80211_BAND_2GHZ];
349
350 geo_ch = &sband->channels[sband->n_channels++];
351
352 geo_ch->center_freq =
353 ieee80211_channel_to_frequency(ch->channel);
354 geo_ch->max_power = ch->max_power_avg;
355 geo_ch->max_antenna_gain = 0xff;
356 geo_ch->hw_value = ch->channel;
357
358 if (is_channel_valid(ch)) {
359 if (!(ch->flags & EEPROM_CHANNEL_IBSS))
360 geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
361
362 if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
363 geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
364
365 if (ch->flags & EEPROM_CHANNEL_RADAR)
366 geo_ch->flags |= IEEE80211_CHAN_RADAR;
367
368 if (ch->max_power_avg > priv->max_channel_txpower_limit)
369 priv->max_channel_txpower_limit =
370 ch->max_power_avg;
371 } else {
372 geo_ch->flags |= IEEE80211_CHAN_DISABLED;
373 }
374
375 /* Save flags for reg domain usage */
376 geo_ch->orig_flags = geo_ch->flags;
377
378 IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
379 ch->channel, geo_ch->center_freq,
380 is_channel_a_band(ch) ? "5.2" : "2.4",
381 geo_ch->flags & IEEE80211_CHAN_DISABLED ?
382 "restricted" : "valid",
383 geo_ch->flags);
384 }
385
386 if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
387 priv->cfg->sku & IWL_SKU_A) {
388 printk(KERN_INFO DRV_NAME
389 ": Incorrectly detected BG card as ABG. Please send "
390 "your PCI ID 0x%04X:0x%04X to maintainer.\n",
391 priv->pci_dev->device, priv->pci_dev->subsystem_device);
392 priv->cfg->sku &= ~IWL_SKU_A;
393 }
394
395 printk(KERN_INFO DRV_NAME
396 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
397 priv->bands[IEEE80211_BAND_2GHZ].n_channels,
398 priv->bands[IEEE80211_BAND_5GHZ].n_channels);
399
400 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
401 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
402 &priv->bands[IEEE80211_BAND_2GHZ];
403 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
404 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
405 &priv->bands[IEEE80211_BAND_5GHZ];
406
407 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
408
409 return 0;
410}
411
412/*
413 * iwlcore_free_geos - undo allocations in iwlcore_init_geos
414 */
415void iwlcore_free_geos(struct iwl_priv *priv)
416{
417 kfree(priv->ieee_channels);
418 kfree(priv->ieee_rates);
419 clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
420}
421EXPORT_SYMBOL(iwlcore_free_geos);
422
423#ifdef CONFIG_IWL4965_HT
424static u8 is_single_rx_stream(struct iwl_priv *priv)
425{
426 return !priv->current_ht_config.is_ht ||
427 ((priv->current_ht_config.supp_mcs_set[1] == 0) &&
428 (priv->current_ht_config.supp_mcs_set[2] == 0)) ||
429 priv->ps_mode == IWL_MIMO_PS_STATIC;
430}
431#else
432static inline u8 is_single_rx_stream(struct iwl_priv *priv)
433{
434 return 1;
435}
436#endif /*CONFIG_IWL4965_HT */
437
438/*
439 * Determine how many receiver/antenna chains to use.
440 * More provides better reception via diversity. Fewer saves power.
441 * MIMO (dual stream) requires at least 2, but works better with 3.
442 * This does not determine *which* chains to use, just how many.
443 */
444static int iwlcore_get_rx_chain_counter(struct iwl_priv *priv,
445 u8 *idle_state, u8 *rx_state)
446{
447 u8 is_single = is_single_rx_stream(priv);
448 u8 is_cam = test_bit(STATUS_POWER_PMI, &priv->status) ? 0 : 1;
449
450 /* # of Rx chains to use when expecting MIMO. */
451 if (is_single || (!is_cam && (priv->ps_mode == IWL_MIMO_PS_STATIC)))
452 *rx_state = 2;
453 else
454 *rx_state = 3;
455
456 /* # Rx chains when idling and maybe trying to save power */
457 switch (priv->ps_mode) {
458 case IWL_MIMO_PS_STATIC:
459 case IWL_MIMO_PS_DYNAMIC:
460 *idle_state = (is_cam) ? 2 : 1;
461 break;
462 case IWL_MIMO_PS_NONE:
463 *idle_state = (is_cam) ? *rx_state : 1;
464 break;
465 default:
466 *idle_state = 1;
467 break;
468 }
469
470 return 0;
471}
472
473/**
474 * iwl_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
475 *
476 * Selects how many and which Rx receivers/antennas/chains to use.
477 * This should not be used for scan command ... it puts data in wrong place.
478 */
479void iwl_set_rxon_chain(struct iwl_priv *priv)
480{
481 u8 is_single = is_single_rx_stream(priv);
482 u8 idle_state, rx_state;
483
484 priv->staging_rxon.rx_chain = 0;
485 rx_state = idle_state = 3;
486
487 /* Tell uCode which antennas are actually connected.
488 * Before first association, we assume all antennas are connected.
489 * Just after first association, iwl_chain_noise_calibration()
490 * checks which antennas actually *are* connected. */
491 priv->staging_rxon.rx_chain |=
492 cpu_to_le16(priv->hw_params.valid_rx_ant <<
493 RXON_RX_CHAIN_VALID_POS);
494
495 /* How many receivers should we use? */
496 iwlcore_get_rx_chain_counter(priv, &idle_state, &rx_state);
497 priv->staging_rxon.rx_chain |=
498 cpu_to_le16(rx_state << RXON_RX_CHAIN_MIMO_CNT_POS);
499 priv->staging_rxon.rx_chain |=
500 cpu_to_le16(idle_state << RXON_RX_CHAIN_CNT_POS);
501
502 if (!is_single && (rx_state >= 2) &&
503 !test_bit(STATUS_POWER_PMI, &priv->status))
504 priv->staging_rxon.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
505 else
506 priv->staging_rxon.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
507
508 IWL_DEBUG_ASSOC("rx chain %X\n", priv->staging_rxon.rx_chain);
509}
510EXPORT_SYMBOL(iwl_set_rxon_chain);
180 511
181/** 512/**
182 * iwlcore_set_rxon_channel - Set the phymode and channel values in staging RXON 513 * iwlcore_set_rxon_channel - Set the phymode and channel values in staging RXON
@@ -188,7 +519,7 @@ EXPORT_SYMBOL(iwlcore_reset_qos);
188 * NOTE: Does not commit to the hardware; it sets appropriate bit fields 519 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
189 * in the staging RXON flag structure based on the phymode 520 * in the staging RXON flag structure based on the phymode
190 */ 521 */
191int iwlcore_set_rxon_channel(struct iwl_priv *priv, 522int iwl_set_rxon_channel(struct iwl_priv *priv,
192 enum ieee80211_band band, 523 enum ieee80211_band band,
193 u16 channel) 524 u16 channel)
194{ 525{
@@ -214,7 +545,7 @@ int iwlcore_set_rxon_channel(struct iwl_priv *priv,
214 545
215 return 0; 546 return 0;
216} 547}
217EXPORT_SYMBOL(iwlcore_set_rxon_channel); 548EXPORT_SYMBOL(iwl_set_rxon_channel);
218 549
219static void iwlcore_init_hw(struct iwl_priv *priv) 550static void iwlcore_init_hw(struct iwl_priv *priv)
220{ 551{
@@ -237,15 +568,96 @@ static void iwlcore_init_hw(struct iwl_priv *priv)
237 hw->queues = 4; 568 hw->queues = 4;
238#ifdef CONFIG_IWL4965_HT 569#ifdef CONFIG_IWL4965_HT
239 /* Enhanced value; more queues, to support 11n aggregation */ 570 /* Enhanced value; more queues, to support 11n aggregation */
240 hw->queues = 16; 571 hw->ampdu_queues = 12;
241#endif /* CONFIG_IWL4965_HT */ 572#endif /* CONFIG_IWL4965_HT */
242} 573}
243 574
575static int iwlcore_init_drv(struct iwl_priv *priv)
576{
577 int ret;
578 int i;
579
580 priv->retry_rate = 1;
581 priv->ibss_beacon = NULL;
582
583 spin_lock_init(&priv->lock);
584 spin_lock_init(&priv->power_data.lock);
585 spin_lock_init(&priv->sta_lock);
586 spin_lock_init(&priv->hcmd_lock);
587 spin_lock_init(&priv->lq_mngr.lock);
588
589 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++)
590 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
591
592 INIT_LIST_HEAD(&priv->free_frames);
593
594 mutex_init(&priv->mutex);
595
596 /* Clear the driver's (not device's) station table */
597 iwlcore_clear_stations_table(priv);
598
599 priv->data_retry_limit = -1;
600 priv->ieee_channels = NULL;
601 priv->ieee_rates = NULL;
602 priv->band = IEEE80211_BAND_2GHZ;
603
604 priv->iw_mode = IEEE80211_IF_TYPE_STA;
605
606 priv->use_ant_b_for_management_frame = 1; /* start with ant B */
607 priv->ps_mode = IWL_MIMO_PS_NONE;
608
609 /* Choose which receivers/antennas to use */
610 iwl_set_rxon_chain(priv);
611
612 iwl_reset_qos(priv);
613
614 priv->qos_data.qos_active = 0;
615 priv->qos_data.qos_cap.val = 0;
616
617 iwl_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
618
619 priv->rates_mask = IWL_RATES_MASK;
620 /* If power management is turned on, default to AC mode */
621 priv->power_mode = IWL_POWER_AC;
622 priv->user_txpower_limit = IWL_DEFAULT_TX_POWER;
623
624 ret = iwl_init_channel_map(priv);
625 if (ret) {
626 IWL_ERROR("initializing regulatory failed: %d\n", ret);
627 goto err;
628 }
629
630 ret = iwlcore_init_geos(priv);
631 if (ret) {
632 IWL_ERROR("initializing geos failed: %d\n", ret);
633 goto err_free_channel_map;
634 }
635
636 ret = ieee80211_register_hw(priv->hw);
637 if (ret) {
638 IWL_ERROR("Failed to register network device (error %d)\n",
639 ret);
640 goto err_free_geos;
641 }
642
643 priv->hw->conf.beacon_int = 100;
644 priv->mac80211_registered = 1;
645
646 return 0;
647
648err_free_geos:
649 iwlcore_free_geos(priv);
650err_free_channel_map:
651 iwl_free_channel_map(priv);
652err:
653 return ret;
654}
655
244int iwl_setup(struct iwl_priv *priv) 656int iwl_setup(struct iwl_priv *priv)
245{ 657{
246 int ret = 0; 658 int ret = 0;
247 iwlcore_init_hw(priv); 659 iwlcore_init_hw(priv);
248 ret = priv->cfg->ops->lib->init_drv(priv); 660 ret = iwlcore_init_drv(priv);
249 return ret; 661 return ret;
250} 662}
251EXPORT_SYMBOL(iwl_setup); 663EXPORT_SYMBOL(iwl_setup);
@@ -263,8 +675,10 @@ int iwlcore_low_level_notify(struct iwl_priv *priv,
263 if (ret) 675 if (ret)
264 IWL_ERROR("Unable to initialize RFKILL system. " 676 IWL_ERROR("Unable to initialize RFKILL system. "
265 "Ignoring error: %d\n", ret); 677 "Ignoring error: %d\n", ret);
678 iwl_power_initialize(priv);
266 break; 679 break;
267 case IWLCORE_START_EVT: 680 case IWLCORE_START_EVT:
681 iwl_power_update_mode(priv, 1);
268 break; 682 break;
269 case IWLCORE_STOP_EVT: 683 case IWLCORE_STOP_EVT:
270 break; 684 break;
@@ -290,3 +704,137 @@ int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags)
290} 704}
291EXPORT_SYMBOL(iwl_send_statistics_request); 705EXPORT_SYMBOL(iwl_send_statistics_request);
292 706
707/**
708 * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host,
709 * using sample data 100 bytes apart. If these sample points are good,
710 * it's a pretty good bet that everything between them is good, too.
711 */
712static int iwlcore_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
713{
714 u32 val;
715 int ret = 0;
716 u32 errcnt = 0;
717 u32 i;
718
719 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
720
721 ret = iwl_grab_nic_access(priv);
722 if (ret)
723 return ret;
724
725 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
726 /* read data comes through single port, auto-incr addr */
727 /* NOTE: Use the debugless read so we don't flood kernel log
728 * if IWL_DL_IO is set */
729 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
730 i + RTC_INST_LOWER_BOUND);
731 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
732 if (val != le32_to_cpu(*image)) {
733 ret = -EIO;
734 errcnt++;
735 if (errcnt >= 3)
736 break;
737 }
738 }
739
740 iwl_release_nic_access(priv);
741
742 return ret;
743}
744
745/**
746 * iwlcore_verify_inst_full - verify runtime uCode image in card vs. host,
747 * looking at all data.
748 */
749static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 *image,
750 u32 len)
751{
752 u32 val;
753 u32 save_len = len;
754 int ret = 0;
755 u32 errcnt;
756
757 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
758
759 ret = iwl_grab_nic_access(priv);
760 if (ret)
761 return ret;
762
763 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND);
764
765 errcnt = 0;
766 for (; len > 0; len -= sizeof(u32), image++) {
767 /* read data comes through single port, auto-incr addr */
768 /* NOTE: Use the debugless read so we don't flood kernel log
769 * if IWL_DL_IO is set */
770 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
771 if (val != le32_to_cpu(*image)) {
772 IWL_ERROR("uCode INST section is invalid at "
773 "offset 0x%x, is 0x%x, s/b 0x%x\n",
774 save_len - len, val, le32_to_cpu(*image));
775 ret = -EIO;
776 errcnt++;
777 if (errcnt >= 20)
778 break;
779 }
780 }
781
782 iwl_release_nic_access(priv);
783
784 if (!errcnt)
785 IWL_DEBUG_INFO
786 ("ucode image in INSTRUCTION memory is good\n");
787
788 return ret;
789}
790
791/**
792 * iwl_verify_ucode - determine which instruction image is in SRAM,
793 * and verify its contents
794 */
795int iwl_verify_ucode(struct iwl_priv *priv)
796{
797 __le32 *image;
798 u32 len;
799 int ret;
800
801 /* Try bootstrap */
802 image = (__le32 *)priv->ucode_boot.v_addr;
803 len = priv->ucode_boot.len;
804 ret = iwlcore_verify_inst_sparse(priv, image, len);
805 if (!ret) {
806 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
807 return 0;
808 }
809
810 /* Try initialize */
811 image = (__le32 *)priv->ucode_init.v_addr;
812 len = priv->ucode_init.len;
813 ret = iwlcore_verify_inst_sparse(priv, image, len);
814 if (!ret) {
815 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
816 return 0;
817 }
818
819 /* Try runtime/protocol */
820 image = (__le32 *)priv->ucode_code.v_addr;
821 len = priv->ucode_code.len;
822 ret = iwlcore_verify_inst_sparse(priv, image, len);
823 if (!ret) {
824 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
825 return 0;
826 }
827
828 IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
829
830 /* Since nothing seems to match, show first several data entries in
831 * instruction SRAM, so maybe visual inspection will give a clue.
832 * Selection of bootstrap image (vs. other images) is arbitrary. */
833 image = (__le32 *)priv->ucode_boot.v_addr;
834 len = priv->ucode_boot.len;
835 ret = iwl_verify_inst_full(priv, image, len);
836
837 return ret;
838}
839EXPORT_SYMBOL(iwl_verify_ucode);
840
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.h b/drivers/net/wireless/iwlwifi/iwl-core.h
index 7193d97630dc..369f1821584f 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.h
+++ b/drivers/net/wireless/iwlwifi/iwl-core.h
@@ -87,17 +87,26 @@ struct iwl_hcmd_ops {
87}; 87};
88struct iwl_hcmd_utils_ops { 88struct iwl_hcmd_utils_ops {
89 int (*enqueue_hcmd)(struct iwl_priv *priv, struct iwl_host_cmd *cmd); 89 int (*enqueue_hcmd)(struct iwl_priv *priv, struct iwl_host_cmd *cmd);
90#ifdef CONFIG_IWLWIFI_RUN_TIME_CALIB
91 void (*gain_computation)(struct iwl_priv *priv,
92 u32 *average_noise,
93 u16 min_average_noise_antennat_i,
94 u32 min_average_noise);
95 void (*chain_noise_reset)(struct iwl_priv *priv);
96#endif
90}; 97};
91 98
92struct iwl_lib_ops { 99struct iwl_lib_ops {
93 /* iwlwifi driver (priv) init */
94 int (*init_drv)(struct iwl_priv *priv);
95 /* set hw dependant perameters */ 100 /* set hw dependant perameters */
96 int (*set_hw_params)(struct iwl_priv *priv); 101 int (*set_hw_params)(struct iwl_priv *priv);
97 102 /* ucode shared memory */
103 int (*alloc_shared_mem)(struct iwl_priv *priv);
104 void (*free_shared_mem)(struct iwl_priv *priv);
98 void (*txq_update_byte_cnt_tbl)(struct iwl_priv *priv, 105 void (*txq_update_byte_cnt_tbl)(struct iwl_priv *priv,
99 struct iwl4965_tx_queue *txq, 106 struct iwl4965_tx_queue *txq,
100 u16 byte_cnt); 107 u16 byte_cnt);
108 /* setup Rx handler */
109 void (*rx_handler_setup)(struct iwl_priv *priv);
101 /* nic init */ 110 /* nic init */
102 int (*hw_nic_init)(struct iwl_priv *priv); 111 int (*hw_nic_init)(struct iwl_priv *priv);
103 /* alive notification */ 112 /* alive notification */
@@ -108,6 +117,15 @@ struct iwl_lib_ops {
108 int (*load_ucode)(struct iwl_priv *priv); 117 int (*load_ucode)(struct iwl_priv *priv);
109 /* rfkill */ 118 /* rfkill */
110 void (*radio_kill_sw)(struct iwl_priv *priv, int disable_radio); 119 void (*radio_kill_sw)(struct iwl_priv *priv, int disable_radio);
120 /* power management */
121 struct {
122 int (*init)(struct iwl_priv *priv);
123 void (*config)(struct iwl_priv *priv);
124 int (*set_pwr_src)(struct iwl_priv *priv, enum iwl_pwr_src src);
125 } apm_ops;
126 /* power */
127 int (*set_power)(struct iwl_priv *priv, void *cmd);
128 void (*update_chain_flags)(struct iwl_priv *priv);
111 /* eeprom operations (as defined in iwl-eeprom.h) */ 129 /* eeprom operations (as defined in iwl-eeprom.h) */
112 struct iwl_eeprom_ops eeprom_ops; 130 struct iwl_eeprom_ops eeprom_ops;
113}; 131};
@@ -133,6 +151,7 @@ struct iwl_cfg {
133 const char *name; 151 const char *name;
134 const char *fw_name; 152 const char *fw_name;
135 unsigned int sku; 153 unsigned int sku;
154 int eeprom_size;
136 const struct iwl_ops *ops; 155 const struct iwl_ops *ops;
137 const struct iwl_mod_params *mod_params; 156 const struct iwl_mod_params *mod_params;
138}; 157};
@@ -143,13 +162,15 @@ struct iwl_cfg {
143 162
144struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg, 163struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg,
145 struct ieee80211_ops *hw_ops); 164 struct ieee80211_ops *hw_ops);
165void iwl_hw_detect(struct iwl_priv *priv);
146 166
147void iwlcore_clear_stations_table(struct iwl_priv *priv); 167void iwlcore_clear_stations_table(struct iwl_priv *priv);
148void iwlcore_reset_qos(struct iwl_priv *priv); 168void iwl_reset_qos(struct iwl_priv *priv);
149int iwlcore_set_rxon_channel(struct iwl_priv *priv, 169void iwl_set_rxon_chain(struct iwl_priv *priv);
170int iwl_set_rxon_channel(struct iwl_priv *priv,
150 enum ieee80211_band band, 171 enum ieee80211_band band,
151 u16 channel); 172 u16 channel);
152 173void iwlcore_free_geos(struct iwl_priv *priv);
153int iwl_setup(struct iwl_priv *priv); 174int iwl_setup(struct iwl_priv *priv);
154 175
155/***************************************************** 176/*****************************************************
@@ -235,6 +256,7 @@ enum iwlcore_card_notify {
235int iwlcore_low_level_notify(struct iwl_priv *priv, 256int iwlcore_low_level_notify(struct iwl_priv *priv,
236 enum iwlcore_card_notify notify); 257 enum iwlcore_card_notify notify);
237extern int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags); 258extern int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags);
259extern int iwl_verify_ucode(struct iwl_priv *priv);
238int iwl_send_lq_cmd(struct iwl_priv *priv, 260int iwl_send_lq_cmd(struct iwl_priv *priv,
239 struct iwl_link_quality_cmd *lq, u8 flags); 261 struct iwl_link_quality_cmd *lq, u8 flags);
240 262
diff --git a/drivers/net/wireless/iwlwifi/iwl-csr.h b/drivers/net/wireless/iwlwifi/iwl-csr.h
index 12725796ea5f..9d6e5d2072d2 100644
--- a/drivers/net/wireless/iwlwifi/iwl-csr.h
+++ b/drivers/net/wireless/iwlwifi/iwl-csr.h
@@ -95,8 +95,7 @@
95#define CSR_GIO_CHICKEN_BITS (CSR_BASE+0x100) 95#define CSR_GIO_CHICKEN_BITS (CSR_BASE+0x100)
96#define CSR_LED_REG (CSR_BASE+0x094) 96#define CSR_LED_REG (CSR_BASE+0x094)
97 97
98/* Analog phase-lock-loop configuration (3945 only) 98/* Analog phase-lock-loop configuration */
99 * Set bit 24. */
100#define CSR_ANA_PLL_CFG (CSR_BASE+0x20c) 99#define CSR_ANA_PLL_CFG (CSR_BASE+0x20c)
101/* 100/*
102 * Indicates hardware rev, to determine CCK backoff for txpower calculation. 101 * Indicates hardware rev, to determine CCK backoff for txpower calculation.
@@ -107,9 +106,9 @@
107 106
108/* Bits for CSR_HW_IF_CONFIG_REG */ 107/* Bits for CSR_HW_IF_CONFIG_REG */
109#define CSR49_HW_IF_CONFIG_REG_BIT_4965_R (0x00000010) 108#define CSR49_HW_IF_CONFIG_REG_BIT_4965_R (0x00000010)
110#define CSR49_HW_IF_CONFIG_REG_MSK_BOARD_VER (0x00000C00) 109#define CSR_HW_IF_CONFIG_REG_MSK_BOARD_VER (0x00000C00)
111#define CSR49_HW_IF_CONFIG_REG_BIT_MAC_SI (0x00000100) 110#define CSR_HW_IF_CONFIG_REG_BIT_MAC_SI (0x00000100)
112#define CSR49_HW_IF_CONFIG_REG_BIT_RADIO_SI (0x00000200) 111#define CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI (0x00000200)
113 112
114#define CSR39_HW_IF_CONFIG_REG_BIT_3945_MB (0x00000100) 113#define CSR39_HW_IF_CONFIG_REG_BIT_3945_MB (0x00000100)
115#define CSR39_HW_IF_CONFIG_REG_BIT_3945_MM (0x00000200) 114#define CSR39_HW_IF_CONFIG_REG_BIT_3945_MM (0x00000200)
@@ -170,6 +169,10 @@
170#define CSR49_FH_INT_TX_MASK (CSR_FH_INT_BIT_TX_CHNL1 | \ 169#define CSR49_FH_INT_TX_MASK (CSR_FH_INT_BIT_TX_CHNL1 | \
171 CSR_FH_INT_BIT_TX_CHNL0) 170 CSR_FH_INT_BIT_TX_CHNL0)
172 171
172/* GPIO */
173#define CSR_GPIO_IN_BIT_AUX_POWER (0x00000200)
174#define CSR_GPIO_IN_VAL_VAUX_PWR_SRC (0x00000000)
175#define CSR_GPIO_IN_VAL_VMAIN_PWR_SRC (0x00000200)
173 176
174/* RESET */ 177/* RESET */
175#define CSR_RESET_REG_FLAG_NEVO_RESET (0x00000001) 178#define CSR_RESET_REG_FLAG_NEVO_RESET (0x00000001)
@@ -191,6 +194,16 @@
191#define CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW (0x08000000) 194#define CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW (0x08000000)
192 195
193 196
197/* HW REV */
198#define CSR_HW_REV_TYPE_MSK (0x00000F0)
199#define CSR_HW_REV_TYPE_3945 (0x00000D0)
200#define CSR_HW_REV_TYPE_4965 (0x0000000)
201#define CSR_HW_REV_TYPE_5300 (0x0000020)
202#define CSR_HW_REV_TYPE_5350 (0x0000030)
203#define CSR_HW_REV_TYPE_5100 (0x0000050)
204#define CSR_HW_REV_TYPE_5150 (0x0000040)
205#define CSR_HW_REV_TYPE_NONE (0x00000F0)
206
194/* EEPROM REG */ 207/* EEPROM REG */
195#define CSR_EEPROM_REG_READ_VALID_MSK (0x00000001) 208#define CSR_EEPROM_REG_READ_VALID_MSK (0x00000001)
196#define CSR_EEPROM_REG_BIT_CMD (0x00000002) 209#define CSR_EEPROM_REG_BIT_CMD (0x00000002)
@@ -206,11 +219,6 @@
206#define CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED (0x00000004) 219#define CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED (0x00000004)
207#define CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT (0x00000008) 220#define CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT (0x00000008)
208 221
209/* GPIO */
210#define CSR_GPIO_IN_BIT_AUX_POWER (0x00000200)
211#define CSR_GPIO_IN_VAL_VAUX_PWR_SRC (0x00000000)
212#define CSR_GPIO_IN_VAL_VMAIN_PWR_SRC CSR_GPIO_IN_BIT_AUX_POWER
213
214/* GI Chicken Bits */ 222/* GI Chicken Bits */
215#define CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX (0x00800000) 223#define CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX (0x00800000)
216#define CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER (0x20000000) 224#define CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER (0x20000000)
@@ -220,6 +228,10 @@
220#define CSR_LED_REG_TRUN_ON (0x78) 228#define CSR_LED_REG_TRUN_ON (0x78)
221#define CSR_LED_REG_TRUN_OFF (0x38) 229#define CSR_LED_REG_TRUN_OFF (0x38)
222 230
231/* ANA_PLL */
232#define CSR39_ANA_PLL_CFG_VAL (0x01000000)
233#define CSR50_ANA_PLL_CFG_VAL (0x00880300)
234
223/*=== HBUS (Host-side Bus) ===*/ 235/*=== HBUS (Host-side Bus) ===*/
224#define HBUS_BASE (0x400) 236#define HBUS_BASE (0x400)
225/* 237/*
diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
index 9a30e1df311d..30914453de1e 100644
--- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
@@ -34,7 +34,7 @@
34#include <net/mac80211.h> 34#include <net/mac80211.h>
35 35
36 36
37#include "iwl-4965.h" 37#include "iwl-dev.h"
38#include "iwl-debug.h" 38#include "iwl-debug.h"
39#include "iwl-core.h" 39#include "iwl-core.h"
40#include "iwl-io.h" 40#include "iwl-io.h"
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.h b/drivers/net/wireless/iwlwifi/iwl-dev.h
index 581b98556c86..78aba21bc18f 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965.h
+++ b/drivers/net/wireless/iwlwifi/iwl-dev.h
@@ -24,8 +24,8 @@
24 * 24 *
25 *****************************************************************************/ 25 *****************************************************************************/
26/* 26/*
27 * Please use this file (iwl-4965.h) for driver implementation definitions. 27 * Please use this file (iwl-dev.h) for driver implementation definitions.
28 * Please use iwl-4965-commands.h for uCode API definitions. 28 * Please use iwl-commands.h for uCode API definitions.
29 * Please use iwl-4965-hw.h for hardware-related definitions. 29 * Please use iwl-4965-hw.h for hardware-related definitions.
30 */ 30 */
31 31
@@ -44,9 +44,13 @@
44#include "iwl-prph.h" 44#include "iwl-prph.h"
45#include "iwl-debug.h" 45#include "iwl-debug.h"
46#include "iwl-led.h" 46#include "iwl-led.h"
47#include "iwl-power.h"
47 48
48/* configuration for the iwl4965 */ 49/* configuration for the iwl4965 */
49extern struct iwl_cfg iwl4965_agn_cfg; 50extern struct iwl_cfg iwl4965_agn_cfg;
51extern struct iwl_cfg iwl5300_agn_cfg;
52extern struct iwl_cfg iwl5100_agn_cfg;
53extern struct iwl_cfg iwl5350_agn_cfg;
50 54
51/* Change firmware file name, using "-" and incrementing number, 55/* Change firmware file name, using "-" and incrementing number,
52 * *only* when uCode interface or architecture changes so that it 56 * *only* when uCode interface or architecture changes so that it
@@ -54,6 +58,8 @@ extern struct iwl_cfg iwl4965_agn_cfg;
54 * This number will also appear in << 8 position of 1st dword of uCode file */ 58 * This number will also appear in << 8 position of 1st dword of uCode file */
55#define IWL4965_UCODE_API "-1" 59#define IWL4965_UCODE_API "-1"
56 60
61/* CT-KILL constants */
62#define CT_KILL_THRESHOLD 110 /* in Celsius */
57 63
58/* Default noise level to report when noise measurement is not available. 64/* Default noise level to report when noise measurement is not available.
59 * This may be because we're: 65 * This may be because we're:
@@ -68,12 +74,6 @@ extern struct iwl_cfg iwl4965_agn_cfg;
68 * averages within an s8's (used in some apps) range of negative values. */ 74 * averages within an s8's (used in some apps) range of negative values. */
69#define IWL_NOISE_MEAS_NOT_AVAILABLE (-127) 75#define IWL_NOISE_MEAS_NOT_AVAILABLE (-127)
70 76
71enum iwl4965_antenna {
72 IWL_ANTENNA_DIVERSITY,
73 IWL_ANTENNA_MAIN,
74 IWL_ANTENNA_AUX
75};
76
77/* 77/*
78 * RTS threshold here is total size [2347] minus 4 FCS bytes 78 * RTS threshold here is total size [2347] minus 4 FCS bytes
79 * Per spec: 79 * Per spec:
@@ -199,9 +199,9 @@ enum {
199struct iwl_channel_info { 199struct iwl_channel_info {
200 struct iwl4965_channel_tgd_info tgd; 200 struct iwl4965_channel_tgd_info tgd;
201 struct iwl4965_channel_tgh_info tgh; 201 struct iwl4965_channel_tgh_info tgh;
202 struct iwl4965_eeprom_channel eeprom; /* EEPROM regulatory limit */ 202 struct iwl_eeprom_channel eeprom; /* EEPROM regulatory limit */
203 struct iwl4965_eeprom_channel fat_eeprom; /* EEPROM regulatory limit for 203 struct iwl_eeprom_channel fat_eeprom; /* EEPROM regulatory limit for
204 * FAT channel */ 204 * FAT channel */
205 205
206 u8 channel; /* channel number */ 206 u8 channel; /* channel number */
207 u8 flags; /* flags copied from EEPROM */ 207 u8 flags; /* flags copied from EEPROM */
@@ -252,29 +252,9 @@ struct iwl4965_clip_group {
252 252
253/* Power management (not Tx power) structures */ 253/* Power management (not Tx power) structures */
254 254
255struct iwl4965_power_vec_entry { 255enum iwl_pwr_src {
256 struct iwl4965_powertable_cmd cmd; 256 IWL_PWR_SRC_VMAIN,
257 u8 no_dtim; 257 IWL_PWR_SRC_VAUX,
258};
259#define IWL_POWER_RANGE_0 (0)
260#define IWL_POWER_RANGE_1 (1)
261
262#define IWL_POWER_MODE_CAM 0x00 /* Continuously Aware Mode, always on */
263#define IWL_POWER_INDEX_3 0x03
264#define IWL_POWER_INDEX_5 0x05
265#define IWL_POWER_AC 0x06
266#define IWL_POWER_BATTERY 0x07
267#define IWL_POWER_LIMIT 0x07
268#define IWL_POWER_MASK 0x0F
269#define IWL_POWER_ENABLED 0x10
270#define IWL_POWER_LEVEL(x) ((x) & IWL_POWER_MASK)
271
272struct iwl4965_power_mgr {
273 spinlock_t lock;
274 struct iwl4965_power_vec_entry pwr_range_0[IWL_POWER_AC];
275 struct iwl4965_power_vec_entry pwr_range_1[IWL_POWER_AC];
276 u8 active_index;
277 u32 dtim_val;
278}; 258};
279 259
280#define IEEE80211_DATA_LEN 2304 260#define IEEE80211_DATA_LEN 2304
@@ -566,16 +546,49 @@ struct iwl4965_ibss_seq {
566 struct list_head list; 546 struct list_head list;
567}; 547};
568 548
549struct iwl_sensitivity_ranges {
550 u16 min_nrg_cck;
551 u16 max_nrg_cck;
552
553 u16 nrg_th_cck;
554 u16 nrg_th_ofdm;
555
556 u16 auto_corr_min_ofdm;
557 u16 auto_corr_min_ofdm_mrc;
558 u16 auto_corr_min_ofdm_x1;
559 u16 auto_corr_min_ofdm_mrc_x1;
560
561 u16 auto_corr_max_ofdm;
562 u16 auto_corr_max_ofdm_mrc;
563 u16 auto_corr_max_ofdm_x1;
564 u16 auto_corr_max_ofdm_mrc_x1;
565
566 u16 auto_corr_max_cck;
567 u16 auto_corr_max_cck_mrc;
568 u16 auto_corr_min_cck;
569 u16 auto_corr_min_cck_mrc;
570};
571
572
573#define IWL_FAT_CHANNEL_52 BIT(IEEE80211_BAND_5GHZ)
574
569/** 575/**
570 * struct iwl_hw_params 576 * struct iwl_hw_params
571 * @max_txq_num: Max # Tx queues supported 577 * @max_txq_num: Max # Tx queues supported
572 * @tx_cmd_len: Size of Tx command (but not including frame itself) 578 * @tx_cmd_len: Size of Tx command (but not including frame itself)
573 * @tx_ant_num: Number of TX antennas 579 * @tx/rx_chains_num: Number of TX/RX chains
580 * @valid_tx/rx_ant: usable antennas
574 * @max_rxq_size: Max # Rx frames in Rx queue (must be power-of-2) 581 * @max_rxq_size: Max # Rx frames in Rx queue (must be power-of-2)
575 * @rx_buffer_size:
576 * @max_rxq_log: Log-base-2 of max_rxq_size 582 * @max_rxq_log: Log-base-2 of max_rxq_size
583 * @rx_buf_size: Rx buffer size
577 * @max_stations: 584 * @max_stations:
578 * @bcast_sta_id: 585 * @bcast_sta_id:
586 * @fat_channel: is 40MHz width possible in band 2.4
587 * BIT(IEEE80211_BAND_5GHZ) BIT(IEEE80211_BAND_5GHZ)
588 * @sw_crypto: 0 for hw, 1 for sw
589 * @max_xxx_size: for ucode uses
590 * @ct_kill_threshold: temperature threshold
591 * @struct iwl_sensitivity_ranges: range of sensitivity values
579 */ 592 */
580struct iwl_hw_params { 593struct iwl_hw_params {
581 u16 max_txq_num; 594 u16 max_txq_num;
@@ -590,10 +603,19 @@ struct iwl_hw_params {
590 u32 max_pkt_size; 603 u32 max_pkt_size;
591 u8 max_stations; 604 u8 max_stations;
592 u8 bcast_sta_id; 605 u8 bcast_sta_id;
606 u8 fat_channel;
607 u8 sw_crypto;
608 u32 max_inst_size;
609 u32 max_data_size;
610 u32 max_bsm_size;
611 u32 ct_kill_threshold; /* value in hw-dependent units */
612#ifdef CONFIG_IWLWIFI_RUN_TIME_CALIB
613 const struct iwl_sensitivity_ranges *sens;
614#endif
593}; 615};
594 616
595#define HT_SHORT_GI_20MHZ_ONLY (1 << 0) 617#define HT_SHORT_GI_20MHZ_ONLY (1 << 0)
596#define HT_SHORT_GI_40MHZ_ONLY (1 << 1) 618#define HT_SHORT_GI_40MHZ_ONLY (1 << 1)
597 619
598 620
599#define IWL_RX_HDR(x) ((struct iwl4965_rx_frame_hdr *)(\ 621#define IWL_RX_HDR(x) ((struct iwl4965_rx_frame_hdr *)(\
@@ -641,10 +663,10 @@ extern unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv,
641 const u8 *dest, int left); 663 const u8 *dest, int left);
642extern int iwl4965_rx_queue_update_write_ptr(struct iwl_priv *priv, 664extern int iwl4965_rx_queue_update_write_ptr(struct iwl_priv *priv,
643 struct iwl4965_rx_queue *q); 665 struct iwl4965_rx_queue *q);
644extern void iwl4965_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb,
645 u32 decrypt_res,
646 struct ieee80211_rx_status *stats);
647extern __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr); 666extern __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr);
667extern void iwl4965_update_chain_flags(struct iwl_priv *priv);
668int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src);
669
648int iwl4965_init_geos(struct iwl_priv *priv); 670int iwl4965_init_geos(struct iwl_priv *priv);
649void iwl4965_free_geos(struct iwl_priv *priv); 671void iwl4965_free_geos(struct iwl_priv *priv);
650 672
@@ -674,7 +696,6 @@ extern u8 iwl4965_sync_station(struct iwl_priv *priv, int sta_id,
674 * iwl4965_mac_ <-- mac80211 callback 696 * iwl4965_mac_ <-- mac80211 callback
675 * 697 *
676 ****************************************************************************/ 698 ****************************************************************************/
677extern void iwl4965_hw_rx_handler_setup(struct iwl_priv *priv);
678extern void iwl4965_hw_setup_deferred_work(struct iwl_priv *priv); 699extern void iwl4965_hw_setup_deferred_work(struct iwl_priv *priv);
679extern void iwl4965_hw_cancel_deferred_work(struct iwl_priv *priv); 700extern void iwl4965_hw_cancel_deferred_work(struct iwl_priv *priv);
680extern int iwl4965_hw_rxq_stop(struct iwl_priv *priv); 701extern int iwl4965_hw_rxq_stop(struct iwl_priv *priv);
@@ -706,14 +727,14 @@ extern void iwl4965_disable_events(struct iwl_priv *priv);
706extern int iwl4965_get_temperature(const struct iwl_priv *priv); 727extern int iwl4965_get_temperature(const struct iwl_priv *priv);
707 728
708/** 729/**
709 * iwl4965_hw_find_station - Find station id for a given BSSID 730 * iwl_find_station - Find station id for a given BSSID
710 * @bssid: MAC address of station ID to find 731 * @bssid: MAC address of station ID to find
711 * 732 *
712 * NOTE: This should not be hardware specific but the code has 733 * NOTE: This should not be hardware specific but the code has
713 * not yet been merged into a single common layer for managing the 734 * not yet been merged into a single common layer for managing the
714 * station tables. 735 * station tables.
715 */ 736 */
716extern u8 iwl4965_hw_find_station(struct iwl_priv *priv, const u8 *bssid); 737extern u8 iwl_find_station(struct iwl_priv *priv, const u8 *bssid);
717 738
718extern int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel); 739extern int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel);
719extern int iwl4965_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index); 740extern int iwl4965_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index);
@@ -729,21 +750,17 @@ extern int iwl4965_tx_queue_update_wr_ptr(struct iwl_priv *priv,
729 u16 byte_cnt); 750 u16 byte_cnt);
730extern void iwl4965_add_station(struct iwl_priv *priv, const u8 *addr, 751extern void iwl4965_add_station(struct iwl_priv *priv, const u8 *addr,
731 int is_ap); 752 int is_ap);
732extern void iwl4965_set_rxon_chain(struct iwl_priv *priv);
733extern int iwl4965_alive_notify(struct iwl_priv *priv); 753extern int iwl4965_alive_notify(struct iwl_priv *priv);
734extern void iwl4965_update_rate_scaling(struct iwl_priv *priv, u8 mode); 754extern void iwl4965_update_rate_scaling(struct iwl_priv *priv, u8 mode);
735extern void iwl4965_chain_noise_reset(struct iwl_priv *priv);
736extern void iwl4965_init_sensitivity(struct iwl_priv *priv, u8 flags,
737 u8 force);
738extern void iwl4965_rf_kill_ct_config(struct iwl_priv *priv); 755extern void iwl4965_rf_kill_ct_config(struct iwl_priv *priv);
739extern void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv, 756extern void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv,
740 u32 rate_n_flags, 757 u32 rate_n_flags,
741 struct ieee80211_tx_control *control); 758 struct ieee80211_tx_control *control);
742 759
743#ifdef CONFIG_IWL4965_HT 760#ifdef CONFIG_IWL4965_HT
744void iwl4965_init_ht_hw_capab(struct iwl_priv *priv, 761extern void iwl4965_init_ht_hw_capab(const struct iwl_priv *priv,
745 struct ieee80211_ht_info *ht_info, 762 struct ieee80211_ht_info *ht_info,
746 enum ieee80211_band band); 763 enum ieee80211_band band);
747void iwl4965_set_rxon_ht(struct iwl_priv *priv, 764void iwl4965_set_rxon_ht(struct iwl_priv *priv,
748 struct iwl_ht_info *ht_info); 765 struct iwl_ht_info *ht_info);
749void iwl4965_set_ht_add_station(struct iwl_priv *priv, u8 index, 766void iwl4965_set_ht_add_station(struct iwl_priv *priv, u8 index,
@@ -754,7 +771,7 @@ int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
754int iwl4965_check_empty_hw_queue(struct iwl_priv *priv, int sta_id, 771int iwl4965_check_empty_hw_queue(struct iwl_priv *priv, int sta_id,
755 u8 tid, int txq_id); 772 u8 tid, int txq_id);
756#else 773#else
757static inline void iwl4965_init_ht_hw_capab(struct iwl_priv *priv, 774static inline void iwl4965_init_ht_hw_capab(const struct iwl_priv *priv,
758 struct ieee80211_ht_info *ht_info, 775 struct ieee80211_ht_info *ht_info,
759 enum ieee80211_band band) {} 776 enum ieee80211_band band) {}
760 777
@@ -787,8 +804,8 @@ struct iwl4965_kw {
787#define IWL_EXT_CHANNEL_OFFSET_RESERVE1 2 804#define IWL_EXT_CHANNEL_OFFSET_RESERVE1 2
788#define IWL_EXT_CHANNEL_OFFSET_BELOW 3 805#define IWL_EXT_CHANNEL_OFFSET_BELOW 3
789 806
790#define NRG_NUM_PREV_STAT_L 20 807#define IWL_TX_CRC_SIZE 4
791#define NUM_RX_CHAINS (3) 808#define IWL_TX_DELIMITER_SIZE 4
792 809
793#define TX_POWER_IWL_ILLEGAL_VOLTAGE -10000 810#define TX_POWER_IWL_ILLEGAL_VOLTAGE -10000
794 811
@@ -818,23 +835,8 @@ struct iwl4965_lq_mngr {
818#define MAX_FA_CCK 50 835#define MAX_FA_CCK 50
819#define MIN_FA_CCK 5 836#define MIN_FA_CCK 5
820 837
821#define NRG_MIN_CCK 97
822#define NRG_MAX_CCK 0
823
824#define AUTO_CORR_MIN_OFDM 85
825#define AUTO_CORR_MIN_OFDM_MRC 170
826#define AUTO_CORR_MIN_OFDM_X1 105
827#define AUTO_CORR_MIN_OFDM_MRC_X1 220
828#define AUTO_CORR_MAX_OFDM 120
829#define AUTO_CORR_MAX_OFDM_MRC 210
830#define AUTO_CORR_MAX_OFDM_X1 140
831#define AUTO_CORR_MAX_OFDM_MRC_X1 270
832#define AUTO_CORR_STEP_OFDM 1 838#define AUTO_CORR_STEP_OFDM 1
833 839
834#define AUTO_CORR_MIN_CCK (125)
835#define AUTO_CORR_MAX_CCK (200)
836#define AUTO_CORR_MIN_CCK_MRC 200
837#define AUTO_CORR_MAX_CCK_MRC 400
838#define AUTO_CORR_STEP_CCK 3 840#define AUTO_CORR_STEP_CCK 3
839#define AUTO_CORR_MAX_TH_CCK 160 841#define AUTO_CORR_MAX_TH_CCK 160
840 842
@@ -853,6 +855,9 @@ struct iwl4965_lq_mngr {
853#define IN_BAND_FILTER 0xFF 855#define IN_BAND_FILTER 0xFF
854#define MIN_AVERAGE_NOISE_MAX_VALUE 0xFFFFFFFF 856#define MIN_AVERAGE_NOISE_MAX_VALUE 0xFFFFFFFF
855 857
858#define NRG_NUM_PREV_STAT_L 20
859#define NUM_RX_CHAINS 3
860
856enum iwl4965_false_alarm_state { 861enum iwl4965_false_alarm_state {
857 IWL_FA_TOO_MANY = 0, 862 IWL_FA_TOO_MANY = 0,
858 IWL_FA_TOO_FEW = 1, 863 IWL_FA_TOO_FEW = 1,
@@ -865,11 +870,6 @@ enum iwl4965_chain_noise_state {
865 IWL_CHAIN_NOISE_CALIBRATED = 2, 870 IWL_CHAIN_NOISE_CALIBRATED = 2,
866}; 871};
867 872
868enum iwl4965_sensitivity_state {
869 IWL_SENS_CALIB_ALLOWED = 0,
870 IWL_SENS_CALIB_NEED_REINIT = 1,
871};
872
873enum iwl4965_calib_enabled_state { 873enum iwl4965_calib_enabled_state {
874 IWL_CALIB_DISABLED = 0, /* must be 0 */ 874 IWL_CALIB_DISABLED = 0, /* must be 0 */
875 IWL_CALIB_ENABLED = 1, 875 IWL_CALIB_ENABLED = 1,
@@ -884,8 +884,9 @@ struct statistics_general_data {
884 u32 beacon_energy_c; 884 u32 beacon_energy_c;
885}; 885};
886 886
887#ifdef CONFIG_IWLWIFI_RUN_TIME_CALIB
887/* Sensitivity calib data */ 888/* Sensitivity calib data */
888struct iwl4965_sensitivity_data { 889struct iwl_sensitivity_data {
889 u32 auto_corr_ofdm; 890 u32 auto_corr_ofdm;
890 u32 auto_corr_ofdm_mrc; 891 u32 auto_corr_ofdm_mrc;
891 u32 auto_corr_ofdm_x1; 892 u32 auto_corr_ofdm_x1;
@@ -909,12 +910,10 @@ struct iwl4965_sensitivity_data {
909 s32 nrg_auto_corr_silence_diff; 910 s32 nrg_auto_corr_silence_diff;
910 u32 num_in_cck_no_fa; 911 u32 num_in_cck_no_fa;
911 u32 nrg_th_ofdm; 912 u32 nrg_th_ofdm;
912
913 u8 state;
914}; 913};
915 914
916/* Chain noise (differential Rx gain) calib data */ 915/* Chain noise (differential Rx gain) calib data */
917struct iwl4965_chain_noise_data { 916struct iwl_chain_noise_data {
918 u8 state; 917 u8 state;
919 u16 beacon_count; 918 u16 beacon_count;
920 u32 chain_noise_a; 919 u32 chain_noise_a;
@@ -927,6 +926,7 @@ struct iwl4965_chain_noise_data {
927 u8 delta_gain_code[NUM_RX_CHAINS]; 926 u8 delta_gain_code[NUM_RX_CHAINS];
928 u8 radio_write; 927 u8 radio_write;
929}; 928};
929#endif /* CONFIG_IWLWIFI_RUN_TIME_CALIB */
930 930
931#define EEPROM_SEM_TIMEOUT 10 /* milliseconds */ 931#define EEPROM_SEM_TIMEOUT 10 /* milliseconds */
932#define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */ 932#define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
@@ -1007,6 +1007,9 @@ struct iwl_priv {
1007 1007
1008 /* pci hardware address support */ 1008 /* pci hardware address support */
1009 void __iomem *hw_base; 1009 void __iomem *hw_base;
1010 u32 hw_rev;
1011 u32 hw_wa_rev;
1012 u8 rev_id;
1010 1013
1011 /* uCode images, save to reload in case of failure */ 1014 /* uCode images, save to reload in case of failure */
1012 struct fw_desc ucode_code; /* runtime inst */ 1015 struct fw_desc ucode_code; /* runtime inst */
@@ -1050,13 +1053,12 @@ struct iwl_priv {
1050 1053
1051 u8 assoc_station_added; 1054 u8 assoc_station_added;
1052 u8 use_ant_b_for_management_frame; /* Tx antenna selection */ 1055 u8 use_ant_b_for_management_frame; /* Tx antenna selection */
1053 u8 valid_antenna; /* Bit mask of antennas actually connected */
1054#ifdef CONFIG_IWL4965_SENSITIVITY
1055 struct iwl4965_sensitivity_data sensitivity_data;
1056 struct iwl4965_chain_noise_data chain_noise_data;
1057 u8 start_calib; 1056 u8 start_calib;
1057#ifdef CONFIG_IWLWIFI_RUN_TIME_CALIB
1058 struct iwl_sensitivity_data sensitivity_data;
1059 struct iwl_chain_noise_data chain_noise_data;
1058 __le16 sensitivity_tbl[HD_TABLE_SIZE]; 1060 __le16 sensitivity_tbl[HD_TABLE_SIZE];
1059#endif /*CONFIG_IWL4965_SENSITIVITY*/ 1061#endif /*CONFIG_IWLWIFI_RUN_TIME_CALIB*/
1060 1062
1061#ifdef CONFIG_IWL4965_HT 1063#ifdef CONFIG_IWL4965_HT
1062 struct iwl_ht_info current_ht_config; 1064 struct iwl_ht_info current_ht_config;
@@ -1092,7 +1094,7 @@ struct iwl_priv {
1092 u64 bytes; 1094 u64 bytes;
1093 } tx_stats[3], rx_stats[3]; 1095 } tx_stats[3], rx_stats[3];
1094 1096
1095 struct iwl4965_power_mgr power_data; 1097 struct iwl_power_mgr power_data;
1096 1098
1097 struct iwl4965_notif_statistics statistics; 1099 struct iwl4965_notif_statistics statistics;
1098 unsigned long last_statistics_time; 1100 unsigned long last_statistics_time;
@@ -1137,7 +1139,8 @@ struct iwl_priv {
1137 struct list_head ibss_mac_hash[IWL_IBSS_MAC_HASH_SIZE]; 1139 struct list_head ibss_mac_hash[IWL_IBSS_MAC_HASH_SIZE];
1138 1140
1139 /* eeprom */ 1141 /* eeprom */
1140 struct iwl4965_eeprom eeprom; 1142 u8 *eeprom;
1143 struct iwl_eeprom_calib_info *calib_info;
1141 1144
1142 enum ieee80211_if_types iw_mode; 1145 enum ieee80211_if_types iw_mode;
1143 1146
@@ -1206,7 +1209,7 @@ struct iwl_priv {
1206#endif /* CONFIG_IWLWIFI_DEBUG */ 1209#endif /* CONFIG_IWLWIFI_DEBUG */
1207 1210
1208 struct work_struct txpower_work; 1211 struct work_struct txpower_work;
1209#ifdef CONFIG_IWL4965_SENSITIVITY 1212#ifdef CONFIG_IWL4965_RUN_TIME_CALIB
1210 struct work_struct sensitivity_work; 1213 struct work_struct sensitivity_work;
1211#endif 1214#endif
1212 struct timer_list statistics_periodic; 1215 struct timer_list statistics_periodic;
@@ -1224,11 +1227,6 @@ static inline int is_channel_valid(const struct iwl_channel_info *ch_info)
1224 return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0; 1227 return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
1225} 1228}
1226 1229
1227static inline int is_channel_narrow(const struct iwl_channel_info *ch_info)
1228{
1229 return (ch_info->flags & EEPROM_CHANNEL_NARROW) ? 1 : 0;
1230}
1231
1232static inline int is_channel_radar(const struct iwl_channel_info *ch_info) 1230static inline int is_channel_radar(const struct iwl_channel_info *ch_info)
1233{ 1231{
1234 return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0; 1232 return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom.c b/drivers/net/wireless/iwlwifi/iwl-eeprom.c
index a07d5dcb7abc..fa306601a550 100644
--- a/drivers/net/wireless/iwlwifi/iwl-eeprom.c
+++ b/drivers/net/wireless/iwlwifi/iwl-eeprom.c
@@ -68,8 +68,8 @@
68 68
69#include <net/mac80211.h> 69#include <net/mac80211.h>
70 70
71#include "iwl-4965-commands.h" 71#include "iwl-commands.h"
72#include "iwl-4965.h" 72#include "iwl-dev.h"
73#include "iwl-core.h" 73#include "iwl-core.h"
74#include "iwl-debug.h" 74#include "iwl-debug.h"
75#include "iwl-eeprom.h" 75#include "iwl-eeprom.h"
@@ -193,6 +193,12 @@ void iwlcore_eeprom_release_semaphore(struct iwl_priv *priv)
193} 193}
194EXPORT_SYMBOL(iwlcore_eeprom_release_semaphore); 194EXPORT_SYMBOL(iwlcore_eeprom_release_semaphore);
195 195
196const u8 *iwlcore_eeprom_query_addr(const struct iwl_priv *priv, size_t offset)
197{
198 BUG_ON(offset >= priv->cfg->eeprom_size);
199 return &priv->eeprom[offset];
200}
201EXPORT_SYMBOL(iwlcore_eeprom_query_addr);
196 202
197/** 203/**
198 * iwl_eeprom_init - read EEPROM contents 204 * iwl_eeprom_init - read EEPROM contents
@@ -203,30 +209,35 @@ EXPORT_SYMBOL(iwlcore_eeprom_release_semaphore);
203 */ 209 */
204int iwl_eeprom_init(struct iwl_priv *priv) 210int iwl_eeprom_init(struct iwl_priv *priv)
205{ 211{
206 u16 *e = (u16 *)&priv->eeprom; 212 u16 *e;
207 u32 gp = iwl_read32(priv, CSR_EEPROM_GP); 213 u32 gp = iwl_read32(priv, CSR_EEPROM_GP);
208 u32 r; 214 u32 r;
209 int sz = sizeof(priv->eeprom); 215 int sz = priv->cfg->eeprom_size;
210 int ret; 216 int ret;
211 int i; 217 int i;
212 u16 addr; 218 u16 addr;
213 219
214 /* The EEPROM structure has several padding buffers within it 220 /* allocate eeprom */
215 * and when adding new EEPROM maps is subject to programmer errors 221 priv->eeprom = kzalloc(sz, GFP_KERNEL);
216 * which may be very difficult to identify without explicitly 222 if (!priv->eeprom) {
217 * checking the resulting size of the eeprom map. */ 223 ret = -ENOMEM;
218 BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE); 224 goto alloc_err;
225 }
226 e = (u16 *)priv->eeprom;
219 227
220 if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) { 228 ret = priv->cfg->ops->lib->eeprom_ops.verify_signature(priv);
229 if (ret < 0) {
221 IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp); 230 IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp);
222 return -ENOENT; 231 ret = -ENOENT;
232 goto err;
223 } 233 }
224 234
225 /* Make sure driver (instead of uCode) is allowed to read EEPROM */ 235 /* Make sure driver (instead of uCode) is allowed to read EEPROM */
226 ret = priv->cfg->ops->lib->eeprom_ops.acquire_semaphore(priv); 236 ret = priv->cfg->ops->lib->eeprom_ops.acquire_semaphore(priv);
227 if (ret < 0) { 237 if (ret < 0) {
228 IWL_ERROR("Failed to acquire EEPROM semaphore.\n"); 238 IWL_ERROR("Failed to acquire EEPROM semaphore.\n");
229 return -ENOENT; 239 ret = -ENOENT;
240 goto err;
230 } 241 }
231 242
232 /* eeprom is an array of 16bit values */ 243 /* eeprom is an array of 16bit values */
@@ -250,61 +261,98 @@ int iwl_eeprom_init(struct iwl_priv *priv)
250 e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16)); 261 e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16));
251 } 262 }
252 ret = 0; 263 ret = 0;
253
254done: 264done:
255 priv->cfg->ops->lib->eeprom_ops.release_semaphore(priv); 265 priv->cfg->ops->lib->eeprom_ops.release_semaphore(priv);
266err:
267 if (ret)
268 kfree(priv->eeprom);
269alloc_err:
256 return ret; 270 return ret;
257} 271}
258EXPORT_SYMBOL(iwl_eeprom_init); 272EXPORT_SYMBOL(iwl_eeprom_init);
259 273
274void iwl_eeprom_free(struct iwl_priv *priv)
275{
276 if(priv->eeprom)
277 kfree(priv->eeprom);
278 priv->eeprom = NULL;
279}
280EXPORT_SYMBOL(iwl_eeprom_free);
281
282int iwl_eeprom_check_version(struct iwl_priv *priv)
283{
284 return priv->cfg->ops->lib->eeprom_ops.check_version(priv);
285}
286EXPORT_SYMBOL(iwl_eeprom_check_version);
287
288const u8 *iwl_eeprom_query_addr(const struct iwl_priv *priv, size_t offset)
289{
290 return priv->cfg->ops->lib->eeprom_ops.query_addr(priv, offset);
291}
292EXPORT_SYMBOL(iwl_eeprom_query_addr);
293
294u16 iwl_eeprom_query16(const struct iwl_priv *priv, size_t offset)
295{
296 return (u16)priv->eeprom[offset] | ((u16)priv->eeprom[offset + 1] << 8);
297}
298EXPORT_SYMBOL(iwl_eeprom_query16);
260 299
261void iwl_eeprom_get_mac(const struct iwl_priv *priv, u8 *mac) 300void iwl_eeprom_get_mac(const struct iwl_priv *priv, u8 *mac)
262{ 301{
263 memcpy(mac, priv->eeprom.mac_address, 6); 302 const u8 *addr = priv->cfg->ops->lib->eeprom_ops.query_addr(priv,
303 EEPROM_MAC_ADDRESS);
304 memcpy(mac, addr, ETH_ALEN);
264} 305}
265EXPORT_SYMBOL(iwl_eeprom_get_mac); 306EXPORT_SYMBOL(iwl_eeprom_get_mac);
266 307
267static void iwl_init_band_reference(const struct iwl_priv *priv, 308static void iwl_init_band_reference(const struct iwl_priv *priv,
268 int band, 309 int eep_band, int *eeprom_ch_count,
269 int *eeprom_ch_count, 310 const struct iwl_eeprom_channel **eeprom_ch_info,
270 const struct iwl4965_eeprom_channel 311 const u8 **eeprom_ch_index)
271 **eeprom_ch_info,
272 const u8 **eeprom_ch_index)
273{ 312{
274 switch (band) { 313 u32 offset = priv->cfg->ops->lib->
314 eeprom_ops.regulatory_bands[eep_band - 1];
315 switch (eep_band) {
275 case 1: /* 2.4GHz band */ 316 case 1: /* 2.4GHz band */
276 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_1); 317 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_1);
277 *eeprom_ch_info = priv->eeprom.band_1_channels; 318 *eeprom_ch_info = (struct iwl_eeprom_channel *)
319 iwl_eeprom_query_addr(priv, offset);
278 *eeprom_ch_index = iwl_eeprom_band_1; 320 *eeprom_ch_index = iwl_eeprom_band_1;
279 break; 321 break;
280 case 2: /* 4.9GHz band */ 322 case 2: /* 4.9GHz band */
281 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_2); 323 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_2);
282 *eeprom_ch_info = priv->eeprom.band_2_channels; 324 *eeprom_ch_info = (struct iwl_eeprom_channel *)
325 iwl_eeprom_query_addr(priv, offset);
283 *eeprom_ch_index = iwl_eeprom_band_2; 326 *eeprom_ch_index = iwl_eeprom_band_2;
284 break; 327 break;
285 case 3: /* 5.2GHz band */ 328 case 3: /* 5.2GHz band */
286 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_3); 329 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_3);
287 *eeprom_ch_info = priv->eeprom.band_3_channels; 330 *eeprom_ch_info = (struct iwl_eeprom_channel *)
331 iwl_eeprom_query_addr(priv, offset);
288 *eeprom_ch_index = iwl_eeprom_band_3; 332 *eeprom_ch_index = iwl_eeprom_band_3;
289 break; 333 break;
290 case 4: /* 5.5GHz band */ 334 case 4: /* 5.5GHz band */
291 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_4); 335 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_4);
292 *eeprom_ch_info = priv->eeprom.band_4_channels; 336 *eeprom_ch_info = (struct iwl_eeprom_channel *)
337 iwl_eeprom_query_addr(priv, offset);
293 *eeprom_ch_index = iwl_eeprom_band_4; 338 *eeprom_ch_index = iwl_eeprom_band_4;
294 break; 339 break;
295 case 5: /* 5.7GHz band */ 340 case 5: /* 5.7GHz band */
296 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_5); 341 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_5);
297 *eeprom_ch_info = priv->eeprom.band_5_channels; 342 *eeprom_ch_info = (struct iwl_eeprom_channel *)
343 iwl_eeprom_query_addr(priv, offset);
298 *eeprom_ch_index = iwl_eeprom_band_5; 344 *eeprom_ch_index = iwl_eeprom_band_5;
299 break; 345 break;
300 case 6: /* 2.4GHz FAT channels */ 346 case 6: /* 2.4GHz FAT channels */
301 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_6); 347 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_6);
302 *eeprom_ch_info = priv->eeprom.band_24_channels; 348 *eeprom_ch_info = (struct iwl_eeprom_channel *)
349 iwl_eeprom_query_addr(priv, offset);
303 *eeprom_ch_index = iwl_eeprom_band_6; 350 *eeprom_ch_index = iwl_eeprom_band_6;
304 break; 351 break;
305 case 7: /* 5 GHz FAT channels */ 352 case 7: /* 5 GHz FAT channels */
306 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_7); 353 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_7);
307 *eeprom_ch_info = priv->eeprom.band_52_channels; 354 *eeprom_ch_info = (struct iwl_eeprom_channel *)
355 iwl_eeprom_query_addr(priv, offset);
308 *eeprom_ch_index = iwl_eeprom_band_7; 356 *eeprom_ch_index = iwl_eeprom_band_7;
309 break; 357 break;
310 default: 358 default:
@@ -323,7 +371,7 @@ static void iwl_init_band_reference(const struct iwl_priv *priv,
323 */ 371 */
324static int iwl4965_set_fat_chan_info(struct iwl_priv *priv, 372static int iwl4965_set_fat_chan_info(struct iwl_priv *priv,
325 enum ieee80211_band band, u16 channel, 373 enum ieee80211_band band, u16 channel,
326 const struct iwl4965_eeprom_channel *eeprom_ch, 374 const struct iwl_eeprom_channel *eeprom_ch,
327 u8 fat_extension_channel) 375 u8 fat_extension_channel)
328{ 376{
329 struct iwl_channel_info *ch_info; 377 struct iwl_channel_info *ch_info;
@@ -334,7 +382,7 @@ static int iwl4965_set_fat_chan_info(struct iwl_priv *priv,
334 if (!is_channel_valid(ch_info)) 382 if (!is_channel_valid(ch_info))
335 return -1; 383 return -1;
336 384
337 IWL_DEBUG_INFO("FAT Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x" 385 IWL_DEBUG_INFO("FAT Ch. %d [%sGHz] %s%s%s%s%s(0x%02x"
338 " %ddBm): Ad-Hoc %ssupported\n", 386 " %ddBm): Ad-Hoc %ssupported\n",
339 ch_info->channel, 387 ch_info->channel,
340 is_channel_a_band(ch_info) ? 388 is_channel_a_band(ch_info) ?
@@ -343,7 +391,6 @@ static int iwl4965_set_fat_chan_info(struct iwl_priv *priv,
343 CHECK_AND_PRINT(ACTIVE), 391 CHECK_AND_PRINT(ACTIVE),
344 CHECK_AND_PRINT(RADAR), 392 CHECK_AND_PRINT(RADAR),
345 CHECK_AND_PRINT(WIDE), 393 CHECK_AND_PRINT(WIDE),
346 CHECK_AND_PRINT(NARROW),
347 CHECK_AND_PRINT(DFS), 394 CHECK_AND_PRINT(DFS),
348 eeprom_ch->flags, 395 eeprom_ch->flags,
349 eeprom_ch->max_power_avg, 396 eeprom_ch->max_power_avg,
@@ -372,7 +419,7 @@ int iwl_init_channel_map(struct iwl_priv *priv)
372{ 419{
373 int eeprom_ch_count = 0; 420 int eeprom_ch_count = 0;
374 const u8 *eeprom_ch_index = NULL; 421 const u8 *eeprom_ch_index = NULL;
375 const struct iwl4965_eeprom_channel *eeprom_ch_info = NULL; 422 const struct iwl_eeprom_channel *eeprom_ch_info = NULL;
376 int band, ch; 423 int band, ch;
377 struct iwl_channel_info *ch_info; 424 struct iwl_channel_info *ch_info;
378 425
@@ -381,12 +428,6 @@ int iwl_init_channel_map(struct iwl_priv *priv)
381 return 0; 428 return 0;
382 } 429 }
383 430
384 if (priv->eeprom.version < 0x2f) {
385 IWL_WARNING("Unsupported EEPROM version: 0x%04X\n",
386 priv->eeprom.version);
387 return -EINVAL;
388 }
389
390 IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n"); 431 IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
391 432
392 priv->channel_count = 433 priv->channel_count =
@@ -447,7 +488,7 @@ int iwl_init_channel_map(struct iwl_priv *priv)
447 ch_info->scan_power = eeprom_ch_info[ch].max_power_avg; 488 ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
448 ch_info->min_power = 0; 489 ch_info->min_power = 0;
449 490
450 IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s%s(0x%02x" 491 IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
451 " %ddBm): Ad-Hoc %ssupported\n", 492 " %ddBm): Ad-Hoc %ssupported\n",
452 ch_info->channel, 493 ch_info->channel,
453 is_channel_a_band(ch_info) ? 494 is_channel_a_band(ch_info) ?
@@ -457,7 +498,6 @@ int iwl_init_channel_map(struct iwl_priv *priv)
457 CHECK_AND_PRINT_I(ACTIVE), 498 CHECK_AND_PRINT_I(ACTIVE),
458 CHECK_AND_PRINT_I(RADAR), 499 CHECK_AND_PRINT_I(RADAR),
459 CHECK_AND_PRINT_I(WIDE), 500 CHECK_AND_PRINT_I(WIDE),
460 CHECK_AND_PRINT_I(NARROW),
461 CHECK_AND_PRINT_I(DFS), 501 CHECK_AND_PRINT_I(DFS),
462 eeprom_ch_info[ch].flags, 502 eeprom_ch_info[ch].flags,
463 eeprom_ch_info[ch].max_power_avg, 503 eeprom_ch_info[ch].max_power_avg,
diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom.h b/drivers/net/wireless/iwlwifi/iwl-eeprom.h
index bd0a042ca77f..dc1f027c66a0 100644
--- a/drivers/net/wireless/iwlwifi/iwl-eeprom.h
+++ b/drivers/net/wireless/iwlwifi/iwl-eeprom.h
@@ -106,7 +106,7 @@ enum {
106 EEPROM_CHANNEL_ACTIVE = (1 << 3), /* active scanning allowed */ 106 EEPROM_CHANNEL_ACTIVE = (1 << 3), /* active scanning allowed */
107 EEPROM_CHANNEL_RADAR = (1 << 4), /* radar detection required */ 107 EEPROM_CHANNEL_RADAR = (1 << 4), /* radar detection required */
108 EEPROM_CHANNEL_WIDE = (1 << 5), /* 20 MHz channel okay */ 108 EEPROM_CHANNEL_WIDE = (1 << 5), /* 20 MHz channel okay */
109 EEPROM_CHANNEL_NARROW = (1 << 6), /* 10 MHz channel (not used) */ 109 /* Bit 6 Reserved (was Narrow Channel) */
110 EEPROM_CHANNEL_DFS = (1 << 7), /* dynamic freq selection candidate */ 110 EEPROM_CHANNEL_DFS = (1 << 7), /* dynamic freq selection candidate */
111}; 111};
112 112
@@ -116,7 +116,7 @@ enum {
116 116
117/* *regulatory* channel data format in eeprom, one for each channel. 117/* *regulatory* channel data format in eeprom, one for each channel.
118 * There are separate entries for FAT (40 MHz) vs. normal (20 MHz) channels. */ 118 * There are separate entries for FAT (40 MHz) vs. normal (20 MHz) channels. */
119struct iwl4965_eeprom_channel { 119struct iwl_eeprom_channel {
120 u8 flags; /* EEPROM_CHANNEL_* flags copied from EEPROM */ 120 u8 flags; /* EEPROM_CHANNEL_* flags copied from EEPROM */
121 s8 max_power_avg; /* max power (dBm) on this chnl, limit 31 */ 121 s8 max_power_avg; /* max power (dBm) on this chnl, limit 31 */
122} __attribute__ ((packed)); 122} __attribute__ ((packed));
@@ -131,17 +131,54 @@ struct iwl4965_eeprom_channel {
131 * each of 3 target output levels */ 131 * each of 3 target output levels */
132#define EEPROM_TX_POWER_MEASUREMENTS (3) 132#define EEPROM_TX_POWER_MEASUREMENTS (3)
133 133
134#define EEPROM_4965_TX_POWER_VERSION (2) 134/* 4965 Specific */
135/* 4965 driver does not work with txpower calibration version < 5 */
136#define EEPROM_4965_TX_POWER_VERSION (5)
137#define EEPROM_4965_EEPROM_VERSION (0x2f)
138#define EEPROM_4965_CALIB_VERSION_OFFSET (2*0xB6) /* 2 bytes */
139#define EEPROM_4965_CALIB_TXPOWER_OFFSET (2*0xE8) /* 48 bytes */
140#define EEPROM_4965_BOARD_REVISION (2*0x4F) /* 2 bytes */
141#define EEPROM_4965_BOARD_PBA (2*0x56+1) /* 9 bytes */
142
143/* 5000 Specific */
144#define EEPROM_5000_TX_POWER_VERSION (4)
145#define EEPROM_5000_EEPROM_VERSION (0x11A)
146
147/*5000 calibrations */
148#define EEPROM_5000_CALIB_ALL (INDIRECT_ADDRESS | INDIRECT_CALIBRATION)
149
150/* 5000 links */
151#define EEPROM_5000_LINK_HOST (2*0x64)
152#define EEPROM_5000_LINK_GENERAL (2*0x65)
153#define EEPROM_5000_LINK_REGULATORY (2*0x66)
154#define EEPROM_5000_LINK_CALIBRATION (2*0x67)
155#define EEPROM_5000_LINK_PROCESS_ADJST (2*0x68)
156#define EEPROM_5000_LINK_OTHERS (2*0x69)
157
158/* 5000 regulatory - indirect access */
159#define EEPROM_5000_REG_SKU_ID ((0x02)\
160 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 4 bytes */
161#define EEPROM_5000_REG_BAND_1_CHANNELS ((0x08)\
162 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 28 bytes */
163#define EEPROM_5000_REG_BAND_2_CHANNELS ((0x26)\
164 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 26 bytes */
165#define EEPROM_5000_REG_BAND_3_CHANNELS ((0x42)\
166 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 24 bytes */
167#define EEPROM_5000_REG_BAND_4_CHANNELS ((0x5C)\
168 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 22 bytes */
169#define EEPROM_5000_REG_BAND_5_CHANNELS ((0x74)\
170 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 12 bytes */
171#define EEPROM_5000_REG_BAND_24_FAT_CHANNELS ((0x82)\
172 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 14 bytes */
173#define EEPROM_5000_REG_BAND_52_FAT_CHANNELS ((0x92)\
174 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 22 bytes */
135 175
136/* 4965 driver does not work with txpower calibration version < 5.
137 * Look for this in calib_version member of struct iwl4965_eeprom. */
138#define EEPROM_TX_POWER_VERSION_NEW (5)
139 176
140/* 2.4 GHz */ 177/* 2.4 GHz */
141extern const u8 iwl_eeprom_band_1[14]; 178extern const u8 iwl_eeprom_band_1[14];
142 179
143/* 180/*
144 * 4965 factory calibration data for one txpower level, on one channel, 181 * factory calibration data for one txpower level, on one channel,
145 * measured on one of the 2 tx chains (radio transmitter and associated 182 * measured on one of the 2 tx chains (radio transmitter and associated
146 * antenna). EEPROM contains: 183 * antenna). EEPROM contains:
147 * 184 *
@@ -154,7 +191,7 @@ extern const u8 iwl_eeprom_band_1[14];
154 * 191 *
155 * 4) RF power amplifier detector level measurement (not used). 192 * 4) RF power amplifier detector level measurement (not used).
156 */ 193 */
157struct iwl4965_eeprom_calib_measure { 194struct iwl_eeprom_calib_measure {
158 u8 temperature; /* Device temperature (Celsius) */ 195 u8 temperature; /* Device temperature (Celsius) */
159 u8 gain_idx; /* Index into gain table */ 196 u8 gain_idx; /* Index into gain table */
160 u8 actual_pow; /* Measured RF output power, half-dBm */ 197 u8 actual_pow; /* Measured RF output power, half-dBm */
@@ -163,22 +200,22 @@ struct iwl4965_eeprom_calib_measure {
163 200
164 201
165/* 202/*
166 * 4965 measurement set for one channel. EEPROM contains: 203 * measurement set for one channel. EEPROM contains:
167 * 204 *
168 * 1) Channel number measured 205 * 1) Channel number measured
169 * 206 *
170 * 2) Measurements for each of 3 power levels for each of 2 radio transmitters 207 * 2) Measurements for each of 3 power levels for each of 2 radio transmitters
171 * (a.k.a. "tx chains") (6 measurements altogether) 208 * (a.k.a. "tx chains") (6 measurements altogether)
172 */ 209 */
173struct iwl4965_eeprom_calib_ch_info { 210struct iwl_eeprom_calib_ch_info {
174 u8 ch_num; 211 u8 ch_num;
175 struct iwl4965_eeprom_calib_measure 212 struct iwl_eeprom_calib_measure
176 measurements[EEPROM_TX_POWER_TX_CHAINS] 213 measurements[EEPROM_TX_POWER_TX_CHAINS]
177 [EEPROM_TX_POWER_MEASUREMENTS]; 214 [EEPROM_TX_POWER_MEASUREMENTS];
178} __attribute__ ((packed)); 215} __attribute__ ((packed));
179 216
180/* 217/*
181 * 4965 txpower subband info. 218 * txpower subband info.
182 * 219 *
183 * For each frequency subband, EEPROM contains the following: 220 * For each frequency subband, EEPROM contains the following:
184 * 221 *
@@ -187,16 +224,16 @@ struct iwl4965_eeprom_calib_ch_info {
187 * 224 *
188 * 2) Sample measurement sets for 2 channels close to the range endpoints. 225 * 2) Sample measurement sets for 2 channels close to the range endpoints.
189 */ 226 */
190struct iwl4965_eeprom_calib_subband_info { 227struct iwl_eeprom_calib_subband_info {
191 u8 ch_from; /* channel number of lowest channel in subband */ 228 u8 ch_from; /* channel number of lowest channel in subband */
192 u8 ch_to; /* channel number of highest channel in subband */ 229 u8 ch_to; /* channel number of highest channel in subband */
193 struct iwl4965_eeprom_calib_ch_info ch1; 230 struct iwl_eeprom_calib_ch_info ch1;
194 struct iwl4965_eeprom_calib_ch_info ch2; 231 struct iwl_eeprom_calib_ch_info ch2;
195} __attribute__ ((packed)); 232} __attribute__ ((packed));
196 233
197 234
198/* 235/*
199 * 4965 txpower calibration info. EEPROM contains: 236 * txpower calibration info. EEPROM contains:
200 * 237 *
201 * 1) Factory-measured saturation power levels (maximum levels at which 238 * 1) Factory-measured saturation power levels (maximum levels at which
202 * tx power amplifier can output a signal without too much distortion). 239 * tx power amplifier can output a signal without too much distortion).
@@ -212,55 +249,58 @@ struct iwl4965_eeprom_calib_subband_info {
212 * characteristics of the analog radio circuitry vary with frequency. 249 * characteristics of the analog radio circuitry vary with frequency.
213 * 250 *
214 * Not all sets need to be filled with data; 251 * Not all sets need to be filled with data;
215 * struct iwl4965_eeprom_calib_subband_info contains range of channels 252 * struct iwl_eeprom_calib_subband_info contains range of channels
216 * (0 if unused) for each set of data. 253 * (0 if unused) for each set of data.
217 */ 254 */
218struct iwl4965_eeprom_calib_info { 255struct iwl_eeprom_calib_info {
219 u8 saturation_power24; /* half-dBm (e.g. "34" = 17 dBm) */ 256 u8 saturation_power24; /* half-dBm (e.g. "34" = 17 dBm) */
220 u8 saturation_power52; /* half-dBm */ 257 u8 saturation_power52; /* half-dBm */
221 s16 voltage; /* signed */ 258 s16 voltage; /* signed */
222 struct iwl4965_eeprom_calib_subband_info 259 struct iwl_eeprom_calib_subband_info
223 band_info[EEPROM_TX_POWER_BANDS]; 260 band_info[EEPROM_TX_POWER_BANDS];
224} __attribute__ ((packed)); 261} __attribute__ ((packed));
225 262
226 263
227 264#define ADDRESS_MSK 0x0000FFFF
228/* 265#define INDIRECT_TYPE_MSK 0x000F0000
229 * 4965 EEPROM map 266#define INDIRECT_HOST 0x00010000
230 */ 267#define INDIRECT_GENERAL 0x00020000
231struct iwl4965_eeprom { 268#define INDIRECT_REGULATORY 0x00030000
232 u8 reserved0[16]; 269#define INDIRECT_CALIBRATION 0x00040000
233 u16 device_id; /* abs.ofs: 16 */ 270#define INDIRECT_PROCESS_ADJST 0x00050000
234 u8 reserved1[2]; 271#define INDIRECT_OTHERS 0x00060000
235 u16 pmc; /* abs.ofs: 20 */ 272#define INDIRECT_ADDRESS 0x00100000
236 u8 reserved2[20]; 273
237 u8 mac_address[6]; /* abs.ofs: 42 */ 274/* General */
238 u8 reserved3[58]; 275#define EEPROM_DEVICE_ID (2*0x08) /* 2 bytes */
239 u16 board_revision; /* abs.ofs: 106 */ 276#define EEPROM_MAC_ADDRESS (2*0x15) /* 6 bytes */
240 u8 reserved4[11]; 277#define EEPROM_BOARD_REVISION (2*0x35) /* 2 bytes */
241 u8 board_pba_number[9]; /* abs.ofs: 119 */ 278#define EEPROM_BOARD_PBA_NUMBER (2*0x3B+1) /* 9 bytes */
242 u8 reserved5[8]; 279#define EEPROM_VERSION (2*0x44) /* 2 bytes */
243 u16 version; /* abs.ofs: 136 */ 280#define EEPROM_SKU_CAP (2*0x45) /* 1 bytes */
244 u8 sku_cap; /* abs.ofs: 138 */ 281#define EEPROM_LEDS_MODE (2*0x45+1) /* 1 bytes */
245 u8 leds_mode; /* abs.ofs: 139 */ 282#define EEPROM_OEM_MODE (2*0x46) /* 2 bytes */
246 u16 oem_mode; 283#define EEPROM_WOWLAN_MODE (2*0x47) /* 2 bytes */
247 u16 wowlan_mode; /* abs.ofs: 142 */ 284#define EEPROM_RADIO_CONFIG (2*0x48) /* 2 bytes */
248 u16 leds_time_interval; /* abs.ofs: 144 */ 285#define EEPROM_3945_M_VERSION (2*0x4A) /* 1 bytes */
249 u8 leds_off_time; /* abs.ofs: 146 */ 286#define EEPROM_ANTENNA_SWITCH_TYPE (2*0x4A+1) /* 1 bytes */
250 u8 leds_on_time; /* abs.ofs: 147 */ 287
251 u8 almgor_m_version; /* abs.ofs: 148 */ 288/* The following masks are to be applied on EEPROM_RADIO_CONFIG */
252 u8 antenna_switch_type; /* abs.ofs: 149 */ 289#define EEPROM_RF_CFG_TYPE_MSK(x) (x & 0x3) /* bits 0-1 */
253 u8 reserved6[8]; 290#define EEPROM_RF_CFG_STEP_MSK(x) ((x >> 2) & 0x3) /* bits 2-3 */
254 u16 board_revision_4965; /* abs.ofs: 158 */ 291#define EEPROM_RF_CFG_DASH_MSK(x) ((x >> 4) & 0x3) /* bits 4-5 */
255 u8 reserved7[13]; 292#define EEPROM_RF_CFG_PNUM_MSK(x) ((x >> 6) & 0x3) /* bits 6-7 */
256 u8 board_pba_number_4965[9]; /* abs.ofs: 173 */ 293#define EEPROM_RF_CFG_TX_ANT_MSK(x) ((x >> 8) & 0xF) /* bits 8-11 */
257 u8 reserved8[10]; 294#define EEPROM_RF_CFG_RX_ANT_MSK(x) ((x >> 12) & 0xF) /* bits 12-15 */
258 u8 sku_id[4]; /* abs.ofs: 192 */ 295
296#define EEPROM_3945_RF_CFG_TYPE_MAX 0x0
297#define EEPROM_4965_RF_CFG_TYPE_MAX 0x1
298#define EEPROM_5000_RF_CFG_TYPE_MAX 0x3
259 299
260/* 300/*
261 * Per-channel regulatory data. 301 * Per-channel regulatory data.
262 * 302 *
263 * Each channel that *might* be supported by 3945 or 4965 has a fixed location 303 * Each channel that *might* be supported by iwl has a fixed location
264 * in EEPROM containing EEPROM_CHANNEL_* usage flags (LSB) and max regulatory 304 * in EEPROM containing EEPROM_CHANNEL_* usage flags (LSB) and max regulatory
265 * txpower (MSB). 305 * txpower (MSB).
266 * 306 *
@@ -269,40 +309,38 @@ struct iwl4965_eeprom {
269 * 309 *
270 * 2.4 GHz channels 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 310 * 2.4 GHz channels 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
271 */ 311 */
272 u16 band_1_count; /* abs.ofs: 196 */ 312#define EEPROM_REGULATORY_SKU_ID (2*0x60) /* 4 bytes */
273 struct iwl4965_eeprom_channel band_1_channels[14]; /* abs.ofs: 196 */ 313#define EEPROM_REGULATORY_BAND_1 (2*0x62) /* 2 bytes */
314#define EEPROM_REGULATORY_BAND_1_CHANNELS (2*0x63) /* 28 bytes */
274 315
275/* 316/*
276 * 4.9 GHz channels 183, 184, 185, 187, 188, 189, 192, 196, 317 * 4.9 GHz channels 183, 184, 185, 187, 188, 189, 192, 196,
277 * 5.0 GHz channels 7, 8, 11, 12, 16 318 * 5.0 GHz channels 7, 8, 11, 12, 16
278 * (4915-5080MHz) (none of these is ever supported) 319 * (4915-5080MHz) (none of these is ever supported)
279 */ 320 */
280 u16 band_2_count; /* abs.ofs: 226 */ 321#define EEPROM_REGULATORY_BAND_2 (2*0x71) /* 2 bytes */
281 struct iwl4965_eeprom_channel band_2_channels[13]; /* abs.ofs: 228 */ 322#define EEPROM_REGULATORY_BAND_2_CHANNELS (2*0x72) /* 26 bytes */
282 323
283/* 324/*
284 * 5.2 GHz channels 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 325 * 5.2 GHz channels 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
285 * (5170-5320MHz) 326 * (5170-5320MHz)
286 */ 327 */
287 u16 band_3_count; /* abs.ofs: 254 */ 328#define EEPROM_REGULATORY_BAND_3 (2*0x7F) /* 2 bytes */
288 struct iwl4965_eeprom_channel band_3_channels[12]; /* abs.ofs: 256 */ 329#define EEPROM_REGULATORY_BAND_3_CHANNELS (2*0x80) /* 24 bytes */
289 330
290/* 331/*
291 * 5.5 GHz channels 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 332 * 5.5 GHz channels 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
292 * (5500-5700MHz) 333 * (5500-5700MHz)
293 */ 334 */
294 u16 band_4_count; /* abs.ofs: 280 */ 335#define EEPROM_REGULATORY_BAND_4 (2*0x8C) /* 2 bytes */
295 struct iwl4965_eeprom_channel band_4_channels[11]; /* abs.ofs: 282 */ 336#define EEPROM_REGULATORY_BAND_4_CHANNELS (2*0x8D) /* 22 bytes */
296 337
297/* 338/*
298 * 5.7 GHz channels 145, 149, 153, 157, 161, 165 339 * 5.7 GHz channels 145, 149, 153, 157, 161, 165
299 * (5725-5825MHz) 340 * (5725-5825MHz)
300 */ 341 */
301 u16 band_5_count; /* abs.ofs: 304 */ 342#define EEPROM_REGULATORY_BAND_5 (2*0x98) /* 2 bytes */
302 struct iwl4965_eeprom_channel band_5_channels[6]; /* abs.ofs: 306 */ 343#define EEPROM_REGULATORY_BAND_5_CHANNELS (2*0x99) /* 12 bytes */
303
304 u8 reserved10[2];
305
306 344
307/* 345/*
308 * 2.4 GHz FAT channels 1 (5), 2 (6), 3 (7), 4 (8), 5 (9), 6 (10), 7 (11) 346 * 2.4 GHz FAT channels 1 (5), 2 (6), 3 (7), 4 (8), 5 (9), 6 (10), 7 (11)
@@ -319,52 +357,35 @@ struct iwl4965_eeprom {
319 * 357 *
320 * NOTE: 4965 does not support FAT channels on 2.4 GHz. 358 * NOTE: 4965 does not support FAT channels on 2.4 GHz.
321 */ 359 */
322 struct iwl4965_eeprom_channel band_24_channels[7]; /* abs.ofs: 320 */ 360#define EEPROM_4965_REGULATORY_BAND_24_FAT_CHANNELS (2*0xA0) /* 14 bytes */
323 u8 reserved11[2];
324 361
325/* 362/*
326 * 5.2 GHz FAT channels 36 (40), 44 (48), 52 (56), 60 (64), 363 * 5.2 GHz FAT channels 36 (40), 44 (48), 52 (56), 60 (64),
327 * 100 (104), 108 (112), 116 (120), 124 (128), 132 (136), 149 (153), 157 (161) 364 * 100 (104), 108 (112), 116 (120), 124 (128), 132 (136), 149 (153), 157 (161)
328 */ 365 */
329 struct iwl4965_eeprom_channel band_52_channels[11]; /* abs.ofs: 336 */ 366#define EEPROM_4965_REGULATORY_BAND_52_FAT_CHANNELS (2*0xA8) /* 22 bytes */
330 u8 reserved12[6];
331
332/*
333 * 4965 driver requires txpower calibration format version 5 or greater.
334 * Driver does not work with txpower calibration version < 5.
335 * This value is simply a 16-bit number, no major/minor versions here.
336 */
337 u16 calib_version; /* abs.ofs: 364 */
338 u8 reserved13[2];
339 u8 reserved14[96]; /* abs.ofs: 368 */
340
341/*
342 * 4965 Txpower calibration data.
343 */
344 struct iwl4965_eeprom_calib_info calib_info; /* abs.ofs: 464 */
345
346 u8 reserved16[140]; /* fill out to full 1024 byte block */
347
348
349} __attribute__ ((packed));
350
351#define IWL_EEPROM_IMAGE_SIZE 1024
352
353/* End of EEPROM */
354 367
355struct iwl_eeprom_ops { 368struct iwl_eeprom_ops {
369 const u32 regulatory_bands[7];
356 int (*verify_signature) (struct iwl_priv *priv); 370 int (*verify_signature) (struct iwl_priv *priv);
357 int (*acquire_semaphore) (struct iwl_priv *priv); 371 int (*acquire_semaphore) (struct iwl_priv *priv);
358 void (*release_semaphore) (struct iwl_priv *priv); 372 void (*release_semaphore) (struct iwl_priv *priv);
373 int (*check_version) (struct iwl_priv *priv);
374 const u8* (*query_addr) (const struct iwl_priv *priv, size_t offset);
359}; 375};
360 376
361 377
362void iwl_eeprom_get_mac(const struct iwl_priv *priv, u8 *mac); 378void iwl_eeprom_get_mac(const struct iwl_priv *priv, u8 *mac);
363int iwl_eeprom_init(struct iwl_priv *priv); 379int iwl_eeprom_init(struct iwl_priv *priv);
380void iwl_eeprom_free(struct iwl_priv *priv);
381int iwl_eeprom_check_version(struct iwl_priv *priv);
382const u8 *iwl_eeprom_query_addr(const struct iwl_priv *priv, size_t offset);
383u16 iwl_eeprom_query16(const struct iwl_priv *priv, size_t offset);
364 384
365int iwlcore_eeprom_verify_signature(struct iwl_priv *priv); 385int iwlcore_eeprom_verify_signature(struct iwl_priv *priv);
366int iwlcore_eeprom_acquire_semaphore(struct iwl_priv *priv); 386int iwlcore_eeprom_acquire_semaphore(struct iwl_priv *priv);
367void iwlcore_eeprom_release_semaphore(struct iwl_priv *priv); 387void iwlcore_eeprom_release_semaphore(struct iwl_priv *priv);
388const u8 *iwlcore_eeprom_query_addr(const struct iwl_priv *priv, size_t offset);
368 389
369int iwl_init_channel_map(struct iwl_priv *priv); 390int iwl_init_channel_map(struct iwl_priv *priv);
370void iwl_free_channel_map(struct iwl_priv *priv); 391void iwl_free_channel_map(struct iwl_priv *priv);
diff --git a/drivers/net/wireless/iwlwifi/iwl-fh.h b/drivers/net/wireless/iwlwifi/iwl-fh.h
new file mode 100644
index 000000000000..944642450d3d
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-fh.h
@@ -0,0 +1,391 @@
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2005 - 2008 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
26 *
27 * Contact Information:
28 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2005 - 2008 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63
64/****************************/
65/* Flow Handler Definitions */
66/****************************/
67
68/**
69 * This I/O area is directly read/writable by driver (e.g. Linux uses writel())
70 * Addresses are offsets from device's PCI hardware base address.
71 */
72#define FH_MEM_LOWER_BOUND (0x1000)
73#define FH_MEM_UPPER_BOUND (0x1EF0)
74
75/**
76 * Keep-Warm (KW) buffer base address.
77 *
78 * Driver must allocate a 4KByte buffer that is used by 4965 for keeping the
79 * host DRAM powered on (via dummy accesses to DRAM) to maintain low-latency
80 * DRAM access when 4965 is Txing or Rxing. The dummy accesses prevent host
81 * from going into a power-savings mode that would cause higher DRAM latency,
82 * and possible data over/under-runs, before all Tx/Rx is complete.
83 *
84 * Driver loads FH_KW_MEM_ADDR_REG with the physical address (bits 35:4)
85 * of the buffer, which must be 4K aligned. Once this is set up, the 4965
86 * automatically invokes keep-warm accesses when normal accesses might not
87 * be sufficient to maintain fast DRAM response.
88 *
89 * Bit fields:
90 * 31-0: Keep-warm buffer physical base address [35:4], must be 4K aligned
91 */
92#define FH_KW_MEM_ADDR_REG (FH_MEM_LOWER_BOUND + 0x97C)
93
94
95/**
96 * TFD Circular Buffers Base (CBBC) addresses
97 *
98 * 4965 has 16 base pointer registers, one for each of 16 host-DRAM-resident
99 * circular buffers (CBs/queues) containing Transmit Frame Descriptors (TFDs)
100 * (see struct iwl_tfd_frame). These 16 pointer registers are offset by 0x04
101 * bytes from one another. Each TFD circular buffer in DRAM must be 256-byte
102 * aligned (address bits 0-7 must be 0).
103 *
104 * Bit fields in each pointer register:
105 * 27-0: TFD CB physical base address [35:8], must be 256-byte aligned
106 */
107#define FH_MEM_CBBC_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0x9D0)
108#define FH_MEM_CBBC_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xA10)
109
110/* Find TFD CB base pointer for given queue (range 0-15). */
111#define FH_MEM_CBBC_QUEUE(x) (FH_MEM_CBBC_LOWER_BOUND + (x) * 0x4)
112
113
114/**
115 * Rx SRAM Control and Status Registers (RSCSR)
116 *
117 * These registers provide handshake between driver and 4965 for the Rx queue
118 * (this queue handles *all* command responses, notifications, Rx data, etc.
119 * sent from 4965 uCode to host driver). Unlike Tx, there is only one Rx
120 * queue, and only one Rx DMA/FIFO channel. Also unlike Tx, which can
121 * concatenate up to 20 DRAM buffers to form a Tx frame, each Receive Buffer
122 * Descriptor (RBD) points to only one Rx Buffer (RB); there is a 1:1
123 * mapping between RBDs and RBs.
124 *
125 * Driver must allocate host DRAM memory for the following, and set the
126 * physical address of each into 4965 registers:
127 *
128 * 1) Receive Buffer Descriptor (RBD) circular buffer (CB), typically with 256
129 * entries (although any power of 2, up to 4096, is selectable by driver).
130 * Each entry (1 dword) points to a receive buffer (RB) of consistent size
131 * (typically 4K, although 8K or 16K are also selectable by driver).
132 * Driver sets up RB size and number of RBDs in the CB via Rx config
133 * register FH_MEM_RCSR_CHNL0_CONFIG_REG.
134 *
135 * Bit fields within one RBD:
136 * 27-0: Receive Buffer physical address bits [35:8], 256-byte aligned
137 *
138 * Driver sets physical address [35:8] of base of RBD circular buffer
139 * into FH_RSCSR_CHNL0_RBDCB_BASE_REG [27:0].
140 *
141 * 2) Rx status buffer, 8 bytes, in which 4965 indicates which Rx Buffers
142 * (RBs) have been filled, via a "write pointer", actually the index of
143 * the RB's corresponding RBD within the circular buffer. Driver sets
144 * physical address [35:4] into FH_RSCSR_CHNL0_STTS_WPTR_REG [31:0].
145 *
146 * Bit fields in lower dword of Rx status buffer (upper dword not used
147 * by driver; see struct iwl4965_shared, val0):
148 * 31-12: Not used by driver
149 * 11- 0: Index of last filled Rx buffer descriptor
150 * (4965 writes, driver reads this value)
151 *
152 * As the driver prepares Receive Buffers (RBs) for 4965 to fill, driver must
153 * enter pointers to these RBs into contiguous RBD circular buffer entries,
154 * and update the 4965's "write" index register,
155 * FH_RSCSR_CHNL0_RBDCB_WPTR_REG.
156 *
157 * This "write" index corresponds to the *next* RBD that the driver will make
158 * available, i.e. one RBD past the tail of the ready-to-fill RBDs within
159 * the circular buffer. This value should initially be 0 (before preparing any
160 * RBs), should be 8 after preparing the first 8 RBs (for example), and must
161 * wrap back to 0 at the end of the circular buffer (but don't wrap before
162 * "read" index has advanced past 1! See below).
163 * NOTE: 4965 EXPECTS THE WRITE INDEX TO BE INCREMENTED IN MULTIPLES OF 8.
164 *
165 * As the 4965 fills RBs (referenced from contiguous RBDs within the circular
166 * buffer), it updates the Rx status buffer in host DRAM, 2) described above,
167 * to tell the driver the index of the latest filled RBD. The driver must
168 * read this "read" index from DRAM after receiving an Rx interrupt from 4965.
169 *
170 * The driver must also internally keep track of a third index, which is the
171 * next RBD to process. When receiving an Rx interrupt, driver should process
172 * all filled but unprocessed RBs up to, but not including, the RB
173 * corresponding to the "read" index. For example, if "read" index becomes "1",
174 * driver may process the RB pointed to by RBD 0. Depending on volume of
175 * traffic, there may be many RBs to process.
176 *
177 * If read index == write index, 4965 thinks there is no room to put new data.
178 * Due to this, the maximum number of filled RBs is 255, instead of 256. To
179 * be safe, make sure that there is a gap of at least 2 RBDs between "write"
180 * and "read" indexes; that is, make sure that there are no more than 254
181 * buffers waiting to be filled.
182 */
183#define FH_MEM_RSCSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xBC0)
184#define FH_MEM_RSCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xC00)
185#define FH_MEM_RSCSR_CHNL0 (FH_MEM_RSCSR_LOWER_BOUND)
186
187/**
188 * Physical base address of 8-byte Rx Status buffer.
189 * Bit fields:
190 * 31-0: Rx status buffer physical base address [35:4], must 16-byte aligned.
191 */
192#define FH_RSCSR_CHNL0_STTS_WPTR_REG (FH_MEM_RSCSR_CHNL0)
193
194/**
195 * Physical base address of Rx Buffer Descriptor Circular Buffer.
196 * Bit fields:
197 * 27-0: RBD CD physical base address [35:8], must be 256-byte aligned.
198 */
199#define FH_RSCSR_CHNL0_RBDCB_BASE_REG (FH_MEM_RSCSR_CHNL0 + 0x004)
200
201/**
202 * Rx write pointer (index, really!).
203 * Bit fields:
204 * 11-0: Index of driver's most recent prepared-to-be-filled RBD, + 1.
205 * NOTE: For 256-entry circular buffer, use only bits [7:0].
206 */
207#define FH_RSCSR_CHNL0_RBDCB_WPTR_REG (FH_MEM_RSCSR_CHNL0 + 0x008)
208#define FH_RSCSR_CHNL0_WPTR (FH_RSCSR_CHNL0_RBDCB_WPTR_REG)
209
210
211/**
212 * Rx Config/Status Registers (RCSR)
213 * Rx Config Reg for channel 0 (only channel used)
214 *
215 * Driver must initialize FH_MEM_RCSR_CHNL0_CONFIG_REG as follows for
216 * normal operation (see bit fields).
217 *
218 * Clearing FH_MEM_RCSR_CHNL0_CONFIG_REG to 0 turns off Rx DMA.
219 * Driver should poll FH_MEM_RSSR_RX_STATUS_REG for
220 * FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE (bit 24) before continuing.
221 *
222 * Bit fields:
223 * 31-30: Rx DMA channel enable: '00' off/pause, '01' pause at end of frame,
224 * '10' operate normally
225 * 29-24: reserved
226 * 23-20: # RBDs in circular buffer = 2^value; use "8" for 256 RBDs (normal),
227 * min "5" for 32 RBDs, max "12" for 4096 RBDs.
228 * 19-18: reserved
229 * 17-16: size of each receive buffer; '00' 4K (normal), '01' 8K,
230 * '10' 12K, '11' 16K.
231 * 15-14: reserved
232 * 13-12: IRQ destination; '00' none, '01' host driver (normal operation)
233 * 11- 4: timeout for closing Rx buffer and interrupting host (units 32 usec)
234 * typical value 0x10 (about 1/2 msec)
235 * 3- 0: reserved
236 */
237#define FH_MEM_RCSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xC00)
238#define FH_MEM_RCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xCC0)
239#define FH_MEM_RCSR_CHNL0 (FH_MEM_RCSR_LOWER_BOUND)
240
241#define FH_MEM_RCSR_CHNL0_CONFIG_REG (FH_MEM_RCSR_CHNL0)
242
243#define FH_RCSR_CHNL0_RX_CONFIG_RB_TIMEOUT_MSK (0x00000FF0) /* bits 4-11 */
244#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_MSK (0x00001000) /* bits 12 */
245#define FH_RCSR_CHNL0_RX_CONFIG_SINGLE_FRAME_MSK (0x00008000) /* bit 15 */
246#define FH_RCSR_CHNL0_RX_CONFIG_RB_SIZE_MSK (0x00030000) /* bits 16-17 */
247#define FH_RCSR_CHNL0_RX_CONFIG_RBDBC_SIZE_MSK (0x00F00000) /* bits 20-23 */
248#define FH_RCSR_CHNL0_RX_CONFIG_DMA_CHNL_EN_MSK (0xC0000000) /* bits 30-31*/
249
250#define FH_RCSR_RX_CONFIG_RBDCB_SIZE_BITSHIFT (20)
251#define FH_RCSR_RX_CONFIG_REG_IRQ_RBTH_BITSHIFT (4)
252#define RX_RB_TIMEOUT (0x10)
253
254#define FH_RCSR_RX_CONFIG_CHNL_EN_PAUSE_VAL (0x00000000)
255#define FH_RCSR_RX_CONFIG_CHNL_EN_PAUSE_EOF_VAL (0x40000000)
256#define FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL (0x80000000)
257
258#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K (0x00000000)
259#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K (0x00010000)
260#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_12K (0x00020000)
261#define FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_16K (0x00030000)
262
263#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_NO_INT_VAL (0x00000000)
264#define FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL (0x00001000)
265
266
267/**
268 * Rx Shared Status Registers (RSSR)
269 *
270 * After stopping Rx DMA channel (writing 0 to
271 * FH_MEM_RCSR_CHNL0_CONFIG_REG), driver must poll
272 * FH_MEM_RSSR_RX_STATUS_REG until Rx channel is idle.
273 *
274 * Bit fields:
275 * 24: 1 = Channel 0 is idle
276 *
277 * FH_MEM_RSSR_SHARED_CTRL_REG and FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV
278 * contain default values that should not be altered by the driver.
279 */
280#define FH_MEM_RSSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xC40)
281#define FH_MEM_RSSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xD00)
282
283#define FH_MEM_RSSR_SHARED_CTRL_REG (FH_MEM_RSSR_LOWER_BOUND)
284#define FH_MEM_RSSR_RX_STATUS_REG (FH_MEM_RSSR_LOWER_BOUND + 0x004)
285#define FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV\
286 (FH_MEM_RSSR_LOWER_BOUND + 0x008)
287
288#define FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE (0x01000000)
289
290
291/**
292 * Transmit DMA Channel Control/Status Registers (TCSR)
293 *
294 * 4965 has one configuration register for each of 8 Tx DMA/FIFO channels
295 * supported in hardware (don't confuse these with the 16 Tx queues in DRAM,
296 * which feed the DMA/FIFO channels); config regs are separated by 0x20 bytes.
297 *
298 * To use a Tx DMA channel, driver must initialize its
299 * FH_TCSR_CHNL_TX_CONFIG_REG(chnl) with:
300 *
301 * FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
302 * FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL
303 *
304 * All other bits should be 0.
305 *
306 * Bit fields:
307 * 31-30: Tx DMA channel enable: '00' off/pause, '01' pause at end of frame,
308 * '10' operate normally
309 * 29- 4: Reserved, set to "0"
310 * 3: Enable internal DMA requests (1, normal operation), disable (0)
311 * 2- 0: Reserved, set to "0"
312 */
313#define FH_TCSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xD00)
314#define FH_TCSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xE60)
315
316/* Find Control/Status reg for given Tx DMA/FIFO channel */
317#define FH_TCSR_CHNL_TX_CONFIG_REG(_chnl) \
318 (FH_TCSR_LOWER_BOUND + 0x20 * _chnl)
319
320#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE_VAL (0x00000000)
321#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL (0x00000008)
322
323#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE (0x00000000)
324#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE_EOF (0x40000000)
325#define FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE (0x80000000)
326
327#define FH_TCSR_CHNL_NUM (7)
328
329#define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_EMPTY (0x00000000)
330#define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_WAIT (0x00002000)
331#define FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID (0x00000003)
332
333#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_NOINT (0x00000000)
334#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD (0x00100000)
335#define FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_IFTFD (0x00200000)
336
337#define FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM (20)
338#define FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX (12)
339#define FH_TCSR_CHNL_TX_CONFIG_REG(_chnl) \
340 (FH_TCSR_LOWER_BOUND + 0x20 * _chnl)
341#define FH_TCSR_CHNL_TX_CREDIT_REG(_chnl) \
342 (FH_TCSR_LOWER_BOUND + 0x20 * _chnl + 0x4)
343#define FH_TCSR_CHNL_TX_BUF_STS_REG(_chnl) \
344 (FH_TCSR_LOWER_BOUND + 0x20 * _chnl + 0x8)
345
346/**
347 * Tx Shared Status Registers (TSSR)
348 *
349 * After stopping Tx DMA channel (writing 0 to
350 * FH_TCSR_CHNL_TX_CONFIG_REG(chnl)), driver must poll
351 * FH_TSSR_TX_STATUS_REG until selected Tx channel is idle
352 * (channel's buffers empty | no pending requests).
353 *
354 * Bit fields:
355 * 31-24: 1 = Channel buffers empty (channel 7:0)
356 * 23-16: 1 = No pending requests (channel 7:0)
357 */
358#define FH_TSSR_LOWER_BOUND (FH_MEM_LOWER_BOUND + 0xEA0)
359#define FH_TSSR_UPPER_BOUND (FH_MEM_LOWER_BOUND + 0xEC0)
360
361#define FH_TSSR_TX_STATUS_REG (FH_TSSR_LOWER_BOUND + 0x010)
362
363#define FH_TSSR_TX_STATUS_REG_BIT_BUFS_EMPTY(_chnl) ((1 << (_chnl)) << 24)
364#define FH_TSSR_TX_STATUS_REG_BIT_NO_PEND_REQ(_chnl) ((1 << (_chnl)) << 16)
365
366#define FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(_chnl) \
367 (FH_TSSR_TX_STATUS_REG_BIT_BUFS_EMPTY(_chnl) | \
368 FH_TSSR_TX_STATUS_REG_BIT_NO_PEND_REQ(_chnl))
369
370
371
372#define FH_REGS_LOWER_BOUND (0x1000)
373#define FH_REGS_UPPER_BOUND (0x2000)
374
375/* Tx service channels */
376#define FH_SRVC_CHNL (9)
377#define FH_SRVC_LOWER_BOUND (FH_REGS_LOWER_BOUND + 0x9C8)
378#define FH_SRVC_UPPER_BOUND (FH_REGS_LOWER_BOUND + 0x9D0)
379#define FH_SRVC_CHNL_SRAM_ADDR_REG(_chnl) \
380 (FH_SRVC_LOWER_BOUND + ((_chnl) - 9) * 0x4)
381
382/* TFDB Area - TFDs buffer table */
383#define FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK (0xFFFFFFFF)
384#define FH_TFDIB_LOWER_BOUND (FH_REGS_LOWER_BOUND + 0x900)
385#define FH_TFDIB_UPPER_BOUND (FH_REGS_LOWER_BOUND + 0x958)
386#define FH_TFDIB_CTRL0_REG(_chnl) (FH_TFDIB_LOWER_BOUND + 0x8 * (_chnl))
387#define FH_TFDIB_CTRL1_REG(_chnl) (FH_TFDIB_LOWER_BOUND + 0x8 * (_chnl) + 0x4)
388
389/* TCSR: tx_config register values */
390#define FH_RSCSR_FRAME_SIZE_MSK (0x00003FFF) /* bits 0-13 */
391
diff --git a/drivers/net/wireless/iwlwifi/iwl-hcmd.c b/drivers/net/wireless/iwlwifi/iwl-hcmd.c
index fdb27f1cdc08..acb5a8abd786 100644
--- a/drivers/net/wireless/iwlwifi/iwl-hcmd.c
+++ b/drivers/net/wireless/iwlwifi/iwl-hcmd.c
@@ -31,7 +31,7 @@
31#include <linux/version.h> 31#include <linux/version.h>
32#include <net/mac80211.h> 32#include <net/mac80211.h>
33 33
34#include "iwl-4965.h" /* FIXME: remove */ 34#include "iwl-dev.h" /* FIXME: remove */
35#include "iwl-debug.h" 35#include "iwl-debug.h"
36#include "iwl-eeprom.h" 36#include "iwl-eeprom.h"
37#include "iwl-core.h" 37#include "iwl-core.h"
diff --git a/drivers/net/wireless/iwlwifi/iwl-led.c b/drivers/net/wireless/iwlwifi/iwl-led.c
index 03fdf5b434a1..aa6ad18494ce 100644
--- a/drivers/net/wireless/iwlwifi/iwl-led.c
+++ b/drivers/net/wireless/iwlwifi/iwl-led.c
@@ -39,7 +39,7 @@
39#include <linux/etherdevice.h> 39#include <linux/etherdevice.h>
40#include <asm/unaligned.h> 40#include <asm/unaligned.h>
41 41
42#include "iwl-4965.h" 42#include "iwl-dev.h"
43#include "iwl-core.h" 43#include "iwl-core.h"
44#include "iwl-io.h" 44#include "iwl-io.h"
45#include "iwl-helpers.h" 45#include "iwl-helpers.h"
diff --git a/drivers/net/wireless/iwlwifi/iwl-power.c b/drivers/net/wireless/iwlwifi/iwl-power.c
new file mode 100644
index 000000000000..2e71803e09ba
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-power.c
@@ -0,0 +1,423 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved.
4 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
25 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28
29
30#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/version.h>
33#include <linux/init.h>
34
35#include <net/mac80211.h>
36
37#include "iwl-eeprom.h"
38#include "iwl-dev.h"
39#include "iwl-core.h"
40#include "iwl-commands.h"
41#include "iwl-debug.h"
42#include "iwl-power.h"
43#include "iwl-helpers.h"
44
45/*
46 * Setting power level allow the card to go to sleep when not busy
47 * there are three factor that decide the power level to go to, they
48 * are list here with its priority
49 * 1- critical_power_setting this will be set according to card temperature.
50 * 2- system_power_setting this will be set by system PM manager.
51 * 3- user_power_setting this will be set by user either by writing to sys or
52 * mac80211
53 *
54 * if system_power_setting and user_power_setting is set to auto
55 * the power level will be decided according to association status and battery
56 * status.
57 *
58 */
59
60#define MSEC_TO_USEC 1024
61#define IWL_POWER_RANGE_0_MAX (2)
62#define IWL_POWER_RANGE_1_MAX (10)
63
64
65#define NOSLP __constant_cpu_to_le16(0), 0, 0
66#define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0
67#define SLP_TOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
68#define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
69 __constant_cpu_to_le32(X1), \
70 __constant_cpu_to_le32(X2), \
71 __constant_cpu_to_le32(X3), \
72 __constant_cpu_to_le32(X4)}
73
74#define IWL_POWER_ON_BATTERY IWL_POWER_INDEX_5
75#define IWL_POWER_ON_AC_DISASSOC IWL_POWER_MODE_CAM
76#define IWL_POWER_ON_AC_ASSOC IWL_POWER_MODE_CAM
77
78
79#define IWL_CT_KILL_TEMPERATURE 110
80#define IWL_MIN_POWER_TEMPERATURE 100
81#define IWL_REDUCED_POWER_TEMPERATURE 95
82
83/* default power management (not Tx power) table values */
84/* for tim 0-10 */
85static struct iwl_power_vec_entry range_0[IWL_POWER_AC] = {
86 {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
87 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 2, 2, 0xFF)}, 0},
88 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 2, 2, 0xFF)}, 0},
89 {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 2, 2, 2, 0xFF)}, 0},
90 {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 2, 4, 4, 0xFF)}, 1},
91 {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(2, 2, 4, 6, 0xFF)}, 2}
92};
93
94
95/* for tim = 3-10 */
96static struct iwl_power_vec_entry range_1[IWL_POWER_AC] = {
97 {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
98 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
99 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 3, 4, 7)}, 0},
100 {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 4, 6, 7, 9)}, 0},
101 {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 4, 6, 9, 10)}, 1},
102 {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(2, 4, 7, 10, 10)}, 2}
103};
104
105/* for tim > 11 */
106static struct iwl_power_vec_entry range_2[IWL_POWER_AC] = {
107 {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
108 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
109 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
110 {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
111 {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
112 {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
113};
114
115/* decide the right power level according to association status
116 * and battery status
117 */
118static u16 iwl_get_auto_power_mode(struct iwl_priv *priv)
119{
120 u16 mode = priv->power_data.user_power_setting;
121
122 switch (priv->power_data.user_power_setting) {
123 case IWL_POWER_AUTO:
124 /* if running on battery */
125 if (priv->power_data.is_battery_active)
126 mode = IWL_POWER_ON_BATTERY;
127 else if (iwl_is_associated(priv))
128 mode = IWL_POWER_ON_AC_ASSOC;
129 else
130 mode = IWL_POWER_ON_AC_DISASSOC;
131 break;
132 case IWL_POWER_BATTERY:
133 mode = IWL_POWER_INDEX_3;
134 break;
135 case IWL_POWER_AC:
136 mode = IWL_POWER_MODE_CAM;
137 break;
138 }
139 return mode;
140}
141
142/* initialize to default */
143static int iwl_power_init_handle(struct iwl_priv *priv)
144{
145 int ret = 0, i;
146 struct iwl_power_mgr *pow_data;
147 int size = sizeof(struct iwl_power_vec_entry) * IWL_POWER_AC;
148 u16 pci_pm;
149
150 IWL_DEBUG_POWER("Initialize power \n");
151
152 pow_data = &(priv->power_data);
153
154 memset(pow_data, 0, sizeof(*pow_data));
155
156 memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
157 memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
158 memcpy(&pow_data->pwr_range_2[0], &range_2[0], size);
159
160 ret = pci_read_config_word(priv->pci_dev,
161 PCI_LINK_CTRL, &pci_pm);
162 if (ret != 0)
163 return 0;
164 else {
165 struct iwl4965_powertable_cmd *cmd;
166
167 IWL_DEBUG_POWER("adjust power command flags\n");
168
169 for (i = 0; i < IWL_POWER_AC; i++) {
170 cmd = &pow_data->pwr_range_0[i].cmd;
171
172 if (pci_pm & 0x1)
173 cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
174 else
175 cmd->flags |= IWL_POWER_PCI_PM_MSK;
176 }
177 }
178 return ret;
179}
180
181/* adjust power command according to dtim period and power level*/
182static int iwl_update_power_command(struct iwl_priv *priv,
183 struct iwl4965_powertable_cmd *cmd,
184 u16 mode)
185{
186 int ret = 0, i;
187 u8 skip;
188 u32 max_sleep = 0;
189 struct iwl_power_vec_entry *range;
190 u8 period = 0;
191 struct iwl_power_mgr *pow_data;
192
193 if (mode > IWL_POWER_INDEX_5) {
194 IWL_DEBUG_POWER("Error invalid power mode \n");
195 return -1;
196 }
197 pow_data = &(priv->power_data);
198
199 if (pow_data->dtim_period <= IWL_POWER_RANGE_0_MAX)
200 range = &pow_data->pwr_range_0[0];
201 else if (pow_data->dtim_period <= IWL_POWER_RANGE_1_MAX)
202 range = &pow_data->pwr_range_1[0];
203 else
204 range = &pow_data->pwr_range_2[0];
205
206 period = pow_data->dtim_period;
207 memcpy(cmd, &range[mode].cmd, sizeof(struct iwl4965_powertable_cmd));
208
209 if (period == 0) {
210 period = 1;
211 skip = 0;
212 } else
213 skip = range[mode].no_dtim;
214
215 if (skip == 0) {
216 max_sleep = period;
217 cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
218 } else {
219 __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
220 max_sleep = le32_to_cpu(slp_itrvl);
221 if (max_sleep == 0xFF)
222 max_sleep = period * (skip + 1);
223 else if (max_sleep > period)
224 max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
225 cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
226 }
227
228 for (i = 0; i < IWL_POWER_VEC_SIZE; i++) {
229 if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
230 cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
231 }
232
233 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
234 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
235 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
236 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
237 le32_to_cpu(cmd->sleep_interval[0]),
238 le32_to_cpu(cmd->sleep_interval[1]),
239 le32_to_cpu(cmd->sleep_interval[2]),
240 le32_to_cpu(cmd->sleep_interval[3]),
241 le32_to_cpu(cmd->sleep_interval[4]));
242
243 return ret;
244}
245
246
247/*
248 * calucaute the final power mode index
249 */
250int iwl_power_update_mode(struct iwl_priv *priv, u8 refresh)
251{
252 struct iwl_power_mgr *setting = &(priv->power_data);
253 int ret = 0;
254 u16 uninitialized_var(final_mode);
255
256 /* If on battery, set to 3,
257 * if plugged into AC power, set to CAM ("continuously aware mode"),
258 * else user level */
259
260 switch (setting->system_power_setting) {
261 case IWL_POWER_AUTO:
262 final_mode = iwl_get_auto_power_mode(priv);
263 break;
264 case IWL_POWER_BATTERY:
265 final_mode = IWL_POWER_INDEX_3;
266 break;
267 case IWL_POWER_AC:
268 final_mode = IWL_POWER_MODE_CAM;
269 break;
270 default:
271 final_mode = setting->system_power_setting;
272 }
273
274 if (setting->critical_power_setting > final_mode)
275 final_mode = setting->critical_power_setting;
276
277 /* driver only support CAM for non STA network */
278 if (priv->iw_mode != IEEE80211_IF_TYPE_STA)
279 final_mode = IWL_POWER_MODE_CAM;
280
281 if (!iwl_is_rfkill(priv) && !setting->power_disabled &&
282 ((setting->power_mode != final_mode) || refresh)) {
283 struct iwl4965_powertable_cmd cmd;
284
285 if (final_mode != IWL_POWER_MODE_CAM)
286 set_bit(STATUS_POWER_PMI, &priv->status);
287
288 iwl_update_power_command(priv, &cmd, final_mode);
289 cmd.keep_alive_beacons = 0;
290
291 if (final_mode == IWL_POWER_INDEX_5)
292 cmd.flags |= IWL_POWER_FAST_PD;
293
294 if (priv->cfg->ops->lib->set_power)
295 ret = priv->cfg->ops->lib->set_power(priv, &cmd);
296
297 if (final_mode == IWL_POWER_MODE_CAM)
298 clear_bit(STATUS_POWER_PMI, &priv->status);
299 else
300 set_bit(STATUS_POWER_PMI, &priv->status);
301
302 if (priv->cfg->ops->lib->update_chain_flags)
303 priv->cfg->ops->lib->update_chain_flags(priv);
304
305 if (!ret)
306 setting->power_mode = final_mode;
307 }
308
309 return ret;
310}
311EXPORT_SYMBOL(iwl_power_update_mode);
312
313/* Allow other iwl code to disable/enable power management active
314 * this will be usefull for rate scale to disable PM during heavy
315 * Tx/Rx activities
316 */
317int iwl_power_disable_management(struct iwl_priv *priv)
318{
319 u16 prev_mode;
320 int ret = 0;
321
322 if (priv->power_data.power_disabled)
323 return -EBUSY;
324
325 prev_mode = priv->power_data.user_power_setting;
326 priv->power_data.user_power_setting = IWL_POWER_MODE_CAM;
327 ret = iwl_power_update_mode(priv, 0);
328 priv->power_data.power_disabled = 1;
329 priv->power_data.user_power_setting = prev_mode;
330
331 return ret;
332}
333EXPORT_SYMBOL(iwl_power_disable_management);
334
335/* Allow other iwl code to disable/enable power management active
336 * this will be usefull for rate scale to disable PM during hight
337 * valume activities
338 */
339int iwl_power_enable_management(struct iwl_priv *priv)
340{
341 int ret = 0;
342
343 priv->power_data.power_disabled = 0;
344 ret = iwl_power_update_mode(priv, 0);
345 return ret;
346}
347EXPORT_SYMBOL(iwl_power_enable_management);
348
349/* set user_power_setting */
350int iwl_power_set_user_mode(struct iwl_priv *priv, u16 mode)
351{
352 int ret = 0;
353
354 if (mode > IWL_POWER_LIMIT)
355 return -EINVAL;
356
357 priv->power_data.user_power_setting = mode;
358
359 ret = iwl_power_update_mode(priv, 0);
360
361 return ret;
362}
363EXPORT_SYMBOL(iwl_power_set_user_mode);
364
365
366/* set system_power_setting. This should be set by over all
367 * PM application.
368 */
369int iwl_power_set_system_mode(struct iwl_priv *priv, u16 mode)
370{
371 int ret = 0;
372
373 if (mode > IWL_POWER_LIMIT)
374 return -EINVAL;
375
376 priv->power_data.system_power_setting = mode;
377
378 ret = iwl_power_update_mode(priv, 0);
379
380 return ret;
381}
382EXPORT_SYMBOL(iwl_power_set_system_mode);
383
384/* initilize to default */
385void iwl_power_initialize(struct iwl_priv *priv)
386{
387
388 iwl_power_init_handle(priv);
389 priv->power_data.user_power_setting = IWL_POWER_AUTO;
390 priv->power_data.power_disabled = 0;
391 priv->power_data.system_power_setting = IWL_POWER_AUTO;
392 priv->power_data.is_battery_active = 0;
393 priv->power_data.power_disabled = 0;
394 priv->power_data.critical_power_setting = 0;
395}
396EXPORT_SYMBOL(iwl_power_initialize);
397
398/* set critical_power_setting according to temperature value */
399int iwl_power_temperature_change(struct iwl_priv *priv)
400{
401 int ret = 0;
402 u16 new_critical = priv->power_data.critical_power_setting;
403 s32 temperature = KELVIN_TO_CELSIUS(priv->last_temperature);
404
405 if (temperature > IWL_CT_KILL_TEMPERATURE)
406 return 0;
407 else if (temperature > IWL_MIN_POWER_TEMPERATURE)
408 new_critical = IWL_POWER_INDEX_5;
409 else if (temperature > IWL_REDUCED_POWER_TEMPERATURE)
410 new_critical = IWL_POWER_INDEX_3;
411 else
412 new_critical = IWL_POWER_MODE_CAM;
413
414 if (new_critical != priv->power_data.critical_power_setting)
415 priv->power_data.critical_power_setting = new_critical;
416
417 if (priv->power_data.critical_power_setting >
418 priv->power_data.power_mode)
419 ret = iwl_power_update_mode(priv, 0);
420
421 return ret;
422}
423EXPORT_SYMBOL(iwl_power_temperature_change);
diff --git a/drivers/net/wireless/iwlwifi/iwl-power.h b/drivers/net/wireless/iwlwifi/iwl-power.h
new file mode 100644
index 000000000000..b066724a1c2b
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-power.h
@@ -0,0 +1,76 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved.
4 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
25 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28#ifndef __iwl_power_setting_h__
29#define __iwl_power_setting_h__
30
31#include <net/mac80211.h>
32#include "iwl-commands.h"
33
34struct iwl_priv;
35
36#define IWL_POWER_MODE_CAM 0x00 /* Continuously Aware Mode, always on */
37#define IWL_POWER_INDEX_3 0x03
38#define IWL_POWER_INDEX_5 0x05
39#define IWL_POWER_AC 0x06
40#define IWL_POWER_BATTERY 0x07
41#define IWL_POWER_AUTO 0x08
42#define IWL_POWER_LIMIT 0x08
43#define IWL_POWER_MASK 0x0F
44#define IWL_POWER_ENABLED 0x10
45
46/* Power management (not Tx power) structures */
47
48struct iwl_power_vec_entry {
49 struct iwl4965_powertable_cmd cmd;
50 u8 no_dtim;
51};
52
53struct iwl_power_mgr {
54 spinlock_t lock;
55 struct iwl_power_vec_entry pwr_range_0[IWL_POWER_AC];
56 struct iwl_power_vec_entry pwr_range_1[IWL_POWER_AC];
57 struct iwl_power_vec_entry pwr_range_2[IWL_POWER_AC];
58 u32 dtim_period;
59 /* final power level that used to calculate final power command */
60 u8 power_mode;
61 u8 user_power_setting; /* set by user through mac80211 or sysfs */
62 u8 system_power_setting; /* set by kernel syatem tools */
63 u8 critical_power_setting; /* set if driver over heated */
64 u8 is_battery_active; /* DC/AC power */
65 u8 power_disabled; /* flag to disable using power saving level */
66};
67
68int iwl_power_update_mode(struct iwl_priv *priv, u8 refresh);
69int iwl_power_disable_management(struct iwl_priv *priv);
70int iwl_power_enable_management(struct iwl_priv *priv);
71int iwl_power_set_user_mode(struct iwl_priv *priv, u16 mode);
72int iwl_power_set_system_mode(struct iwl_priv *priv, u16 mode);
73void iwl_power_initialize(struct iwl_priv *priv);
74int iwl_power_temperature_change(struct iwl_priv *priv);
75
76#endif /* __iwl_power_setting_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-prph.h b/drivers/net/wireless/iwlwifi/iwl-prph.h
index c9cf8eef1a90..acac629386e0 100644
--- a/drivers/net/wireless/iwlwifi/iwl-prph.h
+++ b/drivers/net/wireless/iwlwifi/iwl-prph.h
@@ -239,40 +239,284 @@
239#define ALM_SCD_SBYP_MODE_1_REG (ALM_SCD_BASE + 0x02C) 239#define ALM_SCD_SBYP_MODE_1_REG (ALM_SCD_BASE + 0x02C)
240#define ALM_SCD_SBYP_MODE_2_REG (ALM_SCD_BASE + 0x030) 240#define ALM_SCD_SBYP_MODE_2_REG (ALM_SCD_BASE + 0x030)
241 241
242/**
243 * Tx Scheduler
244 *
245 * The Tx Scheduler selects the next frame to be transmitted, chosing TFDs
246 * (Transmit Frame Descriptors) from up to 16 circular Tx queues resident in
247 * host DRAM. It steers each frame's Tx command (which contains the frame
248 * data) into one of up to 7 prioritized Tx DMA FIFO channels within the
249 * device. A queue maps to only one (selectable by driver) Tx DMA channel,
250 * but one DMA channel may take input from several queues.
251 *
252 * Tx DMA channels have dedicated purposes. For 4965, they are used as follows:
253 *
254 * 0 -- EDCA BK (background) frames, lowest priority
255 * 1 -- EDCA BE (best effort) frames, normal priority
256 * 2 -- EDCA VI (video) frames, higher priority
257 * 3 -- EDCA VO (voice) and management frames, highest priority
258 * 4 -- Commands (e.g. RXON, etc.)
259 * 5 -- HCCA short frames
260 * 6 -- HCCA long frames
261 * 7 -- not used by driver (device-internal only)
262 *
263 * Driver should normally map queues 0-6 to Tx DMA/FIFO channels 0-6.
264 * In addition, driver can map queues 7-15 to Tx DMA/FIFO channels 0-3 to
265 * support 11n aggregation via EDCA DMA channels.
266 *
267 * The driver sets up each queue to work in one of two modes:
268 *
269 * 1) Scheduler-Ack, in which the scheduler automatically supports a
270 * block-ack (BA) window of up to 64 TFDs. In this mode, each queue
271 * contains TFDs for a unique combination of Recipient Address (RA)
272 * and Traffic Identifier (TID), that is, traffic of a given
273 * Quality-Of-Service (QOS) priority, destined for a single station.
274 *
275 * In scheduler-ack mode, the scheduler keeps track of the Tx status of
276 * each frame within the BA window, including whether it's been transmitted,
277 * and whether it's been acknowledged by the receiving station. The device
278 * automatically processes block-acks received from the receiving STA,
279 * and reschedules un-acked frames to be retransmitted (successful
280 * Tx completion may end up being out-of-order).
281 *
282 * The driver must maintain the queue's Byte Count table in host DRAM
283 * (struct iwl4965_sched_queue_byte_cnt_tbl) for this mode.
284 * This mode does not support fragmentation.
285 *
286 * 2) FIFO (a.k.a. non-Scheduler-ACK), in which each TFD is processed in order.
287 * The device may automatically retry Tx, but will retry only one frame
288 * at a time, until receiving ACK from receiving station, or reaching
289 * retry limit and giving up.
290 *
291 * The command queue (#4) must use this mode!
292 * This mode does not require use of the Byte Count table in host DRAM.
293 *
294 * Driver controls scheduler operation via 3 means:
295 * 1) Scheduler registers
296 * 2) Shared scheduler data base in internal 4956 SRAM
297 * 3) Shared data in host DRAM
298 *
299 * Initialization:
300 *
301 * When loading, driver should allocate memory for:
302 * 1) 16 TFD circular buffers, each with space for (typically) 256 TFDs.
303 * 2) 16 Byte Count circular buffers in 16 KBytes contiguous memory
304 * (1024 bytes for each queue).
305 *
306 * After receiving "Alive" response from uCode, driver must initialize
307 * the scheduler (especially for queue #4, the command queue, otherwise
308 * the driver can't issue commands!):
309 */
310
311/**
312 * Max Tx window size is the max number of contiguous TFDs that the scheduler
313 * can keep track of at one time when creating block-ack chains of frames.
314 * Note that "64" matches the number of ack bits in a block-ack packet.
315 * Driver should use SCD_WIN_SIZE and SCD_FRAME_LIMIT values to initialize
316 * IWL49_SCD_CONTEXT_QUEUE_OFFSET(x) values.
317 */
318#define SCD_WIN_SIZE 64
319#define SCD_FRAME_LIMIT 64
320
321/* SCD registers are internal, must be accessed via HBUS_TARG_PRPH regs */
322#define IWL49_SCD_START_OFFSET 0xa02c00
323
324/*
325 * 4965 tells driver SRAM address for internal scheduler structs via this reg.
326 * Value is valid only after "Alive" response from uCode.
327 */
328#define IWL49_SCD_SRAM_BASE_ADDR (IWL49_SCD_START_OFFSET + 0x0)
329
330/*
331 * Driver may need to update queue-empty bits after changing queue's
332 * write and read pointers (indexes) during (re-)initialization (i.e. when
333 * scheduler is not tracking what's happening).
334 * Bit fields:
335 * 31-16: Write mask -- 1: update empty bit, 0: don't change empty bit
336 * 15-00: Empty state, one for each queue -- 1: empty, 0: non-empty
337 * NOTE: This register is not used by Linux driver.
338 */
339#define IWL49_SCD_EMPTY_BITS (IWL49_SCD_START_OFFSET + 0x4)
340
341/*
342 * Physical base address of array of byte count (BC) circular buffers (CBs).
343 * Each Tx queue has a BC CB in host DRAM to support Scheduler-ACK mode.
344 * This register points to BC CB for queue 0, must be on 1024-byte boundary.
345 * Others are spaced by 1024 bytes.
346 * Each BC CB is 2 bytes * (256 + 64) = 740 bytes, followed by 384 bytes pad.
347 * (Index into a queue's BC CB) = (index into queue's TFD CB) = (SSN & 0xff).
348 * Bit fields:
349 * 25-00: Byte Count CB physical address [35:10], must be 1024-byte aligned.
350 */
351#define IWL49_SCD_DRAM_BASE_ADDR (IWL49_SCD_START_OFFSET + 0x10)
352
353/*
354 * Enables any/all Tx DMA/FIFO channels.
355 * Scheduler generates requests for only the active channels.
356 * Set this to 0xff to enable all 8 channels (normal usage).
357 * Bit fields:
358 * 7- 0: Enable (1), disable (0), one bit for each channel 0-7
359 */
360#define IWL49_SCD_TXFACT (IWL49_SCD_START_OFFSET + 0x1c)
361
362/* Mask to enable contiguous Tx DMA/FIFO channels between "lo" and "hi". */
363#define SCD_TXFACT_REG_TXFIFO_MASK(lo, hi) \
364 ((1 << (hi)) | ((1 << (hi)) - (1 << (lo))))
365
366/*
367 * Queue (x) Write Pointers (indexes, really!), one for each Tx queue.
368 * Initialized and updated by driver as new TFDs are added to queue.
369 * NOTE: If using Block Ack, index must correspond to frame's
370 * Start Sequence Number; index = (SSN & 0xff)
371 * NOTE: Alternative to HBUS_TARG_WRPTR, which is what Linux driver uses?
372 */
373#define IWL49_SCD_QUEUE_WRPTR(x) (IWL49_SCD_START_OFFSET + 0x24 + (x) * 4)
374
375/*
376 * Queue (x) Read Pointers (indexes, really!), one for each Tx queue.
377 * For FIFO mode, index indicates next frame to transmit.
378 * For Scheduler-ACK mode, index indicates first frame in Tx window.
379 * Initialized by driver, updated by scheduler.
380 */
381#define IWL49_SCD_QUEUE_RDPTR(x) (IWL49_SCD_START_OFFSET + 0x64 + (x) * 4)
382
383/*
384 * Select which queues work in chain mode (1) vs. not (0).
385 * Use chain mode to build chains of aggregated frames.
386 * Bit fields:
387 * 31-16: Reserved
388 * 15-00: Mode, one bit for each queue -- 1: Chain mode, 0: one-at-a-time
389 * NOTE: If driver sets up queue for chain mode, it should be also set up
390 * Scheduler-ACK mode as well, via SCD_QUEUE_STATUS_BITS(x).
391 */
392#define IWL49_SCD_QUEUECHAIN_SEL (IWL49_SCD_START_OFFSET + 0xd0)
393
394/*
395 * Select which queues interrupt driver when scheduler increments
396 * a queue's read pointer (index).
397 * Bit fields:
398 * 31-16: Reserved
399 * 15-00: Interrupt enable, one bit for each queue -- 1: enabled, 0: disabled
400 * NOTE: This functionality is apparently a no-op; driver relies on interrupts
401 * from Rx queue to read Tx command responses and update Tx queues.
402 */
403#define IWL49_SCD_INTERRUPT_MASK (IWL49_SCD_START_OFFSET + 0xe4)
404
405/*
406 * Queue search status registers. One for each queue.
407 * Sets up queue mode and assigns queue to Tx DMA channel.
408 * Bit fields:
409 * 19-10: Write mask/enable bits for bits 0-9
410 * 9: Driver should init to "0"
411 * 8: Scheduler-ACK mode (1), non-Scheduler-ACK (i.e. FIFO) mode (0).
412 * Driver should init to "1" for aggregation mode, or "0" otherwise.
413 * 7-6: Driver should init to "0"
414 * 5: Window Size Left; indicates whether scheduler can request
415 * another TFD, based on window size, etc. Driver should init
416 * this bit to "1" for aggregation mode, or "0" for non-agg.
417 * 4-1: Tx FIFO to use (range 0-7).
418 * 0: Queue is active (1), not active (0).
419 * Other bits should be written as "0"
420 *
421 * NOTE: If enabling Scheduler-ACK mode, chain mode should also be enabled
422 * via SCD_QUEUECHAIN_SEL.
423 */
424#define IWL49_SCD_QUEUE_STATUS_BITS(x)\
425 (IWL49_SCD_START_OFFSET + 0x104 + (x) * 4)
426
427/* Bit field positions */
428#define IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE (0)
429#define IWL49_SCD_QUEUE_STTS_REG_POS_TXF (1)
430#define IWL49_SCD_QUEUE_STTS_REG_POS_WSL (5)
431#define IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACK (8)
432
433/* Write masks */
434#define IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN (10)
435#define IWL49_SCD_QUEUE_STTS_REG_MSK (0x0007FC00)
436
437/**
438 * 4965 internal SRAM structures for scheduler, shared with driver ...
439 *
440 * Driver should clear and initialize the following areas after receiving
441 * "Alive" response from 4965 uCode, i.e. after initial
442 * uCode load, or after a uCode load done for error recovery:
443 *
444 * SCD_CONTEXT_DATA_OFFSET (size 128 bytes)
445 * SCD_TX_STTS_BITMAP_OFFSET (size 256 bytes)
446 * SCD_TRANSLATE_TBL_OFFSET (size 32 bytes)
447 *
448 * Driver accesses SRAM via HBUS_TARG_MEM_* registers.
449 * Driver reads base address of this scheduler area from SCD_SRAM_BASE_ADDR.
450 * All OFFSET values must be added to this base address.
451 */
452
453/*
454 * Queue context. One 8-byte entry for each of 16 queues.
455 *
456 * Driver should clear this entire area (size 0x80) to 0 after receiving
457 * "Alive" notification from uCode. Additionally, driver should init
458 * each queue's entry as follows:
459 *
460 * LS Dword bit fields:
461 * 0-06: Max Tx window size for Scheduler-ACK. Driver should init to 64.
462 *
463 * MS Dword bit fields:
464 * 16-22: Frame limit. Driver should init to 10 (0xa).
465 *
466 * Driver should init all other bits to 0.
467 *
468 * Init must be done after driver receives "Alive" response from 4965 uCode,
469 * and when setting up queue for aggregation.
470 */
471#define IWL49_SCD_CONTEXT_DATA_OFFSET 0x380
472#define IWL49_SCD_CONTEXT_QUEUE_OFFSET(x) \
473 (IWL49_SCD_CONTEXT_DATA_OFFSET + ((x) * 8))
474
475#define IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS (0)
476#define IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK (0x0000007F)
477#define IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS (16)
478#define IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK (0x007F0000)
479
242/* 480/*
243 * 4965 Tx Scheduler registers. 481 * Tx Status Bitmap
244 * Details are documented in iwl-4965-hw.h 482 *
483 * Driver should clear this entire area (size 0x100) to 0 after receiving
484 * "Alive" notification from uCode. Area is used only by device itself;
485 * no other support (besides clearing) is required from driver.
245 */ 486 */
246#define IWL49_SCD_BASE (PRPH_BASE + 0xa02c00) 487#define IWL49_SCD_TX_STTS_BITMAP_OFFSET 0x400
247 488
248#define IWL49_SCD_SRAM_BASE_ADDR (IWL49_SCD_BASE + 0x0) 489/*
249#define IWL49_SCD_EMPTY_BITS (IWL49_SCD_BASE + 0x4) 490 * RAxTID to queue translation mapping.
250#define IWL49_SCD_DRAM_BASE_ADDR (IWL49_SCD_BASE + 0x10) 491 *
251#define IWL49_SCD_AIT (IWL49_SCD_BASE + 0x18) 492 * When queue is in Scheduler-ACK mode, frames placed in a that queue must be
252#define IWL49_SCD_TXFACT (IWL49_SCD_BASE + 0x1c) 493 * for only one combination of receiver address (RA) and traffic ID (TID), i.e.
253#define IWL49_SCD_QUEUE_WRPTR(x) (IWL49_SCD_BASE + 0x24 + (x) * 4) 494 * one QOS priority level destined for one station (for this wireless link,
254#define IWL49_SCD_QUEUE_RDPTR(x) (IWL49_SCD_BASE + 0x64 + (x) * 4) 495 * not final destination). The SCD_TRANSLATE_TABLE area provides 16 16-bit
255#define IWL49_SCD_SETQUEUENUM (IWL49_SCD_BASE + 0xa4) 496 * mappings, one for each of the 16 queues. If queue is not in Scheduler-ACK
256#define IWL49_SCD_SET_TXSTAT_TXED (IWL49_SCD_BASE + 0xa8) 497 * mode, the device ignores the mapping value.
257#define IWL49_SCD_SET_TXSTAT_DONE (IWL49_SCD_BASE + 0xac) 498 *
258#define IWL49_SCD_SET_TXSTAT_NOT_SCHD (IWL49_SCD_BASE + 0xb0) 499 * Bit fields, for each 16-bit map:
259#define IWL49_SCD_DECREASE_CREDIT (IWL49_SCD_BASE + 0xb4) 500 * 15-9: Reserved, set to 0
260#define IWL49_SCD_DECREASE_SCREDIT (IWL49_SCD_BASE + 0xb8) 501 * 8-4: Index into device's station table for recipient station
261#define IWL49_SCD_LOAD_CREDIT (IWL49_SCD_BASE + 0xbc) 502 * 3-0: Traffic ID (tid), range 0-15
262#define IWL49_SCD_LOAD_SCREDIT (IWL49_SCD_BASE + 0xc0) 503 *
263#define IWL49_SCD_BAR (IWL49_SCD_BASE + 0xc4) 504 * Driver should clear this entire area (size 32 bytes) to 0 after receiving
264#define IWL49_SCD_BAR_DW0 (IWL49_SCD_BASE + 0xc8) 505 * "Alive" notification from uCode. To update a 16-bit map value, driver
265#define IWL49_SCD_BAR_DW1 (IWL49_SCD_BASE + 0xcc) 506 * must read a dword-aligned value from device SRAM, replace the 16-bit map
266#define IWL49_SCD_QUEUECHAIN_SEL (IWL49_SCD_BASE + 0xd0) 507 * value of interest, and write the dword value back into device SRAM.
267#define IWL49_SCD_QUERY_REQ (IWL49_SCD_BASE + 0xd8) 508 */
268#define IWL49_SCD_QUERY_RES (IWL49_SCD_BASE + 0xdc) 509#define IWL49_SCD_TRANSLATE_TBL_OFFSET 0x500
269#define IWL49_SCD_PENDING_FRAMES (IWL49_SCD_BASE + 0xe0) 510
270#define IWL49_SCD_INTERRUPT_MASK (IWL49_SCD_BASE + 0xe4) 511/* Find translation table dword to read/write for given queue */
271#define IWL49_SCD_INTERRUPT_THRESHOLD (IWL49_SCD_BASE + 0xe8) 512#define IWL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(x) \
272#define IWL49_SCD_QUERY_MIN_FRAME_SIZE (IWL49_SCD_BASE + 0x100) 513 ((IWL49_SCD_TRANSLATE_TBL_OFFSET + ((x) * 2)) & 0xfffffffc)
273#define IWL49_SCD_QUEUE_STATUS_BITS(x) (IWL49_SCD_BASE + 0x104 + (x) * 4) 514
274 515#define IWL49_SCD_TXFIFO_POS_TID (0)
275/* SP SCD */ 516#define IWL49_SCD_TXFIFO_POS_RA (4)
517#define IWL49_SCD_QUEUE_RA_TID_MAP_RATID_MSK (0x01FF)
518
519/* 5000 SCD */
276#define IWL50_SCD_BASE (PRPH_BASE + 0xa02c00) 520#define IWL50_SCD_BASE (PRPH_BASE + 0xa02c00)
277 521
278#define IWL50_SCD_SRAM_BASE_ADDR (IWL50_SCD_BASE + 0x0) 522#define IWL50_SCD_SRAM_BASE_ADDR (IWL50_SCD_BASE + 0x0)
@@ -287,4 +531,6 @@
287#define IWL50_SCD_INTERRUPT_MASK (IWL50_SCD_BASE + 0x108) 531#define IWL50_SCD_INTERRUPT_MASK (IWL50_SCD_BASE + 0x108)
288#define IWL50_SCD_QUEUE_STATUS_BITS(x) (IWL50_SCD_BASE + 0x10c + (x) * 4) 532#define IWL50_SCD_QUEUE_STATUS_BITS(x) (IWL50_SCD_BASE + 0x10c + (x) * 4)
289 533
534/*********************** END TX SCHEDULER *************************************/
535
290#endif /* __iwl_prph_h__ */ 536#endif /* __iwl_prph_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-rfkill.c b/drivers/net/wireless/iwlwifi/iwl-rfkill.c
index 5980a5621cb8..59c8a716bd96 100644
--- a/drivers/net/wireless/iwlwifi/iwl-rfkill.c
+++ b/drivers/net/wireless/iwlwifi/iwl-rfkill.c
@@ -33,7 +33,7 @@
33#include <net/mac80211.h> 33#include <net/mac80211.h>
34 34
35#include "iwl-eeprom.h" 35#include "iwl-eeprom.h"
36#include "iwl-4965.h" 36#include "iwl-dev.h"
37#include "iwl-core.h" 37#include "iwl-core.h"
38#include "iwl-helpers.h" 38#include "iwl-helpers.h"
39 39
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.c b/drivers/net/wireless/iwlwifi/iwl-sta.c
index e4fdfaa2b9b2..31b37a1a6430 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.c
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.c
@@ -28,15 +28,48 @@
28 *****************************************************************************/ 28 *****************************************************************************/
29 29
30#include <net/mac80211.h> 30#include <net/mac80211.h>
31#include <linux/etherdevice.h>
31 32
32#include "iwl-eeprom.h" 33#include "iwl-eeprom.h"
33#include "iwl-4965.h" 34#include "iwl-dev.h"
34#include "iwl-core.h" 35#include "iwl-core.h"
35#include "iwl-sta.h" 36#include "iwl-sta.h"
36#include "iwl-io.h" 37#include "iwl-io.h"
37#include "iwl-helpers.h" 38#include "iwl-helpers.h"
38#include "iwl-4965.h" 39
39#include "iwl-sta.h" 40u8 iwl_find_station(struct iwl_priv *priv, const u8 *addr)
41{
42 int i;
43 int start = 0;
44 int ret = IWL_INVALID_STATION;
45 unsigned long flags;
46 DECLARE_MAC_BUF(mac);
47
48 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) ||
49 (priv->iw_mode == IEEE80211_IF_TYPE_AP))
50 start = IWL_STA_ID;
51
52 if (is_broadcast_ether_addr(addr))
53 return priv->hw_params.bcast_sta_id;
54
55 spin_lock_irqsave(&priv->sta_lock, flags);
56 for (i = start; i < priv->hw_params.max_stations; i++)
57 if (priv->stations[i].used &&
58 (!compare_ether_addr(priv->stations[i].sta.sta.addr,
59 addr))) {
60 ret = i;
61 goto out;
62 }
63
64 IWL_DEBUG_ASSOC_LIMIT("can not find STA %s total %d\n",
65 print_mac(mac, addr), priv->num_stations);
66
67 out:
68 spin_unlock_irqrestore(&priv->sta_lock, flags);
69 return ret;
70}
71EXPORT_SYMBOL(iwl_find_station);
72
40 73
41int iwl_get_free_ucode_key_index(struct iwl_priv *priv) 74int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
42{ 75{
@@ -172,10 +205,14 @@ static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
172 memcpy(&priv->stations[sta_id].sta.key.key[3], 205 memcpy(&priv->stations[sta_id].sta.key.key[3],
173 keyconf->key, keyconf->keylen); 206 keyconf->key, keyconf->keylen);
174 207
175 priv->stations[sta_id].sta.key.key_offset = 208 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
209 == STA_KEY_FLG_NO_ENC)
210 priv->stations[sta_id].sta.key.key_offset =
176 iwl_get_free_ucode_key_index(priv); 211 iwl_get_free_ucode_key_index(priv);
177 priv->stations[sta_id].sta.key.key_flags = key_flags; 212 /* else, we are overriding an existing key => no need to allocated room
213 * in uCode. */
178 214
215 priv->stations[sta_id].sta.key.key_flags = key_flags;
179 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; 216 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
180 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; 217 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
181 218
@@ -214,8 +251,13 @@ static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
214 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 251 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
215 keyconf->keylen); 252 keyconf->keylen);
216 253
217 priv->stations[sta_id].sta.key.key_offset = 254 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
218 iwl_get_free_ucode_key_index(priv); 255 == STA_KEY_FLG_NO_ENC)
256 priv->stations[sta_id].sta.key.key_offset =
257 iwl_get_free_ucode_key_index(priv);
258 /* else, we are overriding an existing key => no need to allocated room
259 * in uCode. */
260
219 priv->stations[sta_id].sta.key.key_flags = key_flags; 261 priv->stations[sta_id].sta.key.key_flags = key_flags;
220 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; 262 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
221 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; 263 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
@@ -243,8 +285,13 @@ static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
243 priv->stations[sta_id].keyinfo.alg = keyconf->alg; 285 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
244 priv->stations[sta_id].keyinfo.conf = keyconf; 286 priv->stations[sta_id].keyinfo.conf = keyconf;
245 priv->stations[sta_id].keyinfo.keylen = 16; 287 priv->stations[sta_id].keyinfo.keylen = 16;
246 priv->stations[sta_id].sta.key.key_offset = 288
289 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
290 == STA_KEY_FLG_NO_ENC)
291 priv->stations[sta_id].sta.key.key_offset =
247 iwl_get_free_ucode_key_index(priv); 292 iwl_get_free_ucode_key_index(priv);
293 /* else, we are overriding an existing key => no need to allocated room
294 * in uCode. */
248 295
249 /* This copy is acutally not needed: we get the key with each TX */ 296 /* This copy is acutally not needed: we get the key with each TX */
250 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16); 297 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16);
@@ -256,13 +303,31 @@ static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
256 return ret; 303 return ret;
257} 304}
258 305
259int iwl_remove_dynamic_key(struct iwl_priv *priv, u8 sta_id) 306int iwl_remove_dynamic_key(struct iwl_priv *priv,
307 struct ieee80211_key_conf *keyconf,
308 u8 sta_id)
260{ 309{
261 unsigned long flags; 310 unsigned long flags;
311 int ret = 0;
312 u16 key_flags;
313 u8 keyidx;
262 314
263 priv->key_mapping_key = 0; 315 priv->key_mapping_key = 0;
264 316
265 spin_lock_irqsave(&priv->sta_lock, flags); 317 spin_lock_irqsave(&priv->sta_lock, flags);
318 key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags);
319 keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3;
320
321 if (keyconf->keyidx != keyidx) {
322 /* We need to remove a key with index different that the one
323 * in the uCode. This means that the key we need to remove has
324 * been replaced by another one with different index.
325 * Don't do anything and return ok
326 */
327 spin_unlock_irqrestore(&priv->sta_lock, flags);
328 return 0;
329 }
330
266 if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset, 331 if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset,
267 &priv->ucode_key_table)) 332 &priv->ucode_key_table))
268 IWL_ERROR("index %d not used in uCode key table.\n", 333 IWL_ERROR("index %d not used in uCode key table.\n",
@@ -271,13 +336,16 @@ int iwl_remove_dynamic_key(struct iwl_priv *priv, u8 sta_id)
271 sizeof(struct iwl4965_hw_key)); 336 sizeof(struct iwl4965_hw_key));
272 memset(&priv->stations[sta_id].sta.key, 0, 337 memset(&priv->stations[sta_id].sta.key, 0,
273 sizeof(struct iwl4965_keyinfo)); 338 sizeof(struct iwl4965_keyinfo));
274 priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC; 339 priv->stations[sta_id].sta.key.key_flags =
340 STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
341 priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET;
275 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; 342 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
276 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; 343 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
277 spin_unlock_irqrestore(&priv->sta_lock, flags);
278 344
279 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n"); 345 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
280 return iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0); 346 ret = iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0);
347 spin_unlock_irqrestore(&priv->sta_lock, flags);
348 return ret;
281} 349}
282 350
283int iwl_set_dynamic_key(struct iwl_priv *priv, 351int iwl_set_dynamic_key(struct iwl_priv *priv,
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.h b/drivers/net/wireless/iwlwifi/iwl-sta.h
index 44f272ecc827..38b1b0a98845 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.h
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.h
@@ -29,21 +29,14 @@
29#ifndef __iwl_sta_h__ 29#ifndef __iwl_sta_h__
30#define __iwl_sta_h__ 30#define __iwl_sta_h__
31 31
32#include <net/mac80211.h>
33
34#include "iwl-eeprom.h"
35#include "iwl-core.h"
36#include "iwl-4965.h"
37#include "iwl-io.h"
38#include "iwl-helpers.h"
39
40int iwl_get_free_ucode_key_index(struct iwl_priv *priv); 32int iwl_get_free_ucode_key_index(struct iwl_priv *priv);
41int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty); 33int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty);
42int iwl_remove_default_wep_key(struct iwl_priv *priv, 34int iwl_remove_default_wep_key(struct iwl_priv *priv,
43 struct ieee80211_key_conf *key); 35 struct ieee80211_key_conf *key);
44int iwl_set_default_wep_key(struct iwl_priv *priv, 36int iwl_set_default_wep_key(struct iwl_priv *priv,
45 struct ieee80211_key_conf *key); 37 struct ieee80211_key_conf *key);
46int iwl_remove_dynamic_key(struct iwl_priv *priv, u8 sta_id);
47int iwl_set_dynamic_key(struct iwl_priv *priv, 38int iwl_set_dynamic_key(struct iwl_priv *priv,
48 struct ieee80211_key_conf *key, u8 sta_id); 39 struct ieee80211_key_conf *key, u8 sta_id);
40int iwl_remove_dynamic_key(struct iwl_priv *priv,
41 struct ieee80211_key_conf *key, u8 sta_id);
49#endif /* __iwl_sta_h__ */ 42#endif /* __iwl_sta_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index 13925b627e3b..7040cde8bc28 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -2391,7 +2391,8 @@ static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv *priv,
2391 struct sk_buff *skb_frag, 2391 struct sk_buff *skb_frag,
2392 int last_frag) 2392 int last_frag)
2393{ 2393{
2394 struct iwl3945_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo; 2394 struct iwl3945_hw_key *keyinfo =
2395 &priv->stations[ctl->hw_key->hw_key_idx].keyinfo;
2395 2396
2396 switch (keyinfo->alg) { 2397 switch (keyinfo->alg) {
2397 case ALG_CCMP: 2398 case ALG_CCMP:
@@ -2414,7 +2415,7 @@ static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv *priv,
2414 2415
2415 case ALG_WEP: 2416 case ALG_WEP:
2416 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP | 2417 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP |
2417 (ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT; 2418 (ctl->hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
2418 2419
2419 if (keyinfo->keylen == 13) 2420 if (keyinfo->keylen == 13)
2420 cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128; 2421 cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
@@ -2422,7 +2423,7 @@ static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv *priv,
2422 memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen); 2423 memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen);
2423 2424
2424 IWL_DEBUG_TX("Configuring packet for WEP encryption " 2425 IWL_DEBUG_TX("Configuring packet for WEP encryption "
2425 "with key %d\n", ctl->key_idx); 2426 "with key %d\n", ctl->hw_key->hw_key_idx);
2426 break; 2427 break;
2427 2428
2428 default: 2429 default:
@@ -4840,7 +4841,7 @@ static int iwl3945_init_channel_map(struct iwl3945_priv *priv)
4840 ch_info->scan_power = eeprom_ch_info[ch].max_power_avg; 4841 ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
4841 ch_info->min_power = 0; 4842 ch_info->min_power = 0;
4842 4843
4843 IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s%s(0x%02x" 4844 IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
4844 " %ddBm): Ad-Hoc %ssupported\n", 4845 " %ddBm): Ad-Hoc %ssupported\n",
4845 ch_info->channel, 4846 ch_info->channel,
4846 is_channel_a_band(ch_info) ? 4847 is_channel_a_band(ch_info) ?
@@ -4850,7 +4851,6 @@ static int iwl3945_init_channel_map(struct iwl3945_priv *priv)
4850 CHECK_AND_PRINT(ACTIVE), 4851 CHECK_AND_PRINT(ACTIVE),
4851 CHECK_AND_PRINT(RADAR), 4852 CHECK_AND_PRINT(RADAR),
4852 CHECK_AND_PRINT(WIDE), 4853 CHECK_AND_PRINT(WIDE),
4853 CHECK_AND_PRINT(NARROW),
4854 CHECK_AND_PRINT(DFS), 4854 CHECK_AND_PRINT(DFS),
4855 eeprom_ch_info[ch].flags, 4855 eeprom_ch_info[ch].flags,
4856 eeprom_ch_info[ch].max_power_avg, 4856 eeprom_ch_info[ch].max_power_avg,
@@ -4986,9 +4986,6 @@ static int iwl3945_get_channels_for_scan(struct iwl3945_priv *priv,
4986 if (scan_ch->type & 1) 4986 if (scan_ch->type & 1)
4987 scan_ch->type |= (direct_mask << 1); 4987 scan_ch->type |= (direct_mask << 1);
4988 4988
4989 if (is_channel_narrow(ch_info))
4990 scan_ch->type |= (1 << 7);
4991
4992 scan_ch->active_dwell = cpu_to_le16(active_dwell); 4989 scan_ch->active_dwell = cpu_to_le16(active_dwell);
4993 scan_ch->passive_dwell = cpu_to_le16(passive_dwell); 4990 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
4994 4991
@@ -7146,7 +7143,7 @@ static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
7146 return rc; 7143 return rc;
7147} 7144}
7148 7145
7149static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, int queue, 7146static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
7150 const struct ieee80211_tx_queue_params *params) 7147 const struct ieee80211_tx_queue_params *params)
7151{ 7148{
7152 struct iwl3945_priv *priv = hw->priv; 7149 struct iwl3945_priv *priv = hw->priv;
@@ -7220,9 +7217,9 @@ static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
7220 q = &txq->q; 7217 q = &txq->q;
7221 avail = iwl3945_queue_space(q); 7218 avail = iwl3945_queue_space(q);
7222 7219
7223 stats->data[i].len = q->n_window - avail; 7220 stats[i].len = q->n_window - avail;
7224 stats->data[i].limit = q->n_window - q->high_mark; 7221 stats[i].limit = q->n_window - q->high_mark;
7225 stats->data[i].count = q->n_window; 7222 stats[i].count = q->n_window;
7226 7223
7227 } 7224 }
7228 spin_unlock_irqrestore(&priv->lock, flags); 7225 spin_unlock_irqrestore(&priv->lock, flags);
diff --git a/drivers/net/wireless/iwlwifi/iwl4965-base.c b/drivers/net/wireless/iwlwifi/iwl4965-base.c
index 883b42f7e998..4406fc72d881 100644
--- a/drivers/net/wireless/iwlwifi/iwl4965-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl4965-base.c
@@ -46,11 +46,12 @@
46#include <asm/div64.h> 46#include <asm/div64.h>
47 47
48#include "iwl-eeprom.h" 48#include "iwl-eeprom.h"
49#include "iwl-4965.h" 49#include "iwl-dev.h"
50#include "iwl-core.h" 50#include "iwl-core.h"
51#include "iwl-io.h" 51#include "iwl-io.h"
52#include "iwl-helpers.h" 52#include "iwl-helpers.h"
53#include "iwl-sta.h" 53#include "iwl-sta.h"
54#include "iwl-calib.h"
54 55
55static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv *priv, 56static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv *priv,
56 struct iwl4965_tx_queue *txq); 57 struct iwl4965_tx_queue *txq);
@@ -98,7 +99,7 @@ __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr)
98 return NULL; 99 return NULL;
99} 100}
100 101
101static const struct ieee80211_supported_band *iwl4965_get_hw_mode( 102static const struct ieee80211_supported_band *iwl_get_hw_mode(
102 struct iwl_priv *priv, enum ieee80211_band band) 103 struct iwl_priv *priv, enum ieee80211_band band)
103{ 104{
104 return priv->hw->wiphy->bands[band]; 105 return priv->hw->wiphy->bands[band];
@@ -795,14 +796,6 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
795 /* station table will be cleared */ 796 /* station table will be cleared */
796 priv->assoc_station_added = 0; 797 priv->assoc_station_added = 0;
797 798
798#ifdef CONFIG_IWL4965_SENSITIVITY
799 priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT;
800 if (!priv->error_recovering)
801 priv->start_calib = 0;
802
803 iwl4965_init_sensitivity(priv, CMD_ASYNC, 1);
804#endif /* CONFIG_IWL4965_SENSITIVITY */
805
806 /* If we are currently associated and the new config requires 799 /* If we are currently associated and the new config requires
807 * an RXON_ASSOC and the new config wants the associated mask enabled, 800 * an RXON_ASSOC and the new config wants the associated mask enabled,
808 * we must clear the associated from the active configuration 801 * we must clear the associated from the active configuration
@@ -835,7 +828,7 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
835 le16_to_cpu(priv->staging_rxon.channel), 828 le16_to_cpu(priv->staging_rxon.channel),
836 print_mac(mac, priv->staging_rxon.bssid_addr)); 829 print_mac(mac, priv->staging_rxon.bssid_addr));
837 830
838 iwl4965_set_rxon_hwcrypto(priv, !priv->cfg->mod_params->sw_crypto); 831 iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
839 /* Apply the new configuration */ 832 /* Apply the new configuration */
840 rc = iwl_send_cmd_pdu(priv, REPLY_RXON, 833 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
841 sizeof(struct iwl4965_rxon_cmd), &priv->staging_rxon); 834 sizeof(struct iwl4965_rxon_cmd), &priv->staging_rxon);
@@ -846,13 +839,10 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
846 839
847 iwlcore_clear_stations_table(priv); 840 iwlcore_clear_stations_table(priv);
848 841
849#ifdef CONFIG_IWL4965_SENSITIVITY
850 if (!priv->error_recovering) 842 if (!priv->error_recovering)
851 priv->start_calib = 0; 843 priv->start_calib = 0;
852 844
853 priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT; 845 iwl_init_sensitivity(priv);
854 iwl4965_init_sensitivity(priv, CMD_ASYNC, 1);
855#endif /* CONFIG_IWL4965_SENSITIVITY */
856 846
857 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); 847 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
858 848
@@ -889,6 +879,13 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
889 return 0; 879 return 0;
890} 880}
891 881
882void iwl4965_update_chain_flags(struct iwl_priv *priv)
883{
884
885 iwl_set_rxon_chain(priv);
886 iwl4965_commit_rxon(priv);
887}
888
892static int iwl4965_send_bt_config(struct iwl_priv *priv) 889static int iwl4965_send_bt_config(struct iwl_priv *priv)
893{ 890{
894 struct iwl4965_bt_cmd bt_cmd = { 891 struct iwl4965_bt_cmd bt_cmd = {
@@ -944,13 +941,6 @@ static int iwl4965_send_scan_abort(struct iwl_priv *priv)
944 return rc; 941 return rc;
945} 942}
946 943
947static int iwl4965_card_state_sync_callback(struct iwl_priv *priv,
948 struct iwl_cmd *cmd,
949 struct sk_buff *skb)
950{
951 return 1;
952}
953
954/* 944/*
955 * CARD_STATE_CMD 945 * CARD_STATE_CMD
956 * 946 *
@@ -970,40 +960,9 @@ static int iwl4965_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_fla
970 .meta.flags = meta_flag, 960 .meta.flags = meta_flag,
971 }; 961 };
972 962
973 if (meta_flag & CMD_ASYNC)
974 cmd.meta.u.callback = iwl4965_card_state_sync_callback;
975
976 return iwl_send_cmd(priv, &cmd); 963 return iwl_send_cmd(priv, &cmd);
977} 964}
978 965
979static int iwl4965_add_sta_sync_callback(struct iwl_priv *priv,
980 struct iwl_cmd *cmd, struct sk_buff *skb)
981{
982 struct iwl4965_rx_packet *res = NULL;
983
984 if (!skb) {
985 IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
986 return 1;
987 }
988
989 res = (struct iwl4965_rx_packet *)skb->data;
990 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
991 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
992 res->hdr.flags);
993 return 1;
994 }
995
996 switch (res->u.add_sta.status) {
997 case ADD_STA_SUCCESS_MSK:
998 break;
999 default:
1000 break;
1001 }
1002
1003 /* We didn't cache the SKB; let the caller free it */
1004 return 1;
1005}
1006
1007int iwl4965_send_add_station(struct iwl_priv *priv, 966int iwl4965_send_add_station(struct iwl_priv *priv,
1008 struct iwl4965_addsta_cmd *sta, u8 flags) 967 struct iwl4965_addsta_cmd *sta, u8 flags)
1009{ 968{
@@ -1016,9 +975,7 @@ int iwl4965_send_add_station(struct iwl_priv *priv,
1016 .data = sta, 975 .data = sta,
1017 }; 976 };
1018 977
1019 if (flags & CMD_ASYNC) 978 if (!(flags & CMD_ASYNC))
1020 cmd.meta.u.callback = iwl4965_add_sta_sync_callback;
1021 else
1022 cmd.meta.flags |= CMD_WANT_SKB; 979 cmd.meta.flags |= CMD_WANT_SKB;
1023 980
1024 rc = iwl_send_cmd(priv, &cmd); 981 rc = iwl_send_cmd(priv, &cmd);
@@ -1116,17 +1073,29 @@ unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv,
1116 return priv->ibss_beacon->len; 1073 return priv->ibss_beacon->len;
1117} 1074}
1118 1075
1119static u8 iwl4965_rate_get_lowest_plcp(int rate_mask) 1076static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv)
1120{ 1077{
1121 u8 i; 1078 int i;
1079 int rate_mask;
1080
1081 /* Set rate mask*/
1082 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
1083 rate_mask = priv->active_rate_basic & 0xF;
1084 else
1085 rate_mask = priv->active_rate_basic & 0xFF0;
1122 1086
1087 /* Find lowest valid rate */
1123 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; 1088 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
1124 i = iwl4965_rates[i].next_ieee) { 1089 i = iwl4965_rates[i].next_ieee) {
1125 if (rate_mask & (1 << i)) 1090 if (rate_mask & (1 << i))
1126 return iwl4965_rates[i].plcp; 1091 return iwl4965_rates[i].plcp;
1127 } 1092 }
1128 1093
1129 return IWL_RATE_INVALID; 1094 /* No valid rate was found. Assign the lowest one */
1095 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
1096 return IWL_RATE_1M_PLCP;
1097 else
1098 return IWL_RATE_6M_PLCP;
1130} 1099}
1131 1100
1132static int iwl4965_send_beacon_cmd(struct iwl_priv *priv) 1101static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
@@ -1144,16 +1113,7 @@ static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
1144 return -ENOMEM; 1113 return -ENOMEM;
1145 } 1114 }
1146 1115
1147 if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) { 1116 rate = iwl4965_rate_get_lowest_plcp(priv);
1148 rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic &
1149 0xFF0);
1150 if (rate == IWL_INVALID_RATE)
1151 rate = IWL_RATE_6M_PLCP;
1152 } else {
1153 rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & 0xF);
1154 if (rate == IWL_INVALID_RATE)
1155 rate = IWL_RATE_1M_PLCP;
1156 }
1157 1117
1158 frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate); 1118 frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate);
1159 1119
@@ -1171,15 +1131,6 @@ static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
1171 * 1131 *
1172 ******************************************************************************/ 1132 ******************************************************************************/
1173 1133
1174static void iwl4965_unset_hw_params(struct iwl_priv *priv)
1175{
1176 if (priv->shared_virt)
1177 pci_free_consistent(priv->pci_dev,
1178 sizeof(struct iwl4965_shared),
1179 priv->shared_virt,
1180 priv->shared_phys);
1181}
1182
1183/** 1134/**
1184 * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field 1135 * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field
1185 * 1136 *
@@ -1209,6 +1160,91 @@ static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate,
1209 return ret_rates; 1160 return ret_rates;
1210} 1161}
1211 1162
1163#ifdef CONFIG_IWL4965_HT
1164static void iwl4965_ht_conf(struct iwl_priv *priv,
1165 struct ieee80211_bss_conf *bss_conf)
1166{
1167 struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf;
1168 struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf;
1169 struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
1170
1171 IWL_DEBUG_MAC80211("enter: \n");
1172
1173 iwl_conf->is_ht = bss_conf->assoc_ht;
1174
1175 if (!iwl_conf->is_ht)
1176 return;
1177
1178 priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
1179
1180 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
1181 iwl_conf->sgf |= 0x1;
1182 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
1183 iwl_conf->sgf |= 0x2;
1184
1185 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
1186 iwl_conf->max_amsdu_size =
1187 !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
1188
1189 iwl_conf->supported_chan_width =
1190 !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH);
1191 iwl_conf->extension_chan_offset =
1192 ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET;
1193 /* If no above or below channel supplied disable FAT channel */
1194 if (iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_ABOVE &&
1195 iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_BELOW)
1196 iwl_conf->supported_chan_width = 0;
1197
1198 iwl_conf->tx_mimo_ps_mode =
1199 (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
1200 memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16);
1201
1202 iwl_conf->control_channel = ht_bss_conf->primary_channel;
1203 iwl_conf->tx_chan_width =
1204 !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH);
1205 iwl_conf->ht_protection =
1206 ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION;
1207 iwl_conf->non_GF_STA_present =
1208 !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT);
1209
1210 IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel);
1211 IWL_DEBUG_MAC80211("leave\n");
1212}
1213
1214static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband,
1215 u8 *pos, int *left)
1216{
1217 struct ieee80211_ht_cap *ht_cap;
1218
1219 if (!sband || !sband->ht_info.ht_supported)
1220 return;
1221
1222 if (*left < sizeof(struct ieee80211_ht_cap))
1223 return;
1224
1225 *pos++ = sizeof(struct ieee80211_ht_cap);
1226 ht_cap = (struct ieee80211_ht_cap *) pos;
1227
1228 ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap);
1229 memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16);
1230 ht_cap->ampdu_params_info =
1231 (sband->ht_info.ampdu_factor & IEEE80211_HT_CAP_AMPDU_FACTOR) |
1232 ((sband->ht_info.ampdu_density << 2) &
1233 IEEE80211_HT_CAP_AMPDU_DENSITY);
1234 *left -= sizeof(struct ieee80211_ht_cap);
1235}
1236#else
1237static inline void iwl4965_ht_conf(struct iwl_priv *priv,
1238 struct ieee80211_bss_conf *bss_conf)
1239{
1240}
1241static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband,
1242 u8 *pos, int *left)
1243{
1244}
1245#endif
1246
1247
1212/** 1248/**
1213 * iwl4965_fill_probe_req - fill in all required fields and IE for probe request 1249 * iwl4965_fill_probe_req - fill in all required fields and IE for probe request
1214 */ 1250 */
@@ -1220,10 +1256,8 @@ static u16 iwl4965_fill_probe_req(struct iwl_priv *priv,
1220 int len = 0; 1256 int len = 0;
1221 u8 *pos = NULL; 1257 u8 *pos = NULL;
1222 u16 active_rates, ret_rates, cck_rates, active_rate_basic; 1258 u16 active_rates, ret_rates, cck_rates, active_rate_basic;
1223#ifdef CONFIG_IWL4965_HT
1224 const struct ieee80211_supported_band *sband = 1259 const struct ieee80211_supported_band *sband =
1225 iwl4965_get_hw_mode(priv, band); 1260 iwl_get_hw_mode(priv, band);
1226#endif /* CONFIG_IWL4965_HT */
1227 1261
1228 /* Make sure there is enough space for the probe request, 1262 /* Make sure there is enough space for the probe request,
1229 * two mandatory IEs and the data */ 1263 * two mandatory IEs and the data */
@@ -1306,24 +1340,19 @@ static u16 iwl4965_fill_probe_req(struct iwl_priv *priv,
1306 if (*pos > 0) 1340 if (*pos > 0)
1307 len += 2 + *pos; 1341 len += 2 + *pos;
1308 1342
1309#ifdef CONFIG_IWL4965_HT
1310 if (sband && sband->ht_info.ht_supported) {
1311 struct ieee80211_ht_cap *ht_cap;
1312 pos += (*pos) + 1;
1313 *pos++ = WLAN_EID_HT_CAPABILITY;
1314 *pos++ = sizeof(struct ieee80211_ht_cap);
1315 ht_cap = (struct ieee80211_ht_cap *)pos;
1316 ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap);
1317 memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16);
1318 ht_cap->ampdu_params_info =(sband->ht_info.ampdu_factor &
1319 IEEE80211_HT_CAP_AMPDU_FACTOR) |
1320 ((sband->ht_info.ampdu_density << 2) &
1321 IEEE80211_HT_CAP_AMPDU_DENSITY);
1322 len += 2 + sizeof(struct ieee80211_ht_cap);
1323 }
1324#endif /*CONFIG_IWL4965_HT */
1325
1326 fill_end: 1343 fill_end:
1344 /* fill in HT IE */
1345 left -= 2;
1346 if (left < 0)
1347 return 0;
1348
1349 *pos++ = WLAN_EID_HT_CAPABILITY;
1350 *pos = 0;
1351
1352 iwl_ht_cap_to_ie(sband, pos, &left);
1353
1354 if (*pos > 0)
1355 len += 2 + *pos;
1327 return (u16)len; 1356 return (u16)len;
1328} 1357}
1329 1358
@@ -1376,184 +1405,6 @@ static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force)
1376 } 1405 }
1377} 1406}
1378 1407
1379/*
1380 * Power management (not Tx power!) functions
1381 */
1382#define MSEC_TO_USEC 1024
1383
1384#define NOSLP __constant_cpu_to_le16(0), 0, 0
1385#define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0
1386#define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
1387#define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
1388 __constant_cpu_to_le32(X1), \
1389 __constant_cpu_to_le32(X2), \
1390 __constant_cpu_to_le32(X3), \
1391 __constant_cpu_to_le32(X4)}
1392
1393
1394/* default power management (not Tx power) table values */
1395/* for tim 0-10 */
1396static struct iwl4965_power_vec_entry range_0[IWL_POWER_AC] = {
1397 {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1398 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
1399 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
1400 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
1401 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
1402 {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
1403};
1404
1405/* for tim > 10 */
1406static struct iwl4965_power_vec_entry range_1[IWL_POWER_AC] = {
1407 {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1408 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
1409 SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
1410 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
1411 SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
1412 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
1413 SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
1414 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
1415 {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
1416 SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
1417};
1418
1419int iwl4965_power_init_handle(struct iwl_priv *priv)
1420{
1421 int rc = 0, i;
1422 struct iwl4965_power_mgr *pow_data;
1423 int size = sizeof(struct iwl4965_power_vec_entry) * IWL_POWER_AC;
1424 u16 pci_pm;
1425
1426 IWL_DEBUG_POWER("Initialize power \n");
1427
1428 pow_data = &(priv->power_data);
1429
1430 memset(pow_data, 0, sizeof(*pow_data));
1431
1432 pow_data->active_index = IWL_POWER_RANGE_0;
1433 pow_data->dtim_val = 0xffff;
1434
1435 memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
1436 memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
1437
1438 rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm);
1439 if (rc != 0)
1440 return 0;
1441 else {
1442 struct iwl4965_powertable_cmd *cmd;
1443
1444 IWL_DEBUG_POWER("adjust power command flags\n");
1445
1446 for (i = 0; i < IWL_POWER_AC; i++) {
1447 cmd = &pow_data->pwr_range_0[i].cmd;
1448
1449 if (pci_pm & 0x1)
1450 cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
1451 else
1452 cmd->flags |= IWL_POWER_PCI_PM_MSK;
1453 }
1454 }
1455 return rc;
1456}
1457
1458static int iwl4965_update_power_cmd(struct iwl_priv *priv,
1459 struct iwl4965_powertable_cmd *cmd, u32 mode)
1460{
1461 int rc = 0, i;
1462 u8 skip;
1463 u32 max_sleep = 0;
1464 struct iwl4965_power_vec_entry *range;
1465 u8 period = 0;
1466 struct iwl4965_power_mgr *pow_data;
1467
1468 if (mode > IWL_POWER_INDEX_5) {
1469 IWL_DEBUG_POWER("Error invalid power mode \n");
1470 return -1;
1471 }
1472 pow_data = &(priv->power_data);
1473
1474 if (pow_data->active_index == IWL_POWER_RANGE_0)
1475 range = &pow_data->pwr_range_0[0];
1476 else
1477 range = &pow_data->pwr_range_1[1];
1478
1479 memcpy(cmd, &range[mode].cmd, sizeof(struct iwl4965_powertable_cmd));
1480
1481#ifdef IWL_MAC80211_DISABLE
1482 if (priv->assoc_network != NULL) {
1483 unsigned long flags;
1484
1485 period = priv->assoc_network->tim.tim_period;
1486 }
1487#endif /*IWL_MAC80211_DISABLE */
1488 skip = range[mode].no_dtim;
1489
1490 if (period == 0) {
1491 period = 1;
1492 skip = 0;
1493 }
1494
1495 if (skip == 0) {
1496 max_sleep = period;
1497 cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
1498 } else {
1499 __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
1500 max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
1501 cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
1502 }
1503
1504 for (i = 0; i < IWL_POWER_VEC_SIZE; i++) {
1505 if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
1506 cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
1507 }
1508
1509 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
1510 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
1511 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
1512 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
1513 le32_to_cpu(cmd->sleep_interval[0]),
1514 le32_to_cpu(cmd->sleep_interval[1]),
1515 le32_to_cpu(cmd->sleep_interval[2]),
1516 le32_to_cpu(cmd->sleep_interval[3]),
1517 le32_to_cpu(cmd->sleep_interval[4]));
1518
1519 return rc;
1520}
1521
1522static int iwl4965_send_power_mode(struct iwl_priv *priv, u32 mode)
1523{
1524 u32 uninitialized_var(final_mode);
1525 int rc;
1526 struct iwl4965_powertable_cmd cmd;
1527
1528 /* If on battery, set to 3,
1529 * if plugged into AC power, set to CAM ("continuously aware mode"),
1530 * else user level */
1531 switch (mode) {
1532 case IWL_POWER_BATTERY:
1533 final_mode = IWL_POWER_INDEX_3;
1534 break;
1535 case IWL_POWER_AC:
1536 final_mode = IWL_POWER_MODE_CAM;
1537 break;
1538 default:
1539 final_mode = mode;
1540 break;
1541 }
1542
1543 cmd.keep_alive_beacons = 0;
1544
1545 iwl4965_update_power_cmd(priv, &cmd, final_mode);
1546
1547 rc = iwl_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd);
1548
1549 if (final_mode == IWL_POWER_MODE_CAM)
1550 clear_bit(STATUS_POWER_PMI, &priv->status);
1551 else
1552 set_bit(STATUS_POWER_PMI, &priv->status);
1553
1554 return rc;
1555}
1556
1557int iwl4965_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) 1408int iwl4965_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
1558{ 1409{
1559 /* Filter incoming packets to determine if they are targeted toward 1410 /* Filter incoming packets to determine if they are targeted toward
@@ -1884,7 +1735,7 @@ static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
1884 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN); 1735 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
1885 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff; 1736 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
1886 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff; 1737 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
1887 iwl4965_set_rxon_chain(priv); 1738 iwl_set_rxon_chain(priv);
1888} 1739}
1889 1740
1890static int iwl4965_set_mode(struct iwl_priv *priv, int mode) 1741static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
@@ -1936,7 +1787,7 @@ static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
1936 struct iwl_wep_key *wepkey; 1787 struct iwl_wep_key *wepkey;
1937 int keyidx = 0; 1788 int keyidx = 0;
1938 1789
1939 BUG_ON(ctl->key_idx > 3); 1790 BUG_ON(ctl->hw_key->hw_key_idx > 3);
1940 1791
1941 switch (keyinfo->alg) { 1792 switch (keyinfo->alg) {
1942 case ALG_CCMP: 1793 case ALG_CCMP:
@@ -1955,11 +1806,11 @@ static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
1955 break; 1806 break;
1956 1807
1957 case ALG_WEP: 1808 case ALG_WEP:
1958 wepkey = &priv->wep_keys[ctl->key_idx]; 1809 wepkey = &priv->wep_keys[ctl->hw_key->hw_key_idx];
1959 cmd->cmd.tx.sec_ctl = 0; 1810 cmd->cmd.tx.sec_ctl = 0;
1960 if (priv->default_wep_key) { 1811 if (priv->default_wep_key) {
1961 /* the WEP key was sent as static */ 1812 /* the WEP key was sent as static */
1962 keyidx = ctl->key_idx; 1813 keyidx = ctl->hw_key->hw_key_idx;
1963 memcpy(&cmd->cmd.tx.key[3], wepkey->key, 1814 memcpy(&cmd->cmd.tx.key[3], wepkey->key,
1964 wepkey->key_size); 1815 wepkey->key_size);
1965 if (wepkey->key_size == WEP_KEY_LEN_128) 1816 if (wepkey->key_size == WEP_KEY_LEN_128)
@@ -2086,7 +1937,7 @@ static int iwl4965_get_sta_id(struct iwl_priv *priv,
2086 1937
2087 /* If we are an AP, then find the station, or use BCAST */ 1938 /* If we are an AP, then find the station, or use BCAST */
2088 case IEEE80211_IF_TYPE_AP: 1939 case IEEE80211_IF_TYPE_AP:
2089 sta_id = iwl4965_hw_find_station(priv, hdr->addr1); 1940 sta_id = iwl_find_station(priv, hdr->addr1);
2090 if (sta_id != IWL_INVALID_STATION) 1941 if (sta_id != IWL_INVALID_STATION)
2091 return sta_id; 1942 return sta_id;
2092 return priv->hw_params.bcast_sta_id; 1943 return priv->hw_params.bcast_sta_id;
@@ -2094,7 +1945,7 @@ static int iwl4965_get_sta_id(struct iwl_priv *priv,
2094 /* If this frame is going out to an IBSS network, find the station, 1945 /* If this frame is going out to an IBSS network, find the station,
2095 * or create a new station table entry */ 1946 * or create a new station table entry */
2096 case IEEE80211_IF_TYPE_IBSS: 1947 case IEEE80211_IF_TYPE_IBSS:
2097 sta_id = iwl4965_hw_find_station(priv, hdr->addr1); 1948 sta_id = iwl_find_station(priv, hdr->addr1);
2098 if (sta_id != IWL_INVALID_STATION) 1949 if (sta_id != IWL_INVALID_STATION)
2099 return sta_id; 1950 return sta_id;
2100 1951
@@ -2196,7 +2047,7 @@ static int iwl4965_tx_skb(struct iwl_priv *priv,
2196 goto drop; 2047 goto drop;
2197 } 2048 }
2198 2049
2199 IWL_DEBUG_RATE("station Id %d\n", sta_id); 2050 IWL_DEBUG_TX("station Id %d\n", sta_id);
2200 2051
2201 qc = ieee80211_get_qos_ctrl(hdr); 2052 qc = ieee80211_get_qos_ctrl(hdr);
2202 if (qc) { 2053 if (qc) {
@@ -2367,7 +2218,7 @@ static void iwl4965_set_rate(struct iwl_priv *priv)
2367 struct ieee80211_rate *rate; 2218 struct ieee80211_rate *rate;
2368 int i; 2219 int i;
2369 2220
2370 hw = iwl4965_get_hw_mode(priv, priv->band); 2221 hw = iwl_get_hw_mode(priv, priv->band);
2371 if (!hw) { 2222 if (!hw) {
2372 IWL_ERROR("Failed to set rate: unable to get hw mode\n"); 2223 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
2373 return; 2224 return;
@@ -2466,45 +2317,6 @@ void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
2466 return; 2317 return;
2467} 2318}
2468 2319
2469void iwl4965_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb,
2470 u32 decrypt_res, struct ieee80211_rx_status *stats)
2471{
2472 u16 fc =
2473 le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control);
2474
2475 if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
2476 return;
2477
2478 if (!(fc & IEEE80211_FCTL_PROTECTED))
2479 return;
2480
2481 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
2482 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
2483 case RX_RES_STATUS_SEC_TYPE_TKIP:
2484 /* The uCode has got a bad phase 1 Key, pushes the packet.
2485 * Decryption will be done in SW. */
2486 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2487 RX_RES_STATUS_BAD_KEY_TTAK)
2488 break;
2489
2490 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2491 RX_RES_STATUS_BAD_ICV_MIC)
2492 stats->flag |= RX_FLAG_MMIC_ERROR;
2493 case RX_RES_STATUS_SEC_TYPE_WEP:
2494 case RX_RES_STATUS_SEC_TYPE_CCMP:
2495 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2496 RX_RES_STATUS_DECRYPT_OK) {
2497 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2498 stats->flag |= RX_FLAG_DECRYPTED;
2499 }
2500 break;
2501
2502 default:
2503 break;
2504 }
2505}
2506
2507
2508#define IWL_PACKET_RETRY_TIME HZ 2320#define IWL_PACKET_RETRY_TIME HZ
2509 2321
2510int iwl4965_is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) 2322int iwl4965_is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
@@ -2710,8 +2522,6 @@ static void iwl4965_txstatus_to_ieee(struct iwl_priv *priv,
2710 2522
2711 tx_sta->status.ack_signal = 0; 2523 tx_sta->status.ack_signal = 0;
2712 tx_sta->status.excessive_retries = 0; 2524 tx_sta->status.excessive_retries = 0;
2713 tx_sta->status.queue_length = 0;
2714 tx_sta->status.queue_number = 0;
2715 2525
2716 if (in_interrupt()) 2526 if (in_interrupt())
2717 ieee80211_tx_status_irqsafe(priv->hw, 2527 ieee80211_tx_status_irqsafe(priv->hw,
@@ -2788,7 +2598,7 @@ static inline int iwl4965_get_ra_sta_id(struct iwl_priv *priv,
2788 return IWL_AP_ID; 2598 return IWL_AP_ID;
2789 else { 2599 else {
2790 u8 *da = ieee80211_get_DA(hdr); 2600 u8 *da = ieee80211_get_DA(hdr);
2791 return iwl4965_hw_find_station(priv, da); 2601 return iwl_find_station(priv, da);
2792 } 2602 }
2793} 2603}
2794 2604
@@ -2847,8 +2657,6 @@ static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv,
2847 2657
2848 tx_status = &(priv->txq[txq_id].txb[idx].status); 2658 tx_status = &(priv->txq[txq_id].txb[idx].status);
2849 tx_status->retry_count = tx_resp->failure_frame; 2659 tx_status->retry_count = tx_resp->failure_frame;
2850 tx_status->queue_number = status & 0xff;
2851 tx_status->queue_length = tx_resp->failure_rts;
2852 tx_status->control.flags &= ~IEEE80211_TXCTL_AMPDU; 2660 tx_status->control.flags &= ~IEEE80211_TXCTL_AMPDU;
2853 tx_status->flags = iwl4965_is_tx_success(status)? 2661 tx_status->flags = iwl4965_is_tx_success(status)?
2854 IEEE80211_TX_STATUS_ACK : 0; 2662 IEEE80211_TX_STATUS_ACK : 0;
@@ -3008,9 +2816,6 @@ static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
3008 tx_status = &(txq->txb[txq->q.read_ptr].status); 2816 tx_status = &(txq->txb[txq->q.read_ptr].status);
3009 2817
3010 tx_status->retry_count = tx_resp->failure_frame; 2818 tx_status->retry_count = tx_resp->failure_frame;
3011 tx_status->queue_number = status;
3012 tx_status->queue_length = tx_resp->bt_kill_count;
3013 tx_status->queue_length |= tx_resp->failure_rts;
3014 tx_status->flags = 2819 tx_status->flags =
3015 iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0; 2820 iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0;
3016 iwl4965_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags), 2821 iwl4965_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags),
@@ -3425,7 +3230,7 @@ static void iwl4965_setup_rx_handlers(struct iwl_priv *priv)
3425 priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx; 3230 priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx;
3426 3231
3427 /* Set up hardware specific Rx handlers */ 3232 /* Set up hardware specific Rx handlers */
3428 iwl4965_hw_rx_handler_setup(priv); 3233 priv->cfg->ops->lib->rx_handler_setup(priv);
3429} 3234}
3430 3235
3431/** 3236/**
@@ -4620,7 +4425,7 @@ static int iwl4965_get_channels_for_scan(struct iwl_priv *priv,
4620 u16 active_dwell = 0; 4425 u16 active_dwell = 0;
4621 int added, i; 4426 int added, i;
4622 4427
4623 sband = iwl4965_get_hw_mode(priv, band); 4428 sband = iwl_get_hw_mode(priv, band);
4624 if (!sband) 4429 if (!sband)
4625 return 0; 4430 return 0;
4626 4431
@@ -4652,9 +4457,6 @@ static int iwl4965_get_channels_for_scan(struct iwl_priv *priv,
4652 if (scan_ch->type & 1) 4457 if (scan_ch->type & 1)
4653 scan_ch->type |= (direct_mask << 1); 4458 scan_ch->type |= (direct_mask << 1);
4654 4459
4655 if (is_channel_narrow(ch_info))
4656 scan_ch->type |= (1 << 7);
4657
4658 scan_ch->active_dwell = cpu_to_le16(active_dwell); 4460 scan_ch->active_dwell = cpu_to_le16(active_dwell);
4659 scan_ch->passive_dwell = cpu_to_le16(passive_dwell); 4461 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
4660 4462
@@ -4687,163 +4489,6 @@ static int iwl4965_get_channels_for_scan(struct iwl_priv *priv,
4687 return added; 4489 return added;
4688} 4490}
4689 4491
4690static void iwl4965_init_hw_rates(struct iwl_priv *priv,
4691 struct ieee80211_rate *rates)
4692{
4693 int i;
4694
4695 for (i = 0; i < IWL_RATE_COUNT; i++) {
4696 rates[i].bitrate = iwl4965_rates[i].ieee * 5;
4697 rates[i].hw_value = i; /* Rate scaling will work on indexes */
4698 rates[i].hw_value_short = i;
4699 rates[i].flags = 0;
4700 if ((i > IWL_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
4701 /*
4702 * If CCK != 1M then set short preamble rate flag.
4703 */
4704 rates[i].flags |=
4705 (iwl4965_rates[i].plcp == IWL_RATE_1M_PLCP) ?
4706 0 : IEEE80211_RATE_SHORT_PREAMBLE;
4707 }
4708 }
4709}
4710
4711/**
4712 * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom
4713 */
4714int iwl4965_init_geos(struct iwl_priv *priv)
4715{
4716 struct iwl_channel_info *ch;
4717 struct ieee80211_supported_band *sband;
4718 struct ieee80211_channel *channels;
4719 struct ieee80211_channel *geo_ch;
4720 struct ieee80211_rate *rates;
4721 int i = 0;
4722
4723 if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
4724 priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
4725 IWL_DEBUG_INFO("Geography modes already initialized.\n");
4726 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
4727 return 0;
4728 }
4729
4730 channels = kzalloc(sizeof(struct ieee80211_channel) *
4731 priv->channel_count, GFP_KERNEL);
4732 if (!channels)
4733 return -ENOMEM;
4734
4735 rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)),
4736 GFP_KERNEL);
4737 if (!rates) {
4738 kfree(channels);
4739 return -ENOMEM;
4740 }
4741
4742 /* 5.2GHz channels start after the 2.4GHz channels */
4743 sband = &priv->bands[IEEE80211_BAND_5GHZ];
4744 sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
4745 /* just OFDM */
4746 sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
4747 sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE;
4748
4749 iwl4965_init_ht_hw_capab(priv, &sband->ht_info, IEEE80211_BAND_5GHZ);
4750
4751 sband = &priv->bands[IEEE80211_BAND_2GHZ];
4752 sband->channels = channels;
4753 /* OFDM & CCK */
4754 sband->bitrates = rates;
4755 sband->n_bitrates = IWL_RATE_COUNT;
4756
4757 iwl4965_init_ht_hw_capab(priv, &sband->ht_info, IEEE80211_BAND_2GHZ);
4758
4759 priv->ieee_channels = channels;
4760 priv->ieee_rates = rates;
4761
4762 iwl4965_init_hw_rates(priv, rates);
4763
4764 for (i = 0; i < priv->channel_count; i++) {
4765 ch = &priv->channel_info[i];
4766
4767 /* FIXME: might be removed if scan is OK */
4768 if (!is_channel_valid(ch))
4769 continue;
4770
4771 if (is_channel_a_band(ch))
4772 sband = &priv->bands[IEEE80211_BAND_5GHZ];
4773 else
4774 sband = &priv->bands[IEEE80211_BAND_2GHZ];
4775
4776 geo_ch = &sband->channels[sband->n_channels++];
4777
4778 geo_ch->center_freq = ieee80211_channel_to_frequency(ch->channel);
4779 geo_ch->max_power = ch->max_power_avg;
4780 geo_ch->max_antenna_gain = 0xff;
4781 geo_ch->hw_value = ch->channel;
4782
4783 if (is_channel_valid(ch)) {
4784 if (!(ch->flags & EEPROM_CHANNEL_IBSS))
4785 geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
4786
4787 if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
4788 geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
4789
4790 if (ch->flags & EEPROM_CHANNEL_RADAR)
4791 geo_ch->flags |= IEEE80211_CHAN_RADAR;
4792
4793 if (ch->max_power_avg > priv->max_channel_txpower_limit)
4794 priv->max_channel_txpower_limit =
4795 ch->max_power_avg;
4796 } else {
4797 geo_ch->flags |= IEEE80211_CHAN_DISABLED;
4798 }
4799
4800 /* Save flags for reg domain usage */
4801 geo_ch->orig_flags = geo_ch->flags;
4802
4803 IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
4804 ch->channel, geo_ch->center_freq,
4805 is_channel_a_band(ch) ? "5.2" : "2.4",
4806 geo_ch->flags & IEEE80211_CHAN_DISABLED ?
4807 "restricted" : "valid",
4808 geo_ch->flags);
4809 }
4810
4811 if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
4812 priv->cfg->sku & IWL_SKU_A) {
4813 printk(KERN_INFO DRV_NAME
4814 ": Incorrectly detected BG card as ABG. Please send "
4815 "your PCI ID 0x%04X:0x%04X to maintainer.\n",
4816 priv->pci_dev->device, priv->pci_dev->subsystem_device);
4817 priv->cfg->sku &= ~IWL_SKU_A;
4818 }
4819
4820 printk(KERN_INFO DRV_NAME
4821 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
4822 priv->bands[IEEE80211_BAND_2GHZ].n_channels,
4823 priv->bands[IEEE80211_BAND_5GHZ].n_channels);
4824
4825 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
4826 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
4827 &priv->bands[IEEE80211_BAND_2GHZ];
4828 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
4829 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
4830 &priv->bands[IEEE80211_BAND_5GHZ];
4831
4832 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
4833
4834 return 0;
4835}
4836
4837/*
4838 * iwl4965_free_geos - undo allocations in iwl4965_init_geos
4839 */
4840void iwl4965_free_geos(struct iwl_priv *priv)
4841{
4842 kfree(priv->ieee_channels);
4843 kfree(priv->ieee_rates);
4844 clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
4845}
4846
4847/****************************************************************************** 4492/******************************************************************************
4848 * 4493 *
4849 * uCode download functions 4494 * uCode download functions
@@ -4860,146 +4505,6 @@ static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv)
4860 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); 4505 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
4861} 4506}
4862 4507
4863/**
4864 * iwl4965_verify_inst_full - verify runtime uCode image in card vs. host,
4865 * looking at all data.
4866 */
4867static int iwl4965_verify_inst_full(struct iwl_priv *priv, __le32 *image,
4868 u32 len)
4869{
4870 u32 val;
4871 u32 save_len = len;
4872 int rc = 0;
4873 u32 errcnt;
4874
4875 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
4876
4877 rc = iwl_grab_nic_access(priv);
4878 if (rc)
4879 return rc;
4880
4881 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND);
4882
4883 errcnt = 0;
4884 for (; len > 0; len -= sizeof(u32), image++) {
4885 /* read data comes through single port, auto-incr addr */
4886 /* NOTE: Use the debugless read so we don't flood kernel log
4887 * if IWL_DL_IO is set */
4888 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
4889 if (val != le32_to_cpu(*image)) {
4890 IWL_ERROR("uCode INST section is invalid at "
4891 "offset 0x%x, is 0x%x, s/b 0x%x\n",
4892 save_len - len, val, le32_to_cpu(*image));
4893 rc = -EIO;
4894 errcnt++;
4895 if (errcnt >= 20)
4896 break;
4897 }
4898 }
4899
4900 iwl_release_nic_access(priv);
4901
4902 if (!errcnt)
4903 IWL_DEBUG_INFO
4904 ("ucode image in INSTRUCTION memory is good\n");
4905
4906 return rc;
4907}
4908
4909
4910/**
4911 * iwl4965_verify_inst_sparse - verify runtime uCode image in card vs. host,
4912 * using sample data 100 bytes apart. If these sample points are good,
4913 * it's a pretty good bet that everything between them is good, too.
4914 */
4915static int iwl4965_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
4916{
4917 u32 val;
4918 int rc = 0;
4919 u32 errcnt = 0;
4920 u32 i;
4921
4922 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
4923
4924 rc = iwl_grab_nic_access(priv);
4925 if (rc)
4926 return rc;
4927
4928 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
4929 /* read data comes through single port, auto-incr addr */
4930 /* NOTE: Use the debugless read so we don't flood kernel log
4931 * if IWL_DL_IO is set */
4932 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
4933 i + RTC_INST_LOWER_BOUND);
4934 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
4935 if (val != le32_to_cpu(*image)) {
4936#if 0 /* Enable this if you want to see details */
4937 IWL_ERROR("uCode INST section is invalid at "
4938 "offset 0x%x, is 0x%x, s/b 0x%x\n",
4939 i, val, *image);
4940#endif
4941 rc = -EIO;
4942 errcnt++;
4943 if (errcnt >= 3)
4944 break;
4945 }
4946 }
4947
4948 iwl_release_nic_access(priv);
4949
4950 return rc;
4951}
4952
4953
4954/**
4955 * iwl4965_verify_ucode - determine which instruction image is in SRAM,
4956 * and verify its contents
4957 */
4958static int iwl4965_verify_ucode(struct iwl_priv *priv)
4959{
4960 __le32 *image;
4961 u32 len;
4962 int rc = 0;
4963
4964 /* Try bootstrap */
4965 image = (__le32 *)priv->ucode_boot.v_addr;
4966 len = priv->ucode_boot.len;
4967 rc = iwl4965_verify_inst_sparse(priv, image, len);
4968 if (rc == 0) {
4969 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
4970 return 0;
4971 }
4972
4973 /* Try initialize */
4974 image = (__le32 *)priv->ucode_init.v_addr;
4975 len = priv->ucode_init.len;
4976 rc = iwl4965_verify_inst_sparse(priv, image, len);
4977 if (rc == 0) {
4978 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
4979 return 0;
4980 }
4981
4982 /* Try runtime/protocol */
4983 image = (__le32 *)priv->ucode_code.v_addr;
4984 len = priv->ucode_code.len;
4985 rc = iwl4965_verify_inst_sparse(priv, image, len);
4986 if (rc == 0) {
4987 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
4988 return 0;
4989 }
4990
4991 IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
4992
4993 /* Since nothing seems to match, show first several data entries in
4994 * instruction SRAM, so maybe visual inspection will give a clue.
4995 * Selection of bootstrap image (vs. other images) is arbitrary. */
4996 image = (__le32 *)priv->ucode_boot.v_addr;
4997 len = priv->ucode_boot.len;
4998 rc = iwl4965_verify_inst_full(priv, image, len);
4999
5000 return rc;
5001}
5002
5003static void iwl4965_nic_start(struct iwl_priv *priv) 4508static void iwl4965_nic_start(struct iwl_priv *priv)
5004{ 4509{
5005 /* Remove all resets to allow NIC to operate */ 4510 /* Remove all resets to allow NIC to operate */
@@ -5075,34 +4580,34 @@ static int iwl4965_read_ucode(struct iwl_priv *priv)
5075 } 4580 }
5076 4581
5077 /* Verify that uCode images will fit in card's SRAM */ 4582 /* Verify that uCode images will fit in card's SRAM */
5078 if (inst_size > IWL_MAX_INST_SIZE) { 4583 if (inst_size > priv->hw_params.max_inst_size) {
5079 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", 4584 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
5080 inst_size); 4585 inst_size);
5081 ret = -EINVAL; 4586 ret = -EINVAL;
5082 goto err_release; 4587 goto err_release;
5083 } 4588 }
5084 4589
5085 if (data_size > IWL_MAX_DATA_SIZE) { 4590 if (data_size > priv->hw_params.max_data_size) {
5086 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", 4591 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
5087 data_size); 4592 data_size);
5088 ret = -EINVAL; 4593 ret = -EINVAL;
5089 goto err_release; 4594 goto err_release;
5090 } 4595 }
5091 if (init_size > IWL_MAX_INST_SIZE) { 4596 if (init_size > priv->hw_params.max_inst_size) {
5092 IWL_DEBUG_INFO 4597 IWL_DEBUG_INFO
5093 ("uCode init instr len %d too large to fit in\n", 4598 ("uCode init instr len %d too large to fit in\n",
5094 init_size); 4599 init_size);
5095 ret = -EINVAL; 4600 ret = -EINVAL;
5096 goto err_release; 4601 goto err_release;
5097 } 4602 }
5098 if (init_data_size > IWL_MAX_DATA_SIZE) { 4603 if (init_data_size > priv->hw_params.max_data_size) {
5099 IWL_DEBUG_INFO 4604 IWL_DEBUG_INFO
5100 ("uCode init data len %d too large to fit in\n", 4605 ("uCode init data len %d too large to fit in\n",
5101 init_data_size); 4606 init_data_size);
5102 ret = -EINVAL; 4607 ret = -EINVAL;
5103 goto err_release; 4608 goto err_release;
5104 } 4609 }
5105 if (boot_size > IWL_MAX_BSM_SIZE) { 4610 if (boot_size > priv->hw_params.max_bsm_size) {
5106 IWL_DEBUG_INFO 4611 IWL_DEBUG_INFO
5107 ("uCode boot instr len %d too large to fit in\n", 4612 ("uCode boot instr len %d too large to fit in\n",
5108 boot_size); 4613 boot_size);
@@ -5275,7 +4780,7 @@ static void iwl4965_init_alive_start(struct iwl_priv *priv)
5275 /* Bootstrap uCode has loaded initialize uCode ... verify inst image. 4780 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
5276 * This is a paranoid check, because we would not have gotten the 4781 * This is a paranoid check, because we would not have gotten the
5277 * "initialize" alive if code weren't properly loaded. */ 4782 * "initialize" alive if code weren't properly loaded. */
5278 if (iwl4965_verify_ucode(priv)) { 4783 if (iwl_verify_ucode(priv)) {
5279 /* Runtime instruction load was bad; 4784 /* Runtime instruction load was bad;
5280 * take it all the way back down so we can try again */ 4785 * take it all the way back down so we can try again */
5281 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n"); 4786 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
@@ -5323,7 +4828,7 @@ static void iwl4965_alive_start(struct iwl_priv *priv)
5323 /* Initialize uCode has loaded Runtime uCode ... verify inst image. 4828 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
5324 * This is a paranoid check, because we would not have gotten the 4829 * This is a paranoid check, because we would not have gotten the
5325 * "runtime" alive if code weren't properly loaded. */ 4830 * "runtime" alive if code weren't properly loaded. */
5326 if (iwl4965_verify_ucode(priv)) { 4831 if (iwl_verify_ucode(priv)) {
5327 /* Runtime instruction load was bad; 4832 /* Runtime instruction load was bad;
5328 * take it all the way back down so we can try again */ 4833 * take it all the way back down so we can try again */
5329 IWL_DEBUG_INFO("Bad runtime uCode load.\n"); 4834 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
@@ -5353,8 +4858,6 @@ static void iwl4965_alive_start(struct iwl_priv *priv)
5353 priv->active_rate = priv->rates_mask; 4858 priv->active_rate = priv->rates_mask;
5354 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; 4859 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
5355 4860
5356 iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode));
5357
5358 if (iwl_is_associated(priv)) { 4861 if (iwl_is_associated(priv)) {
5359 struct iwl4965_rxon_cmd *active_rxon = 4862 struct iwl4965_rxon_cmd *active_rxon =
5360 (struct iwl4965_rxon_cmd *)(&priv->active_rxon); 4863 (struct iwl4965_rxon_cmd *)(&priv->active_rxon);
@@ -5485,6 +4988,7 @@ static void __iwl4965_down(struct iwl_priv *priv)
5485 iwl4965_hw_nic_stop_master(priv); 4988 iwl4965_hw_nic_stop_master(priv);
5486 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); 4989 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
5487 iwl4965_hw_nic_reset(priv); 4990 iwl4965_hw_nic_reset(priv);
4991 priv->cfg->ops->lib->free_shared_mem(priv);
5488 4992
5489 exit: 4993 exit:
5490 memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp)); 4994 memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp));
@@ -5546,6 +5050,12 @@ static int __iwl4965_up(struct iwl_priv *priv)
5546 iwl_rfkill_set_hw_state(priv); 5050 iwl_rfkill_set_hw_state(priv);
5547 iwl_write32(priv, CSR_INT, 0xFFFFFFFF); 5051 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
5548 5052
5053 ret = priv->cfg->ops->lib->alloc_shared_mem(priv);
5054 if (ret) {
5055 IWL_ERROR("Unable to allocate shared memory\n");
5056 return ret;
5057 }
5058
5549 ret = priv->cfg->ops->lib->hw_nic_init(priv); 5059 ret = priv->cfg->ops->lib->hw_nic_init(priv);
5550 if (ret) { 5060 if (ret) {
5551 IWL_ERROR("Unable to init nic\n"); 5061 IWL_ERROR("Unable to init nic\n");
@@ -5887,6 +5397,8 @@ static void iwl4965_bg_request_scan(struct work_struct *data)
5887 direct_mask, 5397 direct_mask,
5888 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); 5398 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
5889 5399
5400 scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK |
5401 RXON_FILTER_BCON_AWARE_MSK);
5890 cmd.len += le16_to_cpu(scan->tx_cmd.len) + 5402 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
5891 scan->channel_count * sizeof(struct iwl4965_scan_channel); 5403 scan->channel_count * sizeof(struct iwl4965_scan_channel);
5892 cmd.data = scan; 5404 cmd.data = scan;
@@ -5991,7 +5503,7 @@ static void iwl4965_post_associate(struct iwl_priv *priv)
5991 if (priv->current_ht_config.is_ht) 5503 if (priv->current_ht_config.is_ht)
5992 iwl4965_set_rxon_ht(priv, &priv->current_ht_config); 5504 iwl4965_set_rxon_ht(priv, &priv->current_ht_config);
5993#endif /* CONFIG_IWL4965_HT*/ 5505#endif /* CONFIG_IWL4965_HT*/
5994 iwl4965_set_rxon_chain(priv); 5506 iwl_set_rxon_chain(priv);
5995 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); 5507 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
5996 5508
5997 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", 5509 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
@@ -6040,17 +5552,16 @@ static void iwl4965_post_associate(struct iwl_priv *priv)
6040 5552
6041 iwl4965_sequence_reset(priv); 5553 iwl4965_sequence_reset(priv);
6042 5554
6043#ifdef CONFIG_IWL4965_SENSITIVITY
6044 /* Enable Rx differential gain and sensitivity calibrations */ 5555 /* Enable Rx differential gain and sensitivity calibrations */
6045 iwl4965_chain_noise_reset(priv); 5556 iwl_chain_noise_reset(priv);
6046 priv->start_calib = 1; 5557 priv->start_calib = 1;
6047#endif /* CONFIG_IWL4965_SENSITIVITY */
6048 5558
6049 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) 5559 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
6050 priv->assoc_station_added = 1; 5560 priv->assoc_station_added = 1;
6051 5561
6052 iwl4965_activate_qos(priv, 0); 5562 iwl4965_activate_qos(priv, 0);
6053 5563
5564 iwl_power_update_mode(priv, 0);
6054 /* we have just associated, don't start scan too early */ 5565 /* we have just associated, don't start scan too early */
6055 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; 5566 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
6056} 5567}
@@ -6338,7 +5849,7 @@ static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *co
6338 priv->staging_rxon.flags = 0; 5849 priv->staging_rxon.flags = 0;
6339#endif /* CONFIG_IWL4965_HT */ 5850#endif /* CONFIG_IWL4965_HT */
6340 5851
6341 iwlcore_set_rxon_channel(priv, conf->channel->band, 5852 iwl_set_rxon_channel(priv, conf->channel->band,
6342 ieee80211_frequency_to_channel(conf->channel->center_freq)); 5853 ieee80211_frequency_to_channel(conf->channel->center_freq));
6343 5854
6344 iwl4965_set_flags_for_phymode(priv, conf->channel->band); 5855 iwl4965_set_flags_for_phymode(priv, conf->channel->band);
@@ -6410,7 +5921,7 @@ static void iwl4965_config_ap(struct iwl_priv *priv)
6410 IWL_WARNING("REPLY_RXON_TIMING failed - " 5921 IWL_WARNING("REPLY_RXON_TIMING failed - "
6411 "Attempting to continue.\n"); 5922 "Attempting to continue.\n");
6412 5923
6413 iwl4965_set_rxon_chain(priv); 5924 iwl_set_rxon_chain(priv);
6414 5925
6415 /* FIXME: what should be the assoc_id for AP? */ 5926 /* FIXME: what should be the assoc_id for AP? */
6416 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); 5927 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
@@ -6592,64 +6103,6 @@ static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
6592 6103
6593} 6104}
6594 6105
6595
6596#ifdef CONFIG_IWL4965_HT
6597static void iwl4965_ht_conf(struct iwl_priv *priv,
6598 struct ieee80211_bss_conf *bss_conf)
6599{
6600 struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf;
6601 struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf;
6602 struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
6603
6604 IWL_DEBUG_MAC80211("enter: \n");
6605
6606 iwl_conf->is_ht = bss_conf->assoc_ht;
6607
6608 if (!iwl_conf->is_ht)
6609 return;
6610
6611 priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
6612
6613 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
6614 iwl_conf->sgf |= 0x1;
6615 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
6616 iwl_conf->sgf |= 0x2;
6617
6618 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
6619 iwl_conf->max_amsdu_size =
6620 !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
6621
6622 iwl_conf->supported_chan_width =
6623 !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH);
6624 iwl_conf->extension_chan_offset =
6625 ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET;
6626 /* If no above or below channel supplied disable FAT channel */
6627 if (iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_ABOVE &&
6628 iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_BELOW)
6629 iwl_conf->supported_chan_width = 0;
6630
6631 iwl_conf->tx_mimo_ps_mode =
6632 (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
6633 memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16);
6634
6635 iwl_conf->control_channel = ht_bss_conf->primary_channel;
6636 iwl_conf->tx_chan_width =
6637 !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH);
6638 iwl_conf->ht_protection =
6639 ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION;
6640 iwl_conf->non_GF_STA_present =
6641 !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT);
6642
6643 IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel);
6644 IWL_DEBUG_MAC80211("leave\n");
6645}
6646#else
6647static inline void iwl4965_ht_conf(struct iwl_priv *priv,
6648 struct ieee80211_bss_conf *bss_conf)
6649{
6650}
6651#endif
6652
6653#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6) 6106#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
6654static void iwl4965_bss_info_changed(struct ieee80211_hw *hw, 6107static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
6655 struct ieee80211_vif *vif, 6108 struct ieee80211_vif *vif,
@@ -6680,7 +6133,7 @@ static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
6680 if (changes & BSS_CHANGED_HT) { 6133 if (changes & BSS_CHANGED_HT) {
6681 IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht); 6134 IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht);
6682 iwl4965_ht_conf(priv, bss_conf); 6135 iwl4965_ht_conf(priv, bss_conf);
6683 iwl4965_set_rxon_chain(priv); 6136 iwl_set_rxon_chain(priv);
6684 } 6137 }
6685 6138
6686 if (changes & BSS_CHANGED_ASSOC) { 6139 if (changes & BSS_CHANGED_ASSOC) {
@@ -6780,7 +6233,7 @@ static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw,
6780 6233
6781 IWL_DEBUG_MAC80211("enter\n"); 6234 IWL_DEBUG_MAC80211("enter\n");
6782 6235
6783 sta_id = iwl4965_hw_find_station(priv, addr); 6236 sta_id = iwl_find_station(priv, addr);
6784 if (sta_id == IWL_INVALID_STATION) { 6237 if (sta_id == IWL_INVALID_STATION) {
6785 IWL_DEBUG_MAC80211("leave - %s not in station map.\n", 6238 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
6786 print_mac(mac, addr)); 6239 print_mac(mac, addr));
@@ -6827,7 +6280,7 @@ static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
6827 6280
6828 IWL_DEBUG_MAC80211("enter\n"); 6281 IWL_DEBUG_MAC80211("enter\n");
6829 6282
6830 if (priv->cfg->mod_params->sw_crypto) { 6283 if (priv->hw_params.sw_crypto) {
6831 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); 6284 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
6832 return -EOPNOTSUPP; 6285 return -EOPNOTSUPP;
6833 } 6286 }
@@ -6836,7 +6289,7 @@ static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
6836 /* only support pairwise keys */ 6289 /* only support pairwise keys */
6837 return -EOPNOTSUPP; 6290 return -EOPNOTSUPP;
6838 6291
6839 sta_id = iwl4965_hw_find_station(priv, addr); 6292 sta_id = iwl_find_station(priv, addr);
6840 if (sta_id == IWL_INVALID_STATION) { 6293 if (sta_id == IWL_INVALID_STATION) {
6841 IWL_DEBUG_MAC80211("leave - %s not in station map.\n", 6294 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
6842 print_mac(mac, addr)); 6295 print_mac(mac, addr));
@@ -6873,7 +6326,7 @@ static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
6873 if (is_default_wep_key) 6326 if (is_default_wep_key)
6874 ret = iwl_remove_default_wep_key(priv, key); 6327 ret = iwl_remove_default_wep_key(priv, key);
6875 else 6328 else
6876 ret = iwl_remove_dynamic_key(priv, sta_id); 6329 ret = iwl_remove_dynamic_key(priv, key, sta_id);
6877 6330
6878 IWL_DEBUG_MAC80211("disable hwcrypto key\n"); 6331 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
6879 break; 6332 break;
@@ -6886,7 +6339,7 @@ static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
6886 return ret; 6339 return ret;
6887} 6340}
6888 6341
6889static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, int queue, 6342static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
6890 const struct ieee80211_tx_queue_params *params) 6343 const struct ieee80211_tx_queue_params *params)
6891{ 6344{
6892 struct iwl_priv *priv = hw->priv; 6345 struct iwl_priv *priv = hw->priv;
@@ -6960,9 +6413,9 @@ static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
6960 q = &txq->q; 6413 q = &txq->q;
6961 avail = iwl4965_queue_space(q); 6414 avail = iwl4965_queue_space(q);
6962 6415
6963 stats->data[i].len = q->n_window - avail; 6416 stats[i].len = q->n_window - avail;
6964 stats->data[i].limit = q->n_window - q->high_mark; 6417 stats[i].limit = q->n_window - q->high_mark;
6965 stats->data[i].count = q->n_window; 6418 stats[i].count = q->n_window;
6966 6419
6967 } 6420 }
6968 spin_unlock_irqrestore(&priv->lock, flags); 6421 spin_unlock_irqrestore(&priv->lock, flags);
@@ -7004,7 +6457,7 @@ static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
7004 spin_unlock_irqrestore(&priv->lock, flags); 6457 spin_unlock_irqrestore(&priv->lock, flags);
7005#endif /* CONFIG_IWL4965_HT */ 6458#endif /* CONFIG_IWL4965_HT */
7006 6459
7007 iwlcore_reset_qos(priv); 6460 iwl_reset_qos(priv);
7008 6461
7009 cancel_delayed_work(&priv->post_associate); 6462 cancel_delayed_work(&priv->post_associate);
7010 6463
@@ -7041,6 +6494,8 @@ static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
7041 iwl4965_commit_rxon(priv); 6494 iwl4965_commit_rxon(priv);
7042 } 6495 }
7043 6496
6497 iwl_power_update_mode(priv, 0);
6498
7044 /* Per mac80211.h: This is only used in IBSS mode... */ 6499 /* Per mac80211.h: This is only used in IBSS mode... */
7045 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { 6500 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
7046 6501
@@ -7089,7 +6544,7 @@ static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *sk
7089 IWL_DEBUG_MAC80211("leave\n"); 6544 IWL_DEBUG_MAC80211("leave\n");
7090 spin_unlock_irqrestore(&priv->lock, flags); 6545 spin_unlock_irqrestore(&priv->lock, flags);
7091 6546
7092 iwlcore_reset_qos(priv); 6547 iwl_reset_qos(priv);
7093 6548
7094 queue_work(priv->workqueue, &priv->post_associate.work); 6549 queue_work(priv->workqueue, &priv->post_associate.work);
7095 6550
@@ -7372,20 +6827,11 @@ static ssize_t store_power_level(struct device *d,
7372 goto out; 6827 goto out;
7373 } 6828 }
7374 6829
7375 if ((mode < 1) || (mode > IWL_POWER_LIMIT) || (mode == IWL_POWER_AC)) 6830 rc = iwl_power_set_user_mode(priv, mode);
7376 mode = IWL_POWER_AC; 6831 if (rc) {
7377 else 6832 IWL_DEBUG_MAC80211("failed setting power mode.\n");
7378 mode |= IWL_POWER_ENABLED; 6833 goto out;
7379
7380 if (mode != priv->power_mode) {
7381 rc = iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(mode));
7382 if (rc) {
7383 IWL_DEBUG_MAC80211("failed setting power mode.\n");
7384 goto out;
7385 }
7386 priv->power_mode = mode;
7387 } 6834 }
7388
7389 rc = count; 6835 rc = count;
7390 6836
7391 out: 6837 out:
@@ -7415,7 +6861,7 @@ static ssize_t show_power_level(struct device *d,
7415 struct device_attribute *attr, char *buf) 6861 struct device_attribute *attr, char *buf)
7416{ 6862{
7417 struct iwl_priv *priv = dev_get_drvdata(d); 6863 struct iwl_priv *priv = dev_get_drvdata(d);
7418 int level = IWL_POWER_LEVEL(priv->power_mode); 6864 int level = priv->power_data.power_mode;
7419 char *p = buf; 6865 char *p = buf;
7420 6866
7421 p += sprintf(p, "%d ", level); 6867 p += sprintf(p, "%d ", level);
@@ -7433,14 +6879,14 @@ static ssize_t show_power_level(struct device *d,
7433 timeout_duration[level - 1] / 1000, 6879 timeout_duration[level - 1] / 1000,
7434 period_duration[level - 1] / 1000); 6880 period_duration[level - 1] / 1000);
7435 } 6881 }
7436 6882/*
7437 if (!(priv->power_mode & IWL_POWER_ENABLED)) 6883 if (!(priv->power_mode & IWL_POWER_ENABLED))
7438 p += sprintf(p, " OFF\n"); 6884 p += sprintf(p, " OFF\n");
7439 else 6885 else
7440 p += sprintf(p, " \n"); 6886 p += sprintf(p, " \n");
7441 6887*/
6888 p += sprintf(p, " \n");
7442 return (p - buf + 1); 6889 return (p - buf + 1);
7443
7444} 6890}
7445 6891
7446static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, 6892static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
@@ -7493,44 +6939,6 @@ static ssize_t show_statistics(struct device *d,
7493 6939
7494static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); 6940static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
7495 6941
7496static ssize_t show_antenna(struct device *d,
7497 struct device_attribute *attr, char *buf)
7498{
7499 struct iwl_priv *priv = dev_get_drvdata(d);
7500
7501 if (!iwl_is_alive(priv))
7502 return -EAGAIN;
7503
7504 return sprintf(buf, "%d\n", priv->antenna);
7505}
7506
7507static ssize_t store_antenna(struct device *d,
7508 struct device_attribute *attr,
7509 const char *buf, size_t count)
7510{
7511 int ant;
7512 struct iwl_priv *priv = dev_get_drvdata(d);
7513
7514 if (count == 0)
7515 return 0;
7516
7517 if (sscanf(buf, "%1i", &ant) != 1) {
7518 IWL_DEBUG_INFO("not in hex or decimal form.\n");
7519 return count;
7520 }
7521
7522 if ((ant >= 0) && (ant <= 2)) {
7523 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant);
7524 priv->antenna = (enum iwl4965_antenna)ant;
7525 } else
7526 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant);
7527
7528
7529 return count;
7530}
7531
7532static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
7533
7534static ssize_t show_status(struct device *d, 6942static ssize_t show_status(struct device *d,
7535 struct device_attribute *attr, char *buf) 6943 struct device_attribute *attr, char *buf)
7536{ 6944{
@@ -7613,7 +7021,6 @@ static void iwl4965_cancel_deferred_work(struct iwl_priv *priv)
7613} 7021}
7614 7022
7615static struct attribute *iwl4965_sysfs_entries[] = { 7023static struct attribute *iwl4965_sysfs_entries[] = {
7616 &dev_attr_antenna.attr,
7617 &dev_attr_channels.attr, 7024 &dev_attr_channels.attr,
7618 &dev_attr_dump_errors.attr, 7025 &dev_attr_dump_errors.attr,
7619 &dev_attr_dump_events.attr, 7026 &dev_attr_dump_events.attr,
@@ -7711,13 +7118,19 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
7711 7118
7712 pci_set_master(pdev); 7119 pci_set_master(pdev);
7713 7120
7714 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 7121 err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
7715 if (!err) 7122 if (!err)
7716 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 7123 err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
7124 if (err) {
7125 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
7126 if (!err)
7127 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
7128 /* both attempts failed: */
7717 if (err) { 7129 if (err) {
7718 printk(KERN_WARNING DRV_NAME 7130 printk(KERN_WARNING "%s: No suitable DMA available.\n",
7719 ": No suitable DMA available.\n"); 7131 DRV_NAME);
7720 goto out_pci_disable_device; 7132 goto out_pci_disable_device;
7133 }
7721 } 7134 }
7722 7135
7723 err = pci_request_regions(pdev, DRV_NAME); 7136 err = pci_request_regions(pdev, DRV_NAME);
@@ -7743,30 +7156,30 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
7743 (unsigned long long) pci_resource_len(pdev, 0)); 7156 (unsigned long long) pci_resource_len(pdev, 0));
7744 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); 7157 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
7745 7158
7159 iwl_hw_detect(priv);
7746 printk(KERN_INFO DRV_NAME 7160 printk(KERN_INFO DRV_NAME
7747 ": Detected Intel Wireless WiFi Link %s\n", priv->cfg->name); 7161 ": Detected Intel Wireless WiFi Link %s REV=0x%X\n",
7162 priv->cfg->name, priv->hw_rev);
7748 7163
7749 /***************** 7164 /* amp init */
7750 * 4. Read EEPROM 7165 err = priv->cfg->ops->lib->apm_ops.init(priv);
7751 *****************/
7752 /* nic init */
7753 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
7754 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
7755
7756 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
7757 err = iwl_poll_bit(priv, CSR_GP_CNTRL,
7758 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
7759 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
7760 if (err < 0) { 7166 if (err < 0) {
7761 IWL_DEBUG_INFO("Failed to init the card\n"); 7167 IWL_DEBUG_INFO("Failed to init APMG\n");
7762 goto out_iounmap; 7168 goto out_iounmap;
7763 } 7169 }
7170 /*****************
7171 * 4. Read EEPROM
7172 *****************/
7764 /* Read the EEPROM */ 7173 /* Read the EEPROM */
7765 err = iwl_eeprom_init(priv); 7174 err = iwl_eeprom_init(priv);
7766 if (err) { 7175 if (err) {
7767 IWL_ERROR("Unable to init EEPROM\n"); 7176 IWL_ERROR("Unable to init EEPROM\n");
7768 goto out_iounmap; 7177 goto out_iounmap;
7769 } 7178 }
7179 err = iwl_eeprom_check_version(priv);
7180 if (err)
7181 goto out_iounmap;
7182
7770 /* MAC Address location in EEPROM same for 3945/4965 */ 7183 /* MAC Address location in EEPROM same for 3945/4965 */
7771 iwl_eeprom_get_mac(priv, priv->mac_addr); 7184 iwl_eeprom_get_mac(priv, priv->mac_addr);
7772 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr)); 7185 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr));
@@ -7778,7 +7191,7 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
7778 /* Device-specific setup */ 7191 /* Device-specific setup */
7779 if (priv->cfg->ops->lib->set_hw_params(priv)) { 7192 if (priv->cfg->ops->lib->set_hw_params(priv)) {
7780 IWL_ERROR("failed to set hw parameters\n"); 7193 IWL_ERROR("failed to set hw parameters\n");
7781 goto out_iounmap; 7194 goto out_free_eeprom;
7782 } 7195 }
7783 7196
7784 /******************* 7197 /*******************
@@ -7787,7 +7200,7 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
7787 7200
7788 err = iwl_setup(priv); 7201 err = iwl_setup(priv);
7789 if (err) 7202 if (err)
7790 goto out_unset_hw_params; 7203 goto out_free_eeprom;
7791 /* At this point both hw and priv are initialized. */ 7204 /* At this point both hw and priv are initialized. */
7792 7205
7793 /********************************** 7206 /**********************************
@@ -7813,7 +7226,7 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
7813 err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group); 7226 err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
7814 if (err) { 7227 if (err) {
7815 IWL_ERROR("failed to create sysfs device attributes\n"); 7228 IWL_ERROR("failed to create sysfs device attributes\n");
7816 goto out_unset_hw_params; 7229 goto out_free_eeprom;
7817 } 7230 }
7818 7231
7819 err = iwl_dbgfs_register(priv, DRV_NAME); 7232 err = iwl_dbgfs_register(priv, DRV_NAME);
@@ -7837,8 +7250,8 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
7837 7250
7838 out_remove_sysfs: 7251 out_remove_sysfs:
7839 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); 7252 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
7840 out_unset_hw_params: 7253 out_free_eeprom:
7841 iwl4965_unset_hw_params(priv); 7254 iwl_eeprom_free(priv);
7842 out_iounmap: 7255 out_iounmap:
7843 pci_iounmap(pdev, priv->hw_base); 7256 pci_iounmap(pdev, priv->hw_base);
7844 out_pci_release_regions: 7257 out_pci_release_regions:
@@ -7900,8 +7313,8 @@ static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
7900 iwl4965_rx_queue_free(priv, &priv->rxq); 7313 iwl4965_rx_queue_free(priv, &priv->rxq);
7901 iwl4965_hw_txq_ctx_free(priv); 7314 iwl4965_hw_txq_ctx_free(priv);
7902 7315
7903 iwl4965_unset_hw_params(priv);
7904 iwlcore_clear_stations_table(priv); 7316 iwlcore_clear_stations_table(priv);
7317 iwl_eeprom_free(priv);
7905 7318
7906 7319
7907 /*netif_stop_queue(dev); */ 7320 /*netif_stop_queue(dev); */
@@ -7919,7 +7332,7 @@ static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
7919 pci_set_drvdata(pdev, NULL); 7332 pci_set_drvdata(pdev, NULL);
7920 7333
7921 iwl_free_channel_map(priv); 7334 iwl_free_channel_map(priv);
7922 iwl4965_free_geos(priv); 7335 iwlcore_free_geos(priv);
7923 7336
7924 if (priv->ibss_beacon) 7337 if (priv->ibss_beacon)
7925 dev_kfree_skb(priv->ibss_beacon); 7338 dev_kfree_skb(priv->ibss_beacon);
@@ -7969,6 +7382,11 @@ static int iwl4965_pci_resume(struct pci_dev *pdev)
7969static struct pci_device_id iwl_hw_card_ids[] = { 7382static struct pci_device_id iwl_hw_card_ids[] = {
7970 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)}, 7383 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
7971 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)}, 7384 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
7385#ifdef CONFIG_IWL5000
7386 {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)},
7387 {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)},
7388 {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID, iwl5350_agn_cfg)},
7389#endif /* CONFIG_IWL5000 */
7972 {0} 7390 {0}
7973}; 7391};
7974MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids); 7392MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
diff --git a/drivers/net/wireless/libertas/cmd.h b/drivers/net/wireless/libertas/cmd.h
index 3dfc2d43c224..4295bc613669 100644
--- a/drivers/net/wireless/libertas/cmd.h
+++ b/drivers/net/wireless/libertas/cmd.h
@@ -44,7 +44,7 @@ int lbs_mesh_config(struct lbs_private *priv, uint16_t enable, uint16_t chan);
44 44
45int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria); 45int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria);
46int lbs_suspend(struct lbs_private *priv); 46int lbs_suspend(struct lbs_private *priv);
47int lbs_resume(struct lbs_private *priv); 47void lbs_resume(struct lbs_private *priv);
48 48
49int lbs_cmd_802_11_inactivity_timeout(struct lbs_private *priv, 49int lbs_cmd_802_11_inactivity_timeout(struct lbs_private *priv,
50 uint16_t cmd_action, uint16_t *timeout); 50 uint16_t cmd_action, uint16_t *timeout);
diff --git a/drivers/net/wireless/libertas/decl.h b/drivers/net/wireless/libertas/decl.h
index b652fa301e19..0632b09655d2 100644
--- a/drivers/net/wireless/libertas/decl.h
+++ b/drivers/net/wireless/libertas/decl.h
@@ -64,9 +64,9 @@ void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str);
64struct chan_freq_power *lbs_get_region_cfp_table(u8 region, 64struct chan_freq_power *lbs_get_region_cfp_table(u8 region,
65 int *cfp_no); 65 int *cfp_no);
66struct lbs_private *lbs_add_card(void *card, struct device *dmdev); 66struct lbs_private *lbs_add_card(void *card, struct device *dmdev);
67int lbs_remove_card(struct lbs_private *priv); 67void lbs_remove_card(struct lbs_private *priv);
68int lbs_start_card(struct lbs_private *priv); 68int lbs_start_card(struct lbs_private *priv);
69int lbs_stop_card(struct lbs_private *priv); 69void lbs_stop_card(struct lbs_private *priv);
70void lbs_host_to_card_done(struct lbs_private *priv); 70void lbs_host_to_card_done(struct lbs_private *priv);
71 71
72int lbs_update_channel(struct lbs_private *priv); 72int lbs_update_channel(struct lbs_private *priv);
diff --git a/drivers/net/wireless/libertas/main.c b/drivers/net/wireless/libertas/main.c
index 406f54d40956..0be89573716c 100644
--- a/drivers/net/wireless/libertas/main.c
+++ b/drivers/net/wireless/libertas/main.c
@@ -702,7 +702,7 @@ static int lbs_thread(void *data)
702 702
703 if (shouldsleep) { 703 if (shouldsleep) {
704 lbs_deb_thread("sleeping, connect_status %d, " 704 lbs_deb_thread("sleeping, connect_status %d, "
705 "ps_mode %d, ps_state %d\n", 705 "psmode %d, psstate %d\n",
706 priv->connect_status, 706 priv->connect_status,
707 priv->psmode, priv->psstate); 707 priv->psmode, priv->psstate);
708 spin_unlock_irq(&priv->driver_lock); 708 spin_unlock_irq(&priv->driver_lock);
@@ -889,7 +889,7 @@ int lbs_suspend(struct lbs_private *priv)
889} 889}
890EXPORT_SYMBOL_GPL(lbs_suspend); 890EXPORT_SYMBOL_GPL(lbs_suspend);
891 891
892int lbs_resume(struct lbs_private *priv) 892void lbs_resume(struct lbs_private *priv)
893{ 893{
894 lbs_deb_enter(LBS_DEB_FW); 894 lbs_deb_enter(LBS_DEB_FW);
895 895
@@ -905,7 +905,6 @@ int lbs_resume(struct lbs_private *priv)
905 netif_device_attach(priv->mesh_dev); 905 netif_device_attach(priv->mesh_dev);
906 906
907 lbs_deb_leave(LBS_DEB_FW); 907 lbs_deb_leave(LBS_DEB_FW);
908 return 0;
909} 908}
910EXPORT_SYMBOL_GPL(lbs_resume); 909EXPORT_SYMBOL_GPL(lbs_resume);
911 910
@@ -1155,7 +1154,7 @@ done:
1155EXPORT_SYMBOL_GPL(lbs_add_card); 1154EXPORT_SYMBOL_GPL(lbs_add_card);
1156 1155
1157 1156
1158int lbs_remove_card(struct lbs_private *priv) 1157void lbs_remove_card(struct lbs_private *priv)
1159{ 1158{
1160 struct net_device *dev = priv->dev; 1159 struct net_device *dev = priv->dev;
1161 union iwreq_data wrqu; 1160 union iwreq_data wrqu;
@@ -1167,8 +1166,8 @@ int lbs_remove_card(struct lbs_private *priv)
1167 1166
1168 dev = priv->dev; 1167 dev = priv->dev;
1169 1168
1170 cancel_delayed_work(&priv->scan_work); 1169 cancel_delayed_work_sync(&priv->scan_work);
1171 cancel_delayed_work(&priv->assoc_work); 1170 cancel_delayed_work_sync(&priv->assoc_work);
1172 destroy_workqueue(priv->work_thread); 1171 destroy_workqueue(priv->work_thread);
1173 1172
1174 if (priv->psmode == LBS802_11POWERMODEMAX_PSP) { 1173 if (priv->psmode == LBS802_11POWERMODEMAX_PSP) {
@@ -1190,7 +1189,6 @@ int lbs_remove_card(struct lbs_private *priv)
1190 free_netdev(dev); 1189 free_netdev(dev);
1191 1190
1192 lbs_deb_leave(LBS_DEB_MAIN); 1191 lbs_deb_leave(LBS_DEB_MAIN);
1193 return 0;
1194} 1192}
1195EXPORT_SYMBOL_GPL(lbs_remove_card); 1193EXPORT_SYMBOL_GPL(lbs_remove_card);
1196 1194
@@ -1261,15 +1259,17 @@ done:
1261EXPORT_SYMBOL_GPL(lbs_start_card); 1259EXPORT_SYMBOL_GPL(lbs_start_card);
1262 1260
1263 1261
1264int lbs_stop_card(struct lbs_private *priv) 1262void lbs_stop_card(struct lbs_private *priv)
1265{ 1263{
1266 struct net_device *dev = priv->dev; 1264 struct net_device *dev = priv->dev;
1267 int ret = -1;
1268 struct cmd_ctrl_node *cmdnode; 1265 struct cmd_ctrl_node *cmdnode;
1269 unsigned long flags; 1266 unsigned long flags;
1270 1267
1271 lbs_deb_enter(LBS_DEB_MAIN); 1268 lbs_deb_enter(LBS_DEB_MAIN);
1272 1269
1270 if (!priv)
1271 goto out;
1272
1273 netif_stop_queue(priv->dev); 1273 netif_stop_queue(priv->dev);
1274 netif_carrier_off(priv->dev); 1274 netif_carrier_off(priv->dev);
1275 1275
@@ -1279,6 +1279,7 @@ int lbs_stop_card(struct lbs_private *priv)
1279 device_remove_file(&dev->dev, &dev_attr_lbs_mesh); 1279 device_remove_file(&dev->dev, &dev_attr_lbs_mesh);
1280 1280
1281 /* Flush pending command nodes */ 1281 /* Flush pending command nodes */
1282 del_timer_sync(&priv->command_timer);
1282 spin_lock_irqsave(&priv->driver_lock, flags); 1283 spin_lock_irqsave(&priv->driver_lock, flags);
1283 list_for_each_entry(cmdnode, &priv->cmdpendingq, list) { 1284 list_for_each_entry(cmdnode, &priv->cmdpendingq, list) {
1284 cmdnode->result = -ENOENT; 1285 cmdnode->result = -ENOENT;
@@ -1289,8 +1290,8 @@ int lbs_stop_card(struct lbs_private *priv)
1289 1290
1290 unregister_netdev(dev); 1291 unregister_netdev(dev);
1291 1292
1292 lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret); 1293out:
1293 return ret; 1294 lbs_deb_leave(LBS_DEB_MAIN);
1294} 1295}
1295EXPORT_SYMBOL_GPL(lbs_stop_card); 1296EXPORT_SYMBOL_GPL(lbs_stop_card);
1296 1297
@@ -1532,10 +1533,11 @@ static void lbs_remove_rtap(struct lbs_private *priv)
1532{ 1533{
1533 lbs_deb_enter(LBS_DEB_MAIN); 1534 lbs_deb_enter(LBS_DEB_MAIN);
1534 if (priv->rtap_net_dev == NULL) 1535 if (priv->rtap_net_dev == NULL)
1535 return; 1536 goto out;
1536 unregister_netdev(priv->rtap_net_dev); 1537 unregister_netdev(priv->rtap_net_dev);
1537 free_netdev(priv->rtap_net_dev); 1538 free_netdev(priv->rtap_net_dev);
1538 priv->rtap_net_dev = NULL; 1539 priv->rtap_net_dev = NULL;
1540out:
1539 lbs_deb_leave(LBS_DEB_MAIN); 1541 lbs_deb_leave(LBS_DEB_MAIN);
1540} 1542}
1541 1543
diff --git a/drivers/net/wireless/p54/p54.h b/drivers/net/wireless/p54/p54.h
index 06d2c67f4c81..c6f27b9022f9 100644
--- a/drivers/net/wireless/p54/p54.h
+++ b/drivers/net/wireless/p54/p54.h
@@ -64,7 +64,7 @@ struct p54_common {
64 unsigned int tx_hdr_len; 64 unsigned int tx_hdr_len;
65 void *cached_vdcf; 65 void *cached_vdcf;
66 unsigned int fw_var; 66 unsigned int fw_var;
67 struct ieee80211_tx_queue_stats tx_stats; 67 struct ieee80211_tx_queue_stats tx_stats[4];
68}; 68};
69 69
70int p54_rx(struct ieee80211_hw *dev, struct sk_buff *skb); 70int p54_rx(struct ieee80211_hw *dev, struct sk_buff *skb);
diff --git a/drivers/net/wireless/p54/p54common.c b/drivers/net/wireless/p54/p54common.c
index 63f9badf3f52..33d608a60d79 100644
--- a/drivers/net/wireless/p54/p54common.c
+++ b/drivers/net/wireless/p54/p54common.c
@@ -146,10 +146,10 @@ void p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw)
146 146
147 if (priv->fw_var >= 0x300) { 147 if (priv->fw_var >= 0x300) {
148 /* Firmware supports QoS, use it! */ 148 /* Firmware supports QoS, use it! */
149 priv->tx_stats.data[0].limit = 3; 149 priv->tx_stats[0].limit = 3;
150 priv->tx_stats.data[1].limit = 4; 150 priv->tx_stats[1].limit = 4;
151 priv->tx_stats.data[2].limit = 3; 151 priv->tx_stats[2].limit = 3;
152 priv->tx_stats.data[3].limit = 1; 152 priv->tx_stats[3].limit = 1;
153 dev->queues = 4; 153 dev->queues = 4;
154 } 154 }
155} 155}
@@ -379,7 +379,7 @@ static void inline p54_wake_free_queues(struct ieee80211_hw *dev)
379 * But, what if some are full? */ 379 * But, what if some are full? */
380 380
381 for (i = 0; i < dev->queues; i++) 381 for (i = 0; i < dev->queues; i++)
382 if (priv->tx_stats.data[i].len < priv->tx_stats.data[i].limit) 382 if (priv->tx_stats[i].len < priv->tx_stats[i].limit)
383 ieee80211_wake_queue(dev, i); 383 ieee80211_wake_queue(dev, i);
384} 384}
385 385
@@ -417,8 +417,7 @@ static void p54_rx_frame_sent(struct ieee80211_hw *dev, struct sk_buff *skb)
417 memcpy(&status.control, range->control, 417 memcpy(&status.control, range->control,
418 sizeof(status.control)); 418 sizeof(status.control));
419 kfree(range->control); 419 kfree(range->control);
420 priv->tx_stats.data[status.control.queue].len--; 420 priv->tx_stats[status.control.queue].len--;
421
422 entry_hdr = (struct p54_control_hdr *) entry->data; 421 entry_hdr = (struct p54_control_hdr *) entry->data;
423 entry_data = (struct p54_tx_control_allocdata *) entry_hdr->data; 422 entry_data = (struct p54_tx_control_allocdata *) entry_hdr->data;
424 if ((entry_hdr->magic1 & cpu_to_le16(0x4000)) != 0) 423 if ((entry_hdr->magic1 & cpu_to_le16(0x4000)) != 0)
@@ -555,7 +554,7 @@ static void p54_assign_address(struct ieee80211_hw *dev, struct sk_buff *skb,
555static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb, 554static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb,
556 struct ieee80211_tx_control *control) 555 struct ieee80211_tx_control *control)
557{ 556{
558 struct ieee80211_tx_queue_stats_data *current_queue; 557 struct ieee80211_tx_queue_stats *current_queue;
559 struct p54_common *priv = dev->priv; 558 struct p54_common *priv = dev->priv;
560 struct p54_control_hdr *hdr; 559 struct p54_control_hdr *hdr;
561 struct p54_tx_control_allocdata *txhdr; 560 struct p54_tx_control_allocdata *txhdr;
@@ -563,7 +562,7 @@ static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb,
563 size_t padding, len; 562 size_t padding, len;
564 u8 rate; 563 u8 rate;
565 564
566 current_queue = &priv->tx_stats.data[control->queue]; 565 current_queue = &priv->tx_stats[control->queue];
567 if (unlikely(current_queue->len > current_queue->limit)) 566 if (unlikely(current_queue->len > current_queue->limit))
568 return NETDEV_TX_BUSY; 567 return NETDEV_TX_BUSY;
569 current_queue->len++; 568 current_queue->len++;
@@ -936,7 +935,7 @@ static void p54_configure_filter(struct ieee80211_hw *dev,
936 } 935 }
937} 936}
938 937
939static int p54_conf_tx(struct ieee80211_hw *dev, int queue, 938static int p54_conf_tx(struct ieee80211_hw *dev, u16 queue,
940 const struct ieee80211_tx_queue_params *params) 939 const struct ieee80211_tx_queue_params *params)
941{ 940{
942 struct p54_common *priv = dev->priv; 941 struct p54_common *priv = dev->priv;
@@ -945,7 +944,7 @@ static int p54_conf_tx(struct ieee80211_hw *dev, int queue,
945 vdcf = (struct p54_tx_control_vdcf *)(((struct p54_control_hdr *) 944 vdcf = (struct p54_tx_control_vdcf *)(((struct p54_control_hdr *)
946 ((void *)priv->cached_vdcf + priv->tx_hdr_len))->data); 945 ((void *)priv->cached_vdcf + priv->tx_hdr_len))->data);
947 946
948 if ((params) && !((queue < 0) || (queue > 4))) { 947 if ((params) && !(queue > 4)) {
949 P54_SET_QUEUE(vdcf->queue[queue], params->aifs, 948 P54_SET_QUEUE(vdcf->queue[queue], params->aifs,
950 params->cw_min, params->cw_max, params->txop); 949 params->cw_min, params->cw_max, params->txop);
951 } else 950 } else
@@ -967,11 +966,8 @@ static int p54_get_tx_stats(struct ieee80211_hw *dev,
967 struct ieee80211_tx_queue_stats *stats) 966 struct ieee80211_tx_queue_stats *stats)
968{ 967{
969 struct p54_common *priv = dev->priv; 968 struct p54_common *priv = dev->priv;
970 unsigned int i;
971 969
972 for (i = 0; i < dev->queues; i++) 970 memcpy(stats, &priv->tx_stats, sizeof(stats[0]) * dev->queues);
973 memcpy(&stats->data[i], &priv->tx_stats.data[i],
974 sizeof(stats->data[i]));
975 971
976 return 0; 972 return 0;
977} 973}
@@ -1008,7 +1004,7 @@ struct ieee80211_hw *p54_init_common(size_t priv_data_len)
1008 dev->channel_change_time = 1000; /* TODO: find actual value */ 1004 dev->channel_change_time = 1000; /* TODO: find actual value */
1009 dev->max_rssi = 127; 1005 dev->max_rssi = 127;
1010 1006
1011 priv->tx_stats.data[0].limit = 5; 1007 priv->tx_stats[0].limit = 5;
1012 dev->queues = 1; 1008 dev->queues = 1;
1013 1009
1014 dev->extra_tx_headroom = sizeof(struct p54_control_hdr) + 4 + 1010 dev->extra_tx_headroom = sizeof(struct p54_control_hdr) + 4 +
diff --git a/drivers/net/wireless/rt2x00/Kconfig b/drivers/net/wireless/rt2x00/Kconfig
index ab1029e79884..0ace76149422 100644
--- a/drivers/net/wireless/rt2x00/Kconfig
+++ b/drivers/net/wireless/rt2x00/Kconfig
@@ -5,12 +5,16 @@ config RT2X00
5 This will enable the experimental support for the Ralink drivers, 5 This will enable the experimental support for the Ralink drivers,
6 developed in the rt2x00 project <http://rt2x00.serialmonkey.com>. 6 developed in the rt2x00 project <http://rt2x00.serialmonkey.com>.
7 7
8 These drivers will make use of the mac80211 stack. 8 These drivers make use of the mac80211 stack.
9 9
10 When building one of the individual drivers, the rt2x00 library 10 When building one of the individual drivers, the rt2x00 library
11 will also be created. That library (when the driver is built as 11 will also be created. That library (when the driver is built as
12 a module) will be called "rt2x00lib.ko". 12 a module) will be called "rt2x00lib.ko".
13 13
14 Additionally PCI and USB libraries will also be build depending
15 on the types of drivers being selected, these libraries will be
16 called "rt2x00pci.ko" and "rt2x00usb.ko".
17
14if RT2X00 18if RT2X00
15 19
16config RT2X00_LIB 20config RT2X00_LIB
@@ -40,26 +44,27 @@ config RT2X00_LIB_LEDS
40 depends on RT2X00_LIB 44 depends on RT2X00_LIB
41 45
42config RT2400PCI 46config RT2400PCI
43 tristate "Ralink rt2400 pci/pcmcia support" 47 tristate "Ralink rt2400 (PCI/PCMCIA) support"
44 depends on PCI 48 depends on PCI
45 select RT2X00_LIB_PCI 49 select RT2X00_LIB_PCI
46 select EEPROM_93CX6 50 select EEPROM_93CX6
47 ---help--- 51 ---help---
48 This is an experimental driver for the Ralink rt2400 wireless chip. 52 This adds support for rt2400 wireless chipset family.
53 Supported chips: RT2460.
49 54
50 When compiled as a module, this driver will be called "rt2400pci.ko". 55 When compiled as a module, this driver will be called "rt2400pci.ko".
51 56
52config RT2400PCI_RFKILL 57config RT2400PCI_RFKILL
53 bool "RT2400 rfkill support" 58 bool "Ralink rt2400 rfkill support"
54 depends on RT2400PCI 59 depends on RT2400PCI
55 select RT2X00_LIB_RFKILL 60 select RT2X00_LIB_RFKILL
56 ---help--- 61 ---help---
57 This adds support for integrated rt2400 devices that feature a 62 This adds support for integrated rt2400 hardware that features a
58 hardware button to control the radio state. 63 hardware button to control the radio state.
59 This feature depends on the RF switch subsystem rfkill. 64 This feature depends on the RF switch subsystem rfkill.
60 65
61config RT2400PCI_LEDS 66config RT2400PCI_LEDS
62 bool "RT2400 leds support" 67 bool "Ralink rt2400 leds support"
63 depends on RT2400PCI 68 depends on RT2400PCI
64 select LEDS_CLASS 69 select LEDS_CLASS
65 select RT2X00_LIB_LEDS 70 select RT2X00_LIB_LEDS
@@ -67,26 +72,27 @@ config RT2400PCI_LEDS
67 This adds support for led triggers provided my mac80211. 72 This adds support for led triggers provided my mac80211.
68 73
69config RT2500PCI 74config RT2500PCI
70 tristate "Ralink rt2500 pci/pcmcia support" 75 tristate "Ralink rt2500 (PCI/PCMCIA) support"
71 depends on PCI 76 depends on PCI
72 select RT2X00_LIB_PCI 77 select RT2X00_LIB_PCI
73 select EEPROM_93CX6 78 select EEPROM_93CX6
74 ---help--- 79 ---help---
75 This is an experimental driver for the Ralink rt2500 wireless chip. 80 This adds support for rt2500 wireless chipset family.
81 Supported chips: RT2560.
76 82
77 When compiled as a module, this driver will be called "rt2500pci.ko". 83 When compiled as a module, this driver will be called "rt2500pci.ko".
78 84
79config RT2500PCI_RFKILL 85config RT2500PCI_RFKILL
80 bool "RT2500 rfkill support" 86 bool "Ralink rt2500 rfkill support"
81 depends on RT2500PCI 87 depends on RT2500PCI
82 select RT2X00_LIB_RFKILL 88 select RT2X00_LIB_RFKILL
83 ---help--- 89 ---help---
84 This adds support for integrated rt2500 devices that feature a 90 This adds support for integrated rt2500 hardware that features a
85 hardware button to control the radio state. 91 hardware button to control the radio state.
86 This feature depends on the RF switch subsystem rfkill. 92 This feature depends on the RF switch subsystem rfkill.
87 93
88config RT2500PCI_LEDS 94config RT2500PCI_LEDS
89 bool "RT2500 leds support" 95 bool "Ralink rt2500 leds support"
90 depends on RT2500PCI 96 depends on RT2500PCI
91 select LEDS_CLASS 97 select LEDS_CLASS
92 select RT2X00_LIB_LEDS 98 select RT2X00_LIB_LEDS
@@ -94,28 +100,29 @@ config RT2500PCI_LEDS
94 This adds support for led triggers provided my mac80211. 100 This adds support for led triggers provided my mac80211.
95 101
96config RT61PCI 102config RT61PCI
97 tristate "Ralink rt61 pci/pcmcia support" 103 tristate "Ralink rt2501/rt61 (PCI/PCMCIA) support"
98 depends on PCI 104 depends on PCI
99 select RT2X00_LIB_PCI 105 select RT2X00_LIB_PCI
100 select RT2X00_LIB_FIRMWARE 106 select RT2X00_LIB_FIRMWARE
101 select CRC_ITU_T 107 select CRC_ITU_T
102 select EEPROM_93CX6 108 select EEPROM_93CX6
103 ---help--- 109 ---help---
104 This is an experimental driver for the Ralink rt61 wireless chip. 110 This adds support for rt2501 wireless chipset family.
111 Supported chips: RT2561, RT2561S & RT2661.
105 112
106 When compiled as a module, this driver will be called "rt61pci.ko". 113 When compiled as a module, this driver will be called "rt61pci.ko".
107 114
108config RT61PCI_RFKILL 115config RT61PCI_RFKILL
109 bool "RT61 rfkill support" 116 bool "Ralink rt2501/rt61 rfkill support"
110 depends on RT61PCI 117 depends on RT61PCI
111 select RT2X00_LIB_RFKILL 118 select RT2X00_LIB_RFKILL
112 ---help--- 119 ---help---
113 This adds support for integrated rt61 devices that feature a 120 This adds support for integrated rt61 hardware that features a
114 hardware button to control the radio state. 121 hardware button to control the radio state.
115 This feature depends on the RF switch subsystem rfkill. 122 This feature depends on the RF switch subsystem rfkill.
116 123
117config RT61PCI_LEDS 124config RT61PCI_LEDS
118 bool "RT61 leds support" 125 bool "Ralink rt2501/rt61 leds support"
119 depends on RT61PCI 126 depends on RT61PCI
120 select LEDS_CLASS 127 select LEDS_CLASS
121 select RT2X00_LIB_LEDS 128 select RT2X00_LIB_LEDS
@@ -123,16 +130,17 @@ config RT61PCI_LEDS
123 This adds support for led triggers provided my mac80211. 130 This adds support for led triggers provided my mac80211.
124 131
125config RT2500USB 132config RT2500USB
126 tristate "Ralink rt2500 usb support" 133 tristate "Ralink rt2500 (USB) support"
127 depends on USB 134 depends on USB
128 select RT2X00_LIB_USB 135 select RT2X00_LIB_USB
129 ---help--- 136 ---help---
130 This is an experimental driver for the Ralink rt2500 wireless chip. 137 This adds support for rt2500 wireless chipset family.
138 Supported chips: RT2571 & RT2572.
131 139
132 When compiled as a module, this driver will be called "rt2500usb.ko". 140 When compiled as a module, this driver will be called "rt2500usb.ko".
133 141
134config RT2500USB_LEDS 142config RT2500USB_LEDS
135 bool "RT2500 leds support" 143 bool "Ralink rt2500 leds support"
136 depends on RT2500USB 144 depends on RT2500USB
137 select LEDS_CLASS 145 select LEDS_CLASS
138 select RT2X00_LIB_LEDS 146 select RT2X00_LIB_LEDS
@@ -140,18 +148,19 @@ config RT2500USB_LEDS
140 This adds support for led triggers provided my mac80211. 148 This adds support for led triggers provided my mac80211.
141 149
142config RT73USB 150config RT73USB
143 tristate "Ralink rt73 usb support" 151 tristate "Ralink rt2501/rt73 (USB) support"
144 depends on USB 152 depends on USB
145 select RT2X00_LIB_USB 153 select RT2X00_LIB_USB
146 select RT2X00_LIB_FIRMWARE 154 select RT2X00_LIB_FIRMWARE
147 select CRC_ITU_T 155 select CRC_ITU_T
148 ---help--- 156 ---help---
149 This is an experimental driver for the Ralink rt73 wireless chip. 157 This adds support for rt2501 wireless chipset family.
158 Supported chips: RT2571W, RT2573 & RT2671.
150 159
151 When compiled as a module, this driver will be called "rt73usb.ko". 160 When compiled as a module, this driver will be called "rt73usb.ko".
152 161
153config RT73USB_LEDS 162config RT73USB_LEDS
154 bool "RT73 leds support" 163 bool "Ralink rt2501/rt73 leds support"
155 depends on RT73USB 164 depends on RT73USB
156 select LEDS_CLASS 165 select LEDS_CLASS
157 select RT2X00_LIB_LEDS 166 select RT2X00_LIB_LEDS
@@ -164,7 +173,7 @@ config RT2X00_LIB_DEBUGFS
164 ---help--- 173 ---help---
165 Enable creation of debugfs files for the rt2x00 drivers. 174 Enable creation of debugfs files for the rt2x00 drivers.
166 These debugfs files support both reading and writing of the 175 These debugfs files support both reading and writing of the
167 most important register types of the rt2x00 devices. 176 most important register types of the rt2x00 hardware.
168 177
169config RT2X00_DEBUG 178config RT2X00_DEBUG
170 bool "Ralink debug output" 179 bool "Ralink debug output"
diff --git a/drivers/net/wireless/rt2x00/rt2400pci.c b/drivers/net/wireless/rt2x00/rt2400pci.c
index 560b9c73c0b9..247fbbfb0f2b 100644
--- a/drivers/net/wireless/rt2x00/rt2400pci.c
+++ b/drivers/net/wireless/rt2x00/rt2400pci.c
@@ -1055,11 +1055,11 @@ static void rt2400pci_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1055 * TX data initialization 1055 * TX data initialization
1056 */ 1056 */
1057static void rt2400pci_kick_tx_queue(struct rt2x00_dev *rt2x00dev, 1057static void rt2400pci_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
1058 const unsigned int queue) 1058 const enum data_queue_qid queue)
1059{ 1059{
1060 u32 reg; 1060 u32 reg;
1061 1061
1062 if (queue == RT2X00_BCN_QUEUE_BEACON) { 1062 if (queue == QID_BEACON) {
1063 rt2x00pci_register_read(rt2x00dev, CSR14, &reg); 1063 rt2x00pci_register_read(rt2x00dev, CSR14, &reg);
1064 if (!rt2x00_get_field32(reg, CSR14_BEACON_GEN)) { 1064 if (!rt2x00_get_field32(reg, CSR14_BEACON_GEN)) {
1065 rt2x00_set_field32(&reg, CSR14_TSF_COUNT, 1); 1065 rt2x00_set_field32(&reg, CSR14_TSF_COUNT, 1);
@@ -1071,12 +1071,9 @@ static void rt2400pci_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
1071 } 1071 }
1072 1072
1073 rt2x00pci_register_read(rt2x00dev, TXCSR0, &reg); 1073 rt2x00pci_register_read(rt2x00dev, TXCSR0, &reg);
1074 rt2x00_set_field32(&reg, TXCSR0_KICK_PRIO, 1074 rt2x00_set_field32(&reg, TXCSR0_KICK_PRIO, (queue == QID_AC_BE));
1075 (queue == IEEE80211_TX_QUEUE_DATA0)); 1075 rt2x00_set_field32(&reg, TXCSR0_KICK_TX, (queue == QID_AC_BK));
1076 rt2x00_set_field32(&reg, TXCSR0_KICK_TX, 1076 rt2x00_set_field32(&reg, TXCSR0_KICK_ATIM, (queue == QID_ATIM));
1077 (queue == IEEE80211_TX_QUEUE_DATA1));
1078 rt2x00_set_field32(&reg, TXCSR0_KICK_ATIM,
1079 (queue == RT2X00_BCN_QUEUE_ATIM));
1080 rt2x00pci_register_write(rt2x00dev, TXCSR0, reg); 1077 rt2x00pci_register_write(rt2x00dev, TXCSR0, reg);
1081} 1078}
1082 1079
@@ -1120,7 +1117,7 @@ static void rt2400pci_fill_rxdone(struct queue_entry *entry,
1120 * Interrupt functions. 1117 * Interrupt functions.
1121 */ 1118 */
1122static void rt2400pci_txdone(struct rt2x00_dev *rt2x00dev, 1119static void rt2400pci_txdone(struct rt2x00_dev *rt2x00dev,
1123 const enum ieee80211_tx_queue queue_idx) 1120 const enum data_queue_qid queue_idx)
1124{ 1121{
1125 struct data_queue *queue = rt2x00queue_get_queue(rt2x00dev, queue_idx); 1122 struct data_queue *queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
1126 struct queue_entry_priv_pci_tx *priv_tx; 1123 struct queue_entry_priv_pci_tx *priv_tx;
@@ -1187,19 +1184,19 @@ static irqreturn_t rt2400pci_interrupt(int irq, void *dev_instance)
1187 * 3 - Atim ring transmit done interrupt. 1184 * 3 - Atim ring transmit done interrupt.
1188 */ 1185 */
1189 if (rt2x00_get_field32(reg, CSR7_TXDONE_ATIMRING)) 1186 if (rt2x00_get_field32(reg, CSR7_TXDONE_ATIMRING))
1190 rt2400pci_txdone(rt2x00dev, RT2X00_BCN_QUEUE_ATIM); 1187 rt2400pci_txdone(rt2x00dev, QID_ATIM);
1191 1188
1192 /* 1189 /*
1193 * 4 - Priority ring transmit done interrupt. 1190 * 4 - Priority ring transmit done interrupt.
1194 */ 1191 */
1195 if (rt2x00_get_field32(reg, CSR7_TXDONE_PRIORING)) 1192 if (rt2x00_get_field32(reg, CSR7_TXDONE_PRIORING))
1196 rt2400pci_txdone(rt2x00dev, IEEE80211_TX_QUEUE_DATA0); 1193 rt2400pci_txdone(rt2x00dev, QID_AC_BE);
1197 1194
1198 /* 1195 /*
1199 * 5 - Tx ring transmit done interrupt. 1196 * 5 - Tx ring transmit done interrupt.
1200 */ 1197 */
1201 if (rt2x00_get_field32(reg, CSR7_TXDONE_TXRING)) 1198 if (rt2x00_get_field32(reg, CSR7_TXDONE_TXRING))
1202 rt2400pci_txdone(rt2x00dev, IEEE80211_TX_QUEUE_DATA1); 1199 rt2400pci_txdone(rt2x00dev, QID_AC_BK);
1203 1200
1204 return IRQ_HANDLED; 1201 return IRQ_HANDLED;
1205} 1202}
@@ -1445,8 +1442,7 @@ static int rt2400pci_set_retry_limit(struct ieee80211_hw *hw,
1445 return 0; 1442 return 0;
1446} 1443}
1447 1444
1448static int rt2400pci_conf_tx(struct ieee80211_hw *hw, 1445static int rt2400pci_conf_tx(struct ieee80211_hw *hw, u16 queue,
1449 int queue,
1450 const struct ieee80211_tx_queue_params *params) 1446 const struct ieee80211_tx_queue_params *params)
1451{ 1447{
1452 struct rt2x00_dev *rt2x00dev = hw->priv; 1448 struct rt2x00_dev *rt2x00dev = hw->priv;
@@ -1456,7 +1452,7 @@ static int rt2400pci_conf_tx(struct ieee80211_hw *hw,
1456 * per queue. So by default we only configure the TX queue, 1452 * per queue. So by default we only configure the TX queue,
1457 * and ignore all other configurations. 1453 * and ignore all other configurations.
1458 */ 1454 */
1459 if (queue != IEEE80211_TX_QUEUE_DATA0) 1455 if (queue != 0)
1460 return -EINVAL; 1456 return -EINVAL;
1461 1457
1462 if (rt2x00mac_conf_tx(hw, queue, params)) 1458 if (rt2x00mac_conf_tx(hw, queue, params))
@@ -1521,20 +1517,13 @@ static int rt2400pci_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb,
1521 rt2x00pci_register_write(rt2x00dev, CSR14, reg); 1517 rt2x00pci_register_write(rt2x00dev, CSR14, reg);
1522 1518
1523 /* 1519 /*
1524 * mac80211 doesn't provide the control->queue variable
1525 * for beacons. Set our own queue identification so
1526 * it can be used during descriptor initialization.
1527 */
1528 control->queue = RT2X00_BCN_QUEUE_BEACON;
1529 rt2x00lib_write_tx_desc(rt2x00dev, skb, control);
1530
1531 /*
1532 * Enable beacon generation. 1520 * Enable beacon generation.
1533 * Write entire beacon with descriptor to register, 1521 * Write entire beacon with descriptor to register,
1534 * and kick the beacon generator. 1522 * and kick the beacon generator.
1535 */ 1523 */
1524 rt2x00lib_write_tx_desc(rt2x00dev, skb, control);
1536 memcpy(priv_tx->data, skb->data, skb->len); 1525 memcpy(priv_tx->data, skb->data, skb->len);
1537 rt2x00dev->ops->lib->kick_tx_queue(rt2x00dev, control->queue); 1526 rt2x00dev->ops->lib->kick_tx_queue(rt2x00dev, QID_BEACON);
1538 1527
1539 return 0; 1528 return 0;
1540} 1529}
diff --git a/drivers/net/wireless/rt2x00/rt2500pci.c b/drivers/net/wireless/rt2x00/rt2500pci.c
index a5ed54b69262..0d53c75d55dd 100644
--- a/drivers/net/wireless/rt2x00/rt2500pci.c
+++ b/drivers/net/wireless/rt2x00/rt2500pci.c
@@ -317,8 +317,7 @@ static void rt2500pci_config_intf(struct rt2x00_dev *rt2x00dev,
317 struct rt2x00intf_conf *conf, 317 struct rt2x00intf_conf *conf,
318 const unsigned int flags) 318 const unsigned int flags)
319{ 319{
320 struct data_queue *queue = 320 struct data_queue *queue = rt2x00queue_get_queue(rt2x00dev, QID_BEACON);
321 rt2x00queue_get_queue(rt2x00dev, RT2X00_BCN_QUEUE_BEACON);
322 unsigned int bcn_preload; 321 unsigned int bcn_preload;
323 u32 reg; 322 u32 reg;
324 323
@@ -1210,11 +1209,11 @@ static void rt2500pci_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1210 * TX data initialization 1209 * TX data initialization
1211 */ 1210 */
1212static void rt2500pci_kick_tx_queue(struct rt2x00_dev *rt2x00dev, 1211static void rt2500pci_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
1213 const unsigned int queue) 1212 const enum data_queue_qid queue)
1214{ 1213{
1215 u32 reg; 1214 u32 reg;
1216 1215
1217 if (queue == RT2X00_BCN_QUEUE_BEACON) { 1216 if (queue == QID_BEACON) {
1218 rt2x00pci_register_read(rt2x00dev, CSR14, &reg); 1217 rt2x00pci_register_read(rt2x00dev, CSR14, &reg);
1219 if (!rt2x00_get_field32(reg, CSR14_BEACON_GEN)) { 1218 if (!rt2x00_get_field32(reg, CSR14_BEACON_GEN)) {
1220 rt2x00_set_field32(&reg, CSR14_TSF_COUNT, 1); 1219 rt2x00_set_field32(&reg, CSR14_TSF_COUNT, 1);
@@ -1226,12 +1225,9 @@ static void rt2500pci_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
1226 } 1225 }
1227 1226
1228 rt2x00pci_register_read(rt2x00dev, TXCSR0, &reg); 1227 rt2x00pci_register_read(rt2x00dev, TXCSR0, &reg);
1229 rt2x00_set_field32(&reg, TXCSR0_KICK_PRIO, 1228 rt2x00_set_field32(&reg, TXCSR0_KICK_PRIO, (queue == QID_AC_BE));
1230 (queue == IEEE80211_TX_QUEUE_DATA0)); 1229 rt2x00_set_field32(&reg, TXCSR0_KICK_TX, (queue == QID_AC_BK));
1231 rt2x00_set_field32(&reg, TXCSR0_KICK_TX, 1230 rt2x00_set_field32(&reg, TXCSR0_KICK_ATIM, (queue == QID_ATIM));
1232 (queue == IEEE80211_TX_QUEUE_DATA1));
1233 rt2x00_set_field32(&reg, TXCSR0_KICK_ATIM,
1234 (queue == RT2X00_BCN_QUEUE_ATIM));
1235 rt2x00pci_register_write(rt2x00dev, TXCSR0, reg); 1231 rt2x00pci_register_write(rt2x00dev, TXCSR0, reg);
1236} 1232}
1237 1233
@@ -1276,7 +1272,7 @@ static void rt2500pci_fill_rxdone(struct queue_entry *entry,
1276 * Interrupt functions. 1272 * Interrupt functions.
1277 */ 1273 */
1278static void rt2500pci_txdone(struct rt2x00_dev *rt2x00dev, 1274static void rt2500pci_txdone(struct rt2x00_dev *rt2x00dev,
1279 const enum ieee80211_tx_queue queue_idx) 1275 const enum data_queue_qid queue_idx)
1280{ 1276{
1281 struct data_queue *queue = rt2x00queue_get_queue(rt2x00dev, queue_idx); 1277 struct data_queue *queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
1282 struct queue_entry_priv_pci_tx *priv_tx; 1278 struct queue_entry_priv_pci_tx *priv_tx;
@@ -1343,19 +1339,19 @@ static irqreturn_t rt2500pci_interrupt(int irq, void *dev_instance)
1343 * 3 - Atim ring transmit done interrupt. 1339 * 3 - Atim ring transmit done interrupt.
1344 */ 1340 */
1345 if (rt2x00_get_field32(reg, CSR7_TXDONE_ATIMRING)) 1341 if (rt2x00_get_field32(reg, CSR7_TXDONE_ATIMRING))
1346 rt2500pci_txdone(rt2x00dev, RT2X00_BCN_QUEUE_ATIM); 1342 rt2500pci_txdone(rt2x00dev, QID_ATIM);
1347 1343
1348 /* 1344 /*
1349 * 4 - Priority ring transmit done interrupt. 1345 * 4 - Priority ring transmit done interrupt.
1350 */ 1346 */
1351 if (rt2x00_get_field32(reg, CSR7_TXDONE_PRIORING)) 1347 if (rt2x00_get_field32(reg, CSR7_TXDONE_PRIORING))
1352 rt2500pci_txdone(rt2x00dev, IEEE80211_TX_QUEUE_DATA0); 1348 rt2500pci_txdone(rt2x00dev, QID_AC_BE);
1353 1349
1354 /* 1350 /*
1355 * 5 - Tx ring transmit done interrupt. 1351 * 5 - Tx ring transmit done interrupt.
1356 */ 1352 */
1357 if (rt2x00_get_field32(reg, CSR7_TXDONE_TXRING)) 1353 if (rt2x00_get_field32(reg, CSR7_TXDONE_TXRING))
1358 rt2500pci_txdone(rt2x00dev, IEEE80211_TX_QUEUE_DATA1); 1354 rt2500pci_txdone(rt2x00dev, QID_AC_BK);
1359 1355
1360 return IRQ_HANDLED; 1356 return IRQ_HANDLED;
1361} 1357}
@@ -1834,20 +1830,13 @@ static int rt2500pci_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb,
1834 rt2x00pci_register_write(rt2x00dev, CSR14, reg); 1830 rt2x00pci_register_write(rt2x00dev, CSR14, reg);
1835 1831
1836 /* 1832 /*
1837 * mac80211 doesn't provide the control->queue variable
1838 * for beacons. Set our own queue identification so
1839 * it can be used during descriptor initialization.
1840 */
1841 control->queue = RT2X00_BCN_QUEUE_BEACON;
1842 rt2x00lib_write_tx_desc(rt2x00dev, skb, control);
1843
1844 /*
1845 * Enable beacon generation. 1833 * Enable beacon generation.
1846 * Write entire beacon with descriptor to register, 1834 * Write entire beacon with descriptor to register,
1847 * and kick the beacon generator. 1835 * and kick the beacon generator.
1848 */ 1836 */
1837 rt2x00lib_write_tx_desc(rt2x00dev, skb, control);
1849 memcpy(priv_tx->data, skb->data, skb->len); 1838 memcpy(priv_tx->data, skb->data, skb->len);
1850 rt2x00dev->ops->lib->kick_tx_queue(rt2x00dev, control->queue); 1839 rt2x00dev->ops->lib->kick_tx_queue(rt2x00dev, QID_BEACON);
1851 1840
1852 return 0; 1841 return 0;
1853} 1842}
diff --git a/drivers/net/wireless/rt2x00/rt2500usb.c b/drivers/net/wireless/rt2x00/rt2500usb.c
index fdbd0ef2be4b..80b34d47114a 100644
--- a/drivers/net/wireless/rt2x00/rt2500usb.c
+++ b/drivers/net/wireless/rt2x00/rt2500usb.c
@@ -76,10 +76,10 @@ static inline void rt2500usb_register_multiread(struct rt2x00_dev *rt2x00dev,
76 const unsigned int offset, 76 const unsigned int offset,
77 void *value, const u16 length) 77 void *value, const u16 length)
78{ 78{
79 int timeout = REGISTER_TIMEOUT * (length / sizeof(u16));
80 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ, 79 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
81 USB_VENDOR_REQUEST_IN, offset, 80 USB_VENDOR_REQUEST_IN, offset,
82 value, length, timeout); 81 value, length,
82 REGISTER_TIMEOUT16(length));
83} 83}
84 84
85static inline void rt2500usb_register_write(struct rt2x00_dev *rt2x00dev, 85static inline void rt2500usb_register_write(struct rt2x00_dev *rt2x00dev,
@@ -106,10 +106,10 @@ static inline void rt2500usb_register_multiwrite(struct rt2x00_dev *rt2x00dev,
106 const unsigned int offset, 106 const unsigned int offset,
107 void *value, const u16 length) 107 void *value, const u16 length)
108{ 108{
109 int timeout = REGISTER_TIMEOUT * (length / sizeof(u16));
110 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE, 109 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
111 USB_VENDOR_REQUEST_OUT, offset, 110 USB_VENDOR_REQUEST_OUT, offset,
112 value, length, timeout); 111 value, length,
112 REGISTER_TIMEOUT16(length));
113} 113}
114 114
115static u16 rt2500usb_bbp_check(struct rt2x00_dev *rt2x00dev) 115static u16 rt2500usb_bbp_check(struct rt2x00_dev *rt2x00dev)
@@ -1094,11 +1094,11 @@ static int rt2500usb_get_tx_data_len(struct rt2x00_dev *rt2x00dev,
1094 * TX data initialization 1094 * TX data initialization
1095 */ 1095 */
1096static void rt2500usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev, 1096static void rt2500usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
1097 const unsigned int queue) 1097 const enum data_queue_qid queue)
1098{ 1098{
1099 u16 reg; 1099 u16 reg;
1100 1100
1101 if (queue != RT2X00_BCN_QUEUE_BEACON) 1101 if (queue != QID_BEACON)
1102 return; 1102 return;
1103 1103
1104 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg); 1104 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
@@ -1720,12 +1720,6 @@ static int rt2500usb_beacon_update(struct ieee80211_hw *hw,
1720 rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 0); 1720 rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 0);
1721 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg); 1721 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
1722 1722
1723 /*
1724 * mac80211 doesn't provide the control->queue variable
1725 * for beacons. Set our own queue identification so
1726 * it can be used during descriptor initialization.
1727 */
1728 control->queue = RT2X00_BCN_QUEUE_BEACON;
1729 rt2x00lib_write_tx_desc(rt2x00dev, skb, control); 1723 rt2x00lib_write_tx_desc(rt2x00dev, skb, control);
1730 1724
1731 /* 1725 /*
@@ -1757,7 +1751,7 @@ static int rt2500usb_beacon_update(struct ieee80211_hw *hw,
1757 /* 1751 /*
1758 * Enable beacon generation. 1752 * Enable beacon generation.
1759 */ 1753 */
1760 rt2500usb_kick_tx_queue(rt2x00dev, control->queue); 1754 rt2500usb_kick_tx_queue(rt2x00dev, QID_BEACON);
1761 1755
1762 return 0; 1756 return 0;
1763} 1757}
diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
index 57bdc153952f..79bd9c9f8963 100644
--- a/drivers/net/wireless/rt2x00/rt2x00.h
+++ b/drivers/net/wireless/rt2x00/rt2x00.h
@@ -44,7 +44,7 @@
44/* 44/*
45 * Module information. 45 * Module information.
46 */ 46 */
47#define DRV_VERSION "2.1.4" 47#define DRV_VERSION "2.1.5"
48#define DRV_PROJECT "http://rt2x00.serialmonkey.com" 48#define DRV_PROJECT "http://rt2x00.serialmonkey.com"
49 49
50/* 50/*
@@ -404,7 +404,7 @@ static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
404 * @supported_rates: Rate types which are supported (CCK, OFDM). 404 * @supported_rates: Rate types which are supported (CCK, OFDM).
405 * @num_channels: Number of supported channels. This is used as array size 405 * @num_channels: Number of supported channels. This is used as array size
406 * for @tx_power_a, @tx_power_bg and @channels. 406 * for @tx_power_a, @tx_power_bg and @channels.
407 * channels: Device/chipset specific channel values (See &struct rf_channel). 407 * @channels: Device/chipset specific channel values (See &struct rf_channel).
408 * @tx_power_a: TX power values for all 5.2GHz channels (may be NULL). 408 * @tx_power_a: TX power values for all 5.2GHz channels (may be NULL).
409 * @tx_power_bg: TX power values for all 2.4GHz channels (may be NULL). 409 * @tx_power_bg: TX power values for all 2.4GHz channels (may be NULL).
410 * @tx_power_default: Default TX power value to use when either 410 * @tx_power_default: Default TX power value to use when either
@@ -548,7 +548,7 @@ struct rt2x00lib_ops {
548 int (*get_tx_data_len) (struct rt2x00_dev *rt2x00dev, 548 int (*get_tx_data_len) (struct rt2x00_dev *rt2x00dev,
549 struct sk_buff *skb); 549 struct sk_buff *skb);
550 void (*kick_tx_queue) (struct rt2x00_dev *rt2x00dev, 550 void (*kick_tx_queue) (struct rt2x00_dev *rt2x00dev,
551 const unsigned int queue); 551 const enum data_queue_qid queue);
552 552
553 /* 553 /*
554 * RX control handlers 554 * RX control handlers
@@ -621,7 +621,6 @@ enum rt2x00_flags {
621 /* 621 /*
622 * Driver features 622 * Driver features
623 */ 623 */
624 DRIVER_SUPPORT_MIXED_INTERFACES,
625 DRIVER_REQUIRE_FIRMWARE, 624 DRIVER_REQUIRE_FIRMWARE,
626 DRIVER_REQUIRE_BEACON_GUARD, 625 DRIVER_REQUIRE_BEACON_GUARD,
627 DRIVER_REQUIRE_ATIM_QUEUE, 626 DRIVER_REQUIRE_ATIM_QUEUE,
@@ -928,17 +927,16 @@ static inline u16 get_duration_res(const unsigned int size, const u8 rate)
928} 927}
929 928
930/** 929/**
931 * rt2x00queue_get_queue - Convert mac80211 queue index to rt2x00 queue 930 * rt2x00queue_get_queue - Convert queue index to queue pointer
932 * @rt2x00dev: Pointer to &struct rt2x00_dev. 931 * @rt2x00dev: Pointer to &struct rt2x00_dev.
933 * @queue: mac80211/rt2x00 queue index 932 * @queue: rt2x00 queue index (see &enum data_queue_qid).
934 * (see &enum ieee80211_tx_queue and &enum rt2x00_bcn_queue).
935 */ 933 */
936struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev, 934struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev,
937 const unsigned int queue); 935 const enum data_queue_qid queue);
938 936
939/** 937/**
940 * rt2x00queue_get_entry - Get queue entry where the given index points to. 938 * rt2x00queue_get_entry - Get queue entry where the given index points to.
941 * @rt2x00dev: Pointer to &struct rt2x00_dev. 939 * @queue: Pointer to &struct data_queue from where we obtain the entry.
942 * @index: Index identifier for obtaining the correct index. 940 * @index: Index identifier for obtaining the correct index.
943 */ 941 */
944struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue, 942struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
@@ -947,7 +945,7 @@ struct queue_entry *rt2x00queue_get_entry(struct data_queue *queue,
947/** 945/**
948 * rt2x00queue_index_inc - Index incrementation function 946 * rt2x00queue_index_inc - Index incrementation function
949 * @queue: Queue (&struct data_queue) to perform the action on. 947 * @queue: Queue (&struct data_queue) to perform the action on.
950 * @action: Index type (&enum queue_index) to perform the action on. 948 * @index: Index type (&enum queue_index) to perform the action on.
951 * 949 *
952 * This function will increase the requested index on the queue, 950 * This function will increase the requested index on the queue,
953 * it will grab the appropriate locks and handle queue overflow events by 951 * it will grab the appropriate locks and handle queue overflow events by
@@ -999,7 +997,7 @@ void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
999 struct ieee80211_vif *vif, 997 struct ieee80211_vif *vif,
1000 struct ieee80211_bss_conf *bss_conf, 998 struct ieee80211_bss_conf *bss_conf,
1001 u32 changes); 999 u32 changes);
1002int rt2x00mac_conf_tx(struct ieee80211_hw *hw, int queue, 1000int rt2x00mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
1003 const struct ieee80211_tx_queue_params *params); 1001 const struct ieee80211_tx_queue_params *params);
1004 1002
1005/* 1003/*
diff --git a/drivers/net/wireless/rt2x00/rt2x00dev.c b/drivers/net/wireless/rt2x00/rt2x00dev.c
index b22c02737185..61510c519351 100644
--- a/drivers/net/wireless/rt2x00/rt2x00dev.c
+++ b/drivers/net/wireless/rt2x00/rt2x00dev.c
@@ -525,9 +525,6 @@ void rt2x00lib_txdone(struct queue_entry *entry,
525 rt2x00dev->low_level_stats.dot11ACKFailureCount++; 525 rt2x00dev->low_level_stats.dot11ACKFailureCount++;
526 } 526 }
527 527
528 tx_status.queue_length = entry->queue->limit;
529 tx_status.queue_number = tx_status.control.queue;
530
531 if (tx_status.control.flags & IEEE80211_TXCTL_USE_RTS_CTS) { 528 if (tx_status.control.flags & IEEE80211_TXCTL_USE_RTS_CTS) {
532 if (success) 529 if (success)
533 rt2x00dev->low_level_stats.dot11RTSSuccessCount++; 530 rt2x00dev->low_level_stats.dot11RTSSuccessCount++;
@@ -687,8 +684,7 @@ void rt2x00lib_write_tx_desc(struct rt2x00_dev *rt2x00dev,
687 * Beacons and probe responses require the tsf timestamp 684 * Beacons and probe responses require the tsf timestamp
688 * to be inserted into the frame. 685 * to be inserted into the frame.
689 */ 686 */
690 if (control->queue == RT2X00_BCN_QUEUE_BEACON || 687 if (txdesc.queue == QID_BEACON || is_probe_resp(frame_control))
691 is_probe_resp(frame_control))
692 __set_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc.flags); 688 __set_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc.flags);
693 689
694 /* 690 /*
diff --git a/drivers/net/wireless/rt2x00/rt2x00mac.c b/drivers/net/wireless/rt2x00/rt2x00mac.c
index c206b5092070..767e0ffce04e 100644
--- a/drivers/net/wireless/rt2x00/rt2x00mac.c
+++ b/drivers/net/wireless/rt2x00/rt2x00mac.c
@@ -81,6 +81,7 @@ int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
81{ 81{
82 struct rt2x00_dev *rt2x00dev = hw->priv; 82 struct rt2x00_dev *rt2x00dev = hw->priv;
83 struct ieee80211_hdr *ieee80211hdr = (struct ieee80211_hdr *)skb->data; 83 struct ieee80211_hdr *ieee80211hdr = (struct ieee80211_hdr *)skb->data;
84 enum data_queue_qid qid = mac80211_queue_to_qid(control->queue);
84 struct data_queue *queue; 85 struct data_queue *queue;
85 struct skb_frame_desc *skbdesc; 86 struct skb_frame_desc *skbdesc;
86 u16 frame_control; 87 u16 frame_control;
@@ -101,14 +102,13 @@ int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
101 */ 102 */
102 if (control->flags & IEEE80211_TXCTL_SEND_AFTER_DTIM && 103 if (control->flags & IEEE80211_TXCTL_SEND_AFTER_DTIM &&
103 test_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags)) 104 test_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags))
104 queue = rt2x00queue_get_queue(rt2x00dev, RT2X00_BCN_QUEUE_ATIM); 105 queue = rt2x00queue_get_queue(rt2x00dev, QID_ATIM);
105 else 106 else
106 queue = rt2x00queue_get_queue(rt2x00dev, control->queue); 107 queue = rt2x00queue_get_queue(rt2x00dev, qid);
107 if (unlikely(!queue)) { 108 if (unlikely(!queue)) {
108 ERROR(rt2x00dev, 109 ERROR(rt2x00dev,
109 "Attempt to send packet over invalid queue %d.\n" 110 "Attempt to send packet over invalid queue %d.\n"
110 "Please file bug report to %s.\n", 111 "Please file bug report to %s.\n", qid, DRV_PROJECT);
111 control->queue, DRV_PROJECT);
112 dev_kfree_skb_any(skb); 112 dev_kfree_skb_any(skb);
113 return NETDEV_TX_OK; 113 return NETDEV_TX_OK;
114 } 114 }
@@ -118,11 +118,16 @@ int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
118 * create and queue that frame first. But make sure we have 118 * create and queue that frame first. But make sure we have
119 * at least enough entries available to send this CTS/RTS 119 * at least enough entries available to send this CTS/RTS
120 * frame as well as the data frame. 120 * frame as well as the data frame.
121 * Note that when the driver has set the set_rts_threshold()
122 * callback function it doesn't need software generation of
123 * neither RTS or CTS-to-self frames and handles everything
124 * inside the hardware.
121 */ 125 */
122 frame_control = le16_to_cpu(ieee80211hdr->frame_control); 126 frame_control = le16_to_cpu(ieee80211hdr->frame_control);
123 if (!is_rts_frame(frame_control) && !is_cts_frame(frame_control) && 127 if (!is_rts_frame(frame_control) && !is_cts_frame(frame_control) &&
124 (control->flags & (IEEE80211_TXCTL_USE_RTS_CTS | 128 (control->flags & (IEEE80211_TXCTL_USE_RTS_CTS |
125 IEEE80211_TXCTL_USE_CTS_PROTECT))) { 129 IEEE80211_TXCTL_USE_CTS_PROTECT)) &&
130 !rt2x00dev->ops->hw->set_rts_threshold) {
126 if (rt2x00queue_available(queue) <= 1) { 131 if (rt2x00queue_available(queue) <= 1) {
127 ieee80211_stop_queue(rt2x00dev->hw, control->queue); 132 ieee80211_stop_queue(rt2x00dev->hw, control->queue);
128 return NETDEV_TX_BUSY; 133 return NETDEV_TX_BUSY;
@@ -149,7 +154,7 @@ int rt2x00mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
149 ieee80211_stop_queue(rt2x00dev->hw, control->queue); 154 ieee80211_stop_queue(rt2x00dev->hw, control->queue);
150 155
151 if (rt2x00dev->ops->lib->kick_tx_queue) 156 if (rt2x00dev->ops->lib->kick_tx_queue)
152 rt2x00dev->ops->lib->kick_tx_queue(rt2x00dev, control->queue); 157 rt2x00dev->ops->lib->kick_tx_queue(rt2x00dev, qid);
153 158
154 return NETDEV_TX_OK; 159 return NETDEV_TX_OK;
155} 160}
@@ -182,8 +187,7 @@ int rt2x00mac_add_interface(struct ieee80211_hw *hw,
182{ 187{
183 struct rt2x00_dev *rt2x00dev = hw->priv; 188 struct rt2x00_dev *rt2x00dev = hw->priv;
184 struct rt2x00_intf *intf = vif_to_intf(conf->vif); 189 struct rt2x00_intf *intf = vif_to_intf(conf->vif);
185 struct data_queue *queue = 190 struct data_queue *queue = rt2x00queue_get_queue(rt2x00dev, QID_BEACON);
186 rt2x00queue_get_queue(rt2x00dev, RT2X00_BCN_QUEUE_BEACON);
187 struct queue_entry *entry = NULL; 191 struct queue_entry *entry = NULL;
188 unsigned int i; 192 unsigned int i;
189 193
@@ -196,13 +200,12 @@ int rt2x00mac_add_interface(struct ieee80211_hw *hw,
196 return -ENODEV; 200 return -ENODEV;
197 201
198 /* 202 /*
199 * When we don't support mixed interfaces (a combination 203 * We don't support mixed combinations of sta and ap virtual
200 * of sta and ap virtual interfaces) then we can only 204 * interfaces. We can only add this interface when the rival
201 * add this interface when the rival interface count is 0. 205 * interface count is 0.
202 */ 206 */
203 if (!test_bit(DRIVER_SUPPORT_MIXED_INTERFACES, &rt2x00dev->flags) && 207 if ((conf->type == IEEE80211_IF_TYPE_AP && rt2x00dev->intf_sta_count) ||
204 ((conf->type == IEEE80211_IF_TYPE_AP && rt2x00dev->intf_sta_count) || 208 (conf->type != IEEE80211_IF_TYPE_AP && rt2x00dev->intf_ap_count))
205 (conf->type != IEEE80211_IF_TYPE_AP && rt2x00dev->intf_ap_count)))
206 return -ENOBUFS; 209 return -ENOBUFS;
207 210
208 /* 211 /*
@@ -454,9 +457,9 @@ int rt2x00mac_get_tx_stats(struct ieee80211_hw *hw,
454 unsigned int i; 457 unsigned int i;
455 458
456 for (i = 0; i < hw->queues; i++) { 459 for (i = 0; i < hw->queues; i++) {
457 stats->data[i].len = rt2x00dev->tx[i].length; 460 stats[i].len = rt2x00dev->tx[i].length;
458 stats->data[i].limit = rt2x00dev->tx[i].limit; 461 stats[i].limit = rt2x00dev->tx[i].limit;
459 stats->data[i].count = rt2x00dev->tx[i].count; 462 stats[i].count = rt2x00dev->tx[i].count;
460 } 463 }
461 464
462 return 0; 465 return 0;
@@ -514,7 +517,7 @@ void rt2x00mac_bss_info_changed(struct ieee80211_hw *hw,
514} 517}
515EXPORT_SYMBOL_GPL(rt2x00mac_bss_info_changed); 518EXPORT_SYMBOL_GPL(rt2x00mac_bss_info_changed);
516 519
517int rt2x00mac_conf_tx(struct ieee80211_hw *hw, int queue_idx, 520int rt2x00mac_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
518 const struct ieee80211_tx_queue_params *params) 521 const struct ieee80211_tx_queue_params *params)
519{ 522{
520 struct rt2x00_dev *rt2x00dev = hw->priv; 523 struct rt2x00_dev *rt2x00dev = hw->priv;
diff --git a/drivers/net/wireless/rt2x00/rt2x00pci.c b/drivers/net/wireless/rt2x00/rt2x00pci.c
index 971af2546b59..c17078eac197 100644
--- a/drivers/net/wireless/rt2x00/rt2x00pci.c
+++ b/drivers/net/wireless/rt2x00/rt2x00pci.c
@@ -53,7 +53,7 @@ int rt2x00pci_write_tx_data(struct rt2x00_dev *rt2x00dev,
53 ERROR(rt2x00dev, 53 ERROR(rt2x00dev,
54 "Arrived at non-free entry in the non-full queue %d.\n" 54 "Arrived at non-free entry in the non-full queue %d.\n"
55 "Please file bug report to %s.\n", 55 "Please file bug report to %s.\n",
56 control->queue, DRV_PROJECT); 56 entry->queue->qid, DRV_PROJECT);
57 return -EINVAL; 57 return -EINVAL;
58 } 58 }
59 59
diff --git a/drivers/net/wireless/rt2x00/rt2x00pci.h b/drivers/net/wireless/rt2x00/rt2x00pci.h
index 9d1cdb99431c..2b0ef17bba6e 100644
--- a/drivers/net/wireless/rt2x00/rt2x00pci.h
+++ b/drivers/net/wireless/rt2x00/rt2x00pci.h
@@ -98,8 +98,9 @@ int rt2x00pci_write_tx_data(struct rt2x00_dev *rt2x00dev,
98 * struct queue_entry_priv_pci_rx: Per RX entry PCI specific information 98 * struct queue_entry_priv_pci_rx: Per RX entry PCI specific information
99 * 99 *
100 * @desc: Pointer to device descriptor. 100 * @desc: Pointer to device descriptor.
101 * @desc_dma: DMA pointer to @desc.
101 * @data: Pointer to device's entry memory. 102 * @data: Pointer to device's entry memory.
102 * @dma: DMA pointer to &data. 103 * @data_dma: DMA pointer to &data.
103 */ 104 */
104struct queue_entry_priv_pci_rx { 105struct queue_entry_priv_pci_rx {
105 __le32 *desc; 106 __le32 *desc;
@@ -113,8 +114,9 @@ struct queue_entry_priv_pci_rx {
113 * struct queue_entry_priv_pci_tx: Per TX entry PCI specific information 114 * struct queue_entry_priv_pci_tx: Per TX entry PCI specific information
114 * 115 *
115 * @desc: Pointer to device descriptor 116 * @desc: Pointer to device descriptor
117 * @desc_dma: DMA pointer to @desc.
116 * @data: Pointer to device's entry memory. 118 * @data: Pointer to device's entry memory.
117 * @dma: DMA pointer to &data. 119 * @data_dma: DMA pointer to &data.
118 * @control: mac80211 control structure used to transmit data. 120 * @control: mac80211 control structure used to transmit data.
119 */ 121 */
120struct queue_entry_priv_pci_tx { 122struct queue_entry_priv_pci_tx {
diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
index 659e9f44c40c..e5b861f8416d 100644
--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
@@ -30,7 +30,7 @@
30#include "rt2x00lib.h" 30#include "rt2x00lib.h"
31 31
32struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev, 32struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev,
33 const unsigned int queue) 33 const enum data_queue_qid queue)
34{ 34{
35 int atim = test_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags); 35 int atim = test_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags);
36 36
@@ -40,9 +40,9 @@ struct data_queue *rt2x00queue_get_queue(struct rt2x00_dev *rt2x00dev,
40 if (!rt2x00dev->bcn) 40 if (!rt2x00dev->bcn)
41 return NULL; 41 return NULL;
42 42
43 if (queue == RT2X00_BCN_QUEUE_BEACON) 43 if (queue == QID_BEACON)
44 return &rt2x00dev->bcn[0]; 44 return &rt2x00dev->bcn[0];
45 else if (queue == RT2X00_BCN_QUEUE_ATIM && atim) 45 else if (queue == QID_ATIM && atim)
46 return &rt2x00dev->bcn[1]; 46 return &rt2x00dev->bcn[1];
47 47
48 return NULL; 48 return NULL;
diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.h b/drivers/net/wireless/rt2x00/rt2x00queue.h
index 7027c9f47d3f..d1707a7ca41f 100644
--- a/drivers/net/wireless/rt2x00/rt2x00queue.h
+++ b/drivers/net/wireless/rt2x00/rt2x00queue.h
@@ -54,6 +54,17 @@
54 54
55/** 55/**
56 * enum data_queue_qid: Queue identification 56 * enum data_queue_qid: Queue identification
57 *
58 * @QID_AC_BE: AC BE queue
59 * @QID_AC_BK: AC BK queue
60 * @QID_AC_VI: AC VI queue
61 * @QID_AC_VO: AC VO queue
62 * @QID_HCCA: HCCA queue
63 * @QID_MGMT: MGMT queue (prio queue)
64 * @QID_RX: RX queue
65 * @QID_OTHER: None of the above (don't use, only present for completeness)
66 * @QID_BEACON: Beacon queue (value unspecified, don't send it to device)
67 * @QID_ATIM: Atim queue (value unspeficied, don't send it to device)
57 */ 68 */
58enum data_queue_qid { 69enum data_queue_qid {
59 QID_AC_BE = 0, 70 QID_AC_BE = 0,
@@ -64,22 +75,22 @@ enum data_queue_qid {
64 QID_MGMT = 13, 75 QID_MGMT = 13,
65 QID_RX = 14, 76 QID_RX = 14,
66 QID_OTHER = 15, 77 QID_OTHER = 15,
78 QID_BEACON,
79 QID_ATIM,
67}; 80};
68 81
69/** 82/**
70 * enum rt2x00_bcn_queue: Beacon queue index 83 * mac80211_queue_to_qid - Convert mac80211 queue to rt2x00 qid
71 * 84 * @queue: mac80211 queue.
72 * Start counting with a high offset, this because this enumeration
73 * supplements &enum ieee80211_tx_queue and we should prevent value
74 * conflicts.
75 *
76 * @RT2X00_BCN_QUEUE_BEACON: Beacon queue
77 * @RT2X00_BCN_QUEUE_ATIM: Atim queue (sends frame after beacon)
78 */ 85 */
79enum rt2x00_bcn_queue { 86static inline enum data_queue_qid mac80211_queue_to_qid(unsigned int queue)
80 RT2X00_BCN_QUEUE_BEACON = 100, 87{
81 RT2X00_BCN_QUEUE_ATIM = 101, 88 /* Regular TX queues are mapped directly */
82}; 89 if (queue < 4)
90 return queue;
91 WARN_ON(1);
92 return QID_OTHER;
93}
83 94
84/** 95/**
85 * enum skb_frame_desc_flags: Flags for &struct skb_frame_desc 96 * enum skb_frame_desc_flags: Flags for &struct skb_frame_desc
@@ -105,7 +116,6 @@ enum skb_frame_desc_flags {
105 * of the scope of the skb->data pointer. 116 * of the scope of the skb->data pointer.
106 * @data_len: Length of the frame data. 117 * @data_len: Length of the frame data.
107 * @desc_len: Length of the frame descriptor. 118 * @desc_len: Length of the frame descriptor.
108
109 * @entry: The entry to which this sk buffer belongs. 119 * @entry: The entry to which this sk buffer belongs.
110 */ 120 */
111struct skb_frame_desc { 121struct skb_frame_desc {
@@ -240,7 +250,6 @@ struct txentry_desc {
240 * encryption or decryption. The entry should only be touched after 250 * encryption or decryption. The entry should only be touched after
241 * the device has signaled it is done with it. 251 * the device has signaled it is done with it.
242 */ 252 */
243
244enum queue_entry_flags { 253enum queue_entry_flags {
245 ENTRY_BCN_ASSIGNED, 254 ENTRY_BCN_ASSIGNED,
246 ENTRY_OWNER_DEVICE_DATA, 255 ENTRY_OWNER_DEVICE_DATA,
diff --git a/drivers/net/wireless/rt2x00/rt2x00usb.c b/drivers/net/wireless/rt2x00/rt2x00usb.c
index 5a331674dcb2..98aafc2d584a 100644
--- a/drivers/net/wireless/rt2x00/rt2x00usb.c
+++ b/drivers/net/wireless/rt2x00/rt2x00usb.c
@@ -186,7 +186,7 @@ int rt2x00usb_write_tx_data(struct rt2x00_dev *rt2x00dev,
186 ERROR(rt2x00dev, 186 ERROR(rt2x00dev,
187 "Arrived at non-free entry in the non-full queue %d.\n" 187 "Arrived at non-free entry in the non-full queue %d.\n"
188 "Please file bug report to %s.\n", 188 "Please file bug report to %s.\n",
189 control->queue, DRV_PROJECT); 189 entry->queue->qid, DRV_PROJECT);
190 return -EINVAL; 190 return -EINVAL;
191 } 191 }
192 192
@@ -344,7 +344,7 @@ void rt2x00usb_disable_radio(struct rt2x00_dev *rt2x00dev)
344 struct data_queue *queue; 344 struct data_queue *queue;
345 unsigned int i; 345 unsigned int i;
346 346
347 rt2x00usb_vendor_request_sw(rt2x00dev, USB_RX_CONTROL, 0x0000, 0x0000, 347 rt2x00usb_vendor_request_sw(rt2x00dev, USB_RX_CONTROL, 0, 0,
348 REGISTER_TIMEOUT); 348 REGISTER_TIMEOUT);
349 349
350 /* 350 /*
diff --git a/drivers/net/wireless/rt2x00/rt2x00usb.h b/drivers/net/wireless/rt2x00/rt2x00usb.h
index 11e55180cbaf..4da9eb376ebd 100644
--- a/drivers/net/wireless/rt2x00/rt2x00usb.h
+++ b/drivers/net/wireless/rt2x00/rt2x00usb.h
@@ -47,6 +47,20 @@
47#define REGISTER_TIMEOUT 500 47#define REGISTER_TIMEOUT 500
48#define REGISTER_TIMEOUT_FIRMWARE 1000 48#define REGISTER_TIMEOUT_FIRMWARE 1000
49 49
50/**
51 * REGISTER_TIMEOUT16 - Determine the timeout for 16bit register access
52 * @__datalen: Data length
53 */
54#define REGISTER_TIMEOUT16(__datalen) \
55 ( REGISTER_TIMEOUT * ((__datalen) / sizeof(u16)) )
56
57/**
58 * REGISTER_TIMEOUT32 - Determine the timeout for 32bit register access
59 * @__datalen: Data length
60 */
61#define REGISTER_TIMEOUT32(__datalen) \
62 ( REGISTER_TIMEOUT * ((__datalen) / sizeof(u32)) )
63
50/* 64/*
51 * Cache size 65 * Cache size
52 */ 66 */
@@ -185,13 +199,12 @@ static inline int rt2x00usb_vendor_request_sw(struct rt2x00_dev *rt2x00dev,
185 * kmalloc for correct handling inside the kernel USB layer. 199 * kmalloc for correct handling inside the kernel USB layer.
186 */ 200 */
187static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev, 201static inline int rt2x00usb_eeprom_read(struct rt2x00_dev *rt2x00dev,
188 __le16 *eeprom, const u16 lenght) 202 __le16 *eeprom, const u16 length)
189{ 203{
190 int timeout = REGISTER_TIMEOUT * (lenght / sizeof(u16));
191
192 return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ, 204 return rt2x00usb_vendor_request(rt2x00dev, USB_EEPROM_READ,
193 USB_VENDOR_REQUEST_IN, 0, 0, 205 USB_VENDOR_REQUEST_IN, 0, 0,
194 eeprom, lenght, timeout); 206 eeprom, length,
207 REGISTER_TIMEOUT16(length));
195} 208}
196 209
197/* 210/*
diff --git a/drivers/net/wireless/rt2x00/rt61pci.c b/drivers/net/wireless/rt2x00/rt61pci.c
index 14bc7b281659..b64f2f5d0d53 100644
--- a/drivers/net/wireless/rt2x00/rt61pci.c
+++ b/drivers/net/wireless/rt2x00/rt61pci.c
@@ -1591,11 +1591,11 @@ static void rt61pci_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1591 * TX data initialization 1591 * TX data initialization
1592 */ 1592 */
1593static void rt61pci_kick_tx_queue(struct rt2x00_dev *rt2x00dev, 1593static void rt61pci_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
1594 const unsigned int queue) 1594 const enum data_queue_qid queue)
1595{ 1595{
1596 u32 reg; 1596 u32 reg;
1597 1597
1598 if (queue == RT2X00_BCN_QUEUE_BEACON) { 1598 if (queue == QID_BEACON) {
1599 /* 1599 /*
1600 * For Wi-Fi faily generated beacons between participating 1600 * For Wi-Fi faily generated beacons between participating
1601 * stations. Set TBTT phase adaptive adjustment step to 8us. 1601 * stations. Set TBTT phase adaptive adjustment step to 8us.
@@ -1613,14 +1613,10 @@ static void rt61pci_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
1613 } 1613 }
1614 1614
1615 rt2x00pci_register_read(rt2x00dev, TX_CNTL_CSR, &reg); 1615 rt2x00pci_register_read(rt2x00dev, TX_CNTL_CSR, &reg);
1616 rt2x00_set_field32(&reg, TX_CNTL_CSR_KICK_TX_AC0, 1616 rt2x00_set_field32(&reg, TX_CNTL_CSR_KICK_TX_AC0, (queue == QID_AC_BE));
1617 (queue == IEEE80211_TX_QUEUE_DATA0)); 1617 rt2x00_set_field32(&reg, TX_CNTL_CSR_KICK_TX_AC1, (queue == QID_AC_BK));
1618 rt2x00_set_field32(&reg, TX_CNTL_CSR_KICK_TX_AC1, 1618 rt2x00_set_field32(&reg, TX_CNTL_CSR_KICK_TX_AC2, (queue == QID_AC_VI));
1619 (queue == IEEE80211_TX_QUEUE_DATA1)); 1619 rt2x00_set_field32(&reg, TX_CNTL_CSR_KICK_TX_AC3, (queue == QID_AC_VO));
1620 rt2x00_set_field32(&reg, TX_CNTL_CSR_KICK_TX_AC2,
1621 (queue == IEEE80211_TX_QUEUE_DATA2));
1622 rt2x00_set_field32(&reg, TX_CNTL_CSR_KICK_TX_AC3,
1623 (queue == IEEE80211_TX_QUEUE_DATA3));
1624 rt2x00pci_register_write(rt2x00dev, TX_CNTL_CSR, reg); 1620 rt2x00pci_register_write(rt2x00dev, TX_CNTL_CSR, reg);
1625} 1621}
1626 1622
@@ -2400,24 +2396,17 @@ static int rt61pci_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb,
2400 rt2x00pci_register_write(rt2x00dev, TXRX_CSR9, reg); 2396 rt2x00pci_register_write(rt2x00dev, TXRX_CSR9, reg);
2401 2397
2402 /* 2398 /*
2403 * mac80211 doesn't provide the control->queue variable
2404 * for beacons. Set our own queue identification so
2405 * it can be used during descriptor initialization.
2406 */
2407 control->queue = RT2X00_BCN_QUEUE_BEACON;
2408 rt2x00lib_write_tx_desc(rt2x00dev, skb, control);
2409
2410 /*
2411 * Write entire beacon with descriptor to register, 2399 * Write entire beacon with descriptor to register,
2412 * and kick the beacon generator. 2400 * and kick the beacon generator.
2413 */ 2401 */
2402 rt2x00lib_write_tx_desc(rt2x00dev, skb, control);
2414 beacon_base = HW_BEACON_OFFSET(intf->beacon->entry_idx); 2403 beacon_base = HW_BEACON_OFFSET(intf->beacon->entry_idx);
2415 rt2x00pci_register_multiwrite(rt2x00dev, beacon_base, 2404 rt2x00pci_register_multiwrite(rt2x00dev, beacon_base,
2416 skbdesc->desc, skbdesc->desc_len); 2405 skbdesc->desc, skbdesc->desc_len);
2417 rt2x00pci_register_multiwrite(rt2x00dev, 2406 rt2x00pci_register_multiwrite(rt2x00dev,
2418 beacon_base + skbdesc->desc_len, 2407 beacon_base + skbdesc->desc_len,
2419 skbdesc->data, skbdesc->data_len); 2408 skbdesc->data, skbdesc->data_len);
2420 rt61pci_kick_tx_queue(rt2x00dev, control->queue); 2409 rt61pci_kick_tx_queue(rt2x00dev, QID_BEACON);
2421 2410
2422 return 0; 2411 return 0;
2423} 2412}
diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c
index da19a3a91f4d..351d95c4f50d 100644
--- a/drivers/net/wireless/rt2x00/rt73usb.c
+++ b/drivers/net/wireless/rt2x00/rt73usb.c
@@ -74,10 +74,10 @@ static inline void rt73usb_register_multiread(struct rt2x00_dev *rt2x00dev,
74 const unsigned int offset, 74 const unsigned int offset,
75 void *value, const u32 length) 75 void *value, const u32 length)
76{ 76{
77 int timeout = REGISTER_TIMEOUT * (length / sizeof(u32));
78 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ, 77 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
79 USB_VENDOR_REQUEST_IN, offset, 78 USB_VENDOR_REQUEST_IN, offset,
80 value, length, timeout); 79 value, length,
80 REGISTER_TIMEOUT32(length));
81} 81}
82 82
83static inline void rt73usb_register_write(struct rt2x00_dev *rt2x00dev, 83static inline void rt73usb_register_write(struct rt2x00_dev *rt2x00dev,
@@ -102,10 +102,10 @@ static inline void rt73usb_register_multiwrite(struct rt2x00_dev *rt2x00dev,
102 const unsigned int offset, 102 const unsigned int offset,
103 void *value, const u32 length) 103 void *value, const u32 length)
104{ 104{
105 int timeout = REGISTER_TIMEOUT * (length / sizeof(u32));
106 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE, 105 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
107 USB_VENDOR_REQUEST_OUT, offset, 106 USB_VENDOR_REQUEST_OUT, offset,
108 value, length, timeout); 107 value, length,
108 REGISTER_TIMEOUT32(length));
109} 109}
110 110
111static u32 rt73usb_bbp_check(struct rt2x00_dev *rt2x00dev) 111static u32 rt73usb_bbp_check(struct rt2x00_dev *rt2x00dev)
@@ -876,7 +876,6 @@ static int rt73usb_load_firmware(struct rt2x00_dev *rt2x00dev, void *data,
876 char *ptr = data; 876 char *ptr = data;
877 char *cache; 877 char *cache;
878 int buflen; 878 int buflen;
879 int timeout;
880 879
881 /* 880 /*
882 * Wait for stable hardware. 881 * Wait for stable hardware.
@@ -907,14 +906,14 @@ static int rt73usb_load_firmware(struct rt2x00_dev *rt2x00dev, void *data,
907 906
908 for (i = 0; i < len; i += CSR_CACHE_SIZE_FIRMWARE) { 907 for (i = 0; i < len; i += CSR_CACHE_SIZE_FIRMWARE) {
909 buflen = min_t(int, len - i, CSR_CACHE_SIZE_FIRMWARE); 908 buflen = min_t(int, len - i, CSR_CACHE_SIZE_FIRMWARE);
910 timeout = REGISTER_TIMEOUT * (buflen / sizeof(u32));
911 909
912 memcpy(cache, ptr, buflen); 910 memcpy(cache, ptr, buflen);
913 911
914 rt2x00usb_vendor_request(rt2x00dev, USB_MULTI_WRITE, 912 rt2x00usb_vendor_request(rt2x00dev, USB_MULTI_WRITE,
915 USB_VENDOR_REQUEST_OUT, 913 USB_VENDOR_REQUEST_OUT,
916 FIRMWARE_IMAGE_BASE + i, 0, 914 FIRMWARE_IMAGE_BASE + i, 0,
917 cache, buflen, timeout); 915 cache, buflen,
916 REGISTER_TIMEOUT32(buflen));
918 917
919 ptr += buflen; 918 ptr += buflen;
920 } 919 }
@@ -1331,11 +1330,11 @@ static int rt73usb_get_tx_data_len(struct rt2x00_dev *rt2x00dev,
1331 * TX data initialization 1330 * TX data initialization
1332 */ 1331 */
1333static void rt73usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev, 1332static void rt73usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
1334 const unsigned int queue) 1333 const enum data_queue_qid queue)
1335{ 1334{
1336 u32 reg; 1335 u32 reg;
1337 1336
1338 if (queue != RT2X00_BCN_QUEUE_BEACON) 1337 if (queue != QID_BEACON)
1339 return; 1338 return;
1340 1339
1341 /* 1340 /*
@@ -1966,7 +1965,6 @@ static int rt73usb_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb,
1966 struct rt2x00_intf *intf = vif_to_intf(control->vif); 1965 struct rt2x00_intf *intf = vif_to_intf(control->vif);
1967 struct skb_frame_desc *skbdesc; 1966 struct skb_frame_desc *skbdesc;
1968 unsigned int beacon_base; 1967 unsigned int beacon_base;
1969 unsigned int timeout;
1970 u32 reg; 1968 u32 reg;
1971 1969
1972 if (unlikely(!intf->beacon)) 1970 if (unlikely(!intf->beacon))
@@ -2001,23 +1999,16 @@ static int rt73usb_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb,
2001 rt73usb_register_write(rt2x00dev, TXRX_CSR9, reg); 1999 rt73usb_register_write(rt2x00dev, TXRX_CSR9, reg);
2002 2000
2003 /* 2001 /*
2004 * mac80211 doesn't provide the control->queue variable
2005 * for beacons. Set our own queue identification so
2006 * it can be used during descriptor initialization.
2007 */
2008 control->queue = RT2X00_BCN_QUEUE_BEACON;
2009 rt2x00lib_write_tx_desc(rt2x00dev, skb, control);
2010
2011 /*
2012 * Write entire beacon with descriptor to register, 2002 * Write entire beacon with descriptor to register,
2013 * and kick the beacon generator. 2003 * and kick the beacon generator.
2014 */ 2004 */
2005 rt2x00lib_write_tx_desc(rt2x00dev, skb, control);
2015 beacon_base = HW_BEACON_OFFSET(intf->beacon->entry_idx); 2006 beacon_base = HW_BEACON_OFFSET(intf->beacon->entry_idx);
2016 timeout = REGISTER_TIMEOUT * (skb->len / sizeof(u32));
2017 rt2x00usb_vendor_request(rt2x00dev, USB_MULTI_WRITE, 2007 rt2x00usb_vendor_request(rt2x00dev, USB_MULTI_WRITE,
2018 USB_VENDOR_REQUEST_OUT, beacon_base, 0, 2008 USB_VENDOR_REQUEST_OUT, beacon_base, 0,
2019 skb->data, skb->len, timeout); 2009 skb->data, skb->len,
2020 rt73usb_kick_tx_queue(rt2x00dev, control->queue); 2010 REGISTER_TIMEOUT32(skb->len));
2011 rt73usb_kick_tx_queue(rt2x00dev, QID_BEACON);
2021 2012
2022 return 0; 2013 return 0;
2023} 2014}