1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * DPAA2 Ethernet Switch declarations 4 * 5 * Copyright 2014-2016 Freescale Semiconductor Inc. 6 * Copyright 2017-2021 NXP 7 * 8 */ 9 10 #ifndef __ETHSW_H 11 #define __ETHSW_H 12 13 #include <linux/netdevice.h> 14 #include <linux/etherdevice.h> 15 #include <linux/rtnetlink.h> 16 #include <linux/if_vlan.h> 17 #include <uapi/linux/if_bridge.h> 18 #include <net/switchdev.h> 19 #include <linux/if_bridge.h> 20 #include <linux/fsl/mc.h> 21 #include <soc/fsl/dpaa2-io.h> 22 23 #include "dpsw.h" 24 25 /* Number of IRQs supported */ 26 #define DPSW_IRQ_NUM 2 27 28 /* Port is member of VLAN */ 29 #define ETHSW_VLAN_MEMBER 1 30 /* VLAN to be treated as untagged on egress */ 31 #define ETHSW_VLAN_UNTAGGED 2 32 /* Untagged frames will be assigned to this VLAN */ 33 #define ETHSW_VLAN_PVID 4 34 /* VLAN configured on the switch */ 35 #define ETHSW_VLAN_GLOBAL 8 36 37 /* Maximum Frame Length supported by HW (currently 10k) */ 38 #define DPAA2_MFL (10 * 1024) 39 #define ETHSW_MAX_FRAME_LENGTH (DPAA2_MFL - VLAN_ETH_HLEN - ETH_FCS_LEN) 40 #define ETHSW_L2_MAX_FRM(mtu) ((mtu) + VLAN_ETH_HLEN + ETH_FCS_LEN) 41 42 #define ETHSW_FEATURE_MAC_ADDR BIT(0) 43 44 /* Number of receive queues (one RX and one TX_CONF) */ 45 #define DPAA2_SWITCH_RX_NUM_FQS 2 46 47 /* Hardware requires alignment for ingress/egress buffer addresses */ 48 #define DPAA2_SWITCH_RX_BUF_RAW_SIZE PAGE_SIZE 49 #define DPAA2_SWITCH_RX_BUF_TAILROOM \ 50 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) 51 #define DPAA2_SWITCH_RX_BUF_SIZE \ 52 (DPAA2_SWITCH_RX_BUF_RAW_SIZE - DPAA2_SWITCH_RX_BUF_TAILROOM) 53 54 #define DPAA2_SWITCH_STORE_SIZE 16 55 56 /* Buffer management */ 57 #define BUFS_PER_CMD 7 58 #define DPAA2_ETHSW_NUM_BUFS (1024 * BUFS_PER_CMD) 59 #define DPAA2_ETHSW_REFILL_THRESH (DPAA2_ETHSW_NUM_BUFS * 5 / 6) 60 61 /* Number of times to retry DPIO portal operations while waiting 62 * for portal to finish executing current command and become 63 * available. We want to avoid being stuck in a while loop in case 64 * hardware becomes unresponsive, but not give up too easily if 65 * the portal really is busy for valid reasons 66 */ 67 #define DPAA2_SWITCH_SWP_BUSY_RETRIES 1000 68 69 /* Hardware annotation buffer size */ 70 #define DPAA2_SWITCH_HWA_SIZE 64 71 /* Software annotation buffer size */ 72 #define DPAA2_SWITCH_SWA_SIZE 64 73 74 #define DPAA2_SWITCH_TX_BUF_ALIGN 64 75 76 #define DPAA2_SWITCH_TX_DATA_OFFSET \ 77 (DPAA2_SWITCH_HWA_SIZE + DPAA2_SWITCH_SWA_SIZE) 78 79 #define DPAA2_SWITCH_NEEDED_HEADROOM \ 80 (DPAA2_SWITCH_TX_DATA_OFFSET + DPAA2_SWITCH_TX_BUF_ALIGN) 81 82 extern const struct ethtool_ops dpaa2_switch_port_ethtool_ops; 83 84 struct ethsw_core; 85 86 struct dpaa2_switch_fq { 87 struct ethsw_core *ethsw; 88 enum dpsw_queue_type type; 89 struct dpaa2_io_store *store; 90 struct dpaa2_io_notification_ctx nctx; 91 struct napi_struct napi; 92 u32 fqid; 93 }; 94 95 struct dpaa2_switch_fdb { 96 struct net_device *bridge_dev; 97 u16 fdb_id; 98 bool in_use; 99 }; 100 101 /* Per port private data */ 102 struct ethsw_port_priv { 103 struct net_device *netdev; 104 u16 idx; 105 struct ethsw_core *ethsw_data; 106 u8 link_state; 107 u8 stp_state; 108 bool flood; 109 110 u8 vlans[VLAN_VID_MASK + 1]; 111 u16 pvid; 112 u16 tx_qdid; 113 114 struct dpaa2_switch_fdb *fdb; 115 }; 116 117 /* Switch data */ 118 struct ethsw_core { 119 struct device *dev; 120 struct fsl_mc_io *mc_io; 121 u16 dpsw_handle; 122 struct dpsw_attr sw_attr; 123 u16 major, minor; 124 unsigned long features; 125 int dev_id; 126 struct ethsw_port_priv **ports; 127 struct iommu_domain *iommu_domain; 128 129 u8 vlans[VLAN_VID_MASK + 1]; 130 131 struct workqueue_struct *workqueue; 132 133 struct dpaa2_switch_fq fq[DPAA2_SWITCH_RX_NUM_FQS]; 134 struct fsl_mc_device *dpbp_dev; 135 int buf_count; 136 u16 bpid; 137 int napi_users; 138 139 struct dpaa2_switch_fdb *fdbs; 140 }; 141 142 static inline bool dpaa2_switch_supports_cpu_traffic(struct ethsw_core *ethsw) 143 { 144 if (ethsw->sw_attr.options & DPSW_OPT_CTRL_IF_DIS) { 145 dev_err(ethsw->dev, "Control Interface is disabled, cannot probe\n"); 146 return false; 147 } 148 149 if (ethsw->sw_attr.flooding_cfg != DPSW_FLOODING_PER_FDB) { 150 dev_err(ethsw->dev, "Flooding domain is not per FDB, cannot probe\n"); 151 return false; 152 } 153 154 if (ethsw->sw_attr.broadcast_cfg != DPSW_BROADCAST_PER_FDB) { 155 dev_err(ethsw->dev, "Broadcast domain is not per FDB, cannot probe\n"); 156 return false; 157 } 158 159 if (ethsw->sw_attr.max_fdbs < ethsw->sw_attr.num_ifs) { 160 dev_err(ethsw->dev, "The number of FDBs is lower than the number of ports, cannot probe\n"); 161 return false; 162 } 163 164 return true; 165 } 166 167 bool dpaa2_switch_port_dev_check(const struct net_device *netdev); 168 169 int dpaa2_switch_port_vlans_add(struct net_device *netdev, 170 const struct switchdev_obj_port_vlan *vlan); 171 172 int dpaa2_switch_port_vlans_del(struct net_device *netdev, 173 const struct switchdev_obj_port_vlan *vlan); 174 175 typedef int dpaa2_switch_fdb_cb_t(struct ethsw_port_priv *port_priv, 176 struct fdb_dump_entry *fdb_entry, 177 void *data); 178 #endif /* __ETHSW_H */ 179