Skip to contentSkip to conversation

drivers: hwmon: i5k_amb: simplify probing / device

PATCH In review Enrico Weigelt, metux IT consult 2 participants 3 messages Jun 6, 2019 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

Hi folks,

the current way of device probing looks a bit strange and uses two redundant tables - one only for the module loading and another for the actual probing.

Simplifying it by putting everything into the pci match table.

--mtx

#1 lore raw

PATCH 1/1 drivers: hwmon: i5k_amb: simplify probing / device identification

From: Enrico Weigelt <[email protected]>

Simpilify the probing by putting all chip-specific data directly into the pci match table, removing the redundant chipset_ids table.

---
 drivers/hwmon/i5k_amb.c | 45 +++++++++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 22 deletions(-)
drivers/hwmon/i5k_amb.c +23 -22
index b09c39a..f06c40f 100644
@@ -414,15 +414,15 @@ static int i5k_amb_add(void)
 }
 
 static int i5k_find_amb_registers(struct i5k_amb_data *data,
-					    unsigned long devid)
+				  const struct pci_device_id *devid)
 {
 	struct pci_dev *pcidev;
 	u32 val32;
 	int res = -ENODEV;
 
 	/* Find AMB register memory space */
-	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
-				devid,
+	pcidev = pci_get_device(devid->vendor,
+				devid->device,
 				NULL);
 	if (!pcidev)
 		return -ENODEV;
@@ -447,14 +447,18 @@ static int i5k_find_amb_registers(struct i5k_amb_data *data,
 	return res;
 }
 
-static int i5k_channel_probe(u16 *amb_present, unsigned long dev_id)
+static int i5k_channel_probe(u16 *amb_present,
+			     const struct pci_device_id *devid,
+			     int next)
 {
 	struct pci_dev *pcidev;
 	u16 val16;
 	int res = -ENODEV;
 
 	/* Copy the DIMM presence map for these two channels */
-	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, dev_id, NULL);
+	pcidev = pci_get_device(devid->vendor,
+				(unsigned long)devid->driver_data + next,
+				NULL);
 	if (!pcidev)
 		return -ENODEV;
 
@@ -473,23 +477,20 @@ static int i5k_channel_probe(u16 *amb_present, unsigned long dev_id)
 	return res;
 }
 
-static struct {
-	unsigned long err;
-	unsigned long fbd0;
-} chipset_ids[]  = {
-	{ PCI_DEVICE_ID_INTEL_5000_ERR, PCI_DEVICE_ID_INTEL_5000_FBD0 },
-	{ PCI_DEVICE_ID_INTEL_5400_ERR, PCI_DEVICE_ID_INTEL_5400_FBD0 },
-	{ 0, 0 }
-};
-
-#ifdef MODULE
 static const struct pci_device_id i5k_amb_ids[] = {
-	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5000_ERR) },
-	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR) },
+	{
+		.vendor		= PCI_VENDOR_ID_INTEL,
+		.device		= PCI_DEVICE_ID_INTEL_5000_ERR,
+		.driver_data	= PCI_DEVICE_ID_INTEL_5000_FBD0,
+	},
+	{
+		.vendor		= PCI_VENDOR_ID_INTEL,
+		.device		= PCI_DEVICE_ID_INTEL_5400_ERR,
+		.driver_data	= PCI_DEVICE_ID_INTEL_5400_FBD0,
+	},
 	{ 0, }
 };
 MODULE_DEVICE_TABLE(pci, i5k_amb_ids);
-#endif
 
 static int i5k_amb_probe(struct platform_device *pdev)
 {
@@ -504,22 +505,22 @@ static int i5k_amb_probe(struct platform_device *pdev)
 	/* Figure out where the AMB registers live */
 	i = 0;
 	do {
-		res = i5k_find_amb_registers(data, chipset_ids[i].err);
+		res = i5k_find_amb_registers(data, &i5k_amb_ids[i]);
 		if (res == 0)
 			break;
 		i++;
-	} while (chipset_ids[i].err);
+	} while (i5k_amb_ids[i].device);
 
 	if (res)
 		goto err;
 
 	/* Copy the DIMM presence map for the first two channels */
-	res = i5k_channel_probe(&data->amb_present[0], chipset_ids[i].fbd0);
+	res = i5k_channel_probe(&data->amb_present[0], &i5k_amb_ids[i], 0);
 	if (res)
 		goto err;
 
 	/* Copy the DIMM presence map for the optional second two channels */
-	i5k_channel_probe(&data->amb_present[2], chipset_ids[i].fbd0 + 1);
+	i5k_channel_probe(&data->amb_present[2], &i5k_amb_ids[i], 1);
 
 	/* Set up resource regions */
 	reso = request_mem_region(data->amb_base, data->amb_len, DRVNAME);
Signature · 1 line
1.9.1
maintainer
#2 lore raw

Re: [PATCH] drivers: hwmon: i5k_amb: simplify probing / device identification

Quoted 7 lines · metux IT consult

From: Enrico Weigelt <[email protected]>

Simpilify the probing by putting all chip-specific data directly into the pci match table, removing the redundant chipset_ids table.

---

You don't need the introductory e-mail for a single patch. Just add the extra comments here.

Quoted 27 lines
 drivers/hwmon/i5k_amb.c | 45 +++++++++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 22 deletions(-)
drivers/hwmon/i5k_amb.c +3 -3
index b09c39a..f06c40f 100644
@@ -414,15 +414,15 @@ static int i5k_amb_add(void)
 }
 
 static int i5k_find_amb_registers(struct i5k_amb_data *data,
-					    unsigned long devid)
+				  const struct pci_device_id *devid)
 {
 	struct pci_dev *pcidev;
 	u32 val32;
 	int res = -ENODEV;
 
 	/* Find AMB register memory space */
-	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
-				devid,
+	pcidev = pci_get_device(devid->vendor,
+				devid->device,
 				NULL);
 	if (!pcidev)
 		return -ENODEV;

drivers/hwmon/i5k_amb.c static int i5k_find_amb_registers(struct i5k_amb_data *data, · line 452

Quoted 7 lines
drivers/hwmon/i5k_amb.c +3 -1
@@ -447,14 +447,18 @@ static int i5k_find_amb_registers(struct i5k_amb_data *data,
 	return res;
 }
 
-static int i5k_channel_probe(u16 *amb_present, unsigned long dev_id)
+static int i5k_channel_probe(u16 *amb_present,
+			     const struct pci_device_id *devid,
+			     int next)

'next' is a bit misleading. Something like "offset" or "id_offset" might be better. A better option would be to not change the function parameters and generate dev_id when the function is called. After all, the change in this function is not really necessary and can be handled in calling code.

Quoted 29 lines
drivers/hwmon/i5k_amb.c +3 -12
 {
 	struct pci_dev *pcidev;
 	u16 val16;
 	int res = -ENODEV;
 
 	/* Copy the DIMM presence map for these two channels */
-	pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, dev_id, NULL);
+	pcidev = pci_get_device(devid->vendor,
+				(unsigned long)devid->driver_data + next,
+				NULL);
 	if (!pcidev)
 		return -ENODEV;
 
@@ -473,23 +477,20 @@ static int i5k_channel_probe(u16 *amb_present, unsigned long dev_id)
 	return res;
 }
 
-static struct {
-	unsigned long err;
-	unsigned long fbd0;
-} chipset_ids[]  = {
-	{ PCI_DEVICE_ID_INTEL_5000_ERR, PCI_DEVICE_ID_INTEL_5000_FBD0 },
-	{ PCI_DEVICE_ID_INTEL_5400_ERR, PCI_DEVICE_ID_INTEL_5400_FBD0 },
-	{ 0, 0 }
-};
-
-#ifdef MODULE
 static const struct pci_device_id i5k_amb_ids[] = {
-	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5000_ERR) },

drivers/hwmon/i5k_amb.c static int i5k_channel_probe(u16 *amb_present, unsigned long dev_id) · line 489

Quoted 10 lines
drivers/hwmon/i5k_amb.c +9 -1
-	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR) },
+	{
+		.vendor		= PCI_VENDOR_ID_INTEL,
+		.device		= PCI_DEVICE_ID_INTEL_5000_ERR,
+		.driver_data	= PCI_DEVICE_ID_INTEL_5000_FBD0,
+	},
+	{
+		.vendor		= PCI_VENDOR_ID_INTEL,
+		.device		= PCI_DEVICE_ID_INTEL_5400_ERR,
+		.driver_data	= PCI_DEVICE_ID_INTEL_5400_FBD0,

Why not use PCI_DEVICE_DATA() ?

Quoted 38 lines
drivers/hwmon/i5k_amb.c +5 -5
+	},
 	{ 0, }
 };
 MODULE_DEVICE_TABLE(pci, i5k_amb_ids);
-#endif
 
 static int i5k_amb_probe(struct platform_device *pdev)
 {
@@ -504,22 +505,22 @@ static int i5k_amb_probe(struct platform_device *pdev)
 	/* Figure out where the AMB registers live */
 	i = 0;
 	do {
-		res = i5k_find_amb_registers(data, chipset_ids[i].err);
+		res = i5k_find_amb_registers(data, &i5k_amb_ids[i]);
 		if (res == 0)
 			break;
 		i++;
-	} while (chipset_ids[i].err);
+	} while (i5k_amb_ids[i].device);
 
 	if (res)
 		goto err;
 
 	/* Copy the DIMM presence map for the first two channels */
-	res = i5k_channel_probe(&data->amb_present[0], chipset_ids[i].fbd0);
+	res = i5k_channel_probe(&data->amb_present[0], &i5k_amb_ids[i], 0);
 	if (res)
 		goto err;
 
 	/* Copy the DIMM presence map for the optional second two channels */
-	i5k_channel_probe(&data->amb_present[2], chipset_ids[i].fbd0 + 1);
+	i5k_channel_probe(&data->amb_present[2], &i5k_amb_ids[i], 1);
 
 	/* Set up resource regions */
 	reso = request_mem_region(data->amb_base, data->amb_len, DRVNAME);
Signature · 1 line
1.9.1