blob: 33ab824773c5a795dc49cc91fd28e67bb3e501a5 [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
Christian Riesch607740b2012-07-13 05:26:30 +000023#include "asix.h"
David Hollis933a27d2006-07-29 10:12:50 -040024
25#define PHY_MODE_MARVELL 0x0000
26#define MII_MARVELL_LED_CTRL 0x0018
27#define MII_MARVELL_STATUS 0x001b
28#define MII_MARVELL_CTRL 0x0014
29
30#define MARVELL_LED_MANUAL 0x0019
31
32#define MARVELL_STATUS_HWCFG 0x0004
33
34#define MARVELL_CTRL_TXDELAY 0x0002
35#define MARVELL_CTRL_RXDELAY 0x0080
David Brownell2e55cc72005-08-31 09:53:10 -070036
Grant Grundler34861402011-11-15 07:12:39 +000037#define PHY_MODE_RTL8211CL 0x000C
Grant Grundler610d8852011-10-04 09:55:17 +000038
David Brownell2e55cc72005-08-31 09:53:10 -070039struct ax88172_int_data {
Al Viro51bf2972007-12-22 17:42:36 +000040 __le16 res1;
David Brownell2e55cc72005-08-31 09:53:10 -070041 u8 link;
Al Viro51bf2972007-12-22 17:42:36 +000042 __le16 res2;
David Brownell2e55cc72005-08-31 09:53:10 -070043 u8 status;
Al Viro51bf2972007-12-22 17:42:36 +000044 __le16 res3;
Eric Dumazetba2d3582010-06-02 18:10:09 +000045} __packed;
David Brownell2e55cc72005-08-31 09:53:10 -070046
David Hollis48b1be62006-03-28 20:15:42 -050047static void asix_status(struct usbnet *dev, struct urb *urb)
David Brownell2e55cc72005-08-31 09:53:10 -070048{
49 struct ax88172_int_data *event;
50 int link;
51
52 if (urb->actual_length < 8)
53 return;
54
55 event = urb->transfer_buffer;
56 link = event->link & 0x01;
57 if (netif_carrier_ok(dev->net) != link) {
58 if (link) {
59 netif_carrier_on(dev->net);
60 usbnet_defer_kevent (dev, EVENT_LINK_RESET );
61 } else
62 netif_carrier_off(dev->net);
Joe Perches60b86752010-02-17 10:30:23 +000063 netdev_dbg(dev->net, "Link Status is: %d\n", link);
David Brownell2e55cc72005-08-31 09:53:10 -070064 }
65}
66
David Hollis933a27d2006-07-29 10:12:50 -040067/* Get the PHY Identifier from the PHYSID1 & PHYSID2 MII registers */
68static u32 asix_get_phyid(struct usbnet *dev)
David Brownell2e55cc72005-08-31 09:53:10 -070069{
David Hollis933a27d2006-07-29 10:12:50 -040070 int phy_reg;
71 u32 phy_id;
Grant Grundlera77929a2011-11-15 07:12:40 +000072 int i;
David Brownell2e55cc72005-08-31 09:53:10 -070073
Grant Grundlera77929a2011-11-15 07:12:40 +000074 /* Poll for the rare case the FW or phy isn't ready yet. */
75 for (i = 0; i < 100; i++) {
76 phy_reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID1);
77 if (phy_reg != 0 && phy_reg != 0xFFFF)
78 break;
79 mdelay(1);
80 }
81
82 if (phy_reg <= 0 || phy_reg == 0xFFFF)
David Hollis933a27d2006-07-29 10:12:50 -040083 return 0;
David Brownell2e55cc72005-08-31 09:53:10 -070084
David Hollis933a27d2006-07-29 10:12:50 -040085 phy_id = (phy_reg & 0xffff) << 16;
David Brownell2e55cc72005-08-31 09:53:10 -070086
David Hollis933a27d2006-07-29 10:12:50 -040087 phy_reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_PHYSID2);
88 if (phy_reg < 0)
89 return 0;
90
91 phy_id |= (phy_reg & 0xffff);
92
93 return phy_id;
David Brownell2e55cc72005-08-31 09:53:10 -070094}
95
David Hollis933a27d2006-07-29 10:12:50 -040096static u32 asix_get_link(struct net_device *net)
97{
98 struct usbnet *dev = netdev_priv(net);
99
100 return mii_link_ok(&dev->mii);
101}
102
103static int asix_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
104{
105 struct usbnet *dev = netdev_priv(net);
106
107 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
David Brownell2e55cc72005-08-31 09:53:10 -0700108}
109
110/* We need to override some ethtool_ops so we require our
111 own structure so we don't interfere with other usbnet
112 devices that may be connected at the same time. */
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700113static const struct ethtool_ops ax88172_ethtool_ops = {
David Hollis48b1be62006-03-28 20:15:42 -0500114 .get_drvinfo = asix_get_drvinfo,
David Hollis933a27d2006-07-29 10:12:50 -0400115 .get_link = asix_get_link,
David Brownell2e55cc72005-08-31 09:53:10 -0700116 .get_msglevel = usbnet_get_msglevel,
117 .set_msglevel = usbnet_set_msglevel,
David Hollis48b1be62006-03-28 20:15:42 -0500118 .get_wol = asix_get_wol,
119 .set_wol = asix_set_wol,
120 .get_eeprom_len = asix_get_eeprom_len,
121 .get_eeprom = asix_get_eeprom,
Christian Rieschcb7b24c2012-07-19 00:23:07 +0000122 .set_eeprom = asix_set_eeprom,
Arnd Bergmannc41286f2006-10-09 00:08:01 +0200123 .get_settings = usbnet_get_settings,
124 .set_settings = usbnet_set_settings,
125 .nway_reset = usbnet_nway_reset,
David Brownell2e55cc72005-08-31 09:53:10 -0700126};
127
David Hollis933a27d2006-07-29 10:12:50 -0400128static void ax88172_set_multicast(struct net_device *net)
David Brownell2e55cc72005-08-31 09:53:10 -0700129{
130 struct usbnet *dev = netdev_priv(net);
David Hollis933a27d2006-07-29 10:12:50 -0400131 struct asix_data *data = (struct asix_data *)&dev->data;
132 u8 rx_ctl = 0x8c;
David Brownell2e55cc72005-08-31 09:53:10 -0700133
David Hollis933a27d2006-07-29 10:12:50 -0400134 if (net->flags & IFF_PROMISC) {
135 rx_ctl |= 0x01;
Joe Perches8e95a202009-12-03 07:58:21 +0000136 } else if (net->flags & IFF_ALLMULTI ||
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000137 netdev_mc_count(net) > AX_MAX_MCAST) {
David Hollis933a27d2006-07-29 10:12:50 -0400138 rx_ctl |= 0x02;
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000139 } else if (netdev_mc_empty(net)) {
David Hollis933a27d2006-07-29 10:12:50 -0400140 /* just broadcast and directed */
141 } else {
142 /* We use the 20 byte dev->data
143 * for our 8 byte filter buffer
144 * to avoid allocating memory that
145 * is tricky to free later */
Jiri Pirko22bedad32010-04-01 21:22:57 +0000146 struct netdev_hw_addr *ha;
David Hollis933a27d2006-07-29 10:12:50 -0400147 u32 crc_bits;
David Hollis933a27d2006-07-29 10:12:50 -0400148
149 memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
150
151 /* Build the multicast hash filter. */
Jiri Pirko22bedad32010-04-01 21:22:57 +0000152 netdev_for_each_mc_addr(ha, net) {
153 crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
David Hollis933a27d2006-07-29 10:12:50 -0400154 data->multi_filter[crc_bits >> 3] |=
155 1 << (crc_bits & 7);
David Hollis933a27d2006-07-29 10:12:50 -0400156 }
157
158 asix_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
159 AX_MCAST_FILTER_SIZE, data->multi_filter);
160
161 rx_ctl |= 0x10;
162 }
163
164 asix_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
165}
166
167static int ax88172_link_reset(struct usbnet *dev)
168{
169 u8 mode;
David Decotigny8ae6daca2011-04-27 18:32:38 +0000170 struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
David Hollis933a27d2006-07-29 10:12:50 -0400171
172 mii_check_media(&dev->mii, 1, 1);
173 mii_ethtool_gset(&dev->mii, &ecmd);
174 mode = AX88172_MEDIUM_DEFAULT;
175
176 if (ecmd.duplex != DUPLEX_FULL)
177 mode |= ~AX88172_MEDIUM_FD;
178
David Decotigny8ae6daca2011-04-27 18:32:38 +0000179 netdev_dbg(dev->net, "ax88172_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
180 ethtool_cmd_speed(&ecmd), ecmd.duplex, mode);
David Hollis933a27d2006-07-29 10:12:50 -0400181
182 asix_write_medium_mode(dev, mode);
183
184 return 0;
David Brownell2e55cc72005-08-31 09:53:10 -0700185}
186
Stephen Hemminger17033382009-03-20 19:35:55 +0000187static const struct net_device_ops ax88172_netdev_ops = {
188 .ndo_open = usbnet_open,
189 .ndo_stop = usbnet_stop,
190 .ndo_start_xmit = usbnet_start_xmit,
191 .ndo_tx_timeout = usbnet_tx_timeout,
192 .ndo_change_mtu = usbnet_change_mtu,
193 .ndo_set_mac_address = eth_mac_addr,
194 .ndo_validate_addr = eth_validate_addr,
195 .ndo_do_ioctl = asix_ioctl,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000196 .ndo_set_rx_mode = ax88172_set_multicast,
Stephen Hemminger17033382009-03-20 19:35:55 +0000197};
198
David Hollis48b1be62006-03-28 20:15:42 -0500199static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf)
David Brownell2e55cc72005-08-31 09:53:10 -0700200{
201 int ret = 0;
Al Viro51bf2972007-12-22 17:42:36 +0000202 u8 buf[ETH_ALEN];
David Brownell2e55cc72005-08-31 09:53:10 -0700203 int i;
204 unsigned long gpio_bits = dev->driver_info->data;
205
206 usbnet_get_endpoints(dev,intf);
207
David Brownell2e55cc72005-08-31 09:53:10 -0700208 /* Toggle the GPIOs in a manufacturer/model specific way */
209 for (i = 2; i >= 0; i--) {
Grant Grundler83e1b912011-10-04 09:55:18 +0000210 ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS,
211 (gpio_bits >> (i * 8)) & 0xff, 0, 0, NULL);
212 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +0000213 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -0700214 msleep(5);
215 }
216
Grant Grundler83e1b912011-10-04 09:55:18 +0000217 ret = asix_write_rx_ctl(dev, 0x80);
218 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +0000219 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -0700220
221 /* Get the MAC address */
Grant Grundler83e1b912011-10-04 09:55:18 +0000222 ret = asix_read_cmd(dev, AX88172_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf);
223 if (ret < 0) {
Greg Kroah-Hartman49ae25b2012-09-19 09:46:14 +0000224 netdev_dbg(dev->net, "read AX_CMD_READ_NODE_ID failed: %d\n",
225 ret);
Al Viro51bf2972007-12-22 17:42:36 +0000226 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -0700227 }
228 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
229
David Brownell2e55cc72005-08-31 09:53:10 -0700230 /* Initialize MII structure */
231 dev->mii.dev = dev->net;
David Hollis48b1be62006-03-28 20:15:42 -0500232 dev->mii.mdio_read = asix_mdio_read;
233 dev->mii.mdio_write = asix_mdio_write;
David Brownell2e55cc72005-08-31 09:53:10 -0700234 dev->mii.phy_id_mask = 0x3f;
235 dev->mii.reg_num_mask = 0x1f;
David Hollis933a27d2006-07-29 10:12:50 -0400236 dev->mii.phy_id = asix_get_phy_addr(dev);
David Brownell2e55cc72005-08-31 09:53:10 -0700237
Stephen Hemminger17033382009-03-20 19:35:55 +0000238 dev->net->netdev_ops = &ax88172_netdev_ops;
David Hollis48b1be62006-03-28 20:15:42 -0500239 dev->net->ethtool_ops = &ax88172_ethtool_ops;
Eric Dumazet95162d62012-07-05 04:31:01 +0000240 dev->net->needed_headroom = 4; /* cf asix_tx_fixup() */
241 dev->net->needed_tailroom = 4; /* cf asix_tx_fixup() */
David Brownell2e55cc72005-08-31 09:53:10 -0700242
David Hollis933a27d2006-07-29 10:12:50 -0400243 asix_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
244 asix_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
David Brownell2e55cc72005-08-31 09:53:10 -0700245 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
246 mii_nway_restart(&dev->mii);
247
248 return 0;
Al Viro51bf2972007-12-22 17:42:36 +0000249
250out:
David Brownell2e55cc72005-08-31 09:53:10 -0700251 return ret;
252}
253
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700254static const struct ethtool_ops ax88772_ethtool_ops = {
David Hollis48b1be62006-03-28 20:15:42 -0500255 .get_drvinfo = asix_get_drvinfo,
David Hollis933a27d2006-07-29 10:12:50 -0400256 .get_link = asix_get_link,
David Brownell2e55cc72005-08-31 09:53:10 -0700257 .get_msglevel = usbnet_get_msglevel,
258 .set_msglevel = usbnet_set_msglevel,
David Hollis48b1be62006-03-28 20:15:42 -0500259 .get_wol = asix_get_wol,
260 .set_wol = asix_set_wol,
261 .get_eeprom_len = asix_get_eeprom_len,
262 .get_eeprom = asix_get_eeprom,
Christian Rieschcb7b24c2012-07-19 00:23:07 +0000263 .set_eeprom = asix_set_eeprom,
Arnd Bergmannc41286f2006-10-09 00:08:01 +0200264 .get_settings = usbnet_get_settings,
265 .set_settings = usbnet_set_settings,
266 .nway_reset = usbnet_nway_reset,
David Brownell2e55cc72005-08-31 09:53:10 -0700267};
268
David Hollis933a27d2006-07-29 10:12:50 -0400269static int ax88772_link_reset(struct usbnet *dev)
270{
271 u16 mode;
David Decotigny8ae6daca2011-04-27 18:32:38 +0000272 struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
David Hollis933a27d2006-07-29 10:12:50 -0400273
274 mii_check_media(&dev->mii, 1, 1);
275 mii_ethtool_gset(&dev->mii, &ecmd);
276 mode = AX88772_MEDIUM_DEFAULT;
277
David Decotigny8ae6daca2011-04-27 18:32:38 +0000278 if (ethtool_cmd_speed(&ecmd) != SPEED_100)
David Hollis933a27d2006-07-29 10:12:50 -0400279 mode &= ~AX_MEDIUM_PS;
280
281 if (ecmd.duplex != DUPLEX_FULL)
282 mode &= ~AX_MEDIUM_FD;
283
David Decotigny8ae6daca2011-04-27 18:32:38 +0000284 netdev_dbg(dev->net, "ax88772_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
285 ethtool_cmd_speed(&ecmd), ecmd.duplex, mode);
David Hollis933a27d2006-07-29 10:12:50 -0400286
287 asix_write_medium_mode(dev, mode);
288
289 return 0;
290}
291
Grant Grundler4ad14382011-10-04 09:55:16 +0000292static int ax88772_reset(struct usbnet *dev)
David Brownell2e55cc72005-08-31 09:53:10 -0700293{
Jussi Kivilinna8ef66bd2012-01-10 06:40:17 +0000294 struct asix_data *data = (struct asix_data *)&dev->data;
Andres Salomond0ffff82007-01-11 18:39:16 -0500295 int ret, embd_phy;
David Hollis933a27d2006-07-29 10:12:50 -0400296 u16 rx_ctl;
David Brownell2e55cc72005-08-31 09:53:10 -0700297
Grant Grundler83e1b912011-10-04 09:55:18 +0000298 ret = asix_write_gpio(dev,
299 AX_GPIO_RSE | AX_GPIO_GPO_2 | AX_GPIO_GPO2EN, 5);
300 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +0000301 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -0700302
Andres Salomond0ffff82007-01-11 18:39:16 -0500303 embd_phy = ((asix_get_phy_addr(dev) & 0x1f) == 0x10 ? 1 : 0);
Grant Grundler4ad14382011-10-04 09:55:16 +0000304
Grant Grundler83e1b912011-10-04 09:55:18 +0000305 ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, embd_phy, 0, 0, NULL);
306 if (ret < 0) {
Greg Kroah-Hartman49ae25b2012-09-19 09:46:14 +0000307 netdev_dbg(dev->net, "Select PHY #1 failed: %d\n", ret);
Al Viro51bf2972007-12-22 17:42:36 +0000308 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -0700309 }
310
Grant Grundler83e1b912011-10-04 09:55:18 +0000311 ret = asix_sw_reset(dev, AX_SWRESET_IPPD | AX_SWRESET_PRL);
312 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +0000313 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -0700314
315 msleep(150);
Grant Grundler83e1b912011-10-04 09:55:18 +0000316
317 ret = asix_sw_reset(dev, AX_SWRESET_CLEAR);
318 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +0000319 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -0700320
321 msleep(150);
Grant Grundler4ad14382011-10-04 09:55:16 +0000322
Andres Salomond0ffff82007-01-11 18:39:16 -0500323 if (embd_phy) {
Grant Grundler83e1b912011-10-04 09:55:18 +0000324 ret = asix_sw_reset(dev, AX_SWRESET_IPRL);
325 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +0000326 goto out;
Grant Grundler83e1b912011-10-04 09:55:18 +0000327 } else {
328 ret = asix_sw_reset(dev, AX_SWRESET_PRTE);
329 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +0000330 goto out;
Andres Salomond0ffff82007-01-11 18:39:16 -0500331 }
David Brownell2e55cc72005-08-31 09:53:10 -0700332
333 msleep(150);
David Hollis933a27d2006-07-29 10:12:50 -0400334 rx_ctl = asix_read_rx_ctl(dev);
Greg Kroah-Hartman49ae25b2012-09-19 09:46:14 +0000335 netdev_dbg(dev->net, "RX_CTL is 0x%04x after software reset\n", rx_ctl);
Grant Grundler83e1b912011-10-04 09:55:18 +0000336 ret = asix_write_rx_ctl(dev, 0x0000);
337 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +0000338 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -0700339
David Hollis933a27d2006-07-29 10:12:50 -0400340 rx_ctl = asix_read_rx_ctl(dev);
Greg Kroah-Hartman49ae25b2012-09-19 09:46:14 +0000341 netdev_dbg(dev->net, "RX_CTL is 0x%04x setting to 0x0000\n", rx_ctl);
David Hollis933a27d2006-07-29 10:12:50 -0400342
Grant Grundler83e1b912011-10-04 09:55:18 +0000343 ret = asix_sw_reset(dev, AX_SWRESET_PRL);
344 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +0000345 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -0700346
David Brownell2e55cc72005-08-31 09:53:10 -0700347 msleep(150);
348
Grant Grundler83e1b912011-10-04 09:55:18 +0000349 ret = asix_sw_reset(dev, AX_SWRESET_IPRL | AX_SWRESET_PRL);
350 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +0000351 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -0700352
David Hollis48b1be62006-03-28 20:15:42 -0500353 msleep(150);
354
David Hollis933a27d2006-07-29 10:12:50 -0400355 asix_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
356 asix_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
David Brownell2e55cc72005-08-31 09:53:10 -0700357 ADVERTISE_ALL | ADVERTISE_CSMA);
358 mii_nway_restart(&dev->mii);
359
Grant Grundler83e1b912011-10-04 09:55:18 +0000360 ret = asix_write_medium_mode(dev, AX88772_MEDIUM_DEFAULT);
361 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +0000362 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -0700363
Grant Grundler83e1b912011-10-04 09:55:18 +0000364 ret = asix_write_cmd(dev, AX_CMD_WRITE_IPG0,
David Brownell2e55cc72005-08-31 09:53:10 -0700365 AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,
Grant Grundler83e1b912011-10-04 09:55:18 +0000366 AX88772_IPG2_DEFAULT, 0, NULL);
367 if (ret < 0) {
Greg Kroah-Hartman49ae25b2012-09-19 09:46:14 +0000368 netdev_dbg(dev->net, "Write IPG,IPG1,IPG2 failed: %d\n", ret);
Al Viro51bf2972007-12-22 17:42:36 +0000369 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -0700370 }
David Brownell2e55cc72005-08-31 09:53:10 -0700371
Jussi Kivilinna8ef66bd2012-01-10 06:40:17 +0000372 /* Rewrite MAC address */
373 memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
374 ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
375 data->mac_addr);
376 if (ret < 0)
377 goto out;
378
David Brownell2e55cc72005-08-31 09:53:10 -0700379 /* Set RX_CTL to default values with 2k buffer, and enable cactus */
Grant Grundler83e1b912011-10-04 09:55:18 +0000380 ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL);
381 if (ret < 0)
Al Viro51bf2972007-12-22 17:42:36 +0000382 goto out;
David Brownell2e55cc72005-08-31 09:53:10 -0700383
David Hollis933a27d2006-07-29 10:12:50 -0400384 rx_ctl = asix_read_rx_ctl(dev);
Greg Kroah-Hartman49ae25b2012-09-19 09:46:14 +0000385 netdev_dbg(dev->net, "RX_CTL is 0x%04x after all initializations\n",
386 rx_ctl);
David Hollis933a27d2006-07-29 10:12:50 -0400387
388 rx_ctl = asix_read_medium_status(dev);
Greg Kroah-Hartman49ae25b2012-09-19 09:46:14 +0000389 netdev_dbg(dev->net,
390 "Medium Status is 0x%04x after all initializations\n",
391 rx_ctl);
David Hollis933a27d2006-07-29 10:12:50 -0400392
Grant Grundler4ad14382011-10-04 09:55:16 +0000393 return 0;
394
395out:
396 return ret;
397
398}
399
400static const struct net_device_ops ax88772_netdev_ops = {
401 .ndo_open = usbnet_open,
402 .ndo_stop = usbnet_stop,
403 .ndo_start_xmit = usbnet_start_xmit,
404 .ndo_tx_timeout = usbnet_tx_timeout,
405 .ndo_change_mtu = usbnet_change_mtu,
406 .ndo_set_mac_address = asix_set_mac_address,
407 .ndo_validate_addr = eth_validate_addr,
408 .ndo_do_ioctl = asix_ioctl,
409 .ndo_set_rx_mode = asix_set_multicast,
410};
411
412static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
413{
Grant Grundlerd3665182011-11-15 07:12:41 +0000414 int ret, embd_phy;
Grant Grundler4ad14382011-10-04 09:55:16 +0000415 u8 buf[ETH_ALEN];
416 u32 phyid;
417
Grant Grundler4ad14382011-10-04 09:55:16 +0000418 usbnet_get_endpoints(dev,intf);
419
420 /* Get the MAC address */
Grant Grundler83e1b912011-10-04 09:55:18 +0000421 ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf);
422 if (ret < 0) {
Greg Kroah-Hartman49ae25b2012-09-19 09:46:14 +0000423 netdev_dbg(dev->net, "Failed to read MAC address: %d\n", ret);
Grant Grundler83e1b912011-10-04 09:55:18 +0000424 return ret;
Grant Grundler4ad14382011-10-04 09:55:16 +0000425 }
426 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
427
428 /* Initialize MII structure */
429 dev->mii.dev = dev->net;
430 dev->mii.mdio_read = asix_mdio_read;
431 dev->mii.mdio_write = asix_mdio_write;
432 dev->mii.phy_id_mask = 0x1f;
433 dev->mii.reg_num_mask = 0x1f;
434 dev->mii.phy_id = asix_get_phy_addr(dev);
435
Grant Grundler4ad14382011-10-04 09:55:16 +0000436 dev->net->netdev_ops = &ax88772_netdev_ops;
437 dev->net->ethtool_ops = &ax88772_ethtool_ops;
Eric Dumazet95162d62012-07-05 04:31:01 +0000438 dev->net->needed_headroom = 4; /* cf asix_tx_fixup() */
439 dev->net->needed_tailroom = 4; /* cf asix_tx_fixup() */
Grant Grundler4ad14382011-10-04 09:55:16 +0000440
Grant Grundlerd3665182011-11-15 07:12:41 +0000441 embd_phy = ((dev->mii.phy_id & 0x1f) == 0x10 ? 1 : 0);
442
443 /* Reset the PHY to normal operation mode */
444 ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, embd_phy, 0, 0, NULL);
445 if (ret < 0) {
Greg Kroah-Hartman49ae25b2012-09-19 09:46:14 +0000446 netdev_dbg(dev->net, "Select PHY #1 failed: %d\n", ret);
Grant Grundlerd3665182011-11-15 07:12:41 +0000447 return ret;
448 }
449
450 ret = asix_sw_reset(dev, AX_SWRESET_IPPD | AX_SWRESET_PRL);
Grant Grundler83e1b912011-10-04 09:55:18 +0000451 if (ret < 0)
452 return ret;
Grant Grundler4ad14382011-10-04 09:55:16 +0000453
Grant Grundlerd3665182011-11-15 07:12:41 +0000454 msleep(150);
455
456 ret = asix_sw_reset(dev, AX_SWRESET_CLEAR);
457 if (ret < 0)
458 return ret;
459
460 msleep(150);
461
462 ret = asix_sw_reset(dev, embd_phy ? AX_SWRESET_IPRL : AX_SWRESET_PRTE);
463
464 /* Read PHYID register *AFTER* the PHY was reset properly */
465 phyid = asix_get_phyid(dev);
Greg Kroah-Hartman49ae25b2012-09-19 09:46:14 +0000466 netdev_dbg(dev->net, "PHYID=0x%08x\n", phyid);
Grant Grundlerd3665182011-11-15 07:12:41 +0000467
David Brownell2e55cc72005-08-31 09:53:10 -0700468 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
469 if (dev->driver_info->flags & FLAG_FRAMING_AX) {
470 /* hard_mtu is still the default - the device does not support
471 jumbo eth frames */
472 dev->rx_urb_size = 2048;
473 }
Grant Grundler83e1b912011-10-04 09:55:18 +0000474
David Brownell2e55cc72005-08-31 09:53:10 -0700475 return 0;
David Brownell2e55cc72005-08-31 09:53:10 -0700476}
477
stephen hemmingerbc689c92012-01-05 19:10:23 +0000478static const struct ethtool_ops ax88178_ethtool_ops = {
David Hollis933a27d2006-07-29 10:12:50 -0400479 .get_drvinfo = asix_get_drvinfo,
480 .get_link = asix_get_link,
David Hollis933a27d2006-07-29 10:12:50 -0400481 .get_msglevel = usbnet_get_msglevel,
482 .set_msglevel = usbnet_set_msglevel,
483 .get_wol = asix_get_wol,
484 .set_wol = asix_set_wol,
485 .get_eeprom_len = asix_get_eeprom_len,
486 .get_eeprom = asix_get_eeprom,
Christian Rieschcb7b24c2012-07-19 00:23:07 +0000487 .set_eeprom = asix_set_eeprom,
Arnd Bergmannc41286f2006-10-09 00:08:01 +0200488 .get_settings = usbnet_get_settings,
489 .set_settings = usbnet_set_settings,
490 .nway_reset = usbnet_nway_reset,
David Hollis933a27d2006-07-29 10:12:50 -0400491};
492
493static int marvell_phy_init(struct usbnet *dev)
David Brownell2e55cc72005-08-31 09:53:10 -0700494{
David Hollis933a27d2006-07-29 10:12:50 -0400495 struct asix_data *data = (struct asix_data *)&dev->data;
496 u16 reg;
David Brownell2e55cc72005-08-31 09:53:10 -0700497
Joe Perches60b86752010-02-17 10:30:23 +0000498 netdev_dbg(dev->net, "marvell_phy_init()\n");
David Brownell2e55cc72005-08-31 09:53:10 -0700499
David Hollis933a27d2006-07-29 10:12:50 -0400500 reg = asix_mdio_read(dev->net, dev->mii.phy_id, MII_MARVELL_STATUS);
Joe Perches60b86752010-02-17 10:30:23 +0000501 netdev_dbg(dev->net, "MII_MARVELL_STATUS = 0x%04x\n", reg);
David Brownell2e55cc72005-08-31 09:53:10 -0700502
David Hollis933a27d2006-07-29 10:12:50 -0400503 asix_mdio_write(dev->net, dev->mii.phy_id, MII_MARVELL_CTRL,
504 MARVELL_CTRL_RXDELAY | MARVELL_CTRL_TXDELAY);
David Brownell2e55cc72005-08-31 09:53:10 -0700505
David Hollis933a27d2006-07-29 10:12:50 -0400506 if (data->ledmode) {
507 reg = asix_mdio_read(dev->net, dev->mii.phy_id,
508 MII_MARVELL_LED_CTRL);
Joe Perches60b86752010-02-17 10:30:23 +0000509 netdev_dbg(dev->net, "MII_MARVELL_LED_CTRL (1) = 0x%04x\n", reg);
David Brownell2e55cc72005-08-31 09:53:10 -0700510
David Hollis933a27d2006-07-29 10:12:50 -0400511 reg &= 0xf8ff;
512 reg |= (1 + 0x0100);
513 asix_mdio_write(dev->net, dev->mii.phy_id,
514 MII_MARVELL_LED_CTRL, reg);
David Brownell2e55cc72005-08-31 09:53:10 -0700515
David Hollis933a27d2006-07-29 10:12:50 -0400516 reg = asix_mdio_read(dev->net, dev->mii.phy_id,
517 MII_MARVELL_LED_CTRL);
Joe Perches60b86752010-02-17 10:30:23 +0000518 netdev_dbg(dev->net, "MII_MARVELL_LED_CTRL (2) = 0x%04x\n", reg);
David Hollis933a27d2006-07-29 10:12:50 -0400519 reg &= 0xfc0f;
David Brownell2e55cc72005-08-31 09:53:10 -0700520 }
521
David Brownell2e55cc72005-08-31 09:53:10 -0700522 return 0;
523}
524
Grant Grundler610d8852011-10-04 09:55:17 +0000525static int rtl8211cl_phy_init(struct usbnet *dev)
526{
527 struct asix_data *data = (struct asix_data *)&dev->data;
528
529 netdev_dbg(dev->net, "rtl8211cl_phy_init()\n");
530
531 asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0x0005);
532 asix_mdio_write (dev->net, dev->mii.phy_id, 0x0c, 0);
533 asix_mdio_write (dev->net, dev->mii.phy_id, 0x01,
534 asix_mdio_read (dev->net, dev->mii.phy_id, 0x01) | 0x0080);
535 asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0);
536
537 if (data->ledmode == 12) {
538 asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0x0002);
539 asix_mdio_write (dev->net, dev->mii.phy_id, 0x1a, 0x00cb);
540 asix_mdio_write (dev->net, dev->mii.phy_id, 0x1f, 0);
541 }
542
543 return 0;
544}
545
David Hollis933a27d2006-07-29 10:12:50 -0400546static int marvell_led_status(struct usbnet *dev, u16 speed)
547{
548 u16 reg = asix_mdio_read(dev->net, dev->mii.phy_id, MARVELL_LED_MANUAL);
549
Joe Perches60b86752010-02-17 10:30:23 +0000550 netdev_dbg(dev->net, "marvell_led_status() read 0x%04x\n", reg);
David Hollis933a27d2006-07-29 10:12:50 -0400551
552 /* Clear out the center LED bits - 0x03F0 */
553 reg &= 0xfc0f;
554
555 switch (speed) {
556 case SPEED_1000:
557 reg |= 0x03e0;
558 break;
559 case SPEED_100:
560 reg |= 0x03b0;
561 break;
562 default:
563 reg |= 0x02f0;
564 }
565
Joe Perches60b86752010-02-17 10:30:23 +0000566 netdev_dbg(dev->net, "marvell_led_status() writing 0x%04x\n", reg);
David Hollis933a27d2006-07-29 10:12:50 -0400567 asix_mdio_write(dev->net, dev->mii.phy_id, MARVELL_LED_MANUAL, reg);
568
569 return 0;
570}
571
Grant Grundler610d8852011-10-04 09:55:17 +0000572static int ax88178_reset(struct usbnet *dev)
573{
574 struct asix_data *data = (struct asix_data *)&dev->data;
575 int ret;
576 __le16 eeprom;
577 u8 status;
578 int gpio0 = 0;
Grant Grundlerb2d3ad292011-11-15 07:12:42 +0000579 u32 phyid;
Grant Grundler610d8852011-10-04 09:55:17 +0000580
581 asix_read_cmd(dev, AX_CMD_READ_GPIOS, 0, 0, 1, &status);
Greg Kroah-Hartman49ae25b2012-09-19 09:46:14 +0000582 netdev_dbg(dev->net, "GPIO Status: 0x%04x\n", status);
Grant Grundler610d8852011-10-04 09:55:17 +0000583
584 asix_write_cmd(dev, AX_CMD_WRITE_ENABLE, 0, 0, 0, NULL);
585 asix_read_cmd(dev, AX_CMD_READ_EEPROM, 0x0017, 0, 2, &eeprom);
586 asix_write_cmd(dev, AX_CMD_WRITE_DISABLE, 0, 0, 0, NULL);
587
Greg Kroah-Hartman49ae25b2012-09-19 09:46:14 +0000588 netdev_dbg(dev->net, "EEPROM index 0x17 is 0x%04x\n", eeprom);
Grant Grundler610d8852011-10-04 09:55:17 +0000589
590 if (eeprom == cpu_to_le16(0xffff)) {
591 data->phymode = PHY_MODE_MARVELL;
592 data->ledmode = 0;
593 gpio0 = 1;
594 } else {
Grant Grundlerb2d3ad292011-11-15 07:12:42 +0000595 data->phymode = le16_to_cpu(eeprom) & 0x7F;
Grant Grundler610d8852011-10-04 09:55:17 +0000596 data->ledmode = le16_to_cpu(eeprom) >> 8;
597 gpio0 = (le16_to_cpu(eeprom) & 0x80) ? 0 : 1;
598 }
Greg Kroah-Hartman49ae25b2012-09-19 09:46:14 +0000599 netdev_dbg(dev->net, "GPIO0: %d, PhyMode: %d\n", gpio0, data->phymode);
Grant Grundler610d8852011-10-04 09:55:17 +0000600
Grant Grundlerb2d3ad292011-11-15 07:12:42 +0000601 /* Power up external GigaPHY through AX88178 GPIO pin */
Grant Grundler610d8852011-10-04 09:55:17 +0000602 asix_write_gpio(dev, AX_GPIO_RSE | AX_GPIO_GPO_1 | AX_GPIO_GPO1EN, 40);
603 if ((le16_to_cpu(eeprom) >> 8) != 1) {
604 asix_write_gpio(dev, 0x003c, 30);
605 asix_write_gpio(dev, 0x001c, 300);
606 asix_write_gpio(dev, 0x003c, 30);
607 } else {
Greg Kroah-Hartman49ae25b2012-09-19 09:46:14 +0000608 netdev_dbg(dev->net, "gpio phymode == 1 path\n");
Grant Grundler610d8852011-10-04 09:55:17 +0000609 asix_write_gpio(dev, AX_GPIO_GPO1EN, 30);
610 asix_write_gpio(dev, AX_GPIO_GPO1EN | AX_GPIO_GPO_1, 30);
611 }
612
Grant Grundlerb2d3ad292011-11-15 07:12:42 +0000613 /* Read PHYID register *AFTER* powering up PHY */
614 phyid = asix_get_phyid(dev);
Greg Kroah-Hartman49ae25b2012-09-19 09:46:14 +0000615 netdev_dbg(dev->net, "PHYID=0x%08x\n", phyid);
Grant Grundlerb2d3ad292011-11-15 07:12:42 +0000616
617 /* Set AX88178 to enable MII/GMII/RGMII interface for external PHY */
618 asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 0, 0, 0, NULL);
619
Grant Grundler610d8852011-10-04 09:55:17 +0000620 asix_sw_reset(dev, 0);
621 msleep(150);
622
623 asix_sw_reset(dev, AX_SWRESET_PRL | AX_SWRESET_IPPD);
624 msleep(150);
625
626 asix_write_rx_ctl(dev, 0);
627
628 if (data->phymode == PHY_MODE_MARVELL) {
629 marvell_phy_init(dev);
630 msleep(60);
631 } else if (data->phymode == PHY_MODE_RTL8211CL)
632 rtl8211cl_phy_init(dev);
633
634 asix_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR,
635 BMCR_RESET | BMCR_ANENABLE);
636 asix_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
637 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
638 asix_mdio_write(dev->net, dev->mii.phy_id, MII_CTRL1000,
639 ADVERTISE_1000FULL);
640
641 mii_nway_restart(&dev->mii);
642
Grant Grundler83e1b912011-10-04 09:55:18 +0000643 ret = asix_write_medium_mode(dev, AX88178_MEDIUM_DEFAULT);
644 if (ret < 0)
645 return ret;
Grant Grundler610d8852011-10-04 09:55:17 +0000646
Jussi Kivilinna71bc5d92012-01-10 06:40:23 +0000647 /* Rewrite MAC address */
648 memcpy(data->mac_addr, dev->net->dev_addr, ETH_ALEN);
649 ret = asix_write_cmd(dev, AX_CMD_WRITE_NODE_ID, 0, 0, ETH_ALEN,
650 data->mac_addr);
651 if (ret < 0)
652 return ret;
653
Grant Grundler83e1b912011-10-04 09:55:18 +0000654 ret = asix_write_rx_ctl(dev, AX_DEFAULT_RX_CTL);
655 if (ret < 0)
656 return ret;
Grant Grundler610d8852011-10-04 09:55:17 +0000657
658 return 0;
Grant Grundler610d8852011-10-04 09:55:17 +0000659}
660
David Hollis933a27d2006-07-29 10:12:50 -0400661static int ax88178_link_reset(struct usbnet *dev)
662{
663 u16 mode;
David Decotigny8ae6daca2011-04-27 18:32:38 +0000664 struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
David Hollis933a27d2006-07-29 10:12:50 -0400665 struct asix_data *data = (struct asix_data *)&dev->data;
David Decotigny8ae6daca2011-04-27 18:32:38 +0000666 u32 speed;
David Hollis933a27d2006-07-29 10:12:50 -0400667
Joe Perches60b86752010-02-17 10:30:23 +0000668 netdev_dbg(dev->net, "ax88178_link_reset()\n");
David Hollis933a27d2006-07-29 10:12:50 -0400669
670 mii_check_media(&dev->mii, 1, 1);
671 mii_ethtool_gset(&dev->mii, &ecmd);
672 mode = AX88178_MEDIUM_DEFAULT;
David Decotigny8ae6daca2011-04-27 18:32:38 +0000673 speed = ethtool_cmd_speed(&ecmd);
David Hollis933a27d2006-07-29 10:12:50 -0400674
David Decotigny8ae6daca2011-04-27 18:32:38 +0000675 if (speed == SPEED_1000)
Pantelis Koukousoulasa7f75c02008-11-20 01:48:46 -0800676 mode |= AX_MEDIUM_GM;
David Decotigny8ae6daca2011-04-27 18:32:38 +0000677 else if (speed == SPEED_100)
David Hollis933a27d2006-07-29 10:12:50 -0400678 mode |= AX_MEDIUM_PS;
679 else
680 mode &= ~(AX_MEDIUM_PS | AX_MEDIUM_GM);
681
Pantelis Koukousoulasa7f75c02008-11-20 01:48:46 -0800682 mode |= AX_MEDIUM_ENCK;
683
David Hollis933a27d2006-07-29 10:12:50 -0400684 if (ecmd.duplex == DUPLEX_FULL)
685 mode |= AX_MEDIUM_FD;
686 else
687 mode &= ~AX_MEDIUM_FD;
688
David Decotigny8ae6daca2011-04-27 18:32:38 +0000689 netdev_dbg(dev->net, "ax88178_link_reset() speed: %u duplex: %d setting mode to 0x%04x\n",
690 speed, ecmd.duplex, mode);
David Hollis933a27d2006-07-29 10:12:50 -0400691
692 asix_write_medium_mode(dev, mode);
693
694 if (data->phymode == PHY_MODE_MARVELL && data->ledmode)
David Decotigny8ae6daca2011-04-27 18:32:38 +0000695 marvell_led_status(dev, speed);
David Hollis933a27d2006-07-29 10:12:50 -0400696
697 return 0;
698}
699
700static void ax88178_set_mfb(struct usbnet *dev)
701{
702 u16 mfb = AX_RX_CTL_MFB_16384;
703 u16 rxctl;
704 u16 medium;
705 int old_rx_urb_size = dev->rx_urb_size;
706
707 if (dev->hard_mtu < 2048) {
708 dev->rx_urb_size = 2048;
709 mfb = AX_RX_CTL_MFB_2048;
710 } else if (dev->hard_mtu < 4096) {
711 dev->rx_urb_size = 4096;
712 mfb = AX_RX_CTL_MFB_4096;
713 } else if (dev->hard_mtu < 8192) {
714 dev->rx_urb_size = 8192;
715 mfb = AX_RX_CTL_MFB_8192;
716 } else if (dev->hard_mtu < 16384) {
717 dev->rx_urb_size = 16384;
718 mfb = AX_RX_CTL_MFB_16384;
719 }
720
721 rxctl = asix_read_rx_ctl(dev);
722 asix_write_rx_ctl(dev, (rxctl & ~AX_RX_CTL_MFB_16384) | mfb);
723
724 medium = asix_read_medium_status(dev);
725 if (dev->net->mtu > 1500)
726 medium |= AX_MEDIUM_JFE;
727 else
728 medium &= ~AX_MEDIUM_JFE;
729 asix_write_medium_mode(dev, medium);
730
731 if (dev->rx_urb_size > old_rx_urb_size)
732 usbnet_unlink_rx_urbs(dev);
733}
734
735static int ax88178_change_mtu(struct net_device *net, int new_mtu)
736{
737 struct usbnet *dev = netdev_priv(net);
738 int ll_mtu = new_mtu + net->hard_header_len + 4;
739
Joe Perches60b86752010-02-17 10:30:23 +0000740 netdev_dbg(dev->net, "ax88178_change_mtu() new_mtu=%d\n", new_mtu);
David Hollis933a27d2006-07-29 10:12:50 -0400741
742 if (new_mtu <= 0 || ll_mtu > 16384)
743 return -EINVAL;
744
745 if ((ll_mtu % dev->maxpacket) == 0)
746 return -EDOM;
747
748 net->mtu = new_mtu;
749 dev->hard_mtu = net->mtu + net->hard_header_len;
750 ax88178_set_mfb(dev);
751
752 return 0;
753}
754
Stephen Hemminger17033382009-03-20 19:35:55 +0000755static const struct net_device_ops ax88178_netdev_ops = {
756 .ndo_open = usbnet_open,
757 .ndo_stop = usbnet_stop,
758 .ndo_start_xmit = usbnet_start_xmit,
759 .ndo_tx_timeout = usbnet_tx_timeout,
Jussi Kivilinna7f29a3b2010-03-09 12:24:38 +0000760 .ndo_set_mac_address = asix_set_mac_address,
Stephen Hemminger17033382009-03-20 19:35:55 +0000761 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +0000762 .ndo_set_rx_mode = asix_set_multicast,
Stephen Hemminger17033382009-03-20 19:35:55 +0000763 .ndo_do_ioctl = asix_ioctl,
764 .ndo_change_mtu = ax88178_change_mtu,
765};
766
David Hollis933a27d2006-07-29 10:12:50 -0400767static int ax88178_bind(struct usbnet *dev, struct usb_interface *intf)
768{
David Hollis933a27d2006-07-29 10:12:50 -0400769 int ret;
Al Viro51bf2972007-12-22 17:42:36 +0000770 u8 buf[ETH_ALEN];
David Hollis933a27d2006-07-29 10:12:50 -0400771
772 usbnet_get_endpoints(dev,intf);
773
David Hollis933a27d2006-07-29 10:12:50 -0400774 /* Get the MAC address */
Grant Grundler83e1b912011-10-04 09:55:18 +0000775 ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf);
776 if (ret < 0) {
Greg Kroah-Hartman49ae25b2012-09-19 09:46:14 +0000777 netdev_dbg(dev->net, "Failed to read MAC address: %d\n", ret);
Grant Grundler83e1b912011-10-04 09:55:18 +0000778 return ret;
David Hollis933a27d2006-07-29 10:12:50 -0400779 }
780 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
781
782 /* Initialize MII structure */
783 dev->mii.dev = dev->net;
784 dev->mii.mdio_read = asix_mdio_read;
785 dev->mii.mdio_write = asix_mdio_write;
786 dev->mii.phy_id_mask = 0x1f;
787 dev->mii.reg_num_mask = 0xff;
788 dev->mii.supports_gmii = 1;
David Hollis933a27d2006-07-29 10:12:50 -0400789 dev->mii.phy_id = asix_get_phy_addr(dev);
Stephen Hemminger17033382009-03-20 19:35:55 +0000790
791 dev->net->netdev_ops = &ax88178_netdev_ops;
David Hollis933a27d2006-07-29 10:12:50 -0400792 dev->net->ethtool_ops = &ax88178_ethtool_ops;
David Hollis933a27d2006-07-29 10:12:50 -0400793
Grant Grundlerb2d3ad292011-11-15 07:12:42 +0000794 /* Blink LEDS so users know driver saw dongle */
795 asix_sw_reset(dev, 0);
796 msleep(150);
David Hollis933a27d2006-07-29 10:12:50 -0400797
Grant Grundlerb2d3ad292011-11-15 07:12:42 +0000798 asix_sw_reset(dev, AX_SWRESET_PRL | AX_SWRESET_IPPD);
799 msleep(150);
David Hollis933a27d2006-07-29 10:12:50 -0400800
801 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
802 if (dev->driver_info->flags & FLAG_FRAMING_AX) {
803 /* hard_mtu is still the default - the device does not support
804 jumbo eth frames */
805 dev->rx_urb_size = 2048;
806 }
David Hollis933a27d2006-07-29 10:12:50 -0400807
Grant Grundler83e1b912011-10-04 09:55:18 +0000808 return 0;
David Hollis933a27d2006-07-29 10:12:50 -0400809}
810
David Brownell2e55cc72005-08-31 09:53:10 -0700811static const struct driver_info ax8817x_info = {
812 .description = "ASIX AX8817x USB 2.0 Ethernet",
David Hollis48b1be62006-03-28 20:15:42 -0500813 .bind = ax88172_bind,
814 .status = asix_status,
David Brownell2e55cc72005-08-31 09:53:10 -0700815 .link_reset = ax88172_link_reset,
816 .reset = ax88172_link_reset,
Ben Hutchings37e82732009-11-04 15:29:52 +0000817 .flags = FLAG_ETHER | FLAG_LINK_INTR,
David Brownell2e55cc72005-08-31 09:53:10 -0700818 .data = 0x00130103,
819};
820
821static const struct driver_info dlink_dub_e100_info = {
822 .description = "DLink DUB-E100 USB Ethernet",
David Hollis48b1be62006-03-28 20:15:42 -0500823 .bind = ax88172_bind,
824 .status = asix_status,
David Brownell2e55cc72005-08-31 09:53:10 -0700825 .link_reset = ax88172_link_reset,
826 .reset = ax88172_link_reset,
Ben Hutchings37e82732009-11-04 15:29:52 +0000827 .flags = FLAG_ETHER | FLAG_LINK_INTR,
David Brownell2e55cc72005-08-31 09:53:10 -0700828 .data = 0x009f9d9f,
829};
830
831static const struct driver_info netgear_fa120_info = {
832 .description = "Netgear FA-120 USB Ethernet",
David Hollis48b1be62006-03-28 20:15:42 -0500833 .bind = ax88172_bind,
834 .status = asix_status,
David Brownell2e55cc72005-08-31 09:53:10 -0700835 .link_reset = ax88172_link_reset,
836 .reset = ax88172_link_reset,
Ben Hutchings37e82732009-11-04 15:29:52 +0000837 .flags = FLAG_ETHER | FLAG_LINK_INTR,
David Brownell2e55cc72005-08-31 09:53:10 -0700838 .data = 0x00130103,
839};
840
841static const struct driver_info hawking_uf200_info = {
842 .description = "Hawking UF200 USB Ethernet",
David Hollis48b1be62006-03-28 20:15:42 -0500843 .bind = ax88172_bind,
844 .status = asix_status,
David Brownell2e55cc72005-08-31 09:53:10 -0700845 .link_reset = ax88172_link_reset,
846 .reset = ax88172_link_reset,
Ben Hutchings37e82732009-11-04 15:29:52 +0000847 .flags = FLAG_ETHER | FLAG_LINK_INTR,
David Brownell2e55cc72005-08-31 09:53:10 -0700848 .data = 0x001f1d1f,
849};
850
851static const struct driver_info ax88772_info = {
852 .description = "ASIX AX88772 USB 2.0 Ethernet",
853 .bind = ax88772_bind,
David Hollis48b1be62006-03-28 20:15:42 -0500854 .status = asix_status,
David Brownell2e55cc72005-08-31 09:53:10 -0700855 .link_reset = ax88772_link_reset,
Grant Grundler4ad14382011-10-04 09:55:16 +0000856 .reset = ax88772_reset,
Eric Dumazeta9e0aca2012-03-14 20:18:32 +0000857 .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR | FLAG_MULTI_PACKET,
David Hollis933a27d2006-07-29 10:12:50 -0400858 .rx_fixup = asix_rx_fixup,
859 .tx_fixup = asix_tx_fixup,
860};
861
862static const struct driver_info ax88178_info = {
863 .description = "ASIX AX88178 USB 2.0 Ethernet",
864 .bind = ax88178_bind,
865 .status = asix_status,
866 .link_reset = ax88178_link_reset,
Grant Grundler610d8852011-10-04 09:55:17 +0000867 .reset = ax88178_reset,
Ben Hutchings37e82732009-11-04 15:29:52 +0000868 .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR,
David Hollis933a27d2006-07-29 10:12:50 -0400869 .rx_fixup = asix_rx_fixup,
870 .tx_fixup = asix_tx_fixup,
David Brownell2e55cc72005-08-31 09:53:10 -0700871};
872
Christian Riesch16626b02012-07-13 05:26:31 +0000873extern const struct driver_info ax88172a_info;
874
David Brownell2e55cc72005-08-31 09:53:10 -0700875static const struct usb_device_id products [] = {
876{
877 // Linksys USB200M
878 USB_DEVICE (0x077b, 0x2226),
879 .driver_info = (unsigned long) &ax8817x_info,
880}, {
881 // Netgear FA120
882 USB_DEVICE (0x0846, 0x1040),
883 .driver_info = (unsigned long) &netgear_fa120_info,
884}, {
885 // DLink DUB-E100
886 USB_DEVICE (0x2001, 0x1a00),
887 .driver_info = (unsigned long) &dlink_dub_e100_info,
888}, {
889 // Intellinet, ST Lab USB Ethernet
890 USB_DEVICE (0x0b95, 0x1720),
891 .driver_info = (unsigned long) &ax8817x_info,
892}, {
893 // Hawking UF200, TrendNet TU2-ET100
894 USB_DEVICE (0x07b8, 0x420a),
895 .driver_info = (unsigned long) &hawking_uf200_info,
896}, {
David Hollis39c4b382007-02-20 08:02:24 -0500897 // Billionton Systems, USB2AR
898 USB_DEVICE (0x08dd, 0x90ff),
899 .driver_info = (unsigned long) &ax8817x_info,
David Brownell2e55cc72005-08-31 09:53:10 -0700900}, {
901 // ATEN UC210T
902 USB_DEVICE (0x0557, 0x2009),
903 .driver_info = (unsigned long) &ax8817x_info,
904}, {
905 // Buffalo LUA-U2-KTX
906 USB_DEVICE (0x0411, 0x003d),
907 .driver_info = (unsigned long) &ax8817x_info,
908}, {
Mattia Dongiliac7b77f2008-05-06 20:42:35 -0700909 // Buffalo LUA-U2-GT 10/100/1000
910 USB_DEVICE (0x0411, 0x006e),
911 .driver_info = (unsigned long) &ax88178_info,
912}, {
David Brownell2e55cc72005-08-31 09:53:10 -0700913 // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter"
914 USB_DEVICE (0x6189, 0x182d),
915 .driver_info = (unsigned long) &ax8817x_info,
916}, {
Joerg Neikes4e503912012-03-08 22:44:03 +0000917 // Sitecom LN-031 "USB 2.0 10/100/1000 Ethernet adapter"
918 USB_DEVICE (0x0df6, 0x0056),
919 .driver_info = (unsigned long) &ax88178_info,
920}, {
David Brownell2e55cc72005-08-31 09:53:10 -0700921 // corega FEther USB2-TX
922 USB_DEVICE (0x07aa, 0x0017),
923 .driver_info = (unsigned long) &ax8817x_info,
924}, {
925 // Surecom EP-1427X-2
926 USB_DEVICE (0x1189, 0x0893),
927 .driver_info = (unsigned long) &ax8817x_info,
928}, {
929 // goodway corp usb gwusb2e
930 USB_DEVICE (0x1631, 0x6200),
931 .driver_info = (unsigned long) &ax8817x_info,
932}, {
David Hollis39c4b382007-02-20 08:02:24 -0500933 // JVC MP-PRX1 Port Replicator
934 USB_DEVICE (0x04f1, 0x3008),
935 .driver_info = (unsigned long) &ax8817x_info,
936}, {
Quinlan Pfiffer66dc81e2012-09-28 19:58:44 +0000937 // Lenovo U2L100P 10/100
938 USB_DEVICE (0x17ef, 0x7203),
939 .driver_info = (unsigned long) &ax88772_info,
940}, {
Marek Vasut30885902011-07-20 05:57:04 +0000941 // ASIX AX88772B 10/100
942 USB_DEVICE (0x0b95, 0x772b),
943 .driver_info = (unsigned long) &ax88772_info,
944}, {
David Brownell2e55cc72005-08-31 09:53:10 -0700945 // ASIX AX88772 10/100
David Hollis39c4b382007-02-20 08:02:24 -0500946 USB_DEVICE (0x0b95, 0x7720),
947 .driver_info = (unsigned long) &ax88772_info,
David Hollis5e0f76c6b2005-12-19 13:58:38 -0500948}, {
Eduard Warkentin73274132006-05-18 01:13:17 -0700949 // ASIX AX88178 10/100/1000
950 USB_DEVICE (0x0b95, 0x1780),
David Hollis933a27d2006-07-29 10:12:50 -0400951 .driver_info = (unsigned long) &ax88178_info,
Eduard Warkentin73274132006-05-18 01:13:17 -0700952}, {
Arnaud Ebalardf4680d32010-12-15 12:16:30 +0000953 // Logitec LAN-GTJ/U2A
954 USB_DEVICE (0x0789, 0x0160),
955 .driver_info = (unsigned long) &ax88178_info,
956}, {
David Hollis5e0f76c6b2005-12-19 13:58:38 -0500957 // Linksys USB200M Rev 2
958 USB_DEVICE (0x13b1, 0x0018),
959 .driver_info = (unsigned long) &ax88772_info,
David Hollis5732ce82006-01-05 14:39:49 -0500960}, {
961 // 0Q0 cable ethernet
962 USB_DEVICE (0x1557, 0x7720),
963 .driver_info = (unsigned long) &ax88772_info,
David Hollis933a27d2006-07-29 10:12:50 -0400964}, {
965 // DLink DUB-E100 H/W Ver B1
966 USB_DEVICE (0x07d1, 0x3c05),
967 .driver_info = (unsigned long) &ax88772_info,
968}, {
David Hollisb923e7f2006-09-21 08:09:29 -0400969 // DLink DUB-E100 H/W Ver B1 Alternate
970 USB_DEVICE (0x2001, 0x3c05),
971 .driver_info = (unsigned long) &ax88772_info,
972}, {
Søren holmed3770a2012-09-17 21:50:57 +0000973 // DLink DUB-E100 H/W Ver C1
974 USB_DEVICE (0x2001, 0x1a02),
975 .driver_info = (unsigned long) &ax88772_info,
976}, {
David Hollis933a27d2006-07-29 10:12:50 -0400977 // Linksys USB1000
978 USB_DEVICE (0x1737, 0x0039),
979 .driver_info = (unsigned long) &ax88178_info,
YOSHIFUJI Hideaki / 吉藤英明b29cf312007-01-26 22:57:38 +0900980}, {
981 // IO-DATA ETG-US2
982 USB_DEVICE (0x04bb, 0x0930),
983 .driver_info = (unsigned long) &ax88178_info,
David Hollis2ed22bc2007-05-23 07:33:17 -0400984}, {
985 // Belkin F5D5055
986 USB_DEVICE(0x050d, 0x5055),
987 .driver_info = (unsigned long) &ax88178_info,
Aurelien Nephtali3d60efb52008-05-14 17:04:13 -0700988}, {
989 // Apple USB Ethernet Adapter
990 USB_DEVICE(0x05ac, 0x1402),
991 .driver_info = (unsigned long) &ax88772_info,
Jason Cooperccf95402008-11-11 13:02:53 -0500992}, {
993 // Cables-to-Go USB Ethernet Adapter
994 USB_DEVICE(0x0b95, 0x772a),
995 .driver_info = (unsigned long) &ax88772_info,
Greg Kroah-Hartmanfef7cc02009-02-24 23:52:24 -0800996}, {
997 // ABOCOM for pci
998 USB_DEVICE(0x14ea, 0xab11),
999 .driver_info = (unsigned long) &ax88178_info,
1000}, {
1001 // ASIX 88772a
1002 USB_DEVICE(0x0db0, 0xa877),
1003 .driver_info = (unsigned long) &ax88772_info,
Aurelien Jacobse8303a32011-12-16 10:49:22 +00001004}, {
1005 // Asus USB Ethernet Adapter
1006 USB_DEVICE (0x0b95, 0x7e2b),
1007 .driver_info = (unsigned long) &ax88772_info,
Christian Riesch16626b02012-07-13 05:26:31 +00001008}, {
1009 /* ASIX 88172a demo board */
1010 USB_DEVICE(0x0b95, 0x172a),
1011 .driver_info = (unsigned long) &ax88172a_info,
David Brownell2e55cc72005-08-31 09:53:10 -07001012},
1013 { }, // END
1014};
1015MODULE_DEVICE_TABLE(usb, products);
1016
1017static struct usb_driver asix_driver = {
Grant Grundler83e1b912011-10-04 09:55:18 +00001018 .name = DRIVER_NAME,
David Brownell2e55cc72005-08-31 09:53:10 -07001019 .id_table = products,
1020 .probe = usbnet_probe,
1021 .suspend = usbnet_suspend,
1022 .resume = usbnet_resume,
1023 .disconnect = usbnet_disconnect,
Oliver Neukuma11a6542007-08-03 13:52:19 +02001024 .supports_autosuspend = 1,
Sarah Sharpe1f12eb2012-04-23 10:08:51 -07001025 .disable_hub_initiated_lpm = 1,
David Brownell2e55cc72005-08-31 09:53:10 -07001026};
1027
Greg Kroah-Hartmand632eb12011-11-18 09:44:20 -08001028module_usb_driver(asix_driver);
David Brownell2e55cc72005-08-31 09:53:10 -07001029
1030MODULE_AUTHOR("David Hollis");
Grant Grundler4ad14382011-10-04 09:55:16 +00001031MODULE_VERSION(DRIVER_VERSION);
David Brownell2e55cc72005-08-31 09:53:10 -07001032MODULE_DESCRIPTION("ASIX AX8817X based USB 2.0 Ethernet Devices");
1033MODULE_LICENSE("GPL");
1034