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