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.
33 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
35 #include "fman_port.h"
40 #include <linux/slab.h>
41 #include <linux/module.h>
42 #include <linux/interrupt.h>
43 #include <linux/of_platform.h>
44 #include <linux/of_address.h>
45 #include <linux/delay.h>
46 #include <linux/libfdt_env.h>
49 #define DFLT_FQ_ID 0x00FFFFFF
52 #define PORT_BMI_FIFO_UNITS 0x100
54 #define MAX_PORT_FIFO_SIZE(bmi_max_fifo_size) \
55 min((u32)bmi_max_fifo_size, (u32)1024 * FMAN_BMI_FIFO_UNITS)
57 #define PORT_CG_MAP_NUM 8
58 #define PORT_PRS_RESULT_WORDS_NUM 8
59 #define PORT_IC_OFFSET_UNITS 0x10
61 #define MIN_EXT_BUF_SIZE 64
63 #define BMI_PORT_REGS_OFFSET 0
64 #define QMI_PORT_REGS_OFFSET 0x400
67 #define DFLT_PORT_BUFFER_PREFIX_CONTEXT_DATA_ALIGN \
68 DFLT_FM_SP_BUFFER_PREFIX_CONTEXT_DATA_ALIGN
70 #define DFLT_PORT_CUT_BYTES_FROM_END 4
72 #define DFLT_PORT_ERRORS_TO_DISCARD FM_PORT_FRM_ERR_CLS_DISCARD
73 #define DFLT_PORT_MAX_FRAME_LENGTH 9600
75 #define DFLT_PORT_RX_FIFO_PRI_ELEVATION_LEV(bmi_max_fifo_size) \
76 MAX_PORT_FIFO_SIZE(bmi_max_fifo_size)
78 #define DFLT_PORT_RX_FIFO_THRESHOLD(major, bmi_max_fifo_size) \
80 MAX_PORT_FIFO_SIZE(bmi_max_fifo_size) : \
81 (MAX_PORT_FIFO_SIZE(bmi_max_fifo_size) * 3 / 4)) \
83 #define DFLT_PORT_EXTRA_NUM_OF_FIFO_BUFS 0
86 #define QMI_DEQ_CFG_SUBPORTAL_MASK 0x1f
88 #define QMI_PORT_CFG_EN 0x80000000
89 #define QMI_PORT_STATUS_DEQ_FD_BSY 0x20000000
91 #define QMI_DEQ_CFG_PRI 0x80000000
92 #define QMI_DEQ_CFG_TYPE1 0x10000000
93 #define QMI_DEQ_CFG_TYPE2 0x20000000
94 #define QMI_DEQ_CFG_TYPE3 0x30000000
95 #define QMI_DEQ_CFG_PREFETCH_PARTIAL 0x01000000
96 #define QMI_DEQ_CFG_PREFETCH_FULL 0x03000000
97 #define QMI_DEQ_CFG_SP_MASK 0xf
98 #define QMI_DEQ_CFG_SP_SHIFT 20
100 #define QMI_BYTE_COUNT_LEVEL_CONTROL(_type) \
101 (_type == FMAN_PORT_TYPE_TX ? 0x1400 : 0x400)
104 #define BMI_EBD_EN 0x80000000
106 #define BMI_PORT_CFG_EN 0x80000000
108 #define BMI_PORT_STATUS_BSY 0x80000000
110 #define BMI_DMA_ATTR_SWP_SHIFT FMAN_SP_DMA_ATTR_SWP_SHIFT
111 #define BMI_DMA_ATTR_WRITE_OPTIMIZE FMAN_SP_DMA_ATTR_WRITE_OPTIMIZE
113 #define BMI_RX_FIFO_PRI_ELEVATION_SHIFT 16
114 #define BMI_RX_FIFO_THRESHOLD_ETHE 0x80000000
116 #define BMI_FRAME_END_CS_IGNORE_SHIFT 24
117 #define BMI_FRAME_END_CS_IGNORE_MASK 0x0000001f
119 #define BMI_RX_FRAME_END_CUT_SHIFT 16
120 #define BMI_RX_FRAME_END_CUT_MASK 0x0000001f
122 #define BMI_IC_TO_EXT_SHIFT FMAN_SP_IC_TO_EXT_SHIFT
123 #define BMI_IC_TO_EXT_MASK 0x0000001f
124 #define BMI_IC_FROM_INT_SHIFT FMAN_SP_IC_FROM_INT_SHIFT
125 #define BMI_IC_FROM_INT_MASK 0x0000000f
126 #define BMI_IC_SIZE_MASK 0x0000001f
128 #define BMI_INT_BUF_MARG_SHIFT 28
129 #define BMI_INT_BUF_MARG_MASK 0x0000000f
130 #define BMI_EXT_BUF_MARG_START_SHIFT FMAN_SP_EXT_BUF_MARG_START_SHIFT
131 #define BMI_EXT_BUF_MARG_START_MASK 0x000001ff
132 #define BMI_EXT_BUF_MARG_END_MASK 0x000001ff
134 #define BMI_CMD_MR_LEAC 0x00200000
135 #define BMI_CMD_MR_SLEAC 0x00100000
136 #define BMI_CMD_MR_MA 0x00080000
137 #define BMI_CMD_MR_DEAS 0x00040000
138 #define BMI_CMD_RX_MR_DEF (BMI_CMD_MR_LEAC | \
142 #define BMI_CMD_TX_MR_DEF 0
144 #define BMI_CMD_ATTR_ORDER 0x80000000
145 #define BMI_CMD_ATTR_SYNC 0x02000000
146 #define BMI_CMD_ATTR_COLOR_SHIFT 26
148 #define BMI_FIFO_PIPELINE_DEPTH_SHIFT 12
149 #define BMI_FIFO_PIPELINE_DEPTH_MASK 0x0000000f
150 #define BMI_NEXT_ENG_FD_BITS_SHIFT 24
152 #define BMI_EXT_BUF_POOL_VALID FMAN_SP_EXT_BUF_POOL_VALID
153 #define BMI_EXT_BUF_POOL_EN_COUNTER FMAN_SP_EXT_BUF_POOL_EN_COUNTER
154 #define BMI_EXT_BUF_POOL_BACKUP FMAN_SP_EXT_BUF_POOL_BACKUP
155 #define BMI_EXT_BUF_POOL_ID_SHIFT 16
156 #define BMI_EXT_BUF_POOL_ID_MASK 0x003F0000
157 #define BMI_POOL_DEP_NUM_OF_POOLS_SHIFT 16
159 #define BMI_TX_FIFO_MIN_FILL_SHIFT 16
161 #define BMI_PRIORITY_ELEVATION_LEVEL ((0x3FF + 1) * PORT_BMI_FIFO_UNITS)
162 #define BMI_FIFO_THRESHOLD ((0x3FF + 1) * PORT_BMI_FIFO_UNITS)
164 #define BMI_DEQUEUE_PIPELINE_DEPTH(_type, _speed) \
165 ((_type == FMAN_PORT_TYPE_TX && _speed == 10000) ? 4 : 1)
167 #define RX_ERRS_TO_ENQ \
168 (FM_PORT_FRM_ERR_DMA | \
169 FM_PORT_FRM_ERR_PHYSICAL | \
170 FM_PORT_FRM_ERR_SIZE | \
171 FM_PORT_FRM_ERR_EXTRACTION | \
172 FM_PORT_FRM_ERR_NO_SCHEME | \
173 FM_PORT_FRM_ERR_PRS_TIMEOUT | \
174 FM_PORT_FRM_ERR_PRS_ILL_INSTRUCT | \
175 FM_PORT_FRM_ERR_BLOCK_LIMIT_EXCEEDED | \
176 FM_PORT_FRM_ERR_PRS_HDR_ERR | \
177 FM_PORT_FRM_ERR_KEYSIZE_OVERFLOW | \
178 FM_PORT_FRM_ERR_IPRE)
181 #define NIA_ORDER_RESTOR 0x00800000
182 #define NIA_ENG_BMI 0x00500000
183 #define NIA_ENG_QMI_ENQ 0x00540000
184 #define NIA_ENG_QMI_DEQ 0x00580000
186 #define NIA_BMI_AC_ENQ_FRAME 0x00000002
187 #define NIA_BMI_AC_TX_RELEASE 0x000002C0
188 #define NIA_BMI_AC_RELEASE 0x000000C0
189 #define NIA_BMI_AC_TX 0x00000274
190 #define NIA_BMI_AC_FETCH_ALL_FRAME 0x0000020c
193 #define TX_10G_PORT_BASE 0x30
194 #define RX_10G_PORT_BASE 0x10
196 /* BMI Rx port register map */
197 struct fman_port_rx_bmi_regs
{
198 u32 fmbm_rcfg
; /* Rx Configuration */
199 u32 fmbm_rst
; /* Rx Status */
200 u32 fmbm_rda
; /* Rx DMA attributes */
201 u32 fmbm_rfp
; /* Rx FIFO Parameters */
202 u32 fmbm_rfed
; /* Rx Frame End Data */
203 u32 fmbm_ricp
; /* Rx Internal Context Parameters */
204 u32 fmbm_rim
; /* Rx Internal Buffer Margins */
205 u32 fmbm_rebm
; /* Rx External Buffer Margins */
206 u32 fmbm_rfne
; /* Rx Frame Next Engine */
207 u32 fmbm_rfca
; /* Rx Frame Command Attributes. */
208 u32 fmbm_rfpne
; /* Rx Frame Parser Next Engine */
209 u32 fmbm_rpso
; /* Rx Parse Start Offset */
210 u32 fmbm_rpp
; /* Rx Policer Profile */
211 u32 fmbm_rccb
; /* Rx Coarse Classification Base */
212 u32 fmbm_reth
; /* Rx Excessive Threshold */
213 u32 reserved003c
[1]; /* (0x03C 0x03F) */
214 u32 fmbm_rprai
[PORT_PRS_RESULT_WORDS_NUM
];
215 /* Rx Parse Results Array Init */
216 u32 fmbm_rfqid
; /* Rx Frame Queue ID */
217 u32 fmbm_refqid
; /* Rx Error Frame Queue ID */
218 u32 fmbm_rfsdm
; /* Rx Frame Status Discard Mask */
219 u32 fmbm_rfsem
; /* Rx Frame Status Error Mask */
220 u32 fmbm_rfene
; /* Rx Frame Enqueue Next Engine */
221 u32 reserved0074
[0x2]; /* (0x074-0x07C) */
222 u32 fmbm_rcmne
; /* Rx Frame Continuous Mode Next Engine */
223 u32 reserved0080
[0x20]; /* (0x080 0x0FF) */
224 u32 fmbm_ebmpi
[FMAN_PORT_MAX_EXT_POOLS_NUM
];
225 /* Buffer Manager pool Information- */
226 u32 fmbm_acnt
[FMAN_PORT_MAX_EXT_POOLS_NUM
]; /* Allocate Counter- */
227 u32 reserved0130
[8]; /* 0x130/0x140 - 0x15F reserved - */
228 u32 fmbm_rcgm
[PORT_CG_MAP_NUM
]; /* Congestion Group Map */
229 u32 fmbm_mpd
; /* BM Pool Depletion */
230 u32 reserved0184
[0x1F]; /* (0x184 0x1FF) */
231 u32 fmbm_rstc
; /* Rx Statistics Counters */
232 u32 fmbm_rfrc
; /* Rx Frame Counter */
233 u32 fmbm_rfbc
; /* Rx Bad Frames Counter */
234 u32 fmbm_rlfc
; /* Rx Large Frames Counter */
235 u32 fmbm_rffc
; /* Rx Filter Frames Counter */
236 u32 fmbm_rfdc
; /* Rx Frame Discard Counter */
237 u32 fmbm_rfldec
; /* Rx Frames List DMA Error Counter */
238 u32 fmbm_rodc
; /* Rx Out of Buffers Discard nntr */
239 u32 fmbm_rbdc
; /* Rx Buffers Deallocate Counter */
240 u32 fmbm_rpec
; /* RX Prepare to enqueue Counte */
241 u32 reserved0224
[0x16]; /* (0x224 0x27F) */
242 u32 fmbm_rpc
; /* Rx Performance Counters */
243 u32 fmbm_rpcp
; /* Rx Performance Count Parameters */
244 u32 fmbm_rccn
; /* Rx Cycle Counter */
245 u32 fmbm_rtuc
; /* Rx Tasks Utilization Counter */
246 u32 fmbm_rrquc
; /* Rx Receive Queue Utilization cntr */
247 u32 fmbm_rduc
; /* Rx DMA Utilization Counter */
248 u32 fmbm_rfuc
; /* Rx FIFO Utilization Counter */
249 u32 fmbm_rpac
; /* Rx Pause Activation Counter */
250 u32 reserved02a0
[0x18]; /* (0x2A0 0x2FF) */
251 u32 fmbm_rdcfg
[0x3]; /* Rx Debug Configuration */
252 u32 fmbm_rgpr
; /* Rx General Purpose Register */
253 u32 reserved0310
[0x3a];
256 /* BMI Tx port register map */
257 struct fman_port_tx_bmi_regs
{
258 u32 fmbm_tcfg
; /* Tx Configuration */
259 u32 fmbm_tst
; /* Tx Status */
260 u32 fmbm_tda
; /* Tx DMA attributes */
261 u32 fmbm_tfp
; /* Tx FIFO Parameters */
262 u32 fmbm_tfed
; /* Tx Frame End Data */
263 u32 fmbm_ticp
; /* Tx Internal Context Parameters */
264 u32 fmbm_tfdne
; /* Tx Frame Dequeue Next Engine. */
265 u32 fmbm_tfca
; /* Tx Frame Command attribute. */
266 u32 fmbm_tcfqid
; /* Tx Confirmation Frame Queue ID. */
267 u32 fmbm_tefqid
; /* Tx Frame Error Queue ID */
268 u32 fmbm_tfene
; /* Tx Frame Enqueue Next Engine */
269 u32 fmbm_trlmts
; /* Tx Rate Limiter Scale */
270 u32 fmbm_trlmt
; /* Tx Rate Limiter */
271 u32 reserved0034
[0x0e]; /* (0x034-0x6c) */
272 u32 fmbm_tccb
; /* Tx Coarse Classification base */
273 u32 fmbm_tfne
; /* Tx Frame Next Engine */
274 u32 fmbm_tpfcm
[0x02];
275 /* Tx Priority based Flow Control (PFC) Mapping */
276 u32 fmbm_tcmne
; /* Tx Frame Continuous Mode Next Engine */
277 u32 reserved0080
[0x60]; /* (0x080-0x200) */
278 u32 fmbm_tstc
; /* Tx Statistics Counters */
279 u32 fmbm_tfrc
; /* Tx Frame Counter */
280 u32 fmbm_tfdc
; /* Tx Frames Discard Counter */
281 u32 fmbm_tfledc
; /* Tx Frame len error discard cntr */
282 u32 fmbm_tfufdc
; /* Tx Frame unsprt frmt discard cntr */
283 u32 fmbm_tbdc
; /* Tx Buffers Deallocate Counter */
284 u32 reserved0218
[0x1A]; /* (0x218-0x280) */
285 u32 fmbm_tpc
; /* Tx Performance Counters */
286 u32 fmbm_tpcp
; /* Tx Performance Count Parameters */
287 u32 fmbm_tccn
; /* Tx Cycle Counter */
288 u32 fmbm_ttuc
; /* Tx Tasks Utilization Counter */
289 u32 fmbm_ttcquc
; /* Tx Transmit conf Q util Counter */
290 u32 fmbm_tduc
; /* Tx DMA Utilization Counter */
291 u32 fmbm_tfuc
; /* Tx FIFO Utilization Counter */
292 u32 reserved029c
[16]; /* (0x29C-0x2FF) */
293 u32 fmbm_tdcfg
[0x3]; /* Tx Debug Configuration */
294 u32 fmbm_tgpr
; /* Tx General Purpose Register */
295 u32 reserved0310
[0x3a]; /* (0x310-0x3FF) */
298 /* BMI port register map */
299 union fman_port_bmi_regs
{
300 struct fman_port_rx_bmi_regs rx
;
301 struct fman_port_tx_bmi_regs tx
;
304 /* QMI port register map */
305 struct fman_port_qmi_regs
{
306 u32 fmqm_pnc
; /* PortID n Configuration Register */
307 u32 fmqm_pns
; /* PortID n Status Register */
308 u32 fmqm_pnts
; /* PortID n Task Status Register */
309 u32 reserved00c
[4]; /* 0xn00C - 0xn01B */
310 u32 fmqm_pnen
; /* PortID n Enqueue NIA Register */
311 u32 fmqm_pnetfc
; /* PortID n Enq Total Frame Counter */
312 u32 reserved024
[2]; /* 0xn024 - 0x02B */
313 u32 fmqm_pndn
; /* PortID n Dequeue NIA Register */
314 u32 fmqm_pndc
; /* PortID n Dequeue Config Register */
315 u32 fmqm_pndtfc
; /* PortID n Dequeue tot Frame cntr */
316 u32 fmqm_pndfdc
; /* PortID n Dequeue FQID Dflt Cntr */
317 u32 fmqm_pndcc
; /* PortID n Dequeue Confirm Counter */
320 /* QMI dequeue prefetch modes */
321 enum fman_port_deq_prefetch
{
322 FMAN_PORT_DEQ_NO_PREFETCH
, /* No prefetch mode */
323 FMAN_PORT_DEQ_PART_PREFETCH
, /* Partial prefetch mode */
324 FMAN_PORT_DEQ_FULL_PREFETCH
/* Full prefetch mode */
327 /* A structure for defining FM port resources */
328 struct fman_port_rsrc
{
329 u32 num
; /* Committed required resource */
330 u32 extra
; /* Extra (not committed) required resource */
333 enum fman_port_dma_swap
{
334 FMAN_PORT_DMA_NO_SWAP
, /* No swap, transfer data as is */
335 FMAN_PORT_DMA_SWAP_LE
,
336 /* The transferred data should be swapped in PPC Little Endian mode */
337 FMAN_PORT_DMA_SWAP_BE
338 /* The transferred data should be swapped in Big Endian mode */
341 /* Default port color */
342 enum fman_port_color
{
343 FMAN_PORT_COLOR_GREEN
, /* Default port color is green */
344 FMAN_PORT_COLOR_YELLOW
, /* Default port color is yellow */
345 FMAN_PORT_COLOR_RED
, /* Default port color is red */
346 FMAN_PORT_COLOR_OVERRIDE
/* Ignore color */
349 /* QMI dequeue from the SP channel - types */
350 enum fman_port_deq_type
{
351 FMAN_PORT_DEQ_BY_PRI
,
352 /* Priority precedence and Intra-Class scheduling */
353 FMAN_PORT_DEQ_ACTIVE_FQ
,
354 /* Active FQ precedence and Intra-Class scheduling */
355 FMAN_PORT_DEQ_ACTIVE_FQ_NO_ICS
356 /* Active FQ precedence and override Intra-Class scheduling */
359 /* External buffer pools configuration */
360 struct fman_port_bpools
{
361 u8 count
; /* Num of pools to set up */
362 bool counters_enable
; /* Enable allocate counters */
363 u8 grp_bp_depleted_num
;
364 /* Number of depleted pools - if reached the BMI indicates
365 * the MAC to send a pause frame
368 u8 bpid
; /* BM pool ID */
370 /* Pool's size - must be in ascending order */
372 /* If this is a backup pool */
373 bool grp_bp_depleted
;
374 /* Consider this buffer in multiple pools depletion criteria */
375 bool single_bp_depleted
;
376 /* Consider this buffer in single pool depletion criteria */
377 } bpool
[FMAN_PORT_MAX_EXT_POOLS_NUM
];
380 struct fman_port_cfg
{
384 bool deq_high_priority
;
385 enum fman_port_deq_type deq_type
;
386 enum fman_port_deq_prefetch deq_prefetch_option
;
388 u8 cheksum_last_bytes_ignore
;
390 struct fman_buf_pool_depletion buf_pool_depletion
;
391 struct fman_ext_pools ext_buf_pools
;
392 u32 tx_fifo_min_level
;
393 u32 tx_fifo_low_comf_level
;
394 u32 rx_pri_elevation
;
396 struct fman_sp_buf_margins buf_margins
;
397 u32 int_buf_start_margin
;
398 struct fman_sp_int_context_data_copy int_context
;
401 struct fman_buffer_prefix_content buffer_prefix_content
;
402 bool dont_release_buf
;
405 u32 tx_fifo_deq_pipeline_depth
;
407 bool excessive_threshold_register
;
408 bool fmbm_tfne_has_features
;
410 enum fman_port_dma_swap dma_swap_data
;
411 enum fman_port_color color
;
414 struct fman_port_rx_pools_params
{
416 u16 second_largest_buf_size
;
417 u16 largest_buf_size
;
420 struct fman_port_dts_params
{
421 void __iomem
*base_addr
; /* FMan port virtual memory */
422 enum fman_port_type type
; /* Port type */
423 u16 speed
; /* Port speed */
424 u8 id
; /* HW Port Id */
425 u32 qman_channel_id
; /* QMan channel id (non RX only) */
426 struct fman
*fman
; /* FMan Handle */
432 struct fman_rev_info rev_info
;
434 enum fman_port_type port_type
;
437 union fman_port_bmi_regs __iomem
*bmi_regs
;
438 struct fman_port_qmi_regs __iomem
*qmi_regs
;
440 struct fman_sp_buffer_offsets buffer_offsets
;
442 u8 internal_buf_offset
;
443 struct fman_ext_pools ext_buf_pools
;
445 u16 max_frame_length
;
446 struct fman_port_rsrc open_dmas
;
447 struct fman_port_rsrc tasks
;
448 struct fman_port_rsrc fifo_bufs
;
449 struct fman_port_rx_pools_params rx_pools_params
;
451 struct fman_port_cfg
*cfg
;
452 struct fman_port_dts_params dts_params
;
455 u32 max_port_fifo_size
;
456 u32 max_num_of_ext_pools
;
457 u32 max_num_of_sub_portals
;
458 u32 bm_max_num_of_pools
;
461 static int init_bmi_rx(struct fman_port
*port
)
463 struct fman_port_rx_bmi_regs __iomem
*regs
= &port
->bmi_regs
->rx
;
464 struct fman_port_cfg
*cfg
= port
->cfg
;
468 tmp
= (u32
)cfg
->dma_swap_data
<< BMI_DMA_ATTR_SWP_SHIFT
;
469 /* Enable write optimization */
470 tmp
|= BMI_DMA_ATTR_WRITE_OPTIMIZE
;
471 iowrite32be(tmp
, ®s
->fmbm_rda
);
473 /* Rx FIFO parameters */
474 tmp
= (cfg
->rx_pri_elevation
/ PORT_BMI_FIFO_UNITS
- 1) <<
475 BMI_RX_FIFO_PRI_ELEVATION_SHIFT
;
476 tmp
|= cfg
->rx_fifo_thr
/ PORT_BMI_FIFO_UNITS
- 1;
477 iowrite32be(tmp
, ®s
->fmbm_rfp
);
479 if (cfg
->excessive_threshold_register
)
480 /* always allow access to the extra resources */
481 iowrite32be(BMI_RX_FIFO_THRESHOLD_ETHE
, ®s
->fmbm_reth
);
484 tmp
= (cfg
->cheksum_last_bytes_ignore
& BMI_FRAME_END_CS_IGNORE_MASK
) <<
485 BMI_FRAME_END_CS_IGNORE_SHIFT
;
486 tmp
|= (cfg
->rx_cut_end_bytes
& BMI_RX_FRAME_END_CUT_MASK
) <<
487 BMI_RX_FRAME_END_CUT_SHIFT
;
488 if (cfg
->errata_A006320
)
490 iowrite32be(tmp
, ®s
->fmbm_rfed
);
492 /* Internal context parameters */
493 tmp
= ((cfg
->int_context
.ext_buf_offset
/ PORT_IC_OFFSET_UNITS
) &
494 BMI_IC_TO_EXT_MASK
) << BMI_IC_TO_EXT_SHIFT
;
495 tmp
|= ((cfg
->int_context
.int_context_offset
/ PORT_IC_OFFSET_UNITS
) &
496 BMI_IC_FROM_INT_MASK
) << BMI_IC_FROM_INT_SHIFT
;
497 tmp
|= (cfg
->int_context
.size
/ PORT_IC_OFFSET_UNITS
) &
499 iowrite32be(tmp
, ®s
->fmbm_ricp
);
501 /* Internal buffer offset */
502 tmp
= ((cfg
->int_buf_start_margin
/ PORT_IC_OFFSET_UNITS
) &
503 BMI_INT_BUF_MARG_MASK
) << BMI_INT_BUF_MARG_SHIFT
;
504 iowrite32be(tmp
, ®s
->fmbm_rim
);
506 /* External buffer margins */
507 tmp
= (cfg
->buf_margins
.start_margins
& BMI_EXT_BUF_MARG_START_MASK
) <<
508 BMI_EXT_BUF_MARG_START_SHIFT
;
509 tmp
|= cfg
->buf_margins
.end_margins
& BMI_EXT_BUF_MARG_END_MASK
;
510 iowrite32be(tmp
, ®s
->fmbm_rebm
);
512 /* Frame attributes */
513 tmp
= BMI_CMD_RX_MR_DEF
;
514 tmp
|= BMI_CMD_ATTR_ORDER
;
515 tmp
|= (u32
)cfg
->color
<< BMI_CMD_ATTR_COLOR_SHIFT
;
516 /* Synchronization request */
517 tmp
|= BMI_CMD_ATTR_SYNC
;
519 iowrite32be(tmp
, ®s
->fmbm_rfca
);
522 tmp
= (u32
)cfg
->rx_fd_bits
<< BMI_NEXT_ENG_FD_BITS_SHIFT
;
524 tmp
|= NIA_ENG_BMI
| NIA_BMI_AC_ENQ_FRAME
;
525 iowrite32be(tmp
, ®s
->fmbm_rfne
);
528 iowrite32be(NIA_ENG_QMI_ENQ
| NIA_ORDER_RESTOR
, ®s
->fmbm_rfene
);
530 /* Default/error queues */
531 iowrite32be((cfg
->dflt_fqid
& DFLT_FQ_ID
), ®s
->fmbm_rfqid
);
532 iowrite32be((cfg
->err_fqid
& DFLT_FQ_ID
), ®s
->fmbm_refqid
);
534 /* Discard/error masks */
535 iowrite32be(cfg
->discard_mask
, ®s
->fmbm_rfsdm
);
536 iowrite32be(cfg
->err_mask
, ®s
->fmbm_rfsem
);
541 static int init_bmi_tx(struct fman_port
*port
)
543 struct fman_port_tx_bmi_regs __iomem
*regs
= &port
->bmi_regs
->tx
;
544 struct fman_port_cfg
*cfg
= port
->cfg
;
547 /* Tx Configuration register */
549 iowrite32be(tmp
, ®s
->fmbm_tcfg
);
552 tmp
= (u32
)cfg
->dma_swap_data
<< BMI_DMA_ATTR_SWP_SHIFT
;
553 iowrite32be(tmp
, ®s
->fmbm_tda
);
555 /* Tx FIFO parameters */
556 tmp
= (cfg
->tx_fifo_min_level
/ PORT_BMI_FIFO_UNITS
) <<
557 BMI_TX_FIFO_MIN_FILL_SHIFT
;
558 tmp
|= ((cfg
->tx_fifo_deq_pipeline_depth
- 1) &
559 BMI_FIFO_PIPELINE_DEPTH_MASK
) << BMI_FIFO_PIPELINE_DEPTH_SHIFT
;
560 tmp
|= (cfg
->tx_fifo_low_comf_level
/ PORT_BMI_FIFO_UNITS
) - 1;
561 iowrite32be(tmp
, ®s
->fmbm_tfp
);
564 tmp
= (cfg
->cheksum_last_bytes_ignore
& BMI_FRAME_END_CS_IGNORE_MASK
) <<
565 BMI_FRAME_END_CS_IGNORE_SHIFT
;
566 iowrite32be(tmp
, ®s
->fmbm_tfed
);
568 /* Internal context parameters */
569 tmp
= ((cfg
->int_context
.ext_buf_offset
/ PORT_IC_OFFSET_UNITS
) &
570 BMI_IC_TO_EXT_MASK
) << BMI_IC_TO_EXT_SHIFT
;
571 tmp
|= ((cfg
->int_context
.int_context_offset
/ PORT_IC_OFFSET_UNITS
) &
572 BMI_IC_FROM_INT_MASK
) << BMI_IC_FROM_INT_SHIFT
;
573 tmp
|= (cfg
->int_context
.size
/ PORT_IC_OFFSET_UNITS
) &
575 iowrite32be(tmp
, ®s
->fmbm_ticp
);
577 /* Frame attributes */
578 tmp
= BMI_CMD_TX_MR_DEF
;
579 tmp
|= BMI_CMD_ATTR_ORDER
;
580 tmp
|= (u32
)cfg
->color
<< BMI_CMD_ATTR_COLOR_SHIFT
;
581 iowrite32be(tmp
, ®s
->fmbm_tfca
);
583 /* Dequeue NIA + enqueue NIA */
584 iowrite32be(NIA_ENG_QMI_DEQ
, ®s
->fmbm_tfdne
);
585 iowrite32be(NIA_ENG_QMI_ENQ
| NIA_ORDER_RESTOR
, ®s
->fmbm_tfene
);
586 if (cfg
->fmbm_tfne_has_features
)
587 iowrite32be(!cfg
->dflt_fqid
?
588 BMI_EBD_EN
| NIA_BMI_AC_FETCH_ALL_FRAME
:
589 NIA_BMI_AC_FETCH_ALL_FRAME
, ®s
->fmbm_tfne
);
590 if (!cfg
->dflt_fqid
&& cfg
->dont_release_buf
) {
591 iowrite32be(DFLT_FQ_ID
, ®s
->fmbm_tcfqid
);
592 iowrite32be(NIA_ENG_BMI
| NIA_BMI_AC_TX_RELEASE
,
594 if (cfg
->fmbm_tfne_has_features
)
595 iowrite32be(ioread32be(®s
->fmbm_tfne
) & ~BMI_EBD_EN
,
599 /* Confirmation/error queues */
600 if (cfg
->dflt_fqid
|| !cfg
->dont_release_buf
)
601 iowrite32be(cfg
->dflt_fqid
& DFLT_FQ_ID
, ®s
->fmbm_tcfqid
);
602 iowrite32be((cfg
->err_fqid
& DFLT_FQ_ID
), ®s
->fmbm_tefqid
);
607 static int init_qmi(struct fman_port
*port
)
609 struct fman_port_qmi_regs __iomem
*regs
= port
->qmi_regs
;
610 struct fman_port_cfg
*cfg
= port
->cfg
;
613 /* Rx port configuration */
614 if (port
->port_type
== FMAN_PORT_TYPE_RX
) {
616 iowrite32be(NIA_ENG_BMI
| NIA_BMI_AC_RELEASE
, ®s
->fmqm_pnen
);
620 /* Continue with Tx port configuration */
621 if (port
->port_type
== FMAN_PORT_TYPE_TX
) {
623 iowrite32be(NIA_ENG_BMI
| NIA_BMI_AC_TX_RELEASE
,
626 iowrite32be(NIA_ENG_BMI
| NIA_BMI_AC_TX
, ®s
->fmqm_pndn
);
629 /* Dequeue Configuration register */
631 if (cfg
->deq_high_priority
)
632 tmp
|= QMI_DEQ_CFG_PRI
;
634 switch (cfg
->deq_type
) {
635 case FMAN_PORT_DEQ_BY_PRI
:
636 tmp
|= QMI_DEQ_CFG_TYPE1
;
638 case FMAN_PORT_DEQ_ACTIVE_FQ
:
639 tmp
|= QMI_DEQ_CFG_TYPE2
;
641 case FMAN_PORT_DEQ_ACTIVE_FQ_NO_ICS
:
642 tmp
|= QMI_DEQ_CFG_TYPE3
;
648 switch (cfg
->deq_prefetch_option
) {
649 case FMAN_PORT_DEQ_NO_PREFETCH
:
651 case FMAN_PORT_DEQ_PART_PREFETCH
:
652 tmp
|= QMI_DEQ_CFG_PREFETCH_PARTIAL
;
654 case FMAN_PORT_DEQ_FULL_PREFETCH
:
655 tmp
|= QMI_DEQ_CFG_PREFETCH_FULL
;
661 tmp
|= (cfg
->deq_sp
& QMI_DEQ_CFG_SP_MASK
) << QMI_DEQ_CFG_SP_SHIFT
;
662 tmp
|= cfg
->deq_byte_cnt
;
663 iowrite32be(tmp
, ®s
->fmqm_pndc
);
668 static int init(struct fman_port
*port
)
672 /* Init BMI registers */
673 switch (port
->port_type
) {
674 case FMAN_PORT_TYPE_RX
:
675 err
= init_bmi_rx(port
);
677 case FMAN_PORT_TYPE_TX
:
678 err
= init_bmi_tx(port
);
687 /* Init QMI registers */
688 err
= init_qmi(port
);
694 static int set_bpools(const struct fman_port
*port
,
695 const struct fman_port_bpools
*bp
)
697 u32 __iomem
*bp_reg
, *bp_depl_reg
;
700 bool grp_depl_used
= false, rx_port
;
702 switch (port
->port_type
) {
703 case FMAN_PORT_TYPE_RX
:
704 max_bp_num
= port
->ext_pools_num
;
706 bp_reg
= port
->bmi_regs
->rx
.fmbm_ebmpi
;
707 bp_depl_reg
= &port
->bmi_regs
->rx
.fmbm_mpd
;
714 /* Check buffers are provided in ascending order */
715 for (i
= 0; (i
< (bp
->count
- 1) &&
716 (i
< FMAN_PORT_MAX_EXT_POOLS_NUM
- 1)); i
++) {
717 if (bp
->bpool
[i
].size
> bp
->bpool
[i
+ 1].size
)
722 /* Set up external buffers pools */
723 for (i
= 0; i
< bp
->count
; i
++) {
724 tmp
= BMI_EXT_BUF_POOL_VALID
;
725 tmp
|= ((u32
)bp
->bpool
[i
].bpid
<<
726 BMI_EXT_BUF_POOL_ID_SHIFT
) & BMI_EXT_BUF_POOL_ID_MASK
;
729 if (bp
->counters_enable
)
730 tmp
|= BMI_EXT_BUF_POOL_EN_COUNTER
;
732 if (bp
->bpool
[i
].is_backup
)
733 tmp
|= BMI_EXT_BUF_POOL_BACKUP
;
735 tmp
|= (u32
)bp
->bpool
[i
].size
;
738 iowrite32be(tmp
, &bp_reg
[i
]);
741 /* Clear unused pools */
742 for (i
= bp
->count
; i
< max_bp_num
; i
++)
743 iowrite32be(0, &bp_reg
[i
]);
745 /* Pools depletion */
747 for (i
= 0; i
< FMAN_PORT_MAX_EXT_POOLS_NUM
; i
++) {
748 if (bp
->bpool
[i
].grp_bp_depleted
) {
749 grp_depl_used
= true;
750 tmp
|= 0x80000000 >> i
;
753 if (bp
->bpool
[i
].single_bp_depleted
)
758 tmp
|= ((u32
)bp
->grp_bp_depleted_num
- 1) <<
759 BMI_POOL_DEP_NUM_OF_POOLS_SHIFT
;
761 iowrite32be(tmp
, bp_depl_reg
);
765 static bool is_init_done(struct fman_port_cfg
*cfg
)
767 /* Checks if FMan port driver parameters were initialized */
774 static int verify_size_of_fifo(struct fman_port
*port
)
776 u32 min_fifo_size_required
= 0, opt_fifo_size_for_b2b
= 0;
779 if (port
->port_type
== FMAN_PORT_TYPE_TX
) {
780 min_fifo_size_required
= (u32
)
781 (roundup(port
->max_frame_length
,
782 FMAN_BMI_FIFO_UNITS
) + (3 * FMAN_BMI_FIFO_UNITS
));
784 min_fifo_size_required
+=
785 port
->cfg
->tx_fifo_deq_pipeline_depth
*
788 opt_fifo_size_for_b2b
= min_fifo_size_required
;
790 /* Add some margin for back-to-back capability to improve
791 * performance, allows the hardware to pipeline new frame dma
792 * while the previous frame not yet transmitted.
794 if (port
->port_speed
== 10000)
795 opt_fifo_size_for_b2b
+= 3 * FMAN_BMI_FIFO_UNITS
;
797 opt_fifo_size_for_b2b
+= 2 * FMAN_BMI_FIFO_UNITS
;
801 else if (port
->port_type
== FMAN_PORT_TYPE_RX
) {
802 if (port
->rev_info
.major
>= 6)
803 min_fifo_size_required
= (u32
)
804 (roundup(port
->max_frame_length
,
805 FMAN_BMI_FIFO_UNITS
) +
806 (5 * FMAN_BMI_FIFO_UNITS
));
807 /* 4 according to spec + 1 for FOF>0 */
809 min_fifo_size_required
= (u32
)
810 (roundup(min(port
->max_frame_length
,
811 port
->rx_pools_params
.largest_buf_size
),
812 FMAN_BMI_FIFO_UNITS
) +
813 (7 * FMAN_BMI_FIFO_UNITS
));
815 opt_fifo_size_for_b2b
= min_fifo_size_required
;
817 /* Add some margin for back-to-back capability to improve
818 * performance,allows the hardware to pipeline new frame dma
819 * while the previous frame not yet transmitted.
821 if (port
->port_speed
== 10000)
822 opt_fifo_size_for_b2b
+= 8 * FMAN_BMI_FIFO_UNITS
;
824 opt_fifo_size_for_b2b
+= 3 * FMAN_BMI_FIFO_UNITS
;
827 WARN_ON(min_fifo_size_required
<= 0);
828 WARN_ON(opt_fifo_size_for_b2b
< min_fifo_size_required
);
830 /* Verify the size */
831 if (port
->fifo_bufs
.num
< min_fifo_size_required
)
832 dev_dbg(port
->dev
, "%s: FIFO size should be enlarged to %d bytes\n",
833 __func__
, min_fifo_size_required
);
834 else if (port
->fifo_bufs
.num
< opt_fifo_size_for_b2b
)
835 dev_dbg(port
->dev
, "%s: For b2b processing,FIFO may be enlarged to %d bytes\n",
836 __func__
, opt_fifo_size_for_b2b
);
841 static int set_ext_buffer_pools(struct fman_port
*port
)
843 struct fman_ext_pools
*ext_buf_pools
= &port
->cfg
->ext_buf_pools
;
844 struct fman_buf_pool_depletion
*buf_pool_depletion
=
845 &port
->cfg
->buf_pool_depletion
;
846 u8 ordered_array
[FMAN_PORT_MAX_EXT_POOLS_NUM
];
847 u16 sizes_array
[BM_MAX_NUM_OF_POOLS
];
848 int i
= 0, j
= 0, err
;
849 struct fman_port_bpools bpools
;
851 memset(&ordered_array
, 0, sizeof(u8
) * FMAN_PORT_MAX_EXT_POOLS_NUM
);
852 memset(&sizes_array
, 0, sizeof(u16
) * BM_MAX_NUM_OF_POOLS
);
853 memcpy(&port
->ext_buf_pools
, ext_buf_pools
,
854 sizeof(struct fman_ext_pools
));
856 fman_sp_set_buf_pools_in_asc_order_of_buf_sizes(ext_buf_pools
,
860 memset(&bpools
, 0, sizeof(struct fman_port_bpools
));
861 bpools
.count
= ext_buf_pools
->num_of_pools_used
;
862 bpools
.counters_enable
= true;
863 for (i
= 0; i
< ext_buf_pools
->num_of_pools_used
; i
++) {
864 bpools
.bpool
[i
].bpid
= ordered_array
[i
];
865 bpools
.bpool
[i
].size
= sizes_array
[ordered_array
[i
]];
868 /* save pools parameters for later use */
869 port
->rx_pools_params
.num_of_pools
= ext_buf_pools
->num_of_pools_used
;
870 port
->rx_pools_params
.largest_buf_size
=
871 sizes_array
[ordered_array
[ext_buf_pools
->num_of_pools_used
- 1]];
872 port
->rx_pools_params
.second_largest_buf_size
=
873 sizes_array
[ordered_array
[ext_buf_pools
->num_of_pools_used
- 2]];
875 /* FMBM_RMPD reg. - pool depletion */
876 if (buf_pool_depletion
->pools_grp_mode_enable
) {
877 bpools
.grp_bp_depleted_num
= buf_pool_depletion
->num_of_pools
;
878 for (i
= 0; i
< port
->bm_max_num_of_pools
; i
++) {
879 if (buf_pool_depletion
->pools_to_consider
[i
]) {
880 for (j
= 0; j
< ext_buf_pools
->
881 num_of_pools_used
; j
++) {
882 if (i
== ordered_array
[j
]) {
884 grp_bp_depleted
= true;
892 if (buf_pool_depletion
->single_pool_mode_enable
) {
893 for (i
= 0; i
< port
->bm_max_num_of_pools
; i
++) {
894 if (buf_pool_depletion
->
895 pools_to_consider_for_single_mode
[i
]) {
896 for (j
= 0; j
< ext_buf_pools
->
897 num_of_pools_used
; j
++) {
898 if (i
== ordered_array
[j
]) {
900 single_bp_depleted
= true;
908 err
= set_bpools(port
, &bpools
);
910 dev_err(port
->dev
, "%s: set_bpools() failed\n", __func__
);
917 static int init_low_level_driver(struct fman_port
*port
)
919 struct fman_port_cfg
*cfg
= port
->cfg
;
922 switch (port
->port_type
) {
923 case FMAN_PORT_TYPE_RX
:
924 cfg
->err_mask
= (RX_ERRS_TO_ENQ
& ~cfg
->discard_mask
);
930 tmp_val
= (u32
)((port
->internal_buf_offset
% OFFSET_UNITS
) ?
931 (port
->internal_buf_offset
/ OFFSET_UNITS
+ 1) :
932 (port
->internal_buf_offset
/ OFFSET_UNITS
));
933 port
->internal_buf_offset
= (u8
)(tmp_val
* OFFSET_UNITS
);
934 port
->cfg
->int_buf_start_margin
= port
->internal_buf_offset
;
936 if (init(port
) != 0) {
937 dev_err(port
->dev
, "%s: fman port initialization failed\n",
942 /* The code bellow is a trick so the FM will not release the buffer
943 * to BM nor will try to enqueue the frame to QM
945 if (port
->port_type
== FMAN_PORT_TYPE_TX
) {
946 if (!cfg
->dflt_fqid
&& cfg
->dont_release_buf
) {
947 /* override fmbm_tcfqid 0 with a false non-0 value.
948 * This will force FM to act according to tfene.
949 * Otherwise, if fmbm_tcfqid is 0 the FM will release
950 * buffers to BM regardless of fmbm_tfene
952 iowrite32be(0xFFFFFF, &port
->bmi_regs
->tx
.fmbm_tcfqid
);
953 iowrite32be(NIA_ENG_BMI
| NIA_BMI_AC_TX_RELEASE
,
954 &port
->bmi_regs
->tx
.fmbm_tfene
);
961 static int fill_soc_specific_params(struct fman_port
*port
)
963 u32 bmi_max_fifo_size
;
965 bmi_max_fifo_size
= fman_get_bmi_max_fifo_size(port
->fm
);
966 port
->max_port_fifo_size
= MAX_PORT_FIFO_SIZE(bmi_max_fifo_size
);
967 port
->bm_max_num_of_pools
= 64;
970 * P2041/P3041/P5020/P5040 - Major 3
973 switch (port
->rev_info
.major
) {
976 port
->max_num_of_ext_pools
= 4;
977 port
->max_num_of_sub_portals
= 12;
981 port
->max_num_of_ext_pools
= 8;
982 port
->max_num_of_sub_portals
= 16;
986 dev_err(port
->dev
, "%s: Unsupported FMan version\n", __func__
);
993 static int get_dflt_fifo_deq_pipeline_depth(u8 major
, enum fman_port_type type
,
997 case FMAN_PORT_TYPE_RX
:
998 case FMAN_PORT_TYPE_TX
:
1015 static int get_dflt_num_of_tasks(u8 major
, enum fman_port_type type
,
1019 case FMAN_PORT_TYPE_RX
:
1020 case FMAN_PORT_TYPE_TX
:
1037 static int get_dflt_extra_num_of_tasks(u8 major
, enum fman_port_type type
,
1041 case FMAN_PORT_TYPE_RX
:
1051 case FMAN_PORT_TYPE_TX
:
1057 static int get_dflt_num_of_open_dmas(u8 major
, enum fman_port_type type
,
1064 case FMAN_PORT_TYPE_TX
:
1070 case FMAN_PORT_TYPE_RX
:
1081 case FMAN_PORT_TYPE_TX
:
1082 case FMAN_PORT_TYPE_RX
:
1096 static int get_dflt_extra_num_of_open_dmas(u8 major
, enum fman_port_type type
,
1105 case FMAN_PORT_TYPE_RX
:
1106 case FMAN_PORT_TYPE_TX
:
1116 static int get_dflt_num_of_fifo_bufs(u8 major
, enum fman_port_type type
,
1123 case FMAN_PORT_TYPE_TX
:
1129 case FMAN_PORT_TYPE_RX
:
1140 case FMAN_PORT_TYPE_TX
:
1146 case FMAN_PORT_TYPE_RX
:
1160 static void set_dflt_cfg(struct fman_port
*port
,
1161 struct fman_port_params
*port_params
)
1163 struct fman_port_cfg
*cfg
= port
->cfg
;
1165 cfg
->dma_swap_data
= FMAN_PORT_DMA_NO_SWAP
;
1166 cfg
->color
= FMAN_PORT_COLOR_GREEN
;
1167 cfg
->rx_cut_end_bytes
= DFLT_PORT_CUT_BYTES_FROM_END
;
1168 cfg
->rx_pri_elevation
= BMI_PRIORITY_ELEVATION_LEVEL
;
1169 cfg
->rx_fifo_thr
= BMI_FIFO_THRESHOLD
;
1170 cfg
->tx_fifo_low_comf_level
= (5 * 1024);
1171 cfg
->deq_type
= FMAN_PORT_DEQ_BY_PRI
;
1172 cfg
->deq_prefetch_option
= FMAN_PORT_DEQ_FULL_PREFETCH
;
1173 cfg
->tx_fifo_deq_pipeline_depth
=
1174 BMI_DEQUEUE_PIPELINE_DEPTH(port
->port_type
, port
->port_speed
);
1175 cfg
->deq_byte_cnt
= QMI_BYTE_COUNT_LEVEL_CONTROL(port
->port_type
);
1177 cfg
->rx_pri_elevation
=
1178 DFLT_PORT_RX_FIFO_PRI_ELEVATION_LEV(port
->max_port_fifo_size
);
1179 port
->cfg
->rx_fifo_thr
=
1180 DFLT_PORT_RX_FIFO_THRESHOLD(port
->rev_info
.major
,
1181 port
->max_port_fifo_size
);
1183 if ((port
->rev_info
.major
== 6) &&
1184 ((port
->rev_info
.minor
== 0) || (port
->rev_info
.minor
== 3)))
1185 cfg
->errata_A006320
= true;
1187 /* Excessive Threshold register - exists for pre-FMv3 chips only */
1188 if (port
->rev_info
.major
< 6)
1189 cfg
->excessive_threshold_register
= true;
1191 cfg
->fmbm_tfne_has_features
= true;
1193 cfg
->buffer_prefix_content
.data_align
=
1194 DFLT_PORT_BUFFER_PREFIX_CONTEXT_DATA_ALIGN
;
1197 static void set_rx_dflt_cfg(struct fman_port
*port
,
1198 struct fman_port_params
*port_params
)
1200 port
->cfg
->discard_mask
= DFLT_PORT_ERRORS_TO_DISCARD
;
1202 memcpy(&port
->cfg
->ext_buf_pools
,
1203 &port_params
->specific_params
.rx_params
.ext_buf_pools
,
1204 sizeof(struct fman_ext_pools
));
1205 port
->cfg
->err_fqid
=
1206 port_params
->specific_params
.rx_params
.err_fqid
;
1207 port
->cfg
->dflt_fqid
=
1208 port_params
->specific_params
.rx_params
.dflt_fqid
;
1211 static void set_tx_dflt_cfg(struct fman_port
*port
,
1212 struct fman_port_params
*port_params
,
1213 struct fman_port_dts_params
*dts_params
)
1215 port
->cfg
->tx_fifo_deq_pipeline_depth
=
1216 get_dflt_fifo_deq_pipeline_depth(port
->rev_info
.major
,
1219 port
->cfg
->err_fqid
=
1220 port_params
->specific_params
.non_rx_params
.err_fqid
;
1222 (u8
)(dts_params
->qman_channel_id
& QMI_DEQ_CFG_SUBPORTAL_MASK
);
1223 port
->cfg
->dflt_fqid
=
1224 port_params
->specific_params
.non_rx_params
.dflt_fqid
;
1225 port
->cfg
->deq_high_priority
= true;
1230 * @port: Pointer to the port structure
1231 * @params: Pointer to data structure of parameters
1233 * Creates a descriptor for the FM PORT module.
1234 * The routine returns a pointer to the FM PORT object.
1235 * This descriptor must be passed as first parameter to all other FM PORT
1237 * No actual initialization or configuration of FM hardware is done by this
1240 * Return: 0 on success; Error code otherwise.
1242 int fman_port_config(struct fman_port
*port
, struct fman_port_params
*params
)
1244 void __iomem
*base_addr
= port
->dts_params
.base_addr
;
1247 /* Allocate the FM driver's parameters structure */
1248 port
->cfg
= kzalloc(sizeof(*port
->cfg
), GFP_KERNEL
);
1252 /* Initialize FM port parameters which will be kept by the driver */
1253 port
->port_type
= port
->dts_params
.type
;
1254 port
->port_speed
= port
->dts_params
.speed
;
1255 port
->port_id
= port
->dts_params
.id
;
1256 port
->fm
= port
->dts_params
.fman
;
1257 port
->ext_pools_num
= (u8
)8;
1259 /* get FM revision */
1260 fman_get_revision(port
->fm
, &port
->rev_info
);
1262 err
= fill_soc_specific_params(port
);
1266 switch (port
->port_type
) {
1267 case FMAN_PORT_TYPE_RX
:
1268 set_rx_dflt_cfg(port
, params
);
1269 case FMAN_PORT_TYPE_TX
:
1270 set_tx_dflt_cfg(port
, params
, &port
->dts_params
);
1272 set_dflt_cfg(port
, params
);
1275 /* Continue with other parameters */
1276 /* set memory map pointers */
1277 port
->bmi_regs
= base_addr
+ BMI_PORT_REGS_OFFSET
;
1278 port
->qmi_regs
= base_addr
+ QMI_PORT_REGS_OFFSET
;
1280 port
->max_frame_length
= DFLT_PORT_MAX_FRAME_LENGTH
;
1281 /* resource distribution. */
1283 port
->fifo_bufs
.num
=
1284 get_dflt_num_of_fifo_bufs(port
->rev_info
.major
, port
->port_type
,
1285 port
->port_speed
) * FMAN_BMI_FIFO_UNITS
;
1286 port
->fifo_bufs
.extra
=
1287 DFLT_PORT_EXTRA_NUM_OF_FIFO_BUFS
* FMAN_BMI_FIFO_UNITS
;
1289 port
->open_dmas
.num
=
1290 get_dflt_num_of_open_dmas(port
->rev_info
.major
,
1291 port
->port_type
, port
->port_speed
);
1292 port
->open_dmas
.extra
=
1293 get_dflt_extra_num_of_open_dmas(port
->rev_info
.major
,
1294 port
->port_type
, port
->port_speed
);
1296 get_dflt_num_of_tasks(port
->rev_info
.major
,
1297 port
->port_type
, port
->port_speed
);
1299 get_dflt_extra_num_of_tasks(port
->rev_info
.major
,
1300 port
->port_type
, port
->port_speed
);
1302 /* FM_HEAVY_TRAFFIC_SEQUENCER_HANG_ERRATA_FMAN_A006981 errata
1305 if ((port
->rev_info
.major
== 6) && (port
->rev_info
.minor
== 0) &&
1306 (((port
->port_type
== FMAN_PORT_TYPE_TX
) &&
1307 (port
->port_speed
== 1000)))) {
1308 port
->open_dmas
.num
= 16;
1309 port
->open_dmas
.extra
= 0;
1312 if (port
->rev_info
.major
>= 6 &&
1313 port
->port_type
== FMAN_PORT_TYPE_TX
&&
1314 port
->port_speed
== 1000) {
1315 /* FM_WRONG_RESET_VALUES_ERRATA_FMAN_A005127 Errata
1318 if (port
->rev_info
.major
>= 6) {
1322 iowrite32be(reg
, &port
->bmi_regs
->tx
.fmbm_tfp
);
1334 EXPORT_SYMBOL(fman_port_config
);
1338 * port: A pointer to a FM Port module.
1339 * Initializes the FM PORT module by defining the software structure and
1340 * configuring the hardware registers.
1342 * Return: 0 on success; Error code otherwise.
1344 int fman_port_init(struct fman_port
*port
)
1346 struct fman_port_cfg
*cfg
;
1348 struct fman_port_init_params params
;
1350 if (is_init_done(port
->cfg
))
1353 err
= fman_sp_build_buffer_struct(&port
->cfg
->int_context
,
1354 &port
->cfg
->buffer_prefix_content
,
1355 &port
->cfg
->buf_margins
,
1356 &port
->buffer_offsets
,
1357 &port
->internal_buf_offset
);
1363 if (port
->port_type
== FMAN_PORT_TYPE_RX
) {
1364 /* Call the external Buffer routine which also checks fifo
1365 * size and updates it if necessary
1367 /* define external buffer pools and pool depletion */
1368 err
= set_ext_buffer_pools(port
);
1371 /* check if the largest external buffer pool is large enough */
1372 if (cfg
->buf_margins
.start_margins
+ MIN_EXT_BUF_SIZE
+
1373 cfg
->buf_margins
.end_margins
>
1374 port
->rx_pools_params
.largest_buf_size
) {
1375 dev_err(port
->dev
, "%s: buf_margins.start_margins (%d) + minimum buf size (64) + buf_margins.end_margins (%d) is larger than maximum external buffer size (%d)\n",
1376 __func__
, cfg
->buf_margins
.start_margins
,
1377 cfg
->buf_margins
.end_margins
,
1378 port
->rx_pools_params
.largest_buf_size
);
1383 /* Call FM module routine for communicating parameters */
1384 memset(¶ms
, 0, sizeof(params
));
1385 params
.port_id
= port
->port_id
;
1386 params
.port_type
= port
->port_type
;
1387 params
.port_speed
= port
->port_speed
;
1388 params
.num_of_tasks
= (u8
)port
->tasks
.num
;
1389 params
.num_of_extra_tasks
= (u8
)port
->tasks
.extra
;
1390 params
.num_of_open_dmas
= (u8
)port
->open_dmas
.num
;
1391 params
.num_of_extra_open_dmas
= (u8
)port
->open_dmas
.extra
;
1393 if (port
->fifo_bufs
.num
) {
1394 err
= verify_size_of_fifo(port
);
1398 params
.size_of_fifo
= port
->fifo_bufs
.num
;
1399 params
.extra_size_of_fifo
= port
->fifo_bufs
.extra
;
1400 params
.deq_pipeline_depth
= port
->cfg
->tx_fifo_deq_pipeline_depth
;
1401 params
.max_frame_length
= port
->max_frame_length
;
1403 err
= fman_set_port_params(port
->fm
, ¶ms
);
1407 err
= init_low_level_driver(port
);
1416 EXPORT_SYMBOL(fman_port_init
);
1419 * fman_port_cfg_buf_prefix_content
1420 * @port A pointer to a FM Port module.
1421 * @buffer_prefix_content A structure of parameters describing
1422 * the structure of the buffer.
1424 * Start margin - offset of data from
1425 * start of external buffer.
1426 * Defines the structure, size and content of the application buffer.
1427 * The prefix, in Tx ports, if 'pass_prs_result', the application should set
1428 * a value to their offsets in the prefix of the FM will save the first
1429 * 'priv_data_size', than, depending on 'pass_prs_result' and
1430 * 'pass_time_stamp', copy parse result and timeStamp, and the packet itself
1431 * (in this order), to the application buffer, and to offset.
1432 * Calling this routine changes the buffer margins definitions in the internal
1433 * driver data base from its default configuration:
1434 * Data size: [DEFAULT_PORT_BUFFER_PREFIX_CONTENT_PRIV_DATA_SIZE]
1435 * Pass Parser result: [DEFAULT_PORT_BUFFER_PREFIX_CONTENT_PASS_PRS_RESULT].
1436 * Pass timestamp: [DEFAULT_PORT_BUFFER_PREFIX_CONTENT_PASS_TIME_STAMP].
1437 * May be used for all ports
1439 * Allowed only following fman_port_config() and before fman_port_init().
1441 * Return: 0 on success; Error code otherwise.
1443 int fman_port_cfg_buf_prefix_content(struct fman_port
*port
,
1444 struct fman_buffer_prefix_content
*
1445 buffer_prefix_content
)
1447 if (is_init_done(port
->cfg
))
1450 memcpy(&port
->cfg
->buffer_prefix_content
,
1451 buffer_prefix_content
,
1452 sizeof(struct fman_buffer_prefix_content
));
1453 /* if data_align was not initialized by user,
1454 * we return to driver's default
1456 if (!port
->cfg
->buffer_prefix_content
.data_align
)
1457 port
->cfg
->buffer_prefix_content
.data_align
=
1458 DFLT_PORT_BUFFER_PREFIX_CONTEXT_DATA_ALIGN
;
1462 EXPORT_SYMBOL(fman_port_cfg_buf_prefix_content
);
1466 * port: A pointer to a FM Port module.
1468 * Gracefully disable an FM port. The port will not start new tasks after all
1469 * tasks associated with the port are terminated.
1471 * This is a blocking routine, it returns after port is gracefully stopped,
1472 * i.e. the port will not except new frames, but it will finish all frames
1473 * or tasks which were already began.
1474 * Allowed only following fman_port_init().
1476 * Return: 0 on success; Error code otherwise.
1478 int fman_port_disable(struct fman_port
*port
)
1480 u32 __iomem
*bmi_cfg_reg
, *bmi_status_reg
, tmp
;
1481 bool rx_port
, failure
= false;
1484 if (!is_init_done(port
->cfg
))
1487 switch (port
->port_type
) {
1488 case FMAN_PORT_TYPE_RX
:
1489 bmi_cfg_reg
= &port
->bmi_regs
->rx
.fmbm_rcfg
;
1490 bmi_status_reg
= &port
->bmi_regs
->rx
.fmbm_rst
;
1493 case FMAN_PORT_TYPE_TX
:
1494 bmi_cfg_reg
= &port
->bmi_regs
->tx
.fmbm_tcfg
;
1495 bmi_status_reg
= &port
->bmi_regs
->tx
.fmbm_tst
;
1504 tmp
= ioread32be(&port
->qmi_regs
->fmqm_pnc
) & ~QMI_PORT_CFG_EN
;
1505 iowrite32be(tmp
, &port
->qmi_regs
->fmqm_pnc
);
1507 /* Wait for QMI to finish FD handling */
1511 tmp
= ioread32be(&port
->qmi_regs
->fmqm_pns
);
1512 } while ((tmp
& QMI_PORT_STATUS_DEQ_FD_BSY
) && --count
);
1521 tmp
= ioread32be(bmi_cfg_reg
) & ~BMI_PORT_CFG_EN
;
1522 iowrite32be(tmp
, bmi_cfg_reg
);
1524 /* Wait for graceful stop end */
1528 tmp
= ioread32be(bmi_status_reg
);
1529 } while ((tmp
& BMI_PORT_STATUS_BSY
) && --count
);
1537 dev_dbg(port
->dev
, "%s: FMan Port[%d]: BMI or QMI is Busy. Port forced down\n",
1538 __func__
, port
->port_id
);
1542 EXPORT_SYMBOL(fman_port_disable
);
1546 * port: A pointer to a FM Port module.
1548 * A runtime routine provided to allow disable/enable of port.
1550 * Allowed only following fman_port_init().
1552 * Return: 0 on success; Error code otherwise.
1554 int fman_port_enable(struct fman_port
*port
)
1556 u32 __iomem
*bmi_cfg_reg
, tmp
;
1559 if (!is_init_done(port
->cfg
))
1562 switch (port
->port_type
) {
1563 case FMAN_PORT_TYPE_RX
:
1564 bmi_cfg_reg
= &port
->bmi_regs
->rx
.fmbm_rcfg
;
1567 case FMAN_PORT_TYPE_TX
:
1568 bmi_cfg_reg
= &port
->bmi_regs
->tx
.fmbm_tcfg
;
1577 tmp
= ioread32be(&port
->qmi_regs
->fmqm_pnc
) | QMI_PORT_CFG_EN
;
1578 iowrite32be(tmp
, &port
->qmi_regs
->fmqm_pnc
);
1582 tmp
= ioread32be(bmi_cfg_reg
) | BMI_PORT_CFG_EN
;
1583 iowrite32be(tmp
, bmi_cfg_reg
);
1587 EXPORT_SYMBOL(fman_port_enable
);
1591 * dev: FMan Port OF device pointer
1593 * Bind to a specific FMan Port.
1595 * Allowed only after the port was created.
1597 * Return: A pointer to the FMan port device.
1599 struct fman_port
*fman_port_bind(struct device
*dev
)
1601 return (struct fman_port
*)(dev_get_drvdata(get_device(dev
)));
1603 EXPORT_SYMBOL(fman_port_bind
);
1606 * fman_port_get_qman_channel_id
1607 * port: Pointer to the FMan port devuce
1609 * Get the QMan channel ID for the specific port
1611 * Return: QMan channel ID
1613 u32
fman_port_get_qman_channel_id(struct fman_port
*port
)
1615 return port
->dts_params
.qman_channel_id
;
1617 EXPORT_SYMBOL(fman_port_get_qman_channel_id
);
1619 static int fman_port_probe(struct platform_device
*of_dev
)
1621 struct fman_port
*port
;
1623 struct device_node
*fm_node
, *port_node
;
1624 struct resource res
;
1625 struct resource
*dev_res
;
1626 const u32
*u32_prop
;
1628 enum fman_port_type port_type
;
1632 port
= kzalloc(sizeof(*port
), GFP_KERNEL
);
1636 port
->dev
= &of_dev
->dev
;
1638 port_node
= of_node_get(of_dev
->dev
.of_node
);
1640 /* Get the FM node */
1641 fm_node
= of_get_parent(port_node
);
1643 dev_err(port
->dev
, "%s: of_get_parent() failed\n", __func__
);
1648 fman
= dev_get_drvdata(&of_find_device_by_node(fm_node
)->dev
);
1649 of_node_put(fm_node
);
1655 u32_prop
= (const u32
*)of_get_property(port_node
, "cell-index", &lenp
);
1657 dev_err(port
->dev
, "%s: of_get_property(%s, cell-index) failed\n",
1658 __func__
, port_node
->full_name
);
1662 if (WARN_ON(lenp
!= sizeof(u32
))) {
1666 port_id
= (u8
)fdt32_to_cpu(u32_prop
[0]);
1668 port
->dts_params
.id
= port_id
;
1670 if (of_device_is_compatible(port_node
, "fsl,fman-v3-port-tx")) {
1671 port_type
= FMAN_PORT_TYPE_TX
;
1673 u32_prop
= (const u32
*)of_get_property(port_node
,
1674 "fsl,fman-10g-port",
1679 } else if (of_device_is_compatible(port_node
, "fsl,fman-v2-port-tx")) {
1680 if (port_id
>= TX_10G_PORT_BASE
)
1684 port_type
= FMAN_PORT_TYPE_TX
;
1686 } else if (of_device_is_compatible(port_node
, "fsl,fman-v3-port-rx")) {
1687 port_type
= FMAN_PORT_TYPE_RX
;
1689 u32_prop
= (const u32
*)of_get_property(port_node
,
1690 "fsl,fman-10g-port", &lenp
);
1694 } else if (of_device_is_compatible(port_node
, "fsl,fman-v2-port-rx")) {
1695 if (port_id
>= RX_10G_PORT_BASE
)
1699 port_type
= FMAN_PORT_TYPE_RX
;
1702 dev_err(port
->dev
, "%s: Illegal port type\n", __func__
);
1707 port
->dts_params
.type
= port_type
;
1708 port
->dts_params
.speed
= port_speed
;
1710 if (port_type
== FMAN_PORT_TYPE_TX
) {
1711 u32 qman_channel_id
;
1713 qman_channel_id
= fman_get_qman_channel_id(fman
, port_id
);
1714 if (qman_channel_id
== 0) {
1715 dev_err(port
->dev
, "%s: incorrect qman-channel-id\n",
1720 port
->dts_params
.qman_channel_id
= qman_channel_id
;
1723 err
= of_address_to_resource(port_node
, 0, &res
);
1725 dev_err(port
->dev
, "%s: of_address_to_resource() failed\n",
1731 port
->dts_params
.fman
= fman
;
1733 of_node_put(port_node
);
1735 dev_res
= __devm_request_region(port
->dev
, &res
, res
.start
,
1736 resource_size(&res
), "fman-port");
1738 dev_err(port
->dev
, "%s: __devm_request_region() failed\n",
1744 port
->dts_params
.base_addr
= devm_ioremap(port
->dev
, res
.start
,
1745 resource_size(&res
));
1746 if (port
->dts_params
.base_addr
== 0)
1747 dev_err(port
->dev
, "%s: devm_ioremap() failed\n", __func__
);
1749 dev_set_drvdata(&of_dev
->dev
, port
);
1754 of_node_put(port_node
);
1760 static const struct of_device_id fman_port_match
[] = {
1761 {.compatible
= "fsl,fman-v3-port-rx"},
1762 {.compatible
= "fsl,fman-v2-port-rx"},
1763 {.compatible
= "fsl,fman-v3-port-tx"},
1764 {.compatible
= "fsl,fman-v2-port-tx"},
1768 MODULE_DEVICE_TABLE(of
, fman_port_match
);
1770 static struct platform_driver fman_port_driver
= {
1772 .name
= "fsl-fman-port",
1773 .of_match_table
= fman_port_match
,
1775 .probe
= fman_port_probe
,
1778 builtin_platform_driver(fman_port_driver
);