4 * Copyright (c) 2003 Manuel Estrada Sainz
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/
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.
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.
27 * Queueing code based on linux-wlan-ng 0.2.1-pre5
29 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
31 * The license is the same as above.
33 * Initialy based on USB Skeleton driver - 0.7
35 * Copyright (c) 2001 Greg Kroah-Hartman (greg@kroah.com)
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.
42 * NOTE: The original USB Skeleton driver is GPL, but all that code is
43 * gone so MPL/GPL applies.
46 #define DRIVER_NAME "orinoco_usb"
47 #define PFX DRIVER_NAME ": "
49 #include <linux/module.h>
50 #include <linux/kernel.h>
51 #include <linux/sched.h>
52 #include <linux/signal.h>
53 #include <linux/errno.h>
54 #include <linux/poll.h>
55 #include <linux/init.h>
56 #include <linux/slab.h>
57 #include <linux/fcntl.h>
58 #include <linux/spinlock.h>
59 #include <linux/list.h>
60 #include <linux/smp_lock.h>
61 #include <linux/usb.h>
62 #include <linux/timer.h>
64 #include <linux/netdevice.h>
65 #include <linux/if_arp.h>
66 #include <linux/etherdevice.h>
67 #include <linux/wireless.h>
68 #include <linux/firmware.h>
72 #ifndef URB_ASYNC_UNLINK
73 #define URB_ASYNC_UNLINK 0
76 /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
77 static const u8 encaps_hdr
[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
78 #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
80 struct header_struct
{
92 } __attribute__ ((packed
));
99 static struct ez_usb_fw firmware
= {
104 #ifdef CONFIG_USB_DEBUG
105 static int debug
= 1;
110 /* Debugging macros */
112 #define dbg(format, arg...) \
113 do { if (debug) printk(KERN_DEBUG PFX "%s: " format "\n", \
114 __FUNCTION__ , ## arg); } while (0)
116 #define err(format, arg...) \
117 do { printk(KERN_ERR PFX format "\n", ## arg); } while (0)
119 /* Module paramaters */
120 module_param(debug
, int, 0644);
121 MODULE_PARM_DESC(debug
, "Debug enabled or not");
124 * Under some conditions, the card gets stuck and stops paying attention
125 * to the world (i.e. data communication stalls) until we do something to
126 * it. Sending an INQ_TALLIES command seems to be enough and should be
127 * harmless otherwise. This behaviour has been observed when using the
128 * driver on a systemimager client during installation. In the past a
129 * timer was used to send INQ_TALLIES commands when there was no other
130 * activity, but it was troublesome and was removed.
133 #define USB_COMPAQ_VENDOR_ID 0x049f /* Compaq Computer Corp. */
134 #define USB_COMPAQ_WL215_ID 0x001f /* Compaq WL215 USB Adapter */
135 #define USB_COMPAQ_W200_ID 0x0076 /* Compaq W200 USB Adapter */
136 #define USB_HP_WL215_ID 0x0082 /* Compaq WL215 USB Adapter */
138 #define USB_MELCO_VENDOR_ID 0x0411
139 #define USB_BUFFALO_L11_ID 0x0006 /* BUFFALO WLI-USB-L11 Wireless LAN Adapter */
140 #define USB_BUFFALO_L11G_WR_ID 0x000B /* BUFFALO WLI-USB-L11G-WR Wireless LAN Adapter */
141 #define USB_BUFFALO_L11G_ID 0x000D /* BUFFALO WLI-USB-L11G Wireless LAN Adapter */
143 #define USB_LUCENT_VENDOR_ID 0x047E /* Lucent Technologies */
144 #define USB_LUCENT_ORINOCO_ID 0x0300 /* Lucent/Agere Orinoco USB Client */
146 #define USB_AVAYA8_VENDOR_ID 0x0D98
147 #define USB_AVAYAE_VENDOR_ID 0x0D9E
148 #define USB_AVAYA_WIRELESS_ID 0x0300 /* Avaya Wireless USB Card */
150 #define USB_AGERE_VENDOR_ID 0x0D4E /* Agere Systems */
151 #define USB_AGERE_MODEL0801_ID 0x1000 /* Wireless USB Card Model 0801 */
152 #define USB_AGERE_MODEL0802_ID 0x1001 /* Wireless USB Card Model 0802 */
153 #define USB_AGERE_REBRANDED_ID 0x047A /* WLAN USB Card */
155 #define USB_ELSA_VENDOR_ID 0x05CC
156 #define USB_ELSA_AIRLANCER_ID 0x3100 /* ELSA AirLancer USB-11 */
158 #define USB_LEGEND_VENDOR_ID 0x0E7C
159 #define USB_LEGEND_JOYNET_ID 0x0300 /* Joynet WLAN USB Card */
161 #define USB_SAMSUNG_VENDOR_ID 0x04E8
162 #define USB_SAMSUNG_SEW2001U1_ID 0x5002 /* Samsung SEW-2001u Card */
163 #define USB_SAMSUNG_SEW2001U2_ID 0x5B11 /* Samsung SEW-2001u Card */
164 #define USB_SAMSUNG_SEW2003U_ID 0x7011 /* Samsung SEW-2003U Card */
166 #define USB_IGATE_VENDOR_ID 0x0681
167 #define USB_IGATE_IGATE_11M_ID 0x0012 /* I-GATE 11M USB Card */
169 #define USB_FUJITSU_VENDOR_ID 0x0BF8
170 #define USB_FUJITSU_E1100_ID 0x1002 /* connect2AIR WLAN E-1100 USB */
172 #define USB_2WIRE_VENDOR_ID 0x1630
173 #define USB_2WIRE_WIRELESS_ID 0xff81 /* 2Wire Wireless USB adapter */
176 #define EZUSB_REQUEST_FW_TRANS 0xA0
177 #define EZUSB_REQUEST_TRIGER 0xAA
178 #define EZUSB_REQUEST_TRIG_AC 0xAC
179 #define EZUSB_CPUCS_REG 0x7F92
181 #define EZUSB_RID_TX 0x0700
182 #define EZUSB_RID_RX 0x0701
183 #define EZUSB_RID_INIT1 0x0702
184 #define EZUSB_RID_ACK 0x0710
185 #define EZUSB_RID_DOCMD 0x0860
187 /* Recognize info frames */
188 #define EZUSB_IS_INFO(id) ((id >= 0xF000) && (id <= 0xF2FF))
190 #define EZUSB_MAGIC 0x0210
192 #define EZUSB_FRAME_DATA 1
193 #define EZUSB_FRAME_CONTROL 2
195 #define DEF_TIMEOUT (3*HZ)
197 #define BULK_BUF_SIZE 2048
199 #define FW_BUF_SIZE 64
200 #define FW_VAR_OFFSET_PTR 0x359
201 #define FW_VAR_VALUE 0
202 #define FW_HOLE_START 0x100
203 #define FW_HOLE_END 0x300
205 struct ezusb_packet
{
206 __le16 magic
; /* 0x0210 */
209 __le16 frame_type
; /* 0x01 for data frames, 0x02 otherwise */
210 __le16 size
; /* transport size */
211 __le16 crc
; /* CRC up to here */
215 } __attribute__ ((packed
));
217 /* Table of devices that work or may work with this driver */
218 static struct usb_device_id ezusb_table
[] = {
219 {USB_DEVICE(USB_COMPAQ_VENDOR_ID
, USB_COMPAQ_WL215_ID
)},
220 {USB_DEVICE(USB_COMPAQ_VENDOR_ID
, USB_HP_WL215_ID
)},
221 {USB_DEVICE(USB_COMPAQ_VENDOR_ID
, USB_COMPAQ_W200_ID
)},
222 {USB_DEVICE(USB_MELCO_VENDOR_ID
, USB_BUFFALO_L11_ID
)},
223 {USB_DEVICE(USB_MELCO_VENDOR_ID
, USB_BUFFALO_L11G_WR_ID
)},
224 {USB_DEVICE(USB_MELCO_VENDOR_ID
, USB_BUFFALO_L11G_ID
)},
225 {USB_DEVICE(USB_LUCENT_VENDOR_ID
, USB_LUCENT_ORINOCO_ID
)},
226 {USB_DEVICE(USB_AVAYA8_VENDOR_ID
, USB_AVAYA_WIRELESS_ID
)},
227 {USB_DEVICE(USB_AVAYAE_VENDOR_ID
, USB_AVAYA_WIRELESS_ID
)},
228 {USB_DEVICE(USB_AGERE_VENDOR_ID
, USB_AGERE_MODEL0801_ID
)},
229 {USB_DEVICE(USB_AGERE_VENDOR_ID
, USB_AGERE_MODEL0802_ID
)},
230 {USB_DEVICE(USB_ELSA_VENDOR_ID
, USB_ELSA_AIRLANCER_ID
)},
231 {USB_DEVICE(USB_LEGEND_VENDOR_ID
, USB_LEGEND_JOYNET_ID
)},
232 {USB_DEVICE_VER(USB_SAMSUNG_VENDOR_ID
, USB_SAMSUNG_SEW2001U1_ID
,
234 {USB_DEVICE(USB_SAMSUNG_VENDOR_ID
, USB_SAMSUNG_SEW2001U2_ID
)},
235 {USB_DEVICE(USB_SAMSUNG_VENDOR_ID
, USB_SAMSUNG_SEW2003U_ID
)},
236 {USB_DEVICE(USB_IGATE_VENDOR_ID
, USB_IGATE_IGATE_11M_ID
)},
237 {USB_DEVICE(USB_FUJITSU_VENDOR_ID
, USB_FUJITSU_E1100_ID
)},
238 {USB_DEVICE(USB_2WIRE_VENDOR_ID
, USB_2WIRE_WIRELESS_ID
)},
239 {USB_DEVICE(USB_AGERE_VENDOR_ID
, USB_AGERE_REBRANDED_ID
)},
240 {} /* Terminating entry */
243 MODULE_DEVICE_TABLE(usb
, ezusb_table
);
245 /* Structure to hold all of our device specific stuff */
247 struct usb_device
*udev
;
248 struct net_device
*dev
;
249 struct semaphore sem
;
251 struct list_head req_pending
;
252 struct list_head req_active
;
253 spinlock_t reply_count_lock
;
254 u16 hermes_reg_fake
[0x40];
256 struct urb
*read_urb
;
265 EZUSB_CTX_REQ_SUBMITTED
,
266 EZUSB_CTX_REQ_COMPLETE
,
267 EZUSB_CTX_RESP_RECEIVED
,
268 EZUSB_CTX_REQ_TIMEOUT
,
269 EZUSB_CTX_REQ_FAILED
,
270 EZUSB_CTX_RESP_TIMEOUT
,
271 EZUSB_CTX_REQSUBMIT_FAIL
,
275 struct request_context
{
276 struct list_head list
;
278 struct completion done
; /* Signals that CTLX is dead */
280 struct urb
*outurb
; /* OUT for req pkt */
281 struct ezusb_priv
*upriv
;
282 struct ezusb_packet
*buf
;
284 struct timer_list timer
; /* Timeout handling */
285 ezusb_state_t state
; /* Current state */
286 /* the RID that we will wait for */
292 /* Forward declarations */
293 static void ezusb_ctx_complete(struct request_context
*ctx
);
294 static void ezusb_req_queue_run(struct ezusb_priv
*upriv
);
295 static void ezusb_bulk_in_callback(struct urb
*urb
);
298 /* Debug functions */
299 static inline void hex_dump(const void *data_p
, int size
)
302 const u8
*data
= data_p
;
304 printk(KERN_DEBUG
"Dump at %p, length: %d\n", data
, size
);
306 for (i
= 0; i
< size
; i
++) {
308 printk(KERN_DEBUG
"0x%04X: ", i
);
311 printk("%02X ", data
[i
]);
312 if ((i
& 0xf) == 0xf)
320 static inline u8
ezusb_reply_inc(u8 count
)
328 static void ezusb_request_context_put(struct request_context
*ctx
)
330 if (!atomic_dec_and_test(&ctx
->refcount
))
333 WARN_ON(!ctx
->done
.done
);
334 BUG_ON(ctx
->outurb
->status
== -EINPROGRESS
);
335 BUG_ON(timer_pending(&ctx
->timer
));
336 usb_free_urb(ctx
->outurb
);
341 static inline void ezusb_mod_timer(struct ezusb_priv
*upriv
,
342 struct timer_list
*timer
,
343 unsigned long expire
)
347 mod_timer(timer
, expire
);
350 static void ezusb_request_timerfn(u_long _ctx
)
352 struct request_context
*ctx
= (void *) _ctx
;
354 ctx
->outurb
->transfer_flags
|= URB_ASYNC_UNLINK
;
355 if (usb_unlink_urb(ctx
->outurb
) == -EINPROGRESS
) {
356 ctx
->state
= EZUSB_CTX_REQ_TIMEOUT
;
358 ctx
->state
= EZUSB_CTX_RESP_TIMEOUT
;
359 dbg("couldn't unlink");
360 atomic_inc(&ctx
->refcount
);
362 ezusb_ctx_complete(ctx
);
363 ezusb_request_context_put(ctx
);
367 static struct request_context
*ezusb_alloc_ctx(struct ezusb_priv
*upriv
,
368 u16 out_rid
, u16 in_rid
)
370 struct request_context
*ctx
;
372 ctx
= kmalloc(sizeof(*ctx
), GFP_ATOMIC
);
376 memset(ctx
, 0, sizeof(*ctx
));
378 ctx
->buf
= kmalloc(BULK_BUF_SIZE
, GFP_ATOMIC
);
383 ctx
->outurb
= usb_alloc_urb(0, GFP_ATOMIC
);
391 ctx
->state
= EZUSB_CTX_START
;
392 ctx
->out_rid
= out_rid
;
393 ctx
->in_rid
= in_rid
;
395 atomic_set(&ctx
->refcount
, 1);
396 init_completion(&ctx
->done
);
398 init_timer(&ctx
->timer
);
399 ctx
->timer
.function
= ezusb_request_timerfn
;
400 ctx
->timer
.data
= (u_long
) ctx
;
405 /* Hopefully the real complete_all will soon be exported, in the mean
406 * while this should work. */
407 static inline void ezusb_complete_all(struct completion
*comp
)
415 static void ezusb_ctx_complete(struct request_context
*ctx
)
417 struct ezusb_priv
*upriv
= ctx
->upriv
;
420 spin_lock_irqsave(&upriv
->req_lock
, flags
);
422 list_del_init(&ctx
->list
);
424 spin_unlock_irqrestore(&upriv
->req_lock
, flags
);
425 ezusb_req_queue_run(upriv
);
426 spin_lock_irqsave(&upriv
->req_lock
, flags
);
429 switch (ctx
->state
) {
430 case EZUSB_CTX_COMPLETE
:
431 case EZUSB_CTX_REQSUBMIT_FAIL
:
432 case EZUSB_CTX_REQ_FAILED
:
433 case EZUSB_CTX_REQ_TIMEOUT
:
434 case EZUSB_CTX_RESP_TIMEOUT
:
435 spin_unlock_irqrestore(&upriv
->req_lock
, flags
);
437 if ((ctx
->out_rid
== EZUSB_RID_TX
) && upriv
->dev
) {
438 struct net_device
*dev
= upriv
->dev
;
439 struct orinoco_private
*priv
= netdev_priv(dev
);
440 struct net_device_stats
*stats
= &priv
->stats
;
442 if (ctx
->state
!= EZUSB_CTX_COMPLETE
)
447 netif_wake_queue(dev
);
449 ezusb_complete_all(&ctx
->done
);
450 ezusb_request_context_put(ctx
);
454 spin_unlock_irqrestore(&upriv
->req_lock
, flags
);
456 /* This is normal, as all request contexts get flushed
457 * when the device is disconnected */
458 err("Called, CTLX not terminating, but device gone");
459 ezusb_complete_all(&ctx
->done
);
460 ezusb_request_context_put(ctx
);
464 err("Called, CTLX not in terminating state.");
465 /* Things are really bad if this happens. Just leak
466 * the CTLX because it may still be linked to the
467 * queue or the OUT urb may still be active.
468 * Just leaking at least prevents an Oops or Panic.
475 * ezusb_req_queue_run:
477 * Note: Only one active CTX at any one time, because there's no
478 * other (reliable) way to match the response URB to the correct
481 static void ezusb_req_queue_run(struct ezusb_priv
*upriv
)
484 struct request_context
*ctx
;
487 spin_lock_irqsave(&upriv
->req_lock
, flags
);
489 if (!list_empty(&upriv
->req_active
))
492 if (list_empty(&upriv
->req_pending
))
496 list_entry(upriv
->req_pending
.next
, struct request_context
,
499 if (!ctx
->upriv
->udev
)
502 /* We need to split this off to avoid a race condition */
503 list_move_tail(&ctx
->list
, &upriv
->req_active
);
505 if (ctx
->state
== EZUSB_CTX_QUEUED
) {
506 atomic_inc(&ctx
->refcount
);
507 result
= usb_submit_urb(ctx
->outurb
, GFP_ATOMIC
);
509 ctx
->state
= EZUSB_CTX_REQSUBMIT_FAIL
;
511 spin_unlock_irqrestore(&upriv
->req_lock
, flags
);
513 err("Fatal, failed to submit command urb."
514 " error=%d\n", result
);
516 ezusb_ctx_complete(ctx
);
517 ezusb_request_context_put(ctx
);
521 ctx
->state
= EZUSB_CTX_REQ_SUBMITTED
;
522 ezusb_mod_timer(ctx
->upriv
, &ctx
->timer
,
523 jiffies
+ DEF_TIMEOUT
);
527 spin_unlock_irqrestore(&upriv
->req_lock
, flags
);
533 static void ezusb_req_enqueue_run(struct ezusb_priv
*upriv
,
534 struct request_context
*ctx
)
538 spin_lock_irqsave(&upriv
->req_lock
, flags
);
540 if (!ctx
->upriv
->udev
) {
541 spin_unlock_irqrestore(&upriv
->req_lock
, flags
);
544 atomic_inc(&ctx
->refcount
);
545 list_add_tail(&ctx
->list
, &upriv
->req_pending
);
546 spin_unlock_irqrestore(&upriv
->req_lock
, flags
);
548 ctx
->state
= EZUSB_CTX_QUEUED
;
549 ezusb_req_queue_run(upriv
);
555 static void ezusb_request_out_callback(struct urb
*urb
)
559 struct request_context
*ctx
= urb
->context
;
560 struct ezusb_priv
*upriv
= ctx
->upriv
;
562 spin_lock_irqsave(&upriv
->req_lock
, flags
);
564 del_timer(&ctx
->timer
);
567 spin_unlock_irqrestore(&upriv
->req_lock
, flags
);
568 warn("interrupt called with dead ctx");
574 if (urb
->status
== 0) {
576 case EZUSB_CTX_REQ_SUBMITTED
:
578 ctx
->state
= EZUSB_CTX_REQ_COMPLETE
;
579 /* reply URB still pending */
580 ezusb_mod_timer(upriv
, &ctx
->timer
,
581 jiffies
+ DEF_TIMEOUT
);
582 spin_unlock_irqrestore(&upriv
->req_lock
,
587 case EZUSB_CTX_RESP_RECEIVED
:
588 /* IN already received before this OUT-ACK */
589 ctx
->state
= EZUSB_CTX_COMPLETE
;
590 spin_unlock_irqrestore(&upriv
->req_lock
, flags
);
591 ezusb_ctx_complete(ctx
);
595 spin_unlock_irqrestore(&upriv
->req_lock
, flags
);
596 err("Unexpected state(0x%x, %d) in OUT URB",
601 /* If someone cancels the OUT URB then its status
602 * should be either -ECONNRESET or -ENOENT.
605 case EZUSB_CTX_REQ_SUBMITTED
:
606 case EZUSB_CTX_RESP_RECEIVED
:
607 ctx
->state
= EZUSB_CTX_REQ_FAILED
;
610 case EZUSB_CTX_REQ_FAILED
:
611 case EZUSB_CTX_REQ_TIMEOUT
:
612 spin_unlock_irqrestore(&upriv
->req_lock
, flags
);
614 ezusb_ctx_complete(ctx
);
618 spin_unlock_irqrestore(&upriv
->req_lock
, flags
);
620 err("Unexpected state(0x%x, %d) in OUT URB",
626 ezusb_request_context_put(ctx
);
629 static void ezusb_request_in_callback(struct ezusb_priv
*upriv
,
632 struct ezusb_packet
*ans
= urb
->transfer_buffer
;
633 struct request_context
*ctx
= NULL
;
637 /* Find the CTLX on the active queue that requested this URB */
638 spin_lock_irqsave(&upriv
->req_lock
, flags
);
640 struct list_head
*item
;
642 list_for_each(item
, &upriv
->req_active
) {
643 struct request_context
*c
;
646 c
= list_entry(item
, struct request_context
, list
);
648 ezusb_reply_inc(c
->buf
->req_reply_count
);
649 if ((ans
->ans_reply_count
== reply_count
)
650 && (le16_to_cpu(ans
->hermes_rid
) == c
->in_rid
)) {
654 dbg("Skipped (0x%x/0x%x) (%d/%d)",
655 le16_to_cpu(ans
->hermes_rid
),
656 c
->in_rid
, ans
->ans_reply_count
, reply_count
);
661 spin_unlock_irqrestore(&upriv
->req_lock
, flags
);
662 err("%s: got unexpected RID: 0x%04X", __FUNCTION__
,
663 le16_to_cpu(ans
->hermes_rid
));
664 ezusb_req_queue_run(upriv
);
668 /* The data we want is in the in buffer, exchange */
669 urb
->transfer_buffer
= ctx
->buf
;
670 ctx
->buf
= (void *) ans
;
671 ctx
->buf_length
= urb
->actual_length
;
675 case EZUSB_CTX_REQ_SUBMITTED
:
676 /* We have received our response URB before
677 * our request has been acknowledged. Do NOT
678 * destroy our CTX yet, because our OUT URB
681 ctx
->state
= EZUSB_CTX_RESP_RECEIVED
;
682 spin_unlock_irqrestore(&upriv
->req_lock
, flags
);
684 /* Let the machine continue running. */
687 case EZUSB_CTX_REQ_COMPLETE
:
688 /* This is the usual path: our request
689 * has already been acknowledged, and
690 * we have now received the reply.
692 ctx
->state
= EZUSB_CTX_COMPLETE
;
694 /* Stop the intimer */
695 del_timer(&ctx
->timer
);
696 spin_unlock_irqrestore(&upriv
->req_lock
, flags
);
698 /* Call the completion handler */
699 ezusb_ctx_complete(ctx
);
703 spin_unlock_irqrestore(&upriv
->req_lock
, flags
);
705 warn("Matched IN URB, unexpected context state(0x%x)",
707 /* Throw this CTX away and try submitting another */
708 del_timer(&ctx
->timer
);
709 ctx
->outurb
->transfer_flags
|= URB_ASYNC_UNLINK
;
710 usb_unlink_urb(ctx
->outurb
);
711 ezusb_req_queue_run(upriv
);
717 static void ezusb_req_ctx_wait(struct ezusb_priv
*upriv
,
718 struct request_context
*ctx
)
720 switch (ctx
->state
) {
721 case EZUSB_CTX_QUEUED
:
722 case EZUSB_CTX_REQ_SUBMITTED
:
723 case EZUSB_CTX_REQ_COMPLETE
:
724 case EZUSB_CTX_RESP_RECEIVED
:
726 /* If we get called from a timer, timeout timers don't
727 * get the chance to run themselfs. So we make sure
728 * that we don't sleep for ever */
729 int msecs
= DEF_TIMEOUT
* (1000 / HZ
);
730 while (!ctx
->done
.done
&& msecs
--)
733 wait_event_interruptible(ctx
->done
.wait
,
738 /* Done or failed - nothing to wait for */
743 static inline u16
build_crc(struct ezusb_packet
*data
)
746 u8
*bytes
= (u8
*)data
;
749 for (i
= 0; i
< 8; i
++)
750 crc
= (crc
<< 1) + bytes
[i
];
758 * if data == NULL and length > 0 the data is assumed to be already in
759 * the target buffer and only the header is filled.
762 static int ezusb_fill_req(struct ezusb_packet
*req
, u16 length
, u16 rid
,
763 const void *data
, u16 frame_type
, u8 reply_count
)
765 int total_size
= sizeof(*req
) + length
;
767 BUG_ON(total_size
> BULK_BUF_SIZE
);
769 req
->magic
= cpu_to_le16(EZUSB_MAGIC
);
770 req
->req_reply_count
= reply_count
;
771 req
->ans_reply_count
= 0;
772 req
->frame_type
= cpu_to_le16(frame_type
);
773 req
->size
= cpu_to_le16(length
+ 4);
774 req
->crc
= cpu_to_le16(build_crc(req
));
775 req
->hermes_len
= cpu_to_le16(HERMES_BYTES_TO_RECLEN(length
));
776 req
->hermes_rid
= cpu_to_le16(rid
);
778 memcpy(req
->data
, data
, length
);
782 static int ezusb_submit_in_urb(struct ezusb_priv
*upriv
)
785 void *cur_buf
= upriv
->read_urb
->transfer_buffer
;
787 if (upriv
->read_urb
->status
== -EINPROGRESS
) {
788 dbg("urb busy, not resubmiting");
792 usb_fill_bulk_urb(upriv
->read_urb
, upriv
->udev
, upriv
->read_pipe
,
793 cur_buf
, BULK_BUF_SIZE
,
794 ezusb_bulk_in_callback
, upriv
);
795 upriv
->read_urb
->transfer_flags
= 0;
796 retval
= usb_submit_urb(upriv
->read_urb
, GFP_ATOMIC
);
798 err("%s submit failed %d", __FUNCTION__
, retval
);
804 static inline int ezusb_8051_cpucs(struct ezusb_priv
*upriv
, int reset
)
806 u8 res_val
= reset
; /* avoid argument promotion */
809 err("%s: !upriv->udev", __FUNCTION__
);
812 return usb_control_msg(upriv
->udev
,
813 usb_sndctrlpipe(upriv
->udev
, 0),
814 EZUSB_REQUEST_FW_TRANS
,
815 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
|
816 USB_DIR_OUT
, EZUSB_CPUCS_REG
, 0, &res_val
,
817 sizeof(res_val
), DEF_TIMEOUT
);
820 static int ezusb_firmware_download(struct ezusb_priv
*upriv
,
821 struct ez_usb_fw
*fw
)
823 u8 fw_buffer
[FW_BUF_SIZE
];
828 * This byte is 1 and should be replaced with 0. The offset is
829 * 0x10AD in version 0.0.6. The byte in question should follow
830 * the end of the code pointed to by the jump in the beginning
831 * of the firmware. Also, it is read by code located at 0x358.
833 variant_offset
= be16_to_cpup((__be16
*) &fw
->code
[FW_VAR_OFFSET_PTR
]);
834 if (variant_offset
>= fw
->size
) {
835 printk(KERN_ERR PFX
"Invalid firmware variant offset: "
836 "0x%04x\n", variant_offset
);
841 retval
= ezusb_8051_cpucs(upriv
, 1);
844 for (addr
= 0; addr
< fw
->size
; addr
+= FW_BUF_SIZE
) {
845 /* 0x100-0x300 should be left alone, it contains card
846 * specific data, like USB enumeration information */
847 if ((addr
>= FW_HOLE_START
) && (addr
< FW_HOLE_END
))
850 memcpy(fw_buffer
, &fw
->code
[addr
], FW_BUF_SIZE
);
851 if (variant_offset
>= addr
&&
852 variant_offset
< addr
+ FW_BUF_SIZE
) {
853 dbg("Patching card_variant byte at 0x%04X",
855 fw_buffer
[variant_offset
- addr
] = FW_VAR_VALUE
;
857 retval
= usb_control_msg(upriv
->udev
,
858 usb_sndctrlpipe(upriv
->udev
, 0),
859 EZUSB_REQUEST_FW_TRANS
,
860 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
863 fw_buffer
, FW_BUF_SIZE
,
869 retval
= ezusb_8051_cpucs(upriv
, 0);
875 printk(KERN_ERR PFX
"Firmware download failed, error %d\n",
881 static int ezusb_access_ltv(struct ezusb_priv
*upriv
,
882 struct request_context
*ctx
,
883 u16 length
, const void *data
, u16 frame_type
,
884 void *ans_buff
, int ans_size
, u16
*ans_length
)
893 dbg("Device disconnected");
897 if (upriv
->read_urb
->status
!= -EINPROGRESS
) {
898 err("%s: in urb not pending", __FUNCTION__
);
901 /* protect upriv->reply_count, guarantee sequential numbers */
902 spin_lock_bh(&upriv
->reply_count_lock
);
903 req_size
= ezusb_fill_req(ctx
->buf
, length
, ctx
->out_rid
, data
,
904 frame_type
, upriv
->reply_count
);
905 usb_fill_bulk_urb(ctx
->outurb
, upriv
->udev
, upriv
->write_pipe
,
907 ezusb_request_out_callback
, ctx
);
910 upriv
->reply_count
= ezusb_reply_inc(upriv
->reply_count
);
912 ezusb_req_enqueue_run(upriv
, ctx
);
914 spin_unlock_bh(&upriv
->reply_count_lock
);
917 ezusb_req_ctx_wait(upriv
, ctx
);
921 case EZUSB_CTX_COMPLETE
:
922 retval
= ctx
->outurb
->status
;
925 case EZUSB_CTX_QUEUED
:
926 case EZUSB_CTX_REQ_SUBMITTED
:
930 err("%s: Unexpected context state %d", __FUNCTION__
,
933 case EZUSB_CTX_REQ_TIMEOUT
:
934 case EZUSB_CTX_REQ_FAILED
:
935 case EZUSB_CTX_RESP_TIMEOUT
:
936 case EZUSB_CTX_REQSUBMIT_FAIL
:
937 printk(KERN_ERR PFX
"Access failed, resetting (state %d,"
938 " reply_count %d)\n", state
, upriv
->reply_count
);
939 upriv
->reply_count
= 0;
940 if (state
== EZUSB_CTX_REQ_TIMEOUT
941 || state
== EZUSB_CTX_RESP_TIMEOUT
) {
942 printk(KERN_ERR PFX
"ctx timed out\n");
945 printk(KERN_ERR PFX
"ctx failed\n");
952 struct ezusb_packet
*ans
= ctx
->buf
;
955 if (ans
->hermes_len
!= 0)
956 exp_len
= le16_to_cpu(ans
->hermes_len
) * 2 + 12;
960 if (exp_len
!= ctx
->buf_length
) {
961 err("%s: lenght mismatch for RID 0x%04x: "
962 "expected %d, got %d", __FUNCTION__
,
963 ctx
->in_rid
, exp_len
, ctx
->buf_length
);
969 memcpy(ans_buff
, ans
->data
,
970 min_t(int, exp_len
, ans_size
));
972 *ans_length
= le16_to_cpu(ans
->hermes_len
);
975 ezusb_request_context_put(ctx
);
979 static int ezusb_write_ltv(hermes_t
*hw
, int bap
, u16 rid
,
980 u16 length
, const void *data
)
982 struct ezusb_priv
*upriv
= hw
->priv
;
984 struct request_context
*ctx
;
989 length
= HERMES_RECLEN_TO_BYTES(length
);
991 /* On memory mapped devices HERMES_RID_CNFGROUPADDRESSES can be
992 * set to be empty, but the USB bridge doesn't like it */
996 ctx
= ezusb_alloc_ctx(upriv
, rid
, EZUSB_RID_ACK
);
1000 if (rid
== EZUSB_RID_TX
)
1001 frame_type
= EZUSB_FRAME_DATA
;
1003 frame_type
= EZUSB_FRAME_CONTROL
;
1005 return ezusb_access_ltv(upriv
, ctx
, length
, data
, frame_type
,
1009 static int ezusb_read_ltv(hermes_t
*hw
, int bap
, u16 rid
,
1010 unsigned bufsize
, u16
*length
, void *buf
)
1012 struct ezusb_priv
*upriv
= hw
->priv
;
1013 struct request_context
*ctx
;
1015 if ((bufsize
< 0) || (bufsize
% 2))
1018 ctx
= ezusb_alloc_ctx(upriv
, rid
, rid
);
1022 return ezusb_access_ltv(upriv
, ctx
, 0, NULL
, EZUSB_FRAME_CONTROL
,
1023 buf
, bufsize
, length
);
1026 static int ezusb_docmd_wait(hermes_t
*hw
, u16 cmd
, u16 parm0
,
1027 struct hermes_response
*resp
)
1029 struct ezusb_priv
*upriv
= hw
->priv
;
1030 struct request_context
*ctx
;
1038 dbg("0x%04X, parm0 0x%04X", cmd
, parm0
);
1039 ctx
= ezusb_alloc_ctx(upriv
, EZUSB_RID_DOCMD
, EZUSB_RID_ACK
);
1043 return ezusb_access_ltv(upriv
, ctx
, sizeof(data
), &data
,
1044 EZUSB_FRAME_CONTROL
, NULL
, 0, NULL
);
1047 static int ezusb_bap_pread(struct hermes
*hw
, int bap
,
1048 void *buf
, int len
, u16 id
, u16 offset
)
1050 struct ezusb_priv
*upriv
= hw
->priv
;
1051 struct ezusb_packet
*ans
= (void *) upriv
->read_urb
->transfer_buffer
;
1052 int actual_length
= upriv
->read_urb
->actual_length
;
1054 if (id
== EZUSB_RID_RX
) {
1055 if ((sizeof(*ans
) + offset
+ len
) > actual_length
) {
1056 printk(KERN_ERR PFX
"BAP read beyond buffer end "
1060 memcpy(buf
, ans
->data
+ offset
, len
);
1064 if (EZUSB_IS_INFO(id
)) {
1065 /* Include 4 bytes for length/type */
1066 if ((sizeof(*ans
) + offset
+ len
- 4) > actual_length
) {
1067 printk(KERN_ERR PFX
"BAP read beyond buffer end "
1071 memcpy(buf
, ans
->data
+ offset
- 4, len
);
1073 printk(KERN_ERR PFX
"Unexpected fid 0x%04x\n", id
);
1080 static int ezusb_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1082 struct orinoco_private
*priv
=
1083 (struct orinoco_private
*) netdev_priv(dev
);
1084 struct net_device_stats
*stats
= &priv
->stats
;
1085 struct ezusb_priv
*upriv
= priv
->card
;
1089 int len
, data_len
, data_off
;
1091 unsigned long flags
;
1092 struct request_context
*ctx
;
1096 if (!netif_running(dev
)) {
1097 printk(KERN_ERR
"%s: Tx on stopped device!\n",
1102 if (netif_queue_stopped(dev
)) {
1103 printk(KERN_DEBUG
"%s: Tx while transmitter busy!\n",
1108 if (orinoco_lock(priv
, &flags
) != 0) {
1110 "%s: orinoco_xmit() called while hw_unavailable\n",
1115 if (!netif_carrier_ok(dev
) ||
1116 (priv
->iw_mode
== IW_MODE_MONITOR
)) {
1117 /* Oops, the firmware hasn't established a connection,
1118 silently drop the packet (this seems to be the
1119 safest approach). */
1121 orinoco_unlock(priv
, &flags
);
1126 ctx
= ezusb_alloc_ctx(upriv
, EZUSB_RID_TX
, 0);
1131 memset(ctx
->buf
, 0, BULK_BUF_SIZE
);
1132 buf
= ctx
->buf
->data
;
1134 /* Length of the packet body */
1135 /* FIXME: what if the skb is smaller than this? */
1136 len
= max_t(int, skb
->len
- ETH_HLEN
, ETH_ZLEN
- ETH_HLEN
);
1138 eh
= (struct ethhdr
*) skb
->data
;
1140 tx_control
= cpu_to_le16(0);
1141 memcpy(buf
, &tx_control
, sizeof(tx_control
));
1142 buf
+= sizeof(tx_control
);
1143 /* Encapsulate Ethernet-II frames */
1144 if (ntohs(eh
->h_proto
) > ETH_DATA_LEN
) { /* Ethernet-II frame */
1145 struct header_struct
*hdr
= (void *) buf
;
1146 buf
+= sizeof(*hdr
);
1148 data_off
= sizeof(tx_control
) + sizeof(*hdr
);
1149 p
= skb
->data
+ ETH_HLEN
;
1152 memcpy(hdr
->dest
, eh
->h_dest
, ETH_ALEN
);
1153 memcpy(hdr
->src
, eh
->h_source
, ETH_ALEN
);
1154 hdr
->len
= htons(data_len
+ ENCAPS_OVERHEAD
);
1157 memcpy(&hdr
->dsap
, &encaps_hdr
, sizeof(encaps_hdr
));
1159 hdr
->ethertype
= eh
->h_proto
;
1160 } else { /* IEEE 802.3 frame */
1161 data_len
= len
+ ETH_HLEN
;
1162 data_off
= sizeof(tx_control
);
1166 memcpy(buf
, p
, data_len
);
1169 /* Finally, we actually initiate the send */
1170 netif_stop_queue(dev
);
1172 /* The card may behave better if we send evenly sized usb transfers */
1173 tx_size
= ALIGN(buf
- ctx
->buf
->data
, 2);
1175 err
= ezusb_access_ltv(upriv
, ctx
, tx_size
, NULL
,
1176 EZUSB_FRAME_DATA
, NULL
, 0, NULL
);
1179 netif_start_queue(dev
);
1180 if (net_ratelimit())
1181 printk(KERN_ERR
"%s: Error %d transmitting packet\n",
1187 dev
->trans_start
= jiffies
;
1188 stats
->tx_bytes
+= data_off
+ data_len
;
1190 orinoco_unlock(priv
, &flags
);
1196 orinoco_unlock(priv
, &flags
);
1200 static int ezusb_allocate(struct hermes
*hw
, u16 size
, u16
*fid
)
1202 *fid
= EZUSB_RID_TX
;
1207 static int ezusb_hard_reset(struct orinoco_private
*priv
)
1209 struct ezusb_priv
*upriv
= priv
->card
;
1210 int retval
= ezusb_8051_cpucs(upriv
, 1);
1213 err("Failed to reset");
1217 retval
= ezusb_8051_cpucs(upriv
, 0);
1219 err("Failed to unreset");
1223 dbg("sending control message");
1224 retval
= usb_control_msg(upriv
->udev
,
1225 usb_sndctrlpipe(upriv
->udev
, 0),
1226 EZUSB_REQUEST_TRIGER
,
1227 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
|
1228 USB_DIR_OUT
, 0x0, 0x0, NULL
, 0,
1231 err("EZUSB_REQUEST_TRIGER failed retval %d", retval
);
1235 dbg("Sending EZUSB_REQUEST_TRIG_AC");
1236 retval
= usb_control_msg(upriv
->udev
,
1237 usb_sndctrlpipe(upriv
->udev
, 0),
1238 EZUSB_REQUEST_TRIG_AC
,
1239 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
|
1240 USB_DIR_OUT
, 0x00FA, 0x0, NULL
, 0,
1243 err("EZUSB_REQUEST_TRIG_AC failed retval %d", retval
);
1252 static int ezusb_init(hermes_t
*hw
)
1254 struct ezusb_priv
*upriv
= hw
->priv
;
1257 BUG_ON(in_interrupt());
1260 upriv
->reply_count
= 0;
1261 /* Write the MAGIC number on the simulated registers to keep
1262 * orinoco.c happy */
1263 hermes_write_regn(hw
, SWSUPPORT0
, HERMES_MAGIC
);
1264 hermes_write_regn(hw
, RXFID
, EZUSB_RID_RX
);
1266 usb_kill_urb(upriv
->read_urb
);
1267 ezusb_submit_in_urb(upriv
);
1269 retval
= ezusb_write_ltv(hw
, 0, EZUSB_RID_INIT1
,
1270 HERMES_BYTES_TO_RECLEN(2), "\x10\x00");
1272 printk(KERN_ERR PFX
"EZUSB_RID_INIT1 error %d\n", retval
);
1276 retval
= ezusb_docmd_wait(hw
, HERMES_CMD_INIT
, 0, NULL
);
1278 printk(KERN_ERR PFX
"HERMES_CMD_INIT error %d\n", retval
);
1285 static void ezusb_bulk_in_callback(struct urb
*urb
)
1287 struct ezusb_priv
*upriv
= (struct ezusb_priv
*) urb
->context
;
1288 struct ezusb_packet
*ans
= urb
->transfer_buffer
;
1292 if (upriv
->udev
== NULL
) {
1293 dbg("disconnected");
1297 if (urb
->status
== -ETIMEDOUT
) {
1298 /* When a device gets unplugged we get this every time
1299 * we resubmit, flooding the logs. Since we don't use
1300 * USB timeouts, it shouldn't happen any other time*/
1301 warn("%s: urb timed out, not resubmiting", __FUNCTION__
);
1304 if (urb
->status
== -ECONNABORTED
) {
1305 warn("%s: connection abort, resubmiting urb",
1309 if ((urb
->status
== -EILSEQ
)
1310 || (urb
->status
== -ENOENT
)
1311 || (urb
->status
== -ECONNRESET
)) {
1312 dbg("status %d, not resubmiting", urb
->status
);
1316 dbg("status: %d length: %d",
1317 urb
->status
, urb
->actual_length
);
1318 if (urb
->actual_length
< sizeof(*ans
)) {
1319 err("%s: short read, ignoring", __FUNCTION__
);
1322 crc
= build_crc(ans
);
1323 if (le16_to_cpu(ans
->crc
) != crc
) {
1324 err("CRC error, ignoring packet");
1328 hermes_rid
= le16_to_cpu(ans
->hermes_rid
);
1329 if ((hermes_rid
!= EZUSB_RID_RX
) && !EZUSB_IS_INFO(hermes_rid
)) {
1330 ezusb_request_in_callback(upriv
, urb
);
1331 } else if (upriv
->dev
) {
1332 struct net_device
*dev
= upriv
->dev
;
1333 struct orinoco_private
*priv
= netdev_priv(dev
);
1334 hermes_t
*hw
= &priv
->hw
;
1336 if (hermes_rid
== EZUSB_RID_RX
) {
1337 __orinoco_ev_rx(dev
, hw
);
1339 hermes_write_regn(hw
, INFOFID
,
1340 le16_to_cpu(ans
->hermes_rid
));
1341 __orinoco_ev_info(dev
, hw
);
1347 ezusb_submit_in_urb(upriv
);
1350 static inline void ezusb_delete(struct ezusb_priv
*upriv
)
1352 struct net_device
*dev
;
1353 struct list_head
*item
;
1354 struct list_head
*tmp_item
;
1355 unsigned long flags
;
1357 BUG_ON(in_interrupt());
1363 upriv
->udev
= NULL
; /* No timer will be rearmed from here */
1365 usb_kill_urb(upriv
->read_urb
);
1368 spin_lock_irqsave(&upriv
->req_lock
, flags
);
1369 list_for_each_safe(item
, tmp_item
, &upriv
->req_active
) {
1370 struct request_context
*ctx
;
1372 ctx
= list_entry(item
, struct request_context
, list
);
1373 atomic_inc(&ctx
->refcount
);
1375 ctx
->outurb
->transfer_flags
|= URB_ASYNC_UNLINK
;
1376 if (usb_unlink_urb(ctx
->outurb
) == -EINPROGRESS
) {
1377 spin_unlock_irqrestore(&upriv
->req_lock
, flags
);
1378 wait_for_completion(&ctx
->done
);
1380 spin_unlock_irqrestore(&upriv
->req_lock
, flags
);
1382 del_timer_sync(&ctx
->timer
);
1383 /* FIXME: there is an slight chance for the irq handler to
1385 if (!list_empty(&ctx
->list
))
1386 ezusb_ctx_complete(ctx
);
1388 ezusb_request_context_put(ctx
);
1391 spin_unlock_irqrestore(&upriv
->req_lock
, flags
);
1393 list_for_each_safe(item
, tmp_item
, &upriv
->req_pending
)
1394 ezusb_ctx_complete(list_entry(item
,
1395 struct request_context
, list
));
1397 if (upriv
->read_urb
->status
== -EINPROGRESS
) {
1398 printk(KERN_ERR PFX
"Some URB in progress\n");
1402 kfree(upriv
->read_urb
->transfer_buffer
);
1403 if (upriv
->bap_buf
!= NULL
)
1404 kfree(upriv
->bap_buf
);
1405 if (upriv
->read_urb
!= NULL
)
1406 usb_free_urb(upriv
->read_urb
);
1408 unregister_netdev(upriv
->dev
);
1409 free_orinocodev(upriv
->dev
);
1413 static const struct hermes_ops ezusb_ops
= {
1415 .docmd_wait
= ezusb_docmd_wait
,
1416 .allocate
= ezusb_allocate
,
1417 .read_ltv
= ezusb_read_ltv
,
1418 .write_ltv
= ezusb_write_ltv
,
1419 .bap_pread
= ezusb_bap_pread
1422 static int ezusb_probe(struct usb_interface
*interface
,
1423 const struct usb_device_id
*id
)
1425 struct usb_device
*udev
= interface_to_usbdev(interface
);
1426 struct orinoco_private
*priv
;
1427 struct net_device
*dev
;
1429 struct ezusb_priv
*upriv
= NULL
;
1430 struct usb_interface_descriptor
*iface_desc
;
1431 struct usb_endpoint_descriptor
*ep
;
1432 const struct firmware
*fw_entry
;
1436 dev
= alloc_orinocodev(sizeof(*upriv
), ezusb_hard_reset
);
1438 err("Couldn't allocate dev");
1442 priv
= netdev_priv(dev
);
1447 init_MUTEX(&upriv
->sem
);
1448 spin_lock_init(&upriv
->reply_count_lock
);
1450 spin_lock_init(&upriv
->req_lock
);
1451 INIT_LIST_HEAD(&upriv
->req_pending
);
1452 INIT_LIST_HEAD(&upriv
->req_active
);
1456 hw
->iobase
= (void __force __iomem
*) &upriv
->hermes_reg_fake
;
1457 hw
->reg_spacing
= HERMES_16BIT_REGSPACING
;
1459 hw
->ops
= &ezusb_ops
;
1460 dev
->hard_start_xmit
= ezusb_xmit
;
1462 priv
->irq_no_disable
= 1;
1464 /* set up the endpoint information */
1465 /* check out the endpoints */
1467 iface_desc
= &interface
->altsetting
[0].desc
;
1468 for (i
= 0; i
< iface_desc
->bNumEndpoints
; ++i
) {
1469 ep
= &interface
->altsetting
[0].endpoint
[i
].desc
;
1471 if (((ep
->bEndpointAddress
& USB_ENDPOINT_DIR_MASK
)
1473 ((ep
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
)
1474 == USB_ENDPOINT_XFER_BULK
)) {
1475 /* we found a bulk in endpoint */
1476 if (upriv
->read_urb
!= NULL
) {
1477 warn("Found a second bulk in ep, ignored");
1481 upriv
->read_urb
= usb_alloc_urb(0, GFP_KERNEL
);
1482 if (!upriv
->read_urb
) {
1483 err("No free urbs available");
1486 if (le16_to_cpu(ep
->wMaxPacketSize
) != 64)
1487 warn("bulk in: wMaxPacketSize!= 64");
1488 if (ep
->bEndpointAddress
!= (2 | USB_DIR_IN
))
1489 warn("bulk in: bEndpointAddress: %d",
1490 ep
->bEndpointAddress
);
1491 upriv
->read_pipe
= usb_rcvbulkpipe(udev
,
1494 upriv
->read_urb
->transfer_buffer
=
1495 kmalloc(BULK_BUF_SIZE
, GFP_KERNEL
);
1496 if (!upriv
->read_urb
->transfer_buffer
) {
1497 err("Couldn't allocate IN buffer");
1502 if (((ep
->bEndpointAddress
& USB_ENDPOINT_DIR_MASK
)
1504 ((ep
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
)
1505 == USB_ENDPOINT_XFER_BULK
)) {
1506 /* we found a bulk out endpoint */
1507 if (upriv
->bap_buf
!= NULL
) {
1508 warn("Found a second bulk out ep, ignored");
1512 if (le16_to_cpu(ep
->wMaxPacketSize
) != 64)
1513 warn("bulk out: wMaxPacketSize != 64");
1514 if (ep
->bEndpointAddress
!= 2)
1515 warn("bulk out: bEndpointAddress: %d",
1516 ep
->bEndpointAddress
);
1517 upriv
->write_pipe
= usb_sndbulkpipe(udev
,
1520 upriv
->bap_buf
= kmalloc(BULK_BUF_SIZE
, GFP_KERNEL
);
1521 if (!upriv
->bap_buf
) {
1522 err("Couldn't allocate bulk_out_buffer");
1527 if (!upriv
->bap_buf
|| !upriv
->read_urb
) {
1528 err("Didn't find the required bulk endpoints");
1532 if (request_firmware(&fw_entry
, "orinoco_ezusb_fw",
1533 &interface
->dev
) == 0) {
1534 firmware
.size
= fw_entry
->size
;
1535 firmware
.code
= fw_entry
->data
;
1537 if (firmware
.size
&& firmware
.code
) {
1538 ezusb_firmware_download(upriv
, &firmware
);
1540 err("No firmware to download");
1544 if (ezusb_hard_reset(priv
) < 0) {
1545 err("Cannot reset the device");
1549 /* If the firmware is already downloaded orinoco.c will call
1550 * ezusb_init but if the firmware is not already there, that will make
1551 * the kernel very unstable, so we try initializing here and quit in
1553 if (ezusb_init(hw
) < 0) {
1554 err("Couldn't initialize the device");
1555 err("Firmware may not be downloaded or may be wrong.");
1559 SET_NETDEV_DEV(dev
, &interface
->dev
);
1561 if (register_netdev(dev
) != 0) {
1563 err("%s: register_netdev() failed", __FUNCTION__
);
1569 ezusb_delete(upriv
);
1571 /* upriv->dev was 0, so ezusb_delete() didn't free it */
1572 free_orinocodev(dev
);
1578 firmware
.code
= NULL
;
1580 release_firmware(fw_entry
);
1582 usb_set_intfdata(interface
, upriv
);
1587 static void ezusb_disconnect(struct usb_interface
*intf
)
1589 struct ezusb_priv
*upriv
= usb_get_intfdata(intf
);
1590 usb_set_intfdata(intf
, NULL
);
1591 ezusb_delete(upriv
);
1592 printk(KERN_INFO PFX
"Disconnected\n");
1596 /* usb specific object needed to register this driver with the usb subsystem */
1597 static struct usb_driver orinoco_driver
= {
1598 .name
= DRIVER_NAME
,
1599 .probe
= ezusb_probe
,
1600 .disconnect
= ezusb_disconnect
,
1601 .id_table
= ezusb_table
,
1604 /* Can't be declared "const" or the whole __initdata section will
1606 static char version
[] __initdata
= DRIVER_NAME
" " DRIVER_VERSION
1607 " (Manuel Estrada Sainz)";
1609 static int __init
ezusb_module_init(void)
1613 printk(KERN_DEBUG
"%s\n", version
);
1615 /* register this driver with the USB subsystem */
1616 err
= usb_register(&orinoco_driver
);
1618 printk(KERN_ERR PFX
"usb_register failed, error %d\n",
1626 static void __exit
ezusb_module_exit(void)
1628 /* deregister this driver with the USB subsystem */
1629 usb_deregister(&orinoco_driver
);
1633 module_init(ezusb_module_init
);
1634 module_exit(ezusb_module_exit
);
1636 MODULE_AUTHOR("Manuel Estrada Sainz");
1638 ("Driver for Orinoco wireless LAN cards using EZUSB bridge");
1639 MODULE_LICENSE("Dual MPL/GPL");