Commit | Line | Data |
---|---|---|
71ee6730 DS |
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. | |
fe2caefc PP |
34 | * |
35 | * Contact Information: | |
36 | * linux-drivers@emulex.com | |
37 | * | |
38 | * Emulex | |
39 | * 3333 Susan Street | |
40 | * Costa Mesa, CA 92626 | |
71ee6730 | 41 | */ |
fe2caefc PP |
42 | |
43 | #include <net/neighbour.h> | |
44 | #include <net/netevent.h> | |
45 | ||
46 | #include <rdma/ib_addr.h> | |
cad1fbb0 | 47 | #include <rdma/ib_mad.h> |
dbf727de | 48 | #include <rdma/ib_cache.h> |
fe2caefc PP |
49 | |
50 | #include "ocrdma.h" | |
51 | #include "ocrdma_verbs.h" | |
52 | #include "ocrdma_ah.h" | |
53 | #include "ocrdma_hw.h" | |
cad1fbb0 | 54 | #include "ocrdma_stats.h" |
fe2caefc | 55 | |
0ea87262 DS |
56 | #define OCRDMA_VID_PCP_SHIFT 0xD |
57 | ||
1afc0454 | 58 | static inline int set_av_attr(struct ocrdma_dev *dev, struct ocrdma_ah *ah, |
29565f2f | 59 | struct ib_ah_attr *attr, union ib_gid *sgid, |
dbf727de | 60 | int pdid, bool *isvlan, u16 vlan_tag) |
fe2caefc PP |
61 | { |
62 | int status = 0; | |
fe2caefc PP |
63 | struct ocrdma_eth_vlan eth; |
64 | struct ocrdma_grh grh; | |
65 | int eth_sz; | |
66 | ||
67 | memset(ð, 0, sizeof(eth)); | |
68 | memset(&grh, 0, sizeof(grh)); | |
69 | ||
1be528bc | 70 | /* VLAN */ |
84b105db NG |
71 | if (!vlan_tag || (vlan_tag > 0xFFF)) |
72 | vlan_tag = dev->pvid; | |
6f5deab0 DS |
73 | if (vlan_tag || dev->pfc_state) { |
74 | if (!vlan_tag) { | |
75 | pr_err("ocrdma%d:Using VLAN with PFC is recommended\n", | |
76 | dev->id); | |
77 | pr_err("ocrdma%d:Using VLAN 0 for this connection\n", | |
78 | dev->id); | |
79 | } | |
fe2caefc PP |
80 | eth.eth_type = cpu_to_be16(0x8100); |
81 | eth.roce_eth_type = cpu_to_be16(OCRDMA_ROCE_ETH_TYPE); | |
0ea87262 | 82 | vlan_tag |= (dev->sl & 0x07) << OCRDMA_VID_PCP_SHIFT; |
fe2caefc PP |
83 | eth.vlan_tag = cpu_to_be16(vlan_tag); |
84 | eth_sz = sizeof(struct ocrdma_eth_vlan); | |
29565f2f | 85 | *isvlan = true; |
fe2caefc PP |
86 | } else { |
87 | eth.eth_type = cpu_to_be16(OCRDMA_ROCE_ETH_TYPE); | |
88 | eth_sz = sizeof(struct ocrdma_eth_basic); | |
89 | } | |
1be528bc | 90 | /* MAC */ |
fe2caefc | 91 | memcpy(ð.smac[0], &dev->nic_info.mac_addr[0], ETH_ALEN); |
40aca6ff | 92 | status = ocrdma_resolve_dmac(dev, attr, ð.dmac[0]); |
fe2caefc PP |
93 | if (status) |
94 | return status; | |
1be528bc | 95 | ah->sgid_index = attr->grh.sgid_index; |
96 | memcpy(&grh.sgid[0], sgid->raw, sizeof(union ib_gid)); | |
97 | memcpy(&grh.dgid[0], attr->grh.dgid.raw, sizeof(attr->grh.dgid.raw)); | |
fe2caefc PP |
98 | |
99 | grh.tclass_flow = cpu_to_be32((6 << 28) | | |
100 | (attr->grh.traffic_class << 24) | | |
101 | attr->grh.flow_label); | |
102 | /* 0x1b is next header value in GRH */ | |
103 | grh.pdid_hoplimit = cpu_to_be32((pdid << 16) | | |
104 | (0x1b << 8) | attr->grh.hop_limit); | |
1be528bc | 105 | /* Eth HDR */ |
fe2caefc PP |
106 | memcpy(&ah->av->eth_hdr, ð, eth_sz); |
107 | memcpy((u8 *)ah->av + eth_sz, &grh, sizeof(struct ocrdma_grh)); | |
29565f2f | 108 | if (*isvlan) |
fe2caefc | 109 | ah->av->valid |= OCRDMA_AV_VLAN_VALID; |
fe5e8a1a | 110 | ah->av->valid = cpu_to_le32(ah->av->valid); |
fe2caefc PP |
111 | return status; |
112 | } | |
113 | ||
114 | struct ib_ah *ocrdma_create_ah(struct ib_pd *ibpd, struct ib_ah_attr *attr) | |
115 | { | |
116 | u32 *ahid_addr; | |
117 | int status; | |
118 | struct ocrdma_ah *ah; | |
dbf727de MB |
119 | bool isvlan = false; |
120 | u16 vlan_tag = 0xffff; | |
121 | struct ib_gid_attr sgid_attr; | |
fe2caefc | 122 | struct ocrdma_pd *pd = get_ocrdma_pd(ibpd); |
f99b1649 | 123 | struct ocrdma_dev *dev = get_ocrdma_dev(ibpd->device); |
1be528bc | 124 | union ib_gid sgid; |
fe2caefc PP |
125 | |
126 | if (!(attr->ah_flags & IB_AH_GRH)) | |
127 | return ERR_PTR(-EINVAL); | |
128 | ||
31dbdd9a SX |
129 | if (atomic_cmpxchg(&dev->update_sl, 1, 0)) |
130 | ocrdma_init_service_level(dev); | |
fad51b7d | 131 | ah = kzalloc(sizeof(*ah), GFP_ATOMIC); |
fe2caefc PP |
132 | if (!ah) |
133 | return ERR_PTR(-ENOMEM); | |
fe2caefc PP |
134 | |
135 | status = ocrdma_alloc_av(dev, ah); | |
136 | if (status) | |
137 | goto av_err; | |
1be528bc | 138 | |
dbf727de MB |
139 | status = ib_get_cached_gid(&dev->ibdev, 1, attr->grh.sgid_index, &sgid, |
140 | &sgid_attr); | |
1be528bc | 141 | if (status) { |
142 | pr_err("%s(): Failed to query sgid, status = %d\n", | |
143 | __func__, status); | |
144 | goto av_conf_err; | |
145 | } | |
dbf727de MB |
146 | if (sgid_attr.ndev) { |
147 | if (is_vlan_dev(sgid_attr.ndev)) | |
148 | vlan_tag = vlan_dev_vlan_id(sgid_attr.ndev); | |
149 | dev_put(sgid_attr.ndev); | |
150 | } | |
1be528bc | 151 | |
d27b2f15 MA |
152 | if ((pd->uctx) && |
153 | (!rdma_is_multicast_addr((struct in6_addr *)attr->grh.dgid.raw)) && | |
154 | (!rdma_link_local_addr((struct in6_addr *)attr->grh.dgid.raw))) { | |
1be528bc | 155 | status = rdma_addr_find_dmac_by_grh(&sgid, &attr->grh.dgid, |
dbf727de MB |
156 | attr->dmac, &vlan_tag, |
157 | sgid_attr.ndev->ifindex); | |
1be528bc | 158 | if (status) { |
159 | pr_err("%s(): Failed to resolve dmac from gid." | |
160 | "status = %d\n", __func__, status); | |
161 | goto av_conf_err; | |
162 | } | |
163 | } | |
164 | ||
dbf727de | 165 | status = set_av_attr(dev, ah, attr, &sgid, pd->id, &isvlan, vlan_tag); |
fe2caefc PP |
166 | if (status) |
167 | goto av_conf_err; | |
168 | ||
169 | /* if pd is for the user process, pass the ah_id to user space */ | |
170 | if ((pd->uctx) && (pd->uctx->ah_tbl.va)) { | |
171 | ahid_addr = pd->uctx->ah_tbl.va + attr->dlid; | |
29565f2f DS |
172 | *ahid_addr = 0; |
173 | *ahid_addr |= ah->id & OCRDMA_AH_ID_MASK; | |
174 | if (isvlan) | |
175 | *ahid_addr |= (OCRDMA_AH_VLAN_VALID_MASK << | |
176 | OCRDMA_AH_VLAN_VALID_SHIFT); | |
fe2caefc | 177 | } |
29565f2f | 178 | |
fe2caefc PP |
179 | return &ah->ibah; |
180 | ||
181 | av_conf_err: | |
182 | ocrdma_free_av(dev, ah); | |
183 | av_err: | |
184 | kfree(ah); | |
185 | return ERR_PTR(status); | |
186 | } | |
187 | ||
188 | int ocrdma_destroy_ah(struct ib_ah *ibah) | |
189 | { | |
190 | struct ocrdma_ah *ah = get_ocrdma_ah(ibah); | |
1afc0454 NG |
191 | struct ocrdma_dev *dev = get_ocrdma_dev(ibah->device); |
192 | ||
193 | ocrdma_free_av(dev, ah); | |
fe2caefc PP |
194 | kfree(ah); |
195 | return 0; | |
196 | } | |
197 | ||
198 | int ocrdma_query_ah(struct ib_ah *ibah, struct ib_ah_attr *attr) | |
199 | { | |
200 | struct ocrdma_ah *ah = get_ocrdma_ah(ibah); | |
201 | struct ocrdma_av *av = ah->av; | |
202 | struct ocrdma_grh *grh; | |
203 | attr->ah_flags |= IB_AH_GRH; | |
f0c2c225 | 204 | if (ah->av->valid & OCRDMA_AV_VALID) { |
fe2caefc PP |
205 | grh = (struct ocrdma_grh *)((u8 *)ah->av + |
206 | sizeof(struct ocrdma_eth_vlan)); | |
207 | attr->sl = be16_to_cpu(av->eth_hdr.vlan_tag) >> 13; | |
208 | } else { | |
209 | grh = (struct ocrdma_grh *)((u8 *)ah->av + | |
210 | sizeof(struct ocrdma_eth_basic)); | |
211 | attr->sl = 0; | |
212 | } | |
213 | memcpy(&attr->grh.dgid.raw[0], &grh->dgid[0], sizeof(grh->dgid)); | |
214 | attr->grh.sgid_index = ah->sgid_index; | |
215 | attr->grh.hop_limit = be32_to_cpu(grh->pdid_hoplimit) & 0xff; | |
216 | attr->grh.traffic_class = be32_to_cpu(grh->tclass_flow) >> 24; | |
217 | attr->grh.flow_label = be32_to_cpu(grh->tclass_flow) & 0x00ffffffff; | |
218 | return 0; | |
219 | } | |
220 | ||
221 | int ocrdma_modify_ah(struct ib_ah *ibah, struct ib_ah_attr *attr) | |
222 | { | |
223 | /* modify_ah is unsupported */ | |
224 | return -ENOSYS; | |
225 | } | |
226 | ||
227 | int ocrdma_process_mad(struct ib_device *ibdev, | |
228 | int process_mad_flags, | |
229 | u8 port_num, | |
a97e2d86 IW |
230 | const struct ib_wc *in_wc, |
231 | const struct ib_grh *in_grh, | |
4cd7c947 IW |
232 | const struct ib_mad_hdr *in, size_t in_mad_size, |
233 | struct ib_mad_hdr *out, size_t *out_mad_size, | |
234 | u16 *out_mad_pkey_index) | |
fe2caefc | 235 | { |
cad1fbb0 MA |
236 | int status; |
237 | struct ocrdma_dev *dev; | |
4cd7c947 IW |
238 | const struct ib_mad *in_mad = (const struct ib_mad *)in; |
239 | struct ib_mad *out_mad = (struct ib_mad *)out; | |
240 | ||
3b8ab700 IW |
241 | if (WARN_ON_ONCE(in_mad_size != sizeof(*in_mad) || |
242 | *out_mad_size != sizeof(*out_mad))) | |
243 | return IB_MAD_RESULT_FAILURE; | |
cad1fbb0 MA |
244 | |
245 | switch (in_mad->mad_hdr.mgmt_class) { | |
246 | case IB_MGMT_CLASS_PERF_MGMT: | |
247 | dev = get_ocrdma_dev(ibdev); | |
248 | if (!ocrdma_pma_counters(dev, out_mad)) | |
249 | status = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY; | |
250 | else | |
251 | status = IB_MAD_RESULT_SUCCESS; | |
252 | break; | |
253 | default: | |
254 | status = IB_MAD_RESULT_SUCCESS; | |
255 | break; | |
256 | } | |
257 | return status; | |
fe2caefc | 258 | } |