Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Linux device driver for RTL8180 / RTL8185 |
| 4 | * |
| 5 | * Copyright 2007 Michael Wu <flamingice@sourmilk.net> |
| 6 | * Copyright 2007 Andrea Merello <andreamrl@tiscali.it> |
| 7 | * |
| 8 | * Based on the r8180 driver, which is: |
| 9 | * Copyright 2004-2005 Andrea Merello <andreamrl@tiscali.it>, et al. |
| 10 | * |
| 11 | * Thanks to Realtek for their support! |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License version 2 as |
| 15 | * published by the Free Software Foundation. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/pci.h> |
| 20 | #include <linux/delay.h> |
| 21 | #include <linux/etherdevice.h> |
| 22 | #include <linux/eeprom_93cx6.h> |
| 23 | #include <net/mac80211.h> |
| 24 | |
| 25 | #include "rtl8180.h" |
| 26 | #include "rtl8180_rtl8225.h" |
| 27 | #include "rtl8180_sa2400.h" |
| 28 | #include "rtl8180_max2820.h" |
| 29 | #include "rtl8180_grf5101.h" |
| 30 | |
| 31 | MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>"); |
| 32 | MODULE_AUTHOR("Andrea Merello <andreamrl@tiscali.it>"); |
| 33 | MODULE_DESCRIPTION("RTL8180 / RTL8185 PCI wireless driver"); |
| 34 | MODULE_LICENSE("GPL"); |
| 35 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 36 | static DEFINE_PCI_DEVICE_TABLE(rtl8180_table) = { |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 37 | /* rtl8185 */ |
| 38 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8185) }, |
Adrian Bassett | 4fcc547 | 2008-01-23 16:38:33 +0000 | [diff] [blame] | 39 | { PCI_DEVICE(PCI_VENDOR_ID_BELKIN, 0x700f) }, |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 40 | { PCI_DEVICE(PCI_VENDOR_ID_BELKIN, 0x701f) }, |
| 41 | |
| 42 | /* rtl8180 */ |
| 43 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8180) }, |
| 44 | { PCI_DEVICE(0x1799, 0x6001) }, |
| 45 | { PCI_DEVICE(0x1799, 0x6020) }, |
| 46 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x3300) }, |
| 47 | { } |
| 48 | }; |
| 49 | |
| 50 | MODULE_DEVICE_TABLE(pci, rtl8180_table); |
| 51 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 52 | static const struct ieee80211_rate rtl818x_rates[] = { |
| 53 | { .bitrate = 10, .hw_value = 0, }, |
| 54 | { .bitrate = 20, .hw_value = 1, }, |
| 55 | { .bitrate = 55, .hw_value = 2, }, |
| 56 | { .bitrate = 110, .hw_value = 3, }, |
| 57 | { .bitrate = 60, .hw_value = 4, }, |
| 58 | { .bitrate = 90, .hw_value = 5, }, |
| 59 | { .bitrate = 120, .hw_value = 6, }, |
| 60 | { .bitrate = 180, .hw_value = 7, }, |
| 61 | { .bitrate = 240, .hw_value = 8, }, |
| 62 | { .bitrate = 360, .hw_value = 9, }, |
| 63 | { .bitrate = 480, .hw_value = 10, }, |
| 64 | { .bitrate = 540, .hw_value = 11, }, |
| 65 | }; |
| 66 | |
| 67 | static const struct ieee80211_channel rtl818x_channels[] = { |
| 68 | { .center_freq = 2412 }, |
| 69 | { .center_freq = 2417 }, |
| 70 | { .center_freq = 2422 }, |
| 71 | { .center_freq = 2427 }, |
| 72 | { .center_freq = 2432 }, |
| 73 | { .center_freq = 2437 }, |
| 74 | { .center_freq = 2442 }, |
| 75 | { .center_freq = 2447 }, |
| 76 | { .center_freq = 2452 }, |
| 77 | { .center_freq = 2457 }, |
| 78 | { .center_freq = 2462 }, |
| 79 | { .center_freq = 2467 }, |
| 80 | { .center_freq = 2472 }, |
| 81 | { .center_freq = 2484 }, |
| 82 | }; |
| 83 | |
| 84 | |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 85 | void rtl8180_write_phy(struct ieee80211_hw *dev, u8 addr, u32 data) |
| 86 | { |
| 87 | struct rtl8180_priv *priv = dev->priv; |
| 88 | int i = 10; |
| 89 | u32 buf; |
| 90 | |
| 91 | buf = (data << 8) | addr; |
| 92 | |
| 93 | rtl818x_iowrite32(priv, (__le32 __iomem *)&priv->map->PHY[0], buf | 0x80); |
| 94 | while (i--) { |
| 95 | rtl818x_iowrite32(priv, (__le32 __iomem *)&priv->map->PHY[0], buf); |
| 96 | if (rtl818x_ioread8(priv, &priv->map->PHY[2]) == (data & 0xFF)) |
| 97 | return; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | static void rtl8180_handle_rx(struct ieee80211_hw *dev) |
| 102 | { |
| 103 | struct rtl8180_priv *priv = dev->priv; |
| 104 | unsigned int count = 32; |
| 105 | |
| 106 | while (count--) { |
| 107 | struct rtl8180_rx_desc *entry = &priv->rx_ring[priv->rx_idx]; |
| 108 | struct sk_buff *skb = priv->rx_buf[priv->rx_idx]; |
| 109 | u32 flags = le32_to_cpu(entry->flags); |
| 110 | |
Herton Ronaldo Krzesinski | 38e3b0d | 2008-07-16 11:44:18 -0300 | [diff] [blame] | 111 | if (flags & RTL818X_RX_DESC_FLAG_OWN) |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 112 | return; |
| 113 | |
Herton Ronaldo Krzesinski | 38e3b0d | 2008-07-16 11:44:18 -0300 | [diff] [blame] | 114 | if (unlikely(flags & (RTL818X_RX_DESC_FLAG_DMA_FAIL | |
| 115 | RTL818X_RX_DESC_FLAG_FOF | |
| 116 | RTL818X_RX_DESC_FLAG_RX_ERR))) |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 117 | goto done; |
| 118 | else { |
| 119 | u32 flags2 = le32_to_cpu(entry->flags2); |
| 120 | struct ieee80211_rx_status rx_status = {0}; |
| 121 | struct sk_buff *new_skb = dev_alloc_skb(MAX_RX_SIZE); |
| 122 | |
| 123 | if (unlikely(!new_skb)) |
| 124 | goto done; |
| 125 | |
| 126 | pci_unmap_single(priv->pdev, |
| 127 | *((dma_addr_t *)skb->cb), |
| 128 | MAX_RX_SIZE, PCI_DMA_FROMDEVICE); |
| 129 | skb_put(skb, flags & 0xFFF); |
| 130 | |
| 131 | rx_status.antenna = (flags2 >> 15) & 1; |
| 132 | /* TODO: improve signal/rssi reporting */ |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 133 | rx_status.signal = (flags2 >> 8) & 0x7F; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 134 | /* XXX: is this correct? */ |
| 135 | rx_status.rate_idx = (flags >> 20) & 0xF; |
| 136 | rx_status.freq = dev->conf.channel->center_freq; |
| 137 | rx_status.band = dev->conf.channel->band; |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 138 | rx_status.mactime = le64_to_cpu(entry->tsft); |
| 139 | rx_status.flag |= RX_FLAG_TSFT; |
Herton Ronaldo Krzesinski | 38e3b0d | 2008-07-16 11:44:18 -0300 | [diff] [blame] | 140 | if (flags & RTL818X_RX_DESC_FLAG_CRC32_ERR) |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 141 | rx_status.flag |= RX_FLAG_FAILED_FCS_CRC; |
| 142 | |
Johannes Berg | f1d58c2 | 2009-06-17 13:13:00 +0200 | [diff] [blame] | 143 | memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status)); |
| 144 | ieee80211_rx_irqsafe(dev, skb); |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 145 | |
| 146 | skb = new_skb; |
| 147 | priv->rx_buf[priv->rx_idx] = skb; |
| 148 | *((dma_addr_t *) skb->cb) = |
| 149 | pci_map_single(priv->pdev, skb_tail_pointer(skb), |
| 150 | MAX_RX_SIZE, PCI_DMA_FROMDEVICE); |
| 151 | } |
| 152 | |
| 153 | done: |
| 154 | entry->rx_buf = cpu_to_le32(*((dma_addr_t *)skb->cb)); |
Herton Ronaldo Krzesinski | 38e3b0d | 2008-07-16 11:44:18 -0300 | [diff] [blame] | 155 | entry->flags = cpu_to_le32(RTL818X_RX_DESC_FLAG_OWN | |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 156 | MAX_RX_SIZE); |
| 157 | if (priv->rx_idx == 31) |
Herton Ronaldo Krzesinski | 38e3b0d | 2008-07-16 11:44:18 -0300 | [diff] [blame] | 158 | entry->flags |= cpu_to_le32(RTL818X_RX_DESC_FLAG_EOR); |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 159 | priv->rx_idx = (priv->rx_idx + 1) % 32; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | static void rtl8180_handle_tx(struct ieee80211_hw *dev, unsigned int prio) |
| 164 | { |
| 165 | struct rtl8180_priv *priv = dev->priv; |
| 166 | struct rtl8180_tx_ring *ring = &priv->tx_ring[prio]; |
| 167 | |
| 168 | while (skb_queue_len(&ring->queue)) { |
| 169 | struct rtl8180_tx_desc *entry = &ring->desc[ring->idx]; |
| 170 | struct sk_buff *skb; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 171 | struct ieee80211_tx_info *info; |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 172 | u32 flags = le32_to_cpu(entry->flags); |
| 173 | |
Herton Ronaldo Krzesinski | 38e3b0d | 2008-07-16 11:44:18 -0300 | [diff] [blame] | 174 | if (flags & RTL818X_TX_DESC_FLAG_OWN) |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 175 | return; |
| 176 | |
| 177 | ring->idx = (ring->idx + 1) % ring->entries; |
| 178 | skb = __skb_dequeue(&ring->queue); |
| 179 | pci_unmap_single(priv->pdev, le32_to_cpu(entry->tx_buf), |
| 180 | skb->len, PCI_DMA_TODEVICE); |
| 181 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 182 | info = IEEE80211_SKB_CB(skb); |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 183 | ieee80211_tx_info_clear_status(info); |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 184 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 185 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) && |
| 186 | (flags & RTL818X_TX_DESC_FLAG_TX_OK)) |
| 187 | info->flags |= IEEE80211_TX_STAT_ACK; |
| 188 | |
| 189 | info->status.rates[0].count = (flags & 0xFF) + 1; |
John W. Linville | d989ff7 | 2010-04-28 19:14:42 -0400 | [diff] [blame] | 190 | info->status.rates[1].idx = -1; |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 191 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 192 | ieee80211_tx_status_irqsafe(dev, skb); |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 193 | if (ring->entries - skb_queue_len(&ring->queue) == 2) |
| 194 | ieee80211_wake_queue(dev, prio); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | static irqreturn_t rtl8180_interrupt(int irq, void *dev_id) |
| 199 | { |
| 200 | struct ieee80211_hw *dev = dev_id; |
| 201 | struct rtl8180_priv *priv = dev->priv; |
| 202 | u16 reg; |
| 203 | |
| 204 | spin_lock(&priv->lock); |
| 205 | reg = rtl818x_ioread16(priv, &priv->map->INT_STATUS); |
| 206 | if (unlikely(reg == 0xFFFF)) { |
| 207 | spin_unlock(&priv->lock); |
| 208 | return IRQ_HANDLED; |
| 209 | } |
| 210 | |
| 211 | rtl818x_iowrite16(priv, &priv->map->INT_STATUS, reg); |
| 212 | |
| 213 | if (reg & (RTL818X_INT_TXB_OK | RTL818X_INT_TXB_ERR)) |
| 214 | rtl8180_handle_tx(dev, 3); |
| 215 | |
| 216 | if (reg & (RTL818X_INT_TXH_OK | RTL818X_INT_TXH_ERR)) |
| 217 | rtl8180_handle_tx(dev, 2); |
| 218 | |
| 219 | if (reg & (RTL818X_INT_TXN_OK | RTL818X_INT_TXN_ERR)) |
| 220 | rtl8180_handle_tx(dev, 1); |
| 221 | |
| 222 | if (reg & (RTL818X_INT_TXL_OK | RTL818X_INT_TXL_ERR)) |
| 223 | rtl8180_handle_tx(dev, 0); |
| 224 | |
| 225 | if (reg & (RTL818X_INT_RX_OK | RTL818X_INT_RX_ERR)) |
| 226 | rtl8180_handle_rx(dev); |
| 227 | |
| 228 | spin_unlock(&priv->lock); |
| 229 | |
| 230 | return IRQ_HANDLED; |
| 231 | } |
| 232 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 233 | static int rtl8180_tx(struct ieee80211_hw *dev, struct sk_buff *skb) |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 234 | { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 235 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
John W. Linville | 51e080d | 2010-05-06 16:26:23 -0400 | [diff] [blame^] | 236 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 237 | struct rtl8180_priv *priv = dev->priv; |
| 238 | struct rtl8180_tx_ring *ring; |
| 239 | struct rtl8180_tx_desc *entry; |
| 240 | unsigned long flags; |
| 241 | unsigned int idx, prio; |
| 242 | dma_addr_t mapping; |
| 243 | u32 tx_flags; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 244 | u8 rc_flags; |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 245 | u16 plcp_len = 0; |
| 246 | __le16 rts_duration = 0; |
| 247 | |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 248 | prio = skb_get_queue_mapping(skb); |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 249 | ring = &priv->tx_ring[prio]; |
| 250 | |
| 251 | mapping = pci_map_single(priv->pdev, skb->data, |
| 252 | skb->len, PCI_DMA_TODEVICE); |
| 253 | |
Herton Ronaldo Krzesinski | 38e3b0d | 2008-07-16 11:44:18 -0300 | [diff] [blame] | 254 | tx_flags = RTL818X_TX_DESC_FLAG_OWN | RTL818X_TX_DESC_FLAG_FS | |
| 255 | RTL818X_TX_DESC_FLAG_LS | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 256 | (ieee80211_get_tx_rate(dev, info)->hw_value << 24) | |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 257 | skb->len; |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 258 | |
| 259 | if (priv->r8185) |
Herton Ronaldo Krzesinski | 38e3b0d | 2008-07-16 11:44:18 -0300 | [diff] [blame] | 260 | tx_flags |= RTL818X_TX_DESC_FLAG_DMA | |
| 261 | RTL818X_TX_DESC_FLAG_NO_ENC; |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 262 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 263 | rc_flags = info->control.rates[0].flags; |
| 264 | if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) { |
Herton Ronaldo Krzesinski | 38e3b0d | 2008-07-16 11:44:18 -0300 | [diff] [blame] | 265 | tx_flags |= RTL818X_TX_DESC_FLAG_RTS; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 266 | tx_flags |= ieee80211_get_rts_cts_rate(dev, info)->hw_value << 19; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 267 | } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) { |
Herton Ronaldo Krzesinski | 38e3b0d | 2008-07-16 11:44:18 -0300 | [diff] [blame] | 268 | tx_flags |= RTL818X_TX_DESC_FLAG_CTS; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 269 | tx_flags |= ieee80211_get_rts_cts_rate(dev, info)->hw_value << 19; |
Johannes Berg | aa68cbf | 2008-02-18 14:20:30 +0100 | [diff] [blame] | 270 | } |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 271 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 272 | if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 273 | rts_duration = ieee80211_rts_duration(dev, priv->vif, skb->len, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 274 | info); |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 275 | |
| 276 | if (!priv->r8185) { |
| 277 | unsigned int remainder; |
| 278 | |
| 279 | plcp_len = DIV_ROUND_UP(16 * (skb->len + 4), |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 280 | (ieee80211_get_tx_rate(dev, info)->bitrate * 2) / 10); |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 281 | remainder = (16 * (skb->len + 4)) % |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 282 | ((ieee80211_get_tx_rate(dev, info)->bitrate * 2) / 10); |
Roel Kluin | 35a0ace | 2009-06-22 17:42:21 +0200 | [diff] [blame] | 283 | if (remainder <= 6) |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 284 | plcp_len |= 1 << 15; |
| 285 | } |
| 286 | |
| 287 | spin_lock_irqsave(&priv->lock, flags); |
John W. Linville | 51e080d | 2010-05-06 16:26:23 -0400 | [diff] [blame^] | 288 | |
| 289 | if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { |
| 290 | if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) |
| 291 | priv->seqno += 0x10; |
| 292 | hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); |
| 293 | hdr->seq_ctrl |= cpu_to_le16(priv->seqno); |
| 294 | } |
| 295 | |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 296 | idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries; |
| 297 | entry = &ring->desc[idx]; |
| 298 | |
| 299 | entry->rts_duration = rts_duration; |
| 300 | entry->plcp_len = cpu_to_le16(plcp_len); |
| 301 | entry->tx_buf = cpu_to_le32(mapping); |
| 302 | entry->frame_len = cpu_to_le32(skb->len); |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 303 | entry->flags2 = info->control.rates[1].idx >= 0 ? |
Felix Fietkau | 870abdf | 2008-10-05 18:04:24 +0200 | [diff] [blame] | 304 | ieee80211_get_alt_retry_rate(dev, info, 0)->bitrate << 4 : 0; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 305 | entry->retry_limit = info->control.rates[0].count; |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 306 | entry->flags = cpu_to_le32(tx_flags); |
| 307 | __skb_queue_tail(&ring->queue, skb); |
| 308 | if (ring->entries - skb_queue_len(&ring->queue) < 2) |
John W. Linville | d10e2e0 | 2010-04-27 16:57:38 -0400 | [diff] [blame] | 309 | ieee80211_stop_queue(dev, prio); |
John W. Linville | 51e080d | 2010-05-06 16:26:23 -0400 | [diff] [blame^] | 310 | |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 311 | spin_unlock_irqrestore(&priv->lock, flags); |
| 312 | |
| 313 | rtl818x_iowrite8(priv, &priv->map->TX_DMA_POLLING, (1 << (prio + 4))); |
| 314 | |
| 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | void rtl8180_set_anaparam(struct rtl8180_priv *priv, u32 anaparam) |
| 319 | { |
| 320 | u8 reg; |
| 321 | |
| 322 | rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG); |
| 323 | reg = rtl818x_ioread8(priv, &priv->map->CONFIG3); |
| 324 | rtl818x_iowrite8(priv, &priv->map->CONFIG3, |
| 325 | reg | RTL818X_CONFIG3_ANAPARAM_WRITE); |
| 326 | rtl818x_iowrite32(priv, &priv->map->ANAPARAM, anaparam); |
| 327 | rtl818x_iowrite8(priv, &priv->map->CONFIG3, |
| 328 | reg & ~RTL818X_CONFIG3_ANAPARAM_WRITE); |
| 329 | rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL); |
| 330 | } |
| 331 | |
| 332 | static int rtl8180_init_hw(struct ieee80211_hw *dev) |
| 333 | { |
| 334 | struct rtl8180_priv *priv = dev->priv; |
| 335 | u16 reg; |
| 336 | |
| 337 | rtl818x_iowrite8(priv, &priv->map->CMD, 0); |
| 338 | rtl818x_ioread8(priv, &priv->map->CMD); |
| 339 | msleep(10); |
| 340 | |
| 341 | /* reset */ |
| 342 | rtl818x_iowrite16(priv, &priv->map->INT_MASK, 0); |
| 343 | rtl818x_ioread8(priv, &priv->map->CMD); |
| 344 | |
| 345 | reg = rtl818x_ioread8(priv, &priv->map->CMD); |
| 346 | reg &= (1 << 1); |
| 347 | reg |= RTL818X_CMD_RESET; |
| 348 | rtl818x_iowrite8(priv, &priv->map->CMD, RTL818X_CMD_RESET); |
| 349 | rtl818x_ioread8(priv, &priv->map->CMD); |
| 350 | msleep(200); |
| 351 | |
| 352 | /* check success of reset */ |
| 353 | if (rtl818x_ioread8(priv, &priv->map->CMD) & RTL818X_CMD_RESET) { |
| 354 | printk(KERN_ERR "%s: reset timeout!\n", wiphy_name(dev->wiphy)); |
| 355 | return -ETIMEDOUT; |
| 356 | } |
| 357 | |
| 358 | rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_LOAD); |
| 359 | rtl818x_ioread8(priv, &priv->map->CMD); |
| 360 | msleep(200); |
| 361 | |
| 362 | if (rtl818x_ioread8(priv, &priv->map->CONFIG3) & (1 << 3)) { |
| 363 | /* For cardbus */ |
| 364 | reg = rtl818x_ioread8(priv, &priv->map->CONFIG3); |
| 365 | reg |= 1 << 1; |
| 366 | rtl818x_iowrite8(priv, &priv->map->CONFIG3, reg); |
| 367 | reg = rtl818x_ioread16(priv, &priv->map->FEMR); |
| 368 | reg |= (1 << 15) | (1 << 14) | (1 << 4); |
| 369 | rtl818x_iowrite16(priv, &priv->map->FEMR, reg); |
| 370 | } |
| 371 | |
| 372 | rtl818x_iowrite8(priv, &priv->map->MSR, 0); |
| 373 | |
| 374 | if (!priv->r8185) |
| 375 | rtl8180_set_anaparam(priv, priv->anaparam); |
| 376 | |
| 377 | rtl818x_iowrite32(priv, &priv->map->RDSAR, priv->rx_ring_dma); |
| 378 | rtl818x_iowrite32(priv, &priv->map->TBDA, priv->tx_ring[3].dma); |
| 379 | rtl818x_iowrite32(priv, &priv->map->THPDA, priv->tx_ring[2].dma); |
| 380 | rtl818x_iowrite32(priv, &priv->map->TNPDA, priv->tx_ring[1].dma); |
| 381 | rtl818x_iowrite32(priv, &priv->map->TLPDA, priv->tx_ring[0].dma); |
| 382 | |
| 383 | /* TODO: necessary? specs indicate not */ |
| 384 | rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG); |
| 385 | reg = rtl818x_ioread8(priv, &priv->map->CONFIG2); |
| 386 | rtl818x_iowrite8(priv, &priv->map->CONFIG2, reg & ~(1 << 3)); |
| 387 | if (priv->r8185) { |
| 388 | reg = rtl818x_ioread8(priv, &priv->map->CONFIG2); |
| 389 | rtl818x_iowrite8(priv, &priv->map->CONFIG2, reg | (1 << 4)); |
| 390 | } |
| 391 | rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL); |
| 392 | |
| 393 | /* TODO: set CONFIG5 for calibrating AGC on rtl8180 + philips radio? */ |
| 394 | |
| 395 | /* TODO: turn off hw wep on rtl8180 */ |
| 396 | |
| 397 | rtl818x_iowrite32(priv, &priv->map->INT_TIMEOUT, 0); |
| 398 | |
| 399 | if (priv->r8185) { |
| 400 | rtl818x_iowrite8(priv, &priv->map->WPA_CONF, 0); |
| 401 | rtl818x_iowrite8(priv, &priv->map->RATE_FALLBACK, 0x81); |
| 402 | rtl818x_iowrite8(priv, &priv->map->RESP_RATE, (8 << 4) | 0); |
| 403 | |
| 404 | rtl818x_iowrite16(priv, &priv->map->BRSR, 0x01F3); |
| 405 | |
| 406 | /* TODO: set ClkRun enable? necessary? */ |
| 407 | reg = rtl818x_ioread8(priv, &priv->map->GP_ENABLE); |
| 408 | rtl818x_iowrite8(priv, &priv->map->GP_ENABLE, reg & ~(1 << 6)); |
| 409 | rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG); |
| 410 | reg = rtl818x_ioread8(priv, &priv->map->CONFIG3); |
| 411 | rtl818x_iowrite8(priv, &priv->map->CONFIG3, reg | (1 << 2)); |
| 412 | rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL); |
| 413 | } else { |
| 414 | rtl818x_iowrite16(priv, &priv->map->BRSR, 0x1); |
| 415 | rtl818x_iowrite8(priv, &priv->map->SECURITY, 0); |
| 416 | |
| 417 | rtl818x_iowrite8(priv, &priv->map->PHY_DELAY, 0x6); |
| 418 | rtl818x_iowrite8(priv, &priv->map->CARRIER_SENSE_COUNTER, 0x4C); |
| 419 | } |
| 420 | |
| 421 | priv->rf->init(dev); |
| 422 | if (priv->r8185) |
| 423 | rtl818x_iowrite16(priv, &priv->map->BRSR, 0x01F3); |
| 424 | return 0; |
| 425 | } |
| 426 | |
| 427 | static int rtl8180_init_rx_ring(struct ieee80211_hw *dev) |
| 428 | { |
| 429 | struct rtl8180_priv *priv = dev->priv; |
| 430 | struct rtl8180_rx_desc *entry; |
| 431 | int i; |
| 432 | |
| 433 | priv->rx_ring = pci_alloc_consistent(priv->pdev, |
| 434 | sizeof(*priv->rx_ring) * 32, |
| 435 | &priv->rx_ring_dma); |
| 436 | |
| 437 | if (!priv->rx_ring || (unsigned long)priv->rx_ring & 0xFF) { |
| 438 | printk(KERN_ERR "%s: Cannot allocate RX ring\n", |
| 439 | wiphy_name(dev->wiphy)); |
| 440 | return -ENOMEM; |
| 441 | } |
| 442 | |
| 443 | memset(priv->rx_ring, 0, sizeof(*priv->rx_ring) * 32); |
| 444 | priv->rx_idx = 0; |
| 445 | |
| 446 | for (i = 0; i < 32; i++) { |
| 447 | struct sk_buff *skb = dev_alloc_skb(MAX_RX_SIZE); |
| 448 | dma_addr_t *mapping; |
| 449 | entry = &priv->rx_ring[i]; |
| 450 | if (!skb) |
| 451 | return 0; |
| 452 | |
| 453 | priv->rx_buf[i] = skb; |
| 454 | mapping = (dma_addr_t *)skb->cb; |
| 455 | *mapping = pci_map_single(priv->pdev, skb_tail_pointer(skb), |
| 456 | MAX_RX_SIZE, PCI_DMA_FROMDEVICE); |
| 457 | entry->rx_buf = cpu_to_le32(*mapping); |
Herton Ronaldo Krzesinski | 38e3b0d | 2008-07-16 11:44:18 -0300 | [diff] [blame] | 458 | entry->flags = cpu_to_le32(RTL818X_RX_DESC_FLAG_OWN | |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 459 | MAX_RX_SIZE); |
| 460 | } |
Herton Ronaldo Krzesinski | 38e3b0d | 2008-07-16 11:44:18 -0300 | [diff] [blame] | 461 | entry->flags |= cpu_to_le32(RTL818X_RX_DESC_FLAG_EOR); |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 462 | return 0; |
| 463 | } |
| 464 | |
| 465 | static void rtl8180_free_rx_ring(struct ieee80211_hw *dev) |
| 466 | { |
| 467 | struct rtl8180_priv *priv = dev->priv; |
| 468 | int i; |
| 469 | |
| 470 | for (i = 0; i < 32; i++) { |
| 471 | struct sk_buff *skb = priv->rx_buf[i]; |
| 472 | if (!skb) |
| 473 | continue; |
| 474 | |
| 475 | pci_unmap_single(priv->pdev, |
| 476 | *((dma_addr_t *)skb->cb), |
| 477 | MAX_RX_SIZE, PCI_DMA_FROMDEVICE); |
| 478 | kfree_skb(skb); |
| 479 | } |
| 480 | |
| 481 | pci_free_consistent(priv->pdev, sizeof(*priv->rx_ring) * 32, |
| 482 | priv->rx_ring, priv->rx_ring_dma); |
| 483 | priv->rx_ring = NULL; |
| 484 | } |
| 485 | |
| 486 | static int rtl8180_init_tx_ring(struct ieee80211_hw *dev, |
| 487 | unsigned int prio, unsigned int entries) |
| 488 | { |
| 489 | struct rtl8180_priv *priv = dev->priv; |
| 490 | struct rtl8180_tx_desc *ring; |
| 491 | dma_addr_t dma; |
| 492 | int i; |
| 493 | |
| 494 | ring = pci_alloc_consistent(priv->pdev, sizeof(*ring) * entries, &dma); |
| 495 | if (!ring || (unsigned long)ring & 0xFF) { |
| 496 | printk(KERN_ERR "%s: Cannot allocate TX ring (prio = %d)\n", |
| 497 | wiphy_name(dev->wiphy), prio); |
| 498 | return -ENOMEM; |
| 499 | } |
| 500 | |
| 501 | memset(ring, 0, sizeof(*ring)*entries); |
| 502 | priv->tx_ring[prio].desc = ring; |
| 503 | priv->tx_ring[prio].dma = dma; |
| 504 | priv->tx_ring[prio].idx = 0; |
| 505 | priv->tx_ring[prio].entries = entries; |
| 506 | skb_queue_head_init(&priv->tx_ring[prio].queue); |
| 507 | |
| 508 | for (i = 0; i < entries; i++) |
| 509 | ring[i].next_tx_desc = |
| 510 | cpu_to_le32((u32)dma + ((i + 1) % entries) * sizeof(*ring)); |
| 511 | |
| 512 | return 0; |
| 513 | } |
| 514 | |
| 515 | static void rtl8180_free_tx_ring(struct ieee80211_hw *dev, unsigned int prio) |
| 516 | { |
| 517 | struct rtl8180_priv *priv = dev->priv; |
| 518 | struct rtl8180_tx_ring *ring = &priv->tx_ring[prio]; |
| 519 | |
| 520 | while (skb_queue_len(&ring->queue)) { |
| 521 | struct rtl8180_tx_desc *entry = &ring->desc[ring->idx]; |
| 522 | struct sk_buff *skb = __skb_dequeue(&ring->queue); |
| 523 | |
| 524 | pci_unmap_single(priv->pdev, le32_to_cpu(entry->tx_buf), |
| 525 | skb->len, PCI_DMA_TODEVICE); |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 526 | kfree_skb(skb); |
| 527 | ring->idx = (ring->idx + 1) % ring->entries; |
| 528 | } |
| 529 | |
| 530 | pci_free_consistent(priv->pdev, sizeof(*ring->desc)*ring->entries, |
| 531 | ring->desc, ring->dma); |
| 532 | ring->desc = NULL; |
| 533 | } |
| 534 | |
| 535 | static int rtl8180_start(struct ieee80211_hw *dev) |
| 536 | { |
| 537 | struct rtl8180_priv *priv = dev->priv; |
| 538 | int ret, i; |
| 539 | u32 reg; |
| 540 | |
| 541 | ret = rtl8180_init_rx_ring(dev); |
| 542 | if (ret) |
| 543 | return ret; |
| 544 | |
| 545 | for (i = 0; i < 4; i++) |
| 546 | if ((ret = rtl8180_init_tx_ring(dev, i, 16))) |
| 547 | goto err_free_rings; |
| 548 | |
| 549 | ret = rtl8180_init_hw(dev); |
| 550 | if (ret) |
| 551 | goto err_free_rings; |
| 552 | |
| 553 | rtl818x_iowrite32(priv, &priv->map->RDSAR, priv->rx_ring_dma); |
| 554 | rtl818x_iowrite32(priv, &priv->map->TBDA, priv->tx_ring[3].dma); |
| 555 | rtl818x_iowrite32(priv, &priv->map->THPDA, priv->tx_ring[2].dma); |
| 556 | rtl818x_iowrite32(priv, &priv->map->TNPDA, priv->tx_ring[1].dma); |
| 557 | rtl818x_iowrite32(priv, &priv->map->TLPDA, priv->tx_ring[0].dma); |
| 558 | |
Julia Lawall | ea31ba3 | 2009-11-18 08:26:02 +0000 | [diff] [blame] | 559 | ret = request_irq(priv->pdev->irq, rtl8180_interrupt, |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 560 | IRQF_SHARED, KBUILD_MODNAME, dev); |
| 561 | if (ret) { |
| 562 | printk(KERN_ERR "%s: failed to register IRQ handler\n", |
| 563 | wiphy_name(dev->wiphy)); |
| 564 | goto err_free_rings; |
| 565 | } |
| 566 | |
| 567 | rtl818x_iowrite16(priv, &priv->map->INT_MASK, 0xFFFF); |
| 568 | |
| 569 | rtl818x_iowrite32(priv, &priv->map->MAR[0], ~0); |
| 570 | rtl818x_iowrite32(priv, &priv->map->MAR[1], ~0); |
| 571 | |
| 572 | reg = RTL818X_RX_CONF_ONLYERLPKT | |
| 573 | RTL818X_RX_CONF_RX_AUTORESETPHY | |
| 574 | RTL818X_RX_CONF_MGMT | |
| 575 | RTL818X_RX_CONF_DATA | |
| 576 | (7 << 8 /* MAX RX DMA */) | |
| 577 | RTL818X_RX_CONF_BROADCAST | |
| 578 | RTL818X_RX_CONF_NICMAC; |
| 579 | |
| 580 | if (priv->r8185) |
| 581 | reg |= RTL818X_RX_CONF_CSDM1 | RTL818X_RX_CONF_CSDM2; |
| 582 | else { |
| 583 | reg |= (priv->rfparam & RF_PARAM_CARRIERSENSE1) |
| 584 | ? RTL818X_RX_CONF_CSDM1 : 0; |
| 585 | reg |= (priv->rfparam & RF_PARAM_CARRIERSENSE2) |
| 586 | ? RTL818X_RX_CONF_CSDM2 : 0; |
| 587 | } |
| 588 | |
| 589 | priv->rx_conf = reg; |
| 590 | rtl818x_iowrite32(priv, &priv->map->RX_CONF, reg); |
| 591 | |
| 592 | if (priv->r8185) { |
| 593 | reg = rtl818x_ioread8(priv, &priv->map->CW_CONF); |
| 594 | reg &= ~RTL818X_CW_CONF_PERPACKET_CW_SHIFT; |
| 595 | reg |= RTL818X_CW_CONF_PERPACKET_RETRY_SHIFT; |
| 596 | rtl818x_iowrite8(priv, &priv->map->CW_CONF, reg); |
| 597 | |
| 598 | reg = rtl818x_ioread8(priv, &priv->map->TX_AGC_CTL); |
| 599 | reg &= ~RTL818X_TX_AGC_CTL_PERPACKET_GAIN_SHIFT; |
| 600 | reg &= ~RTL818X_TX_AGC_CTL_PERPACKET_ANTSEL_SHIFT; |
| 601 | reg |= RTL818X_TX_AGC_CTL_FEEDBACK_ANT; |
| 602 | rtl818x_iowrite8(priv, &priv->map->TX_AGC_CTL, reg); |
| 603 | |
| 604 | /* disable early TX */ |
| 605 | rtl818x_iowrite8(priv, (u8 __iomem *)priv->map + 0xec, 0x3f); |
| 606 | } |
| 607 | |
| 608 | reg = rtl818x_ioread32(priv, &priv->map->TX_CONF); |
| 609 | reg |= (6 << 21 /* MAX TX DMA */) | |
| 610 | RTL818X_TX_CONF_NO_ICV; |
| 611 | |
| 612 | if (priv->r8185) |
| 613 | reg &= ~RTL818X_TX_CONF_PROBE_DTS; |
| 614 | else |
| 615 | reg &= ~RTL818X_TX_CONF_HW_SEQNUM; |
| 616 | |
| 617 | /* different meaning, same value on both rtl8185 and rtl8180 */ |
| 618 | reg &= ~RTL818X_TX_CONF_SAT_HWPLCP; |
| 619 | |
| 620 | rtl818x_iowrite32(priv, &priv->map->TX_CONF, reg); |
| 621 | |
| 622 | reg = rtl818x_ioread8(priv, &priv->map->CMD); |
| 623 | reg |= RTL818X_CMD_RX_ENABLE; |
| 624 | reg |= RTL818X_CMD_TX_ENABLE; |
| 625 | rtl818x_iowrite8(priv, &priv->map->CMD, reg); |
| 626 | |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 627 | return 0; |
| 628 | |
| 629 | err_free_rings: |
| 630 | rtl8180_free_rx_ring(dev); |
| 631 | for (i = 0; i < 4; i++) |
| 632 | if (priv->tx_ring[i].desc) |
| 633 | rtl8180_free_tx_ring(dev, i); |
| 634 | |
| 635 | return ret; |
| 636 | } |
| 637 | |
| 638 | static void rtl8180_stop(struct ieee80211_hw *dev) |
| 639 | { |
| 640 | struct rtl8180_priv *priv = dev->priv; |
| 641 | u8 reg; |
| 642 | int i; |
| 643 | |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 644 | rtl818x_iowrite16(priv, &priv->map->INT_MASK, 0); |
| 645 | |
| 646 | reg = rtl818x_ioread8(priv, &priv->map->CMD); |
| 647 | reg &= ~RTL818X_CMD_TX_ENABLE; |
| 648 | reg &= ~RTL818X_CMD_RX_ENABLE; |
| 649 | rtl818x_iowrite8(priv, &priv->map->CMD, reg); |
| 650 | |
| 651 | priv->rf->stop(dev); |
| 652 | |
| 653 | rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG); |
| 654 | reg = rtl818x_ioread8(priv, &priv->map->CONFIG4); |
| 655 | rtl818x_iowrite8(priv, &priv->map->CONFIG4, reg | RTL818X_CONFIG4_VCOOFF); |
| 656 | rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL); |
| 657 | |
| 658 | free_irq(priv->pdev->irq, dev); |
| 659 | |
| 660 | rtl8180_free_rx_ring(dev); |
| 661 | for (i = 0; i < 4; i++) |
| 662 | rtl8180_free_tx_ring(dev, i); |
| 663 | } |
| 664 | |
| 665 | static int rtl8180_add_interface(struct ieee80211_hw *dev, |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 666 | struct ieee80211_vif *vif) |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 667 | { |
| 668 | struct rtl8180_priv *priv = dev->priv; |
| 669 | |
John W. Linville | 643aab6 | 2009-12-22 18:13:04 -0500 | [diff] [blame] | 670 | /* |
| 671 | * We only support one active interface at a time. |
| 672 | */ |
| 673 | if (priv->vif) |
| 674 | return -EBUSY; |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 675 | |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 676 | switch (vif->type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 677 | case NL80211_IFTYPE_STATION: |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 678 | break; |
| 679 | default: |
| 680 | return -EOPNOTSUPP; |
| 681 | } |
| 682 | |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 683 | priv->vif = vif; |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 684 | |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 685 | rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG); |
| 686 | rtl818x_iowrite32(priv, (__le32 __iomem *)&priv->map->MAC[0], |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 687 | le32_to_cpu(*(__le32 *)vif->addr)); |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 688 | rtl818x_iowrite16(priv, (__le16 __iomem *)&priv->map->MAC[4], |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 689 | le16_to_cpu(*(__le16 *)(vif->addr + 4))); |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 690 | rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL); |
| 691 | |
| 692 | return 0; |
| 693 | } |
| 694 | |
| 695 | static void rtl8180_remove_interface(struct ieee80211_hw *dev, |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 696 | struct ieee80211_vif *vif) |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 697 | { |
| 698 | struct rtl8180_priv *priv = dev->priv; |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 699 | priv->vif = NULL; |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 700 | } |
| 701 | |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 702 | static int rtl8180_config(struct ieee80211_hw *dev, u32 changed) |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 703 | { |
| 704 | struct rtl8180_priv *priv = dev->priv; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 705 | struct ieee80211_conf *conf = &dev->conf; |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 706 | |
| 707 | priv->rf->set_chan(dev, conf); |
| 708 | |
| 709 | return 0; |
| 710 | } |
| 711 | |
John W. Linville | da81ded | 2008-11-12 14:37:11 -0500 | [diff] [blame] | 712 | static void rtl8180_bss_info_changed(struct ieee80211_hw *dev, |
| 713 | struct ieee80211_vif *vif, |
| 714 | struct ieee80211_bss_conf *info, |
| 715 | u32 changed) |
| 716 | { |
| 717 | struct rtl8180_priv *priv = dev->priv; |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 718 | int i; |
| 719 | |
| 720 | if (changed & BSS_CHANGED_BSSID) { |
| 721 | for (i = 0; i < ETH_ALEN; i++) |
| 722 | rtl818x_iowrite8(priv, &priv->map->BSSID[i], |
| 723 | info->bssid[i]); |
| 724 | |
| 725 | if (is_valid_ether_addr(info->bssid)) |
| 726 | rtl818x_iowrite8(priv, &priv->map->MSR, |
| 727 | RTL818X_MSR_INFRA); |
| 728 | else |
| 729 | rtl818x_iowrite8(priv, &priv->map->MSR, |
| 730 | RTL818X_MSR_NO_LINK); |
| 731 | } |
John W. Linville | da81ded | 2008-11-12 14:37:11 -0500 | [diff] [blame] | 732 | |
| 733 | if (changed & BSS_CHANGED_ERP_SLOT && priv->rf->conf_erp) |
| 734 | priv->rf->conf_erp(dev, info); |
| 735 | } |
| 736 | |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 737 | static u64 rtl8180_prepare_multicast(struct ieee80211_hw *dev, int mc_count, |
| 738 | struct dev_addr_list *mc_list) |
| 739 | { |
| 740 | return mc_count; |
| 741 | } |
| 742 | |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 743 | static void rtl8180_configure_filter(struct ieee80211_hw *dev, |
| 744 | unsigned int changed_flags, |
| 745 | unsigned int *total_flags, |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 746 | u64 multicast) |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 747 | { |
| 748 | struct rtl8180_priv *priv = dev->priv; |
| 749 | |
| 750 | if (changed_flags & FIF_FCSFAIL) |
| 751 | priv->rx_conf ^= RTL818X_RX_CONF_FCS; |
| 752 | if (changed_flags & FIF_CONTROL) |
| 753 | priv->rx_conf ^= RTL818X_RX_CONF_CTRL; |
| 754 | if (changed_flags & FIF_OTHER_BSS) |
| 755 | priv->rx_conf ^= RTL818X_RX_CONF_MONITOR; |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 756 | if (*total_flags & FIF_ALLMULTI || multicast > 0) |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 757 | priv->rx_conf |= RTL818X_RX_CONF_MULTICAST; |
| 758 | else |
| 759 | priv->rx_conf &= ~RTL818X_RX_CONF_MULTICAST; |
| 760 | |
| 761 | *total_flags = 0; |
| 762 | |
| 763 | if (priv->rx_conf & RTL818X_RX_CONF_FCS) |
| 764 | *total_flags |= FIF_FCSFAIL; |
| 765 | if (priv->rx_conf & RTL818X_RX_CONF_CTRL) |
| 766 | *total_flags |= FIF_CONTROL; |
| 767 | if (priv->rx_conf & RTL818X_RX_CONF_MONITOR) |
| 768 | *total_flags |= FIF_OTHER_BSS; |
| 769 | if (priv->rx_conf & RTL818X_RX_CONF_MULTICAST) |
| 770 | *total_flags |= FIF_ALLMULTI; |
| 771 | |
| 772 | rtl818x_iowrite32(priv, &priv->map->RX_CONF, priv->rx_conf); |
| 773 | } |
| 774 | |
John W. Linville | d2bb8e0 | 2010-01-26 16:22:20 -0500 | [diff] [blame] | 775 | static u64 rtl8180_get_tsf(struct ieee80211_hw *dev) |
| 776 | { |
| 777 | struct rtl8180_priv *priv = dev->priv; |
| 778 | |
| 779 | return rtl818x_ioread32(priv, &priv->map->TSFT[0]) | |
| 780 | (u64)(rtl818x_ioread32(priv, &priv->map->TSFT[1])) << 32; |
| 781 | } |
| 782 | |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 783 | static const struct ieee80211_ops rtl8180_ops = { |
| 784 | .tx = rtl8180_tx, |
| 785 | .start = rtl8180_start, |
| 786 | .stop = rtl8180_stop, |
| 787 | .add_interface = rtl8180_add_interface, |
| 788 | .remove_interface = rtl8180_remove_interface, |
| 789 | .config = rtl8180_config, |
John W. Linville | da81ded | 2008-11-12 14:37:11 -0500 | [diff] [blame] | 790 | .bss_info_changed = rtl8180_bss_info_changed, |
Johannes Berg | 3ac64be | 2009-08-17 16:16:53 +0200 | [diff] [blame] | 791 | .prepare_multicast = rtl8180_prepare_multicast, |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 792 | .configure_filter = rtl8180_configure_filter, |
John W. Linville | d2bb8e0 | 2010-01-26 16:22:20 -0500 | [diff] [blame] | 793 | .get_tsf = rtl8180_get_tsf, |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 794 | }; |
| 795 | |
| 796 | static void rtl8180_eeprom_register_read(struct eeprom_93cx6 *eeprom) |
| 797 | { |
| 798 | struct ieee80211_hw *dev = eeprom->data; |
| 799 | struct rtl8180_priv *priv = dev->priv; |
| 800 | u8 reg = rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); |
| 801 | |
| 802 | eeprom->reg_data_in = reg & RTL818X_EEPROM_CMD_WRITE; |
| 803 | eeprom->reg_data_out = reg & RTL818X_EEPROM_CMD_READ; |
| 804 | eeprom->reg_data_clock = reg & RTL818X_EEPROM_CMD_CK; |
| 805 | eeprom->reg_chip_select = reg & RTL818X_EEPROM_CMD_CS; |
| 806 | } |
| 807 | |
| 808 | static void rtl8180_eeprom_register_write(struct eeprom_93cx6 *eeprom) |
| 809 | { |
| 810 | struct ieee80211_hw *dev = eeprom->data; |
| 811 | struct rtl8180_priv *priv = dev->priv; |
| 812 | u8 reg = 2 << 6; |
| 813 | |
| 814 | if (eeprom->reg_data_in) |
| 815 | reg |= RTL818X_EEPROM_CMD_WRITE; |
| 816 | if (eeprom->reg_data_out) |
| 817 | reg |= RTL818X_EEPROM_CMD_READ; |
| 818 | if (eeprom->reg_data_clock) |
| 819 | reg |= RTL818X_EEPROM_CMD_CK; |
| 820 | if (eeprom->reg_chip_select) |
| 821 | reg |= RTL818X_EEPROM_CMD_CS; |
| 822 | |
| 823 | rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, reg); |
| 824 | rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); |
| 825 | udelay(10); |
| 826 | } |
| 827 | |
| 828 | static int __devinit rtl8180_probe(struct pci_dev *pdev, |
| 829 | const struct pci_device_id *id) |
| 830 | { |
| 831 | struct ieee80211_hw *dev; |
| 832 | struct rtl8180_priv *priv; |
| 833 | unsigned long mem_addr, mem_len; |
| 834 | unsigned int io_addr, io_len; |
| 835 | int err, i; |
| 836 | struct eeprom_93cx6 eeprom; |
| 837 | const char *chip_name, *rf_name = NULL; |
| 838 | u32 reg; |
| 839 | u16 eeprom_val; |
John W. Linville | c693bf9 | 2010-05-04 15:46:15 -0400 | [diff] [blame] | 840 | u8 mac_addr[ETH_ALEN]; |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 841 | |
| 842 | err = pci_enable_device(pdev); |
| 843 | if (err) { |
| 844 | printk(KERN_ERR "%s (rtl8180): Cannot enable new PCI device\n", |
| 845 | pci_name(pdev)); |
| 846 | return err; |
| 847 | } |
| 848 | |
| 849 | err = pci_request_regions(pdev, KBUILD_MODNAME); |
| 850 | if (err) { |
| 851 | printk(KERN_ERR "%s (rtl8180): Cannot obtain PCI resources\n", |
| 852 | pci_name(pdev)); |
| 853 | return err; |
| 854 | } |
| 855 | |
| 856 | io_addr = pci_resource_start(pdev, 0); |
| 857 | io_len = pci_resource_len(pdev, 0); |
| 858 | mem_addr = pci_resource_start(pdev, 1); |
| 859 | mem_len = pci_resource_len(pdev, 1); |
| 860 | |
| 861 | if (mem_len < sizeof(struct rtl818x_csr) || |
| 862 | io_len < sizeof(struct rtl818x_csr)) { |
| 863 | printk(KERN_ERR "%s (rtl8180): Too short PCI resources\n", |
| 864 | pci_name(pdev)); |
| 865 | err = -ENOMEM; |
| 866 | goto err_free_reg; |
| 867 | } |
| 868 | |
| 869 | if ((err = pci_set_dma_mask(pdev, 0xFFFFFF00ULL)) || |
| 870 | (err = pci_set_consistent_dma_mask(pdev, 0xFFFFFF00ULL))) { |
| 871 | printk(KERN_ERR "%s (rtl8180): No suitable DMA available\n", |
| 872 | pci_name(pdev)); |
| 873 | goto err_free_reg; |
| 874 | } |
| 875 | |
| 876 | pci_set_master(pdev); |
| 877 | |
| 878 | dev = ieee80211_alloc_hw(sizeof(*priv), &rtl8180_ops); |
| 879 | if (!dev) { |
| 880 | printk(KERN_ERR "%s (rtl8180): ieee80211 alloc failed\n", |
| 881 | pci_name(pdev)); |
| 882 | err = -ENOMEM; |
| 883 | goto err_free_reg; |
| 884 | } |
| 885 | |
| 886 | priv = dev->priv; |
| 887 | priv->pdev = pdev; |
| 888 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 889 | dev->max_rates = 2; |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 890 | SET_IEEE80211_DEV(dev, &pdev->dev); |
| 891 | pci_set_drvdata(pdev, dev); |
| 892 | |
| 893 | priv->map = pci_iomap(pdev, 1, mem_len); |
| 894 | if (!priv->map) |
| 895 | priv->map = pci_iomap(pdev, 0, io_len); |
| 896 | |
| 897 | if (!priv->map) { |
| 898 | printk(KERN_ERR "%s (rtl8180): Cannot map device memory\n", |
| 899 | pci_name(pdev)); |
| 900 | goto err_free_dev; |
| 901 | } |
| 902 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 903 | BUILD_BUG_ON(sizeof(priv->channels) != sizeof(rtl818x_channels)); |
| 904 | BUILD_BUG_ON(sizeof(priv->rates) != sizeof(rtl818x_rates)); |
| 905 | |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 906 | memcpy(priv->channels, rtl818x_channels, sizeof(rtl818x_channels)); |
| 907 | memcpy(priv->rates, rtl818x_rates, sizeof(rtl818x_rates)); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 908 | |
| 909 | priv->band.band = IEEE80211_BAND_2GHZ; |
| 910 | priv->band.channels = priv->channels; |
| 911 | priv->band.n_channels = ARRAY_SIZE(rtl818x_channels); |
| 912 | priv->band.bitrates = priv->rates; |
| 913 | priv->band.n_bitrates = 4; |
| 914 | dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band; |
| 915 | |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 916 | dev->flags = IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING | |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 917 | IEEE80211_HW_RX_INCLUDES_FCS | |
| 918 | IEEE80211_HW_SIGNAL_UNSPEC; |
Larry Finger | b55eae3 | 2008-12-21 15:40:33 -0600 | [diff] [blame] | 919 | dev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION); |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 920 | dev->queues = 1; |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 921 | dev->max_signal = 65; |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 922 | |
| 923 | reg = rtl818x_ioread32(priv, &priv->map->TX_CONF); |
| 924 | reg &= RTL818X_TX_CONF_HWVER_MASK; |
| 925 | switch (reg) { |
| 926 | case RTL818X_TX_CONF_R8180_ABCD: |
| 927 | chip_name = "RTL8180"; |
| 928 | break; |
| 929 | case RTL818X_TX_CONF_R8180_F: |
| 930 | chip_name = "RTL8180vF"; |
| 931 | break; |
| 932 | case RTL818X_TX_CONF_R8185_ABC: |
| 933 | chip_name = "RTL8185"; |
| 934 | break; |
| 935 | case RTL818X_TX_CONF_R8185_D: |
| 936 | chip_name = "RTL8185vD"; |
| 937 | break; |
| 938 | default: |
| 939 | printk(KERN_ERR "%s (rtl8180): Unknown chip! (0x%x)\n", |
| 940 | pci_name(pdev), reg >> 25); |
| 941 | goto err_iounmap; |
| 942 | } |
| 943 | |
| 944 | priv->r8185 = reg & RTL818X_TX_CONF_R8185_ABC; |
| 945 | if (priv->r8185) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 946 | priv->band.n_bitrates = ARRAY_SIZE(rtl818x_rates); |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 947 | pci_try_set_mwi(pdev); |
| 948 | } |
| 949 | |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 950 | eeprom.data = dev; |
| 951 | eeprom.register_read = rtl8180_eeprom_register_read; |
| 952 | eeprom.register_write = rtl8180_eeprom_register_write; |
| 953 | if (rtl818x_ioread32(priv, &priv->map->RX_CONF) & (1 << 6)) |
| 954 | eeprom.width = PCI_EEPROM_WIDTH_93C66; |
| 955 | else |
| 956 | eeprom.width = PCI_EEPROM_WIDTH_93C46; |
| 957 | |
| 958 | rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_PROGRAM); |
| 959 | rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); |
| 960 | udelay(10); |
| 961 | |
| 962 | eeprom_93cx6_read(&eeprom, 0x06, &eeprom_val); |
| 963 | eeprom_val &= 0xFF; |
| 964 | switch (eeprom_val) { |
| 965 | case 1: rf_name = "Intersil"; |
| 966 | break; |
| 967 | case 2: rf_name = "RFMD"; |
| 968 | break; |
| 969 | case 3: priv->rf = &sa2400_rf_ops; |
| 970 | break; |
| 971 | case 4: priv->rf = &max2820_rf_ops; |
| 972 | break; |
| 973 | case 5: priv->rf = &grf5101_rf_ops; |
| 974 | break; |
| 975 | case 9: priv->rf = rtl8180_detect_rf(dev); |
| 976 | break; |
| 977 | case 10: |
| 978 | rf_name = "RTL8255"; |
| 979 | break; |
| 980 | default: |
| 981 | printk(KERN_ERR "%s (rtl8180): Unknown RF! (0x%x)\n", |
| 982 | pci_name(pdev), eeprom_val); |
| 983 | goto err_iounmap; |
| 984 | } |
| 985 | |
| 986 | if (!priv->rf) { |
| 987 | printk(KERN_ERR "%s (rtl8180): %s RF frontend not supported!\n", |
| 988 | pci_name(pdev), rf_name); |
| 989 | goto err_iounmap; |
| 990 | } |
| 991 | |
| 992 | eeprom_93cx6_read(&eeprom, 0x17, &eeprom_val); |
| 993 | priv->csthreshold = eeprom_val >> 8; |
| 994 | if (!priv->r8185) { |
| 995 | __le32 anaparam; |
| 996 | eeprom_93cx6_multiread(&eeprom, 0xD, (__le16 *)&anaparam, 2); |
| 997 | priv->anaparam = le32_to_cpu(anaparam); |
| 998 | eeprom_93cx6_read(&eeprom, 0x19, &priv->rfparam); |
| 999 | } |
| 1000 | |
John W. Linville | c693bf9 | 2010-05-04 15:46:15 -0400 | [diff] [blame] | 1001 | eeprom_93cx6_multiread(&eeprom, 0x7, (__le16 *)mac_addr, 3); |
| 1002 | if (!is_valid_ether_addr(mac_addr)) { |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 1003 | printk(KERN_WARNING "%s (rtl8180): Invalid hwaddr! Using" |
| 1004 | " randomly generated MAC addr\n", pci_name(pdev)); |
John W. Linville | c693bf9 | 2010-05-04 15:46:15 -0400 | [diff] [blame] | 1005 | random_ether_addr(mac_addr); |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 1006 | } |
John W. Linville | c693bf9 | 2010-05-04 15:46:15 -0400 | [diff] [blame] | 1007 | SET_IEEE80211_PERM_ADDR(dev, mac_addr); |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 1008 | |
| 1009 | /* CCK TX power */ |
| 1010 | for (i = 0; i < 14; i += 2) { |
| 1011 | u16 txpwr; |
| 1012 | eeprom_93cx6_read(&eeprom, 0x10 + (i >> 1), &txpwr); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1013 | priv->channels[i].hw_value = txpwr & 0xFF; |
| 1014 | priv->channels[i + 1].hw_value = txpwr >> 8; |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | /* OFDM TX power */ |
| 1018 | if (priv->r8185) { |
| 1019 | for (i = 0; i < 14; i += 2) { |
| 1020 | u16 txpwr; |
| 1021 | eeprom_93cx6_read(&eeprom, 0x20 + (i >> 1), &txpwr); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1022 | priv->channels[i].hw_value |= (txpwr & 0xFF) << 8; |
| 1023 | priv->channels[i + 1].hw_value |= txpwr & 0xFF00; |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL); |
| 1028 | |
| 1029 | spin_lock_init(&priv->lock); |
| 1030 | |
| 1031 | err = ieee80211_register_hw(dev); |
| 1032 | if (err) { |
| 1033 | printk(KERN_ERR "%s (rtl8180): Cannot register device\n", |
| 1034 | pci_name(pdev)); |
| 1035 | goto err_iounmap; |
| 1036 | } |
| 1037 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1038 | printk(KERN_INFO "%s: hwaddr %pM, %s + %s\n", |
John W. Linville | c693bf9 | 2010-05-04 15:46:15 -0400 | [diff] [blame] | 1039 | wiphy_name(dev->wiphy), mac_addr, |
Michael Wu | f653211 | 2007-10-14 14:43:16 -0400 | [diff] [blame] | 1040 | chip_name, priv->rf->name); |
| 1041 | |
| 1042 | return 0; |
| 1043 | |
| 1044 | err_iounmap: |
| 1045 | iounmap(priv->map); |
| 1046 | |
| 1047 | err_free_dev: |
| 1048 | pci_set_drvdata(pdev, NULL); |
| 1049 | ieee80211_free_hw(dev); |
| 1050 | |
| 1051 | err_free_reg: |
| 1052 | pci_release_regions(pdev); |
| 1053 | pci_disable_device(pdev); |
| 1054 | return err; |
| 1055 | } |
| 1056 | |
| 1057 | static void __devexit rtl8180_remove(struct pci_dev *pdev) |
| 1058 | { |
| 1059 | struct ieee80211_hw *dev = pci_get_drvdata(pdev); |
| 1060 | struct rtl8180_priv *priv; |
| 1061 | |
| 1062 | if (!dev) |
| 1063 | return; |
| 1064 | |
| 1065 | ieee80211_unregister_hw(dev); |
| 1066 | |
| 1067 | priv = dev->priv; |
| 1068 | |
| 1069 | pci_iounmap(pdev, priv->map); |
| 1070 | pci_release_regions(pdev); |
| 1071 | pci_disable_device(pdev); |
| 1072 | ieee80211_free_hw(dev); |
| 1073 | } |
| 1074 | |
| 1075 | #ifdef CONFIG_PM |
| 1076 | static int rtl8180_suspend(struct pci_dev *pdev, pm_message_t state) |
| 1077 | { |
| 1078 | pci_save_state(pdev); |
| 1079 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 1080 | return 0; |
| 1081 | } |
| 1082 | |
| 1083 | static int rtl8180_resume(struct pci_dev *pdev) |
| 1084 | { |
| 1085 | pci_set_power_state(pdev, PCI_D0); |
| 1086 | pci_restore_state(pdev); |
| 1087 | return 0; |
| 1088 | } |
| 1089 | |
| 1090 | #endif /* CONFIG_PM */ |
| 1091 | |
| 1092 | static struct pci_driver rtl8180_driver = { |
| 1093 | .name = KBUILD_MODNAME, |
| 1094 | .id_table = rtl8180_table, |
| 1095 | .probe = rtl8180_probe, |
| 1096 | .remove = __devexit_p(rtl8180_remove), |
| 1097 | #ifdef CONFIG_PM |
| 1098 | .suspend = rtl8180_suspend, |
| 1099 | .resume = rtl8180_resume, |
| 1100 | #endif /* CONFIG_PM */ |
| 1101 | }; |
| 1102 | |
| 1103 | static int __init rtl8180_init(void) |
| 1104 | { |
| 1105 | return pci_register_driver(&rtl8180_driver); |
| 1106 | } |
| 1107 | |
| 1108 | static void __exit rtl8180_exit(void) |
| 1109 | { |
| 1110 | pci_unregister_driver(&rtl8180_driver); |
| 1111 | } |
| 1112 | |
| 1113 | module_init(rtl8180_init); |
| 1114 | module_exit(rtl8180_exit); |