Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com/
0003  *
0004  */
0005 
0006 #ifndef AM65_CPSW_NUSS_H_
0007 #define AM65_CPSW_NUSS_H_
0008 
0009 #include <linux/if_ether.h>
0010 #include <linux/kernel.h>
0011 #include <linux/module.h>
0012 #include <linux/netdevice.h>
0013 #include <linux/phylink.h>
0014 #include <linux/platform_device.h>
0015 #include <linux/soc/ti/k3-ringacc.h>
0016 #include <net/devlink.h>
0017 #include "am65-cpsw-qos.h"
0018 
0019 struct am65_cpts;
0020 
0021 #define HOST_PORT_NUM       0
0022 
0023 #define AM65_CPSW_MAX_TX_QUEUES 8
0024 #define AM65_CPSW_MAX_RX_QUEUES 1
0025 #define AM65_CPSW_MAX_RX_FLOWS  1
0026 
0027 #define AM65_CPSW_PORT_VLAN_REG_OFFSET  0x014
0028 
0029 struct am65_cpsw_slave_data {
0030     bool                mac_only;
0031     struct cpsw_sl          *mac_sl;
0032     struct device_node      *phy_node;
0033     phy_interface_t         phy_if;
0034     struct phy          *ifphy;
0035     bool                rx_pause;
0036     bool                tx_pause;
0037     u8              mac_addr[ETH_ALEN];
0038     int             port_vlan;
0039     struct phylink          *phylink;
0040     struct phylink_config       phylink_config;
0041 };
0042 
0043 struct am65_cpsw_port {
0044     struct am65_cpsw_common     *common;
0045     struct net_device       *ndev;
0046     const char          *name;
0047     u32             port_id;
0048     void __iomem            *port_base;
0049     void __iomem            *stat_base;
0050     void __iomem            *fetch_ram_base;
0051     bool                disabled;
0052     struct am65_cpsw_slave_data slave;
0053     bool                tx_ts_enabled;
0054     bool                rx_ts_enabled;
0055     struct am65_cpsw_qos        qos;
0056     struct devlink_port     devlink_port;
0057 };
0058 
0059 struct am65_cpsw_host {
0060     struct am65_cpsw_common     *common;
0061     void __iomem            *port_base;
0062     void __iomem            *stat_base;
0063 };
0064 
0065 struct am65_cpsw_tx_chn {
0066     struct device *dma_dev;
0067     struct napi_struct napi_tx;
0068     struct am65_cpsw_common *common;
0069     struct k3_cppi_desc_pool *desc_pool;
0070     struct k3_udma_glue_tx_channel *tx_chn;
0071     spinlock_t lock; /* protect TX rings in multi-port mode */
0072     int irq;
0073     u32 id;
0074     u32 descs_num;
0075     char tx_chn_name[128];
0076 };
0077 
0078 struct am65_cpsw_rx_chn {
0079     struct device *dev;
0080     struct device *dma_dev;
0081     struct k3_cppi_desc_pool *desc_pool;
0082     struct k3_udma_glue_rx_channel *rx_chn;
0083     u32 descs_num;
0084     int irq;
0085 };
0086 
0087 #define AM65_CPSW_QUIRK_I2027_NO_TX_CSUM BIT(0)
0088 
0089 struct am65_cpsw_pdata {
0090     u32 quirks;
0091     enum k3_ring_mode fdqring_mode;
0092     const char  *ale_dev_id;
0093 };
0094 
0095 enum cpsw_devlink_param_id {
0096     AM65_CPSW_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
0097     AM65_CPSW_DL_PARAM_SWITCH_MODE,
0098 };
0099 
0100 struct am65_cpsw_devlink {
0101     struct am65_cpsw_common *common;
0102 };
0103 
0104 struct am65_cpsw_common {
0105     struct device       *dev;
0106     struct device       *mdio_dev;
0107     struct am65_cpsw_pdata  pdata;
0108 
0109     void __iomem        *ss_base;
0110     void __iomem        *cpsw_base;
0111 
0112     u32         port_num;
0113     struct am65_cpsw_host   host;
0114     struct am65_cpsw_port   *ports;
0115     u32         disabled_ports_mask;
0116     struct net_device   *dma_ndev;
0117 
0118     int         usage_count; /* number of opened ports */
0119     struct cpsw_ale     *ale;
0120     int         tx_ch_num;
0121     u32         rx_flow_id_base;
0122 
0123     struct am65_cpsw_tx_chn tx_chns[AM65_CPSW_MAX_TX_QUEUES];
0124     struct completion   tdown_complete;
0125     atomic_t        tdown_cnt;
0126 
0127     struct am65_cpsw_rx_chn rx_chns;
0128     struct napi_struct  napi_rx;
0129 
0130     bool            rx_irq_disabled;
0131 
0132     u32         nuss_ver;
0133     u32         cpsw_ver;
0134     unsigned long       bus_freq;
0135     bool            pf_p0_rx_ptype_rrobin;
0136     struct am65_cpts    *cpts;
0137     int         est_enabled;
0138 
0139     bool        is_emac_mode;
0140     u16         br_members;
0141     int         default_vlan;
0142     struct devlink *devlink;
0143     struct net_device *hw_bridge_dev;
0144     struct notifier_block am65_cpsw_netdevice_nb;
0145     unsigned char switch_id[MAX_PHYS_ITEM_ID_LEN];
0146 };
0147 
0148 struct am65_cpsw_ndev_stats {
0149     u64 tx_packets;
0150     u64 tx_bytes;
0151     u64 rx_packets;
0152     u64 rx_bytes;
0153     struct u64_stats_sync syncp;
0154 };
0155 
0156 struct am65_cpsw_ndev_priv {
0157     u32         msg_enable;
0158     struct am65_cpsw_port   *port;
0159     struct am65_cpsw_ndev_stats __percpu *stats;
0160     bool offload_fwd_mark;
0161 };
0162 
0163 #define am65_ndev_to_priv(ndev) \
0164     ((struct am65_cpsw_ndev_priv *)netdev_priv(ndev))
0165 #define am65_ndev_to_port(ndev) (am65_ndev_to_priv(ndev)->port)
0166 #define am65_ndev_to_common(ndev) (am65_ndev_to_port(ndev)->common)
0167 #define am65_ndev_to_slave(ndev) (&am65_ndev_to_port(ndev)->slave)
0168 
0169 #define am65_common_get_host(common) (&(common)->host)
0170 #define am65_common_get_port(common, id) (&(common)->ports[(id) - 1])
0171 
0172 #define am65_cpsw_napi_to_common(pnapi) \
0173     container_of(pnapi, struct am65_cpsw_common, napi_rx)
0174 #define am65_cpsw_napi_to_tx_chn(pnapi) \
0175     container_of(pnapi, struct am65_cpsw_tx_chn, napi_tx)
0176 
0177 #define AM65_CPSW_DRV_NAME "am65-cpsw-nuss"
0178 
0179 #define AM65_CPSW_IS_CPSW2G(common) ((common)->port_num == 1)
0180 
0181 extern const struct ethtool_ops am65_cpsw_ethtool_ops_slave;
0182 
0183 void am65_cpsw_nuss_adjust_link(struct net_device *ndev);
0184 void am65_cpsw_nuss_set_p0_ptype(struct am65_cpsw_common *common);
0185 void am65_cpsw_nuss_remove_tx_chns(struct am65_cpsw_common *common);
0186 int am65_cpsw_nuss_update_tx_chns(struct am65_cpsw_common *common, int num_tx);
0187 
0188 bool am65_cpsw_port_dev_check(const struct net_device *dev);
0189 
0190 #endif /* AM65_CPSW_NUSS_H_ */