Dennis Dalessandro | 3dd1faf | 2016-01-06 09:58:37 -0800 | [diff] [blame] | 1 | /* |
Dennis Dalessandro | fe31419 | 2016-01-22 13:04:58 -0800 | [diff] [blame^] | 2 | * Copyright(c) 2016 Intel Corporation. |
Dennis Dalessandro | 3dd1faf | 2016-01-06 09:58:37 -0800 | [diff] [blame] | 3 | * |
| 4 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 5 | * redistributing this file, you may do so under either license. |
| 6 | * |
| 7 | * GPL LICENSE SUMMARY |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of version 2 of the GNU General Public License as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * BSD LICENSE |
| 19 | * |
| 20 | * Redistribution and use in source and binary forms, with or without |
| 21 | * modification, are permitted provided that the following conditions |
| 22 | * are met: |
| 23 | * |
| 24 | * - Redistributions of source code must retain the above copyright |
| 25 | * notice, this list of conditions and the following disclaimer. |
| 26 | * - Redistributions in binary form must reproduce the above copyright |
| 27 | * notice, this list of conditions and the following disclaimer in |
| 28 | * the documentation and/or other materials provided with the |
| 29 | * distribution. |
| 30 | * - Neither the name of Intel Corporation nor the names of its |
| 31 | * contributors may be used to endorse or promote products derived |
| 32 | * from this software without specific prior written permission. |
| 33 | * |
| 34 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 35 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 37 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 38 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 39 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 40 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 41 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 42 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 43 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 44 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 45 | * |
| 46 | */ |
| 47 | |
Dennis Dalessandro | 3711baf | 2016-01-22 13:04:51 -0800 | [diff] [blame] | 48 | #include <rdma/ib_mad.h> |
Dennis Dalessandro | 3dd1faf | 2016-01-06 09:58:37 -0800 | [diff] [blame] | 49 | #include "mad.h" |
| 50 | |
| 51 | /** |
| 52 | * rvt_process_mad - process an incoming MAD packet |
| 53 | * @ibdev: the infiniband device this packet came in on |
| 54 | * @mad_flags: MAD flags |
| 55 | * @port: the port number this packet came in on |
| 56 | * @in_wc: the work completion entry for this packet |
| 57 | * @in_grh: the global route header for this packet |
| 58 | * @in_mad: the incoming MAD |
| 59 | * @out_mad: any outgoing MAD reply |
| 60 | * |
| 61 | * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not |
| 62 | * interested in processing. |
| 63 | * |
| 64 | * Note that the verbs framework has already done the MAD sanity checks, |
| 65 | * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE |
| 66 | * MADs. |
| 67 | * |
| 68 | * This is called by the ib_mad module. |
| 69 | */ |
| 70 | int rvt_process_mad(struct ib_device *ibdev, int mad_flags, u8 port, |
| 71 | const struct ib_wc *in_wc, const struct ib_grh *in_grh, |
| 72 | const struct ib_mad_hdr *in, size_t in_mad_size, |
| 73 | struct ib_mad_hdr *out, size_t *out_mad_size, |
| 74 | u16 *out_mad_pkey_index) |
| 75 | { |
| 76 | /* |
| 77 | * Drivers will need to provide a number of things. For exmaple counters |
| 78 | * will need to be maintained by the driver but shoud live in the rvt |
| 79 | * structure. More study will be needed to finalize the interface |
| 80 | * between drivers and rvt for mad packets. |
| 81 | * |
| 82 | *VT-DRIVER-API: ???? |
| 83 | * |
| 84 | */ |
| 85 | return IB_MAD_RESULT_FAILURE; |
| 86 | } |
Dennis Dalessandro | 3711baf | 2016-01-22 13:04:51 -0800 | [diff] [blame] | 87 | |
| 88 | static void rvt_send_mad_handler(struct ib_mad_agent *agent, |
| 89 | struct ib_mad_send_wc *mad_send_wc) |
| 90 | { |
| 91 | ib_free_send_mad(mad_send_wc->send_buf); |
| 92 | } |
| 93 | |
| 94 | int rvt_create_mad_agents(struct rvt_dev_info *rdi) |
| 95 | { |
| 96 | struct ib_mad_agent *agent; |
| 97 | struct rvt_ibport *rvp; |
| 98 | int p; |
| 99 | int ret; |
| 100 | |
| 101 | for (p = 0; p < rdi->dparms.nports; p++) { |
| 102 | rvp = rdi->ports[p]; |
| 103 | agent = ib_register_mad_agent(&rdi->ibdev, p + 1, |
| 104 | IB_QPT_SMI, |
| 105 | NULL, 0, rvt_send_mad_handler, |
| 106 | NULL, NULL, 0); |
| 107 | if (IS_ERR(agent)) { |
| 108 | ret = PTR_ERR(agent); |
| 109 | goto err; |
| 110 | } |
| 111 | |
| 112 | rvp->send_agent = agent; |
| 113 | |
| 114 | if (rdi->driver_f.notify_create_mad_agent) |
| 115 | rdi->driver_f.notify_create_mad_agent(rdi, p); |
| 116 | } |
| 117 | |
| 118 | return 0; |
| 119 | |
| 120 | err: |
| 121 | for (p = 0; p < rdi->dparms.nports; p++) { |
| 122 | rvp = rdi->ports[p]; |
| 123 | if (rvp->send_agent) { |
| 124 | agent = rvp->send_agent; |
| 125 | rvp->send_agent = NULL; |
| 126 | ib_unregister_mad_agent(agent); |
| 127 | if (rdi->driver_f.notify_free_mad_agent) |
| 128 | rdi->driver_f.notify_free_mad_agent(rdi, p); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | return ret; |
| 133 | } |
| 134 | |
| 135 | void rvt_free_mad_agents(struct rvt_dev_info *rdi) |
| 136 | { |
| 137 | struct ib_mad_agent *agent; |
| 138 | struct rvt_ibport *rvp; |
| 139 | int p; |
| 140 | |
| 141 | for (p = 0; p < rdi->dparms.nports; p++) { |
| 142 | rvp = rdi->ports[p]; |
| 143 | if (rvp->send_agent) { |
| 144 | agent = rvp->send_agent; |
| 145 | rvp->send_agent = NULL; |
| 146 | ib_unregister_mad_agent(agent); |
| 147 | } |
| 148 | if (rvp->sm_ah) { |
| 149 | ib_destroy_ah(&rvp->sm_ah->ibah); |
| 150 | rvp->sm_ah = NULL; |
| 151 | } |
| 152 | |
| 153 | if (rdi->driver_f.notify_free_mad_agent) |
| 154 | rdi->driver_f.notify_free_mad_agent(rdi, p); |
| 155 | } |
| 156 | } |
| 157 | |