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