blob: 869b14bc6d4303c1871cbc5be95ee09d9b78ba10 [file] [log] [blame]
David Brownell2e55cc72005-08-31 09:53:10 -07001/*
2 * ASIX AX8817X based USB 2.0 Ethernet Devices
David Hollis933a27d2006-07-29 10:12:50 -04003 * Copyright (C) 2003-2006 David Hollis <dhollis@davehollis.com>
David Brownell2e55cc72005-08-31 09:53:10 -07004 * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
David Hollis933a27d2006-07-29 10:12:50 -04005 * Copyright (C) 2006 James Painter <jamie.painter@iname.com>
David Brownell2e55cc72005-08-31 09:53:10 -07006 * Copyright (c) 2002-2003 TiVo Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23// #define DEBUG // error path messages, extra info
24// #define VERBOSE // more; success messages
25
David Brownell2e55cc72005-08-31 09:53:10 -070026#include <linux/module.h>
27#include <linux/kmod.h>
David Brownell2e55cc72005-08-31 09:53:10 -070028#include <linux/init.h>
29#include <linux/netdevice.h>
30#include <linux/etherdevice.h>
31#include <linux/ethtool.h>
32#include <linux/workqueue.h>
33#include <linux/mii.h>
34#include <linux/usb.h>
35#include <linux/crc32.h>
Jussi Kivilinna3692e942008-01-26 00:51:45 +020036#include <linux/usb/usbnet.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090037#include <linux/slab.h>
Eric Dumazet630ec142012-05-28 22:31:41 +000038#include <linux/if_vlan.h>
David Brownell2e55cc72005-08-31 09:53:10 -070039
allanf87ce5b2011-12-22 20:38:51 +000040#define DRIVER_VERSION "22-Dec-2011"
Grant Grundler83e1b912011-10-04 09:55:18 +000041#define DRIVER_NAME "asix"
David Hollis933a27d2006-07-29 10:12:50 -040042
David Brownell2e55cc72005-08-31 09:53:10 -070043/* ASIX AX8817X based USB 2.0 Ethernet Devices */
44
45#define AX_CMD_SET_SW_MII 0x06
46#define AX_CMD_READ_MII_REG 0x07
47#define AX_CMD_WRITE_MII_REG 0x08
48#define AX_CMD_SET_HW_MII 0x0a
49#define AX_CMD_READ_EEPROM 0x0b
50#define AX_CMD_WRITE_EEPROM 0x0c
51#define AX_CMD_WRITE_ENABLE 0x0d
52#define AX_CMD_WRITE_DISABLE 0x0e
David Hollis933a27d2006-07-29 10:12:50 -040053#define AX_CMD_READ_RX_CTL 0x0f
David Brownell2e55cc72005-08-31 09:53:10 -070054#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
David Hollis933a27d2006-07-29 10:12:50 -040058#define AX_CMD_READ_NODE_ID 0x13
Jussi Kivilinna7f29a3b2010-03-09 12:24:38 +000059#define AX_CMD_WRITE_NODE_ID 0x14
David Brownell2e55cc72005-08-31 09:53:10 -070060#define AX_CMD_WRITE_IPG2 0x14
61#define AX_CMD_WRITE_MULTI_FILTER 0x16
David Hollis933a27d2006-07-29 10:12:50 -040062#define AX88172_CMD_READ_NODE_ID 0x17
David Brownell2e55cc72005-08-31 09:53:10 -070063#define AX_CMD_READ_PHY_ID 0x19
64#define AX_CMD_READ_MEDIUM_STATUS 0x1a
65#define AX_CMD_WRITE_MEDIUM_MODE 0x1b
66#define AX_CMD_READ_MONITOR_MODE 0x1c
67#define AX_CMD_WRITE_MONITOR_MODE 0x1d
David Hollis933a27d2006-07-29 10:12:50 -040068#define AX_CMD_READ_GPIOS 0x1e
David Brownell2e55cc72005-08-31 09:53:10 -070069#define AX_CMD_WRITE_GPIOS 0x1f
70#define AX_CMD_SW_RESET 0x20
71#define AX_CMD_SW_PHY_STATUS 0x21
72#define AX_CMD_SW_PHY_SELECT 0x22
David Brownell2e55cc72005-08-31 09:53:10 -070073
74#define AX_MONITOR_MODE 0x01
75#define AX_MONITOR_LINK 0x02
76#define AX_MONITOR_MAGIC 0x04
77#define AX_MONITOR_HSFS 0x10
78
79/* AX88172 Medium Status Register values */
David Hollis933a27d2006-07-29 10:12:50 -040080#define AX88172_MEDIUM_FD 0x02
81#define AX88172_MEDIUM_TX 0x04
82#define AX88172_MEDIUM_FC 0x10
83#define AX88172_MEDIUM_DEFAULT \
84 ( AX88172_MEDIUM_FD | AX88172_MEDIUM_TX | AX88172_MEDIUM_FC )
David Brownell2e55cc72005-08-31 09:53:10 -070085
86#define AX_MCAST_FILTER_SIZE 8
87#define AX_MAX_MCAST 64
88
David Brownell2e55cc72005-08-31 09:53:10 -070089#define AX_SWRESET_CLEAR 0x00
90#define AX_SWRESET_RR 0x01
91#define AX_SWRESET_RT 0x02
92#define AX_SWRESET_PRTE 0x04
93#define AX_SWRESET_PRL 0x08
94#define AX_SWRESET_BZ 0x10
95#define AX_SWRESET_IPRL 0x20
96#define AX_SWRESET_IPPD 0x40
97
98#define AX88772_IPG0_DEFAULT 0x15
99#define AX88772_IPG1_DEFAULT 0x0c
100#define AX88772_IPG2_DEFAULT 0x12
101
David Hollis933a27d2006-07-29 10:12:50 -0400102/* AX88772 & AX88178 Medium Mode Register */
103#define AX_MEDIUM_PF 0x0080
104#define AX_MEDIUM_JFE 0x0040
105#define AX_MEDIUM_TFC 0x0020
106#define AX_MEDIUM_RFC 0x0010
107#define AX_MEDIUM_ENCK 0x0008
108#define AX_MEDIUM_AC 0x0004
109#define AX_MEDIUM_FD 0x0002
110#define AX_MEDIUM_GM 0x0001
111#define AX_MEDIUM_SM 0x1000
112#define AX_MEDIUM_SBP 0x0800
113#define AX_MEDIUM_PS 0x0200
114#define AX_MEDIUM_RE 0x0100
David Brownell2e55cc72005-08-31 09:53:10 -0700115
David Hollis933a27d2006-07-29 10:12:50 -0400116#define AX88178_MEDIUM_DEFAULT \
117 (AX_MEDIUM_PS | AX_MEDIUM_FD | AX_MEDIUM_AC | \
118 AX_MEDIUM_RFC | AX_MEDIUM_TFC | AX_MEDIUM_JFE | \
Grant Grundler83e1b912011-10-04 09:55:18 +0000119 AX_MEDIUM_RE)
David Hollis933a27d2006-07-29 10:12:50 -0400120
121#define AX88772_MEDIUM_DEFAULT \
122 (AX_MEDIUM_FD | AX_MEDIUM_RFC | \
123 AX_MEDIUM_TFC | AX_MEDIUM_PS | \
Grant Grundler83e1b912011-10-04 09:55:18 +0000124 AX_MEDIUM_AC | AX_MEDIUM_RE)
David Hollis933a27d2006-07-29 10:12:50 -0400125
126/* AX88772 & AX88178 RX_CTL values */
Grant Grundler83e1b912011-10-04 09:55:18 +0000127#define AX_RX_CTL_SO 0x0080
128#define AX_RX_CTL_AP 0x0020
129#define AX_RX_CTL_AM 0x0010
130#define AX_RX_CTL_AB 0x0008
131#define AX_RX_CTL_SEP 0x0004
132#define AX_RX_CTL_AMALL 0x0002
133#define AX_RX_CTL_PRO 0x0001
134#define AX_RX_CTL_MFB_2048 0x0000
135#define AX_RX_CTL_MFB_4096 0x0100
136#define AX_RX_CTL_MFB_8192 0x0200
137#define AX_RX_CTL_MFB_16384 0x0300
David Hollis933a27d2006-07-29 10:12:50 -0400138
Grant Grundler83e1b912011-10-04 09:55:18 +0000139#define AX_DEFAULT_RX_CTL (AX_RX_CTL_SO | AX_RX_CTL_AB)
David Hollis933a27d2006-07-29 10:12:50 -0400140
141/* GPIO 0 .. 2 toggles */
142#define AX_GPIO_GPO0EN 0x01 /* GPIO0 Output enable */
143#define AX_GPIO_GPO_0 0x02 /* GPIO0 Output value */
144#define AX_GPIO_GPO1EN 0x04 /* GPIO1 Output enable */
145#define AX_GPIO_GPO_1 0x08 /* GPIO1 Output value */
146#define AX_GPIO_GPO2EN 0x10 /* GPIO2 Output enable */
147#define AX_GPIO_GPO_2 0x20 /* GPIO2 Output value */
148#define AX_GPIO_RESERVED 0x40 /* Reserved */
149#define AX_GPIO_RSE 0x80 /* Reload serial EEPROM */
150
151#define AX_EEPROM_MAGIC 0xdeadbeef
152#define AX88172_EEPROM_LEN 0x40
153#define AX88772_EEPROM_LEN 0xff
154
155#define PHY_MODE_MARVELL 0x0000
156#define MII_MARVELL_LED_CTRL 0x0018
157#define MII_MARVELL_STATUS 0x001b
158#define MII_MARVELL_CTRL 0x0014
159
160#define MARVELL_LED_MANUAL 0x0019
161
162#define MARVELL_STATUS_HWCFG 0x0004
163
164#define MARVELL_CTRL_TXDELAY 0x0002
165#define MARVELL_CTRL_RXDELAY 0x0080
David Brownell2e55cc72005-08-31 09:53:10 -0700166
Grant Grundler34861402011-11-15 07:12:39 +0000167#define PHY_MODE_RTL8211CL 0x000C
Grant Grundler610d8852011-10-04 09:55:17 +0000168
David Brownell2e55cc72005-08-31 09:53:10 -0700169/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
David Hollis48b1be62006-03-28 20:15:42 -0500170struct asix_data {
David Brownell2e55cc72005-08-31 09:53:10 -0700171 u8 multi_filter[AX_MCAST_FILTER_SIZE];
Jussi Kivilinna7f29a3b2010-03-09 12:24:38 +0000172 u8 mac_addr[ETH_ALEN];
David Hollis933a27d2006-07-29 10:12:50 -0400173 u8 phymode;
174 u8 ledmode;
175 u8 eeprom_len;
David Brownell2e55cc72005-08-31 09:53:10 -0700176};
177
178struct ax88172_int_data {
Al Viro51bf2972007-12-22 17:42:36 +0000179 __le16 res1;
David Brownell2e55cc72005-08-31 09:53:10 -0700180 u8 link;
Al Viro51bf2972007-12-22 17:42:36 +0000181 __le16 res2;
David Brownell2e55cc72005-08-31 09:53:10 -0700182 u8 status;
Al Viro51bf2972007-12-22 17:42:36 +0000183 __le16 res3;
Eric Dumazetba2d3582010-06-02 18:10:09 +0000184} __packed;
David Brownell2e55cc72005-08-31 09:53:10 -0700185
Lucas Stach20d700b2014-02-27 12:51:38 +0100186struct asix_rx_fixup_info {
187 struct sk_buff *ax_skb;
188 u32 header;
189 u16 size;
190 bool split_head;
191};
192
193struct asix_common_private {
194 struct asix_rx_fixup_info rx_fixup_info;
195};
196
David Hollis48b1be62006-03-28 20:15:42 -0500197static int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
David Brownell2e55cc72005-08-31 09:53:10 -0700198 u16 size, void *data)
199{
Al Viro51bf2972007-12-22 17:42:36 +0000200 void *buf;
201 int err = -ENOMEM;
202
Joe Perches60b86752010-02-17 10:30:23 +0000203 netdev_dbg(dev->net, "asix_read_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n",
204 cmd, value, index, size);
Al Viro51bf2972007-12-22 17:42:36 +0000205
206 buf = kmalloc(size, GFP_KERNEL);
207 if (!buf)
208 goto out;
209
210 err = usb_control_msg(
David Brownell2e55cc72005-08-31 09:53:10 -0700211 dev->udev,
212 usb_rcvctrlpipe(dev->udev, 0),
213 cmd,
214 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
215 value,
216 index,
Al Viro51bf2972007-12-22 17:42:36 +0000217 buf,
David Brownell2e55cc72005-08-31 09:53:10 -0700218 size,
219 USB_CTRL_GET_TIMEOUT);
Russ Dill94d43362008-01-09 21:32:07 -0700220 if (err == size)
Al Viro51bf2972007-12-22 17:42:36 +0000221 memcpy(data, buf, size);
Russ Dill94d43362008-01-09 21:32:07 -0700222 else if (err >= 0)
223 err = -EINVAL;
Al Viro51bf2972007-12-22 17:42:36 +0000224 kfree(buf);
225
226out:
227 return err;
David Brownell2e55cc72005-08-31 09:53:10 -0700228}
229
David Hollis48b1be62006-03-28 20:15:42 -0500230static int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
David Brownell2e55cc72005-08-31 09:53:10 -0700231 u16 size, void *data)
232{
Al Viro51bf2972007-12-22 17:42:36 +0000233 void *buf = NULL;
234 int err = -ENOMEM;
235
Joe Perches60b86752010-02-17 10:30:23 +0000236 netdev_dbg(dev->net, "asix_write_cmd() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n",
237 cmd, value, index, size);
Al Viro51bf2972007-12-22 17:42:36 +0000238
239 if (data) {
Julia Lawall99bf2362010-05-15 11:20:45 +0000240 buf = kmemdup(data, size, GFP_KERNEL);
Al Viro51bf2972007-12-22 17:42:36 +0000241 if (!buf)
242 goto out;
Al Viro51bf2972007-12-22 17:42:36 +0000243 }
244
245 err = usb_control_msg(
David Brownell2e55cc72005-08-31 09:53:10 -0700246 dev->udev,
247 usb_sndctrlpipe(dev->udev, 0),
248 cmd,
249 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
250 value,
251 index,
Al Viro51bf2972007-12-22 17:42:36 +0000252 buf,
David Brownell2e55cc72005-08-31 09:53:10 -0700253 size,
254 USB_CTRL_SET_TIMEOUT);
Al Viro51bf2972007-12-22 17:42:36 +0000255 kfree(buf);
256
257out:
258 return err;
David Brownell2e55cc72005-08-31 09:53:10 -0700259}
260
David Howells7d12e782006-10-05 14:55:46 +0100261static void asix_async_cmd_callback(struct urb *urb)
David Brownell2e55cc72005-08-31 09:53:10 -0700262{
263 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
Oliver Neukumc94cb312008-12-18 23:00:59 -0800264 int status = urb->status;
David Brownell2e55cc72005-08-31 09:53:10 -0700265
Oliver Neukumc94cb312008-12-18 23:00:59 -0800266 if (status < 0)
David Hollis48b1be62006-03-28 20:15:42 -0500267 printk(KERN_DEBUG "asix_async_cmd_callback() failed with %d",
Oliver Neukumc94cb312008-12-18 23:00:59 -0800268 status);
David Brownell2e55cc72005-08-31 09:53:10 -0700269
270 kfree(req);
271 usb_free_urb(urb);
272}
273
David Hollis933a27d2006-07-29 10:12:50 -0400274static void
275asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
276 u16 size, void *data)
David Hollis48b1be62006-03-28 20:15:42 -0500277{
David Hollis933a27d2006-07-29 10:12:50 -0400278 struct usb_ctrlrequest *req;
279 int status;
280 struct urb *urb;
David Hollis48b1be62006-03-28 20:15:42 -0500281
Joe Perches60b86752010-02-17 10:30:23 +0000282 netdev_dbg(dev->net, "asix_write_cmd_async() cmd=0x%02x value=0x%04x index=0x%04x size=%d\n",
283 cmd, value, index, size);
Grant Grundler83e1b912011-10-04 09:55:18 +0000284
285 urb = usb_alloc_urb(0, GFP_ATOMIC);
286 if (!urb) {
Joe Perches60b86752010-02-17 10:30:23 +0000287 netdev_err(dev->net, "Error allocating URB in write_cmd_async!\n");
David Hollis933a27d2006-07-29 10:12:50 -0400288 return;
David Hollis48b1be62006-03-28 20:15:42 -0500289 }
David Hollis933a27d2006-07-29 10:12:50 -0400290
Grant Grundler83e1b912011-10-04 09:55:18 +0000291 req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC);
292 if (!req) {
Joe Perches60b86752010-02-17 10:30:23 +0000293 netdev_err(dev->net, "Failed to allocate memory for control request\n");
David Hollis933a27d2006-07-29 10:12:50 -0400294 usb_free_urb(urb);
295 return;
296 }
297
298 req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
299 req->bRequest = cmd;
Oliver Neukum9aa742e2006-11-23 12:45:31 +0100300 req->wValue = cpu_to_le16(value);
301 req->wIndex = cpu_to_le16(index);
302 req->wLength = cpu_to_le16(size);
David Hollis933a27d2006-07-29 10:12:50 -0400303
304 usb_fill_control_urb(urb, dev->udev,
305 usb_sndctrlpipe(dev->udev, 0),
306 (void *)req, data, size,
307 asix_async_cmd_callback, req);
308
Grant Grundler83e1b912011-10-04 09:55:18 +0000309 status = usb_submit_urb(urb, GFP_ATOMIC);
310 if (status < 0) {
Joe Perches60b86752010-02-17 10:30:23 +0000311 netdev_err(dev->net, "Error submitting the control message: status=%d\n",
312 status);
David Hollis933a27d2006-07-29 10:12:50 -0400313 kfree(req);
314 usb_free_urb(urb);
315 }
David Hollis48b1be62006-03-28 20:15:42 -0500316}
317
Lucas Stach20d700b2014-02-27 12:51:38 +0100318static int asix_rx_fixup_internal(struct usbnet *dev, struct sk_buff *skb,
319 struct asix_rx_fixup_info *rx)
David Hollis48b1be62006-03-28 20:15:42 -0500320{
Eric Dumazeta9e0aca2012-03-14 20:18:32 +0000321 int offset = 0;
David Hollis48b1be62006-03-28 20:15:42 -0500322
Lucas Stach20d700b2014-02-27 12:51:38 +0100323 while (offset + sizeof(u16) <= skb->len) {
324 u16 remaining = 0;
325 unsigned char *data;
David Hollis48b1be62006-03-28 20:15:42 -0500326
Lucas Stach20d700b2014-02-27 12:51:38 +0100327 if (!rx->size) {
328 if ((skb->len - offset == sizeof(u16)) ||
329 rx->split_head) {
330 if (!rx->split_head) {
331 rx->header = get_unaligned_le16(
332 skb->data + offset);
333 rx->split_head = true;
334 offset += sizeof(u16);
335 break;
336 } else {
337 rx->header |= (get_unaligned_le16(
338 skb->data + offset)
339 << 16);
340 rx->split_head = false;
341 offset += sizeof(u16);
342 }
343 } else {
344 rx->header = get_unaligned_le32(skb->data +
345 offset);
346 offset += sizeof(u32);
347 }
Marek Vasutbc466e62011-07-26 16:44:46 +0000348
Lucas Stach20d700b2014-02-27 12:51:38 +0100349 /* get the packet length */
350 rx->size = (u16) (rx->header & 0x7ff);
351 if (rx->size != ((~rx->header >> 16) & 0x7ff)) {
352 netdev_err(dev->net, "asix_rx_fixup() Bad Header Length 0x%x, offset %d\n",
353 rx->header, offset);
354 rx->size = 0;
355 return 0;
356 }
357 rx->ax_skb = netdev_alloc_skb_ip_align(dev->net,
358 rx->size);
359 if (!rx->ax_skb)
360 return 0;
Neil Jones3f78d1f2010-05-17 17:18:28 -0700361 }
362
Lucas Stach20d700b2014-02-27 12:51:38 +0100363 if (rx->size > dev->net->mtu + ETH_HLEN + VLAN_HLEN) {
Joe Perches60b86752010-02-17 10:30:23 +0000364 netdev_err(dev->net, "asix_rx_fixup() Bad RX Length %d\n",
Lucas Stach20d700b2014-02-27 12:51:38 +0100365 rx->size);
366 kfree_skb(rx->ax_skb);
David Hollis933a27d2006-07-29 10:12:50 -0400367 return 0;
368 }
David Hollis933a27d2006-07-29 10:12:50 -0400369
Lucas Stach20d700b2014-02-27 12:51:38 +0100370 if (rx->size > skb->len - offset) {
371 remaining = rx->size - (skb->len - offset);
372 rx->size = skb->len - offset;
373 }
David Hollis933a27d2006-07-29 10:12:50 -0400374
Lucas Stach20d700b2014-02-27 12:51:38 +0100375 data = skb_put(rx->ax_skb, rx->size);
376 memcpy(data, skb->data + offset, rx->size);
377 if (!remaining)
378 usbnet_skb_return(dev, rx->ax_skb);
379
380 offset += (rx->size + 1) & 0xfffe;
381 rx->size = remaining;
David Hollis933a27d2006-07-29 10:12:50 -0400382 }
383
Eric Dumazeta9e0aca2012-03-14 20:18:32 +0000384 if (skb->len != offset) {
Lucas Stach20d700b2014-02-27 12:51:38 +0100385 netdev_err(dev->net, "asix_rx_fixup() Bad SKB Length %d, %d\n",
386 skb->len, offset);
David Hollis933a27d2006-07-29 10:12:50 -0400387 return 0;
388 }
Lucas Stach20d700b2014-02-27 12:51:38 +0100389
David Hollis933a27d2006-07-29 10:12:50 -0400390 return 1;
David Hollis48b1be62006-03-28 20:15:42 -0500391}
392
Lucas Stach20d700b2014-02-27 12:51:38 +0100393static int asix_rx_fixup_common(struct usbnet *dev, struct sk_buff *skb)
394{
395 struct asix_common_private *dp = dev->driver_priv;
396 struct asix_rx_fixup_info *rx = &dp->rx_fixup_info;
397
398 return asix_rx_fixup_internal(dev, skb, rx);
399}
400
David Hollis933a27d2006-07-29 10:12:50 -0400401static struct sk_buff *asix_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
402 gfp_t flags)
David Hollis48b1be62006-03-28 20:15:42 -0500403{
David Hollis933a27d2006-07-29 10:12:50 -0400404 int padlen;
405 int headroom = skb_headroom(skb);
406 int tailroom = skb_tailroom(skb);
407 u32 packet_len;
408 u32 padbytes = 0xffff0000;
David Hollis48b1be62006-03-28 20:15:42 -0500409
Ingo van Lil2a580942012-04-23 22:05:38 +0000410 padlen = ((skb->len + 4) & (dev->maxpacket - 1)) ? 0 : 4;
David Hollis48b1be62006-03-28 20:15:42 -0500411
Joe Perches8e95a202009-12-03 07:58:21 +0000412 if ((!skb_cloned(skb)) &&
413 ((headroom + tailroom) >= (4 + padlen))) {
David Hollis933a27d2006-07-29 10:12:50 -0400414 if ((headroom < 4) || (tailroom < padlen)) {
415 skb->data = memmove(skb->head + 4, skb->data, skb->len);
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700416 skb_set_tail_pointer(skb, skb->len);
David Hollis933a27d2006-07-29 10:12:50 -0400417 }
418 } else {
419 struct sk_buff *skb2;
420 skb2 = skb_copy_expand(skb, 4, padlen, flags);
421 dev_kfree_skb_any(skb);
422 skb = skb2;
423 if (!skb)
424 return NULL;
425 }
426
427 skb_push(skb, 4);
428 packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4);
David Hollis57e4f042007-02-05 12:03:03 -0500429 cpu_to_le32s(&packet_len);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -0300430 skb_copy_to_linear_data(skb, &packet_len, sizeof(packet_len));
David Hollis933a27d2006-07-29 10:12:50 -0400431
Ingo van Lil2a580942012-04-23 22:05:38 +0000432 if (padlen) {
David Hollis57e4f042007-02-05 12:03:03 -0500433 cpu_to_le32s(&padbytes);
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -0700434 memcpy(skb_tail_pointer(skb), &padbytes, sizeof(padbytes));
David Hollis933a27d2006-07-29 10:12:50 -0400435 skb_put(skb, sizeof(padbytes));
436 }
437 return skb;
David Hollis48b1be62006-03-28 20:15:42 -0500438}
439
440static void asix_status(struct usbnet *dev, struct urb *urb)
David Brownell2e55cc72005-08-31 09:53:10 -0700441{
442 struct ax88172_int_data *event;
443 int link;
444
445 if (urb->actual_length < 8)
446 return;
447
448 event = urb->transfer_buffer;
449 link = event->link & 0x01;
450 if (netif_carrier_ok(dev->net) != link) {
451 if (link) {
452 netif_carrier_on(dev->net);
453 usbnet_defer_kevent (dev, EVENT_LINK_RESET );
454 } else
455 netif_carrier_off(dev->net);
Joe Perches60b86752010-02-17 10:30:23 +0000456 netdev_dbg(dev->net, "Link Status is: %d\n", link);
David Brownell2e55cc72005-08-31 09:53:10 -0700457 }
458}
459
David Hollis933a27d2006-07-29 10:12:50 -0400460static inline int asix_set_sw_mii(struct usbnet *dev)
David Brownell2e55cc72005-08-31 09:53:10 -0700461{
David Hollis933a27d2006-07-29 10:12:50 -0400462 int ret;
463 ret = asix_write_cmd(dev, AX_CMD_SET_SW_MII, 0x0000, 0, 0, NULL);
464 if (ret < 0)
Joe Perches60b86752010-02-17 10:30:23 +0000465 netdev_err(dev->net, "Failed to enable software MII access\n");
David Hollis933a27d2006-07-29 10:12:50 -0400466 return ret;
David Brownell2e55cc72005-08-31 09:53:10 -0700467}
468
David Hollis933a27d2006-07-29 10:12:50 -0400469static inline int asix_set_hw_mii(struct usbnet *dev)
470{
471 int ret;
472 ret = asix_write_cmd(dev, AX_CMD_SET_HW_MII, 0x0000, 0, 0, NULL);
473 if (ret < 0)
Joe Perches60b86752010-02-17 10:30:23 +0000474 netdev_err(dev->net, "Failed to enable hardware MII access\n");
David Hollis933a27d2006-07-29 10:12:50 -0400475 return ret;
476}
477
478static inline int asix_get_phy_addr(struct usbnet *dev)
479{
Al Viro51bf2972007-12-22 17:42:36 +0000480 u8 buf[2];
481 int ret = asix_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf);
David Hollis933a27d2006-07-29 10:12:50 -0400482
Joe Perches60b86752010-02-17 10:30:23 +0000483 netdev_dbg(dev->net, "asix_get_phy_addr()\n");
David Hollis933a27d2006-07-29 10:12:50 -0400484
Al Viro51bf2972007-12-22 17:42:36 +0000485 if (ret < 0) {
Joe Perches60b86752010-02-17 10:30:23 +0000486 netdev_err(dev->net, "Error reading PHYID register: %02x\n", ret);
Al Viro51bf2972007-12-22 17:42:36 +0000487 goto out;
David Hollis933a27d2006-07-29 10:12:50 -0400488 }
Joe Perches60b86752010-02-17 10:30:23 +0000489 netdev_dbg(dev->net, "asix_get_phy_addr() returning 0x%04x\n",
490 *((__le16 *)buf));
Al Viro51bf2972007-12-22 17:42:36 +0000491 ret = buf[1];
492
493out:
David Hollis933a27d2006-07-29 10:12:50 -0400494 return ret;
495}
496
497static int asix_sw_reset(struct usbnet *dev, u8 flags)
498{
499 int ret;
500
501 ret = asix_write_cmd(dev, AX_CMD_SW_RESET, flags, 0, 0, NULL);
502 if (ret < 0)
Joe Perches60b86752010-02-17 10:30:23 +0000503 netdev_err(dev->net, "Failed to send software reset: %02x\n", ret);
David Hollis933a27d2006-07-29 10:12:50 -0400504
505 return ret;
506}
507
508static u16 asix_read_rx_ctl(struct usbnet *dev)
509{
Al Viro51bf2972007-12-22 17:42:36 +0000510 __le16 v;
511 int ret = asix_read_cmd(dev, AX_CMD_READ_RX_CTL, 0, 0, 2, &v);
David Hollis933a27d2006-07-29 10:12:50 -0400512
Al Viro51bf2972007-12-22 17:42:36 +0000513 if (ret < 0) {
Joe Perches60b86752010-02-17 10:30:23 +0000514 netdev_err(dev->net, "Error reading RX_CTL register: %02x\n", ret);
Al Viro51bf2972007-12-22 17:42:36 +0000515 goto out;
David Hollis933a27d2006-07-29 10:12:50 -0400516 }
Al Viro51bf2972007-12-22 17:42:36 +0000517 ret = le16_to_cpu(v);
518out:
David Hollis933a27d2006-07-29 10:12:50 -0400519 return ret;
520}
521
522static int asix_write_rx_ctl(struct usbnet *dev, u16 mode)
523{
524 int ret;
525
Joe Perches60b86752010-02-17 10:30:23 +0000526 netdev_dbg(dev->net, "asix_write_rx_ctl() - mode = 0x%04x\n", mode);
David Hollis933a27d2006-07-29 10:12:50 -0400527 ret = asix_write_cmd(dev, AX_CMD_WRITE_RX_CTL, mode, 0, 0, NULL);
528 if (ret < 0)
Joe Perches60b86752010-02-17 10:30:23 +0000529 netdev_err(dev->net, "Failed to write RX_CTL mode to 0x%04x: %02x\n",
530 mode, ret);
David Hollis933a27d2006-07-29 10:12:50 -0400531
532 return ret;
533}
534
535static u16 asix_read_medium_status(struct usbnet *dev)
536{
Al Viro51bf2972007-12-22 17:42:36 +0000537 __le16 v;
538 int ret = asix_read_cmd(dev, AX_CMD_READ_MEDIUM_STATUS, 0, 0, 2, &v);
David Hollis933a27d2006-07-29 10:12:50 -0400539
Al Viro51bf2972007-12-22 17:42:36 +0000540 if (ret < 0) {
Joe Perches60b86752010-02-17 10:30:23 +0000541 netdev_err(dev->net, "Error reading Medium Status register: %02x\n",
542 ret);
Grant Grundler83e1b912011-10-04 09:55:18 +0000543 return ret; /* TODO: callers not checking for error ret */
David Hollis933a27d2006-07-29 10:12:50 -0400544 }
Grant Grundler83e1b912011-10-04 09:55:18 +0000545
546 return le16_to_cpu(v);
547
David Hollis933a27d2006-07-29 10:12:50 -0400548}
549
550static int asix_write_medium_mode(struct usbnet *dev, u16 mode)
551{
552 int ret;
553
Joe Perches60b86752010-02-17 10:30:23 +0000554 netdev_dbg(dev->net, "asix_write_medium_mode() - mode = 0x%04x\n", mode);
David Hollis933a27d2006-07-29 10:12:50 -0400555 ret = asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
556 if (ret < 0)
Joe Perches60b86752010-02-17 10:30:23 +0000557 netdev_err(dev->net, "Failed to write Medium Mode mode to 0x%04x: %02x\n",
558 mode, ret);
David Hollis933a27d2006-07-29 10:12:50 -0400559
560 return ret;
561}
562
563static int asix_write_gpio(struct usbnet *dev, u16 value, int sleep)
564{
565 int ret;
566
Joe Perches60b86752010-02-17 10:30:23 +0000567 netdev_dbg(dev->net, "asix_write_gpio() - value = 0x%04x\n", value);
David Hollis933a27d2006-07-29 10:12:50 -0400568 ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS, value, 0, 0, NULL);
569 if (ret < 0)
Joe Perches60b86752010-02-17 10:30:23 +0000570 netdev_err(dev->net, "Failed to write GPIO value 0x%04x: %02x\n",
571 value, ret);
David Hollis933a27d2006-07-29 10:12:50 -0400572
573 if (sleep)
574 msleep(sleep);
575
576 return ret;
577}
578
579/*
580 * AX88772 & AX88178 have a 16-bit RX_CTL value
581 */
David Hollis48b1be62006-03-28 20:15:42 -0500582static void asix_set_multicast(struct net_device *net)
David Brownell2e55cc72005-08-31 09:53:10 -0700583{
584 struct usbnet *dev = netdev_priv(net);
David Hollis48b1be62006-03-28 20:15:42 -0500585 struct asix_data *data = (struct asix_data *)&dev->data;
David Hollis933a27d2006-07-29 10:12:50 -0400586 u16 rx_ctl = AX_DEFAULT_RX_CTL;
David Brownell2e55cc72005-08-31 09:53:10 -0700587
588 if (net->flags & IFF_PROMISC) {
David Hollis933a27d2006-07-29 10:12:50 -0400589 rx_ctl |= AX_RX_CTL_PRO;
Joe Perches8e95a202009-12-03 07:58:21 +0000590 } else if (net->flags & IFF_ALLMULTI ||
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000591 netdev_mc_count(net) > AX_MAX_MCAST) {
David Hollis933a27d2006-07-29 10:12:50 -0400592 rx_ctl |= AX_RX_CTL_AMALL;
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000593 } else if (netdev_mc_empty(net)) {
David Brownell2e55cc72005-08-31 09:53:10 -0700594 /* just broadcast and directed */
595 } else {
596 /* We use the 20 byte dev->data
597 * for our 8 byte filter buffer
598 * to avoid allocating memory that
599 * is tricky to free later */
Jiri Pirko22bedad2010-04-01 21:22:57 +0000600 struct netdev_hw_addr *ha;
David Brownell2e55cc72005-08-31 09:53:10 -0700601 u32 crc_bits;
David Brownell2e55cc72005-08-31 09:53:10 -0700602
603 memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
604
605 /* Build the multicast hash filter. */
Jiri Pirko22bedad2010-04-01 21:22:57 +0000606 netdev_for_each_mc_addr(ha, net) {
607 crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
David Brownell2e55cc72005-08-31 09:53:10 -0700608 data->multi_filter[crc_bits >> 3] |=
609 1 << (crc_bits & 7);
David Brownell2e55cc72005-08-31 09:53:10 -0700610 }
611
David Hollis48b1be62006-03-28 20:15:42 -0500612 asix_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
David Brownell2e55cc72005-08-31 09:53:10 -0700613 AX_MCAST_FILTER_SIZE, data->multi_filter);
614
David Hollis933a27d2006-07-29 10:12:50 -0400615 rx_ctl |= AX_RX_CTL_AM;
David Brownell2e55cc72005-08-31 09:53:10 -0700616 }
617
David Hollis48b1be62006-03-28 20:15:42 -0500618 asix_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
David Brownell2e55cc72005-08-31 09:53:10 -0700619}
620
David Hollis48b1be62006-03-28 20:15:42 -0500621static int asix_mdio_read(struct net_device *netdev, int phy_id, int loc)
David Brownell2e55cc72005-08-31 09:53:10 -0700622{
623 struct usbnet *dev = netdev_priv(netdev);
Al Viro51bf2972007-12-22 17:42:36 +0000624 __le16 res;
David Brownell2e55cc72005-08-31 09:53:10 -0700625
Arnd Bergmanna9fc6332006-10-09 00:08:02 +0200626 mutex_lock(&dev->phy_mutex);
David Hollis48b1be62006-03-28 20:15:42 -0500627 asix_set_sw_mii(dev);
628 asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id,
Al Viro51bf2972007-12-22 17:42:36 +0000629 (__u16)loc, 2, &res);
David Hollis48b1be62006-03-28 20:15:42 -0500630 asix_set_hw_mii(dev);
Arnd Bergmanna9fc6332006-10-09 00:08:02 +0200631 mutex_unlock(&dev->phy_mutex);
David Brownell2e55cc72005-08-31 09:53:10 -0700632
Joe Perches60b86752010-02-17 10:30:23 +0000633 netdev_dbg(dev->net, "asix_mdio_read() phy_id=0x%02x, loc=0x%02x, returns=0x%04x\n",
634 phy_id, loc, le16_to_cpu(res));
David Brownell2e55cc72005-08-31 09:53:10 -0700635
Al Viro51bf2972007-12-22 17:42:36 +0000636 return le16_to_cpu(res);
David Brownell2e55cc72005-08-31 09:53:10 -0700637}
638
639static void
David Hollis48b1be62006-03-28 20:15:42 -0500640asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
David Brownell2e55cc72005-08-31 09:53:10 -0700641{
642 struct usbnet *dev = netdev_priv(netdev);
Al Viro51bf2972007-12-22 17:42:36 +0000643 __le16 res = cpu_to_le16(val);
David Brownell2e55cc72005-08-31 09:53:10 -0700644
Joe Perches60b86752010-02-17 10:30:23 +0000645 netdev_dbg(dev->net, "asix_mdio_write() phy_id=0x%02x, loc=0x%02x, val=0x%04x\n",
646 phy_id, loc, val);
Arnd Bergmanna9fc6332006-10-09 00:08:02 +0200647 mutex_lock(&dev->phy_mutex);
David Hollis48b1be62006-03-28 20:15:42 -0500648 asix_set_sw_mii(dev);
Al Viro51bf2972007-12-22 17:42:36 +0000649 asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, &res);
David Hollis48b1be62006-03-28 20:15:42 -0500650 asix_set_hw_mii(dev);
Arnd Bergmanna9fc6332006-10-09 00:08:02 +0200651 mutex_unlock(&dev->phy_mutex);
David Brownell2e55cc72005-08-31 09:53:10 -0700652}
653
David Hollis933a27d2006-07-29 10:12:50 -0400654/* Get the PHY Identifier from the PHYSID1 & PHYSID2 MII registers */
655static u32 asix_get_phyid(struct usbnet *dev)
David Brownell2e55cc72005-08-31 09:53:10 -0700656{
David Hollis933a27d2006-07-29 10:12:50 -0400657 int phy_reg;
658 u32 phy_id;
Grant Grundlera77929a2011-11-15 07:12:40 +0000659 int i;
David Brownell2e55cc72005-08-31 09:53:10 -0700660
Grant Grundlera77929a2011-11-15 07:12:40 +0000661 /* Poll for the rare case the FW or phy isn't ready yet. */
662 for (i = 0; i < 100; i++) {
663 phy_reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID1);
664 if (phy_reg != 0 && phy_reg != 0xFFFF)
665 break;
666 mdelay(1);
667 }
668
669 if (phy_reg <= 0 || phy_reg == 0xFFFF)
David Hollis933a27d2006-07-29 10:12:50 -0400670 return 0;
David Brownell2e55cc72005-08-31 09:53:10 -0700671
David Hollis933a27d2006-07-29 10:12:50 -0400672 phy_id = (phy_reg & 0xffff) << 16;
David Brownell2e55cc72005-08-31 09:53:10 -0700673
David Hollis933a27d2006-07-29 10:12:50 -0400674 phy_reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID2);
675 if (phy_reg < 0)
676 return 0;
677
678 phy_id |= (phy_reg & 0xffff);
679
680 return phy_id;
David Brownell2e55cc72005-08-31 09:53:10 -0700681}
682
683static void
David Hollis48b1be62006-03-28 20:15:42 -0500684asix_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
David Brownell2e55cc72005-08-31 09:53:10 -0700685{
686 struct usbnet *dev = netdev_priv(net);
687 u8 opt;
688
David Hollis48b1be62006-03-28 20:15:42 -0500689 if (asix_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
David Brownell2e55cc72005-08-31 09:53:10 -0700690 wolinfo->supported = 0;
691 wolinfo->wolopts = 0;
692 return;
693 }
694 wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
695 wolinfo->wolopts = 0;
allanf87ce5b2011-12-22 20:38:51 +0000696 if (opt & AX_MONITOR_LINK)
697 wolinfo->wolopts |= WAKE_PHY;
698 if (opt & AX_MONITOR_MAGIC)
699 wolinfo->wolopts |= WAKE_MAGIC;
David Brownell2e55cc72005-08-31 09:53:10 -0700700}
701
702static int
David Hollis48b1be62006-03-28 20:15:42 -0500703asix_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
David Brownell2e55cc72005-08-31 09:53:10 -0700704{
705 struct usbnet *dev = netdev_priv(net);
706 u8 opt = 0;
David Brownell2e55cc72005-08-31 09:53:10 -0700707
708 if (wolinfo->wolopts & WAKE_PHY)
709 opt |= AX_MONITOR_LINK;
710 if (wolinfo->wolopts & WAKE_MAGIC)
711 opt |= AX_MONITOR_MAGIC;
David Brownell2e55cc72005-08-31 09:53:10 -0700712
David Hollis48b1be62006-03-28 20:15:42 -0500713 if (asix_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE,
Al Viro51bf2972007-12-22 17:42:36 +0000714 opt, 0, 0, NULL) < 0)
David Brownell2e55cc72005-08-31 09:53:10 -0700715 return -EINVAL;
716
717 return 0;
718}
719
David Hollis48b1be62006-03-28 20:15:42 -0500720static int asix_get_eeprom_len(struct net_device *net)
David Brownell2e55cc72005-08-31 09:53:10 -0700721{
David Hollis933a27d2006-07-29 10:12:50 -0400722 struct usbnet *dev = netdev_priv(net);
723 struct asix_data *data = (struct asix_data *)&dev->data;
724
725 return data->eeprom_len;
David Brownell2e55cc72005-08-31 09:53:10 -0700726}
727
David Hollis48b1be62006-03-28 20:15:42 -0500728static int asix_get_eeprom(struct net_device *net,
David Brownell2e55cc72005-08-31 09:53:10 -0700729 struct ethtool_eeprom *eeprom, u8 *data)
730{
731 struct usbnet *dev = netdev_priv(net);
Al Viro51bf2972007-12-22 17:42:36 +0000732 __le16 *ebuf = (__le16 *)data;
David Brownell2e55cc72005-08-31 09:53:10 -0700733 int i;
734
735 /* Crude hack to ensure that we don't overwrite memory
736 * if an odd length is supplied
737 */
738 if (eeprom->len % 2)
739 return -EINVAL;
740
741 eeprom->magic = AX_EEPROM_MAGIC;
742
743 /* ax8817x returns 2 bytes from eeprom on read */
744 for (i=0; i < eeprom->len / 2; i++) {
David Hollis48b1be62006-03-28 20:15:42 -0500745 if (asix_read_cmd(dev, AX_CMD_READ_EEPROM,
David Brownell2e55cc72005-08-31 09:53:10 -0700746 eeprom->offset + i, 0, 2, &ebuf[i]) < 0)
747 return -EINVAL;
748 }
749 return 0;
750}
751
David Hollis48b1be62006-03-28 20:15:42 -0500752static void asix_get_drvinfo (struct net_device *net,
David Brownell2e55cc72005-08-31 09:53:10 -0700753 struct ethtool_drvinfo *info)
754{
David Hollis933a27d2006-07-29 10:12:50 -0400755 struct usbnet *dev = netdev_priv(net);
756 struct asix_data *data = (struct asix_data *)&dev->data;
757
David Brownell2e55cc72005-08-31 09:53:10 -0700758 /* Inherit standard device info */
759 usbnet_get_drvinfo(net, info);
Grant Grundler83e1b912011-10-04 09:55:18 +0000760 strncpy (info->driver, DRIVER_NAME, sizeof info->driver);
David Hollis933a27d2006-07-29 10:12:50 -0400761 strncpy (info->version, DRIVER_VERSION, sizeof info->version);
762 info->eedump_len = data->eeprom_len;
David Brownell2e55cc72005-08-31 09:53:10 -0700763}
764
David Hollis933a27d2006-07-29 10:12:50 -0400765static u32 asix_get_link(struct net_device *net)
766{
767 struct usbnet *dev = netdev_priv(net);
768
769 return mii_link_ok(&dev->mii);
770}
771
772static int asix_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
773{
774 struct usbnet *dev = netdev_priv(net);
775
776 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
David Brownell2e55cc72005-08-31 09:53:10 -0700777}
778
Jussi Kivilinna7f29a3b2010-03-09 12:24:38 +0000779static int asix_set_mac_address(struct net_device *net, void *p)
780{
781 struct usbnet *dev = netdev_priv(net);
782 struct asix_data *data = (struct asix_data *)&dev->data;
783 struct sockaddr *addr = p;
784
785 if (netif_running(net))
786 return -EBUSY;
787 if (!is_valid_ether_addr(addr->sa_data))
788 return -EADDRNOTAVAIL;
789
790 memcpy(net->dev_addr, addr->sa_data, ETH_ALEN);
791
792 /* We use the 20 byte dev->data
793 * for our 6 byte mac buffer
794 * to avoid allocating memory that
795 * is tricky to free later */
796 memcpy(data->mac_addr, addr->sa_data, ETH_ALEN);
797 asix_write_cmd_async(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
798 data->mac_addr);
799
800 return 0;
801}
802
David Brownell2e55cc72005-08-31 09:53:10 -0700803/* We need to override some ethtool_ops so we require our
804 own structure so we don't interfere with other usbnet
805 devices that may be connected at the same time. */
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700806static const struct ethtool_ops ax88172_ethtool_ops = {
David Hollis48b1be62006-03-28 20:15:42 -0500807 .get_drvinfo = asix_get_drvinfo,
David Hollis933a27d2006-07-29 10:12:50 -0400808 .get_link = asix_get_link,
David Brownell2e55cc72005-08-31 09:53:10 -0700809 .get_msglevel = usbnet_get_msglevel,
810 .set_msglevel = usbnet_set_msglevel,
David Hollis48b1be62006-03-28 20:15:42 -0500811 .get_wol = asix_get_wol,
812 .set_wol = asix_set_wol,
813 .get_eeprom_len = asix_get_eeprom_len,
814 .get_eeprom = asix_get_eeprom,
Arnd Bergmannc41286f2006-10-09 00:08:01 +0200815 .get_settings = usbnet_get_settings,
816 .set_settings = usbnet_set_settings,
817 .nway_reset = usbnet_nway_reset,
David Brownell2e55cc72005-08-31 09:53:10 -0700818};
819
David Hollis933a27d2006-07-29 10:12:50 -0400820static void ax88172_set_multicast(struct net_device *net)
David Brownell2e55cc72005-08-31 09:53:10 -0700821{
822 struct usbnet *dev = netdev_priv(net);
David Hollis933a27d2006-07-29 10:12:50 -0400823 struct asix_data *data = (struct asix_data *)&dev->data;
824 u8 rx_ctl = 0x8c;
David Brownell2e55cc72005-08-31 09:53:10 -0700825
David Hollis933a27d2006-07-29 10:12:50 -0400826 if (net->flags & IFF_PROMISC) {
827 rx_ctl |= 0x01;
Joe Perches8e95a202009-12-03 07:58:21 +0000828 } else if (net->flags & IFF_ALLMULTI ||
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000829 netdev_mc_count(net) > AX_MAX_MCAST) {
David Hollis933a27d2006-07-29 10:12:50 -0400830 rx_ctl |= 0x02;
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000831 } else if (netdev_mc_empty(net)) {
David Hollis933a27d2006-07-29 10:12:50 -0400832 /* just broadcast and directed */
833 } else {
834 /* We use the 20 byte dev->data
835 * for our 8 byte filter buffer
836 * to avoid allocating memory that
837 * is tricky to free later */
Jiri Pirko22bedad2010-04-01 21:22:57 +0000838 struct netdev_hw_addr *ha;
David Hollis933a27d2006-07-29 10:12:50 -0400839 u32 crc_bits;
David Hollis933a27d2006-07-29 10:12:50 -0400840
841 memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
842
843 /* Build the multicast hash filter. */
Jiri Pirko22bedad2010-04-01 21:22:57 +0000844 netdev_for_each_mc_addr(ha, net) {
845 crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
David Hollis933a27d2006-07-29 10:12:50 -0400846 data->multi_filter[crc_bits >> 3] |=
847 1 << (crc_bits & 7);
David Hollis933a27d2006-07-29 10:12:50 -0400848 }
849
850 asix_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
851 AX_MCAST_FILTER_SIZE, data->multi_filter);
852
853 rx_ctl |= 0x10;
854 }
855
856 asix_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
857}
858
859static int ax88172_link_reset(struct usbnet *dev)
860{
861 u8 mode;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000862 struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
David Hollis933a27d2006-07-29 10:12:50 -0400863
864 mii_check_media(&dev->mii, 1, 1);
865 mii_ethtool_gset(&dev->mii, &ecmd);
866 mode = AX88172_MEDIUM_DEFAULT;
867
868 if (ecmd.duplex != DUPLEX_FULL)
869 mode |= ~AX88172_MEDIUM_FD;
870
David Decotigny8ae6dac2011-04-27 18:32:38 +0000871 netdev_dbg(dev->net, "ax88172_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
872 ethtool_cmd_speed(&ecmd), ecmd.duplex, mode);
David Hollis933a27d2006-07-29 10:12:50 -0400873
874 asix_write_medium_mode(dev, mode);
875
876 return 0;
David Brownell2e55cc72005-08-31 09:53:10 -0700877}
878
Stephen Hemminger17033382009-03-20 19:35:55 +0000879static const struct net_device_ops ax88172_netdev_ops = {
880 .ndo_open = usbnet_open,
881 .ndo_stop = usbnet_stop,
882 .ndo_start_xmit = usbnet_start_xmit,
883 .ndo_tx_timeout = usbnet_tx_timeout,
884 .ndo_change_mtu = usbnet_change_mtu,
885 .ndo_set_mac_address = eth_mac_addr,
886 .ndo_validate_addr = eth_validate_addr,
887 .ndo_do_ioctl = asix_ioctl,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000888 .ndo_set_rx_mode = ax88172_set_multicast,
Stephen Hemminger17033382009-03-20 19:35:55 +0000889};
890
David Hollis48b1be62006-03-28 20:15:42 -0500891static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf)
David Brownell2e55cc72005-08-31 09:53:10 -0700892{
893 int ret = 0;
Al Viro51bf2972007-12-22 17:42:36 +0000894 u8 buf[ETH_ALEN];
David Brownell2e55cc72005-08-31 09:53:10 -0700895 int i;
896 unsigned long gpio_bits = dev->driver_info->data;
David Hollis933a27d2006-07-29 10:12:50 -0400897 struct asix_data *data = (struct asix_data *)&dev->data;
898
899 data->eeprom_len = AX88172_EEPROM_LEN;
David Brownell2e55cc72005-08-31 09:53:10 -0700900
901 usbnet_get_endpoints(dev,intf);
902
David Brownell2e55cc72005-08-31 09:53:10 -0700903 /* Toggle the GPIOs in a manufacturer/model specific way */
904 for (i = 2; i >= 0; i--) {
Grant Grundler83e1b912011-10-04 09:55:18 +0000905 ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS,
906 (gpio_bits >> (i * 8)) & 0xff, 0, 0, NULL);
907 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +0000908 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -0700909 msleep(5);
910 }
911
Grant Grundler83e1b912011-10-04 09:55:18 +0000912 ret = asix_write_rx_ctl(dev, 0x80);
913 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +0000914 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -0700915
916 /* Get the MAC address */
Grant Grundler83e1b912011-10-04 09:55:18 +0000917 ret = asix_read_cmd(dev, AX88172_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf);
918 if (ret < 0) {
David Brownell2e55cc72005-08-31 09:53:10 -0700919 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret);
Al Viro51bf2972007-12-22 17:42:36 +0000920 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -0700921 }
922 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
923
David Brownell2e55cc72005-08-31 09:53:10 -0700924 /* Initialize MII structure */
925 dev->mii.dev = dev->net;
David Hollis48b1be62006-03-28 20:15:42 -0500926 dev->mii.mdio_read = asix_mdio_read;
927 dev->mii.mdio_write = asix_mdio_write;
David Brownell2e55cc72005-08-31 09:53:10 -0700928 dev->mii.phy_id_mask = 0x3f;
929 dev->mii.reg_num_mask = 0x1f;
David Hollis933a27d2006-07-29 10:12:50 -0400930 dev->mii.phy_id = asix_get_phy_addr(dev);
David Brownell2e55cc72005-08-31 09:53:10 -0700931
Stephen Hemminger17033382009-03-20 19:35:55 +0000932 dev->net->netdev_ops = &ax88172_netdev_ops;
David Hollis48b1be62006-03-28 20:15:42 -0500933 dev->net->ethtool_ops = &ax88172_ethtool_ops;
David Brownell2e55cc72005-08-31 09:53:10 -0700934
David Hollis933a27d2006-07-29 10:12:50 -0400935 asix_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
936 asix_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
David Brownell2e55cc72005-08-31 09:53:10 -0700937 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
938 mii_nway_restart(&dev->mii);
939
940 return 0;
Al Viro51bf2972007-12-22 17:42:36 +0000941
942out:
David Brownell2e55cc72005-08-31 09:53:10 -0700943 return ret;
944}
945
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700946static const struct ethtool_ops ax88772_ethtool_ops = {
David Hollis48b1be62006-03-28 20:15:42 -0500947 .get_drvinfo = asix_get_drvinfo,
David Hollis933a27d2006-07-29 10:12:50 -0400948 .get_link = asix_get_link,
David Brownell2e55cc72005-08-31 09:53:10 -0700949 .get_msglevel = usbnet_get_msglevel,
950 .set_msglevel = usbnet_set_msglevel,
David Hollis48b1be62006-03-28 20:15:42 -0500951 .get_wol = asix_get_wol,
952 .set_wol = asix_set_wol,
953 .get_eeprom_len = asix_get_eeprom_len,
954 .get_eeprom = asix_get_eeprom,
Arnd Bergmannc41286f2006-10-09 00:08:01 +0200955 .get_settings = usbnet_get_settings,
956 .set_settings = usbnet_set_settings,
957 .nway_reset = usbnet_nway_reset,
David Brownell2e55cc72005-08-31 09:53:10 -0700958};
959
David Hollis933a27d2006-07-29 10:12:50 -0400960static int ax88772_link_reset(struct usbnet *dev)
961{
962 u16 mode;
David Decotigny8ae6dac2011-04-27 18:32:38 +0000963 struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
David Hollis933a27d2006-07-29 10:12:50 -0400964
965 mii_check_media(&dev->mii, 1, 1);
966 mii_ethtool_gset(&dev->mii, &ecmd);
967 mode = AX88772_MEDIUM_DEFAULT;
968
David Decotigny8ae6dac2011-04-27 18:32:38 +0000969 if (ethtool_cmd_speed(&ecmd) != SPEED_100)
David Hollis933a27d2006-07-29 10:12:50 -0400970 mode &= ~AX_MEDIUM_PS;
971
972 if (ecmd.duplex != DUPLEX_FULL)
973 mode &= ~AX_MEDIUM_FD;
974
David Decotigny8ae6dac2011-04-27 18:32:38 +0000975 netdev_dbg(dev->net, "ax88772_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
976 ethtool_cmd_speed(&ecmd), ecmd.duplex, mode);
David Hollis933a27d2006-07-29 10:12:50 -0400977
978 asix_write_medium_mode(dev, mode);
979
980 return 0;
981}
982
Grant Grundler4ad14382011-10-04 09:55:16 +0000983static int ax88772_reset(struct usbnet *dev)
David Brownell2e55cc72005-08-31 09:53:10 -0700984{
Jussi Kivilinna8ef66bd2012-01-10 06:40:17 +0000985 struct asix_data *data = (struct asix_data *)&dev->data;
Andres Salomond0ffff82007-01-11 18:39:16 -0500986 int ret, embd_phy;
David Hollis933a27d2006-07-29 10:12:50 -0400987 u16 rx_ctl;
David Brownell2e55cc72005-08-31 09:53:10 -0700988
Grant Grundler83e1b912011-10-04 09:55:18 +0000989 ret = asix_write_gpio(dev,
990 AX_GPIO_RSE | AX_GPIO_GPO_2 | AX_GPIO_GPO2EN, 5);
991 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +0000992 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -0700993
Andres Salomond0ffff82007-01-11 18:39:16 -0500994 embd_phy = ((asix_get_phy_addr(dev) & 0x1f) == 0x10 ? 1 : 0);
Grant Grundler4ad14382011-10-04 09:55:16 +0000995
Grant Grundler83e1b912011-10-04 09:55:18 +0000996 ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, embd_phy, 0, 0, NULL);
997 if (ret < 0) {
David Brownell2e55cc72005-08-31 09:53:10 -0700998 dbg("Select PHY #1 failed: %d", ret);
Al Viro51bf2972007-12-22 17:42:36 +0000999 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -07001000 }
1001
Grant Grundler83e1b912011-10-04 09:55:18 +00001002 ret = asix_sw_reset(dev, AX_SWRESET_IPPD | AX_SWRESET_PRL);
1003 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +00001004 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -07001005
1006 msleep(150);
Grant Grundler83e1b912011-10-04 09:55:18 +00001007
1008 ret = asix_sw_reset(dev, AX_SWRESET_CLEAR);
1009 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +00001010 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -07001011
1012 msleep(150);
Grant Grundler4ad14382011-10-04 09:55:16 +00001013
Andres Salomond0ffff82007-01-11 18:39:16 -05001014 if (embd_phy) {
Grant Grundler83e1b912011-10-04 09:55:18 +00001015 ret = asix_sw_reset(dev, AX_SWRESET_IPRL);
1016 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +00001017 goto out;
Grant Grundler83e1b912011-10-04 09:55:18 +00001018 } else {
1019 ret = asix_sw_reset(dev, AX_SWRESET_PRTE);
1020 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +00001021 goto out;
Andres Salomond0ffff82007-01-11 18:39:16 -05001022 }
David Brownell2e55cc72005-08-31 09:53:10 -07001023
1024 msleep(150);
David Hollis933a27d2006-07-29 10:12:50 -04001025 rx_ctl = asix_read_rx_ctl(dev);
1026 dbg("RX_CTL is 0x%04x after software reset", rx_ctl);
Grant Grundler83e1b912011-10-04 09:55:18 +00001027 ret = asix_write_rx_ctl(dev, 0x0000);
1028 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +00001029 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -07001030
David Hollis933a27d2006-07-29 10:12:50 -04001031 rx_ctl = asix_read_rx_ctl(dev);
1032 dbg("RX_CTL is 0x%04x setting to 0x0000", rx_ctl);
1033
Grant Grundler83e1b912011-10-04 09:55:18 +00001034 ret = asix_sw_reset(dev, AX_SWRESET_PRL);
1035 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +00001036 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -07001037
David Brownell2e55cc72005-08-31 09:53:10 -07001038 msleep(150);
1039
Grant Grundler83e1b912011-10-04 09:55:18 +00001040 ret = asix_sw_reset(dev, AX_SWRESET_IPRL | AX_SWRESET_PRL);
1041 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +00001042 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -07001043
David Hollis48b1be62006-03-28 20:15:42 -05001044 msleep(150);
1045
David Hollis933a27d2006-07-29 10:12:50 -04001046 asix_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
1047 asix_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
David Brownell2e55cc72005-08-31 09:53:10 -07001048 ADVERTISE_ALL | ADVERTISE_CSMA);
1049 mii_nway_restart(&dev->mii);
1050
Grant Grundler83e1b912011-10-04 09:55:18 +00001051 ret = asix_write_medium_mode(dev, AX88772_MEDIUM_DEFAULT);
1052 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +00001053 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -07001054
Grant Grundler83e1b912011-10-04 09:55:18 +00001055 ret = asix_write_cmd(dev, AX_CMD_WRITE_IPG0,
David Brownell2e55cc72005-08-31 09:53:10 -07001056 AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,
Grant Grundler83e1b912011-10-04 09:55:18 +00001057 AX88772_IPG2_DEFAULT, 0, NULL);
1058 if (ret < 0) {
David Brownell2e55cc72005-08-31 09:53:10 -07001059 dbg("Write IPG,IPG1,IPG2 failed: %d", ret);
Al Viro51bf2972007-12-22 17:42:36 +00001060 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -07001061 }
David Brownell2e55cc72005-08-31 09:53:10 -07001062
Jussi Kivilinna8ef66bd2012-01-10 06:40:17 +00001063 /* Rewrite MAC address */
1064 memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
1065 ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
1066 data->mac_addr);
1067 if (ret < 0)
1068 goto out;
1069
David Brownell2e55cc72005-08-31 09:53:10 -07001070 /* Set RX_CTL to default values with 2k buffer, and enable cactus */
Grant Grundler83e1b912011-10-04 09:55:18 +00001071 ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL);
1072 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +00001073 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -07001074
David Hollis933a27d2006-07-29 10:12:50 -04001075 rx_ctl = asix_read_rx_ctl(dev);
1076 dbg("RX_CTL is 0x%04x after all initializations", rx_ctl);
1077
1078 rx_ctl = asix_read_medium_status(dev);
1079 dbg("Medium Status is 0x%04x after all initializations", rx_ctl);
1080
Grant Grundler4ad14382011-10-04 09:55:16 +00001081 return 0;
1082
1083out:
1084 return ret;
1085
1086}
1087
1088static const struct net_device_ops ax88772_netdev_ops = {
1089 .ndo_open = usbnet_open,
1090 .ndo_stop = usbnet_stop,
1091 .ndo_start_xmit = usbnet_start_xmit,
1092 .ndo_tx_timeout = usbnet_tx_timeout,
1093 .ndo_change_mtu = usbnet_change_mtu,
1094 .ndo_set_mac_address = asix_set_mac_address,
1095 .ndo_validate_addr = eth_validate_addr,
1096 .ndo_do_ioctl = asix_ioctl,
1097 .ndo_set_rx_mode = asix_set_multicast,
1098};
1099
1100static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
1101{
Grant Grundlerd3665182011-11-15 07:12:41 +00001102 int ret, embd_phy;
Grant Grundler4ad14382011-10-04 09:55:16 +00001103 struct asix_data *data = (struct asix_data *)&dev->data;
1104 u8 buf[ETH_ALEN];
1105 u32 phyid;
1106
1107 data->eeprom_len = AX88772_EEPROM_LEN;
1108
1109 usbnet_get_endpoints(dev,intf);
1110
1111 /* Get the MAC address */
Grant Grundler83e1b912011-10-04 09:55:18 +00001112 ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf);
1113 if (ret < 0) {
Grant Grundler4ad14382011-10-04 09:55:16 +00001114 dbg("Failed to read MAC address: %d", ret);
Grant Grundler83e1b912011-10-04 09:55:18 +00001115 return ret;
Grant Grundler4ad14382011-10-04 09:55:16 +00001116 }
1117 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
1118
1119 /* Initialize MII structure */
1120 dev->mii.dev = dev->net;
1121 dev->mii.mdio_read = asix_mdio_read;
1122 dev->mii.mdio_write = asix_mdio_write;
1123 dev->mii.phy_id_mask = 0x1f;
1124 dev->mii.reg_num_mask = 0x1f;
1125 dev->mii.phy_id = asix_get_phy_addr(dev);
1126
Grant Grundler4ad14382011-10-04 09:55:16 +00001127 dev->net->netdev_ops = &ax88772_netdev_ops;
1128 dev->net->ethtool_ops = &ax88772_ethtool_ops;
1129
Grant Grundlerd3665182011-11-15 07:12:41 +00001130 embd_phy = ((dev->mii.phy_id & 0x1f) == 0x10 ? 1 : 0);
1131
1132 /* Reset the PHY to normal operation mode */
1133 ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, embd_phy, 0, 0, NULL);
1134 if (ret < 0) {
1135 dbg("Select PHY #1 failed: %d", ret);
1136 return ret;
1137 }
1138
1139 ret = asix_sw_reset(dev, AX_SWRESET_IPPD | AX_SWRESET_PRL);
Grant Grundler83e1b912011-10-04 09:55:18 +00001140 if (ret < 0)
1141 return ret;
Grant Grundler4ad14382011-10-04 09:55:16 +00001142
Grant Grundlerd3665182011-11-15 07:12:41 +00001143 msleep(150);
1144
1145 ret = asix_sw_reset(dev, AX_SWRESET_CLEAR);
1146 if (ret < 0)
1147 return ret;
1148
1149 msleep(150);
1150
1151 ret = asix_sw_reset(dev, embd_phy ? AX_SWRESET_IPRL : AX_SWRESET_PRTE);
1152
1153 /* Read PHYID register *AFTER* the PHY was reset properly */
1154 phyid = asix_get_phyid(dev);
1155 dbg("PHYID=0x%08x", phyid);
1156
David Brownell2e55cc72005-08-31 09:53:10 -07001157 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
1158 if (dev->driver_info->flags & FLAG_FRAMING_AX) {
1159 /* hard_mtu is still the default - the device does not support
1160 jumbo eth frames */
1161 dev->rx_urb_size = 2048;
1162 }
Grant Grundler83e1b912011-10-04 09:55:18 +00001163
Lucas Stach20d700b2014-02-27 12:51:38 +01001164 dev->driver_priv = kzalloc(sizeof(struct asix_common_private),
1165 GFP_KERNEL);
1166 if (!dev->driver_priv)
1167 return -ENOMEM;
1168
David Brownell2e55cc72005-08-31 09:53:10 -07001169 return 0;
David Brownell2e55cc72005-08-31 09:53:10 -07001170}
1171
Lucas Stach20d700b2014-02-27 12:51:38 +01001172static void ax88772_unbind(struct usbnet *dev, struct usb_interface *intf)
1173{
1174 kfree(dev->driver_priv);
1175}
1176
stephen hemmingerbc689c92012-01-05 19:10:23 +00001177static const struct ethtool_ops ax88178_ethtool_ops = {
David Hollis933a27d2006-07-29 10:12:50 -04001178 .get_drvinfo = asix_get_drvinfo,
1179 .get_link = asix_get_link,
David Hollis933a27d2006-07-29 10:12:50 -04001180 .get_msglevel = usbnet_get_msglevel,
1181 .set_msglevel = usbnet_set_msglevel,
1182 .get_wol = asix_get_wol,
1183 .set_wol = asix_set_wol,
1184 .get_eeprom_len = asix_get_eeprom_len,
1185 .get_eeprom = asix_get_eeprom,
Arnd Bergmannc41286f2006-10-09 00:08:01 +02001186 .get_settings = usbnet_get_settings,
1187 .set_settings = usbnet_set_settings,
1188 .nway_reset = usbnet_nway_reset,
David Hollis933a27d2006-07-29 10:12:50 -04001189};
1190
1191static int marvell_phy_init(struct usbnet *dev)
David Brownell2e55cc72005-08-31 09:53:10 -07001192{
David Hollis933a27d2006-07-29 10:12:50 -04001193 struct asix_data *data = (struct asix_data *)&dev->data;
1194 u16 reg;
David Brownell2e55cc72005-08-31 09:53:10 -07001195
Joe Perches60b86752010-02-17 10:30:23 +00001196 netdev_dbg(dev->net, "marvell_phy_init()\n");
David Brownell2e55cc72005-08-31 09:53:10 -07001197
David Hollis933a27d2006-07-29 10:12:50 -04001198 reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_MARVELL_STATUS);
Joe Perches60b86752010-02-17 10:30:23 +00001199 netdev_dbg(dev->net, "MII_MARVELL_STATUS = 0x%04x\n", reg);
David Brownell2e55cc72005-08-31 09:53:10 -07001200
David Hollis933a27d2006-07-29 10:12:50 -04001201 asix_mdio_write(dev->net, dev->mii.phy_id, MII_MARVELL_CTRL,
1202 MARVELL_CTRL_RXDELAY | MARVELL_CTRL_TXDELAY);
David Brownell2e55cc72005-08-31 09:53:10 -07001203
David Hollis933a27d2006-07-29 10:12:50 -04001204 if (data->ledmode) {
1205 reg = asix_mdio_read(dev->net, dev->mii.phy_id,
1206 MII_MARVELL_LED_CTRL);
Joe Perches60b86752010-02-17 10:30:23 +00001207 netdev_dbg(dev->net, "MII_MARVELL_LED_CTRL (1) = 0x%04x\n", reg);
David Brownell2e55cc72005-08-31 09:53:10 -07001208
David Hollis933a27d2006-07-29 10:12:50 -04001209 reg &= 0xf8ff;
1210 reg |= (1 + 0x0100);
1211 asix_mdio_write(dev->net, dev->mii.phy_id,
1212 MII_MARVELL_LED_CTRL, reg);
David Brownell2e55cc72005-08-31 09:53:10 -07001213
David Hollis933a27d2006-07-29 10:12:50 -04001214 reg = asix_mdio_read(dev->net, dev->mii.phy_id,
1215 MII_MARVELL_LED_CTRL);
Joe Perches60b86752010-02-17 10:30:23 +00001216 netdev_dbg(dev->net, "MII_MARVELL_LED_CTRL (2) = 0x%04x\n", reg);
David Hollis933a27d2006-07-29 10:12:50 -04001217 reg &= 0xfc0f;
David Brownell2e55cc72005-08-31 09:53:10 -07001218 }
1219
David Brownell2e55cc72005-08-31 09:53:10 -07001220 return 0;
1221}
1222
Grant Grundler610d8852011-10-04 09:55:17 +00001223static int rtl8211cl_phy_init(struct usbnet *dev)
1224{
1225 struct asix_data *data = (struct asix_data *)&dev->data;
1226
1227 netdev_dbg(dev->net, "rtl8211cl_phy_init()\n");
1228
1229 asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0x0005);
1230 asix_mdio_write (dev->net, dev->mii.phy_id, 0x0c, 0);
1231 asix_mdio_write (dev->net, dev->mii.phy_id, 0x01,
1232 asix_mdio_read (dev->net, dev->mii.phy_id, 0x01) | 0x0080);
1233 asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0);
1234
1235 if (data->ledmode == 12) {
1236 asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0x0002);
1237 asix_mdio_write (dev->net, dev->mii.phy_id, 0x1a, 0x00cb);
1238 asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0);
1239 }
1240
1241 return 0;
1242}
1243
David Hollis933a27d2006-07-29 10:12:50 -04001244static int marvell_led_status(struct usbnet *dev, u16 speed)
1245{
1246 u16 reg = asix_mdio_read(dev->net, dev->mii.phy_id, MARVELL_LED_MANUAL);
1247
Joe Perches60b86752010-02-17 10:30:23 +00001248 netdev_dbg(dev->net, "marvell_led_status() read 0x%04x\n", reg);
David Hollis933a27d2006-07-29 10:12:50 -04001249
1250 /* Clear out the center LED bits - 0x03F0 */
1251 reg &= 0xfc0f;
1252
1253 switch (speed) {
1254 case SPEED_1000:
1255 reg |= 0x03e0;
1256 break;
1257 case SPEED_100:
1258 reg |= 0x03b0;
1259 break;
1260 default:
1261 reg |= 0x02f0;
1262 }
1263
Joe Perches60b86752010-02-17 10:30:23 +00001264 netdev_dbg(dev->net, "marvell_led_status() writing 0x%04x\n", reg);
David Hollis933a27d2006-07-29 10:12:50 -04001265 asix_mdio_write(dev->net, dev->mii.phy_id, MARVELL_LED_MANUAL, reg);
1266
1267 return 0;
1268}
1269
Grant Grundler610d8852011-10-04 09:55:17 +00001270static int ax88178_reset(struct usbnet *dev)
1271{
1272 struct asix_data *data = (struct asix_data *)&dev->data;
1273 int ret;
1274 __le16 eeprom;
1275 u8 status;
1276 int gpio0 = 0;
Grant Grundlerb2d3ad22011-11-15 07:12:42 +00001277 u32 phyid;
Grant Grundler610d8852011-10-04 09:55:17 +00001278
1279 asix_read_cmd(dev, AX_CMD_READ_GPIOS, 0, 0, 1, &status);
1280 dbg("GPIO Status: 0x%04x", status);
1281
1282 asix_write_cmd(dev, AX_CMD_WRITE_ENABLE, 0, 0, 0, NULL);
1283 asix_read_cmd(dev, AX_CMD_READ_EEPROM, 0x0017, 0, 2, &eeprom);
1284 asix_write_cmd(dev, AX_CMD_WRITE_DISABLE, 0, 0, 0, NULL);
1285
1286 dbg("EEPROM index 0x17 is 0x%04x", eeprom);
1287
1288 if (eeprom == cpu_to_le16(0xffff)) {
1289 data->phymode = PHY_MODE_MARVELL;
1290 data->ledmode = 0;
1291 gpio0 = 1;
1292 } else {
Grant Grundlerb2d3ad22011-11-15 07:12:42 +00001293 data->phymode = le16_to_cpu(eeprom) & 0x7F;
Grant Grundler610d8852011-10-04 09:55:17 +00001294 data->ledmode = le16_to_cpu(eeprom) >> 8;
1295 gpio0 = (le16_to_cpu(eeprom) & 0x80) ? 0 : 1;
1296 }
1297 dbg("GPIO0: %d, PhyMode: %d", gpio0, data->phymode);
1298
Grant Grundlerb2d3ad22011-11-15 07:12:42 +00001299 /* Power up external GigaPHY through AX88178 GPIO pin */
Grant Grundler610d8852011-10-04 09:55:17 +00001300 asix_write_gpio(dev, AX_GPIO_RSE | AX_GPIO_GPO_1 | AX_GPIO_GPO1EN, 40);
1301 if ((le16_to_cpu(eeprom) >> 8) != 1) {
1302 asix_write_gpio(dev, 0x003c, 30);
1303 asix_write_gpio(dev, 0x001c, 300);
1304 asix_write_gpio(dev, 0x003c, 30);
1305 } else {
1306 dbg("gpio phymode == 1 path");
1307 asix_write_gpio(dev, AX_GPIO_GPO1EN, 30);
1308 asix_write_gpio(dev, AX_GPIO_GPO1EN | AX_GPIO_GPO_1, 30);
1309 }
1310
Grant Grundlerb2d3ad22011-11-15 07:12:42 +00001311 /* Read PHYID register *AFTER* powering up PHY */
1312 phyid = asix_get_phyid(dev);
1313 dbg("PHYID=0x%08x", phyid);
1314
1315 /* Set AX88178 to enable MII/GMII/RGMII interface for external PHY */
1316 asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 0, 0, 0, NULL);
1317
Grant Grundler610d8852011-10-04 09:55:17 +00001318 asix_sw_reset(dev, 0);
1319 msleep(150);
1320
1321 asix_sw_reset(dev, AX_SWRESET_PRL | AX_SWRESET_IPPD);
1322 msleep(150);
1323
1324 asix_write_rx_ctl(dev, 0);
1325
1326 if (data->phymode == PHY_MODE_MARVELL) {
1327 marvell_phy_init(dev);
1328 msleep(60);
1329 } else if (data->phymode == PHY_MODE_RTL8211CL)
1330 rtl8211cl_phy_init(dev);
1331
1332 asix_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR,
1333 BMCR_RESET | BMCR_ANENABLE);
1334 asix_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
1335 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
1336 asix_mdio_write(dev->net, dev->mii.phy_id, MII_CTRL1000,
1337 ADVERTISE_1000FULL);
1338
1339 mii_nway_restart(&dev->mii);
1340
Grant Grundler83e1b912011-10-04 09:55:18 +00001341 ret = asix_write_medium_mode(dev, AX88178_MEDIUM_DEFAULT);
1342 if (ret < 0)
1343 return ret;
Grant Grundler610d8852011-10-04 09:55:17 +00001344
Jussi Kivilinna71bc5d92012-01-10 06:40:23 +00001345 /* Rewrite MAC address */
1346 memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
1347 ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
1348 data->mac_addr);
1349 if (ret < 0)
1350 return ret;
1351
Grant Grundler83e1b912011-10-04 09:55:18 +00001352 ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL);
1353 if (ret < 0)
1354 return ret;
Grant Grundler610d8852011-10-04 09:55:17 +00001355
1356 return 0;
Grant Grundler610d8852011-10-04 09:55:17 +00001357}
1358
David Hollis933a27d2006-07-29 10:12:50 -04001359static int ax88178_link_reset(struct usbnet *dev)
1360{
1361 u16 mode;
David Decotigny8ae6dac2011-04-27 18:32:38 +00001362 struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
David Hollis933a27d2006-07-29 10:12:50 -04001363 struct asix_data *data = (struct asix_data *)&dev->data;
David Decotigny8ae6dac2011-04-27 18:32:38 +00001364 u32 speed;
David Hollis933a27d2006-07-29 10:12:50 -04001365
Joe Perches60b86752010-02-17 10:30:23 +00001366 netdev_dbg(dev->net, "ax88178_link_reset()\n");
David Hollis933a27d2006-07-29 10:12:50 -04001367
1368 mii_check_media(&dev->mii, 1, 1);
1369 mii_ethtool_gset(&dev->mii, &ecmd);
1370 mode = AX88178_MEDIUM_DEFAULT;
David Decotigny8ae6dac2011-04-27 18:32:38 +00001371 speed = ethtool_cmd_speed(&ecmd);
David Hollis933a27d2006-07-29 10:12:50 -04001372
David Decotigny8ae6dac2011-04-27 18:32:38 +00001373 if (speed == SPEED_1000)
Pantelis Koukousoulasa7f75c02008-11-20 01:48:46 -08001374 mode |= AX_MEDIUM_GM;
David Decotigny8ae6dac2011-04-27 18:32:38 +00001375 else if (speed == SPEED_100)
David Hollis933a27d2006-07-29 10:12:50 -04001376 mode |= AX_MEDIUM_PS;
1377 else
1378 mode &= ~(AX_MEDIUM_PS | AX_MEDIUM_GM);
1379
Pantelis Koukousoulasa7f75c02008-11-20 01:48:46 -08001380 mode |= AX_MEDIUM_ENCK;
1381
David Hollis933a27d2006-07-29 10:12:50 -04001382 if (ecmd.duplex == DUPLEX_FULL)
1383 mode |= AX_MEDIUM_FD;
1384 else
1385 mode &= ~AX_MEDIUM_FD;
1386
David Decotigny8ae6dac2011-04-27 18:32:38 +00001387 netdev_dbg(dev->net, "ax88178_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
1388 speed, ecmd.duplex, mode);
David Hollis933a27d2006-07-29 10:12:50 -04001389
1390 asix_write_medium_mode(dev, mode);
1391
1392 if (data->phymode == PHY_MODE_MARVELL && data->ledmode)
David Decotigny8ae6dac2011-04-27 18:32:38 +00001393 marvell_led_status(dev, speed);
David Hollis933a27d2006-07-29 10:12:50 -04001394
1395 return 0;
1396}
1397
1398static void ax88178_set_mfb(struct usbnet *dev)
1399{
1400 u16 mfb = AX_RX_CTL_MFB_16384;
1401 u16 rxctl;
1402 u16 medium;
1403 int old_rx_urb_size = dev->rx_urb_size;
1404
1405 if (dev->hard_mtu < 2048) {
1406 dev->rx_urb_size = 2048;
1407 mfb = AX_RX_CTL_MFB_2048;
1408 } else if (dev->hard_mtu < 4096) {
1409 dev->rx_urb_size = 4096;
1410 mfb = AX_RX_CTL_MFB_4096;
1411 } else if (dev->hard_mtu < 8192) {
1412 dev->rx_urb_size = 8192;
1413 mfb = AX_RX_CTL_MFB_8192;
1414 } else if (dev->hard_mtu < 16384) {
1415 dev->rx_urb_size = 16384;
1416 mfb = AX_RX_CTL_MFB_16384;
1417 }
1418
1419 rxctl = asix_read_rx_ctl(dev);
1420 asix_write_rx_ctl(dev, (rxctl & ~AX_RX_CTL_MFB_16384) | mfb);
1421
1422 medium = asix_read_medium_status(dev);
1423 if (dev->net->mtu > 1500)
1424 medium |= AX_MEDIUM_JFE;
1425 else
1426 medium &= ~AX_MEDIUM_JFE;
1427 asix_write_medium_mode(dev, medium);
1428
1429 if (dev->rx_urb_size > old_rx_urb_size)
1430 usbnet_unlink_rx_urbs(dev);
1431}
1432
1433static int ax88178_change_mtu(struct net_device *net, int new_mtu)
1434{
1435 struct usbnet *dev = netdev_priv(net);
1436 int ll_mtu = new_mtu + net->hard_header_len + 4;
1437
Joe Perches60b86752010-02-17 10:30:23 +00001438 netdev_dbg(dev->net, "ax88178_change_mtu() new_mtu=%d\n", new_mtu);
David Hollis933a27d2006-07-29 10:12:50 -04001439
1440 if (new_mtu <= 0 || ll_mtu > 16384)
1441 return -EINVAL;
1442
1443 if ((ll_mtu % dev->maxpacket) == 0)
1444 return -EDOM;
1445
1446 net->mtu = new_mtu;
1447 dev->hard_mtu = net->mtu + net->hard_header_len;
1448 ax88178_set_mfb(dev);
1449
1450 return 0;
1451}
1452
Stephen Hemminger17033382009-03-20 19:35:55 +00001453static const struct net_device_ops ax88178_netdev_ops = {
1454 .ndo_open = usbnet_open,
1455 .ndo_stop = usbnet_stop,
1456 .ndo_start_xmit = usbnet_start_xmit,
1457 .ndo_tx_timeout = usbnet_tx_timeout,
Jussi Kivilinna7f29a3b2010-03-09 12:24:38 +00001458 .ndo_set_mac_address = asix_set_mac_address,
Stephen Hemminger17033382009-03-20 19:35:55 +00001459 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00001460 .ndo_set_rx_mode = asix_set_multicast,
Stephen Hemminger17033382009-03-20 19:35:55 +00001461 .ndo_do_ioctl = asix_ioctl,
1462 .ndo_change_mtu = ax88178_change_mtu,
1463};
1464
David Hollis933a27d2006-07-29 10:12:50 -04001465static int ax88178_bind(struct usbnet *dev, struct usb_interface *intf)
1466{
David Hollis933a27d2006-07-29 10:12:50 -04001467 int ret;
Al Viro51bf2972007-12-22 17:42:36 +00001468 u8 buf[ETH_ALEN];
Grant Grundler79de9ef2011-10-17 05:51:06 +00001469 struct asix_data *data = (struct asix_data *)&dev->data;
1470
1471 data->eeprom_len = AX88772_EEPROM_LEN;
David Hollis933a27d2006-07-29 10:12:50 -04001472
1473 usbnet_get_endpoints(dev,intf);
1474
David Hollis933a27d2006-07-29 10:12:50 -04001475 /* Get the MAC address */
Grant Grundler83e1b912011-10-04 09:55:18 +00001476 ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf);
1477 if (ret < 0) {
David Hollis933a27d2006-07-29 10:12:50 -04001478 dbg("Failed to read MAC address: %d", ret);
Grant Grundler83e1b912011-10-04 09:55:18 +00001479 return ret;
David Hollis933a27d2006-07-29 10:12:50 -04001480 }
1481 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
1482
1483 /* Initialize MII structure */
1484 dev->mii.dev = dev->net;
1485 dev->mii.mdio_read = asix_mdio_read;
1486 dev->mii.mdio_write = asix_mdio_write;
1487 dev->mii.phy_id_mask = 0x1f;
1488 dev->mii.reg_num_mask = 0xff;
1489 dev->mii.supports_gmii = 1;
David Hollis933a27d2006-07-29 10:12:50 -04001490 dev->mii.phy_id = asix_get_phy_addr(dev);
Stephen Hemminger17033382009-03-20 19:35:55 +00001491
1492 dev->net->netdev_ops = &ax88178_netdev_ops;
David Hollis933a27d2006-07-29 10:12:50 -04001493 dev->net->ethtool_ops = &ax88178_ethtool_ops;
David Hollis933a27d2006-07-29 10:12:50 -04001494
Grant Grundlerb2d3ad22011-11-15 07:12:42 +00001495 /* Blink LEDS so users know driver saw dongle */
1496 asix_sw_reset(dev, 0);
1497 msleep(150);
David Hollis933a27d2006-07-29 10:12:50 -04001498
Grant Grundlerb2d3ad22011-11-15 07:12:42 +00001499 asix_sw_reset(dev, AX_SWRESET_PRL | AX_SWRESET_IPPD);
1500 msleep(150);
David Hollis933a27d2006-07-29 10:12:50 -04001501
1502 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
1503 if (dev->driver_info->flags & FLAG_FRAMING_AX) {
1504 /* hard_mtu is still the default - the device does not support
1505 jumbo eth frames */
1506 dev->rx_urb_size = 2048;
1507 }
David Hollis933a27d2006-07-29 10:12:50 -04001508
Lucas Stach20d700b2014-02-27 12:51:38 +01001509 dev->driver_priv = kzalloc(sizeof(struct asix_common_private),
1510 GFP_KERNEL);
1511 if (!dev->driver_priv)
1512 return -ENOMEM;
1513
Grant Grundler83e1b912011-10-04 09:55:18 +00001514 return 0;
David Hollis933a27d2006-07-29 10:12:50 -04001515}
1516
David Brownell2e55cc72005-08-31 09:53:10 -07001517static const struct driver_info ax8817x_info = {
1518 .description = "ASIX AX8817x USB 2.0 Ethernet",
David Hollis48b1be62006-03-28 20:15:42 -05001519 .bind = ax88172_bind,
1520 .status = asix_status,
David Brownell2e55cc72005-08-31 09:53:10 -07001521 .link_reset = ax88172_link_reset,
1522 .reset = ax88172_link_reset,
Ben Hutchings37e82732009-11-04 15:29:52 +00001523 .flags = FLAG_ETHER | FLAG_LINK_INTR,
David Brownell2e55cc72005-08-31 09:53:10 -07001524 .data = 0x00130103,
1525};
1526
1527static const struct driver_info dlink_dub_e100_info = {
1528 .description = "DLink DUB-E100 USB Ethernet",
David Hollis48b1be62006-03-28 20:15:42 -05001529 .bind = ax88172_bind,
1530 .status = asix_status,
David Brownell2e55cc72005-08-31 09:53:10 -07001531 .link_reset = ax88172_link_reset,
1532 .reset = ax88172_link_reset,
Ben Hutchings37e82732009-11-04 15:29:52 +00001533 .flags = FLAG_ETHER | FLAG_LINK_INTR,
David Brownell2e55cc72005-08-31 09:53:10 -07001534 .data = 0x009f9d9f,
1535};
1536
1537static const struct driver_info netgear_fa120_info = {
1538 .description = "Netgear FA-120 USB Ethernet",
David Hollis48b1be62006-03-28 20:15:42 -05001539 .bind = ax88172_bind,
1540 .status = asix_status,
David Brownell2e55cc72005-08-31 09:53:10 -07001541 .link_reset = ax88172_link_reset,
1542 .reset = ax88172_link_reset,
Ben Hutchings37e82732009-11-04 15:29:52 +00001543 .flags = FLAG_ETHER | FLAG_LINK_INTR,
David Brownell2e55cc72005-08-31 09:53:10 -07001544 .data = 0x00130103,
1545};
1546
1547static const struct driver_info hawking_uf200_info = {
1548 .description = "Hawking UF200 USB Ethernet",
David Hollis48b1be62006-03-28 20:15:42 -05001549 .bind = ax88172_bind,
1550 .status = asix_status,
David Brownell2e55cc72005-08-31 09:53:10 -07001551 .link_reset = ax88172_link_reset,
1552 .reset = ax88172_link_reset,
Ben Hutchings37e82732009-11-04 15:29:52 +00001553 .flags = FLAG_ETHER | FLAG_LINK_INTR,
David Brownell2e55cc72005-08-31 09:53:10 -07001554 .data = 0x001f1d1f,
1555};
1556
1557static const struct driver_info ax88772_info = {
1558 .description = "ASIX AX88772 USB 2.0 Ethernet",
1559 .bind = ax88772_bind,
Lucas Stach20d700b2014-02-27 12:51:38 +01001560 .unbind = ax88772_unbind,
David Hollis48b1be62006-03-28 20:15:42 -05001561 .status = asix_status,
David Brownell2e55cc72005-08-31 09:53:10 -07001562 .link_reset = ax88772_link_reset,
Grant Grundler4ad14382011-10-04 09:55:16 +00001563 .reset = ax88772_reset,
Lucas Stach20d700b2014-02-27 12:51:38 +01001564 .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR |
1565 FLAG_MULTI_PACKET,
1566 .rx_fixup = asix_rx_fixup_common,
David Hollis933a27d2006-07-29 10:12:50 -04001567 .tx_fixup = asix_tx_fixup,
1568};
1569
1570static const struct driver_info ax88178_info = {
1571 .description = "ASIX AX88178 USB 2.0 Ethernet",
1572 .bind = ax88178_bind,
Lucas Stach20d700b2014-02-27 12:51:38 +01001573 .unbind = ax88772_unbind,
David Hollis933a27d2006-07-29 10:12:50 -04001574 .status = asix_status,
1575 .link_reset = ax88178_link_reset,
Grant Grundler610d8852011-10-04 09:55:17 +00001576 .reset = ax88178_reset,
Ben Hutchings37e82732009-11-04 15:29:52 +00001577 .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR,
Lucas Stach20d700b2014-02-27 12:51:38 +01001578 .rx_fixup = asix_rx_fixup_common,
David Hollis933a27d2006-07-29 10:12:50 -04001579 .tx_fixup = asix_tx_fixup,
David Brownell2e55cc72005-08-31 09:53:10 -07001580};
1581
1582static const struct usb_device_id products [] = {
1583{
1584 // Linksys USB200M
1585 USB_DEVICE (0x077b, 0x2226),
1586 .driver_info = (unsigned long) &ax8817x_info,
1587}, {
1588 // Netgear FA120
1589 USB_DEVICE (0x0846, 0x1040),
1590 .driver_info = (unsigned long) &netgear_fa120_info,
1591}, {
1592 // DLink DUB-E100
1593 USB_DEVICE (0x2001, 0x1a00),
1594 .driver_info = (unsigned long) &dlink_dub_e100_info,
1595}, {
1596 // Intellinet, ST Lab USB Ethernet
1597 USB_DEVICE (0x0b95, 0x1720),
1598 .driver_info = (unsigned long) &ax8817x_info,
1599}, {
1600 // Hawking UF200, TrendNet TU2-ET100
1601 USB_DEVICE (0x07b8, 0x420a),
1602 .driver_info = (unsigned long) &hawking_uf200_info,
1603}, {
David Hollis39c4b382007-02-20 08:02:24 -05001604 // Billionton Systems, USB2AR
1605 USB_DEVICE (0x08dd, 0x90ff),
1606 .driver_info = (unsigned long) &ax8817x_info,
David Brownell2e55cc72005-08-31 09:53:10 -07001607}, {
1608 // ATEN UC210T
1609 USB_DEVICE (0x0557, 0x2009),
1610 .driver_info = (unsigned long) &ax8817x_info,
1611}, {
1612 // Buffalo LUA-U2-KTX
1613 USB_DEVICE (0x0411, 0x003d),
1614 .driver_info = (unsigned long) &ax8817x_info,
1615}, {
Mattia Dongiliac7b77f2008-05-06 20:42:35 -07001616 // Buffalo LUA-U2-GT 10/100/1000
1617 USB_DEVICE (0x0411, 0x006e),
1618 .driver_info = (unsigned long) &ax88178_info,
1619}, {
David Brownell2e55cc72005-08-31 09:53:10 -07001620 // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter"
1621 USB_DEVICE (0x6189, 0x182d),
1622 .driver_info = (unsigned long) &ax8817x_info,
1623}, {
Joerg Neikes4e503912012-03-08 22:44:03 +00001624 // Sitecom LN-031 "USB 2.0 10/100/1000 Ethernet adapter"
1625 USB_DEVICE (0x0df6, 0x0056),
1626 .driver_info = (unsigned long) &ax88178_info,
1627}, {
David Brownell2e55cc72005-08-31 09:53:10 -07001628 // corega FEther USB2-TX
1629 USB_DEVICE (0x07aa, 0x0017),
1630 .driver_info = (unsigned long) &ax8817x_info,
1631}, {
1632 // Surecom EP-1427X-2
1633 USB_DEVICE (0x1189, 0x0893),
1634 .driver_info = (unsigned long) &ax8817x_info,
1635}, {
1636 // goodway corp usb gwusb2e
1637 USB_DEVICE (0x1631, 0x6200),
1638 .driver_info = (unsigned long) &ax8817x_info,
1639}, {
David Hollis39c4b382007-02-20 08:02:24 -05001640 // JVC MP-PRX1 Port Replicator
1641 USB_DEVICE (0x04f1, 0x3008),
1642 .driver_info = (unsigned long) &ax8817x_info,
1643}, {
Marek Vasut30885902011-07-20 05:57:04 +00001644 // ASIX AX88772B 10/100
1645 USB_DEVICE (0x0b95, 0x772b),
1646 .driver_info = (unsigned long) &ax88772_info,
1647}, {
David Brownell2e55cc72005-08-31 09:53:10 -07001648 // ASIX AX88772 10/100
David Hollis39c4b382007-02-20 08:02:24 -05001649 USB_DEVICE (0x0b95, 0x7720),
1650 .driver_info = (unsigned long) &ax88772_info,
David Hollis5e0f76c2005-12-19 13:58:38 -05001651}, {
Eduard Warkentin73274132006-05-18 01:13:17 -07001652 // ASIX AX88178 10/100/1000
1653 USB_DEVICE (0x0b95, 0x1780),
David Hollis933a27d2006-07-29 10:12:50 -04001654 .driver_info = (unsigned long) &ax88178_info,
Eduard Warkentin73274132006-05-18 01:13:17 -07001655}, {
Arnaud Ebalardf4680d32010-12-15 12:16:30 +00001656 // Logitec LAN-GTJ/U2A
1657 USB_DEVICE (0x0789, 0x0160),
1658 .driver_info = (unsigned long) &ax88178_info,
1659}, {
David Hollis5e0f76c2005-12-19 13:58:38 -05001660 // Linksys USB200M Rev 2
1661 USB_DEVICE (0x13b1, 0x0018),
1662 .driver_info = (unsigned long) &ax88772_info,
David Hollis5732ce82006-01-05 14:39:49 -05001663}, {
1664 // 0Q0 cable ethernet
1665 USB_DEVICE (0x1557, 0x7720),
1666 .driver_info = (unsigned long) &ax88772_info,
David Hollis933a27d2006-07-29 10:12:50 -04001667}, {
1668 // DLink DUB-E100 H/W Ver B1
1669 USB_DEVICE (0x07d1, 0x3c05),
1670 .driver_info = (unsigned long) &ax88772_info,
1671}, {
David Hollisb923e7f2006-09-21 08:09:29 -04001672 // DLink DUB-E100 H/W Ver B1 Alternate
1673 USB_DEVICE (0x2001, 0x3c05),
1674 .driver_info = (unsigned long) &ax88772_info,
1675}, {
Søren Holmd83e6a42012-09-17 21:50:57 +00001676 // DLink DUB-E100 H/W Ver C1
1677 USB_DEVICE (0x2001, 0x1a02),
1678 .driver_info = (unsigned long) &ax88772_info,
1679}, {
David Hollis933a27d2006-07-29 10:12:50 -04001680 // Linksys USB1000
1681 USB_DEVICE (0x1737, 0x0039),
1682 .driver_info = (unsigned long) &ax88178_info,
YOSHIFUJI Hideaki / 吉藤英明b29cf312007-01-26 22:57:38 +09001683}, {
1684 // IO-DATA ETG-US2
1685 USB_DEVICE (0x04bb, 0x0930),
1686 .driver_info = (unsigned long) &ax88178_info,
David Hollis2ed22bc2007-05-23 07:33:17 -04001687}, {
1688 // Belkin F5D5055
1689 USB_DEVICE(0x050d, 0x5055),
1690 .driver_info = (unsigned long) &ax88178_info,
Aurelien Nephtali3d60efb52008-05-14 17:04:13 -07001691}, {
1692 // Apple USB Ethernet Adapter
1693 USB_DEVICE(0x05ac, 0x1402),
1694 .driver_info = (unsigned long) &ax88772_info,
Jason Cooperccf95402008-11-11 13:02:53 -05001695}, {
1696 // Cables-to-Go USB Ethernet Adapter
1697 USB_DEVICE(0x0b95, 0x772a),
1698 .driver_info = (unsigned long) &ax88772_info,
Greg Kroah-Hartmanfef7cc02009-02-24 23:52:24 -08001699}, {
1700 // ABOCOM for pci
1701 USB_DEVICE(0x14ea, 0xab11),
1702 .driver_info = (unsigned long) &ax88178_info,
1703}, {
1704 // ASIX 88772a
1705 USB_DEVICE(0x0db0, 0xa877),
1706 .driver_info = (unsigned long) &ax88772_info,
Aurelien Jacobse8303a32011-12-16 10:49:22 +00001707}, {
1708 // Asus USB Ethernet Adapter
1709 USB_DEVICE (0x0b95, 0x7e2b),
1710 .driver_info = (unsigned long) &ax88772_info,
David Brownell2e55cc72005-08-31 09:53:10 -07001711},
1712 { }, // END
1713};
1714MODULE_DEVICE_TABLE(usb, products);
1715
1716static struct usb_driver asix_driver = {
Grant Grundler83e1b912011-10-04 09:55:18 +00001717 .name = DRIVER_NAME,
David Brownell2e55cc72005-08-31 09:53:10 -07001718 .id_table = products,
1719 .probe = usbnet_probe,
1720 .suspend = usbnet_suspend,
1721 .resume = usbnet_resume,
1722 .disconnect = usbnet_disconnect,
Oliver Neukuma11a6542007-08-03 13:52:19 +02001723 .supports_autosuspend = 1,
David Brownell2e55cc72005-08-31 09:53:10 -07001724};
1725
Greg Kroah-Hartmand632eb12011-11-18 09:44:20 -08001726module_usb_driver(asix_driver);
David Brownell2e55cc72005-08-31 09:53:10 -07001727
1728MODULE_AUTHOR("David Hollis");
Grant Grundler4ad14382011-10-04 09:55:16 +00001729MODULE_VERSION(DRIVER_VERSION);
David Brownell2e55cc72005-08-31 09:53:10 -07001730MODULE_DESCRIPTION("ASIX AX8817X based USB 2.0 Ethernet Devices");
1731MODULE_LICENSE("GPL");
1732