blob: df9e73758afbe344f8327e2cdf8455c2b831b3df [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>
Parav Panditfe2caef2012-03-21 04:09:06 +053032
33#include "ocrdma.h"
34#include "ocrdma_verbs.h"
35#include "ocrdma_ah.h"
36#include "ocrdma_hw.h"
37
Naresh Gottumukkala1afc0452013-08-07 12:52:33 +053038static inline int set_av_attr(struct ocrdma_dev *dev, struct ocrdma_ah *ah,
Parav Panditfe2caef2012-03-21 04:09:06 +053039 struct ib_ah_attr *attr, int pdid)
40{
41 int status = 0;
42 u16 vlan_tag; bool vlan_enabled = false;
Parav Panditfe2caef2012-03-21 04:09:06 +053043 struct ocrdma_eth_vlan eth;
44 struct ocrdma_grh grh;
45 int eth_sz;
46
47 memset(&eth, 0, sizeof(eth));
48 memset(&grh, 0, sizeof(grh));
49
50 ah->sgid_index = attr->grh.sgid_index;
51
52 vlan_tag = rdma_get_vlan_id(&attr->grh.dgid);
53 if (vlan_tag && (vlan_tag < 0x1000)) {
54 eth.eth_type = cpu_to_be16(0x8100);
55 eth.roce_eth_type = cpu_to_be16(OCRDMA_ROCE_ETH_TYPE);
56 vlan_tag |= (attr->sl & 7) << 13;
57 eth.vlan_tag = cpu_to_be16(vlan_tag);
58 eth_sz = sizeof(struct ocrdma_eth_vlan);
59 vlan_enabled = true;
60 } else {
61 eth.eth_type = cpu_to_be16(OCRDMA_ROCE_ETH_TYPE);
62 eth_sz = sizeof(struct ocrdma_eth_basic);
63 }
64 memcpy(&eth.smac[0], &dev->nic_info.mac_addr[0], ETH_ALEN);
65 status = ocrdma_resolve_dgid(dev, &attr->grh.dgid, &eth.dmac[0]);
66 if (status)
67 return status;
68 status = ocrdma_query_gid(&dev->ibdev, 1, attr->grh.sgid_index,
69 (union ib_gid *)&grh.sgid[0]);
70 if (status)
71 return status;
72
73 grh.tclass_flow = cpu_to_be32((6 << 28) |
74 (attr->grh.traffic_class << 24) |
75 attr->grh.flow_label);
76 /* 0x1b is next header value in GRH */
77 grh.pdid_hoplimit = cpu_to_be32((pdid << 16) |
78 (0x1b << 8) | attr->grh.hop_limit);
79
80 memcpy(&grh.dgid[0], attr->grh.dgid.raw, sizeof(attr->grh.dgid.raw));
81 memcpy(&ah->av->eth_hdr, &eth, eth_sz);
82 memcpy((u8 *)ah->av + eth_sz, &grh, sizeof(struct ocrdma_grh));
83 if (vlan_enabled)
84 ah->av->valid |= OCRDMA_AV_VLAN_VALID;
85 return status;
86}
87
88struct ib_ah *ocrdma_create_ah(struct ib_pd *ibpd, struct ib_ah_attr *attr)
89{
90 u32 *ahid_addr;
91 int status;
92 struct ocrdma_ah *ah;
93 struct ocrdma_pd *pd = get_ocrdma_pd(ibpd);
Naresh Gottumukkalaf99b1642013-08-07 12:52:32 +053094 struct ocrdma_dev *dev = get_ocrdma_dev(ibpd->device);
Parav Panditfe2caef2012-03-21 04:09:06 +053095
96 if (!(attr->ah_flags & IB_AH_GRH))
97 return ERR_PTR(-EINVAL);
98
99 ah = kzalloc(sizeof *ah, GFP_ATOMIC);
100 if (!ah)
101 return ERR_PTR(-ENOMEM);
Parav Panditfe2caef2012-03-21 04:09:06 +0530102
103 status = ocrdma_alloc_av(dev, ah);
104 if (status)
105 goto av_err;
Naresh Gottumukkala1afc0452013-08-07 12:52:33 +0530106 status = set_av_attr(dev, ah, attr, pd->id);
Parav Panditfe2caef2012-03-21 04:09:06 +0530107 if (status)
108 goto av_conf_err;
109
110 /* if pd is for the user process, pass the ah_id to user space */
111 if ((pd->uctx) && (pd->uctx->ah_tbl.va)) {
112 ahid_addr = pd->uctx->ah_tbl.va + attr->dlid;
113 *ahid_addr = ah->id;
114 }
115 return &ah->ibah;
116
117av_conf_err:
118 ocrdma_free_av(dev, ah);
119av_err:
120 kfree(ah);
121 return ERR_PTR(status);
122}
123
124int ocrdma_destroy_ah(struct ib_ah *ibah)
125{
126 struct ocrdma_ah *ah = get_ocrdma_ah(ibah);
Naresh Gottumukkala1afc0452013-08-07 12:52:33 +0530127 struct ocrdma_dev *dev = get_ocrdma_dev(ibah->device);
128
129 ocrdma_free_av(dev, ah);
Parav Panditfe2caef2012-03-21 04:09:06 +0530130 kfree(ah);
131 return 0;
132}
133
134int ocrdma_query_ah(struct ib_ah *ibah, struct ib_ah_attr *attr)
135{
136 struct ocrdma_ah *ah = get_ocrdma_ah(ibah);
137 struct ocrdma_av *av = ah->av;
138 struct ocrdma_grh *grh;
139 attr->ah_flags |= IB_AH_GRH;
140 if (ah->av->valid & Bit(1)) {
141 grh = (struct ocrdma_grh *)((u8 *)ah->av +
142 sizeof(struct ocrdma_eth_vlan));
143 attr->sl = be16_to_cpu(av->eth_hdr.vlan_tag) >> 13;
144 } else {
145 grh = (struct ocrdma_grh *)((u8 *)ah->av +
146 sizeof(struct ocrdma_eth_basic));
147 attr->sl = 0;
148 }
149 memcpy(&attr->grh.dgid.raw[0], &grh->dgid[0], sizeof(grh->dgid));
150 attr->grh.sgid_index = ah->sgid_index;
151 attr->grh.hop_limit = be32_to_cpu(grh->pdid_hoplimit) & 0xff;
152 attr->grh.traffic_class = be32_to_cpu(grh->tclass_flow) >> 24;
153 attr->grh.flow_label = be32_to_cpu(grh->tclass_flow) & 0x00ffffffff;
154 return 0;
155}
156
157int ocrdma_modify_ah(struct ib_ah *ibah, struct ib_ah_attr *attr)
158{
159 /* modify_ah is unsupported */
160 return -ENOSYS;
161}
162
163int ocrdma_process_mad(struct ib_device *ibdev,
164 int process_mad_flags,
165 u8 port_num,
166 struct ib_wc *in_wc,
167 struct ib_grh *in_grh,
168 struct ib_mad *in_mad, struct ib_mad *out_mad)
169{
170 return IB_MAD_RESULT_SUCCESS;
171}