20 #include <linux/pci.h>
21 #include <linux/slab.h>
25 #include <linux/module.h>
58 { .bitrate = 10, .hw_value = 0, },
59 { .bitrate = 20, .hw_value = 1, },
60 { .bitrate = 55, .hw_value = 2, },
61 { .bitrate = 110, .hw_value = 3, },
62 { .bitrate = 60, .hw_value = 4, },
63 { .bitrate = 90, .hw_value = 5, },
64 { .bitrate = 120, .hw_value = 6, },
65 { .bitrate = 180, .hw_value = 7, },
66 { .bitrate = 240, .hw_value = 8, },
67 { .bitrate = 360, .hw_value = 9, },
68 { .bitrate = 480, .hw_value = 10, },
69 { .bitrate = 540, .hw_value = 11, },
73 { .center_freq = 2412 },
74 { .center_freq = 2417 },
75 { .center_freq = 2422 },
76 { .center_freq = 2427 },
77 { .center_freq = 2432 },
78 { .center_freq = 2437 },
79 { .center_freq = 2442 },
80 { .center_freq = 2447 },
81 { .center_freq = 2452 },
82 { .center_freq = 2457 },
83 { .center_freq = 2462 },
84 { .center_freq = 2467 },
85 { .center_freq = 2472 },
86 { .center_freq = 2484 },
96 buf = (data << 8) | addr;
101 if (rtl818x_ioread8(priv, &priv->
map->PHY[2]) == (data & 0xFF))
109 unsigned int count = 32;
132 pci_unmap_single(priv->
pdev,
137 rx_status.
antenna = (flags2 >> 15) & 1;
138 rx_status.
rate_idx = (flags >> 20) & 0xF;
139 agc = (flags2 >> 17) & 0x7F;
147 signal = priv->
rf->calc_rssi(agc, sq);
149 rx_status.
signal = signal;
150 rx_status.
freq = dev->
conf.channel->center_freq;
151 rx_status.
band = dev->
conf.channel->band;
157 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status,
sizeof(rx_status));
163 pci_map_single(priv->
pdev, skb_tail_pointer(skb),
182 while (skb_queue_len(&ring->
queue)) {
192 skb = __skb_dequeue(&ring->
queue);
196 info = IEEE80211_SKB_CB(skb);
197 ieee80211_tx_info_clear_status(info);
203 info->
status.rates[0].count = (flags & 0xFF) + 1;
204 info->
status.rates[1].idx = -1;
218 spin_lock(&priv->
lock);
219 reg = rtl818x_ioread16(priv, &priv->
map->INT_STATUS);
221 spin_unlock(&priv->
lock);
225 rtl818x_iowrite16(priv, &priv->
map->INT_STATUS, reg);
228 rtl8180_handle_tx(dev, 3);
231 rtl8180_handle_tx(dev, 2);
234 rtl8180_handle_tx(dev, 1);
237 rtl8180_handle_tx(dev, 0);
240 rtl8180_handle_rx(dev);
242 spin_unlock(&priv->
lock);
257 unsigned int idx, prio;
264 prio = skb_get_queue_mapping(skb);
272 (ieee80211_get_tx_rate(dev, info)->hw_value << 24) |
279 rc_flags = info->
control.rates[0].flags;
282 tx_flags |= ieee80211_get_rts_cts_rate(dev, info)->hw_value << 19;
285 tx_flags |= ieee80211_get_rts_cts_rate(dev, info)->hw_value << 19;
288 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS)
293 unsigned int remainder;
296 (ieee80211_get_tx_rate(dev, info)->
bitrate * 2) / 10);
297 remainder = (16 * (skb->
len + 4)) %
298 ((ieee80211_get_tx_rate(dev, info)->bitrate * 2) / 10);
313 entry = &ring->
desc[idx];
320 ieee80211_get_alt_retry_rate(dev, info, 0)->bitrate << 4 : 0;
323 __skb_queue_tail(&ring->
queue, skb);
327 spin_unlock_irqrestore(&priv->
lock, flags);
329 rtl818x_iowrite8(priv, &priv->
map->TX_DMA_POLLING, (1 << (prio + 4)));
337 reg = rtl818x_ioread8(priv, &priv->
map->CONFIG3);
338 rtl818x_iowrite8(priv, &priv->
map->CONFIG3,
340 rtl818x_iowrite32(priv, &priv->
map->ANAPARAM, anaparam);
341 rtl818x_iowrite8(priv, &priv->
map->CONFIG3,
351 rtl818x_iowrite8(priv, &priv->
map->CMD, 0);
352 rtl818x_ioread8(priv, &priv->
map->CMD);
356 rtl818x_iowrite16(priv, &priv->
map->INT_MASK, 0);
357 rtl818x_ioread8(priv, &priv->
map->CMD);
359 reg = rtl818x_ioread8(priv, &priv->
map->CMD);
363 rtl818x_ioread8(priv, &priv->
map->CMD);
373 rtl818x_ioread8(priv, &priv->
map->CMD);
376 if (rtl818x_ioread8(priv, &priv->
map->CONFIG3) & (1 << 3)) {
378 reg = rtl818x_ioread8(priv, &priv->
map->CONFIG3);
380 rtl818x_iowrite8(priv, &priv->
map->CONFIG3, reg);
381 reg = rtl818x_ioread16(priv, &priv->
map->FEMR);
382 reg |= (1 << 15) | (1 << 14) | (1 << 4);
383 rtl818x_iowrite16(priv, &priv->
map->FEMR, reg);
386 rtl818x_iowrite8(priv, &priv->
map->MSR, 0);
392 rtl818x_iowrite32(priv, &priv->
map->TBDA, priv->
tx_ring[3].dma);
393 rtl818x_iowrite32(priv, &priv->
map->THPDA, priv->
tx_ring[2].dma);
394 rtl818x_iowrite32(priv, &priv->
map->TNPDA, priv->
tx_ring[1].dma);
395 rtl818x_iowrite32(priv, &priv->
map->TLPDA, priv->
tx_ring[0].dma);
399 reg = rtl818x_ioread8(priv, &priv->
map->CONFIG2);
400 rtl818x_iowrite8(priv, &priv->
map->CONFIG2, reg & ~(1 << 3));
402 reg = rtl818x_ioread8(priv, &priv->
map->CONFIG2);
403 rtl818x_iowrite8(priv, &priv->
map->CONFIG2, reg | (1 << 4));
411 rtl818x_iowrite32(priv, &priv->
map->INT_TIMEOUT, 0);
414 rtl818x_iowrite8(priv, &priv->
map->WPA_CONF, 0);
415 rtl818x_iowrite8(priv, &priv->
map->RATE_FALLBACK, 0x81);
416 rtl818x_iowrite8(priv, &priv->
map->RESP_RATE, (8 << 4) | 0);
418 rtl818x_iowrite16(priv, &priv->
map->BRSR, 0x01F3);
421 reg = rtl818x_ioread8(priv, &priv->
map->GP_ENABLE);
422 rtl818x_iowrite8(priv, &priv->
map->GP_ENABLE, reg & ~(1 << 6));
424 reg = rtl818x_ioread8(priv, &priv->
map->CONFIG3);
425 rtl818x_iowrite8(priv, &priv->
map->CONFIG3, reg | (1 << 2));
428 rtl818x_iowrite16(priv, &priv->
map->BRSR, 0x1);
429 rtl818x_iowrite8(priv, &priv->
map->SECURITY, 0);
431 rtl818x_iowrite8(priv, &priv->
map->PHY_DELAY, 0x6);
432 rtl818x_iowrite8(priv, &priv->
map->CARRIER_SENSE_COUNTER, 0x4C);
437 rtl818x_iowrite16(priv, &priv->
map->BRSR, 0x01F3);
441 static int rtl8180_init_rx_ring(
struct ieee80211_hw *dev)
459 for (i = 0; i < 32; i++) {
468 *mapping = pci_map_single(priv->
pdev, skb_tail_pointer(skb),
478 static void rtl8180_free_rx_ring(
struct ieee80211_hw *dev)
483 for (i = 0; i < 32; i++) {
488 pci_unmap_single(priv->
pdev,
499 static int rtl8180_init_tx_ring(
struct ieee80211_hw *dev,
500 unsigned int prio,
unsigned int entries)
508 if (!ring || (
unsigned long)ring & 0xFF) {
514 memset(ring, 0,
sizeof(*ring)*entries);
519 skb_queue_head_init(&priv->
tx_ring[prio].queue);
528 static void rtl8180_free_tx_ring(
struct ieee80211_hw *dev,
unsigned int prio)
533 while (skb_queue_len(&ring->
queue)) {
554 ret = rtl8180_init_rx_ring(dev);
558 for (i = 0; i < 4; i++)
559 if ((ret = rtl8180_init_tx_ring(dev, i, 16)))
562 ret = rtl8180_init_hw(dev);
567 rtl818x_iowrite32(priv, &priv->
map->TBDA, priv->
tx_ring[3].dma);
568 rtl818x_iowrite32(priv, &priv->
map->THPDA, priv->
tx_ring[2].dma);
569 rtl818x_iowrite32(priv, &priv->
map->TNPDA, priv->
tx_ring[1].dma);
570 rtl818x_iowrite32(priv, &priv->
map->TLPDA, priv->
tx_ring[0].dma);
579 rtl818x_iowrite16(priv, &priv->
map->INT_MASK, 0xFFFF);
581 rtl818x_iowrite32(priv, &priv->
map->MAR[0], ~0);
582 rtl818x_iowrite32(priv, &priv->
map->MAR[1], ~0);
602 rtl818x_iowrite32(priv, &priv->
map->RX_CONF, reg);
605 reg = rtl818x_ioread8(priv, &priv->
map->CW_CONF);
608 rtl818x_iowrite8(priv, &priv->
map->CW_CONF, reg);
610 reg = rtl818x_ioread8(priv, &priv->
map->TX_AGC_CTL);
614 rtl818x_iowrite8(priv, &priv->
map->TX_AGC_CTL, reg);
617 rtl818x_iowrite8(priv, (
u8 __iomem *)priv->
map + 0xec, 0x3f);
620 reg = rtl818x_ioread32(priv, &priv->
map->TX_CONF);
632 rtl818x_iowrite32(priv, &priv->
map->TX_CONF, reg);
634 reg = rtl818x_ioread8(priv, &priv->
map->CMD);
637 rtl818x_iowrite8(priv, &priv->
map->CMD, reg);
642 rtl8180_free_rx_ring(dev);
643 for (i = 0; i < 4; i++)
645 rtl8180_free_tx_ring(dev, i);
656 rtl818x_iowrite16(priv, &priv->
map->INT_MASK, 0);
658 reg = rtl818x_ioread8(priv, &priv->
map->CMD);
661 rtl818x_iowrite8(priv, &priv->
map->CMD, reg);
666 reg = rtl818x_ioread8(priv, &priv->
map->CONFIG4);
672 rtl8180_free_rx_ring(dev);
673 for (i = 0; i < 4; i++)
674 rtl8180_free_tx_ring(dev, i);
682 return rtl818x_ioread32(priv, &priv->
map->TSFT[0]) |
683 (
u64)(rtl818x_ioread32(priv, &priv->
map->TSFT[1])) << 32;
701 skb = ieee80211_beacon_get(dev, vif);
710 mgmt->
u.beacon.timestamp =
cpu_to_le64(rtl8180_get_tsf(dev, vif));
713 skb_set_queue_mapping(skb, 0);
715 rtl8180_tx(dev,
NULL, skb);
726 static int rtl8180_add_interface(
struct ieee80211_hw *dev,
764 static void rtl8180_remove_interface(
struct ieee80211_hw *dev,
776 priv->
rf->set_chan(dev, conf);
781 static void rtl8180_bss_info_changed(
struct ieee80211_hw *dev,
795 rtl818x_iowrite8(priv, &priv->
map->BSSID[i],
798 if (is_valid_ether_addr(info->
bssid)) {
805 rtl818x_iowrite8(priv, &priv->
map->MSR, reg);
809 priv->
rf->conf_erp(dev, info);
827 static void rtl8180_configure_filter(
struct ieee80211_hw *dev,
828 unsigned int changed_flags,
829 unsigned int *total_flags,
856 rtl818x_iowrite32(priv, &priv->
map->RX_CONF, priv->
rx_conf);
861 .start = rtl8180_start,
862 .stop = rtl8180_stop,
863 .add_interface = rtl8180_add_interface,
864 .remove_interface = rtl8180_remove_interface,
865 .config = rtl8180_config,
866 .bss_info_changed = rtl8180_bss_info_changed,
867 .prepare_multicast = rtl8180_prepare_multicast,
868 .configure_filter = rtl8180_configure_filter,
869 .get_tsf = rtl8180_get_tsf,
876 u8 reg = rtl818x_ioread8(priv, &priv->
map->EEPROM_CMD);
899 rtl818x_iowrite8(priv, &priv->
map->EEPROM_CMD, reg);
900 rtl818x_ioread8(priv, &priv->
map->EEPROM_CMD);
909 unsigned long mem_addr, mem_len;
913 const char *chip_name, *rf_name =
NULL;
946 (err = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(32)))) {
966 SET_IEEE80211_DEV(dev, &pdev->
dev);
967 pci_set_drvdata(pdev, dev);
969 priv->
map = pci_iomap(pdev, 1, mem_len);
971 priv->
map = pci_iomap(pdev, 0, io_len);
982 memcpy(priv->
channels, rtl818x_channels,
sizeof(rtl818x_channels));
983 memcpy(priv->
rates, rtl818x_rates,
sizeof(rtl818x_rates));
989 priv->
band.n_bitrates = 4;
1001 reg = rtl818x_ioread32(priv, &priv->
map->TX_CONF);
1005 chip_name =
"RTL8180";
1008 chip_name =
"RTL8180vF";
1011 chip_name =
"RTL8185";
1014 chip_name =
"RTL8185vD";
1018 pci_name(pdev), reg >> 25);
1031 if (rtl818x_ioread32(priv, &priv->
map->RX_CONF) & (1 << 6))
1037 rtl818x_ioread8(priv, &priv->
map->EEPROM_CMD);
1042 switch (eeprom_val) {
1043 case 1: rf_name =
"Intersil";
1045 case 2: rf_name =
"RFMD";
1056 rf_name =
"RTL8255";
1060 pci_name(pdev), eeprom_val);
1066 pci_name(pdev), rf_name);
1080 if (!is_valid_ether_addr(mac_addr)) {
1082 " randomly generated MAC addr\n", pci_name(pdev));
1083 eth_random_addr(mac_addr);
1085 SET_IEEE80211_PERM_ADDR(dev, mac_addr);
1088 for (i = 0; i < 14; i += 2) {
1091 priv->
channels[
i].hw_value = txpwr & 0xFF;
1092 priv->
channels[i + 1].hw_value = txpwr >> 8;
1097 for (i = 0; i < 14; i += 2) {
1100 priv->
channels[
i].hw_value |= (txpwr & 0xFF) << 8;
1101 priv->
channels[i + 1].hw_value |= txpwr & 0xFF00;
1117 mac_addr, chip_name, priv->
rf->name);
1125 pci_set_drvdata(pdev,
NULL);
1160 static int rtl8180_resume(
struct pci_dev *pdev)
1170 .name = KBUILD_MODNAME,
1171 .id_table = rtl8180_table,
1172 .probe = rtl8180_probe,
1175 .suspend = rtl8180_suspend,
1176 .resume = rtl8180_resume,