Commit | Line | Data |
---|---|---|
77241056 MM |
1 | /* |
2 | * | |
3 | * This file is provided under a dual BSD/GPLv2 license. When using or | |
4 | * redistributing this file, you may do so under either license. | |
5 | * | |
6 | * GPL LICENSE SUMMARY | |
7 | * | |
91ab4ed3 | 8 | * Copyright(c) 2015, 2016 Intel Corporation. |
77241056 MM |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of version 2 of the GNU General Public License as | |
12 | * published by the Free Software Foundation. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, but | |
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | * General Public License for more details. | |
18 | * | |
19 | * BSD LICENSE | |
20 | * | |
91ab4ed3 | 21 | * Copyright(c) 2015, 2016 Intel Corporation. |
77241056 MM |
22 | * |
23 | * Redistribution and use in source and binary forms, with or without | |
24 | * modification, are permitted provided that the following conditions | |
25 | * are met: | |
26 | * | |
27 | * - Redistributions of source code must retain the above copyright | |
28 | * notice, this list of conditions and the following disclaimer. | |
29 | * - Redistributions in binary form must reproduce the above copyright | |
30 | * notice, this list of conditions and the following disclaimer in | |
31 | * the documentation and/or other materials provided with the | |
32 | * distribution. | |
33 | * - Neither the name of Intel Corporation nor the names of its | |
34 | * contributors may be used to endorse or promote products derived | |
35 | * from this software without specific prior written permission. | |
36 | * | |
37 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
38 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
39 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
40 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
41 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
43 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
44 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
45 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
46 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
47 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
48 | * | |
49 | */ | |
50 | ||
51 | #include <linux/net.h> | |
52 | #define OPA_NUM_PKEY_BLOCKS_PER_SMP (OPA_SMP_DR_DATA_SIZE \ | |
53 | / (OPA_PARTITION_TABLE_BLK_SIZE * sizeof(u16))) | |
54 | ||
55 | #include "hfi.h" | |
56 | #include "mad.h" | |
57 | #include "trace.h" | |
58 | ||
59 | /* the reset value from the FM is supposed to be 0xffff, handle both */ | |
60 | #define OPA_LINK_WIDTH_RESET_OLD 0x0fff | |
61 | #define OPA_LINK_WIDTH_RESET 0xffff | |
62 | ||
63 | static int reply(struct ib_mad_hdr *smp) | |
64 | { | |
65 | /* | |
66 | * The verbs framework will handle the directed/LID route | |
67 | * packet changes. | |
68 | */ | |
69 | smp->method = IB_MGMT_METHOD_GET_RESP; | |
70 | if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) | |
71 | smp->status |= IB_SMP_DIRECTION; | |
72 | return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY; | |
73 | } | |
74 | ||
75 | static inline void clear_opa_smp_data(struct opa_smp *smp) | |
76 | { | |
77 | void *data = opa_get_smp_data(smp); | |
78 | size_t size = opa_get_smp_data_size(smp); | |
79 | ||
80 | memset(data, 0, size); | |
81 | } | |
82 | ||
83 | static void send_trap(struct hfi1_ibport *ibp, void *data, unsigned len) | |
84 | { | |
85 | struct ib_mad_send_buf *send_buf; | |
86 | struct ib_mad_agent *agent; | |
5cd24119 | 87 | struct opa_smp *smp; |
77241056 MM |
88 | int ret; |
89 | unsigned long flags; | |
90 | unsigned long timeout; | |
91 | int pkey_idx; | |
92 | u32 qpn = ppd_from_ibp(ibp)->sm_trap_qp; | |
93 | ||
4eb06882 | 94 | agent = ibp->rvp.send_agent; |
77241056 MM |
95 | if (!agent) |
96 | return; | |
97 | ||
98 | /* o14-3.2.1 */ | |
99 | if (ppd_from_ibp(ibp)->lstate != IB_PORT_ACTIVE) | |
100 | return; | |
101 | ||
102 | /* o14-2 */ | |
4eb06882 DD |
103 | if (ibp->rvp.trap_timeout && time_before(jiffies, |
104 | ibp->rvp.trap_timeout)) | |
77241056 MM |
105 | return; |
106 | ||
107 | pkey_idx = hfi1_lookup_pkey_idx(ibp, LIM_MGMT_P_KEY); | |
108 | if (pkey_idx < 0) { | |
109 | pr_warn("%s: failed to find limited mgmt pkey, defaulting 0x%x\n", | |
110 | __func__, hfi1_get_pkey(ibp, 1)); | |
111 | pkey_idx = 1; | |
112 | } | |
113 | ||
114 | send_buf = ib_create_send_mad(agent, qpn, pkey_idx, 0, | |
115 | IB_MGMT_MAD_HDR, IB_MGMT_MAD_DATA, | |
116 | GFP_ATOMIC, IB_MGMT_BASE_VERSION); | |
117 | if (IS_ERR(send_buf)) | |
118 | return; | |
119 | ||
120 | smp = send_buf->mad; | |
5cd24119 | 121 | smp->base_version = OPA_MGMT_BASE_VERSION; |
77241056 | 122 | smp->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED; |
5cd24119 | 123 | smp->class_version = OPA_SMI_CLASS_VERSION; |
77241056 | 124 | smp->method = IB_MGMT_METHOD_TRAP; |
4eb06882 DD |
125 | ibp->rvp.tid++; |
126 | smp->tid = cpu_to_be64(ibp->rvp.tid); | |
77241056 MM |
127 | smp->attr_id = IB_SMP_ATTR_NOTICE; |
128 | /* o14-1: smp->mkey = 0; */ | |
5cd24119 | 129 | memcpy(smp->route.lid.data, data, len); |
77241056 | 130 | |
4eb06882 | 131 | spin_lock_irqsave(&ibp->rvp.lock, flags); |
9c4a311e | 132 | if (!ibp->rvp.sm_ah) { |
4eb06882 | 133 | if (ibp->rvp.sm_lid != be16_to_cpu(IB_LID_PERMISSIVE)) { |
77241056 MM |
134 | struct ib_ah *ah; |
135 | ||
4eb06882 | 136 | ah = hfi1_create_qp0_ah(ibp, ibp->rvp.sm_lid); |
77241056 MM |
137 | if (IS_ERR(ah)) |
138 | ret = PTR_ERR(ah); | |
139 | else { | |
140 | send_buf->ah = ah; | |
9c4a311e | 141 | ibp->rvp.sm_ah = ibah_to_rvtah(ah); |
77241056 MM |
142 | ret = 0; |
143 | } | |
144 | } else | |
145 | ret = -EINVAL; | |
146 | } else { | |
9c4a311e | 147 | send_buf->ah = &ibp->rvp.sm_ah->ibah; |
77241056 MM |
148 | ret = 0; |
149 | } | |
4eb06882 | 150 | spin_unlock_irqrestore(&ibp->rvp.lock, flags); |
77241056 MM |
151 | |
152 | if (!ret) | |
153 | ret = ib_post_send_mad(send_buf, NULL); | |
154 | if (!ret) { | |
155 | /* 4.096 usec. */ | |
4eb06882 DD |
156 | timeout = (4096 * (1UL << ibp->rvp.subnet_timeout)) / 1000; |
157 | ibp->rvp.trap_timeout = jiffies + usecs_to_jiffies(timeout); | |
77241056 MM |
158 | } else { |
159 | ib_free_send_mad(send_buf); | |
4eb06882 | 160 | ibp->rvp.trap_timeout = 0; |
77241056 MM |
161 | } |
162 | } | |
163 | ||
164 | /* | |
165 | * Send a bad [PQ]_Key trap (ch. 14.3.8). | |
166 | */ | |
167 | void hfi1_bad_pqkey(struct hfi1_ibport *ibp, __be16 trap_num, u32 key, u32 sl, | |
5cd24119 | 168 | u32 qp1, u32 qp2, u16 lid1, u16 lid2) |
77241056 | 169 | { |
5cd24119 EK |
170 | struct opa_mad_notice_attr data; |
171 | u32 lid = ppd_from_ibp(ibp)->lid; | |
172 | u32 _lid1 = lid1; | |
173 | u32 _lid2 = lid2; | |
77241056 | 174 | |
5cd24119 EK |
175 | memset(&data, 0, sizeof(data)); |
176 | ||
177 | if (trap_num == OPA_TRAP_BAD_P_KEY) | |
4eb06882 | 178 | ibp->rvp.pkey_violations++; |
77241056 | 179 | else |
4eb06882 DD |
180 | ibp->rvp.qkey_violations++; |
181 | ibp->rvp.n_pkt_drops++; | |
77241056 MM |
182 | |
183 | /* Send violation trap */ | |
184 | data.generic_type = IB_NOTICE_TYPE_SECURITY; | |
77241056 MM |
185 | data.prod_type_lsb = IB_NOTICE_PROD_CA; |
186 | data.trap_num = trap_num; | |
5cd24119 EK |
187 | data.issuer_lid = cpu_to_be32(lid); |
188 | data.ntc_257_258.lid1 = cpu_to_be32(_lid1); | |
189 | data.ntc_257_258.lid2 = cpu_to_be32(_lid2); | |
190 | data.ntc_257_258.key = cpu_to_be32(key); | |
191 | data.ntc_257_258.sl = sl << 3; | |
192 | data.ntc_257_258.qp1 = cpu_to_be32(qp1); | |
193 | data.ntc_257_258.qp2 = cpu_to_be32(qp2); | |
77241056 MM |
194 | |
195 | send_trap(ibp, &data, sizeof(data)); | |
196 | } | |
197 | ||
198 | /* | |
199 | * Send a bad M_Key trap (ch. 14.3.9). | |
200 | */ | |
201 | static void bad_mkey(struct hfi1_ibport *ibp, struct ib_mad_hdr *mad, | |
202 | __be64 mkey, __be32 dr_slid, u8 return_path[], u8 hop_cnt) | |
203 | { | |
5cd24119 EK |
204 | struct opa_mad_notice_attr data; |
205 | u32 lid = ppd_from_ibp(ibp)->lid; | |
77241056 | 206 | |
5cd24119 | 207 | memset(&data, 0, sizeof(data)); |
77241056 MM |
208 | /* Send violation trap */ |
209 | data.generic_type = IB_NOTICE_TYPE_SECURITY; | |
77241056 | 210 | data.prod_type_lsb = IB_NOTICE_PROD_CA; |
5cd24119 EK |
211 | data.trap_num = OPA_TRAP_BAD_M_KEY; |
212 | data.issuer_lid = cpu_to_be32(lid); | |
213 | data.ntc_256.lid = data.issuer_lid; | |
214 | data.ntc_256.method = mad->method; | |
215 | data.ntc_256.attr_id = mad->attr_id; | |
216 | data.ntc_256.attr_mod = mad->attr_mod; | |
217 | data.ntc_256.mkey = mkey; | |
77241056 | 218 | if (mad->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) { |
5cd24119 EK |
219 | data.ntc_256.dr_slid = dr_slid; |
220 | data.ntc_256.dr_trunc_hop = IB_NOTICE_TRAP_DR_NOTICE; | |
221 | if (hop_cnt > ARRAY_SIZE(data.ntc_256.dr_rtn_path)) { | |
222 | data.ntc_256.dr_trunc_hop |= | |
77241056 | 223 | IB_NOTICE_TRAP_DR_TRUNC; |
5cd24119 | 224 | hop_cnt = ARRAY_SIZE(data.ntc_256.dr_rtn_path); |
77241056 | 225 | } |
5cd24119 EK |
226 | data.ntc_256.dr_trunc_hop |= hop_cnt; |
227 | memcpy(data.ntc_256.dr_rtn_path, return_path, | |
77241056 MM |
228 | hop_cnt); |
229 | } | |
230 | ||
231 | send_trap(ibp, &data, sizeof(data)); | |
232 | } | |
233 | ||
234 | /* | |
235 | * Send a Port Capability Mask Changed trap (ch. 14.3.11). | |
236 | */ | |
237 | void hfi1_cap_mask_chg(struct hfi1_ibport *ibp) | |
238 | { | |
5cd24119 EK |
239 | struct opa_mad_notice_attr data; |
240 | u32 lid = ppd_from_ibp(ibp)->lid; | |
241 | ||
242 | memset(&data, 0, sizeof(data)); | |
77241056 MM |
243 | |
244 | data.generic_type = IB_NOTICE_TYPE_INFO; | |
77241056 | 245 | data.prod_type_lsb = IB_NOTICE_PROD_CA; |
5cd24119 EK |
246 | data.trap_num = OPA_TRAP_CHANGE_CAPABILITY; |
247 | data.issuer_lid = cpu_to_be32(lid); | |
248 | data.ntc_144.lid = data.issuer_lid; | |
4eb06882 | 249 | data.ntc_144.new_cap_mask = cpu_to_be32(ibp->rvp.port_cap_flags); |
77241056 MM |
250 | |
251 | send_trap(ibp, &data, sizeof(data)); | |
252 | } | |
253 | ||
254 | /* | |
255 | * Send a System Image GUID Changed trap (ch. 14.3.12). | |
256 | */ | |
257 | void hfi1_sys_guid_chg(struct hfi1_ibport *ibp) | |
258 | { | |
5cd24119 EK |
259 | struct opa_mad_notice_attr data; |
260 | u32 lid = ppd_from_ibp(ibp)->lid; | |
261 | ||
262 | memset(&data, 0, sizeof(data)); | |
77241056 MM |
263 | |
264 | data.generic_type = IB_NOTICE_TYPE_INFO; | |
77241056 | 265 | data.prod_type_lsb = IB_NOTICE_PROD_CA; |
5cd24119 EK |
266 | data.trap_num = OPA_TRAP_CHANGE_SYSGUID; |
267 | data.issuer_lid = cpu_to_be32(lid); | |
268 | data.ntc_145.new_sys_guid = ib_hfi1_sys_image_guid; | |
269 | data.ntc_145.lid = data.issuer_lid; | |
77241056 MM |
270 | |
271 | send_trap(ibp, &data, sizeof(data)); | |
272 | } | |
273 | ||
274 | /* | |
275 | * Send a Node Description Changed trap (ch. 14.3.13). | |
276 | */ | |
277 | void hfi1_node_desc_chg(struct hfi1_ibport *ibp) | |
278 | { | |
5cd24119 EK |
279 | struct opa_mad_notice_attr data; |
280 | u32 lid = ppd_from_ibp(ibp)->lid; | |
281 | ||
282 | memset(&data, 0, sizeof(data)); | |
77241056 MM |
283 | |
284 | data.generic_type = IB_NOTICE_TYPE_INFO; | |
77241056 | 285 | data.prod_type_lsb = IB_NOTICE_PROD_CA; |
5cd24119 EK |
286 | data.trap_num = OPA_TRAP_CHANGE_CAPABILITY; |
287 | data.issuer_lid = cpu_to_be32(lid); | |
288 | data.ntc_144.lid = data.issuer_lid; | |
289 | data.ntc_144.change_flags = | |
290 | cpu_to_be16(OPA_NOTICE_TRAP_NODE_DESC_CHG); | |
77241056 MM |
291 | |
292 | send_trap(ibp, &data, sizeof(data)); | |
293 | } | |
294 | ||
295 | static int __subn_get_opa_nodedesc(struct opa_smp *smp, u32 am, | |
296 | u8 *data, struct ib_device *ibdev, | |
297 | u8 port, u32 *resp_len) | |
298 | { | |
299 | struct opa_node_description *nd; | |
300 | ||
301 | if (am) { | |
302 | smp->status |= IB_SMP_INVALID_FIELD; | |
303 | return reply((struct ib_mad_hdr *)smp); | |
304 | } | |
305 | ||
306 | nd = (struct opa_node_description *)data; | |
307 | ||
308 | memcpy(nd->data, ibdev->node_desc, sizeof(nd->data)); | |
309 | ||
310 | if (resp_len) | |
311 | *resp_len += sizeof(*nd); | |
312 | ||
313 | return reply((struct ib_mad_hdr *)smp); | |
314 | } | |
315 | ||
316 | static int __subn_get_opa_nodeinfo(struct opa_smp *smp, u32 am, u8 *data, | |
317 | struct ib_device *ibdev, u8 port, | |
318 | u32 *resp_len) | |
319 | { | |
320 | struct opa_node_info *ni; | |
321 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
322 | unsigned pidx = port - 1; /* IB number port from 1, hw from 0 */ | |
323 | ||
324 | ni = (struct opa_node_info *)data; | |
325 | ||
326 | /* GUID 0 is illegal */ | |
327 | if (am || pidx >= dd->num_pports || dd->pport[pidx].guid == 0) { | |
328 | smp->status |= IB_SMP_INVALID_FIELD; | |
329 | return reply((struct ib_mad_hdr *)smp); | |
330 | } | |
331 | ||
332 | ni->port_guid = cpu_to_be64(dd->pport[pidx].guid); | |
333 | ni->base_version = OPA_MGMT_BASE_VERSION; | |
334 | ni->class_version = OPA_SMI_CLASS_VERSION; | |
335 | ni->node_type = 1; /* channel adapter */ | |
336 | ni->num_ports = ibdev->phys_port_cnt; | |
337 | /* This is already in network order */ | |
338 | ni->system_image_guid = ib_hfi1_sys_image_guid; | |
339 | /* Use first-port GUID as node */ | |
340 | ni->node_guid = cpu_to_be64(dd->pport->guid); | |
341 | ni->partition_cap = cpu_to_be16(hfi1_get_npkeys(dd)); | |
342 | ni->device_id = cpu_to_be16(dd->pcidev->device); | |
343 | ni->revision = cpu_to_be32(dd->minrev); | |
344 | ni->local_port_num = port; | |
345 | ni->vendor_id[0] = dd->oui1; | |
346 | ni->vendor_id[1] = dd->oui2; | |
347 | ni->vendor_id[2] = dd->oui3; | |
348 | ||
349 | if (resp_len) | |
350 | *resp_len += sizeof(*ni); | |
351 | ||
352 | return reply((struct ib_mad_hdr *)smp); | |
353 | } | |
354 | ||
355 | static int subn_get_nodeinfo(struct ib_smp *smp, struct ib_device *ibdev, | |
356 | u8 port) | |
357 | { | |
358 | struct ib_node_info *nip = (struct ib_node_info *)&smp->data; | |
359 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
360 | unsigned pidx = port - 1; /* IB number port from 1, hw from 0 */ | |
361 | ||
362 | /* GUID 0 is illegal */ | |
363 | if (smp->attr_mod || pidx >= dd->num_pports || | |
364 | dd->pport[pidx].guid == 0) | |
365 | smp->status |= IB_SMP_INVALID_FIELD; | |
366 | else | |
367 | nip->port_guid = cpu_to_be64(dd->pport[pidx].guid); | |
368 | ||
369 | nip->base_version = OPA_MGMT_BASE_VERSION; | |
370 | nip->class_version = OPA_SMI_CLASS_VERSION; | |
371 | nip->node_type = 1; /* channel adapter */ | |
372 | nip->num_ports = ibdev->phys_port_cnt; | |
373 | /* This is already in network order */ | |
374 | nip->sys_guid = ib_hfi1_sys_image_guid; | |
375 | /* Use first-port GUID as node */ | |
376 | nip->node_guid = cpu_to_be64(dd->pport->guid); | |
377 | nip->partition_cap = cpu_to_be16(hfi1_get_npkeys(dd)); | |
378 | nip->device_id = cpu_to_be16(dd->pcidev->device); | |
379 | nip->revision = cpu_to_be32(dd->minrev); | |
380 | nip->local_port_num = port; | |
381 | nip->vendor_id[0] = dd->oui1; | |
382 | nip->vendor_id[1] = dd->oui2; | |
383 | nip->vendor_id[2] = dd->oui3; | |
384 | ||
385 | return reply((struct ib_mad_hdr *)smp); | |
386 | } | |
387 | ||
388 | static void set_link_width_enabled(struct hfi1_pportdata *ppd, u32 w) | |
389 | { | |
390 | (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_LWID_ENB, w); | |
391 | } | |
392 | ||
393 | static void set_link_width_downgrade_enabled(struct hfi1_pportdata *ppd, u32 w) | |
394 | { | |
395 | (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_LWID_DG_ENB, w); | |
396 | } | |
397 | ||
398 | static void set_link_speed_enabled(struct hfi1_pportdata *ppd, u32 s) | |
399 | { | |
400 | (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_SPD_ENB, s); | |
401 | } | |
402 | ||
403 | static int check_mkey(struct hfi1_ibport *ibp, struct ib_mad_hdr *mad, | |
404 | int mad_flags, __be64 mkey, __be32 dr_slid, | |
405 | u8 return_path[], u8 hop_cnt) | |
406 | { | |
407 | int valid_mkey = 0; | |
408 | int ret = 0; | |
409 | ||
410 | /* Is the mkey in the process of expiring? */ | |
4eb06882 DD |
411 | if (ibp->rvp.mkey_lease_timeout && |
412 | time_after_eq(jiffies, ibp->rvp.mkey_lease_timeout)) { | |
77241056 | 413 | /* Clear timeout and mkey protection field. */ |
4eb06882 DD |
414 | ibp->rvp.mkey_lease_timeout = 0; |
415 | ibp->rvp.mkeyprot = 0; | |
77241056 MM |
416 | } |
417 | ||
4eb06882 DD |
418 | if ((mad_flags & IB_MAD_IGNORE_MKEY) || ibp->rvp.mkey == 0 || |
419 | ibp->rvp.mkey == mkey) | |
77241056 MM |
420 | valid_mkey = 1; |
421 | ||
422 | /* Unset lease timeout on any valid Get/Set/TrapRepress */ | |
4eb06882 | 423 | if (valid_mkey && ibp->rvp.mkey_lease_timeout && |
77241056 MM |
424 | (mad->method == IB_MGMT_METHOD_GET || |
425 | mad->method == IB_MGMT_METHOD_SET || | |
426 | mad->method == IB_MGMT_METHOD_TRAP_REPRESS)) | |
4eb06882 | 427 | ibp->rvp.mkey_lease_timeout = 0; |
77241056 MM |
428 | |
429 | if (!valid_mkey) { | |
430 | switch (mad->method) { | |
431 | case IB_MGMT_METHOD_GET: | |
432 | /* Bad mkey not a violation below level 2 */ | |
4eb06882 | 433 | if (ibp->rvp.mkeyprot < 2) |
77241056 MM |
434 | break; |
435 | case IB_MGMT_METHOD_SET: | |
436 | case IB_MGMT_METHOD_TRAP_REPRESS: | |
4eb06882 DD |
437 | if (ibp->rvp.mkey_violations != 0xFFFF) |
438 | ++ibp->rvp.mkey_violations; | |
439 | if (!ibp->rvp.mkey_lease_timeout && | |
440 | ibp->rvp.mkey_lease_period) | |
441 | ibp->rvp.mkey_lease_timeout = jiffies + | |
442 | ibp->rvp.mkey_lease_period * HZ; | |
77241056 MM |
443 | /* Generate a trap notice. */ |
444 | bad_mkey(ibp, mad, mkey, dr_slid, return_path, | |
445 | hop_cnt); | |
446 | ret = 1; | |
447 | } | |
448 | } | |
449 | ||
450 | return ret; | |
451 | } | |
452 | ||
453 | /* | |
454 | * The SMA caches reads from LCB registers in case the LCB is unavailable. | |
455 | * (The LCB is unavailable in certain link states, for example.) | |
456 | */ | |
457 | struct lcb_datum { | |
458 | u32 off; | |
459 | u64 val; | |
460 | }; | |
461 | ||
462 | static struct lcb_datum lcb_cache[] = { | |
463 | { DC_LCB_STS_ROUND_TRIP_LTP_CNT, 0 }, | |
464 | }; | |
465 | ||
466 | static int write_lcb_cache(u32 off, u64 val) | |
467 | { | |
468 | int i; | |
469 | ||
470 | for (i = 0; i < ARRAY_SIZE(lcb_cache); i++) { | |
471 | if (lcb_cache[i].off == off) { | |
472 | lcb_cache[i].val = val; | |
473 | return 0; | |
474 | } | |
475 | } | |
476 | ||
477 | pr_warn("%s bad offset 0x%x\n", __func__, off); | |
478 | return -1; | |
479 | } | |
480 | ||
481 | static int read_lcb_cache(u32 off, u64 *val) | |
482 | { | |
483 | int i; | |
484 | ||
485 | for (i = 0; i < ARRAY_SIZE(lcb_cache); i++) { | |
486 | if (lcb_cache[i].off == off) { | |
487 | *val = lcb_cache[i].val; | |
488 | return 0; | |
489 | } | |
490 | } | |
491 | ||
492 | pr_warn("%s bad offset 0x%x\n", __func__, off); | |
493 | return -1; | |
494 | } | |
495 | ||
496 | void read_ltp_rtt(struct hfi1_devdata *dd) | |
497 | { | |
498 | u64 reg; | |
499 | ||
500 | if (read_lcb_csr(dd, DC_LCB_STS_ROUND_TRIP_LTP_CNT, ®)) | |
501 | dd_dev_err(dd, "%s: unable to read LTP RTT\n", __func__); | |
502 | else | |
503 | write_lcb_cache(DC_LCB_STS_ROUND_TRIP_LTP_CNT, reg); | |
504 | } | |
505 | ||
77241056 MM |
506 | static int __subn_get_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data, |
507 | struct ib_device *ibdev, u8 port, | |
508 | u32 *resp_len) | |
509 | { | |
510 | int i; | |
511 | struct hfi1_devdata *dd; | |
512 | struct hfi1_pportdata *ppd; | |
513 | struct hfi1_ibport *ibp; | |
514 | struct opa_port_info *pi = (struct opa_port_info *)data; | |
515 | u8 mtu; | |
516 | u8 credit_rate; | |
517 | u32 state; | |
518 | u32 num_ports = OPA_AM_NPORT(am); | |
519 | u32 start_of_sm_config = OPA_AM_START_SM_CFG(am); | |
520 | u32 buffer_units; | |
521 | u64 tmp = 0; | |
522 | ||
523 | if (num_ports != 1) { | |
524 | smp->status |= IB_SMP_INVALID_FIELD; | |
525 | return reply((struct ib_mad_hdr *)smp); | |
526 | } | |
527 | ||
528 | dd = dd_from_ibdev(ibdev); | |
529 | /* IB numbers ports from 1, hw from 0 */ | |
530 | ppd = dd->pport + (port - 1); | |
531 | ibp = &ppd->ibport_data; | |
532 | ||
533 | if (ppd->vls_supported/2 > ARRAY_SIZE(pi->neigh_mtu.pvlx_to_mtu) || | |
534 | ppd->vls_supported > ARRAY_SIZE(dd->vld)) { | |
535 | smp->status |= IB_SMP_INVALID_FIELD; | |
536 | return reply((struct ib_mad_hdr *)smp); | |
537 | } | |
538 | ||
539 | pi->lid = cpu_to_be32(ppd->lid); | |
540 | ||
541 | /* Only return the mkey if the protection field allows it. */ | |
542 | if (!(smp->method == IB_MGMT_METHOD_GET && | |
4eb06882 DD |
543 | ibp->rvp.mkey != smp->mkey && |
544 | ibp->rvp.mkeyprot == 1)) | |
545 | pi->mkey = ibp->rvp.mkey; | |
546 | ||
547 | pi->subnet_prefix = ibp->rvp.gid_prefix; | |
548 | pi->sm_lid = cpu_to_be32(ibp->rvp.sm_lid); | |
549 | pi->ib_cap_mask = cpu_to_be32(ibp->rvp.port_cap_flags); | |
550 | pi->mkey_lease_period = cpu_to_be16(ibp->rvp.mkey_lease_period); | |
77241056 MM |
551 | pi->sm_trap_qp = cpu_to_be32(ppd->sm_trap_qp); |
552 | pi->sa_qp = cpu_to_be32(ppd->sa_qp); | |
553 | ||
554 | pi->link_width.enabled = cpu_to_be16(ppd->link_width_enabled); | |
555 | pi->link_width.supported = cpu_to_be16(ppd->link_width_supported); | |
556 | pi->link_width.active = cpu_to_be16(ppd->link_width_active); | |
557 | ||
558 | pi->link_width_downgrade.supported = | |
559 | cpu_to_be16(ppd->link_width_downgrade_supported); | |
560 | pi->link_width_downgrade.enabled = | |
561 | cpu_to_be16(ppd->link_width_downgrade_enabled); | |
562 | pi->link_width_downgrade.tx_active = | |
563 | cpu_to_be16(ppd->link_width_downgrade_tx_active); | |
564 | pi->link_width_downgrade.rx_active = | |
565 | cpu_to_be16(ppd->link_width_downgrade_rx_active); | |
566 | ||
567 | pi->link_speed.supported = cpu_to_be16(ppd->link_speed_supported); | |
568 | pi->link_speed.active = cpu_to_be16(ppd->link_speed_active); | |
569 | pi->link_speed.enabled = cpu_to_be16(ppd->link_speed_enabled); | |
570 | ||
571 | state = driver_lstate(ppd); | |
572 | ||
573 | if (start_of_sm_config && (state == IB_PORT_INIT)) | |
574 | ppd->is_sm_config_started = 1; | |
575 | ||
1d01cf33 | 576 | pi->port_phys_conf = (ppd->port_type & 0xf); |
77241056 MM |
577 | |
578 | #if PI_LED_ENABLE_SUP | |
579 | pi->port_states.ledenable_offlinereason = ppd->neighbor_normal << 4; | |
580 | pi->port_states.ledenable_offlinereason |= | |
581 | ppd->is_sm_config_started << 5; | |
582 | pi->port_states.ledenable_offlinereason |= | |
a9c05e35 | 583 | ppd->offline_disabled_reason; |
77241056 MM |
584 | #else |
585 | pi->port_states.offline_reason = ppd->neighbor_normal << 4; | |
586 | pi->port_states.offline_reason |= ppd->is_sm_config_started << 5; | |
a9c05e35 | 587 | pi->port_states.offline_reason |= ppd->offline_disabled_reason; |
77241056 MM |
588 | #endif /* PI_LED_ENABLE_SUP */ |
589 | ||
590 | pi->port_states.portphysstate_portstate = | |
591 | (hfi1_ibphys_portstate(ppd) << 4) | state; | |
592 | ||
4eb06882 | 593 | pi->mkeyprotect_lmc = (ibp->rvp.mkeyprot << 6) | ppd->lmc; |
77241056 MM |
594 | |
595 | memset(pi->neigh_mtu.pvlx_to_mtu, 0, sizeof(pi->neigh_mtu.pvlx_to_mtu)); | |
596 | for (i = 0; i < ppd->vls_supported; i++) { | |
597 | mtu = mtu_to_enum(dd->vld[i].mtu, HFI1_DEFAULT_ACTIVE_MTU); | |
598 | if ((i % 2) == 0) | |
599 | pi->neigh_mtu.pvlx_to_mtu[i/2] |= (mtu << 4); | |
600 | else | |
601 | pi->neigh_mtu.pvlx_to_mtu[i/2] |= mtu; | |
602 | } | |
603 | /* don't forget VL 15 */ | |
604 | mtu = mtu_to_enum(dd->vld[15].mtu, 2048); | |
605 | pi->neigh_mtu.pvlx_to_mtu[15/2] |= mtu; | |
4eb06882 | 606 | pi->smsl = ibp->rvp.sm_sl & OPA_PI_MASK_SMSL; |
77241056 MM |
607 | pi->operational_vls = hfi1_get_ib_cfg(ppd, HFI1_IB_CFG_OP_VLS); |
608 | pi->partenforce_filterraw |= | |
609 | (ppd->linkinit_reason & OPA_PI_MASK_LINKINIT_REASON); | |
610 | if (ppd->part_enforce & HFI1_PART_ENFORCE_IN) | |
611 | pi->partenforce_filterraw |= OPA_PI_MASK_PARTITION_ENFORCE_IN; | |
612 | if (ppd->part_enforce & HFI1_PART_ENFORCE_OUT) | |
613 | pi->partenforce_filterraw |= OPA_PI_MASK_PARTITION_ENFORCE_OUT; | |
4eb06882 | 614 | pi->mkey_violations = cpu_to_be16(ibp->rvp.mkey_violations); |
77241056 | 615 | /* P_KeyViolations are counted by hardware. */ |
4eb06882 DD |
616 | pi->pkey_violations = cpu_to_be16(ibp->rvp.pkey_violations); |
617 | pi->qkey_violations = cpu_to_be16(ibp->rvp.qkey_violations); | |
77241056 MM |
618 | |
619 | pi->vl.cap = ppd->vls_supported; | |
4eb06882 | 620 | pi->vl.high_limit = cpu_to_be16(ibp->rvp.vl_high_limit); |
77241056 MM |
621 | pi->vl.arb_high_cap = (u8)hfi1_get_ib_cfg(ppd, HFI1_IB_CFG_VL_HIGH_CAP); |
622 | pi->vl.arb_low_cap = (u8)hfi1_get_ib_cfg(ppd, HFI1_IB_CFG_VL_LOW_CAP); | |
623 | ||
4eb06882 | 624 | pi->clientrereg_subnettimeout = ibp->rvp.subnet_timeout; |
77241056 MM |
625 | |
626 | pi->port_link_mode = cpu_to_be16(OPA_PORT_LINK_MODE_OPA << 10 | | |
627 | OPA_PORT_LINK_MODE_OPA << 5 | | |
628 | OPA_PORT_LINK_MODE_OPA); | |
629 | ||
630 | pi->port_ltp_crc_mode = cpu_to_be16(ppd->port_ltp_crc_mode); | |
631 | ||
632 | pi->port_mode = cpu_to_be16( | |
633 | ppd->is_active_optimize_enabled ? | |
634 | OPA_PI_MASK_PORT_ACTIVE_OPTOMIZE : 0); | |
635 | ||
636 | pi->port_packet_format.supported = | |
637 | cpu_to_be16(OPA_PORT_PACKET_FORMAT_9B); | |
638 | pi->port_packet_format.enabled = | |
639 | cpu_to_be16(OPA_PORT_PACKET_FORMAT_9B); | |
640 | ||
641 | /* flit_control.interleave is (OPA V1, version .76): | |
642 | * bits use | |
643 | * ---- --- | |
644 | * 2 res | |
645 | * 2 DistanceSupported | |
646 | * 2 DistanceEnabled | |
647 | * 5 MaxNextLevelTxEnabled | |
648 | * 5 MaxNestLevelRxSupported | |
649 | * | |
650 | * HFI supports only "distance mode 1" (see OPA V1, version .76, | |
651 | * section 9.6.2), so set DistanceSupported, DistanceEnabled | |
652 | * to 0x1. | |
653 | */ | |
654 | pi->flit_control.interleave = cpu_to_be16(0x1400); | |
655 | ||
656 | pi->link_down_reason = ppd->local_link_down_reason.sma; | |
657 | pi->neigh_link_down_reason = ppd->neigh_link_down_reason.sma; | |
658 | pi->port_error_action = cpu_to_be32(ppd->port_error_action); | |
659 | pi->mtucap = mtu_to_enum(hfi1_max_mtu, IB_MTU_4096); | |
660 | ||
661 | /* 32.768 usec. response time (guessing) */ | |
662 | pi->resptimevalue = 3; | |
663 | ||
664 | pi->local_port_num = port; | |
665 | ||
666 | /* buffer info for FM */ | |
667 | pi->overall_buffer_space = cpu_to_be16(dd->link_credits); | |
668 | ||
669 | pi->neigh_node_guid = cpu_to_be64(ppd->neighbor_guid); | |
670 | pi->neigh_port_num = ppd->neighbor_port_number; | |
671 | pi->port_neigh_mode = | |
672 | (ppd->neighbor_type & OPA_PI_MASK_NEIGH_NODE_TYPE) | | |
673 | (ppd->mgmt_allowed ? OPA_PI_MASK_NEIGH_MGMT_ALLOWED : 0) | | |
674 | (ppd->neighbor_fm_security ? | |
675 | OPA_PI_MASK_NEIGH_FW_AUTH_BYPASS : 0); | |
676 | ||
677 | /* HFIs shall always return VL15 credits to their | |
678 | * neighbor in a timely manner, without any credit return pacing. | |
679 | */ | |
680 | credit_rate = 0; | |
681 | buffer_units = (dd->vau) & OPA_PI_MASK_BUF_UNIT_BUF_ALLOC; | |
682 | buffer_units |= (dd->vcu << 3) & OPA_PI_MASK_BUF_UNIT_CREDIT_ACK; | |
683 | buffer_units |= (credit_rate << 6) & | |
684 | OPA_PI_MASK_BUF_UNIT_VL15_CREDIT_RATE; | |
685 | buffer_units |= (dd->vl15_init << 11) & OPA_PI_MASK_BUF_UNIT_VL15_INIT; | |
686 | pi->buffer_units = cpu_to_be32(buffer_units); | |
687 | ||
688 | pi->opa_cap_mask = cpu_to_be16(OPA_CAP_MASK3_IsSharedSpaceSupported); | |
689 | ||
690 | /* HFI supports a replay buffer 128 LTPs in size */ | |
691 | pi->replay_depth.buffer = 0x80; | |
692 | /* read the cached value of DC_LCB_STS_ROUND_TRIP_LTP_CNT */ | |
693 | read_lcb_cache(DC_LCB_STS_ROUND_TRIP_LTP_CNT, &tmp); | |
694 | ||
695 | /* this counter is 16 bits wide, but the replay_depth.wire | |
696 | * variable is only 8 bits */ | |
697 | if (tmp > 0xff) | |
698 | tmp = 0xff; | |
699 | pi->replay_depth.wire = tmp; | |
700 | ||
701 | if (resp_len) | |
702 | *resp_len += sizeof(struct opa_port_info); | |
703 | ||
704 | return reply((struct ib_mad_hdr *)smp); | |
705 | } | |
706 | ||
707 | /** | |
708 | * get_pkeys - return the PKEY table | |
709 | * @dd: the hfi1_ib device | |
710 | * @port: the IB port number | |
711 | * @pkeys: the pkey table is placed here | |
712 | */ | |
713 | static int get_pkeys(struct hfi1_devdata *dd, u8 port, u16 *pkeys) | |
714 | { | |
715 | struct hfi1_pportdata *ppd = dd->pport + port - 1; | |
716 | ||
717 | memcpy(pkeys, ppd->pkeys, sizeof(ppd->pkeys)); | |
718 | ||
719 | return 0; | |
720 | } | |
721 | ||
722 | static int __subn_get_opa_pkeytable(struct opa_smp *smp, u32 am, u8 *data, | |
723 | struct ib_device *ibdev, u8 port, | |
724 | u32 *resp_len) | |
725 | { | |
726 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
727 | u32 n_blocks_req = OPA_AM_NBLK(am); | |
728 | u32 start_block = am & 0x7ff; | |
729 | __be16 *p; | |
730 | u16 *q; | |
731 | int i; | |
732 | u16 n_blocks_avail; | |
733 | unsigned npkeys = hfi1_get_npkeys(dd); | |
734 | size_t size; | |
735 | ||
736 | if (n_blocks_req == 0) { | |
737 | pr_warn("OPA Get PKey AM Invalid : P = %d; B = 0x%x; N = 0x%x\n", | |
738 | port, start_block, n_blocks_req); | |
739 | smp->status |= IB_SMP_INVALID_FIELD; | |
740 | return reply((struct ib_mad_hdr *)smp); | |
741 | } | |
742 | ||
743 | n_blocks_avail = (u16) (npkeys/OPA_PARTITION_TABLE_BLK_SIZE) + 1; | |
744 | ||
745 | size = (n_blocks_req * OPA_PARTITION_TABLE_BLK_SIZE) * sizeof(u16); | |
746 | ||
747 | if (start_block + n_blocks_req > n_blocks_avail || | |
748 | n_blocks_req > OPA_NUM_PKEY_BLOCKS_PER_SMP) { | |
749 | pr_warn("OPA Get PKey AM Invalid : s 0x%x; req 0x%x; " | |
750 | "avail 0x%x; blk/smp 0x%lx\n", | |
751 | start_block, n_blocks_req, n_blocks_avail, | |
752 | OPA_NUM_PKEY_BLOCKS_PER_SMP); | |
753 | smp->status |= IB_SMP_INVALID_FIELD; | |
754 | return reply((struct ib_mad_hdr *)smp); | |
755 | } | |
756 | ||
757 | p = (__be16 *) data; | |
758 | q = (u16 *)data; | |
759 | /* get the real pkeys if we are requesting the first block */ | |
760 | if (start_block == 0) { | |
761 | get_pkeys(dd, port, q); | |
762 | for (i = 0; i < npkeys; i++) | |
763 | p[i] = cpu_to_be16(q[i]); | |
764 | if (resp_len) | |
765 | *resp_len += size; | |
766 | } else | |
767 | smp->status |= IB_SMP_INVALID_FIELD; | |
768 | ||
769 | return reply((struct ib_mad_hdr *)smp); | |
770 | } | |
771 | ||
772 | enum { | |
773 | HFI_TRANSITION_DISALLOWED, | |
774 | HFI_TRANSITION_IGNORED, | |
775 | HFI_TRANSITION_ALLOWED, | |
776 | HFI_TRANSITION_UNDEFINED, | |
777 | }; | |
778 | ||
779 | /* | |
780 | * Use shortened names to improve readability of | |
781 | * {logical,physical}_state_transitions | |
782 | */ | |
783 | enum { | |
784 | __D = HFI_TRANSITION_DISALLOWED, | |
785 | __I = HFI_TRANSITION_IGNORED, | |
786 | __A = HFI_TRANSITION_ALLOWED, | |
787 | __U = HFI_TRANSITION_UNDEFINED, | |
788 | }; | |
789 | ||
790 | /* | |
791 | * IB_PORTPHYSSTATE_POLLING (2) through OPA_PORTPHYSSTATE_MAX (11) are | |
792 | * represented in physical_state_transitions. | |
793 | */ | |
794 | #define __N_PHYSTATES (OPA_PORTPHYSSTATE_MAX - IB_PORTPHYSSTATE_POLLING + 1) | |
795 | ||
796 | /* | |
797 | * Within physical_state_transitions, rows represent "old" states, | |
798 | * columns "new" states, and physical_state_transitions.allowed[old][new] | |
799 | * indicates if the transition from old state to new state is legal (see | |
800 | * OPAg1v1, Table 6-4). | |
801 | */ | |
802 | static const struct { | |
803 | u8 allowed[__N_PHYSTATES][__N_PHYSTATES]; | |
804 | } physical_state_transitions = { | |
805 | { | |
806 | /* 2 3 4 5 6 7 8 9 10 11 */ | |
807 | /* 2 */ { __A, __A, __D, __D, __D, __D, __D, __D, __D, __D }, | |
808 | /* 3 */ { __A, __I, __D, __D, __D, __D, __D, __D, __D, __A }, | |
809 | /* 4 */ { __U, __U, __U, __U, __U, __U, __U, __U, __U, __U }, | |
810 | /* 5 */ { __A, __A, __D, __I, __D, __D, __D, __D, __D, __D }, | |
811 | /* 6 */ { __U, __U, __U, __U, __U, __U, __U, __U, __U, __U }, | |
812 | /* 7 */ { __D, __A, __D, __D, __D, __I, __D, __D, __D, __D }, | |
813 | /* 8 */ { __U, __U, __U, __U, __U, __U, __U, __U, __U, __U }, | |
814 | /* 9 */ { __I, __A, __D, __D, __D, __D, __D, __I, __D, __D }, | |
815 | /*10 */ { __U, __U, __U, __U, __U, __U, __U, __U, __U, __U }, | |
816 | /*11 */ { __D, __A, __D, __D, __D, __D, __D, __D, __D, __I }, | |
817 | } | |
818 | }; | |
819 | ||
820 | /* | |
821 | * IB_PORT_DOWN (1) through IB_PORT_ACTIVE_DEFER (5) are represented | |
822 | * logical_state_transitions | |
823 | */ | |
824 | ||
825 | #define __N_LOGICAL_STATES (IB_PORT_ACTIVE_DEFER - IB_PORT_DOWN + 1) | |
826 | ||
827 | /* | |
828 | * Within logical_state_transitions rows represent "old" states, | |
829 | * columns "new" states, and logical_state_transitions.allowed[old][new] | |
830 | * indicates if the transition from old state to new state is legal (see | |
831 | * OPAg1v1, Table 9-12). | |
832 | */ | |
833 | static const struct { | |
834 | u8 allowed[__N_LOGICAL_STATES][__N_LOGICAL_STATES]; | |
835 | } logical_state_transitions = { | |
836 | { | |
837 | /* 1 2 3 4 5 */ | |
838 | /* 1 */ { __I, __D, __D, __D, __U}, | |
839 | /* 2 */ { __D, __I, __A, __D, __U}, | |
840 | /* 3 */ { __D, __D, __I, __A, __U}, | |
841 | /* 4 */ { __D, __D, __I, __I, __U}, | |
842 | /* 5 */ { __U, __U, __U, __U, __U}, | |
843 | } | |
844 | }; | |
845 | ||
846 | static int logical_transition_allowed(int old, int new) | |
847 | { | |
848 | if (old < IB_PORT_NOP || old > IB_PORT_ACTIVE_DEFER || | |
849 | new < IB_PORT_NOP || new > IB_PORT_ACTIVE_DEFER) { | |
850 | pr_warn("invalid logical state(s) (old %d new %d)\n", | |
851 | old, new); | |
852 | return HFI_TRANSITION_UNDEFINED; | |
853 | } | |
854 | ||
855 | if (new == IB_PORT_NOP) | |
856 | return HFI_TRANSITION_ALLOWED; /* always allowed */ | |
857 | ||
858 | /* adjust states for indexing into logical_state_transitions */ | |
859 | old -= IB_PORT_DOWN; | |
860 | new -= IB_PORT_DOWN; | |
861 | ||
862 | if (old < 0 || new < 0) | |
863 | return HFI_TRANSITION_UNDEFINED; | |
864 | return logical_state_transitions.allowed[old][new]; | |
865 | } | |
866 | ||
867 | static int physical_transition_allowed(int old, int new) | |
868 | { | |
869 | if (old < IB_PORTPHYSSTATE_NOP || old > OPA_PORTPHYSSTATE_MAX || | |
870 | new < IB_PORTPHYSSTATE_NOP || new > OPA_PORTPHYSSTATE_MAX) { | |
871 | pr_warn("invalid physical state(s) (old %d new %d)\n", | |
872 | old, new); | |
873 | return HFI_TRANSITION_UNDEFINED; | |
874 | } | |
875 | ||
876 | if (new == IB_PORTPHYSSTATE_NOP) | |
877 | return HFI_TRANSITION_ALLOWED; /* always allowed */ | |
878 | ||
879 | /* adjust states for indexing into physical_state_transitions */ | |
880 | old -= IB_PORTPHYSSTATE_POLLING; | |
881 | new -= IB_PORTPHYSSTATE_POLLING; | |
882 | ||
883 | if (old < 0 || new < 0) | |
884 | return HFI_TRANSITION_UNDEFINED; | |
885 | return physical_state_transitions.allowed[old][new]; | |
886 | } | |
887 | ||
888 | static int port_states_transition_allowed(struct hfi1_pportdata *ppd, | |
889 | u32 logical_new, u32 physical_new) | |
890 | { | |
891 | u32 physical_old = driver_physical_state(ppd); | |
892 | u32 logical_old = driver_logical_state(ppd); | |
893 | int ret, logical_allowed, physical_allowed; | |
894 | ||
895 | logical_allowed = ret = | |
896 | logical_transition_allowed(logical_old, logical_new); | |
897 | ||
898 | if (ret == HFI_TRANSITION_DISALLOWED || | |
899 | ret == HFI_TRANSITION_UNDEFINED) { | |
900 | pr_warn("invalid logical state transition %s -> %s\n", | |
901 | opa_lstate_name(logical_old), | |
902 | opa_lstate_name(logical_new)); | |
903 | return ret; | |
904 | } | |
905 | ||
906 | physical_allowed = ret = | |
907 | physical_transition_allowed(physical_old, physical_new); | |
908 | ||
909 | if (ret == HFI_TRANSITION_DISALLOWED || | |
910 | ret == HFI_TRANSITION_UNDEFINED) { | |
911 | pr_warn("invalid physical state transition %s -> %s\n", | |
912 | opa_pstate_name(physical_old), | |
913 | opa_pstate_name(physical_new)); | |
914 | return ret; | |
915 | } | |
916 | ||
917 | if (logical_allowed == HFI_TRANSITION_IGNORED && | |
918 | physical_allowed == HFI_TRANSITION_IGNORED) | |
919 | return HFI_TRANSITION_IGNORED; | |
920 | ||
a9c05e35 BM |
921 | /* |
922 | * A change request of Physical Port State from | |
923 | * 'Offline' to 'Polling' should be ignored. | |
924 | */ | |
925 | if ((physical_old == OPA_PORTPHYSSTATE_OFFLINE) && | |
926 | (physical_new == IB_PORTPHYSSTATE_POLLING)) | |
927 | return HFI_TRANSITION_IGNORED; | |
928 | ||
77241056 MM |
929 | /* |
930 | * Either physical_allowed or logical_allowed is | |
931 | * HFI_TRANSITION_ALLOWED. | |
932 | */ | |
933 | return HFI_TRANSITION_ALLOWED; | |
934 | } | |
935 | ||
936 | static int set_port_states(struct hfi1_pportdata *ppd, struct opa_smp *smp, | |
937 | u32 logical_state, u32 phys_state, | |
938 | int suppress_idle_sma) | |
939 | { | |
940 | struct hfi1_devdata *dd = ppd->dd; | |
941 | u32 link_state; | |
942 | int ret; | |
943 | ||
944 | ret = port_states_transition_allowed(ppd, logical_state, phys_state); | |
945 | if (ret == HFI_TRANSITION_DISALLOWED || | |
946 | ret == HFI_TRANSITION_UNDEFINED) { | |
947 | /* error message emitted above */ | |
948 | smp->status |= IB_SMP_INVALID_FIELD; | |
949 | return 0; | |
950 | } | |
951 | ||
952 | if (ret == HFI_TRANSITION_IGNORED) | |
953 | return 0; | |
954 | ||
955 | if ((phys_state != IB_PORTPHYSSTATE_NOP) && | |
956 | !(logical_state == IB_PORT_DOWN || | |
957 | logical_state == IB_PORT_NOP)){ | |
958 | pr_warn("SubnSet(OPA_PortInfo) port state invalid: logical_state 0x%x physical_state 0x%x\n", | |
959 | logical_state, phys_state); | |
960 | smp->status |= IB_SMP_INVALID_FIELD; | |
961 | } | |
962 | ||
963 | /* | |
964 | * Logical state changes are summarized in OPAv1g1 spec., | |
965 | * Table 9-12; physical state changes are summarized in | |
966 | * OPAv1g1 spec., Table 6.4. | |
967 | */ | |
968 | switch (logical_state) { | |
969 | case IB_PORT_NOP: | |
970 | if (phys_state == IB_PORTPHYSSTATE_NOP) | |
971 | break; | |
972 | /* FALLTHROUGH */ | |
973 | case IB_PORT_DOWN: | |
974 | if (phys_state == IB_PORTPHYSSTATE_NOP) | |
975 | link_state = HLS_DN_DOWNDEF; | |
976 | else if (phys_state == IB_PORTPHYSSTATE_POLLING) { | |
977 | link_state = HLS_DN_POLL; | |
978 | set_link_down_reason(ppd, | |
979 | OPA_LINKDOWN_REASON_FM_BOUNCE, 0, | |
980 | OPA_LINKDOWN_REASON_FM_BOUNCE); | |
981 | } else if (phys_state == IB_PORTPHYSSTATE_DISABLED) | |
982 | link_state = HLS_DN_DISABLE; | |
983 | else { | |
984 | pr_warn("SubnSet(OPA_PortInfo) invalid physical state 0x%x\n", | |
985 | phys_state); | |
986 | smp->status |= IB_SMP_INVALID_FIELD; | |
987 | break; | |
988 | } | |
989 | ||
990 | set_link_state(ppd, link_state); | |
991 | if (link_state == HLS_DN_DISABLE && | |
992 | (ppd->offline_disabled_reason > | |
a9c05e35 | 993 | HFI1_ODR_MASK(OPA_LINKDOWN_REASON_SMA_DISABLED) || |
77241056 | 994 | ppd->offline_disabled_reason == |
a9c05e35 | 995 | HFI1_ODR_MASK(OPA_LINKDOWN_REASON_NONE))) |
77241056 | 996 | ppd->offline_disabled_reason = |
a9c05e35 | 997 | HFI1_ODR_MASK(OPA_LINKDOWN_REASON_SMA_DISABLED); |
77241056 MM |
998 | /* |
999 | * Don't send a reply if the response would be sent | |
1000 | * through the disabled port. | |
1001 | */ | |
1002 | if (link_state == HLS_DN_DISABLE && smp->hop_cnt) | |
1003 | return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED; | |
1004 | break; | |
1005 | case IB_PORT_ARMED: | |
1006 | ret = set_link_state(ppd, HLS_UP_ARMED); | |
1007 | if ((ret == 0) && (suppress_idle_sma == 0)) | |
1008 | send_idle_sma(dd, SMA_IDLE_ARM); | |
1009 | break; | |
1010 | case IB_PORT_ACTIVE: | |
1011 | if (ppd->neighbor_normal) { | |
1012 | ret = set_link_state(ppd, HLS_UP_ACTIVE); | |
1013 | if (ret == 0) | |
1014 | send_idle_sma(dd, SMA_IDLE_ACTIVE); | |
1015 | } else { | |
1016 | pr_warn("SubnSet(OPA_PortInfo) Cannot move to Active with NeighborNormal 0\n"); | |
1017 | smp->status |= IB_SMP_INVALID_FIELD; | |
1018 | } | |
1019 | break; | |
1020 | default: | |
1021 | pr_warn("SubnSet(OPA_PortInfo) invalid logical state 0x%x\n", | |
1022 | logical_state); | |
1023 | smp->status |= IB_SMP_INVALID_FIELD; | |
1024 | } | |
1025 | ||
1026 | return 0; | |
1027 | } | |
1028 | ||
1029 | /** | |
1030 | * subn_set_opa_portinfo - set port information | |
1031 | * @smp: the incoming SM packet | |
1032 | * @ibdev: the infiniband device | |
1033 | * @port: the port on the device | |
1034 | * | |
1035 | */ | |
1036 | static int __subn_set_opa_portinfo(struct opa_smp *smp, u32 am, u8 *data, | |
1037 | struct ib_device *ibdev, u8 port, | |
1038 | u32 *resp_len) | |
1039 | { | |
1040 | struct opa_port_info *pi = (struct opa_port_info *)data; | |
1041 | struct ib_event event; | |
1042 | struct hfi1_devdata *dd; | |
1043 | struct hfi1_pportdata *ppd; | |
1044 | struct hfi1_ibport *ibp; | |
1045 | u8 clientrereg; | |
1046 | unsigned long flags; | |
1047 | u32 smlid, opa_lid; /* tmp vars to hold LID values */ | |
1048 | u16 lid; | |
1049 | u8 ls_old, ls_new, ps_new; | |
1050 | u8 vls; | |
1051 | u8 msl; | |
1052 | u8 crc_enabled; | |
1053 | u16 lse, lwe, mtu; | |
1054 | u32 num_ports = OPA_AM_NPORT(am); | |
1055 | u32 start_of_sm_config = OPA_AM_START_SM_CFG(am); | |
1056 | int ret, i, invalid = 0, call_set_mtu = 0; | |
1057 | int call_link_downgrade_policy = 0; | |
1058 | ||
1059 | if (num_ports != 1) { | |
1060 | smp->status |= IB_SMP_INVALID_FIELD; | |
1061 | return reply((struct ib_mad_hdr *)smp); | |
1062 | } | |
1063 | ||
1064 | opa_lid = be32_to_cpu(pi->lid); | |
1065 | if (opa_lid & 0xFFFF0000) { | |
1066 | pr_warn("OPA_PortInfo lid out of range: %X\n", opa_lid); | |
1067 | smp->status |= IB_SMP_INVALID_FIELD; | |
1068 | goto get_only; | |
1069 | } | |
1070 | ||
1071 | lid = (u16)(opa_lid & 0x0000FFFF); | |
1072 | ||
1073 | smlid = be32_to_cpu(pi->sm_lid); | |
1074 | if (smlid & 0xFFFF0000) { | |
1075 | pr_warn("OPA_PortInfo SM lid out of range: %X\n", smlid); | |
1076 | smp->status |= IB_SMP_INVALID_FIELD; | |
1077 | goto get_only; | |
1078 | } | |
1079 | smlid &= 0x0000FFFF; | |
1080 | ||
1081 | clientrereg = (pi->clientrereg_subnettimeout & | |
1082 | OPA_PI_MASK_CLIENT_REREGISTER); | |
1083 | ||
1084 | dd = dd_from_ibdev(ibdev); | |
1085 | /* IB numbers ports from 1, hw from 0 */ | |
1086 | ppd = dd->pport + (port - 1); | |
1087 | ibp = &ppd->ibport_data; | |
1088 | event.device = ibdev; | |
1089 | event.element.port_num = port; | |
1090 | ||
1091 | ls_old = driver_lstate(ppd); | |
1092 | ||
4eb06882 DD |
1093 | ibp->rvp.mkey = pi->mkey; |
1094 | ibp->rvp.gid_prefix = pi->subnet_prefix; | |
1095 | ibp->rvp.mkey_lease_period = be16_to_cpu(pi->mkey_lease_period); | |
77241056 MM |
1096 | |
1097 | /* Must be a valid unicast LID address. */ | |
1098 | if ((lid == 0 && ls_old > IB_PORT_INIT) || | |
8859b4a6 | 1099 | lid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) { |
77241056 MM |
1100 | smp->status |= IB_SMP_INVALID_FIELD; |
1101 | pr_warn("SubnSet(OPA_PortInfo) lid invalid 0x%x\n", | |
1102 | lid); | |
1103 | } else if (ppd->lid != lid || | |
1104 | ppd->lmc != (pi->mkeyprotect_lmc & OPA_PI_MASK_LMC)) { | |
1105 | if (ppd->lid != lid) | |
1106 | hfi1_set_uevent_bits(ppd, _HFI1_EVENT_LID_CHANGE_BIT); | |
1107 | if (ppd->lmc != (pi->mkeyprotect_lmc & OPA_PI_MASK_LMC)) | |
1108 | hfi1_set_uevent_bits(ppd, _HFI1_EVENT_LMC_CHANGE_BIT); | |
1109 | hfi1_set_lid(ppd, lid, pi->mkeyprotect_lmc & OPA_PI_MASK_LMC); | |
1110 | event.event = IB_EVENT_LID_CHANGE; | |
1111 | ib_dispatch_event(&event); | |
1112 | } | |
1113 | ||
1114 | msl = pi->smsl & OPA_PI_MASK_SMSL; | |
1115 | if (pi->partenforce_filterraw & OPA_PI_MASK_LINKINIT_REASON) | |
1116 | ppd->linkinit_reason = | |
1117 | (pi->partenforce_filterraw & | |
1118 | OPA_PI_MASK_LINKINIT_REASON); | |
1119 | /* enable/disable SW pkey checking as per FM control */ | |
1120 | if (pi->partenforce_filterraw & OPA_PI_MASK_PARTITION_ENFORCE_IN) | |
1121 | ppd->part_enforce |= HFI1_PART_ENFORCE_IN; | |
1122 | else | |
1123 | ppd->part_enforce &= ~HFI1_PART_ENFORCE_IN; | |
1124 | ||
1125 | if (pi->partenforce_filterraw & OPA_PI_MASK_PARTITION_ENFORCE_OUT) | |
1126 | ppd->part_enforce |= HFI1_PART_ENFORCE_OUT; | |
1127 | else | |
1128 | ppd->part_enforce &= ~HFI1_PART_ENFORCE_OUT; | |
1129 | ||
1130 | /* Must be a valid unicast LID address. */ | |
1131 | if ((smlid == 0 && ls_old > IB_PORT_INIT) || | |
8859b4a6 | 1132 | smlid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) { |
77241056 MM |
1133 | smp->status |= IB_SMP_INVALID_FIELD; |
1134 | pr_warn("SubnSet(OPA_PortInfo) smlid invalid 0x%x\n", smlid); | |
4eb06882 | 1135 | } else if (smlid != ibp->rvp.sm_lid || msl != ibp->rvp.sm_sl) { |
77241056 | 1136 | pr_warn("SubnSet(OPA_PortInfo) smlid 0x%x\n", smlid); |
4eb06882 | 1137 | spin_lock_irqsave(&ibp->rvp.lock, flags); |
9c4a311e | 1138 | if (ibp->rvp.sm_ah) { |
4eb06882 | 1139 | if (smlid != ibp->rvp.sm_lid) |
9c4a311e | 1140 | ibp->rvp.sm_ah->attr.dlid = smlid; |
4eb06882 | 1141 | if (msl != ibp->rvp.sm_sl) |
9c4a311e | 1142 | ibp->rvp.sm_ah->attr.sl = msl; |
77241056 | 1143 | } |
4eb06882 DD |
1144 | spin_unlock_irqrestore(&ibp->rvp.lock, flags); |
1145 | if (smlid != ibp->rvp.sm_lid) | |
1146 | ibp->rvp.sm_lid = smlid; | |
1147 | if (msl != ibp->rvp.sm_sl) | |
1148 | ibp->rvp.sm_sl = msl; | |
77241056 MM |
1149 | event.event = IB_EVENT_SM_CHANGE; |
1150 | ib_dispatch_event(&event); | |
1151 | } | |
1152 | ||
1153 | if (pi->link_down_reason == 0) { | |
1154 | ppd->local_link_down_reason.sma = 0; | |
1155 | ppd->local_link_down_reason.latest = 0; | |
1156 | } | |
1157 | ||
1158 | if (pi->neigh_link_down_reason == 0) { | |
1159 | ppd->neigh_link_down_reason.sma = 0; | |
1160 | ppd->neigh_link_down_reason.latest = 0; | |
1161 | } | |
1162 | ||
1163 | ppd->sm_trap_qp = be32_to_cpu(pi->sm_trap_qp); | |
1164 | ppd->sa_qp = be32_to_cpu(pi->sa_qp); | |
1165 | ||
1166 | ppd->port_error_action = be32_to_cpu(pi->port_error_action); | |
1167 | lwe = be16_to_cpu(pi->link_width.enabled); | |
1168 | if (lwe) { | |
1169 | if (lwe == OPA_LINK_WIDTH_RESET | |
1170 | || lwe == OPA_LINK_WIDTH_RESET_OLD) | |
1171 | set_link_width_enabled(ppd, ppd->link_width_supported); | |
1172 | else if ((lwe & ~ppd->link_width_supported) == 0) | |
1173 | set_link_width_enabled(ppd, lwe); | |
1174 | else | |
1175 | smp->status |= IB_SMP_INVALID_FIELD; | |
1176 | } | |
1177 | lwe = be16_to_cpu(pi->link_width_downgrade.enabled); | |
1178 | /* LWD.E is always applied - 0 means "disabled" */ | |
1179 | if (lwe == OPA_LINK_WIDTH_RESET | |
1180 | || lwe == OPA_LINK_WIDTH_RESET_OLD) { | |
1181 | set_link_width_downgrade_enabled(ppd, | |
1182 | ppd->link_width_downgrade_supported); | |
1183 | } else if ((lwe & ~ppd->link_width_downgrade_supported) == 0) { | |
1184 | /* only set and apply if something changed */ | |
1185 | if (lwe != ppd->link_width_downgrade_enabled) { | |
1186 | set_link_width_downgrade_enabled(ppd, lwe); | |
1187 | call_link_downgrade_policy = 1; | |
1188 | } | |
1189 | } else | |
1190 | smp->status |= IB_SMP_INVALID_FIELD; | |
1191 | ||
1192 | lse = be16_to_cpu(pi->link_speed.enabled); | |
1193 | if (lse) { | |
1194 | if (lse & be16_to_cpu(pi->link_speed.supported)) | |
1195 | set_link_speed_enabled(ppd, lse); | |
1196 | else | |
1197 | smp->status |= IB_SMP_INVALID_FIELD; | |
1198 | } | |
1199 | ||
4eb06882 DD |
1200 | ibp->rvp.mkeyprot = |
1201 | (pi->mkeyprotect_lmc & OPA_PI_MASK_MKEY_PROT_BIT) >> 6; | |
1202 | ibp->rvp.vl_high_limit = be16_to_cpu(pi->vl.high_limit) & 0xFF; | |
77241056 | 1203 | (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_VL_HIGH_LIMIT, |
4eb06882 | 1204 | ibp->rvp.vl_high_limit); |
77241056 MM |
1205 | |
1206 | if (ppd->vls_supported/2 > ARRAY_SIZE(pi->neigh_mtu.pvlx_to_mtu) || | |
1207 | ppd->vls_supported > ARRAY_SIZE(dd->vld)) { | |
1208 | smp->status |= IB_SMP_INVALID_FIELD; | |
1209 | return reply((struct ib_mad_hdr *)smp); | |
1210 | } | |
1211 | for (i = 0; i < ppd->vls_supported; i++) { | |
1212 | if ((i % 2) == 0) | |
1213 | mtu = enum_to_mtu((pi->neigh_mtu.pvlx_to_mtu[i/2] >> 4) | |
1214 | & 0xF); | |
1215 | else | |
1216 | mtu = enum_to_mtu(pi->neigh_mtu.pvlx_to_mtu[i/2] & 0xF); | |
1217 | if (mtu == 0xffff) { | |
1218 | pr_warn("SubnSet(OPA_PortInfo) mtu invalid %d (0x%x)\n", | |
1219 | mtu, | |
1220 | (pi->neigh_mtu.pvlx_to_mtu[0] >> 4) & 0xF); | |
1221 | smp->status |= IB_SMP_INVALID_FIELD; | |
1222 | mtu = hfi1_max_mtu; /* use a valid MTU */ | |
1223 | } | |
1224 | if (dd->vld[i].mtu != mtu) { | |
1225 | dd_dev_info(dd, | |
1226 | "MTU change on vl %d from %d to %d\n", | |
1227 | i, dd->vld[i].mtu, mtu); | |
1228 | dd->vld[i].mtu = mtu; | |
1229 | call_set_mtu++; | |
1230 | } | |
1231 | } | |
1232 | /* As per OPAV1 spec: VL15 must support and be configured | |
1233 | * for operation with a 2048 or larger MTU. | |
1234 | */ | |
1235 | mtu = enum_to_mtu(pi->neigh_mtu.pvlx_to_mtu[15/2] & 0xF); | |
1236 | if (mtu < 2048 || mtu == 0xffff) | |
1237 | mtu = 2048; | |
1238 | if (dd->vld[15].mtu != mtu) { | |
1239 | dd_dev_info(dd, | |
1240 | "MTU change on vl 15 from %d to %d\n", | |
1241 | dd->vld[15].mtu, mtu); | |
1242 | dd->vld[15].mtu = mtu; | |
1243 | call_set_mtu++; | |
1244 | } | |
1245 | if (call_set_mtu) | |
1246 | set_mtu(ppd); | |
1247 | ||
1248 | /* Set operational VLs */ | |
1249 | vls = pi->operational_vls & OPA_PI_MASK_OPERATIONAL_VL; | |
1250 | if (vls) { | |
1251 | if (vls > ppd->vls_supported) { | |
1252 | pr_warn("SubnSet(OPA_PortInfo) VL's supported invalid %d\n", | |
1253 | pi->operational_vls); | |
1254 | smp->status |= IB_SMP_INVALID_FIELD; | |
1255 | } else { | |
1256 | if (hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_OP_VLS, | |
1257 | vls) == -EINVAL) | |
1258 | smp->status |= IB_SMP_INVALID_FIELD; | |
1259 | } | |
1260 | } | |
1261 | ||
1262 | if (pi->mkey_violations == 0) | |
4eb06882 | 1263 | ibp->rvp.mkey_violations = 0; |
77241056 MM |
1264 | |
1265 | if (pi->pkey_violations == 0) | |
4eb06882 | 1266 | ibp->rvp.pkey_violations = 0; |
77241056 MM |
1267 | |
1268 | if (pi->qkey_violations == 0) | |
4eb06882 | 1269 | ibp->rvp.qkey_violations = 0; |
77241056 | 1270 | |
4eb06882 | 1271 | ibp->rvp.subnet_timeout = |
77241056 MM |
1272 | pi->clientrereg_subnettimeout & OPA_PI_MASK_SUBNET_TIMEOUT; |
1273 | ||
1274 | crc_enabled = be16_to_cpu(pi->port_ltp_crc_mode); | |
1275 | crc_enabled >>= 4; | |
1276 | crc_enabled &= 0xf; | |
1277 | ||
1278 | if (crc_enabled != 0) | |
1279 | ppd->port_crc_mode_enabled = port_ltp_to_cap(crc_enabled); | |
1280 | ||
1281 | ppd->is_active_optimize_enabled = | |
1282 | !!(be16_to_cpu(pi->port_mode) | |
1283 | & OPA_PI_MASK_PORT_ACTIVE_OPTOMIZE); | |
1284 | ||
1285 | ls_new = pi->port_states.portphysstate_portstate & | |
1286 | OPA_PI_MASK_PORT_STATE; | |
1287 | ps_new = (pi->port_states.portphysstate_portstate & | |
1288 | OPA_PI_MASK_PORT_PHYSICAL_STATE) >> 4; | |
1289 | ||
1290 | if (ls_old == IB_PORT_INIT) { | |
1291 | if (start_of_sm_config) { | |
1292 | if (ls_new == ls_old || (ls_new == IB_PORT_ARMED)) | |
1293 | ppd->is_sm_config_started = 1; | |
1294 | } else if (ls_new == IB_PORT_ARMED) { | |
1295 | if (ppd->is_sm_config_started == 0) | |
1296 | invalid = 1; | |
1297 | } | |
1298 | } | |
1299 | ||
1300 | /* Handle CLIENT_REREGISTER event b/c SM asked us for it */ | |
1301 | if (clientrereg) { | |
1302 | event.event = IB_EVENT_CLIENT_REREGISTER; | |
1303 | ib_dispatch_event(&event); | |
1304 | } | |
1305 | ||
1306 | /* | |
1307 | * Do the port state change now that the other link parameters | |
1308 | * have been set. | |
1309 | * Changing the port physical state only makes sense if the link | |
1310 | * is down or is being set to down. | |
1311 | */ | |
1312 | ||
1313 | ret = set_port_states(ppd, smp, ls_new, ps_new, invalid); | |
1314 | if (ret) | |
1315 | return ret; | |
1316 | ||
1317 | ret = __subn_get_opa_portinfo(smp, am, data, ibdev, port, resp_len); | |
1318 | ||
1319 | /* restore re-reg bit per o14-12.2.1 */ | |
1320 | pi->clientrereg_subnettimeout |= clientrereg; | |
1321 | ||
1322 | /* | |
1323 | * Apply the new link downgrade policy. This may result in a link | |
1324 | * bounce. Do this after everything else so things are settled. | |
1325 | * Possible problem: if setting the port state above fails, then | |
1326 | * the policy change is not applied. | |
1327 | */ | |
1328 | if (call_link_downgrade_policy) | |
1329 | apply_link_downgrade_policy(ppd, 0); | |
1330 | ||
1331 | return ret; | |
1332 | ||
1333 | get_only: | |
1334 | return __subn_get_opa_portinfo(smp, am, data, ibdev, port, resp_len); | |
1335 | } | |
1336 | ||
1337 | /** | |
1338 | * set_pkeys - set the PKEY table for ctxt 0 | |
1339 | * @dd: the hfi1_ib device | |
1340 | * @port: the IB port number | |
1341 | * @pkeys: the PKEY table | |
1342 | */ | |
1343 | static int set_pkeys(struct hfi1_devdata *dd, u8 port, u16 *pkeys) | |
1344 | { | |
1345 | struct hfi1_pportdata *ppd; | |
1346 | int i; | |
1347 | int changed = 0; | |
1348 | int update_includes_mgmt_partition = 0; | |
1349 | ||
1350 | /* | |
1351 | * IB port one/two always maps to context zero/one, | |
1352 | * always a kernel context, no locking needed | |
1353 | * If we get here with ppd setup, no need to check | |
1354 | * that rcd is valid. | |
1355 | */ | |
1356 | ppd = dd->pport + (port - 1); | |
1357 | /* | |
1358 | * If the update does not include the management pkey, don't do it. | |
1359 | */ | |
1360 | for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) { | |
1361 | if (pkeys[i] == LIM_MGMT_P_KEY) { | |
1362 | update_includes_mgmt_partition = 1; | |
1363 | break; | |
1364 | } | |
1365 | } | |
1366 | ||
1367 | if (!update_includes_mgmt_partition) | |
1368 | return 1; | |
1369 | ||
1370 | for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) { | |
1371 | u16 key = pkeys[i]; | |
1372 | u16 okey = ppd->pkeys[i]; | |
1373 | ||
1374 | if (key == okey) | |
1375 | continue; | |
1376 | /* | |
1377 | * The SM gives us the complete PKey table. We have | |
1378 | * to ensure that we put the PKeys in the matching | |
1379 | * slots. | |
1380 | */ | |
1381 | ppd->pkeys[i] = key; | |
1382 | changed = 1; | |
1383 | } | |
1384 | ||
1385 | if (changed) { | |
1386 | struct ib_event event; | |
1387 | ||
1388 | (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0); | |
1389 | ||
1390 | event.event = IB_EVENT_PKEY_CHANGE; | |
ec3f2c12 | 1391 | event.device = &dd->verbs_dev.rdi.ibdev; |
77241056 MM |
1392 | event.element.port_num = port; |
1393 | ib_dispatch_event(&event); | |
1394 | } | |
1395 | return 0; | |
1396 | } | |
1397 | ||
1398 | static int __subn_set_opa_pkeytable(struct opa_smp *smp, u32 am, u8 *data, | |
1399 | struct ib_device *ibdev, u8 port, | |
1400 | u32 *resp_len) | |
1401 | { | |
1402 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
1403 | u32 n_blocks_sent = OPA_AM_NBLK(am); | |
1404 | u32 start_block = am & 0x7ff; | |
1405 | u16 *p = (u16 *) data; | |
1406 | __be16 *q = (__be16 *)data; | |
1407 | int i; | |
1408 | u16 n_blocks_avail; | |
1409 | unsigned npkeys = hfi1_get_npkeys(dd); | |
1410 | ||
1411 | if (n_blocks_sent == 0) { | |
1412 | pr_warn("OPA Get PKey AM Invalid : P = %d; B = 0x%x; N = 0x%x\n", | |
1413 | port, start_block, n_blocks_sent); | |
1414 | smp->status |= IB_SMP_INVALID_FIELD; | |
1415 | return reply((struct ib_mad_hdr *)smp); | |
1416 | } | |
1417 | ||
1418 | n_blocks_avail = (u16)(npkeys/OPA_PARTITION_TABLE_BLK_SIZE) + 1; | |
1419 | ||
1420 | if (start_block + n_blocks_sent > n_blocks_avail || | |
1421 | n_blocks_sent > OPA_NUM_PKEY_BLOCKS_PER_SMP) { | |
1422 | pr_warn("OPA Set PKey AM Invalid : s 0x%x; req 0x%x; avail 0x%x; blk/smp 0x%lx\n", | |
1423 | start_block, n_blocks_sent, n_blocks_avail, | |
1424 | OPA_NUM_PKEY_BLOCKS_PER_SMP); | |
1425 | smp->status |= IB_SMP_INVALID_FIELD; | |
1426 | return reply((struct ib_mad_hdr *)smp); | |
1427 | } | |
1428 | ||
1429 | for (i = 0; i < n_blocks_sent * OPA_PARTITION_TABLE_BLK_SIZE; i++) | |
1430 | p[i] = be16_to_cpu(q[i]); | |
1431 | ||
1432 | if (start_block == 0 && set_pkeys(dd, port, p) != 0) { | |
1433 | smp->status |= IB_SMP_INVALID_FIELD; | |
1434 | return reply((struct ib_mad_hdr *)smp); | |
1435 | } | |
1436 | ||
1437 | return __subn_get_opa_pkeytable(smp, am, data, ibdev, port, resp_len); | |
1438 | } | |
1439 | ||
1440 | static int get_sc2vlt_tables(struct hfi1_devdata *dd, void *data) | |
1441 | { | |
a787bde8 | 1442 | u64 *val = data; |
77241056 MM |
1443 | |
1444 | *val++ = read_csr(dd, SEND_SC2VLT0); | |
1445 | *val++ = read_csr(dd, SEND_SC2VLT1); | |
1446 | *val++ = read_csr(dd, SEND_SC2VLT2); | |
1447 | *val++ = read_csr(dd, SEND_SC2VLT3); | |
1448 | return 0; | |
1449 | } | |
1450 | ||
1451 | #define ILLEGAL_VL 12 | |
1452 | /* | |
1453 | * filter_sc2vlt changes mappings to VL15 to ILLEGAL_VL (except | |
1454 | * for SC15, which must map to VL15). If we don't remap things this | |
1455 | * way it is possible for VL15 counters to increment when we try to | |
1456 | * send on a SC which is mapped to an invalid VL. | |
1457 | */ | |
1458 | static void filter_sc2vlt(void *data) | |
1459 | { | |
1460 | int i; | |
a787bde8 | 1461 | u8 *pd = data; |
77241056 MM |
1462 | |
1463 | for (i = 0; i < OPA_MAX_SCS; i++) { | |
1464 | if (i == 15) | |
1465 | continue; | |
1466 | if ((pd[i] & 0x1f) == 0xf) | |
1467 | pd[i] = ILLEGAL_VL; | |
1468 | } | |
1469 | } | |
1470 | ||
1471 | static int set_sc2vlt_tables(struct hfi1_devdata *dd, void *data) | |
1472 | { | |
a787bde8 | 1473 | u64 *val = data; |
77241056 MM |
1474 | |
1475 | filter_sc2vlt(data); | |
1476 | ||
1477 | write_csr(dd, SEND_SC2VLT0, *val++); | |
1478 | write_csr(dd, SEND_SC2VLT1, *val++); | |
1479 | write_csr(dd, SEND_SC2VLT2, *val++); | |
1480 | write_csr(dd, SEND_SC2VLT3, *val++); | |
1481 | write_seqlock_irq(&dd->sc2vl_lock); | |
a787bde8 | 1482 | memcpy(dd->sc2vl, data, sizeof(dd->sc2vl)); |
77241056 MM |
1483 | write_sequnlock_irq(&dd->sc2vl_lock); |
1484 | return 0; | |
1485 | } | |
1486 | ||
1487 | static int __subn_get_opa_sl_to_sc(struct opa_smp *smp, u32 am, u8 *data, | |
1488 | struct ib_device *ibdev, u8 port, | |
1489 | u32 *resp_len) | |
1490 | { | |
1491 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
6618c051 | 1492 | u8 *p = data; |
77241056 MM |
1493 | size_t size = ARRAY_SIZE(ibp->sl_to_sc); /* == 32 */ |
1494 | unsigned i; | |
1495 | ||
1496 | if (am) { | |
1497 | smp->status |= IB_SMP_INVALID_FIELD; | |
1498 | return reply((struct ib_mad_hdr *)smp); | |
1499 | } | |
1500 | ||
1501 | for (i = 0; i < ARRAY_SIZE(ibp->sl_to_sc); i++) | |
1502 | *p++ = ibp->sl_to_sc[i]; | |
1503 | ||
1504 | if (resp_len) | |
1505 | *resp_len += size; | |
1506 | ||
1507 | return reply((struct ib_mad_hdr *)smp); | |
1508 | } | |
1509 | ||
1510 | static int __subn_set_opa_sl_to_sc(struct opa_smp *smp, u32 am, u8 *data, | |
1511 | struct ib_device *ibdev, u8 port, | |
1512 | u32 *resp_len) | |
1513 | { | |
1514 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
6618c051 | 1515 | u8 *p = data; |
77241056 MM |
1516 | int i; |
1517 | ||
1518 | if (am) { | |
1519 | smp->status |= IB_SMP_INVALID_FIELD; | |
1520 | return reply((struct ib_mad_hdr *)smp); | |
1521 | } | |
1522 | ||
1523 | for (i = 0; i < ARRAY_SIZE(ibp->sl_to_sc); i++) | |
1524 | ibp->sl_to_sc[i] = *p++; | |
1525 | ||
1526 | return __subn_get_opa_sl_to_sc(smp, am, data, ibdev, port, resp_len); | |
1527 | } | |
1528 | ||
1529 | static int __subn_get_opa_sc_to_sl(struct opa_smp *smp, u32 am, u8 *data, | |
1530 | struct ib_device *ibdev, u8 port, | |
1531 | u32 *resp_len) | |
1532 | { | |
1533 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
6618c051 | 1534 | u8 *p = data; |
77241056 MM |
1535 | size_t size = ARRAY_SIZE(ibp->sc_to_sl); /* == 32 */ |
1536 | unsigned i; | |
1537 | ||
1538 | if (am) { | |
1539 | smp->status |= IB_SMP_INVALID_FIELD; | |
1540 | return reply((struct ib_mad_hdr *)smp); | |
1541 | } | |
1542 | ||
1543 | for (i = 0; i < ARRAY_SIZE(ibp->sc_to_sl); i++) | |
1544 | *p++ = ibp->sc_to_sl[i]; | |
1545 | ||
1546 | if (resp_len) | |
1547 | *resp_len += size; | |
1548 | ||
1549 | return reply((struct ib_mad_hdr *)smp); | |
1550 | } | |
1551 | ||
1552 | static int __subn_set_opa_sc_to_sl(struct opa_smp *smp, u32 am, u8 *data, | |
1553 | struct ib_device *ibdev, u8 port, | |
1554 | u32 *resp_len) | |
1555 | { | |
1556 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
6618c051 | 1557 | u8 *p = data; |
77241056 MM |
1558 | int i; |
1559 | ||
1560 | if (am) { | |
1561 | smp->status |= IB_SMP_INVALID_FIELD; | |
1562 | return reply((struct ib_mad_hdr *)smp); | |
1563 | } | |
1564 | ||
1565 | for (i = 0; i < ARRAY_SIZE(ibp->sc_to_sl); i++) | |
1566 | ibp->sc_to_sl[i] = *p++; | |
1567 | ||
1568 | return __subn_get_opa_sc_to_sl(smp, am, data, ibdev, port, resp_len); | |
1569 | } | |
1570 | ||
1571 | static int __subn_get_opa_sc_to_vlt(struct opa_smp *smp, u32 am, u8 *data, | |
1572 | struct ib_device *ibdev, u8 port, | |
1573 | u32 *resp_len) | |
1574 | { | |
1575 | u32 n_blocks = OPA_AM_NBLK(am); | |
1576 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
1577 | void *vp = (void *) data; | |
1578 | size_t size = 4 * sizeof(u64); | |
1579 | ||
1580 | if (n_blocks != 1) { | |
1581 | smp->status |= IB_SMP_INVALID_FIELD; | |
1582 | return reply((struct ib_mad_hdr *)smp); | |
1583 | } | |
1584 | ||
1585 | get_sc2vlt_tables(dd, vp); | |
1586 | ||
1587 | if (resp_len) | |
1588 | *resp_len += size; | |
1589 | ||
1590 | return reply((struct ib_mad_hdr *)smp); | |
1591 | } | |
1592 | ||
1593 | static int __subn_set_opa_sc_to_vlt(struct opa_smp *smp, u32 am, u8 *data, | |
1594 | struct ib_device *ibdev, u8 port, | |
1595 | u32 *resp_len) | |
1596 | { | |
1597 | u32 n_blocks = OPA_AM_NBLK(am); | |
1598 | int async_update = OPA_AM_ASYNC(am); | |
1599 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
1600 | void *vp = (void *) data; | |
1601 | struct hfi1_pportdata *ppd; | |
1602 | int lstate; | |
1603 | ||
1604 | if (n_blocks != 1 || async_update) { | |
1605 | smp->status |= IB_SMP_INVALID_FIELD; | |
1606 | return reply((struct ib_mad_hdr *)smp); | |
1607 | } | |
1608 | ||
1609 | /* IB numbers ports from 1, hw from 0 */ | |
1610 | ppd = dd->pport + (port - 1); | |
1611 | lstate = driver_lstate(ppd); | |
1612 | /* it's known that async_update is 0 by this point, but include | |
1613 | * the explicit check for clarity */ | |
1614 | if (!async_update && | |
1615 | (lstate == IB_PORT_ARMED || lstate == IB_PORT_ACTIVE)) { | |
1616 | smp->status |= IB_SMP_INVALID_FIELD; | |
1617 | return reply((struct ib_mad_hdr *)smp); | |
1618 | } | |
1619 | ||
1620 | set_sc2vlt_tables(dd, vp); | |
1621 | ||
1622 | return __subn_get_opa_sc_to_vlt(smp, am, data, ibdev, port, resp_len); | |
1623 | } | |
1624 | ||
1625 | static int __subn_get_opa_sc_to_vlnt(struct opa_smp *smp, u32 am, u8 *data, | |
1626 | struct ib_device *ibdev, u8 port, | |
1627 | u32 *resp_len) | |
1628 | { | |
1629 | u32 n_blocks = OPA_AM_NPORT(am); | |
1630 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
1631 | struct hfi1_pportdata *ppd; | |
1632 | void *vp = (void *) data; | |
1633 | int size; | |
1634 | ||
1635 | if (n_blocks != 1) { | |
1636 | smp->status |= IB_SMP_INVALID_FIELD; | |
1637 | return reply((struct ib_mad_hdr *)smp); | |
1638 | } | |
1639 | ||
1640 | ppd = dd->pport + (port - 1); | |
1641 | ||
1642 | size = fm_get_table(ppd, FM_TBL_SC2VLNT, vp); | |
1643 | ||
1644 | if (resp_len) | |
1645 | *resp_len += size; | |
1646 | ||
1647 | return reply((struct ib_mad_hdr *)smp); | |
1648 | } | |
1649 | ||
1650 | static int __subn_set_opa_sc_to_vlnt(struct opa_smp *smp, u32 am, u8 *data, | |
1651 | struct ib_device *ibdev, u8 port, | |
1652 | u32 *resp_len) | |
1653 | { | |
1654 | u32 n_blocks = OPA_AM_NPORT(am); | |
1655 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
1656 | struct hfi1_pportdata *ppd; | |
1657 | void *vp = (void *) data; | |
1658 | int lstate; | |
1659 | ||
1660 | if (n_blocks != 1) { | |
1661 | smp->status |= IB_SMP_INVALID_FIELD; | |
1662 | return reply((struct ib_mad_hdr *)smp); | |
1663 | } | |
1664 | ||
1665 | /* IB numbers ports from 1, hw from 0 */ | |
1666 | ppd = dd->pport + (port - 1); | |
1667 | lstate = driver_lstate(ppd); | |
1668 | if (lstate == IB_PORT_ARMED || lstate == IB_PORT_ACTIVE) { | |
1669 | smp->status |= IB_SMP_INVALID_FIELD; | |
1670 | return reply((struct ib_mad_hdr *)smp); | |
1671 | } | |
1672 | ||
1673 | ppd = dd->pport + (port - 1); | |
1674 | ||
1675 | fm_set_table(ppd, FM_TBL_SC2VLNT, vp); | |
1676 | ||
1677 | return __subn_get_opa_sc_to_vlnt(smp, am, data, ibdev, port, | |
1678 | resp_len); | |
1679 | } | |
1680 | ||
1681 | static int __subn_get_opa_psi(struct opa_smp *smp, u32 am, u8 *data, | |
1682 | struct ib_device *ibdev, u8 port, | |
1683 | u32 *resp_len) | |
1684 | { | |
1685 | u32 nports = OPA_AM_NPORT(am); | |
1686 | u32 start_of_sm_config = OPA_AM_START_SM_CFG(am); | |
1687 | u32 lstate; | |
1688 | struct hfi1_ibport *ibp; | |
1689 | struct hfi1_pportdata *ppd; | |
1690 | struct opa_port_state_info *psi = (struct opa_port_state_info *) data; | |
1691 | ||
1692 | if (nports != 1) { | |
1693 | smp->status |= IB_SMP_INVALID_FIELD; | |
1694 | return reply((struct ib_mad_hdr *)smp); | |
1695 | } | |
1696 | ||
1697 | ibp = to_iport(ibdev, port); | |
1698 | ppd = ppd_from_ibp(ibp); | |
1699 | ||
1700 | lstate = driver_lstate(ppd); | |
1701 | ||
1702 | if (start_of_sm_config && (lstate == IB_PORT_INIT)) | |
1703 | ppd->is_sm_config_started = 1; | |
1704 | ||
1705 | #if PI_LED_ENABLE_SUP | |
1706 | psi->port_states.ledenable_offlinereason = ppd->neighbor_normal << 4; | |
1707 | psi->port_states.ledenable_offlinereason |= | |
1708 | ppd->is_sm_config_started << 5; | |
1709 | psi->port_states.ledenable_offlinereason |= | |
a9c05e35 | 1710 | ppd->offline_disabled_reason; |
77241056 MM |
1711 | #else |
1712 | psi->port_states.offline_reason = ppd->neighbor_normal << 4; | |
1713 | psi->port_states.offline_reason |= ppd->is_sm_config_started << 5; | |
a9c05e35 | 1714 | psi->port_states.offline_reason |= ppd->offline_disabled_reason; |
77241056 MM |
1715 | #endif /* PI_LED_ENABLE_SUP */ |
1716 | ||
1717 | psi->port_states.portphysstate_portstate = | |
1718 | (hfi1_ibphys_portstate(ppd) << 4) | (lstate & 0xf); | |
1719 | psi->link_width_downgrade_tx_active = | |
aadfc3b2 | 1720 | cpu_to_be16(ppd->link_width_downgrade_tx_active); |
77241056 | 1721 | psi->link_width_downgrade_rx_active = |
aadfc3b2 | 1722 | cpu_to_be16(ppd->link_width_downgrade_rx_active); |
77241056 MM |
1723 | if (resp_len) |
1724 | *resp_len += sizeof(struct opa_port_state_info); | |
1725 | ||
1726 | return reply((struct ib_mad_hdr *)smp); | |
1727 | } | |
1728 | ||
1729 | static int __subn_set_opa_psi(struct opa_smp *smp, u32 am, u8 *data, | |
1730 | struct ib_device *ibdev, u8 port, | |
1731 | u32 *resp_len) | |
1732 | { | |
1733 | u32 nports = OPA_AM_NPORT(am); | |
1734 | u32 start_of_sm_config = OPA_AM_START_SM_CFG(am); | |
1735 | u32 ls_old; | |
1736 | u8 ls_new, ps_new; | |
1737 | struct hfi1_ibport *ibp; | |
1738 | struct hfi1_pportdata *ppd; | |
1739 | struct opa_port_state_info *psi = (struct opa_port_state_info *) data; | |
1740 | int ret, invalid = 0; | |
1741 | ||
1742 | if (nports != 1) { | |
1743 | smp->status |= IB_SMP_INVALID_FIELD; | |
1744 | return reply((struct ib_mad_hdr *)smp); | |
1745 | } | |
1746 | ||
1747 | ibp = to_iport(ibdev, port); | |
1748 | ppd = ppd_from_ibp(ibp); | |
1749 | ||
1750 | ls_old = driver_lstate(ppd); | |
1751 | ||
1752 | ls_new = port_states_to_logical_state(&psi->port_states); | |
1753 | ps_new = port_states_to_phys_state(&psi->port_states); | |
1754 | ||
1755 | if (ls_old == IB_PORT_INIT) { | |
1756 | if (start_of_sm_config) { | |
1757 | if (ls_new == ls_old || (ls_new == IB_PORT_ARMED)) | |
1758 | ppd->is_sm_config_started = 1; | |
1759 | } else if (ls_new == IB_PORT_ARMED) { | |
1760 | if (ppd->is_sm_config_started == 0) | |
1761 | invalid = 1; | |
1762 | } | |
1763 | } | |
1764 | ||
1765 | ret = set_port_states(ppd, smp, ls_new, ps_new, invalid); | |
1766 | if (ret) | |
1767 | return ret; | |
1768 | ||
1769 | if (invalid) | |
1770 | smp->status |= IB_SMP_INVALID_FIELD; | |
1771 | ||
1772 | return __subn_get_opa_psi(smp, am, data, ibdev, port, resp_len); | |
1773 | } | |
1774 | ||
1775 | static int __subn_get_opa_cable_info(struct opa_smp *smp, u32 am, u8 *data, | |
1776 | struct ib_device *ibdev, u8 port, | |
1777 | u32 *resp_len) | |
1778 | { | |
1779 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
1780 | u32 addr = OPA_AM_CI_ADDR(am); | |
1781 | u32 len = OPA_AM_CI_LEN(am) + 1; | |
1782 | int ret; | |
1783 | ||
349ac71f | 1784 | #define __CI_PAGE_SIZE BIT(7) /* 128 bytes */ |
77241056 MM |
1785 | #define __CI_PAGE_MASK ~(__CI_PAGE_SIZE - 1) |
1786 | #define __CI_PAGE_NUM(a) ((a) & __CI_PAGE_MASK) | |
1787 | ||
1788 | /* check that addr is within spec, and | |
1789 | * addr and (addr + len - 1) are on the same "page" */ | |
1790 | if (addr >= 4096 || | |
1791 | (__CI_PAGE_NUM(addr) != __CI_PAGE_NUM(addr + len - 1))) { | |
1792 | smp->status |= IB_SMP_INVALID_FIELD; | |
1793 | return reply((struct ib_mad_hdr *)smp); | |
1794 | } | |
1795 | ||
1796 | ret = get_cable_info(dd, port, addr, len, data); | |
1797 | ||
1798 | if (ret == -ENODEV) { | |
1799 | smp->status |= IB_SMP_UNSUP_METH_ATTR; | |
1800 | return reply((struct ib_mad_hdr *)smp); | |
1801 | } | |
1802 | ||
1803 | /* The address range for the CableInfo SMA query is wider than the | |
1804 | * memory available on the QSFP cable. We want to return a valid | |
1805 | * response, albeit zeroed out, for address ranges beyond available | |
1806 | * memory but that are within the CableInfo query spec | |
1807 | */ | |
1808 | if (ret < 0 && ret != -ERANGE) { | |
1809 | smp->status |= IB_SMP_INVALID_FIELD; | |
1810 | return reply((struct ib_mad_hdr *)smp); | |
1811 | } | |
1812 | ||
1813 | if (resp_len) | |
1814 | *resp_len += len; | |
1815 | ||
1816 | return reply((struct ib_mad_hdr *)smp); | |
1817 | } | |
1818 | ||
1819 | static int __subn_get_opa_bct(struct opa_smp *smp, u32 am, u8 *data, | |
1820 | struct ib_device *ibdev, u8 port, u32 *resp_len) | |
1821 | { | |
1822 | u32 num_ports = OPA_AM_NPORT(am); | |
1823 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
1824 | struct hfi1_pportdata *ppd; | |
1825 | struct buffer_control *p = (struct buffer_control *) data; | |
1826 | int size; | |
1827 | ||
1828 | if (num_ports != 1) { | |
1829 | smp->status |= IB_SMP_INVALID_FIELD; | |
1830 | return reply((struct ib_mad_hdr *)smp); | |
1831 | } | |
1832 | ||
1833 | ppd = dd->pport + (port - 1); | |
1834 | size = fm_get_table(ppd, FM_TBL_BUFFER_CONTROL, p); | |
1835 | trace_bct_get(dd, p); | |
1836 | if (resp_len) | |
1837 | *resp_len += size; | |
1838 | ||
1839 | return reply((struct ib_mad_hdr *)smp); | |
1840 | } | |
1841 | ||
1842 | static int __subn_set_opa_bct(struct opa_smp *smp, u32 am, u8 *data, | |
1843 | struct ib_device *ibdev, u8 port, u32 *resp_len) | |
1844 | { | |
1845 | u32 num_ports = OPA_AM_NPORT(am); | |
1846 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
1847 | struct hfi1_pportdata *ppd; | |
1848 | struct buffer_control *p = (struct buffer_control *) data; | |
1849 | ||
1850 | if (num_ports != 1) { | |
1851 | smp->status |= IB_SMP_INVALID_FIELD; | |
1852 | return reply((struct ib_mad_hdr *)smp); | |
1853 | } | |
1854 | ppd = dd->pport + (port - 1); | |
1855 | trace_bct_set(dd, p); | |
1856 | if (fm_set_table(ppd, FM_TBL_BUFFER_CONTROL, p) < 0) { | |
1857 | smp->status |= IB_SMP_INVALID_FIELD; | |
1858 | return reply((struct ib_mad_hdr *)smp); | |
1859 | } | |
1860 | ||
1861 | return __subn_get_opa_bct(smp, am, data, ibdev, port, resp_len); | |
1862 | } | |
1863 | ||
1864 | static int __subn_get_opa_vl_arb(struct opa_smp *smp, u32 am, u8 *data, | |
1865 | struct ib_device *ibdev, u8 port, | |
1866 | u32 *resp_len) | |
1867 | { | |
1868 | struct hfi1_pportdata *ppd = ppd_from_ibp(to_iport(ibdev, port)); | |
1869 | u32 num_ports = OPA_AM_NPORT(am); | |
1870 | u8 section = (am & 0x00ff0000) >> 16; | |
1871 | u8 *p = data; | |
1872 | int size = 0; | |
1873 | ||
1874 | if (num_ports != 1) { | |
1875 | smp->status |= IB_SMP_INVALID_FIELD; | |
1876 | return reply((struct ib_mad_hdr *)smp); | |
1877 | } | |
1878 | ||
1879 | switch (section) { | |
1880 | case OPA_VLARB_LOW_ELEMENTS: | |
1881 | size = fm_get_table(ppd, FM_TBL_VL_LOW_ARB, p); | |
1882 | break; | |
1883 | case OPA_VLARB_HIGH_ELEMENTS: | |
1884 | size = fm_get_table(ppd, FM_TBL_VL_HIGH_ARB, p); | |
1885 | break; | |
1886 | case OPA_VLARB_PREEMPT_ELEMENTS: | |
1887 | size = fm_get_table(ppd, FM_TBL_VL_PREEMPT_ELEMS, p); | |
1888 | break; | |
1889 | case OPA_VLARB_PREEMPT_MATRIX: | |
1890 | size = fm_get_table(ppd, FM_TBL_VL_PREEMPT_MATRIX, p); | |
1891 | break; | |
1892 | default: | |
1893 | pr_warn("OPA SubnGet(VL Arb) AM Invalid : 0x%x\n", | |
1894 | be32_to_cpu(smp->attr_mod)); | |
1895 | smp->status |= IB_SMP_INVALID_FIELD; | |
1896 | break; | |
1897 | } | |
1898 | ||
1899 | if (size > 0 && resp_len) | |
1900 | *resp_len += size; | |
1901 | ||
1902 | return reply((struct ib_mad_hdr *)smp); | |
1903 | } | |
1904 | ||
1905 | static int __subn_set_opa_vl_arb(struct opa_smp *smp, u32 am, u8 *data, | |
1906 | struct ib_device *ibdev, u8 port, | |
1907 | u32 *resp_len) | |
1908 | { | |
1909 | struct hfi1_pportdata *ppd = ppd_from_ibp(to_iport(ibdev, port)); | |
1910 | u32 num_ports = OPA_AM_NPORT(am); | |
1911 | u8 section = (am & 0x00ff0000) >> 16; | |
1912 | u8 *p = data; | |
1913 | ||
1914 | if (num_ports != 1) { | |
1915 | smp->status |= IB_SMP_INVALID_FIELD; | |
1916 | return reply((struct ib_mad_hdr *)smp); | |
1917 | } | |
1918 | ||
1919 | switch (section) { | |
1920 | case OPA_VLARB_LOW_ELEMENTS: | |
1921 | (void) fm_set_table(ppd, FM_TBL_VL_LOW_ARB, p); | |
1922 | break; | |
1923 | case OPA_VLARB_HIGH_ELEMENTS: | |
1924 | (void) fm_set_table(ppd, FM_TBL_VL_HIGH_ARB, p); | |
1925 | break; | |
1926 | /* neither OPA_VLARB_PREEMPT_ELEMENTS, or OPA_VLARB_PREEMPT_MATRIX | |
1927 | * can be changed from the default values */ | |
1928 | case OPA_VLARB_PREEMPT_ELEMENTS: | |
1929 | /* FALLTHROUGH */ | |
1930 | case OPA_VLARB_PREEMPT_MATRIX: | |
1931 | smp->status |= IB_SMP_UNSUP_METH_ATTR; | |
1932 | break; | |
1933 | default: | |
1934 | pr_warn("OPA SubnSet(VL Arb) AM Invalid : 0x%x\n", | |
1935 | be32_to_cpu(smp->attr_mod)); | |
1936 | smp->status |= IB_SMP_INVALID_FIELD; | |
1937 | break; | |
1938 | } | |
1939 | ||
1940 | return __subn_get_opa_vl_arb(smp, am, data, ibdev, port, resp_len); | |
1941 | } | |
1942 | ||
1943 | struct opa_pma_mad { | |
1944 | struct ib_mad_hdr mad_hdr; | |
1945 | u8 data[2024]; | |
1946 | } __packed; | |
1947 | ||
1948 | struct opa_class_port_info { | |
1949 | u8 base_version; | |
1950 | u8 class_version; | |
1951 | __be16 cap_mask; | |
1952 | __be32 cap_mask2_resp_time; | |
1953 | ||
1954 | u8 redirect_gid[16]; | |
1955 | __be32 redirect_tc_fl; | |
1956 | __be32 redirect_lid; | |
1957 | __be32 redirect_sl_qp; | |
1958 | __be32 redirect_qkey; | |
1959 | ||
1960 | u8 trap_gid[16]; | |
1961 | __be32 trap_tc_fl; | |
1962 | __be32 trap_lid; | |
1963 | __be32 trap_hl_qp; | |
1964 | __be32 trap_qkey; | |
1965 | ||
1966 | __be16 trap_pkey; | |
1967 | __be16 redirect_pkey; | |
1968 | ||
1969 | u8 trap_sl_rsvd; | |
1970 | u8 reserved[3]; | |
1971 | } __packed; | |
1972 | ||
1973 | struct opa_port_status_req { | |
1974 | __u8 port_num; | |
1975 | __u8 reserved[3]; | |
1976 | __be32 vl_select_mask; | |
1977 | }; | |
1978 | ||
1979 | #define VL_MASK_ALL 0x000080ff | |
1980 | ||
1981 | struct opa_port_status_rsp { | |
1982 | __u8 port_num; | |
1983 | __u8 reserved[3]; | |
1984 | __be32 vl_select_mask; | |
1985 | ||
1986 | /* Data counters */ | |
1987 | __be64 port_xmit_data; | |
1988 | __be64 port_rcv_data; | |
1989 | __be64 port_xmit_pkts; | |
1990 | __be64 port_rcv_pkts; | |
1991 | __be64 port_multicast_xmit_pkts; | |
1992 | __be64 port_multicast_rcv_pkts; | |
1993 | __be64 port_xmit_wait; | |
1994 | __be64 sw_port_congestion; | |
1995 | __be64 port_rcv_fecn; | |
1996 | __be64 port_rcv_becn; | |
1997 | __be64 port_xmit_time_cong; | |
1998 | __be64 port_xmit_wasted_bw; | |
1999 | __be64 port_xmit_wait_data; | |
2000 | __be64 port_rcv_bubble; | |
2001 | __be64 port_mark_fecn; | |
2002 | /* Error counters */ | |
2003 | __be64 port_rcv_constraint_errors; | |
2004 | __be64 port_rcv_switch_relay_errors; | |
2005 | __be64 port_xmit_discards; | |
2006 | __be64 port_xmit_constraint_errors; | |
2007 | __be64 port_rcv_remote_physical_errors; | |
2008 | __be64 local_link_integrity_errors; | |
2009 | __be64 port_rcv_errors; | |
2010 | __be64 excessive_buffer_overruns; | |
2011 | __be64 fm_config_errors; | |
2012 | __be32 link_error_recovery; | |
2013 | __be32 link_downed; | |
2014 | u8 uncorrectable_errors; | |
2015 | ||
2016 | u8 link_quality_indicator; /* 5res, 3bit */ | |
2017 | u8 res2[6]; | |
2018 | struct _vls_pctrs { | |
2019 | /* per-VL Data counters */ | |
2020 | __be64 port_vl_xmit_data; | |
2021 | __be64 port_vl_rcv_data; | |
2022 | __be64 port_vl_xmit_pkts; | |
2023 | __be64 port_vl_rcv_pkts; | |
2024 | __be64 port_vl_xmit_wait; | |
2025 | __be64 sw_port_vl_congestion; | |
2026 | __be64 port_vl_rcv_fecn; | |
2027 | __be64 port_vl_rcv_becn; | |
2028 | __be64 port_xmit_time_cong; | |
2029 | __be64 port_vl_xmit_wasted_bw; | |
2030 | __be64 port_vl_xmit_wait_data; | |
2031 | __be64 port_vl_rcv_bubble; | |
2032 | __be64 port_vl_mark_fecn; | |
2033 | __be64 port_vl_xmit_discards; | |
2034 | } vls[0]; /* real array size defined by # bits set in vl_select_mask */ | |
2035 | }; | |
2036 | ||
2037 | enum counter_selects { | |
2038 | CS_PORT_XMIT_DATA = (1 << 31), | |
2039 | CS_PORT_RCV_DATA = (1 << 30), | |
2040 | CS_PORT_XMIT_PKTS = (1 << 29), | |
2041 | CS_PORT_RCV_PKTS = (1 << 28), | |
2042 | CS_PORT_MCAST_XMIT_PKTS = (1 << 27), | |
2043 | CS_PORT_MCAST_RCV_PKTS = (1 << 26), | |
2044 | CS_PORT_XMIT_WAIT = (1 << 25), | |
2045 | CS_SW_PORT_CONGESTION = (1 << 24), | |
2046 | CS_PORT_RCV_FECN = (1 << 23), | |
2047 | CS_PORT_RCV_BECN = (1 << 22), | |
2048 | CS_PORT_XMIT_TIME_CONG = (1 << 21), | |
2049 | CS_PORT_XMIT_WASTED_BW = (1 << 20), | |
2050 | CS_PORT_XMIT_WAIT_DATA = (1 << 19), | |
2051 | CS_PORT_RCV_BUBBLE = (1 << 18), | |
2052 | CS_PORT_MARK_FECN = (1 << 17), | |
2053 | CS_PORT_RCV_CONSTRAINT_ERRORS = (1 << 16), | |
2054 | CS_PORT_RCV_SWITCH_RELAY_ERRORS = (1 << 15), | |
2055 | CS_PORT_XMIT_DISCARDS = (1 << 14), | |
2056 | CS_PORT_XMIT_CONSTRAINT_ERRORS = (1 << 13), | |
2057 | CS_PORT_RCV_REMOTE_PHYSICAL_ERRORS = (1 << 12), | |
2058 | CS_LOCAL_LINK_INTEGRITY_ERRORS = (1 << 11), | |
2059 | CS_PORT_RCV_ERRORS = (1 << 10), | |
2060 | CS_EXCESSIVE_BUFFER_OVERRUNS = (1 << 9), | |
2061 | CS_FM_CONFIG_ERRORS = (1 << 8), | |
2062 | CS_LINK_ERROR_RECOVERY = (1 << 7), | |
2063 | CS_LINK_DOWNED = (1 << 6), | |
2064 | CS_UNCORRECTABLE_ERRORS = (1 << 5), | |
2065 | }; | |
2066 | ||
2067 | struct opa_clear_port_status { | |
2068 | __be64 port_select_mask[4]; | |
2069 | __be32 counter_select_mask; | |
2070 | }; | |
2071 | ||
2072 | struct opa_aggregate { | |
2073 | __be16 attr_id; | |
2074 | __be16 err_reqlength; /* 1 bit, 8 res, 7 bit */ | |
2075 | __be32 attr_mod; | |
2076 | u8 data[0]; | |
2077 | }; | |
2078 | ||
f0852922 AL |
2079 | #define MSK_LLI 0x000000f0 |
2080 | #define MSK_LLI_SFT 4 | |
2081 | #define MSK_LER 0x0000000f | |
2082 | #define MSK_LER_SFT 0 | |
2083 | #define ADD_LLI 8 | |
2084 | #define ADD_LER 2 | |
2085 | ||
2086 | /* Request contains first three fields, response contains those plus the rest */ | |
77241056 MM |
2087 | struct opa_port_data_counters_msg { |
2088 | __be64 port_select_mask[4]; | |
2089 | __be32 vl_select_mask; | |
f0852922 | 2090 | __be32 resolution; |
77241056 MM |
2091 | |
2092 | /* Response fields follow */ | |
77241056 MM |
2093 | struct _port_dctrs { |
2094 | u8 port_number; | |
2095 | u8 reserved2[3]; | |
2096 | __be32 link_quality_indicator; /* 29res, 3bit */ | |
2097 | ||
2098 | /* Data counters */ | |
2099 | __be64 port_xmit_data; | |
2100 | __be64 port_rcv_data; | |
2101 | __be64 port_xmit_pkts; | |
2102 | __be64 port_rcv_pkts; | |
2103 | __be64 port_multicast_xmit_pkts; | |
2104 | __be64 port_multicast_rcv_pkts; | |
2105 | __be64 port_xmit_wait; | |
2106 | __be64 sw_port_congestion; | |
2107 | __be64 port_rcv_fecn; | |
2108 | __be64 port_rcv_becn; | |
2109 | __be64 port_xmit_time_cong; | |
2110 | __be64 port_xmit_wasted_bw; | |
2111 | __be64 port_xmit_wait_data; | |
2112 | __be64 port_rcv_bubble; | |
2113 | __be64 port_mark_fecn; | |
2114 | ||
2115 | __be64 port_error_counter_summary; | |
2116 | /* Sum of error counts/port */ | |
2117 | ||
2118 | struct _vls_dctrs { | |
2119 | /* per-VL Data counters */ | |
2120 | __be64 port_vl_xmit_data; | |
2121 | __be64 port_vl_rcv_data; | |
2122 | __be64 port_vl_xmit_pkts; | |
2123 | __be64 port_vl_rcv_pkts; | |
2124 | __be64 port_vl_xmit_wait; | |
2125 | __be64 sw_port_vl_congestion; | |
2126 | __be64 port_vl_rcv_fecn; | |
2127 | __be64 port_vl_rcv_becn; | |
2128 | __be64 port_xmit_time_cong; | |
2129 | __be64 port_vl_xmit_wasted_bw; | |
2130 | __be64 port_vl_xmit_wait_data; | |
2131 | __be64 port_vl_rcv_bubble; | |
2132 | __be64 port_vl_mark_fecn; | |
2133 | } vls[0]; | |
2134 | /* array size defined by #bits set in vl_select_mask*/ | |
2135 | } port[1]; /* array size defined by #ports in attribute modifier */ | |
2136 | }; | |
2137 | ||
2138 | struct opa_port_error_counters64_msg { | |
2139 | /* Request contains first two fields, response contains the | |
2140 | * whole magilla */ | |
2141 | __be64 port_select_mask[4]; | |
2142 | __be32 vl_select_mask; | |
2143 | ||
2144 | /* Response-only fields follow */ | |
2145 | __be32 reserved1; | |
2146 | struct _port_ectrs { | |
2147 | u8 port_number; | |
2148 | u8 reserved2[7]; | |
2149 | __be64 port_rcv_constraint_errors; | |
2150 | __be64 port_rcv_switch_relay_errors; | |
2151 | __be64 port_xmit_discards; | |
2152 | __be64 port_xmit_constraint_errors; | |
2153 | __be64 port_rcv_remote_physical_errors; | |
2154 | __be64 local_link_integrity_errors; | |
2155 | __be64 port_rcv_errors; | |
2156 | __be64 excessive_buffer_overruns; | |
2157 | __be64 fm_config_errors; | |
2158 | __be32 link_error_recovery; | |
2159 | __be32 link_downed; | |
2160 | u8 uncorrectable_errors; | |
2161 | u8 reserved3[7]; | |
2162 | struct _vls_ectrs { | |
2163 | __be64 port_vl_xmit_discards; | |
2164 | } vls[0]; | |
2165 | /* array size defined by #bits set in vl_select_mask */ | |
2166 | } port[1]; /* array size defined by #ports in attribute modifier */ | |
2167 | }; | |
2168 | ||
2169 | struct opa_port_error_info_msg { | |
2170 | __be64 port_select_mask[4]; | |
2171 | __be32 error_info_select_mask; | |
2172 | __be32 reserved1; | |
2173 | struct _port_ei { | |
2174 | ||
2175 | u8 port_number; | |
2176 | u8 reserved2[7]; | |
2177 | ||
2178 | /* PortRcvErrorInfo */ | |
2179 | struct { | |
2180 | u8 status_and_code; | |
2181 | union { | |
2182 | u8 raw[17]; | |
2183 | struct { | |
2184 | /* EI1to12 format */ | |
2185 | u8 packet_flit1[8]; | |
2186 | u8 packet_flit2[8]; | |
2187 | u8 remaining_flit_bits12; | |
2188 | } ei1to12; | |
2189 | struct { | |
2190 | u8 packet_bytes[8]; | |
2191 | u8 remaining_flit_bits; | |
2192 | } ei13; | |
2193 | } ei; | |
2194 | u8 reserved3[6]; | |
2195 | } __packed port_rcv_ei; | |
2196 | ||
2197 | /* ExcessiveBufferOverrunInfo */ | |
2198 | struct { | |
2199 | u8 status_and_sc; | |
2200 | u8 reserved4[7]; | |
2201 | } __packed excessive_buffer_overrun_ei; | |
2202 | ||
2203 | /* PortXmitConstraintErrorInfo */ | |
2204 | struct { | |
2205 | u8 status; | |
2206 | u8 reserved5; | |
2207 | __be16 pkey; | |
2208 | __be32 slid; | |
2209 | } __packed port_xmit_constraint_ei; | |
2210 | ||
2211 | /* PortRcvConstraintErrorInfo */ | |
2212 | struct { | |
2213 | u8 status; | |
2214 | u8 reserved6; | |
2215 | __be16 pkey; | |
2216 | __be32 slid; | |
2217 | } __packed port_rcv_constraint_ei; | |
2218 | ||
2219 | /* PortRcvSwitchRelayErrorInfo */ | |
2220 | struct { | |
2221 | u8 status_and_code; | |
2222 | u8 reserved7[3]; | |
2223 | __u32 error_info; | |
2224 | } __packed port_rcv_switch_relay_ei; | |
2225 | ||
2226 | /* UncorrectableErrorInfo */ | |
2227 | struct { | |
2228 | u8 status_and_code; | |
2229 | u8 reserved8; | |
2230 | } __packed uncorrectable_ei; | |
2231 | ||
2232 | /* FMConfigErrorInfo */ | |
2233 | struct { | |
2234 | u8 status_and_code; | |
2235 | u8 error_info; | |
2236 | } __packed fm_config_ei; | |
2237 | __u32 reserved9; | |
2238 | } port[1]; /* actual array size defined by #ports in attr modifier */ | |
2239 | }; | |
2240 | ||
2241 | /* opa_port_error_info_msg error_info_select_mask bit definitions */ | |
2242 | enum error_info_selects { | |
2243 | ES_PORT_RCV_ERROR_INFO = (1 << 31), | |
2244 | ES_EXCESSIVE_BUFFER_OVERRUN_INFO = (1 << 30), | |
2245 | ES_PORT_XMIT_CONSTRAINT_ERROR_INFO = (1 << 29), | |
2246 | ES_PORT_RCV_CONSTRAINT_ERROR_INFO = (1 << 28), | |
2247 | ES_PORT_RCV_SWITCH_RELAY_ERROR_INFO = (1 << 27), | |
2248 | ES_UNCORRECTABLE_ERROR_INFO = (1 << 26), | |
2249 | ES_FM_CONFIG_ERROR_INFO = (1 << 25) | |
2250 | }; | |
2251 | ||
2252 | static int pma_get_opa_classportinfo(struct opa_pma_mad *pmp, | |
2253 | struct ib_device *ibdev, u32 *resp_len) | |
2254 | { | |
2255 | struct opa_class_port_info *p = | |
2256 | (struct opa_class_port_info *)pmp->data; | |
2257 | ||
2258 | memset(pmp->data, 0, sizeof(pmp->data)); | |
2259 | ||
2260 | if (pmp->mad_hdr.attr_mod != 0) | |
2261 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
2262 | ||
2263 | p->base_version = OPA_MGMT_BASE_VERSION; | |
2264 | p->class_version = OPA_SMI_CLASS_VERSION; | |
2265 | /* | |
2266 | * Expected response time is 4.096 usec. * 2^18 == 1.073741824 sec. | |
2267 | */ | |
2268 | p->cap_mask2_resp_time = cpu_to_be32(18); | |
2269 | ||
2270 | if (resp_len) | |
2271 | *resp_len += sizeof(*p); | |
2272 | ||
2273 | return reply((struct ib_mad_hdr *)pmp); | |
2274 | } | |
2275 | ||
2276 | static void a0_portstatus(struct hfi1_pportdata *ppd, | |
2277 | struct opa_port_status_rsp *rsp, u32 vl_select_mask) | |
2278 | { | |
2279 | if (!is_bx(ppd->dd)) { | |
2280 | unsigned long vl; | |
f4ddedf4 | 2281 | u64 sum_vl_xmit_wait = 0; |
77241056 | 2282 | u32 vl_all_mask = VL_MASK_ALL; |
77241056 MM |
2283 | |
2284 | for_each_set_bit(vl, (unsigned long *)&(vl_all_mask), | |
2285 | 8 * sizeof(vl_all_mask)) { | |
f4ddedf4 IW |
2286 | u64 tmp = sum_vl_xmit_wait + |
2287 | read_port_cntr(ppd, C_TX_WAIT_VL, | |
2288 | idx_from_vl(vl)); | |
2289 | if (tmp < sum_vl_xmit_wait) { | |
2290 | /* we wrapped */ | |
2291 | sum_vl_xmit_wait = (u64)~0; | |
2292 | break; | |
2293 | } | |
2294 | sum_vl_xmit_wait = tmp; | |
77241056 | 2295 | } |
f4ddedf4 IW |
2296 | if (be64_to_cpu(rsp->port_xmit_wait) > sum_vl_xmit_wait) |
2297 | rsp->port_xmit_wait = cpu_to_be64(sum_vl_xmit_wait); | |
77241056 MM |
2298 | } |
2299 | } | |
2300 | ||
2301 | ||
2302 | static int pma_get_opa_portstatus(struct opa_pma_mad *pmp, | |
2303 | struct ib_device *ibdev, u8 port, u32 *resp_len) | |
2304 | { | |
2305 | struct opa_port_status_req *req = | |
2306 | (struct opa_port_status_req *)pmp->data; | |
2307 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
2308 | struct opa_port_status_rsp *rsp; | |
2309 | u32 vl_select_mask = be32_to_cpu(req->vl_select_mask); | |
2310 | unsigned long vl; | |
2311 | size_t response_data_size; | |
2312 | u32 nports = be32_to_cpu(pmp->mad_hdr.attr_mod) >> 24; | |
2313 | u8 port_num = req->port_num; | |
2314 | u8 num_vls = hweight32(vl_select_mask); | |
2315 | struct _vls_pctrs *vlinfo; | |
2316 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
2317 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
2318 | int vfi; | |
2319 | u64 tmp, tmp2; | |
2320 | ||
2321 | response_data_size = sizeof(struct opa_port_status_rsp) + | |
2322 | num_vls * sizeof(struct _vls_pctrs); | |
2323 | if (response_data_size > sizeof(pmp->data)) { | |
2324 | pmp->mad_hdr.status |= OPA_PM_STATUS_REQUEST_TOO_LARGE; | |
2325 | return reply((struct ib_mad_hdr *)pmp); | |
2326 | } | |
2327 | ||
2328 | if (nports != 1 || (port_num && port_num != port) | |
2329 | || num_vls > OPA_MAX_VLS || (vl_select_mask & ~VL_MASK_ALL)) { | |
2330 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
2331 | return reply((struct ib_mad_hdr *)pmp); | |
2332 | } | |
2333 | ||
2334 | memset(pmp->data, 0, sizeof(pmp->data)); | |
2335 | ||
2336 | rsp = (struct opa_port_status_rsp *)pmp->data; | |
2337 | if (port_num) | |
2338 | rsp->port_num = port_num; | |
2339 | else | |
2340 | rsp->port_num = port; | |
2341 | ||
2342 | rsp->port_rcv_constraint_errors = | |
2343 | cpu_to_be64(read_port_cntr(ppd, C_SW_RCV_CSTR_ERR, | |
2344 | CNTR_INVALID_VL)); | |
2345 | ||
2346 | hfi1_read_link_quality(dd, &rsp->link_quality_indicator); | |
2347 | ||
2348 | rsp->vl_select_mask = cpu_to_be32(vl_select_mask); | |
2349 | rsp->port_xmit_data = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_FLITS, | |
2350 | CNTR_INVALID_VL)); | |
2351 | rsp->port_rcv_data = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FLITS, | |
2352 | CNTR_INVALID_VL)); | |
77241056 MM |
2353 | rsp->port_xmit_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_PKTS, |
2354 | CNTR_INVALID_VL)); | |
2355 | rsp->port_rcv_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_PKTS, | |
2356 | CNTR_INVALID_VL)); | |
2357 | rsp->port_multicast_xmit_pkts = | |
2358 | cpu_to_be64(read_dev_cntr(dd, C_DC_MC_XMIT_PKTS, | |
2359 | CNTR_INVALID_VL)); | |
2360 | rsp->port_multicast_rcv_pkts = | |
2361 | cpu_to_be64(read_dev_cntr(dd, C_DC_MC_RCV_PKTS, | |
2362 | CNTR_INVALID_VL)); | |
2363 | rsp->port_xmit_wait = | |
2364 | cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT, CNTR_INVALID_VL)); | |
2365 | rsp->port_rcv_fecn = | |
2366 | cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN, CNTR_INVALID_VL)); | |
2367 | rsp->port_rcv_becn = | |
2368 | cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN, CNTR_INVALID_VL)); | |
2369 | rsp->port_xmit_discards = | |
2370 | cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_DSCD, | |
2371 | CNTR_INVALID_VL)); | |
2372 | rsp->port_xmit_constraint_errors = | |
2373 | cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_CSTR_ERR, | |
2374 | CNTR_INVALID_VL)); | |
2375 | rsp->port_rcv_remote_physical_errors = | |
2376 | cpu_to_be64(read_dev_cntr(dd, C_DC_RMT_PHY_ERR, | |
2377 | CNTR_INVALID_VL)); | |
2378 | tmp = read_dev_cntr(dd, C_DC_RX_REPLAY, CNTR_INVALID_VL); | |
2379 | tmp2 = tmp + read_dev_cntr(dd, C_DC_TX_REPLAY, CNTR_INVALID_VL); | |
2380 | if (tmp2 < tmp) { | |
2381 | /* overflow/wrapped */ | |
2382 | rsp->local_link_integrity_errors = cpu_to_be64(~0); | |
2383 | } else { | |
2384 | rsp->local_link_integrity_errors = cpu_to_be64(tmp2); | |
2385 | } | |
2386 | tmp = read_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL); | |
2387 | tmp2 = tmp + read_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT, | |
2388 | CNTR_INVALID_VL); | |
2389 | if (tmp2 > (u32)UINT_MAX || tmp2 < tmp) { | |
2390 | /* overflow/wrapped */ | |
2391 | rsp->link_error_recovery = cpu_to_be32(~0); | |
2392 | } else { | |
2393 | rsp->link_error_recovery = cpu_to_be32(tmp2); | |
2394 | } | |
2395 | rsp->port_rcv_errors = | |
2396 | cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_ERR, CNTR_INVALID_VL)); | |
2397 | rsp->excessive_buffer_overruns = | |
2398 | cpu_to_be64(read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL)); | |
2399 | rsp->fm_config_errors = | |
2400 | cpu_to_be64(read_dev_cntr(dd, C_DC_FM_CFG_ERR, | |
2401 | CNTR_INVALID_VL)); | |
2402 | rsp->link_downed = cpu_to_be32(read_port_cntr(ppd, C_SW_LINK_DOWN, | |
2403 | CNTR_INVALID_VL)); | |
2404 | ||
2405 | /* rsp->uncorrectable_errors is 8 bits wide, and it pegs at 0xff */ | |
2406 | tmp = read_dev_cntr(dd, C_DC_UNC_ERR, CNTR_INVALID_VL); | |
2407 | rsp->uncorrectable_errors = tmp < 0x100 ? (tmp & 0xff) : 0xff; | |
2408 | ||
2409 | vlinfo = &(rsp->vls[0]); | |
2410 | vfi = 0; | |
2411 | /* The vl_select_mask has been checked above, and we know | |
2412 | * that it contains only entries which represent valid VLs. | |
2413 | * So in the for_each_set_bit() loop below, we don't need | |
2414 | * any additional checks for vl. | |
2415 | */ | |
2416 | for_each_set_bit(vl, (unsigned long *)&(vl_select_mask), | |
2417 | 8 * sizeof(vl_select_mask)) { | |
2418 | memset(vlinfo, 0, sizeof(*vlinfo)); | |
2419 | ||
2420 | tmp = read_dev_cntr(dd, C_DC_RX_FLIT_VL, idx_from_vl(vl)); | |
2421 | rsp->vls[vfi].port_vl_rcv_data = cpu_to_be64(tmp); | |
77241056 MM |
2422 | |
2423 | rsp->vls[vfi].port_vl_rcv_pkts = | |
2424 | cpu_to_be64(read_dev_cntr(dd, C_DC_RX_PKT_VL, | |
2425 | idx_from_vl(vl))); | |
2426 | ||
2427 | rsp->vls[vfi].port_vl_xmit_data = | |
2428 | cpu_to_be64(read_port_cntr(ppd, C_TX_FLIT_VL, | |
2429 | idx_from_vl(vl))); | |
2430 | ||
2431 | rsp->vls[vfi].port_vl_xmit_pkts = | |
2432 | cpu_to_be64(read_port_cntr(ppd, C_TX_PKT_VL, | |
2433 | idx_from_vl(vl))); | |
2434 | ||
2435 | rsp->vls[vfi].port_vl_xmit_wait = | |
2436 | cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT_VL, | |
2437 | idx_from_vl(vl))); | |
2438 | ||
2439 | rsp->vls[vfi].port_vl_rcv_fecn = | |
2440 | cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN_VL, | |
2441 | idx_from_vl(vl))); | |
2442 | ||
2443 | rsp->vls[vfi].port_vl_rcv_becn = | |
2444 | cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN_VL, | |
2445 | idx_from_vl(vl))); | |
2446 | ||
2447 | vlinfo++; | |
2448 | vfi++; | |
2449 | } | |
2450 | ||
2451 | a0_portstatus(ppd, rsp, vl_select_mask); | |
2452 | ||
2453 | if (resp_len) | |
2454 | *resp_len += response_data_size; | |
2455 | ||
2456 | return reply((struct ib_mad_hdr *)pmp); | |
2457 | } | |
2458 | ||
f0852922 AL |
2459 | static u64 get_error_counter_summary(struct ib_device *ibdev, u8 port, |
2460 | u8 res_lli, u8 res_ler) | |
77241056 MM |
2461 | { |
2462 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
2463 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
2464 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
2465 | u64 error_counter_summary = 0, tmp; | |
2466 | ||
2467 | error_counter_summary += read_port_cntr(ppd, C_SW_RCV_CSTR_ERR, | |
2468 | CNTR_INVALID_VL); | |
2469 | /* port_rcv_switch_relay_errors is 0 for HFIs */ | |
2470 | error_counter_summary += read_port_cntr(ppd, C_SW_XMIT_DSCD, | |
2471 | CNTR_INVALID_VL); | |
2472 | error_counter_summary += read_port_cntr(ppd, C_SW_XMIT_CSTR_ERR, | |
2473 | CNTR_INVALID_VL); | |
2474 | error_counter_summary += read_dev_cntr(dd, C_DC_RMT_PHY_ERR, | |
2475 | CNTR_INVALID_VL); | |
f0852922 AL |
2476 | /* local link integrity must be right-shifted by the lli resolution */ |
2477 | tmp = read_dev_cntr(dd, C_DC_RX_REPLAY, CNTR_INVALID_VL); | |
2478 | tmp += read_dev_cntr(dd, C_DC_TX_REPLAY, CNTR_INVALID_VL); | |
2479 | error_counter_summary += (tmp >> res_lli); | |
2480 | /* link error recovery must b right-shifted by the ler resolution */ | |
2481 | tmp = read_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL); | |
2482 | tmp += read_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT, CNTR_INVALID_VL); | |
2483 | error_counter_summary += (tmp >> res_ler); | |
77241056 MM |
2484 | error_counter_summary += read_dev_cntr(dd, C_DC_RCV_ERR, |
2485 | CNTR_INVALID_VL); | |
2486 | error_counter_summary += read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL); | |
2487 | error_counter_summary += read_dev_cntr(dd, C_DC_FM_CFG_ERR, | |
2488 | CNTR_INVALID_VL); | |
2489 | /* ppd->link_downed is a 32-bit value */ | |
2490 | error_counter_summary += read_port_cntr(ppd, C_SW_LINK_DOWN, | |
2491 | CNTR_INVALID_VL); | |
2492 | tmp = read_dev_cntr(dd, C_DC_UNC_ERR, CNTR_INVALID_VL); | |
2493 | /* this is an 8-bit quantity */ | |
2494 | error_counter_summary += tmp < 0x100 ? (tmp & 0xff) : 0xff; | |
2495 | ||
2496 | return error_counter_summary; | |
2497 | } | |
2498 | ||
f4ddedf4 | 2499 | static void a0_datacounters(struct hfi1_pportdata *ppd, struct _port_dctrs *rsp, |
77241056 MM |
2500 | u32 vl_select_mask) |
2501 | { | |
f4ddedf4 | 2502 | if (!is_bx(ppd->dd)) { |
77241056 | 2503 | unsigned long vl; |
db00a055 | 2504 | u64 sum_vl_xmit_wait = 0; |
f4ddedf4 | 2505 | u32 vl_all_mask = VL_MASK_ALL; |
db00a055 | 2506 | |
f4ddedf4 IW |
2507 | for_each_set_bit(vl, (unsigned long *)&(vl_all_mask), |
2508 | 8 * sizeof(vl_all_mask)) { | |
77241056 | 2509 | u64 tmp = sum_vl_xmit_wait + |
f4ddedf4 IW |
2510 | read_port_cntr(ppd, C_TX_WAIT_VL, |
2511 | idx_from_vl(vl)); | |
77241056 MM |
2512 | if (tmp < sum_vl_xmit_wait) { |
2513 | /* we wrapped */ | |
2514 | sum_vl_xmit_wait = (u64) ~0; | |
2515 | break; | |
2516 | } | |
2517 | sum_vl_xmit_wait = tmp; | |
2518 | } | |
2519 | if (be64_to_cpu(rsp->port_xmit_wait) > sum_vl_xmit_wait) | |
2520 | rsp->port_xmit_wait = cpu_to_be64(sum_vl_xmit_wait); | |
2521 | } | |
2522 | } | |
2523 | ||
2524 | static int pma_get_opa_datacounters(struct opa_pma_mad *pmp, | |
2525 | struct ib_device *ibdev, u8 port, u32 *resp_len) | |
2526 | { | |
2527 | struct opa_port_data_counters_msg *req = | |
2528 | (struct opa_port_data_counters_msg *)pmp->data; | |
2529 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
2530 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
2531 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
2532 | struct _port_dctrs *rsp; | |
2533 | struct _vls_dctrs *vlinfo; | |
2534 | size_t response_data_size; | |
2535 | u32 num_ports; | |
2536 | u8 num_pslm; | |
2537 | u8 lq, num_vls; | |
f0852922 | 2538 | u8 res_lli, res_ler; |
77241056 MM |
2539 | u64 port_mask; |
2540 | unsigned long port_num; | |
2541 | unsigned long vl; | |
2542 | u32 vl_select_mask; | |
2543 | int vfi; | |
2544 | ||
2545 | num_ports = be32_to_cpu(pmp->mad_hdr.attr_mod) >> 24; | |
2546 | num_pslm = hweight64(be64_to_cpu(req->port_select_mask[3])); | |
2547 | num_vls = hweight32(be32_to_cpu(req->vl_select_mask)); | |
2548 | vl_select_mask = be32_to_cpu(req->vl_select_mask); | |
f0852922 AL |
2549 | res_lli = (u8)(be32_to_cpu(req->resolution) & MSK_LLI) >> MSK_LLI_SFT; |
2550 | res_lli = res_lli ? res_lli + ADD_LLI : 0; | |
2551 | res_ler = (u8)(be32_to_cpu(req->resolution) & MSK_LER) >> MSK_LER_SFT; | |
2552 | res_ler = res_ler ? res_ler + ADD_LER : 0; | |
77241056 MM |
2553 | |
2554 | if (num_ports != 1 || (vl_select_mask & ~VL_MASK_ALL)) { | |
2555 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
2556 | return reply((struct ib_mad_hdr *)pmp); | |
2557 | } | |
2558 | ||
2559 | /* Sanity check */ | |
2560 | response_data_size = sizeof(struct opa_port_data_counters_msg) + | |
2561 | num_vls * sizeof(struct _vls_dctrs); | |
2562 | ||
2563 | if (response_data_size > sizeof(pmp->data)) { | |
2564 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
2565 | return reply((struct ib_mad_hdr *)pmp); | |
2566 | } | |
2567 | ||
2568 | /* | |
2569 | * The bit set in the mask needs to be consistent with the | |
2570 | * port the request came in on. | |
2571 | */ | |
2572 | port_mask = be64_to_cpu(req->port_select_mask[3]); | |
2573 | port_num = find_first_bit((unsigned long *)&port_mask, | |
2574 | sizeof(port_mask)); | |
2575 | ||
2576 | if ((u8)port_num != port) { | |
2577 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
2578 | return reply((struct ib_mad_hdr *)pmp); | |
2579 | } | |
2580 | ||
2581 | rsp = (struct _port_dctrs *)&(req->port[0]); | |
2582 | memset(rsp, 0, sizeof(*rsp)); | |
2583 | ||
2584 | rsp->port_number = port; | |
2585 | /* | |
2586 | * Note that link_quality_indicator is a 32 bit quantity in | |
2587 | * 'datacounters' queries (as opposed to 'portinfo' queries, | |
2588 | * where it's a byte). | |
2589 | */ | |
2590 | hfi1_read_link_quality(dd, &lq); | |
2591 | rsp->link_quality_indicator = cpu_to_be32((u32)lq); | |
2592 | ||
2593 | /* rsp->sw_port_congestion is 0 for HFIs */ | |
2594 | /* rsp->port_xmit_time_cong is 0 for HFIs */ | |
2595 | /* rsp->port_xmit_wasted_bw ??? */ | |
2596 | /* rsp->port_xmit_wait_data ??? */ | |
2597 | /* rsp->port_mark_fecn is 0 for HFIs */ | |
2598 | ||
2599 | rsp->port_xmit_data = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_FLITS, | |
2600 | CNTR_INVALID_VL)); | |
2601 | rsp->port_rcv_data = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FLITS, | |
2602 | CNTR_INVALID_VL)); | |
77241056 MM |
2603 | rsp->port_xmit_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_XMIT_PKTS, |
2604 | CNTR_INVALID_VL)); | |
2605 | rsp->port_rcv_pkts = cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_PKTS, | |
2606 | CNTR_INVALID_VL)); | |
2607 | rsp->port_multicast_xmit_pkts = | |
2608 | cpu_to_be64(read_dev_cntr(dd, C_DC_MC_XMIT_PKTS, | |
2609 | CNTR_INVALID_VL)); | |
2610 | rsp->port_multicast_rcv_pkts = | |
2611 | cpu_to_be64(read_dev_cntr(dd, C_DC_MC_RCV_PKTS, | |
2612 | CNTR_INVALID_VL)); | |
2613 | rsp->port_xmit_wait = | |
2614 | cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT, CNTR_INVALID_VL)); | |
2615 | rsp->port_rcv_fecn = | |
2616 | cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN, CNTR_INVALID_VL)); | |
2617 | rsp->port_rcv_becn = | |
2618 | cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN, CNTR_INVALID_VL)); | |
2619 | ||
2620 | rsp->port_error_counter_summary = | |
f0852922 AL |
2621 | cpu_to_be64(get_error_counter_summary(ibdev, port, |
2622 | res_lli, res_ler)); | |
77241056 MM |
2623 | |
2624 | vlinfo = &(rsp->vls[0]); | |
2625 | vfi = 0; | |
2626 | /* The vl_select_mask has been checked above, and we know | |
2627 | * that it contains only entries which represent valid VLs. | |
2628 | * So in the for_each_set_bit() loop below, we don't need | |
2629 | * any additional checks for vl. | |
2630 | */ | |
2631 | for_each_set_bit(vl, (unsigned long *)&(vl_select_mask), | |
2632 | 8 * sizeof(req->vl_select_mask)) { | |
2633 | memset(vlinfo, 0, sizeof(*vlinfo)); | |
2634 | ||
2635 | rsp->vls[vfi].port_vl_xmit_data = | |
2636 | cpu_to_be64(read_port_cntr(ppd, C_TX_FLIT_VL, | |
2637 | idx_from_vl(vl))); | |
2638 | ||
2639 | rsp->vls[vfi].port_vl_rcv_data = | |
2640 | cpu_to_be64(read_dev_cntr(dd, C_DC_RX_FLIT_VL, | |
2641 | idx_from_vl(vl))); | |
77241056 MM |
2642 | |
2643 | rsp->vls[vfi].port_vl_xmit_pkts = | |
2644 | cpu_to_be64(read_port_cntr(ppd, C_TX_PKT_VL, | |
2645 | idx_from_vl(vl))); | |
2646 | ||
2647 | rsp->vls[vfi].port_vl_rcv_pkts = | |
2648 | cpu_to_be64(read_dev_cntr(dd, C_DC_RX_PKT_VL, | |
2649 | idx_from_vl(vl))); | |
2650 | ||
2651 | rsp->vls[vfi].port_vl_xmit_wait = | |
2652 | cpu_to_be64(read_port_cntr(ppd, C_TX_WAIT_VL, | |
2653 | idx_from_vl(vl))); | |
2654 | ||
2655 | rsp->vls[vfi].port_vl_rcv_fecn = | |
2656 | cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_FCN_VL, | |
2657 | idx_from_vl(vl))); | |
2658 | rsp->vls[vfi].port_vl_rcv_becn = | |
2659 | cpu_to_be64(read_dev_cntr(dd, C_DC_RCV_BCN_VL, | |
2660 | idx_from_vl(vl))); | |
2661 | ||
2662 | /* rsp->port_vl_xmit_time_cong is 0 for HFIs */ | |
2663 | /* rsp->port_vl_xmit_wasted_bw ??? */ | |
2664 | /* port_vl_xmit_wait_data - TXE (table 13-9 HFI spec) ??? | |
2665 | * does this differ from rsp->vls[vfi].port_vl_xmit_wait */ | |
2666 | /*rsp->vls[vfi].port_vl_mark_fecn = | |
2667 | cpu_to_be64(read_csr(dd, DCC_PRF_PORT_VL_MARK_FECN_CNT | |
2668 | + offset)); | |
2669 | */ | |
2670 | vlinfo++; | |
2671 | vfi++; | |
2672 | } | |
2673 | ||
f4ddedf4 | 2674 | a0_datacounters(ppd, rsp, vl_select_mask); |
77241056 MM |
2675 | |
2676 | if (resp_len) | |
2677 | *resp_len += response_data_size; | |
2678 | ||
2679 | return reply((struct ib_mad_hdr *)pmp); | |
2680 | } | |
2681 | ||
2682 | static int pma_get_opa_porterrors(struct opa_pma_mad *pmp, | |
2683 | struct ib_device *ibdev, u8 port, u32 *resp_len) | |
2684 | { | |
2685 | size_t response_data_size; | |
2686 | struct _port_ectrs *rsp; | |
2687 | unsigned long port_num; | |
2688 | struct opa_port_error_counters64_msg *req; | |
2689 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
2690 | u32 num_ports; | |
2691 | u8 num_pslm; | |
2692 | u8 num_vls; | |
2693 | struct hfi1_ibport *ibp; | |
2694 | struct hfi1_pportdata *ppd; | |
2695 | struct _vls_ectrs *vlinfo; | |
2696 | unsigned long vl; | |
2697 | u64 port_mask, tmp, tmp2; | |
2698 | u32 vl_select_mask; | |
2699 | int vfi; | |
2700 | ||
2701 | req = (struct opa_port_error_counters64_msg *)pmp->data; | |
2702 | ||
2703 | num_ports = be32_to_cpu(pmp->mad_hdr.attr_mod) >> 24; | |
2704 | ||
2705 | num_pslm = hweight64(be64_to_cpu(req->port_select_mask[3])); | |
2706 | num_vls = hweight32(be32_to_cpu(req->vl_select_mask)); | |
2707 | ||
2708 | if (num_ports != 1 || num_ports != num_pslm) { | |
2709 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
2710 | return reply((struct ib_mad_hdr *)pmp); | |
2711 | } | |
2712 | ||
2713 | response_data_size = sizeof(struct opa_port_error_counters64_msg) + | |
2714 | num_vls * sizeof(struct _vls_ectrs); | |
2715 | ||
2716 | if (response_data_size > sizeof(pmp->data)) { | |
2717 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
2718 | return reply((struct ib_mad_hdr *)pmp); | |
2719 | } | |
2720 | /* | |
2721 | * The bit set in the mask needs to be consistent with the | |
2722 | * port the request came in on. | |
2723 | */ | |
2724 | port_mask = be64_to_cpu(req->port_select_mask[3]); | |
2725 | port_num = find_first_bit((unsigned long *)&port_mask, | |
2726 | sizeof(port_mask)); | |
2727 | ||
2728 | if ((u8)port_num != port) { | |
2729 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
2730 | return reply((struct ib_mad_hdr *)pmp); | |
2731 | } | |
2732 | ||
2733 | rsp = (struct _port_ectrs *)&(req->port[0]); | |
2734 | ||
2735 | ibp = to_iport(ibdev, port_num); | |
2736 | ppd = ppd_from_ibp(ibp); | |
2737 | ||
2738 | memset(rsp, 0, sizeof(*rsp)); | |
2739 | rsp->port_number = (u8)port_num; | |
2740 | ||
2741 | rsp->port_rcv_constraint_errors = | |
2742 | cpu_to_be64(read_port_cntr(ppd, C_SW_RCV_CSTR_ERR, | |
2743 | CNTR_INVALID_VL)); | |
2744 | /* port_rcv_switch_relay_errors is 0 for HFIs */ | |
2745 | rsp->port_xmit_discards = | |
2746 | cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_DSCD, | |
2747 | CNTR_INVALID_VL)); | |
2748 | rsp->port_rcv_remote_physical_errors = | |
2749 | cpu_to_be64(read_dev_cntr(dd, C_DC_RMT_PHY_ERR, | |
2750 | CNTR_INVALID_VL)); | |
2751 | tmp = read_dev_cntr(dd, C_DC_RX_REPLAY, CNTR_INVALID_VL); | |
2752 | tmp2 = tmp + read_dev_cntr(dd, C_DC_TX_REPLAY, CNTR_INVALID_VL); | |
2753 | if (tmp2 < tmp) { | |
2754 | /* overflow/wrapped */ | |
2755 | rsp->local_link_integrity_errors = cpu_to_be64(~0); | |
2756 | } else { | |
2757 | rsp->local_link_integrity_errors = cpu_to_be64(tmp2); | |
2758 | } | |
2759 | tmp = read_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL); | |
2760 | tmp2 = tmp + read_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT, | |
2761 | CNTR_INVALID_VL); | |
2762 | if (tmp2 > (u32)UINT_MAX || tmp2 < tmp) { | |
2763 | /* overflow/wrapped */ | |
2764 | rsp->link_error_recovery = cpu_to_be32(~0); | |
2765 | } else { | |
2766 | rsp->link_error_recovery = cpu_to_be32(tmp2); | |
2767 | } | |
2768 | rsp->port_xmit_constraint_errors = | |
2769 | cpu_to_be64(read_port_cntr(ppd, C_SW_XMIT_CSTR_ERR, | |
2770 | CNTR_INVALID_VL)); | |
2771 | rsp->excessive_buffer_overruns = | |
2772 | cpu_to_be64(read_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL)); | |
2773 | rsp->fm_config_errors = | |
2774 | cpu_to_be64(read_dev_cntr(dd, C_DC_FM_CFG_ERR, | |
2775 | CNTR_INVALID_VL)); | |
2776 | rsp->link_downed = cpu_to_be32(read_port_cntr(ppd, C_SW_LINK_DOWN, | |
2777 | CNTR_INVALID_VL)); | |
2778 | tmp = read_dev_cntr(dd, C_DC_UNC_ERR, CNTR_INVALID_VL); | |
2779 | rsp->uncorrectable_errors = tmp < 0x100 ? (tmp & 0xff) : 0xff; | |
2780 | ||
2781 | vlinfo = (struct _vls_ectrs *)&(rsp->vls[0]); | |
2782 | vfi = 0; | |
2783 | vl_select_mask = be32_to_cpu(req->vl_select_mask); | |
2784 | for_each_set_bit(vl, (unsigned long *)&(vl_select_mask), | |
2785 | 8 * sizeof(req->vl_select_mask)) { | |
2786 | memset(vlinfo, 0, sizeof(*vlinfo)); | |
2787 | /* vlinfo->vls[vfi].port_vl_xmit_discards ??? */ | |
2788 | vlinfo += 1; | |
2789 | vfi++; | |
2790 | } | |
2791 | ||
2792 | if (resp_len) | |
2793 | *resp_len += response_data_size; | |
2794 | ||
2795 | return reply((struct ib_mad_hdr *)pmp); | |
2796 | } | |
2797 | ||
2798 | static int pma_get_opa_errorinfo(struct opa_pma_mad *pmp, | |
2799 | struct ib_device *ibdev, u8 port, u32 *resp_len) | |
2800 | { | |
2801 | size_t response_data_size; | |
2802 | struct _port_ei *rsp; | |
2803 | struct opa_port_error_info_msg *req; | |
2804 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
2805 | u64 port_mask; | |
2806 | u32 num_ports; | |
2807 | unsigned long port_num; | |
2808 | u8 num_pslm; | |
2809 | u64 reg; | |
2810 | ||
2811 | req = (struct opa_port_error_info_msg *)pmp->data; | |
2812 | rsp = (struct _port_ei *)&(req->port[0]); | |
2813 | ||
2814 | num_ports = OPA_AM_NPORT(be32_to_cpu(pmp->mad_hdr.attr_mod)); | |
2815 | num_pslm = hweight64(be64_to_cpu(req->port_select_mask[3])); | |
2816 | ||
2817 | memset(rsp, 0, sizeof(*rsp)); | |
2818 | ||
2819 | if (num_ports != 1 || num_ports != num_pslm) { | |
2820 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
2821 | return reply((struct ib_mad_hdr *)pmp); | |
2822 | } | |
2823 | ||
2824 | /* Sanity check */ | |
2825 | response_data_size = sizeof(struct opa_port_error_info_msg); | |
2826 | ||
2827 | if (response_data_size > sizeof(pmp->data)) { | |
2828 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
2829 | return reply((struct ib_mad_hdr *)pmp); | |
2830 | } | |
2831 | ||
2832 | /* | |
2833 | * The bit set in the mask needs to be consistent with the port | |
2834 | * the request came in on. | |
2835 | */ | |
2836 | port_mask = be64_to_cpu(req->port_select_mask[3]); | |
2837 | port_num = find_first_bit((unsigned long *)&port_mask, | |
2838 | sizeof(port_mask)); | |
2839 | ||
2840 | if ((u8)port_num != port) { | |
2841 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
2842 | return reply((struct ib_mad_hdr *)pmp); | |
2843 | } | |
2844 | ||
2845 | /* PortRcvErrorInfo */ | |
2846 | rsp->port_rcv_ei.status_and_code = | |
2847 | dd->err_info_rcvport.status_and_code; | |
2848 | memcpy(&rsp->port_rcv_ei.ei.ei1to12.packet_flit1, | |
2849 | &dd->err_info_rcvport.packet_flit1, sizeof(u64)); | |
2850 | memcpy(&rsp->port_rcv_ei.ei.ei1to12.packet_flit2, | |
2851 | &dd->err_info_rcvport.packet_flit2, sizeof(u64)); | |
2852 | ||
2853 | /* ExcessiverBufferOverrunInfo */ | |
2854 | reg = read_csr(dd, RCV_ERR_INFO); | |
2855 | if (reg & RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK) { | |
2856 | /* if the RcvExcessBufferOverrun bit is set, save SC of | |
2857 | * first pkt that encountered an excess buffer overrun */ | |
2858 | u8 tmp = (u8)reg; | |
2859 | ||
2860 | tmp &= RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SC_SMASK; | |
2861 | tmp <<= 2; | |
2862 | rsp->excessive_buffer_overrun_ei.status_and_sc = tmp; | |
2863 | /* set the status bit */ | |
2864 | rsp->excessive_buffer_overrun_ei.status_and_sc |= 0x80; | |
2865 | } | |
2866 | ||
2867 | rsp->port_xmit_constraint_ei.status = | |
2868 | dd->err_info_xmit_constraint.status; | |
2869 | rsp->port_xmit_constraint_ei.pkey = | |
2870 | cpu_to_be16(dd->err_info_xmit_constraint.pkey); | |
2871 | rsp->port_xmit_constraint_ei.slid = | |
2872 | cpu_to_be32(dd->err_info_xmit_constraint.slid); | |
2873 | ||
2874 | rsp->port_rcv_constraint_ei.status = | |
2875 | dd->err_info_rcv_constraint.status; | |
2876 | rsp->port_rcv_constraint_ei.pkey = | |
2877 | cpu_to_be16(dd->err_info_rcv_constraint.pkey); | |
2878 | rsp->port_rcv_constraint_ei.slid = | |
2879 | cpu_to_be32(dd->err_info_rcv_constraint.slid); | |
2880 | ||
2881 | /* UncorrectableErrorInfo */ | |
2882 | rsp->uncorrectable_ei.status_and_code = dd->err_info_uncorrectable; | |
2883 | ||
2884 | /* FMConfigErrorInfo */ | |
2885 | rsp->fm_config_ei.status_and_code = dd->err_info_fmconfig; | |
2886 | ||
2887 | if (resp_len) | |
2888 | *resp_len += response_data_size; | |
2889 | ||
2890 | return reply((struct ib_mad_hdr *)pmp); | |
2891 | } | |
2892 | ||
2893 | static int pma_set_opa_portstatus(struct opa_pma_mad *pmp, | |
2894 | struct ib_device *ibdev, u8 port, u32 *resp_len) | |
2895 | { | |
2896 | struct opa_clear_port_status *req = | |
2897 | (struct opa_clear_port_status *)pmp->data; | |
2898 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
2899 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
2900 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
2901 | u32 nports = be32_to_cpu(pmp->mad_hdr.attr_mod) >> 24; | |
2902 | u64 portn = be64_to_cpu(req->port_select_mask[3]); | |
2903 | u32 counter_select = be32_to_cpu(req->counter_select_mask); | |
2904 | u32 vl_select_mask = VL_MASK_ALL; /* clear all per-vl cnts */ | |
2905 | unsigned long vl; | |
2906 | ||
2907 | if ((nports != 1) || (portn != 1 << port)) { | |
2908 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
2909 | return reply((struct ib_mad_hdr *)pmp); | |
2910 | } | |
2911 | /* | |
2912 | * only counters returned by pma_get_opa_portstatus() are | |
2913 | * handled, so when pma_get_opa_portstatus() gets a fix, | |
2914 | * the corresponding change should be made here as well. | |
2915 | */ | |
2916 | ||
2917 | if (counter_select & CS_PORT_XMIT_DATA) | |
2918 | write_dev_cntr(dd, C_DC_XMIT_FLITS, CNTR_INVALID_VL, 0); | |
2919 | ||
2920 | if (counter_select & CS_PORT_RCV_DATA) | |
2921 | write_dev_cntr(dd, C_DC_RCV_FLITS, CNTR_INVALID_VL, 0); | |
2922 | ||
2923 | if (counter_select & CS_PORT_XMIT_PKTS) | |
2924 | write_dev_cntr(dd, C_DC_XMIT_PKTS, CNTR_INVALID_VL, 0); | |
2925 | ||
2926 | if (counter_select & CS_PORT_RCV_PKTS) | |
2927 | write_dev_cntr(dd, C_DC_RCV_PKTS, CNTR_INVALID_VL, 0); | |
2928 | ||
2929 | if (counter_select & CS_PORT_MCAST_XMIT_PKTS) | |
2930 | write_dev_cntr(dd, C_DC_MC_XMIT_PKTS, CNTR_INVALID_VL, 0); | |
2931 | ||
2932 | if (counter_select & CS_PORT_MCAST_RCV_PKTS) | |
2933 | write_dev_cntr(dd, C_DC_MC_RCV_PKTS, CNTR_INVALID_VL, 0); | |
2934 | ||
2935 | if (counter_select & CS_PORT_XMIT_WAIT) | |
2936 | write_port_cntr(ppd, C_TX_WAIT, CNTR_INVALID_VL, 0); | |
2937 | ||
2938 | /* ignore cs_sw_portCongestion for HFIs */ | |
2939 | ||
2940 | if (counter_select & CS_PORT_RCV_FECN) | |
2941 | write_dev_cntr(dd, C_DC_RCV_FCN, CNTR_INVALID_VL, 0); | |
2942 | ||
2943 | if (counter_select & CS_PORT_RCV_BECN) | |
2944 | write_dev_cntr(dd, C_DC_RCV_BCN, CNTR_INVALID_VL, 0); | |
2945 | ||
2946 | /* ignore cs_port_xmit_time_cong for HFIs */ | |
2947 | /* ignore cs_port_xmit_wasted_bw for now */ | |
2948 | /* ignore cs_port_xmit_wait_data for now */ | |
2949 | if (counter_select & CS_PORT_RCV_BUBBLE) | |
2950 | write_dev_cntr(dd, C_DC_RCV_BBL, CNTR_INVALID_VL, 0); | |
2951 | ||
2952 | /* Only applicable for switch */ | |
2953 | /*if (counter_select & CS_PORT_MARK_FECN) | |
2954 | write_csr(dd, DCC_PRF_PORT_MARK_FECN_CNT, 0);*/ | |
2955 | ||
2956 | if (counter_select & CS_PORT_RCV_CONSTRAINT_ERRORS) | |
2957 | write_port_cntr(ppd, C_SW_RCV_CSTR_ERR, CNTR_INVALID_VL, 0); | |
2958 | ||
2959 | /* ignore cs_port_rcv_switch_relay_errors for HFIs */ | |
2960 | if (counter_select & CS_PORT_XMIT_DISCARDS) | |
2961 | write_port_cntr(ppd, C_SW_XMIT_DSCD, CNTR_INVALID_VL, 0); | |
2962 | ||
2963 | if (counter_select & CS_PORT_XMIT_CONSTRAINT_ERRORS) | |
2964 | write_port_cntr(ppd, C_SW_XMIT_CSTR_ERR, CNTR_INVALID_VL, 0); | |
2965 | ||
2966 | if (counter_select & CS_PORT_RCV_REMOTE_PHYSICAL_ERRORS) | |
2967 | write_dev_cntr(dd, C_DC_RMT_PHY_ERR, CNTR_INVALID_VL, 0); | |
2968 | ||
2969 | if (counter_select & CS_LOCAL_LINK_INTEGRITY_ERRORS) { | |
2970 | write_dev_cntr(dd, C_DC_TX_REPLAY, CNTR_INVALID_VL, 0); | |
2971 | write_dev_cntr(dd, C_DC_RX_REPLAY, CNTR_INVALID_VL, 0); | |
2972 | } | |
2973 | ||
2974 | if (counter_select & CS_LINK_ERROR_RECOVERY) { | |
2975 | write_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL, 0); | |
2976 | write_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT, | |
2977 | CNTR_INVALID_VL, 0); | |
2978 | } | |
2979 | ||
2980 | if (counter_select & CS_PORT_RCV_ERRORS) | |
2981 | write_dev_cntr(dd, C_DC_RCV_ERR, CNTR_INVALID_VL, 0); | |
2982 | ||
2983 | if (counter_select & CS_EXCESSIVE_BUFFER_OVERRUNS) { | |
2984 | write_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL, 0); | |
2985 | dd->rcv_ovfl_cnt = 0; | |
2986 | } | |
2987 | ||
2988 | if (counter_select & CS_FM_CONFIG_ERRORS) | |
2989 | write_dev_cntr(dd, C_DC_FM_CFG_ERR, CNTR_INVALID_VL, 0); | |
2990 | ||
2991 | if (counter_select & CS_LINK_DOWNED) | |
2992 | write_port_cntr(ppd, C_SW_LINK_DOWN, CNTR_INVALID_VL, 0); | |
2993 | ||
2994 | if (counter_select & CS_UNCORRECTABLE_ERRORS) | |
2995 | write_dev_cntr(dd, C_DC_UNC_ERR, CNTR_INVALID_VL, 0); | |
2996 | ||
2997 | for_each_set_bit(vl, (unsigned long *)&(vl_select_mask), | |
2998 | 8 * sizeof(vl_select_mask)) { | |
2999 | ||
3000 | if (counter_select & CS_PORT_XMIT_DATA) | |
3001 | write_port_cntr(ppd, C_TX_FLIT_VL, idx_from_vl(vl), 0); | |
3002 | ||
3003 | if (counter_select & CS_PORT_RCV_DATA) | |
3004 | write_dev_cntr(dd, C_DC_RX_FLIT_VL, idx_from_vl(vl), 0); | |
3005 | ||
3006 | if (counter_select & CS_PORT_XMIT_PKTS) | |
3007 | write_port_cntr(ppd, C_TX_PKT_VL, idx_from_vl(vl), 0); | |
3008 | ||
3009 | if (counter_select & CS_PORT_RCV_PKTS) | |
3010 | write_dev_cntr(dd, C_DC_RX_PKT_VL, idx_from_vl(vl), 0); | |
3011 | ||
3012 | if (counter_select & CS_PORT_XMIT_WAIT) | |
3013 | write_port_cntr(ppd, C_TX_WAIT_VL, idx_from_vl(vl), 0); | |
3014 | ||
3015 | /* sw_port_vl_congestion is 0 for HFIs */ | |
3016 | if (counter_select & CS_PORT_RCV_FECN) | |
3017 | write_dev_cntr(dd, C_DC_RCV_FCN_VL, idx_from_vl(vl), 0); | |
3018 | ||
3019 | if (counter_select & CS_PORT_RCV_BECN) | |
3020 | write_dev_cntr(dd, C_DC_RCV_BCN_VL, idx_from_vl(vl), 0); | |
3021 | ||
3022 | /* port_vl_xmit_time_cong is 0 for HFIs */ | |
3023 | /* port_vl_xmit_wasted_bw ??? */ | |
3024 | /* port_vl_xmit_wait_data - TXE (table 13-9 HFI spec) ??? */ | |
3025 | if (counter_select & CS_PORT_RCV_BUBBLE) | |
3026 | write_dev_cntr(dd, C_DC_RCV_BBL_VL, idx_from_vl(vl), 0); | |
3027 | ||
3028 | /*if (counter_select & CS_PORT_MARK_FECN) | |
3029 | write_csr(dd, DCC_PRF_PORT_VL_MARK_FECN_CNT + offset, 0); | |
3030 | */ | |
3031 | /* port_vl_xmit_discards ??? */ | |
3032 | } | |
3033 | ||
3034 | if (resp_len) | |
3035 | *resp_len += sizeof(*req); | |
3036 | ||
3037 | return reply((struct ib_mad_hdr *)pmp); | |
3038 | } | |
3039 | ||
3040 | static int pma_set_opa_errorinfo(struct opa_pma_mad *pmp, | |
3041 | struct ib_device *ibdev, u8 port, u32 *resp_len) | |
3042 | { | |
3043 | struct _port_ei *rsp; | |
3044 | struct opa_port_error_info_msg *req; | |
3045 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
3046 | u64 port_mask; | |
3047 | u32 num_ports; | |
3048 | unsigned long port_num; | |
3049 | u8 num_pslm; | |
3050 | u32 error_info_select; | |
3051 | ||
3052 | req = (struct opa_port_error_info_msg *)pmp->data; | |
3053 | rsp = (struct _port_ei *)&(req->port[0]); | |
3054 | ||
3055 | num_ports = OPA_AM_NPORT(be32_to_cpu(pmp->mad_hdr.attr_mod)); | |
3056 | num_pslm = hweight64(be64_to_cpu(req->port_select_mask[3])); | |
3057 | ||
3058 | memset(rsp, 0, sizeof(*rsp)); | |
3059 | ||
3060 | if (num_ports != 1 || num_ports != num_pslm) { | |
3061 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
3062 | return reply((struct ib_mad_hdr *)pmp); | |
3063 | } | |
3064 | ||
3065 | /* | |
3066 | * The bit set in the mask needs to be consistent with the port | |
3067 | * the request came in on. | |
3068 | */ | |
3069 | port_mask = be64_to_cpu(req->port_select_mask[3]); | |
3070 | port_num = find_first_bit((unsigned long *)&port_mask, | |
3071 | sizeof(port_mask)); | |
3072 | ||
3073 | if ((u8)port_num != port) { | |
3074 | pmp->mad_hdr.status |= IB_SMP_INVALID_FIELD; | |
3075 | return reply((struct ib_mad_hdr *)pmp); | |
3076 | } | |
3077 | ||
3078 | error_info_select = be32_to_cpu(req->error_info_select_mask); | |
3079 | ||
3080 | /* PortRcvErrorInfo */ | |
3081 | if (error_info_select & ES_PORT_RCV_ERROR_INFO) | |
3082 | /* turn off status bit */ | |
3083 | dd->err_info_rcvport.status_and_code &= ~OPA_EI_STATUS_SMASK; | |
3084 | ||
3085 | /* ExcessiverBufferOverrunInfo */ | |
3086 | if (error_info_select & ES_EXCESSIVE_BUFFER_OVERRUN_INFO) | |
3087 | /* status bit is essentially kept in the h/w - bit 5 of | |
3088 | * RCV_ERR_INFO */ | |
3089 | write_csr(dd, RCV_ERR_INFO, | |
3090 | RCV_ERR_INFO_RCV_EXCESS_BUFFER_OVERRUN_SMASK); | |
3091 | ||
3092 | if (error_info_select & ES_PORT_XMIT_CONSTRAINT_ERROR_INFO) | |
3093 | dd->err_info_xmit_constraint.status &= ~OPA_EI_STATUS_SMASK; | |
3094 | ||
3095 | if (error_info_select & ES_PORT_RCV_CONSTRAINT_ERROR_INFO) | |
3096 | dd->err_info_rcv_constraint.status &= ~OPA_EI_STATUS_SMASK; | |
3097 | ||
3098 | /* UncorrectableErrorInfo */ | |
3099 | if (error_info_select & ES_UNCORRECTABLE_ERROR_INFO) | |
3100 | /* turn off status bit */ | |
3101 | dd->err_info_uncorrectable &= ~OPA_EI_STATUS_SMASK; | |
3102 | ||
3103 | /* FMConfigErrorInfo */ | |
3104 | if (error_info_select & ES_FM_CONFIG_ERROR_INFO) | |
3105 | /* turn off status bit */ | |
3106 | dd->err_info_fmconfig &= ~OPA_EI_STATUS_SMASK; | |
3107 | ||
3108 | if (resp_len) | |
3109 | *resp_len += sizeof(*req); | |
3110 | ||
3111 | return reply((struct ib_mad_hdr *)pmp); | |
3112 | } | |
3113 | ||
3114 | struct opa_congestion_info_attr { | |
3115 | __be16 congestion_info; | |
3116 | u8 control_table_cap; /* Multiple of 64 entry unit CCTs */ | |
3117 | u8 congestion_log_length; | |
3118 | } __packed; | |
3119 | ||
3120 | static int __subn_get_opa_cong_info(struct opa_smp *smp, u32 am, u8 *data, | |
3121 | struct ib_device *ibdev, u8 port, | |
3122 | u32 *resp_len) | |
3123 | { | |
3124 | struct opa_congestion_info_attr *p = | |
3125 | (struct opa_congestion_info_attr *)data; | |
3126 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
3127 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
3128 | ||
3129 | p->congestion_info = 0; | |
3130 | p->control_table_cap = ppd->cc_max_table_entries; | |
3131 | p->congestion_log_length = OPA_CONG_LOG_ELEMS; | |
3132 | ||
3133 | if (resp_len) | |
3134 | *resp_len += sizeof(*p); | |
3135 | ||
3136 | return reply((struct ib_mad_hdr *)smp); | |
3137 | } | |
3138 | ||
3139 | static int __subn_get_opa_cong_setting(struct opa_smp *smp, u32 am, | |
3140 | u8 *data, | |
3141 | struct ib_device *ibdev, | |
3142 | u8 port, u32 *resp_len) | |
3143 | { | |
3144 | int i; | |
3145 | struct opa_congestion_setting_attr *p = | |
3146 | (struct opa_congestion_setting_attr *) data; | |
3147 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
3148 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
3149 | struct opa_congestion_setting_entry_shadow *entries; | |
3150 | struct cc_state *cc_state; | |
3151 | ||
3152 | rcu_read_lock(); | |
3153 | ||
3154 | cc_state = get_cc_state(ppd); | |
3155 | ||
3156 | if (cc_state == NULL) { | |
3157 | rcu_read_unlock(); | |
3158 | return reply((struct ib_mad_hdr *)smp); | |
3159 | } | |
3160 | ||
3161 | entries = cc_state->cong_setting.entries; | |
3162 | p->port_control = cpu_to_be16(cc_state->cong_setting.port_control); | |
3163 | p->control_map = cpu_to_be32(cc_state->cong_setting.control_map); | |
3164 | for (i = 0; i < OPA_MAX_SLS; i++) { | |
3165 | p->entries[i].ccti_increase = entries[i].ccti_increase; | |
3166 | p->entries[i].ccti_timer = cpu_to_be16(entries[i].ccti_timer); | |
3167 | p->entries[i].trigger_threshold = | |
3168 | entries[i].trigger_threshold; | |
3169 | p->entries[i].ccti_min = entries[i].ccti_min; | |
3170 | } | |
3171 | ||
3172 | rcu_read_unlock(); | |
3173 | ||
3174 | if (resp_len) | |
3175 | *resp_len += sizeof(*p); | |
3176 | ||
3177 | return reply((struct ib_mad_hdr *)smp); | |
3178 | } | |
3179 | ||
3180 | static int __subn_set_opa_cong_setting(struct opa_smp *smp, u32 am, u8 *data, | |
3181 | struct ib_device *ibdev, u8 port, | |
3182 | u32 *resp_len) | |
3183 | { | |
3184 | struct opa_congestion_setting_attr *p = | |
3185 | (struct opa_congestion_setting_attr *) data; | |
3186 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
3187 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
3188 | struct opa_congestion_setting_entry_shadow *entries; | |
3189 | int i; | |
3190 | ||
3191 | ppd->cc_sl_control_map = be32_to_cpu(p->control_map); | |
3192 | ||
3193 | entries = ppd->congestion_entries; | |
3194 | for (i = 0; i < OPA_MAX_SLS; i++) { | |
3195 | entries[i].ccti_increase = p->entries[i].ccti_increase; | |
3196 | entries[i].ccti_timer = be16_to_cpu(p->entries[i].ccti_timer); | |
3197 | entries[i].trigger_threshold = | |
3198 | p->entries[i].trigger_threshold; | |
3199 | entries[i].ccti_min = p->entries[i].ccti_min; | |
3200 | } | |
3201 | ||
3202 | return __subn_get_opa_cong_setting(smp, am, data, ibdev, port, | |
3203 | resp_len); | |
3204 | } | |
3205 | ||
3206 | static int __subn_get_opa_hfi1_cong_log(struct opa_smp *smp, u32 am, | |
3207 | u8 *data, struct ib_device *ibdev, | |
3208 | u8 port, u32 *resp_len) | |
3209 | { | |
3210 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
3211 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
3212 | struct opa_hfi1_cong_log *cong_log = (struct opa_hfi1_cong_log *)data; | |
3213 | s64 ts; | |
3214 | int i; | |
3215 | ||
3216 | if (am != 0) { | |
3217 | smp->status |= IB_SMP_INVALID_FIELD; | |
3218 | return reply((struct ib_mad_hdr *)smp); | |
3219 | } | |
3220 | ||
b77d713a | 3221 | spin_lock_irq(&ppd->cc_log_lock); |
77241056 MM |
3222 | |
3223 | cong_log->log_type = OPA_CC_LOG_TYPE_HFI; | |
3224 | cong_log->congestion_flags = 0; | |
3225 | cong_log->threshold_event_counter = | |
3226 | cpu_to_be16(ppd->threshold_event_counter); | |
3227 | memcpy(cong_log->threshold_cong_event_map, | |
3228 | ppd->threshold_cong_event_map, | |
3229 | sizeof(cong_log->threshold_cong_event_map)); | |
3230 | /* keep timestamp in units of 1.024 usec */ | |
3231 | ts = ktime_to_ns(ktime_get()) / 1024; | |
3232 | cong_log->current_time_stamp = cpu_to_be32(ts); | |
3233 | for (i = 0; i < OPA_CONG_LOG_ELEMS; i++) { | |
3234 | struct opa_hfi1_cong_log_event_internal *cce = | |
3235 | &ppd->cc_events[ppd->cc_mad_idx++]; | |
3236 | if (ppd->cc_mad_idx == OPA_CONG_LOG_ELEMS) | |
3237 | ppd->cc_mad_idx = 0; | |
3238 | /* | |
3239 | * Entries which are older than twice the time | |
3240 | * required to wrap the counter are supposed to | |
3241 | * be zeroed (CA10-49 IBTA, release 1.2.1, V1). | |
3242 | */ | |
3243 | if ((u64)(ts - cce->timestamp) > (2 * UINT_MAX)) | |
3244 | continue; | |
3245 | memcpy(cong_log->events[i].local_qp_cn_entry, &cce->lqpn, 3); | |
3246 | memcpy(cong_log->events[i].remote_qp_number_cn_entry, | |
3247 | &cce->rqpn, 3); | |
3248 | cong_log->events[i].sl_svc_type_cn_entry = | |
3249 | ((cce->sl & 0x1f) << 3) | (cce->svc_type & 0x7); | |
3250 | cong_log->events[i].remote_lid_cn_entry = | |
3251 | cpu_to_be32(cce->rlid); | |
3252 | cong_log->events[i].timestamp_cn_entry = | |
3253 | cpu_to_be32(cce->timestamp); | |
3254 | } | |
3255 | ||
3256 | /* | |
3257 | * Reset threshold_cong_event_map, and threshold_event_counter | |
3258 | * to 0 when log is read. | |
3259 | */ | |
3260 | memset(ppd->threshold_cong_event_map, 0x0, | |
3261 | sizeof(ppd->threshold_cong_event_map)); | |
3262 | ppd->threshold_event_counter = 0; | |
3263 | ||
b77d713a | 3264 | spin_unlock_irq(&ppd->cc_log_lock); |
77241056 MM |
3265 | |
3266 | if (resp_len) | |
3267 | *resp_len += sizeof(struct opa_hfi1_cong_log); | |
3268 | ||
3269 | return reply((struct ib_mad_hdr *)smp); | |
3270 | } | |
3271 | ||
3272 | static int __subn_get_opa_cc_table(struct opa_smp *smp, u32 am, u8 *data, | |
3273 | struct ib_device *ibdev, u8 port, | |
3274 | u32 *resp_len) | |
3275 | { | |
3276 | struct ib_cc_table_attr *cc_table_attr = | |
3277 | (struct ib_cc_table_attr *) data; | |
3278 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
3279 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
3280 | u32 start_block = OPA_AM_START_BLK(am); | |
3281 | u32 n_blocks = OPA_AM_NBLK(am); | |
3282 | struct ib_cc_table_entry_shadow *entries; | |
3283 | int i, j; | |
3284 | u32 sentry, eentry; | |
3285 | struct cc_state *cc_state; | |
3286 | ||
3287 | /* sanity check n_blocks, start_block */ | |
3288 | if (n_blocks == 0 || | |
3289 | start_block + n_blocks > ppd->cc_max_table_entries) { | |
3290 | smp->status |= IB_SMP_INVALID_FIELD; | |
3291 | return reply((struct ib_mad_hdr *)smp); | |
3292 | } | |
3293 | ||
3294 | rcu_read_lock(); | |
3295 | ||
3296 | cc_state = get_cc_state(ppd); | |
3297 | ||
3298 | if (cc_state == NULL) { | |
3299 | rcu_read_unlock(); | |
3300 | return reply((struct ib_mad_hdr *)smp); | |
3301 | } | |
3302 | ||
3303 | sentry = start_block * IB_CCT_ENTRIES; | |
3304 | eentry = sentry + (IB_CCT_ENTRIES * n_blocks); | |
3305 | ||
3306 | cc_table_attr->ccti_limit = cpu_to_be16(cc_state->cct.ccti_limit); | |
3307 | ||
3308 | entries = cc_state->cct.entries; | |
3309 | ||
3310 | /* return n_blocks, though the last block may not be full */ | |
3311 | for (j = 0, i = sentry; i < eentry; j++, i++) | |
3312 | cc_table_attr->ccti_entries[j].entry = | |
3313 | cpu_to_be16(entries[i].entry); | |
3314 | ||
3315 | rcu_read_unlock(); | |
3316 | ||
3317 | if (resp_len) | |
3318 | *resp_len += sizeof(u16)*(IB_CCT_ENTRIES * n_blocks + 1); | |
3319 | ||
3320 | return reply((struct ib_mad_hdr *)smp); | |
3321 | } | |
3322 | ||
3323 | void cc_state_reclaim(struct rcu_head *rcu) | |
3324 | { | |
3325 | struct cc_state *cc_state = container_of(rcu, struct cc_state, rcu); | |
3326 | ||
3327 | kfree(cc_state); | |
3328 | } | |
3329 | ||
3330 | static int __subn_set_opa_cc_table(struct opa_smp *smp, u32 am, u8 *data, | |
3331 | struct ib_device *ibdev, u8 port, | |
3332 | u32 *resp_len) | |
3333 | { | |
3334 | struct ib_cc_table_attr *p = (struct ib_cc_table_attr *) data; | |
3335 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
3336 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
3337 | u32 start_block = OPA_AM_START_BLK(am); | |
3338 | u32 n_blocks = OPA_AM_NBLK(am); | |
3339 | struct ib_cc_table_entry_shadow *entries; | |
3340 | int i, j; | |
3341 | u32 sentry, eentry; | |
3342 | u16 ccti_limit; | |
3343 | struct cc_state *old_cc_state, *new_cc_state; | |
3344 | ||
3345 | /* sanity check n_blocks, start_block */ | |
3346 | if (n_blocks == 0 || | |
3347 | start_block + n_blocks > ppd->cc_max_table_entries) { | |
3348 | smp->status |= IB_SMP_INVALID_FIELD; | |
3349 | return reply((struct ib_mad_hdr *)smp); | |
3350 | } | |
3351 | ||
3352 | sentry = start_block * IB_CCT_ENTRIES; | |
3353 | eentry = sentry + ((n_blocks - 1) * IB_CCT_ENTRIES) + | |
3354 | (be16_to_cpu(p->ccti_limit)) % IB_CCT_ENTRIES + 1; | |
3355 | ||
3356 | /* sanity check ccti_limit */ | |
3357 | ccti_limit = be16_to_cpu(p->ccti_limit); | |
3358 | if (ccti_limit + 1 > eentry) { | |
3359 | smp->status |= IB_SMP_INVALID_FIELD; | |
3360 | return reply((struct ib_mad_hdr *)smp); | |
3361 | } | |
3362 | ||
3363 | new_cc_state = kzalloc(sizeof(*new_cc_state), GFP_KERNEL); | |
3364 | if (new_cc_state == NULL) | |
3365 | goto getit; | |
3366 | ||
3367 | spin_lock(&ppd->cc_state_lock); | |
3368 | ||
3369 | old_cc_state = get_cc_state(ppd); | |
3370 | ||
3371 | if (old_cc_state == NULL) { | |
3372 | spin_unlock(&ppd->cc_state_lock); | |
3373 | kfree(new_cc_state); | |
3374 | return reply((struct ib_mad_hdr *)smp); | |
3375 | } | |
3376 | ||
3377 | *new_cc_state = *old_cc_state; | |
3378 | ||
3379 | new_cc_state->cct.ccti_limit = ccti_limit; | |
3380 | ||
3381 | entries = ppd->ccti_entries; | |
3382 | ppd->total_cct_entry = ccti_limit + 1; | |
3383 | ||
3384 | for (j = 0, i = sentry; i < eentry; j++, i++) | |
3385 | entries[i].entry = be16_to_cpu(p->ccti_entries[j].entry); | |
3386 | ||
3387 | memcpy(new_cc_state->cct.entries, entries, | |
3388 | eentry * sizeof(struct ib_cc_table_entry)); | |
3389 | ||
3390 | new_cc_state->cong_setting.port_control = IB_CC_CCS_PC_SL_BASED; | |
3391 | new_cc_state->cong_setting.control_map = ppd->cc_sl_control_map; | |
3392 | memcpy(new_cc_state->cong_setting.entries, ppd->congestion_entries, | |
3393 | OPA_MAX_SLS * sizeof(struct opa_congestion_setting_entry)); | |
3394 | ||
3395 | rcu_assign_pointer(ppd->cc_state, new_cc_state); | |
3396 | ||
3397 | spin_unlock(&ppd->cc_state_lock); | |
3398 | ||
3399 | call_rcu(&old_cc_state->rcu, cc_state_reclaim); | |
3400 | ||
3401 | getit: | |
3402 | return __subn_get_opa_cc_table(smp, am, data, ibdev, port, resp_len); | |
3403 | } | |
3404 | ||
3405 | struct opa_led_info { | |
3406 | __be32 rsvd_led_mask; | |
3407 | __be32 rsvd; | |
3408 | }; | |
3409 | ||
3410 | #define OPA_LED_SHIFT 31 | |
349ac71f | 3411 | #define OPA_LED_MASK BIT(OPA_LED_SHIFT) |
77241056 MM |
3412 | |
3413 | static int __subn_get_opa_led_info(struct opa_smp *smp, u32 am, u8 *data, | |
3414 | struct ib_device *ibdev, u8 port, | |
3415 | u32 *resp_len) | |
3416 | { | |
3417 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
3418 | struct opa_led_info *p = (struct opa_led_info *) data; | |
3419 | u32 nport = OPA_AM_NPORT(am); | |
3420 | u64 reg; | |
3421 | ||
801cfd6d | 3422 | if (nport != 1) { |
77241056 MM |
3423 | smp->status |= IB_SMP_INVALID_FIELD; |
3424 | return reply((struct ib_mad_hdr *)smp); | |
3425 | } | |
3426 | ||
3427 | reg = read_csr(dd, DCC_CFG_LED_CNTRL); | |
3428 | if ((reg & DCC_CFG_LED_CNTRL_LED_CNTRL_SMASK) && | |
3429 | ((reg & DCC_CFG_LED_CNTRL_LED_SW_BLINK_RATE_SMASK) == 0xf)) | |
3430 | p->rsvd_led_mask = cpu_to_be32(OPA_LED_MASK); | |
3431 | ||
3432 | if (resp_len) | |
3433 | *resp_len += sizeof(struct opa_led_info); | |
3434 | ||
3435 | return reply((struct ib_mad_hdr *)smp); | |
3436 | } | |
3437 | ||
3438 | static int __subn_set_opa_led_info(struct opa_smp *smp, u32 am, u8 *data, | |
3439 | struct ib_device *ibdev, u8 port, | |
3440 | u32 *resp_len) | |
3441 | { | |
3442 | struct hfi1_devdata *dd = dd_from_ibdev(ibdev); | |
3443 | struct opa_led_info *p = (struct opa_led_info *) data; | |
3444 | u32 nport = OPA_AM_NPORT(am); | |
3445 | int on = !!(be32_to_cpu(p->rsvd_led_mask) & OPA_LED_MASK); | |
3446 | ||
801cfd6d | 3447 | if (nport != 1) { |
77241056 MM |
3448 | smp->status |= IB_SMP_INVALID_FIELD; |
3449 | return reply((struct ib_mad_hdr *)smp); | |
3450 | } | |
3451 | ||
91ab4ed3 EH |
3452 | if (on) |
3453 | hfi1_set_led_override(dd->pport, 2000, 1500); | |
3454 | else | |
3455 | hfi1_set_led_override(dd->pport, 0, 0); | |
77241056 MM |
3456 | |
3457 | return __subn_get_opa_led_info(smp, am, data, ibdev, port, resp_len); | |
3458 | } | |
3459 | ||
3460 | static int subn_get_opa_sma(__be16 attr_id, struct opa_smp *smp, u32 am, | |
3461 | u8 *data, struct ib_device *ibdev, u8 port, | |
3462 | u32 *resp_len) | |
3463 | { | |
3464 | int ret; | |
3465 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
3466 | ||
3467 | switch (attr_id) { | |
3468 | case IB_SMP_ATTR_NODE_DESC: | |
3469 | ret = __subn_get_opa_nodedesc(smp, am, data, ibdev, port, | |
3470 | resp_len); | |
3471 | break; | |
3472 | case IB_SMP_ATTR_NODE_INFO: | |
3473 | ret = __subn_get_opa_nodeinfo(smp, am, data, ibdev, port, | |
3474 | resp_len); | |
3475 | break; | |
3476 | case IB_SMP_ATTR_PORT_INFO: | |
3477 | ret = __subn_get_opa_portinfo(smp, am, data, ibdev, port, | |
3478 | resp_len); | |
3479 | break; | |
3480 | case IB_SMP_ATTR_PKEY_TABLE: | |
3481 | ret = __subn_get_opa_pkeytable(smp, am, data, ibdev, port, | |
3482 | resp_len); | |
3483 | break; | |
3484 | case OPA_ATTRIB_ID_SL_TO_SC_MAP: | |
3485 | ret = __subn_get_opa_sl_to_sc(smp, am, data, ibdev, port, | |
3486 | resp_len); | |
3487 | break; | |
3488 | case OPA_ATTRIB_ID_SC_TO_SL_MAP: | |
3489 | ret = __subn_get_opa_sc_to_sl(smp, am, data, ibdev, port, | |
3490 | resp_len); | |
3491 | break; | |
3492 | case OPA_ATTRIB_ID_SC_TO_VLT_MAP: | |
3493 | ret = __subn_get_opa_sc_to_vlt(smp, am, data, ibdev, port, | |
3494 | resp_len); | |
3495 | break; | |
3496 | case OPA_ATTRIB_ID_SC_TO_VLNT_MAP: | |
3497 | ret = __subn_get_opa_sc_to_vlnt(smp, am, data, ibdev, port, | |
3498 | resp_len); | |
3499 | break; | |
3500 | case OPA_ATTRIB_ID_PORT_STATE_INFO: | |
3501 | ret = __subn_get_opa_psi(smp, am, data, ibdev, port, | |
3502 | resp_len); | |
3503 | break; | |
3504 | case OPA_ATTRIB_ID_BUFFER_CONTROL_TABLE: | |
3505 | ret = __subn_get_opa_bct(smp, am, data, ibdev, port, | |
3506 | resp_len); | |
3507 | break; | |
3508 | case OPA_ATTRIB_ID_CABLE_INFO: | |
3509 | ret = __subn_get_opa_cable_info(smp, am, data, ibdev, port, | |
3510 | resp_len); | |
3511 | break; | |
3512 | case IB_SMP_ATTR_VL_ARB_TABLE: | |
3513 | ret = __subn_get_opa_vl_arb(smp, am, data, ibdev, port, | |
3514 | resp_len); | |
3515 | break; | |
3516 | case OPA_ATTRIB_ID_CONGESTION_INFO: | |
3517 | ret = __subn_get_opa_cong_info(smp, am, data, ibdev, port, | |
3518 | resp_len); | |
3519 | break; | |
3520 | case OPA_ATTRIB_ID_HFI_CONGESTION_SETTING: | |
3521 | ret = __subn_get_opa_cong_setting(smp, am, data, ibdev, | |
3522 | port, resp_len); | |
3523 | break; | |
3524 | case OPA_ATTRIB_ID_HFI_CONGESTION_LOG: | |
3525 | ret = __subn_get_opa_hfi1_cong_log(smp, am, data, ibdev, | |
3526 | port, resp_len); | |
3527 | break; | |
3528 | case OPA_ATTRIB_ID_CONGESTION_CONTROL_TABLE: | |
3529 | ret = __subn_get_opa_cc_table(smp, am, data, ibdev, port, | |
3530 | resp_len); | |
3531 | break; | |
3532 | case IB_SMP_ATTR_LED_INFO: | |
3533 | ret = __subn_get_opa_led_info(smp, am, data, ibdev, port, | |
3534 | resp_len); | |
3535 | break; | |
3536 | case IB_SMP_ATTR_SM_INFO: | |
4eb06882 | 3537 | if (ibp->rvp.port_cap_flags & IB_PORT_SM_DISABLED) |
77241056 | 3538 | return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED; |
4eb06882 | 3539 | if (ibp->rvp.port_cap_flags & IB_PORT_SM) |
77241056 MM |
3540 | return IB_MAD_RESULT_SUCCESS; |
3541 | /* FALLTHROUGH */ | |
3542 | default: | |
3543 | smp->status |= IB_SMP_UNSUP_METH_ATTR; | |
3544 | ret = reply((struct ib_mad_hdr *)smp); | |
3545 | break; | |
3546 | } | |
3547 | return ret; | |
3548 | } | |
3549 | ||
3550 | static int subn_set_opa_sma(__be16 attr_id, struct opa_smp *smp, u32 am, | |
3551 | u8 *data, struct ib_device *ibdev, u8 port, | |
3552 | u32 *resp_len) | |
3553 | { | |
3554 | int ret; | |
3555 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
3556 | ||
3557 | switch (attr_id) { | |
3558 | case IB_SMP_ATTR_PORT_INFO: | |
3559 | ret = __subn_set_opa_portinfo(smp, am, data, ibdev, port, | |
3560 | resp_len); | |
3561 | break; | |
3562 | case IB_SMP_ATTR_PKEY_TABLE: | |
3563 | ret = __subn_set_opa_pkeytable(smp, am, data, ibdev, port, | |
3564 | resp_len); | |
3565 | break; | |
3566 | case OPA_ATTRIB_ID_SL_TO_SC_MAP: | |
3567 | ret = __subn_set_opa_sl_to_sc(smp, am, data, ibdev, port, | |
3568 | resp_len); | |
3569 | break; | |
3570 | case OPA_ATTRIB_ID_SC_TO_SL_MAP: | |
3571 | ret = __subn_set_opa_sc_to_sl(smp, am, data, ibdev, port, | |
3572 | resp_len); | |
3573 | break; | |
3574 | case OPA_ATTRIB_ID_SC_TO_VLT_MAP: | |
3575 | ret = __subn_set_opa_sc_to_vlt(smp, am, data, ibdev, port, | |
3576 | resp_len); | |
3577 | break; | |
3578 | case OPA_ATTRIB_ID_SC_TO_VLNT_MAP: | |
3579 | ret = __subn_set_opa_sc_to_vlnt(smp, am, data, ibdev, port, | |
3580 | resp_len); | |
3581 | break; | |
3582 | case OPA_ATTRIB_ID_PORT_STATE_INFO: | |
3583 | ret = __subn_set_opa_psi(smp, am, data, ibdev, port, | |
3584 | resp_len); | |
3585 | break; | |
3586 | case OPA_ATTRIB_ID_BUFFER_CONTROL_TABLE: | |
3587 | ret = __subn_set_opa_bct(smp, am, data, ibdev, port, | |
3588 | resp_len); | |
3589 | break; | |
3590 | case IB_SMP_ATTR_VL_ARB_TABLE: | |
3591 | ret = __subn_set_opa_vl_arb(smp, am, data, ibdev, port, | |
3592 | resp_len); | |
3593 | break; | |
3594 | case OPA_ATTRIB_ID_HFI_CONGESTION_SETTING: | |
3595 | ret = __subn_set_opa_cong_setting(smp, am, data, ibdev, | |
3596 | port, resp_len); | |
3597 | break; | |
3598 | case OPA_ATTRIB_ID_CONGESTION_CONTROL_TABLE: | |
3599 | ret = __subn_set_opa_cc_table(smp, am, data, ibdev, port, | |
3600 | resp_len); | |
3601 | break; | |
3602 | case IB_SMP_ATTR_LED_INFO: | |
3603 | ret = __subn_set_opa_led_info(smp, am, data, ibdev, port, | |
3604 | resp_len); | |
3605 | break; | |
3606 | case IB_SMP_ATTR_SM_INFO: | |
4eb06882 | 3607 | if (ibp->rvp.port_cap_flags & IB_PORT_SM_DISABLED) |
77241056 | 3608 | return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED; |
4eb06882 | 3609 | if (ibp->rvp.port_cap_flags & IB_PORT_SM) |
77241056 MM |
3610 | return IB_MAD_RESULT_SUCCESS; |
3611 | /* FALLTHROUGH */ | |
3612 | default: | |
3613 | smp->status |= IB_SMP_UNSUP_METH_ATTR; | |
3614 | ret = reply((struct ib_mad_hdr *)smp); | |
3615 | break; | |
3616 | } | |
3617 | return ret; | |
3618 | } | |
3619 | ||
3620 | static inline void set_aggr_error(struct opa_aggregate *ag) | |
3621 | { | |
3622 | ag->err_reqlength |= cpu_to_be16(0x8000); | |
3623 | } | |
3624 | ||
3625 | static int subn_get_opa_aggregate(struct opa_smp *smp, | |
3626 | struct ib_device *ibdev, u8 port, | |
3627 | u32 *resp_len) | |
3628 | { | |
3629 | int i; | |
3630 | u32 num_attr = be32_to_cpu(smp->attr_mod) & 0x000000ff; | |
3631 | u8 *next_smp = opa_get_smp_data(smp); | |
3632 | ||
3633 | if (num_attr < 1 || num_attr > 117) { | |
3634 | smp->status |= IB_SMP_INVALID_FIELD; | |
3635 | return reply((struct ib_mad_hdr *)smp); | |
3636 | } | |
3637 | ||
3638 | for (i = 0; i < num_attr; i++) { | |
3639 | struct opa_aggregate *agg; | |
3640 | size_t agg_data_len; | |
3641 | size_t agg_size; | |
3642 | u32 am; | |
3643 | ||
3644 | agg = (struct opa_aggregate *)next_smp; | |
3645 | agg_data_len = (be16_to_cpu(agg->err_reqlength) & 0x007f) * 8; | |
3646 | agg_size = sizeof(*agg) + agg_data_len; | |
3647 | am = be32_to_cpu(agg->attr_mod); | |
3648 | ||
3649 | *resp_len += agg_size; | |
3650 | ||
3651 | if (next_smp + agg_size > ((u8 *)smp) + sizeof(*smp)) { | |
3652 | smp->status |= IB_SMP_INVALID_FIELD; | |
3653 | return reply((struct ib_mad_hdr *)smp); | |
3654 | } | |
3655 | ||
3656 | /* zero the payload for this segment */ | |
3657 | memset(next_smp + sizeof(*agg), 0, agg_data_len); | |
3658 | ||
3659 | (void) subn_get_opa_sma(agg->attr_id, smp, am, agg->data, | |
3660 | ibdev, port, NULL); | |
3661 | if (smp->status & ~IB_SMP_DIRECTION) { | |
3662 | set_aggr_error(agg); | |
3663 | return reply((struct ib_mad_hdr *)smp); | |
3664 | } | |
3665 | next_smp += agg_size; | |
3666 | ||
3667 | } | |
3668 | ||
3669 | return reply((struct ib_mad_hdr *)smp); | |
3670 | } | |
3671 | ||
3672 | static int subn_set_opa_aggregate(struct opa_smp *smp, | |
3673 | struct ib_device *ibdev, u8 port, | |
3674 | u32 *resp_len) | |
3675 | { | |
3676 | int i; | |
3677 | u32 num_attr = be32_to_cpu(smp->attr_mod) & 0x000000ff; | |
3678 | u8 *next_smp = opa_get_smp_data(smp); | |
3679 | ||
3680 | if (num_attr < 1 || num_attr > 117) { | |
3681 | smp->status |= IB_SMP_INVALID_FIELD; | |
3682 | return reply((struct ib_mad_hdr *)smp); | |
3683 | } | |
3684 | ||
3685 | for (i = 0; i < num_attr; i++) { | |
3686 | struct opa_aggregate *agg; | |
3687 | size_t agg_data_len; | |
3688 | size_t agg_size; | |
3689 | u32 am; | |
3690 | ||
3691 | agg = (struct opa_aggregate *)next_smp; | |
3692 | agg_data_len = (be16_to_cpu(agg->err_reqlength) & 0x007f) * 8; | |
3693 | agg_size = sizeof(*agg) + agg_data_len; | |
3694 | am = be32_to_cpu(agg->attr_mod); | |
3695 | ||
3696 | *resp_len += agg_size; | |
3697 | ||
3698 | if (next_smp + agg_size > ((u8 *)smp) + sizeof(*smp)) { | |
3699 | smp->status |= IB_SMP_INVALID_FIELD; | |
3700 | return reply((struct ib_mad_hdr *)smp); | |
3701 | } | |
3702 | ||
3703 | (void) subn_set_opa_sma(agg->attr_id, smp, am, agg->data, | |
3704 | ibdev, port, NULL); | |
3705 | if (smp->status & ~IB_SMP_DIRECTION) { | |
3706 | set_aggr_error(agg); | |
3707 | return reply((struct ib_mad_hdr *)smp); | |
3708 | } | |
3709 | next_smp += agg_size; | |
3710 | ||
3711 | } | |
3712 | ||
3713 | return reply((struct ib_mad_hdr *)smp); | |
3714 | } | |
3715 | ||
3716 | /* | |
3717 | * OPAv1 specifies that, on the transition to link up, these counters | |
3718 | * are cleared: | |
3719 | * PortRcvErrors [*] | |
3720 | * LinkErrorRecovery | |
3721 | * LocalLinkIntegrityErrors | |
3722 | * ExcessiveBufferOverruns [*] | |
3723 | * | |
3724 | * [*] Error info associated with these counters is retained, but the | |
3725 | * error info status is reset to 0. | |
3726 | */ | |
3727 | void clear_linkup_counters(struct hfi1_devdata *dd) | |
3728 | { | |
3729 | /* PortRcvErrors */ | |
3730 | write_dev_cntr(dd, C_DC_RCV_ERR, CNTR_INVALID_VL, 0); | |
3731 | dd->err_info_rcvport.status_and_code &= ~OPA_EI_STATUS_SMASK; | |
3732 | /* LinkErrorRecovery */ | |
3733 | write_dev_cntr(dd, C_DC_SEQ_CRC_CNT, CNTR_INVALID_VL, 0); | |
3734 | write_dev_cntr(dd, C_DC_REINIT_FROM_PEER_CNT, CNTR_INVALID_VL, 0); | |
3735 | /* LocalLinkIntegrityErrors */ | |
3736 | write_dev_cntr(dd, C_DC_TX_REPLAY, CNTR_INVALID_VL, 0); | |
3737 | write_dev_cntr(dd, C_DC_RX_REPLAY, CNTR_INVALID_VL, 0); | |
3738 | /* ExcessiveBufferOverruns */ | |
3739 | write_dev_cntr(dd, C_RCV_OVF, CNTR_INVALID_VL, 0); | |
3740 | dd->rcv_ovfl_cnt = 0; | |
3741 | dd->err_info_xmit_constraint.status &= ~OPA_EI_STATUS_SMASK; | |
3742 | } | |
3743 | ||
3744 | /* | |
3745 | * is_local_mad() returns 1 if 'mad' is sent from, and destined to the | |
3746 | * local node, 0 otherwise. | |
3747 | */ | |
3748 | static int is_local_mad(struct hfi1_ibport *ibp, const struct opa_mad *mad, | |
3749 | const struct ib_wc *in_wc) | |
3750 | { | |
3751 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
3752 | const struct opa_smp *smp = (const struct opa_smp *)mad; | |
3753 | ||
3754 | if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) { | |
3755 | return (smp->hop_cnt == 0 && | |
3756 | smp->route.dr.dr_slid == OPA_LID_PERMISSIVE && | |
3757 | smp->route.dr.dr_dlid == OPA_LID_PERMISSIVE); | |
3758 | } | |
3759 | ||
3760 | return (in_wc->slid == ppd->lid); | |
3761 | } | |
3762 | ||
3763 | /* | |
3764 | * opa_local_smp_check() should only be called on MADs for which | |
3765 | * is_local_mad() returns true. It applies the SMP checks that are | |
3766 | * specific to SMPs which are sent from, and destined to this node. | |
3767 | * opa_local_smp_check() returns 0 if the SMP passes its checks, 1 | |
3768 | * otherwise. | |
3769 | * | |
3770 | * SMPs which arrive from other nodes are instead checked by | |
3771 | * opa_smp_check(). | |
3772 | */ | |
3773 | static int opa_local_smp_check(struct hfi1_ibport *ibp, | |
3774 | const struct ib_wc *in_wc) | |
3775 | { | |
3776 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); | |
3777 | u16 slid = in_wc->slid; | |
3778 | u16 pkey; | |
3779 | ||
3780 | if (in_wc->pkey_index >= ARRAY_SIZE(ppd->pkeys)) | |
3781 | return 1; | |
3782 | ||
3783 | pkey = ppd->pkeys[in_wc->pkey_index]; | |
3784 | /* | |
3785 | * We need to do the "node-local" checks specified in OPAv1, | |
3786 | * rev 0.90, section 9.10.26, which are: | |
3787 | * - pkey is 0x7fff, or 0xffff | |
3788 | * - Source QPN == 0 || Destination QPN == 0 | |
3789 | * - the MAD header's management class is either | |
3790 | * IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE or | |
3791 | * IB_MGMT_CLASS_SUBN_LID_ROUTED | |
3792 | * - SLID != 0 | |
3793 | * | |
3794 | * However, we know (and so don't need to check again) that, | |
3795 | * for local SMPs, the MAD stack passes MADs with: | |
3796 | * - Source QPN of 0 | |
3797 | * - MAD mgmt_class is IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE | |
3798 | * - SLID is either: OPA_LID_PERMISSIVE (0xFFFFFFFF), or | |
3799 | * our own port's lid | |
3800 | * | |
3801 | */ | |
3802 | if (pkey == LIM_MGMT_P_KEY || pkey == FULL_MGMT_P_KEY) | |
3803 | return 0; | |
3804 | ingress_pkey_table_fail(ppd, pkey, slid); | |
3805 | return 1; | |
3806 | } | |
3807 | ||
3808 | static int process_subn_opa(struct ib_device *ibdev, int mad_flags, | |
3809 | u8 port, const struct opa_mad *in_mad, | |
3810 | struct opa_mad *out_mad, | |
3811 | u32 *resp_len) | |
3812 | { | |
3813 | struct opa_smp *smp = (struct opa_smp *)out_mad; | |
3814 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
3815 | u8 *data; | |
3816 | u32 am; | |
3817 | __be16 attr_id; | |
3818 | int ret; | |
3819 | ||
3820 | *out_mad = *in_mad; | |
3821 | data = opa_get_smp_data(smp); | |
3822 | ||
3823 | am = be32_to_cpu(smp->attr_mod); | |
3824 | attr_id = smp->attr_id; | |
3825 | if (smp->class_version != OPA_SMI_CLASS_VERSION) { | |
3826 | smp->status |= IB_SMP_UNSUP_VERSION; | |
3827 | ret = reply((struct ib_mad_hdr *)smp); | |
3828 | goto bail; | |
3829 | } | |
3830 | ret = check_mkey(ibp, (struct ib_mad_hdr *)smp, mad_flags, smp->mkey, | |
3831 | smp->route.dr.dr_slid, smp->route.dr.return_path, | |
3832 | smp->hop_cnt); | |
3833 | if (ret) { | |
3834 | u32 port_num = be32_to_cpu(smp->attr_mod); | |
3835 | ||
3836 | /* | |
3837 | * If this is a get/set portinfo, we already check the | |
3838 | * M_Key if the MAD is for another port and the M_Key | |
3839 | * is OK on the receiving port. This check is needed | |
3840 | * to increment the error counters when the M_Key | |
3841 | * fails to match on *both* ports. | |
3842 | */ | |
3843 | if (attr_id == IB_SMP_ATTR_PORT_INFO && | |
3844 | (smp->method == IB_MGMT_METHOD_GET || | |
3845 | smp->method == IB_MGMT_METHOD_SET) && | |
3846 | port_num && port_num <= ibdev->phys_port_cnt && | |
3847 | port != port_num) | |
3848 | (void) check_mkey(to_iport(ibdev, port_num), | |
3849 | (struct ib_mad_hdr *)smp, 0, | |
3850 | smp->mkey, smp->route.dr.dr_slid, | |
3851 | smp->route.dr.return_path, | |
3852 | smp->hop_cnt); | |
3853 | ret = IB_MAD_RESULT_FAILURE; | |
3854 | goto bail; | |
3855 | } | |
3856 | ||
3857 | *resp_len = opa_get_smp_header_size(smp); | |
3858 | ||
3859 | switch (smp->method) { | |
3860 | case IB_MGMT_METHOD_GET: | |
3861 | switch (attr_id) { | |
3862 | default: | |
3863 | clear_opa_smp_data(smp); | |
3864 | ret = subn_get_opa_sma(attr_id, smp, am, data, | |
3865 | ibdev, port, resp_len); | |
3866 | goto bail; | |
3867 | case OPA_ATTRIB_ID_AGGREGATE: | |
3868 | ret = subn_get_opa_aggregate(smp, ibdev, port, | |
3869 | resp_len); | |
3870 | goto bail; | |
3871 | } | |
3872 | case IB_MGMT_METHOD_SET: | |
3873 | switch (attr_id) { | |
3874 | default: | |
3875 | ret = subn_set_opa_sma(attr_id, smp, am, data, | |
3876 | ibdev, port, resp_len); | |
3877 | goto bail; | |
3878 | case OPA_ATTRIB_ID_AGGREGATE: | |
3879 | ret = subn_set_opa_aggregate(smp, ibdev, port, | |
3880 | resp_len); | |
3881 | goto bail; | |
3882 | } | |
3883 | case IB_MGMT_METHOD_TRAP: | |
3884 | case IB_MGMT_METHOD_REPORT: | |
3885 | case IB_MGMT_METHOD_REPORT_RESP: | |
3886 | case IB_MGMT_METHOD_GET_RESP: | |
3887 | /* | |
3888 | * The ib_mad module will call us to process responses | |
3889 | * before checking for other consumers. | |
3890 | * Just tell the caller to process it normally. | |
3891 | */ | |
3892 | ret = IB_MAD_RESULT_SUCCESS; | |
3893 | goto bail; | |
3894 | default: | |
3895 | smp->status |= IB_SMP_UNSUP_METHOD; | |
3896 | ret = reply((struct ib_mad_hdr *)smp); | |
3897 | } | |
3898 | ||
3899 | bail: | |
3900 | return ret; | |
3901 | } | |
3902 | ||
3903 | static int process_subn(struct ib_device *ibdev, int mad_flags, | |
3904 | u8 port, const struct ib_mad *in_mad, | |
3905 | struct ib_mad *out_mad) | |
3906 | { | |
3907 | struct ib_smp *smp = (struct ib_smp *)out_mad; | |
3908 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
3909 | int ret; | |
3910 | ||
3911 | *out_mad = *in_mad; | |
3912 | if (smp->class_version != 1) { | |
3913 | smp->status |= IB_SMP_UNSUP_VERSION; | |
3914 | ret = reply((struct ib_mad_hdr *)smp); | |
3915 | goto bail; | |
3916 | } | |
3917 | ||
3918 | ret = check_mkey(ibp, (struct ib_mad_hdr *)smp, mad_flags, | |
3919 | smp->mkey, (__force __be32)smp->dr_slid, | |
3920 | smp->return_path, smp->hop_cnt); | |
3921 | if (ret) { | |
3922 | u32 port_num = be32_to_cpu(smp->attr_mod); | |
3923 | ||
3924 | /* | |
3925 | * If this is a get/set portinfo, we already check the | |
3926 | * M_Key if the MAD is for another port and the M_Key | |
3927 | * is OK on the receiving port. This check is needed | |
3928 | * to increment the error counters when the M_Key | |
3929 | * fails to match on *both* ports. | |
3930 | */ | |
3931 | if (in_mad->mad_hdr.attr_id == IB_SMP_ATTR_PORT_INFO && | |
3932 | (smp->method == IB_MGMT_METHOD_GET || | |
3933 | smp->method == IB_MGMT_METHOD_SET) && | |
3934 | port_num && port_num <= ibdev->phys_port_cnt && | |
3935 | port != port_num) | |
3936 | (void) check_mkey(to_iport(ibdev, port_num), | |
3937 | (struct ib_mad_hdr *)smp, 0, | |
3938 | smp->mkey, | |
3939 | (__force __be32)smp->dr_slid, | |
3940 | smp->return_path, smp->hop_cnt); | |
3941 | ret = IB_MAD_RESULT_FAILURE; | |
3942 | goto bail; | |
3943 | } | |
3944 | ||
3945 | switch (smp->method) { | |
3946 | case IB_MGMT_METHOD_GET: | |
3947 | switch (smp->attr_id) { | |
3948 | case IB_SMP_ATTR_NODE_INFO: | |
3949 | ret = subn_get_nodeinfo(smp, ibdev, port); | |
3950 | goto bail; | |
3951 | default: | |
3952 | smp->status |= IB_SMP_UNSUP_METH_ATTR; | |
3953 | ret = reply((struct ib_mad_hdr *)smp); | |
3954 | goto bail; | |
3955 | } | |
3956 | } | |
3957 | ||
3958 | bail: | |
3959 | return ret; | |
3960 | } | |
3961 | ||
3962 | static int process_perf_opa(struct ib_device *ibdev, u8 port, | |
3963 | const struct opa_mad *in_mad, | |
3964 | struct opa_mad *out_mad, u32 *resp_len) | |
3965 | { | |
3966 | struct opa_pma_mad *pmp = (struct opa_pma_mad *)out_mad; | |
3967 | int ret; | |
3968 | ||
3969 | *out_mad = *in_mad; | |
3970 | ||
3971 | if (pmp->mad_hdr.class_version != OPA_SMI_CLASS_VERSION) { | |
3972 | pmp->mad_hdr.status |= IB_SMP_UNSUP_VERSION; | |
3973 | return reply((struct ib_mad_hdr *)pmp); | |
3974 | } | |
3975 | ||
3976 | *resp_len = sizeof(pmp->mad_hdr); | |
3977 | ||
3978 | switch (pmp->mad_hdr.method) { | |
3979 | case IB_MGMT_METHOD_GET: | |
3980 | switch (pmp->mad_hdr.attr_id) { | |
3981 | case IB_PMA_CLASS_PORT_INFO: | |
3982 | ret = pma_get_opa_classportinfo(pmp, ibdev, resp_len); | |
3983 | goto bail; | |
3984 | case OPA_PM_ATTRIB_ID_PORT_STATUS: | |
3985 | ret = pma_get_opa_portstatus(pmp, ibdev, port, | |
3986 | resp_len); | |
3987 | goto bail; | |
3988 | case OPA_PM_ATTRIB_ID_DATA_PORT_COUNTERS: | |
3989 | ret = pma_get_opa_datacounters(pmp, ibdev, port, | |
3990 | resp_len); | |
3991 | goto bail; | |
3992 | case OPA_PM_ATTRIB_ID_ERROR_PORT_COUNTERS: | |
3993 | ret = pma_get_opa_porterrors(pmp, ibdev, port, | |
3994 | resp_len); | |
3995 | goto bail; | |
3996 | case OPA_PM_ATTRIB_ID_ERROR_INFO: | |
3997 | ret = pma_get_opa_errorinfo(pmp, ibdev, port, | |
3998 | resp_len); | |
3999 | goto bail; | |
4000 | default: | |
4001 | pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR; | |
4002 | ret = reply((struct ib_mad_hdr *)pmp); | |
4003 | goto bail; | |
4004 | } | |
4005 | ||
4006 | case IB_MGMT_METHOD_SET: | |
4007 | switch (pmp->mad_hdr.attr_id) { | |
4008 | case OPA_PM_ATTRIB_ID_CLEAR_PORT_STATUS: | |
4009 | ret = pma_set_opa_portstatus(pmp, ibdev, port, | |
4010 | resp_len); | |
4011 | goto bail; | |
4012 | case OPA_PM_ATTRIB_ID_ERROR_INFO: | |
4013 | ret = pma_set_opa_errorinfo(pmp, ibdev, port, | |
4014 | resp_len); | |
4015 | goto bail; | |
4016 | default: | |
4017 | pmp->mad_hdr.status |= IB_SMP_UNSUP_METH_ATTR; | |
4018 | ret = reply((struct ib_mad_hdr *)pmp); | |
4019 | goto bail; | |
4020 | } | |
4021 | ||
4022 | case IB_MGMT_METHOD_TRAP: | |
4023 | case IB_MGMT_METHOD_GET_RESP: | |
4024 | /* | |
4025 | * The ib_mad module will call us to process responses | |
4026 | * before checking for other consumers. | |
4027 | * Just tell the caller to process it normally. | |
4028 | */ | |
4029 | ret = IB_MAD_RESULT_SUCCESS; | |
4030 | goto bail; | |
4031 | ||
4032 | default: | |
4033 | pmp->mad_hdr.status |= IB_SMP_UNSUP_METHOD; | |
4034 | ret = reply((struct ib_mad_hdr *)pmp); | |
4035 | } | |
4036 | ||
4037 | bail: | |
4038 | return ret; | |
4039 | } | |
4040 | ||
4041 | static int hfi1_process_opa_mad(struct ib_device *ibdev, int mad_flags, | |
a724648e JB |
4042 | u8 port, const struct ib_wc *in_wc, |
4043 | const struct ib_grh *in_grh, | |
4044 | const struct opa_mad *in_mad, | |
4045 | struct opa_mad *out_mad, size_t *out_mad_size, | |
4046 | u16 *out_mad_pkey_index) | |
77241056 MM |
4047 | { |
4048 | int ret; | |
4049 | int pkey_idx; | |
4050 | u32 resp_len = 0; | |
4051 | struct hfi1_ibport *ibp = to_iport(ibdev, port); | |
4052 | ||
4053 | pkey_idx = hfi1_lookup_pkey_idx(ibp, LIM_MGMT_P_KEY); | |
4054 | if (pkey_idx < 0) { | |
4055 | pr_warn("failed to find limited mgmt pkey, defaulting 0x%x\n", | |
4056 | hfi1_get_pkey(ibp, 1)); | |
4057 | pkey_idx = 1; | |
4058 | } | |
4059 | *out_mad_pkey_index = (u16)pkey_idx; | |
4060 | ||
4061 | switch (in_mad->mad_hdr.mgmt_class) { | |
4062 | case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE: | |
4063 | case IB_MGMT_CLASS_SUBN_LID_ROUTED: | |
4064 | if (is_local_mad(ibp, in_mad, in_wc)) { | |
4065 | ret = opa_local_smp_check(ibp, in_wc); | |
4066 | if (ret) | |
4067 | return IB_MAD_RESULT_FAILURE; | |
4068 | } | |
4069 | ret = process_subn_opa(ibdev, mad_flags, port, in_mad, | |
4070 | out_mad, &resp_len); | |
4071 | goto bail; | |
4072 | case IB_MGMT_CLASS_PERF_MGMT: | |
4073 | ret = process_perf_opa(ibdev, port, in_mad, out_mad, | |
4074 | &resp_len); | |
4075 | goto bail; | |
4076 | ||
4077 | default: | |
4078 | ret = IB_MAD_RESULT_SUCCESS; | |
4079 | } | |
4080 | ||
4081 | bail: | |
4082 | if (ret & IB_MAD_RESULT_REPLY) | |
4083 | *out_mad_size = round_up(resp_len, 8); | |
4084 | else if (ret & IB_MAD_RESULT_SUCCESS) | |
4085 | *out_mad_size = in_wc->byte_len - sizeof(struct ib_grh); | |
4086 | ||
4087 | return ret; | |
4088 | } | |
4089 | ||
4090 | static int hfi1_process_ib_mad(struct ib_device *ibdev, int mad_flags, u8 port, | |
4091 | const struct ib_wc *in_wc, | |
4092 | const struct ib_grh *in_grh, | |
4093 | const struct ib_mad *in_mad, | |
4094 | struct ib_mad *out_mad) | |
4095 | { | |
4096 | int ret; | |
4097 | ||
4098 | switch (in_mad->mad_hdr.mgmt_class) { | |
4099 | case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE: | |
4100 | case IB_MGMT_CLASS_SUBN_LID_ROUTED: | |
4101 | ret = process_subn(ibdev, mad_flags, port, in_mad, out_mad); | |
4102 | goto bail; | |
4103 | default: | |
4104 | ret = IB_MAD_RESULT_SUCCESS; | |
4105 | } | |
4106 | ||
4107 | bail: | |
4108 | return ret; | |
4109 | } | |
4110 | ||
4111 | /** | |
4112 | * hfi1_process_mad - process an incoming MAD packet | |
4113 | * @ibdev: the infiniband device this packet came in on | |
4114 | * @mad_flags: MAD flags | |
4115 | * @port: the port number this packet came in on | |
4116 | * @in_wc: the work completion entry for this packet | |
4117 | * @in_grh: the global route header for this packet | |
4118 | * @in_mad: the incoming MAD | |
4119 | * @out_mad: any outgoing MAD reply | |
4120 | * | |
4121 | * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not | |
4122 | * interested in processing. | |
4123 | * | |
4124 | * Note that the verbs framework has already done the MAD sanity checks, | |
4125 | * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE | |
4126 | * MADs. | |
4127 | * | |
4128 | * This is called by the ib_mad module. | |
4129 | */ | |
4130 | int hfi1_process_mad(struct ib_device *ibdev, int mad_flags, u8 port, | |
4131 | const struct ib_wc *in_wc, const struct ib_grh *in_grh, | |
4132 | const struct ib_mad_hdr *in_mad, size_t in_mad_size, | |
4133 | struct ib_mad_hdr *out_mad, size_t *out_mad_size, | |
4134 | u16 *out_mad_pkey_index) | |
4135 | { | |
4136 | switch (in_mad->base_version) { | |
4137 | case OPA_MGMT_BASE_VERSION: | |
4138 | if (unlikely(in_mad_size != sizeof(struct opa_mad))) { | |
4139 | dev_err(ibdev->dma_device, "invalid in_mad_size\n"); | |
4140 | return IB_MAD_RESULT_FAILURE; | |
4141 | } | |
4142 | return hfi1_process_opa_mad(ibdev, mad_flags, port, | |
4143 | in_wc, in_grh, | |
4144 | (struct opa_mad *)in_mad, | |
4145 | (struct opa_mad *)out_mad, | |
4146 | out_mad_size, | |
4147 | out_mad_pkey_index); | |
4148 | case IB_MGMT_BASE_VERSION: | |
4149 | return hfi1_process_ib_mad(ibdev, mad_flags, port, | |
4150 | in_wc, in_grh, | |
4151 | (const struct ib_mad *)in_mad, | |
4152 | (struct ib_mad *)out_mad); | |
4153 | default: | |
4154 | break; | |
4155 | } | |
4156 | ||
4157 | return IB_MAD_RESULT_FAILURE; | |
4158 | } |