rtl8187_dev.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510
  1. /*
  2. * Linux device driver for RTL8187
  3. *
  4. * Copyright 2007 Michael Wu <flamingice@sourmilk.net>
  5. * Copyright 2007 Andrea Merello <andreamrl@tiscali.it>
  6. *
  7. * Based on the r8187 driver, which is:
  8. * Copyright 2005 Andrea Merello <andreamrl@tiscali.it>, et al.
  9. *
  10. * The driver was extended to the RTL8187B in 2008 by:
  11. * Herton Ronaldo Krzesinski <herton@mandriva.com.br>
  12. * Hin-Tak Leung <htl10@users.sourceforge.net>
  13. * Larry Finger <Larry.Finger@lwfinger.net>
  14. *
  15. * Magic delays and register offsets below are taken from the original
  16. * r8187 driver sources. Thanks to Realtek for their support!
  17. *
  18. * This program is free software; you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License version 2 as
  20. * published by the Free Software Foundation.
  21. */
  22. #include <linux/init.h>
  23. #include <linux/usb.h>
  24. #include <linux/delay.h>
  25. #include <linux/etherdevice.h>
  26. #include <linux/eeprom_93cx6.h>
  27. #include <net/mac80211.h>
  28. #include "rtl8187.h"
  29. #include "rtl8187_rtl8225.h"
  30. MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>");
  31. MODULE_AUTHOR("Andrea Merello <andreamrl@tiscali.it>");
  32. MODULE_AUTHOR("Herton Ronaldo Krzesinski <herton@mandriva.com.br>");
  33. MODULE_AUTHOR("Hin-Tak Leung <htl10@users.sourceforge.net>");
  34. MODULE_AUTHOR("Larry Finger <Larry.Finger@lwfinger.net>");
  35. MODULE_DESCRIPTION("RTL8187/RTL8187B USB wireless driver");
  36. MODULE_LICENSE("GPL");
  37. static struct usb_device_id rtl8187_table[] __devinitdata = {
  38. /* Asus */
  39. {USB_DEVICE(0x0b05, 0x171d), .driver_info = DEVICE_RTL8187},
  40. /* Belkin */
  41. {USB_DEVICE(0x050d, 0x705e), .driver_info = DEVICE_RTL8187B},
  42. /* Realtek */
  43. {USB_DEVICE(0x0bda, 0x8187), .driver_info = DEVICE_RTL8187},
  44. {USB_DEVICE(0x0bda, 0x8189), .driver_info = DEVICE_RTL8187B},
  45. {USB_DEVICE(0x0bda, 0x8197), .driver_info = DEVICE_RTL8187B},
  46. {USB_DEVICE(0x0bda, 0x8198), .driver_info = DEVICE_RTL8187B},
  47. /* Surecom */
  48. {USB_DEVICE(0x0769, 0x11F2), .driver_info = DEVICE_RTL8187},
  49. /* Logitech */
  50. {USB_DEVICE(0x0789, 0x010C), .driver_info = DEVICE_RTL8187},
  51. /* Netgear */
  52. {USB_DEVICE(0x0846, 0x6100), .driver_info = DEVICE_RTL8187},
  53. {USB_DEVICE(0x0846, 0x6a00), .driver_info = DEVICE_RTL8187},
  54. {USB_DEVICE(0x0846, 0x4260), .driver_info = DEVICE_RTL8187B},
  55. /* HP */
  56. {USB_DEVICE(0x03f0, 0xca02), .driver_info = DEVICE_RTL8187},
  57. /* Sitecom */
  58. {USB_DEVICE(0x0df6, 0x000d), .driver_info = DEVICE_RTL8187},
  59. {USB_DEVICE(0x0df6, 0x0028), .driver_info = DEVICE_RTL8187B},
  60. /* Sphairon Access Systems GmbH */
  61. {USB_DEVICE(0x114B, 0x0150), .driver_info = DEVICE_RTL8187},
  62. /* Dick Smith Electronics */
  63. {USB_DEVICE(0x1371, 0x9401), .driver_info = DEVICE_RTL8187},
  64. /* Abocom */
  65. {USB_DEVICE(0x13d1, 0xabe6), .driver_info = DEVICE_RTL8187},
  66. /* Qcom */
  67. {USB_DEVICE(0x18E8, 0x6232), .driver_info = DEVICE_RTL8187},
  68. /* AirLive */
  69. {USB_DEVICE(0x1b75, 0x8187), .driver_info = DEVICE_RTL8187},
  70. {}
  71. };
  72. MODULE_DEVICE_TABLE(usb, rtl8187_table);
  73. static const struct ieee80211_rate rtl818x_rates[] = {
  74. { .bitrate = 10, .hw_value = 0, },
  75. { .bitrate = 20, .hw_value = 1, },
  76. { .bitrate = 55, .hw_value = 2, },
  77. { .bitrate = 110, .hw_value = 3, },
  78. { .bitrate = 60, .hw_value = 4, },
  79. { .bitrate = 90, .hw_value = 5, },
  80. { .bitrate = 120, .hw_value = 6, },
  81. { .bitrate = 180, .hw_value = 7, },
  82. { .bitrate = 240, .hw_value = 8, },
  83. { .bitrate = 360, .hw_value = 9, },
  84. { .bitrate = 480, .hw_value = 10, },
  85. { .bitrate = 540, .hw_value = 11, },
  86. };
  87. static const struct ieee80211_channel rtl818x_channels[] = {
  88. { .center_freq = 2412 },
  89. { .center_freq = 2417 },
  90. { .center_freq = 2422 },
  91. { .center_freq = 2427 },
  92. { .center_freq = 2432 },
  93. { .center_freq = 2437 },
  94. { .center_freq = 2442 },
  95. { .center_freq = 2447 },
  96. { .center_freq = 2452 },
  97. { .center_freq = 2457 },
  98. { .center_freq = 2462 },
  99. { .center_freq = 2467 },
  100. { .center_freq = 2472 },
  101. { .center_freq = 2484 },
  102. };
  103. static void rtl8187_iowrite_async_cb(struct urb *urb)
  104. {
  105. kfree(urb->context);
  106. }
  107. static void rtl8187_iowrite_async(struct rtl8187_priv *priv, __le16 addr,
  108. void *data, u16 len)
  109. {
  110. struct usb_ctrlrequest *dr;
  111. struct urb *urb;
  112. struct rtl8187_async_write_data {
  113. u8 data[4];
  114. struct usb_ctrlrequest dr;
  115. } *buf;
  116. int rc;
  117. buf = kmalloc(sizeof(*buf), GFP_ATOMIC);
  118. if (!buf)
  119. return;
  120. urb = usb_alloc_urb(0, GFP_ATOMIC);
  121. if (!urb) {
  122. kfree(buf);
  123. return;
  124. }
  125. dr = &buf->dr;
  126. dr->bRequestType = RTL8187_REQT_WRITE;
  127. dr->bRequest = RTL8187_REQ_SET_REG;
  128. dr->wValue = addr;
  129. dr->wIndex = 0;
  130. dr->wLength = cpu_to_le16(len);
  131. memcpy(buf, data, len);
  132. usb_fill_control_urb(urb, priv->udev, usb_sndctrlpipe(priv->udev, 0),
  133. (unsigned char *)dr, buf, len,
  134. rtl8187_iowrite_async_cb, buf);
  135. usb_anchor_urb(urb, &priv->anchored);
  136. rc = usb_submit_urb(urb, GFP_ATOMIC);
  137. if (rc < 0) {
  138. kfree(buf);
  139. usb_unanchor_urb(urb);
  140. }
  141. usb_free_urb(urb);
  142. }
  143. static inline void rtl818x_iowrite32_async(struct rtl8187_priv *priv,
  144. __le32 *addr, u32 val)
  145. {
  146. __le32 buf = cpu_to_le32(val);
  147. rtl8187_iowrite_async(priv, cpu_to_le16((unsigned long)addr),
  148. &buf, sizeof(buf));
  149. }
  150. void rtl8187_write_phy(struct ieee80211_hw *dev, u8 addr, u32 data)
  151. {
  152. struct rtl8187_priv *priv = dev->priv;
  153. data <<= 8;
  154. data |= addr | 0x80;
  155. rtl818x_iowrite8(priv, &priv->map->PHY[3], (data >> 24) & 0xFF);
  156. rtl818x_iowrite8(priv, &priv->map->PHY[2], (data >> 16) & 0xFF);
  157. rtl818x_iowrite8(priv, &priv->map->PHY[1], (data >> 8) & 0xFF);
  158. rtl818x_iowrite8(priv, &priv->map->PHY[0], data & 0xFF);
  159. }
  160. static void rtl8187_tx_cb(struct urb *urb)
  161. {
  162. struct sk_buff *skb = (struct sk_buff *)urb->context;
  163. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  164. struct ieee80211_hw *hw = info->rate_driver_data[0];
  165. struct rtl8187_priv *priv = hw->priv;
  166. skb_pull(skb, priv->is_rtl8187b ? sizeof(struct rtl8187b_tx_hdr) :
  167. sizeof(struct rtl8187_tx_hdr));
  168. ieee80211_tx_info_clear_status(info);
  169. if (!urb->status &&
  170. !(info->flags & IEEE80211_TX_CTL_NO_ACK) &&
  171. priv->is_rtl8187b) {
  172. skb_queue_tail(&priv->b_tx_status.queue, skb);
  173. /* queue is "full", discard last items */
  174. while (skb_queue_len(&priv->b_tx_status.queue) > 5) {
  175. struct sk_buff *old_skb;
  176. dev_dbg(&priv->udev->dev,
  177. "transmit status queue full\n");
  178. old_skb = skb_dequeue(&priv->b_tx_status.queue);
  179. ieee80211_tx_status_irqsafe(hw, old_skb);
  180. }
  181. } else {
  182. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) && !urb->status)
  183. info->flags |= IEEE80211_TX_STAT_ACK;
  184. ieee80211_tx_status_irqsafe(hw, skb);
  185. }
  186. }
  187. static int rtl8187_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
  188. {
  189. struct rtl8187_priv *priv = dev->priv;
  190. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  191. unsigned int ep;
  192. void *buf;
  193. struct urb *urb;
  194. __le16 rts_dur = 0;
  195. u32 flags;
  196. int rc;
  197. urb = usb_alloc_urb(0, GFP_ATOMIC);
  198. if (!urb) {
  199. kfree_skb(skb);
  200. return NETDEV_TX_OK;
  201. }
  202. flags = skb->len;
  203. flags |= RTL818X_TX_DESC_FLAG_NO_ENC;
  204. flags |= ieee80211_get_tx_rate(dev, info)->hw_value << 24;
  205. if (ieee80211_has_morefrags(((struct ieee80211_hdr *)skb->data)->frame_control))
  206. flags |= RTL818X_TX_DESC_FLAG_MOREFRAG;
  207. if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) {
  208. flags |= RTL818X_TX_DESC_FLAG_RTS;
  209. flags |= ieee80211_get_rts_cts_rate(dev, info)->hw_value << 19;
  210. rts_dur = ieee80211_rts_duration(dev, priv->vif,
  211. skb->len, info);
  212. } else if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
  213. flags |= RTL818X_TX_DESC_FLAG_CTS;
  214. flags |= ieee80211_get_rts_cts_rate(dev, info)->hw_value << 19;
  215. }
  216. if (!priv->is_rtl8187b) {
  217. struct rtl8187_tx_hdr *hdr =
  218. (struct rtl8187_tx_hdr *)skb_push(skb, sizeof(*hdr));
  219. hdr->flags = cpu_to_le32(flags);
  220. hdr->len = 0;
  221. hdr->rts_duration = rts_dur;
  222. hdr->retry = cpu_to_le32((info->control.rates[0].count - 1) << 8);
  223. buf = hdr;
  224. ep = 2;
  225. } else {
  226. /* fc needs to be calculated before skb_push() */
  227. unsigned int epmap[4] = { 6, 7, 5, 4 };
  228. struct ieee80211_hdr *tx_hdr =
  229. (struct ieee80211_hdr *)(skb->data);
  230. u16 fc = le16_to_cpu(tx_hdr->frame_control);
  231. struct rtl8187b_tx_hdr *hdr =
  232. (struct rtl8187b_tx_hdr *)skb_push(skb, sizeof(*hdr));
  233. struct ieee80211_rate *txrate =
  234. ieee80211_get_tx_rate(dev, info);
  235. memset(hdr, 0, sizeof(*hdr));
  236. hdr->flags = cpu_to_le32(flags);
  237. hdr->rts_duration = rts_dur;
  238. hdr->retry = cpu_to_le32((info->control.rates[0].count - 1) << 8);
  239. hdr->tx_duration =
  240. ieee80211_generic_frame_duration(dev, priv->vif,
  241. skb->len, txrate);
  242. buf = hdr;
  243. if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
  244. ep = 12;
  245. else
  246. ep = epmap[skb_get_queue_mapping(skb)];
  247. }
  248. info->rate_driver_data[0] = dev;
  249. info->rate_driver_data[1] = urb;
  250. usb_fill_bulk_urb(urb, priv->udev, usb_sndbulkpipe(priv->udev, ep),
  251. buf, skb->len, rtl8187_tx_cb, skb);
  252. urb->transfer_flags |= URB_ZERO_PACKET;
  253. usb_anchor_urb(urb, &priv->anchored);
  254. rc = usb_submit_urb(urb, GFP_ATOMIC);
  255. if (rc < 0) {
  256. usb_unanchor_urb(urb);
  257. kfree_skb(skb);
  258. }
  259. usb_free_urb(urb);
  260. return NETDEV_TX_OK;
  261. }
  262. static void rtl8187_rx_cb(struct urb *urb)
  263. {
  264. struct sk_buff *skb = (struct sk_buff *)urb->context;
  265. struct rtl8187_rx_info *info = (struct rtl8187_rx_info *)skb->cb;
  266. struct ieee80211_hw *dev = info->dev;
  267. struct rtl8187_priv *priv = dev->priv;
  268. struct ieee80211_rx_status rx_status = { 0 };
  269. int rate, signal;
  270. u32 flags;
  271. u32 quality;
  272. unsigned long f;
  273. spin_lock_irqsave(&priv->rx_queue.lock, f);
  274. if (skb->next)
  275. __skb_unlink(skb, &priv->rx_queue);
  276. else {
  277. spin_unlock_irqrestore(&priv->rx_queue.lock, f);
  278. return;
  279. }
  280. spin_unlock_irqrestore(&priv->rx_queue.lock, f);
  281. skb_put(skb, urb->actual_length);
  282. if (unlikely(urb->status)) {
  283. dev_kfree_skb_irq(skb);
  284. return;
  285. }
  286. if (!priv->is_rtl8187b) {
  287. struct rtl8187_rx_hdr *hdr =
  288. (typeof(hdr))(skb_tail_pointer(skb) - sizeof(*hdr));
  289. flags = le32_to_cpu(hdr->flags);
  290. /* As with the RTL8187B below, the AGC is used to calculate
  291. * signal strength and quality. In this case, the scaling
  292. * constants are derived from the output of p54usb.
  293. */
  294. quality = 130 - ((41 * hdr->agc) >> 6);
  295. signal = -4 - ((27 * hdr->agc) >> 6);
  296. rx_status.antenna = (hdr->signal >> 7) & 1;
  297. rx_status.mactime = le64_to_cpu(hdr->mac_time);
  298. } else {
  299. struct rtl8187b_rx_hdr *hdr =
  300. (typeof(hdr))(skb_tail_pointer(skb) - sizeof(*hdr));
  301. /* The Realtek datasheet for the RTL8187B shows that the RX
  302. * header contains the following quantities: signal quality,
  303. * RSSI, AGC, the received power in dB, and the measured SNR.
  304. * In testing, none of these quantities show qualitative
  305. * agreement with AP signal strength, except for the AGC,
  306. * which is inversely proportional to the strength of the
  307. * signal. In the following, the quality and signal strength
  308. * are derived from the AGC. The arbitrary scaling constants
  309. * are chosen to make the results close to the values obtained
  310. * for a BCM4312 using b43 as the driver. The noise is ignored
  311. * for now.
  312. */
  313. flags = le32_to_cpu(hdr->flags);
  314. quality = 170 - hdr->agc;
  315. signal = 14 - hdr->agc / 2;
  316. rx_status.antenna = (hdr->rssi >> 7) & 1;
  317. rx_status.mactime = le64_to_cpu(hdr->mac_time);
  318. }
  319. if (quality > 100)
  320. quality = 100;
  321. rx_status.qual = quality;
  322. priv->quality = quality;
  323. rx_status.signal = signal;
  324. priv->signal = signal;
  325. rate = (flags >> 20) & 0xF;
  326. skb_trim(skb, flags & 0x0FFF);
  327. rx_status.rate_idx = rate;
  328. rx_status.freq = dev->conf.channel->center_freq;
  329. rx_status.band = dev->conf.channel->band;
  330. rx_status.flag |= RX_FLAG_TSFT;
  331. if (flags & RTL818X_RX_DESC_FLAG_CRC32_ERR)
  332. rx_status.flag |= RX_FLAG_FAILED_FCS_CRC;
  333. ieee80211_rx_irqsafe(dev, skb, &rx_status);
  334. skb = dev_alloc_skb(RTL8187_MAX_RX);
  335. if (unlikely(!skb)) {
  336. /* TODO check rx queue length and refill *somewhere* */
  337. return;
  338. }
  339. info = (struct rtl8187_rx_info *)skb->cb;
  340. info->urb = urb;
  341. info->dev = dev;
  342. urb->transfer_buffer = skb_tail_pointer(skb);
  343. urb->context = skb;
  344. skb_queue_tail(&priv->rx_queue, skb);
  345. usb_anchor_urb(urb, &priv->anchored);
  346. if (usb_submit_urb(urb, GFP_ATOMIC)) {
  347. usb_unanchor_urb(urb);
  348. skb_unlink(skb, &priv->rx_queue);
  349. dev_kfree_skb_irq(skb);
  350. }
  351. }
  352. static int rtl8187_init_urbs(struct ieee80211_hw *dev)
  353. {
  354. struct rtl8187_priv *priv = dev->priv;
  355. struct urb *entry = NULL;
  356. struct sk_buff *skb;
  357. struct rtl8187_rx_info *info;
  358. int ret = 0;
  359. while (skb_queue_len(&priv->rx_queue) < 8) {
  360. skb = __dev_alloc_skb(RTL8187_MAX_RX, GFP_KERNEL);
  361. if (!skb) {
  362. ret = -ENOMEM;
  363. goto err;
  364. }
  365. entry = usb_alloc_urb(0, GFP_KERNEL);
  366. if (!entry) {
  367. ret = -ENOMEM;
  368. goto err;
  369. }
  370. usb_fill_bulk_urb(entry, priv->udev,
  371. usb_rcvbulkpipe(priv->udev,
  372. priv->is_rtl8187b ? 3 : 1),
  373. skb_tail_pointer(skb),
  374. RTL8187_MAX_RX, rtl8187_rx_cb, skb);
  375. info = (struct rtl8187_rx_info *)skb->cb;
  376. info->urb = entry;
  377. info->dev = dev;
  378. skb_queue_tail(&priv->rx_queue, skb);
  379. usb_anchor_urb(entry, &priv->anchored);
  380. ret = usb_submit_urb(entry, GFP_KERNEL);
  381. if (ret) {
  382. skb_unlink(skb, &priv->rx_queue);
  383. usb_unanchor_urb(entry);
  384. goto err;
  385. }
  386. usb_free_urb(entry);
  387. }
  388. return ret;
  389. err:
  390. usb_free_urb(entry);
  391. kfree_skb(skb);
  392. usb_kill_anchored_urbs(&priv->anchored);
  393. return ret;
  394. }
  395. static void rtl8187b_status_cb(struct urb *urb)
  396. {
  397. struct ieee80211_hw *hw = (struct ieee80211_hw *)urb->context;
  398. struct rtl8187_priv *priv = hw->priv;
  399. u64 val;
  400. unsigned int cmd_type;
  401. if (unlikely(urb->status))
  402. return;
  403. /*
  404. * Read from status buffer:
  405. *
  406. * bits [30:31] = cmd type:
  407. * - 0 indicates tx beacon interrupt
  408. * - 1 indicates tx close descriptor
  409. *
  410. * In the case of tx beacon interrupt:
  411. * [0:9] = Last Beacon CW
  412. * [10:29] = reserved
  413. * [30:31] = 00b
  414. * [32:63] = Last Beacon TSF
  415. *
  416. * If it's tx close descriptor:
  417. * [0:7] = Packet Retry Count
  418. * [8:14] = RTS Retry Count
  419. * [15] = TOK
  420. * [16:27] = Sequence No
  421. * [28] = LS
  422. * [29] = FS
  423. * [30:31] = 01b
  424. * [32:47] = unused (reserved?)
  425. * [48:63] = MAC Used Time
  426. */
  427. val = le64_to_cpu(priv->b_tx_status.buf);
  428. cmd_type = (val >> 30) & 0x3;
  429. if (cmd_type == 1) {
  430. unsigned int pkt_rc, seq_no;
  431. bool tok;
  432. struct sk_buff *skb;
  433. struct ieee80211_hdr *ieee80211hdr;
  434. unsigned long flags;
  435. pkt_rc = val & 0xFF;
  436. tok = val & (1 << 15);
  437. seq_no = (val >> 16) & 0xFFF;
  438. spin_lock_irqsave(&priv->b_tx_status.queue.lock, flags);
  439. skb_queue_reverse_walk(&priv->b_tx_status.queue, skb) {
  440. ieee80211hdr = (struct ieee80211_hdr *)skb->data;
  441. /*
  442. * While testing, it was discovered that the seq_no
  443. * doesn't actually contains the sequence number.
  444. * Instead of returning just the 12 bits of sequence
  445. * number, hardware is returning entire sequence control
  446. * (fragment number plus sequence number) in a 12 bit
  447. * only field overflowing after some time. As a
  448. * workaround, just consider the lower bits, and expect
  449. * it's unlikely we wrongly ack some sent data
  450. */
  451. if ((le16_to_cpu(ieee80211hdr->seq_ctrl)
  452. & 0xFFF) == seq_no)
  453. break;
  454. }
  455. if (skb != (struct sk_buff *) &priv->b_tx_status.queue) {
  456. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  457. __skb_unlink(skb, &priv->b_tx_status.queue);
  458. if (tok)
  459. info->flags |= IEEE80211_TX_STAT_ACK;
  460. info->status.rates[0].count = pkt_rc + 1;
  461. ieee80211_tx_status_irqsafe(hw, skb);
  462. }
  463. spin_unlock_irqrestore(&priv->b_tx_status.queue.lock, flags);
  464. }
  465. usb_anchor_urb(urb, &priv->anchored);
  466. if (usb_submit_urb(urb, GFP_ATOMIC))
  467. usb_unanchor_urb(urb);
  468. }
  469. static int rtl8187b_init_status_urb(struct ieee80211_hw *dev)
  470. {
  471. struct rtl8187_priv *priv = dev->priv;
  472. struct urb *entry;
  473. int ret = 0;
  474. entry = usb_alloc_urb(0, GFP_KERNEL);
  475. if (!entry)
  476. return -ENOMEM;
  477. usb_fill_bulk_urb(entry, priv->udev, usb_rcvbulkpipe(priv->udev, 9),
  478. &priv->b_tx_status.buf, sizeof(priv->b_tx_status.buf),
  479. rtl8187b_status_cb, dev);
  480. usb_anchor_urb(entry, &priv->anchored);
  481. ret = usb_submit_urb(entry, GFP_KERNEL);
  482. if (ret)
  483. usb_unanchor_urb(entry);
  484. usb_free_urb(entry);
  485. return ret;
  486. }
  487. static int rtl8187_cmd_reset(struct ieee80211_hw *dev)
  488. {
  489. struct rtl8187_priv *priv = dev->priv;
  490. u8 reg;
  491. int i;
  492. reg = rtl818x_ioread8(priv, &priv->map->CMD);
  493. reg &= (1 << 1);
  494. reg |= RTL818X_CMD_RESET;
  495. rtl818x_iowrite8(priv, &priv->map->CMD, reg);
  496. i = 10;
  497. do {
  498. msleep(2);
  499. if (!(rtl818x_ioread8(priv, &priv->map->CMD) &
  500. RTL818X_CMD_RESET))
  501. break;
  502. } while (--i);
  503. if (!i) {
  504. printk(KERN_ERR "%s: Reset timeout!\n", wiphy_name(dev->wiphy));
  505. return -ETIMEDOUT;
  506. }
  507. /* reload registers from eeprom */
  508. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_LOAD);
  509. i = 10;
  510. do {
  511. msleep(4);
  512. if (!(rtl818x_ioread8(priv, &priv->map->EEPROM_CMD) &
  513. RTL818X_EEPROM_CMD_CONFIG))
  514. break;
  515. } while (--i);
  516. if (!i) {
  517. printk(KERN_ERR "%s: eeprom reset timeout!\n",
  518. wiphy_name(dev->wiphy));
  519. return -ETIMEDOUT;
  520. }
  521. return 0;
  522. }
  523. static int rtl8187_init_hw(struct ieee80211_hw *dev)
  524. {
  525. struct rtl8187_priv *priv = dev->priv;
  526. u8 reg;
  527. int res;
  528. /* reset */
  529. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD,
  530. RTL818X_EEPROM_CMD_CONFIG);
  531. reg = rtl818x_ioread8(priv, &priv->map->CONFIG3);
  532. rtl818x_iowrite8(priv, &priv->map->CONFIG3, reg |
  533. RTL818X_CONFIG3_ANAPARAM_WRITE);
  534. rtl818x_iowrite32(priv, &priv->map->ANAPARAM,
  535. RTL8187_RTL8225_ANAPARAM_ON);
  536. rtl818x_iowrite32(priv, &priv->map->ANAPARAM2,
  537. RTL8187_RTL8225_ANAPARAM2_ON);
  538. rtl818x_iowrite8(priv, &priv->map->CONFIG3, reg &
  539. ~RTL818X_CONFIG3_ANAPARAM_WRITE);
  540. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD,
  541. RTL818X_EEPROM_CMD_NORMAL);
  542. rtl818x_iowrite16(priv, &priv->map->INT_MASK, 0);
  543. msleep(200);
  544. rtl818x_iowrite8(priv, (u8 *)0xFE18, 0x10);
  545. rtl818x_iowrite8(priv, (u8 *)0xFE18, 0x11);
  546. rtl818x_iowrite8(priv, (u8 *)0xFE18, 0x00);
  547. msleep(200);
  548. res = rtl8187_cmd_reset(dev);
  549. if (res)
  550. return res;
  551. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG);
  552. reg = rtl818x_ioread8(priv, &priv->map->CONFIG3);
  553. rtl818x_iowrite8(priv, &priv->map->CONFIG3,
  554. reg | RTL818X_CONFIG3_ANAPARAM_WRITE);
  555. rtl818x_iowrite32(priv, &priv->map->ANAPARAM,
  556. RTL8187_RTL8225_ANAPARAM_ON);
  557. rtl818x_iowrite32(priv, &priv->map->ANAPARAM2,
  558. RTL8187_RTL8225_ANAPARAM2_ON);
  559. rtl818x_iowrite8(priv, &priv->map->CONFIG3,
  560. reg & ~RTL818X_CONFIG3_ANAPARAM_WRITE);
  561. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL);
  562. /* setup card */
  563. rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, 0);
  564. rtl818x_iowrite8(priv, &priv->map->GPIO, 0);
  565. rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, (4 << 8));
  566. rtl818x_iowrite8(priv, &priv->map->GPIO, 1);
  567. rtl818x_iowrite8(priv, &priv->map->GP_ENABLE, 0);
  568. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG);
  569. rtl818x_iowrite16(priv, (__le16 *)0xFFF4, 0xFFFF);
  570. reg = rtl818x_ioread8(priv, &priv->map->CONFIG1);
  571. reg &= 0x3F;
  572. reg |= 0x80;
  573. rtl818x_iowrite8(priv, &priv->map->CONFIG1, reg);
  574. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL);
  575. rtl818x_iowrite32(priv, &priv->map->INT_TIMEOUT, 0);
  576. rtl818x_iowrite8(priv, &priv->map->WPA_CONF, 0);
  577. rtl818x_iowrite8(priv, &priv->map->RATE_FALLBACK, 0x81);
  578. // TODO: set RESP_RATE and BRSR properly
  579. rtl818x_iowrite8(priv, &priv->map->RESP_RATE, (8 << 4) | 0);
  580. rtl818x_iowrite16(priv, &priv->map->BRSR, 0x01F3);
  581. /* host_usb_init */
  582. rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, 0);
  583. rtl818x_iowrite8(priv, &priv->map->GPIO, 0);
  584. reg = rtl818x_ioread8(priv, (u8 *)0xFE53);
  585. rtl818x_iowrite8(priv, (u8 *)0xFE53, reg | (1 << 7));
  586. rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, (4 << 8));
  587. rtl818x_iowrite8(priv, &priv->map->GPIO, 0x20);
  588. rtl818x_iowrite8(priv, &priv->map->GP_ENABLE, 0);
  589. rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 0x80);
  590. rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, 0x80);
  591. rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x80);
  592. msleep(100);
  593. rtl818x_iowrite32(priv, &priv->map->RF_TIMING, 0x000a8008);
  594. rtl818x_iowrite16(priv, &priv->map->BRSR, 0xFFFF);
  595. rtl818x_iowrite32(priv, &priv->map->RF_PARA, 0x00100044);
  596. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD,
  597. RTL818X_EEPROM_CMD_CONFIG);
  598. rtl818x_iowrite8(priv, &priv->map->CONFIG3, 0x44);
  599. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD,
  600. RTL818X_EEPROM_CMD_NORMAL);
  601. rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FF7);
  602. msleep(100);
  603. priv->rf->init(dev);
  604. rtl818x_iowrite16(priv, &priv->map->BRSR, 0x01F3);
  605. reg = rtl818x_ioread8(priv, &priv->map->PGSELECT) & ~1;
  606. rtl818x_iowrite8(priv, &priv->map->PGSELECT, reg | 1);
  607. rtl818x_iowrite16(priv, (__le16 *)0xFFFE, 0x10);
  608. rtl818x_iowrite8(priv, &priv->map->TALLY_SEL, 0x80);
  609. rtl818x_iowrite8(priv, (u8 *)0xFFFF, 0x60);
  610. rtl818x_iowrite8(priv, &priv->map->PGSELECT, reg);
  611. return 0;
  612. }
  613. static const u8 rtl8187b_reg_table[][3] = {
  614. {0xF0, 0x32, 0}, {0xF1, 0x32, 0}, {0xF2, 0x00, 0}, {0xF3, 0x00, 0},
  615. {0xF4, 0x32, 0}, {0xF5, 0x43, 0}, {0xF6, 0x00, 0}, {0xF7, 0x00, 0},
  616. {0xF8, 0x46, 0}, {0xF9, 0xA4, 0}, {0xFA, 0x00, 0}, {0xFB, 0x00, 0},
  617. {0xFC, 0x96, 0}, {0xFD, 0xA4, 0}, {0xFE, 0x00, 0}, {0xFF, 0x00, 0},
  618. {0x58, 0x4B, 1}, {0x59, 0x00, 1}, {0x5A, 0x4B, 1}, {0x5B, 0x00, 1},
  619. {0x60, 0x4B, 1}, {0x61, 0x09, 1}, {0x62, 0x4B, 1}, {0x63, 0x09, 1},
  620. {0xCE, 0x0F, 1}, {0xCF, 0x00, 1}, {0xE0, 0xFF, 1}, {0xE1, 0x0F, 1},
  621. {0xE2, 0x00, 1}, {0xF0, 0x4E, 1}, {0xF1, 0x01, 1}, {0xF2, 0x02, 1},
  622. {0xF3, 0x03, 1}, {0xF4, 0x04, 1}, {0xF5, 0x05, 1}, {0xF6, 0x06, 1},
  623. {0xF7, 0x07, 1}, {0xF8, 0x08, 1},
  624. {0x4E, 0x00, 2}, {0x0C, 0x04, 2}, {0x21, 0x61, 2}, {0x22, 0x68, 2},
  625. {0x23, 0x6F, 2}, {0x24, 0x76, 2}, {0x25, 0x7D, 2}, {0x26, 0x84, 2},
  626. {0x27, 0x8D, 2}, {0x4D, 0x08, 2}, {0x50, 0x05, 2}, {0x51, 0xF5, 2},
  627. {0x52, 0x04, 2}, {0x53, 0xA0, 2}, {0x54, 0x1F, 2}, {0x55, 0x23, 2},
  628. {0x56, 0x45, 2}, {0x57, 0x67, 2}, {0x58, 0x08, 2}, {0x59, 0x08, 2},
  629. {0x5A, 0x08, 2}, {0x5B, 0x08, 2}, {0x60, 0x08, 2}, {0x61, 0x08, 2},
  630. {0x62, 0x08, 2}, {0x63, 0x08, 2}, {0x64, 0xCF, 2}, {0x72, 0x56, 2},
  631. {0x73, 0x9A, 2},
  632. {0x34, 0xF0, 0}, {0x35, 0x0F, 0}, {0x5B, 0x40, 0}, {0x84, 0x88, 0},
  633. {0x85, 0x24, 0}, {0x88, 0x54, 0}, {0x8B, 0xB8, 0}, {0x8C, 0x07, 0},
  634. {0x8D, 0x00, 0}, {0x94, 0x1B, 0}, {0x95, 0x12, 0}, {0x96, 0x00, 0},
  635. {0x97, 0x06, 0}, {0x9D, 0x1A, 0}, {0x9F, 0x10, 0}, {0xB4, 0x22, 0},
  636. {0xBE, 0x80, 0}, {0xDB, 0x00, 0}, {0xEE, 0x00, 0}, {0x91, 0x03, 0},
  637. {0x4C, 0x00, 2}, {0x9F, 0x00, 3}, {0x8C, 0x01, 0}, {0x8D, 0x10, 0},
  638. {0x8E, 0x08, 0}, {0x8F, 0x00, 0}
  639. };
  640. static int rtl8187b_init_hw(struct ieee80211_hw *dev)
  641. {
  642. struct rtl8187_priv *priv = dev->priv;
  643. int res, i;
  644. u8 reg;
  645. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD,
  646. RTL818X_EEPROM_CMD_CONFIG);
  647. reg = rtl818x_ioread8(priv, &priv->map->CONFIG3);
  648. reg |= RTL818X_CONFIG3_ANAPARAM_WRITE | RTL818X_CONFIG3_GNT_SELECT;
  649. rtl818x_iowrite8(priv, &priv->map->CONFIG3, reg);
  650. rtl818x_iowrite32(priv, &priv->map->ANAPARAM2,
  651. RTL8187B_RTL8225_ANAPARAM2_ON);
  652. rtl818x_iowrite32(priv, &priv->map->ANAPARAM,
  653. RTL8187B_RTL8225_ANAPARAM_ON);
  654. rtl818x_iowrite8(priv, &priv->map->ANAPARAM3,
  655. RTL8187B_RTL8225_ANAPARAM3_ON);
  656. rtl818x_iowrite8(priv, (u8 *)0xFF61, 0x10);
  657. reg = rtl818x_ioread8(priv, (u8 *)0xFF62);
  658. rtl818x_iowrite8(priv, (u8 *)0xFF62, reg & ~(1 << 5));
  659. rtl818x_iowrite8(priv, (u8 *)0xFF62, reg | (1 << 5));
  660. reg = rtl818x_ioread8(priv, &priv->map->CONFIG3);
  661. reg &= ~RTL818X_CONFIG3_ANAPARAM_WRITE;
  662. rtl818x_iowrite8(priv, &priv->map->CONFIG3, reg);
  663. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD,
  664. RTL818X_EEPROM_CMD_NORMAL);
  665. res = rtl8187_cmd_reset(dev);
  666. if (res)
  667. return res;
  668. rtl818x_iowrite16(priv, (__le16 *)0xFF2D, 0x0FFF);
  669. reg = rtl818x_ioread8(priv, &priv->map->CW_CONF);
  670. reg |= RTL818X_CW_CONF_PERPACKET_RETRY_SHIFT;
  671. rtl818x_iowrite8(priv, &priv->map->CW_CONF, reg);
  672. reg = rtl818x_ioread8(priv, &priv->map->TX_AGC_CTL);
  673. reg |= RTL818X_TX_AGC_CTL_PERPACKET_GAIN_SHIFT |
  674. RTL818X_TX_AGC_CTL_PERPACKET_ANTSEL_SHIFT;
  675. rtl818x_iowrite8(priv, &priv->map->TX_AGC_CTL, reg);
  676. rtl818x_iowrite16_idx(priv, (__le16 *)0xFFE0, 0x0FFF, 1);
  677. reg = rtl818x_ioread8(priv, &priv->map->RATE_FALLBACK);
  678. reg |= RTL818X_RATE_FALLBACK_ENABLE;
  679. rtl818x_iowrite8(priv, &priv->map->RATE_FALLBACK, reg);
  680. rtl818x_iowrite16(priv, &priv->map->BEACON_INTERVAL, 100);
  681. rtl818x_iowrite16(priv, &priv->map->ATIM_WND, 2);
  682. rtl818x_iowrite16_idx(priv, (__le16 *)0xFFD4, 0xFFFF, 1);
  683. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD,
  684. RTL818X_EEPROM_CMD_CONFIG);
  685. reg = rtl818x_ioread8(priv, &priv->map->CONFIG1);
  686. rtl818x_iowrite8(priv, &priv->map->CONFIG1, (reg & 0x3F) | 0x80);
  687. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD,
  688. RTL818X_EEPROM_CMD_NORMAL);
  689. rtl818x_iowrite8(priv, &priv->map->WPA_CONF, 0);
  690. for (i = 0; i < ARRAY_SIZE(rtl8187b_reg_table); i++) {
  691. rtl818x_iowrite8_idx(priv,
  692. (u8 *)(uintptr_t)
  693. (rtl8187b_reg_table[i][0] | 0xFF00),
  694. rtl8187b_reg_table[i][1],
  695. rtl8187b_reg_table[i][2]);
  696. }
  697. rtl818x_iowrite16(priv, &priv->map->TID_AC_MAP, 0xFA50);
  698. rtl818x_iowrite16(priv, &priv->map->INT_MIG, 0);
  699. rtl818x_iowrite32_idx(priv, (__le32 *)0xFFF0, 0, 1);
  700. rtl818x_iowrite32_idx(priv, (__le32 *)0xFFF4, 0, 1);
  701. rtl818x_iowrite8_idx(priv, (u8 *)0xFFF8, 0, 1);
  702. rtl818x_iowrite32(priv, &priv->map->RF_TIMING, 0x00004001);
  703. rtl818x_iowrite16_idx(priv, (__le16 *)0xFF72, 0x569A, 2);
  704. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD,
  705. RTL818X_EEPROM_CMD_CONFIG);
  706. reg = rtl818x_ioread8(priv, &priv->map->CONFIG3);
  707. reg |= RTL818X_CONFIG3_ANAPARAM_WRITE;
  708. rtl818x_iowrite8(priv, &priv->map->CONFIG3, reg);
  709. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD,
  710. RTL818X_EEPROM_CMD_NORMAL);
  711. rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 0x0480);
  712. rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, 0x2488);
  713. rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FFF);
  714. msleep(100);
  715. priv->rf->init(dev);
  716. reg = RTL818X_CMD_TX_ENABLE | RTL818X_CMD_RX_ENABLE;
  717. rtl818x_iowrite8(priv, &priv->map->CMD, reg);
  718. rtl818x_iowrite16(priv, &priv->map->INT_MASK, 0xFFFF);
  719. rtl818x_iowrite8(priv, (u8 *)0xFE41, 0xF4);
  720. rtl818x_iowrite8(priv, (u8 *)0xFE40, 0x00);
  721. rtl818x_iowrite8(priv, (u8 *)0xFE42, 0x00);
  722. rtl818x_iowrite8(priv, (u8 *)0xFE42, 0x01);
  723. rtl818x_iowrite8(priv, (u8 *)0xFE40, 0x0F);
  724. rtl818x_iowrite8(priv, (u8 *)0xFE42, 0x00);
  725. rtl818x_iowrite8(priv, (u8 *)0xFE42, 0x01);
  726. reg = rtl818x_ioread8(priv, (u8 *)0xFFDB);
  727. rtl818x_iowrite8(priv, (u8 *)0xFFDB, reg | (1 << 2));
  728. rtl818x_iowrite16_idx(priv, (__le16 *)0xFF72, 0x59FA, 3);
  729. rtl818x_iowrite16_idx(priv, (__le16 *)0xFF74, 0x59D2, 3);
  730. rtl818x_iowrite16_idx(priv, (__le16 *)0xFF76, 0x59D2, 3);
  731. rtl818x_iowrite16_idx(priv, (__le16 *)0xFF78, 0x19FA, 3);
  732. rtl818x_iowrite16_idx(priv, (__le16 *)0xFF7A, 0x19FA, 3);
  733. rtl818x_iowrite16_idx(priv, (__le16 *)0xFF7C, 0x00D0, 3);
  734. rtl818x_iowrite8(priv, (u8 *)0xFF61, 0);
  735. rtl818x_iowrite8_idx(priv, (u8 *)0xFF80, 0x0F, 1);
  736. rtl818x_iowrite8_idx(priv, (u8 *)0xFF83, 0x03, 1);
  737. rtl818x_iowrite8(priv, (u8 *)0xFFDA, 0x10);
  738. rtl818x_iowrite8_idx(priv, (u8 *)0xFF4D, 0x08, 2);
  739. rtl818x_iowrite32(priv, &priv->map->HSSI_PARA, 0x0600321B);
  740. rtl818x_iowrite16_idx(priv, (__le16 *)0xFFEC, 0x0800, 1);
  741. priv->slot_time = 0x9;
  742. priv->aifsn[0] = 2; /* AIFSN[AC_VO] */
  743. priv->aifsn[1] = 2; /* AIFSN[AC_VI] */
  744. priv->aifsn[2] = 7; /* AIFSN[AC_BK] */
  745. priv->aifsn[3] = 3; /* AIFSN[AC_BE] */
  746. rtl818x_iowrite8(priv, &priv->map->ACM_CONTROL, 0);
  747. return 0;
  748. }
  749. static int rtl8187_start(struct ieee80211_hw *dev)
  750. {
  751. struct rtl8187_priv *priv = dev->priv;
  752. u32 reg;
  753. int ret;
  754. ret = (!priv->is_rtl8187b) ? rtl8187_init_hw(dev) :
  755. rtl8187b_init_hw(dev);
  756. if (ret)
  757. return ret;
  758. mutex_lock(&priv->conf_mutex);
  759. init_usb_anchor(&priv->anchored);
  760. if (priv->is_rtl8187b) {
  761. reg = RTL818X_RX_CONF_MGMT |
  762. RTL818X_RX_CONF_DATA |
  763. RTL818X_RX_CONF_BROADCAST |
  764. RTL818X_RX_CONF_NICMAC |
  765. RTL818X_RX_CONF_BSSID |
  766. (7 << 13 /* RX FIFO threshold NONE */) |
  767. (7 << 10 /* MAX RX DMA */) |
  768. RTL818X_RX_CONF_RX_AUTORESETPHY |
  769. RTL818X_RX_CONF_ONLYERLPKT |
  770. RTL818X_RX_CONF_MULTICAST;
  771. priv->rx_conf = reg;
  772. rtl818x_iowrite32(priv, &priv->map->RX_CONF, reg);
  773. rtl818x_iowrite32(priv, &priv->map->TX_CONF,
  774. RTL818X_TX_CONF_HW_SEQNUM |
  775. RTL818X_TX_CONF_DISREQQSIZE |
  776. (7 << 8 /* short retry limit */) |
  777. (7 << 0 /* long retry limit */) |
  778. (7 << 21 /* MAX TX DMA */));
  779. rtl8187_init_urbs(dev);
  780. rtl8187b_init_status_urb(dev);
  781. mutex_unlock(&priv->conf_mutex);
  782. return 0;
  783. }
  784. rtl818x_iowrite16(priv, &priv->map->INT_MASK, 0xFFFF);
  785. rtl818x_iowrite32(priv, &priv->map->MAR[0], ~0);
  786. rtl818x_iowrite32(priv, &priv->map->MAR[1], ~0);
  787. rtl8187_init_urbs(dev);
  788. reg = RTL818X_RX_CONF_ONLYERLPKT |
  789. RTL818X_RX_CONF_RX_AUTORESETPHY |
  790. RTL818X_RX_CONF_BSSID |
  791. RTL818X_RX_CONF_MGMT |
  792. RTL818X_RX_CONF_DATA |
  793. (7 << 13 /* RX FIFO threshold NONE */) |
  794. (7 << 10 /* MAX RX DMA */) |
  795. RTL818X_RX_CONF_BROADCAST |
  796. RTL818X_RX_CONF_NICMAC;
  797. priv->rx_conf = reg;
  798. rtl818x_iowrite32(priv, &priv->map->RX_CONF, reg);
  799. reg = rtl818x_ioread8(priv, &priv->map->CW_CONF);
  800. reg &= ~RTL818X_CW_CONF_PERPACKET_CW_SHIFT;
  801. reg |= RTL818X_CW_CONF_PERPACKET_RETRY_SHIFT;
  802. rtl818x_iowrite8(priv, &priv->map->CW_CONF, reg);
  803. reg = rtl818x_ioread8(priv, &priv->map->TX_AGC_CTL);
  804. reg &= ~RTL818X_TX_AGC_CTL_PERPACKET_GAIN_SHIFT;
  805. reg &= ~RTL818X_TX_AGC_CTL_PERPACKET_ANTSEL_SHIFT;
  806. reg &= ~RTL818X_TX_AGC_CTL_FEEDBACK_ANT;
  807. rtl818x_iowrite8(priv, &priv->map->TX_AGC_CTL, reg);
  808. reg = RTL818X_TX_CONF_CW_MIN |
  809. (7 << 21 /* MAX TX DMA */) |
  810. RTL818X_TX_CONF_NO_ICV;
  811. rtl818x_iowrite32(priv, &priv->map->TX_CONF, reg);
  812. reg = rtl818x_ioread8(priv, &priv->map->CMD);
  813. reg |= RTL818X_CMD_TX_ENABLE;
  814. reg |= RTL818X_CMD_RX_ENABLE;
  815. rtl818x_iowrite8(priv, &priv->map->CMD, reg);
  816. mutex_unlock(&priv->conf_mutex);
  817. return 0;
  818. }
  819. static void rtl8187_stop(struct ieee80211_hw *dev)
  820. {
  821. struct rtl8187_priv *priv = dev->priv;
  822. struct sk_buff *skb;
  823. u32 reg;
  824. mutex_lock(&priv->conf_mutex);
  825. rtl818x_iowrite16(priv, &priv->map->INT_MASK, 0);
  826. reg = rtl818x_ioread8(priv, &priv->map->CMD);
  827. reg &= ~RTL818X_CMD_TX_ENABLE;
  828. reg &= ~RTL818X_CMD_RX_ENABLE;
  829. rtl818x_iowrite8(priv, &priv->map->CMD, reg);
  830. priv->rf->stop(dev);
  831. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG);
  832. reg = rtl818x_ioread8(priv, &priv->map->CONFIG4);
  833. rtl818x_iowrite8(priv, &priv->map->CONFIG4, reg | RTL818X_CONFIG4_VCOOFF);
  834. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL);
  835. while ((skb = skb_dequeue(&priv->b_tx_status.queue)))
  836. dev_kfree_skb_any(skb);
  837. usb_kill_anchored_urbs(&priv->anchored);
  838. mutex_unlock(&priv->conf_mutex);
  839. }
  840. static int rtl8187_add_interface(struct ieee80211_hw *dev,
  841. struct ieee80211_if_init_conf *conf)
  842. {
  843. struct rtl8187_priv *priv = dev->priv;
  844. int i;
  845. if (priv->mode != NL80211_IFTYPE_MONITOR)
  846. return -EOPNOTSUPP;
  847. switch (conf->type) {
  848. case NL80211_IFTYPE_STATION:
  849. priv->mode = conf->type;
  850. break;
  851. default:
  852. return -EOPNOTSUPP;
  853. }
  854. mutex_lock(&priv->conf_mutex);
  855. priv->vif = conf->vif;
  856. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG);
  857. for (i = 0; i < ETH_ALEN; i++)
  858. rtl818x_iowrite8(priv, &priv->map->MAC[i],
  859. ((u8 *)conf->mac_addr)[i]);
  860. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL);
  861. mutex_unlock(&priv->conf_mutex);
  862. return 0;
  863. }
  864. static void rtl8187_remove_interface(struct ieee80211_hw *dev,
  865. struct ieee80211_if_init_conf *conf)
  866. {
  867. struct rtl8187_priv *priv = dev->priv;
  868. mutex_lock(&priv->conf_mutex);
  869. priv->mode = NL80211_IFTYPE_MONITOR;
  870. priv->vif = NULL;
  871. mutex_unlock(&priv->conf_mutex);
  872. }
  873. static int rtl8187_config(struct ieee80211_hw *dev, u32 changed)
  874. {
  875. struct rtl8187_priv *priv = dev->priv;
  876. struct ieee80211_conf *conf = &dev->conf;
  877. u32 reg;
  878. mutex_lock(&priv->conf_mutex);
  879. reg = rtl818x_ioread32(priv, &priv->map->TX_CONF);
  880. /* Enable TX loopback on MAC level to avoid TX during channel
  881. * changes, as this has be seen to causes problems and the
  882. * card will stop work until next reset
  883. */
  884. rtl818x_iowrite32(priv, &priv->map->TX_CONF,
  885. reg | RTL818X_TX_CONF_LOOPBACK_MAC);
  886. priv->rf->set_chan(dev, conf);
  887. msleep(10);
  888. rtl818x_iowrite32(priv, &priv->map->TX_CONF, reg);
  889. rtl818x_iowrite16(priv, &priv->map->ATIM_WND, 2);
  890. rtl818x_iowrite16(priv, &priv->map->ATIMTR_INTERVAL, 100);
  891. rtl818x_iowrite16(priv, &priv->map->BEACON_INTERVAL, 100);
  892. rtl818x_iowrite16(priv, &priv->map->BEACON_INTERVAL_TIME, 100);
  893. mutex_unlock(&priv->conf_mutex);
  894. return 0;
  895. }
  896. static int rtl8187_config_interface(struct ieee80211_hw *dev,
  897. struct ieee80211_vif *vif,
  898. struct ieee80211_if_conf *conf)
  899. {
  900. struct rtl8187_priv *priv = dev->priv;
  901. int i;
  902. u8 reg;
  903. mutex_lock(&priv->conf_mutex);
  904. for (i = 0; i < ETH_ALEN; i++)
  905. rtl818x_iowrite8(priv, &priv->map->BSSID[i], conf->bssid[i]);
  906. if (is_valid_ether_addr(conf->bssid)) {
  907. reg = RTL818X_MSR_INFRA;
  908. if (priv->is_rtl8187b)
  909. reg |= RTL818X_MSR_ENEDCA;
  910. rtl818x_iowrite8(priv, &priv->map->MSR, reg);
  911. } else {
  912. reg = RTL818X_MSR_NO_LINK;
  913. rtl818x_iowrite8(priv, &priv->map->MSR, reg);
  914. }
  915. mutex_unlock(&priv->conf_mutex);
  916. return 0;
  917. }
  918. /*
  919. * With 8187B, AC_*_PARAM clashes with FEMR definition in struct rtl818x_csr for
  920. * example. Thus we have to use raw values for AC_*_PARAM register addresses.
  921. */
  922. static __le32 *rtl8187b_ac_addr[4] = {
  923. (__le32 *) 0xFFF0, /* AC_VO */
  924. (__le32 *) 0xFFF4, /* AC_VI */
  925. (__le32 *) 0xFFFC, /* AC_BK */
  926. (__le32 *) 0xFFF8, /* AC_BE */
  927. };
  928. #define SIFS_TIME 0xa
  929. static void rtl8187_conf_erp(struct rtl8187_priv *priv, bool use_short_slot,
  930. bool use_short_preamble)
  931. {
  932. if (priv->is_rtl8187b) {
  933. u8 difs, eifs;
  934. u16 ack_timeout;
  935. int queue;
  936. if (use_short_slot) {
  937. priv->slot_time = 0x9;
  938. difs = 0x1c;
  939. eifs = 0x53;
  940. } else {
  941. priv->slot_time = 0x14;
  942. difs = 0x32;
  943. eifs = 0x5b;
  944. }
  945. rtl818x_iowrite8(priv, &priv->map->SIFS, 0x22);
  946. rtl818x_iowrite8(priv, &priv->map->SLOT, priv->slot_time);
  947. rtl818x_iowrite8(priv, &priv->map->DIFS, difs);
  948. /*
  949. * BRSR+1 on 8187B is in fact EIFS register
  950. * Value in units of 4 us
  951. */
  952. rtl818x_iowrite8(priv, (u8 *)&priv->map->BRSR + 1, eifs);
  953. /*
  954. * For 8187B, CARRIER_SENSE_COUNTER is in fact ack timeout
  955. * register. In units of 4 us like eifs register
  956. * ack_timeout = ack duration + plcp + difs + preamble
  957. */
  958. ack_timeout = 112 + 48 + difs;
  959. if (use_short_preamble)
  960. ack_timeout += 72;
  961. else
  962. ack_timeout += 144;
  963. rtl818x_iowrite8(priv, &priv->map->CARRIER_SENSE_COUNTER,
  964. DIV_ROUND_UP(ack_timeout, 4));
  965. for (queue = 0; queue < 4; queue++)
  966. rtl818x_iowrite8(priv, (u8 *) rtl8187b_ac_addr[queue],
  967. priv->aifsn[queue] * priv->slot_time +
  968. SIFS_TIME);
  969. } else {
  970. rtl818x_iowrite8(priv, &priv->map->SIFS, 0x22);
  971. if (use_short_slot) {
  972. rtl818x_iowrite8(priv, &priv->map->SLOT, 0x9);
  973. rtl818x_iowrite8(priv, &priv->map->DIFS, 0x14);
  974. rtl818x_iowrite8(priv, &priv->map->EIFS, 91 - 0x14);
  975. } else {
  976. rtl818x_iowrite8(priv, &priv->map->SLOT, 0x14);
  977. rtl818x_iowrite8(priv, &priv->map->DIFS, 0x24);
  978. rtl818x_iowrite8(priv, &priv->map->EIFS, 91 - 0x24);
  979. }
  980. }
  981. }
  982. static void rtl8187_bss_info_changed(struct ieee80211_hw *dev,
  983. struct ieee80211_vif *vif,
  984. struct ieee80211_bss_conf *info,
  985. u32 changed)
  986. {
  987. struct rtl8187_priv *priv = dev->priv;
  988. if (changed & (BSS_CHANGED_ERP_SLOT | BSS_CHANGED_ERP_PREAMBLE))
  989. rtl8187_conf_erp(priv, info->use_short_slot,
  990. info->use_short_preamble);
  991. }
  992. static void rtl8187_configure_filter(struct ieee80211_hw *dev,
  993. unsigned int changed_flags,
  994. unsigned int *total_flags,
  995. int mc_count, struct dev_addr_list *mclist)
  996. {
  997. struct rtl8187_priv *priv = dev->priv;
  998. if (changed_flags & FIF_FCSFAIL)
  999. priv->rx_conf ^= RTL818X_RX_CONF_FCS;
  1000. if (changed_flags & FIF_CONTROL)
  1001. priv->rx_conf ^= RTL818X_RX_CONF_CTRL;
  1002. if (changed_flags & FIF_OTHER_BSS)
  1003. priv->rx_conf ^= RTL818X_RX_CONF_MONITOR;
  1004. if (*total_flags & FIF_ALLMULTI || mc_count > 0)
  1005. priv->rx_conf |= RTL818X_RX_CONF_MULTICAST;
  1006. else
  1007. priv->rx_conf &= ~RTL818X_RX_CONF_MULTICAST;
  1008. *total_flags = 0;
  1009. if (priv->rx_conf & RTL818X_RX_CONF_FCS)
  1010. *total_flags |= FIF_FCSFAIL;
  1011. if (priv->rx_conf & RTL818X_RX_CONF_CTRL)
  1012. *total_flags |= FIF_CONTROL;
  1013. if (priv->rx_conf & RTL818X_RX_CONF_MONITOR)
  1014. *total_flags |= FIF_OTHER_BSS;
  1015. if (priv->rx_conf & RTL818X_RX_CONF_MULTICAST)
  1016. *total_flags |= FIF_ALLMULTI;
  1017. rtl818x_iowrite32_async(priv, &priv->map->RX_CONF, priv->rx_conf);
  1018. }
  1019. static int rtl8187_conf_tx(struct ieee80211_hw *dev, u16 queue,
  1020. const struct ieee80211_tx_queue_params *params)
  1021. {
  1022. struct rtl8187_priv *priv = dev->priv;
  1023. u8 cw_min, cw_max;
  1024. if (queue > 3)
  1025. return -EINVAL;
  1026. cw_min = fls(params->cw_min);
  1027. cw_max = fls(params->cw_max);
  1028. if (priv->is_rtl8187b) {
  1029. priv->aifsn[queue] = params->aifs;
  1030. /*
  1031. * This is the structure of AC_*_PARAM registers in 8187B:
  1032. * - TXOP limit field, bit offset = 16
  1033. * - ECWmax, bit offset = 12
  1034. * - ECWmin, bit offset = 8
  1035. * - AIFS, bit offset = 0
  1036. */
  1037. rtl818x_iowrite32(priv, rtl8187b_ac_addr[queue],
  1038. (params->txop << 16) | (cw_max << 12) |
  1039. (cw_min << 8) | (params->aifs *
  1040. priv->slot_time + SIFS_TIME));
  1041. } else {
  1042. if (queue != 0)
  1043. return -EINVAL;
  1044. rtl818x_iowrite8(priv, &priv->map->CW_VAL,
  1045. cw_min | (cw_max << 4));
  1046. }
  1047. return 0;
  1048. }
  1049. static const struct ieee80211_ops rtl8187_ops = {
  1050. .tx = rtl8187_tx,
  1051. .start = rtl8187_start,
  1052. .stop = rtl8187_stop,
  1053. .add_interface = rtl8187_add_interface,
  1054. .remove_interface = rtl8187_remove_interface,
  1055. .config = rtl8187_config,
  1056. .config_interface = rtl8187_config_interface,
  1057. .bss_info_changed = rtl8187_bss_info_changed,
  1058. .configure_filter = rtl8187_configure_filter,
  1059. .conf_tx = rtl8187_conf_tx
  1060. };
  1061. static void rtl8187_eeprom_register_read(struct eeprom_93cx6 *eeprom)
  1062. {
  1063. struct ieee80211_hw *dev = eeprom->data;
  1064. struct rtl8187_priv *priv = dev->priv;
  1065. u8 reg = rtl818x_ioread8(priv, &priv->map->EEPROM_CMD);
  1066. eeprom->reg_data_in = reg & RTL818X_EEPROM_CMD_WRITE;
  1067. eeprom->reg_data_out = reg & RTL818X_EEPROM_CMD_READ;
  1068. eeprom->reg_data_clock = reg & RTL818X_EEPROM_CMD_CK;
  1069. eeprom->reg_chip_select = reg & RTL818X_EEPROM_CMD_CS;
  1070. }
  1071. static void rtl8187_eeprom_register_write(struct eeprom_93cx6 *eeprom)
  1072. {
  1073. struct ieee80211_hw *dev = eeprom->data;
  1074. struct rtl8187_priv *priv = dev->priv;
  1075. u8 reg = RTL818X_EEPROM_CMD_PROGRAM;
  1076. if (eeprom->reg_data_in)
  1077. reg |= RTL818X_EEPROM_CMD_WRITE;
  1078. if (eeprom->reg_data_out)
  1079. reg |= RTL818X_EEPROM_CMD_READ;
  1080. if (eeprom->reg_data_clock)
  1081. reg |= RTL818X_EEPROM_CMD_CK;
  1082. if (eeprom->reg_chip_select)
  1083. reg |= RTL818X_EEPROM_CMD_CS;
  1084. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, reg);
  1085. udelay(10);
  1086. }
  1087. static int __devinit rtl8187_probe(struct usb_interface *intf,
  1088. const struct usb_device_id *id)
  1089. {
  1090. struct usb_device *udev = interface_to_usbdev(intf);
  1091. struct ieee80211_hw *dev;
  1092. struct rtl8187_priv *priv;
  1093. struct eeprom_93cx6 eeprom;
  1094. struct ieee80211_channel *channel;
  1095. const char *chip_name;
  1096. u16 txpwr, reg;
  1097. int err, i;
  1098. dev = ieee80211_alloc_hw(sizeof(*priv), &rtl8187_ops);
  1099. if (!dev) {
  1100. printk(KERN_ERR "rtl8187: ieee80211 alloc failed\n");
  1101. return -ENOMEM;
  1102. }
  1103. priv = dev->priv;
  1104. priv->is_rtl8187b = (id->driver_info == DEVICE_RTL8187B);
  1105. SET_IEEE80211_DEV(dev, &intf->dev);
  1106. usb_set_intfdata(intf, dev);
  1107. priv->udev = udev;
  1108. usb_get_dev(udev);
  1109. skb_queue_head_init(&priv->rx_queue);
  1110. BUILD_BUG_ON(sizeof(priv->channels) != sizeof(rtl818x_channels));
  1111. BUILD_BUG_ON(sizeof(priv->rates) != sizeof(rtl818x_rates));
  1112. memcpy(priv->channels, rtl818x_channels, sizeof(rtl818x_channels));
  1113. memcpy(priv->rates, rtl818x_rates, sizeof(rtl818x_rates));
  1114. priv->map = (struct rtl818x_csr *)0xFF00;
  1115. priv->band.band = IEEE80211_BAND_2GHZ;
  1116. priv->band.channels = priv->channels;
  1117. priv->band.n_channels = ARRAY_SIZE(rtl818x_channels);
  1118. priv->band.bitrates = priv->rates;
  1119. priv->band.n_bitrates = ARRAY_SIZE(rtl818x_rates);
  1120. dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
  1121. priv->mode = NL80211_IFTYPE_MONITOR;
  1122. dev->flags = IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
  1123. IEEE80211_HW_SIGNAL_DBM |
  1124. IEEE80211_HW_RX_INCLUDES_FCS;
  1125. eeprom.data = dev;
  1126. eeprom.register_read = rtl8187_eeprom_register_read;
  1127. eeprom.register_write = rtl8187_eeprom_register_write;
  1128. if (rtl818x_ioread32(priv, &priv->map->RX_CONF) & (1 << 6))
  1129. eeprom.width = PCI_EEPROM_WIDTH_93C66;
  1130. else
  1131. eeprom.width = PCI_EEPROM_WIDTH_93C46;
  1132. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG);
  1133. udelay(10);
  1134. eeprom_93cx6_multiread(&eeprom, RTL8187_EEPROM_MAC_ADDR,
  1135. (__le16 __force *)dev->wiphy->perm_addr, 3);
  1136. if (!is_valid_ether_addr(dev->wiphy->perm_addr)) {
  1137. printk(KERN_WARNING "rtl8187: Invalid hwaddr! Using randomly "
  1138. "generated MAC address\n");
  1139. random_ether_addr(dev->wiphy->perm_addr);
  1140. }
  1141. channel = priv->channels;
  1142. for (i = 0; i < 3; i++) {
  1143. eeprom_93cx6_read(&eeprom, RTL8187_EEPROM_TXPWR_CHAN_1 + i,
  1144. &txpwr);
  1145. (*channel++).hw_value = txpwr & 0xFF;
  1146. (*channel++).hw_value = txpwr >> 8;
  1147. }
  1148. for (i = 0; i < 2; i++) {
  1149. eeprom_93cx6_read(&eeprom, RTL8187_EEPROM_TXPWR_CHAN_4 + i,
  1150. &txpwr);
  1151. (*channel++).hw_value = txpwr & 0xFF;
  1152. (*channel++).hw_value = txpwr >> 8;
  1153. }
  1154. eeprom_93cx6_read(&eeprom, RTL8187_EEPROM_TXPWR_BASE,
  1155. &priv->txpwr_base);
  1156. reg = rtl818x_ioread8(priv, &priv->map->PGSELECT) & ~1;
  1157. rtl818x_iowrite8(priv, &priv->map->PGSELECT, reg | 1);
  1158. /* 0 means asic B-cut, we should use SW 3 wire
  1159. * bit-by-bit banging for radio. 1 means we can use
  1160. * USB specific request to write radio registers */
  1161. priv->asic_rev = rtl818x_ioread8(priv, (u8 *)0xFFFE) & 0x3;
  1162. rtl818x_iowrite8(priv, &priv->map->PGSELECT, reg);
  1163. rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL);
  1164. if (!priv->is_rtl8187b) {
  1165. u32 reg32;
  1166. reg32 = rtl818x_ioread32(priv, &priv->map->TX_CONF);
  1167. reg32 &= RTL818X_TX_CONF_HWVER_MASK;
  1168. switch (reg32) {
  1169. case RTL818X_TX_CONF_R8187vD_B:
  1170. /* Some RTL8187B devices have a USB ID of 0x8187
  1171. * detect them here */
  1172. chip_name = "RTL8187BvB(early)";
  1173. priv->is_rtl8187b = 1;
  1174. priv->hw_rev = RTL8187BvB;
  1175. break;
  1176. case RTL818X_TX_CONF_R8187vD:
  1177. chip_name = "RTL8187vD";
  1178. break;
  1179. default:
  1180. chip_name = "RTL8187vB (default)";
  1181. }
  1182. } else {
  1183. /*
  1184. * Force USB request to write radio registers for 8187B, Realtek
  1185. * only uses it in their sources
  1186. */
  1187. /*if (priv->asic_rev == 0) {
  1188. printk(KERN_WARNING "rtl8187: Forcing use of USB "
  1189. "requests to write to radio registers\n");
  1190. priv->asic_rev = 1;
  1191. }*/
  1192. switch (rtl818x_ioread8(priv, (u8 *)0xFFE1)) {
  1193. case RTL818X_R8187B_B:
  1194. chip_name = "RTL8187BvB";
  1195. priv->hw_rev = RTL8187BvB;
  1196. break;
  1197. case RTL818X_R8187B_D:
  1198. chip_name = "RTL8187BvD";
  1199. priv->hw_rev = RTL8187BvD;
  1200. break;
  1201. case RTL818X_R8187B_E:
  1202. chip_name = "RTL8187BvE";
  1203. priv->hw_rev = RTL8187BvE;
  1204. break;
  1205. default:
  1206. chip_name = "RTL8187BvB (default)";
  1207. priv->hw_rev = RTL8187BvB;
  1208. }
  1209. }
  1210. if (!priv->is_rtl8187b) {
  1211. for (i = 0; i < 2; i++) {
  1212. eeprom_93cx6_read(&eeprom,
  1213. RTL8187_EEPROM_TXPWR_CHAN_6 + i,
  1214. &txpwr);
  1215. (*channel++).hw_value = txpwr & 0xFF;
  1216. (*channel++).hw_value = txpwr >> 8;
  1217. }
  1218. } else {
  1219. eeprom_93cx6_read(&eeprom, RTL8187_EEPROM_TXPWR_CHAN_6,
  1220. &txpwr);
  1221. (*channel++).hw_value = txpwr & 0xFF;
  1222. eeprom_93cx6_read(&eeprom, 0x0A, &txpwr);
  1223. (*channel++).hw_value = txpwr & 0xFF;
  1224. eeprom_93cx6_read(&eeprom, 0x1C, &txpwr);
  1225. (*channel++).hw_value = txpwr & 0xFF;
  1226. (*channel++).hw_value = txpwr >> 8;
  1227. }
  1228. if (priv->is_rtl8187b)
  1229. printk(KERN_WARNING "rtl8187: 8187B chip detected.\n");
  1230. /*
  1231. * XXX: Once this driver supports anything that requires
  1232. * beacons it must implement IEEE80211_TX_CTL_ASSIGN_SEQ.
  1233. */
  1234. dev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
  1235. if ((id->driver_info == DEVICE_RTL8187) && priv->is_rtl8187b)
  1236. printk(KERN_INFO "rtl8187: inconsistency between id with OEM"
  1237. " info!\n");
  1238. priv->rf = rtl8187_detect_rf(dev);
  1239. dev->extra_tx_headroom = (!priv->is_rtl8187b) ?
  1240. sizeof(struct rtl8187_tx_hdr) :
  1241. sizeof(struct rtl8187b_tx_hdr);
  1242. if (!priv->is_rtl8187b)
  1243. dev->queues = 1;
  1244. else
  1245. dev->queues = 4;
  1246. err = ieee80211_register_hw(dev);
  1247. if (err) {
  1248. printk(KERN_ERR "rtl8187: Cannot register device\n");
  1249. goto err_free_dev;
  1250. }
  1251. mutex_init(&priv->conf_mutex);
  1252. skb_queue_head_init(&priv->b_tx_status.queue);
  1253. printk(KERN_INFO "%s: hwaddr %pM, %s V%d + %s\n",
  1254. wiphy_name(dev->wiphy), dev->wiphy->perm_addr,
  1255. chip_name, priv->asic_rev, priv->rf->name);
  1256. return 0;
  1257. err_free_dev:
  1258. ieee80211_free_hw(dev);
  1259. usb_set_intfdata(intf, NULL);
  1260. usb_put_dev(udev);
  1261. return err;
  1262. }
  1263. static void __devexit rtl8187_disconnect(struct usb_interface *intf)
  1264. {
  1265. struct ieee80211_hw *dev = usb_get_intfdata(intf);
  1266. struct rtl8187_priv *priv;
  1267. if (!dev)
  1268. return;
  1269. ieee80211_unregister_hw(dev);
  1270. priv = dev->priv;
  1271. usb_reset_device(priv->udev);
  1272. usb_put_dev(interface_to_usbdev(intf));
  1273. ieee80211_free_hw(dev);
  1274. }
  1275. static struct usb_driver rtl8187_driver = {
  1276. .name = KBUILD_MODNAME,
  1277. .id_table = rtl8187_table,
  1278. .probe = rtl8187_probe,
  1279. .disconnect = __devexit_p(rtl8187_disconnect),
  1280. };
  1281. static int __init rtl8187_init(void)
  1282. {
  1283. return usb_register(&rtl8187_driver);
  1284. }
  1285. static void __exit rtl8187_exit(void)
  1286. {
  1287. usb_deregister(&rtl8187_driver);
  1288. }
  1289. module_init(rtl8187_init);
  1290. module_exit(rtl8187_exit);