Project

General

Profile

KSZ9031 phy support for the 3.2 kernel

Added by Timothy Entinger over 7 years ago

We are using a Critical Link BSP for the MitySOM using the AM335x and a baseboard that has the Micrel KSZ9031 ethernet phy on it. For a distro, we are using TI's old Arago distribution running the 3.2 kernel. Support for the phy was not available from Micrel for the 3.2 kernel and Critical Link provided us a branch of the kernel with the phy working.

We now have a need to limit the ethernet phy to 10/100 mbps, but have found that the standard linux tools (ethtool and mii-tool) are not able to set this mode. The tools do not work because the micrel.c file for the phy's does not have an entry for the KSZ9031. Rather the board file does the setup of the phy chip directly. We are not certain which driver (cspw maybe?) the kernel is associating with the phy after it boots.

In U-boot, we can succesfully put the phy into different modes using the mii command.

Here are some of the things we have tried.
1) Writing to the phy's internal registers after the kernel reset's the phy at start-up.

    //Added this code to the am335x_ksz9031_phy_fixup function.
    val = 0x0000;
    val = 0x2000 | 0x0100; //Disable autonegotiation; Set speed to 100 full duplex
    //write to the basic control register
    if (phy_write(phydev,  0, val) < 0) {
        pr_err("Error setting speed to 100mbps full duplex\n");
        return 1;
    }

Also tried this code instead
    //Read contents of 1000 Base-t control register
    val = phy_read(phydev, 9);
    if (val < 0) {
        pr_err("Error reading 1000 Base-t control reg \n");
        return val;
    }
    val &= 0xFCFF; //Disable bits 8, 9; do not advertise 1000 on autonegotiation
    if (phy_write(phydev,  9, val) < 0) {
        pr_err("Error writing to 1000 Base-t control reg\n");
        return 1;
    }
    

2) Setting the preferred mode of the phy in U-boot and booting the kernel (with and without the reset enabled).

Extra comments:
Results of Ethtool
root@jcimity335x:~# ethtool eth0

Settings for eth0:
        Current message level: 0x00000000 (0)
        Link detected: yes

Here is a dump of the phy's internal registers on booting after it has been reset by the GPIO line with no modifcations other than to read and print the register contents at the end of am335x_ksz9031_phy_fixup. The phy works properly here, but will autonegotiate to 1000 mbps.
[    5.726531] Register 0 contents: 0x1140
[    5.730438] Register 1 contents: 0x796d
[    5.734619] Register 2 contents: 0x22
[    5.738525] Register 3 contents: 0x1621
[    5.742645] Register 4 contents: 0x1e1
[    5.746673] Register 5 contents: 0xcde1
[    5.750793] Register 6 contents: 0xf
[    5.754638] Register 7 contents: 0x2001
[    5.758728] Register 8 contents: 0x444d
[    5.762847] Register 9 contents: 0x300
[    5.766876] Register 10 contents: 0x3cff
[    5.771057] Register 11 contents: 0x0
[    5.774963] Register 12 contents: 0x0
[    5.778869] Register 13 contents: 0x0
[    5.782775] Register 14 contents: 0x0
[    5.786712] Register 15 contents: 0x3000
[    5.790863] Register 16 contents: 0x0
[    5.794769] Register 17 contents: 0xf4
[    5.798828] Register 18 contents: 0x0
[    5.802734] Register 19 contents: 0xb87e
[    5.806976] Register 20 contents: 0x44fe
[    5.811157] Register 21 contents: 0x0
[    5.815063] Register 22 contents: 0x0
[    5.818969] Register 23 contents: 0x200
[    5.823059] Register 24 contents: 0x0
[    5.826995] Register 25 contents: 0x0
[    5.830902] Register 26 contents: 0x0
[    5.834808] Register 27 contents: 0x2f
[    5.838836] Register 28 contents: 0x0
[    5.842742] Register 29 contents: 0x0
[    5.846679] Register 30 contents: 0x0
[    5.850585] Register 31 contents: 0x349


Replies (6)

RE: KSZ9031 phy support for the 3.2 kernel - Added by Jonathan Cormier over 7 years ago

I recently worked on this a bit.

Here are some u-boot patches to disable gigabit in u-boot. This won't affect linux as you've noticed.

