fman.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-or-later */
  2. /*
  3. * Copyright 2008 - 2015 Freescale Semiconductor Inc.
  4. * Copyright 2020 NXP
  5. */
  6. #ifndef __FM_H
  7. #define __FM_H
  8. #include <linux/io.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/of_irq.h>
  11. /* FM Frame descriptor macros */
  12. /* Frame queue Context Override */
  13. #define FM_FD_CMD_FCO 0x80000000
  14. #define FM_FD_CMD_RPD 0x40000000 /* Read Prepended Data */
  15. #define FM_FD_CMD_UPD 0x20000000 /* Update Prepended Data */
  16. #define FM_FD_CMD_DTC 0x10000000 /* Do L4 Checksum */
  17. /* TX-Port: Unsupported Format */
  18. #define FM_FD_ERR_UNSUPPORTED_FORMAT 0x04000000
  19. /* TX Port: Length Error */
  20. #define FM_FD_ERR_LENGTH 0x02000000
  21. #define FM_FD_ERR_DMA 0x01000000 /* DMA Data error */
  22. /* IPR frame (not error) */
  23. #define FM_FD_IPR 0x00000001
  24. /* IPR non-consistent-sp */
  25. #define FM_FD_ERR_IPR_NCSP (0x00100000 | FM_FD_IPR)
  26. /* IPR error */
  27. #define FM_FD_ERR_IPR (0x00200000 | FM_FD_IPR)
  28. /* IPR timeout */
  29. #define FM_FD_ERR_IPR_TO (0x00300000 | FM_FD_IPR)
  30. /* TX Port: Length Error */
  31. #define FM_FD_ERR_IPRE (FM_FD_ERR_IPR & ~FM_FD_IPR)
  32. /* Rx FIFO overflow, FCS error, code error, running disparity error
  33. * (SGMII and TBI modes), FIFO parity error. PHY Sequence error,
  34. * PHY error control character detected.
  35. */
  36. #define FM_FD_ERR_PHYSICAL 0x00080000
  37. /* Frame too long OR Frame size exceeds max_length_frame */
  38. #define FM_FD_ERR_SIZE 0x00040000
  39. /* classification discard */
  40. #define FM_FD_ERR_CLS_DISCARD 0x00020000
  41. /* Extract Out of Frame */
  42. #define FM_FD_ERR_EXTRACTION 0x00008000
  43. /* No Scheme Selected */
  44. #define FM_FD_ERR_NO_SCHEME 0x00004000
  45. /* Keysize Overflow */
  46. #define FM_FD_ERR_KEYSIZE_OVERFLOW 0x00002000
  47. /* Frame color is red */
  48. #define FM_FD_ERR_COLOR_RED 0x00000800
  49. /* Frame color is yellow */
  50. #define FM_FD_ERR_COLOR_YELLOW 0x00000400
  51. /* Parser Time out Exceed */
  52. #define FM_FD_ERR_PRS_TIMEOUT 0x00000080
  53. /* Invalid Soft Parser instruction */
  54. #define FM_FD_ERR_PRS_ILL_INSTRUCT 0x00000040
  55. /* Header error was identified during parsing */
  56. #define FM_FD_ERR_PRS_HDR_ERR 0x00000020
  57. /* Frame parsed beyind 256 first bytes */
  58. #define FM_FD_ERR_BLOCK_LIMIT_EXCEEDED 0x00000008
  59. /* non Frame-Manager error */
  60. #define FM_FD_RX_STATUS_ERR_NON_FM 0x00400000
  61. /* FMan driver defines */
  62. #define FMAN_BMI_FIFO_UNITS 0x100
  63. #define OFFSET_UNITS 16
  64. /* BMan defines */
  65. #define BM_MAX_NUM_OF_POOLS 64 /* Buffers pools */
  66. #define FMAN_PORT_MAX_EXT_POOLS_NUM 8 /* External BM pools per Rx port */
  67. /* General defines */
  68. #define MAX_NUM_OF_MACS 10
  69. struct fman; /* FMan data */
  70. /* Enum for defining port types */
  71. enum fman_port_type {
  72. FMAN_PORT_TYPE_TX = 0, /* TX Port */
  73. FMAN_PORT_TYPE_RX, /* RX Port */
  74. };
  75. struct fman_rev_info {
  76. u8 major; /* Major revision */
  77. u8 minor; /* Minor revision */
  78. };
  79. enum fman_exceptions {
  80. FMAN_EX_DMA_BUS_ERROR = 0, /* DMA bus error. */
  81. FMAN_EX_DMA_READ_ECC, /* Read Buffer ECC error */
  82. FMAN_EX_DMA_SYSTEM_WRITE_ECC, /* Write Buffer ECC err on sys side */
  83. FMAN_EX_DMA_FM_WRITE_ECC, /* Write Buffer ECC error on FM side */
  84. FMAN_EX_DMA_SINGLE_PORT_ECC, /* Single Port ECC error on FM side */
  85. FMAN_EX_FPM_STALL_ON_TASKS, /* Stall of tasks on FPM */
  86. FMAN_EX_FPM_SINGLE_ECC, /* Single ECC on FPM. */
  87. FMAN_EX_FPM_DOUBLE_ECC, /* Double ECC error on FPM ram access */
  88. FMAN_EX_QMI_SINGLE_ECC, /* Single ECC on QMI. */
  89. FMAN_EX_QMI_DOUBLE_ECC, /* Double bit ECC occurred on QMI */
  90. FMAN_EX_QMI_DEQ_FROM_UNKNOWN_PORTID,/* DeQ from unknown port id */
  91. FMAN_EX_BMI_LIST_RAM_ECC, /* Linked List RAM ECC error */
  92. FMAN_EX_BMI_STORAGE_PROFILE_ECC,/* storage profile */
  93. FMAN_EX_BMI_STATISTICS_RAM_ECC,/* Statistics RAM ECC Err Enable */
  94. FMAN_EX_BMI_DISPATCH_RAM_ECC, /* Dispatch RAM ECC Error Enable */
  95. FMAN_EX_IRAM_ECC, /* Double bit ECC occurred on IRAM */
  96. FMAN_EX_MURAM_ECC /* Double bit ECC occurred on MURAM */
  97. };
  98. /* Parse results memory layout */
  99. struct fman_prs_result {
  100. u8 lpid; /* Logical port id */
  101. u8 shimr; /* Shim header result */
  102. __be16 l2r; /* Layer 2 result */
  103. __be16 l3r; /* Layer 3 result */
  104. u8 l4r; /* Layer 4 result */
  105. u8 cplan; /* Classification plan id */
  106. __be16 nxthdr; /* Next Header */
  107. __be16 cksum; /* Running-sum */
  108. /* Flags&fragment-offset field of the last IP-header */
  109. __be16 flags_frag_off;
  110. /* Routing type field of a IPV6 routing extension header */
  111. u8 route_type;
  112. /* Routing Extension Header Present; last bit is IP valid */
  113. u8 rhp_ip_valid;
  114. u8 shim_off[2]; /* Shim offset */
  115. u8 ip_pid_off; /* IP PID (last IP-proto) offset */
  116. u8 eth_off; /* ETH offset */
  117. u8 llc_snap_off; /* LLC_SNAP offset */
  118. u8 vlan_off[2]; /* VLAN offset */
  119. u8 etype_off; /* ETYPE offset */
  120. u8 pppoe_off; /* PPP offset */
  121. u8 mpls_off[2]; /* MPLS offset */
  122. u8 ip_off[2]; /* IP offset */
  123. u8 gre_off; /* GRE offset */
  124. u8 l4_off; /* Layer 4 offset */
  125. u8 nxthdr_off; /* Parser end point */
  126. };
  127. /* A structure for defining buffer prefix area content. */
  128. struct fman_buffer_prefix_content {
  129. /* Number of bytes to be left at the beginning of the external
  130. * buffer; Note that the private-area will start from the base
  131. * of the buffer address.
  132. */
  133. u16 priv_data_size;
  134. /* true to pass the parse result to/from the FM;
  135. * User may use FM_PORT_GetBufferPrsResult() in
  136. * order to get the parser-result from a buffer.
  137. */
  138. bool pass_prs_result;
  139. /* true to pass the timeStamp to/from the FM User */
  140. bool pass_time_stamp;
  141. /* true to pass the KG hash result to/from the FM User may
  142. * use FM_PORT_GetBufferHashResult() in order to get the
  143. * parser-result from a buffer.
  144. */
  145. bool pass_hash_result;
  146. /* Add all other Internal-Context information: AD,
  147. * hash-result, key, etc.
  148. */
  149. u16 data_align;
  150. };
  151. /* A structure of information about each of the external
  152. * buffer pools used by a port or storage-profile.
  153. */
  154. struct fman_ext_pool_params {
  155. u8 id; /* External buffer pool id */
  156. u16 size; /* External buffer pool buffer size */
  157. };
  158. /* A structure for informing the driver about the external
  159. * buffer pools allocated in the BM and used by a port or a
  160. * storage-profile.
  161. */
  162. struct fman_ext_pools {
  163. u8 num_of_pools_used; /* Number of pools use by this port */
  164. struct fman_ext_pool_params ext_buf_pool[FMAN_PORT_MAX_EXT_POOLS_NUM];
  165. /* Parameters for each port */
  166. };
  167. /* A structure for defining BM pool depletion criteria */
  168. struct fman_buf_pool_depletion {
  169. /* select mode in which pause frames will be sent after a
  170. * number of pools (all together!) are depleted
  171. */
  172. bool pools_grp_mode_enable;
  173. /* the number of depleted pools that will invoke pause
  174. * frames transmission.
  175. */
  176. u8 num_of_pools;
  177. /* For each pool, true if it should be considered for
  178. * depletion (Note - this pool must be used by this port!).
  179. */
  180. bool pools_to_consider[BM_MAX_NUM_OF_POOLS];
  181. /* select mode in which pause frames will be sent
  182. * after a single-pool is depleted;
  183. */
  184. bool single_pool_mode_enable;
  185. /* For each pool, true if it should be considered
  186. * for depletion (Note - this pool must be used by this port!)
  187. */
  188. bool pools_to_consider_for_single_mode[BM_MAX_NUM_OF_POOLS];
  189. };
  190. /* Enum for inter-module interrupts registration */
  191. enum fman_event_modules {
  192. FMAN_MOD_MAC = 0, /* MAC event */
  193. FMAN_MOD_FMAN_CTRL, /* FMAN Controller */
  194. FMAN_MOD_DUMMY_LAST
  195. };
  196. /* Enum for interrupts types */
  197. enum fman_intr_type {
  198. FMAN_INTR_TYPE_ERR,
  199. FMAN_INTR_TYPE_NORMAL
  200. };
  201. /* Enum for inter-module interrupts registration */
  202. enum fman_inter_module_event {
  203. FMAN_EV_ERR_MAC0 = 0, /* MAC 0 error event */
  204. FMAN_EV_ERR_MAC1, /* MAC 1 error event */
  205. FMAN_EV_ERR_MAC2, /* MAC 2 error event */
  206. FMAN_EV_ERR_MAC3, /* MAC 3 error event */
  207. FMAN_EV_ERR_MAC4, /* MAC 4 error event */
  208. FMAN_EV_ERR_MAC5, /* MAC 5 error event */
  209. FMAN_EV_ERR_MAC6, /* MAC 6 error event */
  210. FMAN_EV_ERR_MAC7, /* MAC 7 error event */
  211. FMAN_EV_ERR_MAC8, /* MAC 8 error event */
  212. FMAN_EV_ERR_MAC9, /* MAC 9 error event */
  213. FMAN_EV_MAC0, /* MAC 0 event (Magic packet detection) */
  214. FMAN_EV_MAC1, /* MAC 1 event (Magic packet detection) */
  215. FMAN_EV_MAC2, /* MAC 2 (Magic packet detection) */
  216. FMAN_EV_MAC3, /* MAC 3 (Magic packet detection) */
  217. FMAN_EV_MAC4, /* MAC 4 (Magic packet detection) */
  218. FMAN_EV_MAC5, /* MAC 5 (Magic packet detection) */
  219. FMAN_EV_MAC6, /* MAC 6 (Magic packet detection) */
  220. FMAN_EV_MAC7, /* MAC 7 (Magic packet detection) */
  221. FMAN_EV_MAC8, /* MAC 8 event (Magic packet detection) */
  222. FMAN_EV_MAC9, /* MAC 9 event (Magic packet detection) */
  223. FMAN_EV_FMAN_CTRL_0, /* Fman controller event 0 */
  224. FMAN_EV_FMAN_CTRL_1, /* Fman controller event 1 */
  225. FMAN_EV_FMAN_CTRL_2, /* Fman controller event 2 */
  226. FMAN_EV_FMAN_CTRL_3, /* Fman controller event 3 */
  227. FMAN_EV_CNT
  228. };
  229. struct fman_intr_src {
  230. void (*isr_cb)(void *src_arg);
  231. void *src_handle;
  232. };
  233. /** fman_exceptions_cb
  234. * fman - Pointer to FMan
  235. * exception - The exception.
  236. *
  237. * Exceptions user callback routine, will be called upon an exception
  238. * passing the exception identification.
  239. *
  240. * Return: irq status
  241. */
  242. typedef irqreturn_t (fman_exceptions_cb)(struct fman *fman,
  243. enum fman_exceptions exception);
  244. /** fman_bus_error_cb
  245. * fman - Pointer to FMan
  246. * port_id - Port id
  247. * addr - Address that caused the error
  248. * tnum - Owner of error
  249. * liodn - Logical IO device number
  250. *
  251. * Bus error user callback routine, will be called upon bus error,
  252. * passing parameters describing the errors and the owner.
  253. *
  254. * Return: IRQ status
  255. */
  256. typedef irqreturn_t (fman_bus_error_cb)(struct fman *fman, u8 port_id,
  257. u64 addr, u8 tnum, u16 liodn);
  258. /* Structure that holds information received from device tree */
  259. struct fman_dts_params {
  260. void __iomem *base_addr; /* FMan virtual address */
  261. struct resource *res; /* FMan memory resource */
  262. u8 id; /* FMan ID */
  263. int err_irq; /* FMan Error IRQ */
  264. u16 clk_freq; /* FMan clock freq (In Mhz) */
  265. u32 qman_channel_base; /* QMan channels base */
  266. u32 num_of_qman_channels; /* Number of QMan channels */
  267. struct resource muram_res; /* MURAM resource */
  268. };
  269. struct fman {
  270. struct device *dev;
  271. void __iomem *base_addr;
  272. struct fman_intr_src intr_mng[FMAN_EV_CNT];
  273. struct fman_fpm_regs __iomem *fpm_regs;
  274. struct fman_bmi_regs __iomem *bmi_regs;
  275. struct fman_qmi_regs __iomem *qmi_regs;
  276. struct fman_dma_regs __iomem *dma_regs;
  277. struct fman_hwp_regs __iomem *hwp_regs;
  278. struct fman_kg_regs __iomem *kg_regs;
  279. fman_exceptions_cb *exception_cb;
  280. fman_bus_error_cb *bus_error_cb;
  281. /* Spinlock for FMan use */
  282. spinlock_t spinlock;
  283. struct fman_state_struct *state;
  284. struct fman_cfg *cfg;
  285. struct muram_info *muram;
  286. struct fman_keygen *keygen;
  287. /* cam section in muram */
  288. unsigned long cam_offset;
  289. size_t cam_size;
  290. /* Fifo in MURAM */
  291. unsigned long fifo_offset;
  292. size_t fifo_size;
  293. u32 liodn_base[64];
  294. u32 liodn_offset[64];
  295. struct fman_dts_params dts_params;
  296. };
  297. /* Structure for port-FM communication during fman_port_init. */
  298. struct fman_port_init_params {
  299. u8 port_id; /* port Id */
  300. enum fman_port_type port_type; /* Port type */
  301. u16 port_speed; /* Port speed */
  302. u16 liodn_offset; /* Port's requested resource */
  303. u8 num_of_tasks; /* Port's requested resource */
  304. u8 num_of_extra_tasks; /* Port's requested resource */
  305. u8 num_of_open_dmas; /* Port's requested resource */
  306. u8 num_of_extra_open_dmas; /* Port's requested resource */
  307. u32 size_of_fifo; /* Port's requested resource */
  308. u32 extra_size_of_fifo; /* Port's requested resource */
  309. u8 deq_pipeline_depth; /* Port's requested resource */
  310. u16 max_frame_length; /* Port's max frame length. */
  311. u16 liodn_base;
  312. /* LIODN base for this port, to be used together with LIODN offset. */
  313. };
  314. void fman_get_revision(struct fman *fman, struct fman_rev_info *rev_info);
  315. void fman_register_intr(struct fman *fman, enum fman_event_modules mod,
  316. u8 mod_id, enum fman_intr_type intr_type,
  317. void (*f_isr)(void *h_src_arg), void *h_src_arg);
  318. void fman_unregister_intr(struct fman *fman, enum fman_event_modules mod,
  319. u8 mod_id, enum fman_intr_type intr_type);
  320. int fman_set_port_params(struct fman *fman,
  321. struct fman_port_init_params *port_params);
  322. int fman_reset_mac(struct fman *fman, u8 mac_id);
  323. u16 fman_get_clock_freq(struct fman *fman);
  324. u32 fman_get_bmi_max_fifo_size(struct fman *fman);
  325. int fman_set_mac_max_frame(struct fman *fman, u8 mac_id, u16 mfl);
  326. u32 fman_get_qman_channel_id(struct fman *fman, u32 port_id);
  327. struct resource *fman_get_mem_region(struct fman *fman);
  328. u16 fman_get_max_frm(void);
  329. int fman_get_rx_extra_headroom(void);
  330. #ifdef CONFIG_DPAA_ERRATUM_A050385
  331. bool fman_has_errata_a050385(void);
  332. #endif
  333. struct fman *fman_bind(struct device *dev);
  334. #endif /* __FM_H */