rtl8180_dev.c 30 KB

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