http://support.criticallink.com/gitweb/?p=u-boot-mityarm-335x.git;a=commit;h=ae1697ccf66a6d57347780600a94cd11bb7fd2f9
http://support.criticallink.com/gitweb/?p=u-boot-mityarm-335x.git;a=commit;h=d0fb2f3476faf112d79aacb779bdf49ee3fdf691

This is just an example of setting the "disable_giga" env field in the som.c file. You could always store it in the uEnv.txt file if booting from sd card or save it to nand using saveenv.
http://support.criticallink.com/gitweb/?p=u-boot-mityarm-335x.git;a=commit;h=8d62235e67f74c84940de71173194ebc67e5a2c6

I'll follow up with a post for the kernel.

RE: KSZ9031 phy support for the 3.2 kernel - Added by Jonathan Cormier over 7 years ago

Timothy Entinger wrote:

We are using a Critical Link BSP for the MitySOM using the AM335x and a baseboard that has the Micrel KSZ9031 ethernet phy on it. For a distro, we are using TI's old Arago distribution running the 3.2 kernel. Support for the phy was not available from Micrel for the 3.2 kernel and Critical Link provided us a branch of the kernel with the phy working.

We now have a need to limit the ethernet phy to 10/100 mbps, but have found that the standard linux tools (ethtool and mii-tool) are not able to set this mode. The tools do not work because the micrel.c file for the phy's does not have an entry for the KSZ9031. Rather the board file does the setup of the phy chip directly. We are not certain which driver (cspw maybe?) the kernel is associating with the phy after it boots.

In the 3.2 kernel, looking at drivers/net/phy/micrel.c. There does appear to be an entry for the KSZ9031 phy.
http://support.criticallink.com/gitweb/?p=linux-mityarm-335x.git;a=blob;f=drivers/net/phy/micrel.c;h=94c7d8fd0f5a82d878b0f28cf42709ca1bf5ead5;hb=HEAD#l415
And we enable the "CONFIG_MICREL_PHY=y" in our defconfig.

Note that the auto negotiation is configured in genphy_config_advert():
http://support.criticallink.com/gitweb/?p=linux-mityarm-335x.git;a=blob;f=drivers/net/phy/phy_device.c;h=56d91914b36c2d3ce7a4ffd4bc6330bc64de27ec;hb=HEAD#l573
Note on line 573 it masks advertising based on supported however on line 606 it won't configure the gigabit registers if gigabit isn't supported. So its important to only clear the phydev->advertising gigabit fields and not the phydev->supported gigabit fields.

In your phy fixup you should be able to do something similar to the u-boot patch to disable advertising.

+               phydev->advertising &= ~(SUPPORTED_1000baseT_Half |
+                               SUPPORTED_1000baseT_Full);

If this doesn't work, I would add some print statements into the genphy_config_advert() and your fixup code to make sure your fixup is running and setting the field correctly.

RE: KSZ9031 phy support for the 3.2 kernel - Added by Jonathan Cormier over 7 years ago

Note to confirm the Micrel phy driver is getting loaded.

root@mitysom-335x ~ $ dmesg | grep -i phy
[    1.760589] davinci_mdio davinci_mdio.0: detected phy mask fffffffb
[    1.771453] davinci_mdio davinci_mdio.0: phy[2]: device 0:02, driver Micrel KSZ9031 Gigabit PHY
[    8.746978] PHY 0:00 not found
[    8.750213] net eth0: CPSW phy found : id is : 0x221622
[   14.746246] PHY: 0:02 - Link is Up - 1000/Full

RE: KSZ9031 phy support for the 3.2 kernel - Added by Timothy Entinger over 7 years ago

I haven't tried you're suggestions yet. I will be able to this afternoon.
The kernel source we're using is much further back on the development tree, here's my dmesg output when I boot.
root@jcimity335x:~# dmesg | grep -i phy
[ 0.126525] PHY reset
[ 1.441070] UBI: physical eraseblock size: 262144 bytes (256 KiB)
[ 5.718750] davinci_mdio davinci_mdio.0: detected phy mask fffffffe
[ 5.856353] davinci_mdio davinci_mdio.0: phy0: device 0:00, driver unknown
[ 14.189697] CPSW phy found : id is : 0x221621
[ 14.204559] PHY 0:01 not found
[ 24.185089] PHY: 0:00 - Link is Up - 1000/Full

