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