All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] PCI/VPD: Final extensions and cleanups
@ 2021-08-26 18:52 Heiner Kallweit
  2021-08-26 18:53 ` [PATCH 1/7] PCI/VPD: Stop exporting pci_vpd_find_tag() Heiner Kallweit
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Heiner Kallweit @ 2021-08-26 18:52 UTC (permalink / raw)
  To: Raju Rangoju, Bjorn Helgaas, Jakub Kicinski, David Miller
  Cc: linux-pci, netdev

This series finalizes the VPD extensions and cleanups.
It should be applied via the PCI tree.

Heiner Kallweit (7):
  PCI/VPD: Stop exporting pci_vpd_find_tag()
  PCI/VPD: Stop exporting pci_vpd_find_info_keyword()
  PCI/VPD: Include post-processing in pci_vpd_find_tag()
  PCI/VPD: Add pci_vpd_find_id_string()
  cxgb4: Use pci_vpd_find_id_string() to find VPD id string
  PCI/VPD: Clean up public VPD defines and inline functions
  PCI/VPD: Use unaligned access helpers

 drivers/net/ethernet/chelsio/cxgb4/t4_hw.c | 13 ++-
 drivers/pci/vpd.c                          | 71 +++++++++++-----
 include/linux/pci.h                        | 95 ++--------------------
 3 files changed, 61 insertions(+), 118 deletions(-)

-- 
2.33.0


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

* [PATCH 1/7] PCI/VPD: Stop exporting pci_vpd_find_tag()
  2021-08-26 18:52 [PATCH 0/7] PCI/VPD: Final extensions and cleanups Heiner Kallweit
@ 2021-08-26 18:53 ` Heiner Kallweit
  2021-08-26 18:54 ` [PATCH 2/7] PCI/VPD: Stop exporting pci_vpd_find_info_keyword() Heiner Kallweit
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Heiner Kallweit @ 2021-08-26 18:53 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci

Now that the last users have been migrated to pci_vpd_find_ro_keyword()
we can stop exporting this function. It's still used in VPD core code.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/pci/vpd.c   |  3 +--
 include/linux/pci.h | 11 -----------
 2 files changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c
index 01e575947..5726fbb7a 100644
--- a/drivers/pci/vpd.c
+++ b/drivers/pci/vpd.c
@@ -296,7 +296,7 @@ void *pci_vpd_alloc(struct pci_dev *dev, unsigned int *size)
 }
 EXPORT_SYMBOL_GPL(pci_vpd_alloc);
 
-int pci_vpd_find_tag(const u8 *buf, unsigned int len, u8 rdt)
+static int pci_vpd_find_tag(const u8 *buf, unsigned int len, u8 rdt)
 {
 	int i = 0;
 
@@ -310,7 +310,6 @@ int pci_vpd_find_tag(const u8 *buf, unsigned int len, u8 rdt)
 
 	return -ENOENT;
 }
-EXPORT_SYMBOL_GPL(pci_vpd_find_tag);
 
 int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
 			      unsigned int len, const char *kw)
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 76e3a9254..2c0260884 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -2350,17 +2350,6 @@ static inline u8 pci_vpd_info_field_size(const u8 *info_field)
  */
 void *pci_vpd_alloc(struct pci_dev *dev, unsigned int *size);
 
-/**
- * pci_vpd_find_tag - Locates the Resource Data Type tag provided
- * @buf: Pointer to buffered vpd data
- * @len: The length of the vpd buffer
- * @rdt: The Resource Data Type to search for
- *
- * Returns the index where the Resource Data Type was found or
- * -ENOENT otherwise.
- */
-int pci_vpd_find_tag(const u8 *buf, unsigned int len, u8 rdt);
-
 /**
  * pci_vpd_find_info_keyword - Locates an information field keyword in the VPD
  * @buf: Pointer to buffered vpd data
-- 
2.33.0



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

* [PATCH 2/7] PCI/VPD: Stop exporting pci_vpd_find_info_keyword()
  2021-08-26 18:52 [PATCH 0/7] PCI/VPD: Final extensions and cleanups Heiner Kallweit
  2021-08-26 18:53 ` [PATCH 1/7] PCI/VPD: Stop exporting pci_vpd_find_tag() Heiner Kallweit
@ 2021-08-26 18:54 ` Heiner Kallweit
  2021-08-26 18:55 ` [PATCH 3/7] PCI/VPD: Include post-processing in pci_vpd_find_tag() Heiner Kallweit
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Heiner Kallweit @ 2021-08-26 18:54 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci

Now that the last users have been migrated to pci_vpd_find_ro_keyword()
we can stop exporting this function. It's still used in VPD core code.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/pci/vpd.c   |  3 +--
 include/linux/pci.h | 13 -------------
 2 files changed, 1 insertion(+), 15 deletions(-)

diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c
index 5726fbb7a..0e7a5e8a8 100644
--- a/drivers/pci/vpd.c
+++ b/drivers/pci/vpd.c
@@ -311,7 +311,7 @@ static int pci_vpd_find_tag(const u8 *buf, unsigned int len, u8 rdt)
 	return -ENOENT;
 }
 
-int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
+static int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
 			      unsigned int len, const char *kw)
 {
 	int i;
@@ -327,7 +327,6 @@ int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
 
 	return -ENOENT;
 }
-EXPORT_SYMBOL_GPL(pci_vpd_find_info_keyword);
 
 /**
  * pci_read_vpd - Read one entry from Vital Product Data
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 2c0260884..0d6c45b1b 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -2350,19 +2350,6 @@ static inline u8 pci_vpd_info_field_size(const u8 *info_field)
  */
 void *pci_vpd_alloc(struct pci_dev *dev, unsigned int *size);
 
-/**
- * pci_vpd_find_info_keyword - Locates an information field keyword in the VPD
- * @buf: Pointer to buffered vpd data
- * @off: The offset into the buffer at which to begin the search
- * @len: The length of the buffer area, relative to off, in which to search
- * @kw: The keyword to search for
- *
- * Returns the index where the information field keyword was found or
- * -ENOENT otherwise.
- */
-int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
-			      unsigned int len, const char *kw);
-
 /**
  * pci_vpd_find_ro_info_keyword - Locate info field keyword in VPD RO section
  * @buf: Pointer to buffered VPD data
-- 
2.33.0



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

* [PATCH 3/7] PCI/VPD: Include post-processing in pci_vpd_find_tag()
  2021-08-26 18:52 [PATCH 0/7] PCI/VPD: Final extensions and cleanups Heiner Kallweit
  2021-08-26 18:53 ` [PATCH 1/7] PCI/VPD: Stop exporting pci_vpd_find_tag() Heiner Kallweit
  2021-08-26 18:54 ` [PATCH 2/7] PCI/VPD: Stop exporting pci_vpd_find_info_keyword() Heiner Kallweit
@ 2021-08-26 18:55 ` Heiner Kallweit
  2021-08-26 18:55 ` [PATCH 4/7] PCI/VPD: Add pci_vpd_find_id_string() Heiner Kallweit
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Heiner Kallweit @ 2021-08-26 18:55 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci

Move pci_vpd_find_tag() post-processing from pci_vpd_find_ro_info_keyword()
to pci_vpd_find_tag(). This simplifies function pci_vpd_find_id_string()
that will be added in a subsequent patch.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/pci/vpd.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c
index 0e7a5e8a8..b7bf014cc 100644
--- a/drivers/pci/vpd.c
+++ b/drivers/pci/vpd.c
@@ -296,16 +296,25 @@ void *pci_vpd_alloc(struct pci_dev *dev, unsigned int *size)
 }
 EXPORT_SYMBOL_GPL(pci_vpd_alloc);
 
-static int pci_vpd_find_tag(const u8 *buf, unsigned int len, u8 rdt)
+static int pci_vpd_find_tag(const u8 *buf, unsigned int len, u8 rdt, unsigned int *size)
 {
 	int i = 0;
 
 	/* look for LRDT tags only, end tag is the only SRDT tag */
 	while (i + PCI_VPD_LRDT_TAG_SIZE <= len && buf[i] & PCI_VPD_LRDT) {
-		if (buf[i] == rdt)
+		unsigned int lrdt_len = pci_vpd_lrdt_size(buf + i);
+		u8 tag = buf[i];
+
+		i += PCI_VPD_LRDT_TAG_SIZE;
+		if (tag == rdt) {
+			if (i + lrdt_len > len)
+				lrdt_len = len - i;
+			if (size)
+				*size = lrdt_len;
 			return i;
+		}
 
-		i += PCI_VPD_LRDT_TAG_SIZE + pci_vpd_lrdt_size(buf + i);
+		i += lrdt_len;
 	}
 
 	return -ENOENT;
@@ -384,16 +393,10 @@ int pci_vpd_find_ro_info_keyword(const void *buf, unsigned int len,
 	int ro_start, infokw_start;
 	unsigned int ro_len, infokw_size;
 
-	ro_start = pci_vpd_find_tag(buf, len, PCI_VPD_LRDT_RO_DATA);
+	ro_start = pci_vpd_find_tag(buf, len, PCI_VPD_LRDT_RO_DATA, &ro_len);
 	if (ro_start < 0)
 		return ro_start;
 
-	ro_len = pci_vpd_lrdt_size(buf + ro_start);
-	ro_start += PCI_VPD_LRDT_TAG_SIZE;
-
-	if (ro_start + ro_len > len)
-		ro_len = len - ro_start;
-
 	infokw_start = pci_vpd_find_info_keyword(buf, ro_start, ro_len, kw);
 	if (infokw_start < 0)
 		return infokw_start;
-- 
2.33.0



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

* [PATCH 4/7] PCI/VPD: Add pci_vpd_find_id_string()
  2021-08-26 18:52 [PATCH 0/7] PCI/VPD: Final extensions and cleanups Heiner Kallweit
                   ` (2 preceding siblings ...)
  2021-08-26 18:55 ` [PATCH 3/7] PCI/VPD: Include post-processing in pci_vpd_find_tag() Heiner Kallweit
@ 2021-08-26 18:55 ` Heiner Kallweit
  2021-08-26 18:56 ` [PATCH 5/7] cxgb4: Use pci_vpd_find_id_string() to find VPD id string Heiner Kallweit
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Heiner Kallweit @ 2021-08-26 18:55 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci

Similar to pci_vpd_find_ro_info_keyword() provide an API function to
retrieve the ID string from VPD. This way callers don't have to deal
with low-level function pci_vpd_lrdt_size() any longer that can be
made private to the VPD core in a subsequent patch.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/pci/vpd.c   |  6 ++++++
 include/linux/pci.h | 10 ++++++++++
 2 files changed, 16 insertions(+)

diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c
index b7bf014cc..79712b3d1 100644
--- a/drivers/pci/vpd.c
+++ b/drivers/pci/vpd.c
@@ -320,6 +320,12 @@ static int pci_vpd_find_tag(const u8 *buf, unsigned int len, u8 rdt, unsigned in
 	return -ENOENT;
 }
 
+int pci_vpd_find_id_string(const u8 *buf, unsigned int len, unsigned int *size)
+{
+	return pci_vpd_find_tag(buf, len, PCI_VPD_LRDT_ID_STRING, size);
+}
+EXPORT_SYMBOL_GPL(pci_vpd_find_id_string);
+
 static int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
 			      unsigned int len, const char *kw)
 {
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 0d6c45b1b..f83930562 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -2350,6 +2350,16 @@ static inline u8 pci_vpd_info_field_size(const u8 *info_field)
  */
 void *pci_vpd_alloc(struct pci_dev *dev, unsigned int *size);
 
+/**
+ * pci_vpd_find_id_string - Locate id string in VPD
+ * @buf: Pointer to buffered VPD data
+ * @len: The length of the buffer area in which to search
+ * @size: Pointer to field where length of id string is returned
+ *
+ * Returns the index of the id string or -ENOENT if not found.
+ */
+int pci_vpd_find_id_string(const u8 *buf, unsigned int len, unsigned int *size);
+
 /**
  * pci_vpd_find_ro_info_keyword - Locate info field keyword in VPD RO section
  * @buf: Pointer to buffered VPD data
-- 
2.33.0



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

* [PATCH 5/7] cxgb4: Use pci_vpd_find_id_string() to find VPD id string
  2021-08-26 18:52 [PATCH 0/7] PCI/VPD: Final extensions and cleanups Heiner Kallweit
                   ` (3 preceding siblings ...)
  2021-08-26 18:55 ` [PATCH 4/7] PCI/VPD: Add pci_vpd_find_id_string() Heiner Kallweit
@ 2021-08-26 18:56 ` Heiner Kallweit
  2021-08-26 18:57 ` [PATCH 6/7] PCI/VPD: Clean up public VPD defines and inline functions Heiner Kallweit
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Heiner Kallweit @ 2021-08-26 18:56 UTC (permalink / raw)
  To: Raju Rangoju, Bjorn Helgaas, Jakub Kicinski, David Miller
  Cc: linux-pci, netdev

Use new VPD API function pci_vpd_find_id_string() for finding the VPD
id string. This simplifies the code and avoids using VPD low-level
function pci_vpd_lrdt_size().

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/ethernet/chelsio/cxgb4/t4_hw.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
index 5e8ac42ac..64144b617 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
@@ -2744,7 +2744,7 @@ int t4_seeprom_wp(struct adapter *adapter, bool enable)
 int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p)
 {
 	unsigned int id_len, pn_len, sn_len, na_len;
-	int sn, pn, na, addr, ret = 0;
+	int id, sn, pn, na, addr, ret = 0;
 	u8 *vpd, base_val = 0;
 
 	vpd = vmalloc(VPD_LEN);
@@ -2764,13 +2764,10 @@ int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p)
 	if (ret < 0)
 		goto out;
 
-	if (vpd[0] != PCI_VPD_LRDT_ID_STRING) {
-		dev_err(adapter->pdev_dev, "missing VPD ID string\n");
-		ret = -EINVAL;
+	ret = pci_vpd_find_id_string(vpd, VPD_LEN, &id_len);
+	if (ret < 0)
 		goto out;
-	}
-
-	id_len = pci_vpd_lrdt_size(vpd);
+	id = ret;
 
 	ret = pci_vpd_check_csum(vpd, VPD_LEN);
 	if (ret) {
@@ -2796,7 +2793,7 @@ int t4_get_raw_vpd_params(struct adapter *adapter, struct vpd_params *p)
 		goto out;
 	na = ret;
 
-	memcpy(p->id, vpd + PCI_VPD_LRDT_TAG_SIZE, min_t(int, id_len, ID_LEN));
+	memcpy(p->id, vpd + id, min_t(int, id_len, ID_LEN));
 	strim(p->id);
 	memcpy(p->sn, vpd + sn, min_t(int, sn_len, SERNUM_LEN));
 	strim(p->sn);
-- 
2.33.0



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

* [PATCH 6/7] PCI/VPD: Clean up public VPD defines and inline functions
  2021-08-26 18:52 [PATCH 0/7] PCI/VPD: Final extensions and cleanups Heiner Kallweit
                   ` (4 preceding siblings ...)
  2021-08-26 18:56 ` [PATCH 5/7] cxgb4: Use pci_vpd_find_id_string() to find VPD id string Heiner Kallweit
@ 2021-08-26 18:57 ` Heiner Kallweit
  2021-08-26 18:58 ` [PATCH 7/7] PCI/VPD: Use unaligned access helpers Heiner Kallweit
  2021-09-02 15:30 ` [PATCH 0/7] PCI/VPD: Final extensions and cleanups Bjorn Helgaas
  7 siblings, 0 replies; 9+ messages in thread
From: Heiner Kallweit @ 2021-08-26 18:57 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci

After recent introduction of new VPD API functions and user migration
these defines and inline functions aren't used outside VPD core any
longer.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/pci/vpd.c   | 26 +++++++++++++++++
 include/linux/pci.h | 69 ---------------------------------------------
 2 files changed, 26 insertions(+), 69 deletions(-)

diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c
index 79712b3d1..ff600dff4 100644
--- a/drivers/pci/vpd.c
+++ b/drivers/pci/vpd.c
@@ -11,6 +11,32 @@
 #include <linux/sched/signal.h>
 #include "pci.h"
 
+#define PCI_VPD_LRDT_TAG_SIZE		3
+#define PCI_VPD_SRDT_LEN_MASK		0x07
+#define PCI_VPD_SRDT_TAG_SIZE		1
+#define PCI_VPD_STIN_END		0x0f
+#define PCI_VPD_INFO_FLD_HDR_SIZE	3
+
+static u16 pci_vpd_lrdt_size(const u8 *lrdt)
+{
+	return (u16)lrdt[1] + ((u16)lrdt[2] << 8);
+}
+
+static u8 pci_vpd_srdt_tag(const u8 *srdt)
+{
+	return *srdt >> 3;
+}
+
+static u8 pci_vpd_srdt_size(const u8 *srdt)
+{
+	return *srdt & PCI_VPD_SRDT_LEN_MASK;
+}
+
+static u8 pci_vpd_info_field_size(const u8 *info_field)
+{
+	return info_field[2];
+}
+
 /* VPD access through PCI 2.2+ VPD capability */
 
 static struct pci_dev *pci_get_func0_dev(struct pci_dev *dev)
diff --git a/include/linux/pci.h b/include/linux/pci.h
index f83930562..2106bfd0a 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -2266,81 +2266,12 @@ int pci_enable_atomic_ops_to_root(struct pci_dev *dev, u32 cap_mask);
 #define PCI_VPD_LRDT_RO_DATA		PCI_VPD_LRDT_ID(PCI_VPD_LTIN_RO_DATA)
 #define PCI_VPD_LRDT_RW_DATA		PCI_VPD_LRDT_ID(PCI_VPD_LTIN_RW_DATA)
 
-/* Small Resource Data Type Tag Item Names */
-#define PCI_VPD_STIN_END		0x0f	/* End */
-
-#define PCI_VPD_SRDT_END		(PCI_VPD_STIN_END << 3)
-
-#define PCI_VPD_SRDT_TIN_MASK		0x78
-#define PCI_VPD_SRDT_LEN_MASK		0x07
-#define PCI_VPD_LRDT_TIN_MASK		0x7f
-
-#define PCI_VPD_LRDT_TAG_SIZE		3
-#define PCI_VPD_SRDT_TAG_SIZE		1
-
-#define PCI_VPD_INFO_FLD_HDR_SIZE	3
-
 #define PCI_VPD_RO_KEYWORD_PARTNO	"PN"
 #define PCI_VPD_RO_KEYWORD_SERIALNO	"SN"
 #define PCI_VPD_RO_KEYWORD_MFR_ID	"MN"
 #define PCI_VPD_RO_KEYWORD_VENDOR0	"V0"
 #define PCI_VPD_RO_KEYWORD_CHKSUM	"RV"
 
-/**
- * pci_vpd_lrdt_size - Extracts the Large Resource Data Type length
- * @lrdt: Pointer to the beginning of the Large Resource Data Type tag
- *
- * Returns the extracted Large Resource Data Type length.
- */
-static inline u16 pci_vpd_lrdt_size(const u8 *lrdt)
-{
-	return (u16)lrdt[1] + ((u16)lrdt[2] << 8);
-}
-
-/**
- * pci_vpd_lrdt_tag - Extracts the Large Resource Data Type Tag Item
- * @lrdt: Pointer to the beginning of the Large Resource Data Type tag
- *
- * Returns the extracted Large Resource Data Type Tag item.
- */
-static inline u16 pci_vpd_lrdt_tag(const u8 *lrdt)
-{
-	return (u16)(lrdt[0] & PCI_VPD_LRDT_TIN_MASK);
-}
-
-/**
- * pci_vpd_srdt_size - Extracts the Small Resource Data Type length
- * @srdt: Pointer to the beginning of the Small Resource Data Type tag
- *
- * Returns the extracted Small Resource Data Type length.
- */
-static inline u8 pci_vpd_srdt_size(const u8 *srdt)
-{
-	return (*srdt) & PCI_VPD_SRDT_LEN_MASK;
-}
-
-/**
- * pci_vpd_srdt_tag - Extracts the Small Resource Data Type Tag Item
- * @srdt: Pointer to the beginning of the Small Resource Data Type tag
- *
- * Returns the extracted Small Resource Data Type Tag Item.
- */
-static inline u8 pci_vpd_srdt_tag(const u8 *srdt)
-{
-	return ((*srdt) & PCI_VPD_SRDT_TIN_MASK) >> 3;
-}
-
-/**
- * pci_vpd_info_field_size - Extracts the information field length
- * @info_field: Pointer to the beginning of an information field header
- *
- * Returns the extracted information field length.
- */
-static inline u8 pci_vpd_info_field_size(const u8 *info_field)
-{
-	return info_field[2];
-}
-
 /**
  * pci_vpd_alloc - Allocate buffer and read VPD into it
  * @dev: PCI device
-- 
2.33.0



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

* [PATCH 7/7] PCI/VPD: Use unaligned access helpers
  2021-08-26 18:52 [PATCH 0/7] PCI/VPD: Final extensions and cleanups Heiner Kallweit
                   ` (5 preceding siblings ...)
  2021-08-26 18:57 ` [PATCH 6/7] PCI/VPD: Clean up public VPD defines and inline functions Heiner Kallweit
@ 2021-08-26 18:58 ` Heiner Kallweit
  2021-09-02 15:30 ` [PATCH 0/7] PCI/VPD: Final extensions and cleanups Bjorn Helgaas
  7 siblings, 0 replies; 9+ messages in thread
From: Heiner Kallweit @ 2021-08-26 18:58 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci

Use unaligned access helpers to simplify the code.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/pci/vpd.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c
index ff600dff4..25557b272 100644
--- a/drivers/pci/vpd.c
+++ b/drivers/pci/vpd.c
@@ -9,6 +9,7 @@
 #include <linux/delay.h>
 #include <linux/export.h>
 #include <linux/sched/signal.h>
+#include <asm/unaligned.h>
 #include "pci.h"
 
 #define PCI_VPD_LRDT_TAG_SIZE		3
@@ -19,7 +20,7 @@
 
 static u16 pci_vpd_lrdt_size(const u8 *lrdt)
 {
-	return (u16)lrdt[1] + ((u16)lrdt[2] << 8);
+	return get_unaligned_le16(lrdt + 1);
 }
 
 static u8 pci_vpd_srdt_tag(const u8 *srdt)
@@ -218,14 +219,8 @@ static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count,
 		return -EINTR;
 
 	while (pos < end) {
-		u32 val;
-
-		val = *buf++;
-		val |= *buf++ << 8;
-		val |= *buf++ << 16;
-		val |= *buf++ << 24;
-
-		ret = pci_user_write_config_dword(dev, vpd->cap + PCI_VPD_DATA, val);
+		ret = pci_user_write_config_dword(dev, vpd->cap + PCI_VPD_DATA,
+						  get_unaligned_le32(buf));
 		if (ret < 0)
 			break;
 		ret = pci_user_write_config_word(dev, vpd->cap + PCI_VPD_ADDR,
@@ -237,6 +232,7 @@ static ssize_t pci_vpd_write(struct pci_dev *dev, loff_t pos, size_t count,
 		if (ret < 0)
 			break;
 
+		buf += sizeof(u32);
 		pos += sizeof(u32);
 	}
 
-- 
2.33.0



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

* Re: [PATCH 0/7] PCI/VPD: Final extensions and cleanups
  2021-08-26 18:52 [PATCH 0/7] PCI/VPD: Final extensions and cleanups Heiner Kallweit
                   ` (6 preceding siblings ...)
  2021-08-26 18:58 ` [PATCH 7/7] PCI/VPD: Use unaligned access helpers Heiner Kallweit
@ 2021-09-02 15:30 ` Bjorn Helgaas
  7 siblings, 0 replies; 9+ messages in thread
From: Bjorn Helgaas @ 2021-09-02 15:30 UTC (permalink / raw)
  To: Heiner Kallweit
  Cc: Raju Rangoju, Bjorn Helgaas, Jakub Kicinski, David Miller,
	linux-pci, netdev

On Thu, Aug 26, 2021 at 08:52:32PM +0200, Heiner Kallweit wrote:
> This series finalizes the VPD extensions and cleanups.
> It should be applied via the PCI tree.
> 
> Heiner Kallweit (7):
>   PCI/VPD: Stop exporting pci_vpd_find_tag()
>   PCI/VPD: Stop exporting pci_vpd_find_info_keyword()
>   PCI/VPD: Include post-processing in pci_vpd_find_tag()
>   PCI/VPD: Add pci_vpd_find_id_string()
>   cxgb4: Use pci_vpd_find_id_string() to find VPD id string
>   PCI/VPD: Clean up public VPD defines and inline functions
>   PCI/VPD: Use unaligned access helpers
> 
>  drivers/net/ethernet/chelsio/cxgb4/t4_hw.c | 13 ++-
>  drivers/pci/vpd.c                          | 71 +++++++++++-----
>  include/linux/pci.h                        | 95 ++--------------------
>  3 files changed, 61 insertions(+), 118 deletions(-)

Applied to pci/vpd for v5.15, thanks!

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

end of thread, other threads:[~2021-09-02 15:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-26 18:52 [PATCH 0/7] PCI/VPD: Final extensions and cleanups Heiner Kallweit
2021-08-26 18:53 ` [PATCH 1/7] PCI/VPD: Stop exporting pci_vpd_find_tag() Heiner Kallweit
2021-08-26 18:54 ` [PATCH 2/7] PCI/VPD: Stop exporting pci_vpd_find_info_keyword() Heiner Kallweit
2021-08-26 18:55 ` [PATCH 3/7] PCI/VPD: Include post-processing in pci_vpd_find_tag() Heiner Kallweit
2021-08-26 18:55 ` [PATCH 4/7] PCI/VPD: Add pci_vpd_find_id_string() Heiner Kallweit
2021-08-26 18:56 ` [PATCH 5/7] cxgb4: Use pci_vpd_find_id_string() to find VPD id string Heiner Kallweit
2021-08-26 18:57 ` [PATCH 6/7] PCI/VPD: Clean up public VPD defines and inline functions Heiner Kallweit
2021-08-26 18:58 ` [PATCH 7/7] PCI/VPD: Use unaligned access helpers Heiner Kallweit
2021-09-02 15:30 ` [PATCH 0/7] PCI/VPD: Final extensions and cleanups Bjorn Helgaas

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.