blob: b80b57b40043bb3c458e21402c7aa73a973926ee [file] [log] [blame]
Parav Panditfe2caef2012-03-21 04:09:06 +05301/*******************************************************************
2 * This file is part of the Emulex RoCE Device Driver for *
3 * RoCE (RDMA over Converged Ethernet) adapters. *
4 * Copyright (C) 2008-2012 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com *
7 * *
8 * This program is free software; you can redistribute it and/or *
9 * modify it under the terms of version 2 of the GNU General *
10 * Public License as published by the Free Software Foundation. *
11 * This program is distributed in the hope that it will be useful. *
12 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
13 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
14 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
15 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
16 * TO BE LEGALLY INVALID. See the GNU General Public License for *
17 * more details, a copy of which can be found in the file COPYING *
18 * included with this package. *
19 *
20 * Contact Information:
21 * linux-drivers@emulex.com
22 *
23 * Emulex
24 * 3333 Susan Street
25 * Costa Mesa, CA 92626
26 *******************************************************************/
27
28#include <net/neighbour.h>
29#include <net/netevent.h>
30
31#include <rdma/ib_addr.h>
Mitesh Ahujacad1fbb2014-12-18 14:12:55 +053032#include <rdma/ib_mad.h>
Parav Panditfe2caef2012-03-21 04:09:06 +053033
34#include "ocrdma.h"
35#include "ocrdma_verbs.h"
36#include "ocrdma_ah.h"
37#include "ocrdma_hw.h"
Mitesh Ahujacad1fbb2014-12-18 14:12:55 +053038#include "ocrdma_stats.h"
Parav Panditfe2caef2012-03-21 04:09:06 +053039
Devesh Sharma0ea87262014-07-02 11:36:04 +053040#define OCRDMA_VID_PCP_SHIFT 0xD
41
Naresh Gottumukkala1afc0452013-08-07 12:52:33 +053042static inline int set_av_attr(struct ocrdma_dev *dev, struct ocrdma_ah *ah,
devesh.sharma@emulex.com1be528b2014-09-05 15:09:48 +053043 struct ib_ah_attr *attr, union ib_gid *sgid, int pdid)
Parav Panditfe2caef2012-03-21 04:09:06 +053044{
45 int status = 0;
46 u16 vlan_tag; bool vlan_enabled = false;
Parav Panditfe2caef2012-03-21 04:09:06 +053047 struct ocrdma_eth_vlan eth;
48 struct ocrdma_grh grh;
49 int eth_sz;
50
51 memset(&eth, 0, sizeof(eth));
52 memset(&grh, 0, sizeof(grh));
53
devesh.sharma@emulex.com1be528b2014-09-05 15:09:48 +053054 /* VLAN */
Moni Shoua40aca6f2013-12-12 18:03:15 +020055 vlan_tag = attr->vlan_id;
Naresh Gottumukkala84b105d2013-08-26 15:27:50 +053056 if (!vlan_tag || (vlan_tag > 0xFFF))
57 vlan_tag = dev->pvid;
Parav Panditfe2caef2012-03-21 04:09:06 +053058 if (vlan_tag && (vlan_tag < 0x1000)) {
59 eth.eth_type = cpu_to_be16(0x8100);
60 eth.roce_eth_type = cpu_to_be16(OCRDMA_ROCE_ETH_TYPE);
Devesh Sharma0ea87262014-07-02 11:36:04 +053061 vlan_tag |= (dev->sl & 0x07) << OCRDMA_VID_PCP_SHIFT;
Parav Panditfe2caef2012-03-21 04:09:06 +053062 eth.vlan_tag = cpu_to_be16(vlan_tag);
63 eth_sz = sizeof(struct ocrdma_eth_vlan);
64 vlan_enabled = true;
65 } else {
66 eth.eth_type = cpu_to_be16(OCRDMA_ROCE_ETH_TYPE);
67 eth_sz = sizeof(struct ocrdma_eth_basic);
68 }
devesh.sharma@emulex.com1be528b2014-09-05 15:09:48 +053069 /* MAC */
Parav Panditfe2caef2012-03-21 04:09:06 +053070 memcpy(&eth.smac[0], &dev->nic_info.mac_addr[0], ETH_ALEN);
Moni Shoua40aca6f2013-12-12 18:03:15 +020071 status = ocrdma_resolve_dmac(dev, attr, &eth.dmac[0]);
Parav Panditfe2caef2012-03-21 04:09:06 +053072 if (status)
73 return status;
devesh.sharma@emulex.com1be528b2014-09-05 15:09:48 +053074 ah->sgid_index = attr->grh.sgid_index;
75 memcpy(&grh.sgid[0], sgid->raw, sizeof(union ib_gid));
76 memcpy(&grh.dgid[0], attr->grh.dgid.raw, sizeof(attr->grh.dgid.raw));
Parav Panditfe2caef2012-03-21 04:09:06 +053077
78 grh.tclass_flow = cpu_to_be32((6 << 28) |
79 (attr->grh.traffic_class << 24) |
80 attr->grh.flow_label);
81 /* 0x1b is next header value in GRH */
82 grh.pdid_hoplimit = cpu_to_be32((pdid << 16) |
83 (0x1b << 8) | attr->grh.hop_limit);
devesh.sharma@emulex.com1be528b2014-09-05 15:09:48 +053084 /* Eth HDR */
Parav Panditfe2caef2012-03-21 04:09:06 +053085 memcpy(&ah->av->eth_hdr, &eth, eth_sz);
86 memcpy((u8 *)ah->av + eth_sz, &grh, sizeof(struct ocrdma_grh));
87 if (vlan_enabled)
88 ah->av->valid |= OCRDMA_AV_VLAN_VALID;
Devesh Sharmafe5e8a12013-12-05 15:48:01 +053089 ah->av->valid = cpu_to_le32(ah->av->valid);
Parav Panditfe2caef2012-03-21 04:09:06 +053090 return status;
91}
92
93struct ib_ah *ocrdma_create_ah(struct ib_pd *ibpd, struct ib_ah_attr *attr)
94{
95 u32 *ahid_addr;
96 int status;
97 struct ocrdma_ah *ah;
98 struct ocrdma_pd *pd = get_ocrdma_pd(ibpd);
Naresh Gottumukkalaf99b1642013-08-07 12:52:32 +053099 struct ocrdma_dev *dev = get_ocrdma_dev(ibpd->device);
devesh.sharma@emulex.com1be528b2014-09-05 15:09:48 +0530100 union ib_gid sgid;
Parav Panditfe2caef2012-03-21 04:09:06 +0530101
102 if (!(attr->ah_flags & IB_AH_GRH))
103 return ERR_PTR(-EINVAL);
104
Selvin Xavier31dbdd92014-06-10 19:32:13 +0530105 if (atomic_cmpxchg(&dev->update_sl, 1, 0))
106 ocrdma_init_service_level(dev);
Devesh Sharmafad51b72014-02-04 11:57:10 +0530107 ah = kzalloc(sizeof(*ah), GFP_ATOMIC);
Parav Panditfe2caef2012-03-21 04:09:06 +0530108 if (!ah)
109 return ERR_PTR(-ENOMEM);
Parav Panditfe2caef2012-03-21 04:09:06 +0530110
111 status = ocrdma_alloc_av(dev, ah);
112 if (status)
113 goto av_err;
devesh.sharma@emulex.com1be528b2014-09-05 15:09:48 +0530114
115 status = ocrdma_query_gid(&dev->ibdev, 1, attr->grh.sgid_index, &sgid);
116 if (status) {
117 pr_err("%s(): Failed to query sgid, status = %d\n",
118 __func__, status);
119 goto av_conf_err;
120 }
121
Devesh Sharmae5f05082014-11-24 10:03:39 +0530122 if (pd->uctx) {
devesh.sharma@emulex.com1be528b2014-09-05 15:09:48 +0530123 status = rdma_addr_find_dmac_by_grh(&sgid, &attr->grh.dgid,
124 attr->dmac, &attr->vlan_id);
125 if (status) {
126 pr_err("%s(): Failed to resolve dmac from gid."
127 "status = %d\n", __func__, status);
128 goto av_conf_err;
129 }
130 }
131
132 status = set_av_attr(dev, ah, attr, &sgid, pd->id);
Parav Panditfe2caef2012-03-21 04:09:06 +0530133 if (status)
134 goto av_conf_err;
135
136 /* if pd is for the user process, pass the ah_id to user space */
137 if ((pd->uctx) && (pd->uctx->ah_tbl.va)) {
138 ahid_addr = pd->uctx->ah_tbl.va + attr->dlid;
139 *ahid_addr = ah->id;
140 }
141 return &ah->ibah;
142
143av_conf_err:
144 ocrdma_free_av(dev, ah);
145av_err:
146 kfree(ah);
147 return ERR_PTR(status);
148}
149
150int ocrdma_destroy_ah(struct ib_ah *ibah)
151{
152 struct ocrdma_ah *ah = get_ocrdma_ah(ibah);
Naresh Gottumukkala1afc0452013-08-07 12:52:33 +0530153 struct ocrdma_dev *dev = get_ocrdma_dev(ibah->device);
154
155 ocrdma_free_av(dev, ah);
Parav Panditfe2caef2012-03-21 04:09:06 +0530156 kfree(ah);
157 return 0;
158}
159
160int ocrdma_query_ah(struct ib_ah *ibah, struct ib_ah_attr *attr)
161{
162 struct ocrdma_ah *ah = get_ocrdma_ah(ibah);
163 struct ocrdma_av *av = ah->av;
164 struct ocrdma_grh *grh;
165 attr->ah_flags |= IB_AH_GRH;
devesh.sharma@emulex.comf0c2c222014-09-05 15:09:49 +0530166 if (ah->av->valid & OCRDMA_AV_VALID) {
Parav Panditfe2caef2012-03-21 04:09:06 +0530167 grh = (struct ocrdma_grh *)((u8 *)ah->av +
168 sizeof(struct ocrdma_eth_vlan));
169 attr->sl = be16_to_cpu(av->eth_hdr.vlan_tag) >> 13;
170 } else {
171 grh = (struct ocrdma_grh *)((u8 *)ah->av +
172 sizeof(struct ocrdma_eth_basic));
173 attr->sl = 0;
174 }
175 memcpy(&attr->grh.dgid.raw[0], &grh->dgid[0], sizeof(grh->dgid));
176 attr->grh.sgid_index = ah->sgid_index;
177 attr->grh.hop_limit = be32_to_cpu(grh->pdid_hoplimit) & 0xff;
178 attr->grh.traffic_class = be32_to_cpu(grh->tclass_flow) >> 24;
179 attr->grh.flow_label = be32_to_cpu(grh->tclass_flow) & 0x00ffffffff;
180 return 0;
181}
182
183int ocrdma_modify_ah(struct ib_ah *ibah, struct ib_ah_attr *attr)
184{
185 /* modify_ah is unsupported */
186 return -ENOSYS;
187}
188
189int ocrdma_process_mad(struct ib_device *ibdev,
190 int process_mad_flags,
191 u8 port_num,
192 struct ib_wc *in_wc,
193 struct ib_grh *in_grh,
194 struct ib_mad *in_mad, struct ib_mad *out_mad)
195{
Mitesh Ahujacad1fbb2014-12-18 14:12:55 +0530196 int status;
197 struct ocrdma_dev *dev;
198
199 switch (in_mad->mad_hdr.mgmt_class) {
200 case IB_MGMT_CLASS_PERF_MGMT:
201 dev = get_ocrdma_dev(ibdev);
202 if (!ocrdma_pma_counters(dev, out_mad))
203 status = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
204 else
205 status = IB_MAD_RESULT_SUCCESS;
206 break;
207 default:
208 status = IB_MAD_RESULT_SUCCESS;
209 break;
210 }
211 return status;
Parav Panditfe2caef2012-03-21 04:09:06 +0530212}