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