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