1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ASIX AX88179/178A USB 3.0/2.0 to Gigabit Ethernet Devices
5 * Copyright (C) 2011-2013 ASIX
8 #include <linux/module.h>
9 #include <linux/etherdevice.h>
10 #include <linux/mii.h>
11 #include <linux/usb.h>
12 #include <linux/crc32.h>
13 #include <linux/usb/usbnet.h>
14 #include <uapi/linux/mdio.h>
15 #include <linux/mdio.h>
17 #define AX88179_PHY_ID 0x03
18 #define AX_EEPROM_LEN 0x100
19 #define AX88179_EEPROM_MAGIC 0x17900b95
20 #define AX_MCAST_FLTSIZE 8
21 #define AX_MAX_MCAST 64
22 #define AX_INT_PPLS_LINK ((u32)BIT(16))
23 #define AX_RXHDR_L4_TYPE_MASK 0x1c
24 #define AX_RXHDR_L4_TYPE_UDP 4
25 #define AX_RXHDR_L4_TYPE_TCP 16
26 #define AX_RXHDR_L3CSUM_ERR 2
27 #define AX_RXHDR_L4CSUM_ERR 1
28 #define AX_RXHDR_CRC_ERR ((u32)BIT(29))
29 #define AX_RXHDR_DROP_ERR ((u32)BIT(31))
30 #define AX_ACCESS_MAC 0x01
31 #define AX_ACCESS_PHY 0x02
32 #define AX_ACCESS_EEPROM 0x04
33 #define AX_ACCESS_EFUS 0x05
34 #define AX_PAUSE_WATERLVL_HIGH 0x54
35 #define AX_PAUSE_WATERLVL_LOW 0x55
37 #define PHYSICAL_LINK_STATUS 0x02
38 #define AX_USB_SS 0x04
39 #define AX_USB_HS 0x02
41 #define GENERAL_STATUS 0x03
42 /* Check AX88179 version. UA1:Bit2 = 0, UA2:Bit2 = 1 */
45 #define AX_SROM_ADDR 0x07
46 #define AX_SROM_CMD 0x0a
50 #define AX_SROM_DATA_LOW 0x08
51 #define AX_SROM_DATA_HIGH 0x09
53 #define AX_RX_CTL 0x0b
54 #define AX_RX_CTL_DROPCRCERR 0x0100
55 #define AX_RX_CTL_IPE 0x0200
56 #define AX_RX_CTL_START 0x0080
57 #define AX_RX_CTL_AP 0x0020
58 #define AX_RX_CTL_AM 0x0010
59 #define AX_RX_CTL_AB 0x0008
60 #define AX_RX_CTL_AMALL 0x0002
61 #define AX_RX_CTL_PRO 0x0001
62 #define AX_RX_CTL_STOP 0x0000
64 #define AX_NODE_ID 0x10
65 #define AX_MULFLTARY 0x16
67 #define AX_MEDIUM_STATUS_MODE 0x22
68 #define AX_MEDIUM_GIGAMODE 0x01
69 #define AX_MEDIUM_FULL_DUPLEX 0x02
70 #define AX_MEDIUM_EN_125MHZ 0x08
71 #define AX_MEDIUM_RXFLOW_CTRLEN 0x10
72 #define AX_MEDIUM_TXFLOW_CTRLEN 0x20
73 #define AX_MEDIUM_RECEIVE_EN 0x100
74 #define AX_MEDIUM_PS 0x200
75 #define AX_MEDIUM_JUMBO_EN 0x8040
77 #define AX_MONITOR_MOD 0x24
78 #define AX_MONITOR_MODE_RWLC 0x02
79 #define AX_MONITOR_MODE_RWMP 0x04
80 #define AX_MONITOR_MODE_PMEPOL 0x20
81 #define AX_MONITOR_MODE_PMETYPE 0x40
83 #define AX_GPIO_CTRL 0x25
84 #define AX_GPIO_CTRL_GPIO3EN 0x80
85 #define AX_GPIO_CTRL_GPIO2EN 0x40
86 #define AX_GPIO_CTRL_GPIO1EN 0x20
88 #define AX_PHYPWR_RSTCTL 0x26
89 #define AX_PHYPWR_RSTCTL_BZ 0x0010
90 #define AX_PHYPWR_RSTCTL_IPRL 0x0020
91 #define AX_PHYPWR_RSTCTL_AT 0x1000
93 #define AX_RX_BULKIN_QCTRL 0x2e
94 #define AX_CLK_SELECT 0x33
95 #define AX_CLK_SELECT_BCS 0x01
96 #define AX_CLK_SELECT_ACS 0x02
97 #define AX_CLK_SELECT_ULR 0x08
99 #define AX_RXCOE_CTL 0x34
100 #define AX_RXCOE_IP 0x01
101 #define AX_RXCOE_TCP 0x02
102 #define AX_RXCOE_UDP 0x04
103 #define AX_RXCOE_TCPV6 0x20
104 #define AX_RXCOE_UDPV6 0x40
106 #define AX_TXCOE_CTL 0x35
107 #define AX_TXCOE_IP 0x01
108 #define AX_TXCOE_TCP 0x02
109 #define AX_TXCOE_UDP 0x04
110 #define AX_TXCOE_TCPV6 0x20
111 #define AX_TXCOE_UDPV6 0x40
113 #define AX_LEDCTRL 0x73
115 #define GMII_PHY_PHYSR 0x11
116 #define GMII_PHY_PHYSR_SMASK 0xc000
117 #define GMII_PHY_PHYSR_GIGA 0x8000
118 #define GMII_PHY_PHYSR_100 0x4000
119 #define GMII_PHY_PHYSR_FULL 0x2000
120 #define GMII_PHY_PHYSR_LINK 0x400
122 #define GMII_LED_ACT 0x1a
123 #define GMII_LED_ACTIVE_MASK 0xff8f
124 #define GMII_LED0_ACTIVE BIT(4)
125 #define GMII_LED1_ACTIVE BIT(5)
126 #define GMII_LED2_ACTIVE BIT(6)
128 #define GMII_LED_LINK 0x1c
129 #define GMII_LED_LINK_MASK 0xf888
130 #define GMII_LED0_LINK_10 BIT(0)
131 #define GMII_LED0_LINK_100 BIT(1)
132 #define GMII_LED0_LINK_1000 BIT(2)
133 #define GMII_LED1_LINK_10 BIT(4)
134 #define GMII_LED1_LINK_100 BIT(5)
135 #define GMII_LED1_LINK_1000 BIT(6)
136 #define GMII_LED2_LINK_10 BIT(8)
137 #define GMII_LED2_LINK_100 BIT(9)
138 #define GMII_LED2_LINK_1000 BIT(10)
139 #define LED0_ACTIVE BIT(0)
140 #define LED0_LINK_10 BIT(1)
141 #define LED0_LINK_100 BIT(2)
142 #define LED0_LINK_1000 BIT(3)
143 #define LED0_FD BIT(4)
144 #define LED0_USB3_MASK 0x001f
145 #define LED1_ACTIVE BIT(5)
146 #define LED1_LINK_10 BIT(6)
147 #define LED1_LINK_100 BIT(7)
148 #define LED1_LINK_1000 BIT(8)
149 #define LED1_FD BIT(9)
150 #define LED1_USB3_MASK 0x03e0
151 #define LED2_ACTIVE BIT(10)
152 #define LED2_LINK_1000 BIT(13)
153 #define LED2_LINK_100 BIT(12)
154 #define LED2_LINK_10 BIT(11)
155 #define LED2_FD BIT(14)
156 #define LED_VALID BIT(15)
157 #define LED2_USB3_MASK 0x7c00
159 #define GMII_PHYPAGE 0x1e
160 #define GMII_PHY_PAGE_SELECT 0x1f
161 #define GMII_PHY_PGSEL_EXT 0x0007
162 #define GMII_PHY_PGSEL_PAGE0 0x0000
163 #define GMII_PHY_PGSEL_PAGE3 0x0003
164 #define GMII_PHY_PGSEL_PAGE5 0x0005
166 struct ax88179_data
{
173 struct ax88179_int_data
{
178 static const struct {
179 unsigned char ctrl
, timer_l
, timer_h
, size
, ifg
;
180 } AX88179_BULKIN_SIZE
[] = {
181 {7, 0x4f, 0, 0x12, 0xff},
182 {7, 0x20, 3, 0x16, 0xff},
183 {7, 0xae, 7, 0x18, 0xff},
184 {7, 0xcc, 0x4c, 0x18, 8},
187 static int __ax88179_read_cmd(struct usbnet
*dev
, u8 cmd
, u16 value
, u16 index
,
188 u16 size
, void *data
, int in_pm
)
191 int (*fn
)(struct usbnet
*, u8
, u8
, u16
, u16
, void *, u16
);
196 fn
= usbnet_read_cmd
;
198 fn
= usbnet_read_cmd_nopm
;
200 ret
= fn(dev
, cmd
, USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
201 value
, index
, data
, size
);
203 if (unlikely(ret
< 0))
204 netdev_warn(dev
->net
, "Failed to read reg index 0x%04x: %d\n",
210 static int __ax88179_write_cmd(struct usbnet
*dev
, u8 cmd
, u16 value
, u16 index
,
211 u16 size
, void *data
, int in_pm
)
214 int (*fn
)(struct usbnet
*, u8
, u8
, u16
, u16
, const void *, u16
);
219 fn
= usbnet_write_cmd
;
221 fn
= usbnet_write_cmd_nopm
;
223 ret
= fn(dev
, cmd
, USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
224 value
, index
, data
, size
);
226 if (unlikely(ret
< 0))
227 netdev_warn(dev
->net
, "Failed to write reg index 0x%04x: %d\n",
233 static void ax88179_write_cmd_async(struct usbnet
*dev
, u8 cmd
, u16 value
,
234 u16 index
, u16 size
, void *data
)
239 buf
= *((u16
*)data
);
241 usbnet_write_cmd_async(dev
, cmd
, USB_DIR_OUT
| USB_TYPE_VENDOR
|
242 USB_RECIP_DEVICE
, value
, index
, &buf
,
245 usbnet_write_cmd_async(dev
, cmd
, USB_DIR_OUT
| USB_TYPE_VENDOR
|
246 USB_RECIP_DEVICE
, value
, index
, data
,
251 static int ax88179_read_cmd_nopm(struct usbnet
*dev
, u8 cmd
, u16 value
,
252 u16 index
, u16 size
, void *data
)
258 ret
= __ax88179_read_cmd(dev
, cmd
, value
, index
, size
, &buf
, 1);
260 *((u16
*)data
) = buf
;
261 } else if (4 == size
) {
263 ret
= __ax88179_read_cmd(dev
, cmd
, value
, index
, size
, &buf
, 1);
265 *((u32
*)data
) = buf
;
267 ret
= __ax88179_read_cmd(dev
, cmd
, value
, index
, size
, data
, 1);
273 static int ax88179_write_cmd_nopm(struct usbnet
*dev
, u8 cmd
, u16 value
,
274 u16 index
, u16 size
, void *data
)
280 buf
= *((u16
*)data
);
282 ret
= __ax88179_write_cmd(dev
, cmd
, value
, index
,
285 ret
= __ax88179_write_cmd(dev
, cmd
, value
, index
,
292 static int ax88179_read_cmd(struct usbnet
*dev
, u8 cmd
, u16 value
, u16 index
,
293 u16 size
, void *data
)
299 ret
= __ax88179_read_cmd(dev
, cmd
, value
, index
, size
, &buf
, 0);
301 *((u16
*)data
) = buf
;
302 } else if (4 == size
) {
304 ret
= __ax88179_read_cmd(dev
, cmd
, value
, index
, size
, &buf
, 0);
306 *((u32
*)data
) = buf
;
308 ret
= __ax88179_read_cmd(dev
, cmd
, value
, index
, size
, data
, 0);
314 static int ax88179_write_cmd(struct usbnet
*dev
, u8 cmd
, u16 value
, u16 index
,
315 u16 size
, void *data
)
321 buf
= *((u16
*)data
);
323 ret
= __ax88179_write_cmd(dev
, cmd
, value
, index
,
326 ret
= __ax88179_write_cmd(dev
, cmd
, value
, index
,
333 static void ax88179_status(struct usbnet
*dev
, struct urb
*urb
)
335 struct ax88179_int_data
*event
;
338 if (urb
->actual_length
< 8)
341 event
= urb
->transfer_buffer
;
342 le32_to_cpus((void *)&event
->intdata1
);
344 link
= (((__force u32
)event
->intdata1
) & AX_INT_PPLS_LINK
) >> 16;
346 if (netif_carrier_ok(dev
->net
) != link
) {
347 usbnet_link_change(dev
, link
, 1);
348 netdev_info(dev
->net
, "ax88179 - Link status is: %d\n", link
);
352 static int ax88179_mdio_read(struct net_device
*netdev
, int phy_id
, int loc
)
354 struct usbnet
*dev
= netdev_priv(netdev
);
357 ax88179_read_cmd(dev
, AX_ACCESS_PHY
, phy_id
, (__u16
)loc
, 2, &res
);
361 static void ax88179_mdio_write(struct net_device
*netdev
, int phy_id
, int loc
,
364 struct usbnet
*dev
= netdev_priv(netdev
);
367 ax88179_write_cmd(dev
, AX_ACCESS_PHY
, phy_id
, (__u16
)loc
, 2, &res
);
370 static inline int ax88179_phy_mmd_indirect(struct usbnet
*dev
, u16 prtad
,
377 ret
= ax88179_write_cmd(dev
, AX_ACCESS_PHY
, AX88179_PHY_ID
,
378 MII_MMD_CTRL
, 2, &tmp16
);
381 ret
= ax88179_write_cmd(dev
, AX_ACCESS_PHY
, AX88179_PHY_ID
,
382 MII_MMD_DATA
, 2, &tmp16
);
384 tmp16
= devad
| MII_MMD_CTRL_NOINCR
;
385 ret
= ax88179_write_cmd(dev
, AX_ACCESS_PHY
, AX88179_PHY_ID
,
386 MII_MMD_CTRL
, 2, &tmp16
);
392 ax88179_phy_read_mmd_indirect(struct usbnet
*dev
, u16 prtad
, u16 devad
)
397 ax88179_phy_mmd_indirect(dev
, prtad
, devad
);
399 ret
= ax88179_read_cmd(dev
, AX_ACCESS_PHY
, AX88179_PHY_ID
,
400 MII_MMD_DATA
, 2, &tmp16
);
408 ax88179_phy_write_mmd_indirect(struct usbnet
*dev
, u16 prtad
, u16 devad
,
413 ax88179_phy_mmd_indirect(dev
, prtad
, devad
);
415 ret
= ax88179_write_cmd(dev
, AX_ACCESS_PHY
, AX88179_PHY_ID
,
416 MII_MMD_DATA
, 2, &data
);
424 static int ax88179_suspend(struct usb_interface
*intf
, pm_message_t message
)
426 struct usbnet
*dev
= usb_get_intfdata(intf
);
430 usbnet_suspend(intf
, message
);
432 /* Disable RX path */
433 ax88179_read_cmd_nopm(dev
, AX_ACCESS_MAC
, AX_MEDIUM_STATUS_MODE
,
435 tmp16
&= ~AX_MEDIUM_RECEIVE_EN
;
436 ax88179_write_cmd_nopm(dev
, AX_ACCESS_MAC
, AX_MEDIUM_STATUS_MODE
,
439 /* Force bulk-in zero length */
440 ax88179_read_cmd_nopm(dev
, AX_ACCESS_MAC
, AX_PHYPWR_RSTCTL
,
443 tmp16
|= AX_PHYPWR_RSTCTL_BZ
| AX_PHYPWR_RSTCTL_IPRL
;
444 ax88179_write_cmd_nopm(dev
, AX_ACCESS_MAC
, AX_PHYPWR_RSTCTL
,
449 ax88179_write_cmd_nopm(dev
, AX_ACCESS_MAC
, AX_CLK_SELECT
, 1, 1, &tmp8
);
451 /* Configure RX control register => stop operation */
452 tmp16
= AX_RX_CTL_STOP
;
453 ax88179_write_cmd_nopm(dev
, AX_ACCESS_MAC
, AX_RX_CTL
, 2, 2, &tmp16
);
458 /* This function is used to enable the autodetach function. */
459 /* This function is determined by offset 0x43 of EEPROM */
460 static int ax88179_auto_detach(struct usbnet
*dev
, int in_pm
)
464 int (*fnr
)(struct usbnet
*, u8
, u16
, u16
, u16
, void *);
465 int (*fnw
)(struct usbnet
*, u8
, u16
, u16
, u16
, void *);
468 fnr
= ax88179_read_cmd
;
469 fnw
= ax88179_write_cmd
;
471 fnr
= ax88179_read_cmd_nopm
;
472 fnw
= ax88179_write_cmd_nopm
;
475 if (fnr(dev
, AX_ACCESS_EEPROM
, 0x43, 1, 2, &tmp16
) < 0)
478 if ((tmp16
== 0xFFFF) || (!(tmp16
& 0x0100)))
481 /* Enable Auto Detach bit */
483 fnr(dev
, AX_ACCESS_MAC
, AX_CLK_SELECT
, 1, 1, &tmp8
);
484 tmp8
|= AX_CLK_SELECT_ULR
;
485 fnw(dev
, AX_ACCESS_MAC
, AX_CLK_SELECT
, 1, 1, &tmp8
);
487 fnr(dev
, AX_ACCESS_MAC
, AX_PHYPWR_RSTCTL
, 2, 2, &tmp16
);
488 tmp16
|= AX_PHYPWR_RSTCTL_AT
;
489 fnw(dev
, AX_ACCESS_MAC
, AX_PHYPWR_RSTCTL
, 2, 2, &tmp16
);
494 static int ax88179_resume(struct usb_interface
*intf
)
496 struct usbnet
*dev
= usb_get_intfdata(intf
);
500 usbnet_link_change(dev
, 0, 0);
502 /* Power up ethernet PHY */
504 ax88179_write_cmd_nopm(dev
, AX_ACCESS_MAC
, AX_PHYPWR_RSTCTL
,
508 tmp16
= AX_PHYPWR_RSTCTL_IPRL
;
509 ax88179_write_cmd_nopm(dev
, AX_ACCESS_MAC
, AX_PHYPWR_RSTCTL
,
513 /* Ethernet PHY Auto Detach*/
514 ax88179_auto_detach(dev
, 1);
517 ax88179_read_cmd_nopm(dev
, AX_ACCESS_MAC
, AX_CLK_SELECT
, 1, 1, &tmp8
);
518 tmp8
|= AX_CLK_SELECT_ACS
| AX_CLK_SELECT_BCS
;
519 ax88179_write_cmd_nopm(dev
, AX_ACCESS_MAC
, AX_CLK_SELECT
, 1, 1, &tmp8
);
522 /* Configure RX control register => start operation */
523 tmp16
= AX_RX_CTL_DROPCRCERR
| AX_RX_CTL_IPE
| AX_RX_CTL_START
|
524 AX_RX_CTL_AP
| AX_RX_CTL_AMALL
| AX_RX_CTL_AB
;
525 ax88179_write_cmd_nopm(dev
, AX_ACCESS_MAC
, AX_RX_CTL
, 2, 2, &tmp16
);
527 return usbnet_resume(intf
);
531 ax88179_get_wol(struct net_device
*net
, struct ethtool_wolinfo
*wolinfo
)
533 struct usbnet
*dev
= netdev_priv(net
);
536 if (ax88179_read_cmd(dev
, AX_ACCESS_MAC
, AX_MONITOR_MOD
,
538 wolinfo
->supported
= 0;
539 wolinfo
->wolopts
= 0;
543 wolinfo
->supported
= WAKE_PHY
| WAKE_MAGIC
;
544 wolinfo
->wolopts
= 0;
545 if (opt
& AX_MONITOR_MODE_RWLC
)
546 wolinfo
->wolopts
|= WAKE_PHY
;
547 if (opt
& AX_MONITOR_MODE_RWMP
)
548 wolinfo
->wolopts
|= WAKE_MAGIC
;
552 ax88179_set_wol(struct net_device
*net
, struct ethtool_wolinfo
*wolinfo
)
554 struct usbnet
*dev
= netdev_priv(net
);
557 if (wolinfo
->wolopts
& ~(WAKE_PHY
| WAKE_MAGIC
))
560 if (wolinfo
->wolopts
& WAKE_PHY
)
561 opt
|= AX_MONITOR_MODE_RWLC
;
562 if (wolinfo
->wolopts
& WAKE_MAGIC
)
563 opt
|= AX_MONITOR_MODE_RWMP
;
565 if (ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_MONITOR_MOD
,
572 static int ax88179_get_eeprom_len(struct net_device
*net
)
574 return AX_EEPROM_LEN
;
578 ax88179_get_eeprom(struct net_device
*net
, struct ethtool_eeprom
*eeprom
,
581 struct usbnet
*dev
= netdev_priv(net
);
583 int first_word
, last_word
;
586 if (eeprom
->len
== 0)
589 eeprom
->magic
= AX88179_EEPROM_MAGIC
;
591 first_word
= eeprom
->offset
>> 1;
592 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
593 eeprom_buff
= kmalloc_array(last_word
- first_word
+ 1, sizeof(u16
),
598 /* ax88179/178A returns 2 bytes from eeprom on read */
599 for (i
= first_word
; i
<= last_word
; i
++) {
600 ret
= __ax88179_read_cmd(dev
, AX_ACCESS_EEPROM
, i
, 1, 2,
601 &eeprom_buff
[i
- first_word
],
609 memcpy(data
, (u8
*)eeprom_buff
+ (eeprom
->offset
& 1), eeprom
->len
);
614 static int ax88179_get_link_ksettings(struct net_device
*net
,
615 struct ethtool_link_ksettings
*cmd
)
617 struct usbnet
*dev
= netdev_priv(net
);
619 mii_ethtool_get_link_ksettings(&dev
->mii
, cmd
);
624 static int ax88179_set_link_ksettings(struct net_device
*net
,
625 const struct ethtool_link_ksettings
*cmd
)
627 struct usbnet
*dev
= netdev_priv(net
);
628 return mii_ethtool_set_link_ksettings(&dev
->mii
, cmd
);
632 ax88179_ethtool_get_eee(struct usbnet
*dev
, struct ethtool_eee
*data
)
636 /* Get Supported EEE */
637 val
= ax88179_phy_read_mmd_indirect(dev
, MDIO_PCS_EEE_ABLE
,
641 data
->supported
= mmd_eee_cap_to_ethtool_sup_t(val
);
643 /* Get advertisement EEE */
644 val
= ax88179_phy_read_mmd_indirect(dev
, MDIO_AN_EEE_ADV
,
648 data
->advertised
= mmd_eee_adv_to_ethtool_adv_t(val
);
650 /* Get LP advertisement EEE */
651 val
= ax88179_phy_read_mmd_indirect(dev
, MDIO_AN_EEE_LPABLE
,
655 data
->lp_advertised
= mmd_eee_adv_to_ethtool_adv_t(val
);
661 ax88179_ethtool_set_eee(struct usbnet
*dev
, struct ethtool_eee
*data
)
663 u16 tmp16
= ethtool_adv_to_mmd_eee_adv_t(data
->advertised
);
665 return ax88179_phy_write_mmd_indirect(dev
, MDIO_AN_EEE_ADV
,
669 static int ax88179_chk_eee(struct usbnet
*dev
)
671 struct ethtool_cmd ecmd
= { .cmd
= ETHTOOL_GSET
};
672 struct ax88179_data
*priv
= (struct ax88179_data
*)dev
->data
;
674 mii_ethtool_gset(&dev
->mii
, &ecmd
);
676 if (ecmd
.duplex
& DUPLEX_FULL
) {
677 int eee_lp
, eee_cap
, eee_adv
;
678 u32 lp
, cap
, adv
, supported
= 0;
680 eee_cap
= ax88179_phy_read_mmd_indirect(dev
,
684 priv
->eee_active
= 0;
688 cap
= mmd_eee_cap_to_ethtool_sup_t(eee_cap
);
690 priv
->eee_active
= 0;
694 eee_lp
= ax88179_phy_read_mmd_indirect(dev
,
698 priv
->eee_active
= 0;
702 eee_adv
= ax88179_phy_read_mmd_indirect(dev
,
707 priv
->eee_active
= 0;
711 adv
= mmd_eee_adv_to_ethtool_adv_t(eee_adv
);
712 lp
= mmd_eee_adv_to_ethtool_adv_t(eee_lp
);
713 supported
= (ecmd
.speed
== SPEED_1000
) ?
714 SUPPORTED_1000baseT_Full
:
715 SUPPORTED_100baseT_Full
;
717 if (!(lp
& adv
& supported
)) {
718 priv
->eee_active
= 0;
722 priv
->eee_active
= 1;
726 priv
->eee_active
= 0;
730 static void ax88179_disable_eee(struct usbnet
*dev
)
734 tmp16
= GMII_PHY_PGSEL_PAGE3
;
735 ax88179_write_cmd(dev
, AX_ACCESS_PHY
, AX88179_PHY_ID
,
736 GMII_PHY_PAGE_SELECT
, 2, &tmp16
);
739 ax88179_write_cmd(dev
, AX_ACCESS_PHY
, AX88179_PHY_ID
,
740 MII_PHYADDR
, 2, &tmp16
);
742 tmp16
= GMII_PHY_PGSEL_PAGE0
;
743 ax88179_write_cmd(dev
, AX_ACCESS_PHY
, AX88179_PHY_ID
,
744 GMII_PHY_PAGE_SELECT
, 2, &tmp16
);
747 static void ax88179_enable_eee(struct usbnet
*dev
)
751 tmp16
= GMII_PHY_PGSEL_PAGE3
;
752 ax88179_write_cmd(dev
, AX_ACCESS_PHY
, AX88179_PHY_ID
,
753 GMII_PHY_PAGE_SELECT
, 2, &tmp16
);
756 ax88179_write_cmd(dev
, AX_ACCESS_PHY
, AX88179_PHY_ID
,
757 MII_PHYADDR
, 2, &tmp16
);
759 tmp16
= GMII_PHY_PGSEL_PAGE5
;
760 ax88179_write_cmd(dev
, AX_ACCESS_PHY
, AX88179_PHY_ID
,
761 GMII_PHY_PAGE_SELECT
, 2, &tmp16
);
764 ax88179_write_cmd(dev
, AX_ACCESS_PHY
, AX88179_PHY_ID
,
765 MII_BMSR
, 2, &tmp16
);
767 tmp16
= GMII_PHY_PGSEL_PAGE0
;
768 ax88179_write_cmd(dev
, AX_ACCESS_PHY
, AX88179_PHY_ID
,
769 GMII_PHY_PAGE_SELECT
, 2, &tmp16
);
772 static int ax88179_get_eee(struct net_device
*net
, struct ethtool_eee
*edata
)
774 struct usbnet
*dev
= netdev_priv(net
);
775 struct ax88179_data
*priv
= (struct ax88179_data
*)dev
->data
;
777 edata
->eee_enabled
= priv
->eee_enabled
;
778 edata
->eee_active
= priv
->eee_active
;
780 return ax88179_ethtool_get_eee(dev
, edata
);
783 static int ax88179_set_eee(struct net_device
*net
, struct ethtool_eee
*edata
)
785 struct usbnet
*dev
= netdev_priv(net
);
786 struct ax88179_data
*priv
= (struct ax88179_data
*)dev
->data
;
787 int ret
= -EOPNOTSUPP
;
789 priv
->eee_enabled
= edata
->eee_enabled
;
790 if (!priv
->eee_enabled
) {
791 ax88179_disable_eee(dev
);
793 priv
->eee_enabled
= ax88179_chk_eee(dev
);
794 if (!priv
->eee_enabled
)
797 ax88179_enable_eee(dev
);
800 ret
= ax88179_ethtool_set_eee(dev
, edata
);
804 mii_nway_restart(&dev
->mii
);
806 usbnet_link_change(dev
, 0, 0);
811 static int ax88179_ioctl(struct net_device
*net
, struct ifreq
*rq
, int cmd
)
813 struct usbnet
*dev
= netdev_priv(net
);
814 return generic_mii_ioctl(&dev
->mii
, if_mii(rq
), cmd
, NULL
);
817 static const struct ethtool_ops ax88179_ethtool_ops
= {
818 .get_link
= ethtool_op_get_link
,
819 .get_msglevel
= usbnet_get_msglevel
,
820 .set_msglevel
= usbnet_set_msglevel
,
821 .get_wol
= ax88179_get_wol
,
822 .set_wol
= ax88179_set_wol
,
823 .get_eeprom_len
= ax88179_get_eeprom_len
,
824 .get_eeprom
= ax88179_get_eeprom
,
825 .get_eee
= ax88179_get_eee
,
826 .set_eee
= ax88179_set_eee
,
827 .nway_reset
= usbnet_nway_reset
,
828 .get_link_ksettings
= ax88179_get_link_ksettings
,
829 .set_link_ksettings
= ax88179_set_link_ksettings
,
830 .get_ts_info
= ethtool_op_get_ts_info
,
833 static void ax88179_set_multicast(struct net_device
*net
)
835 struct usbnet
*dev
= netdev_priv(net
);
836 struct ax88179_data
*data
= (struct ax88179_data
*)dev
->data
;
837 u8
*m_filter
= ((u8
*)dev
->data
) + 12;
839 data
->rxctl
= (AX_RX_CTL_START
| AX_RX_CTL_AB
| AX_RX_CTL_IPE
);
841 if (net
->flags
& IFF_PROMISC
) {
842 data
->rxctl
|= AX_RX_CTL_PRO
;
843 } else if (net
->flags
& IFF_ALLMULTI
||
844 netdev_mc_count(net
) > AX_MAX_MCAST
) {
845 data
->rxctl
|= AX_RX_CTL_AMALL
;
846 } else if (netdev_mc_empty(net
)) {
847 /* just broadcast and directed */
849 /* We use the 20 byte dev->data for our 8 byte filter buffer
850 * to avoid allocating memory that is tricky to free later
853 struct netdev_hw_addr
*ha
;
855 memset(m_filter
, 0, AX_MCAST_FLTSIZE
);
857 netdev_for_each_mc_addr(ha
, net
) {
858 crc_bits
= ether_crc(ETH_ALEN
, ha
->addr
) >> 26;
859 *(m_filter
+ (crc_bits
>> 3)) |= (1 << (crc_bits
& 7));
862 ax88179_write_cmd_async(dev
, AX_ACCESS_MAC
, AX_MULFLTARY
,
863 AX_MCAST_FLTSIZE
, AX_MCAST_FLTSIZE
,
866 data
->rxctl
|= AX_RX_CTL_AM
;
869 ax88179_write_cmd_async(dev
, AX_ACCESS_MAC
, AX_RX_CTL
,
874 ax88179_set_features(struct net_device
*net
, netdev_features_t features
)
877 struct usbnet
*dev
= netdev_priv(net
);
878 netdev_features_t changed
= net
->features
^ features
;
880 if (changed
& NETIF_F_IP_CSUM
) {
881 ax88179_read_cmd(dev
, AX_ACCESS_MAC
, AX_TXCOE_CTL
, 1, 1, &tmp
);
882 tmp
^= AX_TXCOE_TCP
| AX_TXCOE_UDP
;
883 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_TXCOE_CTL
, 1, 1, &tmp
);
886 if (changed
& NETIF_F_IPV6_CSUM
) {
887 ax88179_read_cmd(dev
, AX_ACCESS_MAC
, AX_TXCOE_CTL
, 1, 1, &tmp
);
888 tmp
^= AX_TXCOE_TCPV6
| AX_TXCOE_UDPV6
;
889 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_TXCOE_CTL
, 1, 1, &tmp
);
892 if (changed
& NETIF_F_RXCSUM
) {
893 ax88179_read_cmd(dev
, AX_ACCESS_MAC
, AX_RXCOE_CTL
, 1, 1, &tmp
);
894 tmp
^= AX_RXCOE_IP
| AX_RXCOE_TCP
| AX_RXCOE_UDP
|
895 AX_RXCOE_TCPV6
| AX_RXCOE_UDPV6
;
896 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_RXCOE_CTL
, 1, 1, &tmp
);
902 static int ax88179_change_mtu(struct net_device
*net
, int new_mtu
)
904 struct usbnet
*dev
= netdev_priv(net
);
908 dev
->hard_mtu
= net
->mtu
+ net
->hard_header_len
;
910 if (net
->mtu
> 1500) {
911 ax88179_read_cmd(dev
, AX_ACCESS_MAC
, AX_MEDIUM_STATUS_MODE
,
913 tmp16
|= AX_MEDIUM_JUMBO_EN
;
914 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_MEDIUM_STATUS_MODE
,
917 ax88179_read_cmd(dev
, AX_ACCESS_MAC
, AX_MEDIUM_STATUS_MODE
,
919 tmp16
&= ~AX_MEDIUM_JUMBO_EN
;
920 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_MEDIUM_STATUS_MODE
,
924 /* max qlen depend on hard_mtu and rx_urb_size */
925 usbnet_update_max_qlen(dev
);
930 static int ax88179_set_mac_addr(struct net_device
*net
, void *p
)
932 struct usbnet
*dev
= netdev_priv(net
);
933 struct sockaddr
*addr
= p
;
936 if (netif_running(net
))
938 if (!is_valid_ether_addr(addr
->sa_data
))
939 return -EADDRNOTAVAIL
;
941 memcpy(net
->dev_addr
, addr
->sa_data
, ETH_ALEN
);
943 /* Set the MAC address */
944 ret
= ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_NODE_ID
, ETH_ALEN
,
945 ETH_ALEN
, net
->dev_addr
);
952 static const struct net_device_ops ax88179_netdev_ops
= {
953 .ndo_open
= usbnet_open
,
954 .ndo_stop
= usbnet_stop
,
955 .ndo_start_xmit
= usbnet_start_xmit
,
956 .ndo_tx_timeout
= usbnet_tx_timeout
,
957 .ndo_get_stats64
= usbnet_get_stats64
,
958 .ndo_change_mtu
= ax88179_change_mtu
,
959 .ndo_set_mac_address
= ax88179_set_mac_addr
,
960 .ndo_validate_addr
= eth_validate_addr
,
961 .ndo_do_ioctl
= ax88179_ioctl
,
962 .ndo_set_rx_mode
= ax88179_set_multicast
,
963 .ndo_set_features
= ax88179_set_features
,
966 static int ax88179_check_eeprom(struct usbnet
*dev
)
968 u8 i
, buf
, eeprom
[20];
969 u16 csum
, delay
= HZ
/ 10;
970 unsigned long jtimeout
;
972 /* Read EEPROM content */
973 for (i
= 0; i
< 6; i
++) {
975 if (ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_SROM_ADDR
,
980 if (ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_SROM_CMD
,
984 jtimeout
= jiffies
+ delay
;
986 ax88179_read_cmd(dev
, AX_ACCESS_MAC
, AX_SROM_CMD
,
989 if (time_after(jiffies
, jtimeout
))
992 } while (buf
& EEP_BUSY
);
994 __ax88179_read_cmd(dev
, AX_ACCESS_MAC
, AX_SROM_DATA_LOW
,
995 2, 2, &eeprom
[i
* 2], 0);
997 if ((i
== 0) && (eeprom
[0] == 0xFF))
1001 csum
= eeprom
[6] + eeprom
[7] + eeprom
[8] + eeprom
[9];
1002 csum
= (csum
>> 8) + (csum
& 0xff);
1003 if ((csum
+ eeprom
[10]) != 0xff)
1009 static int ax88179_check_efuse(struct usbnet
*dev
, u16
*ledmode
)
1015 if (ax88179_read_cmd(dev
, AX_ACCESS_EFUS
, 0, 64, 64, efuse
) < 0)
1021 for (i
= 0; i
< 64; i
++)
1022 csum
= csum
+ efuse
[i
];
1025 csum
= (csum
& 0x00FF) + ((csum
>> 8) & 0x00FF);
1030 *ledmode
= (efuse
[51] << 8) | efuse
[52];
1035 static int ax88179_convert_old_led(struct usbnet
*dev
, u16
*ledvalue
)
1039 /* Loaded the old eFuse LED Mode */
1040 if (ax88179_read_cmd(dev
, AX_ACCESS_EEPROM
, 0x3C, 1, 2, &led
) < 0)
1046 led
= LED0_ACTIVE
| LED1_LINK_10
| LED1_LINK_100
|
1047 LED1_LINK_1000
| LED2_ACTIVE
| LED2_LINK_10
|
1048 LED2_LINK_100
| LED2_LINK_1000
| LED_VALID
;
1051 led
= LED0_ACTIVE
| LED1_LINK_1000
| LED2_LINK_100
| LED_VALID
;
1054 led
= LED0_ACTIVE
| LED1_LINK_1000
| LED2_LINK_100
|
1055 LED2_LINK_10
| LED_VALID
;
1058 led
= LED0_ACTIVE
| LED1_ACTIVE
| LED1_LINK_1000
| LED2_ACTIVE
|
1059 LED2_LINK_100
| LED2_LINK_10
| LED_VALID
;
1062 led
= LED0_ACTIVE
| LED1_LINK_10
| LED1_LINK_100
|
1063 LED1_LINK_1000
| LED2_ACTIVE
| LED2_LINK_10
|
1064 LED2_LINK_100
| LED2_LINK_1000
| LED_VALID
;
1073 static int ax88179_led_setting(struct usbnet
*dev
)
1075 u8 ledfd
, value
= 0;
1076 u16 tmp
, ledact
, ledlink
, ledvalue
= 0, delay
= HZ
/ 10;
1077 unsigned long jtimeout
;
1079 /* Check AX88179 version. UA1 or UA2*/
1080 ax88179_read_cmd(dev
, AX_ACCESS_MAC
, GENERAL_STATUS
, 1, 1, &value
);
1082 if (!(value
& AX_SECLD
)) { /* UA1 */
1083 value
= AX_GPIO_CTRL_GPIO3EN
| AX_GPIO_CTRL_GPIO2EN
|
1084 AX_GPIO_CTRL_GPIO1EN
;
1085 if (ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_GPIO_CTRL
,
1091 if (!ax88179_check_eeprom(dev
)) {
1093 if (ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_SROM_ADDR
,
1098 if (ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_SROM_CMD
,
1102 jtimeout
= jiffies
+ delay
;
1104 ax88179_read_cmd(dev
, AX_ACCESS_MAC
, AX_SROM_CMD
,
1107 if (time_after(jiffies
, jtimeout
))
1110 } while (value
& EEP_BUSY
);
1112 ax88179_read_cmd(dev
, AX_ACCESS_MAC
, AX_SROM_DATA_HIGH
,
1114 ledvalue
= (value
<< 8);
1116 ax88179_read_cmd(dev
, AX_ACCESS_MAC
, AX_SROM_DATA_LOW
,
1120 /* load internal ROM for defaule setting */
1121 if ((ledvalue
== 0xFFFF) || ((ledvalue
& LED_VALID
) == 0))
1122 ax88179_convert_old_led(dev
, &ledvalue
);
1124 } else if (!ax88179_check_efuse(dev
, &ledvalue
)) {
1125 if ((ledvalue
== 0xFFFF) || ((ledvalue
& LED_VALID
) == 0))
1126 ax88179_convert_old_led(dev
, &ledvalue
);
1128 ax88179_convert_old_led(dev
, &ledvalue
);
1131 tmp
= GMII_PHY_PGSEL_EXT
;
1132 ax88179_write_cmd(dev
, AX_ACCESS_PHY
, AX88179_PHY_ID
,
1133 GMII_PHY_PAGE_SELECT
, 2, &tmp
);
1136 ax88179_write_cmd(dev
, AX_ACCESS_PHY
, AX88179_PHY_ID
,
1137 GMII_PHYPAGE
, 2, &tmp
);
1139 ax88179_read_cmd(dev
, AX_ACCESS_PHY
, AX88179_PHY_ID
,
1140 GMII_LED_ACT
, 2, &ledact
);
1142 ax88179_read_cmd(dev
, AX_ACCESS_PHY
, AX88179_PHY_ID
,
1143 GMII_LED_LINK
, 2, &ledlink
);
1145 ledact
&= GMII_LED_ACTIVE_MASK
;
1146 ledlink
&= GMII_LED_LINK_MASK
;
1148 if (ledvalue
& LED0_ACTIVE
)
1149 ledact
|= GMII_LED0_ACTIVE
;
1151 if (ledvalue
& LED1_ACTIVE
)
1152 ledact
|= GMII_LED1_ACTIVE
;
1154 if (ledvalue
& LED2_ACTIVE
)
1155 ledact
|= GMII_LED2_ACTIVE
;
1157 if (ledvalue
& LED0_LINK_10
)
1158 ledlink
|= GMII_LED0_LINK_10
;
1160 if (ledvalue
& LED1_LINK_10
)
1161 ledlink
|= GMII_LED1_LINK_10
;
1163 if (ledvalue
& LED2_LINK_10
)
1164 ledlink
|= GMII_LED2_LINK_10
;
1166 if (ledvalue
& LED0_LINK_100
)
1167 ledlink
|= GMII_LED0_LINK_100
;
1169 if (ledvalue
& LED1_LINK_100
)
1170 ledlink
|= GMII_LED1_LINK_100
;
1172 if (ledvalue
& LED2_LINK_100
)
1173 ledlink
|= GMII_LED2_LINK_100
;
1175 if (ledvalue
& LED0_LINK_1000
)
1176 ledlink
|= GMII_LED0_LINK_1000
;
1178 if (ledvalue
& LED1_LINK_1000
)
1179 ledlink
|= GMII_LED1_LINK_1000
;
1181 if (ledvalue
& LED2_LINK_1000
)
1182 ledlink
|= GMII_LED2_LINK_1000
;
1185 ax88179_write_cmd(dev
, AX_ACCESS_PHY
, AX88179_PHY_ID
,
1186 GMII_LED_ACT
, 2, &tmp
);
1189 ax88179_write_cmd(dev
, AX_ACCESS_PHY
, AX88179_PHY_ID
,
1190 GMII_LED_LINK
, 2, &tmp
);
1192 tmp
= GMII_PHY_PGSEL_PAGE0
;
1193 ax88179_write_cmd(dev
, AX_ACCESS_PHY
, AX88179_PHY_ID
,
1194 GMII_PHY_PAGE_SELECT
, 2, &tmp
);
1196 /* LED full duplex setting */
1198 if (ledvalue
& LED0_FD
)
1200 else if ((ledvalue
& LED0_USB3_MASK
) == 0)
1203 if (ledvalue
& LED1_FD
)
1205 else if ((ledvalue
& LED1_USB3_MASK
) == 0)
1208 if (ledvalue
& LED2_FD
)
1210 else if ((ledvalue
& LED2_USB3_MASK
) == 0)
1213 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_LEDCTRL
, 1, 1, &ledfd
);
1218 static void ax88179_get_mac_addr(struct usbnet
*dev
)
1222 /* Maybe the boot loader passed the MAC address via device tree */
1223 if (!eth_platform_get_mac_address(&dev
->udev
->dev
, mac
)) {
1224 netif_dbg(dev
, ifup
, dev
->net
,
1225 "MAC address read from device tree");
1227 ax88179_read_cmd(dev
, AX_ACCESS_MAC
, AX_NODE_ID
, ETH_ALEN
,
1229 netif_dbg(dev
, ifup
, dev
->net
,
1230 "MAC address read from ASIX chip");
1233 if (is_valid_ether_addr(mac
)) {
1234 memcpy(dev
->net
->dev_addr
, mac
, ETH_ALEN
);
1236 netdev_info(dev
->net
, "invalid MAC address, using random\n");
1237 eth_hw_addr_random(dev
->net
);
1240 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_NODE_ID
, ETH_ALEN
, ETH_ALEN
,
1241 dev
->net
->dev_addr
);
1244 static int ax88179_bind(struct usbnet
*dev
, struct usb_interface
*intf
)
1249 struct ax88179_data
*ax179_data
= (struct ax88179_data
*)dev
->data
;
1250 struct ethtool_eee eee_data
;
1252 usbnet_get_endpoints(dev
, intf
);
1257 memset(ax179_data
, 0, sizeof(*ax179_data
));
1259 /* Power up ethernet PHY */
1261 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_PHYPWR_RSTCTL
, 2, 2, tmp16
);
1262 *tmp16
= AX_PHYPWR_RSTCTL_IPRL
;
1263 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_PHYPWR_RSTCTL
, 2, 2, tmp16
);
1266 *tmp
= AX_CLK_SELECT_ACS
| AX_CLK_SELECT_BCS
;
1267 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_CLK_SELECT
, 1, 1, tmp
);
1270 /* Read MAC address from DTB or asix chip */
1271 ax88179_get_mac_addr(dev
);
1272 memcpy(dev
->net
->perm_addr
, dev
->net
->dev_addr
, ETH_ALEN
);
1274 /* RX bulk configuration */
1275 memcpy(tmp
, &AX88179_BULKIN_SIZE
[0], 5);
1276 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_RX_BULKIN_QCTRL
, 5, 5, tmp
);
1278 dev
->rx_urb_size
= 1024 * 20;
1281 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_PAUSE_WATERLVL_LOW
, 1, 1, tmp
);
1284 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_PAUSE_WATERLVL_HIGH
,
1287 dev
->net
->netdev_ops
= &ax88179_netdev_ops
;
1288 dev
->net
->ethtool_ops
= &ax88179_ethtool_ops
;
1289 dev
->net
->needed_headroom
= 8;
1290 dev
->net
->max_mtu
= 4088;
1292 /* Initialize MII structure */
1293 dev
->mii
.dev
= dev
->net
;
1294 dev
->mii
.mdio_read
= ax88179_mdio_read
;
1295 dev
->mii
.mdio_write
= ax88179_mdio_write
;
1296 dev
->mii
.phy_id_mask
= 0xff;
1297 dev
->mii
.reg_num_mask
= 0xff;
1298 dev
->mii
.phy_id
= 0x03;
1299 dev
->mii
.supports_gmii
= 1;
1301 dev
->net
->features
|= NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
|
1304 dev
->net
->hw_features
|= NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
|
1307 /* Enable checksum offload */
1308 *tmp
= AX_RXCOE_IP
| AX_RXCOE_TCP
| AX_RXCOE_UDP
|
1309 AX_RXCOE_TCPV6
| AX_RXCOE_UDPV6
;
1310 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_RXCOE_CTL
, 1, 1, tmp
);
1312 *tmp
= AX_TXCOE_IP
| AX_TXCOE_TCP
| AX_TXCOE_UDP
|
1313 AX_TXCOE_TCPV6
| AX_TXCOE_UDPV6
;
1314 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_TXCOE_CTL
, 1, 1, tmp
);
1316 /* Configure RX control register => start operation */
1317 *tmp16
= AX_RX_CTL_DROPCRCERR
| AX_RX_CTL_IPE
| AX_RX_CTL_START
|
1318 AX_RX_CTL_AP
| AX_RX_CTL_AMALL
| AX_RX_CTL_AB
;
1319 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_RX_CTL
, 2, 2, tmp16
);
1321 *tmp
= AX_MONITOR_MODE_PMETYPE
| AX_MONITOR_MODE_PMEPOL
|
1322 AX_MONITOR_MODE_RWMP
;
1323 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_MONITOR_MOD
, 1, 1, tmp
);
1325 /* Configure default medium type => giga */
1326 *tmp16
= AX_MEDIUM_RECEIVE_EN
| AX_MEDIUM_TXFLOW_CTRLEN
|
1327 AX_MEDIUM_RXFLOW_CTRLEN
| AX_MEDIUM_FULL_DUPLEX
|
1329 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_MEDIUM_STATUS_MODE
,
1332 ax88179_led_setting(dev
);
1334 ax179_data
->eee_enabled
= 0;
1335 ax179_data
->eee_active
= 0;
1337 ax88179_disable_eee(dev
);
1339 ax88179_ethtool_get_eee(dev
, &eee_data
);
1340 eee_data
.advertised
= 0;
1341 ax88179_ethtool_set_eee(dev
, &eee_data
);
1343 /* Restart autoneg */
1344 mii_nway_restart(&dev
->mii
);
1346 usbnet_link_change(dev
, 0, 0);
1351 static void ax88179_unbind(struct usbnet
*dev
, struct usb_interface
*intf
)
1355 /* Configure RX control register => stop operation */
1356 tmp16
= AX_RX_CTL_STOP
;
1357 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_RX_CTL
, 2, 2, &tmp16
);
1360 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_CLK_SELECT
, 1, 1, &tmp16
);
1362 /* Power down ethernet PHY */
1364 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_PHYPWR_RSTCTL
, 2, 2, &tmp16
);
1368 ax88179_rx_checksum(struct sk_buff
*skb
, u32
*pkt_hdr
)
1370 skb
->ip_summed
= CHECKSUM_NONE
;
1372 /* checksum error bit is set */
1373 if ((*pkt_hdr
& AX_RXHDR_L3CSUM_ERR
) ||
1374 (*pkt_hdr
& AX_RXHDR_L4CSUM_ERR
))
1377 /* It must be a TCP or UDP packet with a valid checksum */
1378 if (((*pkt_hdr
& AX_RXHDR_L4_TYPE_MASK
) == AX_RXHDR_L4_TYPE_TCP
) ||
1379 ((*pkt_hdr
& AX_RXHDR_L4_TYPE_MASK
) == AX_RXHDR_L4_TYPE_UDP
))
1380 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1383 static int ax88179_rx_fixup(struct usbnet
*dev
, struct sk_buff
*skb
)
1385 struct sk_buff
*ax_skb
;
1391 /* This check is no longer done by usbnet */
1392 if (skb
->len
< dev
->net
->hard_header_len
)
1395 skb_trim(skb
, skb
->len
- 4);
1396 rx_hdr
= get_unaligned_le32(skb_tail_pointer(skb
));
1398 pkt_cnt
= (u16
)rx_hdr
;
1399 hdr_off
= (u16
)(rx_hdr
>> 16);
1400 pkt_hdr
= (u32
*)(skb
->data
+ hdr_off
);
1405 le32_to_cpus(pkt_hdr
);
1406 pkt_len
= (*pkt_hdr
>> 16) & 0x1fff;
1408 /* Check CRC or runt packet */
1409 if ((*pkt_hdr
& AX_RXHDR_CRC_ERR
) ||
1410 (*pkt_hdr
& AX_RXHDR_DROP_ERR
)) {
1411 skb_pull(skb
, (pkt_len
+ 7) & 0xFFF8);
1417 /* Skip IP alignment psudo header */
1420 skb_set_tail_pointer(skb
, pkt_len
);
1421 skb
->truesize
= pkt_len
+ sizeof(struct sk_buff
);
1422 ax88179_rx_checksum(skb
, pkt_hdr
);
1426 ax_skb
= skb_clone(skb
, GFP_ATOMIC
);
1428 ax_skb
->len
= pkt_len
;
1429 ax_skb
->data
= skb
->data
+ 2;
1430 skb_set_tail_pointer(ax_skb
, pkt_len
);
1431 ax_skb
->truesize
= pkt_len
+ sizeof(struct sk_buff
);
1432 ax88179_rx_checksum(ax_skb
, pkt_hdr
);
1433 usbnet_skb_return(dev
, ax_skb
);
1438 skb_pull(skb
, (pkt_len
+ 7) & 0xFFF8);
1444 static struct sk_buff
*
1445 ax88179_tx_fixup(struct usbnet
*dev
, struct sk_buff
*skb
, gfp_t flags
)
1447 u32 tx_hdr1
, tx_hdr2
;
1448 int frame_size
= dev
->maxpacket
;
1449 int mss
= skb_shinfo(skb
)->gso_size
;
1455 if (((skb
->len
+ 8) % frame_size
) == 0)
1456 tx_hdr2
|= 0x80008000; /* Enable padding */
1458 headroom
= skb_headroom(skb
) - 8;
1460 if ((skb_header_cloned(skb
) || headroom
< 0) &&
1461 pskb_expand_head(skb
, headroom
< 0 ? 8 : 0, 0, GFP_ATOMIC
)) {
1462 dev_kfree_skb_any(skb
);
1466 ptr
= skb_push(skb
, 8);
1467 put_unaligned_le32(tx_hdr1
, ptr
);
1468 put_unaligned_le32(tx_hdr2
, ptr
+ 4);
1473 static int ax88179_link_reset(struct usbnet
*dev
)
1475 struct ax88179_data
*ax179_data
= (struct ax88179_data
*)dev
->data
;
1476 u8 tmp
[5], link_sts
;
1477 u16 mode
, tmp16
, delay
= HZ
/ 10;
1478 u32 tmp32
= 0x40000000;
1479 unsigned long jtimeout
;
1481 jtimeout
= jiffies
+ delay
;
1482 while (tmp32
& 0x40000000) {
1484 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_RX_CTL
, 2, 2, &mode
);
1485 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_RX_CTL
, 2, 2,
1486 &ax179_data
->rxctl
);
1488 /*link up, check the usb device control TX FIFO full or empty*/
1489 ax88179_read_cmd(dev
, 0x81, 0x8c, 0, 4, &tmp32
);
1491 if (time_after(jiffies
, jtimeout
))
1495 mode
= AX_MEDIUM_RECEIVE_EN
| AX_MEDIUM_TXFLOW_CTRLEN
|
1496 AX_MEDIUM_RXFLOW_CTRLEN
;
1498 ax88179_read_cmd(dev
, AX_ACCESS_MAC
, PHYSICAL_LINK_STATUS
,
1501 ax88179_read_cmd(dev
, AX_ACCESS_PHY
, AX88179_PHY_ID
,
1502 GMII_PHY_PHYSR
, 2, &tmp16
);
1504 if (!(tmp16
& GMII_PHY_PHYSR_LINK
)) {
1506 } else if (GMII_PHY_PHYSR_GIGA
== (tmp16
& GMII_PHY_PHYSR_SMASK
)) {
1507 mode
|= AX_MEDIUM_GIGAMODE
| AX_MEDIUM_EN_125MHZ
;
1508 if (dev
->net
->mtu
> 1500)
1509 mode
|= AX_MEDIUM_JUMBO_EN
;
1511 if (link_sts
& AX_USB_SS
)
1512 memcpy(tmp
, &AX88179_BULKIN_SIZE
[0], 5);
1513 else if (link_sts
& AX_USB_HS
)
1514 memcpy(tmp
, &AX88179_BULKIN_SIZE
[1], 5);
1516 memcpy(tmp
, &AX88179_BULKIN_SIZE
[3], 5);
1517 } else if (GMII_PHY_PHYSR_100
== (tmp16
& GMII_PHY_PHYSR_SMASK
)) {
1518 mode
|= AX_MEDIUM_PS
;
1520 if (link_sts
& (AX_USB_SS
| AX_USB_HS
))
1521 memcpy(tmp
, &AX88179_BULKIN_SIZE
[2], 5);
1523 memcpy(tmp
, &AX88179_BULKIN_SIZE
[3], 5);
1525 memcpy(tmp
, &AX88179_BULKIN_SIZE
[3], 5);
1528 /* RX bulk configuration */
1529 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_RX_BULKIN_QCTRL
, 5, 5, tmp
);
1531 dev
->rx_urb_size
= (1024 * (tmp
[3] + 2));
1533 if (tmp16
& GMII_PHY_PHYSR_FULL
)
1534 mode
|= AX_MEDIUM_FULL_DUPLEX
;
1535 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_MEDIUM_STATUS_MODE
,
1538 ax179_data
->eee_enabled
= ax88179_chk_eee(dev
);
1540 netif_carrier_on(dev
->net
);
1545 static int ax88179_reset(struct usbnet
*dev
)
1550 struct ax88179_data
*ax179_data
= (struct ax88179_data
*)dev
->data
;
1551 struct ethtool_eee eee_data
;
1556 /* Power up ethernet PHY */
1558 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_PHYPWR_RSTCTL
, 2, 2, tmp16
);
1560 *tmp16
= AX_PHYPWR_RSTCTL_IPRL
;
1561 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_PHYPWR_RSTCTL
, 2, 2, tmp16
);
1564 *tmp
= AX_CLK_SELECT_ACS
| AX_CLK_SELECT_BCS
;
1565 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_CLK_SELECT
, 1, 1, tmp
);
1568 /* Ethernet PHY Auto Detach*/
1569 ax88179_auto_detach(dev
, 0);
1571 /* Read MAC address from DTB or asix chip */
1572 ax88179_get_mac_addr(dev
);
1574 /* RX bulk configuration */
1575 memcpy(tmp
, &AX88179_BULKIN_SIZE
[0], 5);
1576 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_RX_BULKIN_QCTRL
, 5, 5, tmp
);
1578 dev
->rx_urb_size
= 1024 * 20;
1581 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_PAUSE_WATERLVL_LOW
, 1, 1, tmp
);
1584 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_PAUSE_WATERLVL_HIGH
,
1587 dev
->net
->features
|= NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
|
1590 dev
->net
->hw_features
|= NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
|
1593 /* Enable checksum offload */
1594 *tmp
= AX_RXCOE_IP
| AX_RXCOE_TCP
| AX_RXCOE_UDP
|
1595 AX_RXCOE_TCPV6
| AX_RXCOE_UDPV6
;
1596 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_RXCOE_CTL
, 1, 1, tmp
);
1598 *tmp
= AX_TXCOE_IP
| AX_TXCOE_TCP
| AX_TXCOE_UDP
|
1599 AX_TXCOE_TCPV6
| AX_TXCOE_UDPV6
;
1600 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_TXCOE_CTL
, 1, 1, tmp
);
1602 /* Configure RX control register => start operation */
1603 *tmp16
= AX_RX_CTL_DROPCRCERR
| AX_RX_CTL_IPE
| AX_RX_CTL_START
|
1604 AX_RX_CTL_AP
| AX_RX_CTL_AMALL
| AX_RX_CTL_AB
;
1605 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_RX_CTL
, 2, 2, tmp16
);
1607 *tmp
= AX_MONITOR_MODE_PMETYPE
| AX_MONITOR_MODE_PMEPOL
|
1608 AX_MONITOR_MODE_RWMP
;
1609 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_MONITOR_MOD
, 1, 1, tmp
);
1611 /* Configure default medium type => giga */
1612 *tmp16
= AX_MEDIUM_RECEIVE_EN
| AX_MEDIUM_TXFLOW_CTRLEN
|
1613 AX_MEDIUM_RXFLOW_CTRLEN
| AX_MEDIUM_FULL_DUPLEX
|
1615 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_MEDIUM_STATUS_MODE
,
1618 ax88179_led_setting(dev
);
1620 ax179_data
->eee_enabled
= 0;
1621 ax179_data
->eee_active
= 0;
1623 ax88179_disable_eee(dev
);
1625 ax88179_ethtool_get_eee(dev
, &eee_data
);
1626 eee_data
.advertised
= 0;
1627 ax88179_ethtool_set_eee(dev
, &eee_data
);
1629 /* Restart autoneg */
1630 mii_nway_restart(&dev
->mii
);
1632 usbnet_link_change(dev
, 0, 0);
1637 static int ax88179_stop(struct usbnet
*dev
)
1641 ax88179_read_cmd(dev
, AX_ACCESS_MAC
, AX_MEDIUM_STATUS_MODE
,
1643 tmp16
&= ~AX_MEDIUM_RECEIVE_EN
;
1644 ax88179_write_cmd(dev
, AX_ACCESS_MAC
, AX_MEDIUM_STATUS_MODE
,
1650 static const struct driver_info ax88179_info
= {
1651 .description
= "ASIX AX88179 USB 3.0 Gigabit Ethernet",
1652 .bind
= ax88179_bind
,
1653 .unbind
= ax88179_unbind
,
1654 .status
= ax88179_status
,
1655 .link_reset
= ax88179_link_reset
,
1656 .reset
= ax88179_reset
,
1657 .stop
= ax88179_stop
,
1658 .flags
= FLAG_ETHER
| FLAG_FRAMING_AX
,
1659 .rx_fixup
= ax88179_rx_fixup
,
1660 .tx_fixup
= ax88179_tx_fixup
,
1663 static const struct driver_info ax88178a_info
= {
1664 .description
= "ASIX AX88178A USB 2.0 Gigabit Ethernet",
1665 .bind
= ax88179_bind
,
1666 .unbind
= ax88179_unbind
,
1667 .status
= ax88179_status
,
1668 .link_reset
= ax88179_link_reset
,
1669 .reset
= ax88179_reset
,
1670 .stop
= ax88179_stop
,
1671 .flags
= FLAG_ETHER
| FLAG_FRAMING_AX
,
1672 .rx_fixup
= ax88179_rx_fixup
,
1673 .tx_fixup
= ax88179_tx_fixup
,
1676 static const struct driver_info cypress_GX3_info
= {
1677 .description
= "Cypress GX3 SuperSpeed to Gigabit Ethernet Controller",
1678 .bind
= ax88179_bind
,
1679 .unbind
= ax88179_unbind
,
1680 .status
= ax88179_status
,
1681 .link_reset
= ax88179_link_reset
,
1682 .reset
= ax88179_reset
,
1683 .stop
= ax88179_stop
,
1684 .flags
= FLAG_ETHER
| FLAG_FRAMING_AX
,
1685 .rx_fixup
= ax88179_rx_fixup
,
1686 .tx_fixup
= ax88179_tx_fixup
,
1689 static const struct driver_info dlink_dub1312_info
= {
1690 .description
= "D-Link DUB-1312 USB 3.0 to Gigabit Ethernet Adapter",
1691 .bind
= ax88179_bind
,
1692 .unbind
= ax88179_unbind
,
1693 .status
= ax88179_status
,
1694 .link_reset
= ax88179_link_reset
,
1695 .reset
= ax88179_reset
,
1696 .stop
= ax88179_stop
,
1697 .flags
= FLAG_ETHER
| FLAG_FRAMING_AX
,
1698 .rx_fixup
= ax88179_rx_fixup
,
1699 .tx_fixup
= ax88179_tx_fixup
,
1702 static const struct driver_info sitecom_info
= {
1703 .description
= "Sitecom USB 3.0 to Gigabit Adapter",
1704 .bind
= ax88179_bind
,
1705 .unbind
= ax88179_unbind
,
1706 .status
= ax88179_status
,
1707 .link_reset
= ax88179_link_reset
,
1708 .reset
= ax88179_reset
,
1709 .stop
= ax88179_stop
,
1710 .flags
= FLAG_ETHER
| FLAG_FRAMING_AX
,
1711 .rx_fixup
= ax88179_rx_fixup
,
1712 .tx_fixup
= ax88179_tx_fixup
,
1715 static const struct driver_info samsung_info
= {
1716 .description
= "Samsung USB Ethernet Adapter",
1717 .bind
= ax88179_bind
,
1718 .unbind
= ax88179_unbind
,
1719 .status
= ax88179_status
,
1720 .link_reset
= ax88179_link_reset
,
1721 .reset
= ax88179_reset
,
1722 .stop
= ax88179_stop
,
1723 .flags
= FLAG_ETHER
| FLAG_FRAMING_AX
,
1724 .rx_fixup
= ax88179_rx_fixup
,
1725 .tx_fixup
= ax88179_tx_fixup
,
1728 static const struct driver_info lenovo_info
= {
1729 .description
= "Lenovo OneLinkDock Gigabit LAN",
1730 .bind
= ax88179_bind
,
1731 .unbind
= ax88179_unbind
,
1732 .status
= ax88179_status
,
1733 .link_reset
= ax88179_link_reset
,
1734 .reset
= ax88179_reset
,
1735 .stop
= ax88179_stop
,
1736 .flags
= FLAG_ETHER
| FLAG_FRAMING_AX
,
1737 .rx_fixup
= ax88179_rx_fixup
,
1738 .tx_fixup
= ax88179_tx_fixup
,
1741 static const struct driver_info belkin_info
= {
1742 .description
= "Belkin USB Ethernet Adapter",
1743 .bind
= ax88179_bind
,
1744 .unbind
= ax88179_unbind
,
1745 .status
= ax88179_status
,
1746 .link_reset
= ax88179_link_reset
,
1747 .reset
= ax88179_reset
,
1748 .flags
= FLAG_ETHER
| FLAG_FRAMING_AX
,
1749 .rx_fixup
= ax88179_rx_fixup
,
1750 .tx_fixup
= ax88179_tx_fixup
,
1753 static const struct usb_device_id products
[] = {
1755 /* ASIX AX88179 10/100/1000 */
1756 USB_DEVICE(0x0b95, 0x1790),
1757 .driver_info
= (unsigned long)&ax88179_info
,
1759 /* ASIX AX88178A 10/100/1000 */
1760 USB_DEVICE(0x0b95, 0x178a),
1761 .driver_info
= (unsigned long)&ax88178a_info
,
1763 /* Cypress GX3 SuperSpeed to Gigabit Ethernet Bridge Controller */
1764 USB_DEVICE(0x04b4, 0x3610),
1765 .driver_info
= (unsigned long)&cypress_GX3_info
,
1767 /* D-Link DUB-1312 USB 3.0 to Gigabit Ethernet Adapter */
1768 USB_DEVICE(0x2001, 0x4a00),
1769 .driver_info
= (unsigned long)&dlink_dub1312_info
,
1771 /* Sitecom USB 3.0 to Gigabit Adapter */
1772 USB_DEVICE(0x0df6, 0x0072),
1773 .driver_info
= (unsigned long)&sitecom_info
,
1775 /* Samsung USB Ethernet Adapter */
1776 USB_DEVICE(0x04e8, 0xa100),
1777 .driver_info
= (unsigned long)&samsung_info
,
1779 /* Lenovo OneLinkDock Gigabit LAN */
1780 USB_DEVICE(0x17ef, 0x304b),
1781 .driver_info
= (unsigned long)&lenovo_info
,
1783 /* Belkin B2B128 USB 3.0 Hub + Gigabit Ethernet Adapter */
1784 USB_DEVICE(0x050d, 0x0128),
1785 .driver_info
= (unsigned long)&belkin_info
,
1789 MODULE_DEVICE_TABLE(usb
, products
);
1791 static struct usb_driver ax88179_178a_driver
= {
1792 .name
= "ax88179_178a",
1793 .id_table
= products
,
1794 .probe
= usbnet_probe
,
1795 .suspend
= ax88179_suspend
,
1796 .resume
= ax88179_resume
,
1797 .reset_resume
= ax88179_resume
,
1798 .disconnect
= usbnet_disconnect
,
1799 .supports_autosuspend
= 1,
1800 .disable_hub_initiated_lpm
= 1,
1803 module_usb_driver(ax88179_178a_driver
);
1805 MODULE_DESCRIPTION("ASIX AX88179/178A based USB 3.0/2.0 Gigabit Ethernet Devices");
1806 MODULE_LICENSE("GPL");