public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] net/ncsi: fix oem gma command handling and state race issue
@ 2025-01-11 10:59 Potin Lai
  2025-01-11 10:59 ` [PATCH v2 1/2] net/ncsi: fix locking in Get MAC Address handling Potin Lai
  2025-01-11 10:59 ` [PATCH v2 2/2] net/ncsi: fix state race during channel probe completion Potin Lai
  0 siblings, 2 replies; 5+ messages in thread
From: Potin Lai @ 2025-01-11 10:59 UTC (permalink / raw)
  To: Samuel Mendoza-Jonas, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Ivan Mikhaylov,
	Paul Fertser, Patrick Williams
  Cc: netdev, linux-kernel, Cosmo Chou, Potin Lai, Potin Lai, stable,
	Cosmo Chou

We are seeing kernel panic when enabling two NCSI interfaces at same
time. It looks like mutex lock is being used in softirq caused the
issue.

This patch series try to fix oem gma command handling issue by adding a
new state, also fix a potential state handling issue. 

v1: https://lore.kernel.org/all/20250109145054.30925-1-fercerpav@gmail.com/

Signed-off-by: Potin Lai <potin.lai.pt@gmail.com>
---
Cosmo Chou (1):
      net/ncsi: fix state race during channel probe completion

Paul Fertser (1):
      net/ncsi: fix locking in Get MAC Address handling

 net/ncsi/internal.h    |  2 ++
 net/ncsi/ncsi-manage.c | 21 ++++++++++++++++++---
 net/ncsi/ncsi-rsp.c    | 19 ++++++-------------
 3 files changed, 26 insertions(+), 16 deletions(-)
---
base-commit: fc033cf25e612e840e545f8d5ad2edd6ba613ed5
change-id: 20250111-fix-ncsi-mac-1e4b3df431f1

Best regards,
-- 
Potin Lai <potin.lai.pt@gmail.com>


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

* [PATCH v2 1/2] net/ncsi: fix locking in Get MAC Address handling
  2025-01-11 10:59 [PATCH v2 0/2] net/ncsi: fix oem gma command handling and state race issue Potin Lai
@ 2025-01-11 10:59 ` Potin Lai
  2025-01-11 10:59 ` [PATCH v2 2/2] net/ncsi: fix state race during channel probe completion Potin Lai
  1 sibling, 0 replies; 5+ messages in thread
From: Potin Lai @ 2025-01-11 10:59 UTC (permalink / raw)
  To: Samuel Mendoza-Jonas, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Ivan Mikhaylov,
	Paul Fertser, Patrick Williams
  Cc: netdev, linux-kernel, Cosmo Chou, Potin Lai, Potin Lai, stable

From: Paul Fertser <fercerpav@gmail.com>

Obtaining RTNL lock in a response handler is not allowed since it runs
in an atomic softirq context. Postpone setting the MAC address by adding
a dedicated step to the configuration FSM.

Fixes: 790071347a0a ("net/ncsi: change from ndo_set_mac_address to dev_set_mac_address")
Cc: stable@vger.kernel.org
Cc: Potin Lai <potin.lai@quantatw.com>
Link: https://lore.kernel.org/20241129-potin-revert-ncsi-set-mac-addr-v1-1-94ea2cb596af@gmail.com
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
---
 net/ncsi/internal.h    |  2 ++
 net/ncsi/ncsi-manage.c | 16 ++++++++++++++--
 net/ncsi/ncsi-rsp.c    | 19 ++++++-------------
 3 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/net/ncsi/internal.h b/net/ncsi/internal.h
