1 1.1 jklos 2 1.1 jklos /************************************************************************** 3 1.1 jklos 4 1.1 jklos Copyright (c) 2007, Chelsio Inc. 5 1.1 jklos All rights reserved. 6 1.1 jklos 7 1.1 jklos Redistribution and use in source and binary forms, with or without 8 1.1 jklos modification, are permitted provided that the following conditions are met: 9 1.1 jklos 10 1.1 jklos 1. Redistributions of source code must retain the above copyright notice, 11 1.1 jklos this list of conditions and the following disclaimer. 12 1.1 jklos 13 1.1 jklos 2. Neither the name of the Chelsio Corporation nor the names of its 14 1.1 jklos contributors may be used to endorse or promote products derived from 15 1.1 jklos this software without specific prior written permission. 16 1.1 jklos 17 1.1 jklos THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 1.1 jklos AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 1.1 jklos IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 1.1 jklos ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 1.1 jklos LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 1.1 jklos CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 1.1 jklos SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 1.1 jklos INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 1.1 jklos CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 1.1 jklos ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 1.1 jklos POSSIBILITY OF SUCH DAMAGE. 28 1.1 jklos 29 1.1 jklos ***************************************************************************/ 30 1.1 jklos 31 1.1 jklos #ifndef _CXGB_OFFLOAD_H 32 1.1 jklos #define _CXGB_OFFLOAD_H 33 1.1 jklos 34 1.1 jklos #ifdef CONFIG_DEFINED 35 1.1 jklos #include <common/cxgb_version.h> 36 1.1 jklos #include <cxgb_config.h> 37 1.1 jklos #include <cxgb_l2t.h> 38 1.1 jklos #include <common/cxgb_tcb.h> 39 1.1 jklos #else 40 1.1 jklos #include "cxgb_version.h" 41 1.1 jklos #include "cxgb_config.h" 42 1.1 jklos #include "cxgb_l2t.h" 43 1.1 jklos #include "cxgb_tcb.h" 44 1.1 jklos #endif 45 1.1 jklos 46 1.1 jklos struct adapter; 47 1.1 jklos struct cxgb_client; 48 1.1 jklos 49 1.1 jklos void cxgb_offload_init(void); 50 1.1 jklos void cxgb_offload_exit(void); 51 1.1 jklos 52 1.1 jklos void cxgb_adapter_ofld(struct adapter *adapter); 53 1.1 jklos void cxgb_adapter_unofld(struct adapter *adapter); 54 1.1 jklos int cxgb_offload_activate(struct adapter *adapter); 55 1.1 jklos void cxgb_offload_deactivate(struct adapter *adapter); 56 1.1 jklos int cxgb_ofld_recv(struct toedev *dev, struct mbuf **m, int n); 57 1.1 jklos 58 1.1 jklos void cxgb_set_dummy_ops(struct toedev *dev); 59 1.1 jklos 60 1.1 jklos 61 1.1 jklos /* 62 1.1 jklos * Client registration. Users of T3 driver must register themselves. 63 1.1 jklos * The T3 driver will call the add function of every client for each T3 64 1.1 jklos * adapter activated, passing up the toedev ptr. Each client fills out an 65 1.1 jklos * array of callback functions to process CPL messages. 66 1.1 jklos */ 67 1.1 jklos 68 1.1 jklos void cxgb_register_client(struct cxgb_client *client); 69 1.1 jklos void cxgb_unregister_client(struct cxgb_client *client); 70 1.1 jklos void cxgb_add_clients(struct toedev *tdev); 71 1.1 jklos void cxgb_remove_clients(struct toedev *tdev); 72 1.1 jklos 73 1.1 jklos typedef int (*cxgb_cpl_handler_func)(struct toedev *dev, 74 1.1 jklos struct mbuf *m, void *ctx); 75 1.1 jklos 76 1.1 jklos struct cxgb_client { 77 1.1 jklos char *name; 78 1.1 jklos void (*add) (struct toedev *); 79 1.1 jklos void (*remove) (struct toedev *); 80 1.1 jklos cxgb_cpl_handler_func *handlers; 81 1.1 jklos int (*redirect)(void *ctx, struct rtentry *old, 82 1.1 jklos struct rtentry *new, 83 1.1 jklos struct l2t_entry *l2t); 84 1.1 jklos TAILQ_ENTRY(cxgb_client) client_entry; 85 1.1 jklos }; 86 1.1 jklos 87 1.1 jklos /* 88 1.1 jklos * TID allocation services. 89 1.1 jklos */ 90 1.1 jklos int cxgb_alloc_atid(struct toedev *dev, struct cxgb_client *client, 91 1.1 jklos void *ctx); 92 1.1 jklos int cxgb_alloc_stid(struct toedev *dev, struct cxgb_client *client, 93 1.1 jklos void *ctx); 94 1.1 jklos void *cxgb_free_atid(struct toedev *dev, int atid); 95 1.1 jklos void cxgb_free_stid(struct toedev *dev, int stid); 96 1.1 jklos void cxgb_insert_tid(struct toedev *dev, struct cxgb_client *client, 97 1.1 jklos void *ctx, 98 1.1 jklos unsigned int tid); 99 1.1 jklos void cxgb_queue_tid_release(struct toedev *dev, unsigned int tid); 100 1.1 jklos void cxgb_remove_tid(struct toedev *dev, void *ctx, unsigned int tid); 101 1.1 jklos 102 1.1 jklos struct toe_tid_entry { 103 1.1 jklos struct cxgb_client *client; 104 1.1 jklos void *ctx; 105 1.1 jklos }; 106 1.1 jklos 107 1.1 jklos /* CPL message priority levels */ 108 1.1 jklos enum { 109 1.1 jklos CPL_PRIORITY_DATA = 0, /* data messages */ 110 1.1 jklos CPL_PRIORITY_SETUP = 1, /* connection setup messages */ 111 1.1 jklos CPL_PRIORITY_TEARDOWN = 0, /* connection teardown messages */ 112 1.1 jklos CPL_PRIORITY_LISTEN = 1, /* listen start/stop messages */ 113 1.1 jklos CPL_PRIORITY_ACK = 1, /* RX ACK messages */ 114 1.1 jklos CPL_PRIORITY_CONTROL = 1 /* offload control messages */ 115 1.1 jklos }; 116 1.1 jklos 117 1.1 jklos /* Flags for return value of CPL message handlers */ 118 1.1 jklos enum { 119 1.1 jklos CPL_RET_BUF_DONE = 1, // buffer processing done, buffer may be freed 120 1.1 jklos CPL_RET_BAD_MSG = 2, // bad CPL message (e.g., unknown opcode) 121 1.1 jklos CPL_RET_UNKNOWN_TID = 4 // unexpected unknown TID 122 1.1 jklos }; 123 1.1 jklos 124 1.1 jklos typedef int (*cpl_handler_func)(struct toedev *dev, struct mbuf *m); 125 1.1 jklos 126 1.1 jklos /* 127 1.1 jklos * Returns a pointer to the first byte of the CPL header in an sk_buff that 128 1.1 jklos * contains a CPL message. 129 1.1 jklos */ 130 1.2 christos static __inline void *cplhdr(struct mbuf *m) 131 1.1 jklos { 132 1.1 jklos return mtod(m, uint8_t *); 133 1.1 jklos } 134 1.1 jklos 135 1.1 jklos void t3_register_cpl_handler(unsigned int opcode, cpl_handler_func h); 136 1.1 jklos 137 1.1 jklos union listen_entry { 138 1.1 jklos struct toe_tid_entry toe_tid; 139 1.1 jklos union listen_entry *next; 140 1.1 jklos }; 141 1.1 jklos 142 1.1 jklos union active_open_entry { 143 1.1 jklos struct toe_tid_entry toe_tid; 144 1.1 jklos union active_open_entry *next; 145 1.1 jklos }; 146 1.1 jklos 147 1.1 jklos /* 148 1.1 jklos * Holds the size, base address, free list start, etc of the TID, server TID, 149 1.1 jklos * and active-open TID tables for a offload device. 150 1.1 jklos * The tables themselves are allocated dynamically. 151 1.1 jklos */ 152 1.1 jklos struct tid_info { 153 1.1 jklos struct toe_tid_entry *tid_tab; 154 1.1 jklos unsigned int ntids; 155 1.1 jklos volatile unsigned int tids_in_use; 156 1.1 jklos 157 1.1 jklos union listen_entry *stid_tab; 158 1.1 jklos unsigned int nstids; 159 1.1 jklos unsigned int stid_base; 160 1.1 jklos 161 1.1 jklos union active_open_entry *atid_tab; 162 1.1 jklos unsigned int natids; 163 1.1 jklos unsigned int atid_base; 164 1.1 jklos 165 1.1 jklos /* 166 1.1 jklos * The following members are accessed R/W so we put them in their own 167 1.1 jklos * cache lines. 168 1.1 jklos * 169 1.1 jklos * XXX We could combine the atid fields above with the lock here since 170 1.1 jklos * atids are use once (unlike other tids). OTOH the above fields are 171 1.1 jklos * usually in cache due to tid_tab. 172 1.1 jklos */ 173 1.1 jklos struct mtx atid_lock /* ____cacheline_aligned_in_smp */; 174 1.1 jklos union active_open_entry *afree; 175 1.1 jklos unsigned int atids_in_use; 176 1.1 jklos 177 1.1 jklos struct mtx stid_lock /*____cacheline_aligned */; 178 1.1 jklos union listen_entry *sfree; 179 1.1 jklos unsigned int stids_in_use; 180 1.1 jklos }; 181 1.1 jklos 182 1.1 jklos struct toe_data { 183 1.1 jklos #ifdef notyet 184 1.1 jklos struct list_head list_node; 185 1.1 jklos #endif 186 1.1 jklos struct toedev *dev; 187 1.1 jklos unsigned int tx_max_chunk; /* max payload for TX_DATA */ 188 1.1 jklos unsigned int max_wrs; /* max in-flight WRs per connection */ 189 1.1 jklos unsigned int nmtus; 190 1.1 jklos const unsigned short *mtus; 191 1.1 jklos struct tid_info tid_maps; 192 1.1 jklos 193 1.1 jklos struct toe_tid_entry *tid_release_list; 194 1.1 jklos struct mtx tid_release_lock; 195 1.1 jklos struct cxgb_task tid_release_task; 196 1.1 jklos }; 197 1.1 jklos 198 1.1 jklos /* 199 1.1 jklos * toedev -> toe_data accessor 200 1.1 jklos */ 201 1.1 jklos #define TOE_DATA(dev) (*(struct toe_data **)&(dev)->l4opt) 202 1.1 jklos 203 1.1 jklos /* 204 1.1 jklos * Map an ATID or STID to their entries in the corresponding TID tables. 205 1.1 jklos */ 206 1.2 christos static __inline union active_open_entry *atid2entry(const struct tid_info *t, 207 1.1 jklos unsigned int atid) 208 1.1 jklos { 209 1.1 jklos return &t->atid_tab[atid - t->atid_base]; 210 1.1 jklos } 211 1.1 jklos 212 1.1 jklos 213 1.2 christos static __inline union listen_entry *stid2entry(const struct tid_info *t, 214 1.1 jklos unsigned int stid) 215 1.1 jklos { 216 1.1 jklos return &t->stid_tab[stid - t->stid_base]; 217 1.1 jklos } 218 1.1 jklos 219 1.1 jklos /* 220 1.1 jklos * Find the connection corresponding to a TID. 221 1.1 jklos */ 222 1.2 christos static __inline struct toe_tid_entry *lookup_tid(const struct tid_info *t, 223 1.1 jklos unsigned int tid) 224 1.1 jklos { 225 1.1 jklos return tid < t->ntids ? &(t->tid_tab[tid]) : NULL; 226 1.1 jklos } 227 1.1 jklos 228 1.1 jklos /* 229 1.1 jklos * Find the connection corresponding to a server TID. 230 1.1 jklos */ 231 1.2 christos static __inline struct toe_tid_entry *lookup_stid(const struct tid_info *t, 232 1.1 jklos unsigned int tid) 233 1.1 jklos { 234 1.1 jklos if (tid < t->stid_base || tid >= t->stid_base + t->nstids) 235 1.1 jklos return NULL; 236 1.1 jklos return &(stid2entry(t, tid)->toe_tid); 237 1.1 jklos } 238 1.1 jklos 239 1.1 jklos /* 240 1.1 jklos * Find the connection corresponding to an active-open TID. 241 1.1 jklos */ 242 1.2 christos static __inline struct toe_tid_entry *lookup_atid(const struct tid_info *t, 243 1.1 jklos unsigned int tid) 244 1.1 jklos { 245 1.1 jklos if (tid < t->atid_base || tid >= t->atid_base + t->natids) 246 1.1 jklos return NULL; 247 1.1 jklos return &(atid2entry(t, tid)->toe_tid); 248 1.1 jklos } 249 1.1 jklos 250 1.1 jklos void *cxgb_alloc_mem(unsigned long size); 251 1.1 jklos void cxgb_free_mem(void *addr); 252 1.1 jklos void cxgb_neigh_update(struct rtentry *rt); 253 1.1 jklos void cxgb_redirect(struct rtentry *old, struct rtentry *new); 254 1.1 jklos int process_rx(struct toedev *dev, struct mbuf **m, int n); 255 1.1 jklos int attach_toedev(struct toedev *dev); 256 1.1 jklos void detach_toedev(struct toedev *dev); 257 1.1 jklos 258 1.1 jklos 259 1.1 jklos #endif 260