xref: /OK3568_Linux_fs/kernel/drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (c) 2006-2008 Chelsio, Inc. All rights reserved.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * This software is available to you under a choice of one of two
5*4882a593Smuzhiyun  * licenses.  You may choose to be licensed under the terms of the GNU
6*4882a593Smuzhiyun  * General Public License (GPL) Version 2, available from the file
7*4882a593Smuzhiyun  * COPYING in the main directory of this source tree, or the
8*4882a593Smuzhiyun  * OpenIB.org BSD license below:
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  *     Redistribution and use in source and binary forms, with or
11*4882a593Smuzhiyun  *     without modification, are permitted provided that the following
12*4882a593Smuzhiyun  *     conditions are met:
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  *      - Redistributions of source code must retain the above
15*4882a593Smuzhiyun  *        copyright notice, this list of conditions and the following
16*4882a593Smuzhiyun  *        disclaimer.
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  *      - Redistributions in binary form must reproduce the above
19*4882a593Smuzhiyun  *        copyright notice, this list of conditions and the following
20*4882a593Smuzhiyun  *        disclaimer in the documentation and/or other materials
21*4882a593Smuzhiyun  *        provided with the distribution.
22*4882a593Smuzhiyun  *
23*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24*4882a593Smuzhiyun  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25*4882a593Smuzhiyun  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26*4882a593Smuzhiyun  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27*4882a593Smuzhiyun  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28*4882a593Smuzhiyun  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29*4882a593Smuzhiyun  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30*4882a593Smuzhiyun  * SOFTWARE.
31*4882a593Smuzhiyun  */
32*4882a593Smuzhiyun #ifndef _CXGB3_OFFLOAD_H
33*4882a593Smuzhiyun #define _CXGB3_OFFLOAD_H
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun #include <linux/list.h>
36*4882a593Smuzhiyun #include <linux/skbuff.h>
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun #include "l2t.h"
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun #include "t3cdev.h"
41*4882a593Smuzhiyun #include "t3_cpl.h"
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun struct adapter;
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun void cxgb3_offload_init(void);
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun void cxgb3_adapter_ofld(struct adapter *adapter);
48*4882a593Smuzhiyun void cxgb3_adapter_unofld(struct adapter *adapter);
49*4882a593Smuzhiyun int cxgb3_offload_activate(struct adapter *adapter);
50*4882a593Smuzhiyun void cxgb3_offload_deactivate(struct adapter *adapter);
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun void cxgb3_set_dummy_ops(struct t3cdev *dev);
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun struct t3cdev *dev2t3cdev(struct net_device *dev);
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun /*
57*4882a593Smuzhiyun  * Client registration.  Users of T3 driver must register themselves.
58*4882a593Smuzhiyun  * The T3 driver will call the add function of every client for each T3
59*4882a593Smuzhiyun  * adapter activated, passing up the t3cdev ptr.  Each client fills out an
60*4882a593Smuzhiyun  * array of callback functions to process CPL messages.
61*4882a593Smuzhiyun  */
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun void cxgb3_register_client(struct cxgb3_client *client);
64*4882a593Smuzhiyun void cxgb3_unregister_client(struct cxgb3_client *client);
65*4882a593Smuzhiyun void cxgb3_add_clients(struct t3cdev *tdev);
66*4882a593Smuzhiyun void cxgb3_remove_clients(struct t3cdev *tdev);
67*4882a593Smuzhiyun void cxgb3_event_notify(struct t3cdev *tdev, u32 event, u32 port);
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun typedef int (*cxgb3_cpl_handler_func)(struct t3cdev *dev,
70*4882a593Smuzhiyun 				      struct sk_buff *skb, void *ctx);
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun enum {
73*4882a593Smuzhiyun 	OFFLOAD_STATUS_UP,
74*4882a593Smuzhiyun 	OFFLOAD_STATUS_DOWN,
75*4882a593Smuzhiyun 	OFFLOAD_PORT_DOWN,
76*4882a593Smuzhiyun 	OFFLOAD_PORT_UP,
77*4882a593Smuzhiyun 	OFFLOAD_DB_FULL,
78*4882a593Smuzhiyun 	OFFLOAD_DB_EMPTY,
79*4882a593Smuzhiyun 	OFFLOAD_DB_DROP
80*4882a593Smuzhiyun };
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun struct cxgb3_client {
83*4882a593Smuzhiyun 	char *name;
84*4882a593Smuzhiyun 	void (*add) (struct t3cdev *);
85*4882a593Smuzhiyun 	void (*remove) (struct t3cdev *);
86*4882a593Smuzhiyun 	cxgb3_cpl_handler_func *handlers;
87*4882a593Smuzhiyun 	int (*redirect)(void *ctx, struct dst_entry *old,
88*4882a593Smuzhiyun 			struct dst_entry *new, struct l2t_entry *l2t);
89*4882a593Smuzhiyun 	struct list_head client_list;
90*4882a593Smuzhiyun 	void (*event_handler)(struct t3cdev *tdev, u32 event, u32 port);
91*4882a593Smuzhiyun };
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun /*
94*4882a593Smuzhiyun  * TID allocation services.
95*4882a593Smuzhiyun  */
96*4882a593Smuzhiyun int cxgb3_alloc_atid(struct t3cdev *dev, struct cxgb3_client *client,
97*4882a593Smuzhiyun 		     void *ctx);
98*4882a593Smuzhiyun int cxgb3_alloc_stid(struct t3cdev *dev, struct cxgb3_client *client,
99*4882a593Smuzhiyun 		     void *ctx);
100*4882a593Smuzhiyun void *cxgb3_free_atid(struct t3cdev *dev, int atid);
101*4882a593Smuzhiyun void cxgb3_free_stid(struct t3cdev *dev, int stid);
102*4882a593Smuzhiyun void cxgb3_insert_tid(struct t3cdev *dev, struct cxgb3_client *client,
103*4882a593Smuzhiyun 		      void *ctx, unsigned int tid);
104*4882a593Smuzhiyun void cxgb3_queue_tid_release(struct t3cdev *dev, unsigned int tid);
105*4882a593Smuzhiyun void cxgb3_remove_tid(struct t3cdev *dev, void *ctx, unsigned int tid);
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun struct t3c_tid_entry {
108*4882a593Smuzhiyun 	struct cxgb3_client *client;
109*4882a593Smuzhiyun 	void *ctx;
110*4882a593Smuzhiyun };
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun /* CPL message priority levels */
113*4882a593Smuzhiyun enum {
114*4882a593Smuzhiyun 	CPL_PRIORITY_DATA = 0,	/* data messages */
115*4882a593Smuzhiyun 	CPL_PRIORITY_SETUP = 1,	/* connection setup messages */
116*4882a593Smuzhiyun 	CPL_PRIORITY_TEARDOWN = 0,	/* connection teardown messages */
117*4882a593Smuzhiyun 	CPL_PRIORITY_LISTEN = 1,	/* listen start/stop messages */
118*4882a593Smuzhiyun 	CPL_PRIORITY_ACK = 1,	/* RX ACK messages */
119*4882a593Smuzhiyun 	CPL_PRIORITY_CONTROL = 1	/* offload control messages */
120*4882a593Smuzhiyun };
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun /* Flags for return value of CPL message handlers */
123*4882a593Smuzhiyun enum {
124*4882a593Smuzhiyun 	CPL_RET_BUF_DONE = 1, /* buffer processing done, buffer may be freed */
125*4882a593Smuzhiyun 	CPL_RET_BAD_MSG = 2,  /* bad CPL message (e.g., unknown opcode) */
126*4882a593Smuzhiyun 	CPL_RET_UNKNOWN_TID = 4	/* unexpected unknown TID */
127*4882a593Smuzhiyun };
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun typedef int (*cpl_handler_func)(struct t3cdev *dev, struct sk_buff *skb);
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun /*
132*4882a593Smuzhiyun  * Returns a pointer to the first byte of the CPL header in an sk_buff that
133*4882a593Smuzhiyun  * contains a CPL message.
134*4882a593Smuzhiyun  */
cplhdr(struct sk_buff * skb)135*4882a593Smuzhiyun static inline void *cplhdr(struct sk_buff *skb)
136*4882a593Smuzhiyun {
137*4882a593Smuzhiyun 	return skb->data;
138*4882a593Smuzhiyun }
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun void t3_register_cpl_handler(unsigned int opcode, cpl_handler_func h);
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun union listen_entry {
143*4882a593Smuzhiyun 	struct t3c_tid_entry t3c_tid;
144*4882a593Smuzhiyun 	union listen_entry *next;
145*4882a593Smuzhiyun };
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun union active_open_entry {
148*4882a593Smuzhiyun 	struct t3c_tid_entry t3c_tid;
149*4882a593Smuzhiyun 	union active_open_entry *next;
150*4882a593Smuzhiyun };
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun /*
153*4882a593Smuzhiyun  * Holds the size, base address, free list start, etc of the TID, server TID,
154*4882a593Smuzhiyun  * and active-open TID tables for a offload device.
155*4882a593Smuzhiyun  * The tables themselves are allocated dynamically.
156*4882a593Smuzhiyun  */
157*4882a593Smuzhiyun struct tid_info {
158*4882a593Smuzhiyun 	struct t3c_tid_entry *tid_tab;
159*4882a593Smuzhiyun 	unsigned int ntids;
160*4882a593Smuzhiyun 	atomic_t tids_in_use;
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun 	union listen_entry *stid_tab;
163*4882a593Smuzhiyun 	unsigned int nstids;
164*4882a593Smuzhiyun 	unsigned int stid_base;
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun 	union active_open_entry *atid_tab;
167*4882a593Smuzhiyun 	unsigned int natids;
168*4882a593Smuzhiyun 	unsigned int atid_base;
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun 	/*
171*4882a593Smuzhiyun 	 * The following members are accessed R/W so we put them in their own
172*4882a593Smuzhiyun 	 * cache lines.
173*4882a593Smuzhiyun 	 *
174*4882a593Smuzhiyun 	 * XXX We could combine the atid fields above with the lock here since
175*4882a593Smuzhiyun 	 * atids are use once (unlike other tids).  OTOH the above fields are
176*4882a593Smuzhiyun 	 * usually in cache due to tid_tab.
177*4882a593Smuzhiyun 	 */
178*4882a593Smuzhiyun 	spinlock_t atid_lock ____cacheline_aligned_in_smp;
179*4882a593Smuzhiyun 	union active_open_entry *afree;
180*4882a593Smuzhiyun 	unsigned int atids_in_use;
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun 	spinlock_t stid_lock ____cacheline_aligned;
183*4882a593Smuzhiyun 	union listen_entry *sfree;
184*4882a593Smuzhiyun 	unsigned int stids_in_use;
185*4882a593Smuzhiyun };
186*4882a593Smuzhiyun 
187*4882a593Smuzhiyun struct t3c_data {
188*4882a593Smuzhiyun 	struct list_head list_node;
189*4882a593Smuzhiyun 	struct t3cdev *dev;
190*4882a593Smuzhiyun 	unsigned int tx_max_chunk;	/* max payload for TX_DATA */
191*4882a593Smuzhiyun 	unsigned int max_wrs;	/* max in-flight WRs per connection */
192*4882a593Smuzhiyun 	unsigned int nmtus;
193*4882a593Smuzhiyun 	const unsigned short *mtus;
194*4882a593Smuzhiyun 	struct tid_info tid_maps;
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun 	struct t3c_tid_entry *tid_release_list;
197*4882a593Smuzhiyun 	spinlock_t tid_release_lock;
198*4882a593Smuzhiyun 	struct work_struct tid_release_task;
199*4882a593Smuzhiyun 
200*4882a593Smuzhiyun 	struct sk_buff *nofail_skb;
201*4882a593Smuzhiyun 	unsigned int release_list_incomplete;
202*4882a593Smuzhiyun };
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun /*
205*4882a593Smuzhiyun  * t3cdev -> t3c_data accessor
206*4882a593Smuzhiyun  */
207*4882a593Smuzhiyun #define T3C_DATA(dev) (*(struct t3c_data **)&(dev)->l4opt)
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun #endif
210