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(0x06b9, 0x0121)}, /* Thomson SpeedTouch 121g */
60 {USB_DEVICE(0x0707, 0xee13)}, /* SMC 2862W-G version 2 */
61 {USB_DEVICE(0x083a, 0x4521)}, /* Siemens Gigaset USB Adapter 54 version 2 */
62 {USB_DEVICE(0x0846, 0x4240)}, /* Netgear WG111 (v2) */
63 {USB_DEVICE(0x0915, 0x2000)}, /* Cohiba Proto board */
64 {USB_DEVICE(0x0915, 0x2002)}, /* Cohiba Proto board */
65 {USB_DEVICE(0x0baf, 0x0118)}, /* U.S. Robotics U5 802.11g Adapter*/
66 {USB_DEVICE(0x0bf8, 0x1009)}, /* FUJITSU E-5400 USB D1700*/
67 {USB_DEVICE(0x0cde, 0x0006)}, /* Medion MD40900 */
68 {USB_DEVICE(0x0cde, 0x0008)}, /* Sagem XG703A */
69 {USB_DEVICE(0x0d8e, 0x3762)}, /* DLink DWL-G120 Cohiba */
70 {USB_DEVICE(0x124a, 0x4025)}, /* IOGear GWU513 (GW3887IK chip) */
71 {USB_DEVICE(0x1260, 0xee22)}, /* SMC 2862W-G version 2 */
72 {USB_DEVICE(0x13b1, 0x000a)}, /* Linksys WUSB54G ver 2 */
73 {USB_DEVICE(0x13B1, 0x000C)}, /* Linksys WUSB54AG */
74 {USB_DEVICE(0x1435, 0x0427)}, /* Inventel UR054G */
75 {USB_DEVICE(0x2001, 0x3704)}, /* DLink DWL-G122 rev A2 */
76 {USB_DEVICE(0x413c, 0x8102)}, /* Spinnaker DUT */
77 {USB_DEVICE(0x413c, 0x8104)}, /* Cohiba Proto board */
81 MODULE_DEVICE_TABLE(usb, p54u_table);
83 static void p54u_rx_cb(struct urb *urb)
85 struct sk_buff *skb = (struct sk_buff *) urb->context;
86 struct p54u_rx_info *info = (struct p54u_rx_info *)skb->cb;
87 struct ieee80211_hw *dev = info->dev;
88 struct p54u_priv *priv = dev->priv;
90 skb_unlink(skb, &priv->rx_queue);
92 if (unlikely(urb->status)) {
93 dev_kfree_skb_irq(skb);
97 skb_put(skb, urb->actual_length);
99 if (priv->hw_type == P54U_NET2280)
100 skb_pull(skb, priv->common.tx_hdr_len);
101 if (priv->common.fw_interface == FW_LM87) {
106 if (p54_rx(dev, skb)) {
107 skb = dev_alloc_skb(priv->common.rx_mtu + 32);
108 if (unlikely(!skb)) {
109 /* TODO check rx queue length and refill *somewhere* */
113 info = (struct p54u_rx_info *) skb->cb;
116 urb->transfer_buffer = skb_tail_pointer(skb);
119 if (priv->hw_type == P54U_NET2280)
120 skb_push(skb, priv->common.tx_hdr_len);
121 if (priv->common.fw_interface == FW_LM87) {
125 skb_reset_tail_pointer(skb);
127 if (urb->transfer_buffer != skb_tail_pointer(skb)) {
128 /* this should not happen */
130 urb->transfer_buffer = skb_tail_pointer(skb);
133 skb_queue_tail(&priv->rx_queue, skb);
134 usb_anchor_urb(urb, &priv->submitted);
135 if (usb_submit_urb(urb, GFP_ATOMIC)) {
136 skb_unlink(skb, &priv->rx_queue);
137 usb_unanchor_urb(urb);
138 dev_kfree_skb_irq(skb);
142 static void p54u_tx_cb(struct urb *urb)
144 struct sk_buff *skb = urb->context;
145 struct ieee80211_hw *dev = (struct ieee80211_hw *)
146 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0));
148 p54_free_skb(dev, skb);
151 static void p54u_tx_dummy_cb(struct urb *urb) { }
153 static void p54u_free_urbs(struct ieee80211_hw *dev)
155 struct p54u_priv *priv = dev->priv;
156 usb_kill_anchored_urbs(&priv->submitted);
159 static int p54u_init_urbs(struct ieee80211_hw *dev)
161 struct p54u_priv *priv = dev->priv;
162 struct urb *entry = NULL;
164 struct p54u_rx_info *info;
167 while (skb_queue_len(&priv->rx_queue) < 32) {
168 skb = __dev_alloc_skb(priv->common.rx_mtu + 32, GFP_KERNEL);
173 entry = usb_alloc_urb(0, GFP_KERNEL);
179 usb_fill_bulk_urb(entry, priv->udev,
180 usb_rcvbulkpipe(priv->udev, P54U_PIPE_DATA),
181 skb_tail_pointer(skb),
182 priv->common.rx_mtu + 32, p54u_rx_cb, skb);
183 info = (struct p54u_rx_info *) skb->cb;
186 skb_queue_tail(&priv->rx_queue, skb);
188 usb_anchor_urb(entry, &priv->submitted);
189 ret = usb_submit_urb(entry, GFP_KERNEL);
191 skb_unlink(skb, &priv->rx_queue);
192 usb_unanchor_urb(entry);
208 static void p54u_tx_3887(struct ieee80211_hw *dev, struct sk_buff *skb)
210 struct p54u_priv *priv = dev->priv;
211 struct urb *addr_urb, *data_urb;
214 addr_urb = usb_alloc_urb(0, GFP_ATOMIC);
218 data_urb = usb_alloc_urb(0, GFP_ATOMIC);
220 usb_free_urb(addr_urb);
224 usb_fill_bulk_urb(addr_urb, priv->udev,
225 usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA),
226 &((struct p54_hdr *)skb->data)->req_id, 4,
227 p54u_tx_dummy_cb, dev);
228 usb_fill_bulk_urb(data_urb, priv->udev,
229 usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA),
230 skb->data, skb->len, FREE_AFTER_TX(skb) ?
231 p54u_tx_cb : p54u_tx_dummy_cb, skb);
232 addr_urb->transfer_flags |= URB_ZERO_PACKET;
233 data_urb->transfer_flags |= URB_ZERO_PACKET;
235 usb_anchor_urb(addr_urb, &priv->submitted);
236 err = usb_submit_urb(addr_urb, GFP_ATOMIC);
238 usb_unanchor_urb(addr_urb);
242 usb_anchor_urb(data_urb, &priv->submitted);
243 err = usb_submit_urb(data_urb, GFP_ATOMIC);
245 usb_unanchor_urb(data_urb);
248 usb_free_urb(addr_urb);
249 usb_free_urb(data_urb);
252 p54_free_skb(dev, skb);
255 static __le32 p54u_lm87_chksum(const __le32 *data, size_t length)
261 chk ^= le32_to_cpu(*data++);
262 chk = (chk >> 5) ^ (chk << 3);
265 return cpu_to_le32(chk);
268 static void p54u_tx_lm87(struct ieee80211_hw *dev, struct sk_buff *skb)
270 struct p54u_priv *priv = dev->priv;
271 struct urb *data_urb;
272 struct lm87_tx_hdr *hdr = (void *)skb->data - sizeof(*hdr);
274 data_urb = usb_alloc_urb(0, GFP_ATOMIC);
278 hdr->chksum = p54u_lm87_chksum((__le32 *)skb->data, skb->len);
279 hdr->device_addr = ((struct p54_hdr *)skb->data)->req_id;
281 usb_fill_bulk_urb(data_urb, priv->udev,
282 usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA),
283 hdr, skb->len + sizeof(*hdr), FREE_AFTER_TX(skb) ?
284 p54u_tx_cb : p54u_tx_dummy_cb, skb);
285 data_urb->transfer_flags |= URB_ZERO_PACKET;
287 usb_anchor_urb(data_urb, &priv->submitted);
288 if (usb_submit_urb(data_urb, GFP_ATOMIC)) {
289 usb_unanchor_urb(data_urb);
290 p54_free_skb(dev, skb);
292 usb_free_urb(data_urb);
295 static void p54u_tx_net2280(struct ieee80211_hw *dev, struct sk_buff *skb)
297 struct p54u_priv *priv = dev->priv;
298 struct urb *int_urb, *data_urb;
299 struct net2280_tx_hdr *hdr = (void *)skb->data - sizeof(*hdr);
300 struct net2280_reg_write *reg;
303 reg = kmalloc(sizeof(*reg), GFP_ATOMIC);
307 int_urb = usb_alloc_urb(0, GFP_ATOMIC);
313 data_urb = usb_alloc_urb(0, GFP_ATOMIC);
316 usb_free_urb(int_urb);
320 reg->port = cpu_to_le16(NET2280_DEV_U32);
321 reg->addr = cpu_to_le32(P54U_DEV_BASE);
322 reg->val = cpu_to_le32(ISL38XX_DEV_INT_DATA);
324 memset(hdr, 0, sizeof(*hdr));
325 hdr->len = cpu_to_le16(skb->len);
326 hdr->device_addr = ((struct p54_hdr *) skb->data)->req_id;
328 usb_fill_bulk_urb(int_urb, priv->udev,
329 usb_sndbulkpipe(priv->udev, P54U_PIPE_DEV), reg, sizeof(*reg),
330 p54u_tx_dummy_cb, dev);
333 * This flag triggers a code path in the USB subsystem that will
334 * free what's inside the transfer_buffer after the callback routine
337 int_urb->transfer_flags |= URB_FREE_BUFFER | URB_ZERO_PACKET;
339 usb_fill_bulk_urb(data_urb, priv->udev,
340 usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA),
341 hdr, skb->len + sizeof(*hdr), FREE_AFTER_TX(skb) ?
342 p54u_tx_cb : p54u_tx_dummy_cb, skb);
343 data_urb->transfer_flags |= URB_ZERO_PACKET;
345 usb_anchor_urb(int_urb, &priv->submitted);
346 err = usb_submit_urb(int_urb, GFP_ATOMIC);
348 usb_unanchor_urb(int_urb);
352 usb_anchor_urb(data_urb, &priv->submitted);
353 err = usb_submit_urb(data_urb, GFP_ATOMIC);
355 usb_unanchor_urb(data_urb);
359 usb_free_urb(int_urb);
360 usb_free_urb(data_urb);
363 skb_pull(skb, sizeof(*hdr));
364 p54_free_skb(dev, skb);
368 static int p54u_write(struct p54u_priv *priv,
369 struct net2280_reg_write *buf,
370 enum net2280_op_type type,
371 __le32 addr, __le32 val)
377 ep = usb_sndbulkpipe(priv->udev, P54U_PIPE_DEV);
379 ep = usb_sndbulkpipe(priv->udev, P54U_PIPE_BRG);
381 buf->port = cpu_to_le16(type);
385 return usb_bulk_msg(priv->udev, ep, buf, sizeof(*buf), &alen, 1000);
388 static int p54u_read(struct p54u_priv *priv, void *buf,
389 enum net2280_op_type type,
390 __le32 addr, __le32 *val)
392 struct net2280_reg_read *read = buf;
402 read->port = cpu_to_le16(type);
405 err = usb_bulk_msg(priv->udev, usb_sndbulkpipe(priv->udev, ep),
406 read, sizeof(*read), &alen, 1000);
410 err = usb_bulk_msg(priv->udev, usb_rcvbulkpipe(priv->udev, ep),
411 reg, sizeof(*reg), &alen, 1000);
419 static int p54u_bulk_msg(struct p54u_priv *priv, unsigned int ep,
420 void *data, size_t len)
423 return usb_bulk_msg(priv->udev, usb_sndbulkpipe(priv->udev, ep),
424 data, len, &alen, 2000);
427 static int p54u_upload_firmware_3887(struct ieee80211_hw *dev)
429 static char start_string[] = "~~~~<\r";
430 struct p54u_priv *priv = dev->priv;
431 const struct firmware *fw_entry = NULL;
436 unsigned int left, remains, block_size;
437 struct x2_header *hdr;
438 unsigned long timeout;
440 tmp = buf = kmalloc(P54U_FW_BLOCK, GFP_KERNEL);
442 dev_err(&priv->udev->dev, "(p54usb) cannot allocate firmware"
448 memcpy(buf, start_string, 4);
449 err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, 4);
451 dev_err(&priv->udev->dev, "(p54usb) reset failed! (%d)\n", err);
455 err = request_firmware(&fw_entry, "isl3887usb", &priv->udev->dev);
457 dev_err(&priv->udev->dev, "p54usb: cannot find firmware "
459 err = request_firmware(&fw_entry, "isl3887usb_bare",
462 goto err_req_fw_failed;
465 err = p54_parse_firmware(dev, fw_entry);
467 goto err_upload_failed;
469 left = block_size = min((size_t)P54U_FW_BLOCK, fw_entry->size);
470 strcpy(buf, start_string);
471 left -= strlen(start_string);
472 tmp += strlen(start_string);
474 data = fw_entry->data;
475 remains = fw_entry->size;
477 hdr = (struct x2_header *)(buf + strlen(start_string));
478 memcpy(hdr->signature, X2_SIGNATURE, X2_SIGNATURE_SIZE);
479 hdr->fw_load_addr = cpu_to_le32(ISL38XX_DEV_FIRMWARE_ADDR);
480 hdr->fw_length = cpu_to_le32(fw_entry->size);
481 hdr->crc = cpu_to_le32(~crc32_le(~0, (void *)&hdr->fw_load_addr,
483 left -= sizeof(*hdr);
511 err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, block_size);
513 dev_err(&priv->udev->dev, "(p54usb) firmware "
515 goto err_upload_failed;
519 left = block_size = min((unsigned int)P54U_FW_BLOCK, remains);
522 *((__le32 *)buf) = cpu_to_le32(~crc32_le(~0, fw_entry->data, fw_entry->size));
523 err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, sizeof(u32));
525 dev_err(&priv->udev->dev, "(p54usb) firmware upload failed!\n");
526 goto err_upload_failed;
528 timeout = jiffies + msecs_to_jiffies(1000);
529 while (!(err = usb_bulk_msg(priv->udev,
530 usb_rcvbulkpipe(priv->udev, P54U_PIPE_DATA), buf, 128, &alen, 1000))) {
531 if (alen > 2 && !memcmp(buf, "OK", 2))
534 if (alen > 5 && !memcmp(buf, "ERROR", 5)) {
539 if (time_after(jiffies, timeout)) {
540 dev_err(&priv->udev->dev, "(p54usb) firmware boot "
547 dev_err(&priv->udev->dev, "(p54usb) firmware upload failed!\n");
548 goto err_upload_failed;
553 err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, 2);
555 dev_err(&priv->udev->dev, "(p54usb) firmware boot failed!\n");
556 goto err_upload_failed;
559 timeout = jiffies + msecs_to_jiffies(1000);
560 while (!(err = usb_bulk_msg(priv->udev,
561 usb_rcvbulkpipe(priv->udev, P54U_PIPE_DATA), buf, 128, &alen, 1000))) {
562 if (alen > 0 && buf[0] == 'g')
565 if (time_after(jiffies, timeout)) {
571 goto err_upload_failed;
574 release_firmware(fw_entry);
582 static int p54u_upload_firmware_net2280(struct ieee80211_hw *dev)
584 struct p54u_priv *priv = dev->priv;
585 const struct firmware *fw_entry = NULL;
586 const struct p54p_csr *devreg = (const struct p54p_csr *) P54U_DEV_BASE;
590 unsigned int remains, offset;
593 buf = kmalloc(512, GFP_KERNEL);
595 dev_err(&priv->udev->dev, "(p54usb) firmware buffer "
600 err = request_firmware(&fw_entry, "isl3886usb", &priv->udev->dev);
602 dev_err(&priv->udev->dev, "(p54usb) cannot find firmware "
604 err = request_firmware(&fw_entry, "isl3890usb",
612 err = p54_parse_firmware(dev, fw_entry);
615 release_firmware(fw_entry);
619 #define P54U_WRITE(type, addr, data) \
621 err = p54u_write(priv, buf, type,\
622 cpu_to_le32((u32)(unsigned long)addr), data);\
627 #define P54U_READ(type, addr) \
629 err = p54u_read(priv, buf, type,\
630 cpu_to_le32((u32)(unsigned long)addr), ®);\
635 /* power down net2280 bridge */
636 P54U_READ(NET2280_BRG_U32, NET2280_GPIOCTL);
637 reg |= cpu_to_le32(P54U_BRG_POWER_DOWN);
638 reg &= cpu_to_le32(~P54U_BRG_POWER_UP);
639 P54U_WRITE(NET2280_BRG_U32, NET2280_GPIOCTL, reg);
643 /* power up bridge */
644 reg |= cpu_to_le32(P54U_BRG_POWER_UP);
645 reg &= cpu_to_le32(~P54U_BRG_POWER_DOWN);
646 P54U_WRITE(NET2280_BRG_U32, NET2280_GPIOCTL, reg);
650 P54U_WRITE(NET2280_BRG_U32, NET2280_DEVINIT,
651 cpu_to_le32(NET2280_CLK_30Mhz |
653 NET2280_PCI_SOFT_RESET));
657 P54U_WRITE(NET2280_BRG_CFG_U16, PCI_COMMAND,
658 cpu_to_le32(PCI_COMMAND_MEMORY |
659 PCI_COMMAND_MASTER));
661 P54U_WRITE(NET2280_BRG_CFG_U32, PCI_BASE_ADDRESS_0,
662 cpu_to_le32(NET2280_BASE));
664 P54U_READ(NET2280_BRG_CFG_U16, PCI_STATUS);
665 reg |= cpu_to_le32(PCI_STATUS_REC_MASTER_ABORT);
666 P54U_WRITE(NET2280_BRG_CFG_U16, PCI_STATUS, reg);
668 // TODO: we really need this?
669 P54U_READ(NET2280_BRG_U32, NET2280_RELNUM);
671 P54U_WRITE(NET2280_BRG_U32, NET2280_EPA_RSP,
672 cpu_to_le32(NET2280_CLEAR_NAK_OUT_PACKETS_MODE));
673 P54U_WRITE(NET2280_BRG_U32, NET2280_EPC_RSP,
674 cpu_to_le32(NET2280_CLEAR_NAK_OUT_PACKETS_MODE));
676 P54U_WRITE(NET2280_BRG_CFG_U32, PCI_BASE_ADDRESS_2,
677 cpu_to_le32(NET2280_BASE2));
679 /* finally done setting up the bridge */
681 P54U_WRITE(NET2280_DEV_CFG_U16, 0x10000 | PCI_COMMAND,
682 cpu_to_le32(PCI_COMMAND_MEMORY |
683 PCI_COMMAND_MASTER));
685 P54U_WRITE(NET2280_DEV_CFG_U16, 0x10000 | 0x40 /* TRDY timeout */, 0);
686 P54U_WRITE(NET2280_DEV_CFG_U32, 0x10000 | PCI_BASE_ADDRESS_0,
687 cpu_to_le32(P54U_DEV_BASE));
689 P54U_WRITE(NET2280_BRG_U32, NET2280_USBIRQENB1, 0);
690 P54U_WRITE(NET2280_BRG_U32, NET2280_IRQSTAT1,
691 cpu_to_le32(NET2280_PCI_INTA_INTERRUPT));
694 P54U_WRITE(NET2280_DEV_U32, &devreg->int_enable, 0);
696 P54U_READ(NET2280_DEV_U32, &devreg->ctrl_stat);
697 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET);
698 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RAMBOOT);
699 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_CLKRUN);
700 P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg);
704 reg |= cpu_to_le32(ISL38XX_CTRL_STAT_RESET);
705 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 /* finally, we can upload firmware now! */
718 remains = fw_entry->size;
719 data = fw_entry->data;
720 offset = ISL38XX_DEV_FIRMWARE_ADDR;
723 unsigned int block_len = min(remains, (unsigned int)512);
724 memcpy(buf, data, block_len);
726 err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, block_len);
728 dev_err(&priv->udev->dev, "(p54usb) firmware block "
733 P54U_WRITE(NET2280_DEV_U32, &devreg->direct_mem_base,
734 cpu_to_le32(0xc0000f00));
736 P54U_WRITE(NET2280_DEV_U32,
737 0x0020 | (unsigned long)&devreg->direct_mem_win, 0);
738 P54U_WRITE(NET2280_DEV_U32,
739 0x0020 | (unsigned long)&devreg->direct_mem_win,
742 P54U_WRITE(NET2280_DEV_U32,
743 0x0024 | (unsigned long)&devreg->direct_mem_win,
744 cpu_to_le32(block_len));
745 P54U_WRITE(NET2280_DEV_U32,
746 0x0028 | (unsigned long)&devreg->direct_mem_win,
747 cpu_to_le32(offset));
749 P54U_WRITE(NET2280_DEV_U32, &devreg->dma_addr,
750 cpu_to_le32(NET2280_EPA_FIFO_PCI_ADDR));
751 P54U_WRITE(NET2280_DEV_U32, &devreg->dma_len,
752 cpu_to_le32(block_len >> 2));
753 P54U_WRITE(NET2280_DEV_U32, &devreg->dma_ctrl,
754 cpu_to_le32(ISL38XX_DMA_MASTER_CONTROL_TRIGGER));
758 P54U_READ(NET2280_DEV_U32,
759 0x002C | (unsigned long)&devreg->direct_mem_win);
760 if (!(reg & cpu_to_le32(ISL38XX_DMA_STATUS_DONE)) ||
761 !(reg & cpu_to_le32(ISL38XX_DMA_STATUS_READY))) {
762 dev_err(&priv->udev->dev, "(p54usb) firmware DMA "
763 "transfer failed\n");
767 P54U_WRITE(NET2280_BRG_U32, NET2280_EPA_STAT,
768 cpu_to_le32(NET2280_FIFO_FLUSH));
770 remains -= block_len;
776 P54U_READ(NET2280_DEV_U32, &devreg->ctrl_stat);
777 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET);
778 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_CLKRUN);
779 reg |= cpu_to_le32(ISL38XX_CTRL_STAT_RAMBOOT);
780 P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg);
784 reg |= cpu_to_le32(ISL38XX_CTRL_STAT_RESET);
785 P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg);
787 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET);
788 P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg);
792 P54U_READ(NET2280_DEV_U32, &devreg->int_ident);
793 P54U_WRITE(NET2280_DEV_U32, &devreg->int_ack, reg);
795 /* start up the firmware */
796 P54U_WRITE(NET2280_DEV_U32, &devreg->int_enable,
797 cpu_to_le32(ISL38XX_INT_IDENT_INIT));
799 P54U_WRITE(NET2280_BRG_U32, NET2280_IRQSTAT1,
800 cpu_to_le32(NET2280_PCI_INTA_INTERRUPT));
802 P54U_WRITE(NET2280_BRG_U32, NET2280_USBIRQENB1,
803 cpu_to_le32(NET2280_PCI_INTA_INTERRUPT_ENABLE |
804 NET2280_USB_INTERRUPT_ENABLE));
806 P54U_WRITE(NET2280_DEV_U32, &devreg->dev_int,
807 cpu_to_le32(ISL38XX_DEV_INT_RESET));
809 err = usb_interrupt_msg(priv->udev,
810 usb_rcvbulkpipe(priv->udev, P54U_PIPE_INT),
811 buf, sizeof(__le32), &alen, 1000);
812 if (err || alen != sizeof(__le32))
815 P54U_READ(NET2280_DEV_U32, &devreg->int_ident);
816 P54U_WRITE(NET2280_DEV_U32, &devreg->int_ack, reg);
818 if (!(reg & cpu_to_le32(ISL38XX_INT_IDENT_INIT)))
821 P54U_WRITE(NET2280_BRG_U32, NET2280_USBIRQENB1, 0);
822 P54U_WRITE(NET2280_BRG_U32, NET2280_IRQSTAT1,
823 cpu_to_le32(NET2280_PCI_INTA_INTERRUPT));
829 release_firmware(fw_entry);
834 static int p54u_open(struct ieee80211_hw *dev)
836 struct p54u_priv *priv = dev->priv;
839 err = p54u_init_urbs(dev);
844 priv->common.open = p54u_init_urbs;
849 static void p54u_stop(struct ieee80211_hw *dev)
851 /* TODO: figure out how to reliably stop the 3887 and net2280 so
852 the hardware is still usable next time we want to start it.
853 until then, we just stop listening to the hardware.. */
858 static int __devinit p54u_probe(struct usb_interface *intf,
859 const struct usb_device_id *id)
861 struct usb_device *udev = interface_to_usbdev(intf);
862 struct ieee80211_hw *dev;
863 struct p54u_priv *priv;
865 unsigned int i, recognized_pipes;
867 dev = p54_init_common(sizeof(*priv));
870 dev_err(&udev->dev, "(p54usb) ieee80211 alloc failed\n");
876 SET_IEEE80211_DEV(dev, &intf->dev);
877 usb_set_intfdata(intf, dev);
882 /* really lazy and simple way of figuring out if we're a 3887 */
883 /* TODO: should just stick the identification in the device table */
884 i = intf->altsetting->desc.bNumEndpoints;
885 recognized_pipes = 0;
887 switch (intf->altsetting->endpoint[i].desc.bEndpointAddress) {
892 case P54U_PIPE_DATA | USB_DIR_IN:
893 case P54U_PIPE_MGMT | USB_DIR_IN:
894 case P54U_PIPE_BRG | USB_DIR_IN:
895 case P54U_PIPE_DEV | USB_DIR_IN:
896 case P54U_PIPE_INT | USB_DIR_IN:
900 priv->common.open = p54u_open;
901 priv->common.stop = p54u_stop;
902 if (recognized_pipes < P54U_PIPE_NUMBER) {
903 priv->hw_type = P54U_3887;
904 err = p54u_upload_firmware_3887(dev);
905 if (priv->common.fw_interface == FW_LM87) {
906 dev->extra_tx_headroom += sizeof(struct lm87_tx_hdr);
907 priv->common.tx_hdr_len = sizeof(struct lm87_tx_hdr);
908 priv->common.tx = p54u_tx_lm87;
910 priv->common.tx = p54u_tx_3887;
912 priv->hw_type = P54U_NET2280;
913 dev->extra_tx_headroom += sizeof(struct net2280_tx_hdr);
914 priv->common.tx_hdr_len = sizeof(struct net2280_tx_hdr);
915 priv->common.tx = p54u_tx_net2280;
916 err = p54u_upload_firmware_net2280(dev);
921 skb_queue_head_init(&priv->rx_queue);
922 init_usb_anchor(&priv->submitted);
925 err = p54_read_eeprom(dev);
930 err = ieee80211_register_hw(dev);
932 dev_err(&udev->dev, "(p54usb) Cannot register netdevice\n");
939 ieee80211_free_hw(dev);
940 usb_set_intfdata(intf, NULL);
945 static void __devexit p54u_disconnect(struct usb_interface *intf)
947 struct ieee80211_hw *dev = usb_get_intfdata(intf);
948 struct p54u_priv *priv;
953 ieee80211_unregister_hw(dev);
956 usb_put_dev(interface_to_usbdev(intf));
957 p54_free_common(dev);
958 ieee80211_free_hw(dev);
961 static struct usb_driver p54u_driver = {
963 .id_table = p54u_table,
965 .disconnect = p54u_disconnect,
968 static int __init p54u_init(void)
970 return usb_register(&p54u_driver);
973 static void __exit p54u_exit(void)
975 usb_deregister(&p54u_driver);
978 module_init(p54u_init);
979 module_exit(p54u_exit);