rtl8180_dev.c 30 KB

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