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 __force
*)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
, int if_id
,
1316 struct ieee80211_if_conf
*conf
)
1318 struct adm8211_priv
*priv
= dev
->priv
;
1320 if (memcmp(conf
->bssid
, priv
->bssid
, ETH_ALEN
)) {
1321 adm8211_set_bssid(dev
, conf
->bssid
);
1322 memcpy(priv
->bssid
, conf
->bssid
, ETH_ALEN
);
1325 if (conf
->ssid_len
!= priv
->ssid_len
||
1326 memcmp(conf
->ssid
, priv
->ssid
, conf
->ssid_len
)) {
1327 adm8211_set_ssid(dev
, conf
->ssid
, conf
->ssid_len
);
1328 priv
->ssid_len
= conf
->ssid_len
;
1329 memcpy(priv
->ssid
, conf
->ssid
, conf
->ssid_len
);
1335 static void adm8211_configure_filter(struct ieee80211_hw
*dev
,
1336 unsigned int changed_flags
,
1337 unsigned int *total_flags
,
1338 int mc_count
, struct dev_mc_list
*mclist
)
1340 static const u8 bcast
[ETH_ALEN
] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
1341 struct adm8211_priv
*priv
= dev
->priv
;
1342 unsigned int bit_nr
, new_flags
;
1348 if (*total_flags
& FIF_PROMISC_IN_BSS
) {
1349 new_flags
|= FIF_PROMISC_IN_BSS
;
1350 priv
->nar
|= ADM8211_NAR_PR
;
1351 priv
->nar
&= ~ADM8211_NAR_MM
;
1352 mc_filter
[1] = mc_filter
[0] = ~0;
1353 } else if ((*total_flags
& FIF_ALLMULTI
) || (mc_count
> 32)) {
1354 new_flags
|= FIF_ALLMULTI
;
1355 priv
->nar
&= ~ADM8211_NAR_PR
;
1356 priv
->nar
|= ADM8211_NAR_MM
;
1357 mc_filter
[1] = mc_filter
[0] = ~0;
1359 priv
->nar
&= ~(ADM8211_NAR_MM
| ADM8211_NAR_PR
);
1360 mc_filter
[1] = mc_filter
[0] = 0;
1361 for (i
= 0; i
< mc_count
; i
++) {
1364 bit_nr
= ether_crc(ETH_ALEN
, mclist
->dmi_addr
) >> 26;
1367 mc_filter
[bit_nr
>> 5] |= 1 << (bit_nr
& 31);
1368 mclist
= mclist
->next
;
1374 ADM8211_CSR_WRITE(MAR0
, mc_filter
[0]);
1375 ADM8211_CSR_WRITE(MAR1
, mc_filter
[1]);
1376 ADM8211_CSR_READ(NAR
);
1378 if (priv
->nar
& ADM8211_NAR_PR
)
1379 dev
->flags
|= IEEE80211_HW_RX_INCLUDES_FCS
;
1381 dev
->flags
&= ~IEEE80211_HW_RX_INCLUDES_FCS
;
1383 if (*total_flags
& FIF_BCN_PRBRESP_PROMISC
)
1384 adm8211_set_bssid(dev
, bcast
);
1386 adm8211_set_bssid(dev
, priv
->bssid
);
1390 *total_flags
= new_flags
;
1393 static int adm8211_add_interface(struct ieee80211_hw
*dev
,
1394 struct ieee80211_if_init_conf
*conf
)
1396 struct adm8211_priv
*priv
= dev
->priv
;
1397 if (priv
->mode
!= IEEE80211_IF_TYPE_MNTR
)
1400 switch (conf
->type
) {
1401 case IEEE80211_IF_TYPE_STA
:
1402 priv
->mode
= conf
->type
;
1410 ADM8211_CSR_WRITE(PAR0
, le32_to_cpu(*(__le32
*)conf
->mac_addr
));
1411 ADM8211_CSR_WRITE(PAR1
, le16_to_cpu(*(__le16
*)(conf
->mac_addr
+ 4)));
1413 adm8211_update_mode(dev
);
1420 static void adm8211_remove_interface(struct ieee80211_hw
*dev
,
1421 struct ieee80211_if_init_conf
*conf
)
1423 struct adm8211_priv
*priv
= dev
->priv
;
1424 priv
->mode
= IEEE80211_IF_TYPE_MNTR
;
1427 static int adm8211_init_rings(struct ieee80211_hw
*dev
)
1429 struct adm8211_priv
*priv
= dev
->priv
;
1430 struct adm8211_desc
*desc
= NULL
;
1431 struct adm8211_rx_ring_info
*rx_info
;
1432 struct adm8211_tx_ring_info
*tx_info
;
1435 for (i
= 0; i
< priv
->rx_ring_size
; i
++) {
1436 desc
= &priv
->rx_ring
[i
];
1438 desc
->length
= cpu_to_le32(RX_PKT_SIZE
);
1439 priv
->rx_buffers
[i
].skb
= NULL
;
1441 /* Mark the end of RX ring; hw returns to base address after this
1443 desc
->length
|= cpu_to_le32(RDES1_CONTROL_RER
);
1445 for (i
= 0; i
< priv
->rx_ring_size
; i
++) {
1446 desc
= &priv
->rx_ring
[i
];
1447 rx_info
= &priv
->rx_buffers
[i
];
1449 rx_info
->skb
= dev_alloc_skb(RX_PKT_SIZE
);
1450 if (rx_info
->skb
== NULL
)
1452 rx_info
->mapping
= pci_map_single(priv
->pdev
,
1453 skb_tail_pointer(rx_info
->skb
),
1455 PCI_DMA_FROMDEVICE
);
1456 desc
->buffer1
= cpu_to_le32(rx_info
->mapping
);
1457 desc
->status
= cpu_to_le32(RDES0_STATUS_OWN
| RDES0_STATUS_SQL
);
1460 /* Setup TX ring. TX buffers descriptors will be filled in as needed */
1461 for (i
= 0; i
< priv
->tx_ring_size
; i
++) {
1462 desc
= &priv
->tx_ring
[i
];
1463 tx_info
= &priv
->tx_buffers
[i
];
1465 tx_info
->skb
= NULL
;
1466 tx_info
->mapping
= 0;
1469 desc
->length
= cpu_to_le32(TDES1_CONTROL_TER
);
1471 priv
->cur_rx
= priv
->cur_tx
= priv
->dirty_tx
= 0;
1472 ADM8211_CSR_WRITE(RDB
, priv
->rx_ring_dma
);
1473 ADM8211_CSR_WRITE(TDBD
, priv
->tx_ring_dma
);
1478 static void adm8211_free_rings(struct ieee80211_hw
*dev
)
1480 struct adm8211_priv
*priv
= dev
->priv
;
1483 for (i
= 0; i
< priv
->rx_ring_size
; i
++) {
1484 if (!priv
->rx_buffers
[i
].skb
)
1489 priv
->rx_buffers
[i
].mapping
,
1490 RX_PKT_SIZE
, PCI_DMA_FROMDEVICE
);
1492 dev_kfree_skb(priv
->rx_buffers
[i
].skb
);
1495 for (i
= 0; i
< priv
->tx_ring_size
; i
++) {
1496 if (!priv
->tx_buffers
[i
].skb
)
1499 pci_unmap_single(priv
->pdev
,
1500 priv
->tx_buffers
[i
].mapping
,
1501 priv
->tx_buffers
[i
].skb
->len
,
1504 dev_kfree_skb(priv
->tx_buffers
[i
].skb
);
1508 static int adm8211_start(struct ieee80211_hw
*dev
)
1510 struct adm8211_priv
*priv
= dev
->priv
;
1513 /* Power up MAC and RF chips */
1514 retval
= adm8211_hw_reset(dev
);
1516 printk(KERN_ERR
"%s: hardware reset failed\n",
1517 wiphy_name(dev
->wiphy
));
1521 retval
= adm8211_init_rings(dev
);
1523 printk(KERN_ERR
"%s: failed to initialize rings\n",
1524 wiphy_name(dev
->wiphy
));
1529 adm8211_hw_init(dev
);
1530 adm8211_rf_set_channel(dev
, priv
->channel
);
1532 retval
= request_irq(priv
->pdev
->irq
, &adm8211_interrupt
,
1533 IRQF_SHARED
, "adm8211", dev
);
1535 printk(KERN_ERR
"%s: failed to register IRQ handler\n",
1536 wiphy_name(dev
->wiphy
));
1540 ADM8211_CSR_WRITE(IER
, ADM8211_IER_NIE
| ADM8211_IER_AIE
|
1541 ADM8211_IER_RCIE
| ADM8211_IER_TCIE
|
1542 ADM8211_IER_TDUIE
| ADM8211_IER_GPTIE
);
1543 priv
->mode
= IEEE80211_IF_TYPE_MNTR
;
1544 adm8211_update_mode(dev
);
1545 ADM8211_CSR_WRITE(RDR
, 0);
1547 adm8211_set_interval(dev
, 100, 10);
1554 static void adm8211_stop(struct ieee80211_hw
*dev
)
1556 struct adm8211_priv
*priv
= dev
->priv
;
1558 priv
->mode
= IEEE80211_IF_TYPE_INVALID
;
1560 ADM8211_CSR_WRITE(NAR
, 0);
1561 ADM8211_CSR_WRITE(IER
, 0);
1562 ADM8211_CSR_READ(NAR
);
1564 free_irq(priv
->pdev
->irq
, dev
);
1566 adm8211_free_rings(dev
);
1569 static void adm8211_calc_durations(int *dur
, int *plcp
, size_t payload_len
, int len
,
1570 int plcp_signal
, int short_preamble
)
1572 /* Alternative calculation from NetBSD: */
1574 /* IEEE 802.11b durations for DSSS PHY in microseconds */
1575 #define IEEE80211_DUR_DS_LONG_PREAMBLE 144
1576 #define IEEE80211_DUR_DS_SHORT_PREAMBLE 72
1577 #define IEEE80211_DUR_DS_FAST_PLCPHDR 24
1578 #define IEEE80211_DUR_DS_SLOW_PLCPHDR 48
1579 #define IEEE80211_DUR_DS_SLOW_ACK 112
1580 #define IEEE80211_DUR_DS_FAST_ACK 56
1581 #define IEEE80211_DUR_DS_SLOW_CTS 112
1582 #define IEEE80211_DUR_DS_FAST_CTS 56
1583 #define IEEE80211_DUR_DS_SLOT 20
1584 #define IEEE80211_DUR_DS_SIFS 10
1588 *dur
= (80 * (24 + payload_len
) + plcp_signal
- 1)
1591 if (plcp_signal
<= PLCP_SIGNAL_2M
)
1592 /* 1-2Mbps WLAN: send ACK/CTS at 1Mbps */
1593 *dur
+= 3 * (IEEE80211_DUR_DS_SIFS
+
1594 IEEE80211_DUR_DS_SHORT_PREAMBLE
+
1595 IEEE80211_DUR_DS_FAST_PLCPHDR
) +
1596 IEEE80211_DUR_DS_SLOW_CTS
+ IEEE80211_DUR_DS_SLOW_ACK
;
1598 /* 5-11Mbps WLAN: send ACK/CTS at 2Mbps */
1599 *dur
+= 3 * (IEEE80211_DUR_DS_SIFS
+
1600 IEEE80211_DUR_DS_SHORT_PREAMBLE
+
1601 IEEE80211_DUR_DS_FAST_PLCPHDR
) +
1602 IEEE80211_DUR_DS_FAST_CTS
+ IEEE80211_DUR_DS_FAST_ACK
;
1604 /* lengthen duration if long preamble */
1605 if (!short_preamble
)
1606 *dur
+= 3 * (IEEE80211_DUR_DS_LONG_PREAMBLE
-
1607 IEEE80211_DUR_DS_SHORT_PREAMBLE
) +
1608 3 * (IEEE80211_DUR_DS_SLOW_PLCPHDR
-
1609 IEEE80211_DUR_DS_FAST_PLCPHDR
);
1612 *plcp
= (80 * len
) / plcp_signal
;
1613 remainder
= (80 * len
) % plcp_signal
;
1614 if (plcp_signal
== PLCP_SIGNAL_11M
&&
1615 remainder
<= 30 && remainder
> 0)
1616 *plcp
= (*plcp
| 0x8000) + 1;
1621 /* Transmit skb w/adm8211_tx_hdr (802.11 header created by hardware) */
1622 static void adm8211_tx_raw(struct ieee80211_hw
*dev
, struct sk_buff
*skb
,
1624 struct ieee80211_tx_control
*control
,
1627 struct adm8211_priv
*priv
= dev
->priv
;
1628 unsigned long flags
;
1633 mapping
= pci_map_single(priv
->pdev
, skb
->data
, skb
->len
,
1636 spin_lock_irqsave(&priv
->lock
, flags
);
1638 if (priv
->cur_tx
- priv
->dirty_tx
== priv
->tx_ring_size
/ 2)
1639 flag
= TDES1_CONTROL_IC
| TDES1_CONTROL_LS
| TDES1_CONTROL_FS
;
1641 flag
= TDES1_CONTROL_LS
| TDES1_CONTROL_FS
;
1643 if (priv
->cur_tx
- priv
->dirty_tx
== priv
->tx_ring_size
- 2)
1644 ieee80211_stop_queue(dev
, 0);
1646 entry
= priv
->cur_tx
% priv
->tx_ring_size
;
1648 priv
->tx_buffers
[entry
].skb
= skb
;
1649 priv
->tx_buffers
[entry
].mapping
= mapping
;
1650 memcpy(&priv
->tx_buffers
[entry
].tx_control
, control
, sizeof(*control
));
1651 priv
->tx_buffers
[entry
].hdrlen
= hdrlen
;
1652 priv
->tx_ring
[entry
].buffer1
= cpu_to_le32(mapping
);
1654 if (entry
== priv
->tx_ring_size
- 1)
1655 flag
|= TDES1_CONTROL_TER
;
1656 priv
->tx_ring
[entry
].length
= cpu_to_le32(flag
| skb
->len
);
1658 /* Set TX rate (SIGNAL field in PLCP PPDU format) */
1659 flag
= TDES0_CONTROL_OWN
| (plcp_signal
<< 20) | 8 /* ? */;
1660 priv
->tx_ring
[entry
].status
= cpu_to_le32(flag
);
1664 spin_unlock_irqrestore(&priv
->lock
, flags
);
1666 /* Trigger transmit poll */
1667 ADM8211_CSR_WRITE(TDR
, 0);
1670 /* Put adm8211_tx_hdr on skb and transmit */
1671 static int adm8211_tx(struct ieee80211_hw
*dev
, struct sk_buff
*skb
,
1672 struct ieee80211_tx_control
*control
)
1674 struct adm8211_tx_hdr
*txhdr
;
1676 size_t payload_len
, hdrlen
;
1677 int plcp
, dur
, len
, plcp_signal
, short_preamble
;
1678 struct ieee80211_hdr
*hdr
;
1680 if (control
->tx_rate
< 0) {
1682 plcp_signal
= -control
->tx_rate
;
1685 plcp_signal
= control
->tx_rate
;
1688 hdr
= (struct ieee80211_hdr
*)skb
->data
;
1689 fc
= le16_to_cpu(hdr
->frame_control
) & ~IEEE80211_FCTL_PROTECTED
;
1690 hdrlen
= ieee80211_get_hdrlen(fc
);
1691 memcpy(skb
->cb
, skb
->data
, hdrlen
);
1692 hdr
= (struct ieee80211_hdr
*)skb
->cb
;
1693 skb_pull(skb
, hdrlen
);
1694 payload_len
= skb
->len
;
1696 txhdr
= (struct adm8211_tx_hdr
*) skb_push(skb
, sizeof(*txhdr
));
1697 memset(txhdr
, 0, sizeof(*txhdr
));
1698 memcpy(txhdr
->da
, ieee80211_get_DA(hdr
), ETH_ALEN
);
1699 txhdr
->signal
= plcp_signal
;
1700 txhdr
->frame_body_size
= cpu_to_le16(payload_len
);
1701 txhdr
->frame_control
= hdr
->frame_control
;
1703 len
= hdrlen
+ payload_len
+ FCS_LEN
;
1704 if (fc
& IEEE80211_FCTL_PROTECTED
)
1707 txhdr
->frag
= cpu_to_le16(0x0FFF);
1708 adm8211_calc_durations(&dur
, &plcp
, payload_len
,
1709 len
, plcp_signal
, short_preamble
);
1710 txhdr
->plcp_frag_head_len
= cpu_to_le16(plcp
);
1711 txhdr
->plcp_frag_tail_len
= cpu_to_le16(plcp
);
1712 txhdr
->dur_frag_head
= cpu_to_le16(dur
);
1713 txhdr
->dur_frag_tail
= cpu_to_le16(dur
);
1715 txhdr
->header_control
= cpu_to_le16(ADM8211_TXHDRCTL_ENABLE_EXTEND_HEADER
);
1718 txhdr
->header_control
|= cpu_to_le16(ADM8211_TXHDRCTL_SHORT_PREAMBLE
);
1720 if (control
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
)
1721 txhdr
->header_control
|= cpu_to_le16(ADM8211_TXHDRCTL_ENABLE_RTS
);
1723 if (fc
& IEEE80211_FCTL_PROTECTED
)
1724 txhdr
->header_control
|= cpu_to_le16(ADM8211_TXHDRCTL_ENABLE_WEP_ENGINE
);
1726 txhdr
->retry_limit
= control
->retry_limit
;
1728 adm8211_tx_raw(dev
, skb
, plcp_signal
, control
, hdrlen
);
1730 return NETDEV_TX_OK
;
1733 static int adm8211_alloc_rings(struct ieee80211_hw
*dev
)
1735 struct adm8211_priv
*priv
= dev
->priv
;
1736 unsigned int ring_size
;
1738 priv
->rx_buffers
= kmalloc(sizeof(*priv
->rx_buffers
) * priv
->rx_ring_size
+
1739 sizeof(*priv
->tx_buffers
) * priv
->tx_ring_size
, GFP_KERNEL
);
1740 if (!priv
->rx_buffers
)
1743 priv
->tx_buffers
= (void *)priv
->rx_buffers
+
1744 sizeof(*priv
->rx_buffers
) * priv
->rx_ring_size
;
1746 /* Allocate TX/RX descriptors */
1747 ring_size
= sizeof(struct adm8211_desc
) * priv
->rx_ring_size
+
1748 sizeof(struct adm8211_desc
) * priv
->tx_ring_size
;
1749 priv
->rx_ring
= pci_alloc_consistent(priv
->pdev
, ring_size
,
1750 &priv
->rx_ring_dma
);
1752 if (!priv
->rx_ring
) {
1753 kfree(priv
->rx_buffers
);
1754 priv
->rx_buffers
= NULL
;
1755 priv
->tx_buffers
= NULL
;
1759 priv
->tx_ring
= (struct adm8211_desc
*)(priv
->rx_ring
+
1760 priv
->rx_ring_size
);
1761 priv
->tx_ring_dma
= priv
->rx_ring_dma
+
1762 sizeof(struct adm8211_desc
) * priv
->rx_ring_size
;
1767 static const struct ieee80211_ops adm8211_ops
= {
1769 .start
= adm8211_start
,
1770 .stop
= adm8211_stop
,
1771 .add_interface
= adm8211_add_interface
,
1772 .remove_interface
= adm8211_remove_interface
,
1773 .config
= adm8211_config
,
1774 .config_interface
= adm8211_config_interface
,
1775 .configure_filter
= adm8211_configure_filter
,
1776 .get_stats
= adm8211_get_stats
,
1777 .get_tx_stats
= adm8211_get_tx_stats
,
1778 .get_tsf
= adm8211_get_tsft
1781 static int __devinit
adm8211_probe(struct pci_dev
*pdev
,
1782 const struct pci_device_id
*id
)
1784 struct ieee80211_hw
*dev
;
1785 struct adm8211_priv
*priv
;
1786 unsigned long mem_addr
, mem_len
;
1787 unsigned int io_addr
, io_len
;
1790 u8 perm_addr
[ETH_ALEN
];
1791 DECLARE_MAC_BUF(mac
);
1793 err
= pci_enable_device(pdev
);
1795 printk(KERN_ERR
"%s (adm8211): Cannot enable new PCI device\n",
1800 io_addr
= pci_resource_start(pdev
, 0);
1801 io_len
= pci_resource_len(pdev
, 0);
1802 mem_addr
= pci_resource_start(pdev
, 1);
1803 mem_len
= pci_resource_len(pdev
, 1);
1804 if (io_len
< 256 || mem_len
< 1024) {
1805 printk(KERN_ERR
"%s (adm8211): Too short PCI resources\n",
1807 goto err_disable_pdev
;
1811 /* check signature */
1812 pci_read_config_dword(pdev
, 0x80 /* CR32 */, ®
);
1813 if (reg
!= ADM8211_SIG1
&& reg
!= ADM8211_SIG2
) {
1814 printk(KERN_ERR
"%s (adm8211): Invalid signature (0x%x)\n",
1815 pci_name(pdev
), reg
);
1816 goto err_disable_pdev
;
1819 err
= pci_request_regions(pdev
, "adm8211");
1821 printk(KERN_ERR
"%s (adm8211): Cannot obtain PCI resources\n",
1823 return err
; /* someone else grabbed it? don't disable it */
1826 if (pci_set_dma_mask(pdev
, DMA_32BIT_MASK
) ||
1827 pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
)) {
1828 printk(KERN_ERR
"%s (adm8211): No suitable DMA available\n",
1833 pci_set_master(pdev
);
1835 dev
= ieee80211_alloc_hw(sizeof(*priv
), &adm8211_ops
);
1837 printk(KERN_ERR
"%s (adm8211): ieee80211 alloc failed\n",
1845 spin_lock_init(&priv
->lock
);
1847 SET_IEEE80211_DEV(dev
, &pdev
->dev
);
1849 pci_set_drvdata(pdev
, dev
);
1851 priv
->map
= pci_iomap(pdev
, 1, mem_len
);
1853 priv
->map
= pci_iomap(pdev
, 0, io_len
);
1856 printk(KERN_ERR
"%s (adm8211): Cannot map device memory\n",
1861 priv
->rx_ring_size
= rx_ring_size
;
1862 priv
->tx_ring_size
= tx_ring_size
;
1864 if (adm8211_alloc_rings(dev
)) {
1865 printk(KERN_ERR
"%s (adm8211): Cannot allocate TX/RX ring\n",
1870 *(u32
*)perm_addr
= le32_to_cpu((__force __le32
)ADM8211_CSR_READ(PAR0
));
1871 *(u16
*)&perm_addr
[4] =
1872 le16_to_cpu((__force __le16
)ADM8211_CSR_READ(PAR1
) & 0xFFFF);
1874 if (!is_valid_ether_addr(perm_addr
)) {
1875 printk(KERN_WARNING
"%s (adm8211): Invalid hwaddr in EEPROM!\n",
1877 random_ether_addr(perm_addr
);
1879 SET_IEEE80211_PERM_ADDR(dev
, perm_addr
);
1881 dev
->extra_tx_headroom
= sizeof(struct adm8211_tx_hdr
);
1882 dev
->flags
= IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED
;
1883 /* IEEE80211_HW_RX_INCLUDES_FCS in promisc mode */
1885 dev
->channel_change_time
= 1000;
1886 dev
->max_rssi
= 100; /* FIXME: find better value */
1888 priv
->modes
[0].mode
= MODE_IEEE80211B
;
1889 /* channel info filled in by adm8211_read_eeprom */
1890 memcpy(priv
->rates
, adm8211_rates
, sizeof(adm8211_rates
));
1891 priv
->modes
[0].num_rates
= ARRAY_SIZE(adm8211_rates
);
1892 priv
->modes
[0].rates
= priv
->rates
;
1894 dev
->queues
= 1; /* ADM8211C supports more, maybe ADM8211B too */
1896 priv
->retry_limit
= 3;
1897 priv
->ant_power
= 0x40;
1898 priv
->tx_power
= 0x40;
1899 priv
->lpf_cutoff
= 0xFF;
1900 priv
->lnags_threshold
= 0xFF;
1901 priv
->mode
= IEEE80211_IF_TYPE_INVALID
;
1903 /* Power-on issue. EEPROM won't read correctly without */
1904 if (pdev
->revision
>= ADM8211_REV_BA
) {
1905 ADM8211_CSR_WRITE(FRCTL
, 0);
1906 ADM8211_CSR_READ(FRCTL
);
1907 ADM8211_CSR_WRITE(FRCTL
, 1);
1908 ADM8211_CSR_READ(FRCTL
);
1912 err
= adm8211_read_eeprom(dev
);
1914 printk(KERN_ERR
"%s (adm8211): Can't alloc eeprom buffer\n",
1919 priv
->channel
= priv
->modes
[0].channels
[0].chan
;
1921 err
= ieee80211_register_hwmode(dev
, &priv
->modes
[0]);
1923 printk(KERN_ERR
"%s (adm8211): Can't register hwmode\n",
1928 err
= ieee80211_register_hw(dev
);
1930 printk(KERN_ERR
"%s (adm8211): Cannot register device\n",
1935 printk(KERN_INFO
"%s: hwaddr %s, Rev 0x%02x\n",
1936 wiphy_name(dev
->wiphy
), print_mac(mac
, dev
->wiphy
->perm_addr
),
1942 pci_free_consistent(pdev
,
1943 sizeof(struct adm8211_desc
) * priv
->rx_ring_size
+
1944 sizeof(struct adm8211_desc
) * priv
->tx_ring_size
,
1945 priv
->rx_ring
, priv
->rx_ring_dma
);
1946 kfree(priv
->rx_buffers
);
1949 pci_iounmap(pdev
, priv
->map
);
1952 pci_set_drvdata(pdev
, NULL
);
1953 ieee80211_free_hw(dev
);
1956 pci_release_regions(pdev
);
1959 pci_disable_device(pdev
);
1964 static void __devexit
adm8211_remove(struct pci_dev
*pdev
)
1966 struct ieee80211_hw
*dev
= pci_get_drvdata(pdev
);
1967 struct adm8211_priv
*priv
;
1972 ieee80211_unregister_hw(dev
);
1976 pci_free_consistent(pdev
,
1977 sizeof(struct adm8211_desc
) * priv
->rx_ring_size
+
1978 sizeof(struct adm8211_desc
) * priv
->tx_ring_size
,
1979 priv
->rx_ring
, priv
->rx_ring_dma
);
1981 kfree(priv
->rx_buffers
);
1982 kfree(priv
->eeprom
);
1983 pci_iounmap(pdev
, priv
->map
);
1984 pci_release_regions(pdev
);
1985 pci_disable_device(pdev
);
1986 ieee80211_free_hw(dev
);
1991 static int adm8211_suspend(struct pci_dev
*pdev
, pm_message_t state
)
1993 struct ieee80211_hw
*dev
= pci_get_drvdata(pdev
);
1994 struct adm8211_priv
*priv
= dev
->priv
;
1996 if (priv
->mode
!= IEEE80211_IF_TYPE_INVALID
) {
1997 ieee80211_stop_queues(dev
);
2001 pci_save_state(pdev
);
2002 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
2006 static int adm8211_resume(struct pci_dev
*pdev
)
2008 struct ieee80211_hw
*dev
= pci_get_drvdata(pdev
);
2009 struct adm8211_priv
*priv
= dev
->priv
;
2011 pci_set_power_state(pdev
, PCI_D0
);
2012 pci_restore_state(pdev
);
2014 if (priv
->mode
!= IEEE80211_IF_TYPE_INVALID
) {
2016 ieee80211_start_queues(dev
);
2021 #endif /* CONFIG_PM */
2024 MODULE_DEVICE_TABLE(pci
, adm8211_pci_id_table
);
2026 /* TODO: implement enable_wake */
2027 static struct pci_driver adm8211_driver
= {
2029 .id_table
= adm8211_pci_id_table
,
2030 .probe
= adm8211_probe
,
2031 .remove
= __devexit_p(adm8211_remove
),
2033 .suspend
= adm8211_suspend
,
2034 .resume
= adm8211_resume
,
2035 #endif /* CONFIG_PM */
2040 static int __init
adm8211_init(void)
2042 return pci_register_driver(&adm8211_driver
);
2046 static void __exit
adm8211_exit(void)
2048 pci_unregister_driver(&adm8211_driver
);
2052 module_init(adm8211_init
);
2053 module_exit(adm8211_exit
);