.. | .. |
---|
40 | 40 | |
---|
41 | 41 | #include "mlx4_ib.h" |
---|
42 | 42 | |
---|
43 | | -static struct ib_ah *create_ib_ah(struct ib_pd *pd, |
---|
44 | | - struct rdma_ah_attr *ah_attr, |
---|
45 | | - struct mlx4_ib_ah *ah) |
---|
| 43 | +static void create_ib_ah(struct ib_ah *ib_ah, struct rdma_ah_attr *ah_attr) |
---|
46 | 44 | { |
---|
47 | | - struct mlx4_dev *dev = to_mdev(pd->device)->dev; |
---|
| 45 | + struct mlx4_ib_ah *ah = to_mah(ib_ah); |
---|
| 46 | + struct mlx4_dev *dev = to_mdev(ib_ah->device)->dev; |
---|
48 | 47 | |
---|
49 | | - ah->av.ib.port_pd = cpu_to_be32(to_mpd(pd)->pdn | |
---|
| 48 | + ah->av.ib.port_pd = cpu_to_be32(to_mpd(ib_ah->pd)->pdn | |
---|
50 | 49 | (rdma_ah_get_port_num(ah_attr) << 24)); |
---|
51 | 50 | ah->av.ib.g_slid = rdma_ah_get_path_bits(ah_attr); |
---|
52 | 51 | ah->av.ib.sl_tclass_flowlabel = |
---|
.. | .. |
---|
73 | 72 | --static_rate; |
---|
74 | 73 | ah->av.ib.stat_rate = static_rate; |
---|
75 | 74 | } |
---|
76 | | - |
---|
77 | | - return &ah->ibah; |
---|
78 | 75 | } |
---|
79 | 76 | |
---|
80 | | -static struct ib_ah *create_iboe_ah(struct ib_pd *pd, |
---|
81 | | - struct rdma_ah_attr *ah_attr, |
---|
82 | | - struct mlx4_ib_ah *ah) |
---|
| 77 | +static int create_iboe_ah(struct ib_ah *ib_ah, struct rdma_ah_attr *ah_attr) |
---|
83 | 78 | { |
---|
84 | | - struct mlx4_ib_dev *ibdev = to_mdev(pd->device); |
---|
| 79 | + struct mlx4_ib_dev *ibdev = to_mdev(ib_ah->device); |
---|
| 80 | + struct mlx4_ib_ah *ah = to_mah(ib_ah); |
---|
85 | 81 | const struct ib_gid_attr *gid_attr; |
---|
86 | 82 | struct mlx4_dev *dev = ibdev->dev; |
---|
87 | 83 | int is_mcast = 0; |
---|
.. | .. |
---|
103 | 99 | */ |
---|
104 | 100 | gid_attr = ah_attr->grh.sgid_attr; |
---|
105 | 101 | if (gid_attr) { |
---|
106 | | - if (is_vlan_dev(gid_attr->ndev)) |
---|
107 | | - vlan_tag = vlan_dev_vlan_id(gid_attr->ndev); |
---|
108 | | - memcpy(ah->av.eth.s_mac, gid_attr->ndev->dev_addr, ETH_ALEN); |
---|
| 102 | + ret = rdma_read_gid_l2_fields(gid_attr, &vlan_tag, |
---|
| 103 | + &ah->av.eth.s_mac[0]); |
---|
| 104 | + if (ret) |
---|
| 105 | + return ret; |
---|
| 106 | + |
---|
109 | 107 | ret = mlx4_ib_gid_index_to_real_index(ibdev, gid_attr); |
---|
110 | 108 | if (ret < 0) |
---|
111 | | - return ERR_PTR(ret); |
---|
| 109 | + return ret; |
---|
112 | 110 | ah->av.eth.gid_index = ret; |
---|
113 | 111 | } else { |
---|
114 | 112 | /* mlx4_ib_create_ah_slave fills in the s_mac and the vlan */ |
---|
.. | .. |
---|
117 | 115 | |
---|
118 | 116 | if (vlan_tag < 0x1000) |
---|
119 | 117 | vlan_tag |= (rdma_ah_get_sl(ah_attr) & 7) << 13; |
---|
120 | | - ah->av.eth.port_pd = cpu_to_be32(to_mpd(pd)->pdn | |
---|
| 118 | + ah->av.eth.port_pd = cpu_to_be32(to_mpd(ib_ah->pd)->pdn | |
---|
121 | 119 | (rdma_ah_get_port_num(ah_attr) << 24)); |
---|
122 | 120 | ah->av.eth.vlan = cpu_to_be16(vlan_tag); |
---|
123 | 121 | ah->av.eth.hop_limit = grh->hop_limit; |
---|
.. | .. |
---|
140 | 138 | memcpy(ah->av.eth.dgid, grh->dgid.raw, 16); |
---|
141 | 139 | ah->av.eth.sl_tclass_flowlabel |= cpu_to_be32(rdma_ah_get_sl(ah_attr) |
---|
142 | 140 | << 29); |
---|
143 | | - return &ah->ibah; |
---|
| 141 | + return 0; |
---|
144 | 142 | } |
---|
145 | 143 | |
---|
146 | | -struct ib_ah *mlx4_ib_create_ah(struct ib_pd *pd, struct rdma_ah_attr *ah_attr, |
---|
147 | | - struct ib_udata *udata) |
---|
148 | | - |
---|
| 144 | +int mlx4_ib_create_ah(struct ib_ah *ib_ah, struct rdma_ah_init_attr *init_attr, |
---|
| 145 | + struct ib_udata *udata) |
---|
149 | 146 | { |
---|
150 | | - struct mlx4_ib_ah *ah; |
---|
151 | | - struct ib_ah *ret; |
---|
152 | | - |
---|
153 | | - ah = kzalloc(sizeof *ah, GFP_ATOMIC); |
---|
154 | | - if (!ah) |
---|
155 | | - return ERR_PTR(-ENOMEM); |
---|
| 147 | + struct rdma_ah_attr *ah_attr = init_attr->ah_attr; |
---|
156 | 148 | |
---|
157 | 149 | if (ah_attr->type == RDMA_AH_ATTR_TYPE_ROCE) { |
---|
158 | | - if (!(rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH)) { |
---|
159 | | - ret = ERR_PTR(-EINVAL); |
---|
160 | | - } else { |
---|
161 | | - /* |
---|
162 | | - * TBD: need to handle the case when we get |
---|
163 | | - * called in an atomic context and there we |
---|
164 | | - * might sleep. We don't expect this |
---|
165 | | - * currently since we're working with link |
---|
166 | | - * local addresses which we can translate |
---|
167 | | - * without going to sleep. |
---|
168 | | - */ |
---|
169 | | - ret = create_iboe_ah(pd, ah_attr, ah); |
---|
170 | | - } |
---|
| 150 | + if (!(rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH)) |
---|
| 151 | + return -EINVAL; |
---|
| 152 | + /* |
---|
| 153 | + * TBD: need to handle the case when we get |
---|
| 154 | + * called in an atomic context and there we |
---|
| 155 | + * might sleep. We don't expect this |
---|
| 156 | + * currently since we're working with link |
---|
| 157 | + * local addresses which we can translate |
---|
| 158 | + * without going to sleep. |
---|
| 159 | + */ |
---|
| 160 | + return create_iboe_ah(ib_ah, ah_attr); |
---|
| 161 | + } |
---|
171 | 162 | |
---|
172 | | - if (IS_ERR(ret)) |
---|
173 | | - kfree(ah); |
---|
174 | | - |
---|
175 | | - return ret; |
---|
176 | | - } else |
---|
177 | | - return create_ib_ah(pd, ah_attr, ah); /* never fails */ |
---|
| 163 | + create_ib_ah(ib_ah, ah_attr); |
---|
| 164 | + return 0; |
---|
178 | 165 | } |
---|
179 | 166 | |
---|
180 | | -/* AH's created via this call must be free'd by mlx4_ib_destroy_ah. */ |
---|
181 | | -struct ib_ah *mlx4_ib_create_ah_slave(struct ib_pd *pd, |
---|
182 | | - struct rdma_ah_attr *ah_attr, |
---|
183 | | - int slave_sgid_index, u8 *s_mac, |
---|
184 | | - u16 vlan_tag) |
---|
| 167 | +int mlx4_ib_create_ah_slave(struct ib_ah *ah, struct rdma_ah_attr *ah_attr, |
---|
| 168 | + int slave_sgid_index, u8 *s_mac, u16 vlan_tag) |
---|
185 | 169 | { |
---|
186 | 170 | struct rdma_ah_attr slave_attr = *ah_attr; |
---|
187 | | - struct mlx4_ib_ah *mah; |
---|
188 | | - struct ib_ah *ah; |
---|
| 171 | + struct rdma_ah_init_attr init_attr = {}; |
---|
| 172 | + struct mlx4_ib_ah *mah = to_mah(ah); |
---|
| 173 | + int ret; |
---|
189 | 174 | |
---|
190 | 175 | slave_attr.grh.sgid_attr = NULL; |
---|
191 | 176 | slave_attr.grh.sgid_index = slave_sgid_index; |
---|
192 | | - ah = mlx4_ib_create_ah(pd, &slave_attr, NULL); |
---|
193 | | - if (IS_ERR(ah)) |
---|
194 | | - return ah; |
---|
| 177 | + init_attr.ah_attr = &slave_attr; |
---|
| 178 | + ret = mlx4_ib_create_ah(ah, &init_attr, NULL); |
---|
| 179 | + if (ret) |
---|
| 180 | + return ret; |
---|
195 | 181 | |
---|
196 | | - ah->device = pd->device; |
---|
197 | | - ah->pd = pd; |
---|
198 | 182 | ah->type = ah_attr->type; |
---|
199 | | - mah = to_mah(ah); |
---|
200 | 183 | |
---|
201 | 184 | /* get rid of force-loopback bit */ |
---|
202 | 185 | mah->av.ib.port_pd &= cpu_to_be32(0x7FFFFFFF); |
---|
.. | .. |
---|
208 | 191 | vlan_tag |= (rdma_ah_get_sl(ah_attr) & 7) << 13; |
---|
209 | 192 | mah->av.eth.vlan = cpu_to_be16(vlan_tag); |
---|
210 | 193 | |
---|
211 | | - return ah; |
---|
| 194 | + return 0; |
---|
212 | 195 | } |
---|
213 | 196 | |
---|
214 | 197 | int mlx4_ib_query_ah(struct ib_ah *ibah, struct rdma_ah_attr *ah_attr) |
---|
.. | .. |
---|
247 | 230 | rdma_ah_set_dgid_raw(ah_attr, ah->av.ib.dgid); |
---|
248 | 231 | } |
---|
249 | 232 | |
---|
250 | | - return 0; |
---|
251 | | -} |
---|
252 | | - |
---|
253 | | -int mlx4_ib_destroy_ah(struct ib_ah *ah) |
---|
254 | | -{ |
---|
255 | | - kfree(to_mah(ah)); |
---|
256 | 233 | return 0; |
---|
257 | 234 | } |
---|