index ef0f8f73826f..4e0842df5234 100644
--- a/net/ncsi/internal.h
+++ b/net/ncsi/internal.h
@@ -289,6 +289,7 @@ enum {
 	ncsi_dev_state_config_sp	= 0x0301,
 	ncsi_dev_state_config_cis,
 	ncsi_dev_state_config_oem_gma,
+	ncsi_dev_state_config_apply_mac,
 	ncsi_dev_state_config_clear_vids,
 	ncsi_dev_state_config_svf,
 	ncsi_dev_state_config_ev,
@@ -322,6 +323,7 @@ struct ncsi_dev_priv {
 #define NCSI_DEV_RESHUFFLE	4
 #define NCSI_DEV_RESET		8            /* Reset state of NC          */
 	unsigned int        gma_flag;        /* OEM GMA flag               */
+	struct sockaddr     pending_mac;     /* MAC address received from GMA */
 	spinlock_t          lock;            /* Protect the NCSI device    */
 	unsigned int        package_probe_id;/* Current ID during probe    */
 	unsigned int        package_num;     /* Number of packages         */
diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c
index 5cf55bde366d..bf276eaf9330 100644
--- a/net/ncsi/ncsi-manage.c
+++ b/net/ncsi/ncsi-manage.c
@@ -1038,7 +1038,7 @@ static void ncsi_configure_channel(struct ncsi_dev_priv *ndp)
 			  : ncsi_dev_state_config_clear_vids;
 		break;
 	case ncsi_dev_state_config_oem_gma:
-		nd->state = ncsi_dev_state_config_clear_vids;
+		nd->state = ncsi_dev_state_config_apply_mac;
 
 		nca.package = np->id;
 		nca.channel = nc->id;
@@ -1050,10 +1050,22 @@ static void ncsi_configure_channel(struct ncsi_dev_priv *ndp)
 			nca.type = NCSI_PKT_CMD_OEM;
 			ret = ncsi_gma_handler(&nca, nc->version.mf_id);
 		}
-		if (ret < 0)
+		if (ret < 0) {
+			nd->state = ncsi_dev_state_config_clear_vids;
 			schedule_work(&ndp->work);
+		}
 
 		break;
+	case ncsi_dev_state_config_apply_mac:
+		rtnl_lock();
+		ret = dev_set_mac_address(dev, &ndp->pending_mac, NULL);
+		rtnl_unlock();
+		if (ret < 0)
+			netdev_warn(dev, "NCSI: 'Writing MAC address to device failed\n");
+
+		nd->state = ncsi_dev_state_config_clear_vids;
+
+		fallthrough;
 	case ncsi_dev_state_config_clear_vids:
 	case ncsi_dev_state_config_svf:
 	case ncsi_dev_state_config_ev:
diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c
index e28be33bdf2c..14bd66909ca4 100644
--- a/net/ncsi/ncsi-rsp.c
+++ b/net/ncsi/ncsi-rsp.c
@@ -628,16 +628,14 @@ static int ncsi_rsp_handler_snfc(struct ncsi_request *nr)
 static int ncsi_rsp_handler_oem_gma(struct ncsi_request *nr, int mfr_id)
 {
 	struct ncsi_dev_priv *ndp = nr->ndp;
+	struct sockaddr *saddr = &ndp->pending_mac;
 	struct net_device *ndev = ndp->ndev.dev;
 	struct ncsi_rsp_oem_pkt *rsp;
-	struct sockaddr saddr;
 	u32 mac_addr_off = 0;
-	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;
 	if (mfr_id == NCSI_OEM_MFR_BCM_ID)
 		mac_addr_off = BCM_MAC_ADDR_OFFSET;
@@ -646,22 +644,17 @@ static int ncsi_rsp_handler_oem_gma(struct ncsi_request *nr, int mfr_id)
 	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);
+	saddr->sa_family = ndev->type;
+	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))
+		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;
 
-	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");
-
-	return ret;
+	return 0;
 }
 
 /* Response handler for Mellanox card */

-- 
2.31.1


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

* [PATCH v2 2/2] net/ncsi: fix state race during channel probe completion
  2025-01-11 10:59 [PATCH v2 0/2] net/ncsi: fix oem gma command handling and state race issue Potin Lai
  2025-01-11 10:59 ` [PATCH v2 1/2] net/ncsi: fix locking in Get MAC Address handling Potin Lai
@ 2025-01-11 10:59 ` Potin Lai
  2025-01-12  4:09   ` kernel test robot
  2025-01-12  5:57   ` kernel test robot
  1 sibling, 2 replies; 5+ messages in thread
From: Potin Lai @ 2025-01-11 10:59 UTC (permalink / raw)
  To: Samuel Mendoza-Jonas, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Ivan Mikhaylov,
	Paul Fertser, Patrick Williams
  Cc: netdev, linux-kernel, Cosmo Chou, Potin Lai, Potin Lai,
	Cosmo Chou

From: Cosmo Chou <chou.cosmo@gmail.com>

