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