net: pch: fix and a few cleanups
Subsystems (2)
v2 cover net: pch: fix and a few cleanups
The series provides one fix (patch 1) for GPIO to be able to wait for the GPIO driver to appear. This is separated from the conversion to the GPIO descriptors (patch 2) in order to have a possibility for backporting. Patches 3 and 4 fix a minor warnings from Sparse while moving to a new APIs. Patch 5 is MODULE_VERSION() clean up.
Tested on Intel Minnowboard (v1).
Since v2:
- added a few cleanups on top of the fix
Andy Shevchenko (5):
net: pch_gbe: Propagate error from devm_gpio_request_one()
net: pch_gbe: Convert to use GPIO descriptors
net: pch_gbe: use readx_poll_timeout_atomic() variant
net: pch_gbe: Use proper accessors to BE data in pch_ptp_match()
net: pch_gbe: remove unneeded MODULE_VERSION() call
.../net/ethernet/oki-semi/pch_gbe/pch_gbe.h | 2 - .../oki-semi/pch_gbe/pch_gbe_ethtool.c | 2 + .../ethernet/oki-semi/pch_gbe/pch_gbe_main.c | 103 +++++++++--------- 3 files changed, 54 insertions(+), 53 deletions(-)
Signature · 1 line
2.30.2
PATCH v2 1/5 net: pch_gbe: Propagate error from devm_gpio_request_one()
If GPIO controller is not available yet we need to defer the probe of GBE until provider will become available.
While here, drop GPIOF_EXPORT because it's deprecated and may not be available.
--- drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c +7 -3
@@ -2531,9 +2531,13 @@ static int pch_gbe_probe(struct pci_dev *pdev, adapter->pdev = pdev; adapter->hw.back = adapter; adapter->hw.reg =pcim_iomap_table (pdev)[PCH_GBE_PCI_BAR ]; + adapter->pdata = (struct pch_gbe_privdata *)pci_id->driver_data; -if (adapter->pdata && adapter->pdata->platform_init) - adapter->pdata->platform_init (pdev); +if (adapter->pdata && adapter->pdata->platform_init) { + ret = adapter->pdata->platform_init (pdev); +if (ret) + goto err_free_netdev; + } adapter->ptp_pdev = pci_get_domain_bus_and_slot(pci_domain_nr(adapter->pdev->bus),
@@ -2628,7 +2632,7 @@ static int pch_gbe_probe(struct pci_dev *pdev,*/ static int pch_gbe_minnow_platform_init (struct pci_dev *pdev) { -unsigned long flags =GPIOF_DIR_OUT |GPIOF_INIT_HIGH |GPIOF_EXPORT ; +unsigned long flags =GPIOF_OUT_INIT_HIGH ;unsigned gpio =MINNOW_PHY_RESET_GPIO ;int ret;
Signature · 1 line
2.30.2
PATCH v2 2/5 net: pch_gbe: Convert to use GPIO descriptors
In reply to Andy ShevchenkoThis switches the PCH GBE driver to use GPIO descriptors.
--- .../ethernet/oki-semi/pch_gbe/pch_gbe_main.c | 45 +++++++++++++------ 1 file changed, 32 insertions(+), 13 deletions(-)
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c +32 -13
@@ -8,10 +8,12 @@#include "pch_gbe.h" #include "pch_gbe_phy.h" + +#include <linux/gpio/consumer.h> +#include <linux/gpio/machine.h> #include <linux/module.h> #include <linux/net_tstamp.h> #include <linux/ptp_classify.h> -#include <linux/gpio.h> #define DRV_VERSION "1.01"const char pch_driver_version[] =DRV_VERSION ;
@@ -96,8 +98,6 @@ const char pch_driver_version[] = DRV_VERSION;#define PTP_L4_MULTICAST_SA "01:00:5e:00:01:81"#define PTP_L2_MULTICAST_SA "01:1b:19:00:00:00" -#define MINNOW_PHY_RESET_GPIO 13 -static int pch_gbe_mdio_read (struct net_device *netdev,int addr,int reg);static void pch_gbe_mdio_write (struct net_device *netdev,int addr,int reg,int data);
@@ -2627,26 +2627,45 @@ static int pch_gbe_probe(struct pci_dev *pdev,return ret; } +static void pch_gbe_gpio_remove_table (void *table) +{ +gpiod_remove_lookup_table (table); +} + +static int pch_gbe_gpio_add_table (struct device *dev,void *table) +{ +gpiod_add_lookup_table (table); +return devm_add_action_or_reset (dev, pch_gbe_gpio_remove_table, table); +} + +static struct gpiod_lookup_table pch_gbe_minnow_gpio_table = { + .dev_id ="0000:02:00.1" , + .table = { +GPIO_LOOKUP ("sch_gpio.33158" ,13 ,NULL ,GPIO_ACTIVE_LOW ), + {} + }, +}; +/* The AR803X PHY on the MinnowBoard requires a physical pin to be toggled to * ensure it is awake for probe and init. Request the line and reset the PHY. */ static int pch_gbe_minnow_platform_init (struct pci_dev *pdev) { -unsigned long flags =GPIOF_OUT_INIT_HIGH ; -unsigned gpio =MINNOW_PHY_RESET_GPIO ; +struct gpio_desc *gpiod;int ret; - ret =devm_gpio_request_one (&pdev->dev, gpio, flags, -"minnow_phy_reset" ); -if (ret) { -dev_err (&pdev->dev, -"ERR: Can't request PHY reset GPIO line '%d'\n" , gpio); + ret =pch_gbe_gpio_add_table (&pdev->dev, &pch_gbe_minnow_gpio_table); +if (ret)return ret; - } -gpio_set_value (gpio,0 ); + gpiod =devm_gpiod_get (&pdev->dev,NULL ,GPIOD_OUT_HIGH ); +if (IS_ERR (gpiod)) +return dev_err_probe (&pdev->dev,PTR_ERR (gpiod), +"Can't request PHY reset GPIO line\n" ); + +gpiod_set_value (gpiod,1 );usleep_range (1250 ,1500 ); -gpio_set_value (gpio,1 ); +gpiod_set_value (gpiod,0 );usleep_range (1250 ,1500 );return ret;
Signature · 1 line
2.30.2
PATCH v2 3/5 net: pch_gbe: use readx_poll_timeout_atomic() variant
In reply to Andy ShevchenkoUse readx_poll_timeout_atomic() instead of open coded variants.
While at it, add __iomem attribute to the parameter of pch_gbe_wait_clr_bit().
--- .../ethernet/oki-semi/pch_gbe/pch_gbe_main.c | 27 ++++++------------- 1 file changed, 8 insertions(+), 19 deletions(-)
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c +8 -19
@@ -11,6 +11,7 @@#include <linux/gpio/consumer.h> #include <linux/gpio/machine.h> +#include <linux/iopoll.h> #include <linux/module.h> #include <linux/net_tstamp.h> #include <linux/ptp_classify.h>
@@ -297,15 +298,12 @@ static s32 pch_gbe_mac_read_mac_addr(struct pch_gbe_hw *hw)* @reg: Pointer of register * @bit: Busy bit */ -static void pch_gbe_wait_clr_bit (void *reg,u32 bit) +static void pch_gbe_wait_clr_bit (void __iomem *reg,u32 bit) {u32 tmp;/* wait busy */ - tmp =1000 ; -while ((ioread32 (reg) & bit) && --tmp) -cpu_relax (); -if (!tmp) +if (readx_poll_timeout_atomic (ioread32, reg, tmp, !(tmp & bit),0 ,10 ))pr_err ("Error: busy bit is not cleared\n" ); }
@@ -489,18 +487,13 @@ u16 pch_gbe_mac_ctrl_miim(struct pch_gbe_hw *hw, u32 addr, u32 dir, u32 reg, u16 data) {struct pch_gbe_adapter *adapter =pch_gbe_hw_to_adapter (hw); -u32 data_out =0 ; -unsigned int i;unsigned long flags; +u32 data_out;spin_lock_irqsave (&hw->miim_lock, flags); -for (i =100 ; i; --i) { -if ((ioread32 (&hw->reg->MIIM) &PCH_GBE_MIIM_OPER_READY )) -break ; -udelay (20 ); - } -if (i ==0 ) { +if (readx_poll_timeout_atomic (ioread32, &hw->reg->MIIM, data_out, + data_out &PCH_GBE_MIIM_OPER_READY ,20 ,2000 )) {netdev_err (adapter->netdev,"pch-gbe.miim won't go Ready\n" );spin_unlock_irqrestore (&hw->miim_lock, flags);return 0 ;/* No way to indicate timeout error */
@@ -508,12 +501,8 @@ u16 pch_gbe_mac_ctrl_miim(struct pch_gbe_hw *hw, u32 addr, u32 dir, u32 reg,iowrite32 (((reg <<PCH_GBE_MIIM_REG_ADDR_SHIFT ) | (addr <<PCH_GBE_MIIM_PHY_ADDR_SHIFT ) | dir | data), &hw->reg->MIIM); -for (i =0 ; i <100 ; i++) { -udelay (20 ); - data_out =ioread32 (&hw->reg->MIIM); -if ((data_out &PCH_GBE_MIIM_OPER_READY )) -break ; - } +readx_poll_timeout_atomic (ioread32, &hw->reg->MIIM, data_out, + data_out &PCH_GBE_MIIM_OPER_READY ,20 ,2000 );spin_unlock_irqrestore (&hw->miim_lock, flags); netdev_dbg(adapter->netdev, "PHY %s: reg=%d, data=0x%04X\n",
Signature · 1 line
2.30.2
PATCH v2 4/5 net: pch_gbe: Use proper accessors to BE data in pch_ptp_match()
In reply to Andy ShevchenkoSparse is not happy about handling of strict types in pch_ptp_match():
.../pch_gbe_main.c:158:33: warning: incorrect type in argument 2 (different base types)
.../pch_gbe_main.c:158:33: expected unsigned short [usertype] uid_hi
.../pch_gbe_main.c:158:33: got restricted __be16 [usertype]
.../pch_gbe_main.c:158:45: warning: incorrect type in argument 3 (different base types)
.../pch_gbe_main.c:158:45: expected unsigned int [usertype] uid_lo
.../pch_gbe_main.c:158:45: got restricted __be32 [usertype]
.../pch_gbe_main.c:158:56: warning: incorrect type in argument 4 (different base types)
.../pch_gbe_main.c:158:56: expected unsigned short [usertype] seqid
.../pch_gbe_main.c:158:56: got restricted __be16 [usertype]
Fix that by switching to use proper accessors to BE data.
--- .../ethernet/oki-semi/pch_gbe/pch_gbe_main.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-)
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c +6 -13
@@ -108,7 +108,7 @@ static int pch_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid) {u8 *data = skb->data;unsigned int offset; -u16 *hi, *id; +u16 hi, id;u32 lo;if (ptp_classify_raw (skb) ==PTP_CLASS_NONE )
@@ -119,14 +119,11 @@ static int pch_ptp_match(struct sk_buff *skb, u16 uid_hi, u32 uid_lo, u16 seqid)if (skb->len < offset +OFF_PTP_SEQUENCE_ID +sizeof (seqid))return 0 ; - hi = (u16 *)(data + offset +OFF_PTP_SOURCE_UUID ); - id = (u16 *)(data + offset +OFF_PTP_SEQUENCE_ID ); + hi =get_unaligned_be16 (data + offset +OFF_PTP_SOURCE_UUID +0 ); + lo =get_unaligned_be32 (data + offset +OFF_PTP_SOURCE_UUID +2 ); + id =get_unaligned_be16 (data + offset +OFF_PTP_SEQUENCE_ID ); -memcpy (&lo, &hi[1 ],sizeof (lo)); - -return (uid_hi == *hi && - uid_lo == lo && - seqid == *id); +return (uid_hi == hi && uid_lo == lo && seqid == id); } static void
@@ -136,7 +133,6 @@ pch_rx_timestamp(struct pch_gbe_adapter *adapter, struct sk_buff *skb)struct pci_dev *pdev;u64 ns;u32 hi, lo, val; -u16 uid, seq;if (!adapter->hwts_rx_en)return ;
@@ -152,10 +148,7 @@ pch_rx_timestamp(struct pch_gbe_adapter *adapter, struct sk_buff *skb) lo =pch_src_uuid_lo_read (pdev); hi =pch_src_uuid_hi_read (pdev); - uid = hi &0xffff ; - seq = (hi >>16 ) &0xffff ; - -if (!pch_ptp_match (skb,htons (uid),htonl (lo),htons (seq))) +if (!pch_ptp_match (skb, hi, lo, hi >>16 )) goto out; ns =pch_rx_snap_read (pdev);
Signature · 1 line
2.30.2
PATCH v2 5/5 net: pch_gbe: remove unneeded MODULE_VERSION() call
In reply to Andy ShevchenkoRemove MODULE_VERSION(), as it doesn't seem to serve any practical purpose. For in-tree drivers, the kernel version matters. The code received lots of changes, but module version remained constant, since the driver landed in mainline. So, this version doesn't seem have any practical meaning anymore.
--- drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe.h | 2 -- drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_ethtool.c | 2 ++ drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c | 4 ---- 3 files changed, 2 insertions(+), 6 deletions(-)
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe.h +0 -2
@@ -596,8 +596,6 @@ struct pch_gbe_adapter {#define pch_gbe_hw_to_adapter (hw) container_of(hw, struct pch_gbe_adapter, hw) -extern const char pch_driver_version[]; -/* pch_gbe_main.c */ int pch_gbe_up (struct pch_gbe_adapter *adapter);void pch_gbe_down (struct pch_gbe_adapter *adapter);
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_ethtool.c +2 -0
@@ -8,6 +8,8 @@#include "pch_gbe.h" #include "pch_gbe_phy.h" +static const char pch_driver_version[] ="1.01" ; +/* * pch_gbe_stats - Stats item information */
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c +0 -4
@@ -16,9 +16,6 @@#include <linux/net_tstamp.h> #include <linux/ptp_classify.h> -#define DRV_VERSION "1.01" -const char pch_driver_version[] =DRV_VERSION ; -#define PCH_GBE_MAR_ENTRIES 16#define PCH_GBE_SHORT_PKT 64#define DSC_INIT16 0xC000
@@ -2726,7 +2723,6 @@ module_pci_driver(pch_gbe_driver);MODULE_DESCRIPTION ("EG20T PCH Gigabit ethernet Driver" );MODULE_AUTHOR ("LAPIS SEMICONDUCTOR, <[email protected]>" );MODULE_LICENSE ("GPL" ); -MODULE_VERSION (DRV_VERSION );MODULE_DEVICE_TABLE (pci, pch_gbe_pcidev_id);/* pch_gbe_main.c */
Signature · 1 line
2.30.2
Quoted 7 lines · Andy Shevchenko
The series provides one fix (patch 1) for GPIO to be able to wait for the GPIO driver to appear. This is separated from the conversion to the GPIO descriptors (patch 2) in order to have a possibility for backporting. Patches 3 and 4 fix a minor warnings from Sparse while moving to a new APIs. Patch 5 is
MODULE_VERSION()clean up.Tested on Intel Minnowboard (v1).
Anything should I do here?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi Andy,
...
Quoted 10 lines · Andy Shevchenko
Quoted 7 lines
The series provides one fix (patch 1) for GPIO to be able to wait for the GPIO driver to appear. This is separated from the conversion to the GPIO descriptors (patch 2) in order to have a possibility for backporting. Patches 3 and 4 fix a minor warnings from Sparse while moving to a new APIs. Patch 5 is
MODULE_VERSION()clean up.Tested on Intel Minnowboard (v1).
Anything should I do here?
it's ok for me
Quoted 4 lines
--
With Best Regards,
Andy Shevchenko
Best regards,
Flavio Suligoi
Quoted 9 lines · Flavio Suligoi
Hi Andy,
...Quoted 7 lines · Andy Shevchenko
Quoted 6 lines
The series provides one fix (patch 1) for GPIO to be able to wait for the GPIO driver to appear. This is separated from the conversion to the GPIO descriptors (patch 2) in order to have a possibility for backporting. Patches 3 and 4 fix a minor warnings from Sparse while moving to a new APIs. Patch 5 is
MODULE_VERSION()clean up.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Tested on Intel Minnowboard (v1).
Anything should I do here?
it's ok for me
Thanks!
Who may apply them?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Flavio Suligoi
Tested-byHi Andy,
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines
The series provides one fix (patch 1) for GPIO to be able to wait for the GPIO driver to appear. This is separated from the conversion to the GPIO descriptors (patch 2) in order to have a possibility for backporting. Patches 3 and 4 fix a minor warnings from Sparse while moving to a new APIs. Patch 5 is
MODULE_VERSION()clean up.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Tested on Intel Minnowboard (v1).
Anything should I do here?
it's ok for me
Thanks!
Who may apply them?
I used your patches on kernel net-next 5.12.0-rc2, on a board with an
Intel(R) Atom(TM) CPU E640 @ 1.00GHz and an EG20T PCH.
I used the built-in OKI gigabit ethernet controller:
02:00.1 Ethernet controller: Intel Corporation Platform Controller Hub EG20T Gigabit Ethernet Controller (rev 02)
Kernel driver in use: pch_gbe
with a simple iperf test and all works fine:
ht-700 ~ # iperf -c 192.168.200.1
------------------------------------------------------------
Client connecting to 192.168.200.1, TCP port 5001
TCP window size: 45.0 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.200.159 port 38638 connected with 192.168.200.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 178 MBytes 149 Mbits/sec
ht-700 ~ # iperf -c 192.168.200.1
------------------------------------------------------------
Client connecting to 192.168.200.1, TCP port 5001
TCP window size: 45.0 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.200.159 port 38640 connected with 192.168.200.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0-10.0 sec 178 MBytes 149 Mbits/sec
ht-700 ~ # iperf -c 192.168.200.1 -u
------------------------------------------------------------
Client connecting to 192.168.200.1, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size: 208 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.200.159 port 58364 connected with 192.168.200.1 port 5001
[ ID] Interval Transfer Bandwidth [ 3] 0.0-10.0 sec 1.25 MBytes 1.05 Mbits/sec
[ 3] Sent 893 datagrams
ht-700 ~ # iperf -c 192.168.200.1 -u
------------------------------------------------------------
Client connecting to 192.168.200.1, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size: 208 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.200.159 port 32778 connected with 192.168.200.1 port 5001
[ ID] Interval Transfer Bandwidth [ 3] 0.0-10.0 sec 1.25 MBytes 1.05 Mbits/sec
[ 3] Sent 893 datagrams
ht-700 ~ # uname -a
Linux ht-700 5.12.0-rc2-watchdog+ #12 SMP Thu Apr 8 11:08:49 CEST 2021 x86_64 x86_64 x86_64 GNU/Linux ht-700 ~ #
I hope this can help you.
Quoted 1 line
Quoted 4 lines
--
With Best Regards,
Andy Shevchenko
Best regards,
Flavio Suligoi
Quoted 20 lines · Flavio Suligoi
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines
The series provides one fix (patch 1) for GPIO to be able to wait for the GPIO driver to appear. This is separated from the conversion to the GPIO descriptors (patch 2) in order to have a possibility for backporting. Patches 3 and 4 fix a minor warnings from Sparse while moving to a new APIs. Patch 5 is
MODULE_VERSION()clean up.Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Tested on Intel Minnowboard (v1).
Anything should I do here?
it's ok for me
Thanks!
Who may apply them?I used your patches on kernel net-next 5.12.0-rc2, on a board with an
Intel(R) Atom(TM) CPU E640 @ 1.00GHz and an EG20T PCH.
I used the built-in OKI gigabit ethernet controller:
Quoted 8 lines
02:00.1 Ethernet controller: Intel Corporation Platform Controller Hub EG20T Gigabit Ethernet Controller (rev 02)
Kernel driver in use:pch_gbewith a simple iperf test and all works fine:
I hope this can help you.
Tested-by Flavio Suligoi <[email protected]>
Thank you, Flavio, very much!
Jesse, Jakub, David. can this be applied, please?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 7 lines · Andy Shevchenko
The series provides one fix (patch 1) for GPIO to be able to wait for the GPIO driver to appear. This is separated from the conversion to the GPIO descriptors (patch 2) in order to have a possibility for backporting. Patches 3 and 4 fix a minor warnings from Sparse while moving to a new APIs. Patch 5 is
MODULE_VERSION()clean up.Tested on Intel Minnowboard (v1).
Guys, it has been already the report from kbuild bot (sparse warnings), which should be fixed by this series (at least partially if not completely).
Please, apply this as soon as it's possible.
Or tell me what's wrong with the series.
Thanks!
Quoted 18 lines
Since v2:
- added a few cleanups on top of the fixAndy Shevchenko (5):
net:pch_gbe: Propagate error fromdevm_gpio_request_one()
net:pch_gbe: Convert to use GPIO descriptors
net:pch_gbe: usereadx_poll_timeout_atomic()variant
net:pch_gbe: Use proper accessors to BE data inpch_ptp_match()
net:pch_gbe: remove unneededMODULE_VERSION()call.../net/ethernet/oki-semi/pch_gbe/pch_gbe.h | 2 - .../oki-semi/pch_gbe/pch_gbe_ethtool.c | 2 + .../ethernet/oki-semi/pch_gbe/pch_gbe_main.c | 103 +++++++++--------- 3 files changed, 54 insertions(+), 53 deletions(-)Signature · 1 line
2.30.2
Signature · 2 lines
With Best Regards, Andy Shevchenko