rtl8187_dev.c 43 KB

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