Introduce ICSSG based ethernet Driver
MD Danish Anwar
reviewerv11 cover Introduce ICSSG based ethernet Driver
The Programmable Real-time Unit and Industrial Communication Subsystem Gigabit (PRU_ICSSG) is a low-latency microcontroller subsystem in the TI SoCs. This subsystem is provided for the use cases like the implementation of custom peripheral interfaces, offloading of tasks from the other processor cores of the SoC, etc.
The subsystem includes many accelerators for data processing like multiplier and multiplier-accumulator. It also has peripherals like UART, MII/RGMII, MDIO, etc. Every ICSSG core includes two 32-bit load/store RISC CPU cores called PRUs.
The above features allow it to be used for implementing custom firmware based peripherals like ethernet.
This series adds the YAML documentation and the driver with basic EMAC support for TI AM654 Silicon Rev 2 SoC with the PRU_ICSSG Sub-system. running dual-EMAC firmware.
This currently supports basic EMAC with 1Gbps and 100Mbps link. 10M and half-duplex modes are not yet supported because they require the support of an IEP, which will be added later.
Advanced features like switch-dev and timestamping will be added later.
This is the v11 of the patch series [v1]. This version of the patchset addresses comments made on v10.
There series doesn't have any dependency.
Changes from v10 to v11 :
*) Rebased the series on latest net-next.
*) Split the ICSSG driver introduction patch into 9 different patches as
asked by Jakub.
*) Introduced new patch(patch 8/10) to dump Standard network interface
staticstics via ndo_get_stats64. Now certain stats that are reported by ICSSG hardware and are also part of struct rtnl_link_stats64, will be reported by ndo_get_stats64. While other stats that are not part of the struct rtnl_link_stats64 will be reported by ethtool -S. These stats are not duplicated.
Changes from v9 to v10 :
*) Rebased the series on latest net-next.
*) Moved 'ndev prueth->emac[mac] == emac' assignment to the end of function
prueth_netdev_init().
*) In unsupported phy_mode switch case instead of returning -EINVAL, store
the error code in ret and 'goto free'
Changes from v8 to v9 :
*) Rebased the series on latest net-next.
*) Fixed smatch and sparse warnings as pointed by Simon. *) Fixed leaky ndev in prueth_netdev_init() as asked by Simon.
Changes from v7 to v8 :
*) Rebased the series on 6.5-rc1.
*) Fixed few formattings.
Changes from v6 to v7 :
*) Added RB tag of Rob in patch 1 of this series. *) Addressed Simon's comment on patch 2 of the series. *) Rebased patchset on next-20230428 linux-next.
Changes from v5 to v6 :
*) Added RB tag of Andrew Lunn in patch 2 of this series. *) Addressed Rob's comment on patch 1 of the series. *) Rebased patchset on next-20230421 linux-next.
Changes from v4 to v5 :
*) Re-arranged properties section in ti,icssg-prueth.yaml file. *) Added requirement for minimum one ethernet port.
*) Fixed some minor formatting errors as asked by Krzysztof. *) Dropped SGMII mode from enum mii_mode as SGMII mode is not currently
supported by the driver.
*) Added switch-case block to handle different phy modes by ICSSG driver.
Changes from v3 to v4 :
*) Addressed Krzysztof's comments and fixed dt_binding_check errors in
patch 1/2.
*) Added interrupt-extended property in ethernet-ports properties section. *) Fixed comments in file icssg_switch_map.h according to the Linux coding
style in patch 2/2. Added Documentation of structures in patch 2/2.
Changes from v2 to v3 :
*) Addressed Rob and Krzysztof's comments on patch 1 of this series.
Fixed indentation. Removed description and pinctrl section from ti,icssg-prueth.yaml file.
*) Addressed Krzysztof, Paolo, Randy, Andrew and Christophe's comments on
patch 2 of this seires.
*) Fixed blanklines in Kconfig and Makefile. Changed structures to const
as suggested by Krzysztof.
*) Fixed while loop logic in emac_tx_complete_packets() API as suggested
by Paolo. Previously in the loop's last iteration 'budget' was 0 and napi_consume_skb would wrongly assume the caller is not in NAPI context Now, budget won't be zero in last iteration of loop.
*) Removed inline functions addr_to_da1() and addr_to_da0() as asked by
Andrew.
*) Added dev_err_probe() instead of dev_err() as suggested by Christophe. *) In ti,icssg-prueth.yaml file, in the patternProperties section of
ethernet-ports, kept the port name as "port" instead of "ethernet-port" as all other drivers were using "port". Will change it if is compulsory to use "ethernet-port".
[v1] https://lore.kernel.org/all/[email protected]/
[v2] https://lore.kernel.org/all/[email protected]/
[v3] https://lore.kernel.org/all/[email protected]/
[v4] https://lore.kernel.org/all/[email protected]/
[v5] https://lore.kernel.org/all/[email protected]/
[v6] https://lore.kernel.org/all/[email protected]/
[v7] https://lore.kernel.org/all/[email protected]/
[v8] https://lore.kernel.org/all/[email protected]/
[v9] https://lore.kernel.org/all/[email protected]/
[v10] https://lore.kernel.org/all/[email protected]/
Thanks and Regards,
Md Danish Anwar
MD Danish Anwar (9):
net: ti: icssg-prueth: Add Firmware Interface for ICSSG Ethernet
driver.
net: ti: icssg-prueth: Add mii helper apis and macros
net: ti: icssg-prueth: Add Firmware config and classification APIs.
net: ti: icssg-prueth: Add icssg queues APIs and macros
dt-bindings: net: Add ICSSG Ethernet
net: ti: icssg-prueth: Add ICSSG Stats
net: ti: icssg-prueth: Add Standard network staticstics
net: ti: icssg-prueth: Add ethtool ops for ICSSG Ethernet driver
net: ti: icssg-prueth: Add Power management support
Roger Quadros (1):
net: ti: icssg-prueth: Add ICSSG ethernet driver
.../bindings/net/ti,icssg-prueth.yaml | 184 ++ drivers/net/ethernet/ti/Kconfig | 13 + drivers/net/ethernet/ti/Makefile | 3 + drivers/net/ethernet/ti/icssg_classifier.c | 367 ++++ drivers/net/ethernet/ti/icssg_config.c | 450 ++++ drivers/net/ethernet/ti/icssg_config.h | 200 ++ drivers/net/ethernet/ti/icssg_ethtool.c | 154 ++ drivers/net/ethernet/ti/icssg_mii_cfg.c | 120 ++ drivers/net/ethernet/ti/icssg_mii_rt.h | 151 ++ drivers/net/ethernet/ti/icssg_prueth.c | 1919 +++++++++++++++++ drivers/net/ethernet/ti/icssg_prueth.h | 259 +++ drivers/net/ethernet/ti/icssg_queues.c | 38 + drivers/net/ethernet/ti/icssg_stats.c | 57 + drivers/net/ethernet/ti/icssg_stats.h | 158 ++ drivers/net/ethernet/ti/icssg_switch_map.h | 234 ++ 15 files changed, 4307 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/ti,icssg-prueth.yaml create mode 100644 drivers/net/ethernet/ti/icssg_classifier.c create mode 100644 drivers/net/ethernet/ti/icssg_config.c create mode 100644 drivers/net/ethernet/ti/icssg_config.h create mode 100644 drivers/net/ethernet/ti/icssg_ethtool.c create mode 100644 drivers/net/ethernet/ti/icssg_mii_cfg.c create mode 100644 drivers/net/ethernet/ti/icssg_mii_rt.h create mode 100644 drivers/net/ethernet/ti/icssg_prueth.c create mode 100644 drivers/net/ethernet/ti/icssg_prueth.h create mode 100644 drivers/net/ethernet/ti/icssg_queues.c create mode 100644 drivers/net/ethernet/ti/icssg_stats.c create mode 100644 drivers/net/ethernet/ti/icssg_stats.h create mode 100644 drivers/net/ethernet/ti/icssg_switch_map.h
Signature · 1 line
2.34.1
MD Danish Anwar
reviewerPATCH v11 1/10 net: ti: icssg-prueth: Add Firmware Interface for ICSSG Ethernet driver.
Add firmware interface related headers and macros for ICSSG Ethernet driver. These macros will be later used by the ICSSG ethernet driver.
--- drivers/net/ethernet/ti/icssg_switch_map.h | 234 +++++++++++++++++++++ 1 file changed, 234 insertions(+) create mode 100644 drivers/net/ethernet/ti/icssg_switch_map.h
drivers/net/ethernet/ti/icssg_switch_map.h new file +234 -0
@@ -0,0 +1,234 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Texas Instruments ICSSG Ethernet driver +* +* Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/ +* +*/ + +#ifndef __NET_TI_ICSSG_SWITCH_MAP_H +#define __NET_TI_ICSSG_SWITCH_MAP_H + +/************************* Ethernet Switch Constants *********************/ + +/* if bucket size is changed in firmware then this too should be changed +* because it directly impacts FDB ageing calculation +*/ +#define NUMBER_OF_FDB_BUCKET_ENTRIES (4) + +/* This is fixed in ICSSG */ +#define SIZE_OF_FDB (2048) + +#define FW_LINK_SPEED_1G (0x00) +#define FW_LINK_SPEED_100M (0x01) +#define FW_LINK_SPEED_10M (0x02) +#define FW_LINK_SPEED_HD (0x80) + +/* Time after which FDB entries are checked for aged out values. +* Values are in nanoseconds +*/ +#define FDB_AGEING_TIMEOUT_OFFSET 0x0014 + +/* Default VLAN tag for Host Port */ +#define HOST_PORT_DF_VLAN_OFFSET 0x001C + +/* Same as HOST_PORT_DF_VLAN_OFFSET */ +#define EMAC_ICSSG_SWITCH_PORT0_DEFAULT_VLAN_OFFSET HOST_PORT_DF_VLAN_OFFSET + +/* Default VLAN tag for P1 Port */ +#define P1_PORT_DF_VLAN_OFFSET 0x0020 + +/* Same as P1_PORT_DF_VLAN_OFFSET */ +#define EMAC_ICSSG_SWITCH_PORT1_DEFAULT_VLAN_OFFSET P1_PORT_DF_VLAN_OFFSET + +/* default VLAN tag for P2 Port */ +#define P2_PORT_DF_VLAN_OFFSET 0x0024 + +/* Same as P2_PORT_DF_VLAN_OFFSET */ +#define EMAC_ICSSG_SWITCH_PORT2_DEFAULT_VLAN_OFFSET P2_PORT_DF_VLAN_OFFSET + +/* VLAN-FID Table offset. 4096 VIDs. 2B per VID = 8KB = 0x2000 */ +#define VLAN_STATIC_REG_TABLE_OFFSET 0x0100 + +/* VLAN-FID Table offset for EMAC */ +#define EMAC_ICSSG_SWITCH_DEFAULT_VLAN_TABLE_OFFSET VLAN_STATIC_REG_TABLE_OFFSET + +/* Packet descriptor Q reserved memory */ +#define PORT_DESC0_HI 0x2104 + +/* Packet descriptor Q reserved memory */ +#define PORT_DESC0_LO 0x2F6C + +/* Packet descriptor Q reserved memory */ +#define PORT_DESC1_HI 0x3DD4 + +/* Packet descriptor Q reserved memory */ +#define PORT_DESC1_LO 0x4C3C + +/* Packet descriptor Q reserved memory */ +#define HOST_DESC0_HI 0x5AA4 + +/* Packet descriptor Q reserved memory */ +#define HOST_DESC0_LO 0x5F0C + +/* Packet descriptor Q reserved memory */ +#define HOST_DESC1_HI 0x6374 + +/* Packet descriptor Q reserved memory */ +#define HOST_DESC1_LO 0x67DC + +/* Special packet descriptor Q reserved memory */ +#define HOST_SPPD0 0x7AAC + +/* Special acket descriptor Q reserved memory */ +#define HOST_SPPD1 0x7EAC + +/* IEP count cycle counter*/ +#define TIMESYNC_FW_WC_CYCLECOUNT_OFFSET 0x83EC + +/* IEP count hi roll over count */ +#define TIMESYNC_FW_WC_HI_ROLLOVER_COUNT_OFFSET 0x83F4 + +/* IEP count hi sw counter */ +#define TIMESYNC_FW_WC_COUNT_HI_SW_OFFSET_OFFSET 0x83F8 + +/* Set clock descriptor */ +#define TIMESYNC_FW_WC_SETCLOCK_DESC_OFFSET 0x83FC + +/* IEP count syncout reduction factor */ +#define TIMESYNC_FW_WC_SYNCOUT_REDUCTION_FACTOR_OFFSET 0x843C + +/* IEP count syncout reduction counter */ +#define TIMESYNC_FW_WC_SYNCOUT_REDUCTION_COUNT_OFFSET 0x8440 + +/* IEP count syncout start time cycle counter */ +#define TIMESYNC_FW_WC_SYNCOUT_START_TIME_CYCLECOUNT_OFFSET 0x8444 + +/* Control variable to generate SYNC1 */ +#define TIMESYNC_FW_WC_ISOM_PIN_SIGNAL_EN_OFFSET 0x844C + +/* SystemTime Sync0 periodicity */ +#define TIMESYNC_FW_ST_SYNCOUT_PERIOD_OFFSET 0x8450 + +/* pktTxDelay for P1 = link speed dependent p1 mac delay + p1 phy delay */ +#define TIMESYNC_FW_WC_PKTTXDELAY_P1_OFFSET 0x8454 + +/* pktTxDelay for P2 = link speed dependent p2 mac delay + p2 phy delay */ +#define TIMESYNC_FW_WC_PKTTXDELAY_P2_OFFSET 0x8458 + +/* Set clock operation done signal for next task */ +#define TIMESYNC_FW_SIG_PNFW_OFFSET 0x845C + +/* Set clock operation done signal for next task */ +#define TIMESYNC_FW_SIG_TIMESYNCFW_OFFSET 0x8460 + +/* New list is copied at this time */ +#define TAS_CONFIG_CHANGE_TIME 0x000C + +/* config change error counter */ +#define TAS_CONFIG_CHANGE_ERROR_COUNTER 0x0014 + +/* TAS List update pending flag */ +#define TAS_CONFIG_PENDING 0x0018 + +/* TAS list update trigger flag */ +#define TAS_CONFIG_CHANGE 0x0019 + +/* List length for new TAS schedule */ +#define TAS_ADMIN_LIST_LENGTH 0x001A + +/* Currently active TAS list index */ +#define TAS_ACTIVE_LIST_INDEX 0x001B + +/* Cycle time for the new TAS schedule */ +#define TAS_ADMIN_CYCLE_TIME 0x001C + +/* Cycle counts remaining till the TAS list update */ +#define TAS_CONFIG_CHANGE_CYCLE_COUNT 0x0020 + +/* Base Flow ID for sending Packets to Host for Slice0 */ +#define PSI_L_REGULAR_FLOW_ID_BASE_OFFSET 0x0024 + +/* Same as PSI_L_REGULAR_FLOW_ID_BASE_OFFSET */ +#define EMAC_ICSSG_SWITCH_PSI_L_REGULAR_FLOW_ID_BASE_OFFSET PSI_L_REGULAR_FLOW_ID_BASE_OFFSET + +/* Base Flow ID for sending mgmt and Tx TS to Host for Slice0 */ +#define PSI_L_MGMT_FLOW_ID_OFFSET 0x0026 + +/* Same as PSI_L_MGMT_FLOW_ID_OFFSET */ +#define EMAC_ICSSG_SWITCH_PSI_L_MGMT_FLOW_ID_BASE_OFFSET PSI_L_MGMT_FLOW_ID_OFFSET + +/* Queue number for Special Packets written here */ +#define SPL_PKT_DEFAULT_PRIORITY 0x0028 + +/* Express Preemptible Queue Mask */ +#define EXPRESS_PRE_EMPTIVE_Q_MASK 0x0029 + +/* Port1/Port2 Default Queue number for untagged Packets, only 1B is used */ +#define QUEUE_NUM_UNTAGGED 0x002A + +/* Stores the table used for priority regeneration. 1B per PCP/Queue */ +#define PORT_Q_PRIORITY_REGEN_OFFSET 0x002C + +/* For marking Packet as priority/express (this feature is disabled) or +* cut-through/S&F. +*/ +#define EXPRESS_PRE_EMPTIVE_Q_MAP 0x0034 + +/* Stores the table used for priority mapping. 1B per PCP/Queue */ +#define PORT_Q_PRIORITY_MAPPING_OFFSET 0x003C + +/* Used to notify the FW of the current link speed */ +#define PORT_LINK_SPEED_OFFSET 0x00A8 + +/* TAS gate mask for windows list0 */ +#define TAS_GATE_MASK_LIST0 0x0100 + +/* TAS gate mask for windows list1 */ +#define TAS_GATE_MASK_LIST1 0x0350 + +/* Memory to Enable/Disable Preemption on TX side */ +#define PRE_EMPTION_ENABLE_TX 0x05A0 + +/* Active State of Preemption on TX side */ +#define PRE_EMPTION_ACTIVE_TX 0x05A1 + +/* Memory to Enable/Disable Verify State Machine Preemption */ +#define PRE_EMPTION_ENABLE_VERIFY 0x05A2 + +/* Verify Status of State Machine */ +#define PRE_EMPTION_VERIFY_STATUS 0x05A3 + +/* Non Final Fragment Size supported by Link Partner */ +#define PRE_EMPTION_ADD_FRAG_SIZE_REMOTE 0x05A4 + +/* Non Final Fragment Size supported by Firmware */ +#define PRE_EMPTION_ADD_FRAG_SIZE_LOCAL 0x05A6 + +/* Time in ms the State machine waits for respond Packet */ +#define PRE_EMPTION_VERIFY_TIME 0x05A8 + +/* Memory used for R30 related management commands */ +#define MGR_R30_CMD_OFFSET 0x05AC + +/* HW Buffer Pool0 base address */ +#define BUFFER_POOL_0_ADDR_OFFSET 0x05BC + +/* 16B for Host Egress MSMC Q (Pre-emptible) context */ +#define HOST_RX_Q_PRE_CONTEXT_OFFSET 0x0684 + +/* Buffer for 8 FDB entries to be added by 'Add Multiple FDB entries IOCTL' */ +#define FDB_CMD_BUFFER 0x0894 + +/* TAS queue max sdu length list */ +#define TAS_QUEUE_MAX_SDU_LIST 0x08FA + +/* Used by FW to generate random number with the SEED value */ +#define HD_RAND_SEED_OFFSET 0x0934 + +/* 16B for Host Egress MSMC Q (Express) context */ +#define HOST_RX_Q_EXP_CONTEXT_OFFSET 0x0940 + +/* Start of 32 bits PA_STAT counters */ +#define PA_STAT_32b_START_OFFSET 0x0080 + +#endif /* __NET_TI_ICSSG_SWITCH_MAP_H */
Signature · 1 line
2.34.1
MD Danish Anwar
reviewerPATCH v11 2/10 net: ti: icssg-prueth: Add mii helper apis and macros
In reply to MD Danish AnwarAdd MII helper APIs and MACROs. These APIs and MACROs will be later used by ICSSG Ethernet driver. Also introduce icssg_prueth.h which has definition of prueth related structures.
--- drivers/net/ethernet/ti/icssg_mii_cfg.c | 120 +++++++++++++++ drivers/net/ethernet/ti/icssg_mii_rt.h | 151 ++++++++++++++++++ drivers/net/ethernet/ti/icssg_prueth.h | 197 ++++++++++++++++++++++++ 3 files changed, 468 insertions(+) create mode 100644 drivers/net/ethernet/ti/icssg_mii_cfg.c create mode 100644 drivers/net/ethernet/ti/icssg_mii_rt.h create mode 100644 drivers/net/ethernet/ti/icssg_prueth.h
drivers/net/ethernet/ti/icssg_mii_cfg.c new file +120 -0
@@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Texas Instruments ICSSG Ethernet Driver +* +* Copyright (C) 2018-2022 Texas Instruments Incorporated - https://www.ti.com/ +* +*/ + +#include <linux/etherdevice.h> +#include <linux/regmap.h> +#include <linux/types.h> + +#include "icssg_mii_rt.h" +#include "icssg_prueth.h" + +void icssg_mii_update_ipg (struct regmap *mii_rt,int mii,u32 ipg) +{ +u32 val; + +if (mii ==ICSS_MII0 ) { +regmap_write (mii_rt,PRUSS_MII_RT_TX_IPG0 , ipg); + }else { +regmap_read (mii_rt,PRUSS_MII_RT_TX_IPG0 , &val); +regmap_write (mii_rt,PRUSS_MII_RT_TX_IPG1 , ipg); +regmap_write (mii_rt,PRUSS_MII_RT_TX_IPG0 , val); + } +} + +void icssg_mii_update_mtu (struct regmap *mii_rt,int mii,int mtu) +{ + mtu += (ETH_HLEN +ETH_FCS_LEN ); +if (mii ==ICSS_MII0 ) { +regmap_update_bits (mii_rt, +PRUSS_MII_RT_RX_FRMS0 , +PRUSS_MII_RT_RX_FRMS_MAX_FRM_MASK , + (mtu -1 ) <<PRUSS_MII_RT_RX_FRMS_MAX_FRM_SHIFT ); + }else { +regmap_update_bits (mii_rt, +PRUSS_MII_RT_RX_FRMS1 , +PRUSS_MII_RT_RX_FRMS_MAX_FRM_MASK , + (mtu -1 ) <<PRUSS_MII_RT_RX_FRMS_MAX_FRM_SHIFT ); + } +} + +void icssg_update_rgmii_cfg (struct regmap *miig_rt,struct prueth_emac *emac) +{ +u32 gig_en_mask, gig_val =0 , full_duplex_mask, full_duplex_val =0 ; +int slice =prueth_emac_slice (emac); +u32 inband_en_mask, inband_val =0 ; + + gig_en_mask = (slice ==ICSS_MII0 ) ?RGMII_CFG_GIG_EN_MII0 : +RGMII_CFG_GIG_EN_MII1 ; +if (emac->speed ==SPEED_1000 ) + gig_val = gig_en_mask; +regmap_update_bits (miig_rt,RGMII_CFG_OFFSET , gig_en_mask, gig_val); + + inband_en_mask = (slice ==ICSS_MII0 ) ?RGMII_CFG_INBAND_EN_MII0 : +RGMII_CFG_INBAND_EN_MII1 ; +if (emac->speed ==SPEED_10 &&phy_interface_mode_is_rgmii (emac->phy_if)) + inband_val = inband_en_mask; +regmap_update_bits (miig_rt,RGMII_CFG_OFFSET , inband_en_mask, inband_val); + + full_duplex_mask = (slice ==ICSS_MII0 ) ?RGMII_CFG_FULL_DUPLEX_MII0 : +RGMII_CFG_FULL_DUPLEX_MII1 ; +if (emac->duplex ==DUPLEX_FULL ) + full_duplex_val = full_duplex_mask; +regmap_update_bits (miig_rt,RGMII_CFG_OFFSET , full_duplex_mask, + full_duplex_val); +} + +void icssg_miig_set_interface_mode (struct regmap *miig_rt,int mii,phy_interface_t phy_if) +{ +u32 val, mask, shift; + + mask = mii ==ICSS_MII0 ?ICSSG_CFG_MII0_MODE :ICSSG_CFG_MII1_MODE ; + shift = mii ==ICSS_MII0 ?ICSSG_CFG_MII0_MODE_SHIFT :ICSSG_CFG_MII1_MODE_SHIFT ; + + val =MII_MODE_RGMII ; +if (phy_if ==PHY_INTERFACE_MODE_MII ) + val =MII_MODE_MII ; + + val <<= shift; +regmap_update_bits (miig_rt,ICSSG_CFG_OFFSET , mask, val); +regmap_read (miig_rt,ICSSG_CFG_OFFSET , &val); +} + +u32 icssg_rgmii_cfg_get_bitfield (struct regmap *miig_rt,u32 mask,u32 shift) +{ +u32 val; + +regmap_read (miig_rt,RGMII_CFG_OFFSET , &val); + val &= mask; + val >>= shift; + +return val; +} + +u32 icssg_rgmii_get_speed (struct regmap *miig_rt,int mii) +{ +u32 shift =RGMII_CFG_SPEED_MII0_SHIFT , mask =RGMII_CFG_SPEED_MII0 ; + +if (mii ==ICSS_MII1 ) { + shift =RGMII_CFG_SPEED_MII1_SHIFT ; + mask =RGMII_CFG_SPEED_MII1 ; + } + +return icssg_rgmii_cfg_get_bitfield (miig_rt, mask, shift); +} + +u32 icssg_rgmii_get_fullduplex (struct regmap *miig_rt,int mii) +{ +u32 shift =RGMII_CFG_FULLDUPLEX_MII0_SHIFT ; +u32 mask =RGMII_CFG_FULLDUPLEX_MII0 ; + +if (mii ==ICSS_MII1 ) { + shift =RGMII_CFG_FULLDUPLEX_MII1_SHIFT ; + mask =RGMII_CFG_FULLDUPLEX_MII1 ; + } + +return icssg_rgmii_cfg_get_bitfield (miig_rt, mask, shift); +}
drivers/net/ethernet/ti/icssg_mii_rt.h new file +151 -0
151 lines not on this page · raw message
drivers/net/ethernet/ti/icssg_prueth.h new file +197 -0
197 lines not on this page · raw message
Signature · 1 line
2.34.1
MD Danish Anwar
reviewerPATCH v11 3/10 net: ti: icssg-prueth: Add Firmware config and classification APIs.
In reply to MD Danish AnwarAdd icssg_config.h / .c and icssg_classifier.c files. These are firmware configuration and classification related files. These will be used by ICSSG ethernet driver.
--- drivers/net/ethernet/ti/icssg_classifier.c | 367 +++++++++++++++++ drivers/net/ethernet/ti/icssg_config.c | 450 +++++++++++++++++++++ drivers/net/ethernet/ti/icssg_config.h | 200 +++++++++ 3 files changed, 1017 insertions(+) create mode 100644 drivers/net/ethernet/ti/icssg_classifier.c create mode 100644 drivers/net/ethernet/ti/icssg_config.c create mode 100644 drivers/net/ethernet/ti/icssg_config.h
drivers/net/ethernet/ti/icssg_classifier.c new file +367 -0
@@ -0,0 +1,367 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Texas Instruments ICSSG Ethernet Driver +* +* Copyright (C) 2018-2022 Texas Instruments Incorporated - https://www.ti.com/ +* +*/ + +#include <linux/etherdevice.h> +#include <linux/types.h> +#include <linux/regmap.h> + +#include "icssg_prueth.h" + +#define ICSSG_NUM_CLASSIFIERS 16 +#define ICSSG_NUM_FT1_SLOTS 8 +#define ICSSG_NUM_FT3_SLOTS 16 + +#define ICSSG_NUM_CLASSIFIERS_IN_USE 5 + +/* Filter 1 - FT1 */ +#define FT1_NUM_SLOTS 8 +#define FT1_SLOT_SIZE 0x10/* bytes */ + +/* offsets from FT1 slot base i.e. slot 1 start */ +#define FT1_DA0 0x0 +#define FT1_DA1 0x4 +#define FT1_DA0_MASK 0x8 +#define FT1_DA1_MASK 0xc + +#define FT1_N_REG (slize, n, reg) \ + (offs[slice].ft1_slot_base + FT1_SLOT_SIZE * (n) + (reg)) + +#define FT1_LEN_MASK GENMASK(19, 16) +#define FT1_LEN_SHIFT 16 +#define FT1_LEN (len) (((len) << FT1_LEN_SHIFT) & FT1_LEN_MASK) +#define FT1_START_MASK GENMASK(14, 0) +#define FT1_START (start) ((start) & FT1_START_MASK) +#define FT1_MATCH_SLOT (n) (GENMASK(23, 16) & (BIT(n) << 16)) + +/* FT1 config type */ +enum ft1_cfg_type { +FT1_CFG_TYPE_DISABLED =0 , +FT1_CFG_TYPE_EQ , +FT1_CFG_TYPE_GT , +FT1_CFG_TYPE_LT , +}; + +#define FT1_CFG_SHIFT (n) (2 * (n)) +#define FT1_CFG_MASK (n) (0x3 << FT1_CFG_SHIFT((n))) + +/* Filter 3 - FT3 */ +#define FT3_NUM_SLOTS 16 +#define FT3_SLOT_SIZE 0x20/* bytes */ + +/* offsets from FT3 slot n's base */ +#define FT3_START 0 +#define FT3_START_AUTO 0x4 +#define FT3_START_OFFSET 0x8 +#define FT3_JUMP_OFFSET 0xc +#define FT3_LEN 0x10 +#define FT3_CFG 0x14 +#define FT3_T 0x18 +#define FT3_T_MASK 0x1c + +#define FT3_N_REG (slize, n, reg) \ + (offs[slice].ft3_slot_base + FT3_SLOT_SIZE * (n) + (reg)) + +/* offsets from rx_class n's base */ +#define RX_CLASS_AND_EN 0 +#define RX_CLASS_OR_EN 0x4 +#define RX_CLASS_NUM_SLOTS 16 +#define RX_CLASS_EN_SIZE 0x8/* bytes */ + +#define RX_CLASS_N_REG (slice, n, reg) \ + (offs[slice].rx_class_base + RX_CLASS_EN_SIZE * (n) + (reg)) + +/* RX Class Gates */ +#define RX_CLASS_GATES_SIZE 0x4/* bytes */ + +#define RX_CLASS_GATES_N_REG (slice, n) \ + (offs[slice].rx_class_gates_base + RX_CLASS_GATES_SIZE * (n)) + +#define RX_CLASS_GATES_ALLOW_MASK BIT(6) +#define RX_CLASS_GATES_RAW_MASK BIT(5) +#define RX_CLASS_GATES_PHASE_MASK BIT(4) + +/* RX Class traffic data matching bits */ +#define RX_CLASS_FT_UC BIT(31) +#define RX_CLASS_FT_MC BIT(30) +#define RX_CLASS_FT_BC BIT(29) +#define RX_CLASS_FT_FW BIT(28) +#define RX_CLASS_FT_RCV BIT(27) +#define RX_CLASS_FT_VLAN BIT(26) +#define RX_CLASS_FT_DA_P BIT(25) +#define RX_CLASS_FT_DA_I BIT(24) +#define RX_CLASS_FT_FT1_MATCH_MASK GENMASK(23, 16) +#define RX_CLASS_FT_FT1_MATCH_SHIFT 16 +#define RX_CLASS_FT_FT3_MATCH_MASK GENMASK(15, 0) +#define RX_CLASS_FT_FT3_MATCH_SHIFT 0 + +#define RX_CLASS_FT_FT1_MATCH (slot) \ + ((BIT(slot) << RX_CLASS_FT_FT1_MATCH_SHIFT) & \ + RX_CLASS_FT_FT1_MATCH_MASK) + +/* RX class type */ +enum rx_class_sel_type { +RX_CLASS_SEL_TYPE_OR =0 , +RX_CLASS_SEL_TYPE_AND =1 , +RX_CLASS_SEL_TYPE_OR_AND_AND =2 , +RX_CLASS_SEL_TYPE_OR_OR_AND =3 , +}; + +#define FT1_CFG_SHIFT (n) (2 * (n)) +#define FT1_CFG_MASK (n) (0x3 << FT1_CFG_SHIFT((n))) + +#define RX_CLASS_SEL_SHIFT (n) (2 * (n)) +#define RX_CLASS_SEL_MASK (n) (0x3 << RX_CLASS_SEL_SHIFT((n))) + +#define ICSSG_CFG_OFFSET 0 +#define MAC_INTERFACE_0 0x18 +#define MAC_INTERFACE_1 0x1c + +#define ICSSG_CFG_RX_L2_G_EN BIT(2) + +/* These are register offsets per PRU */ +struct miig_rt_offsets { +u32 mac0; +u32 mac1; +u32 ft1_start_len; +u32 ft1_cfg; +u32 ft1_slot_base; +u32 ft3_slot_base; +u32 ft3_p_base; +u32 ft_rx_ptr; +u32 rx_class_base; +u32 rx_class_cfg1; +u32 rx_class_cfg2; +u32 rx_class_gates_base; +u32 rx_green; +u32 rx_rate_cfg_base; +u32 rx_rate_src_sel0; +u32 rx_rate_src_sel1; +u32 tx_rate_cfg_base; +u32 stat_base; +u32 tx_hsr_tag; +u32 tx_hsr_seq; +u32 tx_vlan_type; +u32 tx_vlan_ins; +}; + +/* These are the offset values for miig_rt_offsets registers */ +static const struct miig_rt_offsets offs[] = { +/* PRU0 */ + { +0x8 , +0xc , +0x80 , +0x84 , +0x88 , +0x108 , +0x308 , +0x408 , +0x40c , +0x48c , +0x490 , +0x494 , +0x4d4 , +0x4e4 , +0x504 , +0x508 , +0x50c , +0x54c , +0x63c , +0x640 , +0x644 , +0x648 , + }, +/* PRU1 */ + { +0x10 , +0x14 , +0x64c , +0x650 , +0x654 , +0x6d4 , +0x8d4 , +0x9d4 , +0x9d8 , +0xa58 , +0xa5c , +0xa60 , +0xaa0 , +0xab0 , +0xad0 , +0xad4 , +0xad8 , +0xb18 , +0xc08 , +0xc0c , +0xc10 , +0xc14 , + }, +}; + +static void rx_class_ft1_set_start_len (struct regmap *miig_rt,int slice, +u16 start,u8 len) +{ +u32 offset, val; + + offset = offs[slice].ft1_start_len; + val =FT1_LEN (len) |FT1_START (start); +regmap_write (miig_rt, offset, val); +} + +static void rx_class_ft1_set_da (struct regmap *miig_rt,int slice, +int n,const u8 *addr) +{ +u32 offset; + + offset =FT1_N_REG (slice, n,FT1_DA0 ); +regmap_write (miig_rt, offset, (u32)(addr[0 ] | addr[1 ] <<8 | + addr[2 ] <<16 | addr[3 ] <<24 )); + offset =FT1_N_REG (slice, n,FT1_DA1 ); +regmap_write (miig_rt, offset, (u32)(addr[4 ] | addr[5 ] <<8 )); +} + +static void rx_class_ft1_set_da_mask (struct regmap *miig_rt,int slice, +int n,const u8 *addr) +{ +u32 offset; + + offset =FT1_N_REG (slice, n,FT1_DA0_MASK ); +regmap_write (miig_rt, offset, (u32)(addr[0 ] | addr[1 ] <<8 | + addr[2 ] <<16 | addr[3 ] <<24 )); + offset =FT1_N_REG (slice, n,FT1_DA1_MASK ); +regmap_write (miig_rt, offset, (u32)(addr[4 ] | addr[5 ] <<8 )); +} + +static void rx_class_ft1_cfg_set_type (struct regmap *miig_rt,int slice,int n, +enum ft1_cfg_type type) +{ +u32 offset; + + offset = offs[slice].ft1_cfg; +regmap_update_bits (miig_rt, offset,FT1_CFG_MASK (n), + type <<FT1_CFG_SHIFT (n)); +} + +static void rx_class_sel_set_type (struct regmap *miig_rt,int slice,int n, +enum rx_class_sel_type type) +{ +u32 offset; + + offset = offs[slice].rx_class_cfg1; +regmap_update_bits (miig_rt, offset,RX_CLASS_SEL_MASK (n), + type <<RX_CLASS_SEL_SHIFT (n)); +} + +static void rx_class_set_and (struct regmap *miig_rt,int slice,int n, +u32 data) +{ +u32 offset; + + offset =RX_CLASS_N_REG (slice, n,RX_CLASS_AND_EN ); +regmap_write (miig_rt, offset, data); +} + +static void rx_class_set_or (struct regmap *miig_rt,int slice,int n, +u32 data) +{ +u32 offset; + + offset =RX_CLASS_N_REG (slice, n,RX_CLASS_OR_EN ); +regmap_write (miig_rt, offset, data); +} + +void icssg_class_set_host_mac_addr (struct regmap *miig_rt,const u8 *mac) +{ +regmap_write (miig_rt,MAC_INTERFACE_0 , (u32)(mac[0 ] | mac[1 ] <<8 | + mac[2 ] <<16 | mac[3 ] <<24 )); +regmap_write (miig_rt,MAC_INTERFACE_1 , (u32)(mac[4 ] | mac[5 ] <<8 )); +} + +void icssg_class_set_mac_addr (struct regmap *miig_rt,int slice,u8 *mac) +{ +regmap_write (miig_rt, offs[slice].mac0, (u32)(mac[0 ] | mac[1 ] <<8 | + mac[2 ] <<16 | mac[3 ] <<24 )); +regmap_write (miig_rt, offs[slice].mac1, (u32)(mac[4 ] | mac[5 ] <<8 )); +} + +/* disable all RX traffic */ +void icssg_class_disable (struct regmap *miig_rt,int slice) +{ +u32 data, offset; +int n; + +/* Enable RX_L2_G */ +regmap_update_bits (miig_rt,ICSSG_CFG_OFFSET ,ICSSG_CFG_RX_L2_G_EN , +ICSSG_CFG_RX_L2_G_EN ); + +for (n =0 ; n <ICSSG_NUM_CLASSIFIERS ; n++) { +/* AND_EN = 0 */ +rx_class_set_and (miig_rt, slice, n,0 ); +/* OR_EN = 0 */ +rx_class_set_or (miig_rt, slice, n,0 ); + +/* set CFG1 to OR */ +rx_class_sel_set_type (miig_rt, slice, n,RX_CLASS_SEL_TYPE_OR ); + +/* configure gate */ + offset =RX_CLASS_GATES_N_REG (slice, n); +regmap_read (miig_rt, offset, &data); +/* clear class_raw so we go through filters */ + data &= ~RX_CLASS_GATES_RAW_MASK ; +/* set allow and phase mask */ + data |=RX_CLASS_GATES_ALLOW_MASK |RX_CLASS_GATES_PHASE_MASK ; +regmap_write (miig_rt, offset, data); + } + +/* FT1 Disabled */ +for (n =0 ; n <ICSSG_NUM_FT1_SLOTS ; n++) { +const u8 addr[] = {0 ,0 ,0 ,0 ,0 ,0 , }; + +rx_class_ft1_cfg_set_type (miig_rt, slice, n, +FT1_CFG_TYPE_DISABLED ); +rx_class_ft1_set_da (miig_rt, slice, n, addr); +rx_class_ft1_set_da_mask (miig_rt, slice, n, addr); + } + +/* clear CFG2 */ +regmap_write (miig_rt, offs[slice].rx_class_cfg2,0 ); +} + +void icssg_class_default (struct regmap *miig_rt,int slice,bool allmulti) +{ +u32 data; + +/* defaults */ +icssg_class_disable (miig_rt, slice); + +/* Setup Classifier */ +/* match on Broadcast or MAC_PRU address */ + data =RX_CLASS_FT_BC |RX_CLASS_FT_DA_P ; + +/* multicast */ +if (allmulti) + data |=RX_CLASS_FT_MC ; + +rx_class_set_or (miig_rt, slice,0 , data); + +/* set CFG1 for OR_OR_AND for classifier */ +rx_class_sel_set_type (miig_rt, slice,0 ,RX_CLASS_SEL_TYPE_OR_OR_AND ); + +/* clear CFG2 */ +regmap_write (miig_rt, offs[slice].rx_class_cfg2,0 ); +} + +/* required for SAV check */ +void icssg_ft1_set_mac_addr (struct regmap *miig_rt,int slice,u8 *mac_addr) +{ +const u8 mask_addr[] = {0 ,0 ,0 ,0 ,0 ,0 , }; + +rx_class_ft1_set_start_len (miig_rt, slice,0 ,6 ); +rx_class_ft1_set_da (miig_rt, slice,0 , mac_addr); +rx_class_ft1_set_da_mask (miig_rt, slice,0 , mask_addr); +rx_class_ft1_cfg_set_type (miig_rt, slice,0 ,FT1_CFG_TYPE_EQ ); +}
drivers/net/ethernet/ti/icssg_config.c new file +450 -0
450 lines not on this page · raw message
drivers/net/ethernet/ti/icssg_config.h new file +200 -0
200 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v11 03/10] net: ti: icssg-prueth: Add Firmware config and classification APIs.
Quoted 6 lines · MD Danish Anwar
Add
icssg_config.h/ .c andicssg_classifier.cfiles. These are firmware configuration and classification related files. These will be used by ICSSG ethernet driver.Signed-off-by MD Danish Anwar <[email protected]>Reviewed-by Andrew Lunn <[email protected]>
Hi Danish,
some feedback from my side.
...
Quoted 1 line
drivers/net/ethernet/ti/icssg_classifier.c +0
-0
...
Quoted 1 line
+void
icssg_class_set_mac_addr(struct regmap *miig_rt, int slice, u8 *mac)
This function appears to be unused.
Perhaps it would be better placed in a later patch?
Or perhaps not, if it makes it hard to split up the patches nicely. In which case, perhaps the __maybe_unused annotation could be added, temporarily.
Flagged by clang-16 W=1, and gcc=12 W=1 builds.
Likewise for other issues flagged below regarding
function declarations/definitions.
drivers/net/ethernet/ti/icssg_classifier.c line 292
Quoted 8 lines
drivers/net/ethernet/ti/icssg_classifier.c +8
-0+{ +regmap_write (miig_rt, offs[slice].mac0, (u32)(mac[0 ] | mac[1 ] <<8 | + mac[2 ] <<16 | mac[3 ] <<24 )); +regmap_write (miig_rt, offs[slice].mac1, (u32)(mac[4 ] | mac[5 ] <<8 )); +} + +/* disable all RX traffic */ +void icssg_class_disable (struct regmap *miig_rt,int slice)
This function is only used in this file.
Please consider making it static.
...
Quoted 1 line
+void
icssg_class_default(struct regmap *miig_rt, int slice, bool allmulti)
This function also appears to be unused.
...
drivers/net/ethernet/ti/icssg_classifier.c line 359
Quoted 2 lines
drivers/net/ethernet/ti/icssg_classifier.c +2
-0+/* required for SAV check */ +void icssg_ft1_set_mac_addr (struct regmap *miig_rt,int slice,u8 *mac_addr)
This function also appears to be unused.
...
Quoted 1 line
drivers/net/ethernet/ti/icssg_config.c +0
-0
...
Quoted 1 line
+void
icssg_config_ipg(struct prueth_emac *emac)
This function is also only used in this file.
...
Quoted 5 lines
drivers/net/ethernet/ti/icssg_config.c +5
-0+static void icssg_init_emac_mode (struct prueth *prueth) +{ +/* When the device is configured as a bridge and it is being brought +* back to the emac mode, the host mac address has to be set as 0. +*/
drivers/net/ethernet/ti/icssg_config.c line 321
Quoted 10 lines
drivers/net/ethernet/ti/icssg_config.c +10
-0+u8 mac[ETH_ALEN ] = {0 }; + +if (prueth->emacs_initialized) +return ; + +regmap_update_bits (prueth->miig_rt,FDB_GEN_CFG1 , +SMEM_VLAN_OFFSET_MASK ,0 ); +regmap_write (prueth->miig_rt,FDB_GEN_CFG2 ,0 ); +/* Clear host MAC address */ +icssg_class_set_host_mac_addr (prueth->miig_rt, mac);
icssg_class_set_host_mac_addr() is defined in icssg_classifier.c but used here in icssg_config.c.
Please consider providing a declaration of this function, ideally in a .h file.
...
drivers/net/ethernet/ti/icssg_config.c line 400
Quoted 2 lines
drivers/net/ethernet/ti/icssg_config.c +2
-0+int emac_set_port_state (struct prueth_emac *emac, +enum icssg_port_state_cmd cmd)
This function also appears to be unused.
...
Quoted 1 line
+void
icssg_config_set_speed(struct prueth_emac *emac)
Ditto.
...
Re: [EXTERNAL] Re: [PATCH v11 03/10] net: ti: icssg-prueth: Add Firmware config and classification APIs.
Hi Simon,
Quoted 5 lines · Simon Horman
Quoted 4 lines · MD Danish Anwar
Add
icssg_config.h/ .c andicssg_classifier.cfiles. These are firmware configuration and classification related files. These will be used by ICSSG ethernet driver.
Quoted 7 lines
Quoted 2 lines
Signed-off-by MD Danish Anwar <[email protected]>Reviewed-by Andrew Lunn <[email protected]>Hi Danish,
some feedback from my side.
Thanks for the feedback.
Quoted 6 lines
...
Quoted 1 line
drivers/net/ethernet/ti/icssg_classifier.c +0
-0...
Quoted 9 lines
Quoted 1 line
+void
icssg_class_set_mac_addr(struct regmap *miig_rt, int slice, u8 *mac)This function appears to be unused.
Perhaps it would be better placed in a later patch?Or perhaps not, if it makes it hard to split up the patches nicely. In which case, perhaps the
__maybe_unusedannotation could be added, temporarily.
Due to splitting the patch into 8-9 patches, I had to introduce these helper APIs earlier. All these APIs are helper APIs, they will be used in patch 6 (Introduce ICSSG Prueth driver).
I had this concern that some APIs which will be used later but introduced earlier can create some warnings, before splitting the patches.
I had raised this concern in [1] and asked Jakub if it would be OK to introduce these APIs earlier. Jakub said it would be fine [2], so I went ahead with this approach.
It will make very hard to break patches if these APIs are introduced and used in same patch.
Quoted 4 lines
Flagged by clang-16 W=1, and gcc=12 W=1 builds.
Likewise for other issues flagged below regarding
function declarations/definitions.
Quoted 12 lines
drivers/net/ethernet/ti/icssg_classifier.c line 292
Quoted 8 lines
drivers/net/ethernet/ti/icssg_classifier.c +8
-0+{ +regmap_write (miig_rt, offs[slice].mac0, (u32)(mac[0 ] | mac[1 ] <<8 | + mac[2 ] <<16 | mac[3 ] <<24 )); +regmap_write (miig_rt, offs[slice].mac1, (u32)(mac[4 ] | mac[5 ] <<8 )); +} + +/* disable all RX traffic */ +void icssg_class_disable (struct regmap *miig_rt,int slice)This function is only used in this file.
Please consider making it static.
This is later used in icssg_prueth.c, that is why this is not static.
Quoted 6 lines
...
Quoted 1 line
+void
icssg_class_default(struct regmap *miig_rt, int slice, bool allmulti)This function also appears to be unused.
This is later used in icssg_prueth.c
Quoted 7 lines
...
drivers/net/ethernet/ti/icssg_classifier.c line 359
Quoted 2 lines
drivers/net/ethernet/ti/icssg_classifier.c +2
-0+/* required for SAV check */ +void icssg_ft1_set_mac_addr (struct regmap *miig_rt,int slice,u8 *mac_addr)This function also appears to be unused.
This is later used in icssg_prueth.c
Quoted 10 lines
...
Quoted 1 line
drivers/net/ethernet/ti/icssg_config.c +0
-0...
Quoted 1 line
+void
icssg_config_ipg(struct prueth_emac *emac)This function is also only used in this file.
This is later used in icssg_prueth.c
Quoted 18 lines
...
Quoted 5 lines
drivers/net/ethernet/ti/icssg_config.c +5
-0+static void icssg_init_emac_mode (struct prueth *prueth) +{ +/* When the device is configured as a bridge and it is being brought +* back to the emac mode, the host mac address has to be set as 0. +*/ drivers/net/ethernet/ti/icssg_config.c line 321
Quoted 10 lines
drivers/net/ethernet/ti/icssg_config.c +10
-0+u8 mac[ETH_ALEN ] = {0 }; + +if (prueth->emacs_initialized) +return ; + +regmap_update_bits (prueth->miig_rt,FDB_GEN_CFG1 , +SMEM_VLAN_OFFSET_MASK ,0 ); +regmap_write (prueth->miig_rt,FDB_GEN_CFG2 ,0 ); +/* Clear host MAC address */ +icssg_class_set_host_mac_addr (prueth->miig_rt, mac);
This is later used in icssg_prueth.c
Quoted 6 lines
icssg_class_set_host_mac_addr()is defined inicssg_classifier.cbut used here inicssg_config.c.Please consider providing a declaration of this function, ideally in a .h file.
The declaration of this function is added later(in patch 6) in icssg_prueth.h
Quoted 7 lines
...
drivers/net/ethernet/ti/icssg_config.c line 400
Quoted 2 lines
drivers/net/ethernet/ti/icssg_config.c +2
-0+int emac_set_port_state (struct prueth_emac *emac, +enum icssg_port_state_cmd cmd)This function also appears to be unused.
Quoted 6 lines
...
Quoted 1 line
+void
icssg_config_set_speed(struct prueth_emac *emac)Ditto.
Both these APIs are later used in icssg_prueth.c
Quoted 1 line
...
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
Signature · 2 lines
Thanks and Regards, Danish.
Re: [EXTERNAL] Re: [PATCH v11 03/10] net: ti: icssg-prueth: Add Firmware config and classification APIs.
Quoted 41 lines · Md Danish Anwar
Hi Simon,
Quoted 5 lines · Simon Horman
Quoted 4 lines · MD Danish Anwar
Add
icssg_config.h/ .c andicssg_classifier.cfiles. These are firmware configuration and classification related files. These will be used by ICSSG ethernet driver.Quoted 7 lines
Quoted 2 lines
Signed-off-by MD Danish Anwar <[email protected]>Reviewed-by Andrew Lunn <[email protected]>Hi Danish,
some feedback from my side.
Thanks for the feedback.
Quoted 6 lines
...
Quoted 1 line
drivers/net/ethernet/ti/icssg_classifier.c +0
-0...
Quoted 9 lines
Quoted 1 line
+void
icssg_class_set_mac_addr(struct regmap *miig_rt, int slice, u8 *mac)This function appears to be unused.
Perhaps it would be better placed in a later patch?Or perhaps not, if it makes it hard to split up the patches nicely. In which case, perhaps the
__maybe_unusedannotation could be added, temporarily.Due to splitting the patch into 8-9 patches, I had to introduce these helper APIs earlier. All these APIs are helper APIs, they will be used in patch 6 (Introduce ICSSG Prueth driver).
I had this concern that some APIs which will be used later but introduced earlier can create some warnings, before splitting the patches.
Quoted 6 lines
I had raised this concern in [1] and asked Jakub if it would be OK to introduce these APIs earlier. Jakub said it would be fine [2], so I went ahead with this approach.
It will make very hard to break patches if these APIs are introduced and used in same patch.
Thanks, I understand.
In that case my suggestion is to, temporarily, add __maybe_unused, which will allow static analysis tools to work more cleanly over the series. It is just a suggestion, not a hard requirement.
Probably something along those lines applies to all the review I provided in my previous email. Please use your discretion here.
Re: [EXTERNAL] Re: [EXTERNAL] Re: [PATCH v11 03/10] net: ti: icssg-prueth: Add Firmware config and classification APIs.
Quoted 49 lines · Simon Horman
Quoted 41 lines · Md Danish Anwar
Hi Simon,
Quoted 5 lines · Simon Horman
Quoted 4 lines · MD Danish Anwar
Add
icssg_config.h/ .c andicssg_classifier.cfiles. These are firmware configuration and classification related files. These will be used by ICSSG ethernet driver.Quoted 7 lines
Quoted 2 lines
Signed-off-by MD Danish Anwar <[email protected]>Reviewed-by Andrew Lunn <[email protected]>Hi Danish,
some feedback from my side.
Thanks for the feedback.
Quoted 6 lines
...
Quoted 1 line
drivers/net/ethernet/ti/icssg_classifier.c +0
-0...
Quoted 9 lines
Quoted 1 line
+void
icssg_class_set_mac_addr(struct regmap *miig_rt, int slice, u8 *mac)This function appears to be unused.
Perhaps it would be better placed in a later patch?Or perhaps not, if it makes it hard to split up the patches nicely. In which case, perhaps the
__maybe_unusedannotation could be added, temporarily.Due to splitting the patch into 8-9 patches, I had to introduce these helper APIs earlier. All these APIs are helper APIs, they will be used in patch 6 (Introduce ICSSG Prueth driver).
I had this concern that some APIs which will be used later but introduced earlier can create some warnings, before splitting the patches.
Quoted 6 lines
I had raised this concern in [1] and asked Jakub if it would be OK to introduce these APIs earlier. Jakub said it would be fine [2], so I went ahead with this approach.
It will make very hard to break patches if these APIs are introduced and used in same patch.
Quoted 8 lines
Thanks, I understand.
In that case my suggestion is to, temporarily, add
__maybe_unused, which will allow static analysis tools to work more cleanly over the series. It is just a suggestion, not a hard requirement.Probably something along those lines applies to all the review I provided in my previous email. Please use your discretion here.
For now I think I will leave it as it is. Let reviewers review all other patches. Let's see if there are any other comments on all the patches in this series. If there are any more comments on other patches, then while re-spinning next revision I will keep this in mind and try to add __maybe_unused tags in all APIs that are used later.
The idea behind splitting the patches was to get them reviewed individually as it is quite difficult to get one big patch reviewed as explained by Jakub. And these warnings were expected. If there are any other comments on this series, I will try to address all of them together in next revision.
Meanwhile, Please let me know if you have any comments on other patches in this series.
Signature · 2 lines
Thanks and Regards, Danish.
Re: [EXTERNAL] Re: [EXTERNAL] Re: [PATCH v11 03/10] net: ti: icssg-prueth: Add Firmware config and classification APIs.
Quoted 56 lines · Md Danish Anwar
Quoted 55 lines · Simon Horman
Quoted 41 lines · Md Danish Anwar
Hi Simon,
Quoted 5 lines · Simon Horman
Quoted 4 lines · MD Danish Anwar
Add
icssg_config.h/ .c andicssg_classifier.cfiles. These are firmware configuration and classification related files. These will be used by ICSSG ethernet driver.Quoted 7 lines
Quoted 2 lines
Signed-off-by MD Danish Anwar <[email protected]>Reviewed-by Andrew Lunn <[email protected]>Hi Danish,
some feedback from my side.
Thanks for the feedback.
Quoted 6 lines
...
Quoted 1 line
drivers/net/ethernet/ti/icssg_classifier.c +0
-0...
Quoted 9 lines
Quoted 1 line
+void
icssg_class_set_mac_addr(struct regmap *miig_rt, int slice, u8 *mac)This function appears to be unused.
Perhaps it would be better placed in a later patch?Or perhaps not, if it makes it hard to split up the patches nicely. In which case, perhaps the
__maybe_unusedannotation could be added, temporarily.Due to splitting the patch into 8-9 patches, I had to introduce these helper APIs earlier. All these APIs are helper APIs, they will be used in patch 6 (Introduce ICSSG Prueth driver).
I had this concern that some APIs which will be used later but introduced earlier can create some warnings, before splitting the patches.
Quoted 6 lines
I had raised this concern in [1] and asked Jakub if it would be OK to introduce these APIs earlier. Jakub said it would be fine [2], so I went ahead with this approach.
It will make very hard to break patches if these APIs are introduced and used in same patch.
Thanks, I understand.
In that case my suggestion is to, temporarily, add
__maybe_unused, which will allow static analysis tools to work more cleanly over the series. It is just a suggestion, not a hard requirement.
Quoted 8 lines
Quoted 2 lines
Probably something along those lines applies to all the review I provided in my previous email. Please use your discretion here.
For now I think I will leave it as it is. Let reviewers review all other patches. Let's see if there are any other comments on all the patches in this series. If there are any more comments on other patches, then while re-spinning next revision I will keep this in mind and try to add
__maybe_unusedtags in all APIs that are used later.
Sure, that sounds reasonable.
Quoted 4 lines
The idea behind splitting the patches was to get them reviewed individually as it is quite difficult to get one big patch reviewed as explained by Jakub. And these warnings were expected. If there are any other comments on this series, I will try to address all of them together in next revision.
Yes, I understand.
Thanks for splitting things up into multiple patches. I know that is a lot of work. But it is very helpful.
Quoted 2 lines
Meanwhile, Please let me know if you have any comments on other patches in this series.
Will do, but I nothing to add at this time.
Jakub Kicinski
maintainerRe: [EXTERNAL] Re: [EXTERNAL] Re: [PATCH v11 03/10] net: ti: icssg-prueth: Add Firmware config and classification APIs.
Quoted 2 lines · On Wed, 26 Jul 2023 09:42:17 +0200 Simon Horman wrote:
Thanks for splitting things up into multiple patches. I know that is a lot of work. But it is very helpful.
+1, definitely much easier to review now!
Re: [EXTERNAL] Re: [EXTERNAL] Re: [EXTERNAL] Re: [PATCH v11 03/10] net: ti: icssg-prueth: Add Firmware config and classification APIs.
In reply to Simon HormanQuoted 60 lines · Simon Horman
Quoted 59 lines · Md Danish Anwar
Quoted 57 lines · Simon Horman
Quoted 41 lines · Md Danish Anwar
Hi Simon,
Quoted 5 lines · Simon Horman
Quoted 4 lines · MD Danish Anwar
Add
icssg_config.h/ .c andicssg_classifier.cfiles. These are firmware configuration and classification related files. These will be used by ICSSG ethernet driver.Quoted 7 lines
Quoted 2 lines
Signed-off-by MD Danish Anwar <[email protected]>Reviewed-by Andrew Lunn <[email protected]>Hi Danish,
some feedback from my side.
Thanks for the feedback.
Quoted 6 lines
...
Quoted 1 line
drivers/net/ethernet/ti/icssg_classifier.c +0
-0...
Quoted 9 lines
Quoted 1 line
+void
icssg_class_set_mac_addr(struct regmap *miig_rt, int slice, u8 *mac)This function appears to be unused.
Perhaps it would be better placed in a later patch?Or perhaps not, if it makes it hard to split up the patches nicely. In which case, perhaps the
__maybe_unusedannotation could be added, temporarily.Due to splitting the patch into 8-9 patches, I had to introduce these helper APIs earlier. All these APIs are helper APIs, they will be used in patch 6 (Introduce ICSSG Prueth driver).
I had this concern that some APIs which will be used later but introduced earlier can create some warnings, before splitting the patches.
Quoted 6 lines
I had raised this concern in [1] and asked Jakub if it would be OK to introduce these APIs earlier. Jakub said it would be fine [2], so I went ahead with this approach.
It will make very hard to break patches if these APIs are introduced and used in same patch.
Thanks, I understand.
In that case my suggestion is to, temporarily, add
__maybe_unused, which will allow static analysis tools to work more cleanly over the series. It is just a suggestion, not a hard requirement.Probably something along those lines applies to all the review I provided in my previous email. Please use your discretion here.
Quoted 8 lines
Quoted 5 lines
For now I think I will leave it as it is. Let reviewers review all other patches. Let's see if there are any other comments on all the patches in this series. If there are any more comments on other patches, then while re-spinning next revision I will keep this in mind and try to add
__maybe_unusedtags in all APIs that are used later.Sure, that sounds reasonable.
I will be adding __maybe_unused tags to all the helper APIs introduced before the main driver patch. In the main driver patch I will be removing all those __maybe_unused tags and all the helper APIs will be back to their original name (without __maybe_unused tags)
Quoted 13 lines
Quoted 4 lines
The idea behind splitting the patches was to get them reviewed individually as it is quite difficult to get one big patch reviewed as explained by Jakub. And these warnings were expected. If there are any other comments on this series, I will try to address all of them together in next revision.
Yes, I understand.
Thanks for splitting things up into multiple patches. I know that is a lot of work. But it is very helpful.Quoted 2 lines
Meanwhile, Please let me know if you have any comments on other patches in this series.
Will do, but I nothing to add at this time.
Signature · 2 lines
Thanks and Regards, Md Danish Anwar
MD Danish Anwar
reviewerPATCH v11 4/10 net: ti: icssg-prueth: Add icssg queues APIs and macros
In reply to MD Danish AnwarAdd icssg_queue.c file. This file introduces macros and APIs related to ICSSG queues. These will be used by ICSSG Ethernet driver.
--- drivers/net/ethernet/ti/icssg_queues.c | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 drivers/net/ethernet/ti/icssg_queues.c
drivers/net/ethernet/ti/icssg_queues.c new file +38 -0
@@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0 +/* ICSSG Buffer queue helpers +* +* Copyright (C) 2021 Texas Instruments Incorporated - https://www.ti.com +*/ + +#include <linux/regmap.h> +#include "icssg_prueth.h" + +#define ICSSG_QUEUES_MAX 64 +#define ICSSG_QUEUE_OFFSET 0xd00 +#define ICSSG_QUEUE_PEEK_OFFSET 0xe00 +#define ICSSG_QUEUE_CNT_OFFSET 0xe40 +#define ICSSG_QUEUE_RESET_OFFSET 0xf40 + +int icssg_queue_pop (struct prueth *prueth,u8 queue) +{ +u32 val, cnt; + +if (queue >=ICSSG_QUEUES_MAX ) +return -EINVAL ; + +regmap_read (prueth->miig_rt,ICSSG_QUEUE_CNT_OFFSET +4 * queue, &cnt); +if (!cnt) +return -EINVAL ; + +regmap_read (prueth->miig_rt,ICSSG_QUEUE_OFFSET +4 * queue, &val); + +return val; +} + +void icssg_queue_push (struct prueth *prueth,int queue,u16 addr) +{ +if (queue >=ICSSG_QUEUES_MAX ) +return ; + +regmap_write (prueth->miig_rt,ICSSG_QUEUE_OFFSET +4 * queue, addr); +}
Signature · 1 line
2.34.1
MD Danish Anwar
reviewerPATCH v11 5/10 dt-bindings: net: Add ICSSG Ethernet
In reply to MD Danish AnwarAdd a YAML binding document for the ICSSG Programmable real time unit based Ethernet hardware. The ICSSG driver uses the PRU and PRUSS consumer APIs to interface the PRUs and load/run the firmware for supporting ethernet functionality.
--- .../bindings/net/ti,icssg-prueth.yaml | 184 ++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/ti,icssg-prueth.yaml
Documentation/devicetree/bindings/net/ti,icssg-prueth.yaml new file +184 -0
@@ -0,0 +1,184 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/ti,icssg-prueth.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Texas Instruments ICSSG PRUSS Ethernet + +maintainers: + - Md Danish Anwar <[email protected]> + +description: + Ethernet based on the Programmable Real-Time Unit and Industrial + Communication Subsystem. + +allOf: + - $ref: /schemas/remoteproc/ti,pru-consumer.yaml# + +properties: + compatible: + enum: + - ti,am654-icssg-prueth # for AM65x SoC family + + sram: + $ref: /schemas/types.yaml#/definitions/phandle + description: + phandle to MSMC SRAM node + + dmas: + maxItems: 10 + + dma-names: + items: + - const: tx0-0 + - const: tx0-1 + - const: tx0-2 + - const: tx0-3 + - const: tx1-0 + - const: tx1-1 + - const: tx1-2 + - const: tx1-3 + - const: rx0 + - const: rx1 + + ti,mii-g-rt: + $ref: /schemas/types.yaml#/definitions/phandle + description: + phandle to MII_G_RT module's syscon regmap. + + ti,mii-rt: + $ref: /schemas/types.yaml#/definitions/phandle + description: + phandle to MII_RT module's syscon regmap + + interrupts: + maxItems: 2 + description: + Interrupt specifiers to TX timestamp IRQ. + + interrupt-names: + items: + - const: tx_ts0 + - const: tx_ts1 + + ethernet-ports: + type: object + additionalProperties: false + + properties: + '#address-cells': + const: 1 + '#size-cells': + const: 0 + + patternProperties: + ^port@[0-1]$: + type: object + description: ICSSG PRUETH external ports + $ref: ethernet-controller.yaml# + unevaluatedProperties: false + + properties: + reg: + items: + - enum: [0, 1] + description: ICSSG PRUETH port number + + interrupts: + maxItems: 1 + + ti,syscon-rgmii-delay: + items: + - items: + - description: phandle to system controller node + - description: The offset to ICSSG control register + $ref: /schemas/types.yaml#/definitions/phandle-array + description: + phandle to system controller node and register offset + to ICSSG control register for RGMII transmit delay + + required: + - reg + anyOf: + - required: + - port@0 + - required: + - port@1 + +required: + - compatible + - sram + - dmas + - dma-names + - ethernet-ports + - ti,mii-g-rt + - interrupts + - interrupt-names + +unevaluatedProperties: false + +examples: + - | + /* Example k3-am654 base board SR2.0, dual-emac */ + pruss2_eth: ethernet { + compatible = "ti,am654-icssg-prueth"; + pinctrl-names = "default"; + pinctrl-0 = <&icssg2_rgmii_pins_default>; + sram = <&msmc_ram>; + + ti,prus = <&pru2_0>, <&rtu2_0>, <&tx_pru2_0>, + <&pru2_1>, <&rtu2_1>, <&tx_pru2_1>; + firmware-name = "ti-pruss/am65x-pru0-prueth-fw.elf", + "ti-pruss/am65x-rtu0-prueth-fw.elf", + "ti-pruss/am65x-txpru0-prueth-fw.elf", + "ti-pruss/am65x-pru1-prueth-fw.elf", + "ti-pruss/am65x-rtu1-prueth-fw.elf", + "ti-pruss/am65x-txpru1-prueth-fw.elf"; + ti,pruss-gp-mux-sel = <2>, /* MII mode */ + <2>, + <2>, + <2>, /* MII mode */ + <2>, + <2>; + dmas = <&main_udmap 0xc300>, /* egress slice 0 */ + <&main_udmap 0xc301>, /* egress slice 0 */ + <&main_udmap 0xc302>, /* egress slice 0 */ + <&main_udmap 0xc303>, /* egress slice 0 */ + <&main_udmap 0xc304>, /* egress slice 1 */ + <&main_udmap 0xc305>, /* egress slice 1 */ + <&main_udmap 0xc306>, /* egress slice 1 */ + <&main_udmap 0xc307>, /* egress slice 1 */ + <&main_udmap 0x4300>, /* ingress slice 0 */ + <&main_udmap 0x4301>; /* ingress slice 1 */ + dma-names = "tx0-0", "tx0-1", "tx0-2", "tx0-3", + "tx1-0", "tx1-1", "tx1-2", "tx1-3", + "rx0", "rx1"; + ti,mii-g-rt = <&icssg2_mii_g_rt>; + interrupt-parent = <&icssg2_intc>; + interrupts = <24 0 2>, <25 1 3>; + interrupt-names = "tx_ts0", "tx_ts1"; + ethernet-ports { + #address-cells = <1>; + #size-cells = <0>; + pruss2_emac0: port@0 { + reg = <0>; + phy-handle = <&pruss2_eth0_phy>; + phy-mode = "rgmii-id"; + interrupts-extended = <&icssg2_intc 24>; + ti,syscon-rgmii-delay = <&scm_conf 0x4120>; + /* Filled in by bootloader */ + local-mac-address = [00 00 00 00 00 00]; + }; + + pruss2_emac1: port@1 { + reg = <1>; + phy-handle = <&pruss2_eth1_phy>; + phy-mode = "rgmii-id"; + interrupts-extended = <&icssg2_intc 25>; + ti,syscon-rgmii-delay = <&scm_conf 0x4124>; + /* Filled in by bootloader */ + local-mac-address = [00 00 00 00 00 00]; + }; + }; + };
Signature · 1 line
2.34.1
MD Danish Anwar
reviewerPATCH v11 6/10 net: ti: icssg-prueth: Add ICSSG ethernet driver
In reply to MD Danish AnwarFrom: Roger Quadros <[email protected]>
This is the Ethernet driver for TI AM654 Silicon rev. 2 with the ICSSG PRU Sub-system running dual-EMAC firmware.
The Programmable Real-time Unit and Industrial Communication Subsystem Gigabit (PRU_ICSSG) is a low-latency microcontroller subsystem in the TI SoCs. This subsystem is provided for the use cases like implementation of custom peripheral interfaces, offloading of tasks from the other processor cores of the SoC, etc.
Every ICSSG core has two Programmable Real-Time Unit(PRUs), two auxiliary Real-Time Transfer Unit (RT_PRUs), and
two Transmit Real-Time Transfer Units (TX_PRUs). Each one of these runs its own firmware. Every ICSSG core has two MII ports connect to these PRUs and also a MDIO port.
The cores can run different firmwares to support different protocols and features like switch-dev, timestamping, etc.
It uses System DMA to transfer and receive packets and shared memory register emulation between the firmware and driver for control and configuration.
This patch adds support for basic EMAC functionality with 1Gbps and 100Mbps link speed. 10M and half duplex mode are not supported currently as they require IEP, the support for which will be added later. Support for switch-dev, timestamp, etc. will be added later by subsequent patch series.
--- drivers/net/ethernet/ti/Kconfig | 13 + drivers/net/ethernet/ti/Makefile | 3 + drivers/net/ethernet/ti/icssg_prueth.c | 1831 ++++++++++++++++++++++++ drivers/net/ethernet/ti/icssg_prueth.h | 48 + 4 files changed, 1895 insertions(+) create mode 100644 drivers/net/ethernet/ti/icssg_prueth.c
drivers/net/ethernet/ti/Kconfig +13 -0
@@ -183,4 +183,17 @@ config CPMAC help TI AR7 CPMAC Ethernet support +config TI_ICSSG_PRUETH + tristate "TI Gigabit PRU Ethernet driver" + select PHYLIB + depends on PRU_REMOTEPROC + depends on ARCH_K3 && OF && TI_K3_UDMA_GLUE_LAYER + help + Support dual Gigabit Ethernet ports over the ICSSG PRU Subsystem. + This subsystem is available starting with the AM65 platform. + + This driver requires firmware binaries which will run on the PRUs + to support the Ethernet operation. Currently, it supports Ethernet + with 1G and 100M link speed. + endif # NET_VENDOR_TI
drivers/net/ethernet/ti/Makefile +3 -0
@@ -28,3 +28,6 @@ obj-$(CONFIG_TI_K3_AM65_CPSW_NUSS) += ti-am65-cpsw-nuss.o ti-am65-cpsw-nuss-y := am65-cpsw-nuss.o cpsw_sl.o am65-cpsw-ethtool.o cpsw_ale.o k3-cppi-desc-pool.o am65-cpsw-qos.o ti-am65-cpsw-nuss-$(CONFIG_TI_K3_AM65_CPSW_SWITCHDEV) += am65-cpsw-switchdev.o obj-$(CONFIG_TI_K3_AM65_CPTS) += am65-cpts.o + +obj-$(CONFIG_TI_ICSSG_PRUETH) += icssg-prueth.o +icssg-prueth-y := icssg_prueth.o icssg_classifier.o icssg_queues.o icssg_config.o k3-cppi-desc-pool.o icssg_mii_cfg.o
drivers/net/ethernet/ti/icssg_prueth.c new file +1831 -0
1,831 lines not on this page · raw message
drivers/net/ethernet/ti/icssg_prueth.h +48 -0
71 lines not on this page · raw message
Signature · 1 line
2.34.1
Jakub Kicinski
maintainerRe: [PATCH v11 06/10] net: ti: icssg-prueth: Add ICSSG ethernet driver
Quoted 4 lines · On Mon, 24 Jul 2023 16:59:30 +0530 MD Danish Anwar wrote:
drivers/net/ethernet/ti/Kconfig | 13 + drivers/net/ethernet/ti/Makefile | 3 + drivers/net/ethernet/ti/icssg_prueth.c | 1831 ++++++++++++++++++++++++ drivers/net/ethernet/ti/icssg_prueth.h | 48 +
Please create a sub-directory for the driver.
drivers/net/ethernet/ti/icssg_prueth.c line 241
Quoted 10 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +10
-0+static int prueth_ndev_add_tx_napi (struct prueth_emac *emac) +{ +struct prueth *prueth = emac->prueth; +int i, ret; + +for (i =0 ; i < emac->tx_ch_num; i++) { +struct prueth_tx_chn *tx_chn = &emac->tx_chns[i]; + +netif_napi_add_tx_weight (emac->ndev, &tx_chn->napi_tx, + emac_napi_tx_poll,NAPI_POLL_WEIGHT );
Skip specifying weight, please.
Quoted 25 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +25
-0+/** +* emac_ndo_start_xmit - EMAC Transmit function +* @skb: SKB pointer +* @ndev: EMAC network adapter +* +* Called by the system to transmit a packet - we queue the packet in +* EMAC hardware transmit queue +* Doesn't wait for completion we'll check for TX completion in +* emac_tx_complete_packets(). +* +* Return: enum netdev_tx +*/ +static enum netdev_tx emac_ndo_start_xmit (struct sk_buff *skb,struct net_device *ndev) +{ +struct cppi5_host_desc_t *first_desc, *next_desc, *cur_desc; +struct prueth_emac *emac =netdev_priv (ndev); +struct netdev_queue *netif_txq; +struct prueth_tx_chn *tx_chn; +dma_addr_t desc_dma, buf_dma; +int i, ret =0 , q_idx; +void **swdata; +u32 pkt_len; +u32 *epib; + + pkt_len =skb_headlen (skb);
drivers/net/ethernet/ti/icssg_prueth.c line 603
Quoted 10 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +10
-0+ q_idx =skb_get_queue_mapping (skb); + + tx_chn = &emac->tx_chns[q_idx]; + netif_txq =netdev_get_tx_queue (ndev, q_idx); + +/* Map the linear buffer */ + buf_dma =dma_map_single (tx_chn->dma_dev, skb->data, pkt_len,DMA_TO_DEVICE ); +if (dma_mapping_error (tx_chn->dma_dev, buf_dma)) { +netdev_err (ndev,"tx: failed to map skb buffer\n" ); + ret =NETDEV_TX_BUSY ;
Drop it if it can't be mapped and return OK. What's going to re-enable the queue in this case?
Quoted 20 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +20
-0+ goto drop_stop_q; + } + + first_desc =k3_cppi_desc_pool_alloc (tx_chn->desc_pool); +if (!first_desc) { +netdev_dbg (ndev,"tx: failed to allocate descriptor\n" ); +dma_unmap_single (tx_chn->dma_dev, buf_dma, pkt_len,DMA_TO_DEVICE ); + ret =NETDEV_TX_BUSY ; + goto drop_stop_q_busy; + } + +cppi5_hdesc_init (first_desc,CPPI5_INFO0_HDESC_EPIB_PRESENT , +PRUETH_NAV_PS_DATA_SIZE ); +cppi5_hdesc_set_pkttype (first_desc,0 ); + epib = first_desc->epib; + epib[0 ] =0 ; + epib[1 ] =0 ; + +/* set dst tag to indicate internal qid at the firmware which is at +* bit8..bit15. bit0..bit7 indicates port num for directed
drivers/net/ethernet/ti/icssg_prueth.c line 633
Quoted 10 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +10
-0+* packets in case of switch mode operation +*/ +cppi5_desc_set_tags_ids (&first_desc->hdr,0 , (emac->port_id | (q_idx <<8 ))); +k3_udma_glue_tx_dma_to_cppi5_addr (tx_chn->tx_chn, &buf_dma); +cppi5_hdesc_attach_buf (first_desc, buf_dma, pkt_len, buf_dma, pkt_len); + swdata =cppi5_hdesc_get_swdata (first_desc); + *swdata = skb; + +if (!skb_is_nonlinear (skb)) + goto tx_push;
Why the goto? The loop won't be entered.
Quoted 11 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +11
-0+/* Handle the case where skb is fragmented in pages */ + cur_desc = first_desc; +for (i =0 ; i <skb_shinfo (skb)->nr_frags; i++) { +skb_frag_t *frag = &skb_shinfo (skb)->frags[i]; +u32 frag_size =skb_frag_size (frag); + + next_desc =k3_cppi_desc_pool_alloc (tx_chn->desc_pool); +if (!next_desc) { +netdev_err (ndev, +"tx: failed to allocate frag. descriptor\n" ); + ret =NETDEV_TX_BUSY ;
drivers/net/ethernet/ti/icssg_prueth.c line 655
Quoted 10 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +10
-0+ goto drop_free_descs; + } + + buf_dma =skb_frag_dma_map (tx_chn->dma_dev, frag,0 , frag_size, +DMA_TO_DEVICE ); +if (dma_mapping_error (tx_chn->dma_dev, buf_dma)) { +netdev_err (ndev,"tx: Failed to map skb page\n" ); +k3_cppi_desc_pool_free (tx_chn->desc_pool, next_desc); + ret =NETDEV_TX_BUSY ; + goto drop_free_descs;
this label frees the skb, you can't return BUSY
Quoted 6 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +6
-0+ } + +cppi5_hdesc_reset_hbdesc (next_desc); +k3_udma_glue_tx_dma_to_cppi5_addr (tx_chn->tx_chn, &buf_dma); +cppi5_hdesc_attach_buf (next_desc, + buf_dma, frag_size, buf_dma, frag_size);
drivers/net/ethernet/ti/icssg_prueth.c line 671
Quoted 10 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +10
-0+ + desc_dma =k3_cppi_desc_pool_virt2dma (tx_chn->desc_pool, + next_desc); +k3_udma_glue_tx_dma_to_cppi5_addr (tx_chn->tx_chn, &desc_dma); +cppi5_hdesc_link_hbdesc (cur_desc, desc_dma); + + pkt_len += frag_size; + cur_desc = next_desc; + } +WARN_ON (pkt_len != skb->len);
WARN_ON_ONCE() if at all
Quoted 13 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +13
-0+ +tx_push: +/* report bql before sending packet */ +netdev_tx_sent_queue (netif_txq, pkt_len); + +cppi5_hdesc_set_pktlen (first_desc, pkt_len); + desc_dma =k3_cppi_desc_pool_virt2dma (tx_chn->desc_pool, first_desc); +/* cppi5_desc_dump(first_desc, 64); */ + +skb_tx_timestamp (skb);/* SW timestamp if SKBTX_IN_PROGRESS not set */ + ret =k3_udma_glue_push_tx_chn (tx_chn->tx_chn, first_desc, desc_dma); +if (ret) { +netdev_err (ndev,"tx: push failed: %d\n" , ret);
drivers/net/ethernet/ti/icssg_prueth.c line 694
Quoted 10 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +10
-0+ goto drop_free_descs; + } + +if (k3_cppi_desc_pool_avail (tx_chn->desc_pool) <MAX_SKB_FRAGS ) { +netif_tx_stop_queue (netif_txq); +/* Barrier, so that stop_queue visible to other cpus */ +smp_mb__after_atomic (); + +if (k3_cppi_desc_pool_avail (tx_chn->desc_pool) >= +MAX_SKB_FRAGS )
MAX_FRAGS + 1?
Quoted 21 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +19
-0+netif_tx_wake_queue (netif_txq); + } + +return NETDEV_TX_OK ; +static int emac_napi_rx_poll (struct napi_struct *napi_rx,int budget) +{ +struct prueth_emac *emac =prueth_napi_to_emac (napi_rx); +int rx_flow =PRUETH_RX_FLOW_DATA ; +int flow =PRUETH_MAX_RX_FLOWS ; +int num_rx =0 ; +int cur_budget; +int ret; + +while (flow--) { + cur_budget = budget - num_rx; + +while (cur_budget--) { + ret =emac_rx_packet (emac, flow); +if (ret)
drivers/net/ethernet/ti/icssg_prueth.c line 923
Quoted 10 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +10
-0+break ; + num_rx++; + } + +if (num_rx >= budget) +break ; + } + +if (num_rx < budget) { +napi_complete (napi_rx);
Prefer using napi_complete_done()
drivers/net/ethernet/ti/icssg_prueth.c line 1201
Quoted 12 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +11
-0+enable_irq (emac->rx_chns.irq[rx_flow]); + } + +return num_rx; +} +static void emac_ndo_tx_timeout (struct net_device *ndev,unsigned int txqueue) +{ +struct prueth_emac *emac =netdev_priv (ndev); + +if (netif_msg_tx_err (emac)) +netdev_err (ndev,"xmit timeout" );
Core already prints something, you can drop this.
Quoted 23 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +22
-0+ ndev->stats.tx_errors++; +} +static void emac_ndo_set_rx_mode_work (struct work_struct *work) +{ + struct prueth_emac *emac = container_of(work, struct prueth_emac, rx_mode_work); +struct net_device *ndev = emac->ndev; +bool promisc, allmulti; + +if (!netif_running (ndev)) +return ; + + promisc = ndev->flags &IFF_PROMISC ; + allmulti = ndev->flags &IFF_ALLMULTI ; +emac_set_port_state (emac,ICSSG_EMAC_PORT_UC_FLOODING_DISABLE ); +emac_set_port_state (emac,ICSSG_EMAC_PORT_MC_FLOODING_DISABLE ); + +if (promisc) { +emac_set_port_state (emac,ICSSG_EMAC_PORT_UC_FLOODING_ENABLE ); +emac_set_port_state (emac,ICSSG_EMAC_PORT_MC_FLOODING_ENABLE ); +return ; + } +
drivers/net/ethernet/ti/icssg_prueth.c line 1235
Quoted 10 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +10
-0+if (allmulti) { +emac_set_port_state (emac,ICSSG_EMAC_PORT_MC_FLOODING_ENABLE ); +return ; + } + +if (!netdev_mc_empty (ndev)) { +emac_set_port_state (emac,ICSSG_EMAC_PORT_MC_FLOODING_ENABLE ); +return ; + } +}
There's no need for locking in this work?
drivers/net/ethernet/ti/icssg_prueth.c line 1417
Quoted 2 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +2
-0+netif_napi_add (ndev, &emac->napi_rx, + emac_napi_rx_poll);
nit: fits on a line
drivers/net/ethernet/ti/icssg_prueth.c line 1820
Quoted 3 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +3
-0+static struct platform_driver prueth_driver = { + .probe = prueth_probe, + .remove = prueth_remove,
Please use .remove_new (which has a void return).
Signature · 1 line
pw-bot: cr
Re: [EXTERNAL] Re: [PATCH v11 06/10] net: ti: icssg-prueth: Add ICSSG ethernet driver
Hi Jakub,
Quoted 8 lines · Jakub Kicinski
Quoted 4 lines · On Mon, 24 Jul 2023 16:59:30 +0530 MD Danish Anwar wrote:
drivers/net/ethernet/ti/Kconfig | 13 + drivers/net/ethernet/ti/Makefile | 3 + drivers/net/ethernet/ti/icssg_prueth.c | 1831 ++++++++++++++++++++++++ drivers/net/ethernet/ti/icssg_prueth.h | 48 +Please create a sub-directory for the driver.
Quoted 13 lines
drivers/net/ethernet/ti/icssg_prueth.c line 241
Quoted 10 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +10
-0+static int prueth_ndev_add_tx_napi (struct prueth_emac *emac) +{ +struct prueth *prueth = emac->prueth; +int i, ret; + +for (i =0 ; i < emac->tx_ch_num; i++) { +struct prueth_tx_chn *tx_chn = &emac->tx_chns[i]; + +netif_napi_add_tx_weight (emac->ndev, &tx_chn->napi_tx, + emac_napi_tx_poll,NAPI_POLL_WEIGHT );Skip specifying weight, please.
Sure, Will change this to 'netif_napi_add_tx(emac->ndev, &tx_chn-> emac_napi_tx_poll);'
Quoted 30 lines
Quoted 30 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +30
-0+/** +* emac_ndo_start_xmit - EMAC Transmit function +* @skb: SKB pointer +* @ndev: EMAC network adapter +* +* Called by the system to transmit a packet - we queue the packet in +* EMAC hardware transmit queue +* Doesn't wait for completion we'll check for TX completion in +* emac_tx_complete_packets(). +* +* Return: enum netdev_tx +*/ +static enum netdev_tx emac_ndo_start_xmit (struct sk_buff *skb,struct net_device *ndev) +{ +struct cppi5_host_desc_t *first_desc, *next_desc, *cur_desc; +struct prueth_emac *emac =netdev_priv (ndev); +struct netdev_queue *netif_txq; +struct prueth_tx_chn *tx_chn; +dma_addr_t desc_dma, buf_dma; +int i, ret =0 , q_idx; +void **swdata; +u32 pkt_len; +u32 *epib; + + pkt_len =skb_headlen (skb); + q_idx =skb_get_queue_mapping (skb); + + tx_chn = &emac->tx_chns[q_idx]; + netif_txq =netdev_get_tx_queue (ndev, q_idx); +
Quoted 9 lines
drivers/net/ethernet/ti/icssg_prueth.c line 603
Quoted 5 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +5
-0+/* Map the linear buffer */ + buf_dma =dma_map_single (tx_chn->dma_dev, skb->data, pkt_len,DMA_TO_DEVICE ); +if (dma_mapping_error (tx_chn->dma_dev, buf_dma)) { +netdev_err (ndev,"tx: failed to map skb buffer\n" ); + ret =NETDEV_TX_BUSY ;Drop it if it can't be mapped and return OK. What's going to re-enable the queue in this case?
Sure. I will drop the packet and return NETDEV_TX_OK.
Quoted 24 lines
Quoted 24 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +24
-0+ goto drop_stop_q; + } + + first_desc =k3_cppi_desc_pool_alloc (tx_chn->desc_pool); +if (!first_desc) { +netdev_dbg (ndev,"tx: failed to allocate descriptor\n" ); +dma_unmap_single (tx_chn->dma_dev, buf_dma, pkt_len,DMA_TO_DEVICE ); + ret =NETDEV_TX_BUSY ; + goto drop_stop_q_busy; + } + +cppi5_hdesc_init (first_desc,CPPI5_INFO0_HDESC_EPIB_PRESENT , +PRUETH_NAV_PS_DATA_SIZE ); +cppi5_hdesc_set_pkttype (first_desc,0 ); + epib = first_desc->epib; + epib[0 ] =0 ; + epib[1 ] =0 ; + +/* set dst tag to indicate internal qid at the firmware which is at +* bit8..bit15. bit0..bit7 indicates port num for directed +* packets in case of switch mode operation +*/ +cppi5_desc_set_tags_ids (&first_desc->hdr,0 , (emac->port_id | (q_idx <<8 ))); +k3_udma_glue_tx_dma_to_cppi5_addr (tx_chn->tx_chn, &buf_dma);
Quoted 9 lines
drivers/net/ethernet/ti/icssg_prueth.c line 633
Quoted 6 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +6
-0+cppi5_hdesc_attach_buf (first_desc, buf_dma, pkt_len, buf_dma, pkt_len); + swdata =cppi5_hdesc_get_swdata (first_desc); + *swdata = skb; + +if (!skb_is_nonlinear (skb)) + goto tx_push;Why the goto? The loop won't be entered.
skb_is_nonlinear() will return true when skb is fragmented i.e. skb_shinfo(skb)->nr_frags > 0.
Makes sense to drop the if condition. As for non-fragmented skb, skb_shinfo(skb)->nr_frags = 0 and we won't enter for loop and will eventually reach at label tx_push.
I will drop the if condition.
Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +15
-0+/* Handle the case where skb is fragmented in pages */ + cur_desc = first_desc; +for (i =0 ; i <skb_shinfo (skb)->nr_frags; i++) { +skb_frag_t *frag = &skb_shinfo (skb)->frags[i]; +u32 frag_size =skb_frag_size (frag); + + next_desc =k3_cppi_desc_pool_alloc (tx_chn->desc_pool); +if (!next_desc) { +netdev_err (ndev, +"tx: failed to allocate frag. descriptor\n" ); + ret =NETDEV_TX_BUSY ; + goto drop_free_descs; + } + + buf_dma = skb_frag_dma_map(tx_chn->dma_dev, frag, 0, frag_size,
Quoted 9 lines
drivers/net/ethernet/ti/icssg_prueth.c line 655
Quoted 6 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +6
-0+ DMA_TO_DEVICE); +if (dma_mapping_error (tx_chn->dma_dev, buf_dma)) { +netdev_err (ndev,"tx: Failed to map skb page\n" ); +k3_cppi_desc_pool_free (tx_chn->desc_pool, next_desc); + ret =NETDEV_TX_BUSY ; + goto drop_free_descs;this label frees the skb, you can't return BUSY
Sure. Will return OK here.
Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +10
-0+ } + +cppi5_hdesc_reset_hbdesc (next_desc); +k3_udma_glue_tx_dma_to_cppi5_addr (tx_chn->tx_chn, &buf_dma); +cppi5_hdesc_attach_buf (next_desc, + buf_dma, frag_size, buf_dma, frag_size); + + desc_dma =k3_cppi_desc_pool_virt2dma (tx_chn->desc_pool, + next_desc); +k3_udma_glue_tx_dma_to_cppi5_addr (tx_chn->tx_chn, &desc_dma);
Quoted 9 lines
drivers/net/ethernet/ti/icssg_prueth.c line 671
Quoted 6 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +6
-0+cppi5_hdesc_link_hbdesc (cur_desc, desc_dma); + + pkt_len += frag_size; + cur_desc = next_desc; + } +WARN_ON (pkt_len != skb->len);
WARN_ON_ONCE()if at all
Sure.
Quoted 17 lines
Quoted 17 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +17
-0+ +tx_push: +/* report bql before sending packet */ +netdev_tx_sent_queue (netif_txq, pkt_len); + +cppi5_hdesc_set_pktlen (first_desc, pkt_len); + desc_dma =k3_cppi_desc_pool_virt2dma (tx_chn->desc_pool, first_desc); +/* cppi5_desc_dump(first_desc, 64); */ + +skb_tx_timestamp (skb);/* SW timestamp if SKBTX_IN_PROGRESS not set */ + ret =k3_udma_glue_push_tx_chn (tx_chn->tx_chn, first_desc, desc_dma); +if (ret) { +netdev_err (ndev,"tx: push failed: %d\n" , ret); + goto drop_free_descs; + } + +if (k3_cppi_desc_pool_avail (tx_chn->desc_pool) <MAX_SKB_FRAGS ) {
Quoted 9 lines
drivers/net/ethernet/ti/icssg_prueth.c line 694
Quoted 6 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +6
-0+netif_tx_stop_queue (netif_txq); +/* Barrier, so that stop_queue visible to other cpus */ +smp_mb__after_atomic (); + +if (k3_cppi_desc_pool_avail (tx_chn->desc_pool) >= +MAX_SKB_FRAGS )
MAX_FRAGS+ 1?
I think MAX_SKB_FRAGS is OK. If the available pool = MAX_SKB_FRAGS we should be able to wake the queue.
Quoted 25 lines
Quoted 25 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +23
-0+netif_tx_wake_queue (netif_txq); + } + +return NETDEV_TX_OK ; +static int emac_napi_rx_poll (struct napi_struct *napi_rx,int budget) +{ +struct prueth_emac *emac =prueth_napi_to_emac (napi_rx); +int rx_flow =PRUETH_RX_FLOW_DATA ; +int flow =PRUETH_MAX_RX_FLOWS ; +int num_rx =0 ; +int cur_budget; +int ret; + +while (flow--) { + cur_budget = budget - num_rx; + +while (cur_budget--) { + ret =emac_rx_packet (emac, flow); +if (ret) +break ; + num_rx++; + } +
Quoted 9 lines
drivers/net/ethernet/ti/icssg_prueth.c line 923
Quoted 6 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +6
-0+if (num_rx >= budget) +break ; + } + +if (num_rx < budget) { +napi_complete (napi_rx);Prefer using
napi_complete_done()
Sure.
Quoted 6 lines
Quoted 5 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +5
-0+enable_irq (emac->rx_chns.irq[rx_flow]); + } + +return num_rx; +}
Quoted 9 lines
drivers/net/ethernet/ti/icssg_prueth.c line 1201
Quoted 6 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +6
-0+static void emac_ndo_tx_timeout (struct net_device *ndev,unsigned int txqueue) +{ +struct prueth_emac *emac =netdev_priv (ndev); + +if (netif_msg_tx_err (emac)) +netdev_err (ndev,"xmit timeout" );Core already prints something, you can drop this.
Sure, I will drop this print.
Quoted 27 lines
Quoted 27 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +26
-0+ ndev->stats.tx_errors++; +} +static void emac_ndo_set_rx_mode_work (struct work_struct *work) +{ + struct prueth_emac *emac = container_of(work, struct prueth_emac, rx_mode_work); +struct net_device *ndev = emac->ndev; +bool promisc, allmulti; + +if (!netif_running (ndev)) +return ; + + promisc = ndev->flags &IFF_PROMISC ; + allmulti = ndev->flags &IFF_ALLMULTI ; +emac_set_port_state (emac,ICSSG_EMAC_PORT_UC_FLOODING_DISABLE ); +emac_set_port_state (emac,ICSSG_EMAC_PORT_MC_FLOODING_DISABLE ); + +if (promisc) { +emac_set_port_state (emac,ICSSG_EMAC_PORT_UC_FLOODING_ENABLE ); +emac_set_port_state (emac,ICSSG_EMAC_PORT_MC_FLOODING_ENABLE ); +return ; + } + +if (allmulti) { +emac_set_port_state (emac,ICSSG_EMAC_PORT_MC_FLOODING_ENABLE ); +return ; + }
Quoted 9 lines
drivers/net/ethernet/ti/icssg_prueth.c line 1235
Quoted 6 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +6
-0+ +if (!netdev_mc_empty (ndev)) { +emac_set_port_state (emac,ICSSG_EMAC_PORT_MC_FLOODING_ENABLE ); +return ; + } +}There's no need for locking in this work?
No I don't think any lock is required here. emac_set_port_state() aquires lock before updating port status. Also emac_ndo_set_rx_mode_work() is scheduled by a singlethreaded workqueue.
Quoted 4 lines
drivers/net/ethernet/ti/icssg_prueth.c line 1417
Quoted 2 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +2
-0+netif_napi_add (ndev, &emac->napi_rx, + emac_napi_rx_poll);nit: fits on a line
Sure I will move it to one line.
Quoted 6 lines
drivers/net/ethernet/ti/icssg_prueth.c line 1820
Quoted 4 lines
drivers/net/ethernet/ti/icssg_prueth.c new file +3
-0+static struct platform_driver prueth_driver = { + .probe = prueth_probe, + .remove = prueth_remove,Please use .remove_new (which has a void return).
Sure I will use .remove_new instead of .remove
Please let me know if this looks ok to you. I will try to address these and send next revision.
Signature · 2 lines
Thanks and Regards, Danish.
Jakub Kicinski
maintainerRe: [EXTERNAL] Re: [PATCH v11 06/10] net: ti: icssg-prueth: Add ICSSG ethernet driver
Quoted 2 lines · On Wed, 26 Jul 2023 16:01:23 +0530 Md Danish Anwar wrote:
I think
MAX_SKB_FRAGSis OK. If the available pool =MAX_SKB_FRAGSwe should be able to wake the queue.
MAX_SKB_FRAGS only counts frags and you also need space to map the head, no?
In general we advise to wait until there's at least 2 * MAX_SKB_FRAGS to avoid frequent sleep/wake cycles. But IDK how long your queue is, maybe it's too much.
Quoted 3 lines
No I don't think any lock is required here.
emac_set_port_state()aquires lock before updating port status. Alsoemac_ndo_set_rx_mode_work()is scheduled by a singlethreaded workqueue.
if (netif_running()) outside of any locks is usually a red flag, but if you're confident it's fine it's fine :)
Re: [EXTERNAL] Re: [EXTERNAL] Re: [PATCH v11 06/10] net: ti: icssg-prueth: Add ICSSG ethernet driver
Quoted 10 lines · Jakub Kicinski
Quoted 2 lines · On Wed, 26 Jul 2023 16:01:23 +0530 Md Danish Anwar wrote:
I think
MAX_SKB_FRAGSis OK. If the available pool =MAX_SKB_FRAGSwe should be able to wake the queue.
MAX_SKB_FRAGSonly counts frags and you also need space to map the head, no?In general we advise to wait until there's at least 2 *
MAX_SKB_FRAGSto avoid frequent sleep/wake cycles. But IDK how long your queue is, maybe it's too much.
Quoted 6 lines
Quoted 3 lines
No I don't think any lock is required here.
emac_set_port_state()aquires lock before updating port status. Alsoemac_ndo_set_rx_mode_work()is scheduled by a singlethreaded workqueue.if (
netif_running()) outside of any locks is usually a red flag, but if you're confident it's fine it's fine :)
Sure Jakub. I will keep these as it is.
Signature · 2 lines
Thanks and Regards, Md Danish Anwar
MD Danish Anwar
reviewerPATCH v11 7/10 net: ti: icssg-prueth: Add ICSSG Stats
In reply to MD Danish AnwarAdd icssg_stats.c to help dump, icssg related driver statistics.
ICSSG has hardware registers for providing statistics like total rx bytes, total tx bytes, etc. These registers are of 32 bits and hence in case of 1G link, they overflows in around 32 seconds. The behaviour of these registers is such that they don't roll back to 0 after overflow but rather stay at UINT_MAX.
These registers support a feature where the value written to them is subtracted from the register. This feature can be utilized to fix the overflowing of stats.
This solution uses a Workqueues based solution where a function gets called before the registers overflow (every 25 seconds in 1G link, 25000 seconds in 100M link), this function saves the register values in local variables and writes the last read value to the register. So any update during the read will be taken care of.
--- drivers/net/ethernet/ti/Makefile | 2 +- drivers/net/ethernet/ti/icssg_prueth.c | 9 ++ drivers/net/ethernet/ti/icssg_prueth.h | 9 ++ drivers/net/ethernet/ti/icssg_stats.c | 44 +++++++ drivers/net/ethernet/ti/icssg_stats.h | 158 +++++++++++++++++++++++++ 5 files changed, 221 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/ti/icssg_stats.c create mode 100644 drivers/net/ethernet/ti/icssg_stats.h
drivers/net/ethernet/ti/Makefile +1 -1
@@ -30,4 +30,4 @@ ti-am65-cpsw-nuss-$(CONFIG_TI_K3_AM65_CPSW_SWITCHDEV) += am65-cpsw-switchdev.o obj-$(CONFIG_TI_K3_AM65_CPTS) += am65-cpts.o obj-$(CONFIG_TI_ICSSG_PRUETH) += icssg-prueth.o -icssg-prueth-y := icssg_prueth.o icssg_classifier.o icssg_queues.o icssg_config.o k3-cppi-desc-pool.o icssg_mii_cfg.o +icssg-prueth-y := icssg_prueth.o icssg_classifier.o icssg_queues.o icssg_config.o k3-cppi-desc-pool.o icssg_mii_cfg.o icssg_stats.o
drivers/net/ethernet/ti/icssg_prueth.c +9 -0
@@ -8,6 +8,7 @@#include <linux/bitops.h> #include <linux/clk.h> +#include <linux/delay.h> #include <linux/dma-mapping.h> #include <linux/dma/ti-cppi5.h> #include <linux/etherdevice.h>
@@ -1105,6 +1106,8 @@ static int emac_ndo_open(struct net_device *ndev) prueth->emacs_initialized++; +queue_work (system_long_wq, &emac->stats_work.work); +return 0 ; reset_tx_chan:
@@ -1178,6 +1181,10 @@ static int emac_ndo_stop(struct net_device *ndev)napi_disable (&emac->napi_rx);cancel_work_sync (&emac->rx_mode_work); + +/* Destroying the queued work in ndo_stop() */ +cancel_delayed_work_sync (&emac->stats_work); +/* stop PRUs */ prueth_emac_stop (emac);
@@ -1332,6 +1339,8 @@ static int prueth_netdev_init(struct prueth *prueth, }INIT_WORK (&emac->rx_mode_work, emac_ndo_set_rx_mode_work); +INIT_DELAYED_WORK (&emac->stats_work, emac_stats_work_handler); + ret = pruss_request_mem_region(prueth->pruss, port == PRUETH_PORT_MII0 ? PRUSS_MEM_DRAM0 : PRUSS_MEM_DRAM1,
drivers/net/ethernet/ti/icssg_prueth.h +9 -0
@@ -45,6 +45,9 @@#define ICSSG_MAX_RFLOWS 8/* per slice */ +/* Number of ICSSG related stats */ +#define ICSSG_NUM_STATS 60 +/* Firmware status codes */ #define ICSS_HS_FW_READY 0x55555555#define ICSS_HS_FW_DEAD 0xDEAD0000/* lower 16 bits contain error code */
@@ -149,6 +152,10 @@ struct prueth_emac {struct workqueue_struct *cmd_wq;struct pruss_mem_region dram; + +struct delayed_work stats_work; +u64 stats[ICSSG_NUM_STATS ]; + };/**
@@ -242,4 +249,6 @@ void icssg_config_set_speed(struct prueth_emac *emac);#define prueth_napi_to_tx_chn (pnapi) \ container_of(pnapi, struct prueth_tx_chn, napi_tx) +void emac_stats_work_handler (struct work_struct *work); +void emac_update_hardware_stats (struct prueth_emac *emac);#endif /* __NET_TI_ICSSG_PRUETH_H */
drivers/net/ethernet/ti/icssg_stats.c new file +44 -0
44 lines not on this page · raw message
drivers/net/ethernet/ti/icssg_stats.h new file +158 -0
158 lines not on this page · raw message
Signature · 1 line
2.34.1
Jakub Kicinski
maintainerRe: [PATCH v11 07/10] net: ti: icssg-prueth: Add ICSSG Stats
drivers/net/ethernet/ti/icssg_stats.h line 97
Quoted 4 lines · On Mon, 24 Jul 2023 16:59:31 +0530 MD Danish Anwar wrote:
drivers/net/ethernet/ti/icssg_stats.h new file +4
-0+/* Rx */ +ICSSG_STATS (rx_packets, true), +ICSSG_STATS (rx_broadcast_frames, false), + ICSSG_STATS(rx_multicast_frames, false),
There is a standard stat for mcast.
Quoted 19 lines
drivers/net/ethernet/ti/icssg_stats.h new file +19
-0+ICSSG_STATS (rx_crc_errors, true), +ICSSG_STATS (rx_mii_error_frames, false), +ICSSG_STATS (rx_odd_nibble_frames, false), +ICSSG_STATS (rx_frame_max_size, false), +ICSSG_STATS (rx_max_size_error_frames, false), +ICSSG_STATS (rx_frame_min_size, false), +ICSSG_STATS (rx_min_size_error_frames, false), +ICSSG_STATS (rx_over_errors, true), +ICSSG_STATS (rx_class0_hits, false), +ICSSG_STATS (rx_class1_hits, false), +ICSSG_STATS (rx_class2_hits, false), +ICSSG_STATS (rx_class3_hits, false), +ICSSG_STATS (rx_class4_hits, false), +ICSSG_STATS (rx_class5_hits, false), +ICSSG_STATS (rx_class6_hits, false), +ICSSG_STATS (rx_class7_hits, false), +ICSSG_STATS (rx_class8_hits, false), +ICSSG_STATS (rx_class9_hits, false), + ICSSG_STATS(rx_class10_hits, false),
drivers/net/ethernet/ti/icssg_stats.h line 126
Quoted 10 lines
drivers/net/ethernet/ti/icssg_stats.h new file +10
-0+ICSSG_STATS (rx_class11_hits, false), +ICSSG_STATS (rx_class12_hits, false), +ICSSG_STATS (rx_class13_hits, false), +ICSSG_STATS (rx_class14_hits, false), +ICSSG_STATS (rx_class15_hits, false), +ICSSG_STATS (rx_smd_frags, false), +ICSSG_STATS (rx_bucket1_size, false), +ICSSG_STATS (rx_bucket2_size, false), +ICSSG_STATS (rx_bucket3_size, false), + ICSSG_STATS(rx_bucket4_size, false),
Are the bucket sizes configurable? Can we set the bucket sizes to standard RMON ones and use ethtool RMON stats?
Re: [EXTERNAL] Re: [PATCH v11 07/10] net: ti: icssg-prueth: Add ICSSG Stats
Hi Jakub
Quoted 8 lines · Jakub Kicinski
drivers/net/ethernet/ti/icssg_stats.h line 97
Quoted 4 lines · On Mon, 24 Jul 2023 16:59:31 +0530 MD Danish Anwar wrote:
drivers/net/ethernet/ti/icssg_stats.h new file +4
-0+/* Rx */ +ICSSG_STATS (rx_packets, true), +ICSSG_STATS (rx_broadcast_frames, false), + ICSSG_STATS(rx_multicast_frames, false),There is a standard stat for mcast.
Sure. I will add multicast stats via .ndo_get_stats64 instead of ethtool.
Quoted 24 lines
Quoted 24 lines
drivers/net/ethernet/ti/icssg_stats.h new file +24
-0+ICSSG_STATS (rx_crc_errors, true), +ICSSG_STATS (rx_mii_error_frames, false), +ICSSG_STATS (rx_odd_nibble_frames, false), +ICSSG_STATS (rx_frame_max_size, false), +ICSSG_STATS (rx_max_size_error_frames, false), +ICSSG_STATS (rx_frame_min_size, false), +ICSSG_STATS (rx_min_size_error_frames, false), +ICSSG_STATS (rx_over_errors, true), +ICSSG_STATS (rx_class0_hits, false), +ICSSG_STATS (rx_class1_hits, false), +ICSSG_STATS (rx_class2_hits, false), +ICSSG_STATS (rx_class3_hits, false), +ICSSG_STATS (rx_class4_hits, false), +ICSSG_STATS (rx_class5_hits, false), +ICSSG_STATS (rx_class6_hits, false), +ICSSG_STATS (rx_class7_hits, false), +ICSSG_STATS (rx_class8_hits, false), +ICSSG_STATS (rx_class9_hits, false), +ICSSG_STATS (rx_class10_hits, false), +ICSSG_STATS (rx_class11_hits, false), +ICSSG_STATS (rx_class12_hits, false), +ICSSG_STATS (rx_class13_hits, false), +ICSSG_STATS (rx_class14_hits, false), + ICSSG_STATS(rx_class15_hits, false),
Quoted 8 lines
drivers/net/ethernet/ti/icssg_stats.h line 126
Quoted 5 lines
drivers/net/ethernet/ti/icssg_stats.h new file +5
-0+ICSSG_STATS (rx_smd_frags, false), +ICSSG_STATS (rx_bucket1_size, false), +ICSSG_STATS (rx_bucket2_size, false), +ICSSG_STATS (rx_bucket3_size, false), + ICSSG_STATS(rx_bucket4_size, false),Are the bucket sizes configurable? Can we set the bucket sizes to standard RMON ones and use ethtool RMON stats?
The bucket sizes are not configurable. Bucket size is read from hardware and is fixed. I don't think we can configure bucket size and use ethtool RMON stats. It's better to dump bucket sizes via ethtool -S.
Signature · 2 lines
Thanks and Regards, Danish.
Jakub Kicinski
maintainerRe: [EXTERNAL] Re: [PATCH v11 07/10] net: ti: icssg-prueth: Add ICSSG Stats
Quoted 6 lines · On Wed, 26 Jul 2023 16:06:06 +0530 Md Danish Anwar wrote:
Quoted 2 lines
Are the bucket sizes configurable? Can we set the bucket sizes to standard RMON ones and use ethtool RMON stats?
The bucket sizes are not configurable. Bucket size is read from hardware and is fixed. I don't think we can configure bucket size and use ethtool RMON stats. It's better to dump bucket sizes via ethtool -S.
The buckets in the ethtool API are up to the device to define. Driver returns bucket ranges via struct ethtool_rmon_hist_range from struct ethtool_ops::get_rmon_stats.
Re: [EXTERNAL] Re: [EXTERNAL] Re: [PATCH v11 07/10] net: ti: icssg-prueth: Add ICSSG Stats
Quoted 11 lines · Jakub Kicinski
Quoted 6 lines · On Wed, 26 Jul 2023 16:06:06 +0530 Md Danish Anwar wrote:
Quoted 2 lines
Are the bucket sizes configurable? Can we set the bucket sizes to standard RMON ones and use ethtool RMON stats?
The bucket sizes are not configurable. Bucket size is read from hardware and is fixed. I don't think we can configure bucket size and use ethtool RMON stats. It's better to dump bucket sizes via ethtool -S.
The buckets in the ethtool API are up to the device to define. Driver returns bucket ranges via struct
ethtool_rmon_hist_rangefrom structethtool_ops::get_rmon_stats.
Sure Jakub I will try to implement this using ethtool_ops::get_rmon_stats.
Signature · 2 lines
Thanks and Regards, Md Danish Anwar
MD Danish Anwar
reviewerPATCH v11 8/10 net: ti: icssg-prueth: Add Standard network staticstics
In reply to MD Danish AnwarImplement .ndo_get_stats64 to dump standard network interface statistics for ICSSG ethernet driver.
--- drivers/net/ethernet/ti/icssg_prueth.c | 21 +++++++++++++++++++++ drivers/net/ethernet/ti/icssg_prueth.h | 2 ++ drivers/net/ethernet/ti/icssg_stats.c | 13 +++++++++++++ 3 files changed, 36 insertions(+)
drivers/net/ethernet/ti/icssg_prueth.c +21 -0
@@ -1260,6 +1260,26 @@ static int emac_ndo_ioctl(struct net_device *ndev, struct ifreq *ifr, int cmd)return phy_do_ioctl (ndev, ifr, cmd); } +static void emac_ndo_get_stats64 (struct net_device *ndev, +struct rtnl_link_stats64 *stats) +{ +struct prueth_emac *emac =netdev_priv (ndev); + +emac_update_hardware_stats (emac); + + stats->rx_packets =emac_get_stat_by_name (emac,"rx_packets" ); + stats->rx_bytes =emac_get_stat_by_name (emac,"rx_bytes" ); + stats->tx_packets =emac_get_stat_by_name (emac,"tx_packets" ); + stats->tx_bytes =emac_get_stat_by_name (emac,"tx_bytes" ); + stats->rx_crc_errors =emac_get_stat_by_name (emac,"rx_crc_errors" ); + stats->rx_over_errors =emac_get_stat_by_name (emac,"rx_over_errors" ); + + stats->rx_errors = ndev->stats.rx_errors; + stats->rx_dropped = ndev->stats.rx_dropped; + stats->tx_errors = ndev->stats.tx_errors; + stats->tx_dropped = ndev->stats.tx_dropped; +} +static const struct net_device_ops emac_netdev_ops = { .ndo_open = emac_ndo_open, .ndo_stop = emac_ndo_stop,
@@ -1269,6 +1289,7 @@ static const struct net_device_ops emac_netdev_ops = { .ndo_tx_timeout = emac_ndo_tx_timeout, .ndo_set_rx_mode = emac_ndo_set_rx_mode, .ndo_eth_ioctl = emac_ndo_ioctl, + .ndo_get_stats64 = emac_ndo_get_stats64, };/* get emac_port corresponding to eth_node name */
drivers/net/ethernet/ti/icssg_prueth.h +2 -0
@@ -47,6 +47,7 @@/* Number of ICSSG related stats */ #define ICSSG_NUM_STATS 60 +#define ICSSG_NUM_STANDARD_STATS 6/* Firmware status codes */ #define ICSS_HS_FW_READY 0x55555555
@@ -251,4 +252,5 @@ void icssg_config_set_speed(struct prueth_emac *emac);void emac_stats_work_handler (struct work_struct *work);void emac_update_hardware_stats (struct prueth_emac *emac); +int emac_get_stat_by_name (struct prueth_emac *emac,char *stat_name);#endif /* __NET_TI_ICSSG_PRUETH_H */
drivers/net/ethernet/ti/icssg_stats.c +13 -0
@@ -42,3 +42,16 @@ void emac_stats_work_handler(struct work_struct *work)queue_delayed_work (system_long_wq, &emac->stats_work,msecs_to_jiffies ((STATS_TIME_LIMIT_1G_MS *1000 ) / emac->speed)); } + +int emac_get_stat_by_name (struct prueth_emac *emac,char *stat_name) +{ +int i; + +for (i =0 ; i <ARRAY_SIZE (icssg_all_stats); i++) { +if (!strcmp (icssg_all_stats[i].name, stat_name)) +return emac->stats[icssg_all_stats[i].offset /sizeof (u32)]; + } + +netdev_err (emac->ndev,"Invalid stats %s\n" , stat_name); +return -EINVAL ; +}
Signature · 1 line
2.34.1
MD Danish Anwar
reviewerPATCH v11 9/10 net: ti: icssg-prueth: Add ethtool ops for ICSSG Ethernet driver
In reply to MD Danish AnwarAdd icssg_ethtool.c file. This file will be used for dumping statistics via ethtool for ICSSG ethernet driver.
--- drivers/net/ethernet/ti/Makefile | 2 +- drivers/net/ethernet/ti/icssg_ethtool.c | 154 ++++++++++++++++++++++++ drivers/net/ethernet/ti/icssg_prueth.c | 1 + drivers/net/ethernet/ti/icssg_prueth.h | 3 + 4 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/ti/icssg_ethtool.c
drivers/net/ethernet/ti/Makefile +1 -1
@@ -30,4 +30,4 @@ ti-am65-cpsw-nuss-$(CONFIG_TI_K3_AM65_CPSW_SWITCHDEV) += am65-cpsw-switchdev.o obj-$(CONFIG_TI_K3_AM65_CPTS) += am65-cpts.o obj-$(CONFIG_TI_ICSSG_PRUETH) += icssg-prueth.o -icssg-prueth-y := icssg_prueth.o icssg_classifier.o icssg_queues.o icssg_config.o k3-cppi-desc-pool.o icssg_mii_cfg.o icssg_stats.o +icssg-prueth-y := icssg_prueth.o icssg_classifier.o icssg_queues.o icssg_config.o k3-cppi-desc-pool.o icssg_mii_cfg.o icssg_stats.o icssg_ethtool.o
drivers/net/ethernet/ti/icssg_ethtool.c new file +154 -0
154 lines not on this page · raw message
drivers/net/ethernet/ti/icssg_prueth.c +1 -0
@@ -1440,6 +1440,7 @@ static int prueth_netdev_init(struct prueth *prueth, ndev->min_mtu =PRUETH_MIN_PKT_SIZE ; ndev->max_mtu =PRUETH_MAX_MTU ; ndev->netdev_ops = &emac_netdev_ops; + ndev->ethtool_ops = &icssg_ethtool_ops; ndev->hw_features =NETIF_F_SG ; ndev->features = ndev->hw_features;
drivers/net/ethernet/ti/icssg_prueth.h +3 -0
@@ -48,6 +48,7 @@/* Number of ICSSG related stats */ #define ICSSG_NUM_STATS 60#define ICSSG_NUM_STANDARD_STATS 6 +#define ICSSG_NUM_ETHTOOL_STATS (ICSSG_NUM_STATS - ICSSG_NUM_STANDARD_STATS)/* Firmware status codes */ #define ICSS_HS_FW_READY 0x55555555
@@ -239,6 +240,8 @@ static inline int prueth_emac_slice(struct prueth_emac *emac) } } +extern const struct ethtool_ops icssg_ethtool_ops; +/* config helpers */ void icssg_config_ipg (struct prueth_emac *emac); int icssg_config(struct prueth *prueth, struct prueth_emac *emac,
Signature · 1 line
2.34.1
MD Danish Anwar
reviewerPATCH v11 10/10 net: ti: icssg-prueth: Add Power management support
In reply to MD Danish AnwarAdd suspend / resume APIs to support power management in ICSSG ethernet driver.
--- drivers/net/ethernet/ti/icssg_prueth.c | 57 ++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)
drivers/net/ethernet/ti/icssg_prueth.c +57 -0
@@ -1835,6 +1835,62 @@ static int prueth_remove(struct platform_device *pdev)return 0 ; } +#ifdef CONFIG_PM_SLEEP +static int prueth_suspend (struct device *dev) +{ +struct prueth *prueth =dev_get_drvdata (dev); +struct net_device *ndev; +int i, ret; + +for (i =0 ; i <PRUETH_NUM_MACS ; i++) { + ndev = prueth->registered_netdevs[i]; + +if (!ndev) +continue ; + +if (netif_running (ndev)) { +netif_device_detach (ndev); + ret =emac_ndo_stop (ndev); +if (ret <0 ) { +netdev_err (ndev,"failed to stop: %d" , ret); +return ret; + } + } + } + +return 0 ; +} + +static int prueth_resume (struct device *dev) +{ +struct prueth *prueth =dev_get_drvdata (dev); +struct net_device *ndev; +int i, ret; + +for (i =0 ; i <PRUETH_NUM_MACS ; i++) { + ndev = prueth->registered_netdevs[i]; + +if (!ndev) +continue ; + +if (netif_running (ndev)) { + ret =emac_ndo_open (ndev); +if (ret <0 ) { +netdev_err (ndev,"failed to start: %d" , ret); +return ret; + } +netif_device_attach (ndev); + } + } + +return 0 ; +} +#endif /* CONFIG_PM_SLEEP */ + +static const struct dev_pm_ops prueth_dev_pm_ops = { +SET_SYSTEM_SLEEP_PM_OPS (prueth_suspend, prueth_resume) +}; +static const struct prueth_pdata am654_icssg_pdata = { .fdqring_mode =K3_RINGACC_RING_MODE_MESSAGE , .quirk_10m_link_issue =1 ,
@@ -1852,6 +1908,7 @@ static struct platform_driver prueth_driver = { .driver = { .name = "icssg-prueth", .of_match_table = prueth_dt_match, + .pm = &prueth_dev_pm_ops, }, };module_platform_driver (prueth_driver);
Signature · 1 line
2.34.1