1 /*******************************************************************************
2 Copyright (C) 2015 Annapurna Labs Ltd.
4 This file may be licensed under the terms of the Annapurna Labs Commercial
7 Alternatively, this file can be distributed under the terms of the GNU General
8 Public License V2 as published by the Free Software Foundation and can be
9 found at http://www.gnu.org/licenses/gpl-2.0.html
11 Alternatively, redistribution and use in source and binary forms, with or
12 without modification, are permitted provided that the following conditions are
15 * Redistributions of source code must retain the above copyright notice,
16 this list of conditions and the following disclaimer.
18 * Redistributions in binary form must reproduce the above copyright
19 notice, this list of conditions and the following disclaimer in
20 the documentation and/or other materials provided with the
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
27 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *******************************************************************************/
37 * @defgroup group_udma_config UDMA Config
38 * @ingroup group_udma_api
41 * @file al_hal_udma_config.h
43 * @brief C Header file for the Universal DMA HAL driver for configuration APIs
47 #ifndef __AL_HAL_UDMA_CONFIG_H__
48 #define __AL_HAL_UDMA_CONFIG_H__
50 #include <al_hal_udma.h>
59 /** Scheduling mode */
60 enum al_udma_sch_mode {
62 SRR, /* Simple Sound Rubin */
63 DWRR /* Deficit Weighted Round Rubin */
66 /** AXI configuration */
67 struct al_udma_axi_conf {
68 uint32_t axi_timeout; /* Timeout for AXI transactions */
69 uint8_t arb_promotion; /* arbitration promotion */
70 al_bool swap_8_bytes; /* enable 8 bytes swap instead of 4 bytes */
71 al_bool swap_s2m_data;
72 al_bool swap_s2m_desc;
73 al_bool swap_m2s_data;
74 al_bool swap_m2s_desc;
77 /** UDMA AXI M2S configuration */
78 struct al_udma_axi_submaster {
79 uint8_t id; /* AXI ID */
89 /** UDMA AXI M2S configuration */
90 struct al_udma_m2s_axi_conf {
91 struct al_udma_axi_submaster comp_write;
92 struct al_udma_axi_submaster data_read;
93 struct al_udma_axi_submaster desc_read;
94 al_bool break_on_max_boundary; /* Data read break on max boundary */
95 uint8_t min_axi_beats; /* Minimum burst for writing completion desc. */
96 uint8_t ostand_max_data_read;
97 uint8_t ostand_max_desc_read;
98 uint8_t ostand_max_comp_req;
99 uint8_t ostand_max_comp_write;
102 /** UDMA AXI S2M configuration */
103 struct al_udma_s2m_axi_conf {
104 struct al_udma_axi_submaster data_write;
105 struct al_udma_axi_submaster desc_read;
106 struct al_udma_axi_submaster comp_write;
107 al_bool break_on_max_boundary; /* Data read break on max boundary */
108 uint8_t min_axi_beats; /* Minimum burst for writing completion desc. */
109 uint8_t ostand_max_data_req;
110 uint8_t ostand_max_data_write;
111 uint8_t ostand_max_comp_req;
112 uint8_t ostand_max_comp_write;
113 uint8_t ostand_max_desc_read;
114 uint8_t ack_fifo_depth; /* size of the stream application ack fifo */
117 /** M2S error logging */
118 struct al_udma_err_log {
119 uint32_t error_status;
123 /** M2S max packet size configuration */
124 struct al_udma_m2s_pkt_len_conf {
125 uint32_t max_pkt_size;
126 al_bool encode_64k_as_zero;
129 /** M2S Descriptor Prefetch configuration */
130 struct al_udma_m2s_desc_pref_conf {
131 uint8_t desc_fifo_depth;
132 enum al_udma_sch_mode sch_mode; /* Scheduling mode
133 * (either strict or RR) */
135 uint8_t max_desc_per_packet; /* max number of descriptors to
137 /* in one burst (5b) */
139 uint8_t min_burst_above_thr; /* min burst size when fifo above
142 uint8_t min_burst_below_thr; /* min burst size when fifo below
145 uint8_t max_pkt_limit; /* maximum number of packets in the data
146 * read FIFO, defined based on header
149 uint16_t data_fifo_depth; /* maximum number of data beats in the
151 * defined based on header FIFO size
155 /** S2M Descriptor Prefetch configuration */
156 struct al_udma_s2m_desc_pref_conf {
157 uint8_t desc_fifo_depth;
158 enum al_udma_sch_mode sch_mode; /* Scheduling mode *
159 * (either strict or RR)
162 al_bool q_promotion; /* enable promotion */
163 al_bool force_promotion; /* force promotion */
164 al_bool en_pref_prediction; /* enable prefetch prediction */
165 uint8_t promotion_th; /* Threshold for queue promotion */
168 uint8_t min_burst_above_thr; /* min burst size when fifo above
171 uint8_t min_burst_below_thr; /* min burst size when fifo below
174 uint8_t a_full_thr; /* almost full threshold */
177 /** S2M Data write configuration */
178 struct al_udma_s2m_data_write_conf {
179 uint16_t data_fifo_depth; /* maximum number of data beats in the
180 * data write FIFO, defined based on
183 uint8_t max_pkt_limit; /* maximum number of packets in the
184 * data write FIFO,defined based on
188 uint32_t desc_wait_timer; /* waiting time for the host to write
189 * new descriptor to the queue
190 * (for the current packet in process)
192 uint32_t flags; /* bitwise of flags of s2m
193 * data_cfg_2 register
197 /** S2M Completion configuration */
198 struct al_udma_s2m_completion_conf {
199 uint8_t desc_size; /* Size of completion descriptor
202 al_bool cnt_words; /* Completion fifo in use counter:
203 * AL_TRUE words, AL_FALS descriptors
205 al_bool q_promotion; /* Enable promotion of the current
206 * unack in progress */
207 /* in the completion write scheduler */
208 al_bool force_rr; /* force RR arbitration in the
211 // uint8_t ack_fifo_depth; /* size of the stream application ack fifo */
212 uint8_t q_free_min; /* minimum number of free completion
215 /* to qualify for promotion */
217 uint16_t comp_fifo_depth; /* Size of completion fifo in words */
218 uint16_t unack_fifo_depth; /* Size of unacked fifo in descs */
219 uint32_t timeout; /* Ack timout from stream interface */
222 /** M2S UDMA DWRR configuration */
223 struct al_udma_m2s_dwrr_conf {
228 uint32_t deficit_init_val;
231 /** M2S DMA Rate Limitation mode */
232 struct al_udma_m2s_rlimit_mode {
234 uint16_t short_cycle_sz;
235 uint32_t token_init_val;
238 /** M2S Stream/Q Rate Limitation */
239 struct al_udma_m2s_rlimit_cfg {
240 uint32_t max_burst_sz; /* maximum number of accumulated bytes in the
243 uint16_t long_cycle_sz; /* number of short cycles between token fill */
244 uint32_t long_cycle; /* number of bits to add in each long cycle */
245 uint32_t short_cycle; /* number of bits to add in each cycle */
246 uint32_t mask; /* mask the different types of rate limiters */
249 enum al_udma_m2s_rlimit_action {
250 AL_UDMA_STRM_RLIMIT_ENABLE,
251 AL_UDMA_STRM_RLIMIT_PAUSE,
252 AL_UDMA_STRM_RLIMIT_RESET
255 /** M2S UDMA Q scheduling configuration */
256 struct al_udma_m2s_q_dwrr_conf {
257 uint32_t max_deficit_cnt_sz; /*maximum number of accumulated bytes
258 * in the deficit counter
260 al_bool strict; /* bypass DWRR */
266 /** M2S UDMA / UDMA Q scheduling configuration */
267 struct al_udma_m2s_sc {
268 enum al_udma_sch_mode sch_mode; /* Scheduling Mode */
269 struct al_udma_m2s_dwrr_conf dwrr; /* DWRR configuration */
272 /** UDMA / UDMA Q rate limitation configuration */
273 struct al_udma_m2s_rlimit {
274 struct al_udma_m2s_rlimit_mode rlimit_mode;
275 /* rate limitation enablers */
277 struct al_udma_tkn_bkt_conf token_bkt; /* Token Bucket configuration */
281 /** UDMA Data read configuration */
282 struct al_udma_m2s_data_rd_conf {
283 uint8_t max_rd_d_beats; /* max burst size for reading data
284 * (in AXI beats-128b) (5b)
286 uint8_t max_rd_d_out_req; /* max number of outstanding data
289 uint16_t max_rd_d_out_beats; /* max num. of data read beats (10b) */
292 /** M2S UDMA completion and application timeouts */
293 struct al_udma_m2s_comp_timeouts {
294 enum al_udma_sch_mode sch_mode; /* Scheduling mode
295 * (either strict or RR)
297 al_bool enable_q_promotion;
298 uint8_t unack_fifo_depth; /* unacked desc fifo size */
299 uint8_t comp_fifo_depth; /* desc fifo size */
300 uint32_t coal_timeout; /* (24b) */
301 uint32_t app_timeout; /* (24b) */
304 /** S2M UDMA per queue completion configuration */
305 struct al_udma_s2m_q_comp_conf {
306 al_bool dis_comp_coal; /* disable completion coalescing */
307 al_bool en_comp_ring_update; /* enable writing completion descs */
308 uint32_t comp_timer; /* completion coalescing timer */
309 al_bool en_hdr_split; /* enable header split */
310 al_bool force_hdr_split; /* force header split */
311 uint16_t hdr_split_size; /* size used for the header split */
312 uint8_t q_qos; /* queue QoS */
315 /** UDMA per queue Target-ID control configuration */
316 struct al_udma_gen_tgtid_q_conf {
317 /* Enable usage of the Target-ID per queue according to 'tgtid' */
320 /* Enable usage of the Target-ID from the descriptor buffer address 63:48 */
323 /* Target-ID to be applied when 'queue_en' is asserted */
326 /* TGTADDR to be applied to msbs when 'desc_en' is asserted.
327 * Relevant for revisions >= AL_UDMA_REV_ID_REV2 */
331 /** UDMA Target-ID control configuration */
332 struct al_udma_gen_tgtid_conf {
333 /* TX queue configuration */
334 struct al_udma_gen_tgtid_q_conf tx_q_conf[DMA_MAX_Q];
336 /* RX queue configuration */
337 struct al_udma_gen_tgtid_q_conf rx_q_conf[DMA_MAX_Q];
340 /** UDMA Target-ID MSIX control configuration */
341 struct al_udma_gen_tgtid_msix_conf {
342 /* Enable write to all TGTID_n registers in the MSI-X Controller */
345 /* use TGTID_n [7:0] from MSI-X Controller for MSI-X message */
349 /* Report Error - to be used for abort */
350 void al_udma_err_report(struct al_udma *udma);
352 /* Statistics - TBD */
353 void al_udma_stats_get(struct al_udma *udma);
355 /* Misc configurations */
356 /* Configure AXI configuration */
357 int al_udma_axi_set(struct udma_gen_axi *axi_regs,
358 struct al_udma_axi_conf *axi);
360 /* Configure UDMA AXI M2S configuration */
361 int al_udma_m2s_axi_set(struct al_udma *udma,
362 struct al_udma_m2s_axi_conf *axi_m2s);
364 /* Configure UDMA AXI S2M configuration */
365 int al_udma_s2m_axi_set(struct al_udma *udma,
366 struct al_udma_s2m_axi_conf *axi_s2m);
368 /* Configure M2S packet len */
369 int al_udma_m2s_packet_size_cfg_set(struct al_udma *udma,
370 struct al_udma_m2s_pkt_len_conf *conf);
372 /* Configure M2S UDMA descriptor prefetch */
373 int al_udma_m2s_pref_set(struct al_udma *udma,
374 struct al_udma_m2s_desc_pref_conf *conf);
375 int al_udma_m2s_pref_get(struct al_udma *udma,
376 struct al_udma_m2s_desc_pref_conf *conf);
378 /* set m2s packet's max descriptors (including meta descriptors) */
379 #define AL_UDMA_M2S_MAX_ALLOWED_DESCS_PER_PACKET 31
380 int al_udma_m2s_max_descs_set(struct al_udma *udma, uint8_t max_descs);
382 /* set s2m packets' max descriptors */
383 #define AL_UDMA_S2M_MAX_ALLOWED_DESCS_PER_PACKET 31
384 int al_udma_s2m_max_descs_set(struct al_udma *udma, uint8_t max_descs);
387 /* Configure S2M UDMA descriptor prefetch */
388 int al_udma_s2m_pref_set(struct al_udma *udma,
389 struct al_udma_s2m_desc_pref_conf *conf);
390 int al_udma_m2s_pref_get(struct al_udma *udma,
391 struct al_udma_m2s_desc_pref_conf *conf);
393 /* Configure S2M UDMA data write */
394 int al_udma_s2m_data_write_set(struct al_udma *udma,
395 struct al_udma_s2m_data_write_conf *conf);
397 /* Configure the s2m full line write feature */
398 int al_udma_s2m_full_line_write_set(struct al_udma *umda, al_bool enable);
400 /* Configure S2M UDMA completion */
401 int al_udma_s2m_completion_set(struct al_udma *udma,
402 struct al_udma_s2m_completion_conf *conf);
404 /* Configure the M2S UDMA scheduling mode */
405 int al_udma_m2s_sc_set(struct al_udma *udma,
406 struct al_udma_m2s_dwrr_conf *sched);
408 /* Configure the M2S UDMA rate limitation */
409 int al_udma_m2s_rlimit_set(struct al_udma *udma,
410 struct al_udma_m2s_rlimit_mode *mode);
411 int al_udma_m2s_rlimit_reset(struct al_udma *udma);
413 /* Configure the M2S Stream rate limitation */
414 int al_udma_m2s_strm_rlimit_set(struct al_udma *udma,
415 struct al_udma_m2s_rlimit_cfg *conf);
416 int al_udma_m2s_strm_rlimit_act(struct al_udma *udma,
417 enum al_udma_m2s_rlimit_action act);
419 /* Configure the M2S UDMA Q rate limitation */
420 int al_udma_m2s_q_rlimit_set(struct al_udma_q *udma_q,
421 struct al_udma_m2s_rlimit_cfg *conf);
422 int al_udma_m2s_q_rlimit_act(struct al_udma_q *udma_q,
423 enum al_udma_m2s_rlimit_action act);
425 /* Configure the M2S UDMA Q scheduling mode */
426 int al_udma_m2s_q_sc_set(struct al_udma_q *udma_q,
427 struct al_udma_m2s_q_dwrr_conf *conf);
428 int al_udma_m2s_q_sc_pause(struct al_udma_q *udma_q, al_bool set);
429 int al_udma_m2s_q_sc_reset(struct al_udma_q *udma_q);
431 /* M2S UDMA completion and application timeouts */
432 int al_udma_m2s_comp_timeouts_set(struct al_udma *udma,
433 struct al_udma_m2s_comp_timeouts *conf);
434 int al_udma_m2s_comp_timeouts_get(struct al_udma *udma,
435 struct al_udma_m2s_comp_timeouts *conf);
437 /* UDMA get revision */
438 static INLINE unsigned int al_udma_get_revision(struct unit_regs __iomem *unit_regs)
440 return (al_reg_read32(&unit_regs->gen.dma_misc.revision)
441 & UDMA_GEN_DMA_MISC_REVISION_PROGRAMMING_ID_MASK) >>
442 UDMA_GEN_DMA_MISC_REVISION_PROGRAMMING_ID_SHIFT;
446 * S2M UDMA Configure the expected behavior of Rx/S2M UDMA when there are no Rx Descriptors.
449 * @param drop_packet when set to true, the UDMA will drop packet.
450 * @param gen_interrupt when set to true, the UDMA will generate
451 * no_desc_hint interrupt when a packet received and the UDMA
452 * doesn't find enough free descriptors for it.
453 * @param wait_for_desc_timeout timeout in SB cycles to wait for new
454 * descriptors before dropping the packets.
456 * - The hint interrupt is raised immediately without waiting
458 * - value 0 means wait for ever.
461 * - When get_interrupt is set, the API won't program the iofic to unmask this
462 * interrupt, in this case the callee should take care for doing that unmask
463 * using the al_udma_iofic_config() API.
465 * - The hardware's default configuration is: no drop packet, generate hint
467 * - This API must be called once and before enabling the UDMA
469 * @return 0 if no error found.
471 int al_udma_s2m_no_desc_cfg_set(struct al_udma *udma, al_bool drop_packet, al_bool gen_interrupt, uint32_t wait_for_desc_timeout);
474 * S2M UDMA configure a queue's completion update
477 * @param enable set to true to enable completion update
479 * completion update better be disabled for tx queues as those descriptors
480 * doesn't carry useful information, thus disabling it saves DMA accesses.
482 * @return 0 if no error found.
484 int al_udma_s2m_q_compl_updade_config(struct al_udma_q *udma_q, al_bool enable);
487 * S2M UDMA configure a queue's completion descriptors coalescing
490 * @param enable set to true to enable completion coalescing
491 * @param coal_timeout in South Bridge cycles.
493 * @return 0 if no error found.
495 int al_udma_s2m_q_compl_coal_config(struct al_udma_q *udma_q, al_bool enable, uint32_t coal_timeout);
498 * S2M UDMA configure completion descriptors write burst parameters
501 * @param burst_size completion descriptors write burst size in bytes.
503 * @return 0 if no error found.
504 */int al_udma_s2m_compl_desc_burst_config(struct al_udma *udma, uint16_t
508 * S2M UDMA configure a queue's completion header split
511 * @param enable set to true to enable completion header split
512 * @param force_hdr_split the header split length will be taken from the queue configuration
513 * @param hdr_len header split length.
515 * @return 0 if no error found.
517 int al_udma_s2m_q_compl_hdr_split_config(struct al_udma_q *udma_q,
519 al_bool force_hdr_split,
522 /* S2M UDMA per queue completion configuration */
523 int al_udma_s2m_q_comp_set(struct al_udma_q *udma_q,
524 struct al_udma_s2m_q_comp_conf *conf);
526 /** UDMA Target-ID control configuration per queue */
527 void al_udma_gen_tgtid_conf_queue_set(
528 struct unit_regs *unit_regs,
529 struct al_udma_gen_tgtid_conf *conf,
532 /** UDMA Target-ID control configuration */
533 void al_udma_gen_tgtid_conf_set(
534 struct unit_regs __iomem *unit_regs,
535 struct al_udma_gen_tgtid_conf *conf);
537 /** UDMA Target-ID MSIX control configuration */
538 void al_udma_gen_tgtid_msix_conf_set(
539 struct unit_regs __iomem *unit_regs,
540 struct al_udma_gen_tgtid_msix_conf *conf);
547 /** @} end of UDMA config group */
548 #endif /* __AL_HAL_UDMA_CONFIG_H__ */