1 /**************************************************************************
3 Copyright (c) 2007, 2009 Chelsio Inc.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
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.
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.
31 ***************************************************************************/
34 #include <sys/protosw.h>
35 #include <netinet/toecore.h>
37 MALLOC_DECLARE(M_CXGB);
39 #define KTR_CXGB KTR_SPARE3
41 #define LISTEN_HASH_SIZE 32
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.
51 volatile unsigned int tids_in_use;
53 union listen_entry *stid_tab;
55 unsigned int stid_base;
57 union active_open_entry *atid_tab;
59 unsigned int atid_base;
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.
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.
70 union active_open_entry *afree;
71 unsigned int atids_in_use;
74 union listen_entry *sfree;
75 unsigned int stids_in_use;
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.
85 struct mtx toep_list_lock;
86 TAILQ_HEAD(, toepcb) toep_list;
89 struct tid_info tid_maps;
92 * The next two locks listen_lock, and tid_release_lock are used rarely
93 * so we let them potentially share a cacheline.
96 LIST_HEAD(, listen_ctx) *listen_hash;
98 int lctx_count; /* # of lctx in the hash table */
99 struct mtx lctx_hash_lock;
101 void **tid_release_list;
102 struct mtx tid_release_lock;
103 struct task tid_release_task;
107 TAILQ_ENTRY(synq_entry) link; /* listen_ctx's synq link */
108 int flags; /* same as toepcb's tp_flags */
110 struct mbuf *m; /* backpointer to containing mbuf */
111 struct listen_ctx *lctx; /* backpointer to listen ctx */
112 struct cpl_pass_establish *cpl;
120 volatile u_int refcnt;
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. */
128 #define LCTX_RPL_PENDING 1 /* waiting for CPL_PASS_OPEN_RPL */
131 LIST_ENTRY(listen_ctx) link; /* listen hash linkage */
135 struct inpcb *inp; /* listening socket's inp */
137 TAILQ_HEAD(, synq_entry) synq;
140 void t3_process_tid_release_list(void *data, int pending);
142 static inline struct tom_data *
143 t3_tomdata(struct toedev *tod)
146 return (__containerof(tod, struct tom_data, tod));
151 union listen_entry *next;
154 union active_open_entry {
156 union active_open_entry *next;
160 * Map an ATID or STID to their entries in the corresponding TID tables.
162 static inline union active_open_entry *atid2entry(const struct tid_info *t,
165 return &t->atid_tab[atid - t->atid_base];
169 static inline union listen_entry *stid2entry(const struct tid_info *t,
172 return &t->stid_tab[stid - t->stid_base];
176 * Find the connection corresponding to a TID.
178 static inline void *lookup_tid(const struct tid_info *t, unsigned int tid)
186 if (p < (void *)t->tid_tab || p >= (void *)&t->atid_tab[t->natids])
193 * Find the connection corresponding to a server TID.
195 static inline void *lookup_stid(const struct tid_info *t, unsigned int tid)
199 if (tid < t->stid_base || tid >= t->stid_base + t->nstids)
202 p = stid2entry(t, tid)->ctx;
203 if (p < (void *)t->tid_tab || p >= (void *)&t->atid_tab[t->natids])
210 * Find the connection corresponding to an active-open TID.
212 static inline void *lookup_atid(const struct tid_info *t, unsigned int tid)
216 if (tid < t->atid_base || tid >= t->atid_base + t->natids)
219 p = atid2entry(t, tid)->ctx;
220 if (p < (void *)t->tid_tab || p >= (void *)&t->atid_tab[t->natids])
226 static inline uint32_t
227 calc_opt2(int cpu_idx)
229 uint32_t opt2 = F_CPU_INDEX_VALID | V_CPU_INDEX(cpu_idx);
231 /* 3 = highspeed CC algorithm */
232 opt2 |= V_FLAVORS_VALID(1) | V_CONG_CONTROL_FLAVOR(3) |
235 /* coalesce and push bit semantics */
236 opt2 |= F_RX_COALESCE_VALID | V_RX_COALESCE(3);
238 return (htobe32(opt2));
242 struct toepcb *toepcb_alloc(struct toedev *);
243 void toepcb_free(struct toepcb *);
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 *,
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);
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 *);