dpaa2-eth.h 21 KB

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