RDMA/ocrdma: Handle Ethernet L2 parameters for IP based GID addressing
[deliverable/linux.git] / drivers / infiniband / hw / ocrdma / ocrdma_ah.c
CommitLineData
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>
fe2caefc
PP
32
33#include "ocrdma.h"
34#include "ocrdma_verbs.h"
35#include "ocrdma_ah.h"
36#include "ocrdma_hw.h"
37
1afc0454 38static inline int set_av_attr(struct ocrdma_dev *dev, struct ocrdma_ah *ah,
fe2caefc
PP
39 struct ib_ah_attr *attr, int pdid)
40{
41 int status = 0;
42 u16 vlan_tag; bool vlan_enabled = false;
fe2caefc
PP
43 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
40aca6ff 52 vlan_tag = attr->vlan_id;
84b105db
NG
53 if (!vlan_tag || (vlan_tag > 0xFFF))
54 vlan_tag = dev->pvid;
fe2caefc
PP
55 if (vlan_tag && (vlan_tag < 0x1000)) {
56 eth.eth_type = cpu_to_be16(0x8100);
57 eth.roce_eth_type = cpu_to_be16(OCRDMA_ROCE_ETH_TYPE);
58 vlan_tag |= (attr->sl & 7) << 13;
59 eth.vlan_tag = cpu_to_be16(vlan_tag);
60 eth_sz = sizeof(struct ocrdma_eth_vlan);
61 vlan_enabled = true;
62 } else {
63 eth.eth_type = cpu_to_be16(OCRDMA_ROCE_ETH_TYPE);
64 eth_sz = sizeof(struct ocrdma_eth_basic);
65 }
66 memcpy(&eth.smac[0], &dev->nic_info.mac_addr[0], ETH_ALEN);
40aca6ff
MS
67 memcpy(&eth.dmac[0], attr->dmac, ETH_ALEN);
68 status = ocrdma_resolve_dmac(dev, attr, &eth.dmac[0]);
fe2caefc
PP
69 if (status)
70 return status;
71 status = ocrdma_query_gid(&dev->ibdev, 1, attr->grh.sgid_index,
72 (union ib_gid *)&grh.sgid[0]);
73 if (status)
74 return status;
75
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);
82
83 memcpy(&grh.dgid[0], attr->grh.dgid.raw, sizeof(attr->grh.dgid.raw));
84 memcpy(&ah->av->eth_hdr, &eth, eth_sz);
85 memcpy((u8 *)ah->av + eth_sz, &grh, sizeof(struct ocrdma_grh));
86 if (vlan_enabled)
87 ah->av->valid |= OCRDMA_AV_VLAN_VALID;
88 return status;
89}
90
91struct ib_ah *ocrdma_create_ah(struct ib_pd *ibpd, struct ib_ah_attr *attr)
92{
93 u32 *ahid_addr;
94 int status;
95 struct ocrdma_ah *ah;
96 struct ocrdma_pd *pd = get_ocrdma_pd(ibpd);
f99b1649 97 struct ocrdma_dev *dev = get_ocrdma_dev(ibpd->device);
fe2caefc
PP
98
99 if (!(attr->ah_flags & IB_AH_GRH))
100 return ERR_PTR(-EINVAL);
101
102 ah = kzalloc(sizeof *ah, GFP_ATOMIC);
103 if (!ah)
104 return ERR_PTR(-ENOMEM);
fe2caefc
PP
105
106 status = ocrdma_alloc_av(dev, ah);
107 if (status)
108 goto av_err;
1afc0454 109 status = set_av_attr(dev, ah, attr, pd->id);
fe2caefc
PP
110 if (status)
111 goto av_conf_err;
112
113 /* if pd is for the user process, pass the ah_id to user space */
114 if ((pd->uctx) && (pd->uctx->ah_tbl.va)) {
115 ahid_addr = pd->uctx->ah_tbl.va + attr->dlid;
116 *ahid_addr = ah->id;
117 }
118 return &ah->ibah;
119
120av_conf_err:
121 ocrdma_free_av(dev, ah);
122av_err:
123 kfree(ah);
124 return ERR_PTR(status);
125}
126
127int ocrdma_destroy_ah(struct ib_ah *ibah)
128{
129 struct ocrdma_ah *ah = get_ocrdma_ah(ibah);
1afc0454
NG
130 struct ocrdma_dev *dev = get_ocrdma_dev(ibah->device);
131
132 ocrdma_free_av(dev, ah);
fe2caefc
PP
133 kfree(ah);
134 return 0;
135}
136
137int ocrdma_query_ah(struct ib_ah *ibah, struct ib_ah_attr *attr)
138{
139 struct ocrdma_ah *ah = get_ocrdma_ah(ibah);
140 struct ocrdma_av *av = ah->av;
141 struct ocrdma_grh *grh;
142 attr->ah_flags |= IB_AH_GRH;
143 if (ah->av->valid & Bit(1)) {
144 grh = (struct ocrdma_grh *)((u8 *)ah->av +
145 sizeof(struct ocrdma_eth_vlan));
146 attr->sl = be16_to_cpu(av->eth_hdr.vlan_tag) >> 13;
147 } else {
148 grh = (struct ocrdma_grh *)((u8 *)ah->av +
149 sizeof(struct ocrdma_eth_basic));
150 attr->sl = 0;
151 }
152 memcpy(&attr->grh.dgid.raw[0], &grh->dgid[0], sizeof(grh->dgid));
153 attr->grh.sgid_index = ah->sgid_index;
154 attr->grh.hop_limit = be32_to_cpu(grh->pdid_hoplimit) & 0xff;
155 attr->grh.traffic_class = be32_to_cpu(grh->tclass_flow) >> 24;
156 attr->grh.flow_label = be32_to_cpu(grh->tclass_flow) & 0x00ffffffff;
157 return 0;
158}
159
160int ocrdma_modify_ah(struct ib_ah *ibah, struct ib_ah_attr *attr)
161{
162 /* modify_ah is unsupported */
163 return -ENOSYS;
164}
165
166int ocrdma_process_mad(struct ib_device *ibdev,
167 int process_mad_flags,
168 u8 port_num,
169 struct ib_wc *in_wc,
170 struct ib_grh *in_grh,
171 struct ib_mad *in_mad, struct ib_mad *out_mad)
172{
173 return IB_MAD_RESULT_SUCCESS;
174}
This page took 0.20757 seconds and 5 git commands to generate.