rtl8187_dev.c 44 KB

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