xref: /freebsd/sys/dev/cxgbe/offload.h (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
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 #include <sys/bitstring.h>
37 
38 #define INIT_ULPTX_WRH(w, wrlen, atomic, tid) do { \
39 	(w)->wr_hi = htonl(V_FW_WR_OP(FW_ULPTX_WR) | V_FW_WR_ATOMIC(atomic)); \
40 	(w)->wr_mid = htonl(V_FW_WR_LEN16(DIV_ROUND_UP(wrlen, 16)) | \
41 			       V_FW_WR_FLOWID(tid)); \
42 	(w)->wr_lo = cpu_to_be64(0); \
43 } while (0)
44 
45 #define INIT_ULPTX_WR(w, wrlen, atomic, tid) \
46     INIT_ULPTX_WRH(&((w)->wr), wrlen, atomic, tid)
47 
48 #define INIT_TP_WR(w, tid) do { \
49 	(w)->wr.wr_hi = htonl(V_FW_WR_OP(FW_TP_WR) | \
50                               V_FW_WR_IMMDLEN(sizeof(*w) - sizeof(w->wr))); \
51 	(w)->wr.wr_mid = htonl(V_FW_WR_LEN16(DIV_ROUND_UP(sizeof(*w), 16)) | \
52                                V_FW_WR_FLOWID(tid)); \
53 	(w)->wr.wr_lo = cpu_to_be64(0); \
54 } while (0)
55 
56 #define INIT_TP_WR_MIT_CPL(w, cpl, tid) do { \
57 	INIT_TP_WR(w, tid); \
58 	OPCODE_TID(w) = htonl(MK_OPCODE_TID(cpl, tid)); \
59 } while (0)
60 
61 /*
62  * Max # of ATIDs.  The absolute HW max is larger than this but we reserve a few
63  * of the upper bits for use as a cookie to demux the reply.
64  */
65 #define MAX_ATIDS (M_TID_TID + 1)
66 
67 union aopen_entry {
68 	void *data;
69 	union aopen_entry *next;
70 };
71 
72 /* cxgbe_rate_tag flags */
73 enum {
74 	EO_FLOWC_PENDING	= (1 << 0),	/* flowc needs to be sent */
75 	EO_FLOWC_RPL_PENDING	= (1 << 1),	/* flowc credits due back */
76 	EO_SND_TAG_REF		= (1 << 2),	/* kernel has a ref on us */
77 	EO_FLUSH_RPL_PENDING	= (1 << 3),	/* credit flush rpl due back */
78 };
79 
80 struct cxgbe_rate_tag {
81 	struct m_snd_tag com;
82 	struct adapter *adapter;
83 	u_int flags;
84 	struct mtx lock;
85 	int port_id;
86 	int etid;
87 	struct mbufq pending_tx, pending_fwack;
88 	int plen;
89 	struct sge_ofld_txq *eo_txq;
90 	uint32_t ctrl0;
91 	uint16_t iqid;
92 	int8_t schedcl;
93 	uint64_t max_rate;      /* in bytes/s */
94 	uint8_t tx_total;	/* total tx WR credits (in 16B units) */
95 	uint8_t tx_credits;	/* tx WR credits (in 16B units) available */
96 	uint8_t tx_nocompl;	/* tx WR credits since last compl request */
97 	uint8_t ncompl;		/* # of completions outstanding. */
98 };
99 
100 static inline struct cxgbe_rate_tag *
101 mst_to_crt(struct m_snd_tag *t)
102 {
103 	return (__containerof(t, struct cxgbe_rate_tag, com));
104 }
105 
106 union etid_entry {
107 	struct cxgbe_rate_tag *cst;
108 	union etid_entry *next;
109 };
110 
111 /*
112  * Holds the size, base address, start, end, etc. of various types of TIDs.  The
113  * tables themselves are allocated dynamically.
114  */
115 struct tid_info {
116 	u_int nstids;
117 	u_int stid_base;
118 
119 	u_int natids;
120 
121 	u_int nftids;
122 	u_int ftid_base;
123 	u_int ftid_end;
124 
125 	u_int nhpftids;
126 	u_int hpftid_base;
127 	u_int hpftid_end;
128 
129 	u_int ntids;
130 	u_int tid_base;
131 
132 	u_int netids;
133 	u_int etid_base;
134 	u_int etid_end;
135 
136 	struct mtx stid_lock __aligned(CACHE_LINE_SIZE);
137 	struct listen_ctx **stid_tab;
138 	bitstr_t *stid_bitmap;
139 	u_int stids_in_use;
140 	bool stid_tab_stopped;
141 
142 	struct mtx atid_lock __aligned(CACHE_LINE_SIZE);
143 	union aopen_entry *atid_tab;
144 	union aopen_entry *afree;
145 	u_int atids_in_use;
146 	bool atid_alloc_stopped;
147 
148 	/* High priority filters and normal filters share the lock and cv. */
149 	struct mtx ftid_lock __aligned(CACHE_LINE_SIZE);
150 	struct cv ftid_cv;
151 	struct filter_entry *ftid_tab;
152 	struct filter_entry *hpftid_tab;
153 	u_int ftids_in_use;
154 	u_int hpftids_in_use;
155 
156 	/*
157 	 * hashfilter and TOE are mutually exclusive and both use ntids and
158 	 * tids_in_use.  The lock and cv are used only by hashfilter.
159 	 */
160 	struct mtx hftid_lock __aligned(CACHE_LINE_SIZE);
161 	struct cv hftid_cv;
162 	void **tid_tab;
163 	u_int tids_in_use;
164 
165 	void *hftid_hash_4t;	/* LIST_HEAD(, filter_entry) *hftid_hash_4t; */
166 	u_long hftid_4t_mask;
167 	void *hftid_hash_tid;	/* LIST_HEAD(, filter_entry) *hftid_hash_tid; */
168 	u_long hftid_tid_mask;
169 
170 	struct mtx etid_lock __aligned(CACHE_LINE_SIZE);
171 	union etid_entry *etid_tab;
172 	union etid_entry *efree;
173 	u_int etids_in_use;
174 };
175 
176 struct t4_range {
177 	u_int start;
178 	u_int size;
179 };
180 
181 struct t4_virt_res {                      /* virtualized HW resources */
182 	struct t4_range ddp;
183 	struct t4_range iscsi;
184 	struct t4_range stag;
185 	struct t4_range rq;
186 	struct t4_range pbl;
187 	struct t4_range qp;
188 	struct t4_range cq;
189 	struct t4_range srq;
190 	struct t4_range ocq;
191 	struct t4_range l2t;
192 	struct t4_range key;
193 };
194 
195 enum {
196 	ULD_TOM = 0,
197 	ULD_IWARP,
198 	ULD_ISCSI,
199 	ULD_MAX = ULD_ISCSI
200 };
201 
202 struct adapter;
203 struct port_info;
204 struct uld_info {
205 	int (*uld_activate)(struct adapter *);
206 	int (*uld_deactivate)(struct adapter *);
207 	int (*uld_stop)(struct adapter *);
208 	int (*uld_restart)(struct adapter *);
209 };
210 
211 struct tom_tunables {
212 	int cong_algorithm;
213 	int sndbuf;
214 	int ddp;
215 	int rx_coalesce;
216 	int tls;
217 	int tx_align;
218 	int tx_zcopy;
219 	int cop_managed_offloading;
220 	int autorcvbuf_inc;
221 	int update_hc_on_pmtu_change;
222 	int iso;
223 };
224 
225 /* iWARP driver tunables */
226 struct iw_tunables {
227 	int wc_en;
228 };
229 
230 struct tls_tunables {
231 	int inline_keys;
232 	int combo_wrs;
233 };
234 
235 #ifdef TCP_OFFLOAD
236 int t4_register_uld(struct uld_info *, int);
237 int t4_unregister_uld(struct uld_info *, int);
238 int t4_activate_uld(struct adapter *, int);
239 int t4_deactivate_uld(struct adapter *, int);
240 int uld_active(struct adapter *, int);
241 #endif
242 #endif
243