Support PTP clock and hardware timestamping for DSA Felix driver
Subsystems (4)
cover Support PTP clock and hardware timestamping for DSA Felix driver
This patch-set is to support PTP clock and hardware timestamping for DSA Felix driver. Some functions in ocelot.c/ocelot_board.c driver were reworked/exported, so that DSA Felix driver was able to reuse them as much as possible.
On TX path, timestamping works on packet which requires timestamp. The injection header will be configured accordingly, and skb clone requires timestamp will be added into a list. The TX timestamp is final handled in threaded interrupt handler when PTP timestamp FIFO is ready.
On RX path, timestamping is always working. The RX timestamp could be got from extraction header.
Yangbo Lu (5):
net: mscc: ocelot: export ocelot_hwstamp_get/set functions
net: mscc: ocelot: convert to use ocelot_get_txtstamp()
net: mscc: ocelot: convert to use ocelot_port_add_txtstamp_skb()
net: dsa: ocelot: define PTP registers for felix_vsc9959
net: dsa: ocelot: add hardware timestamping support for Felix
drivers/net/dsa/ocelot/felix.c | 89 ++++++++++++++++++++++++ drivers/net/dsa/ocelot/felix_vsc9959.c | 16 +++++ drivers/net/ethernet/mscc/ocelot.c | 113 +++++++++++++++++++++++++------ drivers/net/ethernet/mscc/ocelot.h | 6 -- drivers/net/ethernet/mscc/ocelot_board.c | 53 +-------------- include/soc/mscc/ocelot.h | 13 +++- net/dsa/tag_ocelot.c | 14 +++- 7 files changed, 222 insertions(+), 82 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/5 net: mscc: ocelot: export ocelot_hwstamp_get/set functions
Export ocelot_hwstamp_get/set functions so that DSA driver is able to reuse them.
--- drivers/net/ethernet/mscc/ocelot.c | 8 ++++---- include/soc/mscc/ocelot.h | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/net/ethernet/mscc/ocelot.c +4 -4
@@ -1049,15 +1049,14 @@ static int ocelot_get_port_parent_id(struct net_device *dev,return 0 ; } -static int ocelot_hwstamp_get (struct ocelot *ocelot,int port, -struct ifreq *ifr) +int ocelot_hwstamp_get (struct ocelot *ocelot,int port,struct ifreq *ifr) {return copy_to_user (ifr->ifr_data, &ocelot->hwtstamp_config,sizeof (ocelot->hwtstamp_config)) ? -EFAULT :0 ; } +EXPORT_SYMBOL (ocelot_hwstamp_get); -static int ocelot_hwstamp_set (struct ocelot *ocelot,int port, -struct ifreq *ifr) +int ocelot_hwstamp_set (struct ocelot *ocelot,int port,struct ifreq *ifr) {struct ocelot_port *ocelot_port = ocelot->ports[port];struct hwtstamp_config cfg;
@@ -1120,6 +1119,7 @@ static int ocelot_hwstamp_set(struct ocelot *ocelot, int port,return copy_to_user (ifr->ifr_data, &cfg,sizeof (cfg)) ? -EFAULT :0 ; } +EXPORT_SYMBOL (ocelot_hwstamp_set);static int ocelot_ioctl (struct net_device *dev,struct ifreq *ifr,int cmd) {
include/soc/mscc/ocelot.h +2 -0
@@ -533,6 +533,8 @@ int ocelot_fdb_del(struct ocelot *ocelot, int port,int ocelot_vlan_add (struct ocelot *ocelot,int port,u16 vid,bool pvid,bool untagged);int ocelot_vlan_del (struct ocelot *ocelot,int port,u16 vid); +int ocelot_hwstamp_get (struct ocelot *ocelot,int port,struct ifreq *ifr); +int ocelot_hwstamp_set (struct ocelot *ocelot,int port,struct ifreq *ifr);int ocelot_ptp_gettime64 (struct ptp_clock_info *ptp,struct timespec64 *ts);void ocelot_get_hwtimestamp (struct ocelot *ocelot,struct timespec64 *ts);
Signature · 1 line
2.7.4
Re: [PATCH 1/5] net: mscc: ocelot: export ocelot_hwstamp_get/set functions
Quoted 4 lines · Yangbo Lu
Export ocelot_hwstamp_get/set functions so that DSA driver is able to reuse them.
Signed-off-by Yangbo Lu <[email protected]>
Andrew
Re: [PATCH 1/5] net: mscc: ocelot: export ocelot_hwstamp_get/set functions
In reply to Yangbo LuQuoted 4 lines · Yangbo Lu
Export ocelot_hwstamp_get/set functions so that DSA driver is able to reuse them.
Signed-off-by Yangbo Lu <[email protected]>
Signature · 1 line
Florian
PATCH 2/5 net: mscc: ocelot: convert to use ocelot_get_txtstamp()
In reply to Yangbo LuThe method getting TX timestamp by reading timestamp FIFO and matching skbs list is common for DSA Felix driver too. So move code out of ocelot_board.c, convert to use ocelot_get_txtstamp() function and export it.
--- drivers/net/ethernet/mscc/ocelot.c | 62 ++++++++++++++++++++++++++++++-- drivers/net/ethernet/mscc/ocelot.h | 6 ---- drivers/net/ethernet/mscc/ocelot_board.c | 53 +-------------------------- include/soc/mscc/ocelot.h | 9 ++++- 4 files changed, 69 insertions(+), 61 deletions(-)
drivers/net/ethernet/mscc/ocelot.c +60 -2
@@ -661,7 +661,8 @@ static int ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev)return NETDEV_TX_OK ; } -void ocelot_get_hwtimestamp (struct ocelot *ocelot,struct timespec64 *ts) +static void ocelot_get_hwtimestamp (struct ocelot *ocelot, +struct timespec64 *ts) {unsigned long flags;u32 val;
@@ -686,7 +687,64 @@ void ocelot_get_hwtimestamp(struct ocelot *ocelot, struct timespec64 *ts)spin_unlock_irqrestore (&ocelot->ptp_clock_lock, flags); } -EXPORT_SYMBOL (ocelot_get_hwtimestamp); + +void ocelot_get_txtstamp (struct ocelot *ocelot) +{ +int budget =OCELOT_PTP_QUEUE_SZ ; + +while (budget--) { +struct skb_shared_hwtstamps shhwtstamps; +struct list_head *pos, *tmp; +struct sk_buff *skb =NULL ; +struct ocelot_skb *entry; +struct ocelot_port *port; +struct timespec64 ts; +u32 val, id, txport; + + val =ocelot_read (ocelot,SYS_PTP_STATUS ); + +/* Check if a timestamp can be retrieved */ +if (!(val &SYS_PTP_STATUS_PTP_MESS_VLD )) +break ; + +WARN_ON (val &SYS_PTP_STATUS_PTP_OVFL ); + +/* Retrieve the ts ID and Tx port */ + id =SYS_PTP_STATUS_PTP_MESS_ID_X (val); + txport =SYS_PTP_STATUS_PTP_MESS_TXPORT_X (val); + +/* Retrieve its associated skb */ + port = ocelot->ports[txport]; + +list_for_each_safe (pos, tmp, &port->skbs) { + entry = list_entry(pos, struct ocelot_skb, head); +if (entry->id != id) +continue ; + + skb = entry->skb; + +list_del (pos); +kfree (entry); + } + +/* Next ts */ +ocelot_write (ocelot,SYS_PTP_NXT_PTP_NXT ,SYS_PTP_NXT ); + +if (unlikely (!skb)) +continue ; + +/* Get the h/w timestamp */ +ocelot_get_hwtimestamp (ocelot, &ts); + +/* Set the timestamp into the skb */ +memset (&shhwtstamps,0 ,sizeof (shhwtstamps)); + shhwtstamps.hwtstamp =ktime_set (ts.tv_sec, ts.tv_nsec); +skb_tstamp_tx (skb, &shhwtstamps); + +dev_kfree_skb_any (skb); + } +} +EXPORT_SYMBOL (ocelot_get_txtstamp);static int ocelot_mc_unsync (struct net_device *dev,const unsigned char *addr) {
drivers/net/ethernet/mscc/ocelot.h +0 -6
@@ -74,12 +74,6 @@ struct ocelot_port_private {struct ocelot_port_tc tc; }; -struct ocelot_skb { -struct list_head head; -struct sk_buff *skb; -u8 id; -}; -u32 ocelot_port_readl (struct ocelot_port *port,u32 reg);void ocelot_port_writel (struct ocelot_port *port,u32 val,u32 reg);
drivers/net/ethernet/mscc/ocelot_board.c +1 -52
61 lines not on this page · raw message
include/soc/mscc/ocelot.h +8 -1
@@ -406,6 +406,13 @@ struct ocelot_ops {int (*reset)(struct ocelot *ocelot); }; +struct ocelot_skb { +struct list_head head; +struct sk_buff *skb; +u8 id; +}; + +struct ocelot_port {struct ocelot *ocelot;
@@ -536,6 +543,6 @@ int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid);int ocelot_hwstamp_get (struct ocelot *ocelot,int port,struct ifreq *ifr);int ocelot_hwstamp_set (struct ocelot *ocelot,int port,struct ifreq *ifr);int ocelot_ptp_gettime64 (struct ptp_clock_info *ptp,struct timespec64 *ts); -void ocelot_get_hwtimestamp (struct ocelot *ocelot,struct timespec64 *ts); +void ocelot_get_txtstamp (struct ocelot *ocelot);#endif
Signature · 1 line
2.7.4
Re: [PATCH 2/5] net: mscc: ocelot: convert to use ocelot_get_txtstamp()
Quoted 6 lines · Yangbo Lu
The method getting TX timestamp by reading timestamp FIFO and matching skbs list is common for DSA Felix driver too. So move code out of
ocelot_board.c, convert to useocelot_get_txtstamp()function and export it.Signed-off-by Yangbo Lu <[email protected]>
Andrew
Re: [PATCH 2/5] net: mscc: ocelot: convert to use ocelot_get_txtstamp()
In reply to Yangbo LuQuoted 6 lines · Yangbo Lu
The method getting TX timestamp by reading timestamp FIFO and matching skbs list is common for DSA Felix driver too. So move code out of
ocelot_board.c, convert to useocelot_get_txtstamp()function and export it.Signed-off-by Yangbo Lu <[email protected]>
Signature · 1 line
Florian
PATCH 3/5 net: mscc: ocelot: convert to use ocelot_port_add_txtstamp_skb()
In reply to Yangbo LuConvert to use ocelot_port_add_txtstamp_skb() for adding skbs which require TX timestamp into list. Export it so that DSA Felix driver could reuse it too.
--- drivers/net/ethernet/mscc/ocelot.c | 43 ++++++++++++++++++++++++-------------- include/soc/mscc/ocelot.h | 2 ++ 2 files changed, 29 insertions(+), 16 deletions(-)
drivers/net/ethernet/mscc/ocelot.c +27 -16
@@ -575,6 +575,32 @@ static int ocelot_gen_ifh(u32 *ifh, struct frame_info *info)return 0 ; } +int ocelot_port_add_txtstamp_skb (struct ocelot_port *ocelot_port, +struct sk_buff *skb) +{ +struct skb_shared_info *shinfo =skb_shinfo (skb); +struct ocelot *ocelot = ocelot_port->ocelot; + +if (ocelot->ptp && shinfo->tx_flags &SKBTX_HW_TSTAMP && + ocelot_port->ptp_cmd ==IFH_REW_OP_TWO_STEP_PTP ) { +struct ocelot_skb *oskb = +kzalloc (sizeof (struct ocelot_skb ),GFP_ATOMIC ); + +if (unlikely (!oskb)) +return -ENOMEM ; + + shinfo->tx_flags |=SKBTX_IN_PROGRESS ; + + oskb->skb = skb; + oskb->id = ocelot_port->ts_id %4 ; + +list_add_tail (&oskb->head, &ocelot_port->skbs); +return 0 ; + } +return -ENODATA ; +} +EXPORT_SYMBOL (ocelot_port_add_txtstamp_skb); +static int ocelot_port_xmit (struct sk_buff *skb,struct net_device *dev) {struct ocelot_port_private *priv =netdev_priv (dev);
@@ -637,26 +663,11 @@ static int ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev) dev->stats.tx_packets++; dev->stats.tx_bytes += skb->len; -if (ocelot->ptp && shinfo->tx_flags &SKBTX_HW_TSTAMP && - ocelot_port->ptp_cmd ==IFH_REW_OP_TWO_STEP_PTP ) { -struct ocelot_skb *oskb = -kzalloc (sizeof (struct ocelot_skb ),GFP_ATOMIC ); - -if (unlikely (!oskb)) - goto out; - -skb_shinfo (skb)->tx_flags |=SKBTX_IN_PROGRESS ; - - oskb->skb = skb; - oskb->id = ocelot_port->ts_id %4 ; +if (!ocelot_port_add_txtstamp_skb (ocelot_port, skb)) { ocelot_port->ts_id++; - -list_add_tail (&oskb->head, &ocelot_port->skbs); -return NETDEV_TX_OK ; } -out:dev_kfree_skb_any (skb);return NETDEV_TX_OK ; }
include/soc/mscc/ocelot.h +2 -0
@@ -543,6 +543,8 @@ int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid);int ocelot_hwstamp_get (struct ocelot *ocelot,int port,struct ifreq *ifr);int ocelot_hwstamp_set (struct ocelot *ocelot,int port,struct ifreq *ifr);int ocelot_ptp_gettime64 (struct ptp_clock_info *ptp,struct timespec64 *ts); +int ocelot_port_add_txtstamp_skb (struct ocelot_port *ocelot_port, +struct sk_buff *skb);void ocelot_get_txtstamp (struct ocelot *ocelot);#endif
Signature · 1 line
2.7.4
Re: [PATCH 3/5] net: mscc: ocelot: convert to use ocelot_port_add_txtstamp_skb()
Quoted 5 lines · Yangbo Lu
Convert to use
ocelot_port_add_txtstamp_skb()for adding skbs which require TX timestamp into list. Export it so that DSA Felix driver could reuse it too.Signed-off-by Yangbo Lu <[email protected]>
Andrew
Re: [PATCH 3/5] net: mscc: ocelot: convert to use ocelot_port_add_txtstamp_skb()
In reply to Yangbo LuQuoted 5 lines · Yangbo Lu
Convert to use
ocelot_port_add_txtstamp_skb()for adding skbs which require TX timestamp into list. Export it so that DSA Felix driver could reuse it too.Signed-off-by Yangbo Lu <[email protected]>
Signature · 1 line
Florian
PATCH 4/5 net: dsa: ocelot: define PTP registers for felix_vsc9959
In reply to Yangbo LuThis patch is to define PTP registers for felix_vsc9959.
--- drivers/net/dsa/ocelot/felix_vsc9959.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/net/dsa/ocelot/felix_vsc9959.c +16 -0
@@ -282,6 +282,16 @@ static const u32 vsc9959_sys_regmap[] = { REG_RESERVED(SYS_CM_DATA), }; +static const u32 vsc9959_ptp_regmap[] = { +REG (PTP_PIN_CFG ,0x000000 ), +REG (PTP_PIN_TOD_SEC_MSB ,0x000004 ), +REG (PTP_PIN_TOD_SEC_LSB ,0x000008 ), +REG (PTP_PIN_TOD_NSEC ,0x00000c ), +REG (PTP_CFG_MISC ,0x0000a0 ), +REG (PTP_CLK_CFG_ADJ_CFG ,0x0000a4 ), +REG (PTP_CLK_CFG_ADJ_FREQ ,0x0000a8 ), +}; +static const u32 vsc9959_gcb_regmap[] = {REG (GCB_SOFT_RST ,0x000004 ), };
@@ -293,6 +303,7 @@ static const u32 *vsc9959_regmap[] = { [REW] = vsc9959_rew_regmap, [SYS] = vsc9959_sys_regmap, [S2] = vsc9959_s2_regmap, + [PTP] = vsc9959_ptp_regmap, [GCB] = vsc9959_gcb_regmap, };
@@ -330,6 +341,11 @@ static struct resource vsc9959_target_io_res[] = { .end = 0x00603ff, .name = "s2", }, + [PTP] = { + .start = 0x0090000, + .end = 0x00900cb, + .name = "ptp", + }, [GCB] = { .start = 0x0070000, .end = 0x00701ff,
Signature · 1 line
2.7.4
Andrew Lunn
maintainerRe: [PATCH 4/5] net: dsa: ocelot: define PTP registers for felix_vsc9959
Quoted 6 lines
drivers/net/dsa/ocelot/felix_vsc9959.c +6
-0+static const u32 vsc9959_ptp_regmap[] = { +REG (PTP_PIN_CFG ,0x000000 ), +REG (PTP_PIN_TOD_SEC_MSB ,0x000004 ), +REG (PTP_PIN_TOD_SEC_LSB ,0x000008 ), +REG (PTP_PIN_TOD_NSEC ,0x00000c ), +REG (PTP_CFG_MISC ,0x0000a0 ),
drivers/net/dsa/ocelot/felix_vsc9959.c static const u32 vsc9959_sys_regmap[] = {
Quoted 10 lines
drivers/net/dsa/ocelot/felix_vsc9959.c +9
-0+REG (PTP_CLK_CFG_ADJ_CFG ,0x0000a4 ), + REG(PTP_CLK_CFG_ADJ_FREQ, 0x0000a8), +}; + + [PTP] = { + .start =0x0090000 , + .end = 0x00900cb, + .name = "ptp", + },
Seems like an odd end value. Is the last word used for something else?
Also, the last regmap register you defined is 0xa8. So could end actually be 900ab?
Andrew
RE: [PATCH 4/5] net: dsa: ocelot: define PTP registers for felix_vsc9959
Hi Andrew,
Quoted 33 lines
-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Thursday, November 21, 2019 10:49 AM
To: Y.b. Lu <[email protected]>
Cc: [email protected]; Alexandre Belloni <[email protected]>; Microchip Linux Driver Support <[email protected]>; David S . Miller <[email protected]>; Vladimir Oltean <[email protected]>; Claudiu Manoil <[email protected]>; Vivien Didelot <[email protected]>; Florian Fainelli <[email protected]>; Richard Cochran <[email protected]>
Subject: Re: [PATCH 4/5] net: dsa: ocelot: define PTP registers forfelix_vsc9959Quoted 6 lines
drivers/net/dsa/ocelot/felix_vsc9959.c +6
-0+static const u32 vsc9959_ptp_regmap[] = { +REG (PTP_PIN_CFG ,0x000000 ), +REG (PTP_PIN_TOD_SEC_MSB ,0x000004 ), +REG (PTP_PIN_TOD_SEC_LSB ,0x000008 ), +REG (PTP_PIN_TOD_NSEC ,0x00000c ), +REG (PTP_CFG_MISC ,0x0000a0 ),drivers/net/dsa/ocelot/felix_vsc9959.c static const u32 vsc9959_sys_regmap[] = {
Quoted 10 lines
drivers/net/dsa/ocelot/felix_vsc9959.c +9
-0+REG (PTP_CLK_CFG_ADJ_CFG ,0x0000a4 ), + REG(PTP_CLK_CFG_ADJ_FREQ, 0x0000a8), +}; + + [PTP] = { + .start =0x0090000 , + .end = 0x00900cb, + .name = "ptp", + },Seems like an odd end value. Is the last word used for something else?
Quoted 2 lines
Also, the last regmap register you defined is
0xa8. So could end actually be 900ab?
[Y.b. Lu] The PTP registers range is from 0x0090000 to 0x00900cb according to reference manual. The patch has only defined the registers which ocelot driver is using now, not all registers in vsc9959_ptp_regmap.
In the future, as new features will be added, I think more registers will be added to use. Thanks.
Quoted 2 lines
Andrew
Re: [PATCH 4/5] net: dsa: ocelot: define PTP registers for felix_vsc9959
In reply to Yangbo LuQuoted 3 lines · Yangbo Lu
This patch is to define PTP registers for
felix_vsc9959.Signed-off-by Yangbo Lu <[email protected]>
Signature · 1 line
Florian
PATCH 5/5 net: dsa: ocelot: add hardware timestamping support for Felix
In reply to Yangbo LuThis patch is to reuse ocelot functions as possible to enable PTP clock and to support hardware timestamping on Felix.
On TX path, timestamping works on packet which requires timestamp. The injection header will be configured accordingly, and skb clone requires timestamp will be added into a list. The TX timestamp is final handled in threaded interrupt handler when PTP timestamp FIFO is ready.
On RX path, timestamping is always working. The RX timestamp could be got from extraction header.
--- drivers/net/dsa/ocelot/felix.c | 89 ++++++++++++++++++++++++++++++++++++++++++ net/dsa/tag_ocelot.c | 14 ++++++- 2 files changed, 102 insertions(+), 1 deletion(-)
drivers/net/dsa/ocelot/felix.c +89 -0
@@ -3,6 +3,7 @@*/ #include <uapi/linux/if_bridge.h> #include <soc/mscc/ocelot.h> +#include <linux/packing.h> #include <linux/module.h> #include <linux/pci.h> #include <linux/of.h>
@@ -303,6 +304,62 @@ static void felix_teardown(struct dsa_switch *ds)ocelot_deinit (ocelot); } +static int felix_hwtstamp_get (struct dsa_switch *ds,int port, +struct ifreq *ifr) +{ +struct ocelot *ocelot = ds->priv; + +return ocelot_hwstamp_get (ocelot, port, ifr); +} + +static int felix_hwtstamp_set (struct dsa_switch *ds,int port, +struct ifreq *ifr) +{ +struct ocelot *ocelot = ds->priv; + +return ocelot_hwstamp_set (ocelot, port, ifr); +} + +static bool felix_rxtstamp (struct dsa_switch *ds,int port, +struct sk_buff *skb,unsigned int type) +{ +struct skb_shared_hwtstamps *shhwtstamps; +struct ocelot *ocelot = ds->priv; +u8 *extraction = skb->data -ETH_HLEN -OCELOT_TAG_LEN ; +u32 tstamp_lo, tstamp_hi; +struct timespec64 ts; +u64 tstamp, val; + +ocelot_ptp_gettime64 (&ocelot->ptp_info, &ts); + tstamp =ktime_set (ts.tv_sec, ts.tv_nsec); + +packing (extraction, &val,116 ,85 ,OCELOT_TAG_LEN ,UNPACK ,0 ); + tstamp_lo = (u32 )val; + + tstamp_hi = tstamp >>32 ; +if ((tstamp &0xffffffff ) < tstamp_lo) + tstamp_hi--; + + tstamp = ((u64 )tstamp_hi <<32 ) | tstamp_lo; + + shhwtstamps =skb_hwtstamps (skb); +memset (shhwtstamps,0 ,sizeof (struct skb_shared_hwtstamps )); + shhwtstamps->hwtstamp = tstamp; +return false; +} + +bool felix_txtstamp (struct dsa_switch *ds,int port, +struct sk_buff *clone,unsigned int type) +{ +struct ocelot *ocelot = ds->priv; +struct ocelot_port *ocelot_port = ocelot->ports[port]; + +if (!ocelot_port_add_txtstamp_skb (ocelot_port, clone)) +return true; + +return false; +} +static const struct dsa_switch_ops felix_switch_ops = { .get_tag_protocol = felix_get_tag_protocol, .setup = felix_setup,
@@ -325,12 +382,33 @@ static const struct dsa_switch_ops felix_switch_ops = { .port_vlan_filtering = felix_vlan_filtering, .port_vlan_add = felix_vlan_add, .port_vlan_del = felix_vlan_del, + .port_hwtstamp_get = felix_hwtstamp_get, + .port_hwtstamp_set = felix_hwtstamp_set, + .port_rxtstamp = felix_rxtstamp, + .port_txtstamp = felix_txtstamp, };static struct felix_info *felix_instance_tbl[] = { [FELIX_INSTANCE_VSC9959 ] = &felix_info_vsc9959, }; +static irqreturn_t felix_irq_handler (int irq,void *data) +{ +struct ocelot *ocelot = (struct ocelot *)data; + +/* The INTB interrupt is used for both PTP TX timestamp interrupt +* and preemption status change interrupt on each port. +* +* - Get txtstamp if have +* - TODO: handle preemption. Without handling it, driver may get +* interrupt storm. +*/ + +ocelot_get_txtstamp (ocelot); + +return IRQ_HANDLED ; +} +static int felix_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) {
@@ -372,6 +450,16 @@ static int felix_pci_probe(struct pci_dev *pdev,pci_set_master (pdev); + err =devm_request_threaded_irq (&pdev->dev, pdev->irq,NULL , + &felix_irq_handler,IRQF_ONESHOT , +"felix-intb" , ocelot); +if (err) { +dev_err (&pdev->dev,"Failed to request irq\n" ); + goto err_alloc_irq; + } + + ocelot->ptp =1 ; + ds =kzalloc (sizeof (struct dsa_switch ),GFP_KERNEL );if (!ds) { err = -ENOMEM ;
@@ -396,6 +484,7 @@ static int felix_pci_probe(struct pci_dev *pdev, err_register_ds:kfree (ds); err_alloc_ds: +err_alloc_irq: err_alloc_felix:kfree (felix); err_dma:
net/dsa/tag_ocelot.c +13 -1
@@ -137,9 +137,11 @@ static struct sk_buff *ocelot_xmit(struct sk_buff *skb, struct net_device *netdev) {struct dsa_port *dp =dsa_slave_to_port (netdev); -u64 bypass, dest, src, qos_class; +u64 bypass, dest, src, qos_class, rew_op;struct dsa_switch *ds = dp->ds;int port = dp->index; +struct ocelot *ocelot = ds->priv; +struct ocelot_port *ocelot_port = ocelot->ports[port];u8 *injection;if (unlikely (skb_cow_head (skb,OCELOT_TAG_LEN ) <0 )) {
@@ -161,6 +163,16 @@ static struct sk_buff *ocelot_xmit(struct sk_buff *skb,packing (injection, &src,46 ,43 ,OCELOT_TAG_LEN ,PACK ,0 );packing (injection, &qos_class,19 ,17 ,OCELOT_TAG_LEN ,PACK ,0 ); +if (ocelot->ptp && (skb_shinfo (skb)->tx_flags &SKBTX_HW_TSTAMP )) { + rew_op = ocelot_port->ptp_cmd; +if (ocelot_port->ptp_cmd ==IFH_REW_OP_TWO_STEP_PTP ) { + rew_op |= (ocelot_port->ts_id %4 ) <<3 ; + ocelot_port->ts_id++; + } + +packing (injection, &rew_op,125 ,117 ,OCELOT_TAG_LEN ,PACK ,0 ); + } +return skb; }
Signature · 1 line
2.7.4
Andrew Lunn
maintainerRe: [PATCH 5/5] net: dsa: ocelot: add hardware timestamping support for Felix
drivers/net/dsa/ocelot/felix.c static const struct dsa_switch_ops felix_switch_ops = { · line 405
Quoted 11 lines
drivers/net/dsa/ocelot/felix.c +11
-0+static irqreturn_t felix_irq_handler (int irq,void *data) +{ +struct ocelot *ocelot = (struct ocelot *)data; + +/* The INTB interrupt is used for both PTP TX timestamp interrupt +* and preemption status change interrupt on each port. +* +* - Get txtstamp if have +* - TODO: handle preemption. Without handling it, driver may get +* interrupt storm. +*/
I assume there are no register bits to enable/disable these two interrupt sources?
What is preemption?
Andrew
RE: [PATCH 5/5] net: dsa: ocelot: add hardware timestamping support for Felix
Hi Andrew,
Quoted 29 lines
-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Andrew Lunn
Sent: Thursday, November 21, 2019 10:56 AM
To: Y.b. Lu <[email protected]>
Cc: [email protected]; Alexandre Belloni <[email protected]>; Microchip Linux Driver Support <[email protected]>; David S . Miller <[email protected]>; Vladimir Oltean <[email protected]>; Claudiu Manoil <[email protected]>; Vivien Didelot <[email protected]>; Florian Fainelli <[email protected]>; Richard Cochran <[email protected]>
Subject: Re: [PATCH 5/5] net: dsa: ocelot: add hardware timestamping support for Felixdrivers/net/dsa/ocelot/felix.c static const struct dsa_switch_ops felix_switch_ops = { · line 405
Quoted 10 lines
drivers/net/dsa/ocelot/felix.c +10
-0+static irqreturn_t felix_irq_handler (int irq,void *data) { +struct ocelot *ocelot = (struct ocelot *)data; + +/* The INTB interrupt is used for both PTP TX timestamp interrupt +* and preemption status change interrupt on each port. +* +* - Get txtstamp if have +* - TODO: handle preemption. Without handling it, driver may get +* interrupt storm. +*/ I assume there are no register bits to enable/disable these two interrupt sources?
Quoted 1 line
What is preemption?
[Y.b. Lu] For PTP timestamp interrupt, there are not register bits to enable/disable interrupt source, and to clean interrupt status. That's why use threaded handler with oneshot flag.
For preemption, it is a feature of TSN Qbu. I'm not familiar with it. The function hasn't been supported/enabled in driver. It seems it has status bit to check, but has no bits to enable/disable interrupt source either.
Thanks.
Quoted 2 lines
Andrew
David Miller
maintainerFrom: Yangbo Lu <[email protected]>
Date: Wed, 20 Nov 2019 16:23:13 +0800
Quoted 5 lines
This patch-set is to support PTP clock and hardware timestamping for DSA Felix driver. Some functions in
ocelot.c/ocelot_board.cdriver were reworked/exported, so that DSA Felix driver was able to reuse them as much as possible.
Quoted 7 lines
On TX path, timestamping works on packet which requires timestamp. The injection header will be configured accordingly, and skb clone requires timestamp will be added into a list. The TX timestamp is final handled in threaded interrupt handler when PTP timestamp FIFO is ready.
On RX path, timestamping is always working. The RX timestamp could be got from extraction header.
Series applied, thank you.