* [PATCH net-next] sky2: use PCI VPD API in eeprom ethtool ops
@ 2021-11-18 20:04 Heiner Kallweit
2021-11-18 20:38 ` Stephen Hemminger
2021-11-19 11:50 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Heiner Kallweit @ 2021-11-18 20:04 UTC (permalink / raw)
To: Mirko Lindner, Stephen Hemminger, David Miller, Jakub Kicinski
Cc: netdev@vger.kernel.org
Recently pci_read/write_vpd_any() have been added to the PCI VPD API.
These functions allow to access VPD address space outside the
auto-detected VPD, and they can be used to significantly simplify the
eeprom ethtool ops.
Tested with a 88E8070 card with 1KB EEPROM.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/net/ethernet/marvell/sky2.c | 84 +++++------------------------
1 file changed, 12 insertions(+), 72 deletions(-)
diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c
index e9fc74e54..5ed44a191 100644
--- a/drivers/net/ethernet/marvell/sky2.c
+++ b/drivers/net/ethernet/marvell/sky2.c
@@ -4266,96 +4266,36 @@ static int sky2_get_eeprom_len(struct net_device *dev)
return 1 << ( ((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8);
}
-static int sky2_vpd_wait(const struct sky2_hw *hw, int cap, u16 busy)
-{
- unsigned long start = jiffies;
-
- while ( (sky2_pci_read16(hw, cap + PCI_VPD_ADDR) & PCI_VPD_ADDR_F) == busy) {
- /* Can take up to 10.6 ms for write */
- if (time_after(jiffies, start + HZ/4)) {
- dev_err(&hw->pdev->dev, "VPD cycle timed out\n");
- return -ETIMEDOUT;
- }
- msleep(1);
- }
-
- return 0;
-}
-
-static int sky2_vpd_read(struct sky2_hw *hw, int cap, void *data,
- u16 offset, size_t length)
-{
- int rc = 0;
-
- while (length > 0) {
- u32 val;
-
- sky2_pci_write16(hw, cap + PCI_VPD_ADDR, offset);
- rc = sky2_vpd_wait(hw, cap, 0);
- if (rc)
- break;
-
- val = sky2_pci_read32(hw, cap + PCI_VPD_DATA);
-
- memcpy(data, &val, min(sizeof(val), length));
- offset += sizeof(u32);
- data += sizeof(u32);
- length -= sizeof(u32);
- }
-
- return rc;
-}
-
-static int sky2_vpd_write(struct sky2_hw *hw, int cap, const void *data,
- u16 offset, unsigned int length)
-{
- unsigned int i;
- int rc = 0;
-
- for (i = 0; i < length; i += sizeof(u32)) {
- u32 val = *(u32 *)(data + i);
-
- sky2_pci_write32(hw, cap + PCI_VPD_DATA, val);
- sky2_pci_write32(hw, cap + PCI_VPD_ADDR, offset | PCI_VPD_ADDR_F);
-
- rc = sky2_vpd_wait(hw, cap, PCI_VPD_ADDR_F);
- if (rc)
- break;
- }
- return rc;
-}
-
static int sky2_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
u8 *data)
{
struct sky2_port *sky2 = netdev_priv(dev);
- int cap = pci_find_capability(sky2->hw->pdev, PCI_CAP_ID_VPD);
-
- if (!cap)
- return -EINVAL;
+ int rc;
eeprom->magic = SKY2_EEPROM_MAGIC;
+ rc = pci_read_vpd_any(sky2->hw->pdev, eeprom->offset, eeprom->len,
+ data);
+ if (rc < 0)
+ return rc;
+
+ eeprom->len = rc;
- return sky2_vpd_read(sky2->hw, cap, data, eeprom->offset, eeprom->len);
+ return 0;
}
static int sky2_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
u8 *data)
{
struct sky2_port *sky2 = netdev_priv(dev);
- int cap = pci_find_capability(sky2->hw->pdev, PCI_CAP_ID_VPD);
-
- if (!cap)
- return -EINVAL;
+ int rc;
if (eeprom->magic != SKY2_EEPROM_MAGIC)
return -EINVAL;
- /* Partial writes not supported */
- if ((eeprom->offset & 3) || (eeprom->len & 3))
- return -EINVAL;
+ rc = pci_write_vpd_any(sky2->hw->pdev, eeprom->offset, eeprom->len,
+ data);
- return sky2_vpd_write(sky2->hw, cap, data, eeprom->offset, eeprom->len);
+ return rc < 0 ? rc : 0;
}
static netdev_features_t sky2_fix_features(struct net_device *dev,
--
2.33.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] sky2: use PCI VPD API in eeprom ethtool ops
2021-11-18 20:04 [PATCH net-next] sky2: use PCI VPD API in eeprom ethtool ops Heiner Kallweit
@ 2021-11-18 20:38 ` Stephen Hemminger
2021-11-19 11:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2021-11-18 20:38 UTC (permalink / raw)
To: Heiner Kallweit
Cc: Mirko Lindner, David Miller, Jakub Kicinski,
netdev@vger.kernel.org
On Thu, 18 Nov 2021 21:04:23 +0100
Heiner Kallweit <hkallweit1@gmail.com> wrote:
> Recently pci_read/write_vpd_any() have been added to the PCI VPD API.
> These functions allow to access VPD address space outside the
> auto-detected VPD, and they can be used to significantly simplify the
> eeprom ethtool ops.
>
> Tested with a 88E8070 card with 1KB EEPROM.
>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
Looks like a good idea. I don't have sky2 hardware in a system anymore.
Reviewed-by: Stephen Hemminger <stephen@networkplumber.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] sky2: use PCI VPD API in eeprom ethtool ops
2021-11-18 20:04 [PATCH net-next] sky2: use PCI VPD API in eeprom ethtool ops Heiner Kallweit
2021-11-18 20:38 ` Stephen Hemminger
@ 2021-11-19 11:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-11-19 11:50 UTC (permalink / raw)
To: Heiner Kallweit; +Cc: mlindner, stephen, davem, kuba, netdev
Hello:
This patch was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:
On Thu, 18 Nov 2021 21:04:23 +0100 you wrote:
> Recently pci_read/write_vpd_any() have been added to the PCI VPD API.
> These functions allow to access VPD address space outside the
> auto-detected VPD, and they can be used to significantly simplify the
> eeprom ethtool ops.
>
> Tested with a 88E8070 card with 1KB EEPROM.
>
> [...]
Here is the summary with links:
- [net-next] sky2: use PCI VPD API in eeprom ethtool ops
https://git.kernel.org/netdev/net-next/c/92e888bc6f1b
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] 3+ messages in thread
end of thread, other threads:[~2021-11-19 11:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-18 20:04 [PATCH net-next] sky2: use PCI VPD API in eeprom ethtool ops Heiner Kallweit
2021-11-18 20:38 ` Stephen Hemminger
2021-11-19 11:50 ` 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).