cxgb_tom.h revision 237263
1/************************************************************************** 2 3Copyright (c) 2007, 2009 Chelsio Inc. 4All rights reserved. 5 6Redistribution and use in source and binary forms, with or without 7modification, 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 16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26POSSIBILITY OF SUCH DAMAGE. 27 28 29$FreeBSD: head/sys/dev/cxgb/ulp/tom/cxgb_tom.h 237263 2012-06-19 07:34:13Z np $ 30 31***************************************************************************/ 32#ifndef CXGB_TOM_H_ 33#define CXGB_TOM_H_ 34#include <sys/protosw.h> 35#include <netinet/toecore.h> 36 37MALLOC_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 */ 48struct 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 78struct 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 106struct 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 130struct 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 140void t3_process_tid_release_list(void *data, int pending); 141 142static inline struct tom_data * 143t3_tomdata(struct toedev *tod) 144{ 145 return (member2struct(tom_data, tod, tod)); 146} 147 148union listen_entry { 149 void *ctx; 150 union listen_entry *next; 151}; 152 153union active_open_entry { 154 void *ctx; 155 union active_open_entry *next; 156}; 157 158/* 159 * Map an ATID or STID to their entries in the corresponding TID tables. 160 */ 161static inline union active_open_entry *atid2entry(const struct tid_info *t, 162 unsigned int atid) 163{ 164 return &t->atid_tab[atid - t->atid_base]; 165} 166 167 168static inline union listen_entry *stid2entry(const struct tid_info *t, 169 unsigned int stid) 170{ 171 return &t->stid_tab[stid - t->stid_base]; 172} 173 174/* 175 * Find the connection corresponding to a TID. 176 */ 177static inline void *lookup_tid(const struct tid_info *t, unsigned int tid) 178{ 179 void *p; 180 181 if (tid >= t->ntids) 182 return (NULL); 183 184 p = t->tid_tab[tid]; 185 if (p < (void *)t->tid_tab || p >= (void *)&t->atid_tab[t->natids]) 186 return (p); 187 188 return (NULL); 189} 190 191/* 192 * Find the connection corresponding to a server TID. 193 */ 194static inline void *lookup_stid(const struct tid_info *t, unsigned int tid) 195{ 196 void *p; 197 198 if (tid < t->stid_base || tid >= t->stid_base + t->nstids) 199 return (NULL); 200 201 p = stid2entry(t, tid)->ctx; 202 if (p < (void *)t->tid_tab || p >= (void *)&t->atid_tab[t->natids]) 203 return (p); 204 205 return (NULL); 206} 207 208/* 209 * Find the connection corresponding to an active-open TID. 210 */ 211static inline void *lookup_atid(const struct tid_info *t, unsigned int tid) 212{ 213 void *p; 214 215 if (tid < t->atid_base || tid >= t->atid_base + t->natids) 216 return (NULL); 217 218 p = atid2entry(t, tid)->ctx; 219 if (p < (void *)t->tid_tab || p >= (void *)&t->atid_tab[t->natids]) 220 return (p); 221 222 return (NULL); 223} 224 225static inline uint32_t 226calc_opt2(int cpu_idx) 227{ 228 uint32_t opt2 = F_CPU_INDEX_VALID | V_CPU_INDEX(cpu_idx); 229 230 /* 3 = highspeed CC algorithm */ 231 opt2 |= V_FLAVORS_VALID(1) | V_CONG_CONTROL_FLAVOR(3) | 232 V_PACING_FLAVOR(1); 233 234 /* coalesce and push bit semantics */ 235 opt2 |= F_RX_COALESCE_VALID | V_RX_COALESCE(3); 236 237 return (htobe32(opt2)); 238} 239 240/* cxgb_tom.c */ 241struct toepcb *toepcb_alloc(struct toedev *); 242void toepcb_free(struct toepcb *); 243 244/* cxgb_cpl_io.c */ 245void t3_init_cpl_io(struct adapter *); 246int t3_push_frames(struct socket *, int); 247int t3_connect(struct toedev *, struct socket *, struct rtentry *, 248 struct sockaddr *); 249int t3_tod_output(struct toedev *, struct tcpcb *); 250int t3_send_rst(struct toedev *, struct tcpcb *); 251int t3_send_fin(struct toedev *, struct tcpcb *); 252void insert_tid(struct tom_data *, void *, unsigned int); 253void update_tid(struct tom_data *, void *, unsigned int); 254void remove_tid(struct tom_data *, unsigned int); 255uint32_t calc_opt0h(struct socket *, int, int, struct l2t_entry *); 256uint32_t calc_opt0l(struct socket *, int); 257void queue_tid_release(struct toedev *, unsigned int); 258void offload_socket(struct socket *, struct toepcb *); 259void undo_offload_socket(struct socket *); 260int select_rcv_wscale(void); 261unsigned long select_rcv_wnd(struct socket *); 262int find_best_mtu_idx(struct adapter *, struct in_conninfo *, int); 263void make_established(struct socket *, uint32_t, uint32_t, uint16_t); 264void t3_rcvd(struct toedev *, struct tcpcb *); 265void t3_pcb_detach(struct toedev *, struct tcpcb *); 266void send_abort_rpl(struct toedev *, int, int); 267void release_tid(struct toedev *, unsigned int, int); 268 269/* cxgb_listen.c */ 270void t3_init_listen_cpl_handlers(struct adapter *); 271int t3_listen_start(struct toedev *, struct tcpcb *); 272int t3_listen_stop(struct toedev *, struct tcpcb *); 273void t3_syncache_added(struct toedev *, void *); 274void t3_syncache_removed(struct toedev *, void *); 275int t3_syncache_respond(struct toedev *, void *, struct mbuf *); 276int do_abort_req_synqe(struct sge_qset *, struct rsp_desc *, struct mbuf *); 277int do_abort_rpl_synqe(struct sge_qset *, struct rsp_desc *, struct mbuf *); 278void t3_offload_socket(struct toedev *, void *, struct socket *); 279#endif 280