netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/2] net/ncsi: refactoring for GMA command
@ 2023-06-07 15:17 Ivan Mikhaylov
  2023-06-07 15:17 ` [PATCH v3 1/2] net/ncsi: make one oem_gma function for all mfr id Ivan Mikhaylov
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ivan Mikhaylov @ 2023-06-07 15:17 UTC (permalink / raw)
  To: Samuel Mendoza-Jonas, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Vijay Khemka
  Cc: netdev, linux-kernel, openbmc, Ivan Mikhaylov

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. 

Changes from v1:
	1. delete ftgmac100.txt changes about mac-address-increment
	2. add convert to yaml from ftgmac100.txt
	3. add mac-address-increment option for ethernet-controller.yaml

Changes from v2:
	1. remove DT changes from series, will be done in another one

Ivan Mikhaylov (2):
  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/ncsi/ncsi-rsp.c | 93 +++++++++++----------------------------------
 1 file changed, 22 insertions(+), 71 deletions(-)

-- 
2.40.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 1/2] net/ncsi: make one oem_gma function for all mfr id
  2023-06-07 15:17 [PATCH v3 0/2] net/ncsi: refactoring for GMA command Ivan Mikhaylov
@ 2023-06-07 15:17 ` Ivan Mikhaylov
  2023-06-07 15:17 ` [PATCH v3 2/2] net/ncsi: change from ndo_set_mac_address to dev_set_mac_address Ivan Mikhaylov
  2023-06-09  9:40 ` [PATCH v3 0/2] net/ncsi: refactoring for GMA command patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: Ivan Mikhaylov @ 2023-06-07 15:17 UTC (permalink / raw)
  To: Samuel Mendoza-Jonas, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Vijay Khemka
  Cc: netdev, linux-kernel, openbmc, Ivan Mikhaylov, Simon Horman

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

Reviewed-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: Ivan Mikhaylov <fr0st61te@gmail.com>
---
 net/ncsi/ncsi-rsp.c | 88 ++++++++++-----------------------------------
 1 file changed, 19 insertions(+), 69 deletions(-)

diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c
index 6447a09932f5..91c42253a711 100644
--- a/net/ncsi/ncsi-rsp.c
+++ b/net/ncsi/ncsi-rsp.c
@@ -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;
 }
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 2/2] net/ncsi: change from ndo_set_mac_address to dev_set_mac_address
  2023-06-07 15:17 [PATCH v3 0/2] net/ncsi: refactoring for GMA command Ivan Mikhaylov
  2023-06-07 15:17 ` [PATCH v3 1/2] net/ncsi: make one oem_gma function for all mfr id Ivan Mikhaylov
@ 2023-06-07 15:17 ` Ivan Mikhaylov
  2023-06-08 10:49   ` Simon Horman
  2023-06-09  9:40 ` [PATCH v3 0/2] net/ncsi: refactoring for GMA command patchwork-bot+netdevbpf
  2 siblings, 1 reply; 5+ messages in thread
From: Ivan Mikhaylov @ 2023-06-07 15:17 UTC (permalink / raw)
  To: Samuel Mendoza-Jonas, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Vijay Khemka
  Cc: netdev, linux-kernel, openbmc, Ivan Mikhaylov, stable, Paul Fertser

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.

Fixes: cb10c7c0dfd9e ("net/ncsi: Add NCSI Broadcom OEM command")
Cc: stable@vger.kernel.org # v6.0+ 2f38e84 net/ncsi: make one oem_gma function for all mfr id
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Signed-off-by: Ivan Mikhaylov <fr0st61te@gmail.com>
---
 net/ncsi/ncsi-rsp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c
index 91c42253a711..069c2659074b 100644
--- a/net/ncsi/ncsi-rsp.c
+++ b/net/ncsi/ncsi-rsp.c
@@ -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");
 
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 2/2] net/ncsi: change from ndo_set_mac_address to dev_set_mac_address
  2023-06-07 15:17 ` [PATCH v3 2/2] net/ncsi: change from ndo_set_mac_address to dev_set_mac_address Ivan Mikhaylov
@ 2023-06-08 10:49   ` Simon Horman
  0 siblings, 0 replies; 5+ messages in thread
From: Simon Horman @ 2023-06-08 10:49 UTC (permalink / raw)
  To: Ivan Mikhaylov
  Cc: Samuel Mendoza-Jonas, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Vijay Khemka, netdev, linux-kernel,
	openbmc, stable, Paul Fertser

On Wed, Jun 07, 2023 at 06:17:42PM +0300, Ivan Mikhaylov wrote:
> 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.
> 
> Fixes: cb10c7c0dfd9e ("net/ncsi: Add NCSI Broadcom OEM command")
> Cc: stable@vger.kernel.org # v6.0+ 2f38e84 net/ncsi: make one oem_gma function for all mfr id
> Signed-off-by: Paul Fertser <fercerpav@gmail.com>
> Signed-off-by: Ivan Mikhaylov <fr0st61te@gmail.com>

Reviewed-by: Simon Horman <simon.horman@corigine.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 0/2] net/ncsi: refactoring for GMA command
  2023-06-07 15:17 [PATCH v3 0/2] net/ncsi: refactoring for GMA command Ivan Mikhaylov
  2023-06-07 15:17 ` [PATCH v3 1/2] net/ncsi: make one oem_gma function for all mfr id Ivan Mikhaylov
  2023-06-07 15:17 ` [PATCH v3 2/2] net/ncsi: change from ndo_set_mac_address to dev_set_mac_address Ivan Mikhaylov
@ 2023-06-09  9:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-06-09  9:40 UTC (permalink / raw)
  To: Ivan Mikhaylov
  Cc: sam, davem, edumazet, kuba, pabeni, vijaykhemka, netdev,
	linux-kernel, openbmc

Hello:

This series was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:

On Wed,  7 Jun 2023 18:17:40 +0300 you wrote:
> 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.
> 
> Changes from v1:
> 	1. delete ftgmac100.txt changes about mac-address-increment
> 	2. add convert to yaml from ftgmac100.txt
> 	3. add mac-address-increment option for ethernet-controller.yaml
> 
> [...]

Here is the summary with links:
  - [v3,1/2] net/ncsi: make one oem_gma function for all mfr id
    https://git.kernel.org/netdev/net-next/c/74b449b98dcc
  - [v3,2/2] net/ncsi: change from ndo_set_mac_address to dev_set_mac_address
    https://git.kernel.org/netdev/net-next/c/790071347a0a

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-06-09  9:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-07 15:17 [PATCH v3 0/2] net/ncsi: refactoring for GMA command Ivan Mikhaylov
2023-06-07 15:17 ` [PATCH v3 1/2] net/ncsi: make one oem_gma function for all mfr id Ivan Mikhaylov
2023-06-07 15:17 ` [PATCH v3 2/2] net/ncsi: change from ndo_set_mac_address to dev_set_mac_address Ivan Mikhaylov
2023-06-08 10:49   ` Simon Horman
2023-06-09  9:40 ` [PATCH v3 0/2] net/ncsi: refactoring for GMA command patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).