Is it possible that just updating the micrel.c file will be enough to get proper support from ethtool?

RE: KSZ9031 phy support for the 3.2 kernel - Added by Jonathan Cormier over 7 years ago

Looking at my JCI kernel branch it does show that it was before we added the micrel phy support. You mentioned we gave you a more updated version with micrel support?

Do you have the following commits in your kernel tree? If so then you just need to enable CONFIG_MICREL_PHY=y

2014-05-22 09:03 Cormier,Jonathan   o [jcormier/micrel_test] phy/micrel: KSZ9031 disable Asym Pause support                                                                                                        
2014-05-19 16:01 Cormier,Jonathan   o ARM: MitySOM: config: Enabled micrel phy support
2013-09-19 19:40 Patrice Vilchez    o phy/micrel: Add suspend/resume support to Micrel PHYs
2013-08-13 09:59 Dinh Nguyen        o phy: micrel: Add definitions for common Micrel PHY registers
2013-08-21 01:46 Sean Cross         o net/phy: micrel: Add OF configuration support for ksz9021
2013-08-06 17:29 Jingoo Han         o net: phy: micrel: Staticize ksz8873mll_read_status()
2013-03-10 22:50 Hector Palacios    o phy/micrel: move flag handling to function for common use
2013-03-10 22:50 Hector Palacios    o phy/micrel: Add support for KSZ8031
2013-02-28 08:45 Vlastimil Kosar    o net/phy: micrel: Disable asymmetric pause for KSZ9021
2013-01-23 14:05 David J. Choi      o drivers/net/phy/micrel_phy: Add support for new PHYs
2012-11-21 05:38 Jean-Christophe P~ o net: add micrel KSZ8873MLL switch support
2012-09-23 16:58 Marek Vasut        o phy/micrel: Add missing header to micrel_phy.h
2012-09-23 16:58 Marek Vasut        o phy/micrel: Rename KS80xx to KSZ80xx
2012-09-23 16:58 Marek Vasut        o phy/micrel: Implement support for KSZ8021
2012-07-04 05:44 Christian Hohnsta~ o phylib: Support registering a bunch of drivers
2012-06-17 22:52 Jason Wang         o phy/micrel: change phy_id_mask for KSZ9021 and KS8001
2012-05-21 14:20 Nobuhiro Iwamatsu  o phy/micrel: Fix ID of KSZ9021
2014-05-21 15:20 Cormier,Jonathan   o omap2/devices: Set phy_id to NULL to set it to be autodiscovered

You should be able to merge in the changes from the following tag without getting a ton of the newer commits.
mitysom_AM335XPSP_04.06.00.07

List of commits between the JCI branch and the mitysom_AM335XPSP_04.06.00.07 tag. Most of these are micrel phy related.

