2020-03-24 01:52:49 +03:00
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com/
*
*/
# ifndef AM65_CPSW_NUSS_H_
# define AM65_CPSW_NUSS_H_
2021-02-11 13:56:41 +03:00
# include <linux/if_ether.h>
2020-03-24 01:52:49 +03:00
# include <linux/kernel.h>
# include <linux/module.h>
# include <linux/netdevice.h>
2020-05-13 16:26:15 +03:00
# include <linux/phy.h>
2020-05-06 21:13:59 +03:00
# include <linux/platform_device.h>
2020-10-30 23:06:59 +03:00
# include <linux/soc/ti/k3-ringacc.h>
2021-02-11 13:56:41 +03:00
# include <net/devlink.h>
2020-05-13 16:26:15 +03:00
# include "am65-cpsw-qos.h"
2020-03-24 01:52:49 +03:00
2020-05-01 23:50:07 +03:00
struct am65_cpts ;
2020-03-24 01:52:49 +03:00
# define HOST_PORT_NUM 0
# define AM65_CPSW_MAX_TX_QUEUES 8
# define AM65_CPSW_MAX_RX_QUEUES 1
# define AM65_CPSW_MAX_RX_FLOWS 1
2021-02-11 13:56:41 +03:00
# define AM65_CPSW_PORT_VLAN_REG_OFFSET 0x014
2020-03-24 01:52:49 +03:00
struct am65_cpsw_slave_data {
bool mac_only ;
struct cpsw_sl * mac_sl ;
struct device_node * phy_node ;
struct phy_device * phy ;
phy_interface_t phy_if ;
struct phy * ifphy ;
bool rx_pause ;
bool tx_pause ;
u8 mac_addr [ ETH_ALEN ] ;
2021-02-11 13:56:41 +03:00
int port_vlan ;
2020-03-24 01:52:49 +03:00
} ;
struct am65_cpsw_port {
struct am65_cpsw_common * common ;
struct net_device * ndev ;
const char * name ;
u32 port_id ;
void __iomem * port_base ;
void __iomem * stat_base ;
2020-05-13 16:26:15 +03:00
void __iomem * fetch_ram_base ;
2020-03-24 01:52:49 +03:00
bool disabled ;
struct am65_cpsw_slave_data slave ;
2020-05-01 23:50:07 +03:00
bool tx_ts_enabled ;
bool rx_ts_enabled ;
2020-05-13 16:26:15 +03:00
struct am65_cpsw_qos qos ;
2021-02-11 13:56:41 +03:00
struct devlink_port devlink_port ;
2020-03-24 01:52:49 +03:00
} ;
struct am65_cpsw_host {
struct am65_cpsw_common * common ;
void __iomem * port_base ;
void __iomem * stat_base ;
} ;
struct am65_cpsw_tx_chn {
2021-01-15 22:28:50 +03:00
struct device * dma_dev ;
2020-03-24 01:52:49 +03:00
struct napi_struct napi_tx ;
struct am65_cpsw_common * common ;
struct k3_cppi_desc_pool * desc_pool ;
struct k3_udma_glue_tx_channel * tx_chn ;
2020-10-30 23:07:05 +03:00
spinlock_t lock ; /* protect TX rings in multi-port mode */
2020-03-24 01:52:49 +03:00
int irq ;
u32 id ;
u32 descs_num ;
char tx_chn_name [ 128 ] ;
} ;
struct am65_cpsw_rx_chn {
struct device * dev ;
2021-01-15 22:28:50 +03:00
struct device * dma_dev ;
2020-03-24 01:52:49 +03:00
struct k3_cppi_desc_pool * desc_pool ;
struct k3_udma_glue_rx_channel * rx_chn ;
u32 descs_num ;
int irq ;
} ;
# define AM65_CPSW_QUIRK_I2027_NO_TX_CSUM BIT(0)
struct am65_cpsw_pdata {
u32 quirks ;
2020-10-30 23:06:59 +03:00
enum k3_ring_mode fdqring_mode ;
2020-10-30 23:06:58 +03:00
const char * ale_dev_id ;
2020-03-24 01:52:49 +03:00
} ;
2021-02-11 13:56:41 +03:00
enum cpsw_devlink_param_id {
AM65_CPSW_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX ,
AM65_CPSW_DL_PARAM_SWITCH_MODE ,
} ;
struct am65_cpsw_devlink {
struct am65_cpsw_common * common ;
} ;
2020-03-24 01:52:49 +03:00
struct am65_cpsw_common {
struct device * dev ;
2020-05-06 21:13:59 +03:00
struct device * mdio_dev ;
2020-06-26 21:17:09 +03:00
struct am65_cpsw_pdata pdata ;
2020-03-24 01:52:49 +03:00
void __iomem * ss_base ;
void __iomem * cpsw_base ;
u32 port_num ;
struct am65_cpsw_host host ;
struct am65_cpsw_port * ports ;
u32 disabled_ports_mask ;
2020-10-30 23:07:06 +03:00
struct net_device * dma_ndev ;
2020-03-24 01:52:49 +03:00
int usage_count ; /* number of opened ports */
struct cpsw_ale * ale ;
int tx_ch_num ;
u32 rx_flow_id_base ;
struct am65_cpsw_tx_chn tx_chns [ AM65_CPSW_MAX_TX_QUEUES ] ;
struct completion tdown_complete ;
atomic_t tdown_cnt ;
struct am65_cpsw_rx_chn rx_chns ;
struct napi_struct napi_rx ;
2021-08-06 01:55:31 +03:00
bool rx_irq_disabled ;
2020-03-24 01:52:49 +03:00
u32 nuss_ver ;
u32 cpsw_ver ;
2020-09-10 23:28:05 +03:00
unsigned long bus_freq ;
2020-03-24 01:52:49 +03:00
bool pf_p0_rx_ptype_rrobin ;
2020-05-01 23:50:07 +03:00
struct am65_cpts * cpts ;
2020-05-13 16:26:15 +03:00
int est_enabled ;
2021-02-11 13:56:41 +03:00
bool is_emac_mode ;
u16 br_members ;
int default_vlan ;
struct devlink * devlink ;
2021-02-11 13:56:42 +03:00
struct net_device * hw_bridge_dev ;
struct notifier_block am65_cpsw_netdevice_nb ;
2021-02-11 13:56:41 +03:00
unsigned char switch_id [ MAX_PHYS_ITEM_ID_LEN ] ;
2020-03-24 01:52:49 +03:00
} ;
struct am65_cpsw_ndev_stats {
u64 tx_packets ;
u64 tx_bytes ;
u64 rx_packets ;
u64 rx_bytes ;
struct u64_stats_sync syncp ;
} ;
struct am65_cpsw_ndev_priv {
u32 msg_enable ;
struct am65_cpsw_port * port ;
struct am65_cpsw_ndev_stats __percpu * stats ;
2021-02-11 13:56:41 +03:00
bool offload_fwd_mark ;
2020-03-24 01:52:49 +03:00
} ;
# define am65_ndev_to_priv(ndev) \
( ( struct am65_cpsw_ndev_priv * ) netdev_priv ( ndev ) )
# define am65_ndev_to_port(ndev) (am65_ndev_to_priv(ndev)->port)
# define am65_ndev_to_common(ndev) (am65_ndev_to_port(ndev)->common)
# define am65_ndev_to_slave(ndev) (&am65_ndev_to_port(ndev)->slave)
# define am65_common_get_host(common) (&(common)->host)
# define am65_common_get_port(common, id) (&(common)->ports[(id) - 1])
# define am65_cpsw_napi_to_common(pnapi) \
container_of ( pnapi , struct am65_cpsw_common , napi_rx )
# define am65_cpsw_napi_to_tx_chn(pnapi) \
container_of ( pnapi , struct am65_cpsw_tx_chn , napi_tx )
# define AM65_CPSW_DRV_NAME "am65-cpsw-nuss"
# define AM65_CPSW_IS_CPSW2G(common) ((common)->port_num == 1)
extern const struct ethtool_ops am65_cpsw_ethtool_ops_slave ;
void am65_cpsw_nuss_adjust_link ( struct net_device * ndev ) ;
void am65_cpsw_nuss_set_p0_ptype ( struct am65_cpsw_common * common ) ;
void am65_cpsw_nuss_remove_tx_chns ( struct am65_cpsw_common * common ) ;
int am65_cpsw_nuss_update_tx_chns ( struct am65_cpsw_common * common , int num_tx ) ;
2021-02-11 13:56:42 +03:00
bool am65_cpsw_port_dev_check ( const struct net_device * dev ) ;
2020-03-24 01:52:49 +03:00
# endif /* AM65_CPSW_NUSS_H_ */