hunt_phy.c revision 300607
1/*-
2 * Copyright (c) 2012-2016 Solarflare Communications Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 *    this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 *    this list of conditions and the following disclaimer in the documentation
12 *    and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * The views and conclusions contained in the software and documentation are
27 * those of the authors and should not be interpreted as representing official
28 * policies, either expressed or implied, of the FreeBSD Project.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/dev/sfxge/common/hunt_phy.c 300607 2016-05-24 12:16:57Z arybchik $");
33
34#include "efx.h"
35#include "efx_impl.h"
36
37#if EFSYS_OPT_HUNTINGTON
38
39#if EFSYS_OPT_BIST
40
41	__checkReturn		efx_rc_t
42hunt_bist_enable_offline(
43	__in			efx_nic_t *enp)
44{
45	efx_rc_t rc;
46
47	if ((rc = efx_mcdi_bist_enable_offline(enp)) != 0)
48		goto fail1;
49
50	return (0);
51
52fail1:
53	EFSYS_PROBE1(fail1, efx_rc_t, rc);
54
55	return (rc);
56}
57
58	__checkReturn		efx_rc_t
59hunt_bist_start(
60	__in			efx_nic_t *enp,
61	__in			efx_bist_type_t type)
62{
63	efx_rc_t rc;
64
65	if ((rc = efx_mcdi_bist_start(enp, type)) != 0)
66		goto fail1;
67
68	return (0);
69
70fail1:
71	EFSYS_PROBE1(fail1, efx_rc_t, rc);
72
73	return (rc);
74}
75
76	__checkReturn		efx_rc_t
77hunt_bist_poll(
78	__in			efx_nic_t *enp,
79	__in			efx_bist_type_t type,
80	__out			efx_bist_result_t *resultp,
81	__out_opt __drv_when(count > 0, __notnull)
82	uint32_t *value_maskp,
83	__out_ecount_opt(count)	__drv_when(count > 0, __notnull)
84	unsigned long *valuesp,
85	__in			size_t count)
86{
87	efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
88	efx_mcdi_req_t req;
89	uint8_t payload[MAX(MC_CMD_POLL_BIST_IN_LEN,
90			    MCDI_CTL_SDU_LEN_MAX)];
91	uint32_t value_mask = 0;
92	uint32_t result;
93	efx_rc_t rc;
94
95	(void) memset(payload, 0, sizeof (payload));
96	req.emr_cmd = MC_CMD_POLL_BIST;
97	req.emr_in_buf = payload;
98	req.emr_in_length = MC_CMD_POLL_BIST_IN_LEN;
99	req.emr_out_buf = payload;
100	req.emr_out_length = MCDI_CTL_SDU_LEN_MAX;
101
102	efx_mcdi_execute(enp, &req);
103
104	if (req.emr_rc != 0) {
105		rc = req.emr_rc;
106		goto fail1;
107	}
108
109	if (req.emr_out_length_used < MC_CMD_POLL_BIST_OUT_RESULT_OFST + 4) {
110		rc = EMSGSIZE;
111		goto fail2;
112	}
113
114	if (count > 0)
115		(void) memset(valuesp, '\0', count * sizeof (unsigned long));
116
117	result = MCDI_OUT_DWORD(req, POLL_BIST_OUT_RESULT);
118
119	if (result == MC_CMD_POLL_BIST_FAILED &&
120	    req.emr_out_length >= MC_CMD_POLL_BIST_OUT_MEM_LEN &&
121	    count > EFX_BIST_MEM_ECC_FATAL) {
122		if (valuesp != NULL) {
123			valuesp[EFX_BIST_MEM_TEST] =
124			    MCDI_OUT_DWORD(req, POLL_BIST_OUT_MEM_TEST);
125			valuesp[EFX_BIST_MEM_ADDR] =
126			    MCDI_OUT_DWORD(req, POLL_BIST_OUT_MEM_ADDR);
127			valuesp[EFX_BIST_MEM_BUS] =
128			    MCDI_OUT_DWORD(req, POLL_BIST_OUT_MEM_BUS);
129			valuesp[EFX_BIST_MEM_EXPECT] =
130			    MCDI_OUT_DWORD(req, POLL_BIST_OUT_MEM_EXPECT);
131			valuesp[EFX_BIST_MEM_ACTUAL] =
132			    MCDI_OUT_DWORD(req, POLL_BIST_OUT_MEM_ACTUAL);
133			valuesp[EFX_BIST_MEM_ECC] =
134			    MCDI_OUT_DWORD(req, POLL_BIST_OUT_MEM_ECC);
135			valuesp[EFX_BIST_MEM_ECC_PARITY] =
136			    MCDI_OUT_DWORD(req, POLL_BIST_OUT_MEM_ECC_PARITY);
137			valuesp[EFX_BIST_MEM_ECC_FATAL] =
138			    MCDI_OUT_DWORD(req, POLL_BIST_OUT_MEM_ECC_FATAL);
139		}
140		value_mask |= (1 << EFX_BIST_MEM_TEST) |
141		    (1 << EFX_BIST_MEM_ADDR) |
142		    (1 << EFX_BIST_MEM_BUS) |
143		    (1 << EFX_BIST_MEM_EXPECT) |
144		    (1 << EFX_BIST_MEM_ACTUAL) |
145		    (1 << EFX_BIST_MEM_ECC) |
146		    (1 << EFX_BIST_MEM_ECC_PARITY) |
147		    (1 << EFX_BIST_MEM_ECC_FATAL);
148	} else if (result == MC_CMD_POLL_BIST_FAILED &&
149	    encp->enc_phy_type == EFX_PHY_XFI_FARMI &&
150	    req.emr_out_length >= MC_CMD_POLL_BIST_OUT_MRSFP_LEN &&
151	    count > EFX_BIST_FAULT_CODE) {
152		if (valuesp != NULL)
153			valuesp[EFX_BIST_FAULT_CODE] =
154			    MCDI_OUT_DWORD(req, POLL_BIST_OUT_MRSFP_TEST);
155		value_mask |= 1 << EFX_BIST_FAULT_CODE;
156	}
157
158	if (value_maskp != NULL)
159		*value_maskp = value_mask;
160
161	EFSYS_ASSERT(resultp != NULL);
162	if (result == MC_CMD_POLL_BIST_RUNNING)
163		*resultp = EFX_BIST_RESULT_RUNNING;
164	else if (result == MC_CMD_POLL_BIST_PASSED)
165		*resultp = EFX_BIST_RESULT_PASSED;
166	else
167		*resultp = EFX_BIST_RESULT_FAILED;
168
169	return (0);
170
171fail2:
172	EFSYS_PROBE(fail2);
173fail1:
174	EFSYS_PROBE1(fail1, efx_rc_t, rc);
175
176	return (rc);
177}
178
179			void
180hunt_bist_stop(
181	__in		efx_nic_t *enp,
182	__in		efx_bist_type_t type)
183{
184	/* There is no way to stop BIST on Huntinton. */
185	_NOTE(ARGUNUSED(enp, type))
186}
187
188#endif	/* EFSYS_OPT_BIST */
189
190#endif	/* EFSYS_OPT_HUNTINGTON */
191