cxgb_offload.h revision 171471
1169978Skmacy
2169978Skmacy/**************************************************************************
3169978Skmacy
4169978SkmacyCopyright (c) 2007, Chelsio Inc.
5169978SkmacyAll rights reserved.
6169978Skmacy
7169978SkmacyRedistribution and use in source and binary forms, with or without
8169978Skmacymodification, are permitted provided that the following conditions are met:
9169978Skmacy
10169978Skmacy 1. Redistributions of source code must retain the above copyright notice,
11169978Skmacy    this list of conditions and the following disclaimer.
12169978Skmacy
13171471Skmacy 2. Neither the name of the Chelsio Corporation nor the names of its
14169978Skmacy    contributors may be used to endorse or promote products derived from
15169978Skmacy    this software without specific prior written permission.
16169978Skmacy
17169978SkmacyTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18169978SkmacyAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19169978SkmacyIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20169978SkmacyARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21169978SkmacyLIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22169978SkmacyCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23169978SkmacySUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24169978SkmacyINTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25169978SkmacyCONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26169978SkmacyARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27169978SkmacyPOSSIBILITY OF SUCH DAMAGE.
28169978Skmacy
29169978Skmacy$FreeBSD: head/sys/dev/cxgb/cxgb_offload.h 171471 2007-07-17 06:50:35Z kmacy $
30169978Skmacy
31169978Skmacy***************************************************************************/
32169978Skmacy
33169978Skmacy#ifndef _CXGB_OFFLOAD_H
34169978Skmacy#define _CXGB_OFFLOAD_H
35169978Skmacy
36169978Skmacy
37169978Skmacy#include <dev/cxgb/common/cxgb_tcb.h>
38169978Skmacy#include <dev/cxgb/cxgb_l2t.h>
39169978Skmacy
40169978Skmacy#include <dev/cxgb/ulp/toecore/toedev.h>
41169978Skmacy#include <dev/cxgb/common/cxgb_t3_cpl.h>
42169978Skmacy
43169978Skmacystruct adapter;
44169978Skmacystruct cxgb_client;
45169978Skmacy
46169978Skmacyvoid cxgb_offload_init(void);
47169978Skmacyvoid cxgb_offload_exit(void);
48169978Skmacy
49169978Skmacyvoid cxgb_adapter_ofld(struct adapter *adapter);
50169978Skmacyvoid cxgb_adapter_unofld(struct adapter *adapter);
51169978Skmacyint cxgb_offload_activate(struct adapter *adapter);
52169978Skmacyvoid cxgb_offload_deactivate(struct adapter *adapter);
53169978Skmacyint cxgb_ofld_recv(struct toedev *dev, struct mbuf **m, int n);
54169978Skmacy
55169978Skmacyvoid cxgb_set_dummy_ops(struct toedev *dev);
56169978Skmacy
57169978Skmacy
58169978Skmacy/*
59169978Skmacy * Client registration.  Users of T3 driver must register themselves.
60169978Skmacy * The T3 driver will call the add function of every client for each T3
61169978Skmacy * adapter activated, passing up the toedev ptr.  Each client fills out an
62169978Skmacy * array of callback functions to process CPL messages.
63169978Skmacy */
64169978Skmacy
65169978Skmacyvoid cxgb_register_client(struct cxgb_client *client);
66169978Skmacyvoid cxgb_unregister_client(struct cxgb_client *client);
67169978Skmacyvoid cxgb_add_clients(struct toedev *tdev);
68169978Skmacyvoid cxgb_remove_clients(struct toedev *tdev);
69169978Skmacy
70169978Skmacytypedef int (*cxgb_cpl_handler_func)(struct toedev *dev,
71169978Skmacy				      struct mbuf *m, void *ctx);
72169978Skmacy
73169978Skmacystruct cxgb_client {
74169978Skmacy	char 			*name;
75169978Skmacy	void 			(*add) (struct toedev *);
76169978Skmacy	void 			(*remove) (struct toedev *);
77169978Skmacy	cxgb_cpl_handler_func 	*handlers;
78169978Skmacy	int			(*redirect)(void *ctx, struct rtentry *old,
79169978Skmacy					    struct rtentry *new,
80169978Skmacy					    struct l2t_entry *l2t);
81169978Skmacy	TAILQ_ENTRY(cxgb_client)         client_entry;
82169978Skmacy};
83169978Skmacy
84169978Skmacy/*
85169978Skmacy * TID allocation services.
86169978Skmacy */
87169978Skmacyint cxgb_alloc_atid(struct toedev *dev, struct cxgb_client *client,
88169978Skmacy		     void *ctx);
89169978Skmacyint cxgb_alloc_stid(struct toedev *dev, struct cxgb_client *client,
90169978Skmacy		     void *ctx);
91169978Skmacyvoid *cxgb_free_atid(struct toedev *dev, int atid);
92169978Skmacyvoid cxgb_free_stid(struct toedev *dev, int stid);
93169978Skmacyvoid cxgb_insert_tid(struct toedev *dev, struct cxgb_client *client,
94169978Skmacy		      void *ctx,
95169978Skmacy	unsigned int tid);
96169978Skmacyvoid cxgb_queue_tid_release(struct toedev *dev, unsigned int tid);
97169978Skmacyvoid cxgb_remove_tid(struct toedev *dev, void *ctx, unsigned int tid);
98169978Skmacy
99169978Skmacystruct toe_tid_entry {
100169978Skmacy	struct cxgb_client 	*client;
101169978Skmacy	void 			*ctx;
102169978Skmacy};
103169978Skmacy
104169978Skmacy/* CPL message priority levels */
105169978Skmacyenum {
106169978Skmacy	CPL_PRIORITY_DATA = 0,     /* data messages */
107169978Skmacy	CPL_PRIORITY_SETUP = 1,	   /* connection setup messages */
108169978Skmacy	CPL_PRIORITY_TEARDOWN = 0, /* connection teardown messages */
109169978Skmacy	CPL_PRIORITY_LISTEN = 1,   /* listen start/stop messages */
110169978Skmacy	CPL_PRIORITY_ACK = 1,      /* RX ACK messages */
111169978Skmacy	CPL_PRIORITY_CONTROL = 1   /* offload control messages */
112169978Skmacy};
113169978Skmacy
114169978Skmacy/* Flags for return value of CPL message handlers */
115169978Skmacyenum {
116169978Skmacy	CPL_RET_BUF_DONE = 1,   // buffer processing done, buffer may be freed
117169978Skmacy	CPL_RET_BAD_MSG = 2,    // bad CPL message (e.g., unknown opcode)
118169978Skmacy	CPL_RET_UNKNOWN_TID = 4	// unexpected unknown TID
119169978Skmacy};
120169978Skmacy
121169978Skmacytypedef int (*cpl_handler_func)(struct toedev *dev, struct mbuf *m);
122169978Skmacy
123169978Skmacy/*
124169978Skmacy * Returns a pointer to the first byte of the CPL header in an sk_buff that
125169978Skmacy * contains a CPL message.
126169978Skmacy */
127169978Skmacystatic inline void *cplhdr(struct mbuf *m)
128169978Skmacy{
129170654Skmacy	return mtod(m, uint8_t *);
130169978Skmacy}
131169978Skmacy
132169978Skmacyvoid t3_register_cpl_handler(unsigned int opcode, cpl_handler_func h);
133169978Skmacy
134169978Skmacyunion listen_entry {
135169978Skmacy	struct toe_tid_entry toe_tid;
136169978Skmacy	union listen_entry *next;
137169978Skmacy};
138169978Skmacy
139169978Skmacyunion active_open_entry {
140169978Skmacy	struct toe_tid_entry toe_tid;
141169978Skmacy	union active_open_entry *next;
142169978Skmacy};
143169978Skmacy
144169978Skmacy/*
145169978Skmacy * Holds the size, base address, free list start, etc of the TID, server TID,
146169978Skmacy * and active-open TID tables for a offload device.
147169978Skmacy * The tables themselves are allocated dynamically.
148169978Skmacy */
149169978Skmacystruct tid_info {
150169978Skmacy	struct toe_tid_entry *tid_tab;
151169978Skmacy	unsigned int ntids;
152169978Skmacy	volatile int tids_in_use;
153169978Skmacy
154169978Skmacy	union listen_entry *stid_tab;
155169978Skmacy	unsigned int nstids;
156169978Skmacy	unsigned int stid_base;
157169978Skmacy
158169978Skmacy	union active_open_entry *atid_tab;
159169978Skmacy	unsigned int natids;
160169978Skmacy	unsigned int atid_base;
161169978Skmacy
162169978Skmacy	/*
163169978Skmacy	 * The following members are accessed R/W so we put them in their own
164169978Skmacy	 * cache lines.
165169978Skmacy	 *
166169978Skmacy	 * XXX We could combine the atid fields above with the lock here since
167169978Skmacy	 * atids are use once (unlike other tids).  OTOH the above fields are
168169978Skmacy	 * usually in cache due to tid_tab.
169169978Skmacy	 */
170169978Skmacy	struct mtx atid_lock /* ____cacheline_aligned_in_smp */;
171169978Skmacy	union active_open_entry *afree;
172169978Skmacy	unsigned int atids_in_use;
173169978Skmacy
174169978Skmacy	struct mtx stid_lock /*____cacheline_aligned */;
175169978Skmacy	union listen_entry *sfree;
176169978Skmacy	unsigned int stids_in_use;
177169978Skmacy};
178169978Skmacy
179169978Skmacystruct toe_data {
180169978Skmacy#ifdef notyet
181169978Skmacy	struct list_head list_node;
182169978Skmacy#endif
183169978Skmacy	struct toedev *dev;
184169978Skmacy	unsigned int tx_max_chunk;  /* max payload for TX_DATA */
185169978Skmacy	unsigned int max_wrs;       /* max in-flight WRs per connection */
186169978Skmacy	unsigned int nmtus;
187169978Skmacy	const unsigned short *mtus;
188169978Skmacy	struct tid_info tid_maps;
189169978Skmacy
190169978Skmacy	struct toe_tid_entry *tid_release_list;
191169978Skmacy	struct mtx tid_release_lock;
192169978Skmacy	struct task tid_release_task;
193169978Skmacy};
194169978Skmacy
195169978Skmacy/*
196169978Skmacy * toedev -> toe_data accessor
197169978Skmacy */
198169978Skmacy#define TOE_DATA(dev) (*(struct toe_data **)&(dev)->l4opt)
199169978Skmacy
200169978Skmacy/*
201169978Skmacy * Map an ATID or STID to their entries in the corresponding TID tables.
202169978Skmacy */
203169978Skmacystatic inline union active_open_entry *atid2entry(const struct tid_info *t,
204169978Skmacy                                                  unsigned int atid)
205169978Skmacy{
206169978Skmacy        return &t->atid_tab[atid - t->atid_base];
207169978Skmacy}
208169978Skmacy
209169978Skmacy
210169978Skmacystatic inline union listen_entry *stid2entry(const struct tid_info *t,
211169978Skmacy                                             unsigned int stid)
212169978Skmacy{
213169978Skmacy        return &t->stid_tab[stid - t->stid_base];
214169978Skmacy}
215169978Skmacy
216169978Skmacy/*
217169978Skmacy * Find the connection corresponding to a TID.
218169978Skmacy */
219169978Skmacystatic inline struct toe_tid_entry *lookup_tid(const struct tid_info *t,
220169978Skmacy                                               unsigned int tid)
221169978Skmacy{
222169978Skmacy        return tid < t->ntids ? &(t->tid_tab[tid]) : NULL;
223169978Skmacy}
224169978Skmacy
225169978Skmacy/*
226169978Skmacy * Find the connection corresponding to a server TID.
227169978Skmacy */
228169978Skmacystatic inline struct toe_tid_entry *lookup_stid(const struct tid_info *t,
229169978Skmacy                                                unsigned int tid)
230169978Skmacy{
231169978Skmacy        if (tid < t->stid_base || tid >= t->stid_base + t->nstids)
232169978Skmacy                return NULL;
233169978Skmacy        return &(stid2entry(t, tid)->toe_tid);
234169978Skmacy}
235169978Skmacy
236169978Skmacy/*
237169978Skmacy * Find the connection corresponding to an active-open TID.
238169978Skmacy */
239169978Skmacystatic inline struct toe_tid_entry *lookup_atid(const struct tid_info *t,
240169978Skmacy                                                unsigned int tid)
241169978Skmacy{
242169978Skmacy        if (tid < t->atid_base || tid >= t->atid_base + t->natids)
243169978Skmacy                return NULL;
244169978Skmacy        return &(atid2entry(t, tid)->toe_tid);
245169978Skmacy}
246169978Skmacy
247169978Skmacyvoid *cxgb_alloc_mem(unsigned long size);
248169978Skmacyvoid cxgb_free_mem(void *addr);
249169978Skmacyvoid cxgb_neigh_update(struct rtentry *rt);
250169978Skmacyvoid cxgb_redirect(struct rtentry *old, struct rtentry *new);
251169978Skmacyint process_rx(struct toedev *dev, struct mbuf **m, int n);
252169978Skmacyint attach_toedev(struct toedev *dev);
253169978Skmacyvoid detach_toedev(struct toedev *dev);
254169978Skmacy
255169978Skmacy
256169978Skmacy#endif
257