2014-12-22 15:20 Cormier, Jonathan  o [mitysom_AM335XPSP_04.06.00.07] ARM: MitySOM: Fix unused warnings
2014-12-19 17:50 Cormier, Jonathan  o ARM: MitySOM: TIWI: Fix TIWI defconfig
2014-12-19 11:34 Cormier, Jonathan  o ARM: MitySOM: TIWI: Add WARN for when kernel is misconfigured
2014-12-18 14:23 Cormier, Jonathan  o [tiwi-v3.2] ARM: MitySOM: TIWI: Support for CL AM335X TIWI module
2014-12-17 17:04 Cormier, Jonathan  o ARM: MitySOM: TIWI: Add BLE PN option
2014-12-17 16:53 Cormier, Jonathan  o ARM: MitySOM: TIWI: Support for CL AM335X TIWI module - defconfig
2014-12-17 16:07 Cormier, Jonathan  o ARM: MitySOM: TIWI: Support for CL AM335X TIWI module - Kconfig
2014-12-18 10:57 Cormier, Jonathan  o ARM: MitySOM: Add/Fix __init and __initdata tags in devkit baseboard
2014-12-18 10:21 Cormier, Jonathan  o ARM: MitySOM: Fix comment and style issue
2014-12-17 17:23 Cormier, Jonathan  o ARM: MitySOM: Fix Section mismatches
2014-07-08 17:08 Cormier,Jonathan   o ARM: MitySOM: Add support for 1GB nand
2014-06-13 14:58 Gregory Dias       o mitysom335x: defconfig: Modified to add OTG support for the kernel on both USB ports.
2014-05-23 13:20 Cormier,Jonathan   o omap2: irq: Enable INTC_PENDING_IRQ3 register check for AM335x
2014-05-22 09:03 Cormier,Jonathan   o [jcormier/micrel_test] phy/micrel: KSZ9031 disable Asym Pause support
2014-05-19 16:01 Cormier,Jonathan   o ARM: MitySOM: config: Enabled micrel phy support
2013-09-19 19:40 Patrice Vilchez    o phy/micrel: Add suspend/resume support to Micrel PHYs
2013-08-13 09:59 Dinh Nguyen        o phy: micrel: Add definitions for common Micrel PHY registers
2013-08-21 01:46 Sean Cross         o net/phy: micrel: Add OF configuration support for ksz9021
2013-08-06 17:29 Jingoo Han         o net: phy: micrel: Staticize ksz8873mll_read_status()
2013-03-10 22:50 Hector Palacios    o phy/micrel: move flag handling to function for common use
2013-03-10 22:50 Hector Palacios    o phy/micrel: Add support for KSZ8031
2013-02-28 08:45 Vlastimil Kosar    o net/phy: micrel: Disable asymmetric pause for KSZ9021
2013-01-23 14:05 David J. Choi      o drivers/net/phy/micrel_phy: Add support for new PHYs
2012-11-21 05:38 Jean-Christophe P~ o net: add micrel KSZ8873MLL switch support
2012-09-23 16:58 Marek Vasut        o phy/micrel: Add missing header to micrel_phy.h
2012-09-23 16:58 Marek Vasut        o phy/micrel: Rename KS80xx to KSZ80xx
2012-09-23 16:58 Marek Vasut        o phy/micrel: Implement support for KSZ8021
2012-07-04 05:44 Christian Hohnsta~ o phylib: Support registering a bunch of drivers
2012-06-17 22:52 Jason Wang         o phy/micrel: change phy_id_mask for KSZ9021 and KS8001
2012-05-21 14:20 Nobuhiro Iwamatsu  o phy/micrel: Fix ID of KSZ9021
2014-05-21 15:20 Cormier,Jonathan   o omap2/devices: Set phy_id to NULL to set it to be autodiscovered
2014-05-21 15:19 Cormier,Jonathan   o net/phy: Add ability to select first phy detected
2014-05-16 10:02 Cormier,Jonathan   o ARM: MitySOM: Changed MityARM to MitySOM in baseboard
2014-05-06 15:57 Gregory Dias       o ARM: MitySOM: Changed a few places in the config file and board file to rebrand from MityARM to MitySOM.
2014-04-08 17:24 Cormier,Jonathan   o ARM: MitySOM: config: Build ti tsc driver as module. Generates large amount of interrupts and normally there is no touchscreen attached.
2014-04-08 11:17 Cormier,Jonathan   o ARM: MitySOM: config: Enable DEVTMPFS in config
2014-02-27 14:57 Cormier,Jonathan   │ o [JCI] [jcormier/JCI] [wanda/JCI] am335x: Update partition scheme for JCI

RE: KSZ9031 phy support for the 3.2 kernel - Added by Timothy Entinger over 7 years ago

Hi Everyone,

Merging in the changes from the tag (mitysom_AM335XPSP_04.06.00.07) worked for us to limit the ethernet speeds for the phy.
I removed the phy fixup function that was being called.
To reduce the speeds I modified the phy config table for the 9031 and set it to basic features instead of gigabit.

.phy_id        = PHY_ID_KSZ9031,
    .phy_id_mask    = 0x00fffff0,
    .name        = "Micrel KSZ9031 Reduced Gigabit PHY",
    .features    = (PHY_BASIC_FEATURES | SUPPORTED_Pause),
    .flags        = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
    .config_init    = kszphy_config_init,
    .config_aneg    = genphy_config_aneg,
    .read_status    = genphy_read_status,
    .ack_interrupt    = kszphy_ack_interrupt,
    .config_intr    = ksz9021_config_intr,
    .suspend    = genphy_suspend,
    .resume        = genphy_resume,
    .driver        = { .owner = THIS_MODULE, },

Thank you for the quick responses and support.

    (1-6/6)
    Go to top
    Add picture from clipboard (Maximum size: 1 GB)