1 /* SPDX-License-Identifier: GPL-2.0 */
3 * DPAA2 Ethernet Switch declarations
5 * Copyright 2014-2016 Freescale Semiconductor Inc.
6 * Copyright 2017-2021 NXP
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 <net/pkt_cls.h>
22 #include <soc/fsl/dpaa2-io.h>
24 #include "dpaa2-mac.h"
27 /* Number of IRQs supported */
28 #define DPSW_IRQ_NUM 2
30 /* Port is member of VLAN */
31 #define ETHSW_VLAN_MEMBER 1
32 /* VLAN to be treated as untagged on egress */
33 #define ETHSW_VLAN_UNTAGGED 2
34 /* Untagged frames will be assigned to this VLAN */
35 #define ETHSW_VLAN_PVID 4
36 /* VLAN configured on the switch */
37 #define ETHSW_VLAN_GLOBAL 8
39 /* Maximum Frame Length supported by HW (currently 10k) */
40 #define DPAA2_MFL (10 * 1024)
41 #define ETHSW_MAX_FRAME_LENGTH (DPAA2_MFL - VLAN_ETH_HLEN - ETH_FCS_LEN)
42 #define ETHSW_L2_MAX_FRM(mtu) ((mtu) + VLAN_ETH_HLEN + ETH_FCS_LEN)
44 #define ETHSW_FEATURE_MAC_ADDR BIT(0)
46 /* Number of receive queues (one RX and one TX_CONF) */
47 #define DPAA2_SWITCH_RX_NUM_FQS 2
49 /* Hardware requires alignment for ingress/egress buffer addresses */
50 #define DPAA2_SWITCH_RX_BUF_RAW_SIZE PAGE_SIZE
51 #define DPAA2_SWITCH_RX_BUF_TAILROOM \
52 SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
53 #define DPAA2_SWITCH_RX_BUF_SIZE \
54 (DPAA2_SWITCH_RX_BUF_RAW_SIZE - DPAA2_SWITCH_RX_BUF_TAILROOM)
56 #define DPAA2_SWITCH_STORE_SIZE 16
58 /* Buffer management */
59 #define BUFS_PER_CMD 7
60 #define DPAA2_ETHSW_NUM_BUFS (1024 * BUFS_PER_CMD)
61 #define DPAA2_ETHSW_REFILL_THRESH (DPAA2_ETHSW_NUM_BUFS * 5 / 6)
63 /* Number of times to retry DPIO portal operations while waiting
64 * for portal to finish executing current command and become
65 * available. We want to avoid being stuck in a while loop in case
66 * hardware becomes unresponsive, but not give up too easily if
67 * the portal really is busy for valid reasons
69 #define DPAA2_SWITCH_SWP_BUSY_RETRIES 1000
71 /* Hardware annotation buffer size */
72 #define DPAA2_SWITCH_HWA_SIZE 64
73 /* Software annotation buffer size */
74 #define DPAA2_SWITCH_SWA_SIZE 64
76 #define DPAA2_SWITCH_TX_BUF_ALIGN 64
78 #define DPAA2_SWITCH_TX_DATA_OFFSET \
79 (DPAA2_SWITCH_HWA_SIZE + DPAA2_SWITCH_SWA_SIZE)
81 #define DPAA2_SWITCH_NEEDED_HEADROOM \
82 (DPAA2_SWITCH_TX_DATA_OFFSET + DPAA2_SWITCH_TX_BUF_ALIGN)
84 #define DPAA2_ETHSW_PORT_MAX_ACL_ENTRIES 16
85 #define DPAA2_ETHSW_PORT_DEFAULT_TRAPS 1
87 #define DPAA2_ETHSW_PORT_ACL_CMD_BUF_SIZE 256
89 extern const struct ethtool_ops dpaa2_switch_port_ethtool_ops;
93 struct dpaa2_switch_fq {
94 struct ethsw_core *ethsw;
95 enum dpsw_queue_type type;
96 struct dpaa2_io_store *store;
97 struct dpaa2_io_notification_ctx nctx;
98 struct napi_struct napi;
102 struct dpaa2_switch_fdb {
103 struct net_device *bridge_dev;
108 struct dpaa2_switch_acl_entry {
109 struct list_head list;
111 unsigned long cookie;
113 struct dpsw_acl_entry_cfg cfg;
114 struct dpsw_acl_key key;
117 struct dpaa2_switch_mirror_entry {
118 struct list_head list;
119 struct dpsw_reflection_cfg cfg;
120 unsigned long cookie;
124 struct dpaa2_switch_filter_block {
125 struct ethsw_core *ethsw;
129 struct list_head acl_entries;
133 struct list_head mirror_entries;
137 dpaa2_switch_acl_tbl_is_full(struct dpaa2_switch_filter_block *filter_block)
139 if ((filter_block->num_acl_rules + DPAA2_ETHSW_PORT_DEFAULT_TRAPS) >=
140 DPAA2_ETHSW_PORT_MAX_ACL_ENTRIES)
145 /* Per port private data */
146 struct ethsw_port_priv {
147 struct net_device *netdev;
149 struct ethsw_core *ethsw_data;
153 u8 vlans[VLAN_VID_MASK + 1];
157 struct dpaa2_switch_fdb *fdb;
162 struct dpaa2_switch_filter_block *filter_block;
163 struct dpaa2_mac *mac;
164 /* Protects against changes to port_priv->mac */
165 struct mutex mac_lock;
171 struct fsl_mc_io *mc_io;
173 struct dpsw_attr sw_attr;
175 unsigned long features;
177 struct ethsw_port_priv **ports;
178 struct iommu_domain *iommu_domain;
180 u8 vlans[VLAN_VID_MASK + 1];
182 struct workqueue_struct *workqueue;
184 struct dpaa2_switch_fq fq[DPAA2_SWITCH_RX_NUM_FQS];
185 struct fsl_mc_device *dpbp_dev;
190 struct dpaa2_switch_fdb *fdbs;
191 struct dpaa2_switch_filter_block *filter_blocks;
195 static inline int dpaa2_switch_get_index(struct ethsw_core *ethsw,
196 struct net_device *netdev)
200 for (i = 0; i < ethsw->sw_attr.num_ifs; i++)
201 if (ethsw->ports[i]->netdev == netdev)
202 return ethsw->ports[i]->idx;
207 static inline bool dpaa2_switch_supports_cpu_traffic(struct ethsw_core *ethsw)
209 if (ethsw->sw_attr.options & DPSW_OPT_CTRL_IF_DIS) {
210 dev_err(ethsw->dev, "Control Interface is disabled, cannot probe\n");
214 if (ethsw->sw_attr.flooding_cfg != DPSW_FLOODING_PER_FDB) {
215 dev_err(ethsw->dev, "Flooding domain is not per FDB, cannot probe\n");
219 if (ethsw->sw_attr.broadcast_cfg != DPSW_BROADCAST_PER_FDB) {
220 dev_err(ethsw->dev, "Broadcast domain is not per FDB, cannot probe\n");
224 if (ethsw->sw_attr.max_fdbs < ethsw->sw_attr.num_ifs) {
225 dev_err(ethsw->dev, "The number of FDBs is lower than the number of ports, cannot probe\n");
233 dpaa2_switch_port_is_type_phy(struct ethsw_port_priv *port_priv)
235 return dpaa2_mac_is_type_phy(port_priv->mac);
238 static inline bool dpaa2_switch_port_has_mac(struct ethsw_port_priv *port_priv)
240 return port_priv->mac ? true : false;
243 bool dpaa2_switch_port_dev_check(const struct net_device *netdev);
245 int dpaa2_switch_port_vlans_add(struct net_device *netdev,
246 const struct switchdev_obj_port_vlan *vlan);
248 int dpaa2_switch_port_vlans_del(struct net_device *netdev,
249 const struct switchdev_obj_port_vlan *vlan);
251 typedef int dpaa2_switch_fdb_cb_t(struct ethsw_port_priv *port_priv,
252 struct fdb_dump_entry *fdb_entry,
257 int dpaa2_switch_cls_flower_replace(struct dpaa2_switch_filter_block *block,
258 struct flow_cls_offload *cls);
260 int dpaa2_switch_cls_flower_destroy(struct dpaa2_switch_filter_block *block,
261 struct flow_cls_offload *cls);
263 int dpaa2_switch_cls_matchall_replace(struct dpaa2_switch_filter_block *block,
264 struct tc_cls_matchall_offload *cls);
266 int dpaa2_switch_cls_matchall_destroy(struct dpaa2_switch_filter_block *block,
267 struct tc_cls_matchall_offload *cls);
269 int dpaa2_switch_acl_entry_add(struct dpaa2_switch_filter_block *block,
270 struct dpaa2_switch_acl_entry *entry);
272 int dpaa2_switch_block_offload_mirror(struct dpaa2_switch_filter_block *block,
273 struct ethsw_port_priv *port_priv);
275 int dpaa2_switch_block_unoffload_mirror(struct dpaa2_switch_filter_block *block,
276 struct ethsw_port_priv *port_priv);
277 #endif /* __ETHSW_H */