NC-SI PHY Support
Subsystems (3)
cover NC-SI PHY Support
This series introduces support for the NC-SI protocol to u-boot, functionality which so far has only been available in vendor trees.
NC-SI (Network Controller Sideband Interface) is a protocol to manage a sideband connection to a proper network interface, for example a BMC (Baseboard Management Controller) sharing the NIC of the host system. Probing and configuration occurs by communicating with the "remote" NIC via NC-SI control frames (Ethernet header 0x88f8).
Since the RFC[0] the changes have been split out into a few different patches to make the overall changes more obvious. Additionally a few small improvements have been added including adding a check to see if NC-SI is already configured, and marking the PHY bus "reset" as invalid since it does not define a bus.
An example of NC-SI setup before a normal network command:
=> dhcpnet_loop: configuring NCSI first
ethernet at 1e660000: link up, 100 Mbps full-duplex mac:0c:c4:7a:d5:48:43
NCSI: probing channels
NCSI: configuring channel 0
NCSI: configuration done!
BOOTP broadcast 1
BOOTP broadcast 2
DHCP client bound to address 10.61.161.188 (255 ms)
[0]: https://patchwork.ozlabs.org/patch/1107087/
Samuel Mendoza-Jonas (4):
phy: Add support for the NC-SI protocol
phy: Include NC-SI in phy setup
net/ftgmac100: Add NC-SI mode support
net: NC-SI setup and handling
cmd/Kconfig | 6 + cmd/net.c | 18 + drivers/net/ftgmac100.c | 39 +- drivers/net/phy/Kconfig | 4 + drivers/net/phy/Makefile | 1 + drivers/net/phy/ncsi.c | 892 +++++++++++++++++++++++++++++++++++++++ drivers/net/phy/phy.c | 8 + include/net.h | 3 +- include/net/ncsi-pkt.h | 415 ++++++++++++++++++ include/net/ncsi.h | 14 + include/phy.h | 12 + include/phy_interface.h | 2 + net/net.c | 27 +- 13 files changed, 1429 insertions(+), 12 deletions(-) create mode 100644 drivers/net/phy/ncsi.c create mode 100644 include/net/ncsi-pkt.h create mode 100644 include/net/ncsi.h
Signature · 1 line
2.21.0
PATCH 1/4 phy: Add support for the NC-SI protocol
This introduces support for the NC-SI protocol, modelled as a phy driver for other ethernet drivers to consume.
NC-SI (Network Controller Sideband Interface) is a protocol to manage a sideband connection to a proper network interface, for example a BMC (Baseboard Management Controller) sharing the NIC of the host system. Probing and configuration occurs by communicating with the "remote" NIC via NC-SI control frames (Ethernet header 0x88f8).
This implementation is roughly based on the upstream Linux implementation[0], with a reduced feature set and an emphasis on getting a link up as fast as possible rather than probing the full possible topology of the bus.
The current phy model relies on the network being "up", sending NC-SI command frames via net_send_packet() and receiving them from the net_loop() loop (added in a following patch).
The ncsi-pkt.h header[1] is copied from the Linux kernel for consistent field definitions.
[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.h
--- drivers/net/phy/Kconfig | 4 + drivers/net/phy/Makefile | 1 + drivers/net/phy/ncsi.c | 892 +++++++++++++++++++++++++++++++++++++++ include/net.h | 1 + include/net/ncsi-pkt.h | 415 ++++++++++++++++++ include/net/ncsi.h | 14 + include/phy.h | 1 + 7 files changed, 1328 insertions(+) create mode 100644 drivers/net/phy/ncsi.c create mode 100644 include/net/ncsi-pkt.h create mode 100644 include/net/ncsi.h
drivers/net/phy/Kconfig +4 -0
@@ -227,4 +227,8 @@ config PHY_FIXED on, the link is always up with fixed speed and fixed duplex-setting. More information: doc/device-tree-bindings/net/fixed-link.txt +config PHY_NCSI + bool "NC-SI based PHY" + depends on DM_ETH + endif #PHYLIB
drivers/net/phy/Makefile +1 -0
@@ -30,3 +30,4 @@ obj-$(CONFIG_PHY_XILINX) += xilinx_phy.o obj-$(CONFIG_PHY_VITESSE) += vitesse.o obj-$(CONFIG_PHY_MSCC) += mscc.o obj-$(CONFIG_PHY_FIXED) += fixed.o +obj-$(CONFIG_PHY_NCSI) += ncsi.o
drivers/net/phy/ncsi.c new file +892 -0
892 lines not on this page · raw message
include/net.h +1 -0
@@ -350,6 +350,7 @@ struct vlan_ethernet_hdr {#define PROT_VLAN 0x8100/* IEEE 802.1q protocol */ #define PROT_IPV6 0x86dd/* IPv6 over bluebook */ #define PROT_PPP_SES 0x8864/* PPPoE session messages */ +#define PROT_NCSI 0x88f8/* NC-SI control packets */ #define IPPROTO_ICMP 1/* Internet Control Message Protocol */ #define IPPROTO_UDP 17/* User Datagram Protocol */
include/net/ncsi-pkt.h new file +415 -0
415 lines not on this page · raw message
include/net/ncsi.h new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* NC-SI PHY +* +* Copyright (C) 2019, IBM Corporation. +*/ + +#include <common.h> +#include <phy.h> + +bool ncsi_active (void ); +void ncsi_receive (struct ethernet_hdr *et,struct ip_udp_hdr *ip, +unsigned int len); +void ncsi_probe_packages (void );
include/phy.h +1 -0
@@ -17,6 +17,7 @@#include <phy_interface.h> #define PHY_FIXED_ID 0xa5a55a5a +#define PHY_NCSI_ID 0xbeefcafe#define PHY_MAX_ADDR 32
Signature · 1 line
2.21.0
Re: [PATCH 1/4] phy: Add support for the NC-SI protocol
Quoted 18 lines · Samuel Mendoza-Jonas
This introduces support for the NC-SI protocol, modelled as a phy driver for other ethernet drivers to consume.
NC-SI (Network Controller Sideband Interface) is a protocol to manage a sideband connection to a proper network interface, for example a BMC (Baseboard Management Controller) sharing the NIC of the host system. Probing and configuration occurs by communicating with the "remote" NIC via NC-SI control frames (Ethernet header
0x88f8).This implementation is roughly based on the upstream Linux implementation[0], with a reduced feature set and an emphasis on getting a link up as fast as possible rather than probing the full possible topology of the bus.
The current phy model relies on the network being "up", sending NC-SI command frames vianet_send_packet()and receiving them from thenet_loop()loop (added in a following patch).
Quoted 7 lines
The
ncsi-pkt.hheader[1] is copied from the Linux kernel for consistent field definitions.[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.hSigned-off-by Samuel Mendoza-Jonas <[email protected]>
Looks good. Some comments below.
drivers/net/phy/ncsi.c line 208
Quoted 13 lines
drivers/net/phy/ncsi.c new file +12
-0+static int ncsi_validate_rsp (struct ncsi_rsp_pkt *pkt,int payload) +{ +struct ncsi_rsp_pkt_hdr *hdr = &pkt->rsp; +__be32 pchecksum; +u32 checksum; +if (ntohs (hdr->common.length) != payload) { +printf ("NCSI: 0x%02x response has incorrect length %d\n" , + hdr->common.type, hdr->common.length); +return -1 ; + } + + pchecksum =get_unaligned_be32 ((void *)(hdr +1 ) + payload -4 );
Wheee. So the checksum is the last 4-bytes of the payload. I assume it's always longer than 4?
A clarifying comment might help, or try to write it in a different way:
endp = (void *)hdr + sizeof(hdr) + payload; pchecksum = get_unaligned_be32(endp - sizeof(checksum));
or
checksum_offset = sizeof(hdr) + payload - sizeof(checksum);
pchecksum = get_unaligned_be32(payload + checksum_offset);drivers/net/phy/ncsi.c line 211
Quoted 3 lines
drivers/net/phy/ncsi.c new file +3
-0+if (pchecksum !=0 ) { + checksum =ncsi_calculate_checksum ((unsigned char *)hdr, +sizeof (*hdr) + payload -4 );
And then this can be:
checksum = ((unsigned char *)hdr, checksum_offset);
Quoted 10 lines
drivers/net/phy/ncsi.c new file +9
-0+if (pchecksum != checksum) { +printf ("NCSI: 0x%02x response has invalid checksum\n" , + hdr->common.type); +return -1 ; + } + } +static void ncsi_send_sma (unsigned int np,unsigned int nc) +{ +struct ncsi_cmd_sma_pkt cmd;
drivers/net/phy/ncsi.c line 775
Quoted 10 lines
drivers/net/phy/ncsi.c new file +10
-0+unsigned char *addr; + + addr =eth_get_ethaddr (); +if (!addr) { +printf ("NCSI: no MAC address configured\n" ); +return ; + } + +memset (&cmd,0 ,sizeof (cmd)); +memcpy (cmd.mac, addr,6 );
Are there endianness issues with addr here?
drivers/net/phy/ncsi.c line 837
Quoted 13 lines
drivers/net/phy/ncsi.c new file +12
-0+ cmd.index =1 ; + cmd.at_e =1 ; + +ncsi_send_command (np, nc,NCSI_PKT_CMD_SMA , + ((unsigned char *)&cmd) + +sizeof (struct ncsi_cmd_pkt_hdr ), +cmd_payload (NCSI_PKT_CMD_SMA ), true); +} + +int ncsi_probe (struct phy_device *phydev) +{ +// TODO Associate per device
Is this required before we can support multiple NICs?
Quoted 18 lines
drivers/net/phy/ncsi.c new file +18
-0+if (!ncsi_priv) { + ncsi_priv =malloc (sizeof (struct ncsi )); +if (!ncsi_priv) +return -ENOMEM ; +memset (ncsi_priv,0 ,sizeof (struct ncsi )); + } + + phydev->priv = ncsi_priv; + +return 0 ; +} + +int ncsi_startup (struct phy_device *phydev) +{ +/* Set phydev parameters */ + phydev->speed =SPEED_100 ; + phydev->duplex =DUPLEX_FULL ; +/* Normal phy reset is N/A */
drivers/net/phy/ncsi.c line 865
Quoted 10 lines
drivers/net/phy/ncsi.c new file +10
-0+ phydev->flags |=PHY_FLAG_BROKEN_RESET ; + +/* Set initial probe state */ + ncsi_priv->state =NCSI_PROBE_PACKAGE_SP ; + +/* No active package/channel yet */ + ncsi_priv->current_package =NCSI_PACKAGE_MAX ; + ncsi_priv->current_channel =NCSI_CHANNEL_MAX ; + +/* Pretend link works so ftgmac100 sets final bits up */
s/ftgmac100/mac driver/ ?
Quoted 32 lines
drivers/net/phy/ncsi.c new file +27
-0+ phydev->link = true; + +return 0 ; +} + +int ncsi_shutdown (struct phy_device *phydev) +{ +printf ("NCSI: Disabling package %d\n" , ncsi_priv->current_package); +ncsi_send_dp (ncsi_priv->current_package); +return 0 ; +} + +static struct phy_driver ncsi_driver = { + .uid =PHY_NCSI_ID , + .mask =0xffffffff , + .name ="NC-SI" , + .features =PHY_100BT_FEATURES |PHY_DEFAULT_FEATURES | SUPPORTED_100baseT_Full |SUPPORTED_MII , + .probe = ncsi_probe, + .startup = ncsi_startup, + .shutdown = ncsi_shutdown, +}; + +int phy_ncsi_init (void ) +{ +phy_register (&ncsi_driver); +return 0 ; +}
include/net/ncsi-pkt.h line 8
Quoted 8 lines
include/net/ncsi-pkt.h new file +8
-0@@ -0,0 +1,415 @@ +/* +* Copyright Gavin Shan, IBM Corporation 2016. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/
If you grab the version from 5.2-rc3 it has been SPDXified.
include/phy.h line 20
Quoted 7 lines
include/phy.h +1
-0@@ -17,6 +17,7 @@#include <phy_interface.h> #define PHY_FIXED_ID 0xa5a55a5a +#define PHY_NCSI_ID 0xbeefcafe
hmmm...
Quoted 6 lines
include/phy.h +0
-1#define PHY_MAX_ADDR 32 --2.21.0
Re: [PATCH 1/4] phy: Add support for the NC-SI protocol
Quoted 44 lines · Joel Stanley
Quoted 17 lines · Samuel Mendoza-Jonas
This introduces support for the NC-SI protocol, modelled as a phy driver for other ethernet drivers to consume.
NC-SI (Network Controller Sideband Interface) is a protocol to manage a sideband connection to a proper network interface, for example a BMC (Baseboard Management Controller) sharing the NIC of the host system. Probing and configuration occurs by communicating with the "remote" NIC via NC-SI control frames (Ethernet header
0x88f8).This implementation is roughly based on the upstream Linux implementation[0], with a reduced feature set and an emphasis on getting a link up as fast as possible rather than probing the full possible topology of the bus.
The current phy model relies on the network being "up", sending NC-SI command frames vianet_send_packet()and receiving them from thenet_loop()loop (added in a following patch).Quoted 7 lines
The
ncsi-pkt.hheader[1] is copied from the Linux kernel for consistent field definitions.[0]: https://github.com/torvalds/linux/tree/master/net/ncsi
[1]: https://github.com/torvalds/linux/blob/master/net/ncsi/ncsi-pkt.hSigned-off-by Samuel Mendoza-Jonas <[email protected]>Looks good. Some comments below.
drivers/net/phy/ncsi.c line 208
Quoted 12 lines
drivers/net/phy/ncsi.c new file +12
-0+static int ncsi_validate_rsp (struct ncsi_rsp_pkt *pkt,int payload) +{ +struct ncsi_rsp_pkt_hdr *hdr = &pkt->rsp; +__be32 pchecksum; +u32 checksum; +if (ntohs (hdr->common.length) != payload) { +printf ("NCSI: 0x%02x response has incorrect length %d\n" , + hdr->common.type, hdr->common.length); +return -1 ; + } + + pchecksum =get_unaligned_be32 ((void *)(hdr +1 ) + payload -4 );Wheee. So the checksum is the last 4-bytes of the payload. I assume it's always longer than 4?
Quoted 1 line
A clarifying comment might help, or try to write it in a different way:
"Wheee" indeed. I kept this roughly as it is in the kernel so I could more easily verify it was doing the right thing; now that it's more tested I'll do something like below so it's less traumatic.
Quoted 30 lines
endp = (void *)hdr + sizeof(hdr) + payload; pchecksum =
get_unaligned_be32(endp - sizeof(checksum));or
checksum_offset = sizeof(hdr) + payload - sizeof(checksum); pchecksum = get_unaligned_be32(payload + checksum_offset);drivers/net/phy/ncsi.c line 211
Quoted 3 lines
drivers/net/phy/ncsi.c new file +3
-0+if (pchecksum !=0 ) { + checksum =ncsi_calculate_checksum ((unsigned char *)hdr, +sizeof (*hdr) + payload -4 );And then this can be:
checksum = ((unsigned char *)hdr, checksum_offset);Quoted 13 lines
drivers/net/phy/ncsi.c new file +13
-0+if (pchecksum != checksum) { +printf ("NCSI: 0x%02x response has invalid checksum\n" , + hdr->common.type); +return -1 ; + } + } +static void ncsi_send_sma (unsigned int np,unsigned int nc) +{ +struct ncsi_cmd_sma_pkt cmd; +unsigned char *addr; + + addr =eth_get_ethaddr (); +if (!addr) {
Quoted 8 lines
drivers/net/phy/ncsi.c line 775
Quoted 6 lines
drivers/net/phy/ncsi.c new file +6
-0+printf ("NCSI: no MAC address configured\n" ); +return ; + } + +memset (&cmd,0 ,sizeof (cmd)); +memcpy (cmd.mac, addr,6 );Are there endianness issues with addr here?
Aha, will fixup.
Quoted 15 lines
drivers/net/phy/ncsi.c line 837
Quoted 13 lines
drivers/net/phy/ncsi.c new file +12
-0+ cmd.index =1 ; + cmd.at_e =1 ; + +ncsi_send_command (np, nc,NCSI_PKT_CMD_SMA , + ((unsigned char *)&cmd) + +sizeof (struct ncsi_cmd_pkt_hdr ), +cmd_payload (NCSI_PKT_CMD_SMA ), true); +} + +int ncsi_probe (struct phy_device *phydev) +{ +// TODO Associate per device Is this required before we can support multiple NICs?
Yes, I'll chase this up.
Quoted 23 lines
Quoted 23 lines
drivers/net/phy/ncsi.c new file +22
-0+if (!ncsi_priv) { + ncsi_priv =malloc (sizeof (struct ncsi )); +if (!ncsi_priv) +return -ENOMEM ; +memset (ncsi_priv,0 ,sizeof (struct ncsi )); + } + + phydev->priv = ncsi_priv; + +return 0 ; +} + +int ncsi_startup (struct phy_device *phydev) +{ +/* Set phydev parameters */ + phydev->speed =SPEED_100 ; + phydev->duplex =DUPLEX_FULL ; +/* Normal phy reset is N/A */ + phydev->flags |=PHY_FLAG_BROKEN_RESET ; + +/* Set initial probe state */ + ncsi_priv->state =NCSI_PROBE_PACKAGE_SP ;
Quoted 8 lines
drivers/net/phy/ncsi.c line 865
Quoted 6 lines
drivers/net/phy/ncsi.c new file +6
-0+ +/* No active package/channel yet */ + ncsi_priv->current_package =NCSI_PACKAGE_MAX ; + ncsi_priv->current_channel =NCSI_CHANNEL_MAX ; + +/* Pretend link works so ftgmac100 sets final bits up */ s/ftgmac100/mac driver/ ?
Ack
Quoted 33 lines
Quoted 33 lines
drivers/net/phy/ncsi.c new file +27
-0+ phydev->link = true; + +return 0 ; +} + +int ncsi_shutdown (struct phy_device *phydev) +{ +printf ("NCSI: Disabling package %d\n" , ncsi_priv->current_package); +ncsi_send_dp (ncsi_priv->current_package); +return 0 ; +} + +static struct phy_driver ncsi_driver = { + .uid =PHY_NCSI_ID , + .mask =0xffffffff , + .name ="NC-SI" , + .features =PHY_100BT_FEATURES |PHY_DEFAULT_FEATURES | SUPPORTED_100baseT_Full |SUPPORTED_MII , + .probe = ncsi_probe, + .startup = ncsi_startup, + .shutdown = ncsi_shutdown, +}; + +int phy_ncsi_init (void ) +{ +phy_register (&ncsi_driver); +return 0 ; +}include/net/ncsi-pkt.h new file +2
-0@@ -0,0 +1,415 @@ +/* +* Copyright Gavin Shan, IBM Corporation 2016.
Quoted 8 lines
include/net/ncsi-pkt.h line 8
Quoted 6 lines
include/net/ncsi-pkt.h new file +6
-0+* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ If you grab the version from 5.2-rc3 it has been SPDXified.
Cheers, will do.
Quoted 10 lines
include/phy.h line 20
Quoted 8 lines
include/phy.h +1
-0@@ -17,6 +17,7 @@#include <phy_interface.h> #define PHY_FIXED_ID 0xa5a55a5a +#define PHY_NCSI_ID 0xbeefcafehmmm...
Haha - suggestions welcome?
Quoted 6 lines
Quoted 6 lines
include/phy.h +0
-1#define PHY_MAX_ADDR 32 --2.21.0
PATCH 2/4 phy: Include NC-SI in phy setup
In reply to Samuel Mendoza-JonasAdd NC-SI to the usual phy handling. This makes two notable changes:
- Somewhat similar to a fixed phy, phy_connect() will create an NC-SI phy if CONFIG_PHY_NCSI is defined.
- An early return is added to phy_read() and phy_write() to handle a case like the NC-SI phy which does not define a bus.
--- drivers/net/phy/phy.c | 8 ++++++++ include/phy.h | 11 +++++++++++ include/phy_interface.h | 2 ++ 3 files changed, 21 insertions(+)
drivers/net/phy/phy.c +8 -0
@@ -527,6 +527,9 @@ int phy_init(void)#endif #ifdef CONFIG_PHY_FIXED phy_fixed_init (); +#endif +#ifdef CONFIG_PHY_NCSI +phy_ncsi_init ();#endif return 0 ; }
@@ -902,6 +905,11 @@ struct phy_device *phy_connect(struct mii_dev *bus, int addr, sn = fdt_next_subnode(gd->fdt_blob, sn); }#endif + +#ifdef CONFIG_PHY_NCSI + phydev =phy_device_create (bus,0 ,PHY_NCSI_ID , interface); +#endif +if (!phydev) phydev =phy_find_by_mask (bus,1 << addr, interface);
include/phy.h +11 -0
@@ -154,6 +154,11 @@ static inline int phy_read(struct phy_device *phydev, int devad, int regnum) {struct mii_dev *bus = phydev->bus; +if (!bus || !bus->read) { +debug ("%s: No bus configured\n" , __func__); +return -1 ; + } +return bus->read (bus, phydev->addr, devad, regnum); }
@@ -162,6 +167,11 @@ static inline int phy_write(struct phy_device *phydev, int devad, int regnum, {struct mii_dev *bus = phydev->bus; +if (!bus || !bus->read) { +debug ("%s: No bus configured\n" , __func__); +return -1 ; + } +return bus->write (bus, phydev->addr, devad, regnum, val); }
@@ -241,6 +251,7 @@ int phy_vitesse_init(void);int phy_xilinx_init (void );int phy_mscc_init (void );int phy_fixed_init (void ); +int phy_ncsi_init (void );int board_phy_config (struct phy_device *phydev);int get_phy_id (struct mii_dev *bus,int addr,int devad,u32 *phy_id);
include/phy_interface.h +2 -0
@@ -31,6 +31,7 @@ typedef enum {PHY_INTERFACE_MODE_XLAUI ,PHY_INTERFACE_MODE_CAUI2 ,PHY_INTERFACE_MODE_CAUI4 , +PHY_INTERFACE_MODE_NCSI ,PHY_INTERFACE_MODE_NONE ,/* Must be last */ PHY_INTERFACE_MODE_COUNT,
@@ -58,6 +59,7 @@ static const char * const phy_interface_strings[] = { [PHY_INTERFACE_MODE_XLAUI] = "xlaui4", [PHY_INTERFACE_MODE_CAUI2] = "caui2", [PHY_INTERFACE_MODE_CAUI4] = "caui4", + [PHY_INTERFACE_MODE_NCSI] = "NC-SI", [PHY_INTERFACE_MODE_NONE] = "", };
Signature · 1 line
2.21.0
Re: [PATCH 2/4] phy: Include NC-SI in phy setup
Quoted 8 lines · Samuel Mendoza-Jonas
Add NC-SI to the usual phy handling. This makes two notable changes:
- Somewhat similar to a fixed phy,phy_connect()will create an NC-SI phy ifCONFIG_PHY_NCSIis defined.
- An early return is added tophy_read()andphy_write()to handle a case like the NC-SI phy which does not define a bus.Signed-off-by Samuel Mendoza-Jonas <[email protected]>
PATCH 3/4 net/ftgmac100: Add NC-SI mode support
In reply to Samuel Mendoza-JonasUpdate the ftgmac100 driver to support NC-SI instead of an mdio phy where available. This is a common setup for Aspeed AST2x00 platforms.
NC-SI mode is determined from the device-tree if either phy-mode sets it or the use-ncsi property exists. If set then normal mdio setup is skipped in favour of the NC-SI phy.
--- drivers/net/ftgmac100.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-)
drivers/net/ftgmac100.c +29 -10
@@ -18,6 +18,7 @@#include <wait_bit.h> #include <linux/io.h> #include <linux/iopoll.h> +#include <net/ncsi.h> #include "ftgmac100.h"
@@ -81,6 +82,7 @@ struct ftgmac100_data {struct mii_dev *bus;u32 phy_mode;u32 max_speed; +bool ncsi_mode;struct clk_bulk clks;
@@ -181,7 +183,7 @@ static int ftgmac100_phy_adjust_link(struct ftgmac100_data *priv)struct phy_device *phydev = priv->phydev;u32 maccr; -if (!phydev->link) { +if (!phydev->link && !priv->ncsi_mode) {dev_err (phydev->dev,"No link\n" );return -EREMOTEIO ; }
@@ -217,7 +219,8 @@ static int ftgmac100_phy_init(struct udevice *dev)if (!phydev)return -ENODEV ; - phydev->supported &=PHY_GBIT_FEATURES ; +if (!priv->ncsi_mode) + phydev->supported &=PHY_GBIT_FEATURES ;if (priv->max_speed) { ret =phy_set_supported (phydev, priv->max_speed);if (ret)
@@ -275,7 +278,8 @@ static void ftgmac100_stop(struct udevice *dev)writel (0 , &ftgmac100->maccr); -phy_shutdown (priv->phydev); +if (!priv->ncsi_mode) +phy_shutdown (priv->phydev); }static int ftgmac100_start (struct udevice *dev)
@@ -513,6 +517,7 @@ static int ftgmac100_ofdata_to_platdata(struct udevice *dev) pdata->iobase =devfdt_get_addr (dev); pdata->phy_interface =-1 ; phy_mode =dev_read_string (dev,"phy-mode" ); +if (phy_mode) pdata->phy_interface =phy_get_interface_by_name (phy_mode);if (pdata->phy_interface ==-1 ) {
@@ -537,8 +542,13 @@ static int ftgmac100_probe(struct udevice *dev) {struct eth_pdata *pdata =dev_get_platdata (dev);struct ftgmac100_data *priv =dev_get_priv (dev); +const char *phy_mode;int ret; + phy_mode =dev_read_string (dev,"phy-mode" ); + priv->ncsi_mode =dev_read_bool (dev,"use-ncsi" ) || + (phy_mode &&strcmp (phy_mode,"NC-SI" ) ==0 ); + priv->iobase = (struct ftgmac100 *)pdata->iobase; priv->phy_mode = pdata->phy_interface; priv->max_speed = pdata->max_speed;
@@ -548,10 +558,15 @@ static int ftgmac100_probe(struct udevice *dev)if (ret) goto out; - ret =ftgmac100_mdio_init (dev); -if (ret) { -dev_err (dev,"Failed to initialize mdiobus: %d\n" , ret); - goto out; +if (priv->ncsi_mode) { +printf ("%s - NCSI detected\n" , __func__); + }else { + ret =ftgmac100_mdio_init (dev); +if (ret) { +dev_err (dev,"Failed to initialize mdiobus: %d\n" , ret); + goto out; + } + } ret =ftgmac100_phy_init (dev);
@@ -571,9 +586,13 @@ static int ftgmac100_remove(struct udevice *dev) {struct ftgmac100_data *priv =dev_get_priv (dev); -free (priv->phydev); -mdio_unregister (priv->bus); -mdio_free (priv->bus); +if (!priv->ncsi_mode) { +free (priv->phydev); +mdio_unregister (priv->bus); +mdio_free (priv->bus); + }else { +free (priv->phydev); + }clk_release_bulk (&priv->clks);return 0 ;
Signature · 1 line
2.21.0
Re: [PATCH 3/4] net/ftgmac100: Add NC-SI mode support
Quoted 22 lines · Samuel Mendoza-Jonas
Update the ftgmac100 driver to support NC-SI instead of an mdio phy where available. This is a common setup for Aspeed AST2x00 platforms.
NC-SI mode is determined from the device-tree if either phy-mode sets it or the use-ncsi property exists. If set then normal mdio setup is skipped in favour of the NC-SI phy.
Signed-off-by Samuel Mendoza-Jonas <[email protected]>--- drivers/net/ftgmac100.c | 39 +++++++++++++++++++++++++++++----------drivers/net/ftgmac100.c +1
-1@@ -181,7 +183,7 @@ static int ftgmac100_phy_adjust_link(struct ftgmac100_data *priv)struct phy_device *phydev = priv->phydev;u32 maccr; -if (!phydev->link) { +if (!phydev->link && !priv->ncsi_mode) {dev_err (phydev->dev,"No link\n" );return -EREMOTEIO ; }
drivers/net/ftgmac100.c static int ftgmac100_phy_init(struct udevice *dev) · line 223
Quoted 6 lines
drivers/net/ftgmac100.c +2
-1@@ -217,7 +219,8 @@ static int ftgmac100_phy_init(struct udevice *dev)if (!phydev)return -ENODEV ; - phydev->supported &=PHY_GBIT_FEATURES ; +if (!priv->ncsi_mode) + phydev->supported &=PHY_GBIT_FEATURES ;
Instead of hiding this behind ncsi_mode I was assuming the ncsi "phy" driver would answer these questions through the phy_read callbacks.
If you don't think that is going to work then this solution isn't too invasive, and we've been using this in Linux for a while, so we know it works.
Re: [PATCH 3/4] net/ftgmac100: Add NC-SI mode support
Quoted 31 lines · Joel Stanley
Quoted 20 lines · Samuel Mendoza-Jonas
Update the ftgmac100 driver to support NC-SI instead of an mdio phy where available. This is a common setup for Aspeed AST2x00 platforms.
NC-SI mode is determined from the device-tree if either phy-mode sets it or the use-ncsi property exists. If set then normal mdio setup is skipped in favour of the NC-SI phy.
Signed-off-by Samuel Mendoza-Jonas <[email protected]>--- drivers/net/ftgmac100.c | 39 +++++++++++++++++++++++++++++----------drivers/net/ftgmac100.c +1
-1@@ -181,7 +183,7 @@ static int ftgmac100_phy_adjust_link(struct ftgmac100_data *priv)struct phy_device *phydev = priv->phydev;u32 maccr; -if (!phydev->link) { +if (!phydev->link && !priv->ncsi_mode) {dev_err (phydev->dev,"No link\n" );return -EREMOTEIO ; }drivers/net/ftgmac100.c static int ftgmac100_phy_init(struct udevice *dev) · line 223
Quoted 6 lines
drivers/net/ftgmac100.c +2
-1@@ -217,7 +219,8 @@ static int ftgmac100_phy_init(struct udevice *dev)if (!phydev)return -ENODEV ; - phydev->supported &=PHY_GBIT_FEATURES ; +if (!priv->ncsi_mode) + phydev->supported &=PHY_GBIT_FEATURES ;Instead of hiding this behind
ncsi_modeI was assuming the ncsi "phy" driver would answer these questions through thephy_readcallbacks.
Quoted 3 lines
If you don't think that is going to work then this solution isn't too invasive, and we've been using this in Linux for a while, so we know it works.
Having this purely transparent would indeed be nice, but it's been a little awkward fitting NCSI into the u-boot model. phy_read, etc don't really make sense for a NCSI "PHY" like in the Linux model since there aren't any registers as such to query - thus checking the device-tree and skipping the normal mdio bus setup.
I'll have a bit more of a think about the driver model, and probably exactly how Aspeed (for example) hooks this up; maybe there's a way we can fit in to the more usual model.
PATCH 4/4 net: NC-SI setup and handling
In reply to Samuel Mendoza-JonasAdd the handling of NC-SI ethernet frames, and add a check at the start of net_loop() to configure NC-SI before starting other network commands. This also adds an "ncsi" command to manually start NC-SI configuration.
--- cmd/Kconfig | 6 ++++++ cmd/net.c | 18 ++++++++++++++++++ include/net.h | 2 +- net/net.c | 27 ++++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 2 deletions(-)
cmd/Kconfig +6 -0
@@ -1296,6 +1296,12 @@ config CMD_LINK_LOCAL help Acquire a network IP address using the link-local protocol +config CMD_NCSI + bool "ncsi" + depends on PHY_NCSI + help + Configure the attached NIC via NC-SI + endif config CMD_ETHSW
cmd/net.c +18 -0
@@ -457,3 +457,21 @@ U_BOOT_CMD( );#endif /* CONFIG_CMD_LINK_LOCAL */ + +#if defined(CONFIG_CMD_NCSI ) +static int do_ncsi (cmd_tbl_t *cmdtp,int flag,int argc, +char *const argv[]) +{ +if (net_loop (NCSI ) <0 ) +return CMD_RET_FAILURE ; + +return CMD_RET_SUCCESS ; +} + +U_BOOT_CMD ( + ncsi,1 ,1 , do_ncsi, +"Configure attached NIC via NC-SI" , +"" +); + +#endif /* CONFIG_CMD_NCSI */
include/net.h +1 -1
@@ -538,7 +538,7 @@ extern int net_restart_wrap; /* Tried all network devices */enum proto_t {BOOTP ,RARP ,ARP ,TFTPGET ,DHCP ,PING ,DNS ,NFS ,CDP ,NETCONS ,SNTP , -TFTPSRV ,TFTPPUT ,LINKLOCAL ,FASTBOOT ,WOL +TFTPSRV ,TFTPPUT ,LINKLOCAL ,FASTBOOT ,WOL ,NCSI };extern char net_boot_file_name[1024 ];/* Boot File name */
net/net.c +26 -1
@@ -95,6 +95,7 @@#include <net.h> #include <net/fastboot.h> #include <net/tftp.h> +#include <net/ncsi.h> #if defined(CONFIG_LED_STATUS )#include <miiphy.h> #include <status_led.h>
@@ -411,6 +412,16 @@ int net_loop(enum proto_t protocol) net_try_count =1 ;debug_cond (DEBUG_INT_STATE ,"--- net_loop Entry\n" ); +#ifdef CONFIG_PHY_NCSI +if (protocol !=NCSI && !ncsi_active ()) { +printf ("%s: configuring NCSI first\n" , __func__); +if (net_loop (NCSI ) <0 ) +return ret; +eth_init_state_only (); + goto restart; + } +#endif +bootstage_mark_name (BOOTSTAGE_ID_ETH_START ,"eth_start" );net_init ();if (eth_is_on_demand_init () || protocol !=NETCONS ) {
@@ -424,6 +435,7 @@ int net_loop(enum proto_t protocol) }else {eth_init_state_only (); } + restart: #ifdef CONFIG_USB_KEYBOARD net_busy_flag =0 ;
@@ -530,6 +542,11 @@ restart:case WOL :wol_start ();break ; +#endif +#if defined(CONFIG_CMD_NCSI ) +case NCSI : +ncsi_probe_packages (); +break ;#endif default :break ;
@@ -641,7 +658,7 @@ restart:env_set_hex ("filesize" , net_boot_file_size);env_set_hex ("fileaddr" , load_addr); } -if (protocol !=NETCONS ) +if (protocol !=NETCONS && protocol !=NCSI )eth_halt ();else eth_halt_state_only ();
@@ -1324,6 +1341,11 @@ void net_process_received_packet(uchar *in_packet, int len)case PROT_WOL :wol_receive (ip, len);break ; +#endif +#ifdef CONFIG_PHY_NCSI +case PROT_NCSI : +ncsi_receive (et, ip, len); +break ;#endif } }
@@ -1385,6 +1407,9 @@ common:#ifdef CONFIG_CMD_RARP case RARP : +#endif +#ifdef CONFIG_CMD_NCSI +case NCSI :#endif case BOOTP :case CDP :
Signature · 1 line
2.21.0
Re: [PATCH 4/4] net: NC-SI setup and handling
Quoted 6 lines · Samuel Mendoza-Jonas
Add the handling of NC-SI ethernet frames, and add a check at the start of
net_loop()to configure NC-SI before starting other network commands. This also adds an "ncsi" command to manually start NC-SI configuration.Signed-off-by Samuel Mendoza-Jonas <[email protected]>
We need the u-boot net specialists to weigh in, but this looks okay to me. Please clarify the help text for the NCSI command, then add:
cmd/Kconfig config CMD_LINK_LOCAL · line 1303
Quoted 11 lines
cmd/Kconfig +5
-0@@ -1296,6 +1296,12 @@ config CMD_LINK_LOCAL help Acquire a network IP address using the link-local protocol +config CMD_NCSI + bool "ncsi" + depends on PHY_NCSI + help + Configure the attached NIC via NC-SI
Can we clarify in the text if we need the 'ncsi' command to use any NC-SI attached NIC, or if it's more for ncsi and network debugging?
Re: [PATCH 4/4] net: NC-SI setup and handling
Quoted 18 lines · Joel Stanley
Quoted 5 lines · Samuel Mendoza-Jonas
Add the handling of NC-SI ethernet frames, and add a check at the start of
net_loop()to configure NC-SI before starting other network commands. This also adds an "ncsi" command to manually start NC-SI configuration.Signed-off-by Samuel Mendoza-Jonas <[email protected]>We need the u-boot net specialists to weigh in, but this looks okay to me. Please clarify the help text for the NCSI command, then add:
Reviewed-by Joel Stanley <[email protected]>Quoted 6 lines
cmd/Kconfig +0
-0@@ -1296,6 +1296,12 @@ config CMD_LINK_LOCAL help Acquire a network IP address using the link-local protocol
Quoted 8 lines
cmd/Kconfig config CMD_LINK_LOCAL · line 1303
Quoted 5 lines
cmd/Kconfig +5
-0+config CMD_NCSI + bool "ncsi" + depends on PHY_NCSI + help + Configure the attached NIC via NC-SICan we clarify in the text if we need the 'ncsi' command to use any NC-SI attached NIC, or if it's more for ncsi and network debugging?
Can do - the command manually kicks off configuration of the NC-SI topology, but isn't needed in normal use.