Merge master.kernel.org:/pub/scm/linux/kernel/git/dtor/input
[pandora-kernel.git] / drivers / infiniband / core / mad_priv.h
1 /*
2  * Copyright (c) 2004, 2005, Voltaire, Inc. All rights reserved.
3  * Copyright (c) 2005 Intel Corporation. All rights reserved.
4  * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
5  *
6  * This software is available to you under a choice of one of two
7  * licenses.  You may choose to be licensed under the terms of the GNU
8  * General Public License (GPL) Version 2, available from the file
9  * COPYING in the main directory of this source tree, or the
10  * OpenIB.org BSD license below:
11  *
12  *     Redistribution and use in source and binary forms, with or
13  *     without modification, are permitted provided that the following
14  *     conditions are met:
15  *
16  *      - Redistributions of source code must retain the above
17  *        copyright notice, this list of conditions and the following
18  *        disclaimer.
19  *
20  *      - Redistributions in binary form must reproduce the above
21  *        copyright notice, this list of conditions and the following
22  *        disclaimer in the documentation and/or other materials
23  *        provided with the distribution.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32  * SOFTWARE.
33  *
34  * $Id: mad_priv.h 2730 2005-06-28 16:43:03Z sean.hefty $
35  */
36
37 #ifndef __IB_MAD_PRIV_H__
38 #define __IB_MAD_PRIV_H__
39
40 #include <linux/pci.h>
41 #include <linux/kthread.h>
42 #include <linux/workqueue.h>
43 #include <ib_mad.h>
44 #include <ib_smi.h>
45
46
47 #define PFX "ib_mad: "
48
49 #define IB_MAD_QPS_CORE         2 /* Always QP0 and QP1 as a minimum */
50
51 /* QP and CQ parameters */
52 #define IB_MAD_QP_SEND_SIZE     128
53 #define IB_MAD_QP_RECV_SIZE     512
54 #define IB_MAD_SEND_REQ_MAX_SG  2
55 #define IB_MAD_RECV_REQ_MAX_SG  1
56
57 #define IB_MAD_SEND_Q_PSN       0
58
59 /* Registration table sizes */
60 #define MAX_MGMT_CLASS          80
61 #define MAX_MGMT_VERSION        8
62 #define MAX_MGMT_OUI            8
63 #define MAX_MGMT_VENDOR_RANGE2  (IB_MGMT_CLASS_VENDOR_RANGE2_END - \
64                                 IB_MGMT_CLASS_VENDOR_RANGE2_START + 1)
65
66 struct ib_mad_list_head {
67         struct list_head list;
68         struct ib_mad_queue *mad_queue;
69 };
70
71 struct ib_mad_private_header {
72         struct ib_mad_list_head mad_list;
73         struct ib_mad_recv_wc recv_wc;
74         struct ib_wc wc;
75         DECLARE_PCI_UNMAP_ADDR(mapping)
76 } __attribute__ ((packed));
77
78 struct ib_mad_private {
79         struct ib_mad_private_header header;
80         struct ib_grh grh;
81         union {
82                 struct ib_mad mad;
83                 struct ib_rmpp_mad rmpp_mad;
84                 struct ib_smp smp;
85         } mad;
86 } __attribute__ ((packed));
87
88 struct ib_mad_agent_private {
89         struct list_head agent_list;
90         struct ib_mad_agent agent;
91         struct ib_mad_reg_req *reg_req;
92         struct ib_mad_qp_info *qp_info;
93
94         spinlock_t lock;
95         struct list_head send_list;
96         struct list_head wait_list;
97         struct list_head done_list;
98         struct work_struct timed_work;
99         unsigned long timeout;
100         struct list_head local_list;
101         struct work_struct local_work;
102         struct list_head rmpp_list;
103
104         atomic_t refcount;
105         wait_queue_head_t wait;
106 };
107
108 struct ib_mad_snoop_private {
109         struct ib_mad_agent agent;
110         struct ib_mad_qp_info *qp_info;
111         int snoop_index;
112         int mad_snoop_flags;
113         atomic_t refcount;
114         wait_queue_head_t wait;
115 };
116
117 struct ib_mad_send_wr_private {
118         struct ib_mad_list_head mad_list;
119         struct list_head agent_list;
120         struct ib_mad_agent_private *mad_agent_priv;
121         struct ib_send_wr send_wr;
122         struct ib_sge sg_list[IB_MAD_SEND_REQ_MAX_SG];
123         u64 wr_id;                      /* client WR ID */
124         u64 tid;
125         unsigned long timeout;
126         int retries;
127         int retry;
128         int refcount;
129         enum ib_wc_status status;
130
131         /* RMPP control */
132         int last_ack;
133         int seg_num;
134         int newwin;
135         int total_seg;
136         int data_offset;
137         int pad;
138 };
139
140 struct ib_mad_local_private {
141         struct list_head completion_list;
142         struct ib_mad_private *mad_priv;
143         struct ib_mad_agent_private *recv_mad_agent;
144         struct ib_send_wr send_wr;
145         struct ib_sge sg_list[IB_MAD_SEND_REQ_MAX_SG];
146         u64 wr_id;                      /* client WR ID */
147         u64 tid;
148 };
149
150 struct ib_mad_mgmt_method_table {
151         struct ib_mad_agent_private *agent[IB_MGMT_MAX_METHODS];
152 };
153
154 struct ib_mad_mgmt_class_table {
155         struct ib_mad_mgmt_method_table *method_table[MAX_MGMT_CLASS];
156 };
157
158 struct ib_mad_mgmt_vendor_class {
159         u8      oui[MAX_MGMT_OUI][3];
160         struct ib_mad_mgmt_method_table *method_table[MAX_MGMT_OUI];
161 };
162
163 struct ib_mad_mgmt_vendor_class_table {
164         struct ib_mad_mgmt_vendor_class *vendor_class[MAX_MGMT_VENDOR_RANGE2];
165 };
166
167 struct ib_mad_mgmt_version_table {
168         struct ib_mad_mgmt_class_table *class;
169         struct ib_mad_mgmt_vendor_class_table *vendor;
170 };
171
172 struct ib_mad_queue {
173         spinlock_t lock;
174         struct list_head list;
175         int count;
176         int max_active;
177         struct ib_mad_qp_info *qp_info;
178 };
179
180 struct ib_mad_qp_info {
181         struct ib_mad_port_private *port_priv;
182         struct ib_qp *qp;
183         struct ib_mad_queue send_queue;
184         struct ib_mad_queue recv_queue;
185         struct list_head overflow_list;
186         spinlock_t snoop_lock;
187         struct ib_mad_snoop_private **snoop_table;
188         int snoop_table_size;
189         atomic_t snoop_count;
190 };
191
192 struct ib_mad_port_private {
193         struct list_head port_list;
194         struct ib_device *device;
195         int port_num;
196         struct ib_cq *cq;
197         struct ib_pd *pd;
198         struct ib_mr *mr;
199
200         spinlock_t reg_lock;
201         struct ib_mad_mgmt_version_table version[MAX_MGMT_VERSION];
202         struct list_head agent_list;
203         struct workqueue_struct *wq;
204         struct work_struct work;
205         struct ib_mad_qp_info qp_info[IB_MAD_QPS_CORE];
206 };
207
208 extern kmem_cache_t *ib_mad_cache;
209
210 int ib_send_mad(struct ib_mad_send_wr_private *mad_send_wr);
211
212 struct ib_mad_send_wr_private *
213 ib_find_send_mad(struct ib_mad_agent_private *mad_agent_priv, u64 tid);
214
215 void ib_mad_complete_send_wr(struct ib_mad_send_wr_private *mad_send_wr,
216                              struct ib_mad_send_wc *mad_send_wc);
217
218 void ib_mark_mad_done(struct ib_mad_send_wr_private *mad_send_wr);
219
220 void ib_reset_mad_timeout(struct ib_mad_send_wr_private *mad_send_wr,
221                           int timeout_ms);
222
223 #endif  /* __IB_MAD_PRIV_H__ */