dpaa2-switch.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. #ifndef __ETHSW_H
  10. #define __ETHSW_H
  11. #include <linux/netdevice.h>
  12. #include <linux/etherdevice.h>
  13. #include <linux/rtnetlink.h>
  14. #include <linux/if_vlan.h>
  15. #include <uapi/linux/if_bridge.h>
  16. #include <net/switchdev.h>
  17. #include <linux/if_bridge.h>
  18. #include <linux/fsl/mc.h>
  19. #include <net/pkt_cls.h>
  20. #include <soc/fsl/dpaa2-io.h>
  21. #include "dpaa2-mac.h"
  22. #include "dpsw.h"
  23. /* Number of IRQs supported */
  24. #define DPSW_IRQ_NUM 2
  25. /* Port is member of VLAN */
  26. #define ETHSW_VLAN_MEMBER 1
  27. /* VLAN to be treated as untagged on egress */
  28. #define ETHSW_VLAN_UNTAGGED 2
  29. /* Untagged frames will be assigned to this VLAN */
  30. #define ETHSW_VLAN_PVID 4
  31. /* VLAN configured on the switch */
  32. #define ETHSW_VLAN_GLOBAL 8
  33. /* Maximum Frame Length supported by HW (currently 10k) */
  34. #define DPAA2_MFL (10 * 1024)
  35. #define ETHSW_MAX_FRAME_LENGTH (DPAA2_MFL - VLAN_ETH_HLEN - ETH_FCS_LEN)
  36. #define ETHSW_L2_MAX_FRM(mtu) ((mtu) + VLAN_ETH_HLEN + ETH_FCS_LEN)
  37. #define ETHSW_FEATURE_MAC_ADDR BIT(0)
  38. /* Number of receive queues (one RX and one TX_CONF) */
  39. #define DPAA2_SWITCH_RX_NUM_FQS 2
  40. /* Hardware requires alignment for ingress/egress buffer addresses */
  41. #define DPAA2_SWITCH_RX_BUF_RAW_SIZE PAGE_SIZE
  42. #define DPAA2_SWITCH_RX_BUF_TAILROOM \
  43. SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
  44. #define DPAA2_SWITCH_RX_BUF_SIZE \
  45. (DPAA2_SWITCH_RX_BUF_RAW_SIZE - DPAA2_SWITCH_RX_BUF_TAILROOM)
  46. #define DPAA2_SWITCH_STORE_SIZE 16
  47. /* Buffer management */
  48. #define BUFS_PER_CMD 7
  49. #define DPAA2_ETHSW_NUM_BUFS (1024 * BUFS_PER_CMD)
  50. #define DPAA2_ETHSW_REFILL_THRESH (DPAA2_ETHSW_NUM_BUFS * 5 / 6)
  51. /* Number of times to retry DPIO portal operations while waiting
  52. * for portal to finish executing current command and become
  53. * available. We want to avoid being stuck in a while loop in case
  54. * hardware becomes unresponsive, but not give up too easily if
  55. * the portal really is busy for valid reasons
  56. */
  57. #define DPAA2_SWITCH_SWP_BUSY_RETRIES 1000
  58. /* Hardware annotation buffer size */
  59. #define DPAA2_SWITCH_HWA_SIZE 64
  60. /* Software annotation buffer size */
  61. #define DPAA2_SWITCH_SWA_SIZE 64
  62. #define DPAA2_SWITCH_TX_BUF_ALIGN 64
  63. #define DPAA2_SWITCH_TX_DATA_OFFSET \
  64. (DPAA2_SWITCH_HWA_SIZE + DPAA2_SWITCH_SWA_SIZE)
  65. #define DPAA2_SWITCH_NEEDED_HEADROOM \
  66. (DPAA2_SWITCH_TX_DATA_OFFSET + DPAA2_SWITCH_TX_BUF_ALIGN)
  67. #define DPAA2_ETHSW_PORT_MAX_ACL_ENTRIES 16
  68. #define DPAA2_ETHSW_PORT_DEFAULT_TRAPS 1
  69. #define DPAA2_ETHSW_PORT_ACL_CMD_BUF_SIZE 256
  70. extern const struct ethtool_ops dpaa2_switch_port_ethtool_ops;
  71. struct ethsw_core;
  72. struct dpaa2_switch_fq {
  73. struct ethsw_core *ethsw;
  74. enum dpsw_queue_type type;
  75. struct dpaa2_io_store *store;
  76. struct dpaa2_io_notification_ctx nctx;
  77. struct napi_struct napi;
  78. u32 fqid;
  79. };
  80. struct dpaa2_switch_fdb {
  81. struct net_device *bridge_dev;
  82. u16 fdb_id;
  83. bool in_use;
  84. };
  85. struct dpaa2_switch_acl_entry {
  86. struct list_head list;
  87. u16 prio;
  88. unsigned long cookie;
  89. struct dpsw_acl_entry_cfg cfg;
  90. struct dpsw_acl_key key;
  91. };
  92. struct dpaa2_switch_mirror_entry {
  93. struct list_head list;
  94. struct dpsw_reflection_cfg cfg;
  95. unsigned long cookie;
  96. u16 if_id;
  97. };
  98. struct dpaa2_switch_filter_block {
  99. struct ethsw_core *ethsw;
  100. u64 ports;
  101. bool in_use;
  102. struct list_head acl_entries;
  103. u16 acl_id;
  104. u8 num_acl_rules;
  105. struct list_head mirror_entries;
  106. };
  107. static inline bool
  108. dpaa2_switch_acl_tbl_is_full(struct dpaa2_switch_filter_block *filter_block)
  109. {
  110. if ((filter_block->num_acl_rules + DPAA2_ETHSW_PORT_DEFAULT_TRAPS) >=
  111. DPAA2_ETHSW_PORT_MAX_ACL_ENTRIES)
  112. return true;
  113. return false;
  114. }
  115. /* Per port private data */
  116. struct ethsw_port_priv {
  117. struct net_device *netdev;
  118. u16 idx;
  119. struct ethsw_core *ethsw_data;
  120. u8 link_state;
  121. u8 stp_state;
  122. u8 vlans[VLAN_VID_MASK + 1];
  123. u16 pvid;
  124. u16 tx_qdid;
  125. struct dpaa2_switch_fdb *fdb;
  126. bool bcast_flood;
  127. bool ucast_flood;
  128. bool learn_ena;
  129. struct dpaa2_switch_filter_block *filter_block;
  130. struct dpaa2_mac *mac;
  131. };
  132. /* Switch data */
  133. struct ethsw_core {
  134. struct device *dev;
  135. struct fsl_mc_io *mc_io;
  136. u16 dpsw_handle;
  137. struct dpsw_attr sw_attr;
  138. u16 major, minor;
  139. unsigned long features;
  140. int dev_id;
  141. struct ethsw_port_priv **ports;
  142. struct iommu_domain *iommu_domain;
  143. u8 vlans[VLAN_VID_MASK + 1];
  144. struct workqueue_struct *workqueue;
  145. struct dpaa2_switch_fq fq[DPAA2_SWITCH_RX_NUM_FQS];
  146. struct fsl_mc_device *dpbp_dev;
  147. int buf_count;
  148. u16 bpid;
  149. int napi_users;
  150. struct dpaa2_switch_fdb *fdbs;
  151. struct dpaa2_switch_filter_block *filter_blocks;
  152. u16 mirror_port;
  153. };
  154. static inline int dpaa2_switch_get_index(struct ethsw_core *ethsw,
  155. struct net_device *netdev)
  156. {
  157. int i;
  158. for (i = 0; i < ethsw->sw_attr.num_ifs; i++)
  159. if (ethsw->ports[i]->netdev == netdev)
  160. return ethsw->ports[i]->idx;
  161. return -EINVAL;
  162. }
  163. static inline bool dpaa2_switch_supports_cpu_traffic(struct ethsw_core *ethsw)
  164. {
  165. if (ethsw->sw_attr.options & DPSW_OPT_CTRL_IF_DIS) {
  166. dev_err(ethsw->dev, "Control Interface is disabled, cannot probe\n");
  167. return false;
  168. }
  169. if (ethsw->sw_attr.flooding_cfg != DPSW_FLOODING_PER_FDB) {
  170. dev_err(ethsw->dev, "Flooding domain is not per FDB, cannot probe\n");
  171. return false;
  172. }
  173. if (ethsw->sw_attr.broadcast_cfg != DPSW_BROADCAST_PER_FDB) {
  174. dev_err(ethsw->dev, "Broadcast domain is not per FDB, cannot probe\n");
  175. return false;
  176. }
  177. if (ethsw->sw_attr.max_fdbs < ethsw->sw_attr.num_ifs) {
  178. dev_err(ethsw->dev, "The number of FDBs is lower than the number of ports, cannot probe\n");
  179. return false;
  180. }
  181. return true;
  182. }
  183. static inline bool
  184. dpaa2_switch_port_is_type_phy(struct ethsw_port_priv *port_priv)
  185. {
  186. if (port_priv->mac &&
  187. (port_priv->mac->attr.link_type == DPMAC_LINK_TYPE_PHY ||
  188. port_priv->mac->attr.link_type == DPMAC_LINK_TYPE_BACKPLANE))
  189. return true;
  190. return false;
  191. }
  192. static inline bool dpaa2_switch_port_has_mac(struct ethsw_port_priv *port_priv)
  193. {
  194. return port_priv->mac ? true : false;
  195. }
  196. bool dpaa2_switch_port_dev_check(const struct net_device *netdev);
  197. int dpaa2_switch_port_vlans_add(struct net_device *netdev,
  198. const struct switchdev_obj_port_vlan *vlan);
  199. int dpaa2_switch_port_vlans_del(struct net_device *netdev,
  200. const struct switchdev_obj_port_vlan *vlan);
  201. typedef int dpaa2_switch_fdb_cb_t(struct ethsw_port_priv *port_priv,
  202. struct fdb_dump_entry *fdb_entry,
  203. void *data);
  204. /* TC offload */
  205. int dpaa2_switch_cls_flower_replace(struct dpaa2_switch_filter_block *block,
  206. struct flow_cls_offload *cls);
  207. int dpaa2_switch_cls_flower_destroy(struct dpaa2_switch_filter_block *block,
  208. struct flow_cls_offload *cls);
  209. int dpaa2_switch_cls_matchall_replace(struct dpaa2_switch_filter_block *block,
  210. struct tc_cls_matchall_offload *cls);
  211. int dpaa2_switch_cls_matchall_destroy(struct dpaa2_switch_filter_block *block,
  212. struct tc_cls_matchall_offload *cls);
  213. int dpaa2_switch_acl_entry_add(struct dpaa2_switch_filter_block *block,
  214. struct dpaa2_switch_acl_entry *entry);
  215. int dpaa2_switch_block_offload_mirror(struct dpaa2_switch_filter_block *block,
  216. struct ethsw_port_priv *port_priv);
  217. int dpaa2_switch_block_unoffload_mirror(struct dpaa2_switch_filter_block *block,
  218. struct ethsw_port_priv *port_priv);
  219. #endif /* __ETHSW_H */