1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com/ 3 * 4 */ 5 6 #ifndef AM65_CPSW_NUSS_H_ 7 #define AM65_CPSW_NUSS_H_ 8 9 #include <linux/kernel.h> 10 #include <linux/module.h> 11 #include <linux/netdevice.h> 12 #include <linux/phy.h> 13 #include <linux/platform_device.h> 14 #include <linux/soc/ti/k3-ringacc.h> 15 #include "am65-cpsw-qos.h" 16 17 struct am65_cpts; 18 19 #define HOST_PORT_NUM 0 20 21 #define AM65_CPSW_MAX_TX_QUEUES 8 22 #define AM65_CPSW_MAX_RX_QUEUES 1 23 #define AM65_CPSW_MAX_RX_FLOWS 1 24 25 struct am65_cpsw_slave_data { 26 bool mac_only; 27 struct cpsw_sl *mac_sl; 28 struct device_node *phy_node; 29 struct phy_device *phy; 30 phy_interface_t phy_if; 31 struct phy *ifphy; 32 bool rx_pause; 33 bool tx_pause; 34 u8 mac_addr[ETH_ALEN]; 35 }; 36 37 struct am65_cpsw_port { 38 struct am65_cpsw_common *common; 39 struct net_device *ndev; 40 const char *name; 41 u32 port_id; 42 void __iomem *port_base; 43 void __iomem *stat_base; 44 void __iomem *fetch_ram_base; 45 bool disabled; 46 struct am65_cpsw_slave_data slave; 47 bool tx_ts_enabled; 48 bool rx_ts_enabled; 49 struct am65_cpsw_qos qos; 50 }; 51 52 struct am65_cpsw_host { 53 struct am65_cpsw_common *common; 54 void __iomem *port_base; 55 void __iomem *stat_base; 56 }; 57 58 struct am65_cpsw_tx_chn { 59 struct device *dma_dev; 60 struct napi_struct napi_tx; 61 struct am65_cpsw_common *common; 62 struct k3_cppi_desc_pool *desc_pool; 63 struct k3_udma_glue_tx_channel *tx_chn; 64 spinlock_t lock; /* protect TX rings in multi-port mode */ 65 int irq; 66 u32 id; 67 u32 descs_num; 68 char tx_chn_name[128]; 69 }; 70 71 struct am65_cpsw_rx_chn { 72 struct device *dev; 73 struct device *dma_dev; 74 struct k3_cppi_desc_pool *desc_pool; 75 struct k3_udma_glue_rx_channel *rx_chn; 76 u32 descs_num; 77 int irq; 78 }; 79 80 #define AM65_CPSW_QUIRK_I2027_NO_TX_CSUM BIT(0) 81 82 struct am65_cpsw_pdata { 83 u32 quirks; 84 enum k3_ring_mode fdqring_mode; 85 const char *ale_dev_id; 86 }; 87 88 struct am65_cpsw_common { 89 struct device *dev; 90 struct device *mdio_dev; 91 struct am65_cpsw_pdata pdata; 92 93 void __iomem *ss_base; 94 void __iomem *cpsw_base; 95 96 u32 port_num; 97 struct am65_cpsw_host host; 98 struct am65_cpsw_port *ports; 99 u32 disabled_ports_mask; 100 struct net_device *dma_ndev; 101 102 int usage_count; /* number of opened ports */ 103 struct cpsw_ale *ale; 104 int tx_ch_num; 105 u32 rx_flow_id_base; 106 107 struct am65_cpsw_tx_chn tx_chns[AM65_CPSW_MAX_TX_QUEUES]; 108 struct completion tdown_complete; 109 atomic_t tdown_cnt; 110 111 struct am65_cpsw_rx_chn rx_chns; 112 struct napi_struct napi_rx; 113 114 u32 nuss_ver; 115 u32 cpsw_ver; 116 unsigned long bus_freq; 117 bool pf_p0_rx_ptype_rrobin; 118 struct am65_cpts *cpts; 119 int est_enabled; 120 }; 121 122 struct am65_cpsw_ndev_stats { 123 u64 tx_packets; 124 u64 tx_bytes; 125 u64 rx_packets; 126 u64 rx_bytes; 127 struct u64_stats_sync syncp; 128 }; 129 130 struct am65_cpsw_ndev_priv { 131 u32 msg_enable; 132 struct am65_cpsw_port *port; 133 struct am65_cpsw_ndev_stats __percpu *stats; 134 }; 135 136 #define am65_ndev_to_priv(ndev) \ 137 ((struct am65_cpsw_ndev_priv *)netdev_priv(ndev)) 138 #define am65_ndev_to_port(ndev) (am65_ndev_to_priv(ndev)->port) 139 #define am65_ndev_to_common(ndev) (am65_ndev_to_port(ndev)->common) 140 #define am65_ndev_to_slave(ndev) (&am65_ndev_to_port(ndev)->slave) 141 142 #define am65_common_get_host(common) (&(common)->host) 143 #define am65_common_get_port(common, id) (&(common)->ports[(id) - 1]) 144 145 #define am65_cpsw_napi_to_common(pnapi) \ 146 container_of(pnapi, struct am65_cpsw_common, napi_rx) 147 #define am65_cpsw_napi_to_tx_chn(pnapi) \ 148 container_of(pnapi, struct am65_cpsw_tx_chn, napi_tx) 149 150 #define AM65_CPSW_DRV_NAME "am65-cpsw-nuss" 151 152 #define AM65_CPSW_IS_CPSW2G(common) ((common)->port_num == 1) 153 154 extern const struct ethtool_ops am65_cpsw_ethtool_ops_slave; 155 156 void am65_cpsw_nuss_adjust_link(struct net_device *ndev); 157 void am65_cpsw_nuss_set_p0_ptype(struct am65_cpsw_common *common); 158 void am65_cpsw_nuss_remove_tx_chns(struct am65_cpsw_common *common); 159 int am65_cpsw_nuss_update_tx_chns(struct am65_cpsw_common *common, int num_tx); 160 161 #endif /* AM65_CPSW_NUSS_H_ */ 162