Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2004, 2005, Voltaire, Inc. All rights reserved. |
Hal Rosenstock | fa619a7 | 2005-07-27 11:45:37 -0700 | [diff] [blame] | 3 | * Copyright (c) 2005 Intel Corporation. All rights reserved. |
| 4 | * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * |
Jack Morgenstein | f36e179 | 2006-03-03 21:54:13 -0800 | [diff] [blame] | 34 | * $Id: mad_priv.h 5596 2006-03-03 01:00:07Z sean.hefty $ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | */ |
| 36 | |
| 37 | #ifndef __IB_MAD_PRIV_H__ |
| 38 | #define __IB_MAD_PRIV_H__ |
| 39 | |
Sean Hefty | 1b52fa98 | 2006-05-12 14:57:52 -0700 | [diff] [blame] | 40 | #include <linux/completion.h> |
Al Viro | d7b2004 | 2006-09-23 16:44:16 +0100 | [diff] [blame] | 41 | #include <linux/err.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/workqueue.h> |
Roland Dreier | a4d61e8 | 2005-08-25 13:40:04 -0700 | [diff] [blame] | 44 | #include <rdma/ib_mad.h> |
| 45 | #include <rdma/ib_smi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | |
| 48 | #define PFX "ib_mad: " |
| 49 | |
| 50 | #define IB_MAD_QPS_CORE 2 /* Always QP0 and QP1 as a minimum */ |
| 51 | |
| 52 | /* QP and CQ parameters */ |
| 53 | #define IB_MAD_QP_SEND_SIZE 128 |
| 54 | #define IB_MAD_QP_RECV_SIZE 512 |
| 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 | |
| 67 | struct ib_mad_list_head { |
| 68 | struct list_head list; |
| 69 | struct ib_mad_queue *mad_queue; |
| 70 | }; |
| 71 | |
| 72 | struct ib_mad_private_header { |
| 73 | struct ib_mad_list_head mad_list; |
| 74 | struct ib_mad_recv_wc recv_wc; |
Sean Hefty | 24239af | 2005-04-16 15:26:08 -0700 | [diff] [blame] | 75 | struct ib_wc wc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | DECLARE_PCI_UNMAP_ADDR(mapping) |
| 77 | } __attribute__ ((packed)); |
| 78 | |
| 79 | struct 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 | |
Jack Morgenstein | f36e179 | 2006-03-03 21:54:13 -0800 | [diff] [blame] | 89 | struct ib_rmpp_segment { |
| 90 | struct list_head list; |
| 91 | u32 num; |
| 92 | u8 data[0]; |
| 93 | }; |
| 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | struct 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; |
Hal Rosenstock | 6a0c435 | 2005-07-27 11:45:26 -0700 | [diff] [blame] | 104 | struct list_head done_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | struct work_struct timed_work; |
| 106 | unsigned long timeout; |
| 107 | struct list_head local_list; |
| 108 | struct work_struct local_work; |
Hal Rosenstock | fa619a7 | 2005-07-27 11:45:37 -0700 | [diff] [blame] | 109 | struct list_head rmpp_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
| 111 | atomic_t refcount; |
Sean Hefty | 1b52fa98 | 2006-05-12 14:57:52 -0700 | [diff] [blame] | 112 | struct completion comp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | struct 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; |
Sean Hefty | 1b52fa98 | 2006-05-12 14:57:52 -0700 | [diff] [blame] | 121 | struct completion comp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | struct ib_mad_send_wr_private { |
| 125 | struct ib_mad_list_head mad_list; |
| 126 | struct list_head agent_list; |
Hal Rosenstock | d760ce8 | 2005-07-27 11:45:25 -0700 | [diff] [blame] | 127 | struct ib_mad_agent_private *mad_agent_priv; |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 128 | struct ib_mad_send_buf send_buf; |
Jack Morgenstein | f36e179 | 2006-03-03 21:54:13 -0800 | [diff] [blame] | 129 | DECLARE_PCI_UNMAP_ADDR(header_mapping) |
| 130 | DECLARE_PCI_UNMAP_ADDR(payload_mapping) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | struct ib_send_wr send_wr; |
| 132 | struct ib_sge sg_list[IB_MAD_SEND_REQ_MAX_SG]; |
Sean Hefty | 97f52eb | 2005-08-13 21:05:57 -0700 | [diff] [blame] | 133 | __be64 tid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | unsigned long timeout; |
Hal Rosenstock | f75b7a5 | 2005-07-27 11:45:29 -0700 | [diff] [blame] | 135 | int retries; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | int retry; |
| 137 | int refcount; |
| 138 | enum ib_wc_status status; |
Hal Rosenstock | fa619a7 | 2005-07-27 11:45:37 -0700 | [diff] [blame] | 139 | |
| 140 | /* RMPP control */ |
Jack Morgenstein | f36e179 | 2006-03-03 21:54:13 -0800 | [diff] [blame] | 141 | struct list_head rmpp_list; |
| 142 | struct ib_rmpp_segment *last_ack_seg; |
| 143 | struct ib_rmpp_segment *cur_seg; |
Hal Rosenstock | fa619a7 | 2005-07-27 11:45:37 -0700 | [diff] [blame] | 144 | int last_ack; |
| 145 | int seg_num; |
| 146 | int newwin; |
Hal Rosenstock | fa619a7 | 2005-07-27 11:45:37 -0700 | [diff] [blame] | 147 | int pad; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | struct ib_mad_local_private { |
| 151 | struct list_head completion_list; |
| 152 | struct ib_mad_private *mad_priv; |
| 153 | struct ib_mad_agent_private *recv_mad_agent; |
Sean Hefty | 34816ad | 2005-10-25 10:51:39 -0700 | [diff] [blame] | 154 | struct ib_mad_send_wr_private *mad_send_wr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | struct ib_mr *mr; |
| 206 | |
| 207 | spinlock_t reg_lock; |
| 208 | struct ib_mad_mgmt_version_table version[MAX_MGMT_VERSION]; |
| 209 | struct list_head agent_list; |
| 210 | struct workqueue_struct *wq; |
| 211 | struct work_struct work; |
| 212 | struct ib_mad_qp_info qp_info[IB_MAD_QPS_CORE]; |
| 213 | }; |
| 214 | |
Hal Rosenstock | fa619a7 | 2005-07-27 11:45:37 -0700 | [diff] [blame] | 215 | int ib_send_mad(struct ib_mad_send_wr_private *mad_send_wr); |
| 216 | |
| 217 | struct ib_mad_send_wr_private * |
Jack Morgenstein | fa9656b | 2006-03-28 16:39:07 -0800 | [diff] [blame] | 218 | ib_find_send_mad(struct ib_mad_agent_private *mad_agent_priv, |
| 219 | struct ib_mad_recv_wc *mad_recv_wc); |
Hal Rosenstock | fa619a7 | 2005-07-27 11:45:37 -0700 | [diff] [blame] | 220 | |
| 221 | void ib_mad_complete_send_wr(struct ib_mad_send_wr_private *mad_send_wr, |
| 222 | struct ib_mad_send_wc *mad_send_wc); |
| 223 | |
| 224 | void ib_mark_mad_done(struct ib_mad_send_wr_private *mad_send_wr); |
| 225 | |
| 226 | void ib_reset_mad_timeout(struct ib_mad_send_wr_private *mad_send_wr, |
| 227 | int timeout_ms); |
| 228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | #endif /* __IB_MAD_PRIV_H__ */ |