fman.h 14 KB

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