blob: 6c9c133d71ef465ca1c7df621b1773cd3bdaa5cb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) 2004, 2005, Voltaire, Inc. All rights reserved.
Hal Rosenstockfa619a72005-07-27 11:45:37 -07003 * Copyright (c) 2005 Intel Corporation. All rights reserved.
4 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
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 *
Jack Morgensteinf36e1792006-03-03 21:54:13 -080034 * $Id: mad_priv.h 5596 2006-03-03 01:00:07Z sean.hefty $
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 */
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>
Roland Dreiera4d61e82005-08-25 13:40:04 -070043#include <rdma/ib_mad.h>
44#include <rdma/ib_smi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
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
66struct ib_mad_list_head {
67 struct list_head list;
68 struct ib_mad_queue *mad_queue;
69};
70
71struct ib_mad_private_header {
72 struct ib_mad_list_head mad_list;
73 struct ib_mad_recv_wc recv_wc;
Sean Hefty24239af2005-04-16 15:26:08 -070074 struct ib_wc wc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 DECLARE_PCI_UNMAP_ADDR(mapping)
76} __attribute__ ((packed));
77
78struct 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
Jack Morgensteinf36e1792006-03-03 21:54:13 -080088struct ib_rmpp_segment {
89 struct list_head list;
90 u32 num;
91 u8 data[0];
92};
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094struct ib_mad_agent_private {
95 struct list_head agent_list;
96 struct ib_mad_agent agent;
97 struct ib_mad_reg_req *reg_req;
98 struct ib_mad_qp_info *qp_info;
99
100 spinlock_t lock;
101 struct list_head send_list;
102 struct list_head wait_list;
Hal Rosenstock6a0c4352005-07-27 11:45:26 -0700103 struct list_head done_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 struct work_struct timed_work;
105 unsigned long timeout;
106 struct list_head local_list;
107 struct work_struct local_work;
Hal Rosenstockfa619a72005-07-27 11:45:37 -0700108 struct list_head rmpp_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110 atomic_t refcount;
111 wait_queue_head_t wait;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112};
113
114struct ib_mad_snoop_private {
115 struct ib_mad_agent agent;
116 struct ib_mad_qp_info *qp_info;
117 int snoop_index;
118 int mad_snoop_flags;
119 atomic_t refcount;
120 wait_queue_head_t wait;
121};
122
123struct ib_mad_send_wr_private {
124 struct ib_mad_list_head mad_list;
125 struct list_head agent_list;
Hal Rosenstockd760ce82005-07-27 11:45:25 -0700126 struct ib_mad_agent_private *mad_agent_priv;
Sean Hefty34816ad2005-10-25 10:51:39 -0700127 struct ib_mad_send_buf send_buf;
Jack Morgensteinf36e1792006-03-03 21:54:13 -0800128 DECLARE_PCI_UNMAP_ADDR(header_mapping)
129 DECLARE_PCI_UNMAP_ADDR(payload_mapping)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 struct ib_send_wr send_wr;
131 struct ib_sge sg_list[IB_MAD_SEND_REQ_MAX_SG];
Sean Hefty97f52eb2005-08-13 21:05:57 -0700132 __be64 tid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 unsigned long timeout;
Hal Rosenstockf75b7a52005-07-27 11:45:29 -0700134 int retries;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 int retry;
136 int refcount;
137 enum ib_wc_status status;
Hal Rosenstockfa619a72005-07-27 11:45:37 -0700138
139 /* RMPP control */
Jack Morgensteinf36e1792006-03-03 21:54:13 -0800140 struct list_head rmpp_list;
141 struct ib_rmpp_segment *last_ack_seg;
142 struct ib_rmpp_segment *cur_seg;
Hal Rosenstockfa619a72005-07-27 11:45:37 -0700143 int last_ack;
144 int seg_num;
145 int newwin;
Hal Rosenstockfa619a72005-07-27 11:45:37 -0700146 int pad;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147};
148
149struct ib_mad_local_private {
150 struct list_head completion_list;
151 struct ib_mad_private *mad_priv;
152 struct ib_mad_agent_private *recv_mad_agent;
Sean Hefty34816ad2005-10-25 10:51:39 -0700153 struct ib_mad_send_wr_private *mad_send_wr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154};
155
156struct ib_mad_mgmt_method_table {
157 struct ib_mad_agent_private *agent[IB_MGMT_MAX_METHODS];
158};
159
160struct ib_mad_mgmt_class_table {
161 struct ib_mad_mgmt_method_table *method_table[MAX_MGMT_CLASS];
162};
163
164struct ib_mad_mgmt_vendor_class {
165 u8 oui[MAX_MGMT_OUI][3];
166 struct ib_mad_mgmt_method_table *method_table[MAX_MGMT_OUI];
167};
168
169struct ib_mad_mgmt_vendor_class_table {
170 struct ib_mad_mgmt_vendor_class *vendor_class[MAX_MGMT_VENDOR_RANGE2];
171};
172
173struct ib_mad_mgmt_version_table {
174 struct ib_mad_mgmt_class_table *class;
175 struct ib_mad_mgmt_vendor_class_table *vendor;
176};
177
178struct ib_mad_queue {
179 spinlock_t lock;
180 struct list_head list;
181 int count;
182 int max_active;
183 struct ib_mad_qp_info *qp_info;
184};
185
186struct ib_mad_qp_info {
187 struct ib_mad_port_private *port_priv;
188 struct ib_qp *qp;
189 struct ib_mad_queue send_queue;
190 struct ib_mad_queue recv_queue;
191 struct list_head overflow_list;
192 spinlock_t snoop_lock;
193 struct ib_mad_snoop_private **snoop_table;
194 int snoop_table_size;
195 atomic_t snoop_count;
196};
197
198struct ib_mad_port_private {
199 struct list_head port_list;
200 struct ib_device *device;
201 int port_num;
202 struct ib_cq *cq;
203 struct ib_pd *pd;
204 struct ib_mr *mr;
205
206 spinlock_t reg_lock;
207 struct ib_mad_mgmt_version_table version[MAX_MGMT_VERSION];
208 struct list_head agent_list;
209 struct workqueue_struct *wq;
210 struct work_struct work;
211 struct ib_mad_qp_info qp_info[IB_MAD_QPS_CORE];
212};
213
214extern kmem_cache_t *ib_mad_cache;
215
Hal Rosenstockfa619a72005-07-27 11:45:37 -0700216int ib_send_mad(struct ib_mad_send_wr_private *mad_send_wr);
217
218struct ib_mad_send_wr_private *
Jack Morgensteinfa9656b2006-03-28 16:39:07 -0800219ib_find_send_mad(struct ib_mad_agent_private *mad_agent_priv,
220 struct ib_mad_recv_wc *mad_recv_wc);
Hal Rosenstockfa619a72005-07-27 11:45:37 -0700221
222void ib_mad_complete_send_wr(struct ib_mad_send_wr_private *mad_send_wr,
223 struct ib_mad_send_wc *mad_send_wc);
224
225void ib_mark_mad_done(struct ib_mad_send_wr_private *mad_send_wr);
226
227void ib_reset_mad_timeout(struct ib_mad_send_wr_private *mad_send_wr,
228 int timeout_ms);
229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230#endif /* __IB_MAD_PRIV_H__ */