orinoco_usb.c 45 KB

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