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