During channel probing, the last NCSI_PKT_CMD_DP command can trigger
an unnecessary schedule_work() via ncsi_free_request(). We observed
that subsequent config states were triggered before the scheduled
work completed, causing potential state handling issues.

Fix this by clearing req_flags when processing the last package.

Fixes: 8e13f70be05e ("net/ncsi: Probe single packages to avoid conflict")
Signed-off-by: Cosmo Chou <chou.cosmo@gmail.com>
---
 net/ncsi/ncsi-manage.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c
index bf276eaf9330..632281816f11 100644
--- a/net/ncsi/ncsi-manage.c
+++ b/net/ncsi/ncsi-manage.c
@@ -1491,7 +1491,10 @@ static void ncsi_probe_channel(struct ncsi_dev_priv *ndp)
 		}
 		break;
 	case ncsi_dev_state_probe_dp:
-		ndp->pending_req_num = 1;
+		if (ndp->package_probe_id + 1 < ndp->max_package)
+			ndp->pending_req_num = 1;
+		else
+			nca.req_flags = 0;
 
 		/* Deselect the current package */
 		nca.type = NCSI_PKT_CMD_DP;

-- 
2.31.1


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

* Re: [PATCH v2 2/2] net/ncsi: fix state race during channel probe completion
  2025-01-11 10:59 ` [PATCH v2 2/2] net/ncsi: fix state race during channel probe completion Potin Lai
@ 2025-01-12  4:09   ` kernel test robot
  2025-01-12  5:57   ` kernel test robot
  1 sibling, 0 replies; 5+ messages in thread
From: kernel test robot @ 2025-01-12  4:09 UTC (permalink / raw)
  To: Potin Lai, Samuel Mendoza-Jonas, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Ivan Mikhaylov,
	Paul Fertser, Patrick Williams
  Cc: oe-kbuild-all, netdev, linux-kernel, Cosmo Chou, Potin Lai

Hi Potin,

kernel test robot noticed the following build errors:

[auto build test ERROR on fc033cf25e612e840e545f8d5ad2edd6ba613ed5]

url:    https://github.com/intel-lab-lkp/linux/commits/Potin-Lai/net-ncsi-fix-locking-in-Get-MAC-Address-handling/20250111-190440
base:   fc033cf25e612e840e545f8d5ad2edd6ba613ed5
patch link:    https://lore.kernel.org/r/20250111-fix-ncsi-mac-v2-2-838e0a1a233a%40gmail.com
patch subject: [PATCH v2 2/2] net/ncsi: fix state race during channel probe completion
config: arc-randconfig-001-20250112 (https://download.01.org/0day-ci/archive/20250112/202501121148.0ofCuD5J-lkp@intel.com/config)
compiler: arceb-elf-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250112/202501121148.0ofCuD5J-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202501121148.0ofCuD5J-lkp@intel.com/

All errors (new ones prefixed by >>):

   net/ncsi/ncsi-manage.c: In function 'ncsi_probe_channel':
>> net/ncsi/ncsi-manage.c:1494:54: error: 'struct ncsi_dev_priv' has no member named 'max_package'; did you mean 'multi_package'?
    1494 |                 if (ndp->package_probe_id + 1 < ndp->max_package)
         |                                                      ^~~~~~~~~~~
         |                                                      multi_package


vim +1494 net/ncsi/ncsi-manage.c

  1357	
  1358	static void ncsi_probe_channel(struct ncsi_dev_priv *ndp)
  1359	{
  1360		struct ncsi_dev *nd = &ndp->ndev;
  1361		struct ncsi_package *np;
  1362		struct ncsi_cmd_arg nca;
  1363		unsigned char index;
  1364		int ret;
  1365	
  1366		nca.ndp = ndp;
  1367		nca.req_flags = NCSI_REQ_FLAG_EVENT_DRIVEN;
  1368		switch (nd->state) {
  1369		case ncsi_dev_state_probe:
  1370			nd->state = ncsi_dev_state_probe_deselect;
  1371			fallthrough;
  1372		case ncsi_dev_state_probe_deselect:
  1373			ndp->pending_req_num = 8;
  1374	
  1375			/* Deselect all possible packages */
  1376			nca.type = NCSI_PKT_CMD_DP;
  1377			nca.channel = NCSI_RESERVED_CHANNEL;
  1378			for (index = 0; index < 8; index++) {
  1379				nca.package = index;
  1380				ret = ncsi_xmit_cmd(&nca);
  1381				if (ret)
  1382					goto error;
  1383			}
  1384	
  1385			nd->state = ncsi_dev_state_probe_package;
  1386			break;
  1387		case ncsi_dev_state_probe_package:
  1388			ndp->pending_req_num = 1;
  1389	
  1390			nca.type = NCSI_PKT_CMD_SP;
  1391			nca.bytes[0] = 1;
  1392			nca.package = ndp->package_probe_id;
  1393			nca.channel = NCSI_RESERVED_CHANNEL;
  1394			ret = ncsi_xmit_cmd(&nca);
  1395			if (ret)
  1396				goto error;
  1397			nd->state = ncsi_dev_state_probe_channel;
  1398			break;
  1399		case ncsi_dev_state_probe_channel:
  1400			ndp->active_package = ncsi_find_package(ndp,
  1401								ndp->package_probe_id);
  1402			if (!ndp->active_package) {
  1403				/* No response */
  1404				nd->state = ncsi_dev_state_probe_dp;
  1405				schedule_work(&ndp->work);
  1406				break;
  1407			}
  1408			nd->state = ncsi_dev_state_probe_cis;
  1409			if (IS_ENABLED(CONFIG_NCSI_OEM_CMD_GET_MAC) &&
  1410			    ndp->mlx_multi_host)
  1411				nd->state = ncsi_dev_state_probe_mlx_gma;
  1412	
  1413			schedule_work(&ndp->work);
  1414			break;
  1415		case ncsi_dev_state_probe_mlx_gma:
  1416			ndp->pending_req_num = 1;
  1417	
  1418			nca.type = NCSI_PKT_CMD_OEM;
  1419			nca.package = ndp->active_package->id;
  1420			nca.channel = 0;
  1421			ret = ncsi_oem_gma_handler_mlx(&nca);
  1422			if (ret)
  1423				goto error;
  1424	
  1425			nd->state = ncsi_dev_state_probe_mlx_smaf;
  1426			break;
  1427		case ncsi_dev_state_probe_mlx_smaf:
  1428			ndp->pending_req_num = 1;
  1429	
  1430			nca.type = NCSI_PKT_CMD_OEM;
  1431			nca.package = ndp->active_package->id;
  1432			nca.channel = 0;
  1433			ret = ncsi_oem_smaf_mlx(&nca);
  1434			if (ret)
  1435				goto error;
  1436	
  1437			nd->state = ncsi_dev_state_probe_cis;
  1438			break;
  1439		case ncsi_dev_state_probe_keep_phy:
  1440			ndp->pending_req_num = 1;
  1441	
  1442			nca.type = NCSI_PKT_CMD_OEM;
  1443			nca.package = ndp->active_package->id;
  1444			nca.channel = 0;
  1445			ret = ncsi_oem_keep_phy_intel(&nca);
  1446			if (ret)
  1447				goto error;
  1448	
  1449			nd->state = ncsi_dev_state_probe_gvi;
  1450			break;
  1451		case ncsi_dev_state_probe_cis:
  1452		case ncsi_dev_state_probe_gvi:
  1453		case ncsi_dev_state_probe_gc:
  1454		case ncsi_dev_state_probe_gls:
  1455			np = ndp->active_package;
  1456			ndp->pending_req_num = 1;
  1457	
  1458			/* Clear initial state Retrieve version, capability or link status */
  1459			if (nd->state == ncsi_dev_state_probe_cis)
  1460				nca.type = NCSI_PKT_CMD_CIS;
  1461			else if (nd->state == ncsi_dev_state_probe_gvi)
  1462				nca.type = NCSI_PKT_CMD_GVI;
  1463			else if (nd->state == ncsi_dev_state_probe_gc)
  1464				nca.type = NCSI_PKT_CMD_GC;
  1465			else
  1466				nca.type = NCSI_PKT_CMD_GLS;
  1467	
  1468			nca.package = np->id;
  1469			nca.channel = ndp->channel_probe_id;
  1470	
  1471			ret = ncsi_xmit_cmd(&nca);
  1472			if (ret)
  1473				goto error;
  1474	
  1475			if (nd->state == ncsi_dev_state_probe_cis) {
  1476				nd->state = ncsi_dev_state_probe_gvi;
  1477				if (IS_ENABLED(CONFIG_NCSI_OEM_CMD_KEEP_PHY) && ndp->channel_probe_id == 0)
  1478					nd->state = ncsi_dev_state_probe_keep_phy;
  1479			} else if (nd->state == ncsi_dev_state_probe_gvi) {
  1480				nd->state = ncsi_dev_state_probe_gc;
  1481			} else if (nd->state == ncsi_dev_state_probe_gc) {
  1482				nd->state = ncsi_dev_state_probe_gls;
  1483			} else {
  1484				nd->state = ncsi_dev_state_probe_cis;
  1485				ndp->channel_probe_id++;
  1486			}
  1487	
  1488			if (ndp->channel_probe_id == ndp->channel_count) {
  1489				ndp->channel_probe_id = 0;
  1490				nd->state = ncsi_dev_state_probe_dp;
  1491			}
  1492			break;
  1493		case ncsi_dev_state_probe_dp:
> 1494			if (ndp->package_probe_id + 1 < ndp->max_package)
  1495				ndp->pending_req_num = 1;
  1496			else
  1497				nca.req_flags = 0;
  1498	
  1499			/* Deselect the current package */
  1500			nca.type = NCSI_PKT_CMD_DP;
  1501			nca.package = ndp->package_probe_id;
  1502			nca.channel = NCSI_RESERVED_CHANNEL;
  1503			ret = ncsi_xmit_cmd(&nca);
  1504			if (ret)
  1505				goto error;
  1506	
  1507			/* Probe next package */
  1508			ndp->package_probe_id++;
  1509			if (ndp->package_probe_id >= 8) {
  1510				/* Probe finished */
  1511				ndp->flags |= NCSI_DEV_PROBED;
  1512				break;
  1513			}
  1514			nd->state = ncsi_dev_state_probe_package;
  1515			ndp->active_package = NULL;
  1516			break;
  1517		default:
  1518			netdev_warn(nd->dev, "Wrong NCSI state 0x%0x in enumeration\n",
  1519				    nd->state);
  1520		}
  1521	
  1522		if (ndp->flags & NCSI_DEV_PROBED) {
  1523			/* Check if all packages have HWA support */
  1524			ncsi_check_hwa(ndp);
  1525			ncsi_choose_active_channel(ndp);
  1526		}
  1527	
  1528		return;
  1529	error:
  1530		netdev_err(ndp->ndev.dev,
  1531			   "NCSI: Failed to transmit cmd 0x%x during probe\n",
  1532			   nca.type);
  1533		ncsi_report_link(ndp, true);
  1534	}
  1535	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [PATCH v2 2/2] net/ncsi: fix state race during channel probe completion
  2025-01-11 10:59 ` [PATCH v2 2/2] net/ncsi: fix state race during channel probe completion Potin Lai
  2025-01-12  4:09   ` kernel test robot
@ 2025-01-12  5:57   ` kernel test robot
  1 sibling, 0 replies; 5+ messages in thread
From: kernel test robot @ 2025-01-12  5:57 UTC (permalink / raw)
  To: Potin Lai, Samuel Mendoza-Jonas, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Ivan Mikhaylov,
	Paul Fertser, Patrick Williams
  Cc: llvm, oe-kbuild-all, netdev, linux-kernel, Cosmo Chou, Potin Lai

Hi Potin,

kernel test robot noticed the following build errors:

[auto build test ERROR on fc033cf25e612e840e545f8d5ad2edd6ba613ed5]

url:    https://github.com/intel-lab-lkp/linux/commits/Potin-Lai/net-ncsi-fix-locking-in-Get-MAC-Address-handling/20250111-190440
base:   fc033cf25e612e840e545f8d5ad2edd6ba613ed5
patch link:    https://lore.kernel.org/r/20250111-fix-ncsi-mac-v2-2-838e0a1a233a%40gmail.com
patch subject: [PATCH v2 2/2] net/ncsi: fix state race during channel probe completion
config: arm64-randconfig-002-20250112 (https://download.01.org/0day-ci/archive/20250112/202501121302.XcB6e2qZ-lkp@intel.com/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250112/202501121302.XcB6e2qZ-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202501121302.XcB6e2qZ-lkp@intel.com/

All errors (new ones prefixed by >>):

>> net/ncsi/ncsi-manage.c:1494:40: error: no member named 'max_package' in 'struct ncsi_dev_priv'
    1494 |                 if (ndp->package_probe_id + 1 < ndp->max_package)
         |                                                 ~~~  ^
   1 error generated.


vim +1494 net/ncsi/ncsi-manage.c

  1357	
  1358	static void ncsi_probe_channel(struct ncsi_dev_priv *ndp)
  1359	{
  1360		struct ncsi_dev *nd = &ndp->ndev;
  1361		struct ncsi_package *np;
  1362		struct ncsi_cmd_arg nca;
  1363		unsigned char index;
  1364		int ret;
  1365	
  1366		nca.ndp = ndp;
  1367		nca.req_flags = NCSI_REQ_FLAG_EVENT_DRIVEN;
  1368		switch (nd->state) {
  1369		case ncsi_dev_state_probe:
  1370			nd->state = ncsi_dev_state_probe_deselect;
  1371			fallthrough;
  1372		case ncsi_dev_state_probe_deselect:
  1373			ndp->pending_req_num = 8;
  1374	
  1375			/* Deselect all possible packages */
  1376			nca.type = NCSI_PKT_CMD_DP;
  1377			nca.channel = NCSI_RESERVED_CHANNEL;
  1378			for (index = 0; index < 8; index++) {
  1379				nca.package = index;
  1380				ret = ncsi_xmit_cmd(&nca);
  1381				if (ret)
  1382					goto error;
  1383			}
  1384	
  1385			nd->state = ncsi_dev_state_probe_package;
  1386			break;
  1387		case ncsi_dev_state_probe_package:
  1388			ndp->pending_req_num = 1;
  1389	
  1390			nca.type = NCSI_PKT_CMD_SP;
  1391			nca.bytes[0] = 1;
  1392			nca.package = ndp->package_probe_id;
  1393			nca.channel = NCSI_RESERVED_CHANNEL;
  1394			ret = ncsi_xmit_cmd(&nca);
  1395			if (ret)
  1396				goto error;
  1397			nd->state = ncsi_dev_state_probe_channel;
  1398			break;
  1399		case ncsi_dev_state_probe_channel:
  1400			ndp->active_package = ncsi_find_package(ndp,
  1401								ndp->package_probe_id);
  1402			if (!ndp->active_package) {
  1403				/* No response */
  1404				nd->state = ncsi_dev_state_probe_dp;
  1405				schedule_work(&ndp->work);
  1406				break;
  1407			}
  1408			nd->state = ncsi_dev_state_probe_cis;
  1409			if (IS_ENABLED(CONFIG_NCSI_OEM_CMD_GET_MAC) &&
  1410			    ndp->mlx_multi_host)
  1411				nd->state = ncsi_dev_state_probe_mlx_gma;
  1412	
  1413			schedule_work(&ndp->work);
  1414			break;
  1415		case ncsi_dev_state_probe_mlx_gma:
  1416			ndp->pending_req_num = 1;
  1417	
  1418			nca.type = NCSI_PKT_CMD_OEM;
  1419			nca.package = ndp->active_package->id;
  1420			nca.channel = 0;
  1421			ret = ncsi_oem_gma_handler_mlx(&nca);
  1422			if (ret)
  1423				goto error;
  1424	
  1425			nd->state = ncsi_dev_state_probe_mlx_smaf;
  1426			break;
  1427		case ncsi_dev_state_probe_mlx_smaf:
  1428			ndp->pending_req_num = 1;
  1429	
  1430			nca.type = NCSI_PKT_CMD_OEM;
  1431			nca.package = ndp->active_package->id;
  1432			nca.channel = 0;
  1433			ret = ncsi_oem_smaf_mlx(&nca);
  1434			if (ret)
  1435				goto error;
  1436	
  1437			nd->state = ncsi_dev_state_probe_cis;
  1438			break;
  1439		case ncsi_dev_state_probe_keep_phy:
  1440			ndp->pending_req_num = 1;
  1441	
  1442			nca.type = NCSI_PKT_CMD_OEM;
  1443			nca.package = ndp->active_package->id;
  1444			nca.channel = 0;
  1445			ret = ncsi_oem_keep_phy_intel(&nca);
  1446			if (ret)
  1447				goto error;
  1448	
  1449			nd->state = ncsi_dev_state_probe_gvi;
  1450			break;
  1451		case ncsi_dev_state_probe_cis:
  1452		case ncsi_dev_state_probe_gvi:
  1453		case ncsi_dev_state_probe_gc:
  1454		case ncsi_dev_state_probe_gls:
  1455			np = ndp->active_package;
  1456			ndp->pending_req_num = 1;
  1457	
  1458			/* Clear initial state Retrieve version, capability or link status */
  1459			if (nd->state == ncsi_dev_state_probe_cis)
  1460				nca.type = NCSI_PKT_CMD_CIS;
  1461			else if (nd->state == ncsi_dev_state_probe_gvi)
  1462				nca.type = NCSI_PKT_CMD_GVI;
  1463			else if (nd->state == ncsi_dev_state_probe_gc)
  1464				nca.type = NCSI_PKT_CMD_GC;
  1465			else
  1466				nca.type = NCSI_PKT_CMD_GLS;
  1467	
  1468			nca.package = np->id;
  1469			nca.channel = ndp->channel_probe_id;
  1470	
  1471			ret = ncsi_xmit_cmd(&nca);
  1472			if (ret)
  1473				goto error;
  1474	
  1475			if (nd->state == ncsi_dev_state_probe_cis) {
  1476				nd->state = ncsi_dev_state_probe_gvi;
  1477				if (IS_ENABLED(CONFIG_NCSI_OEM_CMD_KEEP_PHY) && ndp->channel_probe_id == 0)
  1478					nd->state = ncsi_dev_state_probe_keep_phy;
  1479			} else if (nd->state == ncsi_dev_state_probe_gvi) {
  1480				nd->state = ncsi_dev_state_probe_gc;
  1481			} else if (nd->state == ncsi_dev_state_probe_gc) {
  1482				nd->state = ncsi_dev_state_probe_gls;
  1483			} else {
  1484				nd->state = ncsi_dev_state_probe_cis;
  1485				ndp->channel_probe_id++;
  1486			}
  1487	
  1488			if (ndp->channel_probe_id == ndp->channel_count) {
  1489				ndp->channel_probe_id = 0;
  1490				nd->state = ncsi_dev_state_probe_dp;
  1491			}
  1492			break;
  1493		case ncsi_dev_state_probe_dp:
> 1494			if (ndp->package_probe_id + 1 < ndp->max_package)
  1495				ndp->pending_req_num = 1;
  1496			else
  1497				nca.req_flags = 0;
  1498	
  1499			/* Deselect the current package */
  1500			nca.type = NCSI_PKT_CMD_DP;
  1501			nca.package = ndp->package_probe_id;
  1502			nca.channel = NCSI_RESERVED_CHANNEL;
  1503			ret = ncsi_xmit_cmd(&nca);
  1504			if (ret)
  1505				goto error;
  1506	
  1507			/* Probe next package */
  1508			ndp->package_probe_id++;
  1509			if (ndp->package_probe_id >= 8) {
  1510				/* Probe finished */
  1511				ndp->flags |= NCSI_DEV_PROBED;
  1512				break;
  1513			}
  1514			nd->state = ncsi_dev_state_probe_package;
  1515			ndp->active_package = NULL;
  1516			break;
  1517		default:
  1518			netdev_warn(nd->dev, "Wrong NCSI state 0x%0x in enumeration\n",
  1519				    nd->state);
  1520		}
  1521	
  1522		if (ndp->flags & NCSI_DEV_PROBED) {
  1523			/* Check if all packages have HWA support */
  1524			ncsi_check_hwa(ndp);
  1525			ncsi_choose_active_channel(ndp);
  1526		}
  1527	
  1528		return;
  1529	error:
  1530		netdev_err(ndp->ndev.dev,
  1531			   "NCSI: Failed to transmit cmd 0x%x during probe\n",
  1532			   nca.type);
  1533		ncsi_report_link(ndp, true);
  1534	}
  1535	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

end of thread, other threads:[~2025-01-12  5:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-11 10:59 [PATCH v2 0/2] net/ncsi: fix oem gma command handling and state race issue Potin Lai
2025-01-11 10:59 ` [PATCH v2 1/2] net/ncsi: fix locking in Get MAC Address handling Potin Lai
2025-01-11 10:59 ` [PATCH v2 2/2] net/ncsi: fix state race during channel probe completion Potin Lai
2025-01-12  4:09   ` kernel test robot
2025-01-12  5:57   ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox