Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Linux device driver for USB based Prism54 |
| 4 | * |
| 5 | * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net> |
| 6 | * |
| 7 | * Based on the islsm (softmac prism54) driver, which is: |
| 8 | * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al. |
| 9 | * |
| 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. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/usb.h> |
| 17 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 19 | #include <linux/firmware.h> |
| 20 | #include <linux/etherdevice.h> |
| 21 | #include <linux/delay.h> |
| 22 | #include <linux/crc32.h> |
| 23 | #include <net/mac80211.h> |
| 24 | |
| 25 | #include "p54.h" |
Christian Lamparter | d8c9210 | 2009-06-23 10:39:45 -0500 | [diff] [blame] | 26 | #include "lmac.h" |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 27 | #include "p54usb.h" |
| 28 | |
| 29 | MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>"); |
| 30 | MODULE_DESCRIPTION("Prism54 USB wireless driver"); |
| 31 | MODULE_LICENSE("GPL"); |
| 32 | MODULE_ALIAS("prism54usb"); |
Christian Lamparter | 9a8675d | 2008-10-18 23:04:15 +0200 | [diff] [blame] | 33 | MODULE_FIRMWARE("isl3886usb"); |
| 34 | MODULE_FIRMWARE("isl3887usb"); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 35 | |
Christian Lamparter | 1a92795 | 2010-10-01 22:01:24 +0200 | [diff] [blame] | 36 | /* |
| 37 | * Note: |
| 38 | * |
| 39 | * Always update our wiki's device list (located at: |
| 40 | * http://wireless.kernel.org/en/users/Drivers/p54/devices ), |
| 41 | * whenever you add a new device. |
| 42 | */ |
| 43 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 44 | static struct usb_device_id p54u_table[] __devinitdata = { |
| 45 | /* Version 1 devices (pci chip + net2280) */ |
Christian Lamparter | 16cad7f | 2010-12-11 12:19:48 +0100 | [diff] [blame] | 46 | {USB_DEVICE(0x0411, 0x0050)}, /* Buffalo WLI2-USB2-G54 */ |
Christian Lamparter | 1a92795 | 2010-10-01 22:01:24 +0200 | [diff] [blame] | 47 | {USB_DEVICE(0x045e, 0x00c2)}, /* Microsoft MN-710 */ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 48 | {USB_DEVICE(0x0506, 0x0a11)}, /* 3COM 3CRWE254G72 */ |
Hans de Goede | 05a9a16 | 2010-03-17 14:37:16 +0100 | [diff] [blame] | 49 | {USB_DEVICE(0x06b9, 0x0120)}, /* Thomson SpeedTouch 120g */ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 50 | {USB_DEVICE(0x0707, 0xee06)}, /* SMC 2862W-G */ |
Shimada Hirofumi | 15a69a8 | 2010-02-14 04:16:16 +0900 | [diff] [blame] | 51 | {USB_DEVICE(0x07aa, 0x001c)}, /* Corega CG-WLUSB2GT */ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 52 | {USB_DEVICE(0x083a, 0x4501)}, /* Accton 802.11g WN4501 USB */ |
| 53 | {USB_DEVICE(0x083a, 0x4502)}, /* Siemens Gigaset USB Adapter */ |
Ivo Couckuyt | 1a17582 | 2008-02-20 14:58:00 -0500 | [diff] [blame] | 54 | {USB_DEVICE(0x083a, 0x5501)}, /* Phillips CPWUA054 */ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 55 | {USB_DEVICE(0x0846, 0x4200)}, /* Netgear WG121 */ |
| 56 | {USB_DEVICE(0x0846, 0x4210)}, /* Netgear WG121 the second ? */ |
| 57 | {USB_DEVICE(0x0846, 0x4220)}, /* Netgear WG111 */ |
Christian Lamparter | ec366eb | 2008-10-13 23:41:53 +0200 | [diff] [blame] | 58 | {USB_DEVICE(0x09aa, 0x1000)}, /* Spinnaker Proto board */ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 59 | {USB_DEVICE(0x0cde, 0x0006)}, /* Medion 40900, Roper Europe */ |
Christian Lamparter | 16cad7f | 2010-12-11 12:19:48 +0100 | [diff] [blame] | 60 | {USB_DEVICE(0x0db0, 0x6826)}, /* MSI UB54G (MS-6826) */ |
Christian Lamparter | 1a92795 | 2010-10-01 22:01:24 +0200 | [diff] [blame] | 61 | {USB_DEVICE(0x107b, 0x55f2)}, /* Gateway WGU-210 (Gemtek) */ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 62 | {USB_DEVICE(0x124a, 0x4023)}, /* Shuttle PN15, Airvast WM168g, IOGear GWU513 */ |
Christian Lamparter | 16cad7f | 2010-12-11 12:19:48 +0100 | [diff] [blame] | 63 | {USB_DEVICE(0x1435, 0x0210)}, /* Inventel UR054G */ |
Eduardo Costa | 56e6417 | 2010-12-14 14:37:59 -0600 | [diff] [blame] | 64 | {USB_DEVICE(0x15a9, 0x0002)}, /* Gemtek WUBI-100GW 802.11g */ |
Christian Lamparter | 1a92795 | 2010-10-01 22:01:24 +0200 | [diff] [blame] | 65 | {USB_DEVICE(0x1630, 0x0005)}, /* 2Wire 802.11g USB (v1) / Z-Com */ |
Christian Lamparter | 16cad7f | 2010-12-11 12:19:48 +0100 | [diff] [blame] | 66 | {USB_DEVICE(0x182d, 0x096b)}, /* Sitecom WL-107 */ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 67 | {USB_DEVICE(0x1915, 0x2234)}, /* Linksys WUSB54G OEM */ |
| 68 | {USB_DEVICE(0x1915, 0x2235)}, /* Linksys WUSB54G Portable OEM */ |
| 69 | {USB_DEVICE(0x2001, 0x3701)}, /* DLink DWL-G120 Spinnaker */ |
| 70 | {USB_DEVICE(0x2001, 0x3703)}, /* DLink DWL-G122 */ |
| 71 | {USB_DEVICE(0x5041, 0x2234)}, /* Linksys WUSB54G */ |
| 72 | {USB_DEVICE(0x5041, 0x2235)}, /* Linksys WUSB54G Portable */ |
| 73 | |
| 74 | /* Version 2 devices (3887) */ |
Felix Homann | 4546002 | 2008-05-29 00:36:45 -0700 | [diff] [blame] | 75 | {USB_DEVICE(0x0471, 0x1230)}, /* Philips CPWUA054/00 */ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 76 | {USB_DEVICE(0x050d, 0x7050)}, /* Belkin F5D7050 ver 1000 */ |
| 77 | {USB_DEVICE(0x0572, 0x2000)}, /* Cohiba Proto board */ |
| 78 | {USB_DEVICE(0x0572, 0x2002)}, /* Cohiba Proto board */ |
Christian Lamparter | 1a92795 | 2010-10-01 22:01:24 +0200 | [diff] [blame] | 79 | {USB_DEVICE(0x06a9, 0x000e)}, /* Westell 802.11g USB (A90-211WG-01) */ |
Michiel | 878e6a4 | 2009-01-04 17:22:28 -0600 | [diff] [blame] | 80 | {USB_DEVICE(0x06b9, 0x0121)}, /* Thomson SpeedTouch 121g */ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 81 | {USB_DEVICE(0x0707, 0xee13)}, /* SMC 2862W-G version 2 */ |
| 82 | {USB_DEVICE(0x083a, 0x4521)}, /* Siemens Gigaset USB Adapter 54 version 2 */ |
Jean-François Moine | 5b9a919 | 2010-02-17 10:59:31 -0600 | [diff] [blame] | 83 | {USB_DEVICE(0x083a, 0xf503)}, /* Accton FD7050E ver 1010ec */ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 84 | {USB_DEVICE(0x0846, 0x4240)}, /* Netgear WG111 (v2) */ |
| 85 | {USB_DEVICE(0x0915, 0x2000)}, /* Cohiba Proto board */ |
| 86 | {USB_DEVICE(0x0915, 0x2002)}, /* Cohiba Proto board */ |
| 87 | {USB_DEVICE(0x0baf, 0x0118)}, /* U.S. Robotics U5 802.11g Adapter*/ |
| 88 | {USB_DEVICE(0x0bf8, 0x1009)}, /* FUJITSU E-5400 USB D1700*/ |
Leann Ogasawara | 7484bdc | 2010-06-15 14:01:51 -0700 | [diff] [blame] | 89 | /* {USB_DEVICE(0x0cde, 0x0006)}, * Medion MD40900 already listed above, |
| 90 | * just noting it here for clarity */ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 91 | {USB_DEVICE(0x0cde, 0x0008)}, /* Sagem XG703A */ |
Christian Lamparter | f7f7117 | 2009-09-14 23:08:43 +0200 | [diff] [blame] | 92 | {USB_DEVICE(0x0cde, 0x0015)}, /* Zcomax XG-705A */ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 93 | {USB_DEVICE(0x0d8e, 0x3762)}, /* DLink DWL-G120 Cohiba */ |
Jan Slupski | 43557e1 | 2008-03-10 22:41:18 -0700 | [diff] [blame] | 94 | {USB_DEVICE(0x124a, 0x4025)}, /* IOGear GWU513 (GW3887IK chip) */ |
Christian Lamparter | ec366eb | 2008-10-13 23:41:53 +0200 | [diff] [blame] | 95 | {USB_DEVICE(0x1260, 0xee22)}, /* SMC 2862W-G version 2 */ |
John W. Linville | 387e100 | 2008-02-20 15:06:02 -0500 | [diff] [blame] | 96 | {USB_DEVICE(0x13b1, 0x000a)}, /* Linksys WUSB54G ver 2 */ |
Martti Huttunen | c109810 | 2007-10-04 00:06:00 -0400 | [diff] [blame] | 97 | {USB_DEVICE(0x13B1, 0x000C)}, /* Linksys WUSB54AG */ |
Christian Lamparter | e306240 | 2009-03-29 22:50:28 +0200 | [diff] [blame] | 98 | {USB_DEVICE(0x1413, 0x5400)}, /* Telsey 802.11g USB2.0 Adapter */ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 99 | {USB_DEVICE(0x1435, 0x0427)}, /* Inventel UR054G */ |
Christian Lamparter | 1a92795 | 2010-10-01 22:01:24 +0200 | [diff] [blame] | 100 | {USB_DEVICE(0x1668, 0x1050)}, /* Actiontec 802UIG-1 */ |
Christian Lamparter | 2b799a6 | 2011-02-26 12:58:06 +0100 | [diff] [blame^] | 101 | {USB_DEVICE(0x1740, 0x1000)}, /* Senao NUB-350 */ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 102 | {USB_DEVICE(0x2001, 0x3704)}, /* DLink DWL-G122 rev A2 */ |
Christian Lamparter | 16cad7f | 2010-12-11 12:19:48 +0100 | [diff] [blame] | 103 | {USB_DEVICE(0x2001, 0x3705)}, /* D-Link DWL-G120 rev C1 */ |
Jason Dravet | 0f666a0 | 2010-06-05 15:08:29 -0500 | [diff] [blame] | 104 | {USB_DEVICE(0x413c, 0x5513)}, /* Dell WLA3310 USB Wireless Adapter */ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 105 | {USB_DEVICE(0x413c, 0x8102)}, /* Spinnaker DUT */ |
| 106 | {USB_DEVICE(0x413c, 0x8104)}, /* Cohiba Proto board */ |
| 107 | {} |
| 108 | }; |
| 109 | |
| 110 | MODULE_DEVICE_TABLE(usb, p54u_table); |
| 111 | |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 112 | static const struct { |
| 113 | u32 intf; |
| 114 | enum p54u_hw_type type; |
Samuel Ortiz | 328d84f | 2009-05-27 10:12:51 +0200 | [diff] [blame] | 115 | const char *fw; |
| 116 | const char *fw_legacy; |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 117 | char hw[20]; |
| 118 | } p54u_fwlist[__NUM_P54U_HWTYPES] = { |
| 119 | { |
| 120 | .type = P54U_NET2280, |
| 121 | .intf = FW_LM86, |
| 122 | .fw = "isl3886usb", |
| 123 | .fw_legacy = "isl3890usb", |
| 124 | .hw = "ISL3886 + net2280", |
| 125 | }, |
| 126 | { |
| 127 | .type = P54U_3887, |
| 128 | .intf = FW_LM87, |
| 129 | .fw = "isl3887usb", |
| 130 | .fw_legacy = "isl3887usb_bare", |
| 131 | .hw = "ISL3887", |
| 132 | }, |
| 133 | }; |
| 134 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 135 | static void p54u_rx_cb(struct urb *urb) |
| 136 | { |
| 137 | struct sk_buff *skb = (struct sk_buff *) urb->context; |
| 138 | struct p54u_rx_info *info = (struct p54u_rx_info *)skb->cb; |
| 139 | struct ieee80211_hw *dev = info->dev; |
| 140 | struct p54u_priv *priv = dev->priv; |
| 141 | |
Christian Lamparter | dd397dc | 2008-12-09 15:14:37 +0100 | [diff] [blame] | 142 | skb_unlink(skb, &priv->rx_queue); |
| 143 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 144 | if (unlikely(urb->status)) { |
Christian Lamparter | dd397dc | 2008-12-09 15:14:37 +0100 | [diff] [blame] | 145 | dev_kfree_skb_irq(skb); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 146 | return; |
| 147 | } |
| 148 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 149 | skb_put(skb, urb->actual_length); |
Christian Lamparter | 2b80848 | 2008-09-04 12:29:38 +0200 | [diff] [blame] | 150 | |
| 151 | if (priv->hw_type == P54U_NET2280) |
| 152 | skb_pull(skb, priv->common.tx_hdr_len); |
| 153 | if (priv->common.fw_interface == FW_LM87) { |
| 154 | skb_pull(skb, 4); |
| 155 | skb_put(skb, 4); |
| 156 | } |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 157 | |
| 158 | if (p54_rx(dev, skb)) { |
Christian Lamparter | 4e416a6 | 2008-09-01 22:48:41 +0200 | [diff] [blame] | 159 | skb = dev_alloc_skb(priv->common.rx_mtu + 32); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 160 | if (unlikely(!skb)) { |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 161 | /* TODO check rx queue length and refill *somewhere* */ |
| 162 | return; |
| 163 | } |
| 164 | |
| 165 | info = (struct p54u_rx_info *) skb->cb; |
| 166 | info->urb = urb; |
| 167 | info->dev = dev; |
| 168 | urb->transfer_buffer = skb_tail_pointer(skb); |
| 169 | urb->context = skb; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 170 | } else { |
Christian Lamparter | 2b80848 | 2008-09-04 12:29:38 +0200 | [diff] [blame] | 171 | if (priv->hw_type == P54U_NET2280) |
| 172 | skb_push(skb, priv->common.tx_hdr_len); |
| 173 | if (priv->common.fw_interface == FW_LM87) { |
| 174 | skb_push(skb, 4); |
| 175 | skb_put(skb, 4); |
| 176 | } |
Christian Lamparter | d47c3ce | 2008-08-13 23:41:48 +0200 | [diff] [blame] | 177 | skb_reset_tail_pointer(skb); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 178 | skb_trim(skb, 0); |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 179 | urb->transfer_buffer = skb_tail_pointer(skb); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 180 | } |
Christian Lamparter | dd397dc | 2008-12-09 15:14:37 +0100 | [diff] [blame] | 181 | skb_queue_tail(&priv->rx_queue, skb); |
| 182 | usb_anchor_urb(urb, &priv->submitted); |
| 183 | if (usb_submit_urb(urb, GFP_ATOMIC)) { |
| 184 | skb_unlink(skb, &priv->rx_queue); |
| 185 | usb_unanchor_urb(urb); |
| 186 | dev_kfree_skb_irq(skb); |
| 187 | } |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Christian Lamparter | 0a5ec96 | 2008-12-14 15:05:42 +0100 | [diff] [blame] | 190 | static void p54u_tx_cb(struct urb *urb) |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 191 | { |
| 192 | struct sk_buff *skb = urb->context; |
Joe Perches | b276736 | 2010-11-30 13:42:08 -0800 | [diff] [blame] | 193 | struct ieee80211_hw *dev = |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 194 | usb_get_intfdata(usb_ifnum_to_if(urb->dev, 0)); |
| 195 | |
Christian Lamparter | e2fe154 | 2009-01-20 00:27:57 +0100 | [diff] [blame] | 196 | p54_free_skb(dev, skb); |
Christian Lamparter | dd397dc | 2008-12-09 15:14:37 +0100 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | static void p54u_tx_dummy_cb(struct urb *urb) { } |
| 200 | |
| 201 | static void p54u_free_urbs(struct ieee80211_hw *dev) |
| 202 | { |
| 203 | struct p54u_priv *priv = dev->priv; |
| 204 | usb_kill_anchored_urbs(&priv->submitted); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 205 | } |
| 206 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 207 | static int p54u_init_urbs(struct ieee80211_hw *dev) |
| 208 | { |
| 209 | struct p54u_priv *priv = dev->priv; |
Christian Lamparter | dd397dc | 2008-12-09 15:14:37 +0100 | [diff] [blame] | 210 | struct urb *entry = NULL; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 211 | struct sk_buff *skb; |
| 212 | struct p54u_rx_info *info; |
Christian Lamparter | dd397dc | 2008-12-09 15:14:37 +0100 | [diff] [blame] | 213 | int ret = 0; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 214 | |
| 215 | while (skb_queue_len(&priv->rx_queue) < 32) { |
Christian Lamparter | 4e416a6 | 2008-09-01 22:48:41 +0200 | [diff] [blame] | 216 | skb = __dev_alloc_skb(priv->common.rx_mtu + 32, GFP_KERNEL); |
Christian Lamparter | dd397dc | 2008-12-09 15:14:37 +0100 | [diff] [blame] | 217 | if (!skb) { |
| 218 | ret = -ENOMEM; |
| 219 | goto err; |
| 220 | } |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 221 | entry = usb_alloc_urb(0, GFP_KERNEL); |
| 222 | if (!entry) { |
Christian Lamparter | dd397dc | 2008-12-09 15:14:37 +0100 | [diff] [blame] | 223 | ret = -ENOMEM; |
| 224 | goto err; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 225 | } |
Christian Lamparter | dd397dc | 2008-12-09 15:14:37 +0100 | [diff] [blame] | 226 | |
Christian Lamparter | 4e416a6 | 2008-09-01 22:48:41 +0200 | [diff] [blame] | 227 | usb_fill_bulk_urb(entry, priv->udev, |
| 228 | usb_rcvbulkpipe(priv->udev, P54U_PIPE_DATA), |
| 229 | skb_tail_pointer(skb), |
| 230 | priv->common.rx_mtu + 32, p54u_rx_cb, skb); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 231 | info = (struct p54u_rx_info *) skb->cb; |
| 232 | info->urb = entry; |
| 233 | info->dev = dev; |
| 234 | skb_queue_tail(&priv->rx_queue, skb); |
Christian Lamparter | dd397dc | 2008-12-09 15:14:37 +0100 | [diff] [blame] | 235 | |
| 236 | usb_anchor_urb(entry, &priv->submitted); |
| 237 | ret = usb_submit_urb(entry, GFP_KERNEL); |
| 238 | if (ret) { |
| 239 | skb_unlink(skb, &priv->rx_queue); |
| 240 | usb_unanchor_urb(entry); |
| 241 | goto err; |
| 242 | } |
| 243 | usb_free_urb(entry); |
| 244 | entry = NULL; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | return 0; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 248 | |
Christian Lamparter | dd397dc | 2008-12-09 15:14:37 +0100 | [diff] [blame] | 249 | err: |
| 250 | usb_free_urb(entry); |
| 251 | kfree_skb(skb); |
| 252 | p54u_free_urbs(dev); |
| 253 | return ret; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Johannes Berg | c912765 | 2008-12-01 18:19:36 +0100 | [diff] [blame] | 256 | static __le32 p54u_lm87_chksum(const __le32 *data, size_t length) |
Christian Lamparter | 2b80848 | 2008-09-04 12:29:38 +0200 | [diff] [blame] | 257 | { |
Larry Finger | 1f1c0e3 | 2008-09-25 14:54:28 -0500 | [diff] [blame] | 258 | u32 chk = 0; |
Christian Lamparter | 2b80848 | 2008-09-04 12:29:38 +0200 | [diff] [blame] | 259 | |
| 260 | length >>= 2; |
| 261 | while (length--) { |
Johannes Berg | c912765 | 2008-12-01 18:19:36 +0100 | [diff] [blame] | 262 | chk ^= le32_to_cpu(*data++); |
Christian Lamparter | 2b80848 | 2008-09-04 12:29:38 +0200 | [diff] [blame] | 263 | chk = (chk >> 5) ^ (chk << 3); |
| 264 | } |
| 265 | |
Larry Finger | 1f1c0e3 | 2008-09-25 14:54:28 -0500 | [diff] [blame] | 266 | return cpu_to_le32(chk); |
Christian Lamparter | 2b80848 | 2008-09-04 12:29:38 +0200 | [diff] [blame] | 267 | } |
| 268 | |
Christian Lamparter | 0a5ec96 | 2008-12-14 15:05:42 +0100 | [diff] [blame] | 269 | static void p54u_tx_lm87(struct ieee80211_hw *dev, struct sk_buff *skb) |
Christian Lamparter | 2b80848 | 2008-09-04 12:29:38 +0200 | [diff] [blame] | 270 | { |
| 271 | struct p54u_priv *priv = dev->priv; |
| 272 | struct urb *data_urb; |
Christian Lamparter | e2fe154 | 2009-01-20 00:27:57 +0100 | [diff] [blame] | 273 | struct lm87_tx_hdr *hdr = (void *)skb->data - sizeof(*hdr); |
Christian Lamparter | 2b80848 | 2008-09-04 12:29:38 +0200 | [diff] [blame] | 274 | |
| 275 | data_urb = usb_alloc_urb(0, GFP_ATOMIC); |
Christian Lamparter | 6d541a6 | 2009-07-06 15:17:56 +0200 | [diff] [blame] | 276 | if (!data_urb) { |
| 277 | p54_free_skb(dev, skb); |
Christian Lamparter | 2b80848 | 2008-09-04 12:29:38 +0200 | [diff] [blame] | 278 | return; |
Christian Lamparter | 6d541a6 | 2009-07-06 15:17:56 +0200 | [diff] [blame] | 279 | } |
Christian Lamparter | 2b80848 | 2008-09-04 12:29:38 +0200 | [diff] [blame] | 280 | |
Christian Lamparter | e2fe154 | 2009-01-20 00:27:57 +0100 | [diff] [blame] | 281 | hdr->chksum = p54u_lm87_chksum((__le32 *)skb->data, skb->len); |
| 282 | hdr->device_addr = ((struct p54_hdr *)skb->data)->req_id; |
Christian Lamparter | 2b80848 | 2008-09-04 12:29:38 +0200 | [diff] [blame] | 283 | |
| 284 | usb_fill_bulk_urb(data_urb, priv->udev, |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 285 | usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA), |
Christian Lamparter | e2fe154 | 2009-01-20 00:27:57 +0100 | [diff] [blame] | 286 | hdr, skb->len + sizeof(*hdr), FREE_AFTER_TX(skb) ? |
| 287 | p54u_tx_cb : p54u_tx_dummy_cb, skb); |
Christian Lamparter | 00627f2 | 2008-12-20 02:21:56 +0100 | [diff] [blame] | 288 | data_urb->transfer_flags |= URB_ZERO_PACKET; |
Christian Lamparter | 2b80848 | 2008-09-04 12:29:38 +0200 | [diff] [blame] | 289 | |
Christian Lamparter | dd397dc | 2008-12-09 15:14:37 +0100 | [diff] [blame] | 290 | usb_anchor_urb(data_urb, &priv->submitted); |
| 291 | if (usb_submit_urb(data_urb, GFP_ATOMIC)) { |
| 292 | usb_unanchor_urb(data_urb); |
Christian Lamparter | dd397dc | 2008-12-09 15:14:37 +0100 | [diff] [blame] | 293 | p54_free_skb(dev, skb); |
| 294 | } |
| 295 | usb_free_urb(data_urb); |
Christian Lamparter | 2b80848 | 2008-09-04 12:29:38 +0200 | [diff] [blame] | 296 | } |
| 297 | |
Christian Lamparter | 0a5ec96 | 2008-12-14 15:05:42 +0100 | [diff] [blame] | 298 | static void p54u_tx_net2280(struct ieee80211_hw *dev, struct sk_buff *skb) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 299 | { |
| 300 | struct p54u_priv *priv = dev->priv; |
Christian Lamparter | 6d541a6 | 2009-07-06 15:17:56 +0200 | [diff] [blame] | 301 | struct urb *int_urb = NULL, *data_urb = NULL; |
Christian Lamparter | e2fe154 | 2009-01-20 00:27:57 +0100 | [diff] [blame] | 302 | struct net2280_tx_hdr *hdr = (void *)skb->data - sizeof(*hdr); |
Christian Lamparter | 6d541a6 | 2009-07-06 15:17:56 +0200 | [diff] [blame] | 303 | struct net2280_reg_write *reg = NULL; |
| 304 | int err = -ENOMEM; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 305 | |
| 306 | reg = kmalloc(sizeof(*reg), GFP_ATOMIC); |
| 307 | if (!reg) |
Christian Lamparter | 6d541a6 | 2009-07-06 15:17:56 +0200 | [diff] [blame] | 308 | goto out; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 309 | |
| 310 | int_urb = usb_alloc_urb(0, GFP_ATOMIC); |
Christian Lamparter | 6d541a6 | 2009-07-06 15:17:56 +0200 | [diff] [blame] | 311 | if (!int_urb) |
| 312 | goto out; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 313 | |
| 314 | data_urb = usb_alloc_urb(0, GFP_ATOMIC); |
Christian Lamparter | 6d541a6 | 2009-07-06 15:17:56 +0200 | [diff] [blame] | 315 | if (!data_urb) |
| 316 | goto out; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 317 | |
| 318 | reg->port = cpu_to_le16(NET2280_DEV_U32); |
| 319 | reg->addr = cpu_to_le32(P54U_DEV_BASE); |
| 320 | reg->val = cpu_to_le32(ISL38XX_DEV_INT_DATA); |
| 321 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 322 | memset(hdr, 0, sizeof(*hdr)); |
Christian Lamparter | e2fe154 | 2009-01-20 00:27:57 +0100 | [diff] [blame] | 323 | hdr->len = cpu_to_le16(skb->len); |
| 324 | hdr->device_addr = ((struct p54_hdr *) skb->data)->req_id; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 325 | |
| 326 | usb_fill_bulk_urb(int_urb, priv->udev, |
| 327 | usb_sndbulkpipe(priv->udev, P54U_PIPE_DEV), reg, sizeof(*reg), |
Christian Lamparter | dd397dc | 2008-12-09 15:14:37 +0100 | [diff] [blame] | 328 | p54u_tx_dummy_cb, dev); |
| 329 | |
| 330 | /* |
Christian Lamparter | 6d541a6 | 2009-07-06 15:17:56 +0200 | [diff] [blame] | 331 | * URB_FREE_BUFFER triggers a code path in the USB subsystem that will |
| 332 | * free what is inside the transfer_buffer after the last reference to |
| 333 | * the int_urb is dropped. |
Christian Lamparter | dd397dc | 2008-12-09 15:14:37 +0100 | [diff] [blame] | 334 | */ |
Christian Lamparter | b4068a8 | 2009-01-20 23:11:21 +0100 | [diff] [blame] | 335 | int_urb->transfer_flags |= URB_FREE_BUFFER | URB_ZERO_PACKET; |
Christian Lamparter | 6d541a6 | 2009-07-06 15:17:56 +0200 | [diff] [blame] | 336 | reg = NULL; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 337 | |
| 338 | usb_fill_bulk_urb(data_urb, priv->udev, |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 339 | usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA), |
Christian Lamparter | e2fe154 | 2009-01-20 00:27:57 +0100 | [diff] [blame] | 340 | hdr, skb->len + sizeof(*hdr), FREE_AFTER_TX(skb) ? |
| 341 | p54u_tx_cb : p54u_tx_dummy_cb, skb); |
Christian Lamparter | b4068a8 | 2009-01-20 23:11:21 +0100 | [diff] [blame] | 342 | data_urb->transfer_flags |= URB_ZERO_PACKET; |
Christian Lamparter | dd397dc | 2008-12-09 15:14:37 +0100 | [diff] [blame] | 343 | |
| 344 | usb_anchor_urb(int_urb, &priv->submitted); |
| 345 | err = usb_submit_urb(int_urb, GFP_ATOMIC); |
| 346 | if (err) { |
| 347 | usb_unanchor_urb(int_urb); |
| 348 | goto out; |
| 349 | } |
| 350 | |
| 351 | usb_anchor_urb(data_urb, &priv->submitted); |
| 352 | err = usb_submit_urb(data_urb, GFP_ATOMIC); |
| 353 | if (err) { |
| 354 | usb_unanchor_urb(data_urb); |
| 355 | goto out; |
| 356 | } |
Christian Lamparter | 6d541a6 | 2009-07-06 15:17:56 +0200 | [diff] [blame] | 357 | out: |
Christian Lamparter | dd397dc | 2008-12-09 15:14:37 +0100 | [diff] [blame] | 358 | usb_free_urb(int_urb); |
| 359 | usb_free_urb(data_urb); |
| 360 | |
| 361 | if (err) { |
Christian Lamparter | 6d541a6 | 2009-07-06 15:17:56 +0200 | [diff] [blame] | 362 | kfree(reg); |
Christian Lamparter | dd397dc | 2008-12-09 15:14:37 +0100 | [diff] [blame] | 363 | p54_free_skb(dev, skb); |
| 364 | } |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | static int p54u_write(struct p54u_priv *priv, |
| 368 | struct net2280_reg_write *buf, |
| 369 | enum net2280_op_type type, |
| 370 | __le32 addr, __le32 val) |
| 371 | { |
| 372 | unsigned int ep; |
| 373 | int alen; |
| 374 | |
| 375 | if (type & 0x0800) |
| 376 | ep = usb_sndbulkpipe(priv->udev, P54U_PIPE_DEV); |
| 377 | else |
| 378 | ep = usb_sndbulkpipe(priv->udev, P54U_PIPE_BRG); |
| 379 | |
| 380 | buf->port = cpu_to_le16(type); |
| 381 | buf->addr = addr; |
| 382 | buf->val = val; |
| 383 | |
| 384 | return usb_bulk_msg(priv->udev, ep, buf, sizeof(*buf), &alen, 1000); |
| 385 | } |
| 386 | |
| 387 | static int p54u_read(struct p54u_priv *priv, void *buf, |
| 388 | enum net2280_op_type type, |
| 389 | __le32 addr, __le32 *val) |
| 390 | { |
| 391 | struct net2280_reg_read *read = buf; |
| 392 | __le32 *reg = buf; |
| 393 | unsigned int ep; |
| 394 | int alen, err; |
| 395 | |
| 396 | if (type & 0x0800) |
| 397 | ep = P54U_PIPE_DEV; |
| 398 | else |
| 399 | ep = P54U_PIPE_BRG; |
| 400 | |
| 401 | read->port = cpu_to_le16(type); |
| 402 | read->addr = addr; |
| 403 | |
| 404 | err = usb_bulk_msg(priv->udev, usb_sndbulkpipe(priv->udev, ep), |
| 405 | read, sizeof(*read), &alen, 1000); |
| 406 | if (err) |
| 407 | return err; |
| 408 | |
| 409 | err = usb_bulk_msg(priv->udev, usb_rcvbulkpipe(priv->udev, ep), |
| 410 | reg, sizeof(*reg), &alen, 1000); |
| 411 | if (err) |
| 412 | return err; |
| 413 | |
| 414 | *val = *reg; |
| 415 | return 0; |
| 416 | } |
| 417 | |
| 418 | static int p54u_bulk_msg(struct p54u_priv *priv, unsigned int ep, |
| 419 | void *data, size_t len) |
| 420 | { |
| 421 | int alen; |
| 422 | return usb_bulk_msg(priv->udev, usb_sndbulkpipe(priv->udev, ep), |
| 423 | data, len, &alen, 2000); |
| 424 | } |
| 425 | |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 426 | static int p54u_device_reset(struct ieee80211_hw *dev) |
Christian Lamparter | 6982869 | 2008-12-26 19:08:31 +0100 | [diff] [blame] | 427 | { |
| 428 | struct p54u_priv *priv = dev->priv; |
Christian Lamparter | c88a768 | 2009-01-16 20:24:31 +0100 | [diff] [blame] | 429 | int ret, lock = (priv->intf->condition != USB_INTERFACE_BINDING); |
Christian Lamparter | 6982869 | 2008-12-26 19:08:31 +0100 | [diff] [blame] | 430 | |
Christian Lamparter | c88a768 | 2009-01-16 20:24:31 +0100 | [diff] [blame] | 431 | if (lock) { |
| 432 | ret = usb_lock_device_for_reset(priv->udev, priv->intf); |
| 433 | if (ret < 0) { |
| 434 | dev_err(&priv->udev->dev, "(p54usb) unable to lock " |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 435 | "device for reset (%d)!\n", ret); |
Christian Lamparter | c88a768 | 2009-01-16 20:24:31 +0100 | [diff] [blame] | 436 | return ret; |
| 437 | } |
Christian Lamparter | 6982869 | 2008-12-26 19:08:31 +0100 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | ret = usb_reset_device(priv->udev); |
| 441 | if (lock) |
| 442 | usb_unlock_device(priv->udev); |
| 443 | |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 444 | if (ret) |
Christian Lamparter | 6982869 | 2008-12-26 19:08:31 +0100 | [diff] [blame] | 445 | dev_err(&priv->udev->dev, "(p54usb) unable to reset " |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 446 | "device (%d)!\n", ret); |
| 447 | |
| 448 | return ret; |
| 449 | } |
| 450 | |
| 451 | static const char p54u_romboot_3887[] = "~~~~"; |
| 452 | static int p54u_firmware_reset_3887(struct ieee80211_hw *dev) |
| 453 | { |
| 454 | struct p54u_priv *priv = dev->priv; |
Larry Finger | 21d6c27 | 2009-11-11 18:02:29 -0600 | [diff] [blame] | 455 | u8 *buf; |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 456 | int ret; |
Christian Lamparter | 6982869 | 2008-12-26 19:08:31 +0100 | [diff] [blame] | 457 | |
Julia Lawall | 27b81bb | 2010-05-15 23:22:55 +0200 | [diff] [blame] | 458 | buf = kmemdup(p54u_romboot_3887, 4, GFP_KERNEL); |
Larry Finger | 21d6c27 | 2009-11-11 18:02:29 -0600 | [diff] [blame] | 459 | if (!buf) |
| 460 | return -ENOMEM; |
Christian Lamparter | 6982869 | 2008-12-26 19:08:31 +0100 | [diff] [blame] | 461 | ret = p54u_bulk_msg(priv, P54U_PIPE_DATA, |
Larry Finger | 21d6c27 | 2009-11-11 18:02:29 -0600 | [diff] [blame] | 462 | buf, 4); |
| 463 | kfree(buf); |
Christian Lamparter | 6982869 | 2008-12-26 19:08:31 +0100 | [diff] [blame] | 464 | if (ret) |
| 465 | dev_err(&priv->udev->dev, "(p54usb) unable to jump to " |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 466 | "boot ROM (%d)!\n", ret); |
Christian Lamparter | 6982869 | 2008-12-26 19:08:31 +0100 | [diff] [blame] | 467 | |
| 468 | return ret; |
| 469 | } |
| 470 | |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 471 | static const char p54u_firmware_upload_3887[] = "<\r"; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 472 | static int p54u_upload_firmware_3887(struct ieee80211_hw *dev) |
| 473 | { |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 474 | struct p54u_priv *priv = dev->priv; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 475 | int err, alen; |
| 476 | u8 carry = 0; |
David Woodhouse | 8b72eb4 | 2008-05-24 00:08:55 +0100 | [diff] [blame] | 477 | u8 *buf, *tmp; |
| 478 | const u8 *data; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 479 | unsigned int left, remains, block_size; |
| 480 | struct x2_header *hdr; |
| 481 | unsigned long timeout; |
| 482 | |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 483 | err = p54u_firmware_reset_3887(dev); |
| 484 | if (err) |
| 485 | return err; |
| 486 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 487 | tmp = buf = kmalloc(P54U_FW_BLOCK, GFP_KERNEL); |
| 488 | if (!buf) { |
Christian Lamparter | 02e37ba | 2008-11-29 22:39:08 +0100 | [diff] [blame] | 489 | dev_err(&priv->udev->dev, "(p54usb) cannot allocate firmware" |
| 490 | "upload buffer!\n"); |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 491 | return -ENOMEM; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 492 | } |
| 493 | |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 494 | left = block_size = min((size_t)P54U_FW_BLOCK, priv->fw->size); |
Christian Lamparter | 6982869 | 2008-12-26 19:08:31 +0100 | [diff] [blame] | 495 | strcpy(buf, p54u_firmware_upload_3887); |
| 496 | left -= strlen(p54u_firmware_upload_3887); |
| 497 | tmp += strlen(p54u_firmware_upload_3887); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 498 | |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 499 | data = priv->fw->data; |
| 500 | remains = priv->fw->size; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 501 | |
Christian Lamparter | 6982869 | 2008-12-26 19:08:31 +0100 | [diff] [blame] | 502 | hdr = (struct x2_header *)(buf + strlen(p54u_firmware_upload_3887)); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 503 | memcpy(hdr->signature, X2_SIGNATURE, X2_SIGNATURE_SIZE); |
| 504 | hdr->fw_load_addr = cpu_to_le32(ISL38XX_DEV_FIRMWARE_ADDR); |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 505 | hdr->fw_length = cpu_to_le32(priv->fw->size); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 506 | hdr->crc = cpu_to_le32(~crc32_le(~0, (void *)&hdr->fw_load_addr, |
| 507 | sizeof(u32)*2)); |
| 508 | left -= sizeof(*hdr); |
| 509 | tmp += sizeof(*hdr); |
| 510 | |
| 511 | while (remains) { |
| 512 | while (left--) { |
| 513 | if (carry) { |
| 514 | *tmp++ = carry; |
| 515 | carry = 0; |
| 516 | remains--; |
| 517 | continue; |
| 518 | } |
| 519 | switch (*data) { |
| 520 | case '~': |
| 521 | *tmp++ = '}'; |
| 522 | carry = '^'; |
| 523 | break; |
| 524 | case '}': |
| 525 | *tmp++ = '}'; |
| 526 | carry = ']'; |
| 527 | break; |
| 528 | default: |
| 529 | *tmp++ = *data; |
| 530 | remains--; |
| 531 | break; |
| 532 | } |
| 533 | data++; |
| 534 | } |
| 535 | |
| 536 | err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, block_size); |
| 537 | if (err) { |
Christian Lamparter | 02e37ba | 2008-11-29 22:39:08 +0100 | [diff] [blame] | 538 | dev_err(&priv->udev->dev, "(p54usb) firmware " |
| 539 | "upload failed!\n"); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 540 | goto err_upload_failed; |
| 541 | } |
| 542 | |
| 543 | tmp = buf; |
| 544 | left = block_size = min((unsigned int)P54U_FW_BLOCK, remains); |
| 545 | } |
| 546 | |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 547 | *((__le32 *)buf) = cpu_to_le32(~crc32_le(~0, priv->fw->data, |
| 548 | priv->fw->size)); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 549 | err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, sizeof(u32)); |
| 550 | if (err) { |
Christian Lamparter | 02e37ba | 2008-11-29 22:39:08 +0100 | [diff] [blame] | 551 | dev_err(&priv->udev->dev, "(p54usb) firmware upload failed!\n"); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 552 | goto err_upload_failed; |
| 553 | } |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 554 | timeout = jiffies + msecs_to_jiffies(1000); |
| 555 | while (!(err = usb_bulk_msg(priv->udev, |
| 556 | usb_rcvbulkpipe(priv->udev, P54U_PIPE_DATA), buf, 128, &alen, 1000))) { |
| 557 | if (alen > 2 && !memcmp(buf, "OK", 2)) |
| 558 | break; |
| 559 | |
| 560 | if (alen > 5 && !memcmp(buf, "ERROR", 5)) { |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 561 | err = -EINVAL; |
| 562 | break; |
| 563 | } |
| 564 | |
| 565 | if (time_after(jiffies, timeout)) { |
Christian Lamparter | 02e37ba | 2008-11-29 22:39:08 +0100 | [diff] [blame] | 566 | dev_err(&priv->udev->dev, "(p54usb) firmware boot " |
| 567 | "timed out!\n"); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 568 | err = -ETIMEDOUT; |
| 569 | break; |
| 570 | } |
| 571 | } |
Christian Lamparter | 02e37ba | 2008-11-29 22:39:08 +0100 | [diff] [blame] | 572 | if (err) { |
| 573 | dev_err(&priv->udev->dev, "(p54usb) firmware upload failed!\n"); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 574 | goto err_upload_failed; |
Christian Lamparter | 02e37ba | 2008-11-29 22:39:08 +0100 | [diff] [blame] | 575 | } |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 576 | |
| 577 | buf[0] = 'g'; |
| 578 | buf[1] = '\r'; |
| 579 | err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, 2); |
| 580 | if (err) { |
Christian Lamparter | 02e37ba | 2008-11-29 22:39:08 +0100 | [diff] [blame] | 581 | dev_err(&priv->udev->dev, "(p54usb) firmware boot failed!\n"); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 582 | goto err_upload_failed; |
| 583 | } |
| 584 | |
| 585 | timeout = jiffies + msecs_to_jiffies(1000); |
| 586 | while (!(err = usb_bulk_msg(priv->udev, |
| 587 | usb_rcvbulkpipe(priv->udev, P54U_PIPE_DATA), buf, 128, &alen, 1000))) { |
| 588 | if (alen > 0 && buf[0] == 'g') |
| 589 | break; |
| 590 | |
| 591 | if (time_after(jiffies, timeout)) { |
| 592 | err = -ETIMEDOUT; |
| 593 | break; |
| 594 | } |
| 595 | } |
| 596 | if (err) |
| 597 | goto err_upload_failed; |
| 598 | |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 599 | err_upload_failed: |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 600 | kfree(buf); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 601 | return err; |
| 602 | } |
| 603 | |
| 604 | static int p54u_upload_firmware_net2280(struct ieee80211_hw *dev) |
| 605 | { |
| 606 | struct p54u_priv *priv = dev->priv; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 607 | const struct p54p_csr *devreg = (const struct p54p_csr *) P54U_DEV_BASE; |
| 608 | int err, alen; |
| 609 | void *buf; |
| 610 | __le32 reg; |
| 611 | unsigned int remains, offset; |
David Woodhouse | 8b72eb4 | 2008-05-24 00:08:55 +0100 | [diff] [blame] | 612 | const u8 *data; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 613 | |
| 614 | buf = kmalloc(512, GFP_KERNEL); |
| 615 | if (!buf) { |
Christian Lamparter | 02e37ba | 2008-11-29 22:39:08 +0100 | [diff] [blame] | 616 | dev_err(&priv->udev->dev, "(p54usb) firmware buffer " |
| 617 | "alloc failed!\n"); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 618 | return -ENOMEM; |
| 619 | } |
| 620 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 621 | #define P54U_WRITE(type, addr, data) \ |
| 622 | do {\ |
| 623 | err = p54u_write(priv, buf, type,\ |
| 624 | cpu_to_le32((u32)(unsigned long)addr), data);\ |
| 625 | if (err) \ |
| 626 | goto fail;\ |
| 627 | } while (0) |
| 628 | |
| 629 | #define P54U_READ(type, addr) \ |
| 630 | do {\ |
| 631 | err = p54u_read(priv, buf, type,\ |
| 632 | cpu_to_le32((u32)(unsigned long)addr), ®);\ |
| 633 | if (err)\ |
| 634 | goto fail;\ |
| 635 | } while (0) |
| 636 | |
| 637 | /* power down net2280 bridge */ |
| 638 | P54U_READ(NET2280_BRG_U32, NET2280_GPIOCTL); |
| 639 | reg |= cpu_to_le32(P54U_BRG_POWER_DOWN); |
| 640 | reg &= cpu_to_le32(~P54U_BRG_POWER_UP); |
| 641 | P54U_WRITE(NET2280_BRG_U32, NET2280_GPIOCTL, reg); |
| 642 | |
| 643 | mdelay(100); |
| 644 | |
| 645 | /* power up bridge */ |
| 646 | reg |= cpu_to_le32(P54U_BRG_POWER_UP); |
| 647 | reg &= cpu_to_le32(~P54U_BRG_POWER_DOWN); |
| 648 | P54U_WRITE(NET2280_BRG_U32, NET2280_GPIOCTL, reg); |
| 649 | |
| 650 | mdelay(100); |
| 651 | |
| 652 | P54U_WRITE(NET2280_BRG_U32, NET2280_DEVINIT, |
| 653 | cpu_to_le32(NET2280_CLK_30Mhz | |
| 654 | NET2280_PCI_ENABLE | |
| 655 | NET2280_PCI_SOFT_RESET)); |
| 656 | |
| 657 | mdelay(20); |
| 658 | |
| 659 | P54U_WRITE(NET2280_BRG_CFG_U16, PCI_COMMAND, |
| 660 | cpu_to_le32(PCI_COMMAND_MEMORY | |
| 661 | PCI_COMMAND_MASTER)); |
| 662 | |
| 663 | P54U_WRITE(NET2280_BRG_CFG_U32, PCI_BASE_ADDRESS_0, |
| 664 | cpu_to_le32(NET2280_BASE)); |
| 665 | |
| 666 | P54U_READ(NET2280_BRG_CFG_U16, PCI_STATUS); |
| 667 | reg |= cpu_to_le32(PCI_STATUS_REC_MASTER_ABORT); |
| 668 | P54U_WRITE(NET2280_BRG_CFG_U16, PCI_STATUS, reg); |
| 669 | |
| 670 | // TODO: we really need this? |
| 671 | P54U_READ(NET2280_BRG_U32, NET2280_RELNUM); |
| 672 | |
| 673 | P54U_WRITE(NET2280_BRG_U32, NET2280_EPA_RSP, |
| 674 | cpu_to_le32(NET2280_CLEAR_NAK_OUT_PACKETS_MODE)); |
| 675 | P54U_WRITE(NET2280_BRG_U32, NET2280_EPC_RSP, |
| 676 | cpu_to_le32(NET2280_CLEAR_NAK_OUT_PACKETS_MODE)); |
| 677 | |
| 678 | P54U_WRITE(NET2280_BRG_CFG_U32, PCI_BASE_ADDRESS_2, |
| 679 | cpu_to_le32(NET2280_BASE2)); |
| 680 | |
| 681 | /* finally done setting up the bridge */ |
| 682 | |
| 683 | P54U_WRITE(NET2280_DEV_CFG_U16, 0x10000 | PCI_COMMAND, |
| 684 | cpu_to_le32(PCI_COMMAND_MEMORY | |
| 685 | PCI_COMMAND_MASTER)); |
| 686 | |
| 687 | P54U_WRITE(NET2280_DEV_CFG_U16, 0x10000 | 0x40 /* TRDY timeout */, 0); |
| 688 | P54U_WRITE(NET2280_DEV_CFG_U32, 0x10000 | PCI_BASE_ADDRESS_0, |
| 689 | cpu_to_le32(P54U_DEV_BASE)); |
| 690 | |
| 691 | P54U_WRITE(NET2280_BRG_U32, NET2280_USBIRQENB1, 0); |
| 692 | P54U_WRITE(NET2280_BRG_U32, NET2280_IRQSTAT1, |
| 693 | cpu_to_le32(NET2280_PCI_INTA_INTERRUPT)); |
| 694 | |
| 695 | /* do romboot */ |
| 696 | P54U_WRITE(NET2280_DEV_U32, &devreg->int_enable, 0); |
| 697 | |
| 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_RAMBOOT); |
| 701 | reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_CLKRUN); |
| 702 | P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg); |
| 703 | |
| 704 | mdelay(20); |
| 705 | |
| 706 | reg |= cpu_to_le32(ISL38XX_CTRL_STAT_RESET); |
| 707 | P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg); |
| 708 | |
| 709 | mdelay(20); |
| 710 | |
| 711 | reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET); |
| 712 | P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg); |
| 713 | |
| 714 | mdelay(100); |
| 715 | |
| 716 | P54U_READ(NET2280_DEV_U32, &devreg->int_ident); |
| 717 | P54U_WRITE(NET2280_DEV_U32, &devreg->int_ack, reg); |
| 718 | |
| 719 | /* finally, we can upload firmware now! */ |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 720 | remains = priv->fw->size; |
| 721 | data = priv->fw->data; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 722 | offset = ISL38XX_DEV_FIRMWARE_ADDR; |
| 723 | |
| 724 | while (remains) { |
| 725 | unsigned int block_len = min(remains, (unsigned int)512); |
| 726 | memcpy(buf, data, block_len); |
| 727 | |
| 728 | err = p54u_bulk_msg(priv, P54U_PIPE_DATA, buf, block_len); |
| 729 | if (err) { |
Christian Lamparter | 02e37ba | 2008-11-29 22:39:08 +0100 | [diff] [blame] | 730 | dev_err(&priv->udev->dev, "(p54usb) firmware block " |
| 731 | "upload failed\n"); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 732 | goto fail; |
| 733 | } |
| 734 | |
| 735 | P54U_WRITE(NET2280_DEV_U32, &devreg->direct_mem_base, |
| 736 | cpu_to_le32(0xc0000f00)); |
| 737 | |
| 738 | P54U_WRITE(NET2280_DEV_U32, |
| 739 | 0x0020 | (unsigned long)&devreg->direct_mem_win, 0); |
| 740 | P54U_WRITE(NET2280_DEV_U32, |
| 741 | 0x0020 | (unsigned long)&devreg->direct_mem_win, |
| 742 | cpu_to_le32(1)); |
| 743 | |
| 744 | P54U_WRITE(NET2280_DEV_U32, |
| 745 | 0x0024 | (unsigned long)&devreg->direct_mem_win, |
| 746 | cpu_to_le32(block_len)); |
| 747 | P54U_WRITE(NET2280_DEV_U32, |
| 748 | 0x0028 | (unsigned long)&devreg->direct_mem_win, |
| 749 | cpu_to_le32(offset)); |
| 750 | |
| 751 | P54U_WRITE(NET2280_DEV_U32, &devreg->dma_addr, |
| 752 | cpu_to_le32(NET2280_EPA_FIFO_PCI_ADDR)); |
| 753 | P54U_WRITE(NET2280_DEV_U32, &devreg->dma_len, |
| 754 | cpu_to_le32(block_len >> 2)); |
| 755 | P54U_WRITE(NET2280_DEV_U32, &devreg->dma_ctrl, |
| 756 | cpu_to_le32(ISL38XX_DMA_MASTER_CONTROL_TRIGGER)); |
| 757 | |
| 758 | mdelay(10); |
| 759 | |
| 760 | P54U_READ(NET2280_DEV_U32, |
| 761 | 0x002C | (unsigned long)&devreg->direct_mem_win); |
| 762 | if (!(reg & cpu_to_le32(ISL38XX_DMA_STATUS_DONE)) || |
| 763 | !(reg & cpu_to_le32(ISL38XX_DMA_STATUS_READY))) { |
Christian Lamparter | 02e37ba | 2008-11-29 22:39:08 +0100 | [diff] [blame] | 764 | dev_err(&priv->udev->dev, "(p54usb) firmware DMA " |
| 765 | "transfer failed\n"); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 766 | goto fail; |
| 767 | } |
| 768 | |
| 769 | P54U_WRITE(NET2280_BRG_U32, NET2280_EPA_STAT, |
| 770 | cpu_to_le32(NET2280_FIFO_FLUSH)); |
| 771 | |
| 772 | remains -= block_len; |
| 773 | data += block_len; |
| 774 | offset += block_len; |
| 775 | } |
| 776 | |
| 777 | /* do ramboot */ |
| 778 | P54U_READ(NET2280_DEV_U32, &devreg->ctrl_stat); |
| 779 | reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET); |
| 780 | reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_CLKRUN); |
| 781 | reg |= cpu_to_le32(ISL38XX_CTRL_STAT_RAMBOOT); |
| 782 | P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg); |
| 783 | |
| 784 | mdelay(20); |
| 785 | |
| 786 | reg |= cpu_to_le32(ISL38XX_CTRL_STAT_RESET); |
| 787 | P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg); |
| 788 | |
| 789 | reg &= cpu_to_le32(~ISL38XX_CTRL_STAT_RESET); |
| 790 | P54U_WRITE(NET2280_DEV_U32, &devreg->ctrl_stat, reg); |
| 791 | |
| 792 | mdelay(100); |
| 793 | |
| 794 | P54U_READ(NET2280_DEV_U32, &devreg->int_ident); |
| 795 | P54U_WRITE(NET2280_DEV_U32, &devreg->int_ack, reg); |
| 796 | |
| 797 | /* start up the firmware */ |
| 798 | P54U_WRITE(NET2280_DEV_U32, &devreg->int_enable, |
| 799 | cpu_to_le32(ISL38XX_INT_IDENT_INIT)); |
| 800 | |
| 801 | P54U_WRITE(NET2280_BRG_U32, NET2280_IRQSTAT1, |
| 802 | cpu_to_le32(NET2280_PCI_INTA_INTERRUPT)); |
| 803 | |
| 804 | P54U_WRITE(NET2280_BRG_U32, NET2280_USBIRQENB1, |
| 805 | cpu_to_le32(NET2280_PCI_INTA_INTERRUPT_ENABLE | |
| 806 | NET2280_USB_INTERRUPT_ENABLE)); |
| 807 | |
| 808 | P54U_WRITE(NET2280_DEV_U32, &devreg->dev_int, |
| 809 | cpu_to_le32(ISL38XX_DEV_INT_RESET)); |
| 810 | |
| 811 | err = usb_interrupt_msg(priv->udev, |
| 812 | usb_rcvbulkpipe(priv->udev, P54U_PIPE_INT), |
| 813 | buf, sizeof(__le32), &alen, 1000); |
| 814 | if (err || alen != sizeof(__le32)) |
| 815 | goto fail; |
| 816 | |
| 817 | P54U_READ(NET2280_DEV_U32, &devreg->int_ident); |
| 818 | P54U_WRITE(NET2280_DEV_U32, &devreg->int_ack, reg); |
| 819 | |
| 820 | if (!(reg & cpu_to_le32(ISL38XX_INT_IDENT_INIT))) |
| 821 | err = -EINVAL; |
| 822 | |
| 823 | P54U_WRITE(NET2280_BRG_U32, NET2280_USBIRQENB1, 0); |
| 824 | P54U_WRITE(NET2280_BRG_U32, NET2280_IRQSTAT1, |
| 825 | cpu_to_le32(NET2280_PCI_INTA_INTERRUPT)); |
| 826 | |
| 827 | #undef P54U_WRITE |
| 828 | #undef P54U_READ |
| 829 | |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 830 | fail: |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 831 | kfree(buf); |
| 832 | return err; |
| 833 | } |
| 834 | |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 835 | static int p54u_load_firmware(struct ieee80211_hw *dev) |
| 836 | { |
| 837 | struct p54u_priv *priv = dev->priv; |
| 838 | int err, i; |
| 839 | |
| 840 | BUILD_BUG_ON(ARRAY_SIZE(p54u_fwlist) != __NUM_P54U_HWTYPES); |
| 841 | |
| 842 | for (i = 0; i < __NUM_P54U_HWTYPES; i++) |
| 843 | if (p54u_fwlist[i].type == priv->hw_type) |
| 844 | break; |
| 845 | |
| 846 | if (i == __NUM_P54U_HWTYPES) |
| 847 | return -EOPNOTSUPP; |
| 848 | |
| 849 | err = request_firmware(&priv->fw, p54u_fwlist[i].fw, &priv->udev->dev); |
| 850 | if (err) { |
| 851 | dev_err(&priv->udev->dev, "(p54usb) cannot load firmware %s " |
| 852 | "(%d)!\n", p54u_fwlist[i].fw, err); |
| 853 | |
| 854 | err = request_firmware(&priv->fw, p54u_fwlist[i].fw_legacy, |
| 855 | &priv->udev->dev); |
| 856 | if (err) |
| 857 | return err; |
| 858 | } |
| 859 | |
| 860 | err = p54_parse_firmware(dev, priv->fw); |
| 861 | if (err) |
| 862 | goto out; |
| 863 | |
| 864 | if (priv->common.fw_interface != p54u_fwlist[i].intf) { |
| 865 | dev_err(&priv->udev->dev, "wrong firmware, please get " |
| 866 | "a firmware for \"%s\" and try again.\n", |
| 867 | p54u_fwlist[i].hw); |
| 868 | err = -EINVAL; |
| 869 | } |
| 870 | |
| 871 | out: |
| 872 | if (err) |
| 873 | release_firmware(priv->fw); |
| 874 | |
| 875 | return err; |
| 876 | } |
| 877 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 878 | static int p54u_open(struct ieee80211_hw *dev) |
| 879 | { |
| 880 | struct p54u_priv *priv = dev->priv; |
| 881 | int err; |
| 882 | |
| 883 | err = p54u_init_urbs(dev); |
| 884 | if (err) { |
| 885 | return err; |
| 886 | } |
| 887 | |
| 888 | priv->common.open = p54u_init_urbs; |
| 889 | |
| 890 | return 0; |
| 891 | } |
| 892 | |
| 893 | static void p54u_stop(struct ieee80211_hw *dev) |
| 894 | { |
| 895 | /* TODO: figure out how to reliably stop the 3887 and net2280 so |
| 896 | the hardware is still usable next time we want to start it. |
| 897 | until then, we just stop listening to the hardware.. */ |
| 898 | p54u_free_urbs(dev); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | static int __devinit p54u_probe(struct usb_interface *intf, |
| 902 | const struct usb_device_id *id) |
| 903 | { |
| 904 | struct usb_device *udev = interface_to_usbdev(intf); |
| 905 | struct ieee80211_hw *dev; |
| 906 | struct p54u_priv *priv; |
| 907 | int err; |
| 908 | unsigned int i, recognized_pipes; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 909 | |
| 910 | dev = p54_init_common(sizeof(*priv)); |
Christian Lamparter | 02e37ba | 2008-11-29 22:39:08 +0100 | [diff] [blame] | 911 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 912 | if (!dev) { |
Christian Lamparter | 02e37ba | 2008-11-29 22:39:08 +0100 | [diff] [blame] | 913 | dev_err(&udev->dev, "(p54usb) ieee80211 alloc failed\n"); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 914 | return -ENOMEM; |
| 915 | } |
| 916 | |
| 917 | priv = dev->priv; |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 918 | priv->hw_type = P54U_INVALID_HW; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 919 | |
| 920 | SET_IEEE80211_DEV(dev, &intf->dev); |
| 921 | usb_set_intfdata(intf, dev); |
| 922 | priv->udev = udev; |
Christian Lamparter | 6982869 | 2008-12-26 19:08:31 +0100 | [diff] [blame] | 923 | priv->intf = intf; |
| 924 | skb_queue_head_init(&priv->rx_queue); |
| 925 | init_usb_anchor(&priv->submitted); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 926 | |
| 927 | usb_get_dev(udev); |
| 928 | |
| 929 | /* really lazy and simple way of figuring out if we're a 3887 */ |
| 930 | /* TODO: should just stick the identification in the device table */ |
| 931 | i = intf->altsetting->desc.bNumEndpoints; |
| 932 | recognized_pipes = 0; |
| 933 | while (i--) { |
| 934 | switch (intf->altsetting->endpoint[i].desc.bEndpointAddress) { |
| 935 | case P54U_PIPE_DATA: |
| 936 | case P54U_PIPE_MGMT: |
| 937 | case P54U_PIPE_BRG: |
| 938 | case P54U_PIPE_DEV: |
| 939 | case P54U_PIPE_DATA | USB_DIR_IN: |
| 940 | case P54U_PIPE_MGMT | USB_DIR_IN: |
| 941 | case P54U_PIPE_BRG | USB_DIR_IN: |
| 942 | case P54U_PIPE_DEV | USB_DIR_IN: |
| 943 | case P54U_PIPE_INT | USB_DIR_IN: |
| 944 | recognized_pipes++; |
| 945 | } |
| 946 | } |
| 947 | priv->common.open = p54u_open; |
Christian Lamparter | 2b80848 | 2008-09-04 12:29:38 +0200 | [diff] [blame] | 948 | priv->common.stop = p54u_stop; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 949 | if (recognized_pipes < P54U_PIPE_NUMBER) { |
Hauke Mehrtens | 1379257 | 2009-05-01 13:12:36 +0200 | [diff] [blame] | 950 | #ifdef CONFIG_PM |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 951 | /* ISL3887 needs a full reset on resume */ |
| 952 | udev->reset_resume = 1; |
Christian Lamparter | 11791a6 | 2010-08-22 22:41:33 +0200 | [diff] [blame] | 953 | #endif /* CONFIG_PM */ |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 954 | err = p54u_device_reset(dev); |
| 955 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 956 | priv->hw_type = P54U_3887; |
Christian Lamparter | a406ac0 | 2009-04-25 21:11:55 +0200 | [diff] [blame] | 957 | dev->extra_tx_headroom += sizeof(struct lm87_tx_hdr); |
| 958 | priv->common.tx_hdr_len = sizeof(struct lm87_tx_hdr); |
| 959 | priv->common.tx = p54u_tx_lm87; |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 960 | priv->upload_fw = p54u_upload_firmware_3887; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 961 | } else { |
Christian Lamparter | 2b80848 | 2008-09-04 12:29:38 +0200 | [diff] [blame] | 962 | priv->hw_type = P54U_NET2280; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 963 | dev->extra_tx_headroom += sizeof(struct net2280_tx_hdr); |
| 964 | priv->common.tx_hdr_len = sizeof(struct net2280_tx_hdr); |
| 965 | priv->common.tx = p54u_tx_net2280; |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 966 | priv->upload_fw = p54u_upload_firmware_net2280; |
Christian Lamparter | 2b80848 | 2008-09-04 12:29:38 +0200 | [diff] [blame] | 967 | } |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 968 | err = p54u_load_firmware(dev); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 969 | if (err) |
| 970 | goto err_free_dev; |
| 971 | |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 972 | err = priv->upload_fw(dev); |
| 973 | if (err) |
| 974 | goto err_free_fw; |
| 975 | |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 976 | p54u_open(dev); |
| 977 | err = p54_read_eeprom(dev); |
| 978 | p54u_stop(dev); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 979 | if (err) |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 980 | goto err_free_fw; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 981 | |
Christian Lamparter | 2ac7107 | 2009-03-05 21:30:10 +0100 | [diff] [blame] | 982 | err = p54_register_common(dev, &udev->dev); |
| 983 | if (err) |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 984 | goto err_free_fw; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 985 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 986 | return 0; |
| 987 | |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 988 | err_free_fw: |
| 989 | release_firmware(priv->fw); |
| 990 | |
| 991 | err_free_dev: |
Christian Lamparter | d8c9210 | 2009-06-23 10:39:45 -0500 | [diff] [blame] | 992 | p54_free_common(dev); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 993 | usb_set_intfdata(intf, NULL); |
| 994 | usb_put_dev(udev); |
| 995 | return err; |
| 996 | } |
| 997 | |
| 998 | static void __devexit p54u_disconnect(struct usb_interface *intf) |
| 999 | { |
| 1000 | struct ieee80211_hw *dev = usb_get_intfdata(intf); |
| 1001 | struct p54u_priv *priv; |
| 1002 | |
| 1003 | if (!dev) |
| 1004 | return; |
| 1005 | |
Christian Lamparter | d8c9210 | 2009-06-23 10:39:45 -0500 | [diff] [blame] | 1006 | p54_unregister_common(dev); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1007 | |
| 1008 | priv = dev->priv; |
| 1009 | usb_put_dev(interface_to_usbdev(intf)); |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 1010 | release_firmware(priv->fw); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1011 | p54_free_common(dev); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
Christian Lamparter | 6982869 | 2008-12-26 19:08:31 +0100 | [diff] [blame] | 1014 | static int p54u_pre_reset(struct usb_interface *intf) |
| 1015 | { |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 1016 | struct ieee80211_hw *dev = usb_get_intfdata(intf); |
| 1017 | |
| 1018 | if (!dev) |
| 1019 | return -ENODEV; |
| 1020 | |
| 1021 | p54u_stop(dev); |
Christian Lamparter | 6982869 | 2008-12-26 19:08:31 +0100 | [diff] [blame] | 1022 | return 0; |
| 1023 | } |
| 1024 | |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 1025 | static int p54u_resume(struct usb_interface *intf) |
| 1026 | { |
| 1027 | struct ieee80211_hw *dev = usb_get_intfdata(intf); |
| 1028 | struct p54u_priv *priv; |
| 1029 | |
| 1030 | if (!dev) |
| 1031 | return -ENODEV; |
| 1032 | |
| 1033 | priv = dev->priv; |
| 1034 | if (unlikely(!(priv->upload_fw && priv->fw))) |
| 1035 | return 0; |
| 1036 | |
| 1037 | return priv->upload_fw(dev); |
| 1038 | } |
| 1039 | |
Christian Lamparter | 6982869 | 2008-12-26 19:08:31 +0100 | [diff] [blame] | 1040 | static int p54u_post_reset(struct usb_interface *intf) |
| 1041 | { |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 1042 | struct ieee80211_hw *dev = usb_get_intfdata(intf); |
| 1043 | struct p54u_priv *priv; |
| 1044 | int err; |
| 1045 | |
| 1046 | err = p54u_resume(intf); |
| 1047 | if (err) |
| 1048 | return err; |
| 1049 | |
| 1050 | /* reinitialize old device state */ |
| 1051 | priv = dev->priv; |
| 1052 | if (priv->common.mode != NL80211_IFTYPE_UNSPECIFIED) |
| 1053 | ieee80211_restart_hw(dev); |
| 1054 | |
Christian Lamparter | 6982869 | 2008-12-26 19:08:31 +0100 | [diff] [blame] | 1055 | return 0; |
| 1056 | } |
| 1057 | |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 1058 | #ifdef CONFIG_PM |
| 1059 | |
| 1060 | static int p54u_suspend(struct usb_interface *intf, pm_message_t message) |
| 1061 | { |
| 1062 | return p54u_pre_reset(intf); |
| 1063 | } |
| 1064 | |
| 1065 | #endif /* CONFIG_PM */ |
| 1066 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1067 | static struct usb_driver p54u_driver = { |
Christian Lamparter | 32ddf07 | 2008-08-08 21:17:37 +0200 | [diff] [blame] | 1068 | .name = "p54usb", |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1069 | .id_table = p54u_table, |
| 1070 | .probe = p54u_probe, |
| 1071 | .disconnect = p54u_disconnect, |
Christian Lamparter | 6982869 | 2008-12-26 19:08:31 +0100 | [diff] [blame] | 1072 | .pre_reset = p54u_pre_reset, |
| 1073 | .post_reset = p54u_post_reset, |
Christian Lamparter | 1ca5f2e | 2009-04-25 21:12:09 +0200 | [diff] [blame] | 1074 | #ifdef CONFIG_PM |
| 1075 | .suspend = p54u_suspend, |
| 1076 | .resume = p54u_resume, |
| 1077 | .reset_resume = p54u_resume, |
| 1078 | #endif /* CONFIG_PM */ |
Christian Lamparter | fbf9529 | 2009-03-05 21:29:51 +0100 | [diff] [blame] | 1079 | .soft_unbind = 1, |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1080 | }; |
| 1081 | |
| 1082 | static int __init p54u_init(void) |
| 1083 | { |
| 1084 | return usb_register(&p54u_driver); |
| 1085 | } |
| 1086 | |
| 1087 | static void __exit p54u_exit(void) |
| 1088 | { |
| 1089 | usb_deregister(&p54u_driver); |
| 1090 | } |
| 1091 | |
| 1092 | module_init(p54u_init); |
| 1093 | module_exit(p54u_exit); |