All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 net-next 1/7] ptp_pch: use mac_pton()
@ 2021-08-13 12:29 Andy Shevchenko
  2021-08-13 12:29 ` [PATCH v1 net-next 2/7] ptp_pch: Use ioread64_lo_hi() / iowrite64_lo_hi() Andy Shevchenko
                   ` (5 more replies)
  0 siblings, 6 replies; 25+ messages in thread
From: Andy Shevchenko @ 2021-08-13 12:29 UTC (permalink / raw)
  To: Andy Shevchenko, netdev, linux-kernel; +Cc: Richard Cochran

Use mac_pton() instead of custom approach.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/ptp/ptp_pch.c | 41 ++++++++++-------------------------------
 1 file changed, 10 insertions(+), 31 deletions(-)

diff --git a/drivers/ptp/ptp_pch.c b/drivers/ptp/ptp_pch.c
index a17e8cc642c5..76ba94f419ff 100644
--- a/drivers/ptp/ptp_pch.c
+++ b/drivers/ptp/ptp_pch.c
@@ -100,7 +100,6 @@ struct pch_ts_regs {
 #define PCH_ECS_ETH		(1 << 0)
 
 #define PCH_ECS_CAN		(1 << 1)
-#define PCH_STATION_BYTES	6
 
 #define PCH_IEEE1588_ETH	(1 << 0)
 #define PCH_IEEE1588_CAN	(1 << 1)
@@ -292,8 +291,9 @@ static void pch_reset(struct pch_dev *chip)
  */
 int pch_set_station_address(u8 *addr, struct pci_dev *pdev)
 {
-	s32 i;
 	struct pch_dev *chip = pci_get_drvdata(pdev);
+	bool valid;
+	u64 mac;
 
 	/* Verify the parameter */
 	if ((chip->regs == NULL) || addr == (u8 *)NULL) {
@@ -301,37 +301,16 @@ int pch_set_station_address(u8 *addr, struct pci_dev *pdev)
 			"invalid params returning PCH_INVALIDPARAM\n");
 		return PCH_INVALIDPARAM;
 	}
-	/* For all station address bytes */
-	for (i = 0; i < PCH_STATION_BYTES; i++) {
-		u32 val;
-		s32 tmp;
 
-		tmp = hex_to_bin(addr[i * 3]);
-		if (tmp < 0) {
-			dev_err(&pdev->dev,
-				"invalid params returning PCH_INVALIDPARAM\n");
-			return PCH_INVALIDPARAM;
-		}
-		val = tmp * 16;
-		tmp = hex_to_bin(addr[(i * 3) + 1]);
-		if (tmp < 0) {
-			dev_err(&pdev->dev,
-				"invalid params returning PCH_INVALIDPARAM\n");
-			return PCH_INVALIDPARAM;
-		}
-		val += tmp;
-		/* Expects ':' separated addresses */
-		if ((i < 5) && (addr[(i * 3) + 2] != ':')) {
-			dev_err(&pdev->dev,
-				"invalid params returning PCH_INVALIDPARAM\n");
-			return PCH_INVALIDPARAM;
-		}
-
-		/* Ideally we should set the address only after validating
-							 entire string */
-		dev_dbg(&pdev->dev, "invoking pch_station_set\n");
-		iowrite32(val, &chip->regs->ts_st[i]);
+	valid = mac_pton(addr, (u8 *)&mac);
+	if (!valid) {
+		dev_err(&pdev->dev, "invalid params returning PCH_INVALIDPARAM\n");
+		return PCH_INVALIDPARAM;
 	}
+
+	dev_dbg(&pdev->dev, "invoking pch_station_set\n");
+	iowrite32(lower_32_bits(mac), &chip->regs->ts_st[0]);
+	iowrite32(upper_32_bits(mac), &chip->regs->ts_st[4]);
 	return 0;
 }
 EXPORT_SYMBOL(pch_set_station_address);
-- 
2.30.2


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

end of thread, other threads:[~2021-08-23  8:29 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-13 12:29 [PATCH v1 net-next 1/7] ptp_pch: use mac_pton() Andy Shevchenko
2021-08-13 12:29 ` [PATCH v1 net-next 2/7] ptp_pch: Use ioread64_lo_hi() / iowrite64_lo_hi() Andy Shevchenko
2021-08-17 16:54   ` kernel test robot
2021-08-17 16:54     ` kernel test robot
2021-08-13 12:29 ` [PATCH v1 net-next 3/7] ptp_pch: Use ioread64_hi_lo() / iowrite64_hi_lo() Andy Shevchenko
2021-08-13 12:29 ` [PATCH v1 net-next 4/7] ptp_pch: Switch to use module_pci_driver() macro Andy Shevchenko
2021-08-13 14:34   ` kernel test robot
2021-08-13 14:34     ` kernel test robot
2021-08-13 15:13     ` Andy Shevchenko
2021-08-13 15:13       ` Andy Shevchenko
2021-08-13 15:39       ` Andy Shevchenko
2021-08-13 15:39         ` Andy Shevchenko
2021-08-13 18:23         ` Jakub Kicinski
2021-08-13 18:23           ` Jakub Kicinski
2021-08-13 19:26           ` Andy Shevchenko
2021-08-13 19:26             ` Andy Shevchenko
2021-08-13 19:38             ` Andy Shevchenko
2021-08-13 19:38               ` Andy Shevchenko
2021-08-23  8:29           ` Andy Shevchenko
2021-08-23  8:29             ` Andy Shevchenko
2021-08-13 16:19   ` kernel test robot
2021-08-13 16:19     ` kernel test robot
2021-08-13 12:29 ` [PATCH v1 net-next 5/7] ptp_pch: Convert to use managed functions pcim_* and devm_* Andy Shevchenko
2021-08-13 12:29 ` [PATCH v1 net-next 6/7] ptp_pch: Remove unused pch_pm_ops Andy Shevchenko
2021-08-13 12:29 ` [PATCH v1 net-next 7/7] ptp_pch: Load module automatically if ID matches Andy Shevchenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.