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