]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/cxgbe/offload.h
Merge llvm-project release/17.x llvmorg-17.0.0-rc4-10-g0176e8729ea4
[FreeBSD/FreeBSD.git] / sys / dev / cxgbe / offload.h
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2010 Chelsio Communications, Inc.
5  * All rights reserved.
6  * Written by: Navdeep Parhar <np@FreeBSD.org>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  */
30
31 #ifndef __T4_OFFLOAD_H__
32 #define __T4_OFFLOAD_H__
33 #include <sys/param.h>
34 #include <sys/proc.h>
35 #include <sys/condvar.h>
36
37 #define INIT_ULPTX_WRH(w, wrlen, atomic, tid) do { \
38         (w)->wr_hi = htonl(V_FW_WR_OP(FW_ULPTX_WR) | V_FW_WR_ATOMIC(atomic)); \
39         (w)->wr_mid = htonl(V_FW_WR_LEN16(DIV_ROUND_UP(wrlen, 16)) | \
40                                V_FW_WR_FLOWID(tid)); \
41         (w)->wr_lo = cpu_to_be64(0); \
42 } while (0)
43
44 #define INIT_ULPTX_WR(w, wrlen, atomic, tid) \
45     INIT_ULPTX_WRH(&((w)->wr), wrlen, atomic, tid)
46
47 #define INIT_TP_WR(w, tid) do { \
48         (w)->wr.wr_hi = htonl(V_FW_WR_OP(FW_TP_WR) | \
49                               V_FW_WR_IMMDLEN(sizeof(*w) - sizeof(w->wr))); \
50         (w)->wr.wr_mid = htonl(V_FW_WR_LEN16(DIV_ROUND_UP(sizeof(*w), 16)) | \
51                                V_FW_WR_FLOWID(tid)); \
52         (w)->wr.wr_lo = cpu_to_be64(0); \
53 } while (0)
54
55 #define INIT_TP_WR_MIT_CPL(w, cpl, tid) do { \
56         INIT_TP_WR(w, tid); \
57         OPCODE_TID(w) = htonl(MK_OPCODE_TID(cpl, tid)); \
58 } while (0)
59
60 TAILQ_HEAD(stid_head, stid_region);
61 struct listen_ctx;
62
63 struct stid_region {
64         TAILQ_ENTRY(stid_region) link;
65         u_int used;     /* # of stids used by this region */
66         u_int free;     /* # of contiguous stids free right after this region */
67 };
68
69 /*
70  * Max # of ATIDs.  The absolute HW max is 14b (enough for 16K) but we reserve
71  * the upper 3b for use as a cookie to demux the reply.
72  */
73 #define MAX_ATIDS 2048U
74
75 union aopen_entry {
76         void *data;
77         union aopen_entry *next;
78 };
79
80 /* cxgbe_rate_tag flags */
81 enum {
82         EO_FLOWC_PENDING        = (1 << 0),     /* flowc needs to be sent */
83         EO_FLOWC_RPL_PENDING    = (1 << 1),     /* flowc credits due back */
84         EO_SND_TAG_REF          = (1 << 2),     /* kernel has a ref on us */
85         EO_FLUSH_RPL_PENDING    = (1 << 3),     /* credit flush rpl due back */
86 };
87
88 struct cxgbe_rate_tag {
89         struct m_snd_tag com;
90         struct adapter *adapter;
91         u_int flags;
92         struct mtx lock;
93         int port_id;
94         int etid;
95         struct mbufq pending_tx, pending_fwack;
96         int plen;
97         struct sge_ofld_txq *eo_txq;
98         uint32_t ctrl0;
99         uint16_t iqid;
100         int8_t schedcl;
101         uint64_t max_rate;      /* in bytes/s */
102         uint8_t tx_total;       /* total tx WR credits (in 16B units) */
103         uint8_t tx_credits;     /* tx WR credits (in 16B units) available */
104         uint8_t tx_nocompl;     /* tx WR credits since last compl request */
105         uint8_t ncompl;         /* # of completions outstanding. */
106 };
107
108 static inline struct cxgbe_rate_tag *
109 mst_to_crt(struct m_snd_tag *t)
110 {
111         return (__containerof(t, struct cxgbe_rate_tag, com));
112 }
113
114 union etid_entry {
115         struct cxgbe_rate_tag *cst;
116         union etid_entry *next;
117 };
118
119 /*
120  * Holds the size, base address, start, end, etc. of various types of TIDs.  The
121  * tables themselves are allocated dynamically.
122  */
123 struct tid_info {
124         u_int nstids;
125         u_int stid_base;
126
127         u_int natids;
128
129         u_int nftids;
130         u_int ftid_base;
131         u_int ftid_end;
132
133         u_int nhpftids;
134         u_int hpftid_base;
135         u_int hpftid_end;
136
137         u_int ntids;
138         u_int tid_base;
139
140         u_int netids;
141         u_int etid_base;
142         u_int etid_end;
143
144         struct mtx stid_lock __aligned(CACHE_LINE_SIZE);
145         struct listen_ctx **stid_tab;
146         u_int stids_in_use;
147         u_int nstids_free_head; /* # of available stids at the beginning */
148         struct stid_head stids;
149
150         struct mtx atid_lock __aligned(CACHE_LINE_SIZE);
151         union aopen_entry *atid_tab;
152         union aopen_entry *afree;
153         u_int atids_in_use;
154
155         /* High priority filters and normal filters share the lock and cv. */
156         struct mtx ftid_lock __aligned(CACHE_LINE_SIZE);
157         struct cv ftid_cv;
158         struct filter_entry *ftid_tab;
159         struct filter_entry *hpftid_tab;
160         u_int ftids_in_use;
161         u_int hpftids_in_use;
162
163         /*
164          * hashfilter and TOE are mutually exclusive and both use ntids and
165          * tids_in_use.  The lock and cv are used only by hashfilter.
166          */
167         struct mtx hftid_lock __aligned(CACHE_LINE_SIZE);
168         struct cv hftid_cv;
169         void **tid_tab;
170         u_int tids_in_use;
171
172         void *hftid_hash_4t;    /* LIST_HEAD(, filter_entry) *hftid_hash_4t; */
173         u_long hftid_4t_mask;
174         void *hftid_hash_tid;   /* LIST_HEAD(, filter_entry) *hftid_hash_tid; */
175         u_long hftid_tid_mask;
176
177         struct mtx etid_lock __aligned(CACHE_LINE_SIZE);
178         union etid_entry *etid_tab;
179         union etid_entry *efree;
180         u_int etids_in_use;
181 };
182
183 struct t4_range {
184         u_int start;
185         u_int size;
186 };
187
188 struct t4_virt_res {                      /* virtualized HW resources */
189         struct t4_range ddp;
190         struct t4_range iscsi;
191         struct t4_range stag;
192         struct t4_range rq;
193         struct t4_range pbl;
194         struct t4_range qp;
195         struct t4_range cq;
196         struct t4_range srq;
197         struct t4_range ocq;
198         struct t4_range l2t;
199         struct t4_range key;
200 };
201
202 enum {
203         ULD_TOM = 0,
204         ULD_IWARP,
205         ULD_ISCSI,
206         ULD_MAX = ULD_ISCSI
207 };
208
209 struct adapter;
210 struct port_info;
211 struct uld_info {
212         SLIST_ENTRY(uld_info) link;
213         int refcount;
214         int uld_id;
215         int (*activate)(struct adapter *);
216         int (*deactivate)(struct adapter *);
217         void (*async_event)(struct adapter *);
218 };
219
220 struct tom_tunables {
221         int cong_algorithm;
222         int sndbuf;
223         int ddp;
224         int rx_coalesce;
225         int tls;
226         int tx_align;
227         int tx_zcopy;
228         int cop_managed_offloading;
229         int autorcvbuf_inc;
230         int update_hc_on_pmtu_change;
231         int iso;
232 };
233
234 /* iWARP driver tunables */
235 struct iw_tunables {
236         int wc_en;
237 };
238
239 struct tls_tunables {
240         int inline_keys;
241         int combo_wrs;
242 };
243
244 #ifdef TCP_OFFLOAD
245 int t4_register_uld(struct uld_info *);
246 int t4_unregister_uld(struct uld_info *);
247 int t4_activate_uld(struct adapter *, int);
248 int t4_deactivate_uld(struct adapter *, int);
249 int uld_active(struct adapter *, int);
250 #endif
251 #endif