]> Git Repo - linux.git/blame - drivers/infiniband/sw/rdmavt/ah.c
Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux.git] / drivers / infiniband / sw / rdmavt / ah.c
CommitLineData
4c1e4972 1/*
fe314195 2 * Copyright(c) 2016 Intel Corporation.
4c1e4972
DD
3 *
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
6 *
7 * GPL LICENSE SUMMARY
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * BSD LICENSE
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * - Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * - Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 * - Neither the name of Intel Corporation nor the names of its
31 * contributors may be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 *
46 */
47
119a8e70 48#include <linux/slab.h>
4c1e4972 49#include "ah.h"
119a8e70
KH
50#include "vt.h" /* for prints */
51
52/**
53 * rvt_check_ah - validate the attributes of AH
54 * @ibdev: the ib device
55 * @ah_attr: the attributes of the AH
90793f71
DD
56 *
57 * If driver supports a more detailed check_ah function call back to it
58 * otherwise just check the basics.
59 *
60 * Return: 0 on success
119a8e70
KH
61 */
62int rvt_check_ah(struct ib_device *ibdev,
90898850 63 struct rdma_ah_attr *ah_attr)
119a8e70
KH
64{
65 int err;
d8966fcd 66 int port_num = rdma_ah_get_port_num(ah_attr);
119a8e70
KH
67 struct ib_port_attr port_attr;
68 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
d8966fcd
DC
69 u8 ah_flags = rdma_ah_get_ah_flags(ah_attr);
70 u8 static_rate = rdma_ah_get_static_rate(ah_attr);
119a8e70 71
d8966fcd 72 err = ib_query_port(ibdev, port_num, &port_attr);
119a8e70
KH
73 if (err)
74 return -EINVAL;
d8966fcd
DC
75 if (port_num < 1 ||
76 port_num > ibdev->phys_port_cnt)
119a8e70 77 return -EINVAL;
d8966fcd
DC
78 if (static_rate != IB_RATE_PORT_CURRENT &&
79 ib_rate_to_mbps(static_rate) < 0)
119a8e70 80 return -EINVAL;
d8966fcd
DC
81 if ((ah_flags & IB_AH_GRH) &&
82 rdma_ah_read_grh(ah_attr)->sgid_index >= port_attr.gid_tbl_len)
119a8e70 83 return -EINVAL;
b036db83
DD
84 if (rdi->driver_f.check_ah)
85 return rdi->driver_f.check_ah(ibdev, ah_attr);
119a8e70
KH
86 return 0;
87}
88EXPORT_SYMBOL(rvt_check_ah);
4c1e4972
DD
89
90/**
91 * rvt_create_ah - create an address handle
92 * @pd: the protection domain
93 * @ah_attr: the attributes of the AH
4f32fb92 94 * @udata: pointer to user's input output buffer information.
4c1e4972
DD
95 *
96 * This may be called from interrupt context.
90793f71
DD
97 *
98 * Return: newly allocated ah
4c1e4972
DD
99 */
100struct ib_ah *rvt_create_ah(struct ib_pd *pd,
4f32fb92
KH
101 struct rdma_ah_attr *ah_attr,
102 struct ib_udata *udata)
4c1e4972 103{
119a8e70
KH
104 struct rvt_ah *ah;
105 struct rvt_dev_info *dev = ib_to_rvt(pd->device);
106 unsigned long flags;
107
108 if (rvt_check_ah(pd->device, ah_attr))
109 return ERR_PTR(-EINVAL);
110
111 ah = kmalloc(sizeof(*ah), GFP_ATOMIC);
112 if (!ah)
113 return ERR_PTR(-ENOMEM);
114
115 spin_lock_irqsave(&dev->n_ahs_lock, flags);
116 if (dev->n_ahs_allocated == dev->dparms.props.max_ah) {
f0bb2d44 117 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
119a8e70
KH
118 kfree(ah);
119 return ERR_PTR(-ENOMEM);
120 }
121
122 dev->n_ahs_allocated++;
123 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
124
d97099fe
JG
125 rdma_copy_ah_attr(&ah->attr, ah_attr);
126
119a8e70
KH
127 atomic_set(&ah->refcount, 0);
128
b036db83
DD
129 if (dev->driver_f.notify_new_ah)
130 dev->driver_f.notify_new_ah(pd->device, ah_attr, ah);
131
119a8e70 132 return &ah->ibah;
4c1e4972
DD
133}
134
90793f71
DD
135/**
136 * rvt_destory_ah - Destory an address handle
137 * @ibah: address handle
138 *
139 * Return: 0 on success
140 */
4c1e4972
DD
141int rvt_destroy_ah(struct ib_ah *ibah)
142{
119a8e70
KH
143 struct rvt_dev_info *dev = ib_to_rvt(ibah->device);
144 struct rvt_ah *ah = ibah_to_rvtah(ibah);
145 unsigned long flags;
146
147 if (atomic_read(&ah->refcount) != 0)
148 return -EBUSY;
149
150 spin_lock_irqsave(&dev->n_ahs_lock, flags);
151 dev->n_ahs_allocated--;
152 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
153
d97099fe 154 rdma_destroy_ah_attr(&ah->attr);
119a8e70
KH
155 kfree(ah);
156
157 return 0;
4c1e4972
DD
158}
159
90793f71
DD
160/**
161 * rvt_modify_ah - modify an ah with given attrs
162 * @ibah: address handle to modify
163 * @ah_attr: attrs to apply
164 *
165 * Return: 0 on success
166 */
90898850 167int rvt_modify_ah(struct ib_ah *ibah, struct rdma_ah_attr *ah_attr)
4c1e4972 168{
119a8e70
KH
169 struct rvt_ah *ah = ibah_to_rvtah(ibah);
170
171 if (rvt_check_ah(ibah->device, ah_attr))
172 return -EINVAL;
173
174 ah->attr = *ah_attr;
175
176 return 0;
4c1e4972
DD
177}
178
90793f71
DD
179/**
180 * rvt_query_ah - return attrs for ah
181 * @ibah: address handle to query
182 * @ah_attr: return info in this
183 *
184 * Return: always 0
185 */
90898850 186int rvt_query_ah(struct ib_ah *ibah, struct rdma_ah_attr *ah_attr)
4c1e4972 187{
119a8e70
KH
188 struct rvt_ah *ah = ibah_to_rvtah(ibah);
189
190 *ah_attr = ah->attr;
191
192 return 0;
4c1e4972 193}
This page took 0.2629 seconds and 4 git commands to generate.