orinoco_usb.c 46 KB

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