orinoco_usb.c 45 KB

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