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