Skip to contentSkip to conversation

Refactoring for GMA command

PATCH Superseded Ivan Mikhaylov 3 participants 8 messages Apr 12, 2023 – Apr 22, 2023

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Refactoring for GMA command

Make one GMA function for all manufacturers, change ndo_set_mac_address to dev_set_mac_address for notifiying net layer about MAC change which ndo_set_mac_address doesn't do.

Add mac-address-increment option for possibility to control MAC address assignment on BMC via GMA command.

Ivan Mikhaylov (4):
net/ncsi: make one oem_gma function for all mfr id net/ncsi: change from ndo_set_mac_address to dev_set_mac_address net/ftgmac100: add mac-address-increment option for GMA command from
NC-SI
net/ncsi: add shift MAC address property

 .../devicetree/bindings/net/ftgmac100.txt     |   4 +
 net/ncsi/ncsi-rsp.c                           | 108 ++++++------------
 2 files changed, 41 insertions(+), 71 deletions(-)
Signature · 1 line
2.40.0
#1 lore raw

PATCH 1/4 net/ncsi: make one oem_gma function for all mfr id

Make the one Get Mac Address function for all manufacturers and change this call in handlers accordingly.

---
 net/ncsi/ncsi-rsp.c | 88 ++++++++++-----------------------------------
 1 file changed, 19 insertions(+), 69 deletions(-)
net/ncsi/ncsi-rsp.c +19 -69
index 6447a09932f5..91c42253a711 100644
@@ -611,14 +611,15 @@ static int ncsi_rsp_handler_snfc(struct ncsi_request *nr)
 	return 0;
 }
 
-/* Response handler for Mellanox command Get Mac Address */
-static int ncsi_rsp_handler_oem_mlx_gma(struct ncsi_request *nr)
+/* Response handler for Get Mac Address command */
+static int ncsi_rsp_handler_oem_gma(struct ncsi_request *nr, int mfr_id)
 {
 	struct ncsi_dev_priv *ndp = nr->ndp;
 	struct net_device *ndev = ndp->ndev.dev;
 	const struct net_device_ops *ops = ndev->netdev_ops;
 	struct ncsi_rsp_oem_pkt *rsp;
 	struct sockaddr saddr;
+	u32 mac_addr_off = 0;
 	int ret = 0;
 
 	/* Get the response header */
@@ -626,7 +627,19 @@ static int ncsi_rsp_handler_oem_mlx_gma(struct ncsi_request *nr)
 
 	saddr.sa_family = ndev->type;
 	ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
-	memcpy(saddr.sa_data, &rsp->data[MLX_MAC_ADDR_OFFSET], ETH_ALEN);
+	if (mfr_id == NCSI_OEM_MFR_BCM_ID)
+		mac_addr_off = BCM_MAC_ADDR_OFFSET;
+	else if (mfr_id == NCSI_OEM_MFR_MLX_ID)
+		mac_addr_off = MLX_MAC_ADDR_OFFSET;
+	else if (mfr_id == NCSI_OEM_MFR_INTEL_ID)
+		mac_addr_off = INTEL_MAC_ADDR_OFFSET;
+
+	memcpy(saddr.sa_data, &rsp->data[mac_addr_off], ETH_ALEN);
+	if (mfr_id == NCSI_OEM_MFR_BCM_ID || mfr_id == NCSI_OEM_MFR_INTEL_ID)
+		eth_addr_inc((u8 *)saddr.sa_data);
+	if (!is_valid_ether_addr((const u8 *)saddr.sa_data))
+		return -ENXIO;
+
 	/* Set the flag for GMA command which should only be called once */
 	ndp->gma_flag = 1;
 
@@ -649,41 +662,10 @@ static int ncsi_rsp_handler_oem_mlx(struct ncsi_request *nr)
 
 	if (mlx->cmd == NCSI_OEM_MLX_CMD_GMA &&
 	    mlx->param == NCSI_OEM_MLX_CMD_GMA_PARAM)
-		return ncsi_rsp_handler_oem_mlx_gma(nr);
+		return ncsi_rsp_handler_oem_gma(nr, NCSI_OEM_MFR_MLX_ID);
 	return 0;
 }
 
-/* Response handler for Broadcom command Get Mac Address */
-static int ncsi_rsp_handler_oem_bcm_gma(struct ncsi_request *nr)
-{
-	struct ncsi_dev_priv *ndp = nr->ndp;
-	struct net_device *ndev = ndp->ndev.dev;
-	const struct net_device_ops *ops = ndev->netdev_ops;
-	struct ncsi_rsp_oem_pkt *rsp;
-	struct sockaddr saddr;
-	int ret = 0;
-
-	/* Get the response header */
-	rsp = (struct ncsi_rsp_oem_pkt *)skb_network_header(nr->rsp);
-
-	saddr.sa_family = ndev->type;
-	ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
-	memcpy(saddr.sa_data, &rsp->data[BCM_MAC_ADDR_OFFSET], ETH_ALEN);
-	/* Increase mac address by 1 for BMC's address */
-	eth_addr_inc((u8 *)saddr.sa_data);
-	if (!is_valid_ether_addr((const u8 *)saddr.sa_data))
-		return -ENXIO;
-
-	/* Set the flag for GMA command which should only be called once */
-	ndp->gma_flag = 1;
-
-	ret = ops->ndo_set_mac_address(ndev, &saddr);
-	if (ret < 0)
-		netdev_warn(ndev, "NCSI: 'Writing mac address to device failed\n");
-
-	return ret;
-}
-
 /* Response handler for Broadcom card */
 static int ncsi_rsp_handler_oem_bcm(struct ncsi_request *nr)
 {
@@ -695,42 +677,10 @@ static int ncsi_rsp_handler_oem_bcm(struct ncsi_request *nr)
 	bcm = (struct ncsi_rsp_oem_bcm_pkt *)(rsp->data);
 
 	if (bcm->type == NCSI_OEM_BCM_CMD_GMA)
-		return ncsi_rsp_handler_oem_bcm_gma(nr);
+		return ncsi_rsp_handler_oem_gma(nr, NCSI_OEM_MFR_BCM_ID);
 	return 0;
 }
 
-/* Response handler for Intel command Get Mac Address */
-static int ncsi_rsp_handler_oem_intel_gma(struct ncsi_request *nr)
-{
-	struct ncsi_dev_priv *ndp = nr->ndp;
-	struct net_device *ndev = ndp->ndev.dev;
-	const struct net_device_ops *ops = ndev->netdev_ops;
-	struct ncsi_rsp_oem_pkt *rsp;
-	struct sockaddr saddr;
-	int ret = 0;
-
-	/* Get the response header */
-	rsp = (struct ncsi_rsp_oem_pkt *)skb_network_header(nr->rsp);
-
-	saddr.sa_family = ndev->type;
-	ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
-	memcpy(saddr.sa_data, &rsp->data[INTEL_MAC_ADDR_OFFSET], ETH_ALEN);
-	/* Increase mac address by 1 for BMC's address */
-	eth_addr_inc((u8 *)saddr.sa_data);
-	if (!is_valid_ether_addr((const u8 *)saddr.sa_data))
-		return -ENXIO;
-
-	/* Set the flag for GMA command which should only be called once */
-	ndp->gma_flag = 1;
-
-	ret = ops->ndo_set_mac_address(ndev, &saddr);
-	if (ret < 0)
-		netdev_warn(ndev,
-			    "NCSI: 'Writing mac address to device failed\n");
-
-	return ret;
-}
-
 /* Response handler for Intel card */
 static int ncsi_rsp_handler_oem_intel(struct ncsi_request *nr)
 {
@@ -742,7 +692,7 @@ static int ncsi_rsp_handler_oem_intel(struct ncsi_request *nr)
 	intel = (struct ncsi_rsp_oem_intel_pkt *)(rsp->data);
 
 	if (intel->cmd == NCSI_OEM_INTEL_CMD_GMA)
-		return ncsi_rsp_handler_oem_intel_gma(nr);
+		return ncsi_rsp_handler_oem_gma(nr, NCSI_OEM_MFR_INTEL_ID);
 
 	return 0;
 }
Signature · 1 line
2.40.0
#2 lore raw

PATCH 2/4 net/ncsi: change from ndo_set_mac_address to dev_set_mac_address

In reply to Ivan Mikhaylov

Change ndo_set_mac_address to dev_set_mac_address because dev_set_mac_address provides a way to notify network layer about MAC change. In other case, services may not aware about MAC change and keep using old one which set from network adapter driver.

As example, DHCP client from systemd do not update MAC address without notification from net subsystem which leads to the problem with acquiring the right address from DHCP server.

---
 net/ncsi/ncsi-rsp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/ncsi/ncsi-rsp.c +3 -2
index 91c42253a711..069c2659074b 100644
@@ -616,7 +616,6 @@ static int ncsi_rsp_handler_oem_gma(struct ncsi_request *nr, int mfr_id)
 {
 	struct ncsi_dev_priv *ndp = nr->ndp;
 	struct net_device *ndev = ndp->ndev.dev;
-	const struct net_device_ops *ops = ndev->netdev_ops;
 	struct ncsi_rsp_oem_pkt *rsp;
 	struct sockaddr saddr;
 	u32 mac_addr_off = 0;
@@ -643,7 +642,9 @@ static int ncsi_rsp_handler_oem_gma(struct ncsi_request *nr, int mfr_id)
 	/* Set the flag for GMA command which should only be called once */
 	ndp->gma_flag = 1;
 
-	ret = ops->ndo_set_mac_address(ndev, &saddr);
+	rtnl_lock();
+	ret = dev_set_mac_address(ndev, &saddr, NULL);
+	rtnl_unlock();
 	if (ret < 0)
 		netdev_warn(ndev, "NCSI: 'Writing mac address to device failed\n");
 
Signature · 1 line
2.40.0
#3 lore raw

PATCH 3/4 net/ftgmac100: add mac-address-increment option for GMA command from NC-SI

In reply to Ivan Mikhaylov

Add s32 mac-address-increment option for Get MAC Address command from NC-SI.

---
 Documentation/devicetree/bindings/net/ftgmac100.txt | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/net/ftgmac100.txt +4 -0
index 29234021f601..7ef5329d888d 100644
@@ -22,6 +22,10 @@ Optional properties:
 - use-ncsi: Use the NC-SI stack instead of an MDIO PHY. Currently assumes
   rmii (100bT) but kept as a separate property in case NC-SI grows support
   for a gigabit link.
+- mac-address-increment: Increment the MAC address taken by GMA command via
+  NC-SI. Specifies a signed number to be added to the host MAC address as
+  obtained by the OEM GMA command. If not specified, 1 is used by default
+  for Broadcom and Intel network cards, 0 otherwise.
 - no-hw-checksum: Used to disable HW checksum support. Here for backward
   compatibility as the driver now should have correct defaults based on
   the SoC.
Signature · 1 line
2.40.0
#7 lore raw

PATCH 4/4 net/ncsi: add shift MAC address property

In reply to Ivan Mikhaylov

Add the shift MAC address property for GMA command which provides which shift should be used but keep old one values for backward compatibility.

---
 net/ncsi/ncsi-rsp.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
net/ncsi/ncsi-rsp.c +16 -1
index 069c2659074b..1f108db34d85 100644
@@ -9,6 +9,8 @@
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/skbuff.h>
+#include <linux/platform_device.h>
+#include <linux/of.h>
 
 #include <net/ncsi.h>
 #include <net/net_namespace.h>
@@ -616,9 +618,12 @@ static int ncsi_rsp_handler_oem_gma(struct ncsi_request *nr, int mfr_id)
 {
 	struct ncsi_dev_priv *ndp = nr->ndp;
 	struct net_device *ndev = ndp->ndev.dev;
+	struct platform_device *pdev;
 	struct ncsi_rsp_oem_pkt *rsp;
 	struct sockaddr saddr;
 	u32 mac_addr_off = 0;
+	s32 shift_mac_addr = 0;
+	u64 mac_addr;
 	int ret = 0;
 
 	/* Get the response header */
@@ -635,7 +640,17 @@ static int ncsi_rsp_handler_oem_gma(struct ncsi_request *nr, int mfr_id)
 
 	memcpy(saddr.sa_data, &rsp->data[mac_addr_off], ETH_ALEN);
 	if (mfr_id == NCSI_OEM_MFR_BCM_ID || mfr_id == NCSI_OEM_MFR_INTEL_ID)
-		eth_addr_inc((u8 *)saddr.sa_data);
+		shift_mac_addr = 1;
+
+	pdev = to_platform_device(ndev->dev.parent);
+	if (pdev)
+		of_property_read_s32(pdev->dev.of_node,
+				     "mac-address-increment", &shift_mac_addr);
+
+	/* Increase mac address by shift value for BMC's address */
+	mac_addr = ether_addr_to_u64((u8 *)saddr.sa_data);
+	mac_addr += shift_mac_addr;
+	u64_to_ether_addr(mac_addr, (u8 *)saddr.sa_data);
 	if (!is_valid_ether_addr((const u8 *)saddr.sa_data))
 		return -ENXIO;
 
Signature · 1 line
2.40.0
#4 lore raw

Re: [PATCH 3/4] net/ftgmac100: add mac-address-increment option for GMA command from NC-SI

In reply to Ivan Mikhaylov
Quoted 7 lines · Ivan Mikhaylov

Add s32 mac-address-increment option for Get MAC Address command from NC-SI.

---
 Documentation/devicetree/bindings/net/ftgmac100.txt | 4 ++++

Use subject prefixes matching the subsystem (which you can get for example with git log --oneline -- DIRECTORY_OR_FILE on the directory your patch is touching).

Quoted 7 lines
 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/net/ftgmac100.txt +0 -0
index 29234021f601..7ef5329d888d 100644

Documentation/devicetree/bindings/net/ftgmac100.txt Optional properties: · line 28

Quoted 7 lines
Documentation/devicetree/bindings/net/ftgmac100.txt +4 -0
@@ -22,6 +22,10 @@ Optional properties:
 - use-ncsi: Use the NC-SI stack instead of an MDIO PHY. Currently assumes
   rmii (100bT) but kept as a separate property in case NC-SI grows support
   for a gigabit link.
+- mac-address-increment: Increment the MAC address taken by GMA command via
+  NC-SI. Specifies a signed number to be added to the host MAC address as
+  obtained by the OEM GMA command. If not specified, 1 is used by default
+  for Broadcom and Intel network cards, 0 otherwise.

First conversion to DT Schema. New properties are not accepted to TXT files.

Best regards,
Krzysztof

maintainer
#5 lore raw

Re: [PATCH 3/4] net/ftgmac100: add mac-address-increment option for GMA command from NC-SI

In reply to Ivan Mikhaylov
Quoted 14 lines · Ivan Mikhaylov

Add s32 mac-address-increment option for Get MAC Address command from NC-SI.

---
 Documentation/devicetree/bindings/net/ftgmac100.txt | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/net/ftgmac100.txt +0 -0
index 29234021f601..7ef5329d888d 100644

Documentation/devicetree/bindings/net/ftgmac100.txt Optional properties: · line 28

Quoted 7 lines
Documentation/devicetree/bindings/net/ftgmac100.txt +4 -0
@@ -22,6 +22,10 @@ Optional properties:
 - use-ncsi: Use the NC-SI stack instead of an MDIO PHY. Currently assumes
   rmii (100bT) but kept as a separate property in case NC-SI grows support
   for a gigabit link.
+- mac-address-increment: Increment the MAC address taken by GMA command via
+  NC-SI. Specifies a signed number to be added to the host MAC address as
+  obtained by the OEM GMA command. If not specified, 1 is used by default
+  for Broadcom and Intel network cards, 0 otherwise.

This would need to be common. There's been some attempts around how to support a base MAC address with a transform per instance. So far it's not clear that something in DT works for everyone. Until there's something common (if ever), you need platform specific code somewhere to handle this. The nvmem binding has had some extensions to support that.

Rob

#6 lore raw

Re: [PATCH 3/4] net/ftgmac100: add mac-address-increment option for GMA command from NC-SI

Quoted 39 lines · Rob Herring
Quoted 20 lines · Ivan Mikhaylov

Add s32 mac-address-increment option for Get MAC Address command from
NC-SI.

---
 Documentation/devicetree/bindings/net/ftgmac100.txt | 4 ++++

 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/net/ftgmac100.txt +0 -0
index 29234021f601..7ef5329d888d 100644
@@ -22,6 +22,10 @@ Optional properties:

 - use-ncsi: Use the NC-SI stack instead of an MDIO PHY. Currently assumes
   rmii (100bT) but kept as a separate property in case NC-SI grows support

Quoted 8 lines

   for a gigabit link.
+- mac-address-increment: Increment the MAC address taken by GMA command via
+  NC-SI. Specifies a signed number to be added to the host MAC address as
+  obtained by the OEM GMA command. If not specified, 1 is used by default
+  for Broadcom and Intel network cards, 0 otherwise.

This would need to be common. There's been some attempts around how to
support a base MAC address with a transform per instance. So far it's not clear that something in DT works for everyone. Until there's something common (if ever), you need platform specific code somewhere to
handle this. The nvmem binding has had some extensions to support that.

Quoted 1 line

Rob

Rob, I agree but unfortunately there isn't a generic option for such case, maybe something should be added into net/ethernet- controller.yaml? As example, mac-address-increment option using widely in openwrt project. About nvmem, are we talking nvmem-cell- names option or reverse_mac_address in drivers/nvmem/imx-ocotp.c?

I'll do the transfer into DT schema, that's not a problem but after naming resolve.

Adding openbmc community, maybe they have some ideas about this one.

Thanks.