ldpaa_eth.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright 2014-2016 Freescale Semiconductor, Inc.
  4. * Copyright 2017 NXP
  5. */
  6. #ifndef __LDPAA_ETH_H
  7. #define __LDPAA_ETH_H
  8. #include <linux/netdevice.h>
  9. #include <fsl-mc/fsl_mc.h>
  10. #include <fsl-mc/fsl_dpaa_fd.h>
  11. #include <fsl-mc/fsl_dprc.h>
  12. #include <fsl-mc/fsl_dpni.h>
  13. #include <fsl-mc/fsl_dpbp.h>
  14. #include <fsl-mc/fsl_dpio.h>
  15. #include <fsl-mc/fsl_qbman_portal.h>
  16. #include <fsl-mc/fsl_mc_private.h>
  17. enum ldpaa_eth_type {
  18. LDPAA_ETH_1G_E,
  19. LDPAA_ETH_10G_E,
  20. };
  21. /* Arbitrary values for now, but we'll need to tune */
  22. #define LDPAA_ETH_NUM_BUFS (7 * 7)
  23. #define LDPAA_ETH_REFILL_THRESH (LDPAA_ETH_NUM_BUFS/2)
  24. #define LDPAA_ETH_RX_BUFFER_SIZE 2048
  25. /* Hardware requires alignment for buffer address and length: 256-byte
  26. * for ingress, 64-byte for egress. Using 256 for both.
  27. */
  28. #define LDPAA_ETH_BUF_ALIGN 256
  29. /* So far we're only accomodating a skb backpointer in the frame's
  30. * software annotation, but the hardware options are either 0 or 64.
  31. */
  32. #define LDPAA_ETH_SWA_SIZE 64
  33. /* Annotation valid bits in FD FRC */
  34. #define LDPAA_FD_FRC_FASV 0x8000
  35. #define LDPAA_FD_FRC_FAEADV 0x4000
  36. #define LDPAA_FD_FRC_FAPRV 0x2000
  37. #define LDPAA_FD_FRC_FAIADV 0x1000
  38. #define LDPAA_FD_FRC_FASWOV 0x0800
  39. #define LDPAA_FD_FRC_FAICFDV 0x0400
  40. /* Annotation bits in FD CTRL */
  41. #define LDPAA_FD_CTRL_ASAL 0x00020000 /* ASAL = 128 */
  42. #define LDPAA_FD_CTRL_PTA 0x00800000
  43. #define LDPAA_FD_CTRL_PTV1 0x00400000
  44. /* TODO: we may want to move this and other WRIOP related defines
  45. * to a separate header
  46. */
  47. /* Frame annotation status */
  48. struct ldpaa_fas {
  49. u8 reserved;
  50. u8 ppid;
  51. __le16 ifpid;
  52. __le32 status;
  53. } __packed;
  54. /* Debug frame, otherwise supposed to be discarded */
  55. #define LDPAA_ETH_FAS_DISC 0x80000000
  56. /* MACSEC frame */
  57. #define LDPAA_ETH_FAS_MS 0x40000000
  58. #define LDPAA_ETH_FAS_PTP 0x08000000
  59. /* Ethernet multicast frame */
  60. #define LDPAA_ETH_FAS_MC 0x04000000
  61. /* Ethernet broadcast frame */
  62. #define LDPAA_ETH_FAS_BC 0x02000000
  63. #define LDPAA_ETH_FAS_KSE 0x00040000
  64. #define LDPAA_ETH_FAS_EOFHE 0x00020000
  65. #define LDPAA_ETH_FAS_MNLE 0x00010000
  66. #define LDPAA_ETH_FAS_TIDE 0x00008000
  67. #define LDPAA_ETH_FAS_PIEE 0x00004000
  68. /* Frame length error */
  69. #define LDPAA_ETH_FAS_FLE 0x00002000
  70. /* Frame physical error; our favourite pastime */
  71. #define LDPAA_ETH_FAS_FPE 0x00001000
  72. #define LDPAA_ETH_FAS_PTE 0x00000080
  73. #define LDPAA_ETH_FAS_ISP 0x00000040
  74. #define LDPAA_ETH_FAS_PHE 0x00000020
  75. #define LDPAA_ETH_FAS_BLE 0x00000010
  76. /* L3 csum validation performed */
  77. #define LDPAA_ETH_FAS_L3CV 0x00000008
  78. /* L3 csum error */
  79. #define LDPAA_ETH_FAS_L3CE 0x00000004
  80. /* L4 csum validation performed */
  81. #define LDPAA_ETH_FAS_L4CV 0x00000002
  82. /* L4 csum error */
  83. #define LDPAA_ETH_FAS_L4CE 0x00000001
  84. /* These bits always signal errors */
  85. #define LDPAA_ETH_RX_ERR_MASK (LDPAA_ETH_FAS_DISC | \
  86. LDPAA_ETH_FAS_KSE | \
  87. LDPAA_ETH_FAS_EOFHE | \
  88. LDPAA_ETH_FAS_MNLE | \
  89. LDPAA_ETH_FAS_TIDE | \
  90. LDPAA_ETH_FAS_PIEE | \
  91. LDPAA_ETH_FAS_FLE | \
  92. LDPAA_ETH_FAS_FPE | \
  93. LDPAA_ETH_FAS_PTE | \
  94. LDPAA_ETH_FAS_ISP | \
  95. LDPAA_ETH_FAS_PHE | \
  96. LDPAA_ETH_FAS_BLE | \
  97. LDPAA_ETH_FAS_L3CE | \
  98. LDPAA_ETH_FAS_L4CE)
  99. /* Unsupported features in the ingress */
  100. #define LDPAA_ETH_RX_UNSUPP_MASK LDPAA_ETH_FAS_MS
  101. /* TODO trim down the bitmask; not all of them apply to Tx-confirm */
  102. #define LDPAA_ETH_TXCONF_ERR_MASK (LDPAA_ETH_FAS_KSE | \
  103. LDPAA_ETH_FAS_EOFHE | \
  104. LDPAA_ETH_FAS_MNLE | \
  105. LDPAA_ETH_FAS_TIDE)
  106. static const char ldpaa_eth_dpni_stat_strings[][ETH_GSTRING_LEN] = {
  107. "[dpni ] rx frames",
  108. "[dpni ] rx bytes",
  109. "[dpni ] rx mcast frames",
  110. "[dpni ] rx mcast bytes",
  111. "[dpni ] rx bcast frames",
  112. "[dpni ] rx bcast bytes",
  113. "[dpni ] tx frames",
  114. "[dpni ] tx bytes",
  115. "[dpni ] tx mcast frames",
  116. "[dpni ] tx mcast bytes",
  117. "[dpni ] tx bcast frames",
  118. "[dpni ] tx bcast bytes",
  119. "[dpni ] rx filtered frames",
  120. "[dpni ] rx discarded frames",
  121. "[dpni ] rx nobuffer discards",
  122. "[dpni ] tx discarded frames",
  123. "[dpni ] tx confirmed frames",
  124. "[dpni ] tx dequeued bytes",
  125. "[dpni ] tx dequeued frames",
  126. "[dpni ] tx rejected bytes",
  127. "[dpni ] tx rejected frames",
  128. "[dpni ] tx pending frames",
  129. };
  130. #define LDPAA_ETH_DPNI_NUM_STATS ARRAY_SIZE(ldpaa_eth_dpni_stat_strings)
  131. static const char ldpaa_eth_dpmac_stat_strings[][ETH_GSTRING_LEN] = {
  132. [DPMAC_CNT_ING_ALL_FRAME] = "[mac] rx all frames",
  133. [DPMAC_CNT_ING_GOOD_FRAME] = "[mac] rx frames ok",
  134. [DPMAC_CNT_ING_ERR_FRAME] = "[mac] rx frame errors",
  135. [DPMAC_CNT_ING_FRAME_DISCARD] = "[mac] rx frame discards",
  136. [DPMAC_CNT_ING_UCAST_FRAME] = "[mac] rx u-cast",
  137. [DPMAC_CNT_ING_BCAST_FRAME] = "[mac] rx b-cast",
  138. [DPMAC_CNT_ING_MCAST_FRAME] = "[mac] rx m-cast",
  139. [DPMAC_CNT_ING_FRAME_64] = "[mac] rx 64 bytes",
  140. [DPMAC_CNT_ING_FRAME_127] = "[mac] rx 65-127 bytes",
  141. [DPMAC_CNT_ING_FRAME_255] = "[mac] rx 128-255 bytes",
  142. [DPMAC_CNT_ING_FRAME_511] = "[mac] rx 256-511 bytes",
  143. [DPMAC_CNT_ING_FRAME_1023] = "[mac] rx 512-1023 bytes",
  144. [DPMAC_CNT_ING_FRAME_1518] = "[mac] rx 1024-1518 bytes",
  145. [DPMAC_CNT_ING_FRAME_1519_MAX] = "[mac] rx 1519-max bytes",
  146. [DPMAC_CNT_ING_FRAG] = "[mac] rx frags",
  147. [DPMAC_CNT_ING_JABBER] = "[mac] rx jabber",
  148. [DPMAC_CNT_ING_ALIGN_ERR] = "[mac] rx align errors",
  149. [DPMAC_CNT_ING_OVERSIZED] = "[mac] rx oversized",
  150. [DPMAC_CNT_ING_VALID_PAUSE_FRAME] = "[mac] rx pause",
  151. [DPMAC_CNT_ING_BYTE] = "[mac] rx bytes",
  152. [DPMAC_CNT_EGR_GOOD_FRAME] = "[mac] tx frames ok",
  153. [DPMAC_CNT_EGR_UCAST_FRAME] = "[mac] tx u-cast",
  154. [DPMAC_CNT_EGR_MCAST_FRAME] = "[mac] tx m-cast",
  155. [DPMAC_CNT_EGR_BCAST_FRAME] = "[mac] tx b-cast",
  156. [DPMAC_CNT_EGR_ERR_FRAME] = "[mac] tx frame errors",
  157. [DPMAC_CNT_EGR_UNDERSIZED] = "[mac] tx undersized",
  158. [DPMAC_CNT_EGR_VALID_PAUSE_FRAME] = "[mac] tx b-pause",
  159. [DPMAC_CNT_EGR_BYTE] = "[mac] tx bytes",
  160. };
  161. #define LDPAA_ETH_DPMAC_NUM_STATS ARRAY_SIZE(ldpaa_eth_dpmac_stat_strings)
  162. struct ldpaa_eth_priv {
  163. struct phy_device *phy;
  164. int phy_mode;
  165. bool started;
  166. uint32_t dpmac_id;
  167. uint16_t dpmac_handle;
  168. uint16_t tx_data_offset;
  169. uint32_t rx_dflt_fqid;
  170. uint16_t tx_qdid;
  171. uint16_t tx_flow_id;
  172. enum ldpaa_eth_type type; /* 1G or 10G ethernet */
  173. /* SW kept statistics */
  174. u64 dpni_stats[LDPAA_ETH_DPNI_NUM_STATS];
  175. u64 dpmac_stats[LDPAA_ETH_DPMAC_NUM_STATS];
  176. };
  177. struct dprc_endpoint dpmac_endpoint;
  178. struct dprc_endpoint dpni_endpoint;
  179. extern struct fsl_mc_io *dflt_mc_io;
  180. extern struct fsl_dpbp_obj *dflt_dpbp;
  181. extern struct fsl_dpio_obj *dflt_dpio;
  182. extern struct fsl_dpni_obj *dflt_dpni;
  183. extern uint16_t dflt_dprc_handle;
  184. static void ldpaa_dpbp_drain_cnt(int count);
  185. static void ldpaa_dpbp_drain(void);
  186. static int ldpaa_dpbp_seed(uint16_t bpid);
  187. static void ldpaa_dpbp_free(void);
  188. static int ldpaa_dpni_setup(struct ldpaa_eth_priv *priv);
  189. static int ldpaa_dpbp_setup(void);
  190. static int ldpaa_dpni_bind(struct ldpaa_eth_priv *priv);
  191. static int ldpaa_dpmac_setup(struct ldpaa_eth_priv *priv);
  192. static int ldpaa_dpmac_bind(struct ldpaa_eth_priv *priv);
  193. #endif /* __LDPAA_H */