1 --- a/drivers/net/wireless/ath/ar9170/usb.c
2 +++ b/drivers/net/wireless/ath/ar9170/usb.c
3 @@ -96,6 +96,225 @@ static struct usb_device_id ar9170_usb_i
5 MODULE_DEVICE_TABLE(usb, ar9170_usb_ids);
7 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29))
10 + * usb_unpoison_anchored_urbs - let an anchor be used successfully again
11 + * @anchor: anchor the requests are bound to
13 + * Reverses the effect of usb_poison_anchored_urbs
14 + * the anchor can be used normally after it returns
16 +void usb_unpoison_anchored_urbs(struct usb_anchor *anchor)
18 + unsigned long flags;
19 + struct urb *lazarus;
21 + spin_lock_irqsave(&anchor->lock, flags);
22 + list_for_each_entry(lazarus, &anchor->urb_list, anchor_list) {
23 + usb_unpoison_urb(lazarus);
25 + //anchor->poisoned = 0; /* XXX: cannot backport */
26 + spin_unlock_irqrestore(&anchor->lock, flags);
28 +EXPORT_SYMBOL_GPL(usb_unpoison_anchored_urbs);
29 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) */
31 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28))
34 + * Compat-wireless notes for USB backport stuff:
36 + * urb->reject exists on 2.6.27, the poison/unpoison helpers
37 + * did not though. The anchor poison does not exist so we cannot use them.
39 + * USB anchor poising seems to exist to prevent future driver sumbissions
40 + * of usb_anchor_urb() to an anchor marked as poisoned. For older kernels
41 + * we cannot use that, so new usb_anchor_urb()s will be anchored. The down
42 + * side to this should be submission of URBs will continue being anchored
43 + * on an anchor instead of having them being rejected immediately when the
44 + * driver realized we needed to stop. For ar9170 we poison URBs upon the
45 + * ar9170 mac80211 stop callback(), don't think this should be so bad.
46 + * It mean there is period of time in older kernels for which we continue
47 + * to anchor new URBs to a known stopped anchor. We have two anchors
53 + * usb_poison_urb - reliably kill a transfer and prevent further use of an URB
54 + * @urb: pointer to URB describing a previously submitted request,
57 + * This routine cancels an in-progress request. It is guaranteed that
58 + * upon return all completion handlers will have finished and the URB
59 + * will be totally idle and cannot be reused. These features make
60 + * this an ideal way to stop I/O in a disconnect() callback.
61 + * If the request has not already finished or been unlinked
62 + * the completion handler will see urb->status == -ENOENT.
64 + * After and while the routine runs, attempts to resubmit the URB will fail
65 + * with error -EPERM. Thus even if the URB's completion handler always
66 + * tries to resubmit, it will not succeed and the URB will become idle.
68 + * This routine may not be used in an interrupt context (such as a bottom
69 + * half or a completion handler), or when holding a spinlock, or in other
70 + * situations where the caller can't schedule().
72 + * This routine should not be called by a driver after its disconnect
73 + * method has returned.
75 +void usb_poison_urb(struct urb *urb)
78 + if (!(urb && urb->dev && urb->ep))
80 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28))
81 + spin_lock_irq(&usb_reject_lock);
84 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28))
85 + spin_unlock_irq(&usb_reject_lock);
88 + * XXX: usb_hcd_unlink_urb() needs backporting... this is defined
89 + * on usb hcd.c but urb.c gets access to it. That is, older kernels
90 + * have usb_hcd_unlink_urb() but its not exported, nor can we
91 + * re-implement it exactly. This essentially dequeues the urb from
92 + * hw, we need to figure out a way to backport this.
94 + //usb_hcd_unlink_urb(urb, -ENOENT);
96 + wait_event(usb_kill_urb_queue, atomic_read(&urb->use_count) == 0);
98 +EXPORT_SYMBOL_GPL(usb_poison_urb);
101 +void usb_unpoison_urb(struct urb *urb)
103 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28))
104 + unsigned long flags;
110 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28))
111 + spin_lock_irqsave(&usb_reject_lock, flags);
114 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28))
115 + spin_unlock_irqrestore(&usb_reject_lock, flags);
118 +EXPORT_SYMBOL_GPL(usb_unpoison_urb);
123 + * usb_poison_anchored_urbs - cease all traffic from an anchor
124 + * @anchor: anchor the requests are bound to
126 + * this allows all outstanding URBs to be poisoned starting
127 + * from the back of the queue. Newly added URBs will also be
130 + * This routine should not be called by a driver after its disconnect
131 + * method has returned.
133 +void usb_poison_anchored_urbs(struct usb_anchor *anchor)
135 + struct urb *victim;
137 + spin_lock_irq(&anchor->lock);
138 + // anchor->poisoned = 1; /* XXX: Cannot backport */
139 + while (!list_empty(&anchor->urb_list)) {
140 + victim = list_entry(anchor->urb_list.prev, struct urb,
142 + /* we must make sure the URB isn't freed before we kill it*/
143 + usb_get_urb(victim);
144 + spin_unlock_irq(&anchor->lock);
145 + /* this will unanchor the URB */
146 + usb_poison_urb(victim);
147 + usb_put_urb(victim);
148 + spin_lock_irq(&anchor->lock);
150 + spin_unlock_irq(&anchor->lock);
152 +EXPORT_SYMBOL_GPL(usb_poison_anchored_urbs);
156 + * usb_get_from_anchor - get an anchor's oldest urb
157 + * @anchor: the anchor whose urb you want
159 + * this will take the oldest urb from an anchor,
160 + * unanchor and return it
162 +struct urb *usb_get_from_anchor(struct usb_anchor *anchor)
164 + struct urb *victim;
165 + unsigned long flags;
167 + spin_lock_irqsave(&anchor->lock, flags);
168 + if (!list_empty(&anchor->urb_list)) {
169 + victim = list_entry(anchor->urb_list.next, struct urb,
171 + usb_get_urb(victim);
172 + spin_unlock_irqrestore(&anchor->lock, flags);
173 + usb_unanchor_urb(victim);
175 + spin_unlock_irqrestore(&anchor->lock, flags);
182 +EXPORT_SYMBOL_GPL(usb_get_from_anchor);
185 + * usb_scuttle_anchored_urbs - unanchor all an anchor's urbs
186 + * @anchor: the anchor whose urbs you want to unanchor
188 + * use this to get rid of all an anchor's urbs
190 +void usb_scuttle_anchored_urbs(struct usb_anchor *anchor)
192 + struct urb *victim;
193 + unsigned long flags;
195 + spin_lock_irqsave(&anchor->lock, flags);
196 + while (!list_empty(&anchor->urb_list)) {
197 + victim = list_entry(anchor->urb_list.prev, struct urb,
199 + usb_get_urb(victim);
200 + spin_unlock_irqrestore(&anchor->lock, flags);
201 + /* this may free the URB */
202 + usb_unanchor_urb(victim);
203 + usb_put_urb(victim);
204 + spin_lock_irqsave(&anchor->lock, flags);
206 + spin_unlock_irqrestore(&anchor->lock, flags);
209 +EXPORT_SYMBOL_GPL(usb_scuttle_anchored_urbs);
212 + * usb_anchor_empty - is an anchor empty
213 + * @anchor: the anchor you want to query
215 + * returns 1 if the anchor has no urbs associated with it
217 +int usb_anchor_empty(struct usb_anchor *anchor)
219 + return list_empty(&anchor->urb_list);
222 +EXPORT_SYMBOL_GPL(usb_anchor_empty);
224 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) */
226 static void ar9170_usb_submit_urb(struct ar9170_usb *aru)
229 --- a/net/wireless/compat-2.6.28.c
230 +++ b/net/wireless/compat-2.6.28.c
233 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28))
235 -#include <linux/usb.h>
237 /* 2.6.28 compat code goes here */
240 - * Compat-wireless notes for USB backport stuff:
242 - * urb->reject exists on 2.6.27, the poison/unpoison helpers
243 - * did not though. The anchor poison does not exist so we cannot use them.
245 - * USB anchor poising seems to exist to prevent future driver sumbissions
246 - * of usb_anchor_urb() to an anchor marked as poisoned. For older kernels
247 - * we cannot use that, so new usb_anchor_urb()s will be anchored. The down
248 - * side to this should be submission of URBs will continue being anchored
249 - * on an anchor instead of having them being rejected immediately when the
250 - * driver realized we needed to stop. For ar9170 we poison URBs upon the
251 - * ar9170 mac80211 stop callback(), don't think this should be so bad.
252 - * It mean there is period of time in older kernels for which we continue
253 - * to anchor new URBs to a known stopped anchor. We have two anchors
259 - * usb_poison_urb - reliably kill a transfer and prevent further use of an URB
260 - * @urb: pointer to URB describing a previously submitted request,
263 - * This routine cancels an in-progress request. It is guaranteed that
264 - * upon return all completion handlers will have finished and the URB
265 - * will be totally idle and cannot be reused. These features make
266 - * this an ideal way to stop I/O in a disconnect() callback.
267 - * If the request has not already finished or been unlinked
268 - * the completion handler will see urb->status == -ENOENT.
270 - * After and while the routine runs, attempts to resubmit the URB will fail
271 - * with error -EPERM. Thus even if the URB's completion handler always
272 - * tries to resubmit, it will not succeed and the URB will become idle.
274 - * This routine may not be used in an interrupt context (such as a bottom
275 - * half or a completion handler), or when holding a spinlock, or in other
276 - * situations where the caller can't schedule().
278 - * This routine should not be called by a driver after its disconnect
279 - * method has returned.
281 -void usb_poison_urb(struct urb *urb)
284 - if (!(urb && urb->dev && urb->ep))
286 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28))
287 - spin_lock_irq(&usb_reject_lock);
290 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28))
291 - spin_unlock_irq(&usb_reject_lock);
294 - * XXX: usb_hcd_unlink_urb() needs backporting... this is defined
295 - * on usb hcd.c but urb.c gets access to it. That is, older kernels
296 - * have usb_hcd_unlink_urb() but its not exported, nor can we
297 - * re-implement it exactly. This essentially dequeues the urb from
298 - * hw, we need to figure out a way to backport this.
300 - //usb_hcd_unlink_urb(urb, -ENOENT);
302 - wait_event(usb_kill_urb_queue, atomic_read(&urb->use_count) == 0);
304 -EXPORT_SYMBOL_GPL(usb_poison_urb);
307 -void usb_unpoison_urb(struct urb *urb)
309 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28))
310 - unsigned long flags;
316 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28))
317 - spin_lock_irqsave(&usb_reject_lock, flags);
320 -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28))
321 - spin_unlock_irqrestore(&usb_reject_lock, flags);
324 -EXPORT_SYMBOL_GPL(usb_unpoison_urb);
329 - * usb_poison_anchored_urbs - cease all traffic from an anchor
330 - * @anchor: anchor the requests are bound to
332 - * this allows all outstanding URBs to be poisoned starting
333 - * from the back of the queue. Newly added URBs will also be
336 - * This routine should not be called by a driver after its disconnect
337 - * method has returned.
339 -void usb_poison_anchored_urbs(struct usb_anchor *anchor)
341 - struct urb *victim;
343 - spin_lock_irq(&anchor->lock);
344 - // anchor->poisoned = 1; /* XXX: Cannot backport */
345 - while (!list_empty(&anchor->urb_list)) {
346 - victim = list_entry(anchor->urb_list.prev, struct urb,
348 - /* we must make sure the URB isn't freed before we kill it*/
349 - usb_get_urb(victim);
350 - spin_unlock_irq(&anchor->lock);
351 - /* this will unanchor the URB */
352 - usb_poison_urb(victim);
353 - usb_put_urb(victim);
354 - spin_lock_irq(&anchor->lock);
356 - spin_unlock_irq(&anchor->lock);
358 -EXPORT_SYMBOL_GPL(usb_poison_anchored_urbs);
362 - * usb_get_from_anchor - get an anchor's oldest urb
363 - * @anchor: the anchor whose urb you want
365 - * this will take the oldest urb from an anchor,
366 - * unanchor and return it
368 -struct urb *usb_get_from_anchor(struct usb_anchor *anchor)
370 - struct urb *victim;
371 - unsigned long flags;
373 - spin_lock_irqsave(&anchor->lock, flags);
374 - if (!list_empty(&anchor->urb_list)) {
375 - victim = list_entry(anchor->urb_list.next, struct urb,
377 - usb_get_urb(victim);
378 - spin_unlock_irqrestore(&anchor->lock, flags);
379 - usb_unanchor_urb(victim);
381 - spin_unlock_irqrestore(&anchor->lock, flags);
388 -EXPORT_SYMBOL_GPL(usb_get_from_anchor);
391 - * usb_scuttle_anchored_urbs - unanchor all an anchor's urbs
392 - * @anchor: the anchor whose urbs you want to unanchor
394 - * use this to get rid of all an anchor's urbs
396 -void usb_scuttle_anchored_urbs(struct usb_anchor *anchor)
398 - struct urb *victim;
399 - unsigned long flags;
401 - spin_lock_irqsave(&anchor->lock, flags);
402 - while (!list_empty(&anchor->urb_list)) {
403 - victim = list_entry(anchor->urb_list.prev, struct urb,
405 - usb_get_urb(victim);
406 - spin_unlock_irqrestore(&anchor->lock, flags);
407 - /* this may free the URB */
408 - usb_unanchor_urb(victim);
409 - usb_put_urb(victim);
410 - spin_lock_irqsave(&anchor->lock, flags);
412 - spin_unlock_irqrestore(&anchor->lock, flags);
415 -EXPORT_SYMBOL_GPL(usb_scuttle_anchored_urbs);
418 - * usb_anchor_empty - is an anchor empty
419 - * @anchor: the anchor you want to query
421 - * returns 1 if the anchor has no urbs associated with it
423 -int usb_anchor_empty(struct usb_anchor *anchor)
425 - return list_empty(&anchor->urb_list);
428 -EXPORT_SYMBOL_GPL(usb_anchor_empty);
431 void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar)
434 --- a/net/wireless/compat-2.6.29.c
435 +++ b/net/wireless/compat-2.6.29.c
438 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29))
440 -#include <linux/usb.h>
443 - * usb_unpoison_anchored_urbs - let an anchor be used successfully again
444 - * @anchor: anchor the requests are bound to
446 - * Reverses the effect of usb_poison_anchored_urbs
447 - * the anchor can be used normally after it returns
449 -void usb_unpoison_anchored_urbs(struct usb_anchor *anchor)
451 - unsigned long flags;
452 - struct urb *lazarus;
454 - spin_lock_irqsave(&anchor->lock, flags);
455 - list_for_each_entry(lazarus, &anchor->urb_list, anchor_list) {
456 - usb_unpoison_urb(lazarus);
458 - //anchor->poisoned = 0; /* XXX: cannot backport */
459 - spin_unlock_irqrestore(&anchor->lock, flags);
461 -EXPORT_SYMBOL_GPL(usb_unpoison_anchored_urbs);
463 +/* 2.6.29 compat code goes here */
465 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) */
467 --- a/include/net/compat-2.6.28.h
468 +++ b/include/net/compat-2.6.28.h
471 #include <linux/skbuff.h>
472 #include <linux/if_ether.h>
473 -#include <linux/usb.h>
476 #define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
478 #define pcmcia_parse_tuple(tuple, parse) pccard_parse_tuple(tuple, parse)
482 -extern void usb_poison_urb(struct urb *urb);
484 -extern void usb_unpoison_urb(struct urb *urb);
487 -extern void usb_poison_anchored_urbs(struct usb_anchor *anchor);
490 -extern struct urb *usb_get_from_anchor(struct usb_anchor *anchor);
491 -extern void usb_scuttle_anchored_urbs(struct usb_anchor *anchor);
492 -extern int usb_anchor_empty(struct usb_anchor *anchor);
495 void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar);
497 --- a/include/net/compat-2.6.29.h
498 +++ b/include/net/compat-2.6.29.h
500 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29))
502 #include <linux/skbuff.h>
503 -#include <linux/usb.h>
506 * skb_queue_is_first - check if skb is the first entry in the queue
507 @@ -41,8 +40,6 @@ static inline struct sk_buff *skb_queue_
511 -extern void usb_unpoison_anchored_urbs(struct usb_anchor *anchor);
513 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)) */
515 #endif /* LINUX_26_29_COMPAT_H */