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. 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.
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.
29 $FreeBSD: src/sys/dev/cxgb/cxgb_offload.h,v 1.5 2007/09/10 00:59:51 kmacy Exp $
31 ***************************************************************************/
33 #ifndef _CXGB_OFFLOAD_H
34 #define _CXGB_OFFLOAD_H
37 #include <common/cxgb_version.h>
38 #include <cxgb_config.h>
40 #include <common/cxgb_tcb.h>
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>
49 #include "cxgb_version.h"
50 #include "cxgb_config.h"
59 void cxgb_offload_init(void);
60 void cxgb_offload_exit(void);
62 void cxgb_adapter_ofld(struct adapter
*adapter
);
63 void cxgb_adapter_unofld(struct adapter
*adapter
);
64 int cxgb_offload_activate(struct adapter
*adapter
);
65 void cxgb_offload_deactivate(struct adapter
*adapter
);
66 int cxgb_ofld_recv(struct toedev
*dev
, struct mbuf
**m
, int n
);
68 void cxgb_set_dummy_ops(struct toedev
*dev
);
72 * Client registration. Users of T3 driver must register themselves.
73 * The T3 driver will call the add function of every client for each T3
74 * adapter activated, passing up the toedev ptr. Each client fills out an
75 * array of callback functions to process CPL messages.
78 void cxgb_register_client(struct cxgb_client
*client
);
79 void cxgb_unregister_client(struct cxgb_client
*client
);
80 void cxgb_add_clients(struct toedev
*tdev
);
81 void cxgb_remove_clients(struct toedev
*tdev
);
83 typedef int (*cxgb_cpl_handler_func
)(struct toedev
*dev
,
84 struct mbuf
*m
, void *ctx
);
88 void (*add
) (struct toedev
*);
89 void (*remove
) (struct toedev
*);
90 cxgb_cpl_handler_func
*handlers
;
91 int (*redirect
)(void *ctx
, struct rtentry
*old
,
93 struct l2t_entry
*l2t
);
94 TAILQ_ENTRY(cxgb_client
) client_entry
;
98 * TID allocation services.
100 int cxgb_alloc_atid(struct toedev
*dev
, struct cxgb_client
*client
,
102 int cxgb_alloc_stid(struct toedev
*dev
, struct cxgb_client
*client
,
104 void *cxgb_free_atid(struct toedev
*dev
, int atid
);
105 void cxgb_free_stid(struct toedev
*dev
, int stid
);
106 void cxgb_insert_tid(struct toedev
*dev
, struct cxgb_client
*client
,
109 void cxgb_queue_tid_release(struct toedev
*dev
, unsigned int tid
);
110 void cxgb_remove_tid(struct toedev
*dev
, void *ctx
, unsigned int tid
);
112 struct toe_tid_entry
{
113 struct cxgb_client
*client
;
117 /* CPL message priority levels */
119 CPL_PRIORITY_DATA
= 0, /* data messages */
120 CPL_PRIORITY_SETUP
= 1, /* connection setup messages */
121 CPL_PRIORITY_TEARDOWN
= 0, /* connection teardown messages */
122 CPL_PRIORITY_LISTEN
= 1, /* listen start/stop messages */
123 CPL_PRIORITY_ACK
= 1, /* RX ACK messages */
124 CPL_PRIORITY_CONTROL
= 1 /* offload control messages */
127 /* Flags for return value of CPL message handlers */
129 CPL_RET_BUF_DONE
= 1, // buffer processing done, buffer may be freed
130 CPL_RET_BAD_MSG
= 2, // bad CPL message (e.g., unknown opcode)
131 CPL_RET_UNKNOWN_TID
= 4 // unexpected unknown TID
134 typedef int (*cpl_handler_func
)(struct toedev
*dev
, struct mbuf
*m
);
137 * Returns a pointer to the first byte of the CPL header in an sk_buff that
138 * contains a CPL message.
140 static inline void *cplhdr(struct mbuf
*m
)
142 return mtod(m
, uint8_t *);
145 void t3_register_cpl_handler(unsigned int opcode
, cpl_handler_func h
);
148 struct toe_tid_entry toe_tid
;
149 union listen_entry
*next
;
152 union active_open_entry
{
153 struct toe_tid_entry toe_tid
;
154 union active_open_entry
*next
;
158 * Holds the size, base address, free list start, etc of the TID, server TID,
159 * and active-open TID tables for a offload device.
160 * The tables themselves are allocated dynamically.
163 struct toe_tid_entry
*tid_tab
;
165 volatile unsigned int tids_in_use
;
167 union listen_entry
*stid_tab
;
169 unsigned int stid_base
;
171 union active_open_entry
*atid_tab
;
173 unsigned int atid_base
;
176 * The following members are accessed R/W so we put them in their own
179 * XXX We could combine the atid fields above with the lock here since
180 * atids are use once (unlike other tids). OTOH the above fields are
181 * usually in cache due to tid_tab.
183 struct mtx atid_lock
/* ____cacheline_aligned_in_smp */;
184 union active_open_entry
*afree
;
185 unsigned int atids_in_use
;
187 struct mtx stid_lock
/*____cacheline_aligned */;
188 union listen_entry
*sfree
;
189 unsigned int stids_in_use
;
194 struct list_head list_node
;
197 unsigned int tx_max_chunk
; /* max payload for TX_DATA */
198 unsigned int max_wrs
; /* max in-flight WRs per connection */
200 const unsigned short *mtus
;
201 struct tid_info tid_maps
;
203 struct toe_tid_entry
*tid_release_list
;
204 struct mtx tid_release_lock
;
206 struct task tid_release_task
;
209 struct cxgb_task tid_release_task
;
214 * toedev -> toe_data accessor
216 #define TOE_DATA(dev) (*(struct toe_data **)&(dev)->l4opt)
219 * Map an ATID or STID to their entries in the corresponding TID tables.
221 static inline union active_open_entry
*atid2entry(const struct tid_info
*t
,
224 return &t
->atid_tab
[atid
- t
->atid_base
];
228 static inline union listen_entry
*stid2entry(const struct tid_info
*t
,
231 return &t
->stid_tab
[stid
- t
->stid_base
];
235 * Find the connection corresponding to a TID.
237 static inline struct toe_tid_entry
*lookup_tid(const struct tid_info
*t
,
240 return tid
< t
->ntids
? &(t
->tid_tab
[tid
]) : NULL
;
244 * Find the connection corresponding to a server TID.
246 static inline struct toe_tid_entry
*lookup_stid(const struct tid_info
*t
,
249 if (tid
< t
->stid_base
|| tid
>= t
->stid_base
+ t
->nstids
)
251 return &(stid2entry(t
, tid
)->toe_tid
);
255 * Find the connection corresponding to an active-open TID.
257 static inline struct toe_tid_entry
*lookup_atid(const struct tid_info
*t
,
260 if (tid
< t
->atid_base
|| tid
>= t
->atid_base
+ t
->natids
)
262 return &(atid2entry(t
, tid
)->toe_tid
);
265 void *cxgb_alloc_mem(unsigned long size
);
266 void cxgb_free_mem(void *addr
);
267 void cxgb_neigh_update(struct rtentry
*rt
);
268 void cxgb_redirect(struct rtentry
*old
, struct rtentry
*new);
269 int process_rx(struct toedev
*dev
, struct mbuf
**m
, int n
);
270 int attach_toedev(struct toedev
*dev
);
271 void detach_toedev(struct toedev
*dev
);