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