aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2016-12-08 14:21:48 -0500
committerDavid S. Miller <davem@davemloft.net>2016-12-08 14:21:48 -0500
commit8a03cf2cb7efe269913db079afb8c31f20bf0bef (patch)
tree81ef9e3bc90e38e3943d0dd5f074d3f580bd1af4
parentd2a4dd37f6b41fbcad76efbf63124eb3126c66fe (diff)
parent02dc1f3d613d5a859513d7416c9aca370425a7e0 (diff)
Merge branch 'lan7801-mac-only'
Woojung Huh says: ==================== phy: lan78xx: add phy fixup unregister functions & LAN7801 update V2 patch of adding phy fixup unregister function with use in LAN7801 update. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--Documentation/networking/phy.txt9
-rw-r--r--drivers/net/phy/phy_device.c47
-rw-r--r--drivers/net/usb/Kconfig5
-rw-r--r--drivers/net/usb/lan78xx.c109
-rw-r--r--drivers/net/usb/lan78xx.h14
-rw-r--r--include/linux/phy.h4
6 files changed, 186 insertions, 2 deletions
diff --git a/Documentation/networking/phy.txt b/Documentation/networking/phy.txt
index e017d933d530..16f90d817224 100644
--- a/Documentation/networking/phy.txt
+++ b/Documentation/networking/phy.txt
@@ -407,6 +407,15 @@ Board Fixups
407 The stubs set one of the two matching criteria, and set the other one to 407 The stubs set one of the two matching criteria, and set the other one to
408 match anything. 408 match anything.
409 409
410 When phy_register_fixup() or *_for_uid()/*_for_id() is called at module,
411 unregister fixup and free allocate memory are required.
412
413 Call one of following function before unloading module.
414
415 int phy_unregister_fixup(const char *phy_id, u32 phy_uid, u32 phy_uid_mask);
416 int phy_unregister_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask);
417 int phy_register_fixup_for_id(const char *phy_id);
418
410Standards 419Standards
411 420
412 IEEE Standard 802.3: CSMA/CD Access Method and Physical Layer Specifications, Section Two: 421 IEEE Standard 802.3: CSMA/CD Access Method and Physical Layer Specifications, Section Two:
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index aeaf1bcb12d0..32fa7c76f29c 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -235,6 +235,53 @@ int phy_register_fixup_for_id(const char *bus_id,
235} 235}
236EXPORT_SYMBOL(phy_register_fixup_for_id); 236EXPORT_SYMBOL(phy_register_fixup_for_id);
237 237
238/**
239 * phy_unregister_fixup - remove a phy_fixup from the list
240 * @bus_id: A string matches fixup->bus_id (or PHY_ANY_ID) in phy_fixup_list
241 * @phy_uid: A phy id matches fixup->phy_id (or PHY_ANY_UID) in phy_fixup_list
242 * @phy_uid_mask: Applied to phy_uid and fixup->phy_uid before comparison
243 */
244int phy_unregister_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask)
245{
246 struct list_head *pos, *n;
247 struct phy_fixup *fixup;
248 int ret;
249
250 ret = -ENODEV;
251
252 mutex_lock(&phy_fixup_lock);
253 list_for_each_safe(pos, n, &phy_fixup_list) {
254 fixup = list_entry(pos, struct phy_fixup, list);
255
256 if ((!strcmp(fixup->bus_id, bus_id)) &&
257 ((fixup->phy_uid & phy_uid_mask) ==
258 (phy_uid & phy_uid_mask))) {
259 list_del(&fixup->list);
260 kfree(fixup);
261 ret = 0;
262 break;
263 }
264 }
265 mutex_unlock(&phy_fixup_lock);
266
267 return ret;
268}
269EXPORT_SYMBOL(phy_unregister_fixup);
270
271/* Unregisters a fixup of any PHY with the UID in phy_uid */
272int phy_unregister_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask)
273{
274 return phy_unregister_fixup(PHY_ANY_ID, phy_uid, phy_uid_mask);
275}
276EXPORT_SYMBOL(phy_unregister_fixup_for_uid);
277
278/* Unregisters a fixup of the PHY with id string bus_id */
279int phy_unregister_fixup_for_id(const char *bus_id)
280{
281 return phy_unregister_fixup(bus_id, PHY_ANY_UID, 0xffffffff);
282}
283EXPORT_SYMBOL(phy_unregister_fixup_for_id);
284
238/* Returns 1 if fixup matches phydev in bus_id and phy_uid. 285/* Returns 1 if fixup matches phydev in bus_id and phy_uid.
239 * Fixups can be set to match any in one or more fields. 286 * Fixups can be set to match any in one or more fields.
240 */ 287 */
diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig
index cdde59089f72..3dd490f53e48 100644
--- a/drivers/net/usb/Kconfig
+++ b/drivers/net/usb/Kconfig
@@ -114,6 +114,11 @@ config USB_LAN78XX
114 help 114 help
115 This option adds support for Microchip LAN78XX based USB 2 115 This option adds support for Microchip LAN78XX based USB 2
116 & USB 3 10/100/1000 Ethernet adapters. 116 & USB 3 10/100/1000 Ethernet adapters.
117 LAN7800 : USB 3 to 10/100/1000 Ethernet adapter
118 LAN7850 : USB 2 to 10/100/1000 Ethernet adapter
119 LAN7801 : USB 3 to 10/100/1000 Ethernet adapter (MAC only)
120
121 Proper PHY driver is required for LAN7801.
117 122
118 To compile this driver as a module, choose M here: the 123 To compile this driver as a module, choose M here: the
119 module will be called lan78xx. 124 module will be called lan78xx.
diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
index 019f758953fc..08f8703e4d54 100644
--- a/drivers/net/usb/lan78xx.c
+++ b/drivers/net/usb/lan78xx.c
@@ -40,7 +40,7 @@
40#define DRIVER_AUTHOR "WOOJUNG HUH <woojung.huh@microchip.com>" 40#define DRIVER_AUTHOR "WOOJUNG HUH <woojung.huh@microchip.com>"
41#define DRIVER_DESC "LAN78XX USB 3.0 Gigabit Ethernet Devices" 41#define DRIVER_DESC "LAN78XX USB 3.0 Gigabit Ethernet Devices"
42#define DRIVER_NAME "lan78xx" 42#define DRIVER_NAME "lan78xx"
43#define DRIVER_VERSION "1.0.5" 43#define DRIVER_VERSION "1.0.6"
44 44
45#define TX_TIMEOUT_JIFFIES (5 * HZ) 45#define TX_TIMEOUT_JIFFIES (5 * HZ)
46#define THROTTLE_JIFFIES (HZ / 8) 46#define THROTTLE_JIFFIES (HZ / 8)
@@ -67,6 +67,7 @@
67#define LAN78XX_USB_VENDOR_ID (0x0424) 67#define LAN78XX_USB_VENDOR_ID (0x0424)
68#define LAN7800_USB_PRODUCT_ID (0x7800) 68#define LAN7800_USB_PRODUCT_ID (0x7800)
69#define LAN7850_USB_PRODUCT_ID (0x7850) 69#define LAN7850_USB_PRODUCT_ID (0x7850)
70#define LAN7801_USB_PRODUCT_ID (0x7801)
70#define LAN78XX_EEPROM_MAGIC (0x78A5) 71#define LAN78XX_EEPROM_MAGIC (0x78A5)
71#define LAN78XX_OTP_MAGIC (0x78F3) 72#define LAN78XX_OTP_MAGIC (0x78F3)
72 73
@@ -390,6 +391,7 @@ struct lan78xx_net {
390 u32 chipid; 391 u32 chipid;
391 u32 chiprev; 392 u32 chiprev;
392 struct mii_bus *mdiobus; 393 struct mii_bus *mdiobus;
394 phy_interface_t interface;
393 395
394 int fc_autoneg; 396 int fc_autoneg;
395 u8 fc_request_control; 397 u8 fc_request_control;
@@ -400,6 +402,10 @@ struct lan78xx_net {
400 struct irq_domain_data domain_data; 402 struct irq_domain_data domain_data;
401}; 403};
402 404
405/* define external phy id */
406#define PHY_LAN8835 (0x0007C130)
407#define PHY_KSZ9031RNX (0x00221620)
408
403/* use ethtool to change the level for any given device */ 409/* use ethtool to change the level for any given device */
404static int msg_level = -1; 410static int msg_level = -1;
405module_param(msg_level, int, 0); 411module_param(msg_level, int, 0);
@@ -1697,6 +1703,7 @@ static int lan78xx_mdiobus_read(struct mii_bus *bus, int phy_id, int idx)
1697done: 1703done:
1698 mutex_unlock(&dev->phy_mutex); 1704 mutex_unlock(&dev->phy_mutex);
1699 usb_autopm_put_interface(dev->intf); 1705 usb_autopm_put_interface(dev->intf);
1706
1700 return ret; 1707 return ret;
1701} 1708}
1702 1709
@@ -1759,6 +1766,10 @@ static int lan78xx_mdio_init(struct lan78xx_net *dev)
1759 /* set to internal PHY id */ 1766 /* set to internal PHY id */
1760 dev->mdiobus->phy_mask = ~(1 << 1); 1767 dev->mdiobus->phy_mask = ~(1 << 1);
1761 break; 1768 break;
1769 case ID_REV_CHIP_ID_7801_:
1770 /* scan thru PHYAD[2..0] */
1771 dev->mdiobus->phy_mask = ~(0xFF);
1772 break;
1762 } 1773 }
1763 1774
1764 ret = mdiobus_register(dev->mdiobus); 1775 ret = mdiobus_register(dev->mdiobus);
@@ -1933,6 +1944,47 @@ static void lan78xx_remove_irq_domain(struct lan78xx_net *dev)
1933 dev->domain_data.irqdomain = NULL; 1944 dev->domain_data.irqdomain = NULL;
1934} 1945}
1935 1946
1947static int lan8835_fixup(struct phy_device *phydev)
1948{
1949 int buf;
1950 int ret;
1951 struct lan78xx_net *dev = netdev_priv(phydev->attached_dev);
1952
1953 /* LED2/PME_N/IRQ_N/RGMII_ID pin to IRQ_N mode */
1954 buf = phy_read_mmd_indirect(phydev, 0x8010, 3);
1955 buf &= ~0x1800;
1956 buf |= 0x0800;
1957 phy_write_mmd_indirect(phydev, 0x8010, 3, buf);
1958
1959 /* RGMII MAC TXC Delay Enable */
1960 ret = lan78xx_write_reg(dev, MAC_RGMII_ID,
1961 MAC_RGMII_ID_TXC_DELAY_EN_);
1962
1963 /* RGMII TX DLL Tune Adjust */
1964 ret = lan78xx_write_reg(dev, RGMII_TX_BYP_DLL, 0x3D00);
1965
1966 dev->interface = PHY_INTERFACE_MODE_RGMII_TXID;
1967
1968 return 1;
1969}
1970
1971static int ksz9031rnx_fixup(struct phy_device *phydev)
1972{
1973 struct lan78xx_net *dev = netdev_priv(phydev->attached_dev);
1974
1975 /* Micrel9301RNX PHY configuration */
1976 /* RGMII Control Signal Pad Skew */
1977 phy_write_mmd_indirect(phydev, 4, 2, 0x0077);
1978 /* RGMII RX Data Pad Skew */
1979 phy_write_mmd_indirect(phydev, 5, 2, 0x7777);
1980 /* RGMII RX Clock Pad Skew */
1981 phy_write_mmd_indirect(phydev, 8, 2, 0x1FF);
1982
1983 dev->interface = PHY_INTERFACE_MODE_RGMII_RXID;
1984
1985 return 1;
1986}
1987
1936static int lan78xx_phy_init(struct lan78xx_net *dev) 1988static int lan78xx_phy_init(struct lan78xx_net *dev)
1937{ 1989{
1938 int ret; 1990 int ret;
@@ -1945,6 +1997,42 @@ static int lan78xx_phy_init(struct lan78xx_net *dev)
1945 return -EIO; 1997 return -EIO;
1946 } 1998 }
1947 1999
2000 if ((dev->chipid == ID_REV_CHIP_ID_7800_) ||
2001 (dev->chipid == ID_REV_CHIP_ID_7850_)) {
2002 phydev->is_internal = true;
2003 dev->interface = PHY_INTERFACE_MODE_GMII;
2004
2005 } else if (dev->chipid == ID_REV_CHIP_ID_7801_) {
2006 if (!phydev->drv) {
2007 netdev_err(dev->net, "no PHY driver found\n");
2008 return -EIO;
2009 }
2010
2011 dev->interface = PHY_INTERFACE_MODE_RGMII;
2012
2013 /* external PHY fixup for KSZ9031RNX */
2014 ret = phy_register_fixup_for_uid(PHY_KSZ9031RNX, 0xfffffff0,
2015 ksz9031rnx_fixup);
2016 if (ret < 0) {
2017 netdev_err(dev->net, "fail to register fixup\n");
2018 return ret;
2019 }
2020 /* external PHY fixup for LAN8835 */
2021 ret = phy_register_fixup_for_uid(PHY_LAN8835, 0xfffffff0,
2022 lan8835_fixup);
2023 if (ret < 0) {
2024 netdev_err(dev->net, "fail to register fixup\n");
2025 return ret;
2026 }
2027 /* add more external PHY fixup here if needed */
2028
2029 phydev->is_internal = false;
2030 } else {
2031 netdev_err(dev->net, "unknown ID found\n");
2032 ret = -EIO;
2033 goto error;
2034 }
2035
1948 /* if phyirq is not set, use polling mode in phylib */ 2036 /* if phyirq is not set, use polling mode in phylib */
1949 if (dev->domain_data.phyirq > 0) 2037 if (dev->domain_data.phyirq > 0)
1950 phydev->irq = dev->domain_data.phyirq; 2038 phydev->irq = dev->domain_data.phyirq;
@@ -1957,7 +2045,7 @@ static int lan78xx_phy_init(struct lan78xx_net *dev)
1957 2045
1958 ret = phy_connect_direct(dev->net, phydev, 2046 ret = phy_connect_direct(dev->net, phydev,
1959 lan78xx_link_status_change, 2047 lan78xx_link_status_change,
1960 PHY_INTERFACE_MODE_GMII); 2048 dev->interface);
1961 if (ret) { 2049 if (ret) {
1962 netdev_err(dev->net, "can't attach PHY to %s\n", 2050 netdev_err(dev->net, "can't attach PHY to %s\n",
1963 dev->mdiobus->id); 2051 dev->mdiobus->id);
@@ -1982,6 +2070,12 @@ static int lan78xx_phy_init(struct lan78xx_net *dev)
1982 netif_dbg(dev, ifup, dev->net, "phy initialised successfully"); 2070 netif_dbg(dev, ifup, dev->net, "phy initialised successfully");
1983 2071
1984 return 0; 2072 return 0;
2073
2074error:
2075 phy_unregister_fixup_for_uid(PHY_KSZ9031RNX, 0xfffffff0);
2076 phy_unregister_fixup_for_uid(PHY_LAN8835, 0xfffffff0);
2077
2078 return ret;
1985} 2079}
1986 2080
1987static int lan78xx_set_rx_max_frame_length(struct lan78xx_net *dev, int size) 2081static int lan78xx_set_rx_max_frame_length(struct lan78xx_net *dev, int size)
@@ -2338,6 +2432,9 @@ static int lan78xx_reset(struct lan78xx_net *dev)
2338 } while ((buf & PMT_CTL_PHY_RST_) || !(buf & PMT_CTL_READY_)); 2432 } while ((buf & PMT_CTL_PHY_RST_) || !(buf & PMT_CTL_READY_));
2339 2433
2340 ret = lan78xx_read_reg(dev, MAC_CR, &buf); 2434 ret = lan78xx_read_reg(dev, MAC_CR, &buf);
2435 /* LAN7801 only has RGMII mode */
2436 if (dev->chipid == ID_REV_CHIP_ID_7801_)
2437 buf &= ~MAC_CR_GMII_EN_;
2341 buf |= MAC_CR_AUTO_DUPLEX_ | MAC_CR_AUTO_SPEED_; 2438 buf |= MAC_CR_AUTO_DUPLEX_ | MAC_CR_AUTO_SPEED_;
2342 ret = lan78xx_write_reg(dev, MAC_CR, buf); 2439 ret = lan78xx_write_reg(dev, MAC_CR, buf);
2343 2440
@@ -2464,8 +2561,12 @@ static int lan78xx_stop(struct net_device *net)
2464 if (timer_pending(&dev->stat_monitor)) 2561 if (timer_pending(&dev->stat_monitor))
2465 del_timer_sync(&dev->stat_monitor); 2562 del_timer_sync(&dev->stat_monitor);
2466 2563
2564 phy_unregister_fixup_for_uid(PHY_KSZ9031RNX, 0xfffffff0);
2565 phy_unregister_fixup_for_uid(PHY_LAN8835, 0xfffffff0);
2566
2467 phy_stop(net->phydev); 2567 phy_stop(net->phydev);
2468 phy_disconnect(net->phydev); 2568 phy_disconnect(net->phydev);
2569
2469 net->phydev = NULL; 2570 net->phydev = NULL;
2470 2571
2471 clear_bit(EVENT_DEV_OPEN, &dev->flags); 2572 clear_bit(EVENT_DEV_OPEN, &dev->flags);
@@ -3888,6 +3989,10 @@ static const struct usb_device_id products[] = {
3888 /* LAN7850 USB Gigabit Ethernet Device */ 3989 /* LAN7850 USB Gigabit Ethernet Device */
3889 USB_DEVICE(LAN78XX_USB_VENDOR_ID, LAN7850_USB_PRODUCT_ID), 3990 USB_DEVICE(LAN78XX_USB_VENDOR_ID, LAN7850_USB_PRODUCT_ID),
3890 }, 3991 },
3992 {
3993 /* LAN7801 USB Gigabit Ethernet Device */
3994 USB_DEVICE(LAN78XX_USB_VENDOR_ID, LAN7801_USB_PRODUCT_ID),
3995 },
3891 {}, 3996 {},
3892}; 3997};
3893MODULE_DEVICE_TABLE(usb, products); 3998MODULE_DEVICE_TABLE(usb, products);
diff --git a/drivers/net/usb/lan78xx.h b/drivers/net/usb/lan78xx.h
index 40927906109a..25aa54611774 100644
--- a/drivers/net/usb/lan78xx.h
+++ b/drivers/net/usb/lan78xx.h
@@ -108,6 +108,7 @@
108#define ID_REV_CHIP_REV_MASK_ (0x0000FFFF) 108#define ID_REV_CHIP_REV_MASK_ (0x0000FFFF)
109#define ID_REV_CHIP_ID_7800_ (0x7800) 109#define ID_REV_CHIP_ID_7800_ (0x7800)
110#define ID_REV_CHIP_ID_7850_ (0x7850) 110#define ID_REV_CHIP_ID_7850_ (0x7850)
111#define ID_REV_CHIP_ID_7801_ (0x7801)
111 112
112#define FPGA_REV (0x04) 113#define FPGA_REV (0x04)
113#define FPGA_REV_MINOR_MASK_ (0x0000FF00) 114#define FPGA_REV_MINOR_MASK_ (0x0000FF00)
@@ -550,6 +551,7 @@
550#define LTM_INACTIVE1_TIMER10_ (0x0000FFFF) 551#define LTM_INACTIVE1_TIMER10_ (0x0000FFFF)
551 552
552#define MAC_CR (0x100) 553#define MAC_CR (0x100)
554#define MAC_CR_GMII_EN_ (0x00080000)
553#define MAC_CR_EEE_TX_CLK_STOP_EN_ (0x00040000) 555#define MAC_CR_EEE_TX_CLK_STOP_EN_ (0x00040000)
554#define MAC_CR_EEE_EN_ (0x00020000) 556#define MAC_CR_EEE_EN_ (0x00020000)
555#define MAC_CR_EEE_TLAR_EN_ (0x00010000) 557#define MAC_CR_EEE_TLAR_EN_ (0x00010000)
@@ -787,6 +789,18 @@
787#define PHY_DEV_ID_MODEL_MASK_ (0x0FC00000) 789#define PHY_DEV_ID_MODEL_MASK_ (0x0FC00000)
788#define PHY_DEV_ID_OUI_MASK_ (0x003FFFFF) 790#define PHY_DEV_ID_OUI_MASK_ (0x003FFFFF)
789 791
792#define RGMII_TX_BYP_DLL (0x708)
793#define RGMII_TX_BYP_DLL_TX_TUNE_ADJ_MASK_ (0x000FC00)
794#define RGMII_TX_BYP_DLL_TX_TUNE_SEL_MASK_ (0x00003F0)
795#define RGMII_TX_BYP_DLL_TX_DLL_RESET_ (0x0000002)
796#define RGMII_TX_BYP_DLL_TX_DLL_BYPASS_ (0x0000001)
797
798#define RGMII_RX_BYP_DLL (0x70C)
799#define RGMII_RX_BYP_DLL_RX_TUNE_ADJ_MASK_ (0x000FC00)
800#define RGMII_RX_BYP_DLL_RX_TUNE_SEL_MASK_ (0x00003F0)
801#define RGMII_RX_BYP_DLL_RX_DLL_RESET_ (0x0000002)
802#define RGMII_RX_BYP_DLL_RX_DLL_BYPASS_ (0x0000001)
803
790#define OTP_BASE_ADDR (0x00001000) 804#define OTP_BASE_ADDR (0x00001000)
791#define OTP_ADDR_RANGE_ (0x1FF) 805#define OTP_ADDR_RANGE_ (0x1FF)
792 806
diff --git a/include/linux/phy.h b/include/linux/phy.h
index feb8a98e8dd3..f7d95f644eed 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -860,6 +860,10 @@ int phy_register_fixup_for_id(const char *bus_id,
860int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask, 860int phy_register_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask,
861 int (*run)(struct phy_device *)); 861 int (*run)(struct phy_device *));
862 862
863int phy_unregister_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask);
864int phy_unregister_fixup_for_id(const char *bus_id);
865int phy_unregister_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask);
866
863int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable); 867int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable);
864int phy_get_eee_err(struct phy_device *phydev); 868int phy_get_eee_err(struct phy_device *phydev);
865int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data); 869int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data);