orinoco_usb.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754
  1. /*
  2. * USB Orinoco driver
  3. *
  4. * Copyright (c) 2003 Manuel Estrada Sainz
  5. *
  6. * The contents of this file are subject to the Mozilla Public License
  7. * Version 1.1 (the "License"); you may not use this file except in
  8. * compliance with the License. You may obtain a copy of the License
  9. * at http://www.mozilla.org/MPL/
  10. *
  11. * Software distributed under the License is distributed on an "AS IS"
  12. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  13. * the License for the specific language governing rights and
  14. * limitations under the License.
  15. *
  16. * Alternatively, the contents of this file may be used under the
  17. * terms of the GNU General Public License version 2 (the "GPL"), in
  18. * which case the provisions of the GPL are applicable instead of the
  19. * above. If you wish to allow the use of your version of this file
  20. * only under the terms of the GPL and not to allow others to use your
  21. * version of this file under the MPL, indicate your decision by
  22. * deleting the provisions above and replace them with the notice and
  23. * other provisions required by the GPL. If you do not delete the
  24. * provisions above, a recipient may use your version of this file
  25. * under either the MPL or the GPL.
  26. *
  27. * Queueing code based on linux-wlan-ng 0.2.1-pre5
  28. *
  29. * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
  30. *
  31. * The license is the same as above.
  32. *
  33. * Initialy based on USB Skeleton driver - 0.7
  34. *
  35. * Copyright (c) 2001 Greg Kroah-Hartman (greg@kroah.com)
  36. *
  37. * This program is free software; you can redistribute it and/or
  38. * modify it under the terms of the GNU General Public License as
  39. * published by the Free Software Foundation; either version 2 of
  40. * the License, or (at your option) any later version.
  41. *
  42. * NOTE: The original USB Skeleton driver is GPL, but all that code is
  43. * gone so MPL/GPL applies.
  44. */
  45. #define DRIVER_NAME "orinoco_usb"
  46. #define PFX DRIVER_NAME ": "
  47. #include <linux/module.h>
  48. #include <linux/kernel.h>
  49. #include <linux/sched.h>
  50. #include <linux/signal.h>
  51. #include <linux/errno.h>
  52. #include <linux/poll.h>
  53. #include <linux/slab.h>
  54. #include <linux/fcntl.h>
  55. #include <linux/spinlock.h>
  56. #include <linux/list.h>
  57. #include <linux/usb.h>
  58. #include <linux/timer.h>
  59. #include <linux/netdevice.h>
  60. #include <linux/if_arp.h>
  61. #include <linux/etherdevice.h>
  62. #include <linux/wireless.h>
  63. #include <linux/firmware.h>
  64. #include "mic.h"
  65. #include "orinoco.h"
  66. #ifndef URB_ASYNC_UNLINK
  67. #define URB_ASYNC_UNLINK 0
  68. #endif
  69. /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
  70. static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
  71. #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
  72. struct header_struct {
  73. /* 802.3 */
  74. u8 dest[ETH_ALEN];
  75. u8 src[ETH_ALEN];
  76. __be16 len;
  77. /* 802.2 */
  78. u8 dsap;
  79. u8 ssap;
  80. u8 ctrl;
  81. /* SNAP */
  82. u8 oui[3];
  83. __be16 ethertype;
  84. } __packed;
  85. struct ez_usb_fw {
  86. u16 size;
  87. const u8 *code;
  88. };
  89. static struct ez_usb_fw firmware = {
  90. .size = 0,
  91. .code = NULL,
  92. };
  93. /* Debugging macros */
  94. #undef err
  95. #define err(format, arg...) \
  96. do { printk(KERN_ERR PFX format "\n", ## arg); } while (0)
  97. MODULE_FIRMWARE("orinoco_ezusb_fw");
  98. /*
  99. * Under some conditions, the card gets stuck and stops paying attention
  100. * to the world (i.e. data communication stalls) until we do something to
  101. * it. Sending an INQ_TALLIES command seems to be enough and should be
  102. * harmless otherwise. This behaviour has been observed when using the
  103. * driver on a systemimager client during installation. In the past a
  104. * timer was used to send INQ_TALLIES commands when there was no other
  105. * activity, but it was troublesome and was removed.
  106. */
  107. #define USB_COMPAQ_VENDOR_ID 0x049f /* Compaq Computer Corp. */
  108. #define USB_COMPAQ_WL215_ID 0x001f /* Compaq WL215 USB Adapter */
  109. #define USB_COMPAQ_W200_ID 0x0076 /* Compaq W200 USB Adapter */
  110. #define USB_HP_WL215_ID 0x0082 /* Compaq WL215 USB Adapter */
  111. #define USB_MELCO_VENDOR_ID 0x0411
  112. #define USB_BUFFALO_L11_ID 0x0006 /* BUFFALO WLI-USB-L11 */
  113. #define USB_BUFFALO_L11G_WR_ID 0x000B /* BUFFALO WLI-USB-L11G-WR */
  114. #define USB_BUFFALO_L11G_ID 0x000D /* BUFFALO WLI-USB-L11G */
  115. #define USB_LUCENT_VENDOR_ID 0x047E /* Lucent Technologies */
  116. #define USB_LUCENT_ORINOCO_ID 0x0300 /* Lucent/Agere Orinoco USB Client */
  117. #define USB_AVAYA8_VENDOR_ID 0x0D98
  118. #define USB_AVAYAE_VENDOR_ID 0x0D9E
  119. #define USB_AVAYA_WIRELESS_ID 0x0300 /* Avaya Wireless USB Card */
  120. #define USB_AGERE_VENDOR_ID 0x0D4E /* Agere Systems */
  121. #define USB_AGERE_MODEL0801_ID 0x1000 /* Wireless USB Card Model 0801 */
  122. #define USB_AGERE_MODEL0802_ID 0x1001 /* Wireless USB Card Model 0802 */
  123. #define USB_AGERE_REBRANDED_ID 0x047A /* WLAN USB Card */
  124. #define USB_ELSA_VENDOR_ID 0x05CC
  125. #define USB_ELSA_AIRLANCER_ID 0x3100 /* ELSA AirLancer USB-11 */
  126. #define USB_LEGEND_VENDOR_ID 0x0E7C
  127. #define USB_LEGEND_JOYNET_ID 0x0300 /* Joynet WLAN USB Card */
  128. #define USB_SAMSUNG_VENDOR_ID 0x04E8
  129. #define USB_SAMSUNG_SEW2001U1_ID 0x5002 /* Samsung SEW-2001u Card */
  130. #define USB_SAMSUNG_SEW2001U2_ID 0x5B11 /* Samsung SEW-2001u Card */
  131. #define USB_SAMSUNG_SEW2003U_ID 0x7011 /* Samsung SEW-2003U Card */
  132. #define USB_IGATE_VENDOR_ID 0x0681
  133. #define USB_IGATE_IGATE_11M_ID 0x0012 /* I-GATE 11M USB Card */
  134. #define USB_FUJITSU_VENDOR_ID 0x0BF8
  135. #define USB_FUJITSU_E1100_ID 0x1002 /* connect2AIR WLAN E-1100 USB */
  136. #define USB_2WIRE_VENDOR_ID 0x1630
  137. #define USB_2WIRE_WIRELESS_ID 0xff81 /* 2Wire Wireless USB adapter */
  138. #define EZUSB_REQUEST_FW_TRANS 0xA0
  139. #define EZUSB_REQUEST_TRIGER 0xAA
  140. #define EZUSB_REQUEST_TRIG_AC 0xAC
  141. #define EZUSB_CPUCS_REG 0x7F92
  142. #define EZUSB_RID_TX 0x0700
  143. #define EZUSB_RID_RX 0x0701
  144. #define EZUSB_RID_INIT1 0x0702
  145. #define EZUSB_RID_ACK 0x0710
  146. #define EZUSB_RID_READ_PDA 0x0800
  147. #define EZUSB_RID_PROG_INIT 0x0852
  148. #define EZUSB_RID_PROG_SET_ADDR 0x0853
  149. #define EZUSB_RID_PROG_BYTES 0x0854
  150. #define EZUSB_RID_PROG_END 0x0855
  151. #define EZUSB_RID_DOCMD 0x0860
  152. /* Recognize info frames */
  153. #define EZUSB_IS_INFO(id) ((id >= 0xF000) && (id <= 0xF2FF))
  154. #define EZUSB_MAGIC 0x0210
  155. #define EZUSB_FRAME_DATA 1
  156. #define EZUSB_FRAME_CONTROL 2
  157. #define DEF_TIMEOUT (3 * HZ)
  158. #define BULK_BUF_SIZE 2048
  159. #define MAX_DL_SIZE (BULK_BUF_SIZE - sizeof(struct ezusb_packet))
  160. #define FW_BUF_SIZE 64
  161. #define FW_VAR_OFFSET_PTR 0x359
  162. #define FW_VAR_VALUE 0
  163. #define FW_HOLE_START 0x100
  164. #define FW_HOLE_END 0x300
  165. struct ezusb_packet {
  166. __le16 magic; /* 0x0210 */
  167. u8 req_reply_count;
  168. u8 ans_reply_count;
  169. __le16 frame_type; /* 0x01 for data frames, 0x02 otherwise */
  170. __le16 size; /* transport size */
  171. __le16 crc; /* CRC up to here */
  172. __le16 hermes_len;
  173. __le16 hermes_rid;
  174. u8 data[0];
  175. } __packed;
  176. /* Table of devices that work or may work with this driver */
  177. static struct usb_device_id ezusb_table[] = {
  178. {USB_DEVICE(USB_COMPAQ_VENDOR_ID, USB_COMPAQ_WL215_ID)},
  179. {USB_DEVICE(USB_COMPAQ_VENDOR_ID, USB_HP_WL215_ID)},
  180. {USB_DEVICE(USB_COMPAQ_VENDOR_ID, USB_COMPAQ_W200_ID)},
  181. {USB_DEVICE(USB_MELCO_VENDOR_ID, USB_BUFFALO_L11_ID)},
  182. {USB_DEVICE(USB_MELCO_VENDOR_ID, USB_BUFFALO_L11G_WR_ID)},
  183. {USB_DEVICE(USB_MELCO_VENDOR_ID, USB_BUFFALO_L11G_ID)},
  184. {USB_DEVICE(USB_LUCENT_VENDOR_ID, USB_LUCENT_ORINOCO_ID)},
  185. {USB_DEVICE(USB_AVAYA8_VENDOR_ID, USB_AVAYA_WIRELESS_ID)},
  186. {USB_DEVICE(USB_AVAYAE_VENDOR_ID, USB_AVAYA_WIRELESS_ID)},
  187. {USB_DEVICE(USB_AGERE_VENDOR_ID, USB_AGERE_MODEL0801_ID)},
  188. {USB_DEVICE(USB_AGERE_VENDOR_ID, USB_AGERE_MODEL0802_ID)},
  189. {USB_DEVICE(USB_ELSA_VENDOR_ID, USB_ELSA_AIRLANCER_ID)},
  190. {USB_DEVICE(USB_LEGEND_VENDOR_ID, USB_LEGEND_JOYNET_ID)},
  191. {USB_DEVICE_VER(USB_SAMSUNG_VENDOR_ID, USB_SAMSUNG_SEW2001U1_ID,
  192. 0, 0)},
  193. {USB_DEVICE(USB_SAMSUNG_VENDOR_ID, USB_SAMSUNG_SEW2001U2_ID)},
  194. {USB_DEVICE(USB_SAMSUNG_VENDOR_ID, USB_SAMSUNG_SEW2003U_ID)},
  195. {USB_DEVICE(USB_IGATE_VENDOR_ID, USB_IGATE_IGATE_11M_ID)},
  196. {USB_DEVICE(USB_FUJITSU_VENDOR_ID, USB_FUJITSU_E1100_ID)},
  197. {USB_DEVICE(USB_2WIRE_VENDOR_ID, USB_2WIRE_WIRELESS_ID)},
  198. {USB_DEVICE(USB_AGERE_VENDOR_ID, USB_AGERE_REBRANDED_ID)},
  199. {} /* Terminating entry */
  200. };
  201. MODULE_DEVICE_TABLE(usb, ezusb_table);
  202. /* Structure to hold all of our device specific stuff */
  203. struct ezusb_priv {
  204. struct usb_device *udev;
  205. struct net_device *dev;
  206. struct mutex mtx;
  207. spinlock_t req_lock;
  208. struct list_head req_pending;
  209. struct list_head req_active;
  210. spinlock_t reply_count_lock;
  211. u16 hermes_reg_fake[0x40];
  212. u8 *bap_buf;
  213. struct urb *read_urb;
  214. int read_pipe;
  215. int write_pipe;
  216. u8 reply_count;
  217. };
  218. enum ezusb_state {
  219. EZUSB_CTX_START,
  220. EZUSB_CTX_QUEUED,
  221. EZUSB_CTX_REQ_SUBMITTED,
  222. EZUSB_CTX_REQ_COMPLETE,
  223. EZUSB_CTX_RESP_RECEIVED,
  224. EZUSB_CTX_REQ_TIMEOUT,
  225. EZUSB_CTX_REQ_FAILED,
  226. EZUSB_CTX_RESP_TIMEOUT,
  227. EZUSB_CTX_REQSUBMIT_FAIL,
  228. EZUSB_CTX_COMPLETE,
  229. };
  230. struct request_context {
  231. struct list_head list;
  232. atomic_t refcount;
  233. struct completion done; /* Signals that CTX is dead */
  234. int killed;
  235. struct urb *outurb; /* OUT for req pkt */
  236. struct ezusb_priv *upriv;
  237. struct ezusb_packet *buf;
  238. int buf_length;
  239. struct timer_list timer; /* Timeout handling */
  240. enum ezusb_state state; /* Current state */
  241. /* the RID that we will wait for */
  242. u16 out_rid;
  243. u16 in_rid;
  244. };
  245. /* Forward declarations */
  246. static void ezusb_ctx_complete(struct request_context *ctx);
  247. static void ezusb_req_queue_run(struct ezusb_priv *upriv);
  248. static void ezusb_bulk_in_callback(struct urb *urb);
  249. static inline u8 ezusb_reply_inc(u8 count)
  250. {
  251. if (count < 0x7F)
  252. return count + 1;
  253. else
  254. return 1;
  255. }
  256. static void ezusb_request_context_put(struct request_context *ctx)
  257. {
  258. if (!atomic_dec_and_test(&ctx->refcount))
  259. return;
  260. WARN_ON(!ctx->done.done);
  261. BUG_ON(ctx->outurb->status == -EINPROGRESS);
  262. BUG_ON(timer_pending(&ctx->timer));
  263. usb_free_urb(ctx->outurb);
  264. kfree(ctx->buf);
  265. kfree(ctx);
  266. }
  267. static inline void ezusb_mod_timer(struct ezusb_priv *upriv,
  268. struct timer_list *timer,
  269. unsigned long expire)
  270. {
  271. if (!upriv->udev)
  272. return;
  273. mod_timer(timer, expire);
  274. }
  275. static void ezusb_request_timerfn(u_long _ctx)
  276. {
  277. struct request_context *ctx = (void *) _ctx;
  278. ctx->outurb->transfer_flags |= URB_ASYNC_UNLINK;
  279. if (usb_unlink_urb(ctx->outurb) == -EINPROGRESS) {
  280. ctx->state = EZUSB_CTX_REQ_TIMEOUT;
  281. } else {
  282. ctx->state = EZUSB_CTX_RESP_TIMEOUT;
  283. dev_dbg(&ctx->outurb->dev->dev, "couldn't unlink\n");
  284. atomic_inc(&ctx->refcount);
  285. ctx->killed = 1;
  286. ezusb_ctx_complete(ctx);
  287. ezusb_request_context_put(ctx);
  288. }
  289. };
  290. static struct request_context *ezusb_alloc_ctx(struct ezusb_priv *upriv,
  291. u16 out_rid, u16 in_rid)
  292. {
  293. struct request_context *ctx;
  294. ctx = kzalloc(sizeof(*ctx), GFP_ATOMIC);
  295. if (!ctx)
  296. return NULL;
  297. ctx->buf = kmalloc(BULK_BUF_SIZE, GFP_ATOMIC);
  298. if (!ctx->buf) {
  299. kfree(ctx);
  300. return NULL;
  301. }
  302. ctx->outurb = usb_alloc_urb(0, GFP_ATOMIC);
  303. if (!ctx->outurb) {
  304. kfree(ctx->buf);
  305. kfree(ctx);
  306. return NULL;
  307. }
  308. ctx->upriv = upriv;
  309. ctx->state = EZUSB_CTX_START;
  310. ctx->out_rid = out_rid;
  311. ctx->in_rid = in_rid;
  312. atomic_set(&ctx->refcount, 1);
  313. init_completion(&ctx->done);
  314. init_timer(&ctx->timer);
  315. ctx->timer.function = ezusb_request_timerfn;
  316. ctx->timer.data = (u_long) ctx;
  317. return ctx;
  318. }
  319. /* Hopefully the real complete_all will soon be exported, in the mean
  320. * while this should work. */
  321. static inline void ezusb_complete_all(struct completion *comp)
  322. {
  323. complete(comp);
  324. complete(comp);
  325. complete(comp);
  326. complete(comp);
  327. }
  328. static void ezusb_ctx_complete(struct request_context *ctx)
  329. {
  330. struct ezusb_priv *upriv = ctx->upriv;
  331. unsigned long flags;
  332. spin_lock_irqsave(&upriv->req_lock, flags);
  333. list_del_init(&ctx->list);
  334. if (upriv->udev) {
  335. spin_unlock_irqrestore(&upriv->req_lock, flags);
  336. ezusb_req_queue_run(upriv);
  337. spin_lock_irqsave(&upriv->req_lock, flags);
  338. }
  339. switch (ctx->state) {
  340. case EZUSB_CTX_COMPLETE:
  341. case EZUSB_CTX_REQSUBMIT_FAIL:
  342. case EZUSB_CTX_REQ_FAILED:
  343. case EZUSB_CTX_REQ_TIMEOUT:
  344. case EZUSB_CTX_RESP_TIMEOUT:
  345. spin_unlock_irqrestore(&upriv->req_lock, flags);
  346. if ((ctx->out_rid == EZUSB_RID_TX) && upriv->dev) {
  347. struct net_device *dev = upriv->dev;
  348. struct orinoco_private *priv = ndev_priv(dev);
  349. struct net_device_stats *stats = &priv->stats;
  350. if (ctx->state != EZUSB_CTX_COMPLETE)
  351. stats->tx_errors++;
  352. else
  353. stats->tx_packets++;
  354. netif_wake_queue(dev);
  355. }
  356. ezusb_complete_all(&ctx->done);
  357. ezusb_request_context_put(ctx);
  358. break;
  359. default:
  360. spin_unlock_irqrestore(&upriv->req_lock, flags);
  361. if (!upriv->udev) {
  362. /* This is normal, as all request contexts get flushed
  363. * when the device is disconnected */
  364. err("Called, CTX not terminating, but device gone");
  365. ezusb_complete_all(&ctx->done);
  366. ezusb_request_context_put(ctx);
  367. break;
  368. }
  369. err("Called, CTX not in terminating state.");
  370. /* Things are really bad if this happens. Just leak
  371. * the CTX because it may still be linked to the
  372. * queue or the OUT urb may still be active.
  373. * Just leaking at least prevents an Oops or Panic.
  374. */
  375. break;
  376. }
  377. }
  378. /**
  379. * ezusb_req_queue_run:
  380. * Description:
  381. * Note: Only one active CTX at any one time, because there's no
  382. * other (reliable) way to match the response URB to the correct
  383. * CTX.
  384. **/
  385. static void ezusb_req_queue_run(struct ezusb_priv *upriv)
  386. {
  387. unsigned long flags;
  388. struct request_context *ctx;
  389. int result;
  390. spin_lock_irqsave(&upriv->req_lock, flags);
  391. if (!list_empty(&upriv->req_active))
  392. goto unlock;
  393. if (list_empty(&upriv->req_pending))
  394. goto unlock;
  395. ctx =
  396. list_entry(upriv->req_pending.next, struct request_context,
  397. list);
  398. if (!ctx->upriv->udev)
  399. goto unlock;
  400. /* We need to split this off to avoid a race condition */
  401. list_move_tail(&ctx->list, &upriv->req_active);
  402. if (ctx->state == EZUSB_CTX_QUEUED) {
  403. atomic_inc(&ctx->refcount);
  404. result = usb_submit_urb(ctx->outurb, GFP_ATOMIC);
  405. if (result) {
  406. ctx->state = EZUSB_CTX_REQSUBMIT_FAIL;
  407. spin_unlock_irqrestore(&upriv->req_lock, flags);
  408. err("Fatal, failed to submit command urb."
  409. " error=%d\n", result);
  410. ezusb_ctx_complete(ctx);
  411. ezusb_request_context_put(ctx);
  412. goto done;
  413. }
  414. ctx->state = EZUSB_CTX_REQ_SUBMITTED;
  415. ezusb_mod_timer(ctx->upriv, &ctx->timer,
  416. jiffies + DEF_TIMEOUT);
  417. }
  418. unlock:
  419. spin_unlock_irqrestore(&upriv->req_lock, flags);
  420. done:
  421. return;
  422. }
  423. static void ezusb_req_enqueue_run(struct ezusb_priv *upriv,
  424. struct request_context *ctx)
  425. {
  426. unsigned long flags;
  427. spin_lock_irqsave(&upriv->req_lock, flags);
  428. if (!ctx->upriv->udev) {
  429. spin_unlock_irqrestore(&upriv->req_lock, flags);
  430. goto done;
  431. }
  432. atomic_inc(&ctx->refcount);
  433. list_add_tail(&ctx->list, &upriv->req_pending);
  434. spin_unlock_irqrestore(&upriv->req_lock, flags);
  435. ctx->state = EZUSB_CTX_QUEUED;
  436. ezusb_req_queue_run(upriv);
  437. done:
  438. return;
  439. }
  440. static void ezusb_request_out_callback(struct urb *urb)
  441. {
  442. unsigned long flags;
  443. enum ezusb_state state;
  444. struct request_context *ctx = urb->context;
  445. struct ezusb_priv *upriv = ctx->upriv;
  446. spin_lock_irqsave(&upriv->req_lock, flags);
  447. del_timer(&ctx->timer);
  448. if (ctx->killed) {
  449. spin_unlock_irqrestore(&upriv->req_lock, flags);
  450. pr_warning("interrupt called with dead ctx");
  451. goto out;
  452. }
  453. state = ctx->state;
  454. if (urb->status == 0) {
  455. switch (state) {
  456. case EZUSB_CTX_REQ_SUBMITTED:
  457. if (ctx->in_rid) {
  458. ctx->state = EZUSB_CTX_REQ_COMPLETE;
  459. /* reply URB still pending */
  460. ezusb_mod_timer(upriv, &ctx->timer,
  461. jiffies + DEF_TIMEOUT);
  462. spin_unlock_irqrestore(&upriv->req_lock,
  463. flags);
  464. break;
  465. }
  466. /* fall through */
  467. case EZUSB_CTX_RESP_RECEIVED:
  468. /* IN already received before this OUT-ACK */
  469. ctx->state = EZUSB_CTX_COMPLETE;
  470. spin_unlock_irqrestore(&upriv->req_lock, flags);
  471. ezusb_ctx_complete(ctx);
  472. break;
  473. default:
  474. spin_unlock_irqrestore(&upriv->req_lock, flags);
  475. err("Unexpected state(0x%x, %d) in OUT URB",
  476. state, urb->status);
  477. break;
  478. }
  479. } else {
  480. /* If someone cancels the OUT URB then its status
  481. * should be either -ECONNRESET or -ENOENT.
  482. */
  483. switch (state) {
  484. case EZUSB_CTX_REQ_SUBMITTED:
  485. case EZUSB_CTX_RESP_RECEIVED:
  486. ctx->state = EZUSB_CTX_REQ_FAILED;
  487. /* fall through */
  488. case EZUSB_CTX_REQ_FAILED:
  489. case EZUSB_CTX_REQ_TIMEOUT:
  490. spin_unlock_irqrestore(&upriv->req_lock, flags);
  491. ezusb_ctx_complete(ctx);
  492. break;
  493. default:
  494. spin_unlock_irqrestore(&upriv->req_lock, flags);
  495. err("Unexpected state(0x%x, %d) in OUT URB",
  496. state, urb->status);
  497. break;
  498. }
  499. }
  500. out:
  501. ezusb_request_context_put(ctx);
  502. }
  503. static void ezusb_request_in_callback(struct ezusb_priv *upriv,
  504. struct urb *urb)
  505. {
  506. struct ezusb_packet *ans = urb->transfer_buffer;
  507. struct request_context *ctx = NULL;
  508. enum ezusb_state state;
  509. unsigned long flags;
  510. /* Find the CTX on the active queue that requested this URB */
  511. spin_lock_irqsave(&upriv->req_lock, flags);
  512. if (upriv->udev) {
  513. struct list_head *item;
  514. list_for_each(item, &upriv->req_active) {
  515. struct request_context *c;
  516. int reply_count;
  517. c = list_entry(item, struct request_context, list);
  518. reply_count =
  519. ezusb_reply_inc(c->buf->req_reply_count);
  520. if ((ans->ans_reply_count == reply_count)
  521. && (le16_to_cpu(ans->hermes_rid) == c->in_rid)) {
  522. ctx = c;
  523. break;
  524. }
  525. netdev_dbg(upriv->dev, "Skipped (0x%x/0x%x) (%d/%d)\n",
  526. le16_to_cpu(ans->hermes_rid), c->in_rid,
  527. ans->ans_reply_count, reply_count);
  528. }
  529. }
  530. if (ctx == NULL) {
  531. spin_unlock_irqrestore(&upriv->req_lock, flags);
  532. err("%s: got unexpected RID: 0x%04X", __func__,
  533. le16_to_cpu(ans->hermes_rid));
  534. ezusb_req_queue_run(upriv);
  535. return;
  536. }
  537. /* The data we want is in the in buffer, exchange */
  538. urb->transfer_buffer = ctx->buf;
  539. ctx->buf = (void *) ans;
  540. ctx->buf_length = urb->actual_length;
  541. state = ctx->state;
  542. switch (state) {
  543. case EZUSB_CTX_REQ_SUBMITTED:
  544. /* We have received our response URB before
  545. * our request has been acknowledged. Do NOT
  546. * destroy our CTX yet, because our OUT URB
  547. * is still alive ...
  548. */
  549. ctx->state = EZUSB_CTX_RESP_RECEIVED;
  550. spin_unlock_irqrestore(&upriv->req_lock, flags);
  551. /* Let the machine continue running. */
  552. break;
  553. case EZUSB_CTX_REQ_COMPLETE:
  554. /* This is the usual path: our request
  555. * has already been acknowledged, and
  556. * we have now received the reply.
  557. */
  558. ctx->state = EZUSB_CTX_COMPLETE;
  559. /* Stop the intimer */
  560. del_timer(&ctx->timer);
  561. spin_unlock_irqrestore(&upriv->req_lock, flags);
  562. /* Call the completion handler */
  563. ezusb_ctx_complete(ctx);
  564. break;
  565. default:
  566. spin_unlock_irqrestore(&upriv->req_lock, flags);
  567. pr_warning("Matched IN URB, unexpected context state(0x%x)",
  568. state);
  569. /* Throw this CTX away and try submitting another */
  570. del_timer(&ctx->timer);
  571. ctx->outurb->transfer_flags |= URB_ASYNC_UNLINK;
  572. usb_unlink_urb(ctx->outurb);
  573. ezusb_req_queue_run(upriv);
  574. break;
  575. } /* switch */
  576. }
  577. static void ezusb_req_ctx_wait(struct ezusb_priv *upriv,
  578. struct request_context *ctx)
  579. {
  580. switch (ctx->state) {
  581. case EZUSB_CTX_QUEUED:
  582. case EZUSB_CTX_REQ_SUBMITTED:
  583. case EZUSB_CTX_REQ_COMPLETE:
  584. case EZUSB_CTX_RESP_RECEIVED:
  585. if (in_softirq()) {
  586. /* If we get called from a timer, timeout timers don't
  587. * get the chance to run themselves. So we make sure
  588. * that we don't sleep for ever */
  589. int msecs = DEF_TIMEOUT * (1000 / HZ);
  590. while (!ctx->done.done && msecs--)
  591. udelay(1000);
  592. } else {
  593. wait_event_interruptible(ctx->done.wait,
  594. ctx->done.done);
  595. }
  596. break;
  597. default:
  598. /* Done or failed - nothing to wait for */
  599. break;
  600. }
  601. }
  602. static inline u16 build_crc(struct ezusb_packet *data)
  603. {
  604. u16 crc = 0;
  605. u8 *bytes = (u8 *)data;
  606. int i;
  607. for (i = 0; i < 8; i++)
  608. crc = (crc << 1) + bytes[i];
  609. return crc;
  610. }
  611. /**
  612. * ezusb_fill_req:
  613. *
  614. * if data == NULL and length > 0 the data is assumed to be already in
  615. * the target buffer and only the header is filled.
  616. *
  617. */
  618. static int ezusb_fill_req(struct ezusb_packet *req, u16 length, u16 rid,
  619. const void *data, u16 frame_type, u8 reply_count)
  620. {
  621. int total_size = sizeof(*req) + length;
  622. BUG_ON(total_size > BULK_BUF_SIZE);
  623. req->magic = cpu_to_le16(EZUSB_MAGIC);
  624. req->req_reply_count = reply_count;
  625. req->ans_reply_count = 0;
  626. req->frame_type = cpu_to_le16(frame_type);
  627. req->size = cpu_to_le16(length + 4);
  628. req->crc = cpu_to_le16(build_crc(req));
  629. req->hermes_len = cpu_to_le16(HERMES_BYTES_TO_RECLEN(length));
  630. req->hermes_rid = cpu_to_le16(rid);
  631. if (data)
  632. memcpy(req->data, data, length);
  633. return total_size;
  634. }
  635. static int ezusb_submit_in_urb(struct ezusb_priv *upriv)
  636. {
  637. int retval = 0;
  638. void *cur_buf = upriv->read_urb->transfer_buffer;
  639. if (upriv->read_urb->status == -EINPROGRESS) {
  640. netdev_dbg(upriv->dev, "urb busy, not resubmiting\n");
  641. retval = -EBUSY;
  642. goto exit;
  643. }
  644. usb_fill_bulk_urb(upriv->read_urb, upriv->udev, upriv->read_pipe,
  645. cur_buf, BULK_BUF_SIZE,
  646. ezusb_bulk_in_callback, upriv);
  647. upriv->read_urb->transfer_flags = 0;
  648. retval = usb_submit_urb(upriv->read_urb, GFP_ATOMIC);
  649. if (retval)
  650. err("%s submit failed %d", __func__, retval);
  651. exit:
  652. return retval;
  653. }
  654. static inline int ezusb_8051_cpucs(struct ezusb_priv *upriv, int reset)
  655. {
  656. u8 res_val = reset; /* avoid argument promotion */
  657. if (!upriv->udev) {
  658. err("%s: !upriv->udev", __func__);
  659. return -EFAULT;
  660. }
  661. return usb_control_msg(upriv->udev,
  662. usb_sndctrlpipe(upriv->udev, 0),
  663. EZUSB_REQUEST_FW_TRANS,
  664. USB_TYPE_VENDOR | USB_RECIP_DEVICE |
  665. USB_DIR_OUT, EZUSB_CPUCS_REG, 0, &res_val,
  666. sizeof(res_val), DEF_TIMEOUT);
  667. }
  668. static int ezusb_firmware_download(struct ezusb_priv *upriv,
  669. struct ez_usb_fw *fw)
  670. {
  671. u8 *fw_buffer;
  672. int retval, addr;
  673. int variant_offset;
  674. fw_buffer = kmalloc(FW_BUF_SIZE, GFP_KERNEL);
  675. if (!fw_buffer) {
  676. printk(KERN_ERR PFX "Out of memory for firmware buffer.\n");
  677. return -ENOMEM;
  678. }
  679. /*
  680. * This byte is 1 and should be replaced with 0. The offset is
  681. * 0x10AD in version 0.0.6. The byte in question should follow
  682. * the end of the code pointed to by the jump in the beginning
  683. * of the firmware. Also, it is read by code located at 0x358.
  684. */
  685. variant_offset = be16_to_cpup((__be16 *) &fw->code[FW_VAR_OFFSET_PTR]);
  686. if (variant_offset >= fw->size) {
  687. printk(KERN_ERR PFX "Invalid firmware variant offset: "
  688. "0x%04x\n", variant_offset);
  689. retval = -EINVAL;
  690. goto fail;
  691. }
  692. retval = ezusb_8051_cpucs(upriv, 1);
  693. if (retval < 0)
  694. goto fail;
  695. for (addr = 0; addr < fw->size; addr += FW_BUF_SIZE) {
  696. /* 0x100-0x300 should be left alone, it contains card
  697. * specific data, like USB enumeration information */
  698. if ((addr >= FW_HOLE_START) && (addr < FW_HOLE_END))
  699. continue;
  700. memcpy(fw_buffer, &fw->code[addr], FW_BUF_SIZE);
  701. if (variant_offset >= addr &&
  702. variant_offset < addr + FW_BUF_SIZE) {
  703. netdev_dbg(upriv->dev,
  704. "Patching card_variant byte at 0x%04X\n",
  705. variant_offset);
  706. fw_buffer[variant_offset - addr] = FW_VAR_VALUE;
  707. }
  708. retval = usb_control_msg(upriv->udev,
  709. usb_sndctrlpipe(upriv->udev, 0),
  710. EZUSB_REQUEST_FW_TRANS,
  711. USB_TYPE_VENDOR | USB_RECIP_DEVICE
  712. | USB_DIR_OUT,
  713. addr, 0x0,
  714. fw_buffer, FW_BUF_SIZE,
  715. DEF_TIMEOUT);
  716. if (retval < 0)
  717. goto fail;
  718. }
  719. retval = ezusb_8051_cpucs(upriv, 0);
  720. if (retval < 0)
  721. goto fail;
  722. goto exit;
  723. fail:
  724. printk(KERN_ERR PFX "Firmware download failed, error %d\n",
  725. retval);
  726. exit:
  727. kfree(fw_buffer);
  728. return retval;
  729. }
  730. static int ezusb_access_ltv(struct ezusb_priv *upriv,
  731. struct request_context *ctx,
  732. u16 length, const void *data, u16 frame_type,
  733. void *ans_buff, unsigned ans_size, u16 *ans_length)
  734. {
  735. int req_size;
  736. int retval = 0;
  737. enum ezusb_state state;
  738. BUG_ON(in_irq());
  739. if (!upriv->udev) {
  740. retval = -ENODEV;
  741. goto exit;
  742. }
  743. if (upriv->read_urb->status != -EINPROGRESS)
  744. err("%s: in urb not pending", __func__);
  745. /* protect upriv->reply_count, guarantee sequential numbers */
  746. spin_lock_bh(&upriv->reply_count_lock);
  747. req_size = ezusb_fill_req(ctx->buf, length, ctx->out_rid, data,
  748. frame_type, upriv->reply_count);
  749. usb_fill_bulk_urb(ctx->outurb, upriv->udev, upriv->write_pipe,
  750. ctx->buf, req_size,
  751. ezusb_request_out_callback, ctx);
  752. if (ctx->in_rid)
  753. upriv->reply_count = ezusb_reply_inc(upriv->reply_count);
  754. ezusb_req_enqueue_run(upriv, ctx);
  755. spin_unlock_bh(&upriv->reply_count_lock);
  756. if (ctx->in_rid)
  757. ezusb_req_ctx_wait(upriv, ctx);
  758. state = ctx->state;
  759. switch (state) {
  760. case EZUSB_CTX_COMPLETE:
  761. retval = ctx->outurb->status;
  762. break;
  763. case EZUSB_CTX_QUEUED:
  764. case EZUSB_CTX_REQ_SUBMITTED:
  765. if (!ctx->in_rid)
  766. break;
  767. default:
  768. err("%s: Unexpected context state %d", __func__,
  769. state);
  770. /* fall though */
  771. case EZUSB_CTX_REQ_TIMEOUT:
  772. case EZUSB_CTX_REQ_FAILED:
  773. case EZUSB_CTX_RESP_TIMEOUT:
  774. case EZUSB_CTX_REQSUBMIT_FAIL:
  775. printk(KERN_ERR PFX "Access failed, resetting (state %d,"
  776. " reply_count %d)\n", state, upriv->reply_count);
  777. upriv->reply_count = 0;
  778. if (state == EZUSB_CTX_REQ_TIMEOUT
  779. || state == EZUSB_CTX_RESP_TIMEOUT) {
  780. printk(KERN_ERR PFX "ctx timed out\n");
  781. retval = -ETIMEDOUT;
  782. } else {
  783. printk(KERN_ERR PFX "ctx failed\n");
  784. retval = -EFAULT;
  785. }
  786. goto exit;
  787. break;
  788. }
  789. if (ctx->in_rid) {
  790. struct ezusb_packet *ans = ctx->buf;
  791. unsigned exp_len;
  792. if (ans->hermes_len != 0)
  793. exp_len = le16_to_cpu(ans->hermes_len) * 2 + 12;
  794. else
  795. exp_len = 14;
  796. if (exp_len != ctx->buf_length) {
  797. err("%s: length mismatch for RID 0x%04x: "
  798. "expected %d, got %d", __func__,
  799. ctx->in_rid, exp_len, ctx->buf_length);
  800. retval = -EIO;
  801. goto exit;
  802. }
  803. if (ans_buff)
  804. memcpy(ans_buff, ans->data, min(exp_len, ans_size));
  805. if (ans_length)
  806. *ans_length = le16_to_cpu(ans->hermes_len);
  807. }
  808. exit:
  809. ezusb_request_context_put(ctx);
  810. return retval;
  811. }
  812. static int ezusb_write_ltv(struct hermes *hw, int bap, u16 rid,
  813. u16 length, const void *data)
  814. {
  815. struct ezusb_priv *upriv = hw->priv;
  816. u16 frame_type;
  817. struct request_context *ctx;
  818. if (length == 0)
  819. return -EINVAL;
  820. length = HERMES_RECLEN_TO_BYTES(length);
  821. /* On memory mapped devices HERMES_RID_CNFGROUPADDRESSES can be
  822. * set to be empty, but the USB bridge doesn't like it */
  823. if (length == 0)
  824. return 0;
  825. ctx = ezusb_alloc_ctx(upriv, rid, EZUSB_RID_ACK);
  826. if (!ctx)
  827. return -ENOMEM;
  828. if (rid == EZUSB_RID_TX)
  829. frame_type = EZUSB_FRAME_DATA;
  830. else
  831. frame_type = EZUSB_FRAME_CONTROL;
  832. return ezusb_access_ltv(upriv, ctx, length, data, frame_type,
  833. NULL, 0, NULL);
  834. }
  835. static int ezusb_read_ltv(struct hermes *hw, int bap, u16 rid,
  836. unsigned bufsize, u16 *length, void *buf)
  837. {
  838. struct ezusb_priv *upriv = hw->priv;
  839. struct request_context *ctx;
  840. if (bufsize % 2)
  841. return -EINVAL;
  842. ctx = ezusb_alloc_ctx(upriv, rid, rid);
  843. if (!ctx)
  844. return -ENOMEM;
  845. return ezusb_access_ltv(upriv, ctx, 0, NULL, EZUSB_FRAME_CONTROL,
  846. buf, bufsize, length);
  847. }
  848. static int ezusb_doicmd_wait(struct hermes *hw, u16 cmd, u16 parm0, u16 parm1,
  849. u16 parm2, struct hermes_response *resp)
  850. {
  851. struct ezusb_priv *upriv = hw->priv;
  852. struct request_context *ctx;
  853. __le16 data[4] = {
  854. cpu_to_le16(cmd),
  855. cpu_to_le16(parm0),
  856. cpu_to_le16(parm1),
  857. cpu_to_le16(parm2),
  858. };
  859. netdev_dbg(upriv->dev,
  860. "0x%04X, parm0 0x%04X, parm1 0x%04X, parm2 0x%04X\n", cmd,
  861. parm0, parm1, parm2);
  862. ctx = ezusb_alloc_ctx(upriv, EZUSB_RID_DOCMD, EZUSB_RID_ACK);
  863. if (!ctx)
  864. return -ENOMEM;
  865. return ezusb_access_ltv(upriv, ctx, sizeof(data), &data,
  866. EZUSB_FRAME_CONTROL, NULL, 0, NULL);
  867. }
  868. static int ezusb_docmd_wait(struct hermes *hw, u16 cmd, u16 parm0,
  869. struct hermes_response *resp)
  870. {
  871. struct ezusb_priv *upriv = hw->priv;
  872. struct request_context *ctx;
  873. __le16 data[4] = {
  874. cpu_to_le16(cmd),
  875. cpu_to_le16(parm0),
  876. 0,
  877. 0,
  878. };
  879. netdev_dbg(upriv->dev, "0x%04X, parm0 0x%04X\n", cmd, parm0);
  880. ctx = ezusb_alloc_ctx(upriv, EZUSB_RID_DOCMD, EZUSB_RID_ACK);
  881. if (!ctx)
  882. return -ENOMEM;
  883. return ezusb_access_ltv(upriv, ctx, sizeof(data), &data,
  884. EZUSB_FRAME_CONTROL, NULL, 0, NULL);
  885. }
  886. static int ezusb_bap_pread(struct hermes *hw, int bap,
  887. void *buf, int len, u16 id, u16 offset)
  888. {
  889. struct ezusb_priv *upriv = hw->priv;
  890. struct ezusb_packet *ans = (void *) upriv->read_urb->transfer_buffer;
  891. int actual_length = upriv->read_urb->actual_length;
  892. if (id == EZUSB_RID_RX) {
  893. if ((sizeof(*ans) + offset + len) > actual_length) {
  894. printk(KERN_ERR PFX "BAP read beyond buffer end "
  895. "in rx frame\n");
  896. return -EINVAL;
  897. }
  898. memcpy(buf, ans->data + offset, len);
  899. return 0;
  900. }
  901. if (EZUSB_IS_INFO(id)) {
  902. /* Include 4 bytes for length/type */
  903. if ((sizeof(*ans) + offset + len - 4) > actual_length) {
  904. printk(KERN_ERR PFX "BAP read beyond buffer end "
  905. "in info frame\n");
  906. return -EFAULT;
  907. }
  908. memcpy(buf, ans->data + offset - 4, len);
  909. } else {
  910. printk(KERN_ERR PFX "Unexpected fid 0x%04x\n", id);
  911. return -EINVAL;
  912. }
  913. return 0;
  914. }
  915. static int ezusb_read_pda(struct hermes *hw, __le16 *pda,
  916. u32 pda_addr, u16 pda_len)
  917. {
  918. struct ezusb_priv *upriv = hw->priv;
  919. struct request_context *ctx;
  920. __le16 data[] = {
  921. cpu_to_le16(pda_addr & 0xffff),
  922. cpu_to_le16(pda_len - 4)
  923. };
  924. ctx = ezusb_alloc_ctx(upriv, EZUSB_RID_READ_PDA, EZUSB_RID_READ_PDA);
  925. if (!ctx)
  926. return -ENOMEM;
  927. /* wl_lkm does not include PDA size in the PDA area.
  928. * We will pad the information into pda, so other routines
  929. * don't have to be modified */
  930. pda[0] = cpu_to_le16(pda_len - 2);
  931. /* Includes CFG_PROD_DATA but not itself */
  932. pda[1] = cpu_to_le16(0x0800); /* CFG_PROD_DATA */
  933. return ezusb_access_ltv(upriv, ctx, sizeof(data), &data,
  934. EZUSB_FRAME_CONTROL, &pda[2], pda_len - 4,
  935. NULL);
  936. }
  937. static int ezusb_program_init(struct hermes *hw, u32 entry_point)
  938. {
  939. struct ezusb_priv *upriv = hw->priv;
  940. struct request_context *ctx;
  941. __le32 data = cpu_to_le32(entry_point);
  942. ctx = ezusb_alloc_ctx(upriv, EZUSB_RID_PROG_INIT, EZUSB_RID_ACK);
  943. if (!ctx)
  944. return -ENOMEM;
  945. return ezusb_access_ltv(upriv, ctx, sizeof(data), &data,
  946. EZUSB_FRAME_CONTROL, NULL, 0, NULL);
  947. }
  948. static int ezusb_program_end(struct hermes *hw)
  949. {
  950. struct ezusb_priv *upriv = hw->priv;
  951. struct request_context *ctx;
  952. ctx = ezusb_alloc_ctx(upriv, EZUSB_RID_PROG_END, EZUSB_RID_ACK);
  953. if (!ctx)
  954. return -ENOMEM;
  955. return ezusb_access_ltv(upriv, ctx, 0, NULL,
  956. EZUSB_FRAME_CONTROL, NULL, 0, NULL);
  957. }
  958. static int ezusb_program_bytes(struct hermes *hw, const char *buf,
  959. u32 addr, u32 len)
  960. {
  961. struct ezusb_priv *upriv = hw->priv;
  962. struct request_context *ctx;
  963. __le32 data = cpu_to_le32(addr);
  964. int err;
  965. ctx = ezusb_alloc_ctx(upriv, EZUSB_RID_PROG_SET_ADDR, EZUSB_RID_ACK);
  966. if (!ctx)
  967. return -ENOMEM;
  968. err = ezusb_access_ltv(upriv, ctx, sizeof(data), &data,
  969. EZUSB_FRAME_CONTROL, NULL, 0, NULL);
  970. if (err)
  971. return err;
  972. ctx = ezusb_alloc_ctx(upriv, EZUSB_RID_PROG_BYTES, EZUSB_RID_ACK);
  973. if (!ctx)
  974. return -ENOMEM;
  975. return ezusb_access_ltv(upriv, ctx, len, buf,
  976. EZUSB_FRAME_CONTROL, NULL, 0, NULL);
  977. }
  978. static int ezusb_program(struct hermes *hw, const char *buf,
  979. u32 addr, u32 len)
  980. {
  981. u32 ch_addr;
  982. u32 ch_len;
  983. int err = 0;
  984. /* We can only send 2048 bytes out of the bulk xmit at a time,
  985. * so we have to split any programming into chunks of <2048
  986. * bytes. */
  987. ch_len = (len < MAX_DL_SIZE) ? len : MAX_DL_SIZE;
  988. ch_addr = addr;
  989. while (ch_addr < (addr + len)) {
  990. pr_debug("Programming subblock of length %d "
  991. "to address 0x%08x. Data @ %p\n",
  992. ch_len, ch_addr, &buf[ch_addr - addr]);
  993. err = ezusb_program_bytes(hw, &buf[ch_addr - addr],
  994. ch_addr, ch_len);
  995. if (err)
  996. break;
  997. ch_addr += ch_len;
  998. ch_len = ((addr + len - ch_addr) < MAX_DL_SIZE) ?
  999. (addr + len - ch_addr) : MAX_DL_SIZE;
  1000. }
  1001. return err;
  1002. }
  1003. static netdev_tx_t ezusb_xmit(struct sk_buff *skb, struct net_device *dev)
  1004. {
  1005. struct orinoco_private *priv = ndev_priv(dev);
  1006. struct net_device_stats *stats = &priv->stats;
  1007. struct ezusb_priv *upriv = priv->card;
  1008. u8 mic[MICHAEL_MIC_LEN + 1];
  1009. int err = 0;
  1010. int tx_control;
  1011. unsigned long flags;
  1012. struct request_context *ctx;
  1013. u8 *buf;
  1014. int tx_size;
  1015. if (!netif_running(dev)) {
  1016. printk(KERN_ERR "%s: Tx on stopped device!\n",
  1017. dev->name);
  1018. return NETDEV_TX_BUSY;
  1019. }
  1020. if (netif_queue_stopped(dev)) {
  1021. printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
  1022. dev->name);
  1023. return NETDEV_TX_BUSY;
  1024. }
  1025. if (orinoco_lock(priv, &flags) != 0) {
  1026. printk(KERN_ERR
  1027. "%s: ezusb_xmit() called while hw_unavailable\n",
  1028. dev->name);
  1029. return NETDEV_TX_BUSY;
  1030. }
  1031. if (!netif_carrier_ok(dev) ||
  1032. (priv->iw_mode == NL80211_IFTYPE_MONITOR)) {
  1033. /* Oops, the firmware hasn't established a connection,
  1034. silently drop the packet (this seems to be the
  1035. safest approach). */
  1036. goto drop;
  1037. }
  1038. /* Check packet length */
  1039. if (skb->len < ETH_HLEN)
  1040. goto drop;
  1041. ctx = ezusb_alloc_ctx(upriv, EZUSB_RID_TX, 0);
  1042. if (!ctx)
  1043. goto busy;
  1044. memset(ctx->buf, 0, BULK_BUF_SIZE);
  1045. buf = ctx->buf->data;
  1046. tx_control = 0;
  1047. err = orinoco_process_xmit_skb(skb, dev, priv, &tx_control,
  1048. &mic[0]);
  1049. if (err)
  1050. goto drop;
  1051. {
  1052. __le16 *tx_cntl = (__le16 *)buf;
  1053. *tx_cntl = cpu_to_le16(tx_control);
  1054. buf += sizeof(*tx_cntl);
  1055. }
  1056. memcpy(buf, skb->data, skb->len);
  1057. buf += skb->len;
  1058. if (tx_control & HERMES_TXCTRL_MIC) {
  1059. u8 *m = mic;
  1060. /* Mic has been offset so it can be copied to an even
  1061. * address. We're copying eveything anyway, so we
  1062. * don't need to copy that first byte. */
  1063. if (skb->len % 2)
  1064. m++;
  1065. memcpy(buf, m, MICHAEL_MIC_LEN);
  1066. buf += MICHAEL_MIC_LEN;
  1067. }
  1068. /* Finally, we actually initiate the send */
  1069. netif_stop_queue(dev);
  1070. /* The card may behave better if we send evenly sized usb transfers */
  1071. tx_size = ALIGN(buf - ctx->buf->data, 2);
  1072. err = ezusb_access_ltv(upriv, ctx, tx_size, NULL,
  1073. EZUSB_FRAME_DATA, NULL, 0, NULL);
  1074. if (err) {
  1075. netif_start_queue(dev);
  1076. if (net_ratelimit())
  1077. printk(KERN_ERR "%s: Error %d transmitting packet\n",
  1078. dev->name, err);
  1079. goto busy;
  1080. }
  1081. dev->trans_start = jiffies;
  1082. stats->tx_bytes += skb->len;
  1083. goto ok;
  1084. drop:
  1085. stats->tx_errors++;
  1086. stats->tx_dropped++;
  1087. ok:
  1088. orinoco_unlock(priv, &flags);
  1089. dev_kfree_skb(skb);
  1090. return NETDEV_TX_OK;
  1091. busy:
  1092. orinoco_unlock(priv, &flags);
  1093. return NETDEV_TX_BUSY;
  1094. }
  1095. static int ezusb_allocate(struct hermes *hw, u16 size, u16 *fid)
  1096. {
  1097. *fid = EZUSB_RID_TX;
  1098. return 0;
  1099. }
  1100. static int ezusb_hard_reset(struct orinoco_private *priv)
  1101. {
  1102. struct ezusb_priv *upriv = priv->card;
  1103. int retval = ezusb_8051_cpucs(upriv, 1);
  1104. if (retval < 0) {
  1105. err("Failed to reset");
  1106. return retval;
  1107. }
  1108. retval = ezusb_8051_cpucs(upriv, 0);
  1109. if (retval < 0) {
  1110. err("Failed to unreset");
  1111. return retval;
  1112. }
  1113. netdev_dbg(upriv->dev, "sending control message\n");
  1114. retval = usb_control_msg(upriv->udev,
  1115. usb_sndctrlpipe(upriv->udev, 0),
  1116. EZUSB_REQUEST_TRIGER,
  1117. USB_TYPE_VENDOR | USB_RECIP_DEVICE |
  1118. USB_DIR_OUT, 0x0, 0x0, NULL, 0,
  1119. DEF_TIMEOUT);
  1120. if (retval < 0) {
  1121. err("EZUSB_REQUEST_TRIGER failed retval %d", retval);
  1122. return retval;
  1123. }
  1124. #if 0
  1125. dbg("Sending EZUSB_REQUEST_TRIG_AC");
  1126. retval = usb_control_msg(upriv->udev,
  1127. usb_sndctrlpipe(upriv->udev, 0),
  1128. EZUSB_REQUEST_TRIG_AC,
  1129. USB_TYPE_VENDOR | USB_RECIP_DEVICE |
  1130. USB_DIR_OUT, 0x00FA, 0x0, NULL, 0,
  1131. DEF_TIMEOUT);
  1132. if (retval < 0) {
  1133. err("EZUSB_REQUEST_TRIG_AC failed retval %d", retval);
  1134. return retval;
  1135. }
  1136. #endif
  1137. return 0;
  1138. }
  1139. static int ezusb_init(struct hermes *hw)
  1140. {
  1141. struct ezusb_priv *upriv = hw->priv;
  1142. int retval;
  1143. BUG_ON(in_interrupt());
  1144. BUG_ON(!upriv);
  1145. upriv->reply_count = 0;
  1146. /* Write the MAGIC number on the simulated registers to keep
  1147. * orinoco.c happy */
  1148. hermes_write_regn(hw, SWSUPPORT0, HERMES_MAGIC);
  1149. hermes_write_regn(hw, RXFID, EZUSB_RID_RX);
  1150. usb_kill_urb(upriv->read_urb);
  1151. ezusb_submit_in_urb(upriv);
  1152. retval = ezusb_write_ltv(hw, 0, EZUSB_RID_INIT1,
  1153. HERMES_BYTES_TO_RECLEN(2), "\x10\x00");
  1154. if (retval < 0) {
  1155. printk(KERN_ERR PFX "EZUSB_RID_INIT1 error %d\n", retval);
  1156. return retval;
  1157. }
  1158. retval = ezusb_docmd_wait(hw, HERMES_CMD_INIT, 0, NULL);
  1159. if (retval < 0) {
  1160. printk(KERN_ERR PFX "HERMES_CMD_INIT error %d\n", retval);
  1161. return retval;
  1162. }
  1163. return 0;
  1164. }
  1165. static void ezusb_bulk_in_callback(struct urb *urb)
  1166. {
  1167. struct ezusb_priv *upriv = (struct ezusb_priv *) urb->context;
  1168. struct ezusb_packet *ans = urb->transfer_buffer;
  1169. u16 crc;
  1170. u16 hermes_rid;
  1171. if (upriv->udev == NULL)
  1172. return;
  1173. if (urb->status == -ETIMEDOUT) {
  1174. /* When a device gets unplugged we get this every time
  1175. * we resubmit, flooding the logs. Since we don't use
  1176. * USB timeouts, it shouldn't happen any other time*/
  1177. pr_warning("%s: urb timed out, not resubmiting", __func__);
  1178. return;
  1179. }
  1180. if (urb->status == -ECONNABORTED) {
  1181. pr_warning("%s: connection abort, resubmiting urb",
  1182. __func__);
  1183. goto resubmit;
  1184. }
  1185. if ((urb->status == -EILSEQ)
  1186. || (urb->status == -ENOENT)
  1187. || (urb->status == -ECONNRESET)) {
  1188. netdev_dbg(upriv->dev, "status %d, not resubmiting\n",
  1189. urb->status);
  1190. return;
  1191. }
  1192. if (urb->status)
  1193. netdev_dbg(upriv->dev, "status: %d length: %d\n",
  1194. urb->status, urb->actual_length);
  1195. if (urb->actual_length < sizeof(*ans)) {
  1196. err("%s: short read, ignoring", __func__);
  1197. goto resubmit;
  1198. }
  1199. crc = build_crc(ans);
  1200. if (le16_to_cpu(ans->crc) != crc) {
  1201. err("CRC error, ignoring packet");
  1202. goto resubmit;
  1203. }
  1204. hermes_rid = le16_to_cpu(ans->hermes_rid);
  1205. if ((hermes_rid != EZUSB_RID_RX) && !EZUSB_IS_INFO(hermes_rid)) {
  1206. ezusb_request_in_callback(upriv, urb);
  1207. } else if (upriv->dev) {
  1208. struct net_device *dev = upriv->dev;
  1209. struct orinoco_private *priv = ndev_priv(dev);
  1210. struct hermes *hw = &priv->hw;
  1211. if (hermes_rid == EZUSB_RID_RX) {
  1212. __orinoco_ev_rx(dev, hw);
  1213. } else {
  1214. hermes_write_regn(hw, INFOFID,
  1215. le16_to_cpu(ans->hermes_rid));
  1216. __orinoco_ev_info(dev, hw);
  1217. }
  1218. }
  1219. resubmit:
  1220. if (upriv->udev)
  1221. ezusb_submit_in_urb(upriv);
  1222. }
  1223. static inline void ezusb_delete(struct ezusb_priv *upriv)
  1224. {
  1225. struct net_device *dev;
  1226. struct list_head *item;
  1227. struct list_head *tmp_item;
  1228. unsigned long flags;
  1229. BUG_ON(in_interrupt());
  1230. BUG_ON(!upriv);
  1231. dev = upriv->dev;
  1232. mutex_lock(&upriv->mtx);
  1233. upriv->udev = NULL; /* No timer will be rearmed from here */
  1234. usb_kill_urb(upriv->read_urb);
  1235. spin_lock_irqsave(&upriv->req_lock, flags);
  1236. list_for_each_safe(item, tmp_item, &upriv->req_active) {
  1237. struct request_context *ctx;
  1238. int err;
  1239. ctx = list_entry(item, struct request_context, list);
  1240. atomic_inc(&ctx->refcount);
  1241. ctx->outurb->transfer_flags |= URB_ASYNC_UNLINK;
  1242. err = usb_unlink_urb(ctx->outurb);
  1243. spin_unlock_irqrestore(&upriv->req_lock, flags);
  1244. if (err == -EINPROGRESS)
  1245. wait_for_completion(&ctx->done);
  1246. del_timer_sync(&ctx->timer);
  1247. /* FIXME: there is an slight chance for the irq handler to
  1248. * be running */
  1249. if (!list_empty(&ctx->list))
  1250. ezusb_ctx_complete(ctx);
  1251. ezusb_request_context_put(ctx);
  1252. spin_lock_irqsave(&upriv->req_lock, flags);
  1253. }
  1254. spin_unlock_irqrestore(&upriv->req_lock, flags);
  1255. list_for_each_safe(item, tmp_item, &upriv->req_pending)
  1256. ezusb_ctx_complete(list_entry(item,
  1257. struct request_context, list));
  1258. if (upriv->read_urb && upriv->read_urb->status == -EINPROGRESS)
  1259. printk(KERN_ERR PFX "Some URB in progress\n");
  1260. mutex_unlock(&upriv->mtx);
  1261. if (upriv->read_urb) {
  1262. kfree(upriv->read_urb->transfer_buffer);
  1263. usb_free_urb(upriv->read_urb);
  1264. }
  1265. kfree(upriv->bap_buf);
  1266. if (upriv->dev) {
  1267. struct orinoco_private *priv = ndev_priv(upriv->dev);
  1268. orinoco_if_del(priv);
  1269. free_orinocodev(priv);
  1270. }
  1271. }
  1272. static void ezusb_lock_irqsave(spinlock_t *lock,
  1273. unsigned long *flags) __acquires(lock)
  1274. {
  1275. spin_lock_bh(lock);
  1276. }
  1277. static void ezusb_unlock_irqrestore(spinlock_t *lock,
  1278. unsigned long *flags) __releases(lock)
  1279. {
  1280. spin_unlock_bh(lock);
  1281. }
  1282. static void ezusb_lock_irq(spinlock_t *lock) __acquires(lock)
  1283. {
  1284. spin_lock_bh(lock);
  1285. }
  1286. static void ezusb_unlock_irq(spinlock_t *lock) __releases(lock)
  1287. {
  1288. spin_unlock_bh(lock);
  1289. }
  1290. static const struct hermes_ops ezusb_ops = {
  1291. .init = ezusb_init,
  1292. .cmd_wait = ezusb_docmd_wait,
  1293. .init_cmd_wait = ezusb_doicmd_wait,
  1294. .allocate = ezusb_allocate,
  1295. .read_ltv = ezusb_read_ltv,
  1296. .write_ltv = ezusb_write_ltv,
  1297. .bap_pread = ezusb_bap_pread,
  1298. .read_pda = ezusb_read_pda,
  1299. .program_init = ezusb_program_init,
  1300. .program_end = ezusb_program_end,
  1301. .program = ezusb_program,
  1302. .lock_irqsave = ezusb_lock_irqsave,
  1303. .unlock_irqrestore = ezusb_unlock_irqrestore,
  1304. .lock_irq = ezusb_lock_irq,
  1305. .unlock_irq = ezusb_unlock_irq,
  1306. };
  1307. static const struct net_device_ops ezusb_netdev_ops = {
  1308. .ndo_open = orinoco_open,
  1309. .ndo_stop = orinoco_stop,
  1310. .ndo_start_xmit = ezusb_xmit,
  1311. .ndo_set_rx_mode = orinoco_set_multicast_list,
  1312. .ndo_change_mtu = orinoco_change_mtu,
  1313. .ndo_set_mac_address = eth_mac_addr,
  1314. .ndo_validate_addr = eth_validate_addr,
  1315. .ndo_tx_timeout = orinoco_tx_timeout,
  1316. .ndo_get_stats = orinoco_get_stats,
  1317. };
  1318. static int ezusb_probe(struct usb_interface *interface,
  1319. const struct usb_device_id *id)
  1320. {
  1321. struct usb_device *udev = interface_to_usbdev(interface);
  1322. struct orinoco_private *priv;
  1323. struct hermes *hw;
  1324. struct ezusb_priv *upriv = NULL;
  1325. struct usb_interface_descriptor *iface_desc;
  1326. struct usb_endpoint_descriptor *ep;
  1327. const struct firmware *fw_entry = NULL;
  1328. int retval = 0;
  1329. int i;
  1330. priv = alloc_orinocodev(sizeof(*upriv), &udev->dev,
  1331. ezusb_hard_reset, NULL);
  1332. if (!priv) {
  1333. err("Couldn't allocate orinocodev");
  1334. goto exit;
  1335. }
  1336. hw = &priv->hw;
  1337. upriv = priv->card;
  1338. mutex_init(&upriv->mtx);
  1339. spin_lock_init(&upriv->reply_count_lock);
  1340. spin_lock_init(&upriv->req_lock);
  1341. INIT_LIST_HEAD(&upriv->req_pending);
  1342. INIT_LIST_HEAD(&upriv->req_active);
  1343. upriv->udev = udev;
  1344. hw->iobase = (void __force __iomem *) &upriv->hermes_reg_fake;
  1345. hw->reg_spacing = HERMES_16BIT_REGSPACING;
  1346. hw->priv = upriv;
  1347. hw->ops = &ezusb_ops;
  1348. /* set up the endpoint information */
  1349. /* check out the endpoints */
  1350. iface_desc = &interface->altsetting[0].desc;
  1351. for (i = 0; i < iface_desc->bNumEndpoints; ++i) {
  1352. ep = &interface->altsetting[0].endpoint[i].desc;
  1353. if (((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
  1354. == USB_DIR_IN) &&
  1355. ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
  1356. == USB_ENDPOINT_XFER_BULK)) {
  1357. /* we found a bulk in endpoint */
  1358. if (upriv->read_urb != NULL) {
  1359. pr_warning("Found a second bulk in ep, ignored");
  1360. continue;
  1361. }
  1362. upriv->read_urb = usb_alloc_urb(0, GFP_KERNEL);
  1363. if (!upriv->read_urb) {
  1364. err("No free urbs available");
  1365. goto error;
  1366. }
  1367. if (le16_to_cpu(ep->wMaxPacketSize) != 64)
  1368. pr_warning("bulk in: wMaxPacketSize!= 64");
  1369. if (ep->bEndpointAddress != (2 | USB_DIR_IN))
  1370. pr_warning("bulk in: bEndpointAddress: %d",
  1371. ep->bEndpointAddress);
  1372. upriv->read_pipe = usb_rcvbulkpipe(udev,
  1373. ep->
  1374. bEndpointAddress);
  1375. upriv->read_urb->transfer_buffer =
  1376. kmalloc(BULK_BUF_SIZE, GFP_KERNEL);
  1377. if (!upriv->read_urb->transfer_buffer) {
  1378. err("Couldn't allocate IN buffer");
  1379. goto error;
  1380. }
  1381. }
  1382. if (((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
  1383. == USB_DIR_OUT) &&
  1384. ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
  1385. == USB_ENDPOINT_XFER_BULK)) {
  1386. /* we found a bulk out endpoint */
  1387. if (upriv->bap_buf != NULL) {
  1388. pr_warning("Found a second bulk out ep, ignored");
  1389. continue;
  1390. }
  1391. if (le16_to_cpu(ep->wMaxPacketSize) != 64)
  1392. pr_warning("bulk out: wMaxPacketSize != 64");
  1393. if (ep->bEndpointAddress != 2)
  1394. pr_warning("bulk out: bEndpointAddress: %d",
  1395. ep->bEndpointAddress);
  1396. upriv->write_pipe = usb_sndbulkpipe(udev,
  1397. ep->
  1398. bEndpointAddress);
  1399. upriv->bap_buf = kmalloc(BULK_BUF_SIZE, GFP_KERNEL);
  1400. if (!upriv->bap_buf) {
  1401. err("Couldn't allocate bulk_out_buffer");
  1402. goto error;
  1403. }
  1404. }
  1405. }
  1406. if (!upriv->bap_buf || !upriv->read_urb) {
  1407. err("Didn't find the required bulk endpoints");
  1408. goto error;
  1409. }
  1410. if (request_firmware(&fw_entry, "orinoco_ezusb_fw",
  1411. &interface->dev) == 0) {
  1412. firmware.size = fw_entry->size;
  1413. firmware.code = fw_entry->data;
  1414. }
  1415. if (firmware.size && firmware.code) {
  1416. if (ezusb_firmware_download(upriv, &firmware) < 0)
  1417. goto error;
  1418. } else {
  1419. err("No firmware to download");
  1420. goto error;
  1421. }
  1422. if (ezusb_hard_reset(priv) < 0) {
  1423. err("Cannot reset the device");
  1424. goto error;
  1425. }
  1426. /* If the firmware is already downloaded orinoco.c will call
  1427. * ezusb_init but if the firmware is not already there, that will make
  1428. * the kernel very unstable, so we try initializing here and quit in
  1429. * case of error */
  1430. if (ezusb_init(hw) < 0) {
  1431. err("Couldn't initialize the device");
  1432. err("Firmware may not be downloaded or may be wrong.");
  1433. goto error;
  1434. }
  1435. /* Initialise the main driver */
  1436. if (orinoco_init(priv) != 0) {
  1437. err("orinoco_init() failed\n");
  1438. goto error;
  1439. }
  1440. if (orinoco_if_add(priv, 0, 0, &ezusb_netdev_ops) != 0) {
  1441. upriv->dev = NULL;
  1442. err("%s: orinoco_if_add() failed", __func__);
  1443. goto error;
  1444. }
  1445. upriv->dev = priv->ndev;
  1446. goto exit;
  1447. error:
  1448. ezusb_delete(upriv);
  1449. if (upriv->dev) {
  1450. /* upriv->dev was 0, so ezusb_delete() didn't free it */
  1451. free_orinocodev(priv);
  1452. }
  1453. upriv = NULL;
  1454. retval = -EFAULT;
  1455. exit:
  1456. if (fw_entry) {
  1457. firmware.code = NULL;
  1458. firmware.size = 0;
  1459. release_firmware(fw_entry);
  1460. }
  1461. usb_set_intfdata(interface, upriv);
  1462. return retval;
  1463. }
  1464. static void ezusb_disconnect(struct usb_interface *intf)
  1465. {
  1466. struct ezusb_priv *upriv = usb_get_intfdata(intf);
  1467. usb_set_intfdata(intf, NULL);
  1468. ezusb_delete(upriv);
  1469. printk(KERN_INFO PFX "Disconnected\n");
  1470. }
  1471. /* usb specific object needed to register this driver with the usb subsystem */
  1472. static struct usb_driver orinoco_driver = {
  1473. .name = DRIVER_NAME,
  1474. .probe = ezusb_probe,
  1475. .disconnect = ezusb_disconnect,
  1476. .id_table = ezusb_table,
  1477. .disable_hub_initiated_lpm = 1,
  1478. };
  1479. module_usb_driver(orinoco_driver);
  1480. MODULE_AUTHOR("Manuel Estrada Sainz");
  1481. MODULE_DESCRIPTION("Driver for Orinoco wireless LAN cards using EZUSB bridge");
  1482. MODULE_LICENSE("Dual MPL/GPL");