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