Devesh Sharma | 71ee673 | 2015-07-24 05:03:59 +0530 | [diff] [blame] | 1 | /* This file is part of the Emulex RoCE Device Driver for |
| 2 | * RoCE (RDMA over Converged Ethernet) adapters. |
| 3 | * Copyright (C) 2012-2015 Emulex. All rights reserved. |
| 4 | * EMULEX and SLI are trademarks of Emulex. |
| 5 | * www.emulex.com |
| 6 | * |
| 7 | * This software is available to you under a choice of one of two licenses. |
| 8 | * You may choose to be licensed under the terms of the GNU General Public |
| 9 | * License (GPL) Version 2, available from the file COPYING in the main |
| 10 | * directory of this source tree, or the BSD license below: |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * |
| 16 | * - Redistributions of source code must retain the above copyright notice, |
| 17 | * this list of conditions and the following disclaimer. |
| 18 | * |
| 19 | * - Redistributions in binary form must reproduce the above copyright |
| 20 | * notice, this list of conditions and the following disclaimer in |
| 21 | * the documentation and/or other materials provided with the distribution. |
| 22 | * |
| 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE |
| 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 30 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 31 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 32 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 33 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 34 | * |
| 35 | * Contact Information: |
| 36 | * linux-drivers@emulex.com |
| 37 | * |
| 38 | * Emulex |
| 39 | * 3333 Susan Street |
| 40 | * Costa Mesa, CA 92626 |
Devesh Sharma | 71ee673 | 2015-07-24 05:03:59 +0530 | [diff] [blame] | 41 | */ |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 42 | |
| 43 | #include <net/neighbour.h> |
| 44 | #include <net/netevent.h> |
| 45 | |
| 46 | #include <rdma/ib_addr.h> |
Mitesh Ahuja | cad1fbb0 | 2014-12-18 14:12:55 +0530 | [diff] [blame] | 47 | #include <rdma/ib_mad.h> |
Matan Barak | dbf727d | 2015-10-15 18:38:51 +0300 | [diff] [blame] | 48 | #include <rdma/ib_cache.h> |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 49 | |
| 50 | #include "ocrdma.h" |
| 51 | #include "ocrdma_verbs.h" |
| 52 | #include "ocrdma_ah.h" |
| 53 | #include "ocrdma_hw.h" |
Mitesh Ahuja | cad1fbb0 | 2014-12-18 14:12:55 +0530 | [diff] [blame] | 54 | #include "ocrdma_stats.h" |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 55 | |
Devesh Sharma | 0ea8726 | 2014-07-02 11:36:04 +0530 | [diff] [blame] | 56 | #define OCRDMA_VID_PCP_SHIFT 0xD |
| 57 | |
Devesh Sharma | 6b06266 | 2016-01-28 08:59:57 -0500 | [diff] [blame] | 58 | static u16 ocrdma_hdr_type_to_proto_num(int devid, u8 hdr_type) |
| 59 | { |
| 60 | switch (hdr_type) { |
| 61 | case OCRDMA_L3_TYPE_IB_GRH: |
Selvin Xavier | 69ae543 | 2016-12-19 11:28:46 -0800 | [diff] [blame] | 62 | return (u16)ETH_P_IBOE; |
Devesh Sharma | 6b06266 | 2016-01-28 08:59:57 -0500 | [diff] [blame] | 63 | case OCRDMA_L3_TYPE_IPV4: |
| 64 | return (u16)0x0800; |
| 65 | case OCRDMA_L3_TYPE_IPV6: |
| 66 | return (u16)0x86dd; |
| 67 | default: |
| 68 | pr_err("ocrdma%d: Invalid network header\n", devid); |
| 69 | return 0; |
| 70 | } |
| 71 | } |
| 72 | |
Naresh Gottumukkala | 1afc045 | 2013-08-07 12:52:33 +0530 | [diff] [blame] | 73 | static inline int set_av_attr(struct ocrdma_dev *dev, struct ocrdma_ah *ah, |
Dasaratharaman Chandramouli | 9089885 | 2017-04-29 14:41:18 -0400 | [diff] [blame] | 74 | struct rdma_ah_attr *attr, union ib_gid *sgid, |
Matan Barak | dbf727d | 2015-10-15 18:38:51 +0300 | [diff] [blame] | 75 | int pdid, bool *isvlan, u16 vlan_tag) |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 76 | { |
Markus Elfring | 0ca4c39 | 2015-12-26 18:18:18 +0100 | [diff] [blame] | 77 | int status; |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 78 | struct ocrdma_eth_vlan eth; |
| 79 | struct ocrdma_grh grh; |
| 80 | int eth_sz; |
Devesh Sharma | 6b06266 | 2016-01-28 08:59:57 -0500 | [diff] [blame] | 81 | u16 proto_num = 0; |
| 82 | u8 nxthdr = 0x11; |
| 83 | struct iphdr ipv4; |
| 84 | union { |
| 85 | struct sockaddr _sockaddr; |
| 86 | struct sockaddr_in _sockaddr_in; |
| 87 | struct sockaddr_in6 _sockaddr_in6; |
| 88 | } sgid_addr, dgid_addr; |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 89 | |
| 90 | memset(ð, 0, sizeof(eth)); |
| 91 | memset(&grh, 0, sizeof(grh)); |
| 92 | |
Devesh Sharma | 6b06266 | 2016-01-28 08:59:57 -0500 | [diff] [blame] | 93 | /* Protocol Number */ |
| 94 | proto_num = ocrdma_hdr_type_to_proto_num(dev->id, ah->hdr_type); |
| 95 | if (!proto_num) |
| 96 | return -EINVAL; |
Selvin Xavier | 69ae543 | 2016-12-19 11:28:46 -0800 | [diff] [blame] | 97 | nxthdr = (proto_num == ETH_P_IBOE) ? 0x1b : 0x11; |
devesh.sharma@emulex.com | 1be528b | 2014-09-05 15:09:48 +0530 | [diff] [blame] | 98 | /* VLAN */ |
Naresh Gottumukkala | 84b105d | 2013-08-26 15:27:50 +0530 | [diff] [blame] | 99 | if (!vlan_tag || (vlan_tag > 0xFFF)) |
| 100 | vlan_tag = dev->pvid; |
Devesh Sharma | 6f5deab | 2015-05-19 11:32:35 +0530 | [diff] [blame] | 101 | if (vlan_tag || dev->pfc_state) { |
| 102 | if (!vlan_tag) { |
| 103 | pr_err("ocrdma%d:Using VLAN with PFC is recommended\n", |
| 104 | dev->id); |
| 105 | pr_err("ocrdma%d:Using VLAN 0 for this connection\n", |
| 106 | dev->id); |
| 107 | } |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 108 | eth.eth_type = cpu_to_be16(0x8100); |
Devesh Sharma | 6b06266 | 2016-01-28 08:59:57 -0500 | [diff] [blame] | 109 | eth.roce_eth_type = cpu_to_be16(proto_num); |
Devesh Sharma | 0ea8726 | 2014-07-02 11:36:04 +0530 | [diff] [blame] | 110 | vlan_tag |= (dev->sl & 0x07) << OCRDMA_VID_PCP_SHIFT; |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 111 | eth.vlan_tag = cpu_to_be16(vlan_tag); |
| 112 | eth_sz = sizeof(struct ocrdma_eth_vlan); |
Devesh Sharma | 29565f2 | 2014-12-18 14:13:07 +0530 | [diff] [blame] | 113 | *isvlan = true; |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 114 | } else { |
Devesh Sharma | 6b06266 | 2016-01-28 08:59:57 -0500 | [diff] [blame] | 115 | eth.eth_type = cpu_to_be16(proto_num); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 116 | eth_sz = sizeof(struct ocrdma_eth_basic); |
| 117 | } |
devesh.sharma@emulex.com | 1be528b | 2014-09-05 15:09:48 +0530 | [diff] [blame] | 118 | /* MAC */ |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 119 | memcpy(ð.smac[0], &dev->nic_info.mac_addr[0], ETH_ALEN); |
Moni Shoua | 40aca6f | 2013-12-12 18:03:15 +0200 | [diff] [blame] | 120 | status = ocrdma_resolve_dmac(dev, attr, ð.dmac[0]); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 121 | if (status) |
| 122 | return status; |
devesh.sharma@emulex.com | 1be528b | 2014-09-05 15:09:48 +0530 | [diff] [blame] | 123 | ah->sgid_index = attr->grh.sgid_index; |
devesh.sharma@emulex.com | 1be528b | 2014-09-05 15:09:48 +0530 | [diff] [blame] | 124 | /* Eth HDR */ |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 125 | memcpy(&ah->av->eth_hdr, ð, eth_sz); |
Devesh Sharma | 6b06266 | 2016-01-28 08:59:57 -0500 | [diff] [blame] | 126 | if (ah->hdr_type == RDMA_NETWORK_IPV4) { |
| 127 | *((__be16 *)&ipv4) = htons((4 << 12) | (5 << 8) | |
| 128 | attr->grh.traffic_class); |
| 129 | ipv4.id = cpu_to_be16(pdid); |
| 130 | ipv4.frag_off = htons(IP_DF); |
| 131 | ipv4.tot_len = htons(0); |
| 132 | ipv4.ttl = attr->grh.hop_limit; |
| 133 | ipv4.protocol = nxthdr; |
| 134 | rdma_gid2ip(&sgid_addr._sockaddr, sgid); |
| 135 | ipv4.saddr = sgid_addr._sockaddr_in.sin_addr.s_addr; |
| 136 | rdma_gid2ip(&dgid_addr._sockaddr, &attr->grh.dgid); |
| 137 | ipv4.daddr = dgid_addr._sockaddr_in.sin_addr.s_addr; |
| 138 | memcpy((u8 *)ah->av + eth_sz, &ipv4, sizeof(struct iphdr)); |
| 139 | } else { |
| 140 | memcpy(&grh.sgid[0], sgid->raw, sizeof(union ib_gid)); |
| 141 | grh.tclass_flow = cpu_to_be32((6 << 28) | |
| 142 | (attr->grh.traffic_class << 24) | |
| 143 | attr->grh.flow_label); |
| 144 | memcpy(&grh.dgid[0], attr->grh.dgid.raw, |
| 145 | sizeof(attr->grh.dgid.raw)); |
| 146 | grh.pdid_hoplimit = cpu_to_be32((pdid << 16) | |
| 147 | (nxthdr << 8) | |
| 148 | attr->grh.hop_limit); |
| 149 | memcpy((u8 *)ah->av + eth_sz, &grh, sizeof(struct ocrdma_grh)); |
| 150 | } |
Devesh Sharma | 29565f2 | 2014-12-18 14:13:07 +0530 | [diff] [blame] | 151 | if (*isvlan) |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 152 | ah->av->valid |= OCRDMA_AV_VLAN_VALID; |
Devesh Sharma | fe5e8a1 | 2013-12-05 15:48:01 +0530 | [diff] [blame] | 153 | ah->av->valid = cpu_to_le32(ah->av->valid); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 154 | return status; |
| 155 | } |
| 156 | |
Dasaratharaman Chandramouli | 9089885 | 2017-04-29 14:41:18 -0400 | [diff] [blame] | 157 | struct ib_ah *ocrdma_create_ah(struct ib_pd *ibpd, struct rdma_ah_attr *attr, |
Moni Shoua | 477864c | 2016-11-23 08:23:24 +0200 | [diff] [blame] | 158 | struct ib_udata *udata) |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 159 | { |
| 160 | u32 *ahid_addr; |
| 161 | int status; |
| 162 | struct ocrdma_ah *ah; |
Matan Barak | dbf727d | 2015-10-15 18:38:51 +0300 | [diff] [blame] | 163 | bool isvlan = false; |
| 164 | u16 vlan_tag = 0xffff; |
| 165 | struct ib_gid_attr sgid_attr; |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 166 | struct ocrdma_pd *pd = get_ocrdma_pd(ibpd); |
Naresh Gottumukkala | f99b164 | 2013-08-07 12:52:32 +0530 | [diff] [blame] | 167 | struct ocrdma_dev *dev = get_ocrdma_dev(ibpd->device); |
devesh.sharma@emulex.com | 1be528b | 2014-09-05 15:09:48 +0530 | [diff] [blame] | 168 | union ib_gid sgid; |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 169 | |
| 170 | if (!(attr->ah_flags & IB_AH_GRH)) |
| 171 | return ERR_PTR(-EINVAL); |
| 172 | |
Selvin Xavier | 31dbdd9 | 2014-06-10 19:32:13 +0530 | [diff] [blame] | 173 | if (atomic_cmpxchg(&dev->update_sl, 1, 0)) |
| 174 | ocrdma_init_service_level(dev); |
Devesh Sharma | 6b06266 | 2016-01-28 08:59:57 -0500 | [diff] [blame] | 175 | |
Devesh Sharma | fad51b7 | 2014-02-04 11:57:10 +0530 | [diff] [blame] | 176 | ah = kzalloc(sizeof(*ah), GFP_ATOMIC); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 177 | if (!ah) |
| 178 | return ERR_PTR(-ENOMEM); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 179 | |
| 180 | status = ocrdma_alloc_av(dev, ah); |
| 181 | if (status) |
| 182 | goto av_err; |
devesh.sharma@emulex.com | 1be528b | 2014-09-05 15:09:48 +0530 | [diff] [blame] | 183 | |
Matan Barak | dbf727d | 2015-10-15 18:38:51 +0300 | [diff] [blame] | 184 | status = ib_get_cached_gid(&dev->ibdev, 1, attr->grh.sgid_index, &sgid, |
| 185 | &sgid_attr); |
devesh.sharma@emulex.com | 1be528b | 2014-09-05 15:09:48 +0530 | [diff] [blame] | 186 | if (status) { |
| 187 | pr_err("%s(): Failed to query sgid, status = %d\n", |
| 188 | __func__, status); |
| 189 | goto av_conf_err; |
| 190 | } |
Matan Barak | dbf727d | 2015-10-15 18:38:51 +0300 | [diff] [blame] | 191 | if (sgid_attr.ndev) { |
| 192 | if (is_vlan_dev(sgid_attr.ndev)) |
| 193 | vlan_tag = vlan_dev_vlan_id(sgid_attr.ndev); |
| 194 | dev_put(sgid_attr.ndev); |
| 195 | } |
Devesh Sharma | 6b06266 | 2016-01-28 08:59:57 -0500 | [diff] [blame] | 196 | /* Get network header type for this GID */ |
| 197 | ah->hdr_type = ib_gid_to_network_type(sgid_attr.gid_type, &sgid); |
devesh.sharma@emulex.com | 1be528b | 2014-09-05 15:09:48 +0530 | [diff] [blame] | 198 | |
Mitesh Ahuja | d27b2f1 | 2015-05-19 11:32:38 +0530 | [diff] [blame] | 199 | if ((pd->uctx) && |
| 200 | (!rdma_is_multicast_addr((struct in6_addr *)attr->grh.dgid.raw)) && |
| 201 | (!rdma_link_local_addr((struct in6_addr *)attr->grh.dgid.raw))) { |
Matan Barak | f7f4b23e | 2016-01-04 10:49:53 +0200 | [diff] [blame] | 202 | status = rdma_addr_find_l2_eth_by_grh(&sgid, &attr->grh.dgid, |
| 203 | attr->dmac, &vlan_tag, |
Matan Barak | c3efe75 | 2016-01-04 10:49:54 +0200 | [diff] [blame] | 204 | &sgid_attr.ndev->ifindex, |
| 205 | NULL); |
devesh.sharma@emulex.com | 1be528b | 2014-09-05 15:09:48 +0530 | [diff] [blame] | 206 | if (status) { |
| 207 | pr_err("%s(): Failed to resolve dmac from gid." |
| 208 | "status = %d\n", __func__, status); |
| 209 | goto av_conf_err; |
| 210 | } |
| 211 | } |
| 212 | |
Matan Barak | dbf727d | 2015-10-15 18:38:51 +0300 | [diff] [blame] | 213 | status = set_av_attr(dev, ah, attr, &sgid, pd->id, &isvlan, vlan_tag); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 214 | if (status) |
| 215 | goto av_conf_err; |
| 216 | |
| 217 | /* if pd is for the user process, pass the ah_id to user space */ |
| 218 | if ((pd->uctx) && (pd->uctx->ah_tbl.va)) { |
| 219 | ahid_addr = pd->uctx->ah_tbl.va + attr->dlid; |
Devesh Sharma | 29565f2 | 2014-12-18 14:13:07 +0530 | [diff] [blame] | 220 | *ahid_addr = 0; |
| 221 | *ahid_addr |= ah->id & OCRDMA_AH_ID_MASK; |
Devesh Sharma | 834d16d | 2016-01-28 08:59:59 -0500 | [diff] [blame] | 222 | if (ocrdma_is_udp_encap_supported(dev)) { |
| 223 | *ahid_addr |= ((u32)ah->hdr_type & |
| 224 | OCRDMA_AH_L3_TYPE_MASK) << |
| 225 | OCRDMA_AH_L3_TYPE_SHIFT; |
| 226 | } |
Devesh Sharma | 29565f2 | 2014-12-18 14:13:07 +0530 | [diff] [blame] | 227 | if (isvlan) |
| 228 | *ahid_addr |= (OCRDMA_AH_VLAN_VALID_MASK << |
| 229 | OCRDMA_AH_VLAN_VALID_SHIFT); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 230 | } |
Devesh Sharma | 29565f2 | 2014-12-18 14:13:07 +0530 | [diff] [blame] | 231 | |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 232 | return &ah->ibah; |
| 233 | |
| 234 | av_conf_err: |
| 235 | ocrdma_free_av(dev, ah); |
| 236 | av_err: |
| 237 | kfree(ah); |
| 238 | return ERR_PTR(status); |
| 239 | } |
| 240 | |
| 241 | int ocrdma_destroy_ah(struct ib_ah *ibah) |
| 242 | { |
| 243 | struct ocrdma_ah *ah = get_ocrdma_ah(ibah); |
Naresh Gottumukkala | 1afc045 | 2013-08-07 12:52:33 +0530 | [diff] [blame] | 244 | struct ocrdma_dev *dev = get_ocrdma_dev(ibah->device); |
| 245 | |
| 246 | ocrdma_free_av(dev, ah); |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 247 | kfree(ah); |
| 248 | return 0; |
| 249 | } |
| 250 | |
Dasaratharaman Chandramouli | 9089885 | 2017-04-29 14:41:18 -0400 | [diff] [blame] | 251 | int ocrdma_query_ah(struct ib_ah *ibah, struct rdma_ah_attr *attr) |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 252 | { |
| 253 | struct ocrdma_ah *ah = get_ocrdma_ah(ibah); |
| 254 | struct ocrdma_av *av = ah->av; |
| 255 | struct ocrdma_grh *grh; |
| 256 | attr->ah_flags |= IB_AH_GRH; |
devesh.sharma@emulex.com | f0c2c22 | 2014-09-05 15:09:49 +0530 | [diff] [blame] | 257 | if (ah->av->valid & OCRDMA_AV_VALID) { |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 258 | grh = (struct ocrdma_grh *)((u8 *)ah->av + |
| 259 | sizeof(struct ocrdma_eth_vlan)); |
| 260 | attr->sl = be16_to_cpu(av->eth_hdr.vlan_tag) >> 13; |
| 261 | } else { |
| 262 | grh = (struct ocrdma_grh *)((u8 *)ah->av + |
| 263 | sizeof(struct ocrdma_eth_basic)); |
| 264 | attr->sl = 0; |
| 265 | } |
| 266 | memcpy(&attr->grh.dgid.raw[0], &grh->dgid[0], sizeof(grh->dgid)); |
| 267 | attr->grh.sgid_index = ah->sgid_index; |
| 268 | attr->grh.hop_limit = be32_to_cpu(grh->pdid_hoplimit) & 0xff; |
| 269 | attr->grh.traffic_class = be32_to_cpu(grh->tclass_flow) >> 24; |
| 270 | attr->grh.flow_label = be32_to_cpu(grh->tclass_flow) & 0x00ffffffff; |
| 271 | return 0; |
| 272 | } |
| 273 | |
Dasaratharaman Chandramouli | 9089885 | 2017-04-29 14:41:18 -0400 | [diff] [blame] | 274 | int ocrdma_modify_ah(struct ib_ah *ibah, struct rdma_ah_attr *attr) |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 275 | { |
| 276 | /* modify_ah is unsupported */ |
| 277 | return -ENOSYS; |
| 278 | } |
| 279 | |
| 280 | int ocrdma_process_mad(struct ib_device *ibdev, |
| 281 | int process_mad_flags, |
| 282 | u8 port_num, |
Ira Weiny | a97e2d8 | 2015-05-31 17:15:30 -0400 | [diff] [blame] | 283 | const struct ib_wc *in_wc, |
| 284 | const struct ib_grh *in_grh, |
Ira Weiny | 4cd7c94 | 2015-06-06 14:38:31 -0400 | [diff] [blame] | 285 | const struct ib_mad_hdr *in, size_t in_mad_size, |
| 286 | struct ib_mad_hdr *out, size_t *out_mad_size, |
| 287 | u16 *out_mad_pkey_index) |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 288 | { |
Mitesh Ahuja | cad1fbb0 | 2014-12-18 14:12:55 +0530 | [diff] [blame] | 289 | int status; |
| 290 | struct ocrdma_dev *dev; |
Ira Weiny | 4cd7c94 | 2015-06-06 14:38:31 -0400 | [diff] [blame] | 291 | const struct ib_mad *in_mad = (const struct ib_mad *)in; |
| 292 | struct ib_mad *out_mad = (struct ib_mad *)out; |
| 293 | |
Ira Weiny | 3b8ab70 | 2015-06-25 09:52:50 -0400 | [diff] [blame] | 294 | if (WARN_ON_ONCE(in_mad_size != sizeof(*in_mad) || |
| 295 | *out_mad_size != sizeof(*out_mad))) |
| 296 | return IB_MAD_RESULT_FAILURE; |
Mitesh Ahuja | cad1fbb0 | 2014-12-18 14:12:55 +0530 | [diff] [blame] | 297 | |
| 298 | switch (in_mad->mad_hdr.mgmt_class) { |
| 299 | case IB_MGMT_CLASS_PERF_MGMT: |
| 300 | dev = get_ocrdma_dev(ibdev); |
| 301 | if (!ocrdma_pma_counters(dev, out_mad)) |
| 302 | status = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY; |
| 303 | else |
| 304 | status = IB_MAD_RESULT_SUCCESS; |
| 305 | break; |
| 306 | default: |
| 307 | status = IB_MAD_RESULT_SUCCESS; |
| 308 | break; |
| 309 | } |
| 310 | return status; |
Parav Pandit | fe2caef | 2012-03-21 04:09:06 +0530 | [diff] [blame] | 311 | } |