Hirschmann Hellcreek DSA driver
Subsystems (5)
Kurt Kanzenbach
maintainerv3 cover Hirschmann Hellcreek DSA driver
Hi,
this series adds a DSA driver for the Hirschmann Hellcreek TSN switch IP. Characteristics of that IP:
* Full duplex Ethernet interface at 100/1000 Mbps on three ports
* IEEE 802.1Q-compliant Ethernet Switch
* IEEE 802.1Qbv Time-Aware scheduling support
* IEEE 1588 and IEEE 802.1AS support
That IP is used e.g. in
https://www.arrow.com/en/campaigns/arrow-kairos
Due to the hardware setup the switch driver is implemented using DSA. A special tagging protocol is leveraged. Furthermore, this driver supports PTP, hardware timestamping and TAPRIO offloading.
This work is part of the AccessTSN project: https://www.accesstsn.com/
The previous versions can be found here:
* https://lkml.kernel.org/netdev/[email protected]/
* https://lkml.kernel.org/netdev/[email protected]/
* https://lkml.kernel.org/netdev/[email protected]/
Changes since v2:
* Make it compile by getting all requirements merged first (Jakub Kicinski, David Miller)
* Use "tsn" for TSN register set (Rob Herring)
* Fix DT binding issues (Rob Herring)
Changes since v1:
* Code simplifications (Florian Fainelli, Vladimir Oltean)
* Fix issues with hellcreek.yaml bindings (Florian Fainelli)
* Clear reserved field in ptp v2 event messages (Richard Cochran)
* Make use of generic ptp parsing function (Richard Cochran, Vladimir Oltean)
* Fix Kconfig (Florian Fainelli)
* Add tags (Florian Fainelli, Rob Herring, Richard Cochran)
Changes since RFC ordered by reviewers:
* Andrew Lunn
* Use dev_dbg for debug messages
* Get rid of __ function names where possible
* Use reverse xmas tree variable ordering
* Remove redundant/useless checks
* Improve comments e.g. for PTP
* Fix Kconfig ordering
* Make LED handling more generic and provide info via DT
* Setup advertisement of PHYs according to hardware
* Drop debugfs patch
* Jakub Kicinski
* Fix compiler warnings
* Florian Fainelli
* Switch to YAML DT bindings
* Richard Cochran
* Fix typo
* Add missing NULL checks
Kamil Alkhouri (2):
net: dsa: hellcreek: Add PTP clock support
net: dsa: hellcreek: Add support for hardware timestamping
Kurt Kanzenbach (6):
net: dsa: Add tag handling for Hirschmann Hellcreek switches
net: dsa: Add DSA driver for Hirschmann Hellcreek switches
net: dsa: hellcreek: Add TAPRIO offloading support
net: dsa: hellcreek: Add PTP status LEDs
dt-bindings: Add vendor prefix for Hirschmann
dt-bindings: net: dsa: Add documentation for Hellcreek switches
.../bindings/net/dsa/hellcreek.yaml | 125 ++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/hirschmann/Kconfig | 9 + drivers/net/dsa/hirschmann/Makefile | 5 + drivers/net/dsa/hirschmann/hellcreek.c | 1551 +++++++++++++++++ drivers/net/dsa/hirschmann/hellcreek.h | 301 ++++ .../net/dsa/hirschmann/hellcreek_hwtstamp.c | 479 +++++ .../net/dsa/hirschmann/hellcreek_hwtstamp.h | 58 + drivers/net/dsa/hirschmann/hellcreek_ptp.c | 452 +++++ drivers/net/dsa/hirschmann/hellcreek_ptp.h | 76 + include/net/dsa.h | 2 + net/dsa/Kconfig | 6 + net/dsa/Makefile | 1 + net/dsa/tag_hellcreek.c | 101 ++ 16 files changed, 3171 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/hellcreek.yaml create mode 100644 drivers/net/dsa/hirschmann/Kconfig create mode 100644 drivers/net/dsa/hirschmann/Makefile create mode 100644 drivers/net/dsa/hirschmann/hellcreek.c create mode 100644 drivers/net/dsa/hirschmann/hellcreek.h create mode 100644 drivers/net/dsa/hirschmann/hellcreek_hwtstamp.c create mode 100644 drivers/net/dsa/hirschmann/hellcreek_hwtstamp.h create mode 100644 drivers/net/dsa/hirschmann/hellcreek_ptp.c create mode 100644 drivers/net/dsa/hirschmann/hellcreek_ptp.h create mode 100644 net/dsa/tag_hellcreek.c
Signature · 1 line
2.20.1
Kurt Kanzenbach
maintainerPATCH v3 1/8 net: dsa: Add tag handling for Hirschmann Hellcreek switches
The Hirschmann Hellcreek TSN switches have a special tagging protocol for frames exchanged between the CPU port and the master interface. The format is a one byte trailer indicating the destination or origin port.
It's quite similar to the Micrel KSZ tagging. That's why the implementation is based on that code.
--- include/net/dsa.h | 2 + net/dsa/Kconfig | 6 +++ net/dsa/Makefile | 1 + net/dsa/tag_hellcreek.c | 101 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 net/dsa/tag_hellcreek.c
include/net/dsa.h +2 -0
@@ -45,6 +45,7 @@ struct phylink_link_state;#define DSA_TAG_PROTO_OCELOT_VALUE 15#define DSA_TAG_PROTO_AR9331_VALUE 16#define DSA_TAG_PROTO_RTL4_A_VALUE 17 +#define DSA_TAG_PROTO_HELLCREEK_VALUE 18enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -65,6 +66,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_OCELOT =DSA_TAG_PROTO_OCELOT_VALUE ,DSA_TAG_PROTO_AR9331 =DSA_TAG_PROTO_AR9331_VALUE ,DSA_TAG_PROTO_RTL4_A =DSA_TAG_PROTO_RTL4_A_VALUE , + DSA_TAG_PROTO_HELLCREEK = DSA_TAG_PROTO_HELLCREEK_VALUE, };struct packet_type ;
net/dsa/Kconfig +6 -0
@@ -56,6 +56,12 @@ config NET_DSA_TAG_BRCM_PREPEND Broadcom switches which places the tag before the Ethernet header (prepended). +config NET_DSA_TAG_HELLCREEK + tristate "Tag driver for Hirschmann Hellcreek TSN switches" + help + Say Y or M if you want to enable support for tagging frames + for the Hirschmann Hellcreek TSN switches. + config NET_DSA_TAG_GSWIP tristate "Tag driver for Lantiq / Intel GSWIP switches" help
net/dsa/Makefile +1 -0
@@ -10,6 +10,7 @@ obj-$(CONFIG_NET_DSA_TAG_BRCM_COMMON) += tag_brcm.o obj-$(CONFIG_NET_DSA_TAG_DSA) += tag_dsa.o obj-$(CONFIG_NET_DSA_TAG_EDSA) += tag_edsa.o obj-$(CONFIG_NET_DSA_TAG_GSWIP) += tag_gswip.o +obj-$(CONFIG_NET_DSA_TAG_HELLCREEK) += tag_hellcreek.o obj-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o obj-$(CONFIG_NET_DSA_TAG_RTL4_A) += tag_rtl4_a.o obj-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o
net/dsa/tag_hellcreek.c new file +101 -0
101 lines not on this page · raw message
Signature · 1 line
2.20.1
Kurt Kanzenbach
maintainerPATCH v3 2/8 net: dsa: Add DSA driver for Hirschmann Hellcreek switches
In reply to Kurt KanzenbachAdd a basic DSA driver for Hirschmann Hellcreek switches. Those switches are implementing features needed for Time Sensitive Networking (TSN) such as support for the Time Precision Protocol and various shapers like the Time Aware Shaper.
This driver includes basic support for networking:
* VLAN handling
* FDB handling
* Port statistics
* STP
* Phylink
--- drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/hirschmann/Kconfig | 8 + drivers/net/dsa/hirschmann/Makefile | 2 + drivers/net/dsa/hirschmann/hellcreek.c | 1170 ++++++++++++++++++++++++ drivers/net/dsa/hirschmann/hellcreek.h | 244 +++++ 6 files changed, 1427 insertions(+) create mode 100644 drivers/net/dsa/hirschmann/Kconfig create mode 100644 drivers/net/dsa/hirschmann/Makefile create mode 100644 drivers/net/dsa/hirschmann/hellcreek.c create mode 100644 drivers/net/dsa/hirschmann/hellcreek.h
drivers/net/dsa/Kconfig +2 -0
@@ -58,6 +58,8 @@ source "drivers/net/dsa/qca/Kconfig" source "drivers/net/dsa/sja1105/Kconfig" +source "drivers/net/dsa/hirschmann/Kconfig" + config NET_DSA_QCA8K tristate "Qualcomm Atheros QCA8K Ethernet switch family support" depends on NET_DSA
drivers/net/dsa/Makefile +1 -0
@@ -23,3 +23,4 @@ obj-y += mv88e6xxx/ obj-y += ocelot/ obj-y += qca/ obj-y += sja1105/ +obj-y += hirschmann/
drivers/net/dsa/hirschmann/Kconfig new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0 +config NET_DSA_HIRSCHMANN_HELLCREEK + tristate "Hirschmann Hellcreek TSN Switch support" + depends on HAS_IOMEM + depends on NET_DSA + select NET_DSA_TAG_HELLCREEK + help + This driver adds support for Hirschmann Hellcreek TSN switches.
drivers/net/dsa/hirschmann/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_NET_DSA_HIRSCHMANN_HELLCREEK) += hellcreek.o
drivers/net/dsa/hirschmann/hellcreek.c new file +1170 -0
1,170 lines not on this page · raw message
drivers/net/dsa/hirschmann/hellcreek.h new file +244 -0
244 lines not on this page · raw message
Signature · 1 line
2.20.1
Andrew Lunn
maintainerRe: [PATCH v3 2/8] net: dsa: Add DSA driver for Hirschmann Hellcreek switches
Quoted 31 lines · Kurt Kanzenbach
Add a basic DSA driver for Hirschmann Hellcreek switches. Those switches are implementing features needed for Time Sensitive Networking (TSN) such as support for the Time Precision Protocol and various shapers like the Time Aware Shaper.
This driver includes basic support for networking:
* VLAN handling
* FDB handling
* Port statistics
* STP
* PhylinkSigned-off-by Kurt Kanzenbach <[email protected]>--- drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/hirschmann/Kconfig | 8 + drivers/net/dsa/hirschmann/Makefile | 2 + drivers/net/dsa/hirschmann/hellcreek.c | 1170 ++++++++++++++++++++++++ drivers/net/dsa/hirschmann/hellcreek.h | 244 +++++ 6 files changed, 1427 insertions(+) create mode 100644 drivers/net/dsa/hirschmann/Kconfig create mode 100644 drivers/net/dsa/hirschmann/Makefile create mode 100644 drivers/net/dsa/hirschmann/hellcreek.c create mode 100644 drivers/net/dsa/hirschmann/hellcreek.hdrivers/net/dsa/Kconfig +0
-0
drivers/net/dsa/Kconfig source "drivers/net/dsa/qca/Kconfig" · line 65
Quoted 8 lines
drivers/net/dsa/Kconfig +2
-0@@ -58,6 +58,8 @@ source "drivers/net/dsa/qca/Kconfig" source "drivers/net/dsa/sja1105/Kconfig" +source "drivers/net/dsa/hirschmann/Kconfig" + config NET_DSA_QCA8K tristate "Qualcomm Atheros QCA8K Ethernet switch family support" depends on NET_DSA
Hi Kurt
The DSA entries are sorted into alphabetic order based on what you see in make menuconfig. As such, "Hirschmann Hellcreek TSN Switch support" fits in between "DSA mock-up Ethernet switch chip support" and "Lantiq / Intel GSWIP"
drivers/net/dsa/Makefile obj-y += mv88e6xxx/ · line 26
Quoted 9 lines
drivers/net/dsa/Makefile +1
-0@@ -23,3 +23,4 @@ obj-y += mv88e6xxx/ obj-y += ocelot/ obj-y += qca/ obj-y += sja1105/ +obj-y += hirschmann/
This file is also sorted.
Quoted 5 lines
drivers/net/dsa/Makefile +5
-0+static int hellcreek_detect(struct hellcreek *hellcreek) +{ + u16 id, rel_low, rel_high, date_low, date_high, tgd_ver; + u8 tgd_maj, tgd_min; + u32 rel, date;
drivers/net/dsa/Makefile
Quoted 10 lines
drivers/net/dsa/Makefile +10
-0+ + id = hellcreek_read(hellcreek, HR_MODID_C); + rel_low = hellcreek_read(hellcreek, HR_REL_L_C); + rel_high = hellcreek_read(hellcreek, HR_REL_H_C); + date_low = hellcreek_read(hellcreek, HR_BLD_L_C); + date_high = hellcreek_read(hellcreek, HR_BLD_H_C); + tgd_ver = hellcreek_read(hellcreek, TR_TGDVER); + + if (id != HELLCREEK_MODULE_ID) + return -ENODEV;
Are there other Hellcreek devices? I'm just wondering if we should have a specific compatible for 0x4c30 as well as the more generic "hirschmann,hellcreek".
Quoted 13 lines
drivers/net/dsa/Makefile +13
-0+static void hellcreek_get_ethtool_stats(struct dsa_switch *ds, int port, + uint64_t *data) +{ + struct hellcreek *hellcreek = ds->priv; + struct hellcreek_port *hellcreek_port; + unsigned long flags; + int i; + + hellcreek_port = &hellcreek->ports[port]; + + spin_lock_irqsave(&hellcreek->reg_lock, flags); + for (i = 0; i < ARRAY_SIZE(hellcreek_counter); ++i) { + const struct hellcreek_counter *counter = &hellcreek_counter[i];
drivers/net/dsa/Makefile
Quoted 10 lines
drivers/net/dsa/Makefile +10
-0+ u8 offset = counter->offset + port * 64; + u16 high, low; + u64 value = 0; + + hellcreek_select_counter(hellcreek, offset); + + /* The registers are locked internally by selecting the + * counter. So low and high can be read without reading high + * again. + */
Is there any locking/snapshot of all the counters at once? Most devices have support for that, so you can compare counters against each other.
drivers/net/dsa/Makefile
Quoted 10 lines
drivers/net/dsa/Makefile +10
-0+ high = hellcreek_read(hellcreek, HR_CRDH); + low = hellcreek_read(hellcreek, HR_CRDL); + value = (high << 16) | low; + + hellcreek_port->counter_values[i] += value; + data[i] = hellcreek_port->counter_values[i]; + } + spin_unlock_irqrestore(&hellcreek->reg_lock, flags); +} +
Andrew
Kurt Kanzenbach
maintainerRe: [PATCH v3 2/8] net: dsa: Add DSA driver for Hirschmann Hellcreek switches
On Tue Aug 25 2020, Andrew Lunn wrote:
[snip]
Quoted 11 lines
drivers/net/dsa/Kconfig source "drivers/net/dsa/qca/Kconfig" · line 65
Quoted 8 lines
source "
drivers/net/dsa/sja1105/Kconfig"drivers/net/dsa/Kconfig +2
-0+source "drivers/net/dsa/hirschmann/Kconfig" + config NET_DSA_QCA8K tristate "Qualcomm Atheros QCA8K Ethernet switch family support" depends on NET_DSAHi Kurt
Quoted 4 lines
The DSA entries are sorted into alphabetic order based on what you see in make menuconfig. As such, "Hirschmann Hellcreek TSN Switch support" fits in between "DSA mock-up Ethernet switch chip support" and "Lantiq / Intel GSWIP"
Yes, of course. I've only sorted the entries in the previous patch...
Quoted 24 lines
drivers/net/dsa/Makefile obj-y += mv88e6xxx/ · line 26
Quoted 10 lines
drivers/net/dsa/Makefile +1
-0@@ -23,3 +23,4 @@ obj-y += mv88e6xxx/ obj-y += ocelot/ obj-y += qca/ obj-y += sja1105/ +obj-y += hirschmann/This file is also sorted.
Quoted 11 lines
drivers/net/dsa/Makefile +11
-0+static int hellcreek_detect(struct hellcreek *hellcreek) +{ + u16 id, rel_low, rel_high, date_low, date_high, tgd_ver; + u8 tgd_maj, tgd_min; + u32 rel, date; + + id = hellcreek_read(hellcreek, HR_MODID_C); + rel_low = hellcreek_read(hellcreek, HR_REL_L_C); + rel_high = hellcreek_read(hellcreek, HR_REL_H_C); + date_low = hellcreek_read(hellcreek, HR_BLD_L_C); + date_high = hellcreek_read(hellcreek, HR_BLD_H_C);
Quoted 8 lines
drivers/net/dsa/Makefile
Quoted 4 lines
drivers/net/dsa/Makefile +4
-0+ tgd_ver = hellcreek_read(hellcreek, TR_TGDVER); + + if (id != HELLCREEK_MODULE_ID) + return -ENODEV;Are there other Hellcreek devices? I'm just wondering if we should have a specific compatible for
0x4c30as well as the more generic "hirschmann,hellcreek".
Yes, there will be different revisions of the Hellcreek devices. This ID is really device specific. A lot of features of this switch are configured in the VHDL code. For instance the MAC settings (100 or 1000 Mbit/s).
I've discussed this with the HW engineer from Hirschmann. He suggested to keep this check here, as the driver is currently specific for the that device. We have to make sure that the driver matches the hardware.
My plan was to extend this when I have access to other revisions. There will be a SPI variant as well. But, I didn't want to implement it without the ability to test it.
Quoted 20 lines
Quoted 20 lines
drivers/net/dsa/Makefile +19
-0+static void hellcreek_get_ethtool_stats(struct dsa_switch *ds, int port, + uint64_t *data) +{ + struct hellcreek *hellcreek = ds->priv; + struct hellcreek_port *hellcreek_port; + unsigned long flags; + int i; + + hellcreek_port = &hellcreek->ports[port]; + + spin_lock_irqsave(&hellcreek->reg_lock, flags); + for (i = 0; i < ARRAY_SIZE(hellcreek_counter); ++i) { + const struct hellcreek_counter *counter = &hellcreek_counter[i]; + u8 offset = counter->offset + port * 64; + u16 high, low; + u64 value = 0; + + hellcreek_select_counter(hellcreek, offset); +
Quoted 8 lines
drivers/net/dsa/Makefile
Quoted 4 lines
drivers/net/dsa/Makefile +4
-0+ /* The registers are locked internally by selecting the + * counter. So low and high can be read without reading high + * again. + */Is there any locking/snapshot of all the counters at once? Most devices have support for that, so you can compare counters against each other.
No, there is not.
Thanks,
Kurt
Andrew Lunn
maintainerRe: [PATCH v3 2/8] net: dsa: Add DSA driver for Hirschmann Hellcreek switches
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/dsa/hirschmann/hellcreek.c new file +11
-0+static int hellcreek_detect (struct hellcreek *hellcreek) +{ +u16 id, rel_low, rel_high, date_low, date_high, tgd_ver; +u8 tgd_maj, tgd_min; +u32 rel, date; + + id =hellcreek_read (hellcreek,HR_MODID_C ); + rel_low =hellcreek_read (hellcreek,HR_REL_L_C ); + rel_high =hellcreek_read (hellcreek,HR_REL_H_C ); + date_low =hellcreek_read (hellcreek,HR_BLD_L_C ); + date_high =hellcreek_read (hellcreek,HR_BLD_H_C );Quoted 8 lines
drivers/net/dsa/hirschmann/hellcreek.c line 196
Quoted 4 lines
drivers/net/dsa/hirschmann/hellcreek.c new file +4
-0+ tgd_ver =hellcreek_read (hellcreek,TR_TGDVER ); + +if (id !=HELLCREEK_MODULE_ID ) +return -ENODEV ;Are there other Hellcreek devices? I'm just wondering if we should have a specific compatible for
0x4c30as well as the more generic "hirschmann,hellcreek".
Quoted 8 lines
Yes, there will be different revisions of the Hellcreek devices. This ID is really device specific. A lot of features of this switch are configured in the VHDL code. For instance the MAC settings (100 or 1000 Mbit/s).
I've discussed this with the HW engineer from Hirschmann. He suggested to keep this check here, as the driver is currently specific for the that device. We have to make sure that the driver matches the hardware.
I agree with the check here. The question is about the compatible string. Should there be a more specific compatible string as well as the generic one?
There have been a few discussions about how the Marvell DSA driver does its compatible string. The compatible string tells you where to find the ID register, not what value to expect in the ID register. The ID register can currently be in one of three different locations. Do all current and future Hellcreak devices have the same value for HR_MODID_C? If not, now is a good time to add a more specific compatible string to tell you where to find the ID register.
Quoted 3 lines
My plan was to extend this when I have access to other revisions. There will be a SPI variant as well. But, I didn't want to implement it without the ability to test it.
Does the SPI variant use the same value for HR_MODID_C? Maybe you need a different compatible, maybe not, depending on how the driver is structured.
The compatible string is part of the ABI. So thinking about it a bit now can make things easier later. I just want to make sure you have thought about this.
Andrew
Kurt Kanzenbach
maintainerRe: [PATCH v3 2/8] net: dsa: Add DSA driver for Hirschmann Hellcreek switches
Quoted 16 lines · Andrew Lunn
I agree with the check here. The question is about the compatible string. Should there be a more specific compatible string as well as the generic one?
There have been a few discussions about how the Marvell DSA driver does its compatible string. The compatible string tells you where to find the ID register, not what value to expect in the ID register. The ID register can currently be in one of three different locations. Do all current and future Hellcreak devices have the same value for
HR_MODID_C? If not, now is a good time to add a more specific compatible string to tell you where to find the ID register.Quoted 3 lines
My plan was to extend this when I have access to other revisions. There will be a SPI variant as well. But, I didn't want to implement it without the ability to test it.
Quoted 7 lines
Does the SPI variant use the same value for
HR_MODID_C? Maybe you need a different compatible, maybe not, depending on how the driver is structured.The compatible string is part of the ABI. So thinking about it a bit now can make things easier later. I just want to make sure you have thought about this.
I totally agree. The Marvell solution seems to work. For all current devices the module ID is located at 0x00. Depending on the chip ID the different properties can be configured later. The SPI variant will have a different module ID. Anyhow, I'll ask how this will be handled for future devices and in general.
Thanks,
Kurt
Kurt Kanzenbach
maintainerRe: [PATCH v3 2/8] net: dsa: Add DSA driver for Hirschmann Hellcreek switches
Hi Andrew,
Quoted 25 lines · Kurt Kanzenbach
Quoted 16 lines · Andrew Lunn
I agree with the check here. The question is about the compatible string. Should there be a more specific compatible string as well as the generic one?
There have been a few discussions about how the Marvell DSA driver does its compatible string. The compatible string tells you where to find the ID register, not what value to expect in the ID register. The ID register can currently be in one of three different locations. Do all current and future Hellcreak devices have the same value for
HR_MODID_C? If not, now is a good time to add a more specific compatible string to tell you where to find the ID register.Quoted 3 lines
My plan was to extend this when I have access to other revisions. There will be a SPI variant as well. But, I didn't want to implement it without the ability to test it.
Quoted 7 lines
Does the SPI variant use the same value for
HR_MODID_C? Maybe you need a different compatible, maybe not, depending on how the driver is structured.The compatible string is part of the ABI. So thinking about it a bit now can make things easier later. I just want to make sure you have thought about this.
Quoted 5 lines
I totally agree. The Marvell solution seems to work. For all current devices the module ID is located at
0x00. Depending on the chip ID the different properties can be configured later. The SPI variant will have a different module ID. Anyhow, I'll ask how this will be handled for future devices and in general.
After further discussion, we cannot use the Marvell solution.
So, the module id doesn't help us in determining anything about the hardware. The module id can be arbitrarily chosen. A lot of the features of the switch IP core are compile time options and cannot be read back via registers. The hardware integrator can chose which features are used, the precision of the get of the day for the ptp clock, the module id, the port speed, additional debug options and so on.
All of this depends on how the IP core is integrated into the hardware most likely an FPGA. My suggestion for now is to use different compatible strings. Currently two variants exists:
* An evaluation platform based on a Cyclone V based DE1 board from Terasic
* The kairos chip (via SPI) which I mentioned in the cover letter
More variants are about to come with more ports, etc.
So, we would need different strings to distinguish between them. Proposal:
* "hirschmann,hellcreek-de1soc-r1"
* "hirschmann,hellcreek-ksp-rbrb-trsrr-r208"
And create some form of platform_data with:
* module id
* amount of ports
* port speed
* qbv support
* ...
Any thoughts on this?
Thanks,
Kurt
Kurt Kanzenbach
maintainerPATCH v3 3/8 net: dsa: hellcreek: Add PTP clock support
In reply to Kurt KanzenbachFrom: Kamil Alkhouri <[email protected]>
The switch has internal PTP hardware clocks. Add support for it. There are three clocks:
* Synchronized
* Syntonized
* Free running
Currently the synchronized clock is exported to user space which is a good default for the beginning. The free running clock might be exported later e.g. for implementing 802.1AS-2011/2020 Time Aware Bridges (TAB). The switch also supports cross time stamping for that purpose.
The implementation adds support setting/getting the time as well as offset and frequency adjustments. However, the clock only holds a partial timeofday timestamp. This is why we track the seconds completely in software (see overflow work and last_ts).
Furthermore, add the PTP multicast addresses into the FDB to forward that packages only to the CPU port where they are processed by a PTP program.
--- drivers/net/dsa/hirschmann/Kconfig | 1 + drivers/net/dsa/hirschmann/Makefile | 4 +- drivers/net/dsa/hirschmann/hellcreek.c | 72 ++++++ drivers/net/dsa/hirschmann/hellcreek.h | 7 + drivers/net/dsa/hirschmann/hellcreek_ptp.c | 283 +++++++++++++++++++++ drivers/net/dsa/hirschmann/hellcreek_ptp.h | 69 +++++ 6 files changed, 435 insertions(+), 1 deletion(-) create mode 100644 drivers/net/dsa/hirschmann/hellcreek_ptp.c create mode 100644 drivers/net/dsa/hirschmann/hellcreek_ptp.h
drivers/net/dsa/hirschmann/Kconfig +1 -0
@@ -3,6 +3,7 @@ config NET_DSA_HIRSCHMANN_HELLCREEK tristate "Hirschmann Hellcreek TSN Switch support" depends on HAS_IOMEM depends on NET_DSA + depends on PTP_1588_CLOCK select NET_DSA_TAG_HELLCREEK help This driver adds support for Hirschmann Hellcreek TSN switches.
drivers/net/dsa/hirschmann/Makefile +3 -1
@@ -1,2 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_NET_DSA_HIRSCHMANN_HELLCREEK) += hellcreek.o +obj-$(CONFIG_NET_DSA_HIRSCHMANN_HELLCREEK) += hellcreek_sw.o +hellcreek_sw-objs := hellcreek.o +hellcreek_sw-objs += hellcreek_ptp.o
drivers/net/dsa/hirschmann/hellcreek.c +72 -0
117 lines not on this page · raw message
drivers/net/dsa/hirschmann/hellcreek.h +7 -0
@@ -234,10 +234,17 @@ struct hellcreek_fdb_entry {struct hellcreek {struct device *dev;struct dsa_switch *ds; +struct ptp_clock *ptp_clock; +struct ptp_clock_info ptp_clock_info;struct hellcreek_port ports[4 ]; +struct delayed_work overflow_work;spinlock_t reg_lock;/* Switch IP register lock */ +spinlock_t ptp_lock;/* PTP IP register lock */ void __iomem *base; +void __iomem *ptp_base;u8 *vidmbrcfg;/* vidmbrcfg shadow */ +u64 seconds;/* PTP seconds */ +u64 last_ts;/* Used for overflow detection */ size_t fdb_entries; };
drivers/net/dsa/hirschmann/hellcreek_ptp.c new file +283 -0
283 lines not on this page · raw message
drivers/net/dsa/hirschmann/hellcreek_ptp.h new file +69 -0
69 lines not on this page · raw message
Signature · 1 line
2.20.1
Kurt Kanzenbach
maintainerPATCH v3 4/8 net: dsa: hellcreek: Add support for hardware timestamping
In reply to Kurt KanzenbachFrom: Kamil Alkhouri <[email protected]>
The switch has the ability to take hardware generated time stamps per port for PTPv2 event messages in Rx and Tx direction. That is useful for achieving needed time synchronization precision for TSN devices/switches. So add support for it.
There are two directions:
* RX
The switch has a single register per port to capture a timestamp. That mechanism is not used due to correlation problems. If the software processing is too slow and a PTPv2 event message is received before the previous one has been processed, false timestamps will be captured. Therefore, the switch can do "inline" timestamping which means it can insert the nanoseconds part of the timestamp directly into the PTPv2 event message. The reserved field (4 bytes) is leveraged for that. This might not be in accordance with (older) PTP standards, but is the only way to get reliable results.
* TX
In Tx direction there is no correlation problem, because the software and the driver has to ensure that only one event message is "on the fly". However, the switch provides also a mechanism to check whether a timestamp is lost. That can only happen when a timestamp is read and at this point another message is timestamped. So, that lost bit is checked just in case to indicate to the user that the driver or the software is somewhat buggy.
--- drivers/net/dsa/hirschmann/Makefile | 1 + drivers/net/dsa/hirschmann/hellcreek.c | 15 + drivers/net/dsa/hirschmann/hellcreek.h | 25 + .../net/dsa/hirschmann/hellcreek_hwtstamp.c | 479 ++++++++++++++++++ .../net/dsa/hirschmann/hellcreek_hwtstamp.h | 58 +++ drivers/net/dsa/hirschmann/hellcreek_ptp.c | 48 +- drivers/net/dsa/hirschmann/hellcreek_ptp.h | 4 + 7 files changed, 616 insertions(+), 14 deletions(-) create mode 100644 drivers/net/dsa/hirschmann/hellcreek_hwtstamp.c create mode 100644 drivers/net/dsa/hirschmann/hellcreek_hwtstamp.h
drivers/net/dsa/hirschmann/Makefile +1 -0
@@ -2,3 +2,4 @@ obj-$(CONFIG_NET_DSA_HIRSCHMANN_HELLCREEK) += hellcreek_sw.o hellcreek_sw-objs := hellcreek.o hellcreek_sw-objs += hellcreek_ptp.o +hellcreek_sw-objs += hellcreek_hwtstamp.o
drivers/net/dsa/hirschmann/hellcreek.c +15 -0
@@ -26,6 +26,7 @@#include "hellcreek.h" #include "hellcreek_ptp.h" +#include "hellcreek_hwtstamp.h" static const struct hellcreek_counter hellcreek_counter[] = { {0x00 ,"RxFiltered" , },
@@ -1099,6 +1100,11 @@ static const struct dsa_switch_ops hellcreek_ds_ops = { .port_bridge_leave = hellcreek_port_bridge_leave, .port_stp_state_set = hellcreek_port_stp_state_set, .phylink_validate = hellcreek_phylink_validate, + .port_hwtstamp_set = hellcreek_port_hwtstamp_set, + .port_hwtstamp_get = hellcreek_port_hwtstamp_get, + .port_txtstamp = hellcreek_port_txtstamp, + .port_rxtstamp = hellcreek_port_rxtstamp, + .get_ts_info = hellcreek_get_ts_info, };static int hellcreek_probe (struct platform_device *pdev)
@@ -1198,10 +1204,18 @@ static int hellcreek_probe(struct platform_device *pdev) goto err_ptp_setup; } + ret =hellcreek_hwtstamp_setup (hellcreek); +if (ret) { +dev_err (dev,"Failed to setup hardware timestamping!\n" ); + goto err_tstamp_setup; + } +platform_set_drvdata (pdev, hellcreek);return 0 ; +err_tstamp_setup: +hellcreek_ptp_free (hellcreek); err_ptp_setup:dsa_unregister_switch (hellcreek->ds);
@@ -1212,6 +1226,7 @@ static int hellcreek_remove(struct platform_device *pdev) {struct hellcreek *hellcreek =platform_get_drvdata (pdev); +hellcreek_hwtstamp_free (hellcreek);hellcreek_ptp_free (hellcreek);dsa_unregister_switch (hellcreek->ds);platform_set_drvdata (pdev,NULL );
drivers/net/dsa/hirschmann/hellcreek.h +25 -0
@@ -212,11 +212,36 @@ struct hellcreek_counter {struct hellcreek ; +/* State flags for hellcreek_port_hwtstamp::state */ +enum { +HELLCREEK_HWTSTAMP_ENABLED , +HELLCREEK_HWTSTAMP_TX_IN_PROGRESS , +}; + +/* A structure to hold hardware timestamping information per port */ +struct hellcreek_port_hwtstamp { +/* Timestamping state */ +unsigned long state; + +/* Resources for receive timestamping */ +struct sk_buff_head rx_queue;/* For synchronization messages */ + +/* Resources for transmit timestamping */ +unsigned long tx_tstamp_start; +struct sk_buff *tx_skb; + +/* Current timestamp configuration */ +struct hwtstamp_config tstamp_config; +}; +struct hellcreek_port {struct hellcreek *hellcreek;int port;u16 ptcfg;/* ptcfg shadow */ u64 *counter_values; + +/* Per-port timestamping resources */ +struct hellcreek_port_hwtstamp port_hwtstamp; };struct hellcreek_fdb_entry {
drivers/net/dsa/hirschmann/hellcreek_hwtstamp.c new file +479 -0
479 lines not on this page · raw message
drivers/net/dsa/hirschmann/hellcreek_hwtstamp.h new file +58 -0
58 lines not on this page · raw message
drivers/net/dsa/hirschmann/hellcreek_ptp.c +34 -14
71 lines not on this page · raw message
drivers/net/dsa/hirschmann/hellcreek_ptp.h +4 -0
@@ -59,6 +59,10 @@int hellcreek_ptp_setup (struct hellcreek *hellcreek);void hellcreek_ptp_free (struct hellcreek *hellcreek); +u16 hellcreek_ptp_read (struct hellcreek *hellcreek,unsigned int offset); +void hellcreek_ptp_write (struct hellcreek *hellcreek,u16 data, +unsigned int offset); +u64 hellcreek_ptp_gettime_seconds (struct hellcreek *hellcreek,u64 ns);#define ptp_to_hellcreek (ptp) \ container_of(ptp, struct hellcreek, ptp_clock_info)
Signature · 1 line
2.20.1
Kurt Kanzenbach
maintainerPATCH v3 5/8 net: dsa: hellcreek: Add TAPRIO offloading support
In reply to Kurt KanzenbachThe switch has support for the 802.1Qbv Time Aware Shaper (TAS). Traffic schedules may be configured individually on each front port. Each port has eight egress queues. The traffic is mapped to a traffic class respectively via the PCP field of a VLAN tagged frame.
The TAPRIO Qdisc already implements that. Therefore, this interface can simply be reused. Add .port_setup_tc() accordingly.
The activation of a schedule on a port is split into two parts:
* Programming the necessary gate control list (GCL)
* Setup hrtimer for starting the schedule
The hardware supports starting a schedule up to eight seconds in the future. The TAPRIO interface provides an absolute base time. Therefore, hrtimers are leveraged.
--- drivers/net/dsa/hirschmann/hellcreek.c | 294 +++++++++++++++++++++++++ drivers/net/dsa/hirschmann/hellcreek.h | 21 ++ 2 files changed, 315 insertions(+)
drivers/net/dsa/hirschmann/hellcreek.c +294 -0
@@ -22,7 +22,9 @@#include <linux/spinlock.h> #include <linux/delay.h> #include <linux/ktime.h> +#include <linux/time.h> #include <net/dsa.h> +#include <net/pkt_sched.h> #include "hellcreek.h" #include "hellcreek_ptp.h"
@@ -153,6 +155,15 @@ static void hellcreek_select_vlan(struct hellcreek *hellcreek, int vid,hellcreek_write (hellcreek, val,HR_VIDCFG ); } +static void hellcreek_select_tgd (struct hellcreek *hellcreek,int port) +{ +u16 val =0 ; + + val |= port <<TR_TGDSEL_TDGSEL_SHIFT ; + +hellcreek_write (hellcreek, val,TR_TGDSEL ); +} +static int hellcreek_wait_until_ready (struct hellcreek *hellcreek) {u16 val;
@@ -958,6 +969,24 @@ static void __hellcreek_setup_tc_identity_mapping(struct hellcreek *hellcreek) } } +static void hellcreek_setup_tc_mapping (struct hellcreek *hellcreek, +struct net_device *netdev) +{ +int i, j; + +/* Setup mapping between traffic classes and port queues. */ +for (i =0 ; i <netdev_get_num_tc (netdev); ++i) { +for (j =0 ; j < netdev->tc_to_txq[i].count; ++j) { +const int queue = j + netdev->tc_to_txq[i].offset; + +hellcreek_select_prio (hellcreek, i); +hellcreek_write (hellcreek, + queue <<HR_PRTCCFG_PCP_TC_MAP_SHIFT , +HR_PRTCCFG ); + } + } +} +static void hellcreek_setup_tc_identity_mapping (struct hellcreek *hellcreek) {unsigned long flags;
@@ -1081,6 +1110,267 @@ static void hellcreek_phylink_validate(struct dsa_switch *ds, int port, __ETHTOOL_LINK_MODE_MASK_NBITS); } +static void hellcreek_setup_gcl (struct hellcreek *hellcreek,int port, +const struct hellcreek_schedule *schedule) +{ +size_t i; + +for (i =1 ; i <= schedule->num_entries; ++i) { +const struct hellcreek_gcl_entry *cur, *initial, *next; +u16 data; +u8 gates; + + cur = &schedule->entries[i -1 ]; + initial = &schedule->entries[0 ]; + next = &schedule->entries[i]; + +if (i == schedule->num_entries) + gates = initial->gate_states ^ + cur->gate_states; +else + gates = next->gate_states ^ + cur->gate_states; + + data = gates; +if (cur->overrun_ignore) + data |=TR_GCLDAT_GCLOVRI ; + +if (i == schedule->num_entries) + data |=TR_GCLDAT_GCLWRLAST ; + +/* Gates states */ +hellcreek_write (hellcreek, data,TR_GCLDAT ); + +/* Time intervall */ +hellcreek_write (hellcreek, + cur->interval &0x0000ffff , +TR_GCLTIL ); +hellcreek_write (hellcreek, + (cur->interval &0xffff0000 ) >>16 , +TR_GCLTIH ); + +/* Commit entry */ + data = ((i -1 ) <<TR_GCLCMD_GCLWRADR_SHIFT ) | + (initial->gate_states << +TR_GCLCMD_INIT_GATE_STATES_SHIFT ); +hellcreek_write (hellcreek, data,TR_GCLCMD ); + } +} + +static void hellcreek_set_cycle_time (struct hellcreek *hellcreek, +const struct hellcreek_schedule *schedule) +{ +u32 cycle_time = schedule->cycle_time; + +hellcreek_write (hellcreek, cycle_time &0x0000ffff ,TR_CTWRL ); +hellcreek_write (hellcreek, (cycle_time &0xffff0000 ) >>16 ,TR_CTWRH ); +} + +static void hellcreek_start_schedule (struct hellcreek *hellcreek, +ktime_t start_time) +{ +struct timespec64 ts =ktime_to_timespec64 (start_time); + +/* Start can be only 8 seconds in the future */ + ts.tv_sec %=8 ; + +/* Start schedule at this point of time */ +hellcreek_write (hellcreek, ts.tv_nsec &0x0000ffff ,TR_ESTWRL ); +hellcreek_write (hellcreek, (ts.tv_nsec &0xffff0000 ) >>16 ,TR_ESTWRH ); + +/* Arm timer, set seconds and switch schedule */ +hellcreek_write (hellcreek,TR_ESTCMD_ESTARM |TR_ESTCMD_ESTSWCFG | + ((ts.tv_sec &TR_ESTCMD_ESTSEC_MASK ) << +TR_ESTCMD_ESTSEC_SHIFT ),TR_ESTCMD ); +} + +static struct hellcreek_schedule *hellcreek_taprio_to_schedule ( +const struct tc_taprio_qopt_offload *taprio) +{ +struct hellcreek_schedule *schedule; +size_t i; + +/* Allocate some memory first */ + schedule =kzalloc (sizeof (*schedule),GFP_KERNEL ); +if (!schedule) +return ERR_PTR (-ENOMEM ); + schedule->entries =kcalloc (taprio->num_entries, +sizeof (*schedule->entries), +GFP_KERNEL ); +if (!schedule->entries) { +kfree (schedule); +return ERR_PTR (-ENOMEM ); + } + +/* Construct hellcreek schedule */ + schedule->num_entries = taprio->num_entries; + schedule->base_time = taprio->base_time; + +for (i =0 ; i < taprio->num_entries; ++i) { +const struct tc_taprio_sched_entry *t = &taprio->entries[i]; +struct hellcreek_gcl_entry *k = &schedule->entries[i]; + + k->interval = t->interval; + k->gate_states = t->gate_mask; + k->overrun_ignore =0 ; + +/* Update complete cycle time */ + schedule->cycle_time += t->interval; + } + +return schedule; +} + +static enum hrtimer_restart hellcreek_set_schedule (struct hrtimer *timer) +{ +struct hellcreek_port *hellcreek_port = +hrtimer_to_hellcreek_port (timer); +struct hellcreek *hellcreek = hellcreek_port->hellcreek; +struct hellcreek_schedule *schedule; +unsigned long flags; + +spin_lock_irqsave (&hellcreek->reg_lock, flags); + +/* First select port */ +hellcreek_select_tgd (hellcreek, hellcreek_port->port); + +/* Set admin base time and switch schedule */ +hellcreek_start_schedule (hellcreek, + hellcreek_port->current_schedule->base_time); + + schedule = hellcreek_port->current_schedule; + hellcreek_port->current_schedule =NULL ; + +spin_unlock_irqrestore (&hellcreek->reg_lock, flags); + +dev_dbg (hellcreek->dev,"ARMed EST timer for port %d\n" , + hellcreek_port->port); + +/* Free resources */ +kfree (schedule->entries); +kfree (schedule); + +return HRTIMER_NORESTART ; +} + +static int hellcreek_port_set_schedule (struct dsa_switch *ds,int port, +const struct tc_taprio_qopt_offload *taprio) +{ +struct net_device *netdev =dsa_to_port (ds, port)->slave; +struct hellcreek *hellcreek = ds->priv; +struct hellcreek_port *hellcreek_port; +struct hellcreek_schedule *schedule; +unsigned long flags; +ktime_t start; +u16 ctrl; + + hellcreek_port = &hellcreek->ports[port]; + +/* Convert taprio data to hellcreek schedule */ + schedule =hellcreek_taprio_to_schedule (taprio); +if (IS_ERR (schedule)) +return PTR_ERR (schedule); + +dev_dbg (hellcreek->dev,"Configure traffic schedule on port %d\n" , + port); + +/* Cancel an in flight timer */ +hrtimer_cancel (&hellcreek_port->cycle_start_timer); + +spin_lock_irqsave (&hellcreek->reg_lock, flags); + +if (hellcreek_port->current_schedule) { +kfree (hellcreek_port->current_schedule->entries); +kfree (hellcreek_port->current_schedule); + } + + hellcreek_port->current_schedule = schedule; + +/* First select port */ +hellcreek_select_tgd (hellcreek, port); + +/* Setup traffic class <-> queue mapping */ +hellcreek_setup_tc_mapping (hellcreek, netdev); + +/* Enable gating and set the admin state to forward everything in the +* mean time +*/ + ctrl = (0xff <<TR_TGDCTRL_ADMINGATESTATES_SHIFT ) |TR_TGDCTRL_GATE_EN ; +hellcreek_write (hellcreek, ctrl,TR_TGDCTRL ); + +/* Cancel pending schedule */ +hellcreek_write (hellcreek,0x00 ,TR_ESTCMD ); + +/* Setup a new schedule */ +hellcreek_setup_gcl (hellcreek, port, schedule); + +/* Configure cycle time */ +hellcreek_set_cycle_time (hellcreek, schedule); + +/* Setup timer for schedule switch: The IP core only allows to set a +* cycle start timer 8 seconds in the future. This is why we setup the +* hritmer to base_time - 5 seconds. Then, we have enough time to +* activate IP core's EST timer. +*/ + start =ktime_sub_ns (schedule->base_time, (u64 )5 *NSEC_PER_SEC ); +hrtimer_start_range_ns (&hellcreek_port->cycle_start_timer, start, +NSEC_PER_SEC ,HRTIMER_MODE_ABS ); + +spin_unlock_irqrestore (&hellcreek->reg_lock, flags); + +return 0 ; +} + +static int hellcreek_port_del_schedule (struct dsa_switch *ds,int port) +{ +struct hellcreek *hellcreek = ds->priv; +struct hellcreek_port *hellcreek_port; +unsigned long flags; + + hellcreek_port = &hellcreek->ports[port]; + +dev_dbg (hellcreek->dev,"Remove traffic schedule on port %d\n" , port); + +/* First cancel timer */ +hrtimer_cancel (&hellcreek_port->cycle_start_timer); + +spin_lock_irqsave (&hellcreek->reg_lock, flags); + +if (hellcreek_port->current_schedule) { +kfree (hellcreek_port->current_schedule->entries); +kfree (hellcreek_port->current_schedule); + hellcreek_port->current_schedule =NULL ; + } + +/* Then select port */ +hellcreek_select_tgd (hellcreek, port); + +/* Revert tc mapping */ +__hellcreek_setup_tc_identity_mapping (hellcreek); + +/* Disable gating and return to regular switching flow */ +hellcreek_write (hellcreek,0xff <<TR_TGDCTRL_ADMINGATESTATES_SHIFT , +TR_TGDCTRL ); + +spin_unlock_irqrestore (&hellcreek->reg_lock, flags); + +return 0 ; +} + +static int hellcreek_port_setup_tc (struct dsa_switch *ds,int port, +enum tc_setup_type type,void *type_data) +{ +const struct tc_taprio_qopt_offload *taprio = type_data; + +if (type !=TC_SETUP_QDISC_TAPRIO ) +return -EOPNOTSUPP ; + +if (taprio->enable) +return hellcreek_port_set_schedule (ds, port, taprio); + +return hellcreek_port_del_schedule (ds, port); +} +static const struct dsa_switch_ops hellcreek_ds_ops = { .get_tag_protocol = hellcreek_get_tag_protocol, .setup = hellcreek_setup,
@@ -1104,6 +1394,7 @@ static const struct dsa_switch_ops hellcreek_ds_ops = { .port_hwtstamp_get = hellcreek_port_hwtstamp_get, .port_txtstamp = hellcreek_port_txtstamp, .port_rxtstamp = hellcreek_port_rxtstamp, + .port_setup_tc = hellcreek_port_setup_tc, .get_ts_info = hellcreek_get_ts_info, };
@@ -1135,6 +1426,9 @@ static int hellcreek_probe(struct platform_device *pdev)if (!port->counter_values)return -ENOMEM ; +hrtimer_init (&port->cycle_start_timer,CLOCK_TAI , +HRTIMER_MODE_ABS ); + port->cycle_start_timer.function = hellcreek_set_schedule; port->hellcreek = hellcreek; port->port = i; }
drivers/net/dsa/hirschmann/hellcreek.h +21 -0
@@ -16,6 +16,7 @@#include <linux/ptp_clock_kernel.h> #include <linux/timecounter.h> #include <linux/spinlock.h> +#include <linux/hrtimer.h> #include <net/dsa.h> /* Ports:
@@ -210,6 +211,20 @@ struct hellcreek_counter {const char *name; }; +struct hellcreek_gcl_entry { +u32 interval; +u8 gate_states; +bool overrun_ignore; +}; + +struct hellcreek_schedule { +struct hellcreek_gcl_entry *entries; +size_t num_entries; +ktime_t base_time; +u32 cycle_time; +int port; +}; +struct hellcreek ;/* State flags for hellcreek_port_hwtstamp::state */
@@ -236,6 +251,8 @@ struct hellcreek_port_hwtstamp {struct hellcreek_port {struct hellcreek *hellcreek; +struct hellcreek_schedule *current_schedule; +struct hrtimer cycle_start_timer;int port;u16 ptcfg;/* ptcfg shadow */ u64 *counter_values;
@@ -273,4 +290,8 @@ struct hellcreek { size_t fdb_entries; }; +#define hrtimer_to_hellcreek_port (timer) \ + container_of(timer, struct hellcreek_port, \ + cycle_start_timer) +#endif /* _HELLCREEK_H_ */
Signature · 1 line
2.20.1
Vladimir Oltean
maintainerRe: [PATCH v3 5/8] net: dsa: hellcreek: Add TAPRIO offloading support
Hi Kurt,
Quoted 64 lines · Kurt Kanzenbach
The switch has support for the 802.1Qbv Time Aware Shaper (TAS). Traffic schedules may be configured individually on each front port. Each port has eight egress queues. The traffic is mapped to a traffic class respectively via the PCP field of a VLAN tagged frame.
The TAPRIO Qdisc already implements that. Therefore, this interface can simply be reused. Add .port_setup_tc() accordingly.
The activation of a schedule on a port is split into two parts:
* Programming the necessary gate control list (GCL)
* Setup hrtimer for starting the scheduleThe hardware supports starting a schedule up to eight seconds in the future. The TAPRIO interface provides an absolute base time. Therefore, hrtimers are leveraged.
Signed-off-by Kurt Kanzenbach <[email protected]>--- drivers/net/dsa/hirschmann/hellcreek.c | 294 +++++++++++++++++++++++++ drivers/net/dsa/hirschmann/hellcreek.h | 21 ++ 2 files changed, 315 insertions(+)drivers/net/dsa/hirschmann/hellcreek.c +18
-0@@ -22,7 +22,9 @@#include <linux/spinlock.h> #include <linux/delay.h> #include <linux/ktime.h> +#include <linux/time.h> #include <net/dsa.h> +#include <net/pkt_sched.h> #include "hellcreek.h" #include "hellcreek_ptp.h" @@ -153,6 +155,15 @@ static void hellcreek_select_vlan(struct hellcreek *hellcreek, int vid,hellcreek_write (hellcreek, val,HR_VIDCFG ); } +static void hellcreek_select_tgd (struct hellcreek *hellcreek,int port) +{ +u16 val =0 ; + + val |= port <<TR_TGDSEL_TDGSEL_SHIFT ; + +hellcreek_write (hellcreek, val,TR_TGDSEL ); +} +static int hellcreek_wait_until_ready (struct hellcreek *hellcreek) {u16 val;@@ -958,6 +969,24 @@ static void __hellcreek_setup_tc_identity_mapping(struct hellcreek *hellcreek) } } +static void hellcreek_setup_tc_mapping (struct hellcreek *hellcreek, +struct net_device *netdev) +{ +int i, j; + +/* Setup mapping between traffic classes and port queues. */ +for (i =0 ; i <netdev_get_num_tc (netdev); ++i) {
drivers/net/dsa/hirschmann/hellcreek.c static void __hellcreek_setup_tc_identity_mapping(struct hellcreek *hellcreek) · line 988
Quoted 10 lines
drivers/net/dsa/hirschmann/hellcreek.c +10
-0+for (j =0 ; j < netdev->tc_to_txq[i].count; ++j) { +const int queue = j + netdev->tc_to_txq[i].offset; + +hellcreek_select_prio (hellcreek, i); +hellcreek_write (hellcreek, + queue <<HR_PRTCCFG_PCP_TC_MAP_SHIFT , +HR_PRTCCFG ); + } + } +}
What other driver have you seen that does this?
Quoted 58 lines
drivers/net/dsa/hirschmann/hellcreek.c +58
-0+ +static int hellcreek_port_set_schedule (struct dsa_switch *ds,int port, +const struct tc_taprio_qopt_offload *taprio) +{ +struct net_device *netdev =dsa_to_port (ds, port)->slave; +struct hellcreek *hellcreek = ds->priv; +struct hellcreek_port *hellcreek_port; +struct hellcreek_schedule *schedule; +unsigned long flags; +ktime_t start; +u16 ctrl; + + hellcreek_port = &hellcreek->ports[port]; + +/* Convert taprio data to hellcreek schedule */ + schedule =hellcreek_taprio_to_schedule (taprio); +if (IS_ERR (schedule)) +return PTR_ERR (schedule); + +dev_dbg (hellcreek->dev,"Configure traffic schedule on port %d\n" , + port); + +/* Cancel an in flight timer */ +hrtimer_cancel (&hellcreek_port->cycle_start_timer); + +spin_lock_irqsave (&hellcreek->reg_lock, flags); + +if (hellcreek_port->current_schedule) { +kfree (hellcreek_port->current_schedule->entries); +kfree (hellcreek_port->current_schedule); + } + + hellcreek_port->current_schedule = schedule; + +/* First select port */ +hellcreek_select_tgd (hellcreek, port); + +/* Setup traffic class <-> queue mapping */ +hellcreek_setup_tc_mapping (hellcreek, netdev); + +/* Enable gating and set the admin state to forward everything in the +* mean time +*/ + ctrl = (0xff <<TR_TGDCTRL_ADMINGATESTATES_SHIFT ) |TR_TGDCTRL_GATE_EN ; +hellcreek_write (hellcreek, ctrl,TR_TGDCTRL ); + +/* Cancel pending schedule */ +hellcreek_write (hellcreek,0x00 ,TR_ESTCMD ); + +/* Setup a new schedule */ +hellcreek_setup_gcl (hellcreek, port, schedule); + +/* Configure cycle time */ +hellcreek_set_cycle_time (hellcreek, schedule); + +/* Setup timer for schedule switch: The IP core only allows to set a +* cycle start timer 8 seconds in the future. This is why we setup the +* hritmer to base_time - 5 seconds. Then, we have enough time to
drivers/net/dsa/hirschmann/hellcreek.c static void hellcreek_phylink_validate(struct dsa_switch *ds, int port, · line 1322
Quoted 10 lines
drivers/net/dsa/hirschmann/hellcreek.c +10
-0+* activate IP core's EST timer. +*/ + start =ktime_sub_ns (schedule->base_time, (u64 )5 *NSEC_PER_SEC ); +hrtimer_start_range_ns (&hellcreek_port->cycle_start_timer, start, +NSEC_PER_SEC ,HRTIMER_MODE_ABS ); + +spin_unlock_irqrestore (&hellcreek->reg_lock, flags); + +return 0 ; +}
Thanks,
-Vladimir
Kurt Kanzenbach
maintainerRe: [PATCH v3 5/8] net: dsa: hellcreek: Add TAPRIO offloading support
Quoted 71 lines · Vladimir Oltean
Hi Kurt,
Quoted 68 lines · Kurt Kanzenbach
The switch has support for the 802.1Qbv Time Aware Shaper (TAS). Traffic schedules may be configured individually on each front port. Each port has eight egress queues. The traffic is mapped to a traffic class respectively via the PCP field of a VLAN tagged frame.
The TAPRIO Qdisc already implements that. Therefore, this interface can simply be reused. Add .port_setup_tc() accordingly.
The activation of a schedule on a port is split into two parts:
* Programming the necessary gate control list (GCL)
* Setup hrtimer for starting the scheduleThe hardware supports starting a schedule up to eight seconds in the future. The TAPRIO interface provides an absolute base time. Therefore, hrtimers are leveraged.
Signed-off-by Kurt Kanzenbach <[email protected]>--- drivers/net/dsa/hirschmann/hellcreek.c | 294 +++++++++++++++++++++++++ drivers/net/dsa/hirschmann/hellcreek.h | 21 ++ 2 files changed, 315 insertions(+)drivers/net/dsa/hirschmann/hellcreek.c +22
-0@@ -22,7 +22,9 @@#include <linux/spinlock.h> #include <linux/delay.h> #include <linux/ktime.h> +#include <linux/time.h> #include <net/dsa.h> +#include <net/pkt_sched.h> #include "hellcreek.h" #include "hellcreek_ptp.h" @@ -153,6 +155,15 @@ static void hellcreek_select_vlan(struct hellcreek *hellcreek, int vid,hellcreek_write (hellcreek, val,HR_VIDCFG ); } +static void hellcreek_select_tgd (struct hellcreek *hellcreek,int port) +{ +u16 val =0 ; + + val |= port <<TR_TGDSEL_TDGSEL_SHIFT ; + +hellcreek_write (hellcreek, val,TR_TGDSEL ); +} +static int hellcreek_wait_until_ready (struct hellcreek *hellcreek) {u16 val;@@ -958,6 +969,24 @@ static void __hellcreek_setup_tc_identity_mapping(struct hellcreek *hellcreek) } } +static void hellcreek_setup_tc_mapping (struct hellcreek *hellcreek, +struct net_device *netdev) +{ +int i, j; + +/* Setup mapping between traffic classes and port queues. */ +for (i =0 ; i <netdev_get_num_tc (netdev); ++i) { +for (j =0 ; j < netdev->tc_to_txq[i].count; ++j) { +const int queue = j + netdev->tc_to_txq[i].offset; + +hellcreek_select_prio (hellcreek, i);
Quoted 9 lines
drivers/net/dsa/hirschmann/hellcreek.c static void __hellcreek_setup_tc_identity_mapping(struct hellcreek *hellcreek) · line 988
Quoted 6 lines
drivers/net/dsa/hirschmann/hellcreek.c +6
-0+hellcreek_write (hellcreek, + queue <<HR_PRTCCFG_PCP_TC_MAP_SHIFT , +HR_PRTCCFG ); + } + } +}What other driver have you seen that does this?
Probably none.
With TAPRIO traffic classes and the mapping to queues can be configured. The switch can also map traffic classes. That sounded like a good match to me.
Thanks,
Kurt
Re: [PATCH v3 5/8] net: dsa: hellcreek: Add TAPRIO offloading support
Hi Kurt,
Quoted 21 lines · Kurt Kanzenbach
Quoted 11 lines
Quoted 11 lines
drivers/net/dsa/hirschmann/hellcreek.c +11
-0+static void hellcreek_setup_tc_mapping (struct hellcreek *hellcreek, +struct net_device *netdev) +{ +int i, j; + +/* Setup mapping between traffic classes and port queues. */ +for (i =0 ; i <netdev_get_num_tc (netdev); ++i) { +for (j =0 ; j < netdev->tc_to_txq[i].count; ++j) { +const int queue = j + netdev->tc_to_txq[i].offset; + +hellcreek_select_prio (hellcreek, i);Quoted 9 lines
drivers/net/dsa/hirschmann/hellcreek.c static void __hellcreek_setup_tc_identity_mapping(struct hellcreek *hellcreek) · line 988
Quoted 6 lines
drivers/net/dsa/hirschmann/hellcreek.c +6
-0+hellcreek_write (hellcreek, + queue <<HR_PRTCCFG_PCP_TC_MAP_SHIFT , +HR_PRTCCFG ); + } + } +}What other driver have you seen that does this?
Quoted 5 lines
Probably none.
With TAPRIO traffic classes and the mapping to queues can be configured. The switch can also map traffic classes. That sounded like a good match to me.
The only reason I could think that you would need this that *right now* taprio has pretty glaring oversight: that in the offload parameters each entry 'gate_mask' reference the "Traffic Class" (i.e. bit 0 is Traffic Class 0), and it really should be the HW queue.
I have a patch that does the conversion on taprio before talking to the driver. Do you think it would help you avoid doing this on the driver side?
Quoted 3 lines
Thanks,
Kurt
Cheers,
Signature · 1 line
Vinicius
Kurt Kanzenbach
maintainerRe: [PATCH v3 5/8] net: dsa: hellcreek: Add TAPRIO offloading support
Quoted 31 lines · Vinicius Costa Gomes
Hi Kurt,
Quoted 21 lines · Kurt Kanzenbach
Quoted 11 lines
Quoted 11 lines
drivers/net/dsa/hirschmann/hellcreek.c +11
-0+static void hellcreek_setup_tc_mapping (struct hellcreek *hellcreek, +struct net_device *netdev) +{ +int i, j; + +/* Setup mapping between traffic classes and port queues. */ +for (i =0 ; i <netdev_get_num_tc (netdev); ++i) { +for (j =0 ; j < netdev->tc_to_txq[i].count; ++j) { +const int queue = j + netdev->tc_to_txq[i].offset; + +hellcreek_select_prio (hellcreek, i);Quoted 9 lines
drivers/net/dsa/hirschmann/hellcreek.c static void __hellcreek_setup_tc_identity_mapping(struct hellcreek *hellcreek) · line 988
Quoted 6 lines
drivers/net/dsa/hirschmann/hellcreek.c +6
-0+hellcreek_write (hellcreek, + queue <<HR_PRTCCFG_PCP_TC_MAP_SHIFT , +HR_PRTCCFG ); + } + } +}What other driver have you seen that does this?
Quoted 5 lines
Probably none.
With TAPRIO traffic classes and the mapping to queues can be configured. The switch can also map traffic classes. That sounded like a good match to me.
Quoted 8 lines
The only reason I could think that you would need this that *right now* taprio has pretty glaring oversight: that in the offload parameters each entry '
gate_mask' reference the "Traffic Class" (i.e. bit 0 is Traffic Class 0), and it really should be the HW queue.I have a patch that does the conversion on taprio before talking to the driver. Do you think it would help you avoid doing this on the driver side?
I think so. As Vladimir pointed out, the driver should setup an identity mapping which I already did by default.
Can you point me your patch?
Thanks,
Kurt
Re: [PATCH v3 5/8] net: dsa: hellcreek: Add TAPRIO offloading support
Hi Kurt,
Quoted 4 lines · Kurt Kanzenbach
I think so. As Vladimir pointed out, the driver should setup an identity mapping which I already did by default.
Can you point me your patch?
Just sent it for consideration:
http://patchwork.ozlabs.org/project/netdev/patch/[email protected]/
Cheers,
Signature · 1 line
Vinicius
Kurt Kanzenbach
maintainerRe: [PATCH v3 5/8] net: dsa: hellcreek: Add TAPRIO offloading support
Hi Vinicius,
Quoted 4 lines · Vinicius Costa Gomes
Hi Kurt,
Kurt Kanzenbach <[email protected]> writes:
Quoted 8 lines
Quoted 4 lines
I think so. As Vladimir pointed out, the driver should setup an identity mapping which I already did by default.
Can you point me your patch?
Just sent it for consideration:
http://patchwork.ozlabs.org/project/netdev/patch/[email protected]/
Thank you. That looks good. So the driver just has to deal with queues and I can setup an identity mapping in the hellcreek code.
I see the patch is already merged, otherwise I'd have acked it.
Thanks,
Kurt
Vladimir Oltean
maintainerRe: [PATCH v3 5/8] net: dsa: hellcreek: Add TAPRIO offloading support
In reply to Vinicius Costa GomesHi Vinicius,
Quoted 11 lines · Vinicius Costa Gomes
Quoted 4 lines · Kurt Kanzenbach
With TAPRIO traffic classes and the mapping to queues can be configured. The switch can also map traffic classes. That sounded like a good match to me.
The only reason I could think that you would need this that *right now* taprio has pretty glaring oversight: that in the offload parameters each entry '
gate_mask' reference the "Traffic Class" (i.e. bit 0 is Traffic Class 0), and it really should be the HW queue.
Sorry, but could you please explain why having the gate_mask reference the traffic classes is a glaring oversight, and how changing it would help here?
Also, Kurt, could you please explain what the HR_PRTCCFG_PCP_TC_MAP_SHIFT field in HR_PRTCCFG is doing?
To me, it appears that it's configuring ingress QoS classification on the port (and the reason why this is strange to me is because you're applying this configuration through an egress qdisc), but I want to make sure I'm not misunderstanding.
Thanks,
-Vladimir
Kurt Kanzenbach
maintainerRe: [PATCH v3 5/8] net: dsa: hellcreek: Add TAPRIO offloading support
Quoted 19 lines · Vladimir Oltean
Hi Vinicius,
Quoted 11 lines · Vinicius Costa Gomes
Quoted 4 lines · Kurt Kanzenbach
With TAPRIO traffic classes and the mapping to queues can be configured. The switch can also map traffic classes. That sounded like a good match to me.
The only reason I could think that you would need this that *right now* taprio has pretty glaring oversight: that in the offload parameters each entry '
gate_mask' reference the "Traffic Class" (i.e. bit 0 is Traffic Class 0), and it really should be the HW queue.Sorry, but could you please explain why having the
gate_maskreference the traffic classes is a glaring oversight, and how changing it would help here?
Quoted 6 lines
Also, Kurt, could you please explain what the
HR_PRTCCFG_PCP_TC_MAP_SHIFTfield inHR_PRTCCFGis doing?
To me, it appears that it's configuring ingress QoS classification on the port (and the reason why this is strange to me is because you're applying this configuration through an egress qdisc), but I want to make sure I'm not misunderstanding.
All the TSN operations in the switch such as the gate control work on internally on traffic classes. The traffic class is determined by the PCP field on the VLAN tagged frames. This mapping is configurable via the pcp to tc map. And the TC also defines the hardware queue.
Thanks,
Kurt
Re: [PATCH v3 5/8] net: dsa: hellcreek: Add TAPRIO offloading support
In reply to Vladimir OlteanQuoted 15 lines · Vladimir Oltean
Hi Vinicius,
Quoted 11 lines · Vinicius Costa Gomes
Quoted 4 lines · Kurt Kanzenbach
With TAPRIO traffic classes and the mapping to queues can be configured. The switch can also map traffic classes. That sounded like a good match to me.
The only reason I could think that you would need this that *right now* taprio has pretty glaring oversight: that in the offload parameters each entry '
gate_mask' reference the "Traffic Class" (i.e. bit 0 is Traffic Class 0), and it really should be the HW queue.
Quoted 3 lines
Sorry, but could you please explain why having the
gate_maskreference the traffic classes is a glaring oversight, and how changing it would help here?
The glaring oversight is that it when it references the traffic classes, instead of queues, it basically ignores the 'queues *' mapping that the user provided. (it was ignored for so long because for many cases the mapping is 1:1)
On my reading of this part of the hellcreek code, all this was doing was assigning priorities (based on the traffic classes) to queues, and taprio is able to "hide" this from the driver, so all the driver needs to care about are queues.
Quoted 10 lines
Also, Kurt, could you please explain what the
HR_PRTCCFG_PCP_TC_MAP_SHIFTfield inHR_PRTCCFGis doing?
To me, it appears that it's configuring ingress QoS classification on the port (and the reason why this is strange to me is because you're applying this configuration through an egress qdisc), but I want to make sure I'm not misunderstanding.Thanks,
-Vladimir
Signature · 1 line
Vinicius
Vladimir Oltean
maintainerRe: [PATCH v3 5/8] net: dsa: hellcreek: Add TAPRIO offloading support
In reply to Kurt KanzenbachQuoted 148 lines · Kurt Kanzenbach
The switch has support for the 802.1Qbv Time Aware Shaper (TAS). Traffic schedules may be configured individually on each front port. Each port has eight egress queues. The traffic is mapped to a traffic class respectively via the PCP field of a VLAN tagged frame.
The TAPRIO Qdisc already implements that. Therefore, this interface can simply be reused. Add .port_setup_tc() accordingly.
The activation of a schedule on a port is split into two parts:
* Programming the necessary gate control list (GCL)
* Setup hrtimer for starting the scheduleThe hardware supports starting a schedule up to eight seconds in the future. The TAPRIO interface provides an absolute base time. Therefore, hrtimers are leveraged.
Signed-off-by Kurt Kanzenbach <[email protected]>--- drivers/net/dsa/hirschmann/hellcreek.c | 294 +++++++++++++++++++++++++ drivers/net/dsa/hirschmann/hellcreek.h | 21 ++ 2 files changed, 315 insertions(+)drivers/net/dsa/hirschmann/hellcreek.c +95
-0@@ -22,7 +22,9 @@#include <linux/spinlock.h> #include <linux/delay.h> #include <linux/ktime.h> +#include <linux/time.h> #include <net/dsa.h> +#include <net/pkt_sched.h> #include "hellcreek.h" #include "hellcreek_ptp.h" @@ -153,6 +155,15 @@ static void hellcreek_select_vlan(struct hellcreek *hellcreek, int vid,hellcreek_write (hellcreek, val,HR_VIDCFG ); } +static void hellcreek_select_tgd (struct hellcreek *hellcreek,int port) +{ +u16 val =0 ; + + val |= port <<TR_TGDSEL_TDGSEL_SHIFT ; + +hellcreek_write (hellcreek, val,TR_TGDSEL ); +} +static int hellcreek_wait_until_ready (struct hellcreek *hellcreek) {u16 val;@@ -958,6 +969,24 @@ static void __hellcreek_setup_tc_identity_mapping(struct hellcreek *hellcreek) } } +static void hellcreek_setup_tc_mapping (struct hellcreek *hellcreek, +struct net_device *netdev) +{ +int i, j; + +/* Setup mapping between traffic classes and port queues. */ +for (i =0 ; i <netdev_get_num_tc (netdev); ++i) { +for (j =0 ; j < netdev->tc_to_txq[i].count; ++j) { +const int queue = j + netdev->tc_to_txq[i].offset; + +hellcreek_select_prio (hellcreek, i); +hellcreek_write (hellcreek, + queue <<HR_PRTCCFG_PCP_TC_MAP_SHIFT , +HR_PRTCCFG ); + } + } +} +static void hellcreek_setup_tc_identity_mapping (struct hellcreek *hellcreek) {unsigned long flags;@@ -1081,6 +1110,267 @@ static void hellcreek_phylink_validate(struct dsa_switch *ds, int port, __ETHTOOL_LINK_MODE_MASK_NBITS); } +static void hellcreek_setup_gcl (struct hellcreek *hellcreek,int port, +const struct hellcreek_schedule *schedule) +{ +size_t i; + +for (i =1 ; i <= schedule->num_entries; ++i) { +const struct hellcreek_gcl_entry *cur, *initial, *next; +u16 data; +u8 gates; + + cur = &schedule->entries[i -1 ]; + initial = &schedule->entries[0 ]; + next = &schedule->entries[i]; + +if (i == schedule->num_entries) + gates = initial->gate_states ^ + cur->gate_states; +else + gates = next->gate_states ^ + cur->gate_states; + + data = gates; +if (cur->overrun_ignore) + data |=TR_GCLDAT_GCLOVRI ; + +if (i == schedule->num_entries) + data |=TR_GCLDAT_GCLWRLAST ; + +/* Gates states */ +hellcreek_write (hellcreek, data,TR_GCLDAT ); + +/* Time intervall */ +hellcreek_write (hellcreek, + cur->interval &0x0000ffff , +TR_GCLTIL ); +hellcreek_write (hellcreek, + (cur->interval &0xffff0000 ) >>16 , +TR_GCLTIH ); + +/* Commit entry */ + data = ((i -1 ) <<TR_GCLCMD_GCLWRADR_SHIFT ) | + (initial->gate_states << +TR_GCLCMD_INIT_GATE_STATES_SHIFT ); +hellcreek_write (hellcreek, data,TR_GCLCMD ); + } +} + +static void hellcreek_set_cycle_time (struct hellcreek *hellcreek, +const struct hellcreek_schedule *schedule) +{ +u32 cycle_time = schedule->cycle_time; + +hellcreek_write (hellcreek, cycle_time &0x0000ffff ,TR_CTWRL ); +hellcreek_write (hellcreek, (cycle_time &0xffff0000 ) >>16 ,TR_CTWRH ); +} + +static void hellcreek_start_schedule (struct hellcreek *hellcreek, +ktime_t start_time) +{ +struct timespec64 ts =ktime_to_timespec64 (start_time); + +/* Start can be only 8 seconds in the future */ + ts.tv_sec %=8 ; + +/* Start schedule at this point of time */ +hellcreek_write (hellcreek, ts.tv_nsec &0x0000ffff ,TR_ESTWRL );
drivers/net/dsa/hirschmann/hellcreek.c static void hellcreek_phylink_validate(struct dsa_switch *ds, int port, · line 1188
Quoted 10 lines
drivers/net/dsa/hirschmann/hellcreek.c +10
-0+hellcreek_write (hellcreek, (ts.tv_nsec &0xffff0000 ) >>16 ,TR_ESTWRH ); + +/* Arm timer, set seconds and switch schedule */ +hellcreek_write (hellcreek,TR_ESTCMD_ESTARM |TR_ESTCMD_ESTSWCFG | + ((ts.tv_sec &TR_ESTCMD_ESTSEC_MASK ) << +TR_ESTCMD_ESTSEC_SHIFT ),TR_ESTCMD ); +} + +static struct hellcreek_schedule *hellcreek_taprio_to_schedule ( +const struct tc_taprio_qopt_offload *taprio)
Personal indentation preference:
static struct hellcreek_schedule *hellcreek_taprio_to_schedule(const struct tc_taprio_qopt_offload *taprio)
Quoted 17 lines
drivers/net/dsa/hirschmann/hellcreek.c +17
-0+{ +struct hellcreek_schedule *schedule; +size_t i; + +/* Allocate some memory first */ + schedule =kzalloc (sizeof (*schedule),GFP_KERNEL ); +if (!schedule) +return ERR_PTR (-ENOMEM ); + schedule->entries =kcalloc (taprio->num_entries, +sizeof (*schedule->entries), +GFP_KERNEL ); +if (!schedule->entries) { +kfree (schedule); +return ERR_PTR (-ENOMEM ); + } + +/* Construct hellcreek schedule */
drivers/net/dsa/hirschmann/hellcreek.c static void hellcreek_phylink_validate(struct dsa_switch *ds, int port, · line 1215
Quoted 10 lines
drivers/net/dsa/hirschmann/hellcreek.c +10
-0+ schedule->num_entries = taprio->num_entries; + schedule->base_time = taprio->base_time; + +for (i =0 ; i < taprio->num_entries; ++i) { +const struct tc_taprio_sched_entry *t = &taprio->entries[i]; +struct hellcreek_gcl_entry *k = &schedule->entries[i]; + + k->interval = t->interval; + k->gate_states = t->gate_mask; + k->overrun_ignore =0 ;
Tab to align with gate_states and interval?
What does overrun_ignore do, anyway?
drivers/net/dsa/hirschmann/hellcreek.c static void hellcreek_phylink_validate(struct dsa_switch *ds, int port, · line 1227
Quoted 12 lines
drivers/net/dsa/hirschmann/hellcreek.c +12
-0+ +/* Update complete cycle time */ + schedule->cycle_time += t->interval; + } + +return schedule; +} + +static enum hrtimer_restart hellcreek_set_schedule (struct hrtimer *timer) +{ +struct hellcreek_port *hellcreek_port = +hrtimer_to_hellcreek_port (timer);
That moment when not even the helper macro fits in 80 characters.. I think you should let this line have 81 characters.
Quoted 80 lines
drivers/net/dsa/hirschmann/hellcreek.c +80
-0+struct hellcreek *hellcreek = hellcreek_port->hellcreek; +struct hellcreek_schedule *schedule; +unsigned long flags; + +spin_lock_irqsave (&hellcreek->reg_lock, flags); + +/* First select port */ +hellcreek_select_tgd (hellcreek, hellcreek_port->port); + +/* Set admin base time and switch schedule */ +hellcreek_start_schedule (hellcreek, + hellcreek_port->current_schedule->base_time); + + schedule = hellcreek_port->current_schedule; + hellcreek_port->current_schedule =NULL ; + +spin_unlock_irqrestore (&hellcreek->reg_lock, flags); + +dev_dbg (hellcreek->dev,"ARMed EST timer for port %d\n" , + hellcreek_port->port); + +/* Free resources */ +kfree (schedule->entries); +kfree (schedule); + +return HRTIMER_NORESTART ; +} + +static int hellcreek_port_set_schedule (struct dsa_switch *ds,int port, +const struct tc_taprio_qopt_offload *taprio) +{ +struct net_device *netdev =dsa_to_port (ds, port)->slave; +struct hellcreek *hellcreek = ds->priv; +struct hellcreek_port *hellcreek_port; +struct hellcreek_schedule *schedule; +unsigned long flags; +ktime_t start; +u16 ctrl; + + hellcreek_port = &hellcreek->ports[port]; + +/* Convert taprio data to hellcreek schedule */ + schedule =hellcreek_taprio_to_schedule (taprio); +if (IS_ERR (schedule)) +return PTR_ERR (schedule); + +dev_dbg (hellcreek->dev,"Configure traffic schedule on port %d\n" , + port); + +/* Cancel an in flight timer */ +hrtimer_cancel (&hellcreek_port->cycle_start_timer); + +spin_lock_irqsave (&hellcreek->reg_lock, flags); + +if (hellcreek_port->current_schedule) { +kfree (hellcreek_port->current_schedule->entries); +kfree (hellcreek_port->current_schedule); + } + + hellcreek_port->current_schedule = schedule; + +/* First select port */ +hellcreek_select_tgd (hellcreek, port); + +/* Setup traffic class <-> queue mapping */ +hellcreek_setup_tc_mapping (hellcreek, netdev); + +/* Enable gating and set the admin state to forward everything in the +* mean time +*/ + ctrl = (0xff <<TR_TGDCTRL_ADMINGATESTATES_SHIFT ) |TR_TGDCTRL_GATE_EN ; +hellcreek_write (hellcreek, ctrl,TR_TGDCTRL ); + +/* Cancel pending schedule */ +hellcreek_write (hellcreek,0x00 ,TR_ESTCMD ); + +/* Setup a new schedule */ +hellcreek_setup_gcl (hellcreek, port, schedule); + +/* Configure cycle time */
drivers/net/dsa/hirschmann/hellcreek.c static void hellcreek_phylink_validate(struct dsa_switch *ds, int port, · line 1317
Quoted 10 lines
drivers/net/dsa/hirschmann/hellcreek.c +10
-0+hellcreek_set_cycle_time (hellcreek, schedule); + +/* Setup timer for schedule switch: The IP core only allows to set a +* cycle start timer 8 seconds in the future. This is why we setup the +* hritmer to base_time - 5 seconds. Then, we have enough time to +* activate IP core's EST timer. +*/ + start =ktime_sub_ns (schedule->base_time, (u64 )5 *NSEC_PER_SEC ); +hrtimer_start_range_ns (&hellcreek_port->cycle_start_timer, start, +NSEC_PER_SEC ,HRTIMER_MODE_ABS );
Explain again how this works, please? The hrtimer measures the CLOCK_TAI of the CPU, but you are offloading the CLOCK_TAI domain of the NIC? So you are assuming that the CPU and the NIC PHC are synchronized? What if they aren't?
And what if the base-time is in the past, do you deal with that (how does the hardware deal with a base-time in the past)?
A base-time in the past (example: 0) should work: you should advance the base-time into the nearest future multiple of the cycle-time, to at least preserve phase correctness of the schedule.
Just trying to understand if this whole hrtimer thing is worth it. It complicates the driver by quite a significant amount.
Quoted 131 lines
drivers/net/dsa/hirschmann/hellcreek.c +60
-0+ +spin_unlock_irqrestore (&hellcreek->reg_lock, flags); + +return 0 ; +} + +static int hellcreek_port_del_schedule (struct dsa_switch *ds,int port) +{ +struct hellcreek *hellcreek = ds->priv; +struct hellcreek_port *hellcreek_port; +unsigned long flags; + + hellcreek_port = &hellcreek->ports[port]; + +dev_dbg (hellcreek->dev,"Remove traffic schedule on port %d\n" , port); + +/* First cancel timer */ +hrtimer_cancel (&hellcreek_port->cycle_start_timer); + +spin_lock_irqsave (&hellcreek->reg_lock, flags); + +if (hellcreek_port->current_schedule) { +kfree (hellcreek_port->current_schedule->entries); +kfree (hellcreek_port->current_schedule); + hellcreek_port->current_schedule =NULL ; + } + +/* Then select port */ +hellcreek_select_tgd (hellcreek, port); + +/* Revert tc mapping */ +__hellcreek_setup_tc_identity_mapping (hellcreek); + +/* Disable gating and return to regular switching flow */ +hellcreek_write (hellcreek,0xff <<TR_TGDCTRL_ADMINGATESTATES_SHIFT , +TR_TGDCTRL ); + +spin_unlock_irqrestore (&hellcreek->reg_lock, flags); + +return 0 ; +} + +static int hellcreek_port_setup_tc (struct dsa_switch *ds,int port, +enum tc_setup_type type,void *type_data) +{ +const struct tc_taprio_qopt_offload *taprio = type_data; + +if (type !=TC_SETUP_QDISC_TAPRIO ) +return -EOPNOTSUPP ; + +if (taprio->enable) +return hellcreek_port_set_schedule (ds, port, taprio); + +return hellcreek_port_del_schedule (ds, port); +} +static const struct dsa_switch_ops hellcreek_ds_ops = { .get_tag_protocol = hellcreek_get_tag_protocol, .setup = hellcreek_setup,@@ -1104,6 +1394,7 @@ static const struct dsa_switch_ops hellcreek_ds_ops = { .port_hwtstamp_get = hellcreek_port_hwtstamp_get, .port_txtstamp = hellcreek_port_txtstamp, .port_rxtstamp = hellcreek_port_rxtstamp, + .port_setup_tc = hellcreek_port_setup_tc, .get_ts_info = hellcreek_get_ts_info, };@@ -1135,6 +1426,9 @@ static int hellcreek_probe(struct platform_device *pdev)if (!port->counter_values)return -ENOMEM ; +hrtimer_init (&port->cycle_start_timer,CLOCK_TAI , +HRTIMER_MODE_ABS ); + port->cycle_start_timer.function = hellcreek_set_schedule; port->hellcreek = hellcreek; port->port = i; }drivers/net/dsa/hirschmann/hellcreek.h +21
-0@@ -16,6 +16,7 @@#include <linux/ptp_clock_kernel.h> #include <linux/timecounter.h> #include <linux/spinlock.h> +#include <linux/hrtimer.h> #include <net/dsa.h> /* Ports: @@ -210,6 +211,20 @@ struct hellcreek_counter {const char *name; }; +struct hellcreek_gcl_entry { +u32 interval; +u8 gate_states; +bool overrun_ignore; +}; + +struct hellcreek_schedule { +struct hellcreek_gcl_entry *entries; +size_t num_entries; +ktime_t base_time; +u32 cycle_time; +int port; +}; +struct hellcreek ;/* State flags for hellcreek_port_hwtstamp::state */ @@ -236,6 +251,8 @@ struct hellcreek_port_hwtstamp {struct hellcreek_port {struct hellcreek *hellcreek; +struct hellcreek_schedule *current_schedule; +struct hrtimer cycle_start_timer;int port;u16 ptcfg;/* ptcfg shadow */ u64 *counter_values;@@ -273,4 +290,8 @@ struct hellcreek { size_t fdb_entries; }; +#define hrtimer_to_hellcreek_port (timer) \ + container_of(timer, struct hellcreek_port, \ + cycle_start_timer) +#endif /* _HELLCREEK_H_ */ Signature · 1 line
2.20.1
Thanks,
-Vladimir
Kurt Kanzenbach
maintainerRe: [PATCH v3 5/8] net: dsa: hellcreek: Add TAPRIO offloading support
Quoted 1 line · Vladimir Oltean
On Thu, Aug 20, 2020 at 10:11:15AM +0200, Kurt Kanzenbach wrote:
[snip]
Quoted 7 lines
drivers/net/dsa/hirschmann/hellcreek.c static void hellcreek_phylink_validate(struct dsa_switch *ds, int port, · line 1188
Quoted 2 lines
drivers/net/dsa/hirschmann/hellcreek.c +2
-0+static struct hellcreek_schedule *hellcreek_taprio_to_schedule ( +const struct tc_taprio_qopt_offload *taprio)Personal indentation preference:
static struct
hellcreek_schedule*hellcreek_taprio_to_schedule(const structtc_taprio_qopt_offload*taprio)
Sure.
Quoted 22 lines
Quoted 22 lines
drivers/net/dsa/hirschmann/hellcreek.c +21
-0+{ +struct hellcreek_schedule *schedule; +size_t i; + +/* Allocate some memory first */ + schedule =kzalloc (sizeof (*schedule),GFP_KERNEL ); +if (!schedule) +return ERR_PTR (-ENOMEM ); + schedule->entries =kcalloc (taprio->num_entries, +sizeof (*schedule->entries), +GFP_KERNEL ); +if (!schedule->entries) { +kfree (schedule); +return ERR_PTR (-ENOMEM ); + } + +/* Construct hellcreek schedule */ + schedule->num_entries = taprio->num_entries; + schedule->base_time = taprio->base_time; + +for (i =0 ; i < taprio->num_entries; ++i) {
Quoted 8 lines
drivers/net/dsa/hirschmann/hellcreek.c static void hellcreek_phylink_validate(struct dsa_switch *ds, int port, · line 1215
Quoted 6 lines
drivers/net/dsa/hirschmann/hellcreek.c +6
-0+const struct tc_taprio_sched_entry *t = &taprio->entries[i]; +struct hellcreek_gcl_entry *k = &schedule->entries[i]; + + k->interval = t->interval; + k->gate_states = t->gate_mask; + k->overrun_ignore =0 ;Tab to align with
gate_statesand interval?
Hm. I've used M x align. It should take care of it.
Quoted 1 line
What does
overrun_ignoredo, anyway?
I don't remember. The HW engineer suggested to set it to zero.
Quoted 16 lines
drivers/net/dsa/hirschmann/hellcreek.c static void hellcreek_phylink_validate(struct dsa_switch *ds, int port, · line 1227
Quoted 13 lines
drivers/net/dsa/hirschmann/hellcreek.c +12
-0+ +/* Update complete cycle time */ + schedule->cycle_time += t->interval; + } + +return schedule; +} + +static enum hrtimer_restart hellcreek_set_schedule (struct hrtimer *timer) +{ +struct hellcreek_port *hellcreek_port = +hrtimer_to_hellcreek_port (timer);That moment when not even the helper macro fits in 80 characters.. I think you should let this line have 81 characters.
OK.
Quoted 88 lines
Quoted 88 lines
drivers/net/dsa/hirschmann/hellcreek.c +87
-0+struct hellcreek *hellcreek = hellcreek_port->hellcreek; +struct hellcreek_schedule *schedule; +unsigned long flags; + +spin_lock_irqsave (&hellcreek->reg_lock, flags); + +/* First select port */ +hellcreek_select_tgd (hellcreek, hellcreek_port->port); + +/* Set admin base time and switch schedule */ +hellcreek_start_schedule (hellcreek, + hellcreek_port->current_schedule->base_time); + + schedule = hellcreek_port->current_schedule; + hellcreek_port->current_schedule =NULL ; + +spin_unlock_irqrestore (&hellcreek->reg_lock, flags); + +dev_dbg (hellcreek->dev,"ARMed EST timer for port %d\n" , + hellcreek_port->port); + +/* Free resources */ +kfree (schedule->entries); +kfree (schedule); + +return HRTIMER_NORESTART ; +} + +static int hellcreek_port_set_schedule (struct dsa_switch *ds,int port, +const struct tc_taprio_qopt_offload *taprio) +{ +struct net_device *netdev =dsa_to_port (ds, port)->slave; +struct hellcreek *hellcreek = ds->priv; +struct hellcreek_port *hellcreek_port; +struct hellcreek_schedule *schedule; +unsigned long flags; +ktime_t start; +u16 ctrl; + + hellcreek_port = &hellcreek->ports[port]; + +/* Convert taprio data to hellcreek schedule */ + schedule =hellcreek_taprio_to_schedule (taprio); +if (IS_ERR (schedule)) +return PTR_ERR (schedule); + +dev_dbg (hellcreek->dev,"Configure traffic schedule on port %d\n" , + port); + +/* Cancel an in flight timer */ +hrtimer_cancel (&hellcreek_port->cycle_start_timer); + +spin_lock_irqsave (&hellcreek->reg_lock, flags); + +if (hellcreek_port->current_schedule) { +kfree (hellcreek_port->current_schedule->entries); +kfree (hellcreek_port->current_schedule); + } + + hellcreek_port->current_schedule = schedule; + +/* First select port */ +hellcreek_select_tgd (hellcreek, port); + +/* Setup traffic class <-> queue mapping */ +hellcreek_setup_tc_mapping (hellcreek, netdev); + +/* Enable gating and set the admin state to forward everything in the +* mean time +*/ + ctrl = (0xff <<TR_TGDCTRL_ADMINGATESTATES_SHIFT ) |TR_TGDCTRL_GATE_EN ; +hellcreek_write (hellcreek, ctrl,TR_TGDCTRL ); + +/* Cancel pending schedule */ +hellcreek_write (hellcreek,0x00 ,TR_ESTCMD ); + +/* Setup a new schedule */ +hellcreek_setup_gcl (hellcreek, port, schedule); + +/* Configure cycle time */ +hellcreek_set_cycle_time (hellcreek, schedule); + +/* Setup timer for schedule switch: The IP core only allows to set a +* cycle start timer 8 seconds in the future. This is why we setup the +* hritmer to base_time - 5 seconds. Then, we have enough time to +* activate IP core's EST timer. +*/
Quoted 8 lines
drivers/net/dsa/hirschmann/hellcreek.c static void hellcreek_phylink_validate(struct dsa_switch *ds, int port, · line 1317
Quoted 3 lines
drivers/net/dsa/hirschmann/hellcreek.c +3
-0+ start =ktime_sub_ns (schedule->base_time, (u64 )5 *NSEC_PER_SEC ); +hrtimer_start_range_ns (&hellcreek_port->cycle_start_timer, start, +NSEC_PER_SEC ,HRTIMER_MODE_ABS );Explain again how this works, please? The hrtimer measures the
CLOCK_TAIof the CPU, but you are offloading theCLOCK_TAIdomain of the NIC? So you are assuming that the CPU and the NIC PHC are synchronized? What if they aren't?
Yes, I assume that's synchronized with e.g. phc2sys.
Quoted 6 lines
And what if the base-time is in the past, do you deal with that (how does the hardware deal with a base-time in the past)?
A base-time in the past (example: 0) should work: you should advance the base-time into the nearest future multiple of the cycle-time, to at least preserve phase correctness of the schedule.
If the hrtimer is programmed with a value in the past, it fires instantly. The callback is executed and the start time is programmed.
Quoted 3 lines
Just trying to understand if this whole hrtimer thing is worth it. It complicates the driver by quite a significant amount.
See my other reply mail, why I used hrtimers.
Thanks,
Kurt
Vladimir Oltean
maintainerRe: [PATCH v3 5/8] net: dsa: hellcreek: Add TAPRIO offloading support
Quoted 10 lines · Kurt Kanzenbach
Quoted 6 lines · Vladimir Oltean
On Thu, Aug 20, 2020 at 10:11:15AM +0200, Kurt Kanzenbach wrote:
Explain again how this works, please? The hrtimer measures the
CLOCK_TAIof the CPU, but you are offloading theCLOCK_TAIdomain of the NIC? So you are assuming that the CPU and the NIC PHC are synchronized? What if they aren't?Yes, I assume that's synchronized with e.g. phc2sys.
My intuition tells me that this isn't the user's expectation, and that it should do the right thing even if it's not synchronized to the system clock.
Quoted 9 lines
Quoted 6 lines
And what if the base-time is in the past, do you deal with that (how does the hardware deal with a base-time in the past)?
A base-time in the past (example: 0) should work: you should advance the base-time into the nearest future multiple of the cycle-time, to at least preserve phase correctness of the schedule.If the hrtimer is programmed with a value in the past, it fires instantly.
Yes, it does.
Quoted 2 lines
The callback is executed and the start time is programmed.
With a valid value from the hardware's perspective?
Thanks,
-Vladimir
Kurt Kanzenbach
maintainerRe: [PATCH v3 5/8] net: dsa: hellcreek: Add TAPRIO offloading support
Quoted 9 lines · Vladimir Oltean
Quoted 8 lines · Kurt Kanzenbach
Quoted 6 lines · Vladimir Oltean
On Thu, Aug 20, 2020 at 10:11:15AM +0200, Kurt Kanzenbach wrote:
Explain again how this works, please? The hrtimer measures the
CLOCK_TAIof the CPU, but you are offloading theCLOCK_TAIdomain of the NIC? So you are assuming that the CPU and the NIC PHC are synchronized? What if they aren't?
Quoted 6 lines
Quoted 2 lines
Yes, I assume that's synchronized with e.g. phc2sys.
My intuition tells me that this isn't the user's expectation, and that it should do the right thing even if it's not synchronized to the system clock.
I get your point. But how to do it? We would need a timer based on the PTP clock in the switch.
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines
And what if the base-time is in the past, do you deal with that (how does the hardware deal with a base-time in the past)?
A base-time in the past (example: 0) should work: you should advance the base-time into the nearest future multiple of the cycle-time, to at least preserve phase correctness of the schedule.If the hrtimer is programmed with a value in the past, it fires instantly.
Quoted 6 lines
Yes, it does.
Quoted 2 lines
The callback is executed and the start time is programmed.
With a valid value from the hardware's perspective?
Yes. That's no problem.
Thanks,
Kurt
Re: [PATCH v3 5/8] net: dsa: hellcreek: Add TAPRIO offloading support
Quoted 3 lines · Kurt Kanzenbach
I get your point. But how to do it? We would need a timer based on the PTP clock in the switch.
Can't you use an hrtimer based on CLOCK_MONOTONIC?
I would expect the driver to work based solely on the device's clock.
Thanks,
Richard
Kurt Kanzenbach
maintainerRe: [PATCH v3 5/8] net: dsa: hellcreek: Add TAPRIO offloading support
Hi Richard,
Quoted 6 lines · Richard Cochran
Quoted 3 lines · Kurt Kanzenbach
I get your point. But how to do it? We would need a timer based on the PTP clock in the switch.
Can't you use an hrtimer based on
CLOCK_MONOTONIC?
When the switch and the Linux machine aren't synchronized, we would calculate the difference between both systems and could arm the Linux timer based on CLOCK_MONOTONIC. Given the fact that we eight seconds, it would *probably* work when the ptp offset adjustments are in that range.
Quoted 2 lines
I would expect the driver to work based solely on the device's clock.
Understood.
Thanks,
Kurt
Re: [PATCH v3 5/8] net: dsa: hellcreek: Add TAPRIO offloading support
In reply to Kurt KanzenbachHi,
Quoted 8 lines · Kurt Kanzenbach
The switch has support for the 802.1Qbv Time Aware Shaper (TAS). Traffic schedules may be configured individually on each front port. Each port has eight egress queues. The traffic is mapped to a traffic class respectively via the PCP field of a VLAN tagged frame.
The TAPRIO Qdisc already implements that. Therefore, this interface can simply be reused. Add .port_setup_tc() accordingly.
Quoted 8 lines
The activation of a schedule on a port is split into two parts:
* Programming the necessary gate control list (GCL)
* Setup hrtimer for starting the scheduleThe hardware supports starting a schedule up to eight seconds in the future. The TAPRIO interface provides an absolute base time. Therefore, hrtimers are leveraged.
The driver side looks good, looks like a well behaved piece of hardware, even not supporting schedules with a base time 8 seconds (or later) in the future is not so bad.
Quoted 261 lines
Signed-off-by Kurt Kanzenbach <[email protected]>--- drivers/net/dsa/hirschmann/hellcreek.c | 294 +++++++++++++++++++++++++ drivers/net/dsa/hirschmann/hellcreek.h | 21 ++ 2 files changed, 315 insertions(+)drivers/net/dsa/hirschmann/hellcreek.c +224
-0@@ -22,7 +22,9 @@#include <linux/spinlock.h> #include <linux/delay.h> #include <linux/ktime.h> +#include <linux/time.h> #include <net/dsa.h> +#include <net/pkt_sched.h> #include "hellcreek.h" #include "hellcreek_ptp.h" @@ -153,6 +155,15 @@ static void hellcreek_select_vlan(struct hellcreek *hellcreek, int vid,hellcreek_write (hellcreek, val,HR_VIDCFG ); } +static void hellcreek_select_tgd (struct hellcreek *hellcreek,int port) +{ +u16 val =0 ; + + val |= port <<TR_TGDSEL_TDGSEL_SHIFT ; + +hellcreek_write (hellcreek, val,TR_TGDSEL ); +} +static int hellcreek_wait_until_ready (struct hellcreek *hellcreek) {u16 val;@@ -958,6 +969,24 @@ static void __hellcreek_setup_tc_identity_mapping(struct hellcreek *hellcreek) } } +static void hellcreek_setup_tc_mapping (struct hellcreek *hellcreek, +struct net_device *netdev) +{ +int i, j; + +/* Setup mapping between traffic classes and port queues. */ +for (i =0 ; i <netdev_get_num_tc (netdev); ++i) { +for (j =0 ; j < netdev->tc_to_txq[i].count; ++j) { +const int queue = j + netdev->tc_to_txq[i].offset; + +hellcreek_select_prio (hellcreek, i); +hellcreek_write (hellcreek, + queue <<HR_PRTCCFG_PCP_TC_MAP_SHIFT , +HR_PRTCCFG ); + } + } +} +static void hellcreek_setup_tc_identity_mapping (struct hellcreek *hellcreek) {unsigned long flags;@@ -1081,6 +1110,267 @@ static void hellcreek_phylink_validate(struct dsa_switch *ds, int port, __ETHTOOL_LINK_MODE_MASK_NBITS); } +static void hellcreek_setup_gcl (struct hellcreek *hellcreek,int port, +const struct hellcreek_schedule *schedule) +{ +size_t i; + +for (i =1 ; i <= schedule->num_entries; ++i) { +const struct hellcreek_gcl_entry *cur, *initial, *next; +u16 data; +u8 gates; + + cur = &schedule->entries[i -1 ]; + initial = &schedule->entries[0 ]; + next = &schedule->entries[i]; + +if (i == schedule->num_entries) + gates = initial->gate_states ^ + cur->gate_states; +else + gates = next->gate_states ^ + cur->gate_states; + + data = gates; +if (cur->overrun_ignore) + data |=TR_GCLDAT_GCLOVRI ; + +if (i == schedule->num_entries) + data |=TR_GCLDAT_GCLWRLAST ; + +/* Gates states */ +hellcreek_write (hellcreek, data,TR_GCLDAT ); + +/* Time intervall */ +hellcreek_write (hellcreek, + cur->interval &0x0000ffff , +TR_GCLTIL ); +hellcreek_write (hellcreek, + (cur->interval &0xffff0000 ) >>16 , +TR_GCLTIH ); + +/* Commit entry */ + data = ((i -1 ) <<TR_GCLCMD_GCLWRADR_SHIFT ) | + (initial->gate_states << +TR_GCLCMD_INIT_GATE_STATES_SHIFT ); +hellcreek_write (hellcreek, data,TR_GCLCMD ); + } +} + +static void hellcreek_set_cycle_time (struct hellcreek *hellcreek, +const struct hellcreek_schedule *schedule) +{ +u32 cycle_time = schedule->cycle_time; + +hellcreek_write (hellcreek, cycle_time &0x0000ffff ,TR_CTWRL ); +hellcreek_write (hellcreek, (cycle_time &0xffff0000 ) >>16 ,TR_CTWRH ); +} + +static void hellcreek_start_schedule (struct hellcreek *hellcreek, +ktime_t start_time) +{ +struct timespec64 ts =ktime_to_timespec64 (start_time); + +/* Start can be only 8 seconds in the future */ + ts.tv_sec %=8 ; + +/* Start schedule at this point of time */ +hellcreek_write (hellcreek, ts.tv_nsec &0x0000ffff ,TR_ESTWRL ); +hellcreek_write (hellcreek, (ts.tv_nsec &0xffff0000 ) >>16 ,TR_ESTWRH ); + +/* Arm timer, set seconds and switch schedule */ +hellcreek_write (hellcreek,TR_ESTCMD_ESTARM |TR_ESTCMD_ESTSWCFG | + ((ts.tv_sec &TR_ESTCMD_ESTSEC_MASK ) << +TR_ESTCMD_ESTSEC_SHIFT ),TR_ESTCMD ); +} + +static struct hellcreek_schedule *hellcreek_taprio_to_schedule ( +const struct tc_taprio_qopt_offload *taprio) +{ +struct hellcreek_schedule *schedule; +size_t i; + +/* Allocate some memory first */ + schedule =kzalloc (sizeof (*schedule),GFP_KERNEL ); +if (!schedule) +return ERR_PTR (-ENOMEM ); + schedule->entries =kcalloc (taprio->num_entries, +sizeof (*schedule->entries), +GFP_KERNEL ); +if (!schedule->entries) { +kfree (schedule); +return ERR_PTR (-ENOMEM ); + } + +/* Construct hellcreek schedule */ + schedule->num_entries = taprio->num_entries; + schedule->base_time = taprio->base_time; + +for (i =0 ; i < taprio->num_entries; ++i) { +const struct tc_taprio_sched_entry *t = &taprio->entries[i]; +struct hellcreek_gcl_entry *k = &schedule->entries[i]; + + k->interval = t->interval; + k->gate_states = t->gate_mask; + k->overrun_ignore =0 ; + +/* Update complete cycle time */ + schedule->cycle_time += t->interval; + } + +return schedule; +} + +static enum hrtimer_restart hellcreek_set_schedule (struct hrtimer *timer) +{ +struct hellcreek_port *hellcreek_port = +hrtimer_to_hellcreek_port (timer); +struct hellcreek *hellcreek = hellcreek_port->hellcreek; +struct hellcreek_schedule *schedule; +unsigned long flags; + +spin_lock_irqsave (&hellcreek->reg_lock, flags); + +/* First select port */ +hellcreek_select_tgd (hellcreek, hellcreek_port->port); + +/* Set admin base time and switch schedule */ +hellcreek_start_schedule (hellcreek, + hellcreek_port->current_schedule->base_time); + + schedule = hellcreek_port->current_schedule; + hellcreek_port->current_schedule =NULL ; + +spin_unlock_irqrestore (&hellcreek->reg_lock, flags); + +dev_dbg (hellcreek->dev,"ARMed EST timer for port %d\n" , + hellcreek_port->port); + +/* Free resources */ +kfree (schedule->entries); +kfree (schedule); + +return HRTIMER_NORESTART ; +} + +static int hellcreek_port_set_schedule (struct dsa_switch *ds,int port, +const struct tc_taprio_qopt_offload *taprio) +{ +struct net_device *netdev =dsa_to_port (ds, port)->slave; +struct hellcreek *hellcreek = ds->priv; +struct hellcreek_port *hellcreek_port; +struct hellcreek_schedule *schedule; +unsigned long flags; +ktime_t start; +u16 ctrl; + + hellcreek_port = &hellcreek->ports[port]; + +/* Convert taprio data to hellcreek schedule */ + schedule =hellcreek_taprio_to_schedule (taprio); +if (IS_ERR (schedule)) +return PTR_ERR (schedule); + +dev_dbg (hellcreek->dev,"Configure traffic schedule on port %d\n" , + port); + +/* Cancel an in flight timer */ +hrtimer_cancel (&hellcreek_port->cycle_start_timer); + +spin_lock_irqsave (&hellcreek->reg_lock, flags); + +if (hellcreek_port->current_schedule) { +kfree (hellcreek_port->current_schedule->entries); +kfree (hellcreek_port->current_schedule); + } + + hellcreek_port->current_schedule = schedule; + +/* First select port */ +hellcreek_select_tgd (hellcreek, port); + +/* Setup traffic class <-> queue mapping */ +hellcreek_setup_tc_mapping (hellcreek, netdev); + +/* Enable gating and set the admin state to forward everything in the +* mean time +*/ + ctrl = (0xff <<TR_TGDCTRL_ADMINGATESTATES_SHIFT ) |TR_TGDCTRL_GATE_EN ; +hellcreek_write (hellcreek, ctrl,TR_TGDCTRL ); + +/* Cancel pending schedule */ +hellcreek_write (hellcreek,0x00 ,TR_ESTCMD ); + +/* Setup a new schedule */ +hellcreek_setup_gcl (hellcreek, port, schedule); + +/* Configure cycle time */
drivers/net/dsa/hirschmann/hellcreek.c static void hellcreek_phylink_validate(struct dsa_switch *ds, int port, · line 1317
Quoted 10 lines
drivers/net/dsa/hirschmann/hellcreek.c +10
-0+hellcreek_set_cycle_time (hellcreek, schedule); + +/* Setup timer for schedule switch: The IP core only allows to set a +* cycle start timer 8 seconds in the future. This is why we setup the +* hritmer to base_time - 5 seconds. Then, we have enough time to +* activate IP core's EST timer. +*/ + start =ktime_sub_ns (schedule->base_time, (u64 )5 *NSEC_PER_SEC ); +hrtimer_start_range_ns (&hellcreek_port->cycle_start_timer, start, +NSEC_PER_SEC ,HRTIMER_MODE_ABS );
If we are talking about seconds here, I don't think you need to use a hrtimer, you could use a workqueue/delayed_work. Should make things a bit simpler.
Quoted 131 lines
drivers/net/dsa/hirschmann/hellcreek.c +60
-0+ +spin_unlock_irqrestore (&hellcreek->reg_lock, flags); + +return 0 ; +} + +static int hellcreek_port_del_schedule (struct dsa_switch *ds,int port) +{ +struct hellcreek *hellcreek = ds->priv; +struct hellcreek_port *hellcreek_port; +unsigned long flags; + + hellcreek_port = &hellcreek->ports[port]; + +dev_dbg (hellcreek->dev,"Remove traffic schedule on port %d\n" , port); + +/* First cancel timer */ +hrtimer_cancel (&hellcreek_port->cycle_start_timer); + +spin_lock_irqsave (&hellcreek->reg_lock, flags); + +if (hellcreek_port->current_schedule) { +kfree (hellcreek_port->current_schedule->entries); +kfree (hellcreek_port->current_schedule); + hellcreek_port->current_schedule =NULL ; + } + +/* Then select port */ +hellcreek_select_tgd (hellcreek, port); + +/* Revert tc mapping */ +__hellcreek_setup_tc_identity_mapping (hellcreek); + +/* Disable gating and return to regular switching flow */ +hellcreek_write (hellcreek,0xff <<TR_TGDCTRL_ADMINGATESTATES_SHIFT , +TR_TGDCTRL ); + +spin_unlock_irqrestore (&hellcreek->reg_lock, flags); + +return 0 ; +} + +static int hellcreek_port_setup_tc (struct dsa_switch *ds,int port, +enum tc_setup_type type,void *type_data) +{ +const struct tc_taprio_qopt_offload *taprio = type_data; + +if (type !=TC_SETUP_QDISC_TAPRIO ) +return -EOPNOTSUPP ; + +if (taprio->enable) +return hellcreek_port_set_schedule (ds, port, taprio); + +return hellcreek_port_del_schedule (ds, port); +} +static const struct dsa_switch_ops hellcreek_ds_ops = { .get_tag_protocol = hellcreek_get_tag_protocol, .setup = hellcreek_setup,@@ -1104,6 +1394,7 @@ static const struct dsa_switch_ops hellcreek_ds_ops = { .port_hwtstamp_get = hellcreek_port_hwtstamp_get, .port_txtstamp = hellcreek_port_txtstamp, .port_rxtstamp = hellcreek_port_rxtstamp, + .port_setup_tc = hellcreek_port_setup_tc, .get_ts_info = hellcreek_get_ts_info, };@@ -1135,6 +1426,9 @@ static int hellcreek_probe(struct platform_device *pdev)if (!port->counter_values)return -ENOMEM ; +hrtimer_init (&port->cycle_start_timer,CLOCK_TAI , +HRTIMER_MODE_ABS ); + port->cycle_start_timer.function = hellcreek_set_schedule; port->hellcreek = hellcreek; port->port = i; }drivers/net/dsa/hirschmann/hellcreek.h +21
-0@@ -16,6 +16,7 @@#include <linux/ptp_clock_kernel.h> #include <linux/timecounter.h> #include <linux/spinlock.h> +#include <linux/hrtimer.h> #include <net/dsa.h> /* Ports: @@ -210,6 +211,20 @@ struct hellcreek_counter {const char *name; }; +struct hellcreek_gcl_entry { +u32 interval; +u8 gate_states; +bool overrun_ignore; +}; + +struct hellcreek_schedule { +struct hellcreek_gcl_entry *entries; +size_t num_entries; +ktime_t base_time; +u32 cycle_time; +int port; +}; +struct hellcreek ;/* State flags for hellcreek_port_hwtstamp::state */ @@ -236,6 +251,8 @@ struct hellcreek_port_hwtstamp {struct hellcreek_port {struct hellcreek *hellcreek; +struct hellcreek_schedule *current_schedule; +struct hrtimer cycle_start_timer;int port;u16 ptcfg;/* ptcfg shadow */ u64 *counter_values;@@ -273,4 +290,8 @@ struct hellcreek { size_t fdb_entries; }; +#define hrtimer_to_hellcreek_port (timer) \ + container_of(timer, struct hellcreek_port, \ + cycle_start_timer) +#endif /* _HELLCREEK_H_ */ Signature · 1 line
2.20.1
Cheers,
Signature · 1 line
Vinicius
Kurt Kanzenbach
maintainerRe: [PATCH v3 5/8] net: dsa: hellcreek: Add TAPRIO offloading support
Quoted 4 lines · Vinicius Costa Gomes
Hi,
Kurt Kanzenbach <[email protected]> writes:
[snip]
Quoted 4 lines
Quoted 4 lines
drivers/net/dsa/hirschmann/hellcreek.c +4
-0+/* Setup timer for schedule switch: The IP core only allows to set a +* cycle start timer 8 seconds in the future. This is why we setup the +* hritmer to base_time - 5 seconds. Then, we have enough time to +* activate IP core's EST timer.
Quoted 8 lines
drivers/net/dsa/hirschmann/hellcreek.c static void hellcreek_phylink_validate(struct dsa_switch *ds, int port, · line 1317
Quoted 4 lines
drivers/net/dsa/hirschmann/hellcreek.c +4
-0+*/ + start =ktime_sub_ns (schedule->base_time, (u64 )5 *NSEC_PER_SEC ); +hrtimer_start_range_ns (&hellcreek_port->cycle_start_timer, start, +NSEC_PER_SEC ,HRTIMER_MODE_ABS );If we are talking about seconds here, I don't think you need to use a hrtimer, you could use a workqueue/delayed_work. Should make things a bit simpler.
I've used hrtimers for one reason: The hrtimer provides a way to fire at an absolute base time based on CLOCK_TAI. All the other facilities such as workqueues, timer list timers, etc do not.
In the typical setup, we run ptp4l as boundary clock (or as TAB which is work in progress) and phc2sys to synchronize the ptp clock to the Linux system. Let's assume we setup a TAPRIO schedule with a base time X. Now, the grand master time changes meaning the timer has to go off earlier or later.
Thanks,
Kurt
Vladimir Oltean
maintainerRe: [PATCH v3 5/8] net: dsa: hellcreek: Add TAPRIO offloading support
Quoted 19 lines · Kurt Kanzenbach
Quoted 4 lines · Vinicius Costa Gomes
Hi,
Kurt Kanzenbach <[email protected]> writes:
[snip]
Quoted 4 lines
Quoted 4 lines
drivers/net/dsa/hirschmann/hellcreek.c +4
-0+/* Setup timer for schedule switch: The IP core only allows to set a +* cycle start timer 8 seconds in the future. This is why we setup the +* hritmer to base_time - 5 seconds. Then, we have enough time to +* activate IP core's EST timer. Quoted 8 lines
drivers/net/dsa/hirschmann/hellcreek.c static void hellcreek_phylink_validate(struct dsa_switch *ds, int port, · line 1317
Quoted 4 lines
drivers/net/dsa/hirschmann/hellcreek.c +4
-0+*/ + start =ktime_sub_ns (schedule->base_time, (u64 )5 *NSEC_PER_SEC ); +hrtimer_start_range_ns (&hellcreek_port->cycle_start_timer, start, +NSEC_PER_SEC ,HRTIMER_MODE_ABS );If we are talking about seconds here, I don't think you need to use a hrtimer, you could use a workqueue/delayed_work. Should make things a bit simpler.
Quoted 3 lines
I've used hrtimers for one reason: The hrtimer provides a way to fire at an absolute base time based on
CLOCK_TAI. All the other facilities such as workqueues, timer list timers, etc do not.
That still doesn't justify the complexity of irqsave spinlocks and such. You could just as well schedule a workqueue from that hrtimer and have process context...
Thanks,
-Vladimir
Kurt Kanzenbach
maintainerRe: [PATCH v3 5/8] net: dsa: hellcreek: Add TAPRIO offloading support
Quoted 20 lines · Vladimir Oltean
Quoted 19 lines · Kurt Kanzenbach
Quoted 4 lines · Vinicius Costa Gomes
Hi,
Kurt Kanzenbach <[email protected]> writes:
[snip]
Quoted 12 lines
drivers/net/dsa/hirschmann/hellcreek.c static void hellcreek_phylink_validate(struct dsa_switch *ds, int port, · line 1317
Quoted 8 lines
drivers/net/dsa/hirschmann/hellcreek.c +8
-0+/* Setup timer for schedule switch: The IP core only allows to set a +* cycle start timer 8 seconds in the future. This is why we setup the +* hritmer to base_time - 5 seconds. Then, we have enough time to +* activate IP core's EST timer. +*/ + start =ktime_sub_ns (schedule->base_time, (u64 )5 *NSEC_PER_SEC ); +hrtimer_start_range_ns (&hellcreek_port->cycle_start_timer, start, +NSEC_PER_SEC ,HRTIMER_MODE_ABS );If we are talking about seconds here, I don't think you need to use a hrtimer, you could use a workqueue/delayed_work. Should make things a bit simpler.
Quoted 7 lines
Quoted 3 lines
I've used hrtimers for one reason: The hrtimer provides a way to fire at an absolute base time based on
CLOCK_TAI. All the other facilities such as workqueues, timer list timers, etc do not.That still doesn't justify the complexity of irqsave spinlocks and such. You could just as well schedule a workqueue from that hrtimer and have process context...
After giving this a bit more thought, it can be implemented by using workqueues only. That ptp time is "cached" anyway the we could just periodically check for the base time arrival. That should solve the irqsave and the being synchronized problem.
Thanks,
Kurt
Vladimir Oltean
maintainerRe: [PATCH v3 5/8] net: dsa: hellcreek: Add TAPRIO offloading support
Quoted 8 lines · Kurt Kanzenbach
After giving this a bit more thought, it can be implemented by using workqueues only. That ptp time is "cached" anyway the we could just periodically check for the base time arrival. That should solve the irqsave and the being synchronized problem.
Thanks,
Kurt
Ok, this sounds simple enough. If the base-time is within 8 seconds of the current PTP time, then apply the taprio configuration, otherwise reschedule a delayed workqueue after N seconds (where N has what value?).
If my math is correct, then N can't simply be the the delta between the current PTP time and the (base-time minus 8 seconds) value - i.e. just one schedule_delayed_work - because at large deltas, the PHC frequency adjustment (+/- 6.25%) starts to matter. At maximum frequency, the PHC can exceed the monotonic clock of the system by more than 8 seconds in (8 * 100 / 6.25) = 128 seconds. So if the base-time is in the future by more than 128 seconds and you plan for a single schedule_delayed_work, there's a chance that you'll miss the window. And even if you try to compensate using the current frequency adjustment, that's all that it is
- the current, instantaneous frequency adjustment, not the one from 128 seconds later.
How about N being half that delta? It's not ideal, since there would need to be log2(delta) reschedules, but at least the error of the first approximation won't propagate to the next, and the delta will keep decreasing as time passes, therefore so will the error.
Thanks,
-Vladimir
Re: [PATCH v3 5/8] net: dsa: hellcreek: Add TAPRIO offloading support
In reply to Kurt KanzenbachHi Kurt,
Quoted 19 lines · Kurt Kanzenbach
Quoted 4 lines · Vinicius Costa Gomes
Hi,
Kurt Kanzenbach <[email protected]> writes:
[snip]
Quoted 4 lines
Quoted 4 lines
drivers/net/dsa/hirschmann/hellcreek.c +4
-0+/* Setup timer for schedule switch: The IP core only allows to set a +* cycle start timer 8 seconds in the future. This is why we setup the +* hritmer to base_time - 5 seconds. Then, we have enough time to +* activate IP core's EST timer. Quoted 8 lines
drivers/net/dsa/hirschmann/hellcreek.c static void hellcreek_phylink_validate(struct dsa_switch *ds, int port, · line 1317
Quoted 4 lines
drivers/net/dsa/hirschmann/hellcreek.c +4
-0+*/ + start =ktime_sub_ns (schedule->base_time, (u64 )5 *NSEC_PER_SEC ); +hrtimer_start_range_ns (&hellcreek_port->cycle_start_timer, start, +NSEC_PER_SEC ,HRTIMER_MODE_ABS );If we are talking about seconds here, I don't think you need to use a hrtimer, you could use a workqueue/delayed_work. Should make things a bit simpler.
Quoted 3 lines
I've used hrtimers for one reason: The hrtimer provides a way to fire at an absolute base time based on
CLOCK_TAI. All the other facilities such as workqueues, timer list timers, etc do not.
Oh, yeah. Good point.
Cheers,
Signature · 1 line
Vinicius
Kurt Kanzenbach
maintainerPATCH v3 6/8 net: dsa: hellcreek: Add PTP status LEDs
In reply to Kurt KanzenbachThe switch has two controllable I/Os which are usually connected to LEDs. This is useful to immediately visually see the PTP status.
These provide two signals:
* is_gm
This LED can be activated if the current device is the grand master in that PTP domain.
* sync_good
This LED can be activated if the current device is in sync with the network time.
Expose these via the LED framework to be controlled via user space e.g. linuxptp.
--- drivers/net/dsa/hirschmann/hellcreek.h | 4 + drivers/net/dsa/hirschmann/hellcreek_ptp.c | 149 +++++++++++++++++++++ drivers/net/dsa/hirschmann/hellcreek_ptp.h | 3 + 3 files changed, 156 insertions(+)
drivers/net/dsa/hirschmann/hellcreek.h +4 -0
@@ -17,6 +17,7 @@#include <linux/timecounter.h> #include <linux/spinlock.h> #include <linux/hrtimer.h> +#include <linux/leds.h> #include <net/dsa.h> /* Ports:
@@ -280,6 +281,8 @@ struct hellcreek {struct ptp_clock_info ptp_clock_info;struct hellcreek_port ports[4 ];struct delayed_work overflow_work; +struct led_classdev led_is_gm; +struct led_classdev led_sync_good;spinlock_t reg_lock;/* Switch IP register lock */ spinlock_t ptp_lock;/* PTP IP register lock */ void __iomem *base;
@@ -287,6 +290,7 @@ struct hellcreek {u8 *vidmbrcfg;/* vidmbrcfg shadow */ u64 seconds;/* PTP seconds */ u64 last_ts;/* Used for overflow detection */ +u16 status_out;/* ptp.status_out shadow */ size_t fdb_entries; };
drivers/net/dsa/hirschmann/hellcreek_ptp.c +149 -0
170 lines not on this page · raw message
drivers/net/dsa/hirschmann/hellcreek_ptp.h +3 -0
@@ -70,4 +70,7 @@ u64 hellcreek_ptp_gettime_seconds(struct hellcreek *hellcreek, u64 ns);#define dw_overflow_to_hellcreek (dw) \ container_of(dw, struct hellcreek, overflow_work) +#define led_to_hellcreek (ldev, led) \ + container_of(ldev, struct hellcreek, led) +#endif /* _HELLCREEK_PTP_H_ */
Signature · 1 line
2.20.1
Re: [PATCH v3 6/8] net: dsa: hellcreek: Add PTP status LEDs
Quoted 12 lines · Kurt Kanzenbach
The switch has two controllable I/Os which are usually connected to LEDs. This is useful to immediately visually see the PTP status.
These provide two signals:
*
is_gmThis LED can be activated if the current device is the grand master in that PTP domain.
*
sync_good
Quoted 7 lines
This LED can be activated if the current device is in sync with the network time.
Expose these via the LED framework to be controlled via user space e.g. linuxptp.
Signed-off-by Kurt Kanzenbach <[email protected]>
Andrew
Kurt Kanzenbach
maintainerPATCH v3 7/8 dt-bindings: Add vendor prefix for Hirschmann
In reply to Kurt KanzenbachHirschmann is building devices for automation and networking. Add them to the vendor prefixes.
--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -433,6 +433,8 @@ patternProperties: description: HiDeep Inc. "^himax,.*": description: Himax Technologies, Inc. + "^hirschmann,.*": + description: Hirschmann Automation and Control GmbH "^hisilicon,.*": description: Hisilicon Limited. "^hit,.*":
Signature · 1 line
2.20.1
Kurt Kanzenbach
maintainerPATCH v3 8/8 dt-bindings: net: dsa: Add documentation for Hellcreek switches
In reply to Kurt KanzenbachAdd basic documentation and example.
--- .../bindings/net/dsa/hellcreek.yaml | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/hellcreek.yaml
Documentation/devicetree/bindings/net/dsa/hellcreek.yaml new file +125 -0
@@ -0,0 +1,125 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/dsa/hellcreek.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Hirschmann Hellcreek TSN Switch Device Tree Bindings + +allOf: + - $ref: dsa.yaml# + +maintainers: + - Andrew Lunn <[email protected]> + - Florian Fainelli <[email protected]> + - Vivien Didelot <[email protected]> + - Kurt Kanzenbach <[email protected]> + +description: + The Hellcreek TSN Switch IP is a 802.1Q Ethernet compliant switch. It supports + the Precision Time Protocol, Hardware Timestamping as well the Time Aware + Shaper. + +properties: + compatible: + items: + - const: hirschmann,hellcreek + + reg: + description: + The physical base address and size of TSN and PTP memory base + minItems: 2 + maxItems: 2 + + reg-names: + items: + - const: tsn + - const: ptp + + leds: + type: object + properties: + '#address-cells': + const: 1 + '#size-cells': + const: 0 + + patternProperties: + "^led@[0-9]+$": + type: object + description: Hellcreek leds + $ref: ../../leds/common.yaml# + + properties: + reg: + items: + - enum: [0, 1] + description: Led number + + label: true + + default-state: true + + required: + - reg + + additionalProperties: false + +required: + - compatible + - reg + - reg-names + - ethernet-ports + - leds + +unevaluatedProperties: false + +examples: + - | + switch0: switch@ff240000 { + compatible = "hirschmann,hellcreek"; + reg = <0xff240000 0x1000>, + <0xff250000 0x1000>; + reg-names = "tsn", "ptp"; + dsa,member = <0 0>; + + ethernet-ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + label = "cpu"; + ethernet = <&gmac0>; + }; + + port@2 { + reg = <2>; + label = "lan0"; + phy-handle = <&phy1>; + }; + + port@3 { + reg = <3>; + label = "lan1"; + phy-handle = <&phy2>; + }; + }; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + label = "sync_good"; + default-state = "on"; + }; + + led@1 { + reg = <1>; + label = "is_gm"; + default-state = "off"; + }; + }; + };
Signature · 1 line
2.20.1
Re: [PATCH v3 8/8] dt-bindings: net: dsa: Add documentation for Hellcreek switches
Quoted 3 lines · Kurt Kanzenbach
Add basic documentation and example.
Signed-off-by Kurt Kanzenbach <[email protected]>
Andrew
Re: [PATCH v3 8/8] dt-bindings: net: dsa: Add documentation for Hellcreek switches
In reply to Kurt KanzenbachQuoted 52 lines · Kurt Kanzenbach
Add basic documentation and example.
Signed-off-by Kurt Kanzenbach <[email protected]>--- .../bindings/net/dsa/hellcreek.yaml | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/hellcreek.yamlDocumentation/devicetree/bindings/net/dsa/hellcreek.yaml new file +38
-0@@ -0,0 +1,125 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/dsa/hellcreek.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Hirschmann Hellcreek TSN Switch Device Tree Bindings + +allOf: + - $ref: dsa.yaml# + +maintainers: + - Andrew Lunn <[email protected]> + - Florian Fainelli <[email protected]> + - Vivien Didelot <[email protected]> + - Kurt Kanzenbach <[email protected]> + +description: + The Hellcreek TSN Switch IP is a 802.1Q Ethernet compliant switch. It supports + the Precision Time Protocol, Hardware Timestamping as well the Time Aware + Shaper. + +properties: + compatible: + items: + - const: hirschmann,hellcreek + + reg: + description: + The physical base address and size of TSN and PTP memory base + minItems: 2 + maxItems: 2 + + reg-names: + items: + - const: tsn + - const: ptp +
Documentation/devicetree/bindings/net/dsa/hellcreek.yaml line 48
Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/hellcreek.yaml new file +10
-0+ leds: + type: object + properties: + '#address-cells': + const: 1 + '#size-cells': + const: 0 + + patternProperties: + "^led@[0-9]+$":
As there are only 2 LED nodes:
"led@[01]$"
Quoted 8 lines
Documentation/devicetree/bindings/net/dsa/hellcreek.yaml new file +8
-0+ type: object + description: Hellcreek leds + $ref: ../../leds/common.yaml# + + properties: + reg: + items: + - enum: [0, 1]
Documentation/devicetree/bindings/net/dsa/hellcreek.yaml line 66
Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/hellcreek.yaml new file +10
-0+ description: Led number + + label: true + + default-state: true + + required: + - reg + + additionalProperties: false
For the 'leds' node:
additionalProperties: false
With those fixes,
Quoted 62 lines
Documentation/devicetree/bindings/net/dsa/hellcreek.yaml new file +59
-0+ +required: + - compatible + - reg + - reg-names + - ethernet-ports + - leds + +unevaluatedProperties: false + +examples: + - | + switch0: switch@ff240000 { + compatible = "hirschmann,hellcreek"; + reg = <0xff240000 0x1000>, + <0xff250000 0x1000>; + reg-names = "tsn", "ptp"; + dsa,member = <0 0>; + + ethernet-ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + label = "cpu"; + ethernet = <&gmac0>; + }; + + port@2 { + reg = <2>; + label = "lan0"; + phy-handle = <&phy1>; + }; + + port@3 { + reg = <3>; + label = "lan1"; + phy-handle = <&phy2>; + }; + }; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + label = "sync_good"; + default-state = "on"; + }; + + led@1 { + reg = <1>; + label = "is_gm"; + default-state = "off"; + }; + }; + };Signature · 1 line
2.20.1
Jakub Kicinski
maintainerQuoted 7 lines · On Thu, 20 Aug 2020 10:11:10 +0200 Kurt Kanzenbach wrote:
this series adds a DSA driver for the Hirschmann Hellcreek TSN switch IP. Characteristics of that IP:
* Full duplex Ethernet interface at 100/1000 Mbps on three ports
* IEEE 802.1Q-compliant Ethernet Switch
* IEEE 802.1Qbv Time-Aware scheduling support
* IEEE 1588 and IEEE 802.1AS support
I don't see anything worth complaining about here, but this is not my area of expertise..
DSA and TAPRIO folks - does this look good to you?
Vladimir Oltean
maintainerQuoted 9 lines · Jakub Kicinski
Quoted 7 lines · On Thu, 20 Aug 2020 10:11:10 +0200 Kurt Kanzenbach wrote:
this series adds a DSA driver for the Hirschmann Hellcreek TSN switch IP. Characteristics of that IP:
* Full duplex Ethernet interface at 100/1000 Mbps on three ports
* IEEE 802.1Q-compliant Ethernet Switch
* IEEE 802.1Qbv Time-Aware scheduling support
* IEEE 1588 and IEEE 802.1AS support
Quoted 4 lines
I don't see anything worth complaining about here, but this is not my area of expertise..
DSA and TAPRIO folks - does this look good to you?
Just my comment on patch 5/8 about netdev->tc_to_txq. There are 2 distinct things about that:
- accessing struct net_device directly hurts the DSA model a little bit.
- I think there's some confusion regarding the use of netdev->tc_to_txq itself. I don't think that's the right place to setup a VLAN PCP to traffic class mapping. That's simply "what traffic class does each netdev queue have". I would even go as far as say that Linux doesn't support a VLAN PCP to TC mapping (similar to the DSCP to TC mapping from the DCB ops) at all, except for the ingress-qos-map and egress-qos-map of the 8021q driver, which can't be offloaded and don't map nicely over existing hardware anyway (what hardware has an ingress-qos-map and an egress-qos-map per individual VLAN?!). Although I do really see the need for having a mapping between VLAN PCP and traffic class, I would suggest Kurt to not expose this through taprio/mqprio (hardcode the PCP mapping as 1-to-1 with TC, as other drivers do), and let's try to come up separately with an abstraction for that.
Thanks,
-Vladimir
David Miller
maintainerFrom: Vladimir Oltean <[email protected]>
Date: Tue, 25 Aug 2020 01:02:03 +0300
Quoted 9 lines
Just my comment on patch 5/8 about
netdev->tc_to_txq. There are 2 distinct things about that:
- accessing structnet_devicedirectly hurts the DSA model a little bit.
- I think there's some confusion regarding the use ofnetdev->tc_to_txqitself. I don't think that's the right place to setup a VLAN PCP to traffic class mapping. That's simply "what traffic class does each netdev queue have". I would even go as far as say that Linux doesn't support a VLAN PCP to TC mapping (similar to the DSCP to TC mapping from the DCB ops) at all, except for the ingress-qos-map and
Quoted 8 lines
egress-qos-map of the 8021q driver, which can't be offloaded and don't map nicely over existing hardware anyway (what hardware has an ingress-qos-map and an egress-qos-map per individual VLAN?!). Although I do really see the need for having a mapping between VLAN PCP and traffic class, I would suggest Kurt to not expose this through taprio/mqprio (hardcode the PCP mapping as 1-to-1 with TC, as other drivers do), and let's try to come up separately with an abstraction for that.
Agreed, Kurt can you repost this series without the TAPRIO support for now since it's controversial and needs more discussion and changes?
Thank you.
Vladimir Oltean
maintainerQuoted 21 lines · David Miller
From: Vladimir Oltean <[email protected]>
Date: Tue, 25 Aug 2020 01:02:03 +0300Quoted 9 lines
Just my comment on patch 5/8 about
netdev->tc_to_txq. There are 2 distinct things about that:
- accessing structnet_devicedirectly hurts the DSA model a little bit.
- I think there's some confusion regarding the use ofnetdev->tc_to_txqitself. I don't think that's the right place to setup a VLAN PCP to traffic class mapping. That's simply "what traffic class does each netdev queue have". I would even go as far as say that Linux doesn't support a VLAN PCP to TC mapping (similar to the DSCP to TC mapping from the DCB ops) at all, except for the ingress-qos-map andQuoted 8 lines
egress-qos-map of the 8021q driver, which can't be offloaded and don't map nicely over existing hardware anyway (what hardware has an ingress-qos-map and an egress-qos-map per individual VLAN?!). Although I do really see the need for having a mapping between VLAN PCP and traffic class, I would suggest Kurt to not expose this through taprio/mqprio (hardcode the PCP mapping as 1-to-1 with TC, as other drivers do), and let's try to come up separately with an abstraction for that.
Quoted 4 lines
Agreed, Kurt can you repost this series without the TAPRIO support for now since it's controversial and needs more discussion and changes?
Thank you.
To be clear, the most important part of the taprio qdisc offload (setting up the gate control list) does not need to be postponed. It's just the VLAN PCP mapping that is a bit controversial.
Thanks,
-Vladimir
Kurt Kanzenbach
maintainerQuoted 2 lines · David Miller
Agreed, Kurt can you repost this series without the TAPRIO support for now since it's controversial and needs more discussion and changes?
OK. It seems like the TAPRIO implementation has to be discussed more and it might be good to do that separately.
I'll replace the spinlocks (which were only introduced for the hrtimers) with mutexes and post a sane version of the driver without the TAPRIO support.
Quoted 2 lines
Thank you.
Thanks,
Kurt
Quoted 10 lines · Kurt Kanzenbach
Quoted 2 lines · David Miller
Agreed, Kurt can you repost this series without the TAPRIO support for now since it's controversial and needs more discussion and changes?
OK. It seems like the TAPRIO implementation has to be discussed more and it might be good to do that separately.
I'll replace the spinlocks (which were only introduced for the hrtimers) with mutexes and post a sane version of the driver without the TAPRIO support.
Sounds great, thanks!
Signature · 1 line
Florian