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