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(0x1413, 0x5400)}, /* Telsey 802.11g USB2.0 Adapter */
75 {USB_DEVICE(0x1435, 0x0427)}, /* Inventel UR054G */
76 {USB_DEVICE(0x2001, 0x3704)}, /* DLink DWL-G122 rev A2 */
77 {USB_DEVICE(0x413c, 0x8102)}, /* Spinnaker DUT */
78 {USB_DEVICE(0x413c, 0x8104)}, /* Cohiba Proto board */
82 MODULE_DEVICE_TABLE(usb, p54u_table);
84 static void p54u_rx_cb(struct urb *urb)
86 struct sk_buff *skb = (struct sk_buff *) urb->context;
87 struct p54u_rx_info *info = (struct p54u_rx_info *)skb->cb;
88 struct ieee80211_hw *dev = info->dev;
89 struct p54u_priv *priv = dev->priv;
91 skb_unlink(skb, &priv->rx_queue);
93 if (unlikely(urb->status)) {
94 dev_kfree_skb_irq(skb);
98 skb_put(skb, urb->actual_length);
100 if (priv->hw_type == P54U_NET2280)
101 skb_pull(skb, priv->common.tx_hdr_len);
102 if (priv->common.fw_interface == FW_LM87) {
107 if (p54_rx(dev, skb)) {
108 skb = dev_alloc_skb(priv->common.rx_mtu + 32);
109 if (unlikely(!skb)) {
110 /* TODO check rx queue length and refill *somewhere* */
114 info = (struct p54u_rx_info *) skb->cb;
117 urb->transfer_buffer = skb_tail_pointer(skb);
120 if (priv->hw_type == P54U_NET2280)
121 skb_push(skb, priv->common.tx_hdr_len);
122 if (priv->common.fw_interface == FW_LM87) {
126 skb_reset_tail_pointer(skb);
128 if (urb->transfer_buffer != skb_tail_pointer(skb)) {
129 /* this should not happen */
131 urb->transfer_buffer = skb_tail_pointer(skb);
134 skb_queue_tail(&priv->rx_queue, skb);
135 usb_anchor_urb(urb, &priv->submitted);
136 if (usb_submit_urb(urb, GFP_ATOMIC)) {
137 skb_unlink(skb, &priv->rx_queue);
138 usb_unanchor_urb(urb);
139 dev_kfree_skb_irq(skb);
143 static void p54u_tx_cb(struct urb *urb)
145 struct sk_buff *skb = urb->context;
146 struct ieee80211_hw *dev = (struct ieee80211_hw *)
147 usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0));
149 p54_free_skb(dev, skb);
152 static void p54u_tx_dummy_cb(struct urb *urb) { }
154 static void p54u_free_urbs(struct ieee80211_hw *dev)
156 struct p54u_priv *priv = dev->priv;
157 usb_kill_anchored_urbs(&priv->submitted);
160 static int p54u_init_urbs(struct ieee80211_hw *dev)
162 struct p54u_priv *priv = dev->priv;
163 struct urb *entry = NULL;
165 struct p54u_rx_info *info;
168 while (skb_queue_len(&priv->rx_queue) < 32) {
169 skb = __dev_alloc_skb(priv->common.rx_mtu + 32, GFP_KERNEL);
174 entry = usb_alloc_urb(0, GFP_KERNEL);
180 usb_fill_bulk_urb(entry, priv->udev,
181 usb_rcvbulkpipe(priv->udev, P54U_PIPE_DATA),
182 skb_tail_pointer(skb),
183 priv->common.rx_mtu + 32, p54u_rx_cb, skb);
184 info = (struct p54u_rx_info *) skb->cb;
187 skb_queue_tail(&priv->rx_queue, skb);
189 usb_anchor_urb(entry, &priv->submitted);
190 ret = usb_submit_urb(entry, GFP_KERNEL);
192 skb_unlink(skb, &priv->rx_queue);
193 usb_unanchor_urb(entry);
209 static void p54u_tx_3887(struct ieee80211_hw *dev, struct sk_buff *skb)
211 struct p54u_priv *priv = dev->priv;
212 struct urb *addr_urb, *data_urb;
215 addr_urb = usb_alloc_urb(0, GFP_ATOMIC);
219 data_urb = usb_alloc_urb(0, GFP_ATOMIC);
221 usb_free_urb(addr_urb);
225 usb_fill_bulk_urb(addr_urb, priv->udev,
226 usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA),
227 &((struct p54_hdr *)skb->data)->req_id, 4,
228 p54u_tx_dummy_cb, dev);
229 usb_fill_bulk_urb(data_urb, priv->udev,
230 usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA),
231 skb->data, skb->len, FREE_AFTER_TX(skb) ?
232 p54u_tx_cb : p54u_tx_dummy_cb, skb);
233 addr_urb->transfer_flags |= URB_ZERO_PACKET;
234 data_urb->transfer_flags |= URB_ZERO_PACKET;
236 usb_anchor_urb(addr_urb, &priv->submitted);
237 err = usb_submit_urb(addr_urb, GFP_ATOMIC);
239 usb_unanchor_urb(addr_urb);
243 usb_anchor_urb(data_urb, &priv->submitted);
244 err = usb_submit_urb(data_urb, GFP_ATOMIC);
246 usb_unanchor_urb(data_urb);
249 usb_free_urb(addr_urb);
250 usb_free_urb(data_urb);
253 p54_free_skb(dev, skb);
256 static __le32 p54u_lm87_chksum(const __le32 *data, size_t length)
262 chk ^= le32_to_cpu(*data++);
263 chk = (chk >> 5) ^ (chk << 3);
266 return cpu_to_le32(chk);
269 static void p54u_tx_lm87(struct ieee80211_hw *dev, struct sk_buff *skb)
271 struct p54u_priv *priv = dev->priv;
272 struct urb *data_urb;
273 struct lm87_tx_hdr *hdr = (void *)skb->data - sizeof(*hdr);
275 data_urb = usb_alloc_urb(0, GFP_ATOMIC);
279 hdr->chksum = p54u_lm87_chksum((__le32 *)skb->data, skb->len);
280 hdr->device_addr = ((struct p54_hdr *)skb->data)->req_id;
282 usb_fill_bulk_urb(data_urb, priv->udev,
283 usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA),
284 hdr, skb->len + sizeof(*hdr), FREE_AFTER_TX(skb) ?
285 p54u_tx_cb : p54u_tx_dummy_cb, skb);
286 data_urb->transfer_flags |= URB_ZERO_PACKET;
288 usb_anchor_urb(data_urb, &priv->submitted);
289 if (usb_submit_urb(data_urb, GFP_ATOMIC)) {
290 usb_unanchor_urb(data_urb);
291 p54_free_skb(dev, skb);
293 usb_free_urb(data_urb);
296 static void p54u_tx_net2280(struct ieee80211_hw *dev, struct sk_buff *skb)
298 struct p54u_priv *priv = dev->priv;
299 struct urb *int_urb, *data_urb;
300 struct net2280_tx_hdr *hdr = (void *)skb->data - sizeof(*hdr);
301 struct net2280_reg_write *reg;
304 reg = kmalloc(sizeof(*reg), GFP_ATOMIC);
308 int_urb = usb_alloc_urb(0, GFP_ATOMIC);
314 data_urb = usb_alloc_urb(0, GFP_ATOMIC);
317 usb_free_urb(int_urb);
321 reg->port = cpu_to_le16(NET2280_DEV_U32);
322 reg->addr = cpu_to_le32(P54U_DEV_BASE);
323 reg->val = cpu_to_le32(ISL38XX_DEV_INT_DATA);
325 memset(hdr, 0, sizeof(*hdr));
326 hdr->len = cpu_to_le16(skb->len);
327 hdr->device_addr = ((struct p54_hdr *) skb->data)->req_id;
329 usb_fill_bulk_urb(int_urb, priv->udev,
330 usb_sndbulkpipe(priv->udev, P54U_PIPE_DEV), reg, sizeof(*reg),
331 p54u_tx_dummy_cb, dev);
334 * This flag triggers a code path in the USB subsystem that will
335 * free what's inside the transfer_buffer after the callback routine
338 int_urb->transfer_flags |= URB_FREE_BUFFER | URB_ZERO_PACKET;
340 usb_fill_bulk_urb(data_urb, priv->udev,
341 usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA),
342 hdr, skb->len + sizeof(*hdr), FREE_AFTER_TX(skb) ?
343 p54u_tx_cb : p54u_tx_dummy_cb, skb);
344 data_urb->transfer_flags |= URB_ZERO_PACKET;
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 const char p54u_romboot_3887[] = "~~~~";
429 static const char p54u_firmware_upload_3887[] = "<\r";
431 static int p54u_device_reset_3887(struct ieee80211_hw *dev)
433 struct p54u_priv *priv = dev->priv;
434 int ret, lock = (priv->intf->condition != USB_INTERFACE_BINDING);
438 ret = usb_lock_device_for_reset(priv->udev, priv->intf);
440 dev_err(&priv->udev->dev, "(p54usb) unable to lock "
441 " device for reset: %d\n", ret);
446 ret = usb_reset_device(priv->udev);
448 usb_unlock_device(priv->udev);
451 dev_err(&priv->udev->dev, "(p54usb) unable to reset "
452 "device: %d\n", ret);
456 memcpy(&buf, p54u_romboot_3887, sizeof(buf));
457 ret = p54u_bulk_msg(priv, P54U_PIPE_DATA,
460 dev_err(&priv->udev->dev, "(p54usb) unable to jump to "
461 "boot ROM: %d\n", ret);
466 static int p54u_upload_firmware_3887(struct ieee80211_hw *dev)
468 struct p54u_priv *priv = dev->priv;
469 const struct firmware *fw_entry = NULL;
474 unsigned int left, remains, block_size;
475 struct x2_header *hdr;
476 unsigned long timeout;
478 tmp = buf = kmalloc(P54U_FW_BLOCK, GFP_KERNEL);
480 dev_err(&priv->udev->dev, "(p54usb) cannot allocate firmware"
486 err = p54u_device_reset_3887(dev);
490 err = request_firmware(&fw_entry, "isl3887usb", &priv->udev->dev);
492 dev_err(&priv->udev->dev, "p54usb: cannot find firmware "
494 err = request_firmware(&fw_entry, "isl3887usb_bare",
497 goto err_req_fw_failed;
500 err = p54_parse_firmware(dev, fw_entry);
502 goto err_upload_failed;
504 if (priv->common.fw_interface != FW_LM87) {
505 dev_err(&priv->udev->dev, "wrong firmware, "
506 "please get a LM87 firmware and try again.\n");
508 goto err_upload_failed;
511 left = block_size = min((size_t)P54U_FW_BLOCK, fw_entry->size);
512 strcpy(buf, p54u_firmware_upload_3887);
513 left -= strlen(p54u_firmware_upload_3887);
514 tmp += strlen(p54u_firmware_upload_3887);
516 data = fw_entry->data;
517 remains = fw_entry->size;
519 hdr = (struct x2_header *)(buf + strlen(p54u_firmware_upload_3887));
520 memcpy(hdr->signature, X2_SIGNATURE, X2_SIGNATURE_SIZE);
521 hdr->fw_load_addr = cpu_to_le32(ISL38XX_DEV_FIRMWARE_ADDR);
522 hdr->fw_length = cpu_to_le32(fw_entry->size);
523 hdr->crc = cpu_to_le32(~crc32_le(~0, (void *)&hdr->fw_load_addr,
525 left -= sizeof(*hdr);
553 err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, block_size);
555 dev_err(&priv->udev->dev, "(p54usb) firmware "
557 goto err_upload_failed;
561 left = block_size = min((unsigned int)P54U_FW_BLOCK, remains);
564 *((__le32 *)buf) = cpu_to_le32(~crc32_le(~0, fw_entry->data, fw_entry->size));
565 err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, sizeof(u32));
567 dev_err(&priv->udev->dev, "(p54usb) firmware upload failed!\n");
568 goto err_upload_failed;
570 timeout = jiffies + msecs_to_jiffies(1000);
571 while (!(err = usb_bulk_msg(priv->udev,
572 usb_rcvbulkpipe(priv->udev, P54U_PIPE_DATA), buf, 128, &alen, 1000))) {
573 if (alen > 2 && !memcmp(buf, "OK", 2))
576 if (alen > 5 && !memcmp(buf, "ERROR", 5)) {
581 if (time_after(jiffies, timeout)) {
582 dev_err(&priv->udev->dev, "(p54usb) firmware boot "
589 dev_err(&priv->udev->dev, "(p54usb) firmware upload failed!\n");
590 goto err_upload_failed;
595 err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, 2);
597 dev_err(&priv->udev->dev, "(p54usb) firmware boot failed!\n");
598 goto err_upload_failed;
601 timeout = jiffies + msecs_to_jiffies(1000);
602 while (!(err = usb_bulk_msg(priv->udev,
603 usb_rcvbulkpipe(priv->udev, P54U_PIPE_DATA), buf, 128, &alen, 1000))) {
604 if (alen > 0 && buf[0] == 'g')
607 if (time_after(jiffies, timeout)) {
613 goto err_upload_failed;
616 release_firmware(fw_entry);
624 static int p54u_upload_firmware_net2280(struct ieee80211_hw *dev)
626 struct p54u_priv *priv = dev->priv;
627 const struct firmware *fw_entry = NULL;
628 const struct p54p_csr *devreg = (const struct p54p_csr *) P54U_DEV_BASE;
632 unsigned int remains, offset;
635 buf = kmalloc(512, GFP_KERNEL);
637 dev_err(&priv->udev->dev, "(p54usb) firmware buffer "
642 err = request_firmware(&fw_entry, "isl3886usb", &priv->udev->dev);
644 dev_err(&priv->udev->dev, "(p54usb) cannot find firmware "
646 err = request_firmware(&fw_entry, "isl3890usb",
654 err = p54_parse_firmware(dev, fw_entry);
657 release_firmware(fw_entry);
661 if (priv->common.fw_interface != FW_LM86) {
662 dev_err(&priv->udev->dev, "wrong firmware, "
663 "please get a LM86(USB) firmware and try again.\n");
665 release_firmware(fw_entry);
669 #define P54U_WRITE(type, addr, data) \
671 err = p54u_write(priv, buf, type,\
672 cpu_to_le32((u32)(unsigned long)addr), data);\
677 #define P54U_READ(type, addr) \
679 err = p54u_read(priv, buf, type,\
680 cpu_to_le32((u32)(unsigned long)addr), ®);\
685 /* power down net2280 bridge */
686 P54U_READ(NET2280_BRG_U32, NET2280_GPIOCTL);
687 reg |= cpu_to_le32(P54U_BRG_POWER_DOWN);
688 reg &= cpu_to_le32(~P54U_BRG_POWER_UP);
689 P54U_WRITE(NET2280_BRG_U32, NET2280_GPIOCTL, reg);
693 /* power up bridge */
694 reg |= cpu_to_le32(P54U_BRG_POWER_UP);
695 reg &= cpu_to_le32(~P54U_BRG_POWER_DOWN);
696 P54U_WRITE(NET2280_BRG_U32, NET2280_GPIOCTL, reg);
700 P54U_WRITE(NET2280_BRG_U32, NET2280_DEVINIT,
701 cpu_to_le32(NET2280_CLK_30Mhz |
703 NET2280_PCI_SOFT_RESET));
707 P54U_WRITE(NET2280_BRG_CFG_U16, PCI_COMMAND,
708 cpu_to_le32(PCI_COMMAND_MEMORY |
709 PCI_COMMAND_MASTER));
711 P54U_WRITE(NET2280_BRG_CFG_U32, PCI_BASE_ADDRESS_0,
712 cpu_to_le32(NET2280_BASE));
714 P54U_READ(NET2280_BRG_CFG_U16, PCI_STATUS);
715 reg |= cpu_to_le32(PCI_STATUS_REC_MASTER_ABORT);
716 P54U_WRITE(NET2280_BRG_CFG_U16, PCI_STATUS, reg);
718 // TODO: we really need this?
719 P54U_READ(NET2280_BRG_U32, NET2280_RELNUM);
721 P54U_WRITE(NET2280_BRG_U32, NET2280_EPA_RSP,
722 cpu_to_le32(NET2280_CLEAR_NAK_OUT_PACKETS_MODE));
723 P54U_WRITE(NET2280_BRG_U32, NET2280_EPC_RSP,
724 cpu_to_le32(NET2280_CLEAR_NAK_OUT_PACKETS_MODE));
726 P54U_WRITE(NET2280_BRG_CFG_U32, PCI_BASE_ADDRESS_2,
727 cpu_to_le32(NET2280_BASE2));
729 /* finally done setting up the bridge */
731 P54U_WRITE(NET2280_DEV_CFG_U16, 0x10000 | PCI_COMMAND,
732 cpu_to_le32(PCI_COMMAND_MEMORY |
733 PCI_COMMAND_MASTER));
735 P54U_WRITE(NET2280_DEV_CFG_U16, 0x10000 | 0x40 /* TRDY timeout */, 0);
736 P54U_WRITE(NET2280_DEV_CFG_U32, 0x10000 | PCI_BASE_ADDRESS_0,
737 cpu_to_le32(P54U_DEV_BASE));
739 P54U_WRITE(NET2280_BRG_U32, NET2280_USBIRQENB1, 0);
740 P54U_WRITE(NET2280_BRG_U32, NET2280_IRQSTAT1,
741 cpu_to_le32(NET2280_PCI_INTA_INTERRUPT));
744 P54U_WRITE(NET2280_DEV_U32, &devreg->int_enable, 0);
746 P54U_READ(NET2280_DEV_U32, &devreg->ctrl_stat);
747 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET);
748 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RAMBOOT);
749 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_CLKRUN);
750 P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg);
754 reg |= cpu_to_le32(ISL38XX_CTRL_STAT_RESET);
755 P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg);
759 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET);
760 P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg);
764 P54U_READ(NET2280_DEV_U32, &devreg->int_ident);
765 P54U_WRITE(NET2280_DEV_U32, &devreg->int_ack, reg);
767 /* finally, we can upload firmware now! */
768 remains = fw_entry->size;
769 data = fw_entry->data;
770 offset = ISL38XX_DEV_FIRMWARE_ADDR;
773 unsigned int block_len = min(remains, (unsigned int)512);
774 memcpy(buf, data, block_len);
776 err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, block_len);
778 dev_err(&priv->udev->dev, "(p54usb) firmware block "
783 P54U_WRITE(NET2280_DEV_U32, &devreg->direct_mem_base,
784 cpu_to_le32(0xc0000f00));
786 P54U_WRITE(NET2280_DEV_U32,
787 0x0020 | (unsigned long)&devreg->direct_mem_win, 0);
788 P54U_WRITE(NET2280_DEV_U32,
789 0x0020 | (unsigned long)&devreg->direct_mem_win,
792 P54U_WRITE(NET2280_DEV_U32,
793 0x0024 | (unsigned long)&devreg->direct_mem_win,
794 cpu_to_le32(block_len));
795 P54U_WRITE(NET2280_DEV_U32,
796 0x0028 | (unsigned long)&devreg->direct_mem_win,
797 cpu_to_le32(offset));
799 P54U_WRITE(NET2280_DEV_U32, &devreg->dma_addr,
800 cpu_to_le32(NET2280_EPA_FIFO_PCI_ADDR));
801 P54U_WRITE(NET2280_DEV_U32, &devreg->dma_len,
802 cpu_to_le32(block_len >> 2));
803 P54U_WRITE(NET2280_DEV_U32, &devreg->dma_ctrl,
804 cpu_to_le32(ISL38XX_DMA_MASTER_CONTROL_TRIGGER));
808 P54U_READ(NET2280_DEV_U32,
809 0x002C | (unsigned long)&devreg->direct_mem_win);
810 if (!(reg & cpu_to_le32(ISL38XX_DMA_STATUS_DONE)) ||
811 !(reg & cpu_to_le32(ISL38XX_DMA_STATUS_READY))) {
812 dev_err(&priv->udev->dev, "(p54usb) firmware DMA "
813 "transfer failed\n");
817 P54U_WRITE(NET2280_BRG_U32, NET2280_EPA_STAT,
818 cpu_to_le32(NET2280_FIFO_FLUSH));
820 remains -= block_len;
826 P54U_READ(NET2280_DEV_U32, &devreg->ctrl_stat);
827 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET);
828 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_CLKRUN);
829 reg |= cpu_to_le32(ISL38XX_CTRL_STAT_RAMBOOT);
830 P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg);
834 reg |= cpu_to_le32(ISL38XX_CTRL_STAT_RESET);
835 P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg);
837 reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET);
838 P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg);
842 P54U_READ(NET2280_DEV_U32, &devreg->int_ident);
843 P54U_WRITE(NET2280_DEV_U32, &devreg->int_ack, reg);
845 /* start up the firmware */
846 P54U_WRITE(NET2280_DEV_U32, &devreg->int_enable,
847 cpu_to_le32(ISL38XX_INT_IDENT_INIT));
849 P54U_WRITE(NET2280_BRG_U32, NET2280_IRQSTAT1,
850 cpu_to_le32(NET2280_PCI_INTA_INTERRUPT));
852 P54U_WRITE(NET2280_BRG_U32, NET2280_USBIRQENB1,
853 cpu_to_le32(NET2280_PCI_INTA_INTERRUPT_ENABLE |
854 NET2280_USB_INTERRUPT_ENABLE));
856 P54U_WRITE(NET2280_DEV_U32, &devreg->dev_int,
857 cpu_to_le32(ISL38XX_DEV_INT_RESET));
859 err = usb_interrupt_msg(priv->udev,
860 usb_rcvbulkpipe(priv->udev, P54U_PIPE_INT),
861 buf, sizeof(__le32), &alen, 1000);
862 if (err || alen != sizeof(__le32))
865 P54U_READ(NET2280_DEV_U32, &devreg->int_ident);
866 P54U_WRITE(NET2280_DEV_U32, &devreg->int_ack, reg);
868 if (!(reg & cpu_to_le32(ISL38XX_INT_IDENT_INIT)))
871 P54U_WRITE(NET2280_BRG_U32, NET2280_USBIRQENB1, 0);
872 P54U_WRITE(NET2280_BRG_U32, NET2280_IRQSTAT1,
873 cpu_to_le32(NET2280_PCI_INTA_INTERRUPT));
879 release_firmware(fw_entry);
884 static int p54u_open(struct ieee80211_hw *dev)
886 struct p54u_priv *priv = dev->priv;
889 err = p54u_init_urbs(dev);
894 priv->common.open = p54u_init_urbs;
899 static void p54u_stop(struct ieee80211_hw *dev)
901 /* TODO: figure out how to reliably stop the 3887 and net2280 so
902 the hardware is still usable next time we want to start it.
903 until then, we just stop listening to the hardware.. */
908 static int __devinit p54u_probe(struct usb_interface *intf,
909 const struct usb_device_id *id)
911 struct usb_device *udev = interface_to_usbdev(intf);
912 struct ieee80211_hw *dev;
913 struct p54u_priv *priv;
915 unsigned int i, recognized_pipes;
917 dev = p54_init_common(sizeof(*priv));
920 dev_err(&udev->dev, "(p54usb) ieee80211 alloc failed\n");
926 SET_IEEE80211_DEV(dev, &intf->dev);
927 usb_set_intfdata(intf, dev);
930 skb_queue_head_init(&priv->rx_queue);
931 init_usb_anchor(&priv->submitted);
935 /* really lazy and simple way of figuring out if we're a 3887 */
936 /* TODO: should just stick the identification in the device table */
937 i = intf->altsetting->desc.bNumEndpoints;
938 recognized_pipes = 0;
940 switch (intf->altsetting->endpoint[i].desc.bEndpointAddress) {
945 case P54U_PIPE_DATA | USB_DIR_IN:
946 case P54U_PIPE_MGMT | USB_DIR_IN:
947 case P54U_PIPE_BRG | USB_DIR_IN:
948 case P54U_PIPE_DEV | USB_DIR_IN:
949 case P54U_PIPE_INT | USB_DIR_IN:
953 priv->common.open = p54u_open;
954 priv->common.stop = p54u_stop;
955 if (recognized_pipes < P54U_PIPE_NUMBER) {
956 priv->hw_type = P54U_3887;
957 err = p54u_upload_firmware_3887(dev);
958 if (priv->common.fw_interface == FW_LM87) {
959 dev->extra_tx_headroom += sizeof(struct lm87_tx_hdr);
960 priv->common.tx_hdr_len = sizeof(struct lm87_tx_hdr);
961 priv->common.tx = p54u_tx_lm87;
963 priv->common.tx = p54u_tx_3887;
965 priv->hw_type = P54U_NET2280;
966 dev->extra_tx_headroom += sizeof(struct net2280_tx_hdr);
967 priv->common.tx_hdr_len = sizeof(struct net2280_tx_hdr);
968 priv->common.tx = p54u_tx_net2280;
969 err = p54u_upload_firmware_net2280(dev);
975 err = p54_read_eeprom(dev);
980 err = p54_register_common(dev, &udev->dev);
987 ieee80211_free_hw(dev);
988 usb_set_intfdata(intf, NULL);
993 static void __devexit p54u_disconnect(struct usb_interface *intf)
995 struct ieee80211_hw *dev = usb_get_intfdata(intf);
996 struct p54u_priv *priv;
1001 ieee80211_unregister_hw(dev);
1004 usb_put_dev(interface_to_usbdev(intf));
1005 p54_free_common(dev);
1006 ieee80211_free_hw(dev);
1009 static int p54u_pre_reset(struct usb_interface *intf)
1014 static int p54u_post_reset(struct usb_interface *intf)
1019 static struct usb_driver p54u_driver = {
1021 .id_table = p54u_table,
1022 .probe = p54u_probe,
1023 .disconnect = p54u_disconnect,
1024 .pre_reset = p54u_pre_reset,
1025 .post_reset = p54u_post_reset,
1029 static int __init p54u_init(void)
1031 return usb_register(&p54u_driver);
1034 static void __exit p54u_exit(void)
1036 usb_deregister(&p54u_driver);
1039 module_init(p54u_init);
1040 module_exit(p54u_exit);