3 * Linux device driver for ADMtek ADM8211 (IEEE 802.11b MAC/BBP)
5 * Copyright (c) 2003, Jouni Malinen <j@w1.fi>
6 * Copyright (c) 2004-2007, Michael Wu <flamingice@sourmilk.net>
7 * Some parts copyright (c) 2003 by David Young <dyoung@pobox.com>
8 * and used with permission.
10 * Much thanks to Infineon-ADMtek for their support of this driver.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation. See README and COPYING for
18 #include <linux/init.h>
20 #include <linux/skbuff.h>
21 #include <linux/etherdevice.h>
22 #include <linux/pci.h>
23 #include <linux/delay.h>
24 #include <linux/crc32.h>
25 #include <linux/eeprom_93cx6.h>
26 #include <net/mac80211.h>
30 MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>");
31 MODULE_AUTHOR("Jouni Malinen <j@w1.fi>");
32 MODULE_DESCRIPTION("Driver for IEEE 802.11b wireless cards based on ADMtek ADM8211");
33 MODULE_SUPPORTED_DEVICE("ADM8211");
34 MODULE_LICENSE("GPL");
36 static unsigned int tx_ring_size __read_mostly
= 16;
37 static unsigned int rx_ring_size __read_mostly
= 16;
39 module_param(tx_ring_size
, uint
, 0);
40 module_param(rx_ring_size
, uint
, 0);
42 static struct pci_device_id adm8211_pci_id_table
[] __devinitdata
= {
44 { PCI_DEVICE(0x10B7, 0x6000) }, /* 3Com 3CRSHPW796 */
45 { PCI_DEVICE(0x1200, 0x8201) }, /* ? */
46 { PCI_DEVICE(0x1317, 0x8201) }, /* ADM8211A */
47 { PCI_DEVICE(0x1317, 0x8211) }, /* ADM8211B/C */
51 static void adm8211_eeprom_register_read(struct eeprom_93cx6
*eeprom
)
53 struct adm8211_priv
*priv
= eeprom
->data
;
54 u32 reg
= ADM8211_CSR_READ(SPR
);
56 eeprom
->reg_data_in
= reg
& ADM8211_SPR_SDI
;
57 eeprom
->reg_data_out
= reg
& ADM8211_SPR_SDO
;
58 eeprom
->reg_data_clock
= reg
& ADM8211_SPR_SCLK
;
59 eeprom
->reg_chip_select
= reg
& ADM8211_SPR_SCS
;
62 static void adm8211_eeprom_register_write(struct eeprom_93cx6
*eeprom
)
64 struct adm8211_priv
*priv
= eeprom
->data
;
65 u32 reg
= 0x4000 | ADM8211_SPR_SRS
;
67 if (eeprom
->reg_data_in
)
68 reg
|= ADM8211_SPR_SDI
;
69 if (eeprom
->reg_data_out
)
70 reg
|= ADM8211_SPR_SDO
;
71 if (eeprom
->reg_data_clock
)
72 reg
|= ADM8211_SPR_SCLK
;
73 if (eeprom
->reg_chip_select
)
74 reg
|= ADM8211_SPR_SCS
;
76 ADM8211_CSR_WRITE(SPR
, reg
);
77 ADM8211_CSR_READ(SPR
); /* eeprom_delay */
80 static int adm8211_read_eeprom(struct ieee80211_hw
*dev
)
82 struct adm8211_priv
*priv
= dev
->priv
;
83 unsigned int words
, i
;
84 struct ieee80211_chan_range chan_range
;
86 struct eeprom_93cx6 eeprom
= {
88 .register_read
= adm8211_eeprom_register_read
,
89 .register_write
= adm8211_eeprom_register_write
92 if (ADM8211_CSR_READ(CSR_TEST0
) & ADM8211_CSR_TEST0_EPTYP
) {
93 /* 256 * 16-bit = 512 bytes */
94 eeprom
.width
= PCI_EEPROM_WIDTH_93C66
;
97 /* 64 * 16-bit = 128 bytes */
98 eeprom
.width
= PCI_EEPROM_WIDTH_93C46
;
102 priv
->eeprom_len
= words
* 2;
103 priv
->eeprom
= kmalloc(priv
->eeprom_len
, GFP_KERNEL
);
107 eeprom_93cx6_multiread(&eeprom
, 0, (__le16
*)priv
->eeprom
, words
);
109 cr49
= le16_to_cpu(priv
->eeprom
->cr49
);
110 priv
->rf_type
= (cr49
>> 3) & 0x7;
111 switch (priv
->rf_type
) {
112 case ADM8211_TYPE_INTERSIL
:
113 case ADM8211_TYPE_RFMD
:
114 case ADM8211_TYPE_MARVEL
:
115 case ADM8211_TYPE_AIROHA
:
116 case ADM8211_TYPE_ADMTEK
:
120 if (priv
->pdev
->revision
< ADM8211_REV_CA
)
121 priv
->rf_type
= ADM8211_TYPE_RFMD
;
123 priv
->rf_type
= ADM8211_TYPE_AIROHA
;
125 printk(KERN_WARNING
"%s (adm8211): Unknown RFtype %d\n",
126 pci_name(priv
->pdev
), (cr49
>> 3) & 0x7);
129 priv
->bbp_type
= cr49
& 0x7;
130 switch (priv
->bbp_type
) {
131 case ADM8211_TYPE_INTERSIL
:
132 case ADM8211_TYPE_RFMD
:
133 case ADM8211_TYPE_MARVEL
:
134 case ADM8211_TYPE_AIROHA
:
135 case ADM8211_TYPE_ADMTEK
:
138 if (priv
->pdev
->revision
< ADM8211_REV_CA
)
139 priv
->bbp_type
= ADM8211_TYPE_RFMD
;
141 priv
->bbp_type
= ADM8211_TYPE_ADMTEK
;
143 printk(KERN_WARNING
"%s (adm8211): Unknown BBPtype: %d\n",
144 pci_name(priv
->pdev
), cr49
>> 3);
147 if (priv
->eeprom
->country_code
>= ARRAY_SIZE(cranges
)) {
148 printk(KERN_WARNING
"%s (adm8211): Invalid country code (%d)\n",
149 pci_name(priv
->pdev
), priv
->eeprom
->country_code
);
151 chan_range
= cranges
[2];
153 chan_range
= cranges
[priv
->eeprom
->country_code
];
155 printk(KERN_DEBUG
"%s (adm8211): Channel range: %d - %d\n",
156 pci_name(priv
->pdev
), (int)chan_range
.min
, (int)chan_range
.max
);
158 priv
->modes
[0].num_channels
= chan_range
.max
- chan_range
.min
+ 1;
159 priv
->modes
[0].channels
= priv
->channels
;
161 memcpy(priv
->channels
, adm8211_channels
, sizeof(adm8211_channels
));
163 for (i
= 1; i
<= ARRAY_SIZE(adm8211_channels
); i
++)
164 if (i
>= chan_range
.min
&& i
<= chan_range
.max
)
165 priv
->channels
[i
- 1].flag
=
166 IEEE80211_CHAN_W_SCAN
|
167 IEEE80211_CHAN_W_ACTIVE_SCAN
|
168 IEEE80211_CHAN_W_IBSS
;
170 switch (priv
->eeprom
->specific_bbptype
) {
171 case ADM8211_BBP_RFMD3000
:
172 case ADM8211_BBP_RFMD3002
:
173 case ADM8211_BBP_ADM8011
:
174 priv
->specific_bbptype
= priv
->eeprom
->specific_bbptype
;
178 if (priv
->pdev
->revision
< ADM8211_REV_CA
)
179 priv
->specific_bbptype
= ADM8211_BBP_RFMD3000
;
181 priv
->specific_bbptype
= ADM8211_BBP_ADM8011
;
183 printk(KERN_WARNING
"%s (adm8211): Unknown specific BBP: %d\n",
184 pci_name(priv
->pdev
), priv
->eeprom
->specific_bbptype
);
187 switch (priv
->eeprom
->specific_rftype
) {
188 case ADM8211_RFMD2948
:
189 case ADM8211_RFMD2958
:
190 case ADM8211_RFMD2958_RF3000_CONTROL_POWER
:
191 case ADM8211_MAX2820
:
192 case ADM8211_AL2210L
:
193 priv
->transceiver_type
= priv
->eeprom
->specific_rftype
;
197 if (priv
->pdev
->revision
== ADM8211_REV_BA
)
198 priv
->transceiver_type
= ADM8211_RFMD2958_RF3000_CONTROL_POWER
;
199 else if (priv
->pdev
->revision
== ADM8211_REV_CA
)
200 priv
->transceiver_type
= ADM8211_AL2210L
;
201 else if (priv
->pdev
->revision
== ADM8211_REV_AB
)
202 priv
->transceiver_type
= ADM8211_RFMD2948
;
204 printk(KERN_WARNING
"%s (adm8211): Unknown transceiver: %d\n",
205 pci_name(priv
->pdev
), priv
->eeprom
->specific_rftype
);
210 printk(KERN_DEBUG
"%s (adm8211): RFtype=%d BBPtype=%d Specific BBP=%d "
211 "Transceiver=%d\n", pci_name(priv
->pdev
), priv
->rf_type
,
212 priv
->bbp_type
, priv
->specific_bbptype
, priv
->transceiver_type
);
217 static inline void adm8211_write_sram(struct ieee80211_hw
*dev
,
220 struct adm8211_priv
*priv
= dev
->priv
;
222 ADM8211_CSR_WRITE(WEPCTL
, addr
| ADM8211_WEPCTL_TABLE_WR
|
223 (priv
->pdev
->revision
< ADM8211_REV_BA
?
224 0 : ADM8211_WEPCTL_SEL_WEPTABLE
));
225 ADM8211_CSR_READ(WEPCTL
);
228 ADM8211_CSR_WRITE(WESK
, data
);
229 ADM8211_CSR_READ(WESK
);
233 static void adm8211_write_sram_bytes(struct ieee80211_hw
*dev
,
234 unsigned int addr
, u8
*buf
,
237 struct adm8211_priv
*priv
= dev
->priv
;
238 u32 reg
= ADM8211_CSR_READ(WEPCTL
);
241 if (priv
->pdev
->revision
< ADM8211_REV_BA
) {
242 for (i
= 0; i
< len
; i
+= 2) {
243 u16 val
= buf
[i
] | (buf
[i
+ 1] << 8);
244 adm8211_write_sram(dev
, addr
+ i
/ 2, val
);
247 for (i
= 0; i
< len
; i
+= 4) {
248 u32 val
= (buf
[i
+ 0] << 0 ) | (buf
[i
+ 1] << 8 ) |
249 (buf
[i
+ 2] << 16) | (buf
[i
+ 3] << 24);
250 adm8211_write_sram(dev
, addr
+ i
/ 4, val
);
254 ADM8211_CSR_WRITE(WEPCTL
, reg
);
257 static void adm8211_clear_sram(struct ieee80211_hw
*dev
)
259 struct adm8211_priv
*priv
= dev
->priv
;
260 u32 reg
= ADM8211_CSR_READ(WEPCTL
);
263 for (addr
= 0; addr
< ADM8211_SRAM_SIZE
; addr
++)
264 adm8211_write_sram(dev
, addr
, 0);
266 ADM8211_CSR_WRITE(WEPCTL
, reg
);
269 static int adm8211_get_stats(struct ieee80211_hw
*dev
,
270 struct ieee80211_low_level_stats
*stats
)
272 struct adm8211_priv
*priv
= dev
->priv
;
274 memcpy(stats
, &priv
->stats
, sizeof(*stats
));
279 static int adm8211_get_tx_stats(struct ieee80211_hw
*dev
,
280 struct ieee80211_tx_queue_stats
*stats
)
282 struct adm8211_priv
*priv
= dev
->priv
;
283 struct ieee80211_tx_queue_stats_data
*data
= &stats
->data
[0];
285 data
->len
= priv
->cur_tx
- priv
->dirty_tx
;
286 data
->limit
= priv
->tx_ring_size
- 2;
287 data
->count
= priv
->dirty_tx
;
292 static void adm8211_interrupt_tci(struct ieee80211_hw
*dev
)
294 struct adm8211_priv
*priv
= dev
->priv
;
295 unsigned int dirty_tx
;
297 spin_lock(&priv
->lock
);
299 for (dirty_tx
= priv
->dirty_tx
; priv
->cur_tx
- dirty_tx
; dirty_tx
++) {
300 unsigned int entry
= dirty_tx
% priv
->tx_ring_size
;
301 u32 status
= le32_to_cpu(priv
->tx_ring
[entry
].status
);
302 struct ieee80211_tx_status tx_status
;
303 struct adm8211_tx_ring_info
*info
;
306 if (status
& TDES0_CONTROL_OWN
||
307 !(status
& TDES0_CONTROL_DONE
))
310 info
= &priv
->tx_buffers
[entry
];
313 /* TODO: check TDES0_STATUS_TUF and TDES0_STATUS_TRO */
315 pci_unmap_single(priv
->pdev
, info
->mapping
,
316 info
->skb
->len
, PCI_DMA_TODEVICE
);
318 memset(&tx_status
, 0, sizeof(tx_status
));
319 skb_pull(skb
, sizeof(struct adm8211_tx_hdr
));
320 memcpy(skb_push(skb
, info
->hdrlen
), skb
->cb
, info
->hdrlen
);
321 memcpy(&tx_status
.control
, &info
->tx_control
,
322 sizeof(tx_status
.control
));
323 if (!(tx_status
.control
.flags
& IEEE80211_TXCTL_NO_ACK
)) {
324 if (status
& TDES0_STATUS_ES
)
325 tx_status
.excessive_retries
= 1;
327 tx_status
.flags
|= IEEE80211_TX_STATUS_ACK
;
329 ieee80211_tx_status_irqsafe(dev
, skb
, &tx_status
);
334 if (priv
->cur_tx
- dirty_tx
< priv
->tx_ring_size
- 2)
335 ieee80211_wake_queue(dev
, 0);
337 priv
->dirty_tx
= dirty_tx
;
338 spin_unlock(&priv
->lock
);
342 static void adm8211_interrupt_rci(struct ieee80211_hw
*dev
)
344 struct adm8211_priv
*priv
= dev
->priv
;
345 unsigned int entry
= priv
->cur_rx
% priv
->rx_ring_size
;
348 struct sk_buff
*skb
, *newskb
;
349 unsigned int limit
= priv
->rx_ring_size
;
350 static const u8 rate_tbl
[] = {10, 20, 55, 110, 220};
353 while (!(priv
->rx_ring
[entry
].status
& cpu_to_le32(RDES0_STATUS_OWN
))) {
357 status
= le32_to_cpu(priv
->rx_ring
[entry
].status
);
358 rate
= (status
& RDES0_STATUS_RXDR
) >> 12;
359 rssi
= le32_to_cpu(priv
->rx_ring
[entry
].length
) &
362 pktlen
= status
& RDES0_STATUS_FL
;
363 if (pktlen
> RX_PKT_SIZE
) {
365 printk(KERN_DEBUG
"%s: frame too long (%d)\n",
366 wiphy_name(dev
->wiphy
), pktlen
);
367 pktlen
= RX_PKT_SIZE
;
370 if (!priv
->soft_rx_crc
&& status
& RDES0_STATUS_ES
) {
371 skb
= NULL
; /* old buffer will be reused */
372 /* TODO: update RX error stats */
373 /* TODO: check RDES0_STATUS_CRC*E */
374 } else if (pktlen
< RX_COPY_BREAK
) {
375 skb
= dev_alloc_skb(pktlen
);
377 pci_dma_sync_single_for_cpu(
379 priv
->rx_buffers
[entry
].mapping
,
380 pktlen
, PCI_DMA_FROMDEVICE
);
381 memcpy(skb_put(skb
, pktlen
),
382 skb_tail_pointer(priv
->rx_buffers
[entry
].skb
),
384 pci_dma_sync_single_for_device(
386 priv
->rx_buffers
[entry
].mapping
,
387 RX_PKT_SIZE
, PCI_DMA_FROMDEVICE
);
390 newskb
= dev_alloc_skb(RX_PKT_SIZE
);
392 skb
= priv
->rx_buffers
[entry
].skb
;
393 skb_put(skb
, pktlen
);
396 priv
->rx_buffers
[entry
].mapping
,
397 RX_PKT_SIZE
, PCI_DMA_FROMDEVICE
);
398 priv
->rx_buffers
[entry
].skb
= newskb
;
399 priv
->rx_buffers
[entry
].mapping
=
400 pci_map_single(priv
->pdev
,
401 skb_tail_pointer(newskb
),
406 /* TODO: update rx dropped stats */
409 priv
->rx_ring
[entry
].buffer1
=
410 cpu_to_le32(priv
->rx_buffers
[entry
].mapping
);
413 priv
->rx_ring
[entry
].status
= cpu_to_le32(RDES0_STATUS_OWN
|
415 priv
->rx_ring
[entry
].length
=
416 cpu_to_le32(RX_PKT_SIZE
|
417 (entry
== priv
->rx_ring_size
- 1 ?
418 RDES1_CONTROL_RER
: 0));
421 struct ieee80211_rx_status rx_status
= {0};
423 if (priv
->pdev
->revision
< ADM8211_REV_CA
)
424 rx_status
.ssi
= rssi
;
426 rx_status
.ssi
= 100 - rssi
;
429 rx_status
.rate
= rate_tbl
[rate
];
431 rx_status
.channel
= priv
->channel
;
432 rx_status
.freq
= adm8211_channels
[priv
->channel
- 1].freq
;
433 rx_status
.phymode
= MODE_IEEE80211B
;
435 ieee80211_rx_irqsafe(dev
, skb
, &rx_status
);
438 entry
= (++priv
->cur_rx
) % priv
->rx_ring_size
;
441 /* TODO: check LPC and update stats? */
445 static irqreturn_t
adm8211_interrupt(int irq
, void *dev_id
)
447 #define ADM8211_INT(x) \
449 if (unlikely(stsr & ADM8211_STSR_ ## x)) \
450 printk(KERN_DEBUG "%s: " #x "\n", wiphy_name(dev->wiphy)); \
453 struct ieee80211_hw
*dev
= dev_id
;
454 struct adm8211_priv
*priv
= dev
->priv
;
455 u32 stsr
= ADM8211_CSR_READ(STSR
);
456 ADM8211_CSR_WRITE(STSR
, stsr
);
457 if (stsr
== 0xffffffff)
460 if (!(stsr
& (ADM8211_STSR_NISS
| ADM8211_STSR_AISS
)))
463 if (stsr
& ADM8211_STSR_RCI
)
464 adm8211_interrupt_rci(dev
);
465 if (stsr
& ADM8211_STSR_TCI
)
466 adm8211_interrupt_tci(dev
);
468 /*ADM8211_INT(LinkOn);*/
469 /*ADM8211_INT(LinkOff);*/
480 /*ADM8211_INT(TBTT);*/
488 /*ADM8211_INT(TRT);*/
489 /*ADM8211_INT(TLT);*/
490 /*ADM8211_INT(TDU);*/
498 #define WRITE_SYN(name,v_mask,v_shift,a_mask,a_shift,bits,prewrite,postwrite)\
499 static void adm8211_rf_write_syn_ ## name (struct ieee80211_hw *dev, \
500 u16 addr, u32 value) { \
501 struct adm8211_priv *priv = dev->priv; \
507 bitbuf = (value << v_shift) | (addr << a_shift); \
509 ADM8211_CSR_WRITE(SYNRF, ADM8211_SYNRF_IF_SELECT_1); \
510 ADM8211_CSR_READ(SYNRF); \
511 ADM8211_CSR_WRITE(SYNRF, ADM8211_SYNRF_IF_SELECT_0); \
512 ADM8211_CSR_READ(SYNRF); \
515 ADM8211_CSR_WRITE(SYNRF, ADM8211_SYNRF_WRITE_SYNDATA_0); \
516 ADM8211_CSR_READ(SYNRF); \
519 for (i = 0; i <= bits; i++) { \
520 if (bitbuf & (1 << (bits - i))) \
521 reg = ADM8211_SYNRF_WRITE_SYNDATA_1; \
523 reg = ADM8211_SYNRF_WRITE_SYNDATA_0; \
525 ADM8211_CSR_WRITE(SYNRF, reg); \
526 ADM8211_CSR_READ(SYNRF); \
528 ADM8211_CSR_WRITE(SYNRF, reg | ADM8211_SYNRF_WRITE_CLOCK_1); \
529 ADM8211_CSR_READ(SYNRF); \
530 ADM8211_CSR_WRITE(SYNRF, reg | ADM8211_SYNRF_WRITE_CLOCK_0); \
531 ADM8211_CSR_READ(SYNRF); \
534 if (postwrite == 1) { \
535 ADM8211_CSR_WRITE(SYNRF, reg | ADM8211_SYNRF_IF_SELECT_0); \
536 ADM8211_CSR_READ(SYNRF); \
538 if (postwrite == 2) { \
539 ADM8211_CSR_WRITE(SYNRF, reg | ADM8211_SYNRF_IF_SELECT_1); \
540 ADM8211_CSR_READ(SYNRF); \
543 ADM8211_CSR_WRITE(SYNRF, 0); \
544 ADM8211_CSR_READ(SYNRF); \
547 WRITE_SYN(max2820
, 0x00FFF, 0, 0x0F, 12, 15, 1, 1)
548 WRITE_SYN(al2210l
, 0xFFFFF, 4, 0x0F, 0, 23, 1, 1)
549 WRITE_SYN(rfmd2958
, 0x3FFFF, 0, 0x1F, 18, 23, 0, 1)
550 WRITE_SYN(rfmd2948
, 0x0FFFF, 4, 0x0F, 0, 21, 0, 2)
554 static int adm8211_write_bbp(struct ieee80211_hw
*dev
, u8 addr
, u8 data
)
556 struct adm8211_priv
*priv
= dev
->priv
;
557 unsigned int timeout
;
561 while (timeout
> 0) {
562 reg
= ADM8211_CSR_READ(BBPCTL
);
563 if (!(reg
& (ADM8211_BBPCTL_WR
| ADM8211_BBPCTL_RD
)))
570 printk(KERN_DEBUG
"%s: adm8211_write_bbp(%d,%d) failed"
571 " prewrite (reg=0x%08x)\n",
572 wiphy_name(dev
->wiphy
), addr
, data
, reg
);
576 switch (priv
->bbp_type
) {
577 case ADM8211_TYPE_INTERSIL
:
578 reg
= ADM8211_BBPCTL_MMISEL
; /* three wire interface */
580 case ADM8211_TYPE_RFMD
:
581 reg
= (0x20 << 24) | ADM8211_BBPCTL_TXCE
| ADM8211_BBPCTL_CCAP
|
584 case ADM8211_TYPE_ADMTEK
:
585 reg
= (0x20 << 24) | ADM8211_BBPCTL_TXCE
| ADM8211_BBPCTL_CCAP
|
589 reg
|= ADM8211_BBPCTL_WR
| (addr
<< 8) | data
;
591 ADM8211_CSR_WRITE(BBPCTL
, reg
);
594 while (timeout
> 0) {
595 reg
= ADM8211_CSR_READ(BBPCTL
);
596 if (!(reg
& ADM8211_BBPCTL_WR
))
603 ADM8211_CSR_WRITE(BBPCTL
, ADM8211_CSR_READ(BBPCTL
) &
605 printk(KERN_DEBUG
"%s: adm8211_write_bbp(%d,%d) failed"
606 " postwrite (reg=0x%08x)\n",
607 wiphy_name(dev
->wiphy
), addr
, data
, reg
);
614 static int adm8211_rf_set_channel(struct ieee80211_hw
*dev
, unsigned int chan
)
616 static const u32 adm8211_rfmd2958_reg5
[] =
617 {0x22BD, 0x22D2, 0x22E8, 0x22FE, 0x2314, 0x232A, 0x2340,
618 0x2355, 0x236B, 0x2381, 0x2397, 0x23AD, 0x23C2, 0x23F7};
619 static const u32 adm8211_rfmd2958_reg6
[] =
620 {0x05D17, 0x3A2E8, 0x2E8BA, 0x22E8B, 0x1745D, 0x0BA2E, 0x00000,
621 0x345D1, 0x28BA2, 0x1D174, 0x11745, 0x05D17, 0x3A2E8, 0x11745};
623 struct adm8211_priv
*priv
= dev
->priv
;
624 u8 ant_power
= priv
->ant_power
> 0x3F ?
625 priv
->eeprom
->antenna_power
[chan
- 1] : priv
->ant_power
;
626 u8 tx_power
= priv
->tx_power
> 0x3F ?
627 priv
->eeprom
->tx_power
[chan
- 1] : priv
->tx_power
;
628 u8 lpf_cutoff
= priv
->lpf_cutoff
== 0xFF ?
629 priv
->eeprom
->lpf_cutoff
[chan
- 1] : priv
->lpf_cutoff
;
630 u8 lnags_thresh
= priv
->lnags_threshold
== 0xFF ?
631 priv
->eeprom
->lnags_threshold
[chan
- 1] : priv
->lnags_threshold
;
636 /* Program synthesizer to new channel */
637 switch (priv
->transceiver_type
) {
638 case ADM8211_RFMD2958
:
639 case ADM8211_RFMD2958_RF3000_CONTROL_POWER
:
640 adm8211_rf_write_syn_rfmd2958(dev
, 0x00, 0x04007);
641 adm8211_rf_write_syn_rfmd2958(dev
, 0x02, 0x00033);
643 adm8211_rf_write_syn_rfmd2958(dev
, 0x05,
644 adm8211_rfmd2958_reg5
[chan
- 1]);
645 adm8211_rf_write_syn_rfmd2958(dev
, 0x06,
646 adm8211_rfmd2958_reg6
[chan
- 1]);
649 case ADM8211_RFMD2948
:
650 adm8211_rf_write_syn_rfmd2948(dev
, SI4126_MAIN_CONF
,
651 SI4126_MAIN_XINDIV2
);
652 adm8211_rf_write_syn_rfmd2948(dev
, SI4126_POWERDOWN
,
653 SI4126_POWERDOWN_PDIB
|
654 SI4126_POWERDOWN_PDRB
);
655 adm8211_rf_write_syn_rfmd2948(dev
, SI4126_PHASE_DET_GAIN
, 0);
656 adm8211_rf_write_syn_rfmd2948(dev
, SI4126_RF2_N_DIV
,
658 2110 : (2033 + (chan
* 5))));
659 adm8211_rf_write_syn_rfmd2948(dev
, SI4126_IF_N_DIV
, 1496);
660 adm8211_rf_write_syn_rfmd2948(dev
, SI4126_RF2_R_DIV
, 44);
661 adm8211_rf_write_syn_rfmd2948(dev
, SI4126_IF_R_DIV
, 44);
664 case ADM8211_MAX2820
:
665 adm8211_rf_write_syn_max2820(dev
, 0x3,
666 (chan
== 14 ? 0x054 : (0x7 + (chan
* 5))));
669 case ADM8211_AL2210L
:
670 adm8211_rf_write_syn_al2210l(dev
, 0x0,
671 (chan
== 14 ? 0x229B4 : (0x22967 + (chan
* 5))));
675 printk(KERN_DEBUG
"%s: unsupported transceiver type %d\n",
676 wiphy_name(dev
->wiphy
), priv
->transceiver_type
);
681 if (priv
->bbp_type
== ADM8211_TYPE_RFMD
) {
683 /* SMC 2635W specific? adm8211b doesn't use the 2948 though.. */
684 /* TODO: remove if SMC 2635W doesn't need this */
685 if (priv
->transceiver_type
== ADM8211_RFMD2948
) {
686 reg
= ADM8211_CSR_READ(GPIO
);
688 reg
|= ADM8211_CSR_GPIO_EN0
;
690 reg
|= ADM8211_CSR_GPIO_O0
;
691 ADM8211_CSR_WRITE(GPIO
, reg
);
694 if (priv
->transceiver_type
== ADM8211_RFMD2958
) {
696 adm8211_rf_write_syn_rfmd2958(dev
, 0x0B, 0x07100);
697 /* set PCNT1 P_DESIRED/MID_BIAS */
698 reg
= le16_to_cpu(priv
->eeprom
->cr49
);
701 reg
|= ant_power
<< 9;
702 adm8211_rf_write_syn_rfmd2958(dev
, 0x0A, reg
);
703 /* set TXRX TX_GAIN */
704 adm8211_rf_write_syn_rfmd2958(dev
, 0x09, 0x00050 |
705 (priv
->pdev
->revision
< ADM8211_REV_CA
? tx_power
: 0));
707 reg
= ADM8211_CSR_READ(PLCPHD
);
709 reg
|= tx_power
<< 18;
710 ADM8211_CSR_WRITE(PLCPHD
, reg
);
713 ADM8211_CSR_WRITE(SYNRF
, ADM8211_SYNRF_SELRF
|
714 ADM8211_SYNRF_PE1
| ADM8211_SYNRF_PHYRST
);
715 ADM8211_CSR_READ(SYNRF
);
719 if (priv
->transceiver_type
!= ADM8211_RFMD2958
)
720 adm8211_write_bbp(dev
, RF3000_TX_VAR_GAIN__TX_LEN_EXT
,
722 adm8211_write_bbp(dev
, RF3000_LOW_GAIN_CALIB
, lpf_cutoff
);
723 adm8211_write_bbp(dev
, RF3000_HIGH_GAIN_CALIB
, lnags_thresh
);
724 adm8211_write_bbp(dev
, 0x1c, priv
->pdev
->revision
== ADM8211_REV_BA
?
725 priv
->eeprom
->cr28
: 0);
726 adm8211_write_bbp(dev
, 0x1d, priv
->eeprom
->cr29
);
728 ADM8211_CSR_WRITE(SYNRF
, 0);
730 /* Nothing to do for ADMtek BBP */
731 } else if (priv
->bbp_type
!= ADM8211_TYPE_ADMTEK
)
732 printk(KERN_DEBUG
"%s: unsupported BBP type %d\n",
733 wiphy_name(dev
->wiphy
), priv
->bbp_type
);
737 /* update current channel for adhoc (and maybe AP mode) */
738 reg
= ADM8211_CSR_READ(CAP0
);
741 ADM8211_CSR_WRITE(CAP0
, reg
);
746 static void adm8211_update_mode(struct ieee80211_hw
*dev
)
748 struct adm8211_priv
*priv
= dev
->priv
;
752 priv
->soft_rx_crc
= 0;
753 switch (priv
->mode
) {
754 case IEEE80211_IF_TYPE_STA
:
755 priv
->nar
&= ~(ADM8211_NAR_PR
| ADM8211_NAR_EA
);
756 priv
->nar
|= ADM8211_NAR_ST
| ADM8211_NAR_SR
;
758 case IEEE80211_IF_TYPE_IBSS
:
759 priv
->nar
&= ~ADM8211_NAR_PR
;
760 priv
->nar
|= ADM8211_NAR_EA
| ADM8211_NAR_ST
| ADM8211_NAR_SR
;
762 /* don't trust the error bits on rev 0x20 and up in adhoc */
763 if (priv
->pdev
->revision
>= ADM8211_REV_BA
)
764 priv
->soft_rx_crc
= 1;
766 case IEEE80211_IF_TYPE_MNTR
:
767 priv
->nar
&= ~(ADM8211_NAR_EA
| ADM8211_NAR_ST
);
768 priv
->nar
|= ADM8211_NAR_PR
| ADM8211_NAR_SR
;
775 static void adm8211_hw_init_syn(struct ieee80211_hw
*dev
)
777 struct adm8211_priv
*priv
= dev
->priv
;
779 switch (priv
->transceiver_type
) {
780 case ADM8211_RFMD2958
:
781 case ADM8211_RFMD2958_RF3000_CONTROL_POWER
:
782 /* comments taken from ADMtek vendor driver */
784 /* Reset RF2958 after power on */
785 adm8211_rf_write_syn_rfmd2958(dev
, 0x1F, 0x00000);
786 /* Initialize RF VCO Core Bias to maximum */
787 adm8211_rf_write_syn_rfmd2958(dev
, 0x0C, 0x3001F);
788 /* Initialize IF PLL */
789 adm8211_rf_write_syn_rfmd2958(dev
, 0x01, 0x29C03);
790 /* Initialize IF PLL Coarse Tuning */
791 adm8211_rf_write_syn_rfmd2958(dev
, 0x03, 0x1FF6F);
792 /* Initialize RF PLL */
793 adm8211_rf_write_syn_rfmd2958(dev
, 0x04, 0x29403);
794 /* Initialize RF PLL Coarse Tuning */
795 adm8211_rf_write_syn_rfmd2958(dev
, 0x07, 0x1456F);
796 /* Initialize TX gain and filter BW (R9) */
797 adm8211_rf_write_syn_rfmd2958(dev
, 0x09,
798 (priv
->transceiver_type
== ADM8211_RFMD2958
?
800 /* Initialize CAL register */
801 adm8211_rf_write_syn_rfmd2958(dev
, 0x08, 0x3FFF8);
804 case ADM8211_MAX2820
:
805 adm8211_rf_write_syn_max2820(dev
, 0x1, 0x01E);
806 adm8211_rf_write_syn_max2820(dev
, 0x2, 0x001);
807 adm8211_rf_write_syn_max2820(dev
, 0x3, 0x054);
808 adm8211_rf_write_syn_max2820(dev
, 0x4, 0x310);
809 adm8211_rf_write_syn_max2820(dev
, 0x5, 0x000);
812 case ADM8211_AL2210L
:
813 adm8211_rf_write_syn_al2210l(dev
, 0x0, 0x0196C);
814 adm8211_rf_write_syn_al2210l(dev
, 0x1, 0x007CB);
815 adm8211_rf_write_syn_al2210l(dev
, 0x2, 0x3582F);
816 adm8211_rf_write_syn_al2210l(dev
, 0x3, 0x010A9);
817 adm8211_rf_write_syn_al2210l(dev
, 0x4, 0x77280);
818 adm8211_rf_write_syn_al2210l(dev
, 0x5, 0x45641);
819 adm8211_rf_write_syn_al2210l(dev
, 0x6, 0xEA130);
820 adm8211_rf_write_syn_al2210l(dev
, 0x7, 0x80000);
821 adm8211_rf_write_syn_al2210l(dev
, 0x8, 0x7850F);
822 adm8211_rf_write_syn_al2210l(dev
, 0x9, 0xF900C);
823 adm8211_rf_write_syn_al2210l(dev
, 0xA, 0x00000);
824 adm8211_rf_write_syn_al2210l(dev
, 0xB, 0x00000);
827 case ADM8211_RFMD2948
:
833 static int adm8211_hw_init_bbp(struct ieee80211_hw
*dev
)
835 struct adm8211_priv
*priv
= dev
->priv
;
838 /* write addresses */
839 if (priv
->bbp_type
== ADM8211_TYPE_INTERSIL
) {
840 ADM8211_CSR_WRITE(MMIWA
, 0x100E0C0A);
841 ADM8211_CSR_WRITE(MMIRD0
, 0x00007C7E);
842 ADM8211_CSR_WRITE(MMIRD1
, 0x00100000);
843 } else if (priv
->bbp_type
== ADM8211_TYPE_RFMD
||
844 priv
->bbp_type
== ADM8211_TYPE_ADMTEK
) {
845 /* check specific BBP type */
846 switch (priv
->specific_bbptype
) {
847 case ADM8211_BBP_RFMD3000
:
848 case ADM8211_BBP_RFMD3002
:
849 ADM8211_CSR_WRITE(MMIWA
, 0x00009101);
850 ADM8211_CSR_WRITE(MMIRD0
, 0x00000301);
853 case ADM8211_BBP_ADM8011
:
854 ADM8211_CSR_WRITE(MMIWA
, 0x00008903);
855 ADM8211_CSR_WRITE(MMIRD0
, 0x00001716);
857 reg
= ADM8211_CSR_READ(BBPCTL
);
858 reg
&= ~ADM8211_BBPCTL_TYPE
;
860 ADM8211_CSR_WRITE(BBPCTL
, reg
);
864 switch (priv
->pdev
->revision
) {
866 if (priv
->transceiver_type
== ADM8211_RFMD2958
||
867 priv
->transceiver_type
== ADM8211_RFMD2958_RF3000_CONTROL_POWER
||
868 priv
->transceiver_type
== ADM8211_RFMD2948
)
869 ADM8211_CSR_WRITE(SYNCTL
, 0x1 << 22);
870 else if (priv
->transceiver_type
== ADM8211_MAX2820
||
871 priv
->transceiver_type
== ADM8211_AL2210L
)
872 ADM8211_CSR_WRITE(SYNCTL
, 0x3 << 22);
876 reg
= ADM8211_CSR_READ(MMIRD1
);
879 ADM8211_CSR_WRITE(MMIRD1
, reg
);
885 ADM8211_CSR_WRITE(MMIRD1
, 0x7e100000);
890 ADM8211_CSR_WRITE(MACTEST
, 0x800);
893 adm8211_hw_init_syn(dev
);
895 /* Set RF Power control IF pin to PE1+PHYRST# */
896 ADM8211_CSR_WRITE(SYNRF
, ADM8211_SYNRF_SELRF
|
897 ADM8211_SYNRF_PE1
| ADM8211_SYNRF_PHYRST
);
898 ADM8211_CSR_READ(SYNRF
);
902 if (priv
->bbp_type
== ADM8211_TYPE_RFMD
) {
907 * 15: 50 (chan 1..13; chan 14: d0)
911 adm8211_write_bbp(dev
, RF3000_CCA_CTRL
, 0x80);
912 /* antenna selection: diversity */
913 adm8211_write_bbp(dev
, RF3000_DIVERSITY__RSSI
, 0x80);
914 adm8211_write_bbp(dev
, RF3000_TX_VAR_GAIN__TX_LEN_EXT
, 0x74);
915 adm8211_write_bbp(dev
, RF3000_LOW_GAIN_CALIB
, 0x38);
916 adm8211_write_bbp(dev
, RF3000_HIGH_GAIN_CALIB
, 0x40);
918 if (priv
->eeprom
->major_version
< 2) {
919 adm8211_write_bbp(dev
, 0x1c, 0x00);
920 adm8211_write_bbp(dev
, 0x1d, 0x80);
922 if (priv
->pdev
->revision
== ADM8211_REV_BA
)
923 adm8211_write_bbp(dev
, 0x1c, priv
->eeprom
->cr28
);
925 adm8211_write_bbp(dev
, 0x1c, 0x00);
927 adm8211_write_bbp(dev
, 0x1d, priv
->eeprom
->cr29
);
929 } else if (priv
->bbp_type
== ADM8211_TYPE_ADMTEK
) {
931 adm8211_write_bbp(dev
, 0x00, 0xFF);
932 /* antenna selection: diversity */
933 adm8211_write_bbp(dev
, 0x07, 0x0A);
935 /* TODO: find documentation for this */
936 switch (priv
->transceiver_type
) {
937 case ADM8211_RFMD2958
:
938 case ADM8211_RFMD2958_RF3000_CONTROL_POWER
:
939 adm8211_write_bbp(dev
, 0x00, 0x00);
940 adm8211_write_bbp(dev
, 0x01, 0x00);
941 adm8211_write_bbp(dev
, 0x02, 0x00);
942 adm8211_write_bbp(dev
, 0x03, 0x00);
943 adm8211_write_bbp(dev
, 0x06, 0x0f);
944 adm8211_write_bbp(dev
, 0x09, 0x00);
945 adm8211_write_bbp(dev
, 0x0a, 0x00);
946 adm8211_write_bbp(dev
, 0x0b, 0x00);
947 adm8211_write_bbp(dev
, 0x0c, 0x00);
948 adm8211_write_bbp(dev
, 0x0f, 0xAA);
949 adm8211_write_bbp(dev
, 0x10, 0x8c);
950 adm8211_write_bbp(dev
, 0x11, 0x43);
951 adm8211_write_bbp(dev
, 0x18, 0x40);
952 adm8211_write_bbp(dev
, 0x20, 0x23);
953 adm8211_write_bbp(dev
, 0x21, 0x02);
954 adm8211_write_bbp(dev
, 0x22, 0x28);
955 adm8211_write_bbp(dev
, 0x23, 0x30);
956 adm8211_write_bbp(dev
, 0x24, 0x2d);
957 adm8211_write_bbp(dev
, 0x28, 0x35);
958 adm8211_write_bbp(dev
, 0x2a, 0x8c);
959 adm8211_write_bbp(dev
, 0x2b, 0x81);
960 adm8211_write_bbp(dev
, 0x2c, 0x44);
961 adm8211_write_bbp(dev
, 0x2d, 0x0A);
962 adm8211_write_bbp(dev
, 0x29, 0x40);
963 adm8211_write_bbp(dev
, 0x60, 0x08);
964 adm8211_write_bbp(dev
, 0x64, 0x01);
967 case ADM8211_MAX2820
:
968 adm8211_write_bbp(dev
, 0x00, 0x00);
969 adm8211_write_bbp(dev
, 0x01, 0x00);
970 adm8211_write_bbp(dev
, 0x02, 0x00);
971 adm8211_write_bbp(dev
, 0x03, 0x00);
972 adm8211_write_bbp(dev
, 0x06, 0x0f);
973 adm8211_write_bbp(dev
, 0x09, 0x05);
974 adm8211_write_bbp(dev
, 0x0a, 0x02);
975 adm8211_write_bbp(dev
, 0x0b, 0x00);
976 adm8211_write_bbp(dev
, 0x0c, 0x0f);
977 adm8211_write_bbp(dev
, 0x0f, 0x55);
978 adm8211_write_bbp(dev
, 0x10, 0x8d);
979 adm8211_write_bbp(dev
, 0x11, 0x43);
980 adm8211_write_bbp(dev
, 0x18, 0x4a);
981 adm8211_write_bbp(dev
, 0x20, 0x20);
982 adm8211_write_bbp(dev
, 0x21, 0x02);
983 adm8211_write_bbp(dev
, 0x22, 0x23);
984 adm8211_write_bbp(dev
, 0x23, 0x30);
985 adm8211_write_bbp(dev
, 0x24, 0x2d);
986 adm8211_write_bbp(dev
, 0x2a, 0x8c);
987 adm8211_write_bbp(dev
, 0x2b, 0x81);
988 adm8211_write_bbp(dev
, 0x2c, 0x44);
989 adm8211_write_bbp(dev
, 0x29, 0x4a);
990 adm8211_write_bbp(dev
, 0x60, 0x2b);
991 adm8211_write_bbp(dev
, 0x64, 0x01);
994 case ADM8211_AL2210L
:
995 adm8211_write_bbp(dev
, 0x00, 0x00);
996 adm8211_write_bbp(dev
, 0x01, 0x00);
997 adm8211_write_bbp(dev
, 0x02, 0x00);
998 adm8211_write_bbp(dev
, 0x03, 0x00);
999 adm8211_write_bbp(dev
, 0x06, 0x0f);
1000 adm8211_write_bbp(dev
, 0x07, 0x05);
1001 adm8211_write_bbp(dev
, 0x08, 0x03);
1002 adm8211_write_bbp(dev
, 0x09, 0x00);
1003 adm8211_write_bbp(dev
, 0x0a, 0x00);
1004 adm8211_write_bbp(dev
, 0x0b, 0x00);
1005 adm8211_write_bbp(dev
, 0x0c, 0x10);
1006 adm8211_write_bbp(dev
, 0x0f, 0x55);
1007 adm8211_write_bbp(dev
, 0x10, 0x8d);
1008 adm8211_write_bbp(dev
, 0x11, 0x43);
1009 adm8211_write_bbp(dev
, 0x18, 0x4a);
1010 adm8211_write_bbp(dev
, 0x20, 0x20);
1011 adm8211_write_bbp(dev
, 0x21, 0x02);
1012 adm8211_write_bbp(dev
, 0x22, 0x23);
1013 adm8211_write_bbp(dev
, 0x23, 0x30);
1014 adm8211_write_bbp(dev
, 0x24, 0x2d);
1015 adm8211_write_bbp(dev
, 0x2a, 0xaa);
1016 adm8211_write_bbp(dev
, 0x2b, 0x81);
1017 adm8211_write_bbp(dev
, 0x2c, 0x44);
1018 adm8211_write_bbp(dev
, 0x29, 0xfa);
1019 adm8211_write_bbp(dev
, 0x60, 0x2d);
1020 adm8211_write_bbp(dev
, 0x64, 0x01);
1023 case ADM8211_RFMD2948
:
1027 printk(KERN_DEBUG
"%s: unsupported transceiver %d\n",
1028 wiphy_name(dev
->wiphy
), priv
->transceiver_type
);
1032 printk(KERN_DEBUG
"%s: unsupported BBP %d\n",
1033 wiphy_name(dev
->wiphy
), priv
->bbp_type
);
1035 ADM8211_CSR_WRITE(SYNRF
, 0);
1037 /* Set RF CAL control source to MAC control */
1038 reg
= ADM8211_CSR_READ(SYNCTL
);
1039 reg
|= ADM8211_SYNCTL_SELCAL
;
1040 ADM8211_CSR_WRITE(SYNCTL
, reg
);
1045 /* configures hw beacons/probe responses */
1046 static int adm8211_set_rate(struct ieee80211_hw
*dev
)
1048 struct adm8211_priv
*priv
= dev
->priv
;
1051 u8 rate_buf
[12] = {0};
1053 /* write supported rates */
1054 if (priv
->pdev
->revision
!= ADM8211_REV_BA
) {
1055 rate_buf
[0] = ARRAY_SIZE(adm8211_rates
);
1056 for (i
= 0; i
< ARRAY_SIZE(adm8211_rates
); i
++)
1057 rate_buf
[i
+ 1] = (adm8211_rates
[i
].rate
/ 5) | 0x80;
1059 /* workaround for rev BA specific bug */
1067 adm8211_write_sram_bytes(dev
, ADM8211_SRAM_SUPP_RATE
, rate_buf
,
1068 ARRAY_SIZE(adm8211_rates
) + 1);
1070 reg
= ADM8211_CSR_READ(PLCPHD
) & 0x00FFFFFF; /* keep bits 0-23 */
1071 reg
|= 1 << 15; /* short preamble */
1073 ADM8211_CSR_WRITE(PLCPHD
, reg
);
1075 /* MTMLT = 512 TU (max TX MSDU lifetime)
1076 * BCNTSIG = plcp_signal (beacon, probe resp, and atim TX rate)
1077 * SRTYLIM = 224 (short retry limit, TX header value is default) */
1078 ADM8211_CSR_WRITE(TXLMT
, (512 << 16) | (110 << 8) | (224 << 0));
1083 static void adm8211_hw_init(struct ieee80211_hw
*dev
)
1085 struct adm8211_priv
*priv
= dev
->priv
;
1089 reg
= le32_to_cpu(ADM8211_CSR_READ(PAR
));
1090 reg
|= ADM8211_PAR_MRLE
| ADM8211_PAR_MRME
;
1091 reg
&= ~(ADM8211_PAR_BAR
| ADM8211_PAR_CAL
);
1093 if (!pci_set_mwi(priv
->pdev
)) {
1095 pci_read_config_byte(priv
->pdev
, PCI_CACHE_LINE_SIZE
, &cline
);
1098 case 0x8: reg
|= (0x1 << 14);
1100 case 0x16: reg
|= (0x2 << 14);
1102 case 0x32: reg
|= (0x3 << 14);
1104 default: reg
|= (0x0 << 14);
1109 ADM8211_CSR_WRITE(PAR
, reg
);
1111 reg
= ADM8211_CSR_READ(CSR_TEST1
);
1112 reg
&= ~(0xF << 28);
1113 reg
|= (1 << 28) | (1 << 31);
1114 ADM8211_CSR_WRITE(CSR_TEST1
, reg
);
1116 /* lose link after 4 lost beacons */
1117 reg
= (0x04 << 21) | ADM8211_WCSR_TSFTWE
| ADM8211_WCSR_LSOE
;
1118 ADM8211_CSR_WRITE(WCSR
, reg
);
1120 /* Disable APM, enable receive FIFO threshold, and set drain receive
1121 * threshold to store-and-forward */
1122 reg
= ADM8211_CSR_READ(CMDR
);
1123 reg
&= ~(ADM8211_CMDR_APM
| ADM8211_CMDR_DRT
);
1124 reg
|= ADM8211_CMDR_RTE
| ADM8211_CMDR_DRT_SF
;
1125 ADM8211_CSR_WRITE(CMDR
, reg
);
1127 adm8211_set_rate(dev
);
1131 * PWR0PAPE = 8 us or 5 us
1132 * PWR1PAPE = 1 us or 3 us
1137 * PWR0TXPE = 8 or 6 */
1138 if (priv
->pdev
->revision
< ADM8211_REV_CA
)
1139 ADM8211_CSR_WRITE(TOFS2
, 0x8815cd18);
1141 ADM8211_CSR_WRITE(TOFS2
, 0x8535cd16);
1143 /* Enable store and forward for transmit */
1144 priv
->nar
= ADM8211_NAR_SF
| ADM8211_NAR_PB
;
1145 ADM8211_CSR_WRITE(NAR
, priv
->nar
);
1148 ADM8211_CSR_WRITE(SYNRF
, ADM8211_SYNRF_RADIO
);
1149 ADM8211_CSR_READ(SYNRF
);
1151 ADM8211_CSR_WRITE(SYNRF
, 0);
1152 ADM8211_CSR_READ(SYNRF
);
1155 /* Set CFP Max Duration to 0x10 TU */
1156 reg
= ADM8211_CSR_READ(CFPP
);
1157 reg
&= ~(0xffff << 8);
1159 ADM8211_CSR_WRITE(CFPP
, reg
);
1161 /* USCNT = 0x16 (number of system clocks, 22 MHz, in 1us
1162 * TUCNT = 0x3ff - Tu counter 1024 us */
1163 ADM8211_CSR_WRITE(TOFS0
, (0x16 << 24) | 0x3ff);
1165 /* SLOT=20 us, SIFS=110 cycles of 22 MHz (5 us),
1166 * DIFS=50 us, EIFS=100 us */
1167 if (priv
->pdev
->revision
< ADM8211_REV_CA
)
1168 ADM8211_CSR_WRITE(IFST
, (20 << 23) | (110 << 15) |
1171 ADM8211_CSR_WRITE(IFST
, (20 << 23) | (24 << 15) |
1174 /* PCNT = 1 (MAC idle time awake/sleep, unit S)
1175 * RMRD = 2346 * 8 + 1 us (max RX duration) */
1176 ADM8211_CSR_WRITE(RMD
, (1 << 16) | 18769);
1178 /* MART=65535 us, MIRT=256 us, TSFTOFST=0 us */
1179 ADM8211_CSR_WRITE(RSPT
, 0xffffff00);
1181 /* Initialize BBP (and SYN) */
1182 adm8211_hw_init_bbp(dev
);
1184 /* make sure interrupts are off */
1185 ADM8211_CSR_WRITE(IER
, 0);
1187 /* ACK interrupts */
1188 ADM8211_CSR_WRITE(STSR
, ADM8211_CSR_READ(STSR
));
1190 /* Setup WEP (turns it off for now) */
1191 reg
= ADM8211_CSR_READ(MACTEST
);
1193 ADM8211_CSR_WRITE(MACTEST
, reg
);
1195 reg
= ADM8211_CSR_READ(WEPCTL
);
1196 reg
&= ~ADM8211_WEPCTL_WEPENABLE
;
1197 reg
|= ADM8211_WEPCTL_WEPRXBYP
;
1198 ADM8211_CSR_WRITE(WEPCTL
, reg
);
1200 /* Clear the missed-packet counter. */
1201 ADM8211_CSR_READ(LPC
);
1204 static int adm8211_hw_reset(struct ieee80211_hw
*dev
)
1206 struct adm8211_priv
*priv
= dev
->priv
;
1210 /* Power-on issue */
1211 /* TODO: check if this is necessary */
1212 ADM8211_CSR_WRITE(FRCTL
, 0);
1214 /* Reset the chip */
1215 tmp
= ADM8211_CSR_READ(PAR
);
1216 ADM8211_CSR_WRITE(PAR
, ADM8211_PAR_SWR
);
1218 while ((ADM8211_CSR_READ(PAR
) & ADM8211_PAR_SWR
) && timeout
--)
1224 ADM8211_CSR_WRITE(PAR
, tmp
);
1226 if (priv
->pdev
->revision
== ADM8211_REV_BA
&&
1227 (priv
->transceiver_type
== ADM8211_RFMD2958_RF3000_CONTROL_POWER
||
1228 priv
->transceiver_type
== ADM8211_RFMD2958
)) {
1229 reg
= ADM8211_CSR_READ(CSR_TEST1
);
1230 reg
|= (1 << 4) | (1 << 5);
1231 ADM8211_CSR_WRITE(CSR_TEST1
, reg
);
1232 } else if (priv
->pdev
->revision
== ADM8211_REV_CA
) {
1233 reg
= ADM8211_CSR_READ(CSR_TEST1
);
1234 reg
&= ~((1 << 4) | (1 << 5));
1235 ADM8211_CSR_WRITE(CSR_TEST1
, reg
);
1238 ADM8211_CSR_WRITE(FRCTL
, 0);
1240 reg
= ADM8211_CSR_READ(CSR_TEST0
);
1241 reg
|= ADM8211_CSR_TEST0_EPRLD
; /* EEPROM Recall */
1242 ADM8211_CSR_WRITE(CSR_TEST0
, reg
);
1244 adm8211_clear_sram(dev
);
1249 static u64
adm8211_get_tsft(struct ieee80211_hw
*dev
)
1251 struct adm8211_priv
*priv
= dev
->priv
;
1255 tsftl
= ADM8211_CSR_READ(TSFTL
);
1256 tsft
= ADM8211_CSR_READ(TSFTH
);
1263 static void adm8211_set_interval(struct ieee80211_hw
*dev
,
1264 unsigned short bi
, unsigned short li
)
1266 struct adm8211_priv
*priv
= dev
->priv
;
1269 /* BP (beacon interval) = data->beacon_interval
1270 * LI (listen interval) = data->listen_interval (in beacon intervals) */
1271 reg
= (bi
<< 16) | li
;
1272 ADM8211_CSR_WRITE(BPLI
, reg
);
1275 static void adm8211_set_bssid(struct ieee80211_hw
*dev
, const u8
*bssid
)
1277 struct adm8211_priv
*priv
= dev
->priv
;
1280 ADM8211_CSR_WRITE(BSSID0
, le32_to_cpu(*(__le32
*)bssid
));
1281 reg
= ADM8211_CSR_READ(ABDA1
);
1283 reg
|= (bssid
[4] << 16) | (bssid
[5] << 24);
1284 ADM8211_CSR_WRITE(ABDA1
, reg
);
1287 static int adm8211_set_ssid(struct ieee80211_hw
*dev
, u8
*ssid
, size_t ssid_len
)
1289 struct adm8211_priv
*priv
= dev
->priv
;
1295 memset(buf
, 0, sizeof(buf
));
1297 memcpy(buf
+ 1, ssid
, ssid_len
);
1298 adm8211_write_sram_bytes(dev
, ADM8211_SRAM_SSID
, buf
, 33);
1299 /* TODO: configure beacon for adhoc? */
1303 static int adm8211_config(struct ieee80211_hw
*dev
, struct ieee80211_conf
*conf
)
1305 struct adm8211_priv
*priv
= dev
->priv
;
1307 if (conf
->channel
!= priv
->channel
) {
1308 priv
->channel
= conf
->channel
;
1309 adm8211_rf_set_channel(dev
, priv
->channel
);
1315 static int adm8211_config_interface(struct ieee80211_hw
*dev
,
1316 struct ieee80211_vif
*vif
,
1317 struct ieee80211_if_conf
*conf
)
1319 struct adm8211_priv
*priv
= dev
->priv
;
1321 if (memcmp(conf
->bssid
, priv
->bssid
, ETH_ALEN
)) {
1322 adm8211_set_bssid(dev
, conf
->bssid
);
1323 memcpy(priv
->bssid
, conf
->bssid
, ETH_ALEN
);
1326 if (conf
->ssid_len
!= priv
->ssid_len
||
1327 memcmp(conf
->ssid
, priv
->ssid
, conf
->ssid_len
)) {
1328 adm8211_set_ssid(dev
, conf
->ssid
, conf
->ssid_len
);
1329 priv
->ssid_len
= conf
->ssid_len
;
1330 memcpy(priv
->ssid
, conf
->ssid
, conf
->ssid_len
);
1336 static void adm8211_configure_filter(struct ieee80211_hw
*dev
,
1337 unsigned int changed_flags
,
1338 unsigned int *total_flags
,
1339 int mc_count
, struct dev_mc_list
*mclist
)
1341 static const u8 bcast
[ETH_ALEN
] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
1342 struct adm8211_priv
*priv
= dev
->priv
;
1343 unsigned int bit_nr
, new_flags
;
1349 if (*total_flags
& FIF_PROMISC_IN_BSS
) {
1350 new_flags
|= FIF_PROMISC_IN_BSS
;
1351 priv
->nar
|= ADM8211_NAR_PR
;
1352 priv
->nar
&= ~ADM8211_NAR_MM
;
1353 mc_filter
[1] = mc_filter
[0] = ~0;
1354 } else if ((*total_flags
& FIF_ALLMULTI
) || (mc_count
> 32)) {
1355 new_flags
|= FIF_ALLMULTI
;
1356 priv
->nar
&= ~ADM8211_NAR_PR
;
1357 priv
->nar
|= ADM8211_NAR_MM
;
1358 mc_filter
[1] = mc_filter
[0] = ~0;
1360 priv
->nar
&= ~(ADM8211_NAR_MM
| ADM8211_NAR_PR
);
1361 mc_filter
[1] = mc_filter
[0] = 0;
1362 for (i
= 0; i
< mc_count
; i
++) {
1365 bit_nr
= ether_crc(ETH_ALEN
, mclist
->dmi_addr
) >> 26;
1368 mc_filter
[bit_nr
>> 5] |= 1 << (bit_nr
& 31);
1369 mclist
= mclist
->next
;
1375 ADM8211_CSR_WRITE(MAR0
, mc_filter
[0]);
1376 ADM8211_CSR_WRITE(MAR1
, mc_filter
[1]);
1377 ADM8211_CSR_READ(NAR
);
1379 if (priv
->nar
& ADM8211_NAR_PR
)
1380 dev
->flags
|= IEEE80211_HW_RX_INCLUDES_FCS
;
1382 dev
->flags
&= ~IEEE80211_HW_RX_INCLUDES_FCS
;
1384 if (*total_flags
& FIF_BCN_PRBRESP_PROMISC
)
1385 adm8211_set_bssid(dev
, bcast
);
1387 adm8211_set_bssid(dev
, priv
->bssid
);
1391 *total_flags
= new_flags
;
1394 static int adm8211_add_interface(struct ieee80211_hw
*dev
,
1395 struct ieee80211_if_init_conf
*conf
)
1397 struct adm8211_priv
*priv
= dev
->priv
;
1398 if (priv
->mode
!= IEEE80211_IF_TYPE_MNTR
)
1401 switch (conf
->type
) {
1402 case IEEE80211_IF_TYPE_STA
:
1403 priv
->mode
= conf
->type
;
1411 ADM8211_CSR_WRITE(PAR0
, le32_to_cpu(*(__le32
*)conf
->mac_addr
));
1412 ADM8211_CSR_WRITE(PAR1
, le16_to_cpu(*(__le16
*)(conf
->mac_addr
+ 4)));
1414 adm8211_update_mode(dev
);
1421 static void adm8211_remove_interface(struct ieee80211_hw
*dev
,
1422 struct ieee80211_if_init_conf
*conf
)
1424 struct adm8211_priv
*priv
= dev
->priv
;
1425 priv
->mode
= IEEE80211_IF_TYPE_MNTR
;
1428 static int adm8211_init_rings(struct ieee80211_hw
*dev
)
1430 struct adm8211_priv
*priv
= dev
->priv
;
1431 struct adm8211_desc
*desc
= NULL
;
1432 struct adm8211_rx_ring_info
*rx_info
;
1433 struct adm8211_tx_ring_info
*tx_info
;
1436 for (i
= 0; i
< priv
->rx_ring_size
; i
++) {
1437 desc
= &priv
->rx_ring
[i
];
1439 desc
->length
= cpu_to_le32(RX_PKT_SIZE
);
1440 priv
->rx_buffers
[i
].skb
= NULL
;
1442 /* Mark the end of RX ring; hw returns to base address after this
1444 desc
->length
|= cpu_to_le32(RDES1_CONTROL_RER
);
1446 for (i
= 0; i
< priv
->rx_ring_size
; i
++) {
1447 desc
= &priv
->rx_ring
[i
];
1448 rx_info
= &priv
->rx_buffers
[i
];
1450 rx_info
->skb
= dev_alloc_skb(RX_PKT_SIZE
);
1451 if (rx_info
->skb
== NULL
)
1453 rx_info
->mapping
= pci_map_single(priv
->pdev
,
1454 skb_tail_pointer(rx_info
->skb
),
1456 PCI_DMA_FROMDEVICE
);
1457 desc
->buffer1
= cpu_to_le32(rx_info
->mapping
);
1458 desc
->status
= cpu_to_le32(RDES0_STATUS_OWN
| RDES0_STATUS_SQL
);
1461 /* Setup TX ring. TX buffers descriptors will be filled in as needed */
1462 for (i
= 0; i
< priv
->tx_ring_size
; i
++) {
1463 desc
= &priv
->tx_ring
[i
];
1464 tx_info
= &priv
->tx_buffers
[i
];
1466 tx_info
->skb
= NULL
;
1467 tx_info
->mapping
= 0;
1470 desc
->length
= cpu_to_le32(TDES1_CONTROL_TER
);
1472 priv
->cur_rx
= priv
->cur_tx
= priv
->dirty_tx
= 0;
1473 ADM8211_CSR_WRITE(RDB
, priv
->rx_ring_dma
);
1474 ADM8211_CSR_WRITE(TDBD
, priv
->tx_ring_dma
);
1479 static void adm8211_free_rings(struct ieee80211_hw
*dev
)
1481 struct adm8211_priv
*priv
= dev
->priv
;
1484 for (i
= 0; i
< priv
->rx_ring_size
; i
++) {
1485 if (!priv
->rx_buffers
[i
].skb
)
1490 priv
->rx_buffers
[i
].mapping
,
1491 RX_PKT_SIZE
, PCI_DMA_FROMDEVICE
);
1493 dev_kfree_skb(priv
->rx_buffers
[i
].skb
);
1496 for (i
= 0; i
< priv
->tx_ring_size
; i
++) {
1497 if (!priv
->tx_buffers
[i
].skb
)
1500 pci_unmap_single(priv
->pdev
,
1501 priv
->tx_buffers
[i
].mapping
,
1502 priv
->tx_buffers
[i
].skb
->len
,
1505 dev_kfree_skb(priv
->tx_buffers
[i
].skb
);
1509 static int adm8211_start(struct ieee80211_hw
*dev
)
1511 struct adm8211_priv
*priv
= dev
->priv
;
1514 /* Power up MAC and RF chips */
1515 retval
= adm8211_hw_reset(dev
);
1517 printk(KERN_ERR
"%s: hardware reset failed\n",
1518 wiphy_name(dev
->wiphy
));
1522 retval
= adm8211_init_rings(dev
);
1524 printk(KERN_ERR
"%s: failed to initialize rings\n",
1525 wiphy_name(dev
->wiphy
));
1530 adm8211_hw_init(dev
);
1531 adm8211_rf_set_channel(dev
, priv
->channel
);
1533 retval
= request_irq(priv
->pdev
->irq
, &adm8211_interrupt
,
1534 IRQF_SHARED
, "adm8211", dev
);
1536 printk(KERN_ERR
"%s: failed to register IRQ handler\n",
1537 wiphy_name(dev
->wiphy
));
1541 ADM8211_CSR_WRITE(IER
, ADM8211_IER_NIE
| ADM8211_IER_AIE
|
1542 ADM8211_IER_RCIE
| ADM8211_IER_TCIE
|
1543 ADM8211_IER_TDUIE
| ADM8211_IER_GPTIE
);
1544 priv
->mode
= IEEE80211_IF_TYPE_MNTR
;
1545 adm8211_update_mode(dev
);
1546 ADM8211_CSR_WRITE(RDR
, 0);
1548 adm8211_set_interval(dev
, 100, 10);
1555 static void adm8211_stop(struct ieee80211_hw
*dev
)
1557 struct adm8211_priv
*priv
= dev
->priv
;
1559 priv
->mode
= IEEE80211_IF_TYPE_INVALID
;
1561 ADM8211_CSR_WRITE(NAR
, 0);
1562 ADM8211_CSR_WRITE(IER
, 0);
1563 ADM8211_CSR_READ(NAR
);
1565 free_irq(priv
->pdev
->irq
, dev
);
1567 adm8211_free_rings(dev
);
1570 static void adm8211_calc_durations(int *dur
, int *plcp
, size_t payload_len
, int len
,
1571 int plcp_signal
, int short_preamble
)
1573 /* Alternative calculation from NetBSD: */
1575 /* IEEE 802.11b durations for DSSS PHY in microseconds */
1576 #define IEEE80211_DUR_DS_LONG_PREAMBLE 144
1577 #define IEEE80211_DUR_DS_SHORT_PREAMBLE 72
1578 #define IEEE80211_DUR_DS_FAST_PLCPHDR 24
1579 #define IEEE80211_DUR_DS_SLOW_PLCPHDR 48
1580 #define IEEE80211_DUR_DS_SLOW_ACK 112
1581 #define IEEE80211_DUR_DS_FAST_ACK 56
1582 #define IEEE80211_DUR_DS_SLOW_CTS 112
1583 #define IEEE80211_DUR_DS_FAST_CTS 56
1584 #define IEEE80211_DUR_DS_SLOT 20
1585 #define IEEE80211_DUR_DS_SIFS 10
1589 *dur
= (80 * (24 + payload_len
) + plcp_signal
- 1)
1592 if (plcp_signal
<= PLCP_SIGNAL_2M
)
1593 /* 1-2Mbps WLAN: send ACK/CTS at 1Mbps */
1594 *dur
+= 3 * (IEEE80211_DUR_DS_SIFS
+
1595 IEEE80211_DUR_DS_SHORT_PREAMBLE
+
1596 IEEE80211_DUR_DS_FAST_PLCPHDR
) +
1597 IEEE80211_DUR_DS_SLOW_CTS
+ IEEE80211_DUR_DS_SLOW_ACK
;
1599 /* 5-11Mbps WLAN: send ACK/CTS at 2Mbps */
1600 *dur
+= 3 * (IEEE80211_DUR_DS_SIFS
+
1601 IEEE80211_DUR_DS_SHORT_PREAMBLE
+
1602 IEEE80211_DUR_DS_FAST_PLCPHDR
) +
1603 IEEE80211_DUR_DS_FAST_CTS
+ IEEE80211_DUR_DS_FAST_ACK
;
1605 /* lengthen duration if long preamble */
1606 if (!short_preamble
)
1607 *dur
+= 3 * (IEEE80211_DUR_DS_LONG_PREAMBLE
-
1608 IEEE80211_DUR_DS_SHORT_PREAMBLE
) +
1609 3 * (IEEE80211_DUR_DS_SLOW_PLCPHDR
-
1610 IEEE80211_DUR_DS_FAST_PLCPHDR
);
1613 *plcp
= (80 * len
) / plcp_signal
;
1614 remainder
= (80 * len
) % plcp_signal
;
1615 if (plcp_signal
== PLCP_SIGNAL_11M
&&
1616 remainder
<= 30 && remainder
> 0)
1617 *plcp
= (*plcp
| 0x8000) + 1;
1622 /* Transmit skb w/adm8211_tx_hdr (802.11 header created by hardware) */
1623 static void adm8211_tx_raw(struct ieee80211_hw
*dev
, struct sk_buff
*skb
,
1625 struct ieee80211_tx_control
*control
,
1628 struct adm8211_priv
*priv
= dev
->priv
;
1629 unsigned long flags
;
1634 mapping
= pci_map_single(priv
->pdev
, skb
->data
, skb
->len
,
1637 spin_lock_irqsave(&priv
->lock
, flags
);
1639 if (priv
->cur_tx
- priv
->dirty_tx
== priv
->tx_ring_size
/ 2)
1640 flag
= TDES1_CONTROL_IC
| TDES1_CONTROL_LS
| TDES1_CONTROL_FS
;
1642 flag
= TDES1_CONTROL_LS
| TDES1_CONTROL_FS
;
1644 if (priv
->cur_tx
- priv
->dirty_tx
== priv
->tx_ring_size
- 2)
1645 ieee80211_stop_queue(dev
, 0);
1647 entry
= priv
->cur_tx
% priv
->tx_ring_size
;
1649 priv
->tx_buffers
[entry
].skb
= skb
;
1650 priv
->tx_buffers
[entry
].mapping
= mapping
;
1651 memcpy(&priv
->tx_buffers
[entry
].tx_control
, control
, sizeof(*control
));
1652 priv
->tx_buffers
[entry
].hdrlen
= hdrlen
;
1653 priv
->tx_ring
[entry
].buffer1
= cpu_to_le32(mapping
);
1655 if (entry
== priv
->tx_ring_size
- 1)
1656 flag
|= TDES1_CONTROL_TER
;
1657 priv
->tx_ring
[entry
].length
= cpu_to_le32(flag
| skb
->len
);
1659 /* Set TX rate (SIGNAL field in PLCP PPDU format) */
1660 flag
= TDES0_CONTROL_OWN
| (plcp_signal
<< 20) | 8 /* ? */;
1661 priv
->tx_ring
[entry
].status
= cpu_to_le32(flag
);
1665 spin_unlock_irqrestore(&priv
->lock
, flags
);
1667 /* Trigger transmit poll */
1668 ADM8211_CSR_WRITE(TDR
, 0);
1671 /* Put adm8211_tx_hdr on skb and transmit */
1672 static int adm8211_tx(struct ieee80211_hw
*dev
, struct sk_buff
*skb
,
1673 struct ieee80211_tx_control
*control
)
1675 struct adm8211_tx_hdr
*txhdr
;
1677 size_t payload_len
, hdrlen
;
1678 int plcp
, dur
, len
, plcp_signal
, short_preamble
;
1679 struct ieee80211_hdr
*hdr
;
1681 if (control
->tx_rate
< 0) {
1683 plcp_signal
= -control
->tx_rate
;
1686 plcp_signal
= control
->tx_rate
;
1689 hdr
= (struct ieee80211_hdr
*)skb
->data
;
1690 fc
= le16_to_cpu(hdr
->frame_control
) & ~IEEE80211_FCTL_PROTECTED
;
1691 hdrlen
= ieee80211_get_hdrlen(fc
);
1692 memcpy(skb
->cb
, skb
->data
, hdrlen
);
1693 hdr
= (struct ieee80211_hdr
*)skb
->cb
;
1694 skb_pull(skb
, hdrlen
);
1695 payload_len
= skb
->len
;
1697 txhdr
= (struct adm8211_tx_hdr
*) skb_push(skb
, sizeof(*txhdr
));
1698 memset(txhdr
, 0, sizeof(*txhdr
));
1699 memcpy(txhdr
->da
, ieee80211_get_DA(hdr
), ETH_ALEN
);
1700 txhdr
->signal
= plcp_signal
;
1701 txhdr
->frame_body_size
= cpu_to_le16(payload_len
);
1702 txhdr
->frame_control
= hdr
->frame_control
;
1704 len
= hdrlen
+ payload_len
+ FCS_LEN
;
1705 if (fc
& IEEE80211_FCTL_PROTECTED
)
1708 txhdr
->frag
= cpu_to_le16(0x0FFF);
1709 adm8211_calc_durations(&dur
, &plcp
, payload_len
,
1710 len
, plcp_signal
, short_preamble
);
1711 txhdr
->plcp_frag_head_len
= cpu_to_le16(plcp
);
1712 txhdr
->plcp_frag_tail_len
= cpu_to_le16(plcp
);
1713 txhdr
->dur_frag_head
= cpu_to_le16(dur
);
1714 txhdr
->dur_frag_tail
= cpu_to_le16(dur
);
1716 txhdr
->header_control
= cpu_to_le16(ADM8211_TXHDRCTL_ENABLE_EXTEND_HEADER
);
1719 txhdr
->header_control
|= cpu_to_le16(ADM8211_TXHDRCTL_SHORT_PREAMBLE
);
1721 if (control
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
)
1722 txhdr
->header_control
|= cpu_to_le16(ADM8211_TXHDRCTL_ENABLE_RTS
);
1724 if (fc
& IEEE80211_FCTL_PROTECTED
)
1725 txhdr
->header_control
|= cpu_to_le16(ADM8211_TXHDRCTL_ENABLE_WEP_ENGINE
);
1727 txhdr
->retry_limit
= control
->retry_limit
;
1729 adm8211_tx_raw(dev
, skb
, plcp_signal
, control
, hdrlen
);
1731 return NETDEV_TX_OK
;
1734 static int adm8211_alloc_rings(struct ieee80211_hw
*dev
)
1736 struct adm8211_priv
*priv
= dev
->priv
;
1737 unsigned int ring_size
;
1739 priv
->rx_buffers
= kmalloc(sizeof(*priv
->rx_buffers
) * priv
->rx_ring_size
+
1740 sizeof(*priv
->tx_buffers
) * priv
->tx_ring_size
, GFP_KERNEL
);
1741 if (!priv
->rx_buffers
)
1744 priv
->tx_buffers
= (void *)priv
->rx_buffers
+
1745 sizeof(*priv
->rx_buffers
) * priv
->rx_ring_size
;
1747 /* Allocate TX/RX descriptors */
1748 ring_size
= sizeof(struct adm8211_desc
) * priv
->rx_ring_size
+
1749 sizeof(struct adm8211_desc
) * priv
->tx_ring_size
;
1750 priv
->rx_ring
= pci_alloc_consistent(priv
->pdev
, ring_size
,
1751 &priv
->rx_ring_dma
);
1753 if (!priv
->rx_ring
) {
1754 kfree(priv
->rx_buffers
);
1755 priv
->rx_buffers
= NULL
;
1756 priv
->tx_buffers
= NULL
;
1760 priv
->tx_ring
= (struct adm8211_desc
*)(priv
->rx_ring
+
1761 priv
->rx_ring_size
);
1762 priv
->tx_ring_dma
= priv
->rx_ring_dma
+
1763 sizeof(struct adm8211_desc
) * priv
->rx_ring_size
;
1768 static const struct ieee80211_ops adm8211_ops
= {
1770 .start
= adm8211_start
,
1771 .stop
= adm8211_stop
,
1772 .add_interface
= adm8211_add_interface
,
1773 .remove_interface
= adm8211_remove_interface
,
1774 .config
= adm8211_config
,
1775 .config_interface
= adm8211_config_interface
,
1776 .configure_filter
= adm8211_configure_filter
,
1777 .get_stats
= adm8211_get_stats
,
1778 .get_tx_stats
= adm8211_get_tx_stats
,
1779 .get_tsf
= adm8211_get_tsft
1782 static int __devinit
adm8211_probe(struct pci_dev
*pdev
,
1783 const struct pci_device_id
*id
)
1785 struct ieee80211_hw
*dev
;
1786 struct adm8211_priv
*priv
;
1787 unsigned long mem_addr
, mem_len
;
1788 unsigned int io_addr
, io_len
;
1791 u8 perm_addr
[ETH_ALEN
];
1792 DECLARE_MAC_BUF(mac
);
1794 err
= pci_enable_device(pdev
);
1796 printk(KERN_ERR
"%s (adm8211): Cannot enable new PCI device\n",
1801 io_addr
= pci_resource_start(pdev
, 0);
1802 io_len
= pci_resource_len(pdev
, 0);
1803 mem_addr
= pci_resource_start(pdev
, 1);
1804 mem_len
= pci_resource_len(pdev
, 1);
1805 if (io_len
< 256 || mem_len
< 1024) {
1806 printk(KERN_ERR
"%s (adm8211): Too short PCI resources\n",
1808 goto err_disable_pdev
;
1812 /* check signature */
1813 pci_read_config_dword(pdev
, 0x80 /* CR32 */, ®
);
1814 if (reg
!= ADM8211_SIG1
&& reg
!= ADM8211_SIG2
) {
1815 printk(KERN_ERR
"%s (adm8211): Invalid signature (0x%x)\n",
1816 pci_name(pdev
), reg
);
1817 goto err_disable_pdev
;
1820 err
= pci_request_regions(pdev
, "adm8211");
1822 printk(KERN_ERR
"%s (adm8211): Cannot obtain PCI resources\n",
1824 return err
; /* someone else grabbed it? don't disable it */
1827 if (pci_set_dma_mask(pdev
, DMA_32BIT_MASK
) ||
1828 pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
)) {
1829 printk(KERN_ERR
"%s (adm8211): No suitable DMA available\n",
1834 pci_set_master(pdev
);
1836 dev
= ieee80211_alloc_hw(sizeof(*priv
), &adm8211_ops
);
1838 printk(KERN_ERR
"%s (adm8211): ieee80211 alloc failed\n",
1846 spin_lock_init(&priv
->lock
);
1848 SET_IEEE80211_DEV(dev
, &pdev
->dev
);
1850 pci_set_drvdata(pdev
, dev
);
1852 priv
->map
= pci_iomap(pdev
, 1, mem_len
);
1854 priv
->map
= pci_iomap(pdev
, 0, io_len
);
1857 printk(KERN_ERR
"%s (adm8211): Cannot map device memory\n",
1862 priv
->rx_ring_size
= rx_ring_size
;
1863 priv
->tx_ring_size
= tx_ring_size
;
1865 if (adm8211_alloc_rings(dev
)) {
1866 printk(KERN_ERR
"%s (adm8211): Cannot allocate TX/RX ring\n",
1871 *(__le32
*)perm_addr
= cpu_to_le32(ADM8211_CSR_READ(PAR0
));
1872 *(__le16
*)&perm_addr
[4] =
1873 cpu_to_le16(ADM8211_CSR_READ(PAR1
) & 0xFFFF);
1875 if (!is_valid_ether_addr(perm_addr
)) {
1876 printk(KERN_WARNING
"%s (adm8211): Invalid hwaddr in EEPROM!\n",
1878 random_ether_addr(perm_addr
);
1880 SET_IEEE80211_PERM_ADDR(dev
, perm_addr
);
1882 dev
->extra_tx_headroom
= sizeof(struct adm8211_tx_hdr
);
1883 dev
->flags
= IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED
;
1884 /* IEEE80211_HW_RX_INCLUDES_FCS in promisc mode */
1886 dev
->channel_change_time
= 1000;
1887 dev
->max_rssi
= 100; /* FIXME: find better value */
1889 priv
->modes
[0].mode
= MODE_IEEE80211B
;
1890 /* channel info filled in by adm8211_read_eeprom */
1891 memcpy(priv
->rates
, adm8211_rates
, sizeof(adm8211_rates
));
1892 priv
->modes
[0].num_rates
= ARRAY_SIZE(adm8211_rates
);
1893 priv
->modes
[0].rates
= priv
->rates
;
1895 dev
->queues
= 1; /* ADM8211C supports more, maybe ADM8211B too */
1897 priv
->retry_limit
= 3;
1898 priv
->ant_power
= 0x40;
1899 priv
->tx_power
= 0x40;
1900 priv
->lpf_cutoff
= 0xFF;
1901 priv
->lnags_threshold
= 0xFF;
1902 priv
->mode
= IEEE80211_IF_TYPE_INVALID
;
1904 /* Power-on issue. EEPROM won't read correctly without */
1905 if (pdev
->revision
>= ADM8211_REV_BA
) {
1906 ADM8211_CSR_WRITE(FRCTL
, 0);
1907 ADM8211_CSR_READ(FRCTL
);
1908 ADM8211_CSR_WRITE(FRCTL
, 1);
1909 ADM8211_CSR_READ(FRCTL
);
1913 err
= adm8211_read_eeprom(dev
);
1915 printk(KERN_ERR
"%s (adm8211): Can't alloc eeprom buffer\n",
1920 priv
->channel
= priv
->modes
[0].channels
[0].chan
;
1922 err
= ieee80211_register_hwmode(dev
, &priv
->modes
[0]);
1924 printk(KERN_ERR
"%s (adm8211): Can't register hwmode\n",
1929 err
= ieee80211_register_hw(dev
);
1931 printk(KERN_ERR
"%s (adm8211): Cannot register device\n",
1936 printk(KERN_INFO
"%s: hwaddr %s, Rev 0x%02x\n",
1937 wiphy_name(dev
->wiphy
), print_mac(mac
, dev
->wiphy
->perm_addr
),
1943 pci_free_consistent(pdev
,
1944 sizeof(struct adm8211_desc
) * priv
->rx_ring_size
+
1945 sizeof(struct adm8211_desc
) * priv
->tx_ring_size
,
1946 priv
->rx_ring
, priv
->rx_ring_dma
);
1947 kfree(priv
->rx_buffers
);
1950 pci_iounmap(pdev
, priv
->map
);
1953 pci_set_drvdata(pdev
, NULL
);
1954 ieee80211_free_hw(dev
);
1957 pci_release_regions(pdev
);
1960 pci_disable_device(pdev
);
1965 static void __devexit
adm8211_remove(struct pci_dev
*pdev
)
1967 struct ieee80211_hw
*dev
= pci_get_drvdata(pdev
);
1968 struct adm8211_priv
*priv
;
1973 ieee80211_unregister_hw(dev
);
1977 pci_free_consistent(pdev
,
1978 sizeof(struct adm8211_desc
) * priv
->rx_ring_size
+
1979 sizeof(struct adm8211_desc
) * priv
->tx_ring_size
,
1980 priv
->rx_ring
, priv
->rx_ring_dma
);
1982 kfree(priv
->rx_buffers
);
1983 kfree(priv
->eeprom
);
1984 pci_iounmap(pdev
, priv
->map
);
1985 pci_release_regions(pdev
);
1986 pci_disable_device(pdev
);
1987 ieee80211_free_hw(dev
);
1992 static int adm8211_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1994 struct ieee80211_hw
*dev
= pci_get_drvdata(pdev
);
1995 struct adm8211_priv
*priv
= dev
->priv
;
1997 if (priv
->mode
!= IEEE80211_IF_TYPE_INVALID
) {
1998 ieee80211_stop_queues(dev
);
2002 pci_save_state(pdev
);
2003 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
2007 static int adm8211_resume(struct pci_dev
*pdev
)
2009 struct ieee80211_hw
*dev
= pci_get_drvdata(pdev
);
2010 struct adm8211_priv
*priv
= dev
->priv
;
2012 pci_set_power_state(pdev
, PCI_D0
);
2013 pci_restore_state(pdev
);
2015 if (priv
->mode
!= IEEE80211_IF_TYPE_INVALID
) {
2017 ieee80211_start_queues(dev
);
2022 #endif /* CONFIG_PM */
2025 MODULE_DEVICE_TABLE(pci
, adm8211_pci_id_table
);
2027 /* TODO: implement enable_wake */
2028 static struct pci_driver adm8211_driver
= {
2030 .id_table
= adm8211_pci_id_table
,
2031 .probe
= adm8211_probe
,
2032 .remove
= __devexit_p(adm8211_remove
),
2034 .suspend
= adm8211_suspend
,
2035 .resume
= adm8211_resume
,
2036 #endif /* CONFIG_PM */
2041 static int __init
adm8211_init(void)
2043 return pci_register_driver(&adm8211_driver
);
2047 static void __exit
adm8211_exit(void)
2049 pci_unregister_driver(&adm8211_driver
);
2053 module_init(adm8211_init
);
2054 module_exit(adm8211_exit
);