net: eth: altera: tse: Add PTP and mSGDMA prefetcher
v4 cover net: eth: altera: tse: Add PTP and mSGDMA prefetcher
From: Joyce Ooi <[email protected]>
This patch series cleans up the Altera TSE driver and adds support for the newer msgdma prefetcher as well as ptp support when using the msgdma prefetcher.
v2: Rename altera_ptp to intel_fpga_tod, modify msgdma and sgdma tx_buffer
functions to be of type netdev_tx_t, and minor suggested edits
v3: Modify tx_buffer to stop queue before returning NETDEV_TX_BUSY
v4: Fix build warnings
Dalon Westergreen (10):
net: eth: altera: tse_start_xmit ignores tx_buffer call response
net: eth: altera: set rx and tx ring size before init_dma call
net: eth: altera: fix altera_dmaops declaration
net: eth: altera: add optional function to start tx dma
net: eth: altera: Move common functions to altera_utils
net: eth: altera: Add missing identifier names to function
declarations
net: eth: altera: change tx functions to type netdev_tx_t
net: eth: altera: add support for ptp and timestamping
net: eth: altera: add msgdma prefetcher
net: eth: altera: update devicetree bindings documentation
.../devicetree/bindings/net/altera_tse.txt | 103 ++++- drivers/net/ethernet/altera/Kconfig | 1 + drivers/net/ethernet/altera/Makefile | 3 +- drivers/net/ethernet/altera/altera_msgdma.c | 5 +- drivers/net/ethernet/altera/altera_msgdma.h | 30 +- .../net/ethernet/altera/altera_msgdma_prefetcher.c | 431 +++++++++++++++++++++ .../net/ethernet/altera/altera_msgdma_prefetcher.h | 30 ++ .../ethernet/altera/altera_msgdmahw_prefetcher.h | 87 +++++ drivers/net/ethernet/altera/altera_sgdma.c | 22 +- drivers/net/ethernet/altera/altera_sgdma.h | 32 +- drivers/net/ethernet/altera/altera_tse.h | 98 ++--- drivers/net/ethernet/altera/altera_tse_ethtool.c | 29 ++ drivers/net/ethernet/altera/altera_tse_main.c | 216 +++++++++-- drivers/net/ethernet/altera/altera_utils.c | 29 ++ drivers/net/ethernet/altera/altera_utils.h | 51 +++ drivers/net/ethernet/altera/intel_fpga_tod.c | 358 +++++++++++++++++ drivers/net/ethernet/altera/intel_fpga_tod.h | 56 +++ 17 files changed, 1428 insertions(+), 153 deletions(-) create mode 100644 drivers/net/ethernet/altera/altera_msgdma_prefetcher.c create mode 100644 drivers/net/ethernet/altera/altera_msgdma_prefetcher.h create mode 100644 drivers/net/ethernet/altera/altera_msgdmahw_prefetcher.h create mode 100644 drivers/net/ethernet/altera/intel_fpga_tod.c create mode 100644 drivers/net/ethernet/altera/intel_fpga_tod.h
Signature · 1 line
2.13.0
PATCH v4 1/10 net: eth: altera: tse_start_xmit ignores tx_buffer call response
From: Dalon Westergreen <[email protected]>
The return from tx_buffer call in tse_start_xmit is inapropriately ignored. tse_buffer calls should return 0 for success or NETDEV_TX_BUSY. tse_start_xmit should return not report a successful transmit when the tse_buffer call returns an error condition.
In addition to the above, the msgdma and sgdma do not return the same value on success or failure. The sgdma_tx_buffer returned 0 on failure and a positive number of transmitted packets on success. Given that it only ever sends 1 packet, this made no sense. The msgdma implementation msgdma_tx_buffer returns 0 on success.
-> Don't ignore the return from tse_buffer calls -> Fix sgdma tse_buffer call to return 0 on success
and NETDEV_TX_BUSY on failure.
---
v2: no change
v3: queue is stopped before returning NETDEV_TX_BUSY
v4: no change
--- drivers/net/ethernet/altera/altera_sgdma.c | 19 ++++++++++++------- drivers/net/ethernet/altera/altera_tse_main.c | 4 +++- 2 files changed, 15 insertions(+), 8 deletions(-)
drivers/net/ethernet/altera/altera_sgdma.c +12 -7
@@ -4,6 +4,7 @@*/ #include <linux/list.h> +#include <linux/netdevice.h> #include "altera_utils.h" #include "altera_tse.h" #include "altera_sgdmahw.h"
@@ -159,10 +160,11 @@ void sgdma_clear_txirq(struct altera_tse_private *priv) SGDMA_CTRLREG_CLRINT); } -/* transmits buffer through SGDMA. Returns number of buffers -* transmitted, 0 if not possible. -* -* tx_lock is held by the caller +/* transmits buffer through SGDMA. +* original behavior returned the number of transmitted packets (always 1) & +* returned 0 on error. This differs from the msgdma. the calling function +* will now actually look at the code, so from now, 0 is good and return +* NETDEV_TX_BUSY when busy. */ int sgdma_tx_buffer (struct altera_tse_private *priv,struct tse_buffer *buffer) {
@@ -173,8 +175,11 @@ int sgdma_tx_buffer(struct altera_tse_private *priv, struct tse_buffer *buffer)struct sgdma_descrip __iomem *ndesc = &descbase[1 ];/* wait 'til the tx sgdma is ready for the next transmit request */ -if (sgdma_txbusy (priv)) -return 0 ; +if (sgdma_txbusy (priv)) { +if (!netif_queue_stopped (priv->dev)) +netif_stop_queue (priv->dev); +return NETDEV_TX_BUSY ; + } sgdma_setup_descrip(cdesc, /* current descriptor */ ndesc, /* next descriptor */
@@ -191,7 +196,7 @@ int sgdma_tx_buffer(struct altera_tse_private *priv, struct tse_buffer *buffer)/* enqueue the request to the pending transmit queue */ queue_tx (priv, buffer); -return 1 ; +return 0 ; }
drivers/net/ethernet/altera/altera_tse_main.c +3 -1
@@ -595,7 +595,9 @@ static netdev_tx_t tse_start_xmit(struct sk_buff *skb, struct net_device *dev) buffer->dma_addr = dma_addr; buffer->len = nopaged_len; - priv->dmaops->tx_buffer (priv, buffer); + ret = priv->dmaops->tx_buffer (priv, buffer); +if (ret) + goto out;skb_tx_timestamp (skb);
Signature · 1 line
2.13.0
Re: [PATCH v4 01/10] net: eth: altera: tse_start_xmit ignores tx_buffer call response
Quoted 87 lines · Joyce
From: Dalon Westergreen <[email protected]>
The return from
tx_buffercall intse_start_xmitis inapropriately ignored.tse_buffercalls should return 0 for success orNETDEV_TX_BUSY.tse_start_xmitshould return not report a successful transmit when thetse_buffercall returns an error condition.In addition to the above, the msgdma and sgdma do not return the same value on success or failure. The
sgdma_tx_bufferreturned 0 on failure and a positive number of transmitted packets on success. Given that it only ever sends 1 packet, this made no sense. The msgdma implementationmsgdma_tx_bufferreturns 0 on success.-> Don't ignore the return from
tse_buffercalls -> Fix sgdmatse_buffercall to return 0 on success
andNETDEV_TX_BUSYon failure.Signed-off-by Dalon Westergreen <[email protected]>Signed-off-by Joyce Ooi <[email protected]>---
v2: no change
v3: queue is stopped before returningNETDEV_TX_BUSY
v4: no change--- drivers/net/ethernet/altera/altera_sgdma.c | 19 ++++++++++++------- drivers/net/ethernet/altera/altera_tse_main.c | 4 +++- 2 files changed, 15 insertions(+), 8 deletions(-)drivers/net/ethernet/altera/altera_sgdma.c +12
-7@@ -4,6 +4,7 @@*/ #include <linux/list.h> +#include <linux/netdevice.h> #include "altera_utils.h" #include "altera_tse.h" #include "altera_sgdmahw.h" @@ -159,10 +160,11 @@ void sgdma_clear_txirq(struct altera_tse_private *priv) SGDMA_CTRLREG_CLRINT); } -/* transmits buffer through SGDMA. Returns number of buffers -* transmitted, 0 if not possible. -* -* tx_lock is held by the caller +/* transmits buffer through SGDMA. +* original behavior returned the number of transmitted packets (always 1) & +* returned 0 on error. This differs from the msgdma. the calling function +* will now actually look at the code, so from now, 0 is good and return +* NETDEV_TX_BUSY when busy. */ int sgdma_tx_buffer (struct altera_tse_private *priv,struct tse_buffer *buffer) {@@ -173,8 +175,11 @@ int sgdma_tx_buffer(struct altera_tse_private *priv, struct tse_buffer *buffer)struct sgdma_descrip __iomem *ndesc = &descbase[1 ];/* wait 'til the tx sgdma is ready for the next transmit request */ -if (sgdma_txbusy (priv)) -return 0 ; +if (sgdma_txbusy (priv)) { +if (!netif_queue_stopped (priv->dev)) +netif_stop_queue (priv->dev); +return NETDEV_TX_BUSY ; + } sgdma_setup_descrip(cdesc, /* current descriptor */ ndesc, /* next descriptor */@@ -191,7 +196,7 @@ int sgdma_tx_buffer(struct altera_tse_private *priv, struct tse_buffer *buffer)/* enqueue the request to the pending transmit queue */ queue_tx (priv, buffer); -return 1 ; +return 0 ; }drivers/net/ethernet/altera/altera_tse_main.c +0
-0
drivers/net/ethernet/altera/altera_tse_main.c static netdev_tx_t tse_start_xmit(struct sk_buff *skb, struct net_device *dev) · line 603
Quoted 10 lines
drivers/net/ethernet/altera/altera_tse_main.c +3
-1@@ -595,7 +595,9 @@ static netdev_tx_t tse_start_xmit(struct sk_buff *skb, struct net_device *dev) buffer->dma_addr = dma_addr; buffer->len = nopaged_len; - priv->dmaops->tx_buffer (priv, buffer); + ret = priv->dmaops->tx_buffer (priv, buffer); +if (ret) + goto out;skb_tx_timestamp (skb);
PATCH v4 2/10 net: eth: altera: set rx and tx ring size before init_dma call
In reply to Ooi, JoyceFrom: Dalon Westergreen <[email protected]>
It is more appropriate to set the rx and tx ring size before calling the init function for the dma.
---
v2: no change
v3: no change
v4: no change
--- drivers/net/ethernet/altera/altera_tse_main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/altera/altera_tse_main.c +4 -2
@@ -1154,6 +1154,10 @@ static int tse_open(struct net_device *dev)int i;unsigned long int flags; +/* set tx and rx ring size */ + priv->rx_ring_size = dma_rx_num; + priv->tx_ring_size = dma_tx_num; +/* Reset and configure TSE MAC and probe associated PHY */ ret = priv->dmaops->init_dma (priv);if (ret !=0 ) {
@@ -1196,8 +1200,6 @@ static int tse_open(struct net_device *dev) priv->dmaops->reset_dma (priv);/* Create and initialize the TX/RX descriptors chains. */ - priv->rx_ring_size = dma_rx_num; - priv->tx_ring_size = dma_tx_num; ret =alloc_init_skbufs (priv);if (ret) {netdev_err (dev,"DMA descriptors initialization failed\n" );
Signature · 1 line
2.13.0
Re: [PATCH v4 02/10] net: eth: altera: set rx and tx ring size before init_dma call
Quoted 32 lines · Joyce
From: Dalon Westergreen <[email protected]>
It is more appropriate to set the rx and tx ring size before calling the init function for the dma.
Signed-off-by Dalon Westergreen <[email protected]>Signed-off-by Joyce Ooi <[email protected]>---
v2: no change
v3: no change
v4: no change--- drivers/net/ethernet/altera/altera_tse_main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/net/ethernet/altera/altera_tse_main.c +4
-0@@ -1154,6 +1154,10 @@ static int tse_open(struct net_device *dev)int i;unsigned long int flags; +/* set tx and rx ring size */ + priv->rx_ring_size = dma_rx_num; + priv->tx_ring_size = dma_tx_num; +/* Reset and configure TSE MAC and probe associated PHY */ ret = priv->dmaops->init_dma (priv);if (ret !=0 ) {
drivers/net/ethernet/altera/altera_tse_main.c static int tse_open(struct net_device *dev) · line 1205
Quoted 8 lines
drivers/net/ethernet/altera/altera_tse_main.c +0
-2@@ -1196,8 +1200,6 @@ static int tse_open(struct net_device *dev) priv->dmaops->reset_dma (priv);/* Create and initialize the TX/RX descriptors chains. */ - priv->rx_ring_size = dma_rx_num; - priv->tx_ring_size = dma_tx_num; ret =alloc_init_skbufs (priv);if (ret) {netdev_err (dev,"DMA descriptors initialization failed\n" );
PATCH v4 3/10 net: eth: altera: fix altera_dmaops declaration
In reply to Ooi, JoyceFrom: Dalon Westergreen <[email protected]>
The declaration of struct altera_dmaops does not have identifier names. Add identifier names to confrom with required coding styles.
---
v2: no change
v3: no change
v4: no change
--- drivers/net/ethernet/altera/altera_tse.h | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-)
drivers/net/ethernet/altera/altera_tse.h +16 -14
@@ -385,20 +385,22 @@ struct altera_tse_private;struct altera_dmaops {int altera_dtype;int dmamask; -void (*reset_dma)(struct altera_tse_private *); -void (*enable_txirq)(struct altera_tse_private *); -void (*enable_rxirq)(struct altera_tse_private *); -void (*disable_txirq)(struct altera_tse_private *); -void (*disable_rxirq)(struct altera_tse_private *); -void (*clear_txirq)(struct altera_tse_private *); -void (*clear_rxirq)(struct altera_tse_private *); -int (*tx_buffer)(struct altera_tse_private *,struct tse_buffer *); -u32 (*tx_completions)(struct altera_tse_private *); -void (*add_rx_desc)(struct altera_tse_private *,struct tse_buffer *); -u32 (*get_rx_status)(struct altera_tse_private *); -int (*init_dma)(struct altera_tse_private *); -void (*uninit_dma)(struct altera_tse_private *); -void (*start_rxdma)(struct altera_tse_private *); +void (*reset_dma)(struct altera_tse_private *priv); +void (*enable_txirq)(struct altera_tse_private *priv); +void (*enable_rxirq)(struct altera_tse_private *priv); +void (*disable_txirq)(struct altera_tse_private *priv); +void (*disable_rxirq)(struct altera_tse_private *priv); +void (*clear_txirq)(struct altera_tse_private *priv); +void (*clear_rxirq)(struct altera_tse_private *priv); +int (*tx_buffer)(struct altera_tse_private *priv, +struct tse_buffer *buffer); +u32 (*tx_completions)(struct altera_tse_private *priv); +void (*add_rx_desc)(struct altera_tse_private *priv, +struct tse_buffer *buffer); +u32 (*get_rx_status)(struct altera_tse_private *priv); +int (*init_dma)(struct altera_tse_private *priv); +void (*uninit_dma)(struct altera_tse_private *priv); +void (*start_rxdma)(struct altera_tse_private *priv); };/* This structure is private to each device.
Signature · 1 line
2.13.0
Re: [PATCH v4 03/10] net: eth: altera: fix altera_dmaops declaration
Quoted 48 lines · Joyce
From: Dalon Westergreen <[email protected]>
The declaration of struct
altera_dmaopsdoes not have identifier names. Add identifier names to confrom with required coding styles.Signed-off-by Dalon Westergreen <[email protected]>Signed-off-by Joyce Ooi <[email protected]>---
v2: no change
v3: no change
v4: no change--- drivers/net/ethernet/altera/altera_tse.h | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-)drivers/net/ethernet/altera/altera_tse.h +9
-14@@ -385,20 +385,22 @@ struct altera_tse_private;struct altera_dmaops {int altera_dtype;int dmamask; -void (*reset_dma)(struct altera_tse_private *); -void (*enable_txirq)(struct altera_tse_private *); -void (*enable_rxirq)(struct altera_tse_private *); -void (*disable_txirq)(struct altera_tse_private *); -void (*disable_rxirq)(struct altera_tse_private *); -void (*clear_txirq)(struct altera_tse_private *); -void (*clear_rxirq)(struct altera_tse_private *); -int (*tx_buffer)(struct altera_tse_private *,struct tse_buffer *); -u32 (*tx_completions)(struct altera_tse_private *); -void (*add_rx_desc)(struct altera_tse_private *,struct tse_buffer *); -u32 (*get_rx_status)(struct altera_tse_private *); -int (*init_dma)(struct altera_tse_private *); -void (*uninit_dma)(struct altera_tse_private *); -void (*start_rxdma)(struct altera_tse_private *); +void (*reset_dma)(struct altera_tse_private *priv); +void (*enable_txirq)(struct altera_tse_private *priv); +void (*enable_rxirq)(struct altera_tse_private *priv); +void (*disable_txirq)(struct altera_tse_private *priv); +void (*disable_rxirq)(struct altera_tse_private *priv); +void (*clear_txirq)(struct altera_tse_private *priv); +void (*clear_rxirq)(struct altera_tse_private *priv); +int (*tx_buffer)(struct altera_tse_private *priv, +struct tse_buffer *buffer);
drivers/net/ethernet/altera/altera_tse.h struct altera_tse_private; · line 406
Quoted 10 lines
drivers/net/ethernet/altera/altera_tse.h +7
-0+u32 (*tx_completions)(struct altera_tse_private *priv); +void (*add_rx_desc)(struct altera_tse_private *priv, +struct tse_buffer *buffer); +u32 (*get_rx_status)(struct altera_tse_private *priv); +int (*init_dma)(struct altera_tse_private *priv); +void (*uninit_dma)(struct altera_tse_private *priv); +void (*start_rxdma)(struct altera_tse_private *priv); };/* This structure is private to each device.
PATCH v4 4/10 net: eth: altera: add optional function to start tx dma
In reply to Ooi, JoyceFrom: Dalon Westergreen <[email protected]>
Allow for optional start up of tx dma if the start_txdma function is defined in altera_dmaops.
---
v2: no change
v3: no change
v4: no change
--- drivers/net/ethernet/altera/altera_tse.h | 1 + drivers/net/ethernet/altera/altera_tse_main.c | 5 +++++ 2 files changed, 6 insertions(+)
drivers/net/ethernet/altera/altera_tse.h +1 -0
@@ -401,6 +401,7 @@ struct altera_dmaops {int (*init_dma)(struct altera_tse_private *priv);void (*uninit_dma)(struct altera_tse_private *priv);void (*start_rxdma)(struct altera_tse_private *priv); +void (*start_txdma)(struct altera_tse_private *priv); };/* This structure is private to each device.
drivers/net/ethernet/altera/altera_tse_main.c +5 -0
@@ -1244,6 +1244,9 @@ static int tse_open(struct net_device *dev) priv->dmaops->start_rxdma (priv); +if (priv->dmaops->start_txdma) + priv->dmaops->start_txdma (priv); +/* Start MAC Rx/Tx */ spin_lock (&priv->mac_cfg_lock);tse_set_mac (priv, true);
@@ -1646,6 +1649,7 @@ static const struct altera_dmaops altera_dtype_sgdma = { .init_dma = sgdma_initialize, .uninit_dma = sgdma_uninitialize, .start_rxdma = sgdma_start_rxdma, + .start_txdma = NULL, };static const struct altera_dmaops altera_dtype_msgdma = {
@@ -1665,6 +1669,7 @@ static const struct altera_dmaops altera_dtype_msgdma = { .init_dma = msgdma_initialize, .uninit_dma = msgdma_uninitialize, .start_rxdma = msgdma_start_rxdma, + .start_txdma = NULL, };static const struct of_device_id altera_tse_ids[] = {
Signature · 1 line
2.13.0
Re: [PATCH v4 04/10] net: eth: altera: add optional function to start tx dma
Quoted 52 lines · Joyce
From: Dalon Westergreen <[email protected]>
Allow for optional start up of tx dma if the
start_txdmafunction is defined inaltera_dmaops.Signed-off-by Dalon Westergreen <[email protected]>Signed-off-by Joyce Ooi <[email protected]>---
v2: no change
v3: no change
v4: no change--- drivers/net/ethernet/altera/altera_tse.h | 1 + drivers/net/ethernet/altera/altera_tse_main.c | 5 +++++ 2 files changed, 6 insertions(+)drivers/net/ethernet/altera/altera_tse.h +1
-0@@ -401,6 +401,7 @@ struct altera_dmaops {int (*init_dma)(struct altera_tse_private *priv);void (*uninit_dma)(struct altera_tse_private *priv);void (*start_rxdma)(struct altera_tse_private *priv); +void (*start_txdma)(struct altera_tse_private *priv); };/* This structure is private to each device. drivers/net/ethernet/altera/altera_tse_main.c +4
-0@@ -1244,6 +1244,9 @@ static int tse_open(struct net_device *dev) priv->dmaops->start_rxdma (priv); +if (priv->dmaops->start_txdma) + priv->dmaops->start_txdma (priv); +/* Start MAC Rx/Tx */ spin_lock (&priv->mac_cfg_lock);tse_set_mac (priv, true);@@ -1646,6 +1649,7 @@ static const struct altera_dmaops altera_dtype_sgdma = { .init_dma = sgdma_initialize, .uninit_dma = sgdma_uninitialize, .start_rxdma = sgdma_start_rxdma, + .start_txdma = NULL, };static const struct altera_dmaops altera_dtype_msgdma = {
drivers/net/ethernet/altera/altera_tse_main.c static const struct altera_dmaops altera_dtype_msgdma = { · line 1675
Quoted 7 lines
drivers/net/ethernet/altera/altera_tse_main.c +1
-0@@ -1665,6 +1669,7 @@ static const struct altera_dmaops altera_dtype_msgdma = { .init_dma = msgdma_initialize, .uninit_dma = msgdma_uninitialize, .start_rxdma = msgdma_start_rxdma, + .start_txdma = NULL, };static const struct of_device_id altera_tse_ids[] = {
PATCH v4 5/10 net: eth: altera: Move common functions to altera_utils
In reply to Ooi, JoyceFrom: Dalon Westergreen <[email protected]>
Move request_and_map and other shared functions to altera_utils. This is the first step to moving common code out of tse specific code so that it can be shared with future altera ethernet ip.
---
v2: no change
v3: no change
v4: no change
--- drivers/net/ethernet/altera/altera_tse.h | 45 --------------------- drivers/net/ethernet/altera/altera_tse_ethtool.c | 1 + drivers/net/ethernet/altera/altera_tse_main.c | 32 +-------------- drivers/net/ethernet/altera/altera_utils.c | 29 ++++++++++++++ drivers/net/ethernet/altera/altera_utils.h | 51 ++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 76 deletions(-)
drivers/net/ethernet/altera/altera_tse.h +0 -45
@@ -489,49 +489,4 @@ struct altera_tse_private {*/ void altera_tse_set_ethtool_ops (struct net_device *); -static inline -u32 csrrd32 (void __iomem *mac,size_t offs) -{ -void __iomem *paddr = (void __iomem *)((uintptr_t )mac + offs); -return readl (paddr); -} - -static inline -u16 csrrd16 (void __iomem *mac,size_t offs) -{ -void __iomem *paddr = (void __iomem *)((uintptr_t )mac + offs); -return readw (paddr); -} - -static inline -u8 csrrd8 (void __iomem *mac,size_t offs) -{ -void __iomem *paddr = (void __iomem *)((uintptr_t )mac + offs); -return readb (paddr); -} - -static inline -void csrwr32 (u32 val,void __iomem *mac,size_t offs) -{ -void __iomem *paddr = (void __iomem *)((uintptr_t )mac + offs); - -writel (val, paddr); -} - -static inline -void csrwr16 (u16 val,void __iomem *mac,size_t offs) -{ -void __iomem *paddr = (void __iomem *)((uintptr_t )mac + offs); - -writew (val, paddr); -} - -static inline -void csrwr8 (u8 val,void __iomem *mac,size_t offs) -{ -void __iomem *paddr = (void __iomem *)((uintptr_t )mac + offs); - -writeb (val, paddr); -} -#endif /* __ALTERA_TSE_H__ */
drivers/net/ethernet/altera/altera_tse_ethtool.c +1 -0
@@ -22,6 +22,7 @@#include <linux/phy.h> #include "altera_tse.h" +#include "altera_utils.h" #define TSE_STATS_LEN 31#define TSE_NUM_REGS 128
drivers/net/ethernet/altera/altera_tse_main.c +1 -31
@@ -23,7 +23,6 @@#include <linux/if_vlan.h> #include <linux/init.h> #include <linux/interrupt.h> -#include <linux/io.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/mii.h>
@@ -33,7 +32,7 @@#include <linux/of_net.h> #include <linux/of_platform.h> #include <linux/phy.h> -#include <linux/platform_device.h> +#include <linux/ptp_classify.h> #include <linux/skbuff.h> #include <asm/cacheflush.h>
@@ -1320,35 +1319,6 @@ static struct net_device_ops altera_tse_netdev_ops = { .ndo_validate_addr = eth_validate_addr, }; -static int request_and_map (struct platform_device *pdev,const char *name, -struct resource **res,void __iomem **ptr) -{ -struct resource *region; -struct device *device = &pdev->dev; - - *res =platform_get_resource_byname (pdev,IORESOURCE_MEM , name); -if (*res ==NULL ) { -dev_err (device,"resource %s not defined\n" , name); -return -ENODEV ; - } - - region =devm_request_mem_region (device, (*res)->start, -resource_size (*res),dev_name (device)); -if (region ==NULL ) { -dev_err (device,"unable to request %s\n" , name); -return -EBUSY ; - } - - *ptr =devm_ioremap (device, region->start, -resource_size (region)); -if (*ptr ==NULL ) { -dev_err (device,"ioremap of %s failed!" , name); -return -ENOMEM ; - } - -return 0 ; -} -/* Probe Altera TSE MAC device */ static int altera_tse_probe (struct platform_device *pdev)
drivers/net/ethernet/altera/altera_utils.c +29 -0
@@ -31,3 +31,32 @@ int tse_bit_is_clear(void __iomem *ioaddr, size_t offs, u32 bit_mask)u32 value =csrrd32 (ioaddr, offs);return (value & bit_mask) ?0 :1 ; } + +int request_and_map (struct platform_device *pdev,const char *name, +struct resource **res,void __iomem **ptr) +{ +struct resource *region; +struct device *device = &pdev->dev; + + *res =platform_get_resource_byname (pdev,IORESOURCE_MEM , name); +if (!*res) { +dev_err (device,"resource %s not defined\n" , name); +return -ENODEV ; + } + + region =devm_request_mem_region (device, (*res)->start, +resource_size (*res),dev_name (device)); +if (!region) { +dev_err (device,"unable to request %s\n" , name); +return -EBUSY ; + } + + *ptr =devm_ioremap (device, region->start, +resource_size (region)); +if (!*ptr) { +dev_err (device,"ioremap of %s failed!" , name); +return -ENOMEM ; + } + +return 0 ; +}
drivers/net/ethernet/altera/altera_utils.h +51 -0
63 lines not on this page · raw message
Signature · 1 line
2.13.0
Re: [PATCH v4 05/10] net: eth: altera: Move common functions to altera_utils
Quoted 240 lines · Joyce
From: Dalon Westergreen <[email protected]>
Move
request_and_mapand other shared functions toaltera_utils. This is the first step to moving common code out of tse specific code so that it can be shared with future altera ethernet ip.Signed-off-by Dalon Westergreen <[email protected]>Signed-off-by Joyce Ooi <[email protected]>---
v2: no change
v3: no change
v4: no change--- drivers/net/ethernet/altera/altera_tse.h | 45 --------------------- drivers/net/ethernet/altera/altera_tse_ethtool.c | 1 + drivers/net/ethernet/altera/altera_tse_main.c | 32 +-------------- drivers/net/ethernet/altera/altera_utils.c | 29 ++++++++++++++ drivers/net/ethernet/altera/altera_utils.h | 51 ++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 76 deletions(-)drivers/net/ethernet/altera/altera_tse.h +0
-45@@ -489,49 +489,4 @@ struct altera_tse_private {*/ void altera_tse_set_ethtool_ops (struct net_device *); -static inline -u32 csrrd32 (void __iomem *mac,size_t offs) -{ -void __iomem *paddr = (void __iomem *)((uintptr_t )mac + offs); -return readl (paddr); -} - -static inline -u16 csrrd16 (void __iomem *mac,size_t offs) -{ -void __iomem *paddr = (void __iomem *)((uintptr_t )mac + offs); -return readw (paddr); -} - -static inline -u8 csrrd8 (void __iomem *mac,size_t offs) -{ -void __iomem *paddr = (void __iomem *)((uintptr_t )mac + offs); -return readb (paddr); -} - -static inline -void csrwr32 (u32 val,void __iomem *mac,size_t offs) -{ -void __iomem *paddr = (void __iomem *)((uintptr_t )mac + offs); - -writel (val, paddr); -} - -static inline -void csrwr16 (u16 val,void __iomem *mac,size_t offs) -{ -void __iomem *paddr = (void __iomem *)((uintptr_t )mac + offs); - -writew (val, paddr); -} - -static inline -void csrwr8 (u8 val,void __iomem *mac,size_t offs) -{ -void __iomem *paddr = (void __iomem *)((uintptr_t )mac + offs); - -writeb (val, paddr); -} -#endif /* __ALTERA_TSE_H__ */ drivers/net/ethernet/altera/altera_tse_ethtool.c +1
-0@@ -22,6 +22,7 @@#include <linux/phy.h> #include "altera_tse.h" +#include "altera_utils.h" #define TSE_STATS_LEN 31#define TSE_NUM_REGS 128drivers/net/ethernet/altera/altera_tse_main.c +1
-31@@ -23,7 +23,6 @@#include <linux/if_vlan.h> #include <linux/init.h> #include <linux/interrupt.h> -#include <linux/io.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/mii.h> @@ -33,7 +32,7 @@#include <linux/of_net.h> #include <linux/of_platform.h> #include <linux/phy.h> -#include <linux/platform_device.h> +#include <linux/ptp_classify.h> #include <linux/skbuff.h> #include <asm/cacheflush.h> @@ -1320,35 +1319,6 @@ static struct net_device_ops altera_tse_netdev_ops = { .ndo_validate_addr = eth_validate_addr, }; -static int request_and_map (struct platform_device *pdev,const char *name, -struct resource **res,void __iomem **ptr) -{ -struct resource *region; -struct device *device = &pdev->dev; - - *res =platform_get_resource_byname (pdev,IORESOURCE_MEM , name); -if (*res ==NULL ) { -dev_err (device,"resource %s not defined\n" , name); -return -ENODEV ; - } - - region =devm_request_mem_region (device, (*res)->start, -resource_size (*res),dev_name (device)); -if (region ==NULL ) { -dev_err (device,"unable to request %s\n" , name); -return -EBUSY ; - } - - *ptr =devm_ioremap (device, region->start, -resource_size (region)); -if (*ptr ==NULL ) { -dev_err (device,"ioremap of %s failed!" , name); -return -ENOMEM ; - } - -return 0 ; -} -/* Probe Altera TSE MAC device */ static int altera_tse_probe (struct platform_device *pdev)drivers/net/ethernet/altera/altera_utils.c +29
-0@@ -31,3 +31,32 @@ int tse_bit_is_clear(void __iomem *ioaddr, size_t offs, u32 bit_mask)u32 value =csrrd32 (ioaddr, offs);return (value & bit_mask) ?0 :1 ; } + +int request_and_map (struct platform_device *pdev,const char *name, +struct resource **res,void __iomem **ptr) +{ +struct resource *region; +struct device *device = &pdev->dev; + + *res =platform_get_resource_byname (pdev,IORESOURCE_MEM , name); +if (!*res) { +dev_err (device,"resource %s not defined\n" , name); +return -ENODEV ; + } + + region =devm_request_mem_region (device, (*res)->start, +resource_size (*res),dev_name (device)); +if (!region) { +dev_err (device,"unable to request %s\n" , name); +return -EBUSY ; + } + + *ptr =devm_ioremap (device, region->start, +resource_size (region)); +if (!*ptr) { +dev_err (device,"ioremap of %s failed!" , name); +return -ENOMEM ; + } + +return 0 ; +}drivers/net/ethernet/altera/altera_utils.h +42
-0@@ -3,7 +3,9 @@* Copyright (C) 2014 Altera Corporation. All rights reserved */ +#include <linux/platform_device.h> #include <linux/kernel.h> +#include <linux/io.h> #ifndef __ALTERA_UTILS_H__#define __ALTERA_UTILS_H__@@ -12,5 +14,54 @@ void tse_set_bit(void __iomem *ioaddr, size_t offs, u32 bit_mask);void tse_clear_bit (void __iomem *ioaddr,size_t offs,u32 bit_mask);int tse_bit_is_set (void __iomem *ioaddr,size_t offs,u32 bit_mask);int tse_bit_is_clear (void __iomem *ioaddr,size_t offs,u32 bit_mask); +int request_and_map (struct platform_device *pdev,const char *name, +struct resource **res,void __iomem **ptr); +static inline +u32 csrrd32 (void __iomem *mac,size_t offs) +{ +void __iomem *paddr = (void __iomem *)((uintptr_t )mac + offs); + +return readl (paddr); +} + +static inline +u16 csrrd16 (void __iomem *mac,size_t offs) +{ +void __iomem *paddr = (void __iomem *)((uintptr_t )mac + offs); + +return readw (paddr); +} + +static inline +u8 csrrd8 (void __iomem *mac,size_t offs) +{ +void __iomem *paddr = (void __iomem *)((uintptr_t )mac + offs); + +return readb (paddr); +} + +static inline +void csrwr32 (u32 val,void __iomem *mac,size_t offs) +{ +void __iomem *paddr = (void __iomem *)((uintptr_t )mac + offs); + +writel (val, paddr); +} + +static inline +void csrwr16 (u16 val,void __iomem *mac,size_t offs) +{ +void __iomem *paddr = (void __iomem *)((uintptr_t )mac + offs); + +writew (val, paddr);
drivers/net/ethernet/altera/altera_utils.h void tse_set_bit(void __iomem *ioaddr, size_t offs, u32 bit_mask); · line 67
Quoted 10 lines
drivers/net/ethernet/altera/altera_utils.h +9
-0+} + +static inline +void csrwr8 (u8 val,void __iomem *mac,size_t offs) +{ +void __iomem *paddr = (void __iomem *)((uintptr_t )mac + offs); + +writeb (val, paddr); +}#endif /* __ALTERA_UTILS_H__*/
PATCH v4 6/10 net: eth: altera: Add missing identifier names to function declarations
In reply to Ooi, JoyceFrom: Dalon Westergreen <[email protected]>
The sgdma and msgdma header files included function declarations without identifier names for pointers. Add appropriate identifier names.
---
v2: this patch is added in patch version 2
v3: no change
v4: no change
--- drivers/net/ethernet/altera/altera_msgdma.h | 30 ++++++++++++++------------- drivers/net/ethernet/altera/altera_sgdma.h | 32 +++++++++++++++-------------- 2 files changed, 33 insertions(+), 29 deletions(-)
drivers/net/ethernet/altera/altera_msgdma.h +16 -14
@@ -6,19 +6,21 @@#ifndef __ALTERA_MSGDMA_H__#define __ALTERA_MSGDMA_H__ -void msgdma_reset (struct altera_tse_private *); -void msgdma_enable_txirq (struct altera_tse_private *); -void msgdma_enable_rxirq (struct altera_tse_private *); -void msgdma_disable_rxirq (struct altera_tse_private *); -void msgdma_disable_txirq (struct altera_tse_private *); -void msgdma_clear_rxirq (struct altera_tse_private *); -void msgdma_clear_txirq (struct altera_tse_private *); -u32 msgdma_tx_completions (struct altera_tse_private *); -void msgdma_add_rx_desc (struct altera_tse_private *,struct tse_buffer *); -int msgdma_tx_buffer (struct altera_tse_private *,struct tse_buffer *); -u32 msgdma_rx_status (struct altera_tse_private *); -int msgdma_initialize (struct altera_tse_private *); -void msgdma_uninitialize (struct altera_tse_private *); -void msgdma_start_rxdma (struct altera_tse_private *); +void msgdma_reset (struct altera_tse_private *priv); +void msgdma_enable_txirq (struct altera_tse_private *priv); +void msgdma_enable_rxirq (struct altera_tse_private *priv); +void msgdma_disable_rxirq (struct altera_tse_private *priv); +void msgdma_disable_txirq (struct altera_tse_private *priv); +void msgdma_clear_rxirq (struct altera_tse_private *priv); +void msgdma_clear_txirq (struct altera_tse_private *priv); +u32 msgdma_tx_completions (struct altera_tse_private *priv); +void msgdma_add_rx_desc (struct altera_tse_private *priv, +struct tse_buffer *buffer); +int msgdma_tx_buffer (struct altera_tse_private *priv, +struct tse_buffer *buffer); +u32 msgdma_rx_status (struct altera_tse_private *priv); +int msgdma_initialize (struct altera_tse_private *priv); +void msgdma_uninitialize (struct altera_tse_private *priv); +void msgdma_start_rxdma (struct altera_tse_private *priv);#endif /* __ALTERA_MSGDMA_H__ */
drivers/net/ethernet/altera/altera_sgdma.h +17 -15
@@ -6,20 +6,22 @@#ifndef __ALTERA_SGDMA_H__#define __ALTERA_SGDMA_H__ -void sgdma_reset (struct altera_tse_private *); -void sgdma_enable_txirq (struct altera_tse_private *); -void sgdma_enable_rxirq (struct altera_tse_private *); -void sgdma_disable_rxirq (struct altera_tse_private *); -void sgdma_disable_txirq (struct altera_tse_private *); -void sgdma_clear_rxirq (struct altera_tse_private *); -void sgdma_clear_txirq (struct altera_tse_private *); -int sgdma_tx_buffer (struct altera_tse_private *priv,struct tse_buffer *); -u32 sgdma_tx_completions (struct altera_tse_private *); -void sgdma_add_rx_desc (struct altera_tse_private *priv,struct tse_buffer *); -void sgdma_status (struct altera_tse_private *); -u32 sgdma_rx_status (struct altera_tse_private *); -int sgdma_initialize (struct altera_tse_private *); -void sgdma_uninitialize (struct altera_tse_private *); -void sgdma_start_rxdma (struct altera_tse_private *); +void sgdma_reset (struct altera_tse_private *priv); +void sgdma_enable_txirq (struct altera_tse_private *priv); +void sgdma_enable_rxirq (struct altera_tse_private *priv); +void sgdma_disable_rxirq (struct altera_tse_private *priv); +void sgdma_disable_txirq (struct altera_tse_private *priv); +void sgdma_clear_rxirq (struct altera_tse_private *priv); +void sgdma_clear_txirq (struct altera_tse_private *priv); +int sgdma_tx_buffer (struct altera_tse_private *priv, +struct tse_buffer *buffer); +u32 sgdma_tx_completions (struct altera_tse_private *priv); +void sgdma_add_rx_desc (struct altera_tse_private *priv, +struct tse_buffer *buffer); +void sgdma_status (struct altera_tse_private *priv); +u32 sgdma_rx_status (struct altera_tse_private *priv); +int sgdma_initialize (struct altera_tse_private *priv); +void sgdma_uninitialize (struct altera_tse_private *priv); +void sgdma_start_rxdma (struct altera_tse_private *priv);#endif /* __ALTERA_SGDMA_H__ */
Signature · 1 line
2.13.0
Re: [PATCH v4 06/10] net: eth: altera: Add missing identifier names to function declarations
Quoted 90 lines · Joyce
From: Dalon Westergreen <[email protected]>
The sgdma and msgdma header files included function declarations without identifier names for pointers. Add appropriate identifier names.
Signed-off-by Dalon Westergreen <[email protected]>Signed-off-by Joyce Ooi <[email protected]>---
v2: this patch is added in patch version 2
v3: no change
v4: no change--- drivers/net/ethernet/altera/altera_msgdma.h | 30 ++++++++++++++------------- drivers/net/ethernet/altera/altera_sgdma.h | 32 +++++++++++++++-------------- 2 files changed, 33 insertions(+), 29 deletions(-)drivers/net/ethernet/altera/altera_msgdma.h +16
-14@@ -6,19 +6,21 @@#ifndef __ALTERA_MSGDMA_H__#define __ALTERA_MSGDMA_H__ -void msgdma_reset (struct altera_tse_private *); -void msgdma_enable_txirq (struct altera_tse_private *); -void msgdma_enable_rxirq (struct altera_tse_private *); -void msgdma_disable_rxirq (struct altera_tse_private *); -void msgdma_disable_txirq (struct altera_tse_private *); -void msgdma_clear_rxirq (struct altera_tse_private *); -void msgdma_clear_txirq (struct altera_tse_private *); -u32 msgdma_tx_completions (struct altera_tse_private *); -void msgdma_add_rx_desc (struct altera_tse_private *,struct tse_buffer *); -int msgdma_tx_buffer (struct altera_tse_private *,struct tse_buffer *); -u32 msgdma_rx_status (struct altera_tse_private *); -int msgdma_initialize (struct altera_tse_private *); -void msgdma_uninitialize (struct altera_tse_private *); -void msgdma_start_rxdma (struct altera_tse_private *); +void msgdma_reset (struct altera_tse_private *priv); +void msgdma_enable_txirq (struct altera_tse_private *priv); +void msgdma_enable_rxirq (struct altera_tse_private *priv); +void msgdma_disable_rxirq (struct altera_tse_private *priv); +void msgdma_disable_txirq (struct altera_tse_private *priv); +void msgdma_clear_rxirq (struct altera_tse_private *priv); +void msgdma_clear_txirq (struct altera_tse_private *priv); +u32 msgdma_tx_completions (struct altera_tse_private *priv); +void msgdma_add_rx_desc (struct altera_tse_private *priv, +struct tse_buffer *buffer); +int msgdma_tx_buffer (struct altera_tse_private *priv, +struct tse_buffer *buffer); +u32 msgdma_rx_status (struct altera_tse_private *priv); +int msgdma_initialize (struct altera_tse_private *priv); +void msgdma_uninitialize (struct altera_tse_private *priv); +void msgdma_start_rxdma (struct altera_tse_private *priv);#endif /* __ALTERA_MSGDMA_H__ */ drivers/net/ethernet/altera/altera_sgdma.h +9
-15@@ -6,20 +6,22 @@#ifndef __ALTERA_SGDMA_H__#define __ALTERA_SGDMA_H__ -void sgdma_reset (struct altera_tse_private *); -void sgdma_enable_txirq (struct altera_tse_private *); -void sgdma_enable_rxirq (struct altera_tse_private *); -void sgdma_disable_rxirq (struct altera_tse_private *); -void sgdma_disable_txirq (struct altera_tse_private *); -void sgdma_clear_rxirq (struct altera_tse_private *); -void sgdma_clear_txirq (struct altera_tse_private *); -int sgdma_tx_buffer (struct altera_tse_private *priv,struct tse_buffer *); -u32 sgdma_tx_completions (struct altera_tse_private *); -void sgdma_add_rx_desc (struct altera_tse_private *priv,struct tse_buffer *); -void sgdma_status (struct altera_tse_private *); -u32 sgdma_rx_status (struct altera_tse_private *); -int sgdma_initialize (struct altera_tse_private *); -void sgdma_uninitialize (struct altera_tse_private *); -void sgdma_start_rxdma (struct altera_tse_private *); +void sgdma_reset (struct altera_tse_private *priv); +void sgdma_enable_txirq (struct altera_tse_private *priv); +void sgdma_enable_rxirq (struct altera_tse_private *priv); +void sgdma_disable_rxirq (struct altera_tse_private *priv); +void sgdma_disable_txirq (struct altera_tse_private *priv); +void sgdma_clear_rxirq (struct altera_tse_private *priv); +void sgdma_clear_txirq (struct altera_tse_private *priv); +int sgdma_tx_buffer (struct altera_tse_private *priv, +struct tse_buffer *buffer);
drivers/net/ethernet/altera/altera_sgdma.h line 27
Quoted 10 lines
drivers/net/ethernet/altera/altera_sgdma.h +8
-0+u32 sgdma_tx_completions (struct altera_tse_private *priv); +void sgdma_add_rx_desc (struct altera_tse_private *priv, +struct tse_buffer *buffer); +void sgdma_status (struct altera_tse_private *priv); +u32 sgdma_rx_status (struct altera_tse_private *priv); +int sgdma_initialize (struct altera_tse_private *priv); +void sgdma_uninitialize (struct altera_tse_private *priv); +void sgdma_start_rxdma (struct altera_tse_private *priv);#endif /* __ALTERA_SGDMA_H__ */
PATCH v4 7/10 net: eth: altera: change tx functions to type netdev_tx_t
In reply to Ooi, JoyceFrom: Dalon Westergreen <[email protected]>
Modify all msgdma and sgdma tx_buffer functions to be of type netdev_tx_t, and also modify main tx function to be of netdev_tx_t type.
---
v2: this patch is added in patch version 2
v3: no change
v4: no change
--- drivers/net/ethernet/altera/altera_msgdma.c | 5 +++-- drivers/net/ethernet/altera/altera_msgdma.h | 4 ++-- drivers/net/ethernet/altera/altera_sgdma.c | 5 +++-- drivers/net/ethernet/altera/altera_sgdma.h | 4 ++-- drivers/net/ethernet/altera/altera_tse.h | 4 ++-- 5 files changed, 12 insertions(+), 10 deletions(-)
drivers/net/ethernet/altera/altera_msgdma.c +3 -2
@@ -106,7 +106,8 @@ void msgdma_clear_txirq(struct altera_tse_private *priv) }/* return 0 to indicate transmit is pending */ -int msgdma_tx_buffer (struct altera_tse_private *priv,struct tse_buffer *buffer) +netdev_tx_t +msgdma_tx_buffer (struct altera_tse_private *priv,struct tse_buffer *buffer) {csrwr32 (lower_32_bits (buffer->dma_addr), priv->tx_dma_desc,msgdma_descroffs (read_addr_lo));
@@ -120,7 +121,7 @@ int msgdma_tx_buffer(struct altera_tse_private *priv, struct tse_buffer *buffer) msgdma_descroffs(stride));csrwr32 (MSGDMA_DESC_CTL_TX_SINGLE , priv->tx_dma_desc,msgdma_descroffs (control)); -return 0 ; +return NETDEV_TX_OK ; }u32 msgdma_tx_completions (struct altera_tse_private *priv)
drivers/net/ethernet/altera/altera_msgdma.h +2 -2
@@ -16,8 +16,8 @@ void msgdma_clear_txirq(struct altera_tse_private *priv);u32 msgdma_tx_completions (struct altera_tse_private *priv);void msgdma_add_rx_desc (struct altera_tse_private *priv,struct tse_buffer *buffer); -int msgdma_tx_buffer (struct altera_tse_private *priv, -struct tse_buffer *buffer); +netdev_tx_t msgdma_tx_buffer (struct altera_tse_private *priv, +struct tse_buffer *buffer);u32 msgdma_rx_status (struct altera_tse_private *priv);int msgdma_initialize (struct altera_tse_private *priv);void msgdma_uninitialize (struct altera_tse_private *priv);
drivers/net/ethernet/altera/altera_sgdma.c +3 -2
@@ -166,7 +166,8 @@ void sgdma_clear_txirq(struct altera_tse_private *priv)* will now actually look at the code, so from now, 0 is good and return * NETDEV_TX_BUSY when busy. */ -int sgdma_tx_buffer (struct altera_tse_private *priv,struct tse_buffer *buffer) +netdev_tx_t +sgdma_tx_buffer (struct altera_tse_private *priv,struct tse_buffer *buffer) {struct sgdma_descrip __iomem *descbase = (struct sgdma_descrip __iomem *)priv->tx_dma_desc;
@@ -196,7 +197,7 @@ int sgdma_tx_buffer(struct altera_tse_private *priv, struct tse_buffer *buffer)/* enqueue the request to the pending transmit queue */ queue_tx (priv, buffer); -return 0 ; +return NETDEV_TX_OK ; }
drivers/net/ethernet/altera/altera_sgdma.h +2 -2
@@ -13,8 +13,8 @@ void sgdma_disable_rxirq(struct altera_tse_private *priv);void sgdma_disable_txirq (struct altera_tse_private *priv);void sgdma_clear_rxirq (struct altera_tse_private *priv);void sgdma_clear_txirq (struct altera_tse_private *priv); -int sgdma_tx_buffer (struct altera_tse_private *priv, -struct tse_buffer *buffer); +netdev_tx_t sgdma_tx_buffer (struct altera_tse_private *priv, +struct tse_buffer *buffer);u32 sgdma_tx_completions (struct altera_tse_private *priv);void sgdma_add_rx_desc (struct altera_tse_private *priv,struct tse_buffer *buffer);
drivers/net/ethernet/altera/altera_tse.h +2 -2
@@ -392,8 +392,8 @@ struct altera_dmaops {void (*disable_rxirq)(struct altera_tse_private *priv);void (*clear_txirq)(struct altera_tse_private *priv);void (*clear_rxirq)(struct altera_tse_private *priv); -int (*tx_buffer)(struct altera_tse_private *priv, -struct tse_buffer *buffer); +netdev_tx_t (*tx_buffer)(struct altera_tse_private *priv, +struct tse_buffer *buffer);u32 (*tx_completions)(struct altera_tse_private *priv);void (*add_rx_desc)(struct altera_tse_private *priv,struct tse_buffer *buffer);
Signature · 1 line
2.13.0
Re: [PATCH v4 07/10] net: eth: altera: change tx functions to type netdev_tx_t
Quoted 102 lines · Joyce
From: Dalon Westergreen <[email protected]>
Modify all msgdma and sgdma
tx_bufferfunctions to be of typenetdev_tx_t, and also modify main tx function to be ofnetdev_tx_ttype.Signed-off-by Dalon Westergreen <[email protected]>Signed-off-by Joyce Ooi <[email protected]>---
v2: this patch is added in patch version 2
v3: no change
v4: no change--- drivers/net/ethernet/altera/altera_msgdma.c | 5 +++-- drivers/net/ethernet/altera/altera_msgdma.h | 4 ++-- drivers/net/ethernet/altera/altera_sgdma.c | 5 +++-- drivers/net/ethernet/altera/altera_sgdma.h | 4 ++-- drivers/net/ethernet/altera/altera_tse.h | 4 ++-- 5 files changed, 12 insertions(+), 10 deletions(-)drivers/net/ethernet/altera/altera_msgdma.c +3
-2@@ -106,7 +106,8 @@ void msgdma_clear_txirq(struct altera_tse_private *priv) }/* return 0 to indicate transmit is pending */ -int msgdma_tx_buffer (struct altera_tse_private *priv,struct tse_buffer *buffer) +netdev_tx_t +msgdma_tx_buffer (struct altera_tse_private *priv,struct tse_buffer *buffer) {csrwr32 (lower_32_bits (buffer->dma_addr), priv->tx_dma_desc,msgdma_descroffs (read_addr_lo));@@ -120,7 +121,7 @@ int msgdma_tx_buffer(struct altera_tse_private *priv, struct tse_buffer *buffer) msgdma_descroffs(stride));csrwr32 (MSGDMA_DESC_CTL_TX_SINGLE , priv->tx_dma_desc,msgdma_descroffs (control)); -return 0 ; +return NETDEV_TX_OK ; }u32 msgdma_tx_completions (struct altera_tse_private *priv)drivers/net/ethernet/altera/altera_msgdma.h +2
-2@@ -16,8 +16,8 @@ void msgdma_clear_txirq(struct altera_tse_private *priv);u32 msgdma_tx_completions (struct altera_tse_private *priv);void msgdma_add_rx_desc (struct altera_tse_private *priv,struct tse_buffer *buffer); -int msgdma_tx_buffer (struct altera_tse_private *priv, -struct tse_buffer *buffer); +netdev_tx_t msgdma_tx_buffer (struct altera_tse_private *priv, +struct tse_buffer *buffer);u32 msgdma_rx_status (struct altera_tse_private *priv);int msgdma_initialize (struct altera_tse_private *priv);void msgdma_uninitialize (struct altera_tse_private *priv);drivers/net/ethernet/altera/altera_sgdma.c +3
-2@@ -166,7 +166,8 @@ void sgdma_clear_txirq(struct altera_tse_private *priv)* will now actually look at the code, so from now, 0 is good and return * NETDEV_TX_BUSY when busy. */ -int sgdma_tx_buffer (struct altera_tse_private *priv,struct tse_buffer *buffer) +netdev_tx_t +sgdma_tx_buffer (struct altera_tse_private *priv,struct tse_buffer *buffer) {struct sgdma_descrip __iomem *descbase = (struct sgdma_descrip __iomem *)priv->tx_dma_desc;@@ -196,7 +197,7 @@ int sgdma_tx_buffer(struct altera_tse_private *priv, struct tse_buffer *buffer)/* enqueue the request to the pending transmit queue */ queue_tx (priv, buffer); -return 0 ; +return NETDEV_TX_OK ; }drivers/net/ethernet/altera/altera_sgdma.h +2
-2@@ -13,8 +13,8 @@ void sgdma_disable_rxirq(struct altera_tse_private *priv);void sgdma_disable_txirq (struct altera_tse_private *priv);void sgdma_clear_rxirq (struct altera_tse_private *priv);void sgdma_clear_txirq (struct altera_tse_private *priv); -int sgdma_tx_buffer (struct altera_tse_private *priv, -struct tse_buffer *buffer); +netdev_tx_t sgdma_tx_buffer (struct altera_tse_private *priv, +struct tse_buffer *buffer);u32 sgdma_tx_completions (struct altera_tse_private *priv);void sgdma_add_rx_desc (struct altera_tse_private *priv,struct tse_buffer *buffer);drivers/net/ethernet/altera/altera_tse.h +0
-0
drivers/net/ethernet/altera/altera_tse.h struct altera_dmaops { · line 399
Quoted 10 lines
drivers/net/ethernet/altera/altera_tse.h +2
-2@@ -392,8 +392,8 @@ struct altera_dmaops {void (*disable_rxirq)(struct altera_tse_private *priv);void (*clear_txirq)(struct altera_tse_private *priv);void (*clear_rxirq)(struct altera_tse_private *priv); -int (*tx_buffer)(struct altera_tse_private *priv, -struct tse_buffer *buffer); +netdev_tx_t (*tx_buffer)(struct altera_tse_private *priv, +struct tse_buffer *buffer);u32 (*tx_completions)(struct altera_tse_private *priv);void (*add_rx_desc)(struct altera_tse_private *priv,struct tse_buffer *buffer);
PATCH v4 8/10 net: eth: altera: add support for ptp and timestamping
In reply to Ooi, JoyceFrom: Dalon Westergreen <[email protected]>
Add support for the ptp clock used with the tse, and update the driver to support timestamping when enabled. We also enable debugfs entries for the ptp clock to allow some user control and interaction with the ptp clock.
---
v2: this patch is added in patch version 2
v3: no change
v4: no change
--- drivers/net/ethernet/altera/Kconfig | 1 + drivers/net/ethernet/altera/Makefile | 3 +- drivers/net/ethernet/altera/altera_tse.h | 8 + drivers/net/ethernet/altera/altera_tse_ethtool.c | 28 ++ drivers/net/ethernet/altera/altera_tse_main.c | 118 +++++++- drivers/net/ethernet/altera/intel_fpga_tod.c | 358 +++++++++++++++++++++++ drivers/net/ethernet/altera/intel_fpga_tod.h | 56 ++++ 7 files changed, 570 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ethernet/altera/intel_fpga_tod.c create mode 100644 drivers/net/ethernet/altera/intel_fpga_tod.h
drivers/net/ethernet/altera/Kconfig +1 -0
@@ -3,6 +3,7 @@ config ALTERA_TSE tristate "Altera Triple-Speed Ethernet MAC support" depends on HAS_DMA select PHYLIB + imply PTP_1588_CLOCK help This driver supports the Altera Triple-Speed (TSE) Ethernet MAC.
drivers/net/ethernet/altera/Makefile +2 -1
@@ -5,4 +5,5 @@ obj-$(CONFIG_ALTERA_TSE) += altera_tse.o altera_tse-objs := altera_tse_main.o altera_tse_ethtool.o \ -altera_msgdma.o altera_sgdma.o altera_utils.o + altera_msgdma.o altera_sgdma.o altera_utils.o \ + intel_fpga_tod.o
drivers/net/ethernet/altera/altera_tse.h +8 -0
@@ -28,6 +28,8 @@#include <linux/netdevice.h> #include <linux/phy.h> +#include "intel_fpga_tod.h" +#define ALTERA_TSE_SW_RESET_WATCHDOG_CNTR 10000#define ALTERA_TSE_MAC_FIFO_WIDTH 4/* TX/RX FIFO width in * bytes
@@ -417,6 +419,12 @@ struct altera_tse_private {/* TSE Revision */ u32 revision; +/* Shared PTP structure */ +struct intel_fpga_tod_private ptp_priv; +int hwts_tx_en; +int hwts_rx_en; +u32 ptp_enable; +/* mSGDMA Rx Dispatcher address space */ void __iomem *rx_dma_csr;void __iomem *rx_dma_desc;
drivers/net/ethernet/altera/altera_tse_ethtool.c +28 -0
@@ -19,6 +19,7 @@#include <linux/ethtool.h> #include <linux/kernel.h> #include <linux/netdevice.h> +#include <linux/net_tstamp.h> #include <linux/phy.h> #include "altera_tse.h"
@@ -222,6 +223,32 @@ static void tse_get_regs(struct net_device *dev, struct ethtool_regs *regs, buf[i] =csrrd32 (priv->mac_dev, i *4 ); } +static int tse_get_ts_info (struct net_device *dev, +struct ethtool_ts_info *info) +{ +struct altera_tse_private *priv =netdev_priv (dev); + +if (priv->ptp_enable) { +if (priv->ptp_priv.ptp_clock) + info->phc_index = +ptp_clock_index (priv->ptp_priv.ptp_clock); + + info->so_timestamping =SOF_TIMESTAMPING_TX_HARDWARE | +SOF_TIMESTAMPING_RX_HARDWARE | +SOF_TIMESTAMPING_RAW_HARDWARE ; + + info->tx_types = (1 <<HWTSTAMP_TX_OFF ) | + (1 <<HWTSTAMP_TX_ON ); + + info->rx_filters = (1 <<HWTSTAMP_FILTER_NONE ) | + (1 <<HWTSTAMP_FILTER_ALL ); + +return 0 ; + }else { +return ethtool_op_get_ts_info (dev, info); + } +} +static const struct ethtool_ops tse_ethtool_ops = { .get_drvinfo = tse_get_drvinfo, .get_regs_len = tse_reglen,
@@ -234,6 +261,7 @@ static const struct ethtool_ops tse_ethtool_ops = { .set_msglevel = tse_set_msglevel, .get_link_ksettings = phy_ethtool_get_link_ksettings, .set_link_ksettings = phy_ethtool_set_link_ksettings, + .get_ts_info = tse_get_ts_info, };void altera_tse_set_ethtool_ops (struct net_device *netdev)
drivers/net/ethernet/altera/altera_tse_main.c +117 -1
174 lines not on this page · raw message
drivers/net/ethernet/altera/intel_fpga_tod.c new file +358 -0
358 lines not on this page · raw message
drivers/net/ethernet/altera/intel_fpga_tod.h new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.13.0
Re: [PATCH v4 08/10] net: eth: altera: add support for ptp and timestamping
drivers/net/ethernet/altera/altera_tse_ethtool.c static void tse_get_regs(struct net_device *dev, struct ethtool_regs *regs, · line 234
Quoted 13 lines · Joyce
drivers/net/ethernet/altera/altera_tse_ethtool.c +9
-0@@ -222,6 +223,32 @@ static void tse_get_regs(struct net_device *dev, struct ethtool_regs *regs, buf[i] =csrrd32 (priv->mac_dev, i *4 ); } +static int tse_get_ts_info (struct net_device *dev, +struct ethtool_ts_info *info) +{ +struct altera_tse_private *priv =netdev_priv (dev); + +if (priv->ptp_enable) { +if (priv->ptp_priv.ptp_clock) + info->phc_index = +ptp_clock_index (priv->ptp_priv.ptp_clock);
Need to handle case where priv->ptp_priv.ptp_clock == NULL.
drivers/net/ethernet/altera/altera_tse_ethtool.c static void tse_get_regs(struct net_device *dev, struct ethtool_regs *regs, · line 241
Quoted 6 lines
drivers/net/ethernet/altera/altera_tse_ethtool.c +6
-0+ info->so_timestamping =SOF_TIMESTAMPING_TX_HARDWARE | +SOF_TIMESTAMPING_RX_HARDWARE | +SOF_TIMESTAMPING_RAW_HARDWARE ; + + info->tx_types = (1 <<HWTSTAMP_TX_OFF ) | + (1 <<HWTSTAMP_TX_ON );
No need to break statement. This fits nicely on one line.
drivers/net/ethernet/altera/altera_tse_ethtool.c static void tse_get_regs(struct net_device *dev, struct ethtool_regs *regs, · line 247
Quoted 6 lines
drivers/net/ethernet/altera/altera_tse_ethtool.c +6
-0+ + info->rx_filters = (1 <<HWTSTAMP_FILTER_NONE ) | + (1 <<HWTSTAMP_FILTER_ALL ); + +return 0 ; + }else {
No need for else block.
Quoted 10 lines
drivers/net/ethernet/altera/altera_tse_ethtool.c +4
-0+return ethtool_op_get_ts_info (dev, info); + } +} +static const struct ethtool_ops tse_ethtool_ops = { .get_drvinfo = tse_get_drvinfo, .get_regs_len = tse_reglen,
drivers/net/ethernet/altera/altera_tse_ethtool.c static int tse_shutdown(struct net_device *dev) · line 1331
Quoted 8 lines
drivers/net/ethernet/altera/altera_tse_ethtool.c +5
-0@@ -1309,6 +1324,83 @@ static int tse_shutdown(struct net_device *dev)return 0 ; } +/* ioctl to configure timestamping */ +static int tse_do_ioctl (struct net_device *dev,struct ifreq *ifr,int cmd) +{ +struct altera_tse_private *priv =netdev_priv (dev); +struct hwtstamp_config config;
Need to check here for phy_has_hwtstamp() and pass through to PHY layer if true.
Quoted 78 lines
drivers/net/ethernet/altera/altera_tse_main.c +72
-0+ +if (!netif_running (dev)) +return -EINVAL ; + +if (!priv->ptp_enable) { +netdev_alert (priv->dev,"Timestamping not supported" ); +return -EOPNOTSUPP ; + } + +if (cmd ==SIOCSHWTSTAMP ) { +if (copy_from_user (&config, ifr->ifr_data, +sizeof (struct hwtstamp_config ))) +return -EFAULT ; + +if (config.flags) +return -EINVAL ; + +switch (config.tx_type) { +case HWTSTAMP_TX_OFF : + priv->hwts_tx_en =0 ; +break ; +case HWTSTAMP_TX_ON : + priv->hwts_tx_en =1 ; +break ; +default : +return -ERANGE ; + } + +switch (config.rx_filter) { +case HWTSTAMP_FILTER_NONE : + priv->hwts_rx_en =0 ; + config.rx_filter =HWTSTAMP_FILTER_NONE ; +break ; +default : + priv->hwts_rx_en =1 ; + config.rx_filter =HWTSTAMP_FILTER_ALL ; +break ; + } + +if (copy_to_user (ifr->ifr_data, &config, +sizeof (struct hwtstamp_config ))) +return -EFAULT ; +else +return 0 ; + } + +if (cmd ==SIOCGHWTSTAMP ) { + config.flags =0 ; + +if (priv->hwts_tx_en) + config.tx_type =HWTSTAMP_TX_ON ; +else + config.tx_type =HWTSTAMP_TX_OFF ; + +if (priv->hwts_rx_en) + config.rx_filter =HWTSTAMP_FILTER_ALL ; +else + config.rx_filter =HWTSTAMP_FILTER_NONE ; + +if (copy_to_user (ifr->ifr_data, &config, +sizeof (struct hwtstamp_config ))) +return -EFAULT ; +else +return 0 ; + } + +if (!dev->phydev) +return -EINVAL ; + +return phy_mii_ioctl (dev->phydev, ifr, cmd); +} +static struct net_device_ops altera_tse_netdev_ops = { .ndo_open = tse_open, .ndo_stop = tse_shutdown,
drivers/net/ethernet/altera/altera_tse_main.c static int altera_tse_probe(struct platform_device *pdev) · line 1666
Quoted 6 lines
drivers/net/ethernet/altera/altera_tse_main.c +3
-0@@ -1568,6 +1661,27 @@ static int altera_tse_probe(struct platform_device *pdev)netdev_err (ndev,"Cannot attach to PHY (error: %d)\n" , ret); goto err_init_phy; } + + priv->ptp_enable =of_property_read_bool (pdev->dev.of_node, +"altr,has-ptp" );
The name "ptp_enable" is a poor choice. It sounds like something that can be enabled at run time. Suggest "has_ptp" instead.
Quoted 20 lines
drivers/net/ethernet/altera/altera_tse_main.c +18
-0+dev_info (&pdev->dev,"PTP Enable: %d\n" , priv->ptp_enable); + +if (priv->ptp_enable) { +/* MAP PTP */ + ret =intel_fpga_tod_probe (pdev, &priv->ptp_priv); +if (ret) { +dev_err (&pdev->dev,"cannot map PTP\n" ); + goto err_init_phy; + } + ret =intel_fpga_tod_register (&priv->ptp_priv, + priv->device); +if (ret) { +dev_err (&pdev->dev,"Failed to register PTP clock\n" ); + ret = -ENXIO ; + goto err_init_phy; + } + } +return 0 ;
drivers/net/ethernet/altera/altera_tse_main.c static int altera_tse_probe(struct platform_device *pdev)
Quoted 10 lines
drivers/net/ethernet/altera/altera_tse_main.c +7
-0err_init_phy: +/* Initialize PTP control block registers */ +int intel_fpga_tod_init(struct intel_fpga_tod_private *priv) +{ +struct timespec64 now; +int ret =0 ; + + ret =intel_fpga_tod_adjust_fine (&priv->ptp_clock_ops,0l );
Why clobber a learned frequency offset here? If user space closes then re-opens, then it expects the old frequency to be preserved.
It is fine to set this to zero when the driver loads, but not after.
drivers/net/ethernet/altera/intel_fpga_tod.c line 288
Quoted 5 lines
drivers/net/ethernet/altera/intel_fpga_tod.c new file +5
-0+if (ret !=0 ) + goto out; + +/* Initialize the hardware clock to the system time */ +ktime_get_real_ts64 (&now);
Please initialize to zero instead, as some people prefer it that way.
(But only the first time when the driver loads!)
drivers/net/ethernet/altera/intel_fpga_tod.c line 295
Quoted 7 lines
drivers/net/ethernet/altera/intel_fpga_tod.c new file +7
-0+intel_fpga_tod_set_time (&priv->ptp_clock_ops, &now); + +spin_lock_init (&priv->tod_lock); + +out: +return ret; +}
Thanks,
Richard
RE: [PATCH v4 08/10] net: eth: altera: add support for ptp and timestamping
Quoted 20 lines
-----Original Message-----
From: Richard Cochran <[email protected]>
Sent: Thursday, July 9, 2020 7:31 PM
To: Ooi, Joyce <[email protected]>
Cc: Thor Thayer <[email protected]>; David S . Miller <[email protected]>; Jakub Kicinski <[email protected]>; [email protected]; [email protected]; Dalon Westergreen <[email protected]>; Tan, Ley Foon <[email protected]>; See, Chin Liang <[email protected]>; Nguyen, Dinh <[email protected]>; Westergreen, Dalon <[email protected]>
Subject: Re: [PATCH v4 08/10] net: eth: altera: add support for ptp and timestampingReview static void tse_get_regs(struct net_device *dev,
Quoted 1 line · Joyce
(quoted diff) +0
-0@@ -222,6 +223,32 @@ static void tse_get_regs(struct net_device *dev,struct
ethtool_regs*regs,Quoted 2 lines
(quoted diff) +0
-0buf[i] = csrrd32(priv->mac_dev, i * 4); }
Quoted 11 lines
drivers/net/ethernet/altera/altera_tse_ethtool.c static void tse_get_regs(struct net_device *dev, struct ethtool_regs *regs, · line 234
Quoted 9 lines
drivers/net/ethernet/altera/altera_tse_ethtool.c +9
-0+static int tse_get_ts_info (struct net_device *dev, +struct ethtool_ts_info *info) +{ +struct altera_tse_private *priv =netdev_priv (dev); + +if (priv->ptp_enable) { +if (priv->ptp_priv.ptp_clock) + info->phc_index = +ptp_clock_index (priv->ptp_priv.ptp_clock);Need to handle case where
priv->ptp_priv.ptp_clock== NULL.
Ok, will add a checking if priv->ptp_priv.ptp_clock == NULL, it'll return error.
Quoted 17 lines
Review static void tse_get_regs(struct net_device *dev, · line 234
Quoted 2 lines
(quoted diff) +1
-0+ info->so_timestamping =
SOF_TIMESTAMPING_TX_HARDWARE|Review static void tse_get_regs(struct net_device *dev, · line 235
Quoted 1 line
(quoted diff) +1
-0+
SOF_TIMESTAMPING_RX_HARDWARE|Review static void tse_get_regs(struct net_device *dev, · line 236
Quoted 1 line
(quoted diff) +1
-0+SOF_TIMESTAMPING_RAW_HARDWARE;drivers/net/ethernet/altera/altera_tse_ethtool.c static void tse_get_regs(struct net_device *dev, struct ethtool_regs *regs, · line 241
Quoted 3 lines
drivers/net/ethernet/altera/altera_tse_ethtool.c +3
-0+ + info->tx_types = (1 <<HWTSTAMP_TX_OFF ) | + (1 <<HWTSTAMP_TX_ON );No need to break statement. This fits nicely on one line.
drivers/net/ethernet/altera/altera_tse_ethtool.c static void tse_get_regs(struct net_device *dev, struct ethtool_regs *regs,
Quoted 3 lines
drivers/net/ethernet/altera/altera_tse_ethtool.c +3
-0+ + info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) | + (1 <<
HWTSTAMP_FILTER_ALL);
Quoted 5 lines
drivers/net/ethernet/altera/altera_tse_ethtool.c static void tse_get_regs(struct net_device *dev, struct ethtool_regs *regs, · line 247
Quoted 3 lines
drivers/net/ethernet/altera/altera_tse_ethtool.c +3
-0+ +return 0 ; + }else {No need for else block.
Noted, will make the changes.
Quoted 14 lines
Quoted 14 lines
drivers/net/ethernet/altera/altera_tse_ethtool.c +4
-0+return ethtool_op_get_ts_info (dev, info); + } +} +static const struct ethtool_ops tse_ethtool_ops = { .get_drvinfo = tse_get_drvinfo, .get_regs_len = tse_reglen,@@ -1309,6 +1324,83 @@ static int tse_shutdown(struct net_device *dev)return 0 ; }
Quoted 7 lines
drivers/net/ethernet/altera/altera_tse_main.c static int tse_shutdown(struct net_device *dev) · line 1331
Quoted 4 lines
drivers/net/ethernet/altera/altera_tse_main.c +4
-0+/* ioctl to configure timestamping */ static int tse_do_ioctl (struct +net_device *dev,struct ifreq *ifr,int cmd) { +struct altera_tse_private *priv =netdev_priv (dev); +struct hwtstamp_config config;Need to check here for
phy_has_hwtstamp()and pass through to PHY layer if true.
Ok, will add a phy_has_hwtstamp checking before if (cmd == SIOCSHWTSTAMP) and if (cmd == SIOCGHWTSTAMP) are called.
Quoted 79 lines
drivers/net/ethernet/altera/altera_tse_main.c static int altera_tse_probe(struct
Quoted 78 lines
drivers/net/ethernet/altera/altera_tse_main.c +71
-0+ +if (!netif_running (dev)) +return -EINVAL ; + +if (!priv->ptp_enable) { +netdev_alert (priv->dev,"Timestamping not supported" ); +return -EOPNOTSUPP ; + } + +if (cmd ==SIOCSHWTSTAMP ) { +if (copy_from_user (&config, ifr->ifr_data, +sizeof (struct hwtstamp_config ))) +return -EFAULT ; + +if (config.flags) +return -EINVAL ; + +switch (config.tx_type) { +case HWTSTAMP_TX_OFF : + priv->hwts_tx_en =0 ; +break ; +case HWTSTAMP_TX_ON : + priv->hwts_tx_en =1 ; +break ; +default : +return -ERANGE ; + } + +switch (config.rx_filter) { +case HWTSTAMP_FILTER_NONE : + priv->hwts_rx_en =0 ; + config.rx_filter =HWTSTAMP_FILTER_NONE ; +break ; +default : + priv->hwts_rx_en =1 ; + config.rx_filter =HWTSTAMP_FILTER_ALL ; +break ; + } + +if (copy_to_user (ifr->ifr_data, &config, +sizeof (struct hwtstamp_config ))) +return -EFAULT ; +else +return 0 ; + } + +if (cmd ==SIOCGHWTSTAMP ) { + config.flags =0 ; + +if (priv->hwts_tx_en) + config.tx_type =HWTSTAMP_TX_ON ; +else + config.tx_type =HWTSTAMP_TX_OFF ; + +if (priv->hwts_rx_en) + config.rx_filter =HWTSTAMP_FILTER_ALL ; +else + config.rx_filter =HWTSTAMP_FILTER_NONE ; + +if (copy_to_user (ifr->ifr_data, &config, +sizeof (struct hwtstamp_config ))) +return -EFAULT ; +else +return 0 ; + } + +if (!dev->phydev) +return -EINVAL ; + +return phy_mii_ioctl (dev->phydev, ifr, cmd); } +static struct net_device_ops altera_tse_netdev_ops = { .ndo_open = tse_open, .ndo_stop = tse_shutdown,@@ -1568,6 +1661,27 @@ static int altera_tse_probe(struct
platform_device*pdev)
Quoted 9 lines
drivers/net/ethernet/altera/altera_tse_main.c static int altera_tse_probe(struct platform_device *pdev) · line 1666
Quoted 6 lines
drivers/net/ethernet/altera/altera_tse_main.c +3
-0netdev_err (ndev,"Cannot attach to PHY (error: %d)\n" , ret); goto err_init_phy; } + + priv->ptp_enable =of_property_read_bool (pdev->dev.of_node, +"altr,has-ptp" );The name "
ptp_enable" is a poor choice. It sounds like something that can be enabled at run time. Suggest "has_ptp" instead.
Ok, will rename to 'has_ptp'.
Quoted 35 lines
Quoted 4 lines
drivers/net/ethernet/altera/altera_tse_main.c +3
-0+dev_info (&pdev->dev,"PTP Enable: %d\n" , priv->ptp_enable); + +if (priv->ptp_enable) {drivers/net/ethernet/altera/altera_tse_main.c static int altera_tse_probe(struct platform_device *pdev)
Quoted 10 lines
drivers/net/ethernet/altera/altera_tse_main.c +10
-0+/* MAP PTP */ + ret =intel_fpga_tod_probe (pdev, &priv->ptp_priv); +if (ret) { +dev_err (&pdev->dev,"cannot map PTP\n" ); + goto err_init_phy; + } + ret =intel_fpga_tod_register (&priv->ptp_priv, + priv->device); +if (ret) { + dev_err(&pdev->dev, "Failed to register PTPclock\n");
Quoted 6 lines
drivers/net/ethernet/altera/altera_tse_main.c +5
-0+ ret = -ENXIO ; + goto err_init_phy; + } + } +return 0 ;drivers/net/ethernet/altera/altera_tse_main.c static int altera_tse_probe(struct platform_device *pdev)
Quoted 10 lines
drivers/net/ethernet/altera/altera_tse_main.c +6
-0err_init_phy: +/* Initialize PTP control block registers */ int +intel_fpga_tod_init(struct intel_fpga_tod_private *priv) { +struct timespec64 now; +int ret =0 ; + + ret =intel_fpga_tod_adjust_fine (&priv->ptp_clock_ops,0l );Why clobber a learned frequency offset here? If user space closes then re- opens, then it expects the old frequency to be preserved.
Quoted 1 line
It is fine to set this to zero when the driver loads, but not after.
I'll remove this adjust_fine() during init as it'll be called whenever the callback function is called.
Quoted 10 lines
drivers/net/ethernet/altera/intel_fpga_tod.c line 288
Quoted 6 lines
drivers/net/ethernet/altera/intel_fpga_tod.c new file +5
-0+if (ret !=0 ) + goto out; + +/* Initialize the hardware clock to the system time */ +ktime_get_real_ts64 (&now);Please initialize to zero instead, as some people prefer it that way.
(But only the first time when the driver loads!)
Ok sure, I'll initialize the hardware clock to 0.
Quoted 11 lines
drivers/net/ethernet/altera/intel_fpga_tod.c line 295
Quoted 8 lines
drivers/net/ethernet/altera/intel_fpga_tod.c new file +7
-0+intel_fpga_tod_set_time (&priv->ptp_clock_ops, &now); + +spin_lock_init (&priv->tod_lock); + +out: +return ret; +}Thanks,
Richard
Re: [PATCH v4 08/10] net: eth: altera: add support for ptp and timestamping
In reply to Ooi, JoyceQuoted 101 lines · Joyce
From: Dalon Westergreen <[email protected]>
Add support for the ptp clock used with the tse, and update the driver to support timestamping when enabled. We also enable debugfs entries for the ptp clock to allow some user control and interaction with the ptp clock.
Cc Richard Cochran <[email protected]>Signed-off-by Dalon Westergreen <[email protected]>Signed-off-by Joyce Ooi <[email protected]>Acked-by Richard Cochran <[email protected]>---
v2: this patch is added in patch version 2
v3: no change
v4: no change--- drivers/net/ethernet/altera/Kconfig | 1 + drivers/net/ethernet/altera/Makefile | 3 +- drivers/net/ethernet/altera/altera_tse.h | 8 + drivers/net/ethernet/altera/altera_tse_ethtool.c | 28 ++ drivers/net/ethernet/altera/altera_tse_main.c | 118 +++++++- drivers/net/ethernet/altera/intel_fpga_tod.c | 358 +++++++++++++++++++++++ drivers/net/ethernet/altera/intel_fpga_tod.h | 56 ++++ 7 files changed, 570 insertions(+), 2 deletions(-)create mode 100644
drivers/net/ethernet/altera/intel_fpga_tod.ccreate mode 100644drivers/net/ethernet/altera/intel_fpga_tod.hdrivers/net/ethernet/altera/Kconfig +1
-0@@ -3,6 +3,7 @@ config ALTERA_TSE tristate "Altera Triple-Speed Ethernet MAC support" depends on HAS_DMA select PHYLIB + imply PTP_1588_CLOCK help This driver supports the Altera Triple-Speed (TSE) Ethernet MAC.drivers/net/ethernet/altera/Makefile +2
-1@@ -5,4 +5,5 @@ obj-$(CONFIG_ALTERA_TSE) += altera_tse.o altera_tse-objs := altera_tse_main.o altera_tse_ethtool.o \ -altera_msgdma.o altera_sgdma.o altera_utils.o + altera_msgdma.o altera_sgdma.o altera_utils.o \ + intel_fpga_tod.odrivers/net/ethernet/altera/altera_tse.h +8
-0@@ -28,6 +28,8 @@#include <linux/netdevice.h> #include <linux/phy.h> +#include "intel_fpga_tod.h" +#define ALTERA_TSE_SW_RESET_WATCHDOG_CNTR 10000#define ALTERA_TSE_MAC_FIFO_WIDTH 4/* TX/RX FIFO width in * bytes @@ -417,6 +419,12 @@ struct altera_tse_private {/* TSE Revision */ u32 revision; +/* Shared PTP structure */ +struct intel_fpga_tod_private ptp_priv; +int hwts_tx_en; +int hwts_rx_en; +u32 ptp_enable; +/* mSGDMA Rx Dispatcher address space */ void __iomem *rx_dma_csr;void __iomem *rx_dma_desc;drivers/net/ethernet/altera/altera_tse_ethtool.c +10
-0@@ -19,6 +19,7 @@#include <linux/ethtool.h> #include <linux/kernel.h> #include <linux/netdevice.h> +#include <linux/net_tstamp.h> #include <linux/phy.h> #include "altera_tse.h" @@ -222,6 +223,32 @@ static void tse_get_regs(struct net_device *dev, struct ethtool_regs *regs, buf[i] =csrrd32 (priv->mac_dev, i *4 ); } +static int tse_get_ts_info (struct net_device *dev, +struct ethtool_ts_info *info) +{ +struct altera_tse_private *priv =netdev_priv (dev); + +if (priv->ptp_enable) { +if (priv->ptp_priv.ptp_clock) + info->phc_index = +ptp_clock_index (priv->ptp_priv.ptp_clock);
drivers/net/ethernet/altera/altera_tse_ethtool.c static void tse_get_regs(struct net_device *dev, struct ethtool_regs *regs, · line 244
Quoted 10 lines
drivers/net/ethernet/altera/altera_tse_ethtool.c +10
-0+ + info->so_timestamping =SOF_TIMESTAMPING_TX_HARDWARE | +SOF_TIMESTAMPING_RX_HARDWARE | +SOF_TIMESTAMPING_RAW_HARDWARE ; + + info->tx_types = (1 <<HWTSTAMP_TX_OFF ) | + (1 <<HWTSTAMP_TX_ON ) > + + info->rx_filters = (1 <<HWTSTAMP_FILTER_NONE ) | + (1 <<HWTSTAMP_FILTER_ALL ); +
Indentation looks off for these 2 above. Please check this.
Quoted 354 lines
drivers/net/ethernet/altera/altera_tse_ethtool.c +7
-0+return 0 ; + }else { +return ethtool_op_get_ts_info (dev, info); + } +} +static const struct ethtool_ops tse_ethtool_ops = { .get_drvinfo = tse_get_drvinfo, .get_regs_len = tse_reglen,@@ -234,6 +261,7 @@ static const struct ethtool_ops tse_ethtool_ops = { .set_msglevel = tse_set_msglevel, .get_link_ksettings = phy_ethtool_get_link_ksettings, .set_link_ksettings = phy_ethtool_set_link_ksettings, + .get_ts_info = tse_get_ts_info, };void altera_tse_set_ethtool_ops (struct net_device *netdev)drivers/net/ethernet/altera/altera_tse_main.c +117
-1@@ -18,14 +18,17 @@*/ #include <linux/atomic.h> +#include <linux/clk.h> #include <linux/delay.h> #include <linux/etherdevice.h> +#include <linux/if_ether.h> #include <linux/if_vlan.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/mii.h> +#include <linux/net_tstamp.h> #include <linux/netdevice.h> #include <linux/of_device.h> #include <linux/of_mdio.h> @@ -40,6 +43,7 @@#include "altera_tse.h" #include "altera_sgdma.h" #include "altera_msgdma.h" +#include "intel_fpga_tod.h" static atomic_t instance_count =ATOMIC_INIT (~0 );/* Module parameters */ @@ -598,7 +602,11 @@ static netdev_tx_t tse_start_xmit(struct sk_buff *skb, struct net_device *dev)if (ret) goto out; -skb_tx_timestamp (skb); +if (unlikely ((skb_shinfo (skb)->tx_flags &SKBTX_HW_TSTAMP ) && + priv->hwts_tx_en)) +skb_shinfo (skb)->tx_flags |=SKBTX_IN_PROGRESS ; +else +skb_tx_timestamp (skb); priv->tx_prod++; dev->stats.tx_bytes += skb->len;@@ -1238,6 +1246,13 @@ static int tse_open(struct net_device *dev)if (dev->phydev)phy_start (dev->phydev); + ret =intel_fpga_tod_init (&priv->ptp_priv); +if (ret) +netdev_warn (dev,"Failed PTP initialization\n" ); + + priv->hwts_tx_en =0 ; + priv->hwts_rx_en =0 ; +napi_enable (&priv->napi);netif_start_queue (dev);@@ -1309,6 +1324,83 @@ static int tse_shutdown(struct net_device *dev)return 0 ; } +/* ioctl to configure timestamping */ +static int tse_do_ioctl (struct net_device *dev,struct ifreq *ifr,int cmd) +{ +struct altera_tse_private *priv =netdev_priv (dev); +struct hwtstamp_config config; + +if (!netif_running (dev)) +return -EINVAL ; + +if (!priv->ptp_enable) { +netdev_alert (priv->dev,"Timestamping not supported" ); +return -EOPNOTSUPP ; + } + +if (cmd ==SIOCSHWTSTAMP ) { +if (copy_from_user (&config, ifr->ifr_data, +sizeof (struct hwtstamp_config ))) +return -EFAULT ; + +if (config.flags) +return -EINVAL ; + +switch (config.tx_type) { +case HWTSTAMP_TX_OFF : + priv->hwts_tx_en =0 ; +break ; +case HWTSTAMP_TX_ON : + priv->hwts_tx_en =1 ; +break ; +default : +return -ERANGE ; + } + +switch (config.rx_filter) { +case HWTSTAMP_FILTER_NONE : + priv->hwts_rx_en =0 ; + config.rx_filter =HWTSTAMP_FILTER_NONE ; +break ; +default : + priv->hwts_rx_en =1 ; + config.rx_filter =HWTSTAMP_FILTER_ALL ; +break ; + } + +if (copy_to_user (ifr->ifr_data, &config, +sizeof (struct hwtstamp_config ))) +return -EFAULT ; +else +return 0 ; + } + +if (cmd ==SIOCGHWTSTAMP ) { + config.flags =0 ; + +if (priv->hwts_tx_en) + config.tx_type =HWTSTAMP_TX_ON ; +else + config.tx_type =HWTSTAMP_TX_OFF ; + +if (priv->hwts_rx_en) + config.rx_filter =HWTSTAMP_FILTER_ALL ; +else + config.rx_filter =HWTSTAMP_FILTER_NONE ; + +if (copy_to_user (ifr->ifr_data, &config, +sizeof (struct hwtstamp_config ))) +return -EFAULT ; +else +return 0 ; + } + +if (!dev->phydev) +return -EINVAL ; + +return phy_mii_ioctl (dev->phydev, ifr, cmd); +} +static struct net_device_ops altera_tse_netdev_ops = { .ndo_open = tse_open, .ndo_stop = tse_shutdown,@@ -1317,6 +1409,7 @@ static struct net_device_ops altera_tse_netdev_ops = { .ndo_set_rx_mode = tse_set_rx_mode, .ndo_change_mtu = tse_change_mtu, .ndo_validate_addr = eth_validate_addr, + .ndo_do_ioctl = tse_do_ioctl, };/* Probe Altera TSE MAC device @@ -1568,6 +1661,27 @@ static int altera_tse_probe(struct platform_device *pdev)netdev_err (ndev,"Cannot attach to PHY (error: %d)\n" , ret); goto err_init_phy; } + + priv->ptp_enable =of_property_read_bool (pdev->dev.of_node, +"altr,has-ptp" ); +dev_info (&pdev->dev,"PTP Enable: %d\n" , priv->ptp_enable); + +if (priv->ptp_enable) { +/* MAP PTP */ + ret =intel_fpga_tod_probe (pdev, &priv->ptp_priv); +if (ret) { +dev_err (&pdev->dev,"cannot map PTP\n" ); + goto err_init_phy; + } + ret =intel_fpga_tod_register (&priv->ptp_priv, + priv->device); +if (ret) { +dev_err (&pdev->dev,"Failed to register PTP clock\n" ); + ret = -ENXIO ; + goto err_init_phy; + } + } +return 0 ; err_init_phy:@@ -1595,6 +1709,8 @@ static int altera_tse_remove(struct platform_device *pdev) }platform_set_drvdata (pdev,NULL ); +if (priv->ptp_enable) +intel_fpga_tod_unregister (&priv->ptp_priv);altera_tse_mdio_destroy (ndev);unregister_netdev (ndev);free_netdev (ndev);drivers/net/ethernet/altera/intel_fpga_tod.c new file +145
-0@@ -0,0 +1,358 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Intel FPGA ToD PTP Hardware Clock (PHC) Linux driver +* Copyright (C) 2015-2016 Altera Corporation. All rights reserved. +* Copyright (C) 2017-2020 Intel Corporation. All rights reserved. +* +* Author(s): +* Dalon Westergreen <[email protected]> +*/ + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/gcd.h> +#include <linux/module.h> +#include <linux/math64.h> +#include <linux/net_tstamp.h> +#include <linux/of_platform.h> +#include <linux/platform_device.h> + +#include "altera_utils.h" +#include "intel_fpga_tod.h" + +#define NOMINAL_PPB 1000000000ULL +#define TOD_PERIOD_MAX 0xfffff +#define TOD_PERIOD_MIN 0 +#define TOD_DRIFT_ADJUST_FNS_MAX 0xffff +#define TOD_DRIFT_ADJUST_RATE_MAX 0xffff +#define TOD_ADJUST_COUNT_MAX 0xfffff +#define TOD_ADJUST_MS_MAX (((((TOD_PERIOD_MAX) >> 16) + 1) * \ + ((TOD_ADJUST_COUNT_MAX) + 1)) / \ + 1000000UL) + +/* A fine ToD HW clock offset adjustment. +* To perform the fine offset adjustment the AdjustPeriod register is used +* to replace the Period register for AdjustCount clock cycles in hardware. +*/ +static int fine_adjust_tod_clock (struct intel_fpga_tod_private *priv, +u32 adjust_period,u32 adjust_count) +{ +int limit; + +csrwr32 (adjust_period, priv->tod_ctrl,tod_csroffs (adjust_period)); +csrwr32 (adjust_count, priv->tod_ctrl,tod_csroffs (adjust_count)); + +/* Wait for present offset adjustment update to complete */ + limit =TOD_ADJUST_MS_MAX ; +while (limit--) { +if (!csrrd32 (priv->tod_ctrl,tod_csroffs (adjust_count))) +break ; +mdelay (1 ); + } +if (limit <0 ) +return -EBUSY ; + +return 0 ; +} + +/* A coarse ToD HW clock offset adjustment. +* The coarse time adjustment performs by adding or subtracting the delta value +* from the current ToD HW clock time. +*/ +static int coarse_adjust_tod_clock (struct intel_fpga_tod_private *priv, +s64 delta) +{ +u32 seconds_msb, seconds_lsb, nanosec; +u64 seconds, now; + +if (delta ==0 ) + goto out; + +/* Get current time */ + nanosec =csrrd32 (priv->tod_ctrl,tod_csroffs (nanosec)); + seconds_lsb =csrrd32 (priv->tod_ctrl,tod_csroffs (seconds_lsb)); + seconds_msb =csrrd32 (priv->tod_ctrl,tod_csroffs (seconds_msb)); + +/* Calculate new time */ + seconds = (((u64)(seconds_msb &0x0000ffff )) <<32 ) | seconds_lsb; + now = seconds *NSEC_PER_SEC + nanosec + delta; + + seconds =div_u64_rem (now,NSEC_PER_SEC , &nanosec); + seconds_msb =upper_32_bits (seconds) &0x0000ffff ; + seconds_lsb =lower_32_bits (seconds); + +/* Set corrected time */ +csrwr32 (seconds_msb, priv->tod_ctrl,tod_csroffs (seconds_msb)); +csrwr32 (seconds_lsb, priv->tod_ctrl,tod_csroffs (seconds_lsb)); +csrwr32 (nanosec, priv->tod_ctrl,tod_csroffs (nanosec)); + +out: +return 0 ; +} + +static int intel_fpga_tod_adjust_fine (struct ptp_clock_info *ptp, +long scaled_ppm) +{ +struct intel_fpga_tod_private *priv = + container_of(ptp, struct intel_fpga_tod_private, ptp_clock_ops); +u32 tod_period, tod_rem, tod_drift_adjust_fns, tod_drift_adjust_rate; +unsigned long flags; +unsigned long rate; +int ret =0 ; +u64 ppb; + + rate =clk_get_rate (priv->tod_clk); + +/* From scaled_ppm_to_ppb */ + ppb =1 + scaled_ppm; + ppb *=125 ; + ppb >>=13 ; + + ppb +=NOMINAL_PPB ; + + tod_period =div_u64_rem (ppb <<16 , rate, &tod_rem); +if (tod_period >TOD_PERIOD_MAX ) { + ret = -ERANGE ; + goto out; + } + +/* The drift of ToD adjusted periodically by adding a drift_adjust_fns +* correction value every drift_adjust_rate count of clock cycles. +*/ + tod_drift_adjust_fns = tod_rem /gcd (tod_rem, rate); + tod_drift_adjust_rate = rate /gcd (tod_rem, rate); + +while ((tod_drift_adjust_fns >TOD_DRIFT_ADJUST_FNS_MAX ) | + (tod_drift_adjust_rate >TOD_DRIFT_ADJUST_RATE_MAX )) { + tod_drift_adjust_fns = tod_drift_adjust_fns >>1 ; + tod_drift_adjust_rate = tod_drift_adjust_rate >>1 ; + } + +if (tod_drift_adjust_fns ==0 ) + tod_drift_adjust_rate =0 ; + +spin_lock_irqsave (&priv->tod_lock, flags); +csrwr32 (tod_period, priv->tod_ctrl,tod_csroffs (period)); +csrwr32 (0 , priv->tod_ctrl,tod_csroffs (adjust_period)); +csrwr32 (0 , priv->tod_ctrl,tod_csroffs (adjust_count)); +csrwr32 (tod_drift_adjust_fns, priv->tod_ctrl, +tod_csroffs (drift_adjust)); +csrwr32 (tod_drift_adjust_rate, priv->tod_ctrl, +tod_csroffs (drift_adjust_rate)); +spin_unlock_irqrestore (&priv->tod_lock, flags); + +out: +return ret; +}
drivers/net/ethernet/altera/intel_fpga_tod.c line 155
Quoted 10 lines
drivers/net/ethernet/altera/intel_fpga_tod.c new file +10
-0+ +static int intel_fpga_tod_adjust_time (struct ptp_clock_info *ptp,s64 delta) +{ +struct intel_fpga_tod_private *priv = + container_of(ptp, struct intel_fpga_tod_private, ptp_clock_ops); +unsigned long flags; +u32 period, diff, rem, rem_period, adj_period; +u64 count; +int neg_adj =0 , ret =0 ; +
Suggest reverse christmas tree form.
Quoted 32 lines
drivers/net/ethernet/altera/intel_fpga_tod.c new file +32
-0+if (delta <0 ) { + neg_adj =1 ; + delta = -delta; + } + +spin_lock_irqsave (&priv->tod_lock, flags); + +/* Get the maximum possible value of the Period register offset +* adjustment in nanoseconds scale. This depends on the current +* Period register setting and the maximum and minimum possible +* values of the Period register. +*/ + period =csrrd32 (priv->tod_ctrl,tod_csroffs (period)); + +if (neg_adj) + diff = (period -TOD_PERIOD_MIN ) >>16 ; +else + diff = (TOD_PERIOD_MAX - period) >>16 ; + +/* Find the number of cycles required for the +* time adjustment +*/ + count =div_u64_rem (delta, diff, &rem); + +if (neg_adj) { + adj_period = period - (diff <<16 ); + rem_period = period - (rem <<16 ); + }else { + adj_period = period + (diff <<16 ); + rem_period = period + (rem <<16 ); + } +
drivers/net/ethernet/altera/intel_fpga_tod.c line 197
Quoted 10 lines
drivers/net/ethernet/altera/intel_fpga_tod.c new file +10
-0+/* If count is larger than the maximum count, +* just set the time. +*/ +if (count >TOD_ADJUST_COUNT_MAX ) { +/* Perform the coarse time offset adjustment */ + ret =coarse_adjust_tod_clock (priv, delta); + }else { +/* Adjust the period for count cycles to adjust +* the time. +*/
This comment could all be on 1 line.
Quoted 145 lines
drivers/net/ethernet/altera/intel_fpga_tod.c new file +145
-0+if (count) + ret =fine_adjust_tod_clock (priv, adj_period, count); + +/* If there is a remainder, adjust the period for an +* additional cycle +*/ +if (rem) + ret =fine_adjust_tod_clock (priv, rem_period,1 ); + } + +spin_unlock_irqrestore (&priv->tod_lock, flags); + +return ret; +} + +static int intel_fpga_tod_get_time (struct ptp_clock_info *ptp, +struct timespec64 *ts) +{ +struct intel_fpga_tod_private *priv = + container_of(ptp, struct intel_fpga_tod_private, ptp_clock_ops); +u32 seconds_msb, seconds_lsb, nanosec; +unsigned long flags; +u64 seconds; + +spin_lock_irqsave (&priv->tod_lock, flags); + nanosec =csrrd32 (priv->tod_ctrl,tod_csroffs (nanosec)); + seconds_lsb =csrrd32 (priv->tod_ctrl,tod_csroffs (seconds_lsb)); + seconds_msb =csrrd32 (priv->tod_ctrl,tod_csroffs (seconds_msb)); +spin_unlock_irqrestore (&priv->tod_lock, flags); + + seconds = (((u64)(seconds_msb &0x0000ffff )) <<32 ) | seconds_lsb; + + ts->tv_nsec = nanosec; + ts->tv_sec = (__kernel_old_time_t )seconds; + +return 0 ; +} + +static int intel_fpga_tod_set_time (struct ptp_clock_info *ptp, +const struct timespec64 *ts) +{ +struct intel_fpga_tod_private *priv = + container_of(ptp, struct intel_fpga_tod_private, ptp_clock_ops); +u32 seconds_msb =upper_32_bits (ts->tv_sec) &0x0000ffff ; +u32 seconds_lsb =lower_32_bits (ts->tv_sec); +u32 nanosec =lower_32_bits (ts->tv_nsec); +unsigned long flags; + +spin_lock_irqsave (&priv->tod_lock, flags); +csrwr32 (seconds_msb, priv->tod_ctrl,tod_csroffs (seconds_msb)); +csrwr32 (seconds_lsb, priv->tod_ctrl,tod_csroffs (seconds_lsb)); +csrwr32 (nanosec, priv->tod_ctrl,tod_csroffs (nanosec)); +spin_unlock_irqrestore (&priv->tod_lock, flags); + +return 0 ; +} + +static int intel_fpga_tod_enable_feature (struct ptp_clock_info *ptp, +struct ptp_clock_request *request, +int on) +{ +return -EOPNOTSUPP ; +} + +static struct ptp_clock_info intel_fpga_tod_clock_ops = { + .owner =THIS_MODULE , + .name ="intel_fpga_tod" , + .max_adj =500000000 , + .n_alarm =0 , + .n_ext_ts =0 , + .n_per_out =0 , + .pps =0 , + .adjfine = intel_fpga_tod_adjust_fine, + .adjtime = intel_fpga_tod_adjust_time, + .gettime64 = intel_fpga_tod_get_time, + .settime64 = intel_fpga_tod_set_time, + .enable = intel_fpga_tod_enable_feature, +}; + +/* Initialize PTP control block registers */ +int intel_fpga_tod_init (struct intel_fpga_tod_private *priv) +{ +struct timespec64 now; +int ret =0 ; + + ret =intel_fpga_tod_adjust_fine (&priv->ptp_clock_ops,0l ); +if (ret !=0 ) + goto out; + +/* Initialize the hardware clock to the system time */ +ktime_get_real_ts64 (&now); +intel_fpga_tod_set_time (&priv->ptp_clock_ops, &now); + +spin_lock_init (&priv->tod_lock); + +out: +return ret; +} + +/* Register the PTP clock driver to kernel */ +int intel_fpga_tod_register (struct intel_fpga_tod_private *priv, +struct device *device) +{ +int ret =0 ; + + priv->ptp_clock_ops = intel_fpga_tod_clock_ops; + + priv->ptp_clock =ptp_clock_register (&priv->ptp_clock_ops, device); +if (IS_ERR (priv->ptp_clock)) { + priv->ptp_clock =NULL ; + ret = -ENODEV ; + } + +if (priv->tod_clk) + ret =clk_prepare_enable (priv->tod_clk); + +return ret; +} + +/* Remove/unregister the ptp clock driver from the kernel */ +void intel_fpga_tod_unregister (struct intel_fpga_tod_private *priv) +{ +if (priv->ptp_clock) { +ptp_clock_unregister (priv->ptp_clock); + priv->ptp_clock =NULL ; + } + +if (priv->tod_clk) +clk_disable_unprepare (priv->tod_clk); +} + +/* Common PTP probe function */ +int intel_fpga_tod_probe (struct platform_device *pdev, +struct intel_fpga_tod_private *priv) +{ +struct resource *ptp_res; +int ret = -ENODEV ; + + priv->dev = (struct net_device *)platform_get_drvdata (pdev); + +/* Time-of-Day (ToD) Clock address space */ + ret =request_and_map (pdev,"tod_ctrl" , &ptp_res, + (void __iomem **)&priv->tod_ctrl); +if (ret) + goto err;
drivers/net/ethernet/altera/intel_fpga_tod.c line 352
Quoted 10 lines
drivers/net/ethernet/altera/intel_fpga_tod.c new file +10
-0+ +dev_info (&pdev->dev,"\tTOD Ctrl at 0x%08lx\n" , + (unsigned long )ptp_res->start); + +/* Time-of-Day (ToD) Clock period clock */ + priv->tod_clk =devm_clk_get (&pdev->dev,"tod_clk" ); +if (IS_ERR (priv->tod_clk)) { +dev_err (&pdev->dev,"cannot obtain ToD period clock\n" ); + ret = -ENXIO ; + goto err;
Could remove goto - will drop into err anyway.
Quoted 20 lines
drivers/net/ethernet/altera/intel_fpga_tod.c new file +6
-0+ } +err: +return ret; +} + +MODULE_LICENSE ("GPL" );drivers/net/ethernet/altera/intel_fpga_tod.h new file +8
-0@@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Altera PTP Hardware Clock (PHC) Linux driver +* Copyright (C) 2015-2016 Altera Corporation. All rights reserved. +* Copyright (C) 2017-2020 Intel Corporation. All rights reserved. +* +* Author(s): +* Dalon Westergreen <[email protected]> +*/
drivers/net/ethernet/altera/intel_fpga_tod.h line 18
Quoted 10 lines
drivers/net/ethernet/altera/intel_fpga_tod.h new file +10
-0+ +#ifndef __INTEL_FPGA_TOD_H__ +#define __INTEL_FPGA_TOD_H__ + +#include <linux/debugfs.h> +#include <linux/netdevice.h> +#include <linux/ptp_clock_kernel.h> +#include <linux/platform_device.h> +#include <linux/mutex.h> +
Nit. Alphabetic order?
Quoted 39 lines
drivers/net/ethernet/altera/intel_fpga_tod.h new file +38
-0+/* Altera Time-of-Day (ToD) clock register space. */ +struct intel_fpga_tod { +u32 seconds_msb; +u32 seconds_lsb; +u32 nanosec; +u32 reserved1[0x1 ]; +u32 period; +u32 adjust_period; +u32 adjust_count; +u32 drift_adjust; +u32 drift_adjust_rate; +}; + +#define tod_csroffs (a) (offsetof(struct intel_fpga_tod, a)) + +struct intel_fpga_tod_private { +struct net_device *dev; + +struct ptp_clock_info ptp_clock_ops; +struct ptp_clock *ptp_clock; + +/* Time-of-Day (ToD) Clock address space */ +struct intel_fpga_tod __iomem *tod_ctrl; +struct clk *tod_clk; + +/* ToD clock registers protection */ +spinlock_t tod_lock; +}; + +int intel_fpga_tod_init (struct intel_fpga_tod_private *priv); +void intel_fpga_tod_uinit (struct intel_fpga_tod_private *priv); +int intel_fpga_tod_register (struct intel_fpga_tod_private *priv, +struct device *device); +void intel_fpga_tod_unregister (struct intel_fpga_tod_private *priv); +int intel_fpga_tod_probe (struct platform_device *pdev, +struct intel_fpga_tod_private *priv); + +#endif /* __INTEL_FPGA_TOD_H__ */
PATCH v4 9/10 net: eth: altera: add msgdma prefetcher
In reply to Ooi, JoyceFrom: Dalon Westergreen <[email protected]>
Add support for the mSGDMA prefetcher. The prefetcher adds support for a linked list of descriptors in system memory. The prefetcher feeds these to the mSGDMA dispatcher.
The prefetcher is configured to poll for the next descriptor in the list to be owned by hardware, then pass the descriptor to the dispatcher. It will then poll the next descriptor until it is owned by hardware.
The dispatcher responses are written back to the appropriate descriptor, and the owned by hardware bit is cleared.
The driver sets up a linked list twice the tx and rx ring sizes, with the last descriptor pointing back to the first. This ensures that the ring of descriptors will always have inactive descriptors preventing the prefetcher from looping over and reusing descriptors inappropriately. The prefetcher will continuously loop over these descriptors. The driver modifies descriptors as required to update the skb address and length as well as the owned by hardware bit.
In addition to the above, the mSGDMA prefetcher can be used to handle rx and tx timestamps coming from the ethernet ip. These can be included in the prefetcher response in the descriptor.
---
v2: minor fixes and suggested edits
v3: queue is stopped before returning NETDEV_TX_BUSY
v4: fix build warnings
--- drivers/net/ethernet/altera/Makefile | 2 +- .../net/ethernet/altera/altera_msgdma_prefetcher.c | 431 +++++++++++++++++++++ .../net/ethernet/altera/altera_msgdma_prefetcher.h | 30 ++ .../ethernet/altera/altera_msgdmahw_prefetcher.h | 87 +++++ drivers/net/ethernet/altera/altera_tse.h | 14 + drivers/net/ethernet/altera/altera_tse_main.c | 51 +++ 6 files changed, 614 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/altera/altera_msgdma_prefetcher.c create mode 100644 drivers/net/ethernet/altera/altera_msgdma_prefetcher.h create mode 100644 drivers/net/ethernet/altera/altera_msgdmahw_prefetcher.h
drivers/net/ethernet/altera/Makefile +1 -1
@@ -6,4 +6,4 @@ obj-$(CONFIG_ALTERA_TSE) += altera_tse.o altera_tse-objs := altera_tse_main.o altera_tse_ethtool.o \ altera_msgdma.o altera_sgdma.o altera_utils.o \ - intel_fpga_tod.o + intel_fpga_tod.o altera_msgdma_prefetcher.o
drivers/net/ethernet/altera/altera_msgdma_prefetcher.c new file +431 -0
431 lines not on this page · raw message
drivers/net/ethernet/altera/altera_msgdma_prefetcher.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* MSGDMA Prefetcher driver for Altera ethernet devices +* +* Copyright (C) 2020 Intel Corporation. All rights reserved. +* Author(s): +* Dalon Westergreen <[email protected]> +*/ + +#ifndef __ALTERA_PREF_MSGDMA_H__ +#define __ALTERA_PREF_MSGDMA_H__ + +void msgdma_pref_reset (struct altera_tse_private *priv); +void msgdma_pref_enable_txirq (struct altera_tse_private *priv); +void msgdma_pref_enable_rxirq (struct altera_tse_private *priv); +void msgdma_pref_disable_rxirq (struct altera_tse_private *priv); +void msgdma_pref_disable_txirq (struct altera_tse_private *priv); +void msgdma_pref_clear_rxirq (struct altera_tse_private *priv); +void msgdma_pref_clear_txirq (struct altera_tse_private *priv); +u32 msgdma_pref_tx_completions (struct altera_tse_private *priv); +void msgdma_pref_add_rx_desc (struct altera_tse_private *priv, +struct tse_buffer *buffer); +netdev_tx_t msgdma_pref_tx_buffer (struct altera_tse_private *priv, +struct tse_buffer *buffer); +u32 msgdma_pref_rx_status (struct altera_tse_private *priv); +int msgdma_pref_initialize (struct altera_tse_private *priv); +void msgdma_pref_uninitialize (struct altera_tse_private *priv); +void msgdma_pref_start_rxdma (struct altera_tse_private *priv); +void msgdma_pref_start_txdma (struct altera_tse_private *priv); + +#endif /* __ALTERA_PREF_MSGDMA_H__ */
drivers/net/ethernet/altera/altera_msgdmahw_prefetcher.h new file +87 -0
87 lines not on this page · raw message
drivers/net/ethernet/altera/altera_tse.h +14 -0
@@ -382,6 +382,7 @@ struct altera_tse_private;#define ALTERA_DTYPE_SGDMA 1#define ALTERA_DTYPE_MSGDMA 2 +#define ALTERA_DTYPE_MSGDMA_PREF 3/* standard DMA interface for SGDMA and MSGDMA */ struct altera_dmaops {
@@ -434,6 +435,19 @@ struct altera_tse_private {void __iomem *tx_dma_csr;void __iomem *tx_dma_desc; +/* mSGDMA Rx Prefecher address space */ +void __iomem *rx_pref_csr; +struct msgdma_pref_extended_desc *pref_rxdesc; +dma_addr_t pref_rxdescphys; +u32 pref_rx_prod; + +/* mSGDMA Tx Prefecher address space */ +void __iomem *tx_pref_csr; +struct msgdma_pref_extended_desc *pref_txdesc; +dma_addr_t pref_txdescphys; +u32 rx_poll_freq; +u32 tx_poll_freq; +/* Rx buffers queue */ struct tse_buffer *rx_ring;u32 rx_cons;
drivers/net/ethernet/altera/altera_tse_main.c +51 -0
70 lines not on this page · raw message
Signature · 1 line
2.13.0
David Miller
maintainerRe: [PATCH v4 09/10] net: eth: altera: add msgdma prefetcher
From: "Ooi, Joyce" <[email protected]>
Date: Wed, 8 Jul 2020 15:24:00 +0800
drivers/net/ethernet/altera/altera_msgdma_prefetcher.c line 25
Quoted 7 lines
drivers/net/ethernet/altera/altera_msgdma_prefetcher.c new file +7
-0+int msgdma_pref_initialize (struct altera_tse_private *priv) +{ +int i; +struct msgdma_pref_extended_desc *rx_descs; +struct msgdma_pref_extended_desc *tx_descs; +dma_addr_t rx_descsphys; +dma_addr_t tx_descsphys;
Reverse christmas tree please.
drivers/net/ethernet/altera/altera_msgdma_prefetcher.c line 192
Quoted 5 lines
drivers/net/ethernet/altera/altera_msgdma_prefetcher.c new file +5
-0+netdev_tx_t msgdma_pref_tx_buffer (struct altera_tse_private *priv, +struct tse_buffer *buffer) +{ +u32 desc_entry = priv->tx_prod % (priv->tx_ring_size *2 ); +struct msgdma_pref_extended_desc *tx_descs = priv->pref_txdesc;
Likewise.
drivers/net/ethernet/altera/altera_msgdma_prefetcher.c line 229
Quoted 12 lines
drivers/net/ethernet/altera/altera_msgdma_prefetcher.c new file +12
-0+u32 msgdma_pref_tx_completions (struct altera_tse_private *priv) +{ +u32 control; +u32 ready =0 ; +u32 cons = priv->tx_cons; +u32 desc_ringsize = priv->tx_ring_size *2 ; +u32 ringsize = priv->tx_ring_size; +u64 ns =0 ; +struct msgdma_pref_extended_desc *cur; +struct tse_buffer *tx_buff; +struct skb_shared_hwtstamps shhwtstamp; +int i;
Likewise.
drivers/net/ethernet/altera/altera_msgdma_prefetcher.c line 399
Quoted 11 lines
drivers/net/ethernet/altera/altera_msgdma_prefetcher.c new file +11
-0+u32 msgdma_pref_rx_status (struct altera_tse_private *priv) +{ +u32 rxstatus =0 ; +u32 pktlength; +u32 pktstatus; +u64 ns =0 ; +u32 entry = priv->rx_cons % priv->rx_ring_size; +u32 desc_entry = priv->rx_prod % (priv->rx_ring_size *2 ); +struct msgdma_pref_extended_desc *rx_descs = priv->pref_rxdesc; +struct skb_shared_hwtstamps *shhwtstamp =NULL ; +struct tse_buffer *rx_buff = priv->rx_ring;
Likewise.
drivers/net/ethernet/altera/altera_tse_main.c static int altera_tse_probe(struct platform_device *pdev) · line 1506
Quoted 3 lines
drivers/net/ethernet/altera/altera_tse_main.c +3
-0+ }else if (priv->dmaops && + priv->dmaops->altera_dtype == +ALTERA_DTYPE_MSGDMA_PREF ) {
This is not properly formatted.
On a multi-line conditional, every subsequent line after the first should align with the first column after the openning parenthesis of the first line.
RE: [PATCH v4 09/10] net: eth: altera: add msgdma prefetcher
Quoted 58 lines
-----Original Message-----
From: David Miller <[email protected]>
Sent: Thursday, July 9, 2020 1:34 AM
To: Ooi, Joyce <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Tan, Ley Foon <[email protected]>; See, Chin Liang <[email protected]>; Nguyen, Dinh <[email protected]>; Westergreen, Dalon <[email protected]>
Subject: Re: [PATCH v4 09/10] net: eth: altera: add msgdma prefetcherFrom: "Ooi, Joyce" <[email protected]>
Date: Wed, 8 Jul 2020 15:24:00 +0800drivers/net/ethernet/altera/altera_msgdma_prefetcher.c line 25
Quoted 6 lines
drivers/net/ethernet/altera/altera_msgdma_prefetcher.c new file +6
-0+int msgdma_pref_initialize (struct altera_tse_private *priv) { +int i; +struct msgdma_pref_extended_desc *rx_descs; +struct msgdma_pref_extended_desc *tx_descs; +dma_addr_t rx_descsphys; +dma_addr_t tx_descsphys;Reverse christmas tree please.
drivers/net/ethernet/altera/altera_msgdma_prefetcher.c line 192
Quoted 5 lines
drivers/net/ethernet/altera/altera_msgdma_prefetcher.c new file +5
-0+netdev_tx_t msgdma_pref_tx_buffer (struct altera_tse_private *priv, +struct tse_buffer *buffer) +{ +u32 desc_entry = priv->tx_prod % (priv->tx_ring_size *2 ); +struct msgdma_pref_extended_desc *tx_descs = priv->pref_txdesc;Likewise.
drivers/net/ethernet/altera/altera_msgdma_prefetcher.c line 229
Quoted 11 lines
drivers/net/ethernet/altera/altera_msgdma_prefetcher.c new file +11
-0+u32 msgdma_pref_tx_completions (struct altera_tse_private *priv) { +u32 control; +u32 ready =0 ; +u32 cons = priv->tx_cons; +u32 desc_ringsize = priv->tx_ring_size *2 ; +u32 ringsize = priv->tx_ring_size; +u64 ns =0 ; +struct msgdma_pref_extended_desc *cur; +struct tse_buffer *tx_buff; +struct skb_shared_hwtstamps shhwtstamp; +int i;Likewise.
drivers/net/ethernet/altera/altera_msgdma_prefetcher.c line 399
Quoted 10 lines
drivers/net/ethernet/altera/altera_msgdma_prefetcher.c new file +10
-0+u32 msgdma_pref_rx_status (struct altera_tse_private *priv) { +u32 rxstatus =0 ; +u32 pktlength; +u32 pktstatus; +u64 ns =0 ; +u32 entry = priv->rx_cons % priv->rx_ring_size; +u32 desc_entry = priv->rx_prod % (priv->rx_ring_size *2 ); +struct msgdma_pref_extended_desc *rx_descs = priv->pref_rxdesc; +struct skb_shared_hwtstamps *shhwtstamp =NULL ; +struct tse_buffer *rx_buff = priv->rx_ring;Likewise.
Quoted 8 lines
drivers/net/ethernet/altera/altera_tse_main.c static int altera_tse_probe(struct platform_device *pdev) · line 1506
Quoted 3 lines
drivers/net/ethernet/altera/altera_tse_main.c +3
-0+ }else if (priv->dmaops && + priv->dmaops->altera_dtype == +ALTERA_DTYPE_MSGDMA_PREF ) {This is not properly formatted.
On a multi-line conditional, every subsequent line after the first should align with the first column after the openning parenthesis of the first line.
Noted, will make the changes.
Jakub Kicinski
maintainerRe: [PATCH v4 09/10] net: eth: altera: add msgdma prefetcher
In reply to Ooi, Joycedrivers/net/ethernet/altera/altera_tse_main.c static int altera_tse_probe(struct platform_device *pdev) · line 1531
Quoted 13 lines · Joyce
drivers/net/ethernet/altera/altera_tse_main.c +13
-0+/* get prefetcher rx poll frequency from device tree */ +if (of_property_read_u32 (pdev->dev.of_node,"rx-poll-freq" , + &priv->rx_poll_freq)) { +dev_info (&pdev->dev,"Defaulting RX Poll Frequency to 128\n" ); + priv->rx_poll_freq =128 ; + } + +/* get prefetcher rx poll frequency from device tree */ +if (of_property_read_u32 (pdev->dev.of_node,"tx-poll-freq" , + &priv->tx_poll_freq)) { +dev_info (&pdev->dev,"Defaulting TX Poll Frequency to 128\n" ); + priv->tx_poll_freq =128 ; + }
I'm no device tree expert but these look like config options rather than HW description. They also don't appear to be documented in the next patch.
RE: [PATCH v4 09/10] net: eth: altera: add msgdma prefetcher
Quoted 26 lines
-----Original Message-----
From: Jakub Kicinski <[email protected]>
Sent: Thursday, July 9, 2020 5:49 AM
To: Ooi, Joyce <[email protected]>
Cc: Thor Thayer <[email protected]>; David S . Miller <[email protected]>; [email protected]; linux- [email protected]; Dalon Westergreen <[email protected]>; Tan, Ley Foon <[email protected]>; See, Chin Liang <[email protected]>; Nguyen, Dinh <[email protected]>; Westergreen, Dalon <[email protected]>
Subject: Re: [PATCH v4 09/10] net: eth: altera: add msgdma prefetcherReview
Quoted 2 lines · Joyce
(quoted diff) +2
-0+ /* get prefetcher rx poll frequency from device tree */ + if (of_property_read_u32(pdev->dev.of_node, "rx-poll-freq",
Review
Quoted 2 lines
(quoted diff) +2
-0+ &priv->rx_poll_freq)) { + dev_info(&pdev->dev, "Defaulting RX Poll Frequencyto 128\n");
drivers/net/ethernet/altera/altera_tse_main.c static int altera_tse_probe(struct platform_device *pdev)
Quoted 5 lines
drivers/net/ethernet/altera/altera_tse_main.c +5
-0+ priv->rx_poll_freq =128 ; + } + +/* get prefetcher rx poll frequency from device tree */ + if (of_property_read_u32(pdev->dev.of_node, "tx-poll-freq",
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ &priv->tx_poll_freq)) { + dev_info(&pdev->dev, "Defaulting TX Poll Frequencyto 128\n");
drivers/net/ethernet/altera/altera_tse_main.c static int altera_tse_probe(struct platform_device *pdev) · line 1531
Quoted 2 lines
drivers/net/ethernet/altera/altera_tse_main.c +2
-0+ priv->tx_poll_freq =128 ; + }I'm no device tree expert but these look like config options rather than HW description. They also don't appear to be documented in the next patch.
The poll_freq are part of the msgdma prefetcher IP, whereby it specifies the frequency of descriptor polling operation. I can add the poll_freq description in the next patch.
Jakub Kicinski
maintainerRe: [PATCH v4 09/10] net: eth: altera: add msgdma prefetcher
Quoted 6 lines · Joyce
Quoted 2 lines
I'm no device tree expert but these look like config options rather than HW description. They also don't appear to be documented in the next patch.
The
poll_freqare part of the msgdma prefetcher IP, whereby it specifies the frequency of descriptor polling operation. I can add thepoll_freqdescription in the next patch.
Is the value decided at the time of synthesis or can the driver choose the value it wants?
Re: [PATCH v4 09/10] net: eth: altera: add msgdma prefetcher
Quoted 11 lines · Jakub Kicinski
Quoted 7 lines · Joyce
Quoted 3 lines
I'm no device tree expert but these look like config options rather than HW
description. They also don't appear to be documented in the next patch.The
poll_freqare part of the msgdma prefetcher IP, whereby it specifies the frequency of descriptor polling operation. I can add thepoll_freqdescription in the next patch.Is the value decided at the time of synthesis or can the driver choose the value it wants?
It is not controlled at synthesis, this parameter should likely not be a devicetree parameter, perhaps just make it a module parameter with a default value.
--dalon
Jakub Kicinski
maintainerRe: [PATCH v4 09/10] net: eth: altera: add msgdma prefetcher
Quoted 10 lines · Dalon
Quoted 9 lines · Jakub Kicinski
Quoted 7 lines · Joyce
Quoted 3 lines
I'm no device tree expert but these look like config options rather than HW
description. They also don't appear to be documented in the next patch.The
poll_freqare part of the msgdma prefetcher IP, whereby it specifies the frequency of descriptor polling operation. I can add thepoll_freqdescription in the next patch.
Quoted 6 lines
Quoted 2 lines
Is the value decided at the time of synthesis or can the driver choose the value it wants?
It is not controlled at synthesis, this parameter should likely not be a devicetree parameter, perhaps just make it a module parameter with a default value.
Let's see if I understand the feature - instead of using a doorbell the HW periodically checks the contents of the next-to-use descriptor to see if it contains a valid tx frame or rx buffer?
I've seen vendors abuse fields of ethtool --coalesce to configure similar settings. tx-usecs-irq and rx-usecs-irq, I think. Since this part of ethtool API has been ported to netlink, could we perhaps add a new field to ethtool --coalesce?
Re: [PATCH v4 09/10] net: eth: altera: add msgdma prefetcher
Quoted 16 lines · Jakub Kicinski
Quoted 15 lines · Dalon
Quoted 13 lines · Jakub Kicinski
Quoted 9 lines · Joyce
Quoted 5 lines
I'm no device tree expert but these look like config options rather than
HW
description. They also don't appear to be documented in the next patch.The
poll_freqare part of the msgdma prefetcher IP, whereby it specifies the frequency of descriptor polling operation. I can add thepoll_freqdescription in the next patch.Is the value decided at the time of synthesis or can the driver choose the value it wants?
Quoted 8 lines
Quoted 3 lines
It is not controlled at synthesis, this parameter should likely not be a devicetree parameter, perhaps just make it a module parameter with a default value.
Let's see if I understand the feature - instead of using a doorbell the HW periodically checks the contents of the next-to-use descriptor to see if it contains a valid tx frame or rx buffer?
Yes, it checks the next-to-use descriptor to see if the descriptor is valid.
the value specifies the number of cycles to wait before checking again
Quoted 4 lines
I've seen vendors abuse fields of ethtool --coalesce to configure similar settings. tx-usecs-irq and rx-usecs-irq, I think. Since this part of ethtool API has been ported to netlink, could we perhaps add a new field to ethtool --coalesce?
I don't think this is necessary, i think just having a module parameter meets our needs. I don't see a need for the value to change on a per interface basis. This was primarily used during testing / bringup.
-dalon
Jakub Kicinski
maintainerRe: [PATCH v4 09/10] net: eth: altera: add msgdma prefetcher
Quoted 8 lines · Dalon
Quoted 4 lines
I've seen vendors abuse fields of ethtool --coalesce to configure similar settings. tx-usecs-irq and rx-usecs-irq, I think. Since this part of ethtool API has been ported to netlink, could we perhaps add a new field to ethtool --coalesce?
I don't think this is necessary, i think just having a module parameter meets our needs. I don't see a need for the value to change on a per interface basis. This was primarily used during testing / bringup.
It's hard to tell which knobs users will find worth turning therefore the testing / bringup justification unfortunately has little bearing on our upstream interface choices.
We try hard to avoid module parameters in networking drivers, so if you want this tunable upstream a proper user interface will be required.
David Miller
maintainerRe: [PATCH v4 09/10] net: eth: altera: add msgdma prefetcher
In reply to Westergreen, DalonFrom: "Westergreen, Dalon" <[email protected]>
Date: Tue, 14 Jul 2020 18:51:15 +0000
Quoted 3 lines
I don't think this is necessary, i think just having a module parameter meets our needs. I don't see a need for the value to change on a per interface basis. This was primarily used during testing / bringup.
Please no module parameters...
Re: [PATCH v4 09/10] net: eth: altera: add msgdma prefetcher
Quoted 8 lines · David Miller
From: "Westergreen, Dalon" <[email protected]>
Date: Tue, 14 Jul 2020 18:51:15 +0000Quoted 3 lines
I don't think this is necessary, i think just having a module parameter meets our needs. I don't see a need for the value to change on a per interface basis. This was primarily used during testing / bringup.
Please no module parameters...
I think we are fine just hard coding the value. that seems to be the best path forward.
--dalon
PATCH v4 10/10 net: eth: altera: update devicetree bindings documentation
In reply to Ooi, JoyceFrom: Dalon Westergreen <[email protected]>
Update devicetree bindings documentation to include msgdma prefetcher and ptp bindings.
---
v2: no change
v3: no change
v4: no change
--- .../devicetree/bindings/net/altera_tse.txt | 103 +++++++++++++++++---- 1 file changed, 84 insertions(+), 19 deletions(-)
Documentation/devicetree/bindings/net/altera_tse.txt +84 -19
@@ -2,53 +2,86 @@ Required properties: - compatible: Should be "altr,tse-1.0" for legacy SGDMA based TSE, and should - be "altr,tse-msgdma-1.0" for the preferred MSGDMA based TSE. + be "altr,tse-msgdma-1.0" for the preferred MSGDMA based TSE, + and "altr,tse-msgdma-2.0" for MSGDMA with prefetcher based + implementations. ALTR is supported for legacy device trees, but is deprecated. altr should be used for all new designs. - reg: Address and length of the register set for the device. It contains the information of registers in the same order as described by reg-names - reg-names: Should contain the reg names - "control_port": MAC configuration space region - "tx_csr": xDMA Tx dispatcher control and status space region - "tx_desc": MSGDMA Tx dispatcher descriptor space region - "rx_csr" : xDMA Rx dispatcher control and status space region - "rx_desc": MSGDMA Rx dispatcher descriptor space region - "rx_resp": MSGDMA Rx dispatcher response space region - "s1": SGDMA descriptor memory - interrupts: Should contain the TSE interrupts and it's mode. - interrupt-names: Should contain the interrupt names - "rx_irq": xDMA Rx dispatcher interrupt - "tx_irq": xDMA Tx dispatcher interrupt + "rx_irq": DMA Rx dispatcher interrupt + "tx_irq": DMA Tx dispatcher interrupt - rx-fifo-depth: MAC receive FIFO buffer depth in bytes - tx-fifo-depth: MAC transmit FIFO buffer depth in bytes - phy-mode: See ethernet.txt in the same directory. - phy-handle: See ethernet.txt in the same directory. - phy-addr: See ethernet.txt in the same directory. A configuration should include phy-handle or phy-addr. -- altr,has-supplementary-unicast: - If present, TSE supports additional unicast addresses. - Otherwise additional unicast addresses are not supported. -- altr,has-hash-multicast-filter: - If present, TSE supports a hash based multicast filter. - Otherwise, hash-based multicast filtering is not supported. - - mdio device tree subnode: When the TSE has a phy connected to its local mdio, there must be device tree subnode with the following required properties: - - compatible: Must be "altr,tse-mdio". - #address-cells: Must be <1>. - #size-cells: Must be <0>. For each phy on the mdio bus, there must be a node with the following fields: - - reg: phy id used to communicate to phy. - device_type: Must be "ethernet-phy". The MAC address will be determined using the optional properties defined in ethernet.txt. +- altr,has-supplementary-unicast: + If present, TSE supports additional unicast addresses. + Otherwise additional unicast addresses are not supported. +- altr,has-hash-multicast-filter: + If present, TSE supports a hash based multicast filter. + Otherwise, hash-based multicast filtering is not supported. +- altr,has-ptp: + If present, TSE supports 1588 timestamping. Currently only + supported with the msgdma prefetcher. +- altr,tx-poll-cnt: + Optional cycle count for Tx prefetcher to poll descriptor + list. If not present, defaults to 128, which at 125MHz is + roughly 1usec. Only for "altr,tse-msgdma-2.0". +- altr,rx-poll-cnt: + Optional cycle count for Tx prefetcher to poll descriptor + list. If not present, defaults to 128, which at 125MHz is + roughly 1usec. Only for "altr,tse-msgdma-2.0". + +Required registers by compatibility string: + - "altr,tse-1.0" + "control_port": MAC configuration space region + "tx_csr": DMA Tx dispatcher control and status space region + "rx_csr" : DMA Rx dispatcher control and status space region + "s1": DMA descriptor memory + + - "altr,tse-msgdma-1.0" + "control_port": MAC configuration space region + "tx_csr": DMA Tx dispatcher control and status space region + "tx_desc": DMA Tx dispatcher descriptor space region + "rx_csr" : DMA Rx dispatcher control and status space region + "rx_desc": DMA Rx dispatcher descriptor space region + "rx_resp": DMA Rx dispatcher response space region + + - "altr,tse-msgdma-2.0" + "control_port": MAC configuration space region + "tx_csr": DMA Tx dispatcher control and status space region + "tx_pref": DMA Tx prefetcher configuration space region + "rx_csr" : DMA Rx dispatcher control and status space region + "rx_pref": DMA Rx prefetcher configuration space region + "tod_ctrl": Time of Day Control register only required when + timestamping support is enabled. Timestamping is + only supported with the msgdma-2.0 implementation. + +Optional properties: +- local-mac-address: See ethernet.txt in the same directory. +- max-frame-size: See ethernet.txt in the same directory. + Example: tse_sub_0_eth_tse_0: ethernet@1,00000000 {
@@ -86,6 +119,11 @@ Example: device_type = "ethernet-phy"; }; + phy2: ethernet-phy@2 { + reg = <0x2>; + device_type = "ethernet-phy"; + }; + }; };
@@ -111,3 +149,30 @@ Example: altr,has-hash-multicast-filter; phy-handle = <&phy1>; }; + + + tse_sub_2_eth_tse_0: ethernet@1,00002000 { + compatible = "altr,tse-msgdma-2.0"; + reg = <0x00000001 0x00002000 0x00000400>, + <0x00000001 0x00002400 0x00000020>, + <0x00000001 0x00002420 0x00000020>, + <0x00000001 0x00002440 0x00000020>, + <0x00000001 0x00002460 0x00000020>, + <0x00000001 0x00002480 0x00000040>; + reg-names = "control_port", "rx_csr", "rx_pref","tx_csr", "tx_pref", "tod_ctrl"; + interrupt-parent = <&hps_0_arm_gic_0>; + interrupts = <0 45 4>, <0 44 4>; + interrupt-names = "rx_irq", "tx_irq"; + rx-fifo-depth = <2048>; + tx-fifo-depth = <2048>; + address-bits = <48>; + max-frame-size = <1500>; + local-mac-address = [ 00 00 00 00 00 00 ]; + phy-mode = "sgmii"; + altr,has-supplementary-unicast; + altr,has-hash-multicast-filter; + altr,has-ptp; + altr,tx-poll-cnt = <128>; + altr,rx-poll-cnt = <32>; + phy-handle = <&phy2>; + };
Signature · 1 line
2.13.0