3 * Linux device driver for USB based Prism54
5 * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
7 * Based on the islsm (softmac prism54) driver, which is:
8 * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/init.h>
16 #include <linux/usb.h>
17 #include <linux/pci.h>
18 #include <linux/firmware.h>
19 #include <linux/etherdevice.h>
20 #include <linux/delay.h>
21 #include <linux/crc32.h>
22 #include <net/mac80211.h>
27 MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>");
28 MODULE_DESCRIPTION("Prism54 USB wireless driver");
29 MODULE_LICENSE("GPL");
30 MODULE_ALIAS("prism54usb");
32 static struct usb_device_id p54u_table
[] __devinitdata
= {
33 /* Version 1 devices (pci chip + net2280) */
34 {USB_DEVICE(0x0506, 0x0a11)}, /* 3COM 3CRWE254G72 */
35 {USB_DEVICE(0x0707, 0xee06)}, /* SMC 2862W-G */
36 {USB_DEVICE(0x083a, 0x4501)}, /* Accton 802.11g WN4501 USB */
37 {USB_DEVICE(0x083a, 0x4502)}, /* Siemens Gigaset USB Adapter */
38 {USB_DEVICE(0x083a, 0x5501)}, /* Phillips CPWUA054 */
39 {USB_DEVICE(0x0846, 0x4200)}, /* Netgear WG121 */
40 {USB_DEVICE(0x0846, 0x4210)}, /* Netgear WG121 the second ? */
41 {USB_DEVICE(0x0846, 0x4220)}, /* Netgear WG111 */
42 {USB_DEVICE(0x0cde, 0x0006)}, /* Medion 40900, Roper Europe */
43 {USB_DEVICE(0x124a, 0x4023)}, /* Shuttle PN15, Airvast WM168g, IOGear GWU513 */
44 {USB_DEVICE(0x1915, 0x2234)}, /* Linksys WUSB54G OEM */
45 {USB_DEVICE(0x1915, 0x2235)}, /* Linksys WUSB54G Portable OEM */
46 {USB_DEVICE(0x2001, 0x3701)}, /* DLink DWL-G120 Spinnaker */
47 {USB_DEVICE(0x2001, 0x3703)}, /* DLink DWL-G122 */
48 {USB_DEVICE(0x5041, 0x2234)}, /* Linksys WUSB54G */
49 {USB_DEVICE(0x5041, 0x2235)}, /* Linksys WUSB54G Portable */
51 /* Version 2 devices (3887) */
52 {USB_DEVICE(0x050d, 0x7050)}, /* Belkin F5D7050 ver 1000 */
53 {USB_DEVICE(0x0572, 0x2000)}, /* Cohiba Proto board */
54 {USB_DEVICE(0x0572, 0x2002)}, /* Cohiba Proto board */
55 {USB_DEVICE(0x0707, 0xee13)}, /* SMC 2862W-G version 2 */
56 {USB_DEVICE(0x083a, 0x4521)}, /* Siemens Gigaset USB Adapter 54 version 2 */
57 {USB_DEVICE(0x0846, 0x4240)}, /* Netgear WG111 (v2) */
58 {USB_DEVICE(0x0915, 0x2000)}, /* Cohiba Proto board */
59 {USB_DEVICE(0x0915, 0x2002)}, /* Cohiba Proto board */
60 {USB_DEVICE(0x0baf, 0x0118)}, /* U.S. Robotics U5 802.11g Adapter*/
61 {USB_DEVICE(0x0bf8, 0x1009)}, /* FUJITSU E-5400 USB D1700*/
62 {USB_DEVICE(0x0cde, 0x0006)}, /* Medion MD40900 */
63 {USB_DEVICE(0x0cde, 0x0008)}, /* Sagem XG703A */
64 {USB_DEVICE(0x0d8e, 0x3762)}, /* DLink DWL-G120 Cohiba */
65 {USB_DEVICE(0x09aa, 0x1000)}, /* Spinnaker Proto board */
66 {USB_DEVICE(0x13b1, 0x000a)}, /* Linksys WUSB54G ver 2 */
67 {USB_DEVICE(0x13B1, 0x000C)}, /* Linksys WUSB54AG */
68 {USB_DEVICE(0x1435, 0x0427)}, /* Inventel UR054G */
69 {USB_DEVICE(0x2001, 0x3704)}, /* DLink DWL-G122 rev A2 */
70 {USB_DEVICE(0x413c, 0x8102)}, /* Spinnaker DUT */
71 {USB_DEVICE(0x413c, 0x8104)}, /* Cohiba Proto board */
75 MODULE_DEVICE_TABLE(usb
, p54u_table
);
77 static void p54u_rx_cb(struct urb
*urb
)
79 struct sk_buff
*skb
= (struct sk_buff
*) urb
->context
;
80 struct p54u_rx_info
*info
= (struct p54u_rx_info
*)skb
->cb
;
81 struct ieee80211_hw
*dev
= info
->dev
;
82 struct p54u_priv
*priv
= dev
->priv
;
84 if (unlikely(urb
->status
)) {
90 skb_unlink(skb
, &priv
->rx_queue
);
91 skb_put(skb
, urb
->actual_length
);
93 skb_pull(skb
, sizeof(struct net2280_tx_hdr
));
95 if (p54_rx(dev
, skb
)) {
96 skb
= dev_alloc_skb(MAX_RX_SIZE
);
99 /* TODO check rx queue length and refill *somewhere* */
103 info
= (struct p54u_rx_info
*) skb
->cb
;
106 urb
->transfer_buffer
= skb_tail_pointer(skb
);
108 skb_queue_tail(&priv
->rx_queue
, skb
);
111 skb_queue_tail(&priv
->rx_queue
, skb
);
114 usb_submit_urb(urb
, GFP_ATOMIC
);
117 static void p54u_tx_cb(struct urb
*urb
)
122 static void p54u_tx_free_cb(struct urb
*urb
)
124 kfree(urb
->transfer_buffer
);
128 static int p54u_init_urbs(struct ieee80211_hw
*dev
)
130 struct p54u_priv
*priv
= dev
->priv
;
133 struct p54u_rx_info
*info
;
135 while (skb_queue_len(&priv
->rx_queue
) < 32) {
136 skb
= __dev_alloc_skb(MAX_RX_SIZE
, GFP_KERNEL
);
139 entry
= usb_alloc_urb(0, GFP_KERNEL
);
144 usb_fill_bulk_urb(entry
, priv
->udev
, usb_rcvbulkpipe(priv
->udev
, P54U_PIPE_DATA
), skb_tail_pointer(skb
), MAX_RX_SIZE
, p54u_rx_cb
, skb
);
145 info
= (struct p54u_rx_info
*) skb
->cb
;
148 skb_queue_tail(&priv
->rx_queue
, skb
);
149 usb_submit_urb(entry
, GFP_KERNEL
);
155 static void p54u_free_urbs(struct ieee80211_hw
*dev
)
157 struct p54u_priv
*priv
= dev
->priv
;
158 struct p54u_rx_info
*info
;
161 while ((skb
= skb_dequeue(&priv
->rx_queue
))) {
162 info
= (struct p54u_rx_info
*) skb
->cb
;
166 usb_kill_urb(info
->urb
);
171 static void p54u_tx_3887(struct ieee80211_hw
*dev
, struct p54_control_hdr
*data
,
172 size_t len
, int free_on_tx
)
174 struct p54u_priv
*priv
= dev
->priv
;
175 struct urb
*addr_urb
, *data_urb
;
177 addr_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
181 data_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
183 usb_free_urb(addr_urb
);
187 usb_fill_bulk_urb(addr_urb
, priv
->udev
,
188 usb_sndbulkpipe(priv
->udev
, P54U_PIPE_DATA
), &data
->req_id
,
189 sizeof(data
->req_id
), p54u_tx_cb
, dev
);
190 usb_fill_bulk_urb(data_urb
, priv
->udev
,
191 usb_sndbulkpipe(priv
->udev
, P54U_PIPE_DATA
), data
, len
,
192 free_on_tx
? p54u_tx_free_cb
: p54u_tx_cb
, dev
);
194 usb_submit_urb(addr_urb
, GFP_ATOMIC
);
195 usb_submit_urb(data_urb
, GFP_ATOMIC
);
198 static void p54u_tx_net2280(struct ieee80211_hw
*dev
, struct p54_control_hdr
*data
,
199 size_t len
, int free_on_tx
)
201 struct p54u_priv
*priv
= dev
->priv
;
202 struct urb
*int_urb
, *data_urb
;
203 struct net2280_tx_hdr
*hdr
;
204 struct net2280_reg_write
*reg
;
206 reg
= kmalloc(sizeof(*reg
), GFP_ATOMIC
);
210 int_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
216 data_urb
= usb_alloc_urb(0, GFP_ATOMIC
);
219 usb_free_urb(int_urb
);
223 reg
->port
= cpu_to_le16(NET2280_DEV_U32
);
224 reg
->addr
= cpu_to_le32(P54U_DEV_BASE
);
225 reg
->val
= cpu_to_le32(ISL38XX_DEV_INT_DATA
);
227 len
+= sizeof(*data
);
228 hdr
= (void *)data
- sizeof(*hdr
);
229 memset(hdr
, 0, sizeof(*hdr
));
230 hdr
->device_addr
= data
->req_id
;
231 hdr
->len
= cpu_to_le16(len
);
233 usb_fill_bulk_urb(int_urb
, priv
->udev
,
234 usb_sndbulkpipe(priv
->udev
, P54U_PIPE_DEV
), reg
, sizeof(*reg
),
235 p54u_tx_free_cb
, dev
);
236 usb_submit_urb(int_urb
, GFP_ATOMIC
);
238 usb_fill_bulk_urb(data_urb
, priv
->udev
,
239 usb_sndbulkpipe(priv
->udev
, P54U_PIPE_DATA
), hdr
, len
+ sizeof(*hdr
),
240 free_on_tx
? p54u_tx_free_cb
: p54u_tx_cb
, dev
);
241 usb_submit_urb(data_urb
, GFP_ATOMIC
);
244 static int p54u_write(struct p54u_priv
*priv
,
245 struct net2280_reg_write
*buf
,
246 enum net2280_op_type type
,
247 __le32 addr
, __le32 val
)
253 ep
= usb_sndbulkpipe(priv
->udev
, P54U_PIPE_DEV
);
255 ep
= usb_sndbulkpipe(priv
->udev
, P54U_PIPE_BRG
);
257 buf
->port
= cpu_to_le16(type
);
261 return usb_bulk_msg(priv
->udev
, ep
, buf
, sizeof(*buf
), &alen
, 1000);
264 static int p54u_read(struct p54u_priv
*priv
, void *buf
,
265 enum net2280_op_type type
,
266 __le32 addr
, __le32
*val
)
268 struct net2280_reg_read
*read
= buf
;
278 read
->port
= cpu_to_le16(type
);
281 err
= usb_bulk_msg(priv
->udev
, usb_sndbulkpipe(priv
->udev
, ep
),
282 read
, sizeof(*read
), &alen
, 1000);
286 err
= usb_bulk_msg(priv
->udev
, usb_rcvbulkpipe(priv
->udev
, ep
),
287 reg
, sizeof(*reg
), &alen
, 1000);
295 static int p54u_bulk_msg(struct p54u_priv
*priv
, unsigned int ep
,
296 void *data
, size_t len
)
299 return usb_bulk_msg(priv
->udev
, usb_sndbulkpipe(priv
->udev
, ep
),
300 data
, len
, &alen
, 2000);
303 static int p54u_read_eeprom(struct ieee80211_hw
*dev
)
305 struct p54u_priv
*priv
= dev
->priv
;
307 struct p54_control_hdr
*hdr
;
309 size_t offset
= priv
->hw_type
? 0x10 : 0x20;
311 buf
= kmalloc(0x2020, GFP_KERNEL
);
313 printk(KERN_ERR
"prism54usb: cannot allocate memory for "
314 "eeprom readback!\n");
319 *((u32
*) buf
) = priv
->common
.rx_start
;
320 err
= p54u_bulk_msg(priv
, P54U_PIPE_DATA
, buf
, sizeof(u32
));
322 printk(KERN_ERR
"prism54usb: addr send failed\n");
326 struct net2280_reg_write
*reg
= buf
;
327 reg
->port
= cpu_to_le16(NET2280_DEV_U32
);
328 reg
->addr
= cpu_to_le32(P54U_DEV_BASE
);
329 reg
->val
= cpu_to_le32(ISL38XX_DEV_INT_DATA
);
330 err
= p54u_bulk_msg(priv
, P54U_PIPE_DEV
, buf
, sizeof(*reg
));
332 printk(KERN_ERR
"prism54usb: dev_int send failed\n");
337 hdr
= buf
+ priv
->common
.tx_hdr_len
;
338 p54_fill_eeprom_readback(hdr
);
339 hdr
->req_id
= cpu_to_le32(priv
->common
.rx_start
);
340 if (priv
->common
.tx_hdr_len
) {
341 struct net2280_tx_hdr
*tx_hdr
= buf
;
342 tx_hdr
->device_addr
= hdr
->req_id
;
343 tx_hdr
->len
= cpu_to_le16(EEPROM_READBACK_LEN
);
346 /* we can just pretend to send 0x2000 bytes of nothing in the headers */
347 err
= p54u_bulk_msg(priv
, P54U_PIPE_DATA
, buf
,
348 EEPROM_READBACK_LEN
+ priv
->common
.tx_hdr_len
);
350 printk(KERN_ERR
"prism54usb: eeprom req send failed\n");
354 err
= usb_bulk_msg(priv
->udev
,
355 usb_rcvbulkpipe(priv
->udev
, P54U_PIPE_DATA
),
356 buf
, 0x2020, &alen
, 1000);
357 if (!err
&& alen
> offset
) {
358 p54_parse_eeprom(dev
, (u8
*)buf
+ offset
, alen
- offset
);
360 printk(KERN_ERR
"prism54usb: eeprom read failed!\n");
370 static int p54u_upload_firmware_3887(struct ieee80211_hw
*dev
)
372 static char start_string
[] = "~~~~<\r";
373 struct p54u_priv
*priv
= dev
->priv
;
374 const struct firmware
*fw_entry
= NULL
;
377 u8
*buf
, *tmp
, *data
;
378 unsigned int left
, remains
, block_size
;
379 struct x2_header
*hdr
;
380 unsigned long timeout
;
382 tmp
= buf
= kmalloc(P54U_FW_BLOCK
, GFP_KERNEL
);
384 printk(KERN_ERR
"p54usb: cannot allocate firmware upload buffer!\n");
389 memcpy(buf
, start_string
, 4);
390 err
= p54u_bulk_msg(priv
, P54U_PIPE_DATA
, buf
, 4);
392 printk(KERN_ERR
"p54usb: reset failed! (%d)\n", err
);
396 err
= request_firmware(&fw_entry
, "isl3887usb_bare", &priv
->udev
->dev
);
398 printk(KERN_ERR
"p54usb: cannot find firmware (isl3887usb_bare)!\n");
399 goto err_req_fw_failed
;
402 p54_parse_firmware(dev
, fw_entry
);
404 left
= block_size
= min((size_t)P54U_FW_BLOCK
, fw_entry
->size
);
405 strcpy(buf
, start_string
);
406 left
-= strlen(start_string
);
407 tmp
+= strlen(start_string
);
409 data
= fw_entry
->data
;
410 remains
= fw_entry
->size
;
412 hdr
= (struct x2_header
*)(buf
+ strlen(start_string
));
413 memcpy(hdr
->signature
, X2_SIGNATURE
, X2_SIGNATURE_SIZE
);
414 hdr
->fw_load_addr
= cpu_to_le32(ISL38XX_DEV_FIRMWARE_ADDR
);
415 hdr
->fw_length
= cpu_to_le32(fw_entry
->size
);
416 hdr
->crc
= cpu_to_le32(~crc32_le(~0, (void *)&hdr
->fw_load_addr
,
418 left
-= sizeof(*hdr
);
446 err
= p54u_bulk_msg(priv
, P54U_PIPE_DATA
, buf
, block_size
);
448 printk(KERN_ERR
"prism54usb: firmware upload failed!\n");
449 goto err_upload_failed
;
453 left
= block_size
= min((unsigned int)P54U_FW_BLOCK
, remains
);
456 *((__le32
*)buf
) = cpu_to_le32(~crc32_le(~0, fw_entry
->data
, fw_entry
->size
));
457 err
= p54u_bulk_msg(priv
, P54U_PIPE_DATA
, buf
, sizeof(u32
));
459 printk(KERN_ERR
"prism54usb: firmware upload failed!\n");
460 goto err_upload_failed
;
463 timeout
= jiffies
+ msecs_to_jiffies(1000);
464 while (!(err
= usb_bulk_msg(priv
->udev
,
465 usb_rcvbulkpipe(priv
->udev
, P54U_PIPE_DATA
), buf
, 128, &alen
, 1000))) {
466 if (alen
> 2 && !memcmp(buf
, "OK", 2))
469 if (alen
> 5 && !memcmp(buf
, "ERROR", 5)) {
470 printk(KERN_INFO
"prism54usb: firmware upload failed!\n");
475 if (time_after(jiffies
, timeout
)) {
476 printk(KERN_ERR
"prism54usb: firmware boot timed out!\n");
482 goto err_upload_failed
;
486 err
= p54u_bulk_msg(priv
, P54U_PIPE_DATA
, buf
, 2);
488 printk(KERN_ERR
"prism54usb: firmware boot failed!\n");
489 goto err_upload_failed
;
492 timeout
= jiffies
+ msecs_to_jiffies(1000);
493 while (!(err
= usb_bulk_msg(priv
->udev
,
494 usb_rcvbulkpipe(priv
->udev
, P54U_PIPE_DATA
), buf
, 128, &alen
, 1000))) {
495 if (alen
> 0 && buf
[0] == 'g')
498 if (time_after(jiffies
, timeout
)) {
504 goto err_upload_failed
;
507 release_firmware(fw_entry
);
515 static int p54u_upload_firmware_net2280(struct ieee80211_hw
*dev
)
517 struct p54u_priv
*priv
= dev
->priv
;
518 const struct firmware
*fw_entry
= NULL
;
519 const struct p54p_csr
*devreg
= (const struct p54p_csr
*) P54U_DEV_BASE
;
523 unsigned int remains
, offset
;
526 buf
= kmalloc(512, GFP_KERNEL
);
528 printk(KERN_ERR
"p54usb: firmware buffer alloc failed!\n");
532 err
= request_firmware(&fw_entry
, "isl3890usb", &priv
->udev
->dev
);
534 printk(KERN_ERR
"p54usb: cannot find firmware (isl3890usb)!\n");
539 p54_parse_firmware(dev
, fw_entry
);
541 #define P54U_WRITE(type, addr, data) \
543 err = p54u_write(priv, buf, type,\
544 cpu_to_le32((u32)(unsigned long)addr), data);\
549 #define P54U_READ(type, addr) \
551 err = p54u_read(priv, buf, type,\
552 cpu_to_le32((u32)(unsigned long)addr), ®);\
557 /* power down net2280 bridge */
558 P54U_READ(NET2280_BRG_U32
, NET2280_GPIOCTL
);
559 reg
|= cpu_to_le32(P54U_BRG_POWER_DOWN
);
560 reg
&= cpu_to_le32(~P54U_BRG_POWER_UP
);
561 P54U_WRITE(NET2280_BRG_U32
, NET2280_GPIOCTL
, reg
);
565 /* power up bridge */
566 reg
|= cpu_to_le32(P54U_BRG_POWER_UP
);
567 reg
&= cpu_to_le32(~P54U_BRG_POWER_DOWN
);
568 P54U_WRITE(NET2280_BRG_U32
, NET2280_GPIOCTL
, reg
);
572 P54U_WRITE(NET2280_BRG_U32
, NET2280_DEVINIT
,
573 cpu_to_le32(NET2280_CLK_30Mhz
|
575 NET2280_PCI_SOFT_RESET
));
579 P54U_WRITE(NET2280_BRG_CFG_U16
, PCI_COMMAND
,
580 cpu_to_le32(PCI_COMMAND_MEMORY
|
581 PCI_COMMAND_MASTER
));
583 P54U_WRITE(NET2280_BRG_CFG_U32
, PCI_BASE_ADDRESS_0
,
584 cpu_to_le32(NET2280_BASE
));
586 P54U_READ(NET2280_BRG_CFG_U16
, PCI_STATUS
);
587 reg
|= cpu_to_le32(PCI_STATUS_REC_MASTER_ABORT
);
588 P54U_WRITE(NET2280_BRG_CFG_U16
, PCI_STATUS
, reg
);
590 // TODO: we really need this?
591 P54U_READ(NET2280_BRG_U32
, NET2280_RELNUM
);
593 P54U_WRITE(NET2280_BRG_U32
, NET2280_EPA_RSP
,
594 cpu_to_le32(NET2280_CLEAR_NAK_OUT_PACKETS_MODE
));
595 P54U_WRITE(NET2280_BRG_U32
, NET2280_EPC_RSP
,
596 cpu_to_le32(NET2280_CLEAR_NAK_OUT_PACKETS_MODE
));
598 P54U_WRITE(NET2280_BRG_CFG_U32
, PCI_BASE_ADDRESS_2
,
599 cpu_to_le32(NET2280_BASE2
));
601 /* finally done setting up the bridge */
603 P54U_WRITE(NET2280_DEV_CFG_U16
, 0x10000 | PCI_COMMAND
,
604 cpu_to_le32(PCI_COMMAND_MEMORY
|
605 PCI_COMMAND_MASTER
));
607 P54U_WRITE(NET2280_DEV_CFG_U16
, 0x10000 | 0x40 /* TRDY timeout */, 0);
608 P54U_WRITE(NET2280_DEV_CFG_U32
, 0x10000 | PCI_BASE_ADDRESS_0
,
609 cpu_to_le32(P54U_DEV_BASE
));
611 P54U_WRITE(NET2280_BRG_U32
, NET2280_USBIRQENB1
, 0);
612 P54U_WRITE(NET2280_BRG_U32
, NET2280_IRQSTAT1
,
613 cpu_to_le32(NET2280_PCI_INTA_INTERRUPT
));
616 P54U_WRITE(NET2280_DEV_U32
, &devreg
->int_enable
, 0);
618 P54U_READ(NET2280_DEV_U32
, &devreg
->ctrl_stat
);
619 reg
&= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET
);
620 reg
&= cpu_to_le32(~ISL38XX_CTRL_STAT_RAMBOOT
);
621 reg
&= cpu_to_le32(~ISL38XX_CTRL_STAT_CLKRUN
);
622 P54U_WRITE(NET2280_DEV_U32
, &devreg
->ctrl_stat
, reg
);
626 reg
|= cpu_to_le32(ISL38XX_CTRL_STAT_RESET
);
627 P54U_WRITE(NET2280_DEV_U32
, &devreg
->ctrl_stat
, reg
);
631 reg
&= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET
);
632 P54U_WRITE(NET2280_DEV_U32
, &devreg
->ctrl_stat
, reg
);
636 P54U_READ(NET2280_DEV_U32
, &devreg
->int_ident
);
637 P54U_WRITE(NET2280_DEV_U32
, &devreg
->int_ack
, reg
);
639 /* finally, we can upload firmware now! */
640 remains
= fw_entry
->size
;
641 data
= fw_entry
->data
;
642 offset
= ISL38XX_DEV_FIRMWARE_ADDR
;
645 unsigned int block_len
= min(remains
, (unsigned int)512);
646 memcpy(buf
, data
, block_len
);
648 err
= p54u_bulk_msg(priv
, P54U_PIPE_DATA
, buf
, block_len
);
650 printk(KERN_ERR
"prism54usb: firmware block upload "
655 P54U_WRITE(NET2280_DEV_U32
, &devreg
->direct_mem_base
,
656 cpu_to_le32(0xc0000f00));
658 P54U_WRITE(NET2280_DEV_U32
,
659 0x0020 | (unsigned long)&devreg
->direct_mem_win
, 0);
660 P54U_WRITE(NET2280_DEV_U32
,
661 0x0020 | (unsigned long)&devreg
->direct_mem_win
,
664 P54U_WRITE(NET2280_DEV_U32
,
665 0x0024 | (unsigned long)&devreg
->direct_mem_win
,
666 cpu_to_le32(block_len
));
667 P54U_WRITE(NET2280_DEV_U32
,
668 0x0028 | (unsigned long)&devreg
->direct_mem_win
,
669 cpu_to_le32(offset
));
671 P54U_WRITE(NET2280_DEV_U32
, &devreg
->dma_addr
,
672 cpu_to_le32(NET2280_EPA_FIFO_PCI_ADDR
));
673 P54U_WRITE(NET2280_DEV_U32
, &devreg
->dma_len
,
674 cpu_to_le32(block_len
>> 2));
675 P54U_WRITE(NET2280_DEV_U32
, &devreg
->dma_ctrl
,
676 cpu_to_le32(ISL38XX_DMA_MASTER_CONTROL_TRIGGER
));
680 P54U_READ(NET2280_DEV_U32
,
681 0x002C | (unsigned long)&devreg
->direct_mem_win
);
682 if (!(reg
& cpu_to_le32(ISL38XX_DMA_STATUS_DONE
)) ||
683 !(reg
& cpu_to_le32(ISL38XX_DMA_STATUS_READY
))) {
684 printk(KERN_ERR
"prism54usb: firmware DMA transfer "
689 P54U_WRITE(NET2280_BRG_U32
, NET2280_EPA_STAT
,
690 cpu_to_le32(NET2280_FIFO_FLUSH
));
692 remains
-= block_len
;
698 P54U_READ(NET2280_DEV_U32
, &devreg
->ctrl_stat
);
699 reg
&= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET
);
700 reg
&= cpu_to_le32(~ISL38XX_CTRL_STAT_CLKRUN
);
701 reg
|= cpu_to_le32(ISL38XX_CTRL_STAT_RAMBOOT
);
702 P54U_WRITE(NET2280_DEV_U32
, &devreg
->ctrl_stat
, reg
);
706 reg
|= cpu_to_le32(ISL38XX_CTRL_STAT_RESET
);
707 P54U_WRITE(NET2280_DEV_U32
, &devreg
->ctrl_stat
, reg
);
709 reg
&= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET
);
710 P54U_WRITE(NET2280_DEV_U32
, &devreg
->ctrl_stat
, reg
);
714 P54U_READ(NET2280_DEV_U32
, &devreg
->int_ident
);
715 P54U_WRITE(NET2280_DEV_U32
, &devreg
->int_ack
, reg
);
717 /* start up the firmware */
718 P54U_WRITE(NET2280_DEV_U32
, &devreg
->int_enable
,
719 cpu_to_le32(ISL38XX_INT_IDENT_INIT
));
721 P54U_WRITE(NET2280_BRG_U32
, NET2280_IRQSTAT1
,
722 cpu_to_le32(NET2280_PCI_INTA_INTERRUPT
));
724 P54U_WRITE(NET2280_BRG_U32
, NET2280_USBIRQENB1
,
725 cpu_to_le32(NET2280_PCI_INTA_INTERRUPT_ENABLE
|
726 NET2280_USB_INTERRUPT_ENABLE
));
728 P54U_WRITE(NET2280_DEV_U32
, &devreg
->dev_int
,
729 cpu_to_le32(ISL38XX_DEV_INT_RESET
));
731 err
= usb_interrupt_msg(priv
->udev
,
732 usb_rcvbulkpipe(priv
->udev
, P54U_PIPE_INT
),
733 buf
, sizeof(__le32
), &alen
, 1000);
734 if (err
|| alen
!= sizeof(__le32
))
737 P54U_READ(NET2280_DEV_U32
, &devreg
->int_ident
);
738 P54U_WRITE(NET2280_DEV_U32
, &devreg
->int_ack
, reg
);
740 if (!(reg
& cpu_to_le32(ISL38XX_INT_IDENT_INIT
)))
743 P54U_WRITE(NET2280_BRG_U32
, NET2280_USBIRQENB1
, 0);
744 P54U_WRITE(NET2280_BRG_U32
, NET2280_IRQSTAT1
,
745 cpu_to_le32(NET2280_PCI_INTA_INTERRUPT
));
751 release_firmware(fw_entry
);
756 static int p54u_open(struct ieee80211_hw
*dev
)
758 struct p54u_priv
*priv
= dev
->priv
;
761 err
= p54u_init_urbs(dev
);
766 priv
->common
.open
= p54u_init_urbs
;
771 static void p54u_stop(struct ieee80211_hw
*dev
)
773 /* TODO: figure out how to reliably stop the 3887 and net2280 so
774 the hardware is still usable next time we want to start it.
775 until then, we just stop listening to the hardware.. */
780 static int __devinit
p54u_probe(struct usb_interface
*intf
,
781 const struct usb_device_id
*id
)
783 struct usb_device
*udev
= interface_to_usbdev(intf
);
784 struct ieee80211_hw
*dev
;
785 struct p54u_priv
*priv
;
787 unsigned int i
, recognized_pipes
;
788 DECLARE_MAC_BUF(mac
);
790 dev
= p54_init_common(sizeof(*priv
));
792 printk(KERN_ERR
"prism54usb: ieee80211 alloc failed\n");
798 SET_IEEE80211_DEV(dev
, &intf
->dev
);
799 usb_set_intfdata(intf
, dev
);
804 /* really lazy and simple way of figuring out if we're a 3887 */
805 /* TODO: should just stick the identification in the device table */
806 i
= intf
->altsetting
->desc
.bNumEndpoints
;
807 recognized_pipes
= 0;
809 switch (intf
->altsetting
->endpoint
[i
].desc
.bEndpointAddress
) {
814 case P54U_PIPE_DATA
| USB_DIR_IN
:
815 case P54U_PIPE_MGMT
| USB_DIR_IN
:
816 case P54U_PIPE_BRG
| USB_DIR_IN
:
817 case P54U_PIPE_DEV
| USB_DIR_IN
:
818 case P54U_PIPE_INT
| USB_DIR_IN
:
822 priv
->common
.open
= p54u_open
;
824 if (recognized_pipes
< P54U_PIPE_NUMBER
) {
825 priv
->hw_type
= P54U_3887
;
826 priv
->common
.tx
= p54u_tx_3887
;
828 dev
->extra_tx_headroom
+= sizeof(struct net2280_tx_hdr
);
829 priv
->common
.tx_hdr_len
= sizeof(struct net2280_tx_hdr
);
830 priv
->common
.tx
= p54u_tx_net2280
;
832 priv
->common
.stop
= p54u_stop
;
835 err
= p54u_upload_firmware_3887(dev
);
837 err
= p54u_upload_firmware_net2280(dev
);
841 err
= p54u_read_eeprom(dev
);
845 if (!is_valid_ether_addr(dev
->wiphy
->perm_addr
)) {
846 u8 perm_addr
[ETH_ALEN
];
848 printk(KERN_WARNING
"prism54usb: Invalid hwaddr! Using randomly generated MAC addr\n");
849 random_ether_addr(perm_addr
);
850 SET_IEEE80211_PERM_ADDR(dev
, perm_addr
);
853 skb_queue_head_init(&priv
->rx_queue
);
855 err
= ieee80211_register_hw(dev
);
857 printk(KERN_ERR
"prism54usb: Cannot register netdevice\n");
861 printk(KERN_INFO
"%s: hwaddr %s, isl38%02x\n",
862 wiphy_name(dev
->wiphy
),
863 print_mac(mac
, dev
->wiphy
->perm_addr
),
864 priv
->common
.version
);
869 ieee80211_free_hw(dev
);
870 usb_set_intfdata(intf
, NULL
);
875 static void __devexit
p54u_disconnect(struct usb_interface
*intf
)
877 struct ieee80211_hw
*dev
= usb_get_intfdata(intf
);
878 struct p54u_priv
*priv
;
883 ieee80211_unregister_hw(dev
);
886 usb_put_dev(interface_to_usbdev(intf
));
887 p54_free_common(dev
);
888 ieee80211_free_hw(dev
);
891 static struct usb_driver p54u_driver
= {
892 .name
= "prism54usb",
893 .id_table
= p54u_table
,
895 .disconnect
= p54u_disconnect
,
898 static int __init
p54u_init(void)
900 return usb_register(&p54u_driver
);
903 static void __exit
p54u_exit(void)
905 usb_deregister(&p54u_driver
);
908 module_init(p54u_init
);
909 module_exit(p54u_exit
);