diff options
author | David Brownell <david-b@pacbell.net> | 2005-08-31 12:53:10 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-09-08 19:28:31 -0400 |
commit | 2e55cc7210fef90f88201e860d8767594974574e (patch) | |
tree | 6e2a9a9a5a974a5ac6f1b76c36a4aab01d8d2fe5 /drivers | |
parent | 38bde1d4699af45e6a4167a72e2e512e45c35ca8 (diff) |
[PATCH] USB: usbnet (3/9) module for ASIX Ethernet adapters
This patch moves the ASIX AX8817x driver into its own file, just using
the "usbnet" infrastructure as a utility library.
- As with "cdc_subset" this involved minor Kconfig/kbuild tweaks,
moving code from one file to another, and exporting a few functions.
- This includes updates from Jamie Painter to add (and use) a new hook
to handle the different maximum transfer sizes for rx and tx sides.
- Also from Jamie, some bugfixes:
* MDIO byteorder (to address some PPC media negotiation problems);
* Force alignment at key spots when using ax88772 framing (on some
embedded hardware, the network stack will break otherwise);
* Address some link reset problems.
It also makes this driver use the standard (5 seconds vs half second)
control timeouts used elsewhere in USB; and wraps a few lines before
the 80th column (which previously needed it).
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/usb/net/Kconfig | 13 | ||||
-rw-r--r-- | drivers/usb/net/Makefile | 1 | ||||
-rw-r--r-- | drivers/usb/net/asix.c | 948 | ||||
-rw-r--r-- | drivers/usb/net/usbnet.c | 936 | ||||
-rw-r--r-- | drivers/usb/net/usbnet.h | 8 |
5 files changed, 1010 insertions, 896 deletions
diff --git a/drivers/usb/net/Kconfig b/drivers/usb/net/Kconfig index 6399b43d41a5..4fb51b998cc8 100644 --- a/drivers/usb/net/Kconfig +++ b/drivers/usb/net/Kconfig | |||
@@ -202,23 +202,22 @@ config USB_CDCETHER | |||
202 | IEEE 802 "local assignment" bit is set in the address, a "usbX" | 202 | IEEE 802 "local assignment" bit is set in the address, a "usbX" |
203 | name is used instead. | 203 | name is used instead. |
204 | 204 | ||
205 | comment "USB Network Adapters" | 205 | comment "Drivers built using the usbnet core" |
206 | depends on USB_USBNET | ||
207 | 206 | ||
208 | config USB_AX8817X | 207 | config USB_NET_AX8817X |
209 | boolean "ASIX AX88xxx Based USB 2.0 Ethernet Devices" | 208 | tristate "ASIX AX88xxx Based USB 2.0 Ethernet Adapters" |
210 | depends on USB_USBNET && NET_ETHERNET | 209 | depends on USB_USBNET && NET_ETHERNET |
211 | select CRC32 | 210 | select CRC32 |
212 | select MII | 211 | select MII |
213 | default y | 212 | default y |
214 | help | 213 | help |
215 | This option adds support for ASIX AX88xxx based USB 2.0 | 214 | This option adds support for ASIX AX88xxx based USB 2.0 |
216 | 10/100 Ethernet devices. | 215 | 10/100 Ethernet adapters. |
217 | 216 | ||
218 | This driver should work with at least the following devices: | 217 | This driver should work with at least the following devices: |
219 | * Aten UC210T | 218 | * Aten UC210T |
220 | * ASIX AX88172 | 219 | * ASIX AX88172 |
221 | * Billionton Systems, USB2AR | 220 | * Billionton Systems, USB2AR |
222 | * Buffalo LUA-U2-KTX | 221 | * Buffalo LUA-U2-KTX |
223 | * Corega FEther USB2-TX | 222 | * Corega FEther USB2-TX |
224 | * D-Link DUB-E100 | 223 | * D-Link DUB-E100 |
@@ -231,7 +230,7 @@ config USB_AX8817X | |||
231 | * TrendNet TU2-ET100 | 230 | * TrendNet TU2-ET100 |
232 | 231 | ||
233 | This driver creates an interface named "ethX", where X depends on | 232 | This driver creates an interface named "ethX", where X depends on |
234 | what other networking devices you have in use. | 233 | what other networking devices you have in use. |
235 | 234 | ||
236 | 235 | ||
237 | config USB_NET_CDC_SUBSET | 236 | config USB_NET_CDC_SUBSET |
diff --git a/drivers/usb/net/Makefile b/drivers/usb/net/Makefile index 23608ccc6380..60dc91e5cdbf 100644 --- a/drivers/usb/net/Makefile +++ b/drivers/usb/net/Makefile | |||
@@ -6,6 +6,7 @@ obj-$(CONFIG_USB_CATC) += catc.o | |||
6 | obj-$(CONFIG_USB_KAWETH) += kaweth.o | 6 | obj-$(CONFIG_USB_KAWETH) += kaweth.o |
7 | obj-$(CONFIG_USB_PEGASUS) += pegasus.o | 7 | obj-$(CONFIG_USB_PEGASUS) += pegasus.o |
8 | obj-$(CONFIG_USB_RTL8150) += rtl8150.o | 8 | obj-$(CONFIG_USB_RTL8150) += rtl8150.o |
9 | obj-$(CONFIG_USB_NET_AX8817X) += asix.o | ||
9 | obj-$(CONFIG_USB_NET_CDC_SUBSET) += cdc_subset.o | 10 | obj-$(CONFIG_USB_NET_CDC_SUBSET) += cdc_subset.o |
10 | obj-$(CONFIG_USB_USBNET) += usbnet.o | 11 | obj-$(CONFIG_USB_USBNET) += usbnet.o |
11 | obj-$(CONFIG_USB_ZD1201) += zd1201.o | 12 | obj-$(CONFIG_USB_ZD1201) += zd1201.o |
diff --git a/drivers/usb/net/asix.c b/drivers/usb/net/asix.c new file mode 100644 index 000000000000..861f00a43750 --- /dev/null +++ b/drivers/usb/net/asix.c | |||
@@ -0,0 +1,948 @@ | |||
1 | /* | ||
2 | * ASIX AX8817X based USB 2.0 Ethernet Devices | ||
3 | * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com> | ||
4 | * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net> | ||
5 | * Copyright (c) 2002-2003 TiVo Inc. | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | ||
21 | |||
22 | // #define DEBUG // error path messages, extra info | ||
23 | // #define VERBOSE // more; success messages | ||
24 | |||
25 | #include <linux/config.h> | ||
26 | #ifdef CONFIG_USB_DEBUG | ||
27 | # define DEBUG | ||
28 | #endif | ||
29 | #include <linux/module.h> | ||
30 | #include <linux/kmod.h> | ||
31 | #include <linux/sched.h> | ||
32 | #include <linux/init.h> | ||
33 | #include <linux/netdevice.h> | ||
34 | #include <linux/etherdevice.h> | ||
35 | #include <linux/ethtool.h> | ||
36 | #include <linux/workqueue.h> | ||
37 | #include <linux/mii.h> | ||
38 | #include <linux/usb.h> | ||
39 | #include <linux/crc32.h> | ||
40 | |||
41 | #include "usbnet.h" | ||
42 | |||
43 | |||
44 | /* ASIX AX8817X based USB 2.0 Ethernet Devices */ | ||
45 | |||
46 | #define AX_CMD_SET_SW_MII 0x06 | ||
47 | #define AX_CMD_READ_MII_REG 0x07 | ||
48 | #define AX_CMD_WRITE_MII_REG 0x08 | ||
49 | #define AX_CMD_SET_HW_MII 0x0a | ||
50 | #define AX_CMD_READ_EEPROM 0x0b | ||
51 | #define AX_CMD_WRITE_EEPROM 0x0c | ||
52 | #define AX_CMD_WRITE_ENABLE 0x0d | ||
53 | #define AX_CMD_WRITE_DISABLE 0x0e | ||
54 | #define AX_CMD_WRITE_RX_CTL 0x10 | ||
55 | #define AX_CMD_READ_IPG012 0x11 | ||
56 | #define AX_CMD_WRITE_IPG0 0x12 | ||
57 | #define AX_CMD_WRITE_IPG1 0x13 | ||
58 | #define AX_CMD_WRITE_IPG2 0x14 | ||
59 | #define AX_CMD_WRITE_MULTI_FILTER 0x16 | ||
60 | #define AX_CMD_READ_NODE_ID 0x17 | ||
61 | #define AX_CMD_READ_PHY_ID 0x19 | ||
62 | #define AX_CMD_READ_MEDIUM_STATUS 0x1a | ||
63 | #define AX_CMD_WRITE_MEDIUM_MODE 0x1b | ||
64 | #define AX_CMD_READ_MONITOR_MODE 0x1c | ||
65 | #define AX_CMD_WRITE_MONITOR_MODE 0x1d | ||
66 | #define AX_CMD_WRITE_GPIOS 0x1f | ||
67 | #define AX_CMD_SW_RESET 0x20 | ||
68 | #define AX_CMD_SW_PHY_STATUS 0x21 | ||
69 | #define AX_CMD_SW_PHY_SELECT 0x22 | ||
70 | #define AX88772_CMD_READ_NODE_ID 0x13 | ||
71 | |||
72 | #define AX_MONITOR_MODE 0x01 | ||
73 | #define AX_MONITOR_LINK 0x02 | ||
74 | #define AX_MONITOR_MAGIC 0x04 | ||
75 | #define AX_MONITOR_HSFS 0x10 | ||
76 | |||
77 | /* AX88172 Medium Status Register values */ | ||
78 | #define AX_MEDIUM_FULL_DUPLEX 0x02 | ||
79 | #define AX_MEDIUM_TX_ABORT_ALLOW 0x04 | ||
80 | #define AX_MEDIUM_FLOW_CONTROL_EN 0x10 | ||
81 | |||
82 | #define AX_MCAST_FILTER_SIZE 8 | ||
83 | #define AX_MAX_MCAST 64 | ||
84 | |||
85 | #define AX_EEPROM_LEN 0x40 | ||
86 | |||
87 | #define AX_SWRESET_CLEAR 0x00 | ||
88 | #define AX_SWRESET_RR 0x01 | ||
89 | #define AX_SWRESET_RT 0x02 | ||
90 | #define AX_SWRESET_PRTE 0x04 | ||
91 | #define AX_SWRESET_PRL 0x08 | ||
92 | #define AX_SWRESET_BZ 0x10 | ||
93 | #define AX_SWRESET_IPRL 0x20 | ||
94 | #define AX_SWRESET_IPPD 0x40 | ||
95 | |||
96 | #define AX88772_IPG0_DEFAULT 0x15 | ||
97 | #define AX88772_IPG1_DEFAULT 0x0c | ||
98 | #define AX88772_IPG2_DEFAULT 0x12 | ||
99 | |||
100 | #define AX88772_MEDIUM_FULL_DUPLEX 0x0002 | ||
101 | #define AX88772_MEDIUM_RESERVED 0x0004 | ||
102 | #define AX88772_MEDIUM_RX_FC_ENABLE 0x0010 | ||
103 | #define AX88772_MEDIUM_TX_FC_ENABLE 0x0020 | ||
104 | #define AX88772_MEDIUM_PAUSE_FORMAT 0x0080 | ||
105 | #define AX88772_MEDIUM_RX_ENABLE 0x0100 | ||
106 | #define AX88772_MEDIUM_100MB 0x0200 | ||
107 | #define AX88772_MEDIUM_DEFAULT \ | ||
108 | (AX88772_MEDIUM_FULL_DUPLEX | AX88772_MEDIUM_RX_FC_ENABLE | \ | ||
109 | AX88772_MEDIUM_TX_FC_ENABLE | AX88772_MEDIUM_100MB | \ | ||
110 | AX88772_MEDIUM_RESERVED | AX88772_MEDIUM_RX_ENABLE ) | ||
111 | |||
112 | #define AX_EEPROM_MAGIC 0xdeadbeef | ||
113 | |||
114 | /* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */ | ||
115 | struct ax8817x_data { | ||
116 | u8 multi_filter[AX_MCAST_FILTER_SIZE]; | ||
117 | }; | ||
118 | |||
119 | struct ax88172_int_data { | ||
120 | u16 res1; | ||
121 | u8 link; | ||
122 | u16 res2; | ||
123 | u8 status; | ||
124 | u16 res3; | ||
125 | } __attribute__ ((packed)); | ||
126 | |||
127 | static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, | ||
128 | u16 size, void *data) | ||
129 | { | ||
130 | return usb_control_msg( | ||
131 | dev->udev, | ||
132 | usb_rcvctrlpipe(dev->udev, 0), | ||
133 | cmd, | ||
134 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
135 | value, | ||
136 | index, | ||
137 | data, | ||
138 | size, | ||
139 | USB_CTRL_GET_TIMEOUT); | ||
140 | } | ||
141 | |||
142 | static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, | ||
143 | u16 size, void *data) | ||
144 | { | ||
145 | return usb_control_msg( | ||
146 | dev->udev, | ||
147 | usb_sndctrlpipe(dev->udev, 0), | ||
148 | cmd, | ||
149 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
150 | value, | ||
151 | index, | ||
152 | data, | ||
153 | size, | ||
154 | USB_CTRL_SET_TIMEOUT); | ||
155 | } | ||
156 | |||
157 | static void ax8817x_async_cmd_callback(struct urb *urb, struct pt_regs *regs) | ||
158 | { | ||
159 | struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context; | ||
160 | |||
161 | if (urb->status < 0) | ||
162 | printk(KERN_DEBUG "ax8817x_async_cmd_callback() failed with %d", | ||
163 | urb->status); | ||
164 | |||
165 | kfree(req); | ||
166 | usb_free_urb(urb); | ||
167 | } | ||
168 | |||
169 | static void ax8817x_status(struct usbnet *dev, struct urb *urb) | ||
170 | { | ||
171 | struct ax88172_int_data *event; | ||
172 | int link; | ||
173 | |||
174 | if (urb->actual_length < 8) | ||
175 | return; | ||
176 | |||
177 | event = urb->transfer_buffer; | ||
178 | link = event->link & 0x01; | ||
179 | if (netif_carrier_ok(dev->net) != link) { | ||
180 | if (link) { | ||
181 | netif_carrier_on(dev->net); | ||
182 | usbnet_defer_kevent (dev, EVENT_LINK_RESET ); | ||
183 | } else | ||
184 | netif_carrier_off(dev->net); | ||
185 | devdbg(dev, "ax8817x - Link Status is: %d", link); | ||
186 | } | ||
187 | } | ||
188 | |||
189 | static void | ||
190 | ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index, | ||
191 | u16 size, void *data) | ||
192 | { | ||
193 | struct usb_ctrlrequest *req; | ||
194 | int status; | ||
195 | struct urb *urb; | ||
196 | |||
197 | if ((urb = usb_alloc_urb(0, GFP_ATOMIC)) == NULL) { | ||
198 | devdbg(dev, "Error allocating URB in write_cmd_async!"); | ||
199 | return; | ||
200 | } | ||
201 | |||
202 | if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) { | ||
203 | deverr(dev, "Failed to allocate memory for control request"); | ||
204 | usb_free_urb(urb); | ||
205 | return; | ||
206 | } | ||
207 | |||
208 | req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE; | ||
209 | req->bRequest = cmd; | ||
210 | req->wValue = cpu_to_le16(value); | ||
211 | req->wIndex = cpu_to_le16(index); | ||
212 | req->wLength = cpu_to_le16(size); | ||
213 | |||
214 | usb_fill_control_urb(urb, dev->udev, | ||
215 | usb_sndctrlpipe(dev->udev, 0), | ||
216 | (void *)req, data, size, | ||
217 | ax8817x_async_cmd_callback, req); | ||
218 | |||
219 | if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { | ||
220 | deverr(dev, "Error submitting the control message: status=%d", | ||
221 | status); | ||
222 | kfree(req); | ||
223 | usb_free_urb(urb); | ||
224 | } | ||
225 | } | ||
226 | |||
227 | static void ax8817x_set_multicast(struct net_device *net) | ||
228 | { | ||
229 | struct usbnet *dev = netdev_priv(net); | ||
230 | struct ax8817x_data *data = (struct ax8817x_data *)&dev->data; | ||
231 | u8 rx_ctl = 0x8c; | ||
232 | |||
233 | if (net->flags & IFF_PROMISC) { | ||
234 | rx_ctl |= 0x01; | ||
235 | } else if (net->flags & IFF_ALLMULTI | ||
236 | || net->mc_count > AX_MAX_MCAST) { | ||
237 | rx_ctl |= 0x02; | ||
238 | } else if (net->mc_count == 0) { | ||
239 | /* just broadcast and directed */ | ||
240 | } else { | ||
241 | /* We use the 20 byte dev->data | ||
242 | * for our 8 byte filter buffer | ||
243 | * to avoid allocating memory that | ||
244 | * is tricky to free later */ | ||
245 | struct dev_mc_list *mc_list = net->mc_list; | ||
246 | u32 crc_bits; | ||
247 | int i; | ||
248 | |||
249 | memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE); | ||
250 | |||
251 | /* Build the multicast hash filter. */ | ||
252 | for (i = 0; i < net->mc_count; i++) { | ||
253 | crc_bits = | ||
254 | ether_crc(ETH_ALEN, | ||
255 | mc_list->dmi_addr) >> 26; | ||
256 | data->multi_filter[crc_bits >> 3] |= | ||
257 | 1 << (crc_bits & 7); | ||
258 | mc_list = mc_list->next; | ||
259 | } | ||
260 | |||
261 | ax8817x_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0, | ||
262 | AX_MCAST_FILTER_SIZE, data->multi_filter); | ||
263 | |||
264 | rx_ctl |= 0x10; | ||
265 | } | ||
266 | |||
267 | ax8817x_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL); | ||
268 | } | ||
269 | |||
270 | static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc) | ||
271 | { | ||
272 | struct usbnet *dev = netdev_priv(netdev); | ||
273 | u16 res; | ||
274 | u8 buf[1]; | ||
275 | |||
276 | ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf); | ||
277 | ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, | ||
278 | (__u16)loc, 2, (u16 *)&res); | ||
279 | ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf); | ||
280 | |||
281 | return res & 0xffff; | ||
282 | } | ||
283 | |||
284 | /* same as above, but converts resulting value to cpu byte order */ | ||
285 | static int ax8817x_mdio_read_le(struct net_device *netdev, int phy_id, int loc) | ||
286 | { | ||
287 | return le16_to_cpu(ax8817x_mdio_read(netdev,phy_id, loc)); | ||
288 | } | ||
289 | |||
290 | static void | ||
291 | ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val) | ||
292 | { | ||
293 | struct usbnet *dev = netdev_priv(netdev); | ||
294 | u16 res = val; | ||
295 | u8 buf[1]; | ||
296 | |||
297 | ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf); | ||
298 | ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, | ||
299 | (__u16)loc, 2, (u16 *)&res); | ||
300 | ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf); | ||
301 | } | ||
302 | |||
303 | /* same as above, but converts new value to le16 byte order before writing */ | ||
304 | static void | ||
305 | ax8817x_mdio_write_le(struct net_device *netdev, int phy_id, int loc, int val) | ||
306 | { | ||
307 | ax8817x_mdio_write( netdev, phy_id, loc, cpu_to_le16(val) ); | ||
308 | } | ||
309 | |||
310 | static int ax88172_link_reset(struct usbnet *dev) | ||
311 | { | ||
312 | u16 lpa; | ||
313 | u16 adv; | ||
314 | u16 res; | ||
315 | u8 mode; | ||
316 | |||
317 | mode = AX_MEDIUM_TX_ABORT_ALLOW | AX_MEDIUM_FLOW_CONTROL_EN; | ||
318 | lpa = ax8817x_mdio_read_le(dev->net, dev->mii.phy_id, MII_LPA); | ||
319 | adv = ax8817x_mdio_read_le(dev->net, dev->mii.phy_id, MII_ADVERTISE); | ||
320 | res = mii_nway_result(lpa|adv); | ||
321 | if (res & LPA_DUPLEX) | ||
322 | mode |= AX_MEDIUM_FULL_DUPLEX; | ||
323 | ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL); | ||
324 | |||
325 | return 0; | ||
326 | } | ||
327 | |||
328 | static void | ||
329 | ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) | ||
330 | { | ||
331 | struct usbnet *dev = netdev_priv(net); | ||
332 | u8 opt; | ||
333 | |||
334 | if (ax8817x_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) { | ||
335 | wolinfo->supported = 0; | ||
336 | wolinfo->wolopts = 0; | ||
337 | return; | ||
338 | } | ||
339 | wolinfo->supported = WAKE_PHY | WAKE_MAGIC; | ||
340 | wolinfo->wolopts = 0; | ||
341 | if (opt & AX_MONITOR_MODE) { | ||
342 | if (opt & AX_MONITOR_LINK) | ||
343 | wolinfo->wolopts |= WAKE_PHY; | ||
344 | if (opt & AX_MONITOR_MAGIC) | ||
345 | wolinfo->wolopts |= WAKE_MAGIC; | ||
346 | } | ||
347 | } | ||
348 | |||
349 | static int | ||
350 | ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) | ||
351 | { | ||
352 | struct usbnet *dev = netdev_priv(net); | ||
353 | u8 opt = 0; | ||
354 | u8 buf[1]; | ||
355 | |||
356 | if (wolinfo->wolopts & WAKE_PHY) | ||
357 | opt |= AX_MONITOR_LINK; | ||
358 | if (wolinfo->wolopts & WAKE_MAGIC) | ||
359 | opt |= AX_MONITOR_MAGIC; | ||
360 | if (opt != 0) | ||
361 | opt |= AX_MONITOR_MODE; | ||
362 | |||
363 | if (ax8817x_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE, | ||
364 | opt, 0, 0, &buf) < 0) | ||
365 | return -EINVAL; | ||
366 | |||
367 | return 0; | ||
368 | } | ||
369 | |||
370 | static int ax8817x_get_eeprom_len(struct net_device *net) | ||
371 | { | ||
372 | return AX_EEPROM_LEN; | ||
373 | } | ||
374 | |||
375 | static int ax8817x_get_eeprom(struct net_device *net, | ||
376 | struct ethtool_eeprom *eeprom, u8 *data) | ||
377 | { | ||
378 | struct usbnet *dev = netdev_priv(net); | ||
379 | u16 *ebuf = (u16 *)data; | ||
380 | int i; | ||
381 | |||
382 | /* Crude hack to ensure that we don't overwrite memory | ||
383 | * if an odd length is supplied | ||
384 | */ | ||
385 | if (eeprom->len % 2) | ||
386 | return -EINVAL; | ||
387 | |||
388 | eeprom->magic = AX_EEPROM_MAGIC; | ||
389 | |||
390 | /* ax8817x returns 2 bytes from eeprom on read */ | ||
391 | for (i=0; i < eeprom->len / 2; i++) { | ||
392 | if (ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM, | ||
393 | eeprom->offset + i, 0, 2, &ebuf[i]) < 0) | ||
394 | return -EINVAL; | ||
395 | } | ||
396 | return 0; | ||
397 | } | ||
398 | |||
399 | static void ax8817x_get_drvinfo (struct net_device *net, | ||
400 | struct ethtool_drvinfo *info) | ||
401 | { | ||
402 | /* Inherit standard device info */ | ||
403 | usbnet_get_drvinfo(net, info); | ||
404 | info->eedump_len = 0x3e; | ||
405 | } | ||
406 | |||
407 | static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd) | ||
408 | { | ||
409 | struct usbnet *dev = netdev_priv(net); | ||
410 | |||
411 | return mii_ethtool_gset(&dev->mii,cmd); | ||
412 | } | ||
413 | |||
414 | static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd) | ||
415 | { | ||
416 | struct usbnet *dev = netdev_priv(net); | ||
417 | |||
418 | return mii_ethtool_sset(&dev->mii,cmd); | ||
419 | } | ||
420 | |||
421 | /* We need to override some ethtool_ops so we require our | ||
422 | own structure so we don't interfere with other usbnet | ||
423 | devices that may be connected at the same time. */ | ||
424 | static struct ethtool_ops ax8817x_ethtool_ops = { | ||
425 | .get_drvinfo = ax8817x_get_drvinfo, | ||
426 | .get_link = ethtool_op_get_link, | ||
427 | .get_msglevel = usbnet_get_msglevel, | ||
428 | .set_msglevel = usbnet_set_msglevel, | ||
429 | .get_wol = ax8817x_get_wol, | ||
430 | .set_wol = ax8817x_set_wol, | ||
431 | .get_eeprom_len = ax8817x_get_eeprom_len, | ||
432 | .get_eeprom = ax8817x_get_eeprom, | ||
433 | .get_settings = ax8817x_get_settings, | ||
434 | .set_settings = ax8817x_set_settings, | ||
435 | }; | ||
436 | |||
437 | static int ax8817x_ioctl (struct net_device *net, struct ifreq *rq, int cmd) | ||
438 | { | ||
439 | struct usbnet *dev = netdev_priv(net); | ||
440 | |||
441 | return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); | ||
442 | } | ||
443 | |||
444 | static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf) | ||
445 | { | ||
446 | int ret = 0; | ||
447 | void *buf; | ||
448 | int i; | ||
449 | unsigned long gpio_bits = dev->driver_info->data; | ||
450 | |||
451 | usbnet_get_endpoints(dev,intf); | ||
452 | |||
453 | buf = kmalloc(ETH_ALEN, GFP_KERNEL); | ||
454 | if(!buf) { | ||
455 | ret = -ENOMEM; | ||
456 | goto out1; | ||
457 | } | ||
458 | |||
459 | /* Toggle the GPIOs in a manufacturer/model specific way */ | ||
460 | for (i = 2; i >= 0; i--) { | ||
461 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS, | ||
462 | (gpio_bits >> (i * 8)) & 0xff, 0, 0, | ||
463 | buf)) < 0) | ||
464 | goto out2; | ||
465 | msleep(5); | ||
466 | } | ||
467 | |||
468 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, | ||
469 | 0x80, 0, 0, buf)) < 0) { | ||
470 | dbg("send AX_CMD_WRITE_RX_CTL failed: %d", ret); | ||
471 | goto out2; | ||
472 | } | ||
473 | |||
474 | /* Get the MAC address */ | ||
475 | memset(buf, 0, ETH_ALEN); | ||
476 | if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_NODE_ID, | ||
477 | 0, 0, 6, buf)) < 0) { | ||
478 | dbg("read AX_CMD_READ_NODE_ID failed: %d", ret); | ||
479 | goto out2; | ||
480 | } | ||
481 | memcpy(dev->net->dev_addr, buf, ETH_ALEN); | ||
482 | |||
483 | /* Get the PHY id */ | ||
484 | if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, | ||
485 | 0, 0, 2, buf)) < 0) { | ||
486 | dbg("error on read AX_CMD_READ_PHY_ID: %02x", ret); | ||
487 | goto out2; | ||
488 | } else if (ret < 2) { | ||
489 | /* this should always return 2 bytes */ | ||
490 | dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", | ||
491 | ret); | ||
492 | ret = -EIO; | ||
493 | goto out2; | ||
494 | } | ||
495 | |||
496 | /* Initialize MII structure */ | ||
497 | dev->mii.dev = dev->net; | ||
498 | dev->mii.mdio_read = ax8817x_mdio_read; | ||
499 | dev->mii.mdio_write = ax8817x_mdio_write; | ||
500 | dev->mii.phy_id_mask = 0x3f; | ||
501 | dev->mii.reg_num_mask = 0x1f; | ||
502 | dev->mii.phy_id = *((u8 *)buf + 1); | ||
503 | dev->net->do_ioctl = ax8817x_ioctl; | ||
504 | |||
505 | dev->net->set_multicast_list = ax8817x_set_multicast; | ||
506 | dev->net->ethtool_ops = &ax8817x_ethtool_ops; | ||
507 | |||
508 | ax8817x_mdio_write_le(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); | ||
509 | ax8817x_mdio_write_le(dev->net, dev->mii.phy_id, MII_ADVERTISE, | ||
510 | ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); | ||
511 | mii_nway_restart(&dev->mii); | ||
512 | |||
513 | return 0; | ||
514 | out2: | ||
515 | kfree(buf); | ||
516 | out1: | ||
517 | return ret; | ||
518 | } | ||
519 | |||
520 | static struct ethtool_ops ax88772_ethtool_ops = { | ||
521 | .get_drvinfo = ax8817x_get_drvinfo, | ||
522 | .get_link = ethtool_op_get_link, | ||
523 | .get_msglevel = usbnet_get_msglevel, | ||
524 | .set_msglevel = usbnet_set_msglevel, | ||
525 | .get_wol = ax8817x_get_wol, | ||
526 | .set_wol = ax8817x_set_wol, | ||
527 | .get_eeprom_len = ax8817x_get_eeprom_len, | ||
528 | .get_eeprom = ax8817x_get_eeprom, | ||
529 | .get_settings = ax8817x_get_settings, | ||
530 | .set_settings = ax8817x_set_settings, | ||
531 | }; | ||
532 | |||
533 | static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf) | ||
534 | { | ||
535 | int ret; | ||
536 | void *buf; | ||
537 | |||
538 | usbnet_get_endpoints(dev,intf); | ||
539 | |||
540 | buf = kmalloc(6, GFP_KERNEL); | ||
541 | if(!buf) { | ||
542 | dbg ("Cannot allocate memory for buffer"); | ||
543 | ret = -ENOMEM; | ||
544 | goto out1; | ||
545 | } | ||
546 | |||
547 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS, | ||
548 | 0x00B0, 0, 0, buf)) < 0) | ||
549 | goto out2; | ||
550 | |||
551 | msleep(5); | ||
552 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_PHY_SELECT, | ||
553 | 0x0001, 0, 0, buf)) < 0) { | ||
554 | dbg("Select PHY #1 failed: %d", ret); | ||
555 | goto out2; | ||
556 | } | ||
557 | |||
558 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPPD, | ||
559 | 0, 0, buf)) < 0) { | ||
560 | dbg("Failed to power down internal PHY: %d", ret); | ||
561 | goto out2; | ||
562 | } | ||
563 | |||
564 | msleep(150); | ||
565 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_CLEAR, | ||
566 | 0, 0, buf)) < 0) { | ||
567 | dbg("Failed to perform software reset: %d", ret); | ||
568 | goto out2; | ||
569 | } | ||
570 | |||
571 | msleep(150); | ||
572 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, | ||
573 | AX_SWRESET_IPRL | AX_SWRESET_PRL, | ||
574 | 0, 0, buf)) < 0) { | ||
575 | dbg("Failed to set Internal/External PHY reset control: %d", | ||
576 | ret); | ||
577 | goto out2; | ||
578 | } | ||
579 | |||
580 | msleep(150); | ||
581 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, | ||
582 | 0x0000, 0, 0, buf)) < 0) { | ||
583 | dbg("Failed to reset RX_CTL: %d", ret); | ||
584 | goto out2; | ||
585 | } | ||
586 | |||
587 | /* Get the MAC address */ | ||
588 | memset(buf, 0, ETH_ALEN); | ||
589 | if ((ret = ax8817x_read_cmd(dev, AX88772_CMD_READ_NODE_ID, | ||
590 | 0, 0, ETH_ALEN, buf)) < 0) { | ||
591 | dbg("Failed to read MAC address: %d", ret); | ||
592 | goto out2; | ||
593 | } | ||
594 | memcpy(dev->net->dev_addr, buf, ETH_ALEN); | ||
595 | |||
596 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, | ||
597 | 0, 0, 0, buf)) < 0) { | ||
598 | dbg("Enabling software MII failed: %d", ret); | ||
599 | goto out2; | ||
600 | } | ||
601 | |||
602 | if (((ret = ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, | ||
603 | 0x0010, 2, 2, buf)) < 0) | ||
604 | || (*((u16 *)buf) != 0x003b)) { | ||
605 | dbg("Read PHY register 2 must be 0x3b00: %d", ret); | ||
606 | goto out2; | ||
607 | } | ||
608 | |||
609 | /* Initialize MII structure */ | ||
610 | dev->mii.dev = dev->net; | ||
611 | dev->mii.mdio_read = ax8817x_mdio_read; | ||
612 | dev->mii.mdio_write = ax8817x_mdio_write; | ||
613 | dev->mii.phy_id_mask = 0xff; | ||
614 | dev->mii.reg_num_mask = 0xff; | ||
615 | dev->net->do_ioctl = ax8817x_ioctl; | ||
616 | |||
617 | /* Get the PHY id */ | ||
618 | if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, | ||
619 | 0, 0, 2, buf)) < 0) { | ||
620 | dbg("Error reading PHY ID: %02x", ret); | ||
621 | goto out2; | ||
622 | } else if (ret < 2) { | ||
623 | /* this should always return 2 bytes */ | ||
624 | dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", | ||
625 | ret); | ||
626 | ret = -EIO; | ||
627 | goto out2; | ||
628 | } | ||
629 | dev->mii.phy_id = *((u8 *)buf + 1); | ||
630 | |||
631 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_PRL, | ||
632 | 0, 0, buf)) < 0) { | ||
633 | dbg("Set external PHY reset pin level: %d", ret); | ||
634 | goto out2; | ||
635 | } | ||
636 | msleep(150); | ||
637 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, | ||
638 | AX_SWRESET_IPRL | AX_SWRESET_PRL, | ||
639 | 0, 0, buf)) < 0) { | ||
640 | dbg("Set Internal/External PHY reset control: %d", ret); | ||
641 | goto out2; | ||
642 | } | ||
643 | msleep(150); | ||
644 | |||
645 | |||
646 | dev->net->set_multicast_list = ax8817x_set_multicast; | ||
647 | dev->net->ethtool_ops = &ax88772_ethtool_ops; | ||
648 | |||
649 | ax8817x_mdio_write_le(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); | ||
650 | ax8817x_mdio_write_le(dev->net, dev->mii.phy_id, MII_ADVERTISE, | ||
651 | ADVERTISE_ALL | ADVERTISE_CSMA); | ||
652 | mii_nway_restart(&dev->mii); | ||
653 | |||
654 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, | ||
655 | AX88772_MEDIUM_DEFAULT, 0, 0, buf)) < 0) { | ||
656 | dbg("Write medium mode register: %d", ret); | ||
657 | goto out2; | ||
658 | } | ||
659 | |||
660 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_IPG0, | ||
661 | AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT, | ||
662 | AX88772_IPG2_DEFAULT, 0, buf)) < 0) { | ||
663 | dbg("Write IPG,IPG1,IPG2 failed: %d", ret); | ||
664 | goto out2; | ||
665 | } | ||
666 | if ((ret = | ||
667 | ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf)) < 0) { | ||
668 | dbg("Failed to set hardware MII: %02x", ret); | ||
669 | goto out2; | ||
670 | } | ||
671 | |||
672 | /* Set RX_CTL to default values with 2k buffer, and enable cactus */ | ||
673 | if ((ret = | ||
674 | ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0088, 0, 0, | ||
675 | buf)) < 0) { | ||
676 | dbg("Reset RX_CTL failed: %d", ret); | ||
677 | goto out2; | ||
678 | } | ||
679 | |||
680 | kfree(buf); | ||
681 | |||
682 | /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */ | ||
683 | if (dev->driver_info->flags & FLAG_FRAMING_AX) { | ||
684 | /* hard_mtu is still the default - the device does not support | ||
685 | jumbo eth frames */ | ||
686 | dev->rx_urb_size = 2048; | ||
687 | } | ||
688 | |||
689 | return 0; | ||
690 | |||
691 | out2: | ||
692 | kfree(buf); | ||
693 | out1: | ||
694 | return ret; | ||
695 | } | ||
696 | |||
697 | static int ax88772_rx_fixup(struct usbnet *dev, struct sk_buff *skb) | ||
698 | { | ||
699 | u8 *head; | ||
700 | u32 header; | ||
701 | char *packet; | ||
702 | struct sk_buff *ax_skb; | ||
703 | u16 size; | ||
704 | |||
705 | head = (u8 *) skb->data; | ||
706 | memcpy(&header, head, sizeof(header)); | ||
707 | le32_to_cpus(&header); | ||
708 | packet = head + sizeof(header); | ||
709 | |||
710 | skb_pull(skb, 4); | ||
711 | |||
712 | while (skb->len > 0) { | ||
713 | if ((short)(header & 0x0000ffff) != | ||
714 | ~((short)((header & 0xffff0000) >> 16))) { | ||
715 | devdbg(dev,"header length data is error"); | ||
716 | } | ||
717 | /* get the packet length */ | ||
718 | size = (u16) (header & 0x0000ffff); | ||
719 | |||
720 | if ((skb->len) - ((size + 1) & 0xfffe) == 0) | ||
721 | return 2; | ||
722 | if (size > ETH_FRAME_LEN) { | ||
723 | devdbg(dev,"invalid rx length %d", size); | ||
724 | return 0; | ||
725 | } | ||
726 | ax_skb = skb_clone(skb, GFP_ATOMIC); | ||
727 | if (ax_skb) { | ||
728 | ax_skb->len = size; | ||
729 | ax_skb->data = packet; | ||
730 | ax_skb->tail = packet + size; | ||
731 | usbnet_skb_return(dev, ax_skb); | ||
732 | } else { | ||
733 | return 0; | ||
734 | } | ||
735 | |||
736 | skb_pull(skb, (size + 1) & 0xfffe); | ||
737 | |||
738 | if (skb->len == 0) | ||
739 | break; | ||
740 | |||
741 | head = (u8 *) skb->data; | ||
742 | memcpy(&header, head, sizeof(header)); | ||
743 | le32_to_cpus(&header); | ||
744 | packet = head + sizeof(header); | ||
745 | skb_pull(skb, 4); | ||
746 | } | ||
747 | |||
748 | if (skb->len < 0) { | ||
749 | devdbg(dev,"invalid rx length %d", skb->len); | ||
750 | return 0; | ||
751 | } | ||
752 | return 1; | ||
753 | } | ||
754 | |||
755 | static struct sk_buff *ax88772_tx_fixup(struct usbnet *dev, struct sk_buff *skb, | ||
756 | unsigned flags) | ||
757 | { | ||
758 | int padlen; | ||
759 | int headroom = skb_headroom(skb); | ||
760 | int tailroom = skb_tailroom(skb); | ||
761 | u32 packet_len; | ||
762 | u32 padbytes = 0xffff0000; | ||
763 | |||
764 | padlen = ((skb->len + 4) % 512) ? 0 : 4; | ||
765 | |||
766 | if ((!skb_cloned(skb)) | ||
767 | && ((headroom + tailroom) >= (4 + padlen))) { | ||
768 | if ((headroom < 4) || (tailroom < padlen)) { | ||
769 | skb->data = memmove(skb->head + 4, skb->data, skb->len); | ||
770 | skb->tail = skb->data + skb->len; | ||
771 | } | ||
772 | } else { | ||
773 | struct sk_buff *skb2; | ||
774 | skb2 = skb_copy_expand(skb, 4, padlen, flags); | ||
775 | dev_kfree_skb_any(skb); | ||
776 | skb = skb2; | ||
777 | if (!skb) | ||
778 | return NULL; | ||
779 | } | ||
780 | |||
781 | skb_push(skb, 4); | ||
782 | packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4); | ||
783 | memcpy(skb->data, &packet_len, sizeof(packet_len)); | ||
784 | |||
785 | if ((skb->len % 512) == 0) { | ||
786 | memcpy( skb->tail, &padbytes, sizeof(padbytes)); | ||
787 | skb_put(skb, sizeof(padbytes)); | ||
788 | } | ||
789 | return skb; | ||
790 | } | ||
791 | |||
792 | static int ax88772_link_reset(struct usbnet *dev) | ||
793 | { | ||
794 | u16 lpa; | ||
795 | u16 adv; | ||
796 | u16 res; | ||
797 | u16 mode; | ||
798 | |||
799 | mode = AX88772_MEDIUM_DEFAULT; | ||
800 | lpa = ax8817x_mdio_read_le(dev->net, dev->mii.phy_id, MII_LPA); | ||
801 | adv = ax8817x_mdio_read_le(dev->net, dev->mii.phy_id, MII_ADVERTISE); | ||
802 | res = mii_nway_result(lpa|adv); | ||
803 | |||
804 | if ((res & LPA_DUPLEX) == 0) | ||
805 | mode &= ~AX88772_MEDIUM_FULL_DUPLEX; | ||
806 | if ((res & LPA_100) == 0) | ||
807 | mode &= ~AX88772_MEDIUM_100MB; | ||
808 | ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL); | ||
809 | |||
810 | return 0; | ||
811 | } | ||
812 | |||
813 | static const struct driver_info ax8817x_info = { | ||
814 | .description = "ASIX AX8817x USB 2.0 Ethernet", | ||
815 | .bind = ax8817x_bind, | ||
816 | .status = ax8817x_status, | ||
817 | .link_reset = ax88172_link_reset, | ||
818 | .reset = ax88172_link_reset, | ||
819 | .flags = FLAG_ETHER, | ||
820 | .data = 0x00130103, | ||
821 | }; | ||
822 | |||
823 | static const struct driver_info dlink_dub_e100_info = { | ||
824 | .description = "DLink DUB-E100 USB Ethernet", | ||
825 | .bind = ax8817x_bind, | ||
826 | .status = ax8817x_status, | ||
827 | .link_reset = ax88172_link_reset, | ||
828 | .reset = ax88172_link_reset, | ||
829 | .flags = FLAG_ETHER, | ||
830 | .data = 0x009f9d9f, | ||
831 | }; | ||
832 | |||
833 | static const struct driver_info netgear_fa120_info = { | ||
834 | .description = "Netgear FA-120 USB Ethernet", | ||
835 | .bind = ax8817x_bind, | ||
836 | .status = ax8817x_status, | ||
837 | .link_reset = ax88172_link_reset, | ||
838 | .reset = ax88172_link_reset, | ||
839 | .flags = FLAG_ETHER, | ||
840 | .data = 0x00130103, | ||
841 | }; | ||
842 | |||
843 | static const struct driver_info hawking_uf200_info = { | ||
844 | .description = "Hawking UF200 USB Ethernet", | ||
845 | .bind = ax8817x_bind, | ||
846 | .status = ax8817x_status, | ||
847 | .link_reset = ax88172_link_reset, | ||
848 | .reset = ax88172_link_reset, | ||
849 | .flags = FLAG_ETHER, | ||
850 | .data = 0x001f1d1f, | ||
851 | }; | ||
852 | |||
853 | static const struct driver_info ax88772_info = { | ||
854 | .description = "ASIX AX88772 USB 2.0 Ethernet", | ||
855 | .bind = ax88772_bind, | ||
856 | .status = ax8817x_status, | ||
857 | .link_reset = ax88772_link_reset, | ||
858 | .reset = ax88772_link_reset, | ||
859 | .flags = FLAG_ETHER | FLAG_FRAMING_AX, | ||
860 | .rx_fixup = ax88772_rx_fixup, | ||
861 | .tx_fixup = ax88772_tx_fixup, | ||
862 | .data = 0x00130103, | ||
863 | }; | ||
864 | |||
865 | static const struct usb_device_id products [] = { | ||
866 | { | ||
867 | // Linksys USB200M | ||
868 | USB_DEVICE (0x077b, 0x2226), | ||
869 | .driver_info = (unsigned long) &ax8817x_info, | ||
870 | }, { | ||
871 | // Netgear FA120 | ||
872 | USB_DEVICE (0x0846, 0x1040), | ||
873 | .driver_info = (unsigned long) &netgear_fa120_info, | ||
874 | }, { | ||
875 | // DLink DUB-E100 | ||
876 | USB_DEVICE (0x2001, 0x1a00), | ||
877 | .driver_info = (unsigned long) &dlink_dub_e100_info, | ||
878 | }, { | ||
879 | // Intellinet, ST Lab USB Ethernet | ||
880 | USB_DEVICE (0x0b95, 0x1720), | ||
881 | .driver_info = (unsigned long) &ax8817x_info, | ||
882 | }, { | ||
883 | // Hawking UF200, TrendNet TU2-ET100 | ||
884 | USB_DEVICE (0x07b8, 0x420a), | ||
885 | .driver_info = (unsigned long) &hawking_uf200_info, | ||
886 | }, { | ||
887 | // Billionton Systems, USB2AR | ||
888 | USB_DEVICE (0x08dd, 0x90ff), | ||
889 | .driver_info = (unsigned long) &ax8817x_info, | ||
890 | }, { | ||
891 | // ATEN UC210T | ||
892 | USB_DEVICE (0x0557, 0x2009), | ||
893 | .driver_info = (unsigned long) &ax8817x_info, | ||
894 | }, { | ||
895 | // Buffalo LUA-U2-KTX | ||
896 | USB_DEVICE (0x0411, 0x003d), | ||
897 | .driver_info = (unsigned long) &ax8817x_info, | ||
898 | }, { | ||
899 | // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter" | ||
900 | USB_DEVICE (0x6189, 0x182d), | ||
901 | .driver_info = (unsigned long) &ax8817x_info, | ||
902 | }, { | ||
903 | // corega FEther USB2-TX | ||
904 | USB_DEVICE (0x07aa, 0x0017), | ||
905 | .driver_info = (unsigned long) &ax8817x_info, | ||
906 | }, { | ||
907 | // Surecom EP-1427X-2 | ||
908 | USB_DEVICE (0x1189, 0x0893), | ||
909 | .driver_info = (unsigned long) &ax8817x_info, | ||
910 | }, { | ||
911 | // goodway corp usb gwusb2e | ||
912 | USB_DEVICE (0x1631, 0x6200), | ||
913 | .driver_info = (unsigned long) &ax8817x_info, | ||
914 | }, { | ||
915 | // ASIX AX88772 10/100 | ||
916 | USB_DEVICE (0x0b95, 0x7720), | ||
917 | .driver_info = (unsigned long) &ax88772_info, | ||
918 | }, | ||
919 | { }, // END | ||
920 | }; | ||
921 | MODULE_DEVICE_TABLE(usb, products); | ||
922 | |||
923 | static struct usb_driver asix_driver = { | ||
924 | .owner = THIS_MODULE, | ||
925 | .name = "asix", | ||
926 | .id_table = products, | ||
927 | .probe = usbnet_probe, | ||
928 | .suspend = usbnet_suspend, | ||
929 | .resume = usbnet_resume, | ||
930 | .disconnect = usbnet_disconnect, | ||
931 | }; | ||
932 | |||
933 | static int __init asix_init(void) | ||
934 | { | ||
935 | return usb_register(&asix_driver); | ||
936 | } | ||
937 | module_init(asix_init); | ||
938 | |||
939 | static void __exit asix_exit(void) | ||
940 | { | ||
941 | usb_deregister(&asix_driver); | ||
942 | } | ||
943 | module_exit(asix_exit); | ||
944 | |||
945 | MODULE_AUTHOR("David Hollis"); | ||
946 | MODULE_DESCRIPTION("ASIX AX8817X based USB 2.0 Ethernet Devices"); | ||
947 | MODULE_LICENSE("GPL"); | ||
948 | |||
diff --git a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c index 57b41fbd3bb8..99a488140140 100644 --- a/drivers/usb/net/usbnet.c +++ b/drivers/usb/net/usbnet.c | |||
@@ -3,8 +3,6 @@ | |||
3 | * Copyright (C) 2000-2005 by David Brownell | 3 | * Copyright (C) 2000-2005 by David Brownell |
4 | * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz> | 4 | * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz> |
5 | * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com> | 5 | * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com> |
6 | * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net> | ||
7 | * Copyright (c) 2002-2003 TiVo Inc. | ||
8 | * | 6 | * |
9 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
@@ -156,9 +154,6 @@ | |||
156 | #define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4) | 154 | #define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4) |
157 | #define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4) | 155 | #define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4) |
158 | 156 | ||
159 | /* packets are always ethernet, sometimes wrapped in other framing */ | ||
160 | #define MIN_PACKET sizeof(struct ethhdr) | ||
161 | |||
162 | // reawaken network queue this soon after stopping; else watchdog barks | 157 | // reawaken network queue this soon after stopping; else watchdog barks |
163 | #define TX_TIMEOUT_JIFFIES (5*HZ) | 158 | #define TX_TIMEOUT_JIFFIES (5*HZ) |
164 | 159 | ||
@@ -186,11 +181,7 @@ MODULE_PARM_DESC (msg_level, "Override default message level"); | |||
186 | 181 | ||
187 | /*-------------------------------------------------------------------------*/ | 182 | /*-------------------------------------------------------------------------*/ |
188 | 183 | ||
189 | static void usbnet_get_drvinfo (struct net_device *, struct ethtool_drvinfo *); | ||
190 | static u32 usbnet_get_link (struct net_device *); | 184 | static u32 usbnet_get_link (struct net_device *); |
191 | static u32 usbnet_get_msglevel (struct net_device *); | ||
192 | static void usbnet_set_msglevel (struct net_device *, u32); | ||
193 | static void defer_kevent (struct usbnet *, int); | ||
194 | 185 | ||
195 | /* mostly for PDA style devices, which are always connected if present */ | 186 | /* mostly for PDA style devices, which are always connected if present */ |
196 | static int always_connected (struct usbnet *dev) | 187 | static int always_connected (struct usbnet *dev) |
@@ -199,8 +190,7 @@ static int always_connected (struct usbnet *dev) | |||
199 | } | 190 | } |
200 | 191 | ||
201 | /* handles CDC Ethernet and many other network "bulk data" interfaces */ | 192 | /* handles CDC Ethernet and many other network "bulk data" interfaces */ |
202 | static int | 193 | int usbnet_get_endpoints(struct usbnet *dev, struct usb_interface *intf) |
203 | get_endpoints (struct usbnet *dev, struct usb_interface *intf) | ||
204 | { | 194 | { |
205 | int tmp; | 195 | int tmp; |
206 | struct usb_host_interface *alt = NULL; | 196 | struct usb_host_interface *alt = NULL; |
@@ -264,6 +254,7 @@ get_endpoints (struct usbnet *dev, struct usb_interface *intf) | |||
264 | dev->status = status; | 254 | dev->status = status; |
265 | return 0; | 255 | return 0; |
266 | } | 256 | } |
257 | EXPORT_SYMBOL_GPL(usbnet_get_endpoints); | ||
267 | 258 | ||
268 | static void intr_complete (struct urb *urb, struct pt_regs *regs); | 259 | static void intr_complete (struct urb *urb, struct pt_regs *regs); |
269 | 260 | ||
@@ -303,7 +294,11 @@ static int init_status (struct usbnet *dev, struct usb_interface *intf) | |||
303 | return 0; | 294 | return 0; |
304 | } | 295 | } |
305 | 296 | ||
306 | static void skb_return (struct usbnet *dev, struct sk_buff *skb) | 297 | /* Passes this packet up the stack, updating its accounting. |
298 | * Some link protocols batch packets, so their rx_fixup paths | ||
299 | * can return clones as well as just modify the original skb. | ||
300 | */ | ||
301 | void usbnet_skb_return (struct usbnet *dev, struct sk_buff *skb) | ||
307 | { | 302 | { |
308 | int status; | 303 | int status; |
309 | 304 | ||
@@ -320,784 +315,7 @@ static void skb_return (struct usbnet *dev, struct sk_buff *skb) | |||
320 | if (status != NET_RX_SUCCESS && netif_msg_rx_err (dev)) | 315 | if (status != NET_RX_SUCCESS && netif_msg_rx_err (dev)) |
321 | devdbg (dev, "netif_rx status %d", status); | 316 | devdbg (dev, "netif_rx status %d", status); |
322 | } | 317 | } |
323 | 318 | EXPORT_SYMBOL_GPL(usbnet_skb_return); | |
324 | |||
325 | #ifdef CONFIG_USB_AX8817X | ||
326 | /* ASIX AX8817X based USB 2.0 Ethernet Devices */ | ||
327 | |||
328 | #define HAVE_HARDWARE | ||
329 | #define NEED_MII | ||
330 | |||
331 | #include <linux/crc32.h> | ||
332 | |||
333 | #define AX_CMD_SET_SW_MII 0x06 | ||
334 | #define AX_CMD_READ_MII_REG 0x07 | ||
335 | #define AX_CMD_WRITE_MII_REG 0x08 | ||
336 | #define AX_CMD_SET_HW_MII 0x0a | ||
337 | #define AX_CMD_READ_EEPROM 0x0b | ||
338 | #define AX_CMD_WRITE_EEPROM 0x0c | ||
339 | #define AX_CMD_WRITE_ENABLE 0x0d | ||
340 | #define AX_CMD_WRITE_DISABLE 0x0e | ||
341 | #define AX_CMD_WRITE_RX_CTL 0x10 | ||
342 | #define AX_CMD_READ_IPG012 0x11 | ||
343 | #define AX_CMD_WRITE_IPG0 0x12 | ||
344 | #define AX_CMD_WRITE_IPG1 0x13 | ||
345 | #define AX_CMD_WRITE_IPG2 0x14 | ||
346 | #define AX_CMD_WRITE_MULTI_FILTER 0x16 | ||
347 | #define AX_CMD_READ_NODE_ID 0x17 | ||
348 | #define AX_CMD_READ_PHY_ID 0x19 | ||
349 | #define AX_CMD_READ_MEDIUM_STATUS 0x1a | ||
350 | #define AX_CMD_WRITE_MEDIUM_MODE 0x1b | ||
351 | #define AX_CMD_READ_MONITOR_MODE 0x1c | ||
352 | #define AX_CMD_WRITE_MONITOR_MODE 0x1d | ||
353 | #define AX_CMD_WRITE_GPIOS 0x1f | ||
354 | #define AX_CMD_SW_RESET 0x20 | ||
355 | #define AX_CMD_SW_PHY_STATUS 0x21 | ||
356 | #define AX_CMD_SW_PHY_SELECT 0x22 | ||
357 | #define AX88772_CMD_READ_NODE_ID 0x13 | ||
358 | |||
359 | #define AX_MONITOR_MODE 0x01 | ||
360 | #define AX_MONITOR_LINK 0x02 | ||
361 | #define AX_MONITOR_MAGIC 0x04 | ||
362 | #define AX_MONITOR_HSFS 0x10 | ||
363 | |||
364 | /* AX88172 Medium Status Register values */ | ||
365 | #define AX_MEDIUM_FULL_DUPLEX 0x02 | ||
366 | #define AX_MEDIUM_TX_ABORT_ALLOW 0x04 | ||
367 | #define AX_MEDIUM_FLOW_CONTROL_EN 0x10 | ||
368 | |||
369 | #define AX_MCAST_FILTER_SIZE 8 | ||
370 | #define AX_MAX_MCAST 64 | ||
371 | |||
372 | #define AX_EEPROM_LEN 0x40 | ||
373 | |||
374 | #define AX_SWRESET_CLEAR 0x00 | ||
375 | #define AX_SWRESET_RR 0x01 | ||
376 | #define AX_SWRESET_RT 0x02 | ||
377 | #define AX_SWRESET_PRTE 0x04 | ||
378 | #define AX_SWRESET_PRL 0x08 | ||
379 | #define AX_SWRESET_BZ 0x10 | ||
380 | #define AX_SWRESET_IPRL 0x20 | ||
381 | #define AX_SWRESET_IPPD 0x40 | ||
382 | |||
383 | #define AX88772_IPG0_DEFAULT 0x15 | ||
384 | #define AX88772_IPG1_DEFAULT 0x0c | ||
385 | #define AX88772_IPG2_DEFAULT 0x12 | ||
386 | |||
387 | #define AX88772_MEDIUM_FULL_DUPLEX 0x0002 | ||
388 | #define AX88772_MEDIUM_RESERVED 0x0004 | ||
389 | #define AX88772_MEDIUM_RX_FC_ENABLE 0x0010 | ||
390 | #define AX88772_MEDIUM_TX_FC_ENABLE 0x0020 | ||
391 | #define AX88772_MEDIUM_PAUSE_FORMAT 0x0080 | ||
392 | #define AX88772_MEDIUM_RX_ENABLE 0x0100 | ||
393 | #define AX88772_MEDIUM_100MB 0x0200 | ||
394 | #define AX88772_MEDIUM_DEFAULT \ | ||
395 | (AX88772_MEDIUM_FULL_DUPLEX | AX88772_MEDIUM_RX_FC_ENABLE | \ | ||
396 | AX88772_MEDIUM_TX_FC_ENABLE | AX88772_MEDIUM_100MB | \ | ||
397 | AX88772_MEDIUM_RESERVED | AX88772_MEDIUM_RX_ENABLE ) | ||
398 | |||
399 | #define AX_EEPROM_MAGIC 0xdeadbeef | ||
400 | |||
401 | /* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */ | ||
402 | struct ax8817x_data { | ||
403 | u8 multi_filter[AX_MCAST_FILTER_SIZE]; | ||
404 | }; | ||
405 | |||
406 | struct ax88172_int_data { | ||
407 | u16 res1; | ||
408 | u8 link; | ||
409 | u16 res2; | ||
410 | u8 status; | ||
411 | u16 res3; | ||
412 | } __attribute__ ((packed)); | ||
413 | |||
414 | static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, | ||
415 | u16 size, void *data) | ||
416 | { | ||
417 | return usb_control_msg( | ||
418 | dev->udev, | ||
419 | usb_rcvctrlpipe(dev->udev, 0), | ||
420 | cmd, | ||
421 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
422 | value, | ||
423 | index, | ||
424 | data, | ||
425 | size, | ||
426 | CONTROL_TIMEOUT_MS); | ||
427 | } | ||
428 | |||
429 | static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, | ||
430 | u16 size, void *data) | ||
431 | { | ||
432 | return usb_control_msg( | ||
433 | dev->udev, | ||
434 | usb_sndctrlpipe(dev->udev, 0), | ||
435 | cmd, | ||
436 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | ||
437 | value, | ||
438 | index, | ||
439 | data, | ||
440 | size, | ||
441 | CONTROL_TIMEOUT_MS); | ||
442 | } | ||
443 | |||
444 | static void ax8817x_async_cmd_callback(struct urb *urb, struct pt_regs *regs) | ||
445 | { | ||
446 | struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context; | ||
447 | |||
448 | if (urb->status < 0) | ||
449 | printk(KERN_DEBUG "ax8817x_async_cmd_callback() failed with %d", | ||
450 | urb->status); | ||
451 | |||
452 | kfree(req); | ||
453 | usb_free_urb(urb); | ||
454 | } | ||
455 | |||
456 | static void ax8817x_status(struct usbnet *dev, struct urb *urb) | ||
457 | { | ||
458 | struct ax88172_int_data *event; | ||
459 | int link; | ||
460 | |||
461 | if (urb->actual_length < 8) | ||
462 | return; | ||
463 | |||
464 | event = urb->transfer_buffer; | ||
465 | link = event->link & 0x01; | ||
466 | if (netif_carrier_ok(dev->net) != link) { | ||
467 | if (link) { | ||
468 | netif_carrier_on(dev->net); | ||
469 | defer_kevent (dev, EVENT_LINK_RESET ); | ||
470 | } else | ||
471 | netif_carrier_off(dev->net); | ||
472 | devdbg(dev, "ax8817x - Link Status is: %d", link); | ||
473 | } | ||
474 | } | ||
475 | |||
476 | static void ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index, | ||
477 | u16 size, void *data) | ||
478 | { | ||
479 | struct usb_ctrlrequest *req; | ||
480 | int status; | ||
481 | struct urb *urb; | ||
482 | |||
483 | if ((urb = usb_alloc_urb(0, GFP_ATOMIC)) == NULL) { | ||
484 | devdbg(dev, "Error allocating URB in write_cmd_async!"); | ||
485 | return; | ||
486 | } | ||
487 | |||
488 | if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) { | ||
489 | deverr(dev, "Failed to allocate memory for control request"); | ||
490 | usb_free_urb(urb); | ||
491 | return; | ||
492 | } | ||
493 | |||
494 | req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE; | ||
495 | req->bRequest = cmd; | ||
496 | req->wValue = cpu_to_le16(value); | ||
497 | req->wIndex = cpu_to_le16(index); | ||
498 | req->wLength = cpu_to_le16(size); | ||
499 | |||
500 | usb_fill_control_urb(urb, dev->udev, | ||
501 | usb_sndctrlpipe(dev->udev, 0), | ||
502 | (void *)req, data, size, | ||
503 | ax8817x_async_cmd_callback, req); | ||
504 | |||
505 | if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { | ||
506 | deverr(dev, "Error submitting the control message: status=%d", status); | ||
507 | kfree(req); | ||
508 | usb_free_urb(urb); | ||
509 | } | ||
510 | } | ||
511 | |||
512 | static void ax8817x_set_multicast(struct net_device *net) | ||
513 | { | ||
514 | struct usbnet *dev = netdev_priv(net); | ||
515 | struct ax8817x_data *data = (struct ax8817x_data *)&dev->data; | ||
516 | u8 rx_ctl = 0x8c; | ||
517 | |||
518 | if (net->flags & IFF_PROMISC) { | ||
519 | rx_ctl |= 0x01; | ||
520 | } else if (net->flags & IFF_ALLMULTI | ||
521 | || net->mc_count > AX_MAX_MCAST) { | ||
522 | rx_ctl |= 0x02; | ||
523 | } else if (net->mc_count == 0) { | ||
524 | /* just broadcast and directed */ | ||
525 | } else { | ||
526 | /* We use the 20 byte dev->data | ||
527 | * for our 8 byte filter buffer | ||
528 | * to avoid allocating memory that | ||
529 | * is tricky to free later */ | ||
530 | struct dev_mc_list *mc_list = net->mc_list; | ||
531 | u32 crc_bits; | ||
532 | int i; | ||
533 | |||
534 | memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE); | ||
535 | |||
536 | /* Build the multicast hash filter. */ | ||
537 | for (i = 0; i < net->mc_count; i++) { | ||
538 | crc_bits = | ||
539 | ether_crc(ETH_ALEN, | ||
540 | mc_list->dmi_addr) >> 26; | ||
541 | data->multi_filter[crc_bits >> 3] |= | ||
542 | 1 << (crc_bits & 7); | ||
543 | mc_list = mc_list->next; | ||
544 | } | ||
545 | |||
546 | ax8817x_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0, | ||
547 | AX_MCAST_FILTER_SIZE, data->multi_filter); | ||
548 | |||
549 | rx_ctl |= 0x10; | ||
550 | } | ||
551 | |||
552 | ax8817x_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL); | ||
553 | } | ||
554 | |||
555 | static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc) | ||
556 | { | ||
557 | struct usbnet *dev = netdev_priv(netdev); | ||
558 | u16 res; | ||
559 | u8 buf[1]; | ||
560 | |||
561 | ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf); | ||
562 | ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res); | ||
563 | ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf); | ||
564 | |||
565 | return res & 0xffff; | ||
566 | } | ||
567 | |||
568 | static void ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val) | ||
569 | { | ||
570 | struct usbnet *dev = netdev_priv(netdev); | ||
571 | u16 res = val; | ||
572 | u8 buf[1]; | ||
573 | |||
574 | ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf); | ||
575 | ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res); | ||
576 | ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf); | ||
577 | } | ||
578 | |||
579 | static int ax88172_link_reset(struct usbnet *dev) | ||
580 | { | ||
581 | u16 lpa; | ||
582 | u8 mode; | ||
583 | |||
584 | mode = AX_MEDIUM_TX_ABORT_ALLOW | AX_MEDIUM_FLOW_CONTROL_EN; | ||
585 | lpa = ax8817x_mdio_read(dev->net, dev->mii.phy_id, MII_LPA); | ||
586 | if (lpa & LPA_DUPLEX) | ||
587 | mode |= AX_MEDIUM_FULL_DUPLEX; | ||
588 | ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL); | ||
589 | |||
590 | return 0; | ||
591 | } | ||
592 | |||
593 | static void ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) | ||
594 | { | ||
595 | struct usbnet *dev = netdev_priv(net); | ||
596 | u8 opt; | ||
597 | |||
598 | if (ax8817x_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) { | ||
599 | wolinfo->supported = 0; | ||
600 | wolinfo->wolopts = 0; | ||
601 | return; | ||
602 | } | ||
603 | wolinfo->supported = WAKE_PHY | WAKE_MAGIC; | ||
604 | wolinfo->wolopts = 0; | ||
605 | if (opt & AX_MONITOR_MODE) { | ||
606 | if (opt & AX_MONITOR_LINK) | ||
607 | wolinfo->wolopts |= WAKE_PHY; | ||
608 | if (opt & AX_MONITOR_MAGIC) | ||
609 | wolinfo->wolopts |= WAKE_MAGIC; | ||
610 | } | ||
611 | } | ||
612 | |||
613 | static int ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) | ||
614 | { | ||
615 | struct usbnet *dev = netdev_priv(net); | ||
616 | u8 opt = 0; | ||
617 | u8 buf[1]; | ||
618 | |||
619 | if (wolinfo->wolopts & WAKE_PHY) | ||
620 | opt |= AX_MONITOR_LINK; | ||
621 | if (wolinfo->wolopts & WAKE_MAGIC) | ||
622 | opt |= AX_MONITOR_MAGIC; | ||
623 | if (opt != 0) | ||
624 | opt |= AX_MONITOR_MODE; | ||
625 | |||
626 | if (ax8817x_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE, | ||
627 | opt, 0, 0, &buf) < 0) | ||
628 | return -EINVAL; | ||
629 | |||
630 | return 0; | ||
631 | } | ||
632 | |||
633 | static int ax8817x_get_eeprom_len(struct net_device *net) | ||
634 | { | ||
635 | return AX_EEPROM_LEN; | ||
636 | } | ||
637 | |||
638 | static int ax8817x_get_eeprom(struct net_device *net, | ||
639 | struct ethtool_eeprom *eeprom, u8 *data) | ||
640 | { | ||
641 | struct usbnet *dev = netdev_priv(net); | ||
642 | u16 *ebuf = (u16 *)data; | ||
643 | int i; | ||
644 | |||
645 | /* Crude hack to ensure that we don't overwrite memory | ||
646 | * if an odd length is supplied | ||
647 | */ | ||
648 | if (eeprom->len % 2) | ||
649 | return -EINVAL; | ||
650 | |||
651 | eeprom->magic = AX_EEPROM_MAGIC; | ||
652 | |||
653 | /* ax8817x returns 2 bytes from eeprom on read */ | ||
654 | for (i=0; i < eeprom->len / 2; i++) { | ||
655 | if (ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM, | ||
656 | eeprom->offset + i, 0, 2, &ebuf[i]) < 0) | ||
657 | return -EINVAL; | ||
658 | } | ||
659 | return 0; | ||
660 | } | ||
661 | |||
662 | static void ax8817x_get_drvinfo (struct net_device *net, | ||
663 | struct ethtool_drvinfo *info) | ||
664 | { | ||
665 | /* Inherit standard device info */ | ||
666 | usbnet_get_drvinfo(net, info); | ||
667 | info->eedump_len = 0x3e; | ||
668 | } | ||
669 | |||
670 | static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd) | ||
671 | { | ||
672 | struct usbnet *dev = netdev_priv(net); | ||
673 | |||
674 | return mii_ethtool_gset(&dev->mii,cmd); | ||
675 | } | ||
676 | |||
677 | static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd) | ||
678 | { | ||
679 | struct usbnet *dev = netdev_priv(net); | ||
680 | |||
681 | return mii_ethtool_sset(&dev->mii,cmd); | ||
682 | } | ||
683 | |||
684 | /* We need to override some ethtool_ops so we require our | ||
685 | own structure so we don't interfere with other usbnet | ||
686 | devices that may be connected at the same time. */ | ||
687 | static struct ethtool_ops ax8817x_ethtool_ops = { | ||
688 | .get_drvinfo = ax8817x_get_drvinfo, | ||
689 | .get_link = ethtool_op_get_link, | ||
690 | .get_msglevel = usbnet_get_msglevel, | ||
691 | .set_msglevel = usbnet_set_msglevel, | ||
692 | .get_wol = ax8817x_get_wol, | ||
693 | .set_wol = ax8817x_set_wol, | ||
694 | .get_eeprom_len = ax8817x_get_eeprom_len, | ||
695 | .get_eeprom = ax8817x_get_eeprom, | ||
696 | .get_settings = ax8817x_get_settings, | ||
697 | .set_settings = ax8817x_set_settings, | ||
698 | }; | ||
699 | |||
700 | static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf) | ||
701 | { | ||
702 | int ret = 0; | ||
703 | void *buf; | ||
704 | int i; | ||
705 | unsigned long gpio_bits = dev->driver_info->data; | ||
706 | |||
707 | get_endpoints(dev,intf); | ||
708 | |||
709 | buf = kmalloc(ETH_ALEN, GFP_KERNEL); | ||
710 | if(!buf) { | ||
711 | ret = -ENOMEM; | ||
712 | goto out1; | ||
713 | } | ||
714 | |||
715 | /* Toggle the GPIOs in a manufacturer/model specific way */ | ||
716 | for (i = 2; i >= 0; i--) { | ||
717 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS, | ||
718 | (gpio_bits >> (i * 8)) & 0xff, 0, 0, | ||
719 | buf)) < 0) | ||
720 | goto out2; | ||
721 | msleep(5); | ||
722 | } | ||
723 | |||
724 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x80, 0, 0, buf)) < 0) { | ||
725 | dbg("send AX_CMD_WRITE_RX_CTL failed: %d", ret); | ||
726 | goto out2; | ||
727 | } | ||
728 | |||
729 | /* Get the MAC address */ | ||
730 | memset(buf, 0, ETH_ALEN); | ||
731 | if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, 6, buf)) < 0) { | ||
732 | dbg("read AX_CMD_READ_NODE_ID failed: %d", ret); | ||
733 | goto out2; | ||
734 | } | ||
735 | memcpy(dev->net->dev_addr, buf, ETH_ALEN); | ||
736 | |||
737 | /* Get the PHY id */ | ||
738 | if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) { | ||
739 | dbg("error on read AX_CMD_READ_PHY_ID: %02x", ret); | ||
740 | goto out2; | ||
741 | } else if (ret < 2) { | ||
742 | /* this should always return 2 bytes */ | ||
743 | dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", ret); | ||
744 | ret = -EIO; | ||
745 | goto out2; | ||
746 | } | ||
747 | |||
748 | /* Initialize MII structure */ | ||
749 | dev->mii.dev = dev->net; | ||
750 | dev->mii.mdio_read = ax8817x_mdio_read; | ||
751 | dev->mii.mdio_write = ax8817x_mdio_write; | ||
752 | dev->mii.phy_id_mask = 0x3f; | ||
753 | dev->mii.reg_num_mask = 0x1f; | ||
754 | dev->mii.phy_id = *((u8 *)buf + 1); | ||
755 | |||
756 | dev->net->set_multicast_list = ax8817x_set_multicast; | ||
757 | dev->net->ethtool_ops = &ax8817x_ethtool_ops; | ||
758 | |||
759 | ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); | ||
760 | ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE, | ||
761 | ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); | ||
762 | mii_nway_restart(&dev->mii); | ||
763 | |||
764 | if (dev->driver_info->flags & FLAG_FRAMING_AX) { | ||
765 | /* REVISIT: adjust hard_header_len too */ | ||
766 | dev->hard_mtu = 2048; | ||
767 | } | ||
768 | |||
769 | return 0; | ||
770 | out2: | ||
771 | kfree(buf); | ||
772 | out1: | ||
773 | return ret; | ||
774 | } | ||
775 | |||
776 | static struct ethtool_ops ax88772_ethtool_ops = { | ||
777 | .get_drvinfo = ax8817x_get_drvinfo, | ||
778 | .get_link = ethtool_op_get_link, | ||
779 | .get_msglevel = usbnet_get_msglevel, | ||
780 | .set_msglevel = usbnet_set_msglevel, | ||
781 | .get_wol = ax8817x_get_wol, | ||
782 | .set_wol = ax8817x_set_wol, | ||
783 | .get_eeprom_len = ax8817x_get_eeprom_len, | ||
784 | .get_eeprom = ax8817x_get_eeprom, | ||
785 | .get_settings = ax8817x_get_settings, | ||
786 | .set_settings = ax8817x_set_settings, | ||
787 | }; | ||
788 | |||
789 | static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf) | ||
790 | { | ||
791 | int ret; | ||
792 | void *buf; | ||
793 | |||
794 | get_endpoints(dev,intf); | ||
795 | |||
796 | buf = kmalloc(6, GFP_KERNEL); | ||
797 | if(!buf) { | ||
798 | dbg ("Cannot allocate memory for buffer"); | ||
799 | ret = -ENOMEM; | ||
800 | goto out1; | ||
801 | } | ||
802 | |||
803 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS, | ||
804 | 0x00B0, 0, 0, buf)) < 0) | ||
805 | goto out2; | ||
806 | |||
807 | msleep(5); | ||
808 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 0x0001, 0, 0, buf)) < 0) { | ||
809 | dbg("Select PHY #1 failed: %d", ret); | ||
810 | goto out2; | ||
811 | } | ||
812 | |||
813 | if ((ret = | ||
814 | ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPPD, 0, 0, buf)) < 0) { | ||
815 | dbg("Failed to power down internal PHY: %d", ret); | ||
816 | goto out2; | ||
817 | } | ||
818 | |||
819 | msleep(150); | ||
820 | if ((ret = | ||
821 | ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_CLEAR, 0, 0, buf)) < 0) { | ||
822 | dbg("Failed to perform software reset: %d", ret); | ||
823 | goto out2; | ||
824 | } | ||
825 | |||
826 | msleep(150); | ||
827 | if ((ret = | ||
828 | ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL | AX_SWRESET_PRL, 0, 0, buf)) < 0) { | ||
829 | dbg("Failed to set Internal/External PHY reset control: %d", ret); | ||
830 | goto out2; | ||
831 | } | ||
832 | |||
833 | msleep(150); | ||
834 | if ((ret = | ||
835 | ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0000, 0, 0, | ||
836 | buf)) < 0) { | ||
837 | dbg("Failed to reset RX_CTL: %d", ret); | ||
838 | goto out2; | ||
839 | } | ||
840 | |||
841 | /* Get the MAC address */ | ||
842 | memset(buf, 0, ETH_ALEN); | ||
843 | if ((ret = ax8817x_read_cmd(dev, AX88772_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf)) < 0) { | ||
844 | dbg("Failed to read MAC address: %d", ret); | ||
845 | goto out2; | ||
846 | } | ||
847 | memcpy(dev->net->dev_addr, buf, ETH_ALEN); | ||
848 | |||
849 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, buf)) < 0) { | ||
850 | dbg("Enabling software MII failed: %d", ret); | ||
851 | goto out2; | ||
852 | } | ||
853 | |||
854 | if (((ret = | ||
855 | ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, 0x0010, 2, 2, buf)) < 0) | ||
856 | || (*((u16 *)buf) != 0x003b)) { | ||
857 | dbg("Read PHY register 2 must be 0x3b00: %d", ret); | ||
858 | goto out2; | ||
859 | } | ||
860 | |||
861 | /* Initialize MII structure */ | ||
862 | dev->mii.dev = dev->net; | ||
863 | dev->mii.mdio_read = ax8817x_mdio_read; | ||
864 | dev->mii.mdio_write = ax8817x_mdio_write; | ||
865 | dev->mii.phy_id_mask = 0xff; | ||
866 | dev->mii.reg_num_mask = 0xff; | ||
867 | |||
868 | /* Get the PHY id */ | ||
869 | if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) { | ||
870 | dbg("Error reading PHY ID: %02x", ret); | ||
871 | goto out2; | ||
872 | } else if (ret < 2) { | ||
873 | /* this should always return 2 bytes */ | ||
874 | dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", | ||
875 | ret); | ||
876 | ret = -EIO; | ||
877 | goto out2; | ||
878 | } | ||
879 | dev->mii.phy_id = *((u8 *)buf + 1); | ||
880 | |||
881 | if ((ret = | ||
882 | ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_PRL, 0, 0, buf)) < 0) { | ||
883 | dbg("Set external PHY reset pin level: %d", ret); | ||
884 | goto out2; | ||
885 | } | ||
886 | msleep(150); | ||
887 | if ((ret = | ||
888 | ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL | AX_SWRESET_PRL, 0, 0, buf)) < 0) { | ||
889 | dbg("Set Internal/External PHY reset control: %d", ret); | ||
890 | goto out2; | ||
891 | } | ||
892 | msleep(150); | ||
893 | |||
894 | |||
895 | dev->net->set_multicast_list = ax8817x_set_multicast; | ||
896 | dev->net->ethtool_ops = &ax88772_ethtool_ops; | ||
897 | |||
898 | ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); | ||
899 | ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE, | ||
900 | ADVERTISE_ALL | ADVERTISE_CSMA); | ||
901 | mii_nway_restart(&dev->mii); | ||
902 | |||
903 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, AX88772_MEDIUM_DEFAULT, 0, 0, buf)) < 0) { | ||
904 | dbg("Write medium mode register: %d", ret); | ||
905 | goto out2; | ||
906 | } | ||
907 | |||
908 | if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_IPG0, AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,AX88772_IPG2_DEFAULT, 0, buf)) < 0) { | ||
909 | dbg("Write IPG,IPG1,IPG2 failed: %d", ret); | ||
910 | goto out2; | ||
911 | } | ||
912 | if ((ret = | ||
913 | ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf)) < 0) { | ||
914 | dbg("Failed to set hardware MII: %02x", ret); | ||
915 | goto out2; | ||
916 | } | ||
917 | |||
918 | /* Set RX_CTL to default values with 2k buffer, and enable cactus */ | ||
919 | if ((ret = | ||
920 | ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0088, 0, 0, | ||
921 | buf)) < 0) { | ||
922 | dbg("Reset RX_CTL failed: %d", ret); | ||
923 | goto out2; | ||
924 | } | ||
925 | |||
926 | kfree(buf); | ||
927 | |||
928 | return 0; | ||
929 | |||
930 | out2: | ||
931 | kfree(buf); | ||
932 | out1: | ||
933 | return ret; | ||
934 | } | ||
935 | |||
936 | static int ax88772_rx_fixup(struct usbnet *dev, struct sk_buff *skb) | ||
937 | { | ||
938 | u32 *header; | ||
939 | char *packet; | ||
940 | struct sk_buff *ax_skb; | ||
941 | u16 size; | ||
942 | |||
943 | header = (u32 *) skb->data; | ||
944 | le32_to_cpus(header); | ||
945 | packet = (char *)(header + 1); | ||
946 | |||
947 | skb_pull(skb, 4); | ||
948 | |||
949 | while (skb->len > 0) { | ||
950 | if ((short)(*header & 0x0000ffff) != | ||
951 | ~((short)((*header & 0xffff0000) >> 16))) { | ||
952 | devdbg(dev,"header length data is error"); | ||
953 | } | ||
954 | /* get the packet length */ | ||
955 | size = (u16) (*header & 0x0000ffff); | ||
956 | |||
957 | if ((skb->len) - ((size + 1) & 0xfffe) == 0) | ||
958 | return 2; | ||
959 | if (size > ETH_FRAME_LEN) { | ||
960 | devdbg(dev,"invalid rx length %d", size); | ||
961 | return 0; | ||
962 | } | ||
963 | ax_skb = skb_clone(skb, GFP_ATOMIC); | ||
964 | if (ax_skb) { | ||
965 | ax_skb->len = size; | ||
966 | ax_skb->data = packet; | ||
967 | ax_skb->tail = packet + size; | ||
968 | skb_return(dev, ax_skb); | ||
969 | } else { | ||
970 | return 0; | ||
971 | } | ||
972 | |||
973 | skb_pull(skb, (size + 1) & 0xfffe); | ||
974 | |||
975 | if (skb->len == 0) | ||
976 | break; | ||
977 | |||
978 | header = (u32 *) skb->data; | ||
979 | le32_to_cpus(header); | ||
980 | packet = (char *)(header + 1); | ||
981 | skb_pull(skb, 4); | ||
982 | } | ||
983 | |||
984 | if (skb->len < 0) { | ||
985 | devdbg(dev,"invalid rx length %d", skb->len); | ||
986 | return 0; | ||
987 | } | ||
988 | return 1; | ||
989 | } | ||
990 | |||
991 | static struct sk_buff *ax88772_tx_fixup(struct usbnet *dev, struct sk_buff *skb, | ||
992 | unsigned flags) | ||
993 | { | ||
994 | int padlen; | ||
995 | int headroom = skb_headroom(skb); | ||
996 | int tailroom = skb_tailroom(skb); | ||
997 | u32 *packet_len; | ||
998 | u32 *padbytes_ptr; | ||
999 | |||
1000 | padlen = ((skb->len + 4) % 512) ? 0 : 4; | ||
1001 | |||
1002 | if ((!skb_cloned(skb)) | ||
1003 | && ((headroom + tailroom) >= (4 + padlen))) { | ||
1004 | if ((headroom < 4) || (tailroom < padlen)) { | ||
1005 | skb->data = memmove(skb->head + 4, skb->data, skb->len); | ||
1006 | skb->tail = skb->data + skb->len; | ||
1007 | } | ||
1008 | } else { | ||
1009 | struct sk_buff *skb2; | ||
1010 | skb2 = skb_copy_expand(skb, 4, padlen, flags); | ||
1011 | dev_kfree_skb_any(skb); | ||
1012 | skb = skb2; | ||
1013 | if (!skb) | ||
1014 | return NULL; | ||
1015 | } | ||
1016 | |||
1017 | packet_len = (u32 *) skb_push(skb, 4); | ||
1018 | |||
1019 | packet_len = (u32 *) skb->data; | ||
1020 | *packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4); | ||
1021 | |||
1022 | if ((skb->len % 512) == 0) { | ||
1023 | padbytes_ptr = (u32 *) skb->tail; | ||
1024 | *padbytes_ptr = 0xffff0000; | ||
1025 | skb_put(skb, padlen); | ||
1026 | } | ||
1027 | return skb; | ||
1028 | } | ||
1029 | |||
1030 | static int ax88772_link_reset(struct usbnet *dev) | ||
1031 | { | ||
1032 | u16 lpa; | ||
1033 | u16 mode; | ||
1034 | |||
1035 | mode = AX88772_MEDIUM_DEFAULT; | ||
1036 | lpa = ax8817x_mdio_read(dev->net, dev->mii.phy_id, MII_LPA); | ||
1037 | |||
1038 | if ((lpa & LPA_DUPLEX) == 0) | ||
1039 | mode &= ~AX88772_MEDIUM_FULL_DUPLEX; | ||
1040 | if ((lpa & LPA_100) == 0) | ||
1041 | mode &= ~AX88772_MEDIUM_100MB; | ||
1042 | ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL); | ||
1043 | |||
1044 | return 0; | ||
1045 | } | ||
1046 | |||
1047 | static const struct driver_info ax8817x_info = { | ||
1048 | .description = "ASIX AX8817x USB 2.0 Ethernet", | ||
1049 | .bind = ax8817x_bind, | ||
1050 | .status = ax8817x_status, | ||
1051 | .link_reset = ax88172_link_reset, | ||
1052 | .reset = ax88172_link_reset, | ||
1053 | .flags = FLAG_ETHER, | ||
1054 | .data = 0x00130103, | ||
1055 | }; | ||
1056 | |||
1057 | static const struct driver_info dlink_dub_e100_info = { | ||
1058 | .description = "DLink DUB-E100 USB Ethernet", | ||
1059 | .bind = ax8817x_bind, | ||
1060 | .status = ax8817x_status, | ||
1061 | .link_reset = ax88172_link_reset, | ||
1062 | .reset = ax88172_link_reset, | ||
1063 | .flags = FLAG_ETHER, | ||
1064 | .data = 0x009f9d9f, | ||
1065 | }; | ||
1066 | |||
1067 | static const struct driver_info netgear_fa120_info = { | ||
1068 | .description = "Netgear FA-120 USB Ethernet", | ||
1069 | .bind = ax8817x_bind, | ||
1070 | .status = ax8817x_status, | ||
1071 | .link_reset = ax88172_link_reset, | ||
1072 | .reset = ax88172_link_reset, | ||
1073 | .flags = FLAG_ETHER, | ||
1074 | .data = 0x00130103, | ||
1075 | }; | ||
1076 | |||
1077 | static const struct driver_info hawking_uf200_info = { | ||
1078 | .description = "Hawking UF200 USB Ethernet", | ||
1079 | .bind = ax8817x_bind, | ||
1080 | .status = ax8817x_status, | ||
1081 | .link_reset = ax88172_link_reset, | ||
1082 | .reset = ax88172_link_reset, | ||
1083 | .flags = FLAG_ETHER, | ||
1084 | .data = 0x001f1d1f, | ||
1085 | }; | ||
1086 | |||
1087 | static const struct driver_info ax88772_info = { | ||
1088 | .description = "ASIX AX88772 USB 2.0 Ethernet", | ||
1089 | .bind = ax88772_bind, | ||
1090 | .status = ax8817x_status, | ||
1091 | .link_reset = ax88772_link_reset, | ||
1092 | .reset = ax88772_link_reset, | ||
1093 | .flags = FLAG_ETHER | FLAG_FRAMING_AX, | ||
1094 | .rx_fixup = ax88772_rx_fixup, | ||
1095 | .tx_fixup = ax88772_tx_fixup, | ||
1096 | .data = 0x00130103, | ||
1097 | }; | ||
1098 | |||
1099 | #endif /* CONFIG_USB_AX8817X */ | ||
1100 | |||
1101 | 319 | ||
1102 | 320 | ||
1103 | /*------------------------------------------------------------------------- | 321 | /*------------------------------------------------------------------------- |
@@ -1284,7 +502,7 @@ next_desc: | |||
1284 | status = usb_driver_claim_interface (&usbnet_driver, info->data, dev); | 502 | status = usb_driver_claim_interface (&usbnet_driver, info->data, dev); |
1285 | if (status < 0) | 503 | if (status < 0) |
1286 | return status; | 504 | return status; |
1287 | status = get_endpoints (dev, info->data); | 505 | status = usbnet_get_endpoints (dev, info->data); |
1288 | if (status < 0) { | 506 | if (status < 0) { |
1289 | /* ensure immediate exit from usbnet_disconnect */ | 507 | /* ensure immediate exit from usbnet_disconnect */ |
1290 | usb_set_intfdata(info->data, NULL); | 508 | usb_set_intfdata(info->data, NULL); |
@@ -1721,7 +939,7 @@ static int genelink_rx_fixup (struct usbnet *dev, struct sk_buff *skb) | |||
1721 | 939 | ||
1722 | // copy the packet data to the new skb | 940 | // copy the packet data to the new skb |
1723 | memcpy(skb_put(gl_skb, size), packet->packet_data, size); | 941 | memcpy(skb_put(gl_skb, size), packet->packet_data, size); |
1724 | skb_return (dev, gl_skb); | 942 | usbnet_skb_return (dev, gl_skb); |
1725 | } | 943 | } |
1726 | 944 | ||
1727 | // advance to the next packet | 945 | // advance to the next packet |
@@ -2616,7 +1834,7 @@ next_desc: | |||
2616 | * bother to make it unique. Likewise there's no point in tracking | 1834 | * bother to make it unique. Likewise there's no point in tracking |
2617 | * of the CDC event notifications. | 1835 | * of the CDC event notifications. |
2618 | */ | 1836 | */ |
2619 | return get_endpoints (dev, intf); | 1837 | return usbnet_get_endpoints (dev, intf); |
2620 | 1838 | ||
2621 | bad_desc: | 1839 | bad_desc: |
2622 | dev_info (&dev->udev->dev, "unsupported MDLM descriptors\n"); | 1840 | dev_info (&dev->udev->dev, "unsupported MDLM descriptors\n"); |
@@ -2694,7 +1912,7 @@ static void defer_bh(struct usbnet *dev, struct sk_buff *skb, struct sk_buff_hea | |||
2694 | * NOTE: annoying asymmetry: if it's active, schedule_work() fails, | 1912 | * NOTE: annoying asymmetry: if it's active, schedule_work() fails, |
2695 | * but tasklet_schedule() doesn't. hope the failure is rare. | 1913 | * but tasklet_schedule() doesn't. hope the failure is rare. |
2696 | */ | 1914 | */ |
2697 | static void defer_kevent (struct usbnet *dev, int work) | 1915 | void usbnet_defer_kevent (struct usbnet *dev, int work) |
2698 | { | 1916 | { |
2699 | set_bit (work, &dev->flags); | 1917 | set_bit (work, &dev->flags); |
2700 | if (!schedule_work (&dev->kevent)) | 1918 | if (!schedule_work (&dev->kevent)) |
@@ -2702,6 +1920,7 @@ static void defer_kevent (struct usbnet *dev, int work) | |||
2702 | else | 1920 | else |
2703 | devdbg (dev, "kevent %d scheduled", work); | 1921 | devdbg (dev, "kevent %d scheduled", work); |
2704 | } | 1922 | } |
1923 | EXPORT_SYMBOL_GPL(usbnet_defer_kevent); | ||
2705 | 1924 | ||
2706 | /*-------------------------------------------------------------------------*/ | 1925 | /*-------------------------------------------------------------------------*/ |
2707 | 1926 | ||
@@ -2713,14 +1932,12 @@ static void rx_submit (struct usbnet *dev, struct urb *urb, unsigned flags) | |||
2713 | struct skb_data *entry; | 1932 | struct skb_data *entry; |
2714 | int retval = 0; | 1933 | int retval = 0; |
2715 | unsigned long lockflags; | 1934 | unsigned long lockflags; |
2716 | size_t size; | 1935 | size_t size = dev->rx_urb_size; |
2717 | 1936 | ||
2718 | size = max(dev->net->hard_header_len + dev->net->mtu, | ||
2719 | (unsigned)ETH_FRAME_LEN); | ||
2720 | if ((skb = alloc_skb (size + NET_IP_ALIGN, flags)) == NULL) { | 1937 | if ((skb = alloc_skb (size + NET_IP_ALIGN, flags)) == NULL) { |
2721 | if (netif_msg_rx_err (dev)) | 1938 | if (netif_msg_rx_err (dev)) |
2722 | devdbg (dev, "no rx skb"); | 1939 | devdbg (dev, "no rx skb"); |
2723 | defer_kevent (dev, EVENT_RX_MEMORY); | 1940 | usbnet_defer_kevent (dev, EVENT_RX_MEMORY); |
2724 | usb_free_urb (urb); | 1941 | usb_free_urb (urb); |
2725 | return; | 1942 | return; |
2726 | } | 1943 | } |
@@ -2742,10 +1959,10 @@ static void rx_submit (struct usbnet *dev, struct urb *urb, unsigned flags) | |||
2742 | && !test_bit (EVENT_RX_HALT, &dev->flags)) { | 1959 | && !test_bit (EVENT_RX_HALT, &dev->flags)) { |
2743 | switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){ | 1960 | switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){ |
2744 | case -EPIPE: | 1961 | case -EPIPE: |
2745 | defer_kevent (dev, EVENT_RX_HALT); | 1962 | usbnet_defer_kevent (dev, EVENT_RX_HALT); |
2746 | break; | 1963 | break; |
2747 | case -ENOMEM: | 1964 | case -ENOMEM: |
2748 | defer_kevent (dev, EVENT_RX_MEMORY); | 1965 | usbnet_defer_kevent (dev, EVENT_RX_MEMORY); |
2749 | break; | 1966 | break; |
2750 | case -ENODEV: | 1967 | case -ENODEV: |
2751 | if (netif_msg_ifdown (dev)) | 1968 | if (netif_msg_ifdown (dev)) |
@@ -2783,7 +2000,7 @@ static inline void rx_process (struct usbnet *dev, struct sk_buff *skb) | |||
2783 | // else network stack removes extra byte if we forced a short packet | 2000 | // else network stack removes extra byte if we forced a short packet |
2784 | 2001 | ||
2785 | if (skb->len) | 2002 | if (skb->len) |
2786 | skb_return (dev, skb); | 2003 | usbnet_skb_return (dev, skb); |
2787 | else { | 2004 | else { |
2788 | if (netif_msg_rx_err (dev)) | 2005 | if (netif_msg_rx_err (dev)) |
2789 | devdbg (dev, "drop"); | 2006 | devdbg (dev, "drop"); |
@@ -2824,7 +2041,7 @@ static void rx_complete (struct urb *urb, struct pt_regs *regs) | |||
2824 | // storm, recovering as needed. | 2041 | // storm, recovering as needed. |
2825 | case -EPIPE: | 2042 | case -EPIPE: |
2826 | dev->stats.rx_errors++; | 2043 | dev->stats.rx_errors++; |
2827 | defer_kevent (dev, EVENT_RX_HALT); | 2044 | usbnet_defer_kevent (dev, EVENT_RX_HALT); |
2828 | // FALLTHROUGH | 2045 | // FALLTHROUGH |
2829 | 2046 | ||
2830 | // software-driven interface shutdown | 2047 | // software-driven interface shutdown |
@@ -3066,16 +2283,22 @@ done: | |||
3066 | 2283 | ||
3067 | /*-------------------------------------------------------------------------*/ | 2284 | /*-------------------------------------------------------------------------*/ |
3068 | 2285 | ||
3069 | static void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info) | 2286 | /* ethtool methods; minidrivers may need to add some more, but |
2287 | * they'll probably want to use this base set. | ||
2288 | */ | ||
2289 | |||
2290 | void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info) | ||
3070 | { | 2291 | { |
3071 | struct usbnet *dev = netdev_priv(net); | 2292 | struct usbnet *dev = netdev_priv(net); |
3072 | 2293 | ||
2294 | /* REVISIT don't always return "usbnet" */ | ||
3073 | strncpy (info->driver, driver_name, sizeof info->driver); | 2295 | strncpy (info->driver, driver_name, sizeof info->driver); |
3074 | strncpy (info->version, DRIVER_VERSION, sizeof info->version); | 2296 | strncpy (info->version, DRIVER_VERSION, sizeof info->version); |
3075 | strncpy (info->fw_version, dev->driver_info->description, | 2297 | strncpy (info->fw_version, dev->driver_info->description, |
3076 | sizeof info->fw_version); | 2298 | sizeof info->fw_version); |
3077 | usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info); | 2299 | usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info); |
3078 | } | 2300 | } |
2301 | EXPORT_SYMBOL_GPL(usbnet_get_drvinfo); | ||
3079 | 2302 | ||
3080 | static u32 usbnet_get_link (struct net_device *net) | 2303 | static u32 usbnet_get_link (struct net_device *net) |
3081 | { | 2304 | { |
@@ -3089,32 +2312,29 @@ static u32 usbnet_get_link (struct net_device *net) | |||
3089 | return 1; | 2312 | return 1; |
3090 | } | 2313 | } |
3091 | 2314 | ||
3092 | static u32 usbnet_get_msglevel (struct net_device *net) | 2315 | u32 usbnet_get_msglevel (struct net_device *net) |
3093 | { | 2316 | { |
3094 | struct usbnet *dev = netdev_priv(net); | 2317 | struct usbnet *dev = netdev_priv(net); |
3095 | 2318 | ||
3096 | return dev->msg_enable; | 2319 | return dev->msg_enable; |
3097 | } | 2320 | } |
2321 | EXPORT_SYMBOL_GPL(usbnet_get_msglevel); | ||
3098 | 2322 | ||
3099 | static void usbnet_set_msglevel (struct net_device *net, u32 level) | 2323 | void usbnet_set_msglevel (struct net_device *net, u32 level) |
3100 | { | 2324 | { |
3101 | struct usbnet *dev = netdev_priv(net); | 2325 | struct usbnet *dev = netdev_priv(net); |
3102 | 2326 | ||
3103 | dev->msg_enable = level; | 2327 | dev->msg_enable = level; |
3104 | } | 2328 | } |
2329 | EXPORT_SYMBOL_GPL(usbnet_set_msglevel); | ||
3105 | 2330 | ||
3106 | static int usbnet_ioctl (struct net_device *net, struct ifreq *rq, int cmd) | 2331 | /* drivers may override default ethtool_ops in their bind() routine */ |
3107 | { | 2332 | static struct ethtool_ops usbnet_ethtool_ops = { |
3108 | #ifdef NEED_MII | 2333 | .get_drvinfo = usbnet_get_drvinfo, |
3109 | { | 2334 | .get_link = usbnet_get_link, |
3110 | struct usbnet *dev = netdev_priv(net); | 2335 | .get_msglevel = usbnet_get_msglevel, |
3111 | 2336 | .set_msglevel = usbnet_set_msglevel, | |
3112 | if (dev->mii.mdio_read != NULL && dev->mii.mdio_write != NULL) | 2337 | }; |
3113 | return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); | ||
3114 | } | ||
3115 | #endif | ||
3116 | return -EOPNOTSUPP; | ||
3117 | } | ||
3118 | 2338 | ||
3119 | /*-------------------------------------------------------------------------*/ | 2339 | /*-------------------------------------------------------------------------*/ |
3120 | 2340 | ||
@@ -3209,7 +2429,7 @@ static void tx_complete (struct urb *urb, struct pt_regs *regs) | |||
3209 | 2429 | ||
3210 | switch (urb->status) { | 2430 | switch (urb->status) { |
3211 | case -EPIPE: | 2431 | case -EPIPE: |
3212 | defer_kevent (dev, EVENT_TX_HALT); | 2432 | usbnet_defer_kevent (dev, EVENT_TX_HALT); |
3213 | break; | 2433 | break; |
3214 | 2434 | ||
3215 | /* software-driven interface shutdown */ | 2435 | /* software-driven interface shutdown */ |
@@ -3339,7 +2559,7 @@ static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net) | |||
3339 | switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) { | 2559 | switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) { |
3340 | case -EPIPE: | 2560 | case -EPIPE: |
3341 | netif_stop_queue (net); | 2561 | netif_stop_queue (net); |
3342 | defer_kevent (dev, EVENT_TX_HALT); | 2562 | usbnet_defer_kevent (dev, EVENT_TX_HALT); |
3343 | break; | 2563 | break; |
3344 | default: | 2564 | default: |
3345 | if (netif_msg_tx_err (dev)) | 2565 | if (netif_msg_tx_err (dev)) |
@@ -3478,8 +2698,6 @@ EXPORT_SYMBOL_GPL(usbnet_disconnect); | |||
3478 | 2698 | ||
3479 | /*-------------------------------------------------------------------------*/ | 2699 | /*-------------------------------------------------------------------------*/ |
3480 | 2700 | ||
3481 | static struct ethtool_ops usbnet_ethtool_ops; | ||
3482 | |||
3483 | // precondition: never called in_interrupt | 2701 | // precondition: never called in_interrupt |
3484 | 2702 | ||
3485 | int | 2703 | int |
@@ -3530,8 +2748,11 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) | |||
3530 | dev->net = net; | 2748 | dev->net = net; |
3531 | strcpy (net->name, "usb%d"); | 2749 | strcpy (net->name, "usb%d"); |
3532 | memcpy (net->dev_addr, node_id, sizeof node_id); | 2750 | memcpy (net->dev_addr, node_id, sizeof node_id); |
3533 | dev->hard_mtu = net->mtu + net->hard_header_len; | ||
3534 | 2751 | ||
2752 | /* rx and tx sides can use different message sizes; | ||
2753 | * bind() should set rx_urb_size in that case. | ||
2754 | */ | ||
2755 | dev->hard_mtu = net->mtu + net->hard_header_len; | ||
3535 | #if 0 | 2756 | #if 0 |
3536 | // dma_supported() is deeply broken on almost all architectures | 2757 | // dma_supported() is deeply broken on almost all architectures |
3537 | // possible with some EHCI controllers | 2758 | // possible with some EHCI controllers |
@@ -3546,7 +2767,6 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) | |||
3546 | net->stop = usbnet_stop; | 2767 | net->stop = usbnet_stop; |
3547 | net->watchdog_timeo = TX_TIMEOUT_JIFFIES; | 2768 | net->watchdog_timeo = TX_TIMEOUT_JIFFIES; |
3548 | net->tx_timeout = usbnet_tx_timeout; | 2769 | net->tx_timeout = usbnet_tx_timeout; |
3549 | net->do_ioctl = usbnet_ioctl; | ||
3550 | net->ethtool_ops = &usbnet_ethtool_ops; | 2770 | net->ethtool_ops = &usbnet_ethtool_ops; |
3551 | 2771 | ||
3552 | // allow device-specific bind/init procedures | 2772 | // allow device-specific bind/init procedures |
@@ -3563,8 +2783,8 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) | |||
3563 | /* maybe the remote can't receive an Ethernet MTU */ | 2783 | /* maybe the remote can't receive an Ethernet MTU */ |
3564 | if (net->mtu > (dev->hard_mtu - net->hard_header_len)) | 2784 | if (net->mtu > (dev->hard_mtu - net->hard_header_len)) |
3565 | net->mtu = dev->hard_mtu - net->hard_header_len; | 2785 | net->mtu = dev->hard_mtu - net->hard_header_len; |
3566 | } else if (!info->in || info->out) | 2786 | } else if (!info->in || !info->out) |
3567 | status = get_endpoints (dev, udev); | 2787 | status = usbnet_get_endpoints (dev, udev); |
3568 | else { | 2788 | else { |
3569 | dev->in = usb_rcvbulkpipe (xdev, info->in); | 2789 | dev->in = usb_rcvbulkpipe (xdev, info->in); |
3570 | dev->out = usb_sndbulkpipe (xdev, info->out); | 2790 | dev->out = usb_sndbulkpipe (xdev, info->out); |
@@ -3581,6 +2801,8 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) | |||
3581 | if (status < 0) | 2801 | if (status < 0) |
3582 | goto out1; | 2802 | goto out1; |
3583 | 2803 | ||
2804 | if (!dev->rx_urb_size) | ||
2805 | dev->rx_urb_size = dev->hard_mtu; | ||
3584 | dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1); | 2806 | dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1); |
3585 | 2807 | ||
3586 | SET_NETDEV_DEV(net, &udev->dev); | 2808 | SET_NETDEV_DEV(net, &udev->dev); |
@@ -3662,62 +2884,6 @@ EXPORT_SYMBOL_GPL(usbnet_resume); | |||
3662 | 2884 | ||
3663 | static const struct usb_device_id products [] = { | 2885 | static const struct usb_device_id products [] = { |
3664 | 2886 | ||
3665 | #ifdef CONFIG_USB_AX8817X | ||
3666 | { | ||
3667 | // Linksys USB200M | ||
3668 | USB_DEVICE (0x077b, 0x2226), | ||
3669 | .driver_info = (unsigned long) &ax8817x_info, | ||
3670 | }, { | ||
3671 | // Netgear FA120 | ||
3672 | USB_DEVICE (0x0846, 0x1040), | ||
3673 | .driver_info = (unsigned long) &netgear_fa120_info, | ||
3674 | }, { | ||
3675 | // DLink DUB-E100 | ||
3676 | USB_DEVICE (0x2001, 0x1a00), | ||
3677 | .driver_info = (unsigned long) &dlink_dub_e100_info, | ||
3678 | }, { | ||
3679 | // Intellinet, ST Lab USB Ethernet | ||
3680 | USB_DEVICE (0x0b95, 0x1720), | ||
3681 | .driver_info = (unsigned long) &ax8817x_info, | ||
3682 | }, { | ||
3683 | // Hawking UF200, TrendNet TU2-ET100 | ||
3684 | USB_DEVICE (0x07b8, 0x420a), | ||
3685 | .driver_info = (unsigned long) &hawking_uf200_info, | ||
3686 | }, { | ||
3687 | // Billionton Systems, USB2AR | ||
3688 | USB_DEVICE (0x08dd, 0x90ff), | ||
3689 | .driver_info = (unsigned long) &ax8817x_info, | ||
3690 | }, { | ||
3691 | // ATEN UC210T | ||
3692 | USB_DEVICE (0x0557, 0x2009), | ||
3693 | .driver_info = (unsigned long) &ax8817x_info, | ||
3694 | }, { | ||
3695 | // Buffalo LUA-U2-KTX | ||
3696 | USB_DEVICE (0x0411, 0x003d), | ||
3697 | .driver_info = (unsigned long) &ax8817x_info, | ||
3698 | }, { | ||
3699 | // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter" | ||
3700 | USB_DEVICE (0x6189, 0x182d), | ||
3701 | .driver_info = (unsigned long) &ax8817x_info, | ||
3702 | }, { | ||
3703 | // corega FEther USB2-TX | ||
3704 | USB_DEVICE (0x07aa, 0x0017), | ||
3705 | .driver_info = (unsigned long) &ax8817x_info, | ||
3706 | }, { | ||
3707 | // Surecom EP-1427X-2 | ||
3708 | USB_DEVICE (0x1189, 0x0893), | ||
3709 | .driver_info = (unsigned long) &ax8817x_info, | ||
3710 | }, { | ||
3711 | // goodway corp usb gwusb2e | ||
3712 | USB_DEVICE (0x1631, 0x6200), | ||
3713 | .driver_info = (unsigned long) &ax8817x_info, | ||
3714 | }, { | ||
3715 | // ASIX AX88772 10/100 | ||
3716 | USB_DEVICE (0x0b95, 0x7720), | ||
3717 | .driver_info = (unsigned long) &ax88772_info, | ||
3718 | }, | ||
3719 | #endif | ||
3720 | |||
3721 | #ifdef CONFIG_USB_GENESYS | 2887 | #ifdef CONFIG_USB_GENESYS |
3722 | { | 2888 | { |
3723 | USB_DEVICE (0x05e3, 0x0502), // GL620USB-A | 2889 | USB_DEVICE (0x05e3, 0x0502), // GL620USB-A |
@@ -3881,14 +3047,6 @@ static struct usb_driver usbnet_driver = { | |||
3881 | .resume = usbnet_resume, | 3047 | .resume = usbnet_resume, |
3882 | }; | 3048 | }; |
3883 | 3049 | ||
3884 | /* Default ethtool_ops assigned. Devices can override in their bind() routine */ | ||
3885 | static struct ethtool_ops usbnet_ethtool_ops = { | ||
3886 | .get_drvinfo = usbnet_get_drvinfo, | ||
3887 | .get_link = usbnet_get_link, | ||
3888 | .get_msglevel = usbnet_get_msglevel, | ||
3889 | .set_msglevel = usbnet_set_msglevel, | ||
3890 | }; | ||
3891 | |||
3892 | /*-------------------------------------------------------------------------*/ | 3050 | /*-------------------------------------------------------------------------*/ |
3893 | 3051 | ||
3894 | static int __init usbnet_init(void) | 3052 | static int __init usbnet_init(void) |
diff --git a/drivers/usb/net/usbnet.h b/drivers/usb/net/usbnet.h index d903b4617563..21b5feb54fc0 100644 --- a/drivers/usb/net/usbnet.h +++ b/drivers/usb/net/usbnet.h | |||
@@ -44,6 +44,7 @@ struct usbnet { | |||
44 | unsigned long data [5]; | 44 | unsigned long data [5]; |
45 | u32 xid; | 45 | u32 xid; |
46 | u32 hard_mtu; /* count any extra framing */ | 46 | u32 hard_mtu; /* count any extra framing */ |
47 | size_t rx_urb_size; /* size for rx urbs */ | ||
47 | struct mii_if_info mii; | 48 | struct mii_if_info mii; |
48 | 49 | ||
49 | /* various kinds of pending driver work */ | 50 | /* various kinds of pending driver work */ |
@@ -140,6 +141,13 @@ struct skb_data { /* skb->cb is one of these */ | |||
140 | }; | 141 | }; |
141 | 142 | ||
142 | 143 | ||
144 | extern int usbnet_get_endpoints(struct usbnet *, struct usb_interface *); | ||
145 | extern void usbnet_defer_kevent (struct usbnet *, int); | ||
146 | extern void usbnet_skb_return (struct usbnet *, struct sk_buff *); | ||
147 | |||
148 | extern u32 usbnet_get_msglevel (struct net_device *); | ||
149 | extern void usbnet_set_msglevel (struct net_device *, u32); | ||
150 | extern void usbnet_get_drvinfo (struct net_device *, struct ethtool_drvinfo *); | ||
143 | 151 | ||
144 | /* messaging support includes the interface name, so it must not be | 152 | /* messaging support includes the interface name, so it must not be |
145 | * used before it has one ... notably, in minidriver bind() calls. | 153 | * used before it has one ... notably, in minidriver bind() calls. |