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