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");
31 MODULE_FIRMWARE("isl3886usb");
32 MODULE_FIRMWARE("isl3887usb");
34 static struct usb_device_id p54u_table[] __devinitdata = {
35 /* Version 1 devices (pci chip + net2280) */
36 {USB_DEVICE(0x0506, 0x0a11)}, /* 3COM 3CRWE254G72 */
37 {USB_DEVICE(0x0707, 0xee06)}, /* SMC 2862W-G */
38 {USB_DEVICE(0x083a, 0x4501)}, /* Accton 802.11g WN4501 USB */
39 {USB_DEVICE(0x083a, 0x4502)}, /* Siemens Gigaset USB Adapter */
40 {USB_DEVICE(0x083a, 0x5501)}, /* Phillips CPWUA054 */
41 {USB_DEVICE(0x0846, 0x4200)}, /* Netgear WG121 */
42 {USB_DEVICE(0x0846, 0x4210)}, /* Netgear WG121 the second ? */
43 {USB_DEVICE(0x0846, 0x4220)}, /* Netgear WG111 */
44 {USB_DEVICE(0x09aa, 0x1000)}, /* Spinnaker Proto board */
45 {USB_DEVICE(0x0cde, 0x0006)}, /* Medion 40900, Roper Europe */
46 {USB_DEVICE(0x124a, 0x4023)}, /* Shuttle PN15, Airvast WM168g, IOGear GWU513 */
47 {USB_DEVICE(0x1915, 0x2234)}, /* Linksys WUSB54G OEM */
48 {USB_DEVICE(0x1915, 0x2235)}, /* Linksys WUSB54G Portable OEM */
49 {USB_DEVICE(0x2001, 0x3701)}, /* DLink DWL-G120 Spinnaker */
50 {USB_DEVICE(0x2001, 0x3703)}, /* DLink DWL-G122 */
51 {USB_DEVICE(0x5041, 0x2234)}, /* Linksys WUSB54G */
52 {USB_DEVICE(0x5041, 0x2235)}, /* Linksys WUSB54G Portable */
54 /* Version 2 devices (3887) */
55 {USB_DEVICE(0x0471, 0x1230)}, /* Philips CPWUA054/00 */
56 {USB_DEVICE(0x050d, 0x7050)}, /* Belkin F5D7050 ver 1000 */
57 {USB_DEVICE(0x0572, 0x2000)}, /* Cohiba Proto board */
58 {USB_DEVICE(0x0572, 0x2002)}, /* Cohiba Proto board */
59 {USB_DEVICE(0x0707, 0xee13)}, /* SMC 2862W-G version 2 */
60 {USB_DEVICE(0x083a, 0x4521)}, /* Siemens Gigaset USB Adapter 54 version 2 */
61 {USB_DEVICE(0x0846, 0x4240)}, /* Netgear WG111 (v2) */
62 {USB_DEVICE(0x0915, 0x2000)}, /* Cohiba Proto board */
63 {USB_DEVICE(0x0915, 0x2002)}, /* Cohiba Proto board */
64 {USB_DEVICE(0x0baf, 0x0118)}, /* U.S. Robotics U5 802.11g Adapter*/
65 {USB_DEVICE(0x0bf8, 0x1009)}, /* FUJITSU E-5400 USB D1700*/
66 {USB_DEVICE(0x0cde, 0x0006)}, /* Medion MD40900 */
67 {USB_DEVICE(0x0cde, 0x0008)}, /* Sagem XG703A */
68 {USB_DEVICE(0x0d8e, 0x3762)}, /* DLink DWL-G120 Cohiba */
69 {USB_DEVICE(0x124a, 0x4025)}, /* IOGear GWU513 (GW3887IK chip) */
70 {USB_DEVICE(0x1260, 0xee22)}, /* SMC 2862W-G version 2 */
71 {USB_DEVICE(0x13b1, 0x000a)}, /* Linksys WUSB54G ver 2 */
72 {USB_DEVICE(0x13B1, 0x000C)}, /* Linksys WUSB54AG */
73 {USB_DEVICE(0x1435, 0x0427)}, /* Inventel UR054G */
74 {USB_DEVICE(0x2001, 0x3704)}, /* DLink DWL-G122 rev A2 */
75 {USB_DEVICE(0x413c, 0x8102)}, /* Spinnaker DUT */
76 {USB_DEVICE(0x413c, 0x8104)}, /* Cohiba Proto board */
80 MODULE_DEVICE_TABLE(usb, p54u_table);
82 static void p54u_rx_cb(struct urb *urb)
84 struct sk_buff *skb = (struct sk_buff *) urb->context;
85 struct p54u_rx_info *info = (struct p54u_rx_info *)skb->cb;
86 struct ieee80211_hw *dev = info->dev;
87 struct p54u_priv *priv = dev->priv;
89 skb_unlink(skb, &priv->rx_queue);
91 if (unlikely(urb->status)) {
92 dev_kfree_skb_irq(skb);
96 skb_put(skb, urb->actual_length);
98 if (priv->hw_type == P54U_NET2280)
99 skb_pull(skb, priv->common.tx_hdr_len);
100 if (priv->common.fw_interface == FW_LM87) {
105 if (p54_rx(dev, skb)) {
106 skb = dev_alloc_skb(priv->common.rx_mtu + 32);
107 if (unlikely(!skb)) {
108 /* TODO check rx queue length and refill *somewhere* */
112 info = (struct p54u_rx_info *) skb->cb;
115 urb->transfer_buffer = skb_tail_pointer(skb);
118 if (priv->hw_type == P54U_NET2280)
119 skb_push(skb, priv->common.tx_hdr_len);
120 if (priv->common.fw_interface == FW_LM87) {
124 skb_reset_tail_pointer(skb);
126 if (urb->transfer_buffer != skb_tail_pointer(skb)) {
127 /* this should not happen */
129 urb->transfer_buffer = skb_tail_pointer(skb);
132 skb_queue_tail(&priv->rx_queue, skb);
133 usb_anchor_urb(urb, &priv->submitted);
134 if (usb_submit_urb(urb, GFP_ATOMIC)) {
135 skb_unlink(skb, &priv->rx_queue);
136 usb_unanchor_urb(urb);
137 dev_kfree_skb_irq(skb);
141 static void p54u_tx_cb(struct urb *urb)
143 struct sk_buff *skb = urb->context;
144 struct ieee80211_hw *dev = (struct ieee80211_hw *)
145 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0));
146 struct p54u_priv *priv = dev->priv;
148 skb_pull(skb, priv->common.tx_hdr_len);
149 if (FREE_AFTER_TX(skb))
150 p54_free_skb(dev, skb);
153 static void p54u_tx_dummy_cb(struct urb *urb) { }
155 static void p54u_free_urbs(struct ieee80211_hw *dev)
157 struct p54u_priv *priv = dev->priv;
158 usb_kill_anchored_urbs(&priv->submitted);
161 static int p54u_init_urbs(struct ieee80211_hw *dev)
163 struct p54u_priv *priv = dev->priv;
164 struct urb *entry = NULL;
166 struct p54u_rx_info *info;
169 while (skb_queue_len(&priv->rx_queue) < 32) {
170 skb = __dev_alloc_skb(priv->common.rx_mtu + 32, GFP_KERNEL);
175 entry = usb_alloc_urb(0, GFP_KERNEL);
181 usb_fill_bulk_urb(entry, priv->udev,
182 usb_rcvbulkpipe(priv->udev, P54U_PIPE_DATA),
183 skb_tail_pointer(skb),
184 priv->common.rx_mtu + 32, p54u_rx_cb, skb);
185 info = (struct p54u_rx_info *) skb->cb;
188 skb_queue_tail(&priv->rx_queue, skb);
190 usb_anchor_urb(entry, &priv->submitted);
191 ret = usb_submit_urb(entry, GFP_KERNEL);
193 skb_unlink(skb, &priv->rx_queue);
194 usb_unanchor_urb(entry);
210 static void p54u_tx_3887(struct ieee80211_hw *dev, struct sk_buff *skb)
212 struct p54u_priv *priv = dev->priv;
213 struct urb *addr_urb, *data_urb;
216 addr_urb = usb_alloc_urb(0, GFP_ATOMIC);
220 data_urb = usb_alloc_urb(0, GFP_ATOMIC);
222 usb_free_urb(addr_urb);
226 usb_fill_bulk_urb(addr_urb, priv->udev,
227 usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA),
228 &((struct p54_hdr *)skb->data)->req_id, 4,
229 p54u_tx_dummy_cb, dev);
230 usb_fill_bulk_urb(data_urb, priv->udev,
231 usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA),
232 skb->data, skb->len, p54u_tx_cb, skb);
234 usb_anchor_urb(addr_urb, &priv->submitted);
235 err = usb_submit_urb(addr_urb, GFP_ATOMIC);
237 usb_unanchor_urb(addr_urb);
241 usb_anchor_urb(addr_urb, &priv->submitted);
242 err = usb_submit_urb(data_urb, GFP_ATOMIC);
244 usb_unanchor_urb(data_urb);
247 usb_free_urb(addr_urb);
248 usb_free_urb(data_urb);
251 p54_free_skb(dev, skb);
254 static __le32 p54u_lm87_chksum(const __le32 *data, size_t length)
260 chk ^= le32_to_cpu(*data++);
261 chk = (chk >> 5) ^ (chk << 3);
264 return cpu_to_le32(chk);
267 static void p54u_tx_lm87(struct ieee80211_hw *dev, struct sk_buff *skb)
269 struct p54u_priv *priv = dev->priv;
270 struct urb *data_urb;
271 struct lm87_tx_hdr *hdr;
273 __le32 addr = ((struct p54_hdr *)skb->data)->req_id;
275 data_urb = usb_alloc_urb(0, GFP_ATOMIC);
279 checksum = p54u_lm87_chksum((__le32 *)skb->data, skb->len);
280 hdr = (struct lm87_tx_hdr *)skb_push(skb, sizeof(*hdr));
281 hdr->chksum = checksum;
282 hdr->device_addr = addr;
284 usb_fill_bulk_urb(data_urb, priv->udev,
285 usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA),
286 skb->data, skb->len, p54u_tx_cb, skb);
288 usb_anchor_urb(data_urb, &priv->submitted);
289 if (usb_submit_urb(data_urb, GFP_ATOMIC)) {
290 usb_unanchor_urb(data_urb);
291 skb_pull(skb, sizeof(*hdr));
292 p54_free_skb(dev, skb);
294 usb_free_urb(data_urb);
297 static void p54u_tx_net2280(struct ieee80211_hw *dev, struct sk_buff *skb)
299 struct p54u_priv *priv = dev->priv;
300 struct urb *int_urb, *data_urb;
301 struct net2280_tx_hdr *hdr;
302 struct net2280_reg_write *reg;
305 reg = kmalloc(sizeof(*reg), GFP_ATOMIC);
309 int_urb = usb_alloc_urb(0, GFP_ATOMIC);
315 data_urb = usb_alloc_urb(0, GFP_ATOMIC);
318 usb_free_urb(int_urb);
322 reg->port = cpu_to_le16(NET2280_DEV_U32);
323 reg->addr = cpu_to_le32(P54U_DEV_BASE);
324 reg->val = cpu_to_le32(ISL38XX_DEV_INT_DATA);
326 hdr = (void *)skb_push(skb, sizeof(*hdr));
327 memset(hdr, 0, sizeof(*hdr));
328 hdr->device_addr = ((struct p54_hdr *)skb->data)->req_id;
329 hdr->len = cpu_to_le16(skb->len + sizeof(struct p54_hdr));
331 usb_fill_bulk_urb(int_urb, priv->udev,
332 usb_sndbulkpipe(priv->udev, P54U_PIPE_DEV), reg, sizeof(*reg),
333 p54u_tx_dummy_cb, dev);
336 * This flag triggers a code path in the USB subsystem that will
337 * free what's inside the transfer_buffer after the callback routine
340 int_urb->transfer_flags |= URB_FREE_BUFFER;
342 usb_fill_bulk_urb(data_urb, priv->udev,
343 usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA),
344 skb->data, skb->len, p54u_tx_cb, skb);
346 usb_anchor_urb(int_urb, &priv->submitted);
347 err = usb_submit_urb(int_urb, GFP_ATOMIC);
349 usb_unanchor_urb(int_urb);
353 usb_anchor_urb(data_urb, &priv->submitted);
354 err = usb_submit_urb(data_urb, GFP_ATOMIC);
356 usb_unanchor_urb(data_urb);
360 usb_free_urb(int_urb);
361 usb_free_urb(data_urb);
364 skb_pull(skb, sizeof(*hdr));
365 p54_free_skb(dev, skb);
369 static int p54u_write(struct p54u_priv *priv,
370 struct net2280_reg_write *buf,
371 enum net2280_op_type type,
372 __le32 addr, __le32 val)
378 ep = usb_sndbulkpipe(priv->udev, P54U_PIPE_DEV);
380 ep = usb_sndbulkpipe(priv->udev, P54U_PIPE_BRG);
382 buf->port = cpu_to_le16(type);
386 return usb_bulk_msg(priv->udev, ep, buf, sizeof(*buf), &alen, 1000);
389 static int p54u_read(struct p54u_priv *priv, void *buf,
390 enum net2280_op_type type,
391 __le32 addr, __le32 *val)
393 struct net2280_reg_read *read = buf;
403 read->port = cpu_to_le16(type);
406 err = usb_bulk_msg(priv->udev, usb_sndbulkpipe(priv->udev, ep),
407 read, sizeof(*read), &alen, 1000);
411 err = usb_bulk_msg(priv->udev, usb_rcvbulkpipe(priv->udev, ep),
412 reg, sizeof(*reg), &alen, 1000);
420 static int p54u_bulk_msg(struct p54u_priv *priv, unsigned int ep,
421 void *data, size_t len)
424 return usb_bulk_msg(priv->udev, usb_sndbulkpipe(priv->udev, ep),
425 data, len, &alen, 2000);
428 static int p54u_upload_firmware_3887(struct ieee80211_hw *dev)
430 static char start_string[] = "~~~~<\r";
431 struct p54u_priv *priv = dev->priv;
432 const struct firmware *fw_entry = NULL;
437 unsigned int left, remains, block_size;
438 struct x2_header *hdr;
439 unsigned long timeout;
441 tmp = buf = kmalloc(P54U_FW_BLOCK, GFP_KERNEL);
443 dev_err(&priv->udev->dev, "(p54usb) cannot allocate firmware"
449 memcpy(buf, start_string, 4);
450 err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, 4);
452 dev_err(&priv->udev->dev, "(p54usb) reset failed! (%d)\n", err);
456 err = request_firmware(&fw_entry, "isl3887usb", &priv->udev->dev);
458 dev_err(&priv->udev->dev, "p54usb: cannot find firmware "
460 err = request_firmware(&fw_entry, "isl3887usb_bare",
463 goto err_req_fw_failed;
466 err = p54_parse_firmware(dev, fw_entry);
468 goto err_upload_failed;
470 left = block_size = min((size_t)P54U_FW_BLOCK, fw_entry->size);
471 strcpy(buf, start_string);
472 left -= strlen(start_string);
473 tmp += strlen(start_string);
475 data = fw_entry->data;
476 remains = fw_entry->size;
478 hdr = (struct x2_header *)(buf + strlen(start_string));
479 memcpy(hdr->signature, X2_SIGNATURE, X2_SIGNATURE_SIZE);
480 hdr->fw_load_addr = cpu_to_le32(ISL38XX_DEV_FIRMWARE_ADDR);
481 hdr->fw_length = cpu_to_le32(fw_entry->size);
482 hdr->crc = cpu_to_le32(~crc32_le(~0, (void *)&hdr->fw_load_addr,
484 left -= sizeof(*hdr);
512 err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, block_size);
514 dev_err(&priv->udev->dev, "(p54usb) firmware "
516 goto err_upload_failed;
520 left = block_size = min((unsigned int)P54U_FW_BLOCK, remains);
523 *((__le32 *)buf) = cpu_to_le32(~crc32_le(~0, fw_entry->data, fw_entry->size));
524 err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, sizeof(u32));
526 dev_err(&priv->udev->dev, "(p54usb) firmware upload failed!\n");
527 goto err_upload_failed;
529 timeout = jiffies + msecs_to_jiffies(1000);
530 while (!(err = usb_bulk_msg(priv->udev,
531 usb_rcvbulkpipe(priv->udev, P54U_PIPE_DATA), buf, 128, &alen, 1000))) {
532 if (alen > 2 && !memcmp(buf, "OK", 2))
535 if (alen > 5 && !memcmp(buf, "ERROR", 5)) {
540 if (time_after(jiffies, timeout)) {
541 dev_err(&priv->udev->dev, "(p54usb) firmware boot "
548 dev_err(&priv->udev->dev, "(p54usb) firmware upload failed!\n");
549 goto err_upload_failed;
554 err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, 2);
556 dev_err(&priv->udev->dev, "(p54usb) firmware boot failed!\n");
557 goto err_upload_failed;
560 timeout = jiffies + msecs_to_jiffies(1000);
561 while (!(err = usb_bulk_msg(priv->udev,
562 usb_rcvbulkpipe(priv->udev, P54U_PIPE_DATA), buf, 128, &alen, 1000))) {
563 if (alen > 0 && buf[0] == 'g')
566 if (time_after(jiffies, timeout)) {
572 goto err_upload_failed;
575 release_firmware(fw_entry);
583 static int p54u_upload_firmware_net2280(struct ieee80211_hw *dev)
585 struct p54u_priv *priv = dev->priv;
586 const struct firmware *fw_entry = NULL;
587 const struct p54p_csr *devreg = (const struct p54p_csr *) P54U_DEV_BASE;
591 unsigned int remains, offset;
594 buf = kmalloc(512, GFP_KERNEL);
596 dev_err(&priv->udev->dev, "(p54usb) firmware buffer "
601 err = request_firmware(&fw_entry, "isl3886usb", &priv->udev->dev);
603 dev_err(&priv->udev->dev, "(p54usb) cannot find firmware "
605 err = request_firmware(&fw_entry, "isl3890usb",
613 err = p54_parse_firmware(dev, fw_entry);
616 release_firmware(fw_entry);
620 #define P54U_WRITE(type, addr, data) \
622 err = p54u_write(priv, buf, type,\
623 cpu_to_le32((u32)(unsigned long)addr), data);\
628 #define P54U_READ(type, addr) \
630 err = p54u_read(priv, buf, type,\
631 cpu_to_le32((u32)(unsigned long)addr), ®);\
636 /* power down net2280 bridge */
637 P54U_READ(NET2280_BRG_U32, NET2280_GPIOCTL);
638 reg |= cpu_to_le32(P54U_BRG_POWER_DOWN);
639 reg &= cpu_to_le32(~P54U_BRG_POWER_UP);
640 P54U_WRITE(NET2280_BRG_U32, NET2280_GPIOCTL, reg);
644 /* power up bridge */
645 reg |= cpu_to_le32(P54U_BRG_POWER_UP);
646 reg &= cpu_to_le32(~P54U_BRG_POWER_DOWN);
647 P54U_WRITE(NET2280_BRG_U32, NET2280_GPIOCTL, reg);
651 P54U_WRITE(NET2280_BRG_U32, NET2280_DEVINIT,
652 cpu_to_le32(NET2280_CLK_30Mhz |
654 NET2280_PCI_SOFT_RESET));
658 P54U_WRITE(NET2280_BRG_CFG_U16, PCI_COMMAND,
659 cpu_to_le32(PCI_COMMAND_MEMORY |
660 PCI_COMMAND_MASTER));
662 P54U_WRITE(NET2280_BRG_CFG_U32, PCI_BASE_ADDRESS_0,
663 cpu_to_le32(NET2280_BASE));
665 P54U_READ(NET2280_BRG_CFG_U16, PCI_STATUS);
666 reg |= cpu_to_le32(PCI_STATUS_REC_MASTER_ABORT);
667 P54U_WRITE(NET2280_BRG_CFG_U16, PCI_STATUS, reg);
669 // TODO: we really need this?
670 P54U_READ(NET2280_BRG_U32, NET2280_RELNUM);
672 P54U_WRITE(NET2280_BRG_U32, NET2280_EPA_RSP,
673 cpu_to_le32(NET2280_CLEAR_NAK_OUT_PACKETS_MODE));
674 P54U_WRITE(NET2280_BRG_U32, NET2280_EPC_RSP,
675 cpu_to_le32(NET2280_CLEAR_NAK_OUT_PACKETS_MODE));
677 P54U_WRITE(NET2280_BRG_CFG_U32, PCI_BASE_ADDRESS_2,
678 cpu_to_le32(NET2280_BASE2));
680 /* finally done setting up the bridge */
682 P54U_WRITE(NET2280_DEV_CFG_U16, 0x10000 | PCI_COMMAND,
683 cpu_to_le32(PCI_COMMAND_MEMORY |
684 PCI_COMMAND_MASTER));
686 P54U_WRITE(NET2280_DEV_CFG_U16, 0x10000 | 0x40 /* TRDY timeout */, 0);
687 P54U_WRITE(NET2280_DEV_CFG_U32, 0x10000 | PCI_BASE_ADDRESS_0,
688 cpu_to_le32(P54U_DEV_BASE));
690 P54U_WRITE(NET2280_BRG_U32, NET2280_USBIRQENB1, 0);
691 P54U_WRITE(NET2280_BRG_U32, NET2280_IRQSTAT1,
692 cpu_to_le32(NET2280_PCI_INTA_INTERRUPT));
695 P54U_WRITE(NET2280_DEV_U32, &devreg->int_enable, 0);
697 P54U_READ(NET2280_DEV_U32, &devreg->ctrl_stat);
698 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET);
699 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RAMBOOT);
700 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_CLKRUN);
701 P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg);
705 reg |= cpu_to_le32(ISL38XX_CTRL_STAT_RESET);
706 P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg);
710 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET);
711 P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg);
715 P54U_READ(NET2280_DEV_U32, &devreg->int_ident);
716 P54U_WRITE(NET2280_DEV_U32, &devreg->int_ack, reg);
718 /* finally, we can upload firmware now! */
719 remains = fw_entry->size;
720 data = fw_entry->data;
721 offset = ISL38XX_DEV_FIRMWARE_ADDR;
724 unsigned int block_len = min(remains, (unsigned int)512);
725 memcpy(buf, data, block_len);
727 err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, block_len);
729 dev_err(&priv->udev->dev, "(p54usb) firmware block "
734 P54U_WRITE(NET2280_DEV_U32, &devreg->direct_mem_base,
735 cpu_to_le32(0xc0000f00));
737 P54U_WRITE(NET2280_DEV_U32,
738 0x0020 | (unsigned long)&devreg->direct_mem_win, 0);
739 P54U_WRITE(NET2280_DEV_U32,
740 0x0020 | (unsigned long)&devreg->direct_mem_win,
743 P54U_WRITE(NET2280_DEV_U32,
744 0x0024 | (unsigned long)&devreg->direct_mem_win,
745 cpu_to_le32(block_len));
746 P54U_WRITE(NET2280_DEV_U32,
747 0x0028 | (unsigned long)&devreg->direct_mem_win,
748 cpu_to_le32(offset));
750 P54U_WRITE(NET2280_DEV_U32, &devreg->dma_addr,
751 cpu_to_le32(NET2280_EPA_FIFO_PCI_ADDR));
752 P54U_WRITE(NET2280_DEV_U32, &devreg->dma_len,
753 cpu_to_le32(block_len >> 2));
754 P54U_WRITE(NET2280_DEV_U32, &devreg->dma_ctrl,
755 cpu_to_le32(ISL38XX_DMA_MASTER_CONTROL_TRIGGER));
759 P54U_READ(NET2280_DEV_U32,
760 0x002C | (unsigned long)&devreg->direct_mem_win);
761 if (!(reg & cpu_to_le32(ISL38XX_DMA_STATUS_DONE)) ||
762 !(reg & cpu_to_le32(ISL38XX_DMA_STATUS_READY))) {
763 dev_err(&priv->udev->dev, "(p54usb) firmware DMA "
764 "transfer failed\n");
768 P54U_WRITE(NET2280_BRG_U32, NET2280_EPA_STAT,
769 cpu_to_le32(NET2280_FIFO_FLUSH));
771 remains -= block_len;
777 P54U_READ(NET2280_DEV_U32, &devreg->ctrl_stat);
778 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET);
779 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_CLKRUN);
780 reg |= cpu_to_le32(ISL38XX_CTRL_STAT_RAMBOOT);
781 P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg);
785 reg |= cpu_to_le32(ISL38XX_CTRL_STAT_RESET);
786 P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg);
788 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET);
789 P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg);
793 P54U_READ(NET2280_DEV_U32, &devreg->int_ident);
794 P54U_WRITE(NET2280_DEV_U32, &devreg->int_ack, reg);
796 /* start up the firmware */
797 P54U_WRITE(NET2280_DEV_U32, &devreg->int_enable,
798 cpu_to_le32(ISL38XX_INT_IDENT_INIT));
800 P54U_WRITE(NET2280_BRG_U32, NET2280_IRQSTAT1,
801 cpu_to_le32(NET2280_PCI_INTA_INTERRUPT));
803 P54U_WRITE(NET2280_BRG_U32, NET2280_USBIRQENB1,
804 cpu_to_le32(NET2280_PCI_INTA_INTERRUPT_ENABLE |
805 NET2280_USB_INTERRUPT_ENABLE));
807 P54U_WRITE(NET2280_DEV_U32, &devreg->dev_int,
808 cpu_to_le32(ISL38XX_DEV_INT_RESET));
810 err = usb_interrupt_msg(priv->udev,
811 usb_rcvbulkpipe(priv->udev, P54U_PIPE_INT),
812 buf, sizeof(__le32), &alen, 1000);
813 if (err || alen != sizeof(__le32))
816 P54U_READ(NET2280_DEV_U32, &devreg->int_ident);
817 P54U_WRITE(NET2280_DEV_U32, &devreg->int_ack, reg);
819 if (!(reg & cpu_to_le32(ISL38XX_INT_IDENT_INIT)))
822 P54U_WRITE(NET2280_BRG_U32, NET2280_USBIRQENB1, 0);
823 P54U_WRITE(NET2280_BRG_U32, NET2280_IRQSTAT1,
824 cpu_to_le32(NET2280_PCI_INTA_INTERRUPT));
830 release_firmware(fw_entry);
835 static int p54u_open(struct ieee80211_hw *dev)
837 struct p54u_priv *priv = dev->priv;
840 err = p54u_init_urbs(dev);
845 priv->common.open = p54u_init_urbs;
850 static void p54u_stop(struct ieee80211_hw *dev)
852 /* TODO: figure out how to reliably stop the 3887 and net2280 so
853 the hardware is still usable next time we want to start it.
854 until then, we just stop listening to the hardware.. */
859 static int __devinit p54u_probe(struct usb_interface *intf,
860 const struct usb_device_id *id)
862 struct usb_device *udev = interface_to_usbdev(intf);
863 struct ieee80211_hw *dev;
864 struct p54u_priv *priv;
866 unsigned int i, recognized_pipes;
868 dev = p54_init_common(sizeof(*priv));
871 dev_err(&udev->dev, "(p54usb) ieee80211 alloc failed\n");
877 SET_IEEE80211_DEV(dev, &intf->dev);
878 usb_set_intfdata(intf, dev);
883 /* really lazy and simple way of figuring out if we're a 3887 */
884 /* TODO: should just stick the identification in the device table */
885 i = intf->altsetting->desc.bNumEndpoints;
886 recognized_pipes = 0;
888 switch (intf->altsetting->endpoint[i].desc.bEndpointAddress) {
893 case P54U_PIPE_DATA | USB_DIR_IN:
894 case P54U_PIPE_MGMT | USB_DIR_IN:
895 case P54U_PIPE_BRG | USB_DIR_IN:
896 case P54U_PIPE_DEV | USB_DIR_IN:
897 case P54U_PIPE_INT | USB_DIR_IN:
901 priv->common.open = p54u_open;
902 priv->common.stop = p54u_stop;
903 if (recognized_pipes < P54U_PIPE_NUMBER) {
904 priv->hw_type = P54U_3887;
905 err = p54u_upload_firmware_3887(dev);
906 if (priv->common.fw_interface == FW_LM87) {
907 dev->extra_tx_headroom += sizeof(struct lm87_tx_hdr);
908 priv->common.tx_hdr_len = sizeof(struct lm87_tx_hdr);
909 priv->common.tx = p54u_tx_lm87;
911 priv->common.tx = p54u_tx_3887;
913 priv->hw_type = P54U_NET2280;
914 dev->extra_tx_headroom += sizeof(struct net2280_tx_hdr);
915 priv->common.tx_hdr_len = sizeof(struct net2280_tx_hdr);
916 priv->common.tx = p54u_tx_net2280;
917 err = p54u_upload_firmware_net2280(dev);
922 skb_queue_head_init(&priv->rx_queue);
923 init_usb_anchor(&priv->submitted);
926 err = p54_read_eeprom(dev);
931 err = ieee80211_register_hw(dev);
933 dev_err(&udev->dev, "(p54usb) Cannot register netdevice\n");
940 ieee80211_free_hw(dev);
941 usb_set_intfdata(intf, NULL);
946 static void __devexit p54u_disconnect(struct usb_interface *intf)
948 struct ieee80211_hw *dev = usb_get_intfdata(intf);
949 struct p54u_priv *priv;
954 ieee80211_unregister_hw(dev);
957 usb_put_dev(interface_to_usbdev(intf));
958 p54_free_common(dev);
959 ieee80211_free_hw(dev);
962 static struct usb_driver p54u_driver = {
964 .id_table = p54u_table,
966 .disconnect = p54u_disconnect,
969 static int __init p54u_init(void)
971 return usb_register(&p54u_driver);
974 static void __exit p54u_exit(void)
976 usb_deregister(&p54u_driver);
979 module_init(p54u_init);
980 module_exit(p54u_exit);