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. *
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. *
20 * Contact Information:
21 * linux-drivers@emulex.com
25 * Costa Mesa, CA 92626
26 *******************************************************************/
28 #include <net/neighbour.h>
29 #include <net/netevent.h>
31 #include <rdma/ib_addr.h>
34 #include "ocrdma_verbs.h"
35 #include "ocrdma_ah.h"
36 #include "ocrdma_hw.h"
38 #define OCRDMA_VID_PCP_SHIFT 0xD
40 static inline int set_av_attr(struct ocrdma_dev *dev, struct ocrdma_ah *ah,
41 struct ib_ah_attr *attr, union ib_gid *sgid, int pdid)
44 u16 vlan_tag; bool vlan_enabled = false;
45 struct ocrdma_eth_vlan eth;
46 struct ocrdma_grh grh;
49 memset(ð, 0, sizeof(eth));
50 memset(&grh, 0, sizeof(grh));
53 vlan_tag = attr->vlan_id;
54 if (!vlan_tag || (vlan_tag > 0xFFF))
56 if (vlan_tag && (vlan_tag < 0x1000)) {
57 eth.eth_type = cpu_to_be16(0x8100);
58 eth.roce_eth_type = cpu_to_be16(OCRDMA_ROCE_ETH_TYPE);
59 vlan_tag |= (dev->sl & 0x07) << OCRDMA_VID_PCP_SHIFT;
60 eth.vlan_tag = cpu_to_be16(vlan_tag);
61 eth_sz = sizeof(struct ocrdma_eth_vlan);
64 eth.eth_type = cpu_to_be16(OCRDMA_ROCE_ETH_TYPE);
65 eth_sz = sizeof(struct ocrdma_eth_basic);
68 memcpy(ð.smac[0], &dev->nic_info.mac_addr[0], ETH_ALEN);
69 status = ocrdma_resolve_dmac(dev, attr, ð.dmac[0]);
72 ah->sgid_index = attr->grh.sgid_index;
73 memcpy(&grh.sgid[0], sgid->raw, sizeof(union ib_gid));
74 memcpy(&grh.dgid[0], attr->grh.dgid.raw, sizeof(attr->grh.dgid.raw));
76 grh.tclass_flow = cpu_to_be32((6 << 28) |
77 (attr->grh.traffic_class << 24) |
78 attr->grh.flow_label);
79 /* 0x1b is next header value in GRH */
80 grh.pdid_hoplimit = cpu_to_be32((pdid << 16) |
81 (0x1b << 8) | attr->grh.hop_limit);
83 memcpy(&ah->av->eth_hdr, ð, eth_sz);
84 memcpy((u8 *)ah->av + eth_sz, &grh, sizeof(struct ocrdma_grh));
86 ah->av->valid |= OCRDMA_AV_VLAN_VALID;
87 ah->av->valid = cpu_to_le32(ah->av->valid);
91 struct ib_ah *ocrdma_create_ah(struct ib_pd *ibpd, struct ib_ah_attr *attr)
96 struct ocrdma_pd *pd = get_ocrdma_pd(ibpd);
97 struct ocrdma_dev *dev = get_ocrdma_dev(ibpd->device);
101 if (!(attr->ah_flags & IB_AH_GRH))
102 return ERR_PTR(-EINVAL);
104 if (atomic_cmpxchg(&dev->update_sl, 1, 0))
105 ocrdma_init_service_level(dev);
106 ah = kzalloc(sizeof(*ah), GFP_ATOMIC);
108 return ERR_PTR(-ENOMEM);
110 status = ocrdma_alloc_av(dev, ah);
114 status = ocrdma_query_gid(&dev->ibdev, 1, attr->grh.sgid_index, &sgid);
116 pr_err("%s(): Failed to query sgid, status = %d\n",
121 memset(&zmac, 0, ETH_ALEN);
123 memcmp(attr->dmac, &zmac, ETH_ALEN)) {
124 status = rdma_addr_find_dmac_by_grh(&sgid, &attr->grh.dgid,
125 attr->dmac, &attr->vlan_id);
127 pr_err("%s(): Failed to resolve dmac from gid."
128 "status = %d\n", __func__, status);
133 status = set_av_attr(dev, ah, attr, &sgid, pd->id);
137 /* if pd is for the user process, pass the ah_id to user space */
138 if ((pd->uctx) && (pd->uctx->ah_tbl.va)) {
139 ahid_addr = pd->uctx->ah_tbl.va + attr->dlid;
145 ocrdma_free_av(dev, ah);
148 return ERR_PTR(status);
151 int ocrdma_destroy_ah(struct ib_ah *ibah)
153 struct ocrdma_ah *ah = get_ocrdma_ah(ibah);
154 struct ocrdma_dev *dev = get_ocrdma_dev(ibah->device);
156 ocrdma_free_av(dev, ah);
161 int ocrdma_query_ah(struct ib_ah *ibah, struct ib_ah_attr *attr)
163 struct ocrdma_ah *ah = get_ocrdma_ah(ibah);
164 struct ocrdma_av *av = ah->av;
165 struct ocrdma_grh *grh;
166 attr->ah_flags |= IB_AH_GRH;
167 if (ah->av->valid & OCRDMA_AV_VALID) {
168 grh = (struct ocrdma_grh *)((u8 *)ah->av +
169 sizeof(struct ocrdma_eth_vlan));
170 attr->sl = be16_to_cpu(av->eth_hdr.vlan_tag) >> 13;
172 grh = (struct ocrdma_grh *)((u8 *)ah->av +
173 sizeof(struct ocrdma_eth_basic));
176 memcpy(&attr->grh.dgid.raw[0], &grh->dgid[0], sizeof(grh->dgid));
177 attr->grh.sgid_index = ah->sgid_index;
178 attr->grh.hop_limit = be32_to_cpu(grh->pdid_hoplimit) & 0xff;
179 attr->grh.traffic_class = be32_to_cpu(grh->tclass_flow) >> 24;
180 attr->grh.flow_label = be32_to_cpu(grh->tclass_flow) & 0x00ffffffff;
184 int ocrdma_modify_ah(struct ib_ah *ibah, struct ib_ah_attr *attr)
186 /* modify_ah is unsupported */
190 int ocrdma_process_mad(struct ib_device *ibdev,
191 int process_mad_flags,
194 struct ib_grh *in_grh,
195 struct ib_mad *in_mad, struct ib_mad *out_mad)
197 return IB_MAD_RESULT_SUCCESS;