xref: /NextBSD/sys/dev/cxgb/ulp/tom/cxgb_tom.h (revision eb1a5f8de9f7ea602c373a710f531abbf81141c4)
1 /**************************************************************************
2 
3 Copyright (c) 2007, 2009 Chelsio Inc.
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8 
9  1. Redistributions of source code must retain the above copyright notice,
10     this list of conditions and the following disclaimer.
11 
12  2. Neither the name of the Chelsio Corporation nor the names of its
13     contributors may be used to endorse or promote products derived from
14     this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 POSSIBILITY OF SUCH DAMAGE.
27 
28 
29 $FreeBSD$
30 
31 ***************************************************************************/
32 #ifndef CXGB_TOM_H_
33 #define CXGB_TOM_H_
34 #include <sys/protosw.h>
35 #include <netinet/toecore.h>
36 
37 MALLOC_DECLARE(M_CXGB);
38 
39 #define	KTR_CXGB	KTR_SPARE3
40 
41 #define LISTEN_HASH_SIZE 32
42 
43 /*
44  * Holds the size, base address, free list start, etc of the TID, server TID,
45  * and active-open TID tables for a offload device.
46  * The tables themselves are allocated dynamically.
47  */
48 struct tid_info {
49 	void **tid_tab;
50 	unsigned int ntids;
51 	volatile unsigned int tids_in_use;
52 
53 	union listen_entry *stid_tab;
54 	unsigned int nstids;
55 	unsigned int stid_base;
56 
57 	union active_open_entry *atid_tab;
58 	unsigned int natids;
59 	unsigned int atid_base;
60 
61 	/*
62 	 * The following members are accessed R/W so we put them in their own
63 	 * cache lines.  TOM_XXX: actually do what is said here.
64 	 *
65 	 * XXX We could combine the atid fields above with the lock here since
66 	 * atids are use once (unlike other tids).  OTOH the above fields are
67 	 * usually in cache due to tid_tab.
68 	 */
69 	struct mtx atid_lock;
70 	union active_open_entry *afree;
71 	unsigned int atids_in_use;
72 
73 	struct mtx stid_lock;
74 	union listen_entry *sfree;
75 	unsigned int stids_in_use;
76 };
77 
78 struct tom_data {
79         struct toedev tod;
80 
81 	/*
82 	 * toepcb's associated with this TOE device are either on the
83 	 * toep list or in the synq of a listening socket in lctx hash.
84 	 */
85 	struct mtx toep_list_lock;
86 	TAILQ_HEAD(, toepcb) toep_list;
87 
88 	struct l2t_data *l2t;
89 	struct tid_info tid_maps;
90 
91         /*
92 	 * The next two locks listen_lock, and tid_release_lock are used rarely
93 	 * so we let them potentially share a cacheline.
94          */
95 
96 	LIST_HEAD(, listen_ctx) *listen_hash;
97 	u_long listen_mask;
98 	int lctx_count;		/* # of lctx in the hash table */
99         struct mtx lctx_hash_lock;
100 
101         void **tid_release_list;
102         struct mtx tid_release_lock;
103         struct task tid_release_task;
104 };
105 
106 struct synq_entry {
107 	TAILQ_ENTRY(synq_entry) link;	/* listen_ctx's synq link */
108 	int flags;			/* same as toepcb's tp_flags */
109 	int tid;
110 	struct mbuf *m;			/* backpointer to containing mbuf */
111 	struct listen_ctx *lctx;	/* backpointer to listen ctx */
112 	struct cpl_pass_establish *cpl;
113 	struct toepcb *toep;
114 	struct l2t_entry *e;
115 	uint32_t iss;
116 	uint32_t ts;
117 	uint32_t opt0h;
118 	uint32_t qset;
119 	int rx_credits;
120 	volatile u_int refcnt;
121 
122 #define RPL_OK		0	/* ok to reply */
123 #define RPL_DONE	1	/* replied already */
124 #define RPL_DONT	2	/* don't reply */
125 	volatile u_int reply;	/* see above. */
126 };
127 
128 #define LCTX_RPL_PENDING	1	/* waiting for CPL_PASS_OPEN_RPL */
129 
130 struct listen_ctx {
131 	LIST_ENTRY(listen_ctx) link;	/* listen hash linkage */
132 	volatile int refcnt;
133 	int stid;
134 	int flags;
135 	struct inpcb *inp;		/* listening socket's inp */
136 	int qset;
137 	TAILQ_HEAD(, synq_entry) synq;
138 };
139 
140 void t3_process_tid_release_list(void *data, int pending);
141 
142 static inline struct tom_data *
t3_tomdata(struct toedev * tod)143 t3_tomdata(struct toedev *tod)
144 {
145 
146 	return (__containerof(tod, struct tom_data, tod));
147 }
148 
149 union listen_entry {
150 	void *ctx;
151 	union listen_entry *next;
152 };
153 
154 union active_open_entry {
155 	void *ctx;
156 	union active_open_entry *next;
157 };
158 
159 /*
160  * Map an ATID or STID to their entries in the corresponding TID tables.
161  */
atid2entry(const struct tid_info * t,unsigned int atid)162 static inline union active_open_entry *atid2entry(const struct tid_info *t,
163                                                   unsigned int atid)
164 {
165         return &t->atid_tab[atid - t->atid_base];
166 }
167 
168 
stid2entry(const struct tid_info * t,unsigned int stid)169 static inline union listen_entry *stid2entry(const struct tid_info *t,
170                                              unsigned int stid)
171 {
172         return &t->stid_tab[stid - t->stid_base];
173 }
174 
175 /*
176  * Find the connection corresponding to a TID.
177  */
lookup_tid(const struct tid_info * t,unsigned int tid)178 static inline void *lookup_tid(const struct tid_info *t, unsigned int tid)
179 {
180 	void *p;
181 
182 	if (tid >= t->ntids)
183 		return (NULL);
184 
185 	p = t->tid_tab[tid];
186 	if (p < (void *)t->tid_tab || p >= (void *)&t->atid_tab[t->natids])
187 		return (p);
188 
189 	return (NULL);
190 }
191 
192 /*
193  * Find the connection corresponding to a server TID.
194  */
lookup_stid(const struct tid_info * t,unsigned int tid)195 static inline void *lookup_stid(const struct tid_info *t, unsigned int tid)
196 {
197 	void *p;
198 
199         if (tid < t->stid_base || tid >= t->stid_base + t->nstids)
200                 return (NULL);
201 
202 	p = stid2entry(t, tid)->ctx;
203 	if (p < (void *)t->tid_tab || p >= (void *)&t->atid_tab[t->natids])
204 		return (p);
205 
206 	return (NULL);
207 }
208 
209 /*
210  * Find the connection corresponding to an active-open TID.
211  */
lookup_atid(const struct tid_info * t,unsigned int tid)212 static inline void *lookup_atid(const struct tid_info *t, unsigned int tid)
213 {
214 	void *p;
215 
216         if (tid < t->atid_base || tid >= t->atid_base + t->natids)
217                 return (NULL);
218 
219 	p = atid2entry(t, tid)->ctx;
220 	if (p < (void *)t->tid_tab || p >= (void *)&t->atid_tab[t->natids])
221 		return (p);
222 
223 	return (NULL);
224 }
225 
226 static inline uint32_t
calc_opt2(int cpu_idx)227 calc_opt2(int cpu_idx)
228 {
229 	uint32_t opt2 = F_CPU_INDEX_VALID | V_CPU_INDEX(cpu_idx);
230 
231 	/* 3 = highspeed CC algorithm */
232 	opt2 |= V_FLAVORS_VALID(1) | V_CONG_CONTROL_FLAVOR(3) |
233 	    V_PACING_FLAVOR(1);
234 
235 	/* coalesce and push bit semantics */
236 	opt2 |= F_RX_COALESCE_VALID | V_RX_COALESCE(3);
237 
238 	return (htobe32(opt2));
239 }
240 
241 /* cxgb_tom.c */
242 struct toepcb *toepcb_alloc(struct toedev *);
243 void toepcb_free(struct toepcb *);
244 
245 /* cxgb_cpl_io.c */
246 void t3_init_cpl_io(struct adapter *);
247 int t3_push_frames(struct socket *, int);
248 int t3_connect(struct toedev *, struct socket *, struct rtentry *,
249     struct sockaddr *);
250 int t3_tod_output(struct toedev *, struct tcpcb *);
251 int t3_send_rst(struct toedev *, struct tcpcb *);
252 int t3_send_fin(struct toedev *, struct tcpcb *);
253 void insert_tid(struct tom_data *, void *, unsigned int);
254 void update_tid(struct tom_data *, void *, unsigned int);
255 void remove_tid(struct tom_data *, unsigned int);
256 uint32_t calc_opt0h(struct socket *, int, int, struct l2t_entry *);
257 uint32_t calc_opt0l(struct socket *, int);
258 void queue_tid_release(struct toedev *, unsigned int);
259 void offload_socket(struct socket *, struct toepcb *);
260 void undo_offload_socket(struct socket *);
261 int select_rcv_wscale(void);
262 unsigned long select_rcv_wnd(struct socket *);
263 int find_best_mtu_idx(struct adapter *, struct in_conninfo *, int);
264 void make_established(struct socket *, uint32_t, uint32_t, uint16_t);
265 void t3_rcvd(struct toedev *, struct tcpcb *);
266 void t3_pcb_detach(struct toedev *, struct tcpcb *);
267 void send_abort_rpl(struct toedev *, int, int);
268 void release_tid(struct toedev *, unsigned int, int);
269 
270 /* cxgb_listen.c */
271 void t3_init_listen_cpl_handlers(struct adapter *);
272 int t3_listen_start(struct toedev *, struct tcpcb *);
273 int t3_listen_stop(struct toedev *, struct tcpcb *);
274 void t3_syncache_added(struct toedev *, void *);
275 void t3_syncache_removed(struct toedev *, void *);
276 int t3_syncache_respond(struct toedev *, void *, struct mbuf *);
277 int do_abort_req_synqe(struct sge_qset *, struct rsp_desc *, struct mbuf *);
278 int do_abort_rpl_synqe(struct sge_qset *, struct rsp_desc *, struct mbuf *);
279 void t3_offload_socket(struct toedev *, void *, struct socket *);
280 #endif
281