1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright © 2023 Dmitry Salychev 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28 #ifndef _DPAA2_CHANNEL_H 29 #define _DPAA2_CHANNEL_H 30 31 #include <sys/types.h> 32 #include <sys/param.h> 33 #include <sys/systm.h> 34 #include <sys/kernel.h> 35 #include <sys/malloc.h> 36 #include <sys/queue.h> 37 #include <sys/taskqueue.h> 38 #include <sys/buf_ring.h> 39 #include <sys/lock.h> 40 #include <sys/mutex.h> 41 42 #include "dpaa2_types.h" 43 #include "dpaa2_io.h" 44 #include "dpaa2_ni.h" 45 46 #define DPAA2_TX_BUFRING_SZ (4096u) 47 48 #define RX_SEG_N (1u) 49 #define RX_SEG_SZ (((MJUM9BYTES - 1) / PAGE_SIZE + 1) * PAGE_SIZE) 50 #define RX_SEG_MAXSZ (((MJUM9BYTES - 1) / PAGE_SIZE + 1) * PAGE_SIZE) 51 CTASSERT(RX_SEG_SZ % PAGE_SIZE == 0); 52 CTASSERT(RX_SEG_MAXSZ % PAGE_SIZE == 0); 53 54 /** 55 * @brief QBMan channel to process ingress traffic. 56 * 57 * NOTE: Several WQs are organized into a single channel. 58 */ 59 struct dpaa2_channel { 60 device_t ni_dev; 61 device_t io_dev; 62 device_t con_dev; 63 uint16_t id; 64 uint16_t flowid; 65 66 uint64_t tx_frames; 67 uint64_t tx_dropped; 68 69 struct mtx dma_mtx; 70 bus_dma_tag_t rx_dmat; 71 bus_dma_tag_t tx_dmat; 72 bus_dma_tag_t sgt_dmat; 73 74 struct dpaa2_io_notif_ctx ctx; /* to configure CDANs */ 75 76 struct dpaa2_buf store; /* to keep VDQ responses */ 77 uint32_t store_sz; /* in frames */ 78 uint32_t store_idx; /* frame index */ 79 80 uint32_t recycled_n; 81 struct dpaa2_buf *recycled[DPAA2_SWP_BUFS_PER_CMD]; 82 83 uint32_t rxq_n; 84 struct dpaa2_ni_fq rx_queues[DPAA2_MAX_TCS]; 85 struct dpaa2_ni_fq txc_queue; 86 87 struct taskqueue *cleanup_tq; 88 struct task cleanup_task; 89 struct task bp_task; 90 91 struct mtx xmit_mtx; 92 struct buf_ring *xmit_br; 93 } __aligned(CACHE_LINE_SIZE); 94 95 int dpaa2_chan_setup(device_t, device_t, device_t, device_t, 96 struct dpaa2_channel **, uint32_t, task_fn_t); 97 int dpaa2_chan_setup_fq(device_t, struct dpaa2_channel *, 98 enum dpaa2_ni_queue_type); 99 int dpaa2_chan_next_frame(struct dpaa2_channel *, struct dpaa2_dq **); 100 101 #endif /* _DPAA2_CHANNEL_H */ 102