orinoco_usb.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793
  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. } __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. } __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 = kzalloc(sizeof(*ctx), GFP_ATOMIC);
  309. if (!ctx)
  310. return NULL;
  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. u8 mic[MICHAEL_MIC_LEN+1];
  1016. int err = 0;
  1017. int tx_control;
  1018. unsigned long flags;
  1019. struct request_context *ctx;
  1020. u8 *buf;
  1021. int tx_size;
  1022. if (!netif_running(dev)) {
  1023. printk(KERN_ERR "%s: Tx on stopped device!\n",
  1024. dev->name);
  1025. return NETDEV_TX_BUSY;
  1026. }
  1027. if (netif_queue_stopped(dev)) {
  1028. printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
  1029. dev->name);
  1030. return NETDEV_TX_BUSY;
  1031. }
  1032. if (orinoco_lock(priv, &flags) != 0) {
  1033. printk(KERN_ERR
  1034. "%s: ezusb_xmit() called while hw_unavailable\n",
  1035. dev->name);
  1036. return NETDEV_TX_BUSY;
  1037. }
  1038. if (!netif_carrier_ok(dev) ||
  1039. (priv->iw_mode == NL80211_IFTYPE_MONITOR)) {
  1040. /* Oops, the firmware hasn't established a connection,
  1041. silently drop the packet (this seems to be the
  1042. safest approach). */
  1043. goto drop;
  1044. }
  1045. /* Check packet length */
  1046. if (skb->len < ETH_HLEN)
  1047. goto drop;
  1048. ctx = ezusb_alloc_ctx(upriv, EZUSB_RID_TX, 0);
  1049. if (!ctx)
  1050. goto busy;
  1051. memset(ctx->buf, 0, BULK_BUF_SIZE);
  1052. buf = ctx->buf->data;
  1053. tx_control = 0;
  1054. err = orinoco_process_xmit_skb(skb, dev, priv, &tx_control,
  1055. &mic[0]);
  1056. if (err)
  1057. goto drop;
  1058. {
  1059. __le16 *tx_cntl = (__le16 *)buf;
  1060. *tx_cntl = cpu_to_le16(tx_control);
  1061. buf += sizeof(*tx_cntl);
  1062. }
  1063. memcpy(buf, skb->data, skb->len);
  1064. buf += skb->len;
  1065. if (tx_control & HERMES_TXCTRL_MIC) {
  1066. u8 *m = mic;
  1067. /* Mic has been offset so it can be copied to an even
  1068. * address. We're copying eveything anyway, so we
  1069. * don't need to copy that first byte. */
  1070. if (skb->len % 2)
  1071. m++;
  1072. memcpy(buf, m, MICHAEL_MIC_LEN);
  1073. buf += MICHAEL_MIC_LEN;
  1074. }
  1075. /* Finally, we actually initiate the send */
  1076. netif_stop_queue(dev);
  1077. /* The card may behave better if we send evenly sized usb transfers */
  1078. tx_size = ALIGN(buf - ctx->buf->data, 2);
  1079. err = ezusb_access_ltv(upriv, ctx, tx_size, NULL,
  1080. EZUSB_FRAME_DATA, NULL, 0, NULL);
  1081. if (err) {
  1082. netif_start_queue(dev);
  1083. if (net_ratelimit())
  1084. printk(KERN_ERR "%s: Error %d transmitting packet\n",
  1085. dev->name, err);
  1086. goto busy;
  1087. }
  1088. dev->trans_start = jiffies;
  1089. stats->tx_bytes += skb->len;
  1090. goto ok;
  1091. drop:
  1092. stats->tx_errors++;
  1093. stats->tx_dropped++;
  1094. ok:
  1095. orinoco_unlock(priv, &flags);
  1096. dev_kfree_skb(skb);
  1097. return NETDEV_TX_OK;
  1098. busy:
  1099. orinoco_unlock(priv, &flags);
  1100. return NETDEV_TX_BUSY;
  1101. }
  1102. static int ezusb_allocate(struct hermes *hw, u16 size, u16 *fid)
  1103. {
  1104. *fid = EZUSB_RID_TX;
  1105. return 0;
  1106. }
  1107. static int ezusb_hard_reset(struct orinoco_private *priv)
  1108. {
  1109. struct ezusb_priv *upriv = priv->card;
  1110. int retval = ezusb_8051_cpucs(upriv, 1);
  1111. if (retval < 0) {
  1112. err("Failed to reset");
  1113. return retval;
  1114. }
  1115. retval = ezusb_8051_cpucs(upriv, 0);
  1116. if (retval < 0) {
  1117. err("Failed to unreset");
  1118. return retval;
  1119. }
  1120. dbg("sending control message");
  1121. retval = usb_control_msg(upriv->udev,
  1122. usb_sndctrlpipe(upriv->udev, 0),
  1123. EZUSB_REQUEST_TRIGER,
  1124. USB_TYPE_VENDOR | USB_RECIP_DEVICE |
  1125. USB_DIR_OUT, 0x0, 0x0, NULL, 0,
  1126. DEF_TIMEOUT);
  1127. if (retval < 0) {
  1128. err("EZUSB_REQUEST_TRIGER failed retval %d", retval);
  1129. return retval;
  1130. }
  1131. #if 0
  1132. dbg("Sending EZUSB_REQUEST_TRIG_AC");
  1133. retval = usb_control_msg(upriv->udev,
  1134. usb_sndctrlpipe(upriv->udev, 0),
  1135. EZUSB_REQUEST_TRIG_AC,
  1136. USB_TYPE_VENDOR | USB_RECIP_DEVICE |
  1137. USB_DIR_OUT, 0x00FA, 0x0, NULL, 0,
  1138. DEF_TIMEOUT);
  1139. if (retval < 0) {
  1140. err("EZUSB_REQUEST_TRIG_AC failed retval %d", retval);
  1141. return retval;
  1142. }
  1143. #endif
  1144. return 0;
  1145. }
  1146. static int ezusb_init(hermes_t *hw)
  1147. {
  1148. struct ezusb_priv *upriv = hw->priv;
  1149. int retval;
  1150. BUG_ON(in_interrupt());
  1151. BUG_ON(!upriv);
  1152. upriv->reply_count = 0;
  1153. /* Write the MAGIC number on the simulated registers to keep
  1154. * orinoco.c happy */
  1155. hermes_write_regn(hw, SWSUPPORT0, HERMES_MAGIC);
  1156. hermes_write_regn(hw, RXFID, EZUSB_RID_RX);
  1157. usb_kill_urb(upriv->read_urb);
  1158. ezusb_submit_in_urb(upriv);
  1159. retval = ezusb_write_ltv(hw, 0, EZUSB_RID_INIT1,
  1160. HERMES_BYTES_TO_RECLEN(2), "\x10\x00");
  1161. if (retval < 0) {
  1162. printk(KERN_ERR PFX "EZUSB_RID_INIT1 error %d\n", retval);
  1163. return retval;
  1164. }
  1165. retval = ezusb_docmd_wait(hw, HERMES_CMD_INIT, 0, NULL);
  1166. if (retval < 0) {
  1167. printk(KERN_ERR PFX "HERMES_CMD_INIT error %d\n", retval);
  1168. return retval;
  1169. }
  1170. return 0;
  1171. }
  1172. static void ezusb_bulk_in_callback(struct urb *urb)
  1173. {
  1174. struct ezusb_priv *upriv = (struct ezusb_priv *) urb->context;
  1175. struct ezusb_packet *ans = urb->transfer_buffer;
  1176. u16 crc;
  1177. u16 hermes_rid;
  1178. if (upriv->udev == NULL) {
  1179. dbg("disconnected");
  1180. return;
  1181. }
  1182. if (urb->status == -ETIMEDOUT) {
  1183. /* When a device gets unplugged we get this every time
  1184. * we resubmit, flooding the logs. Since we don't use
  1185. * USB timeouts, it shouldn't happen any other time*/
  1186. pr_warning("%s: urb timed out, not resubmiting", __func__);
  1187. return;
  1188. }
  1189. if (urb->status == -ECONNABORTED) {
  1190. pr_warning("%s: connection abort, resubmiting urb",
  1191. __func__);
  1192. goto resubmit;
  1193. }
  1194. if ((urb->status == -EILSEQ)
  1195. || (urb->status == -ENOENT)
  1196. || (urb->status == -ECONNRESET)) {
  1197. dbg("status %d, not resubmiting", urb->status);
  1198. return;
  1199. }
  1200. if (urb->status)
  1201. dbg("status: %d length: %d",
  1202. urb->status, urb->actual_length);
  1203. if (urb->actual_length < sizeof(*ans)) {
  1204. err("%s: short read, ignoring", __func__);
  1205. goto resubmit;
  1206. }
  1207. crc = build_crc(ans);
  1208. if (le16_to_cpu(ans->crc) != crc) {
  1209. err("CRC error, ignoring packet");
  1210. goto resubmit;
  1211. }
  1212. hermes_rid = le16_to_cpu(ans->hermes_rid);
  1213. if ((hermes_rid != EZUSB_RID_RX) && !EZUSB_IS_INFO(hermes_rid)) {
  1214. ezusb_request_in_callback(upriv, urb);
  1215. } else if (upriv->dev) {
  1216. struct net_device *dev = upriv->dev;
  1217. struct orinoco_private *priv = ndev_priv(dev);
  1218. hermes_t *hw = &priv->hw;
  1219. if (hermes_rid == EZUSB_RID_RX) {
  1220. __orinoco_ev_rx(dev, hw);
  1221. } else {
  1222. hermes_write_regn(hw, INFOFID,
  1223. le16_to_cpu(ans->hermes_rid));
  1224. __orinoco_ev_info(dev, hw);
  1225. }
  1226. }
  1227. resubmit:
  1228. if (upriv->udev)
  1229. ezusb_submit_in_urb(upriv);
  1230. }
  1231. static inline void ezusb_delete(struct ezusb_priv *upriv)
  1232. {
  1233. struct net_device *dev;
  1234. struct list_head *item;
  1235. struct list_head *tmp_item;
  1236. unsigned long flags;
  1237. BUG_ON(in_interrupt());
  1238. BUG_ON(!upriv);
  1239. dev = upriv->dev;
  1240. mutex_lock(&upriv->mtx);
  1241. upriv->udev = NULL; /* No timer will be rearmed from here */
  1242. usb_kill_urb(upriv->read_urb);
  1243. spin_lock_irqsave(&upriv->req_lock, flags);
  1244. list_for_each_safe(item, tmp_item, &upriv->req_active) {
  1245. struct request_context *ctx;
  1246. int err;
  1247. ctx = list_entry(item, struct request_context, list);
  1248. atomic_inc(&ctx->refcount);
  1249. ctx->outurb->transfer_flags |= URB_ASYNC_UNLINK;
  1250. err = usb_unlink_urb(ctx->outurb);
  1251. spin_unlock_irqrestore(&upriv->req_lock, flags);
  1252. if (err == -EINPROGRESS)
  1253. wait_for_completion(&ctx->done);
  1254. del_timer_sync(&ctx->timer);
  1255. /* FIXME: there is an slight chance for the irq handler to
  1256. * be running */
  1257. if (!list_empty(&ctx->list))
  1258. ezusb_ctx_complete(ctx);
  1259. ezusb_request_context_put(ctx);
  1260. spin_lock_irqsave(&upriv->req_lock, flags);
  1261. }
  1262. spin_unlock_irqrestore(&upriv->req_lock, flags);
  1263. list_for_each_safe(item, tmp_item, &upriv->req_pending)
  1264. ezusb_ctx_complete(list_entry(item,
  1265. struct request_context, list));
  1266. if (upriv->read_urb && upriv->read_urb->status == -EINPROGRESS)
  1267. printk(KERN_ERR PFX "Some URB in progress\n");
  1268. mutex_unlock(&upriv->mtx);
  1269. if (upriv->read_urb) {
  1270. kfree(upriv->read_urb->transfer_buffer);
  1271. usb_free_urb(upriv->read_urb);
  1272. }
  1273. kfree(upriv->bap_buf);
  1274. if (upriv->dev) {
  1275. struct orinoco_private *priv = ndev_priv(upriv->dev);
  1276. orinoco_if_del(priv);
  1277. free_orinocodev(priv);
  1278. }
  1279. }
  1280. static void ezusb_lock_irqsave(spinlock_t *lock,
  1281. unsigned long *flags) __acquires(lock)
  1282. {
  1283. spin_lock_bh(lock);
  1284. }
  1285. static void ezusb_unlock_irqrestore(spinlock_t *lock,
  1286. unsigned long *flags) __releases(lock)
  1287. {
  1288. spin_unlock_bh(lock);
  1289. }
  1290. static void ezusb_lock_irq(spinlock_t *lock) __acquires(lock)
  1291. {
  1292. spin_lock_bh(lock);
  1293. }
  1294. static void ezusb_unlock_irq(spinlock_t *lock) __releases(lock)
  1295. {
  1296. spin_unlock_bh(lock);
  1297. }
  1298. static const struct hermes_ops ezusb_ops = {
  1299. .init = ezusb_init,
  1300. .cmd_wait = ezusb_docmd_wait,
  1301. .init_cmd_wait = ezusb_doicmd_wait,
  1302. .allocate = ezusb_allocate,
  1303. .read_ltv = ezusb_read_ltv,
  1304. .write_ltv = ezusb_write_ltv,
  1305. .bap_pread = ezusb_bap_pread,
  1306. .read_pda = ezusb_read_pda,
  1307. .program_init = ezusb_program_init,
  1308. .program_end = ezusb_program_end,
  1309. .program = ezusb_program,
  1310. .lock_irqsave = ezusb_lock_irqsave,
  1311. .unlock_irqrestore = ezusb_unlock_irqrestore,
  1312. .lock_irq = ezusb_lock_irq,
  1313. .unlock_irq = ezusb_unlock_irq,
  1314. };
  1315. static const struct net_device_ops ezusb_netdev_ops = {
  1316. .ndo_open = orinoco_open,
  1317. .ndo_stop = orinoco_stop,
  1318. .ndo_start_xmit = ezusb_xmit,
  1319. .ndo_set_multicast_list = orinoco_set_multicast_list,
  1320. .ndo_change_mtu = orinoco_change_mtu,
  1321. .ndo_set_mac_address = eth_mac_addr,
  1322. .ndo_validate_addr = eth_validate_addr,
  1323. .ndo_tx_timeout = orinoco_tx_timeout,
  1324. .ndo_get_stats = orinoco_get_stats,
  1325. };
  1326. static int ezusb_probe(struct usb_interface *interface,
  1327. const struct usb_device_id *id)
  1328. {
  1329. struct usb_device *udev = interface_to_usbdev(interface);
  1330. struct orinoco_private *priv;
  1331. hermes_t *hw;
  1332. struct ezusb_priv *upriv = NULL;
  1333. struct usb_interface_descriptor *iface_desc;
  1334. struct usb_endpoint_descriptor *ep;
  1335. const struct firmware *fw_entry;
  1336. int retval = 0;
  1337. int i;
  1338. priv = alloc_orinocodev(sizeof(*upriv), &udev->dev,
  1339. ezusb_hard_reset, NULL);
  1340. if (!priv) {
  1341. err("Couldn't allocate orinocodev");
  1342. goto exit;
  1343. }
  1344. hw = &priv->hw;
  1345. upriv = priv->card;
  1346. mutex_init(&upriv->mtx);
  1347. spin_lock_init(&upriv->reply_count_lock);
  1348. spin_lock_init(&upriv->req_lock);
  1349. INIT_LIST_HEAD(&upriv->req_pending);
  1350. INIT_LIST_HEAD(&upriv->req_active);
  1351. upriv->udev = udev;
  1352. hw->iobase = (void __force __iomem *) &upriv->hermes_reg_fake;
  1353. hw->reg_spacing = HERMES_16BIT_REGSPACING;
  1354. hw->priv = upriv;
  1355. hw->ops = &ezusb_ops;
  1356. /* set up the endpoint information */
  1357. /* check out the endpoints */
  1358. iface_desc = &interface->altsetting[0].desc;
  1359. for (i = 0; i < iface_desc->bNumEndpoints; ++i) {
  1360. ep = &interface->altsetting[0].endpoint[i].desc;
  1361. if (((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
  1362. == USB_DIR_IN) &&
  1363. ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
  1364. == USB_ENDPOINT_XFER_BULK)) {
  1365. /* we found a bulk in endpoint */
  1366. if (upriv->read_urb != NULL) {
  1367. pr_warning("Found a second bulk in ep, ignored");
  1368. continue;
  1369. }
  1370. upriv->read_urb = usb_alloc_urb(0, GFP_KERNEL);
  1371. if (!upriv->read_urb) {
  1372. err("No free urbs available");
  1373. goto error;
  1374. }
  1375. if (le16_to_cpu(ep->wMaxPacketSize) != 64)
  1376. pr_warning("bulk in: wMaxPacketSize!= 64");
  1377. if (ep->bEndpointAddress != (2 | USB_DIR_IN))
  1378. pr_warning("bulk in: bEndpointAddress: %d",
  1379. ep->bEndpointAddress);
  1380. upriv->read_pipe = usb_rcvbulkpipe(udev,
  1381. ep->
  1382. bEndpointAddress);
  1383. upriv->read_urb->transfer_buffer =
  1384. kmalloc(BULK_BUF_SIZE, GFP_KERNEL);
  1385. if (!upriv->read_urb->transfer_buffer) {
  1386. err("Couldn't allocate IN buffer");
  1387. goto error;
  1388. }
  1389. }
  1390. if (((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
  1391. == USB_DIR_OUT) &&
  1392. ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
  1393. == USB_ENDPOINT_XFER_BULK)) {
  1394. /* we found a bulk out endpoint */
  1395. if (upriv->bap_buf != NULL) {
  1396. pr_warning("Found a second bulk out ep, ignored");
  1397. continue;
  1398. }
  1399. if (le16_to_cpu(ep->wMaxPacketSize) != 64)
  1400. pr_warning("bulk out: wMaxPacketSize != 64");
  1401. if (ep->bEndpointAddress != 2)
  1402. pr_warning("bulk out: bEndpointAddress: %d",
  1403. ep->bEndpointAddress);
  1404. upriv->write_pipe = usb_sndbulkpipe(udev,
  1405. ep->
  1406. bEndpointAddress);
  1407. upriv->bap_buf = kmalloc(BULK_BUF_SIZE, GFP_KERNEL);
  1408. if (!upriv->bap_buf) {
  1409. err("Couldn't allocate bulk_out_buffer");
  1410. goto error;
  1411. }
  1412. }
  1413. }
  1414. if (!upriv->bap_buf || !upriv->read_urb) {
  1415. err("Didn't find the required bulk endpoints");
  1416. goto error;
  1417. }
  1418. if (request_firmware(&fw_entry, "orinoco_ezusb_fw",
  1419. &interface->dev) == 0) {
  1420. firmware.size = fw_entry->size;
  1421. firmware.code = fw_entry->data;
  1422. }
  1423. if (firmware.size && firmware.code) {
  1424. ezusb_firmware_download(upriv, &firmware);
  1425. } else {
  1426. err("No firmware to download");
  1427. goto error;
  1428. }
  1429. if (ezusb_hard_reset(priv) < 0) {
  1430. err("Cannot reset the device");
  1431. goto error;
  1432. }
  1433. /* If the firmware is already downloaded orinoco.c will call
  1434. * ezusb_init but if the firmware is not already there, that will make
  1435. * the kernel very unstable, so we try initializing here and quit in
  1436. * case of error */
  1437. if (ezusb_init(hw) < 0) {
  1438. err("Couldn't initialize the device");
  1439. err("Firmware may not be downloaded or may be wrong.");
  1440. goto error;
  1441. }
  1442. /* Initialise the main driver */
  1443. if (orinoco_init(priv) != 0) {
  1444. err("orinoco_init() failed\n");
  1445. goto error;
  1446. }
  1447. if (orinoco_if_add(priv, 0, 0, &ezusb_netdev_ops) != 0) {
  1448. upriv->dev = NULL;
  1449. err("%s: orinoco_if_add() failed", __func__);
  1450. goto error;
  1451. }
  1452. upriv->dev = priv->ndev;
  1453. goto exit;
  1454. error:
  1455. ezusb_delete(upriv);
  1456. if (upriv->dev) {
  1457. /* upriv->dev was 0, so ezusb_delete() didn't free it */
  1458. free_orinocodev(priv);
  1459. }
  1460. upriv = NULL;
  1461. retval = -EFAULT;
  1462. exit:
  1463. if (fw_entry) {
  1464. firmware.code = NULL;
  1465. firmware.size = 0;
  1466. release_firmware(fw_entry);
  1467. }
  1468. usb_set_intfdata(interface, upriv);
  1469. return retval;
  1470. }
  1471. static void ezusb_disconnect(struct usb_interface *intf)
  1472. {
  1473. struct ezusb_priv *upriv = usb_get_intfdata(intf);
  1474. usb_set_intfdata(intf, NULL);
  1475. ezusb_delete(upriv);
  1476. printk(KERN_INFO PFX "Disconnected\n");
  1477. }
  1478. /* usb specific object needed to register this driver with the usb subsystem */
  1479. static struct usb_driver orinoco_driver = {
  1480. .name = DRIVER_NAME,
  1481. .probe = ezusb_probe,
  1482. .disconnect = ezusb_disconnect,
  1483. .id_table = ezusb_table,
  1484. };
  1485. /* Can't be declared "const" or the whole __initdata section will
  1486. * become const */
  1487. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  1488. " (Manuel Estrada Sainz)";
  1489. static int __init ezusb_module_init(void)
  1490. {
  1491. int err;
  1492. printk(KERN_DEBUG "%s\n", version);
  1493. /* register this driver with the USB subsystem */
  1494. err = usb_register(&orinoco_driver);
  1495. if (err < 0) {
  1496. printk(KERN_ERR PFX "usb_register failed, error %d\n",
  1497. err);
  1498. return err;
  1499. }
  1500. return 0;
  1501. }
  1502. static void __exit ezusb_module_exit(void)
  1503. {
  1504. /* deregister this driver with the USB subsystem */
  1505. usb_deregister(&orinoco_driver);
  1506. }
  1507. module_init(ezusb_module_init);
  1508. module_exit(ezusb_module_exit);
  1509. MODULE_AUTHOR("Manuel Estrada Sainz");
  1510. MODULE_DESCRIPTION
  1511. ("Driver for Orinoco wireless LAN cards using EZUSB bridge");
  1512. MODULE_LICENSE("Dual MPL/GPL");