blob: d1092421aaa7e7b69ba926d508155574f072ba61 [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
Jeff Kirsher9cb00072013-12-06 06:28:46 -080019 * along with this program; if not, see <http://www.gnu.org/licenses/>.
David Brownell2e55cc72005-08-31 09:53:10 -070020 */
21
Christian Riesch607740b2012-07-13 05:26:30 +000022#ifndef _ASIX_H
23#define _ASIX_H
24
David Brownell2e55cc72005-08-31 09:53:10 -070025// #define DEBUG // error path messages, extra info
26// #define VERBOSE // more; success messages
27
David Brownell2e55cc72005-08-31 09:53:10 -070028#include <linux/module.h>
29#include <linux/kmod.h>
David Brownell2e55cc72005-08-31 09:53:10 -070030#include <linux/netdevice.h>
31#include <linux/etherdevice.h>
32#include <linux/ethtool.h>
33#include <linux/workqueue.h>
34#include <linux/mii.h>
35#include <linux/usb.h>
36#include <linux/crc32.h>
Jussi Kivilinna3692e942008-01-26 00:51:45 +020037#include <linux/usb/usbnet.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090038#include <linux/slab.h>
Eric Dumazet9dae3102012-05-28 22:31:41 +000039#include <linux/if_vlan.h>
David Brownell2e55cc72005-08-31 09:53:10 -070040
allanf87ce5b2011-12-22 20:38:51 +000041#define DRIVER_VERSION "22-Dec-2011"
Grant Grundler83e1b912011-10-04 09:55:18 +000042#define DRIVER_NAME "asix"
David Hollis933a27d2006-07-29 10:12:50 -040043
David Brownell2e55cc72005-08-31 09:53:10 -070044/* ASIX AX8817X based USB 2.0 Ethernet Devices */
45
46#define AX_CMD_SET_SW_MII 0x06
47#define AX_CMD_READ_MII_REG 0x07
48#define AX_CMD_WRITE_MII_REG 0x08
Robert Fossd9fe64e2016-08-29 09:32:15 -040049#define AX_CMD_STATMNGSTS_REG 0x09
David Brownell2e55cc72005-08-31 09:53:10 -070050#define AX_CMD_SET_HW_MII 0x0a
51#define AX_CMD_READ_EEPROM 0x0b
52#define AX_CMD_WRITE_EEPROM 0x0c
53#define AX_CMD_WRITE_ENABLE 0x0d
54#define AX_CMD_WRITE_DISABLE 0x0e
David Hollis933a27d2006-07-29 10:12:50 -040055#define AX_CMD_READ_RX_CTL 0x0f
David Brownell2e55cc72005-08-31 09:53:10 -070056#define AX_CMD_WRITE_RX_CTL 0x10
57#define AX_CMD_READ_IPG012 0x11
58#define AX_CMD_WRITE_IPG0 0x12
59#define AX_CMD_WRITE_IPG1 0x13
David Hollis933a27d2006-07-29 10:12:50 -040060#define AX_CMD_READ_NODE_ID 0x13
Jussi Kivilinna7f29a3b2010-03-09 12:24:38 +000061#define AX_CMD_WRITE_NODE_ID 0x14
David Brownell2e55cc72005-08-31 09:53:10 -070062#define AX_CMD_WRITE_IPG2 0x14
63#define AX_CMD_WRITE_MULTI_FILTER 0x16
David Hollis933a27d2006-07-29 10:12:50 -040064#define AX88172_CMD_READ_NODE_ID 0x17
David Brownell2e55cc72005-08-31 09:53:10 -070065#define AX_CMD_READ_PHY_ID 0x19
66#define AX_CMD_READ_MEDIUM_STATUS 0x1a
67#define AX_CMD_WRITE_MEDIUM_MODE 0x1b
68#define AX_CMD_READ_MONITOR_MODE 0x1c
69#define AX_CMD_WRITE_MONITOR_MODE 0x1d
David Hollis933a27d2006-07-29 10:12:50 -040070#define AX_CMD_READ_GPIOS 0x1e
David Brownell2e55cc72005-08-31 09:53:10 -070071#define AX_CMD_WRITE_GPIOS 0x1f
72#define AX_CMD_SW_RESET 0x20
73#define AX_CMD_SW_PHY_STATUS 0x21
74#define AX_CMD_SW_PHY_SELECT 0x22
Robert Fossd9fe64e2016-08-29 09:32:15 -040075#define AX_QCTCTRL 0x2A
76
77#define AX_CHIPCODE_MASK 0x70
78#define AX_AX88772_CHIPCODE 0x00
79#define AX_AX88772A_CHIPCODE 0x10
80#define AX_AX88772B_CHIPCODE 0x20
81#define AX_HOST_EN 0x01
82
83#define AX_PHYSEL_PSEL 0x01
84#define AX_PHYSEL_SSMII 0
85#define AX_PHYSEL_SSEN 0x10
David Brownell2e55cc72005-08-31 09:53:10 -070086
Christian Riesch16626b02012-07-13 05:26:31 +000087#define AX_PHY_SELECT_MASK (BIT(3) | BIT(2))
88#define AX_PHY_SELECT_INTERNAL 0
89#define AX_PHY_SELECT_EXTERNAL BIT(2)
90
David Brownell2e55cc72005-08-31 09:53:10 -070091#define AX_MONITOR_MODE 0x01
92#define AX_MONITOR_LINK 0x02
93#define AX_MONITOR_MAGIC 0x04
94#define AX_MONITOR_HSFS 0x10
95
96/* AX88172 Medium Status Register values */
David Hollis933a27d2006-07-29 10:12:50 -040097#define AX88172_MEDIUM_FD 0x02
98#define AX88172_MEDIUM_TX 0x04
99#define AX88172_MEDIUM_FC 0x10
100#define AX88172_MEDIUM_DEFAULT \
101 ( AX88172_MEDIUM_FD | AX88172_MEDIUM_TX | AX88172_MEDIUM_FC )
David Brownell2e55cc72005-08-31 09:53:10 -0700102
103#define AX_MCAST_FILTER_SIZE 8
104#define AX_MAX_MCAST 64
105
David Brownell2e55cc72005-08-31 09:53:10 -0700106#define AX_SWRESET_CLEAR 0x00
107#define AX_SWRESET_RR 0x01
108#define AX_SWRESET_RT 0x02
109#define AX_SWRESET_PRTE 0x04
110#define AX_SWRESET_PRL 0x08
111#define AX_SWRESET_BZ 0x10
112#define AX_SWRESET_IPRL 0x20
113#define AX_SWRESET_IPPD 0x40
114
115#define AX88772_IPG0_DEFAULT 0x15
116#define AX88772_IPG1_DEFAULT 0x0c
117#define AX88772_IPG2_DEFAULT 0x12
118
David Hollis933a27d2006-07-29 10:12:50 -0400119/* AX88772 & AX88178 Medium Mode Register */
120#define AX_MEDIUM_PF 0x0080
121#define AX_MEDIUM_JFE 0x0040
122#define AX_MEDIUM_TFC 0x0020
123#define AX_MEDIUM_RFC 0x0010
124#define AX_MEDIUM_ENCK 0x0008
125#define AX_MEDIUM_AC 0x0004
126#define AX_MEDIUM_FD 0x0002
127#define AX_MEDIUM_GM 0x0001
128#define AX_MEDIUM_SM 0x1000
129#define AX_MEDIUM_SBP 0x0800
130#define AX_MEDIUM_PS 0x0200
131#define AX_MEDIUM_RE 0x0100
David Brownell2e55cc72005-08-31 09:53:10 -0700132
David Hollis933a27d2006-07-29 10:12:50 -0400133#define AX88178_MEDIUM_DEFAULT \
134 (AX_MEDIUM_PS | AX_MEDIUM_FD | AX_MEDIUM_AC | \
135 AX_MEDIUM_RFC | AX_MEDIUM_TFC | AX_MEDIUM_JFE | \
Grant Grundler83e1b912011-10-04 09:55:18 +0000136 AX_MEDIUM_RE)
David Hollis933a27d2006-07-29 10:12:50 -0400137
138#define AX88772_MEDIUM_DEFAULT \
139 (AX_MEDIUM_FD | AX_MEDIUM_RFC | \
140 AX_MEDIUM_TFC | AX_MEDIUM_PS | \
Grant Grundler83e1b912011-10-04 09:55:18 +0000141 AX_MEDIUM_AC | AX_MEDIUM_RE)
David Hollis933a27d2006-07-29 10:12:50 -0400142
143/* AX88772 & AX88178 RX_CTL values */
Grant Grundler83e1b912011-10-04 09:55:18 +0000144#define AX_RX_CTL_SO 0x0080
145#define AX_RX_CTL_AP 0x0020
146#define AX_RX_CTL_AM 0x0010
147#define AX_RX_CTL_AB 0x0008
148#define AX_RX_CTL_SEP 0x0004
149#define AX_RX_CTL_AMALL 0x0002
150#define AX_RX_CTL_PRO 0x0001
151#define AX_RX_CTL_MFB_2048 0x0000
152#define AX_RX_CTL_MFB_4096 0x0100
153#define AX_RX_CTL_MFB_8192 0x0200
154#define AX_RX_CTL_MFB_16384 0x0300
David Hollis933a27d2006-07-29 10:12:50 -0400155
Grant Grundler83e1b912011-10-04 09:55:18 +0000156#define AX_DEFAULT_RX_CTL (AX_RX_CTL_SO | AX_RX_CTL_AB)
David Hollis933a27d2006-07-29 10:12:50 -0400157
158/* GPIO 0 .. 2 toggles */
159#define AX_GPIO_GPO0EN 0x01 /* GPIO0 Output enable */
160#define AX_GPIO_GPO_0 0x02 /* GPIO0 Output value */
161#define AX_GPIO_GPO1EN 0x04 /* GPIO1 Output enable */
162#define AX_GPIO_GPO_1 0x08 /* GPIO1 Output value */
163#define AX_GPIO_GPO2EN 0x10 /* GPIO2 Output enable */
164#define AX_GPIO_GPO_2 0x20 /* GPIO2 Output value */
165#define AX_GPIO_RESERVED 0x40 /* Reserved */
166#define AX_GPIO_RSE 0x80 /* Reload serial EEPROM */
167
168#define AX_EEPROM_MAGIC 0xdeadbeef
Christian Rieschceb02c92012-07-19 00:23:06 +0000169#define AX_EEPROM_LEN 0x200
David Hollis933a27d2006-07-29 10:12:50 -0400170
David Brownell2e55cc72005-08-31 09:53:10 -0700171/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
David Hollis48b1be62006-03-28 20:15:42 -0500172struct asix_data {
David Brownell2e55cc72005-08-31 09:53:10 -0700173 u8 multi_filter[AX_MCAST_FILTER_SIZE];
Jussi Kivilinna7f29a3b2010-03-09 12:24:38 +0000174 u8 mac_addr[ETH_ALEN];
David Hollis933a27d2006-07-29 10:12:50 -0400175 u8 phymode;
176 u8 ledmode;
Christian Rieschceb02c92012-07-19 00:23:06 +0000177 u8 res;
David Brownell2e55cc72005-08-31 09:53:10 -0700178};
179
Lucas Stach8b5b6f52013-01-16 04:24:07 +0000180struct asix_rx_fixup_info {
181 struct sk_buff *ax_skb;
182 u32 header;
Dean Jenkins7b0378f2015-10-02 14:29:04 +0100183 u16 remaining;
Lucas Stach8b5b6f52013-01-16 04:24:07 +0000184 bool split_head;
185};
186
187struct asix_common_private {
Robert Fossd9fe64e2016-08-29 09:32:15 -0400188 void (*resume)(struct usbnet *dev);
189 void (*suspend)(struct usbnet *dev);
190 u16 presvd_phy_advertise;
191 u16 presvd_phy_bmcr;
Lucas Stach8b5b6f52013-01-16 04:24:07 +0000192 struct asix_rx_fixup_info rx_fixup_info;
193};
194
Mark Brown55d10a12013-08-09 18:31:22 +0100195extern const struct driver_info ax88172a_info;
196
Lucas Stach5620df62013-01-16 04:24:06 +0000197/* ASIX specific flags */
198#define FLAG_EEPROM_MAC (1UL << 0) /* init device MAC from eeprom */
199
Christian Riesch607740b2012-07-13 05:26:30 +0000200int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
Robert Fossd9fe64e2016-08-29 09:32:15 -0400201 u16 size, void *data, int in_pm);
David Brownell2e55cc72005-08-31 09:53:10 -0700202
Christian Riesch607740b2012-07-13 05:26:30 +0000203int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
Robert Fossd9fe64e2016-08-29 09:32:15 -0400204 u16 size, void *data, int in_pm);
Al Viro51bf2972007-12-22 17:42:36 +0000205
Christian Riesch607740b2012-07-13 05:26:30 +0000206void asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value,
207 u16 index, u16 size, void *data);
Al Viro51bf2972007-12-22 17:42:36 +0000208
Lucas Stach8b5b6f52013-01-16 04:24:07 +0000209int asix_rx_fixup_internal(struct usbnet *dev, struct sk_buff *skb,
210 struct asix_rx_fixup_info *rx);
211int asix_rx_fixup_common(struct usbnet *dev, struct sk_buff *skb);
Al Viro51bf2972007-12-22 17:42:36 +0000212
Christian Riesch607740b2012-07-13 05:26:30 +0000213struct sk_buff *asix_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
214 gfp_t flags);
Al Viro51bf2972007-12-22 17:42:36 +0000215
Robert Fossd9fe64e2016-08-29 09:32:15 -0400216int asix_set_sw_mii(struct usbnet *dev, int in_pm);
217int asix_set_hw_mii(struct usbnet *dev, int in_pm);
David Brownell2e55cc72005-08-31 09:53:10 -0700218
Christian Riesch16626b02012-07-13 05:26:31 +0000219int asix_read_phy_addr(struct usbnet *dev, int internal);
Christian Riesch607740b2012-07-13 05:26:30 +0000220int asix_get_phy_addr(struct usbnet *dev);
Al Viro51bf2972007-12-22 17:42:36 +0000221
Robert Fossd9fe64e2016-08-29 09:32:15 -0400222int asix_sw_reset(struct usbnet *dev, u8 flags, int in_pm);
Al Viro51bf2972007-12-22 17:42:36 +0000223
Robert Fossd9fe64e2016-08-29 09:32:15 -0400224u16 asix_read_rx_ctl(struct usbnet *dev, int in_pm);
225int asix_write_rx_ctl(struct usbnet *dev, u16 mode, int in_pm);
Al Viro51bf2972007-12-22 17:42:36 +0000226
Robert Fossd9fe64e2016-08-29 09:32:15 -0400227u16 asix_read_medium_status(struct usbnet *dev, int in_pm);
228int asix_write_medium_mode(struct usbnet *dev, u16 mode, int in_pm);
Al Viro51bf2972007-12-22 17:42:36 +0000229
Robert Fossd9fe64e2016-08-29 09:32:15 -0400230int asix_write_gpio(struct usbnet *dev, u16 value, int sleep, int in_pm);
David Brownell2e55cc72005-08-31 09:53:10 -0700231
Christian Riesch607740b2012-07-13 05:26:30 +0000232void asix_set_multicast(struct net_device *net);
David Brownell2e55cc72005-08-31 09:53:10 -0700233
Christian Riesch607740b2012-07-13 05:26:30 +0000234int asix_mdio_read(struct net_device *netdev, int phy_id, int loc);
235void asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val);
David Brownell2e55cc72005-08-31 09:53:10 -0700236
Robert Fossd9fe64e2016-08-29 09:32:15 -0400237int asix_mdio_read_nopm(struct net_device *netdev, int phy_id, int loc);
238void asix_mdio_write_nopm(struct net_device *netdev, int phy_id, int loc,
239 int val);
240
Christian Riesch607740b2012-07-13 05:26:30 +0000241void asix_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo);
242int asix_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo);
David Brownell2e55cc72005-08-31 09:53:10 -0700243
Christian Riesch607740b2012-07-13 05:26:30 +0000244int asix_get_eeprom_len(struct net_device *net);
245int asix_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
246 u8 *data);
Christian Rieschcb7b24c2012-07-19 00:23:07 +0000247int asix_set_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom,
248 u8 *data);
David Hollis48b1be62006-03-28 20:15:42 -0500249
Christian Riesch607740b2012-07-13 05:26:30 +0000250void asix_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info);
Grant Grundler83e1b912011-10-04 09:55:18 +0000251
Christian Riesch607740b2012-07-13 05:26:30 +0000252int asix_set_mac_address(struct net_device *net, void *p);
David Hollis933a27d2006-07-29 10:12:50 -0400253
Christian Riesch607740b2012-07-13 05:26:30 +0000254#endif /* _ASIX_H */