2 /**************************************************************************
4 Copyright (c) 2007, Chelsio Inc.
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
10 1. Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
17 3. Neither the name of the Chelsio Corporation nor the names of its
18 contributors may be used to endorse or promote products derived from
19 this software without specific prior written permission.
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 POSSIBILITY OF SUCH DAMAGE.
35 ***************************************************************************/
37 #ifndef _CXGB_OFFLOAD_H
38 #define _CXGB_OFFLOAD_H
41 #include <dev/cxgb/common/cxgb_tcb.h>
42 #include <dev/cxgb/cxgb_l2t.h>
44 #include <dev/cxgb/ulp/toecore/toedev.h>
45 #include <dev/cxgb/common/cxgb_t3_cpl.h>
50 void cxgb_offload_init(void);
51 void cxgb_offload_exit(void);
53 void cxgb_adapter_ofld(struct adapter *adapter);
54 void cxgb_adapter_unofld(struct adapter *adapter);
55 int cxgb_offload_activate(struct adapter *adapter);
56 void cxgb_offload_deactivate(struct adapter *adapter);
57 int cxgb_ofld_recv(struct toedev *dev, struct mbuf **m, int n);
59 void cxgb_set_dummy_ops(struct toedev *dev);
63 * Client registration. Users of T3 driver must register themselves.
64 * The T3 driver will call the add function of every client for each T3
65 * adapter activated, passing up the toedev ptr. Each client fills out an
66 * array of callback functions to process CPL messages.
69 void cxgb_register_client(struct cxgb_client *client);
70 void cxgb_unregister_client(struct cxgb_client *client);
71 void cxgb_add_clients(struct toedev *tdev);
72 void cxgb_remove_clients(struct toedev *tdev);
74 typedef int (*cxgb_cpl_handler_func)(struct toedev *dev,
75 struct mbuf *m, void *ctx);
79 void (*add) (struct toedev *);
80 void (*remove) (struct toedev *);
81 cxgb_cpl_handler_func *handlers;
82 int (*redirect)(void *ctx, struct rtentry *old,
84 struct l2t_entry *l2t);
85 TAILQ_ENTRY(cxgb_client) client_entry;
89 * TID allocation services.
91 int cxgb_alloc_atid(struct toedev *dev, struct cxgb_client *client,
93 int cxgb_alloc_stid(struct toedev *dev, struct cxgb_client *client,
95 void *cxgb_free_atid(struct toedev *dev, int atid);
96 void cxgb_free_stid(struct toedev *dev, int stid);
97 void cxgb_insert_tid(struct toedev *dev, struct cxgb_client *client,
100 void cxgb_queue_tid_release(struct toedev *dev, unsigned int tid);
101 void cxgb_remove_tid(struct toedev *dev, void *ctx, unsigned int tid);
103 struct toe_tid_entry {
104 struct cxgb_client *client;
108 /* CPL message priority levels */
110 CPL_PRIORITY_DATA = 0, /* data messages */
111 CPL_PRIORITY_SETUP = 1, /* connection setup messages */
112 CPL_PRIORITY_TEARDOWN = 0, /* connection teardown messages */
113 CPL_PRIORITY_LISTEN = 1, /* listen start/stop messages */
114 CPL_PRIORITY_ACK = 1, /* RX ACK messages */
115 CPL_PRIORITY_CONTROL = 1 /* offload control messages */
118 /* Flags for return value of CPL message handlers */
120 CPL_RET_BUF_DONE = 1, // buffer processing done, buffer may be freed
121 CPL_RET_BAD_MSG = 2, // bad CPL message (e.g., unknown opcode)
122 CPL_RET_UNKNOWN_TID = 4 // unexpected unknown TID
125 typedef int (*cpl_handler_func)(struct toedev *dev, struct mbuf *m);
128 * Returns a pointer to the first byte of the CPL header in an sk_buff that
129 * contains a CPL message.
131 static inline void *cplhdr(struct mbuf *m)
136 void t3_register_cpl_handler(unsigned int opcode, cpl_handler_func h);
139 struct toe_tid_entry toe_tid;
140 union listen_entry *next;
143 union active_open_entry {
144 struct toe_tid_entry toe_tid;
145 union active_open_entry *next;
149 * Holds the size, base address, free list start, etc of the TID, server TID,
150 * and active-open TID tables for a offload device.
151 * The tables themselves are allocated dynamically.
154 struct toe_tid_entry *tid_tab;
156 volatile int tids_in_use;
158 union listen_entry *stid_tab;
160 unsigned int stid_base;
162 union active_open_entry *atid_tab;
164 unsigned int atid_base;
167 * The following members are accessed R/W so we put them in their own
170 * XXX We could combine the atid fields above with the lock here since
171 * atids are use once (unlike other tids). OTOH the above fields are
172 * usually in cache due to tid_tab.
174 struct mtx atid_lock /* ____cacheline_aligned_in_smp */;
175 union active_open_entry *afree;
176 unsigned int atids_in_use;
178 struct mtx stid_lock /*____cacheline_aligned */;
179 union listen_entry *sfree;
180 unsigned int stids_in_use;
185 struct list_head list_node;
188 unsigned int tx_max_chunk; /* max payload for TX_DATA */
189 unsigned int max_wrs; /* max in-flight WRs per connection */
191 const unsigned short *mtus;
192 struct tid_info tid_maps;
194 struct toe_tid_entry *tid_release_list;
195 struct mtx tid_release_lock;
196 struct task tid_release_task;
200 * toedev -> toe_data accessor
202 #define TOE_DATA(dev) (*(struct toe_data **)&(dev)->l4opt)
205 * Map an ATID or STID to their entries in the corresponding TID tables.
207 static inline union active_open_entry *atid2entry(const struct tid_info *t,
210 return &t->atid_tab[atid - t->atid_base];
214 static inline union listen_entry *stid2entry(const struct tid_info *t,
217 return &t->stid_tab[stid - t->stid_base];
221 * Find the connection corresponding to a TID.
223 static inline struct toe_tid_entry *lookup_tid(const struct tid_info *t,
226 return tid < t->ntids ? &(t->tid_tab[tid]) : NULL;
230 * Find the connection corresponding to a server TID.
232 static inline struct toe_tid_entry *lookup_stid(const struct tid_info *t,
235 if (tid < t->stid_base || tid >= t->stid_base + t->nstids)
237 return &(stid2entry(t, tid)->toe_tid);
241 * Find the connection corresponding to an active-open TID.
243 static inline struct toe_tid_entry *lookup_atid(const struct tid_info *t,
246 if (tid < t->atid_base || tid >= t->atid_base + t->natids)
248 return &(atid2entry(t, tid)->toe_tid);
251 void *cxgb_alloc_mem(unsigned long size);
252 void cxgb_free_mem(void *addr);
253 void cxgb_neigh_update(struct rtentry *rt);
254 void cxgb_redirect(struct rtentry *old, struct rtentry *new);
255 int process_rx(struct toedev *dev, struct mbuf **m, int n);
256 int attach_toedev(struct toedev *dev);
257 void detach_toedev(struct toedev *dev);