1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48#include <linux/slab.h>
49#include "ah.h"
50#include "vt.h"
51
52
53
54
55
56
57
58
59
60
61
62int rvt_check_ah(struct ib_device *ibdev,
63 struct ib_ah_attr *ah_attr)
64{
65 int err;
66 struct ib_port_attr port_attr;
67 struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
68 enum rdma_link_layer link = rdma_port_get_link_layer(ibdev,
69 ah_attr->port_num);
70
71 err = ib_query_port(ibdev, ah_attr->port_num, &port_attr);
72 if (err)
73 return -EINVAL;
74 if (ah_attr->port_num < 1 ||
75 ah_attr->port_num > ibdev->phys_port_cnt)
76 return -EINVAL;
77 if (ah_attr->static_rate != IB_RATE_PORT_CURRENT &&
78 ib_rate_to_mbps(ah_attr->static_rate) < 0)
79 return -EINVAL;
80 if ((ah_attr->ah_flags & IB_AH_GRH) &&
81 ah_attr->grh.sgid_index >= port_attr.gid_tbl_len)
82 return -EINVAL;
83 if (link != IB_LINK_LAYER_ETHERNET) {
84 if (ah_attr->dlid == 0)
85 return -EINVAL;
86 if (ah_attr->dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE) &&
87 ah_attr->dlid != be16_to_cpu(IB_LID_PERMISSIVE) &&
88 !(ah_attr->ah_flags & IB_AH_GRH))
89 return -EINVAL;
90 }
91 if (rdi->driver_f.check_ah)
92 return rdi->driver_f.check_ah(ibdev, ah_attr);
93 return 0;
94}
95EXPORT_SYMBOL(rvt_check_ah);
96
97
98
99
100
101
102
103
104
105
106struct ib_ah *rvt_create_ah(struct ib_pd *pd,
107 struct ib_ah_attr *ah_attr)
108{
109 struct rvt_ah *ah;
110 struct rvt_dev_info *dev = ib_to_rvt(pd->device);
111 unsigned long flags;
112
113 if (rvt_check_ah(pd->device, ah_attr))
114 return ERR_PTR(-EINVAL);
115
116 ah = kmalloc(sizeof(*ah), GFP_ATOMIC);
117 if (!ah)
118 return ERR_PTR(-ENOMEM);
119
120 spin_lock_irqsave(&dev->n_ahs_lock, flags);
121 if (dev->n_ahs_allocated == dev->dparms.props.max_ah) {
122 spin_unlock(&dev->n_ahs_lock);
123 kfree(ah);
124 return ERR_PTR(-ENOMEM);
125 }
126
127 dev->n_ahs_allocated++;
128 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
129
130 ah->attr = *ah_attr;
131 atomic_set(&ah->refcount, 0);
132
133 if (dev->driver_f.notify_new_ah)
134 dev->driver_f.notify_new_ah(pd->device, ah_attr, ah);
135
136 return &ah->ibah;
137}
138
139
140
141
142
143
144
145int rvt_destroy_ah(struct ib_ah *ibah)
146{
147 struct rvt_dev_info *dev = ib_to_rvt(ibah->device);
148 struct rvt_ah *ah = ibah_to_rvtah(ibah);
149 unsigned long flags;
150
151 if (atomic_read(&ah->refcount) != 0)
152 return -EBUSY;
153
154 spin_lock_irqsave(&dev->n_ahs_lock, flags);
155 dev->n_ahs_allocated--;
156 spin_unlock_irqrestore(&dev->n_ahs_lock, flags);
157
158 kfree(ah);
159
160 return 0;
161}
162
163
164
165
166
167
168
169
170int rvt_modify_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
171{
172 struct rvt_ah *ah = ibah_to_rvtah(ibah);
173
174 if (rvt_check_ah(ibah->device, ah_attr))
175 return -EINVAL;
176
177 ah->attr = *ah_attr;
178
179 return 0;
180}
181
182
183
184
185
186
187
188
189int rvt_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
190{
191 struct rvt_ah *ah = ibah_to_rvtah(ibah);
192
193 *ah_attr = ah->attr;
194
195 return 0;
196}
197