22 #include <linux/slab.h>
24 #include <linux/pci.h>
28 #include <linux/module.h>
63 { .center_freq = 2412},
64 { .center_freq = 2417},
65 { .center_freq = 2422},
66 { .center_freq = 2427},
67 { .center_freq = 2432},
68 { .center_freq = 2437},
69 { .center_freq = 2442},
70 { .center_freq = 2447},
71 { .center_freq = 2452},
72 { .center_freq = 2457},
73 { .center_freq = 2462},
74 { .center_freq = 2467},
75 { .center_freq = 2472},
76 { .center_freq = 2484},
112 unsigned int words,
i;
117 .register_read = adm8211_eeprom_register_read,
118 .register_write = adm8211_eeprom_register_write
139 priv->
rf_type = (cr49 >> 3) & 0x7;
155 pci_name(priv->
pdev), (cr49 >> 3) & 0x7);
173 pci_name(priv->
pdev), cr49 >> 3);
178 pci_name(priv->
pdev), priv->
eeprom->country_code);
180 chan_range = cranges[2];
182 chan_range = cranges[priv->
eeprom->country_code];
185 pci_name(priv->
pdev), (
int)chan_range.min, (
int)chan_range.max);
192 priv->
band.bitrates = adm8211_rates;
195 for (i = 1; i <=
ARRAY_SIZE(adm8211_channels); i++)
196 if (i < chan_range.min || i > chan_range.max)
199 switch (priv->
eeprom->specific_bbptype) {
213 pci_name(priv->
pdev), priv->
eeprom->specific_bbptype);
216 switch (priv->
eeprom->specific_rftype) {
217 case ADM8211_RFMD2948:
218 case ADM8211_RFMD2958:
219 case ADM8211_RFMD2958_RF3000_CONTROL_POWER:
220 case ADM8211_MAX2820:
221 case ADM8211_AL2210L:
234 pci_name(priv->
pdev), priv->
eeprom->specific_rftype);
240 "Transceiver=%d\n", pci_name(priv->
pdev), priv->
rf_type,
246 static inline void adm8211_write_sram(
struct ieee80211_hw *dev,
262 static void adm8211_write_sram_bytes(
struct ieee80211_hw *dev,
263 unsigned int addr,
u8 *
buf,
271 for (i = 0; i < len; i += 2) {
272 u16 val = buf[
i] | (buf[i + 1] << 8);
273 adm8211_write_sram(dev, addr + i / 2, val);
276 for (i = 0; i < len; i += 4) {
277 u32 val = (buf[i + 0] << 0 ) | (buf[i + 1] << 8 ) |
278 (buf[i + 2] << 16) | (buf[i + 3] << 24);
279 adm8211_write_sram(dev, addr + i / 4, val);
286 static void adm8211_clear_sram(
struct ieee80211_hw *dev)
293 adm8211_write_sram(dev, addr, 0);
308 static void adm8211_interrupt_tci(
struct ieee80211_hw *dev)
313 spin_lock(&priv->
lock);
315 for (dirty_tx = priv->
dirty_tx; priv->
cur_tx - dirty_tx; dirty_tx++) {
328 txi = IEEE80211_SKB_CB(skb);
335 ieee80211_tx_info_clear_status(txi);
348 if (priv->
cur_tx - dirty_tx < priv->tx_ring_size - 2)
352 spin_unlock(&priv->
lock);
356 static void adm8211_interrupt_rci(
struct ieee80211_hw *dev)
388 skb = dev_alloc_skb(pktlen);
390 pci_dma_sync_single_for_cpu(
395 skb_tail_pointer(priv->
rx_buffers[entry].skb),
397 pci_dma_sync_single_for_device(
413 pci_map_single(priv->
pdev,
414 skb_tail_pointer(newskb),
439 rx_status.
signal = 100 - rssi;
446 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status,
sizeof(rx_status));
459 #define ADM8211_INT(x) \
461 if (unlikely(stsr & ADM8211_STSR_ ## x)) \
462 wiphy_debug(dev->wiphy, "%s\n", #x); \
469 if (stsr == 0xffffffff)
476 adm8211_interrupt_rci(dev);
478 adm8211_interrupt_tci(dev);
503 #define WRITE_SYN(name,v_mask,v_shift,a_mask,a_shift,bits,prewrite,postwrite)\
504 static void adm8211_rf_write_syn_ ## name (struct ieee80211_hw *dev, \
505 u16 addr, u32 value) { \
506 struct adm8211_priv *priv = dev->priv; \
512 bitbuf = (value << v_shift) | (addr << a_shift); \
514 ADM8211_CSR_WRITE(SYNRF, ADM8211_SYNRF_IF_SELECT_1); \
515 ADM8211_CSR_READ(SYNRF); \
516 ADM8211_CSR_WRITE(SYNRF, ADM8211_SYNRF_IF_SELECT_0); \
517 ADM8211_CSR_READ(SYNRF); \
520 ADM8211_CSR_WRITE(SYNRF, ADM8211_SYNRF_WRITE_SYNDATA_0); \
521 ADM8211_CSR_READ(SYNRF); \
524 for (i = 0; i <= bits; i++) { \
525 if (bitbuf & (1 << (bits - i))) \
526 reg = ADM8211_SYNRF_WRITE_SYNDATA_1; \
528 reg = ADM8211_SYNRF_WRITE_SYNDATA_0; \
530 ADM8211_CSR_WRITE(SYNRF, reg); \
531 ADM8211_CSR_READ(SYNRF); \
533 ADM8211_CSR_WRITE(SYNRF, reg | ADM8211_SYNRF_WRITE_CLOCK_1); \
534 ADM8211_CSR_READ(SYNRF); \
535 ADM8211_CSR_WRITE(SYNRF, reg | ADM8211_SYNRF_WRITE_CLOCK_0); \
536 ADM8211_CSR_READ(SYNRF); \
539 if (postwrite == 1) { \
540 ADM8211_CSR_WRITE(SYNRF, reg | ADM8211_SYNRF_IF_SELECT_0); \
541 ADM8211_CSR_READ(SYNRF); \
543 if (postwrite == 2) { \
544 ADM8211_CSR_WRITE(SYNRF, reg | ADM8211_SYNRF_IF_SELECT_1); \
545 ADM8211_CSR_READ(SYNRF); \
548 ADM8211_CSR_WRITE(SYNRF, 0); \
549 ADM8211_CSR_READ(SYNRF); \
552 WRITE_SYN(max2820, 0x00FFF, 0, 0x0F, 12, 15, 1, 1)
553 WRITE_SYN(al2210l, 0xFFFFF, 4, 0x0F, 0, 23, 1, 1)
554 WRITE_SYN(rfmd2958, 0x3FFFF, 0, 0x1F, 18, 23, 0, 1)
555 WRITE_SYN(rfmd2948, 0x0FFFF, 4, 0x0F, 0, 21, 0, 2)
566 while (timeout > 0) {
576 "adm8211_write_bbp(%d,%d) failed prewrite (reg=0x%08x)\n",
599 while (timeout > 0) {
611 "adm8211_write_bbp(%d,%d) failed postwrite (reg=0x%08x)\n",
619 static int adm8211_rf_set_channel(
struct ieee80211_hw *dev,
unsigned int chan)
621 static const u32 adm8211_rfmd2958_reg5[] =
622 {0x22BD, 0x22D2, 0x22E8, 0x22FE, 0x2314, 0x232A, 0x2340,
623 0x2355, 0x236B, 0x2381, 0x2397, 0x23AD, 0x23C2, 0x23F7};
624 static const u32 adm8211_rfmd2958_reg6[] =
625 {0x05D17, 0x3A2E8, 0x2E8BA, 0x22E8B, 0x1745D, 0x0BA2E, 0x00000,
626 0x345D1, 0x28BA2, 0x1D174, 0x11745, 0x05D17, 0x3A2E8, 0x11745};
645 adm8211_rf_write_syn_rfmd2958(dev, 0x00, 0x04007);
646 adm8211_rf_write_syn_rfmd2958(dev, 0x02, 0x00033);
648 adm8211_rf_write_syn_rfmd2958(dev, 0x05,
649 adm8211_rfmd2958_reg5[chan - 1]);
650 adm8211_rf_write_syn_rfmd2958(dev, 0x06,
651 adm8211_rfmd2958_reg6[chan - 1]);
663 2110 : (2033 + (chan * 5))));
670 adm8211_rf_write_syn_max2820(dev, 0x3,
671 (chan == 14 ? 0x054 : (0x7 + (chan * 5))));
675 adm8211_rf_write_syn_al2210l(dev, 0x0,
676 (chan == 14 ? 0x229B4 : (0x22967 + (chan * 5))));
701 adm8211_rf_write_syn_rfmd2958(dev, 0x0B, 0x07100);
706 reg |= ant_power << 9;
707 adm8211_rf_write_syn_rfmd2958(dev, 0x0A, reg);
709 adm8211_rf_write_syn_rfmd2958(dev, 0x09, 0x00050 |
714 reg |= tx_power << 18;
731 adm8211_write_bbp(dev, 0x1d, priv->
eeprom->cr29);
751 static void adm8211_update_mode(
struct ieee80211_hw *dev)
758 switch (priv->
mode) {
780 static void adm8211_hw_init_syn(
struct ieee80211_hw *dev)
790 adm8211_rf_write_syn_rfmd2958(dev, 0x1F, 0x00000);
792 adm8211_rf_write_syn_rfmd2958(dev, 0x0C, 0x3001F);
794 adm8211_rf_write_syn_rfmd2958(dev, 0x01, 0x29C03);
796 adm8211_rf_write_syn_rfmd2958(dev, 0x03, 0x1FF6F);
798 adm8211_rf_write_syn_rfmd2958(dev, 0x04, 0x29403);
800 adm8211_rf_write_syn_rfmd2958(dev, 0x07, 0x1456F);
802 adm8211_rf_write_syn_rfmd2958(dev, 0x09,
806 adm8211_rf_write_syn_rfmd2958(dev, 0x08, 0x3FFF8);
810 adm8211_rf_write_syn_max2820(dev, 0x1, 0x01E);
811 adm8211_rf_write_syn_max2820(dev, 0x2, 0x001);
812 adm8211_rf_write_syn_max2820(dev, 0x3, 0x054);
813 adm8211_rf_write_syn_max2820(dev, 0x4, 0x310);
814 adm8211_rf_write_syn_max2820(dev, 0x5, 0x000);
818 adm8211_rf_write_syn_al2210l(dev, 0x0, 0x0196C);
819 adm8211_rf_write_syn_al2210l(dev, 0x1, 0x007CB);
820 adm8211_rf_write_syn_al2210l(dev, 0x2, 0x3582F);
821 adm8211_rf_write_syn_al2210l(dev, 0x3, 0x010A9);
822 adm8211_rf_write_syn_al2210l(dev, 0x4, 0x77280);
823 adm8211_rf_write_syn_al2210l(dev, 0x5, 0x45641);
824 adm8211_rf_write_syn_al2210l(dev, 0x6, 0xEA130);
825 adm8211_rf_write_syn_al2210l(dev, 0x7, 0x80000);
826 adm8211_rf_write_syn_al2210l(dev, 0x8, 0x7850F);
827 adm8211_rf_write_syn_al2210l(dev, 0x9, 0xF900C);
828 adm8211_rf_write_syn_al2210l(dev, 0xA, 0x00000);
829 adm8211_rf_write_syn_al2210l(dev, 0xB, 0x00000);
838 static int adm8211_hw_init_bbp(
struct ieee80211_hw *dev)
869 switch (priv->
pdev->revision) {
898 adm8211_hw_init_syn(dev);
923 if (priv->
eeprom->major_version < 2) {
924 adm8211_write_bbp(dev, 0x1c, 0x00);
925 adm8211_write_bbp(dev, 0x1d, 0x80);
928 adm8211_write_bbp(dev, 0x1c, priv->
eeprom->cr28);
930 adm8211_write_bbp(dev, 0x1c, 0x00);
932 adm8211_write_bbp(dev, 0x1d, priv->
eeprom->cr29);
936 adm8211_write_bbp(dev, 0x00, 0xFF);
938 adm8211_write_bbp(dev, 0x07, 0x0A);
944 adm8211_write_bbp(dev, 0x00, 0x00);
945 adm8211_write_bbp(dev, 0x01, 0x00);
946 adm8211_write_bbp(dev, 0x02, 0x00);
947 adm8211_write_bbp(dev, 0x03, 0x00);
948 adm8211_write_bbp(dev, 0x06, 0x0f);
949 adm8211_write_bbp(dev, 0x09, 0x00);
950 adm8211_write_bbp(dev, 0x0a, 0x00);
951 adm8211_write_bbp(dev, 0x0b, 0x00);
952 adm8211_write_bbp(dev, 0x0c, 0x00);
953 adm8211_write_bbp(dev, 0x0f, 0xAA);
954 adm8211_write_bbp(dev, 0x10, 0x8c);
955 adm8211_write_bbp(dev, 0x11, 0x43);
956 adm8211_write_bbp(dev, 0x18, 0x40);
957 adm8211_write_bbp(dev, 0x20, 0x23);
958 adm8211_write_bbp(dev, 0x21, 0x02);
959 adm8211_write_bbp(dev, 0x22, 0x28);
960 adm8211_write_bbp(dev, 0x23, 0x30);
961 adm8211_write_bbp(dev, 0x24, 0x2d);
962 adm8211_write_bbp(dev, 0x28, 0x35);
963 adm8211_write_bbp(dev, 0x2a, 0x8c);
964 adm8211_write_bbp(dev, 0x2b, 0x81);
965 adm8211_write_bbp(dev, 0x2c, 0x44);
966 adm8211_write_bbp(dev, 0x2d, 0x0A);
967 adm8211_write_bbp(dev, 0x29, 0x40);
968 adm8211_write_bbp(dev, 0x60, 0x08);
969 adm8211_write_bbp(dev, 0x64, 0x01);
973 adm8211_write_bbp(dev, 0x00, 0x00);
974 adm8211_write_bbp(dev, 0x01, 0x00);
975 adm8211_write_bbp(dev, 0x02, 0x00);
976 adm8211_write_bbp(dev, 0x03, 0x00);
977 adm8211_write_bbp(dev, 0x06, 0x0f);
978 adm8211_write_bbp(dev, 0x09, 0x05);
979 adm8211_write_bbp(dev, 0x0a, 0x02);
980 adm8211_write_bbp(dev, 0x0b, 0x00);
981 adm8211_write_bbp(dev, 0x0c, 0x0f);
982 adm8211_write_bbp(dev, 0x0f, 0x55);
983 adm8211_write_bbp(dev, 0x10, 0x8d);
984 adm8211_write_bbp(dev, 0x11, 0x43);
985 adm8211_write_bbp(dev, 0x18, 0x4a);
986 adm8211_write_bbp(dev, 0x20, 0x20);
987 adm8211_write_bbp(dev, 0x21, 0x02);
988 adm8211_write_bbp(dev, 0x22, 0x23);
989 adm8211_write_bbp(dev, 0x23, 0x30);
990 adm8211_write_bbp(dev, 0x24, 0x2d);
991 adm8211_write_bbp(dev, 0x2a, 0x8c);
992 adm8211_write_bbp(dev, 0x2b, 0x81);
993 adm8211_write_bbp(dev, 0x2c, 0x44);
994 adm8211_write_bbp(dev, 0x29, 0x4a);
995 adm8211_write_bbp(dev, 0x60, 0x2b);
996 adm8211_write_bbp(dev, 0x64, 0x01);
1000 adm8211_write_bbp(dev, 0x00, 0x00);
1001 adm8211_write_bbp(dev, 0x01, 0x00);
1002 adm8211_write_bbp(dev, 0x02, 0x00);
1003 adm8211_write_bbp(dev, 0x03, 0x00);
1004 adm8211_write_bbp(dev, 0x06, 0x0f);
1005 adm8211_write_bbp(dev, 0x07, 0x05);
1006 adm8211_write_bbp(dev, 0x08, 0x03);
1007 adm8211_write_bbp(dev, 0x09, 0x00);
1008 adm8211_write_bbp(dev, 0x0a, 0x00);
1009 adm8211_write_bbp(dev, 0x0b, 0x00);
1010 adm8211_write_bbp(dev, 0x0c, 0x10);
1011 adm8211_write_bbp(dev, 0x0f, 0x55);
1012 adm8211_write_bbp(dev, 0x10, 0x8d);
1013 adm8211_write_bbp(dev, 0x11, 0x43);
1014 adm8211_write_bbp(dev, 0x18, 0x4a);
1015 adm8211_write_bbp(dev, 0x20, 0x20);
1016 adm8211_write_bbp(dev, 0x21, 0x02);
1017 adm8211_write_bbp(dev, 0x22, 0x23);
1018 adm8211_write_bbp(dev, 0x23, 0x30);
1019 adm8211_write_bbp(dev, 0x24, 0x2d);
1020 adm8211_write_bbp(dev, 0x2a, 0xaa);
1021 adm8211_write_bbp(dev, 0x2b, 0x81);
1022 adm8211_write_bbp(dev, 0x2c, 0x44);
1023 adm8211_write_bbp(dev, 0x29, 0xfa);
1024 adm8211_write_bbp(dev, 0x60, 0x2d);
1025 adm8211_write_bbp(dev, 0x64, 0x01);
1055 u8 rate_buf[12] = {0};
1060 for (i = 0; i <
ARRAY_SIZE(adm8211_rates); i++)
1061 rate_buf[i + 1] = (adm8211_rates[i].
bitrate / 5) | 0x80;
1102 case 0x8: reg |= (0x1 << 14);
1104 case 0x16: reg |= (0x2 << 14);
1106 case 0x32: reg |= (0x3 << 14);
1108 default: reg |= (0x0 << 14);
1116 reg &= ~(0xF << 28);
1117 reg |= (1 << 28) | (1 << 31);
1131 adm8211_set_rate(dev);
1161 reg &= ~(0xffff << 8);
1186 adm8211_hw_init_bbp(dev);
1234 reg |= (1 << 4) | (1 << 5);
1238 reg &= ~((1 << 4) | (1 << 5));
1248 adm8211_clear_sram(dev);
1268 static void adm8211_set_interval(
struct ieee80211_hw *dev,
1269 unsigned short bi,
unsigned short li)
1276 reg = (bi << 16) | li;
1288 reg |= (bssid[4] << 16) | (bssid[5] << 24);
1298 if (channel != priv->
channel) {
1300 adm8211_rf_set_channel(dev, priv->
channel);
1306 static void adm8211_bss_info_changed(
struct ieee80211_hw *dev,
1317 adm8211_set_bssid(dev, conf->
bssid);
1325 unsigned int bit_nr;
1329 mc_filter[1] = mc_filter[0] = 0;
1335 mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31);
1338 return mc_filter[0] | ((
u64)(mc_filter[1]) << 32);
1341 static void adm8211_configure_filter(
struct ieee80211_hw *dev,
1342 unsigned int changed_flags,
1343 unsigned int *total_flags,
1346 static const u8 bcast[
ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
1348 unsigned int new_flags;
1351 mc_filter[0] = multicast;
1352 mc_filter[1] = multicast >> 32;
1360 mc_filter[1] = mc_filter[0] = ~0;
1361 }
else if (*total_flags &
FIF_ALLMULTI || multicast == ~(0ULL)) {
1365 mc_filter[1] = mc_filter[0] = ~0;
1382 adm8211_set_bssid(dev, bcast);
1384 adm8211_set_bssid(dev, priv->
bssid);
1388 *total_flags = new_flags;
1391 static int adm8211_add_interface(
struct ieee80211_hw *dev,
1398 switch (vif->
type) {
1411 adm8211_update_mode(dev);
1418 static void adm8211_remove_interface(
struct ieee80211_hw *dev,
1425 static int adm8211_init_rings(
struct ieee80211_hw *dev)
1451 skb_tail_pointer(rx_info->
skb),
1476 static void adm8211_free_rings(
struct ieee80211_hw *dev)
1497 pci_unmap_single(priv->
pdev,
1512 retval = adm8211_hw_reset(dev);
1518 retval = adm8211_init_rings(dev);
1525 adm8211_hw_init(dev);
1526 adm8211_rf_set_channel(dev, priv->
channel);
1539 adm8211_update_mode(dev);
1542 adm8211_set_interval(dev, 100, 10);
1561 adm8211_free_rings(dev);
1564 static void adm8211_calc_durations(
int *dur,
int *plcp,
size_t payload_len,
int len,
1565 int plcp_signal,
int short_preamble)
1570 #define IEEE80211_DUR_DS_LONG_PREAMBLE 144
1571 #define IEEE80211_DUR_DS_SHORT_PREAMBLE 72
1572 #define IEEE80211_DUR_DS_FAST_PLCPHDR 24
1573 #define IEEE80211_DUR_DS_SLOW_PLCPHDR 48
1574 #define IEEE80211_DUR_DS_SLOW_ACK 112
1575 #define IEEE80211_DUR_DS_FAST_ACK 56
1576 #define IEEE80211_DUR_DS_SLOW_CTS 112
1577 #define IEEE80211_DUR_DS_FAST_CTS 56
1578 #define IEEE80211_DUR_DS_SLOT 20
1579 #define IEEE80211_DUR_DS_SIFS 10
1583 *dur = (80 * (24 +
payload_len) + plcp_signal - 1)
1591 IEEE80211_DUR_DS_SLOW_CTS + IEEE80211_DUR_DS_SLOW_ACK;
1597 IEEE80211_DUR_DS_FAST_CTS + IEEE80211_DUR_DS_FAST_ACK;
1600 if (!short_preamble)
1603 3 * (IEEE80211_DUR_DS_SLOW_PLCPHDR -
1604 IEEE80211_DUR_DS_FAST_PLCPHDR);
1607 *plcp = (80 * len) / plcp_signal;
1608 remainder = (80 * len) % plcp_signal;
1610 remainder <= 30 && remainder > 0)
1611 *plcp = (*plcp | 0x8000) + 1;
1622 unsigned long flags;
1627 mapping = pci_map_single(priv->
pdev, skb->
data, skb->
len,
1657 spin_unlock_irqrestore(&priv->
lock, flags);
1670 int plcp, dur, len, plcp_signal, short_preamble;
1673 struct ieee80211_rate *txrate = ieee80211_get_tx_rate(dev, info);
1676 rc_flags = info->
control.rates[0].flags;
1678 plcp_signal = txrate->
bitrate;
1685 payload_len = skb->
len;
1688 memset(txhdr, 0,
sizeof(*txhdr));
1690 txhdr->
signal = plcp_signal;
1694 len = hdrlen + payload_len +
FCS_LEN;
1697 adm8211_calc_durations(&dur, &plcp, payload_len,
1698 len, plcp_signal, short_preamble);
1714 adm8211_tx_raw(dev, skb, plcp_signal, hdrlen);
1717 static int adm8211_alloc_rings(
struct ieee80211_hw *dev)
1752 .start = adm8211_start,
1753 .stop = adm8211_stop,
1754 .add_interface = adm8211_add_interface,
1755 .remove_interface = adm8211_remove_interface,
1756 .config = adm8211_config,
1757 .bss_info_changed = adm8211_bss_info_changed,
1758 .prepare_multicast = adm8211_prepare_multicast,
1759 .configure_filter = adm8211_configure_filter,
1760 .get_stats = adm8211_get_stats,
1761 .get_tsf = adm8211_get_tsft
1769 unsigned long mem_addr, mem_len;
1786 if (io_len < 256 || mem_len < 1024) {
1789 goto err_disable_pdev;
1794 pci_read_config_dword(pdev, 0x80 , ®);
1797 pci_name(pdev), reg);
1798 goto err_disable_pdev;
1829 SET_IEEE80211_DEV(dev, &pdev->
dev);
1831 pci_set_drvdata(pdev, dev);
1833 priv->
map = pci_iomap(pdev, 1, mem_len);
1835 priv->
map = pci_iomap(pdev, 0, io_len);
1846 if (adm8211_alloc_rings(dev)) {
1853 *(
__le16 *)&perm_addr[4] =
1856 if (!is_valid_ether_addr(perm_addr)) {
1859 eth_random_addr(perm_addr);
1861 SET_IEEE80211_PERM_ADDR(dev, perm_addr);
1889 err = adm8211_read_eeprom(dev);
1904 goto err_free_eeprom;
1926 pci_set_drvdata(pdev,
NULL);
1972 static int adm8211_resume(
struct pci_dev *pdev)
1986 .id_table = adm8211_pci_id_table,
1987 .probe = adm8211_probe,
1990 .suspend = adm8211_suspend,
1991 .resume = adm8211_resume,