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