dpaa2-eth.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  1. /* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
  2. /* Copyright 2014-2016 Freescale Semiconductor Inc.
  3. * Copyright 2016-2022 NXP
  4. */
  5. #ifndef __DPAA2_ETH_H
  6. #define __DPAA2_ETH_H
  7. #include <linux/dcbnl.h>
  8. #include <linux/netdevice.h>
  9. #include <linux/if_vlan.h>
  10. #include <linux/fsl/mc.h>
  11. #include <linux/net_tstamp.h>
  12. #include <net/devlink.h>
  13. #include <net/xdp.h>
  14. #include <soc/fsl/dpaa2-io.h>
  15. #include <soc/fsl/dpaa2-fd.h>
  16. #include "dpni.h"
  17. #include "dpni-cmd.h"
  18. #include "dpaa2-eth-trace.h"
  19. #include "dpaa2-eth-debugfs.h"
  20. #include "dpaa2-mac.h"
  21. #define DPAA2_WRIOP_VERSION(x, y, z) ((x) << 10 | (y) << 5 | (z) << 0)
  22. #define DPAA2_ETH_STORE_SIZE 16
  23. /* Maximum number of scatter-gather entries in an ingress frame,
  24. * considering the maximum receive frame size is 64K
  25. */
  26. #define DPAA2_ETH_MAX_SG_ENTRIES ((64 * 1024) / DPAA2_ETH_RX_BUF_SIZE)
  27. /* Maximum acceptable MTU value. It is in direct relation with the hardware
  28. * enforced Max Frame Length (currently 10k).
  29. */
  30. #define DPAA2_ETH_MFL (10 * 1024)
  31. #define DPAA2_ETH_MAX_MTU (DPAA2_ETH_MFL - VLAN_ETH_HLEN)
  32. /* Convert L3 MTU to L2 MFL */
  33. #define DPAA2_ETH_L2_MAX_FRM(mtu) ((mtu) + VLAN_ETH_HLEN)
  34. /* Set the taildrop threshold (in bytes) to allow the enqueue of a large
  35. * enough number of jumbo frames in the Rx queues (length of the current
  36. * frame is not taken into account when making the taildrop decision)
  37. */
  38. #define DPAA2_ETH_FQ_TAILDROP_THRESH (1024 * 1024)
  39. /* Maximum burst size value for Tx shaping */
  40. #define DPAA2_ETH_MAX_BURST_SIZE 0xF7FF
  41. /* Maximum number of Tx confirmation frames to be processed
  42. * in a single NAPI call
  43. */
  44. #define DPAA2_ETH_TXCONF_PER_NAPI 256
  45. /* Maximum number of Tx frames to be processed in a single NAPI
  46. * call when AF_XDP is running. Bind it to DPAA2_ETH_TXCONF_PER_NAPI
  47. * to maximize the throughput.
  48. */
  49. #define DPAA2_ETH_TX_ZC_PER_NAPI DPAA2_ETH_TXCONF_PER_NAPI
  50. /* Buffer qouta per channel. We want to keep in check number of ingress frames
  51. * in flight: for small sized frames, congestion group taildrop may kick in
  52. * first; for large sizes, Rx FQ taildrop threshold will ensure only a
  53. * reasonable number of frames will be pending at any given time.
  54. * Ingress frame drop due to buffer pool depletion should be a corner case only
  55. */
  56. #define DPAA2_ETH_NUM_BUFS 1280
  57. #define DPAA2_ETH_REFILL_THRESH \
  58. (DPAA2_ETH_NUM_BUFS - DPAA2_ETH_BUFS_PER_CMD)
  59. /* Congestion group taildrop threshold: number of frames allowed to accumulate
  60. * at any moment in a group of Rx queues belonging to the same traffic class.
  61. * Choose value such that we don't risk depleting the buffer pool before the
  62. * taildrop kicks in
  63. */
  64. #define DPAA2_ETH_CG_TAILDROP_THRESH(priv) \
  65. (1024 * dpaa2_eth_queue_count(priv) / dpaa2_eth_tc_count(priv))
  66. /* Congestion group notification threshold: when this many frames accumulate
  67. * on the Rx queues belonging to the same TC, the MAC is instructed to send
  68. * PFC frames for that TC.
  69. * When number of pending frames drops below exit threshold transmission of
  70. * PFC frames is stopped.
  71. */
  72. #define DPAA2_ETH_CN_THRESH_ENTRY(priv) \
  73. (DPAA2_ETH_CG_TAILDROP_THRESH(priv) / 2)
  74. #define DPAA2_ETH_CN_THRESH_EXIT(priv) \
  75. (DPAA2_ETH_CN_THRESH_ENTRY(priv) * 3 / 4)
  76. /* Maximum number of buffers that can be acquired/released through a single
  77. * QBMan command
  78. */
  79. #define DPAA2_ETH_BUFS_PER_CMD 7
  80. /* Hardware requires alignment for ingress/egress buffer addresses */
  81. #define DPAA2_ETH_TX_BUF_ALIGN 64
  82. #define DPAA2_ETH_RX_BUF_RAW_SIZE PAGE_SIZE
  83. #define DPAA2_ETH_RX_BUF_TAILROOM \
  84. SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
  85. #define DPAA2_ETH_RX_BUF_SIZE \
  86. (DPAA2_ETH_RX_BUF_RAW_SIZE - DPAA2_ETH_RX_BUF_TAILROOM)
  87. /* Hardware annotation area in RX/TX buffers */
  88. #define DPAA2_ETH_RX_HWA_SIZE 64
  89. #define DPAA2_ETH_TX_HWA_SIZE 128
  90. /* PTP nominal frequency 1GHz */
  91. #define DPAA2_PTP_CLK_PERIOD_NS 1
  92. /* Due to a limitation in WRIOP 1.0.0, the RX buffer data must be aligned
  93. * to 256B. For newer revisions, the requirement is only for 64B alignment
  94. */
  95. #define DPAA2_ETH_RX_BUF_ALIGN_REV1 256
  96. #define DPAA2_ETH_RX_BUF_ALIGN 64
  97. /* The firmware allows assigning multiple buffer pools to a single DPNI -
  98. * maximum 8 DPBP objects. By default, only the first DPBP (idx 0) is used for
  99. * all queues. Thus, when enabling AF_XDP we must accommodate up to 9 DPBPs
  100. * object: the default and 8 other distinct buffer pools, one for each queue.
  101. */
  102. #define DPAA2_ETH_DEFAULT_BP_IDX 0
  103. #define DPAA2_ETH_MAX_BPS 9
  104. /* We are accommodating a skb backpointer and some S/G info
  105. * in the frame's software annotation. The hardware
  106. * options are either 0 or 64, so we choose the latter.
  107. */
  108. #define DPAA2_ETH_SWA_SIZE 64
  109. /* We store different information in the software annotation area of a Tx frame
  110. * based on what type of frame it is
  111. */
  112. enum dpaa2_eth_swa_type {
  113. DPAA2_ETH_SWA_SINGLE,
  114. DPAA2_ETH_SWA_SG,
  115. DPAA2_ETH_SWA_XDP,
  116. DPAA2_ETH_SWA_XSK,
  117. DPAA2_ETH_SWA_SW_TSO,
  118. };
  119. /* Must keep this struct smaller than DPAA2_ETH_SWA_SIZE */
  120. struct dpaa2_eth_swa {
  121. enum dpaa2_eth_swa_type type;
  122. union {
  123. struct {
  124. struct sk_buff *skb;
  125. int sgt_size;
  126. } single;
  127. struct {
  128. struct sk_buff *skb;
  129. struct scatterlist *scl;
  130. int num_sg;
  131. int sgt_size;
  132. } sg;
  133. struct {
  134. int dma_size;
  135. struct xdp_frame *xdpf;
  136. } xdp;
  137. struct {
  138. struct xdp_buff *xdp_buff;
  139. int sgt_size;
  140. } xsk;
  141. struct {
  142. struct sk_buff *skb;
  143. int num_sg;
  144. int sgt_size;
  145. int is_last_fd;
  146. } tso;
  147. };
  148. };
  149. /* Annotation valid bits in FD FRC */
  150. #define DPAA2_FD_FRC_FASV 0x8000
  151. #define DPAA2_FD_FRC_FAEADV 0x4000
  152. #define DPAA2_FD_FRC_FAPRV 0x2000
  153. #define DPAA2_FD_FRC_FAIADV 0x1000
  154. #define DPAA2_FD_FRC_FASWOV 0x0800
  155. #define DPAA2_FD_FRC_FAICFDV 0x0400
  156. /* Error bits in FD CTRL */
  157. #define DPAA2_FD_RX_ERR_MASK (FD_CTRL_SBE | FD_CTRL_FAERR)
  158. #define DPAA2_FD_TX_ERR_MASK (FD_CTRL_UFD | \
  159. FD_CTRL_SBE | \
  160. FD_CTRL_FSE | \
  161. FD_CTRL_FAERR)
  162. /* Annotation bits in FD CTRL */
  163. #define DPAA2_FD_CTRL_ASAL 0x00020000 /* ASAL = 128B */
  164. /* Frame annotation status */
  165. struct dpaa2_fas {
  166. u8 reserved;
  167. u8 ppid;
  168. __le16 ifpid;
  169. __le32 status;
  170. };
  171. /* Frame annotation status word is located in the first 8 bytes
  172. * of the buffer's hardware annoatation area
  173. */
  174. #define DPAA2_FAS_OFFSET 0
  175. #define DPAA2_FAS_SIZE (sizeof(struct dpaa2_fas))
  176. /* Timestamp is located in the next 8 bytes of the buffer's
  177. * hardware annotation area
  178. */
  179. #define DPAA2_TS_OFFSET 0x8
  180. /* Frame annotation parse results */
  181. struct dpaa2_fapr {
  182. /* 64-bit word 1 */
  183. __le32 faf_lo;
  184. __le16 faf_ext;
  185. __le16 nxt_hdr;
  186. /* 64-bit word 2 */
  187. __le64 faf_hi;
  188. /* 64-bit word 3 */
  189. u8 last_ethertype_offset;
  190. u8 vlan_tci_offset_n;
  191. u8 vlan_tci_offset_1;
  192. u8 llc_snap_offset;
  193. u8 eth_offset;
  194. u8 ip1_pid_offset;
  195. u8 shim_offset_2;
  196. u8 shim_offset_1;
  197. /* 64-bit word 4 */
  198. u8 l5_offset;
  199. u8 l4_offset;
  200. u8 gre_offset;
  201. u8 l3_offset_n;
  202. u8 l3_offset_1;
  203. u8 mpls_offset_n;
  204. u8 mpls_offset_1;
  205. u8 pppoe_offset;
  206. /* 64-bit word 5 */
  207. __le16 running_sum;
  208. __le16 gross_running_sum;
  209. u8 ipv6_frag_offset;
  210. u8 nxt_hdr_offset;
  211. u8 routing_hdr_offset_2;
  212. u8 routing_hdr_offset_1;
  213. /* 64-bit word 6 */
  214. u8 reserved[5]; /* Soft-parsing context */
  215. u8 ip_proto_offset_n;
  216. u8 nxt_hdr_frag_offset;
  217. u8 parse_error_code;
  218. };
  219. #define DPAA2_FAPR_OFFSET 0x10
  220. #define DPAA2_FAPR_SIZE sizeof((struct dpaa2_fapr))
  221. /* Frame annotation egress action descriptor */
  222. #define DPAA2_FAEAD_OFFSET 0x58
  223. struct dpaa2_faead {
  224. __le32 conf_fqid;
  225. __le32 ctrl;
  226. };
  227. #define DPAA2_FAEAD_A2V 0x20000000
  228. #define DPAA2_FAEAD_A4V 0x08000000
  229. #define DPAA2_FAEAD_UPDV 0x00001000
  230. #define DPAA2_FAEAD_EBDDV 0x00002000
  231. #define DPAA2_FAEAD_UPD 0x00000010
  232. struct ptp_tstamp {
  233. u16 sec_msb;
  234. u32 sec_lsb;
  235. u32 nsec;
  236. };
  237. static inline void ns_to_ptp_tstamp(struct ptp_tstamp *tstamp, u64 ns)
  238. {
  239. u64 sec, nsec;
  240. sec = ns;
  241. nsec = do_div(sec, 1000000000);
  242. tstamp->sec_lsb = sec & 0xFFFFFFFF;
  243. tstamp->sec_msb = (sec >> 32) & 0xFFFF;
  244. tstamp->nsec = nsec;
  245. }
  246. /* Accessors for the hardware annotation fields that we use */
  247. static inline void *dpaa2_get_hwa(void *buf_addr, bool swa)
  248. {
  249. return buf_addr + (swa ? DPAA2_ETH_SWA_SIZE : 0);
  250. }
  251. static inline struct dpaa2_fas *dpaa2_get_fas(void *buf_addr, bool swa)
  252. {
  253. return dpaa2_get_hwa(buf_addr, swa) + DPAA2_FAS_OFFSET;
  254. }
  255. static inline __le64 *dpaa2_get_ts(void *buf_addr, bool swa)
  256. {
  257. return dpaa2_get_hwa(buf_addr, swa) + DPAA2_TS_OFFSET;
  258. }
  259. static inline struct dpaa2_fapr *dpaa2_get_fapr(void *buf_addr, bool swa)
  260. {
  261. return dpaa2_get_hwa(buf_addr, swa) + DPAA2_FAPR_OFFSET;
  262. }
  263. static inline struct dpaa2_faead *dpaa2_get_faead(void *buf_addr, bool swa)
  264. {
  265. return dpaa2_get_hwa(buf_addr, swa) + DPAA2_FAEAD_OFFSET;
  266. }
  267. /* Error and status bits in the frame annotation status word */
  268. /* Debug frame, otherwise supposed to be discarded */
  269. #define DPAA2_FAS_DISC 0x80000000
  270. /* MACSEC frame */
  271. #define DPAA2_FAS_MS 0x40000000
  272. #define DPAA2_FAS_PTP 0x08000000
  273. /* Ethernet multicast frame */
  274. #define DPAA2_FAS_MC 0x04000000
  275. /* Ethernet broadcast frame */
  276. #define DPAA2_FAS_BC 0x02000000
  277. #define DPAA2_FAS_KSE 0x00040000
  278. #define DPAA2_FAS_EOFHE 0x00020000
  279. #define DPAA2_FAS_MNLE 0x00010000
  280. #define DPAA2_FAS_TIDE 0x00008000
  281. #define DPAA2_FAS_PIEE 0x00004000
  282. /* Frame length error */
  283. #define DPAA2_FAS_FLE 0x00002000
  284. /* Frame physical error */
  285. #define DPAA2_FAS_FPE 0x00001000
  286. #define DPAA2_FAS_PTE 0x00000080
  287. #define DPAA2_FAS_ISP 0x00000040
  288. #define DPAA2_FAS_PHE 0x00000020
  289. #define DPAA2_FAS_BLE 0x00000010
  290. /* L3 csum validation performed */
  291. #define DPAA2_FAS_L3CV 0x00000008
  292. /* L3 csum error */
  293. #define DPAA2_FAS_L3CE 0x00000004
  294. /* L4 csum validation performed */
  295. #define DPAA2_FAS_L4CV 0x00000002
  296. /* L4 csum error */
  297. #define DPAA2_FAS_L4CE 0x00000001
  298. /* Possible errors on the ingress path */
  299. #define DPAA2_FAS_RX_ERR_MASK (DPAA2_FAS_KSE | \
  300. DPAA2_FAS_EOFHE | \
  301. DPAA2_FAS_MNLE | \
  302. DPAA2_FAS_TIDE | \
  303. DPAA2_FAS_PIEE | \
  304. DPAA2_FAS_FLE | \
  305. DPAA2_FAS_FPE | \
  306. DPAA2_FAS_PTE | \
  307. DPAA2_FAS_ISP | \
  308. DPAA2_FAS_PHE | \
  309. DPAA2_FAS_BLE | \
  310. DPAA2_FAS_L3CE | \
  311. DPAA2_FAS_L4CE)
  312. /* Time in milliseconds between link state updates */
  313. #define DPAA2_ETH_LINK_STATE_REFRESH 1000
  314. /* Number of times to retry a frame enqueue before giving up.
  315. * Value determined empirically, in order to minimize the number
  316. * of frames dropped on Tx
  317. */
  318. #define DPAA2_ETH_ENQUEUE_RETRIES 10
  319. /* Number of times to retry DPIO portal operations while waiting
  320. * for portal to finish executing current command and become
  321. * available. We want to avoid being stuck in a while loop in case
  322. * hardware becomes unresponsive, but not give up too easily if
  323. * the portal really is busy for valid reasons
  324. */
  325. #define DPAA2_ETH_SWP_BUSY_RETRIES 1000
  326. /* Driver statistics, other than those in struct rtnl_link_stats64.
  327. * These are usually collected per-CPU and aggregated by ethtool.
  328. */
  329. struct dpaa2_eth_drv_stats {
  330. __u64 tx_conf_frames;
  331. __u64 tx_conf_bytes;
  332. __u64 tx_sg_frames;
  333. __u64 tx_sg_bytes;
  334. __u64 tx_tso_frames;
  335. __u64 tx_tso_bytes;
  336. __u64 rx_sg_frames;
  337. __u64 rx_sg_bytes;
  338. /* Linear skbs sent as a S/G FD due to insufficient headroom */
  339. __u64 tx_converted_sg_frames;
  340. __u64 tx_converted_sg_bytes;
  341. /* Enqueues retried due to portal busy */
  342. __u64 tx_portal_busy;
  343. };
  344. /* Per-FQ statistics */
  345. struct dpaa2_eth_fq_stats {
  346. /* Number of frames received on this queue */
  347. __u64 frames;
  348. };
  349. /* Per-channel statistics */
  350. struct dpaa2_eth_ch_stats {
  351. /* Volatile dequeues retried due to portal busy */
  352. __u64 dequeue_portal_busy;
  353. /* Pull errors */
  354. __u64 pull_err;
  355. /* Number of CDANs; useful to estimate avg NAPI len */
  356. __u64 cdan;
  357. /* XDP counters */
  358. __u64 xdp_drop;
  359. __u64 xdp_tx;
  360. __u64 xdp_tx_err;
  361. __u64 xdp_redirect;
  362. /* Must be last, does not show up in ethtool stats */
  363. __u64 frames;
  364. __u64 frames_per_cdan;
  365. __u64 bytes_per_cdan;
  366. };
  367. #define DPAA2_ETH_CH_STATS 7
  368. /* Maximum number of queues associated with a DPNI */
  369. #define DPAA2_ETH_MAX_TCS 8
  370. #define DPAA2_ETH_MAX_RX_QUEUES_PER_TC 16
  371. #define DPAA2_ETH_MAX_RX_QUEUES \
  372. (DPAA2_ETH_MAX_RX_QUEUES_PER_TC * DPAA2_ETH_MAX_TCS)
  373. #define DPAA2_ETH_MAX_TX_QUEUES 16
  374. #define DPAA2_ETH_MAX_RX_ERR_QUEUES 1
  375. #define DPAA2_ETH_MAX_QUEUES (DPAA2_ETH_MAX_RX_QUEUES + \
  376. DPAA2_ETH_MAX_TX_QUEUES + \
  377. DPAA2_ETH_MAX_RX_ERR_QUEUES)
  378. #define DPAA2_ETH_MAX_NETDEV_QUEUES \
  379. (DPAA2_ETH_MAX_TX_QUEUES * DPAA2_ETH_MAX_TCS)
  380. #define DPAA2_ETH_MAX_DPCONS 16
  381. enum dpaa2_eth_fq_type {
  382. DPAA2_RX_FQ = 0,
  383. DPAA2_TX_CONF_FQ,
  384. DPAA2_RX_ERR_FQ
  385. };
  386. struct dpaa2_eth_priv;
  387. struct dpaa2_eth_channel;
  388. struct dpaa2_eth_fq;
  389. struct dpaa2_eth_xdp_fds {
  390. struct dpaa2_fd fds[DEV_MAP_BULK_SIZE];
  391. ssize_t num;
  392. };
  393. typedef void dpaa2_eth_consume_cb_t(struct dpaa2_eth_priv *priv,
  394. struct dpaa2_eth_channel *ch,
  395. const struct dpaa2_fd *fd,
  396. struct dpaa2_eth_fq *fq);
  397. struct dpaa2_eth_fq {
  398. u32 fqid;
  399. u32 tx_qdbin;
  400. u32 tx_fqid[DPAA2_ETH_MAX_TCS];
  401. u16 flowid;
  402. u8 tc;
  403. int target_cpu;
  404. u32 dq_frames;
  405. u32 dq_bytes;
  406. struct dpaa2_eth_channel *channel;
  407. enum dpaa2_eth_fq_type type;
  408. dpaa2_eth_consume_cb_t *consume;
  409. struct dpaa2_eth_fq_stats stats;
  410. struct dpaa2_eth_xdp_fds xdp_redirect_fds;
  411. struct dpaa2_eth_xdp_fds xdp_tx_fds;
  412. };
  413. struct dpaa2_eth_ch_xdp {
  414. struct bpf_prog *prog;
  415. unsigned int res;
  416. };
  417. struct dpaa2_eth_bp {
  418. struct fsl_mc_device *dev;
  419. int bpid;
  420. };
  421. struct dpaa2_eth_channel {
  422. struct dpaa2_io_notification_ctx nctx;
  423. struct fsl_mc_device *dpcon;
  424. int dpcon_id;
  425. int ch_id;
  426. struct napi_struct napi;
  427. struct dpaa2_io *dpio;
  428. struct dpaa2_io_store *store;
  429. struct dpaa2_eth_priv *priv;
  430. int buf_count;
  431. struct dpaa2_eth_ch_stats stats;
  432. struct dpaa2_eth_ch_xdp xdp;
  433. struct xdp_rxq_info xdp_rxq;
  434. struct list_head *rx_list;
  435. /* Buffers to be recycled back in the buffer pool */
  436. u64 recycled_bufs[DPAA2_ETH_BUFS_PER_CMD];
  437. int recycled_bufs_cnt;
  438. bool xsk_zc;
  439. int xsk_tx_pkts_sent;
  440. struct xsk_buff_pool *xsk_pool;
  441. struct dpaa2_eth_bp *bp;
  442. };
  443. struct dpaa2_eth_dist_fields {
  444. u64 rxnfc_field;
  445. enum net_prot cls_prot;
  446. int cls_field;
  447. int size;
  448. u64 id;
  449. };
  450. struct dpaa2_eth_cls_rule {
  451. struct ethtool_rx_flow_spec fs;
  452. u8 in_use;
  453. };
  454. #define DPAA2_ETH_SGT_CACHE_SIZE 256
  455. struct dpaa2_eth_sgt_cache {
  456. void *buf[DPAA2_ETH_SGT_CACHE_SIZE];
  457. u16 count;
  458. };
  459. struct dpaa2_eth_trap_item {
  460. void *trap_ctx;
  461. };
  462. struct dpaa2_eth_trap_data {
  463. struct dpaa2_eth_trap_item *trap_items_arr;
  464. struct dpaa2_eth_priv *priv;
  465. };
  466. #define DPAA2_ETH_SG_ENTRIES_MAX (PAGE_SIZE / sizeof(struct scatterlist))
  467. #define DPAA2_ETH_DEFAULT_COPYBREAK 512
  468. #define DPAA2_ETH_ENQUEUE_MAX_FDS 256
  469. struct dpaa2_eth_fds {
  470. struct dpaa2_fd array[DPAA2_ETH_ENQUEUE_MAX_FDS];
  471. };
  472. /* Driver private data */
  473. struct dpaa2_eth_priv {
  474. struct net_device *net_dev;
  475. u8 num_fqs;
  476. struct dpaa2_eth_fq fq[DPAA2_ETH_MAX_QUEUES];
  477. int (*enqueue)(struct dpaa2_eth_priv *priv,
  478. struct dpaa2_eth_fq *fq,
  479. struct dpaa2_fd *fd, u8 prio,
  480. u32 num_frames,
  481. int *frames_enqueued);
  482. u8 num_channels;
  483. struct dpaa2_eth_channel *channel[DPAA2_ETH_MAX_DPCONS];
  484. struct dpaa2_eth_sgt_cache __percpu *sgt_cache;
  485. unsigned long features;
  486. struct dpni_attr dpni_attrs;
  487. u16 dpni_ver_major;
  488. u16 dpni_ver_minor;
  489. u16 tx_data_offset;
  490. void __iomem *onestep_reg_base;
  491. u8 ptp_correction_off;
  492. void (*dpaa2_set_onestep_params_cb)(struct dpaa2_eth_priv *priv,
  493. u32 offset, u8 udp);
  494. u16 rx_buf_size;
  495. struct iommu_domain *iommu_domain;
  496. enum hwtstamp_tx_types tx_tstamp_type; /* Tx timestamping type */
  497. bool rx_tstamp; /* Rx timestamping enabled */
  498. /* Buffer pool management */
  499. struct dpaa2_eth_bp *bp[DPAA2_ETH_MAX_BPS];
  500. int num_bps;
  501. u16 tx_qdid;
  502. struct fsl_mc_io *mc_io;
  503. /* Cores which have an affine DPIO/DPCON.
  504. * This is the cpu set on which Rx and Tx conf frames are processed
  505. */
  506. struct cpumask dpio_cpumask;
  507. /* Standard statistics */
  508. struct rtnl_link_stats64 __percpu *percpu_stats;
  509. /* Extra stats, in addition to the ones known by the kernel */
  510. struct dpaa2_eth_drv_stats __percpu *percpu_extras;
  511. u16 mc_token;
  512. u8 rx_fqtd_enabled;
  513. u8 rx_cgtd_enabled;
  514. struct dpni_link_state link_state;
  515. bool do_link_poll;
  516. struct task_struct *poll_thread;
  517. /* enabled ethtool hashing bits */
  518. u64 rx_hash_fields;
  519. u64 rx_cls_fields;
  520. struct dpaa2_eth_cls_rule *cls_rules;
  521. u8 rx_cls_enabled;
  522. u8 vlan_cls_enabled;
  523. u8 pfc_enabled;
  524. #ifdef CONFIG_FSL_DPAA2_ETH_DCB
  525. u8 dcbx_mode;
  526. struct ieee_pfc pfc;
  527. #endif
  528. struct bpf_prog *xdp_prog;
  529. #ifdef CONFIG_DEBUG_FS
  530. struct dpaa2_debugfs dbg;
  531. #endif
  532. struct dpaa2_mac *mac;
  533. /* Serializes changes to priv->mac */
  534. struct mutex mac_lock;
  535. struct workqueue_struct *dpaa2_ptp_wq;
  536. struct work_struct tx_onestep_tstamp;
  537. struct sk_buff_head tx_skbs;
  538. /* The one-step timestamping configuration on hardware
  539. * registers could only be done when no one-step
  540. * timestamping frames are in flight. So we use a mutex
  541. * lock here to make sure the lock is released by last
  542. * one-step timestamping packet through TX confirmation
  543. * queue before transmit current packet.
  544. */
  545. struct mutex onestep_tstamp_lock;
  546. struct devlink *devlink;
  547. struct dpaa2_eth_trap_data *trap_data;
  548. struct devlink_port devlink_port;
  549. u32 rx_copybreak;
  550. struct dpaa2_eth_fds __percpu *fd;
  551. };
  552. struct dpaa2_eth_devlink_priv {
  553. struct dpaa2_eth_priv *dpaa2_priv;
  554. };
  555. #define TX_TSTAMP 0x1
  556. #define TX_TSTAMP_ONESTEP_SYNC 0x2
  557. #define DPAA2_RXH_SUPPORTED (RXH_L2DA | RXH_VLAN | RXH_L3_PROTO \
  558. | RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 \
  559. | RXH_L4_B_2_3)
  560. /* default Rx hash options, set during probing */
  561. #define DPAA2_RXH_DEFAULT (RXH_L3_PROTO | RXH_IP_SRC | RXH_IP_DST | \
  562. RXH_L4_B_0_1 | RXH_L4_B_2_3)
  563. #define dpaa2_eth_hash_enabled(priv) \
  564. ((priv)->dpni_attrs.num_queues > 1)
  565. /* Required by struct dpni_rx_tc_dist_cfg::key_cfg_iova */
  566. #define DPAA2_CLASSIFIER_DMA_SIZE 256
  567. extern const struct ethtool_ops dpaa2_ethtool_ops;
  568. extern int dpaa2_phc_index;
  569. extern struct ptp_qoriq *dpaa2_ptp;
  570. static inline int dpaa2_eth_cmp_dpni_ver(struct dpaa2_eth_priv *priv,
  571. u16 ver_major, u16 ver_minor)
  572. {
  573. if (priv->dpni_ver_major == ver_major)
  574. return priv->dpni_ver_minor - ver_minor;
  575. return priv->dpni_ver_major - ver_major;
  576. }
  577. /* Minimum firmware version that supports a more flexible API
  578. * for configuring the Rx flow hash key
  579. */
  580. #define DPNI_RX_DIST_KEY_VER_MAJOR 7
  581. #define DPNI_RX_DIST_KEY_VER_MINOR 5
  582. #define dpaa2_eth_has_legacy_dist(priv) \
  583. (dpaa2_eth_cmp_dpni_ver((priv), DPNI_RX_DIST_KEY_VER_MAJOR, \
  584. DPNI_RX_DIST_KEY_VER_MINOR) < 0)
  585. #define dpaa2_eth_fs_enabled(priv) \
  586. (!((priv)->dpni_attrs.options & DPNI_OPT_NO_FS))
  587. #define dpaa2_eth_fs_mask_enabled(priv) \
  588. ((priv)->dpni_attrs.options & DPNI_OPT_HAS_KEY_MASKING)
  589. #define dpaa2_eth_fs_count(priv) \
  590. ((priv)->dpni_attrs.fs_entries)
  591. #define dpaa2_eth_tc_count(priv) \
  592. ((priv)->dpni_attrs.num_tcs)
  593. /* We have exactly one {Rx, Tx conf} queue per channel */
  594. #define dpaa2_eth_queue_count(priv) \
  595. ((priv)->num_channels)
  596. enum dpaa2_eth_rx_dist {
  597. DPAA2_ETH_RX_DIST_HASH,
  598. DPAA2_ETH_RX_DIST_CLS
  599. };
  600. /* Unique IDs for the supported Rx classification header fields */
  601. #define DPAA2_ETH_DIST_ETHDST BIT(0)
  602. #define DPAA2_ETH_DIST_ETHSRC BIT(1)
  603. #define DPAA2_ETH_DIST_ETHTYPE BIT(2)
  604. #define DPAA2_ETH_DIST_VLAN BIT(3)
  605. #define DPAA2_ETH_DIST_IPSRC BIT(4)
  606. #define DPAA2_ETH_DIST_IPDST BIT(5)
  607. #define DPAA2_ETH_DIST_IPPROTO BIT(6)
  608. #define DPAA2_ETH_DIST_L4SRC BIT(7)
  609. #define DPAA2_ETH_DIST_L4DST BIT(8)
  610. #define DPAA2_ETH_DIST_ALL (~0ULL)
  611. #define DPNI_PTP_ONESTEP_VER_MAJOR 8
  612. #define DPNI_PTP_ONESTEP_VER_MINOR 2
  613. #define DPAA2_ETH_FEATURE_ONESTEP_CFG_DIRECT BIT(0)
  614. #define DPAA2_PTP_SINGLE_STEP_ENABLE BIT(31)
  615. #define DPAA2_PTP_SINGLE_STEP_CH BIT(7)
  616. #define DPAA2_PTP_SINGLE_CORRECTION_OFF(v) ((v) << 8)
  617. #define DPNI_PAUSE_VER_MAJOR 7
  618. #define DPNI_PAUSE_VER_MINOR 13
  619. #define dpaa2_eth_has_pause_support(priv) \
  620. (dpaa2_eth_cmp_dpni_ver((priv), DPNI_PAUSE_VER_MAJOR, \
  621. DPNI_PAUSE_VER_MINOR) >= 0)
  622. static inline bool dpaa2_eth_tx_pause_enabled(u64 link_options)
  623. {
  624. return !!(link_options & DPNI_LINK_OPT_PAUSE) ^
  625. !!(link_options & DPNI_LINK_OPT_ASYM_PAUSE);
  626. }
  627. static inline bool dpaa2_eth_rx_pause_enabled(u64 link_options)
  628. {
  629. return !!(link_options & DPNI_LINK_OPT_PAUSE);
  630. }
  631. static inline unsigned int dpaa2_eth_needed_headroom(struct sk_buff *skb)
  632. {
  633. unsigned int headroom = DPAA2_ETH_SWA_SIZE + DPAA2_ETH_TX_BUF_ALIGN;
  634. /* If we don't have an skb (e.g. XDP buffer), we only need space for
  635. * the software annotation area
  636. */
  637. if (!skb)
  638. return headroom;
  639. /* For non-linear skbs we have no headroom requirement, as we build a
  640. * SG frame with a newly allocated SGT buffer
  641. */
  642. if (skb_is_nonlinear(skb))
  643. return 0;
  644. /* If we have Tx timestamping, need 128B hardware annotation */
  645. if (skb->cb[0])
  646. headroom += DPAA2_ETH_TX_HWA_SIZE;
  647. return headroom;
  648. }
  649. /* Extra headroom space requested to hardware, in order to make sure there's
  650. * no realloc'ing in forwarding scenarios
  651. */
  652. static inline unsigned int dpaa2_eth_rx_head_room(struct dpaa2_eth_priv *priv)
  653. {
  654. return priv->tx_data_offset - DPAA2_ETH_RX_HWA_SIZE;
  655. }
  656. static inline bool dpaa2_eth_is_type_phy(struct dpaa2_eth_priv *priv)
  657. {
  658. lockdep_assert_held(&priv->mac_lock);
  659. return dpaa2_mac_is_type_phy(priv->mac);
  660. }
  661. static inline bool dpaa2_eth_has_mac(struct dpaa2_eth_priv *priv)
  662. {
  663. lockdep_assert_held(&priv->mac_lock);
  664. return priv->mac ? true : false;
  665. }
  666. int dpaa2_eth_set_hash(struct net_device *net_dev, u64 flags);
  667. int dpaa2_eth_set_cls(struct net_device *net_dev, u64 key);
  668. int dpaa2_eth_cls_key_size(u64 key);
  669. int dpaa2_eth_cls_fld_off(int prot, int field);
  670. void dpaa2_eth_cls_trim_rule(void *key_mem, u64 fields);
  671. void dpaa2_eth_set_rx_taildrop(struct dpaa2_eth_priv *priv,
  672. bool tx_pause, bool pfc);
  673. extern const struct dcbnl_rtnl_ops dpaa2_eth_dcbnl_ops;
  674. int dpaa2_eth_dl_alloc(struct dpaa2_eth_priv *priv);
  675. void dpaa2_eth_dl_free(struct dpaa2_eth_priv *priv);
  676. void dpaa2_eth_dl_register(struct dpaa2_eth_priv *priv);
  677. void dpaa2_eth_dl_unregister(struct dpaa2_eth_priv *priv);
  678. int dpaa2_eth_dl_port_add(struct dpaa2_eth_priv *priv);
  679. void dpaa2_eth_dl_port_del(struct dpaa2_eth_priv *priv);
  680. int dpaa2_eth_dl_traps_register(struct dpaa2_eth_priv *priv);
  681. void dpaa2_eth_dl_traps_unregister(struct dpaa2_eth_priv *priv);
  682. struct dpaa2_eth_trap_item *dpaa2_eth_dl_get_trap(struct dpaa2_eth_priv *priv,
  683. struct dpaa2_fapr *fapr);
  684. struct dpaa2_eth_bp *dpaa2_eth_allocate_dpbp(struct dpaa2_eth_priv *priv);
  685. void dpaa2_eth_free_dpbp(struct dpaa2_eth_priv *priv, struct dpaa2_eth_bp *bp);
  686. struct sk_buff *dpaa2_eth_alloc_skb(struct dpaa2_eth_priv *priv,
  687. struct dpaa2_eth_channel *ch,
  688. const struct dpaa2_fd *fd, u32 fd_length,
  689. void *fd_vaddr);
  690. void dpaa2_eth_receive_skb(struct dpaa2_eth_priv *priv,
  691. struct dpaa2_eth_channel *ch,
  692. const struct dpaa2_fd *fd, void *vaddr,
  693. struct dpaa2_eth_fq *fq,
  694. struct rtnl_link_stats64 *percpu_stats,
  695. struct sk_buff *skb);
  696. void dpaa2_eth_rx(struct dpaa2_eth_priv *priv,
  697. struct dpaa2_eth_channel *ch,
  698. const struct dpaa2_fd *fd,
  699. struct dpaa2_eth_fq *fq);
  700. struct dpaa2_eth_bp *dpaa2_eth_allocate_dpbp(struct dpaa2_eth_priv *priv);
  701. void dpaa2_eth_free_dpbp(struct dpaa2_eth_priv *priv,
  702. struct dpaa2_eth_bp *bp);
  703. void *dpaa2_iova_to_virt(struct iommu_domain *domain, dma_addr_t iova_addr);
  704. void dpaa2_eth_recycle_buf(struct dpaa2_eth_priv *priv,
  705. struct dpaa2_eth_channel *ch,
  706. dma_addr_t addr);
  707. void dpaa2_eth_xdp_enqueue(struct dpaa2_eth_priv *priv,
  708. struct dpaa2_eth_channel *ch,
  709. struct dpaa2_fd *fd,
  710. void *buf_start, u16 queue_id);
  711. int dpaa2_xsk_wakeup(struct net_device *dev, u32 qid, u32 flags);
  712. int dpaa2_xsk_setup_pool(struct net_device *dev, struct xsk_buff_pool *pool, u16 qid);
  713. void dpaa2_eth_free_tx_fd(struct dpaa2_eth_priv *priv,
  714. struct dpaa2_eth_channel *ch,
  715. struct dpaa2_eth_fq *fq,
  716. const struct dpaa2_fd *fd, bool in_napi);
  717. bool dpaa2_xsk_tx(struct dpaa2_eth_priv *priv,
  718. struct dpaa2_eth_channel *ch);
  719. /* SGT (Scatter-Gather Table) cache management */
  720. void *dpaa2_eth_sgt_get(struct dpaa2_eth_priv *priv);
  721. void dpaa2_eth_sgt_recycle(struct dpaa2_eth_priv *priv, void *sgt_buf);
  722. #endif /* __DPAA2_H */