Deleted Added
full compact
ef10_mcdi.c (291928) ef10_mcdi.c (291985)
1/*-
2 * Copyright (c) 2012-2015 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>
1/*-
2 * Copyright (c) 2012-2015 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_mcdi.c 291928 2015-12-07 07:22:21Z arybchik $");
32__FBSDID("$FreeBSD: head/sys/dev/sfxge/common/hunt_mcdi.c 291985 2015-12-08 06:25:52Z arybchik $");
33
34#include "efsys.h"
35#include "efx.h"
36#include "efx_impl.h"
37
38
39#if EFSYS_OPT_HUNTINGTON
40
41#if EFSYS_OPT_MCDI
42
43#ifndef WITH_MCDI_V2
44#error "WITH_MCDI_V2 required for Huntington MCDIv2 commands."
45#endif
46
47typedef enum efx_mcdi_header_type_e {
48 EFX_MCDI_HEADER_TYPE_V1, /* MCDIv0 (BootROM), MCDIv1 commands */
49 EFX_MCDI_HEADER_TYPE_V2, /* MCDIv2 commands */
50} efx_mcdi_header_type_t;
51
52/*
53 * Return the header format to use for sending an MCDI request.
54 *
55 * An MCDIv1 (Siena compatible) command should use MCDIv2 encapsulation if the
56 * request input buffer or response output buffer are too large for the MCDIv1
57 * format. An MCDIv2 command must always be sent using MCDIv2 encapsulation.
58 */
59#define EFX_MCDI_HEADER_TYPE(_cmd, _length) \
60 ((((_cmd) & ~EFX_MASK32(MCDI_HEADER_CODE)) || \
61 ((_length) & ~EFX_MASK32(MCDI_HEADER_DATALEN))) ? \
62 EFX_MCDI_HEADER_TYPE_V2 : EFX_MCDI_HEADER_TYPE_V1)
63
64
65/*
66 * MCDI Header NOT_EPOCH flag
67 * ==========================
68 * A new epoch begins at initial startup or after an MC reboot, and defines when
69 * the MC should reject stale MCDI requests.
70 *
71 * The first MCDI request sent by the host should contain NOT_EPOCH=0, and all
72 * subsequent requests (until the next MC reboot) should contain NOT_EPOCH=1.
73 *
74 * After rebooting the MC will fail all requests with NOT_EPOCH=1 by writing a
75 * response with ERROR=1 and DATALEN=0 until a request is seen with NOT_EPOCH=0.
76 */
77
78
79 __checkReturn efx_rc_t
80hunt_mcdi_init(
81 __in efx_nic_t *enp,
82 __in const efx_mcdi_transport_t *emtp)
83{
84 efsys_mem_t *esmp = emtp->emt_dma_mem;
85 efx_dword_t dword;
86 efx_rc_t rc;
87
88 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON);
89 EFSYS_ASSERT(enp->en_features & EFX_FEATURE_MCDI_DMA);
90
91 /* A host DMA buffer is required for Huntington MCDI */
92 if (esmp == NULL) {
93 rc = EINVAL;
94 goto fail1;
95 }
96
97 /*
98 * Ensure that the MC doorbell is in a known state before issuing MCDI
99 * commands. The recovery algorithm requires that the MC command buffer
100 * must be 256 byte aligned. See bug24769.
101 */
102 if ((EFSYS_MEM_ADDR(esmp) & 0xFF) != 0) {
103 rc = EINVAL;
104 goto fail2;
105 }
106 EFX_POPULATE_DWORD_1(dword, EFX_DWORD_0, 1);
107 EFX_BAR_WRITED(enp, ER_DZ_MC_DB_HWRD_REG, &dword, B_FALSE);
108
109 /* Save initial MC reboot status */
110 (void) hunt_mcdi_poll_reboot(enp);
111
112 /* Start a new epoch (allow fresh MCDI requests to succeed) */
113 efx_mcdi_new_epoch(enp);
114
115 return (0);
116
117fail2:
118 EFSYS_PROBE(fail2);
119fail1:
120 EFSYS_PROBE1(fail1, efx_rc_t, rc);
121
122 return (rc);
123}
124
125 void
126hunt_mcdi_fini(
127 __in efx_nic_t *enp)
128{
129 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
130
131 emip->emi_new_epoch = B_FALSE;
132}
133
134 void
135hunt_mcdi_request_copyin(
136 __in efx_nic_t *enp,
137 __in efx_mcdi_req_t *emrp,
138 __in unsigned int seq,
139 __in boolean_t ev_cpl,
140 __in boolean_t new_epoch)
141{
142 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
143 efsys_mem_t *esmp = emtp->emt_dma_mem;
144 efx_mcdi_header_type_t hdr_type;
145 efx_dword_t dword;
146 efx_dword_t hdr[2];
147 unsigned int xflags;
148 unsigned int pos;
149 size_t offset;
150
151 EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_HUNTINGTON);
152
153 xflags = 0;
154 if (ev_cpl)
155 xflags |= MCDI_HEADER_XFLAGS_EVREQ;
156
157 offset = 0;
158
159 hdr_type = EFX_MCDI_HEADER_TYPE(emrp->emr_cmd,
160 MAX(emrp->emr_in_length, emrp->emr_out_length));
161
162 if (hdr_type == EFX_MCDI_HEADER_TYPE_V2) {
163 /* Construct MCDI v2 header */
164 EFX_POPULATE_DWORD_8(hdr[0],
165 MCDI_HEADER_CODE, MC_CMD_V2_EXTN,
166 MCDI_HEADER_RESYNC, 1,
167 MCDI_HEADER_DATALEN, 0,
168 MCDI_HEADER_SEQ, seq,
169 MCDI_HEADER_NOT_EPOCH, new_epoch ? 0 : 1,
170 MCDI_HEADER_ERROR, 0,
171 MCDI_HEADER_RESPONSE, 0,
172 MCDI_HEADER_XFLAGS, xflags);
173 EFSYS_MEM_WRITED(esmp, offset, &hdr[0]);
174 offset += sizeof (efx_dword_t);
175
176 EFX_POPULATE_DWORD_2(hdr[1],
177 MC_CMD_V2_EXTN_IN_EXTENDED_CMD, emrp->emr_cmd,
178 MC_CMD_V2_EXTN_IN_ACTUAL_LEN, emrp->emr_in_length);
179 EFSYS_MEM_WRITED(esmp, offset, &hdr[1]);
180 offset += sizeof (efx_dword_t);
181 } else {
182 /* Construct MCDI v1 header */
183 EFX_POPULATE_DWORD_8(hdr[0],
184 MCDI_HEADER_CODE, emrp->emr_cmd,
185 MCDI_HEADER_RESYNC, 1,
186 MCDI_HEADER_DATALEN, emrp->emr_in_length,
187 MCDI_HEADER_SEQ, seq,
188 MCDI_HEADER_NOT_EPOCH, new_epoch ? 0 : 1,
189 MCDI_HEADER_ERROR, 0,
190 MCDI_HEADER_RESPONSE, 0,
191 MCDI_HEADER_XFLAGS, xflags);
192 EFSYS_MEM_WRITED(esmp, 0, &hdr[0]);
193 offset += sizeof (efx_dword_t);
194 }
195
196#if EFSYS_OPT_MCDI_LOGGING
197 if (emtp->emt_logger != NULL) {
198 emtp->emt_logger(emtp->emt_context, EFX_LOG_MCDI_REQUEST,
199 &hdr, offset,
200 emrp->emr_in_buf, emrp->emr_in_length);
201 }
202#endif /* EFSYS_OPT_MCDI_LOGGING */
203
204 /* Construct the payload */
205 for (pos = 0; pos < emrp->emr_in_length; pos += sizeof (efx_dword_t)) {
206 memcpy(&dword, MCDI_IN(*emrp, efx_dword_t, pos),
207 MIN(sizeof (dword), emrp->emr_in_length - pos));
208 EFSYS_MEM_WRITED(esmp, offset + pos, &dword);
209 }
210
211 /* Ring the doorbell to post the command DMA address to the MC */
212 EFSYS_ASSERT((EFSYS_MEM_ADDR(esmp) & 0xFF) == 0);
213
214 /* Guarantee ordering of memory (MCDI request) and PIO (MC doorbell) */
215 EFSYS_DMA_SYNC_FOR_DEVICE(esmp, 0, offset + emrp->emr_in_length);
216 EFSYS_PIO_WRITE_BARRIER();
217
218 EFX_POPULATE_DWORD_1(dword,
219 EFX_DWORD_0, EFSYS_MEM_ADDR(esmp) >> 32);
220 EFX_BAR_WRITED(enp, ER_DZ_MC_DB_LWRD_REG, &dword, B_FALSE);
221
222 EFX_POPULATE_DWORD_1(dword,
223 EFX_DWORD_0, EFSYS_MEM_ADDR(esmp) & 0xffffffff);
224 EFX_BAR_WRITED(enp, ER_DZ_MC_DB_HWRD_REG, &dword, B_FALSE);
225}
226
227 void
228hunt_mcdi_request_copyout(
229 __in efx_nic_t *enp,
230 __in efx_mcdi_req_t *emrp)
231{
33
34#include "efsys.h"
35#include "efx.h"
36#include "efx_impl.h"
37
38
39#if EFSYS_OPT_HUNTINGTON
40
41#if EFSYS_OPT_MCDI
42
43#ifndef WITH_MCDI_V2
44#error "WITH_MCDI_V2 required for Huntington MCDIv2 commands."
45#endif
46
47typedef enum efx_mcdi_header_type_e {
48 EFX_MCDI_HEADER_TYPE_V1, /* MCDIv0 (BootROM), MCDIv1 commands */
49 EFX_MCDI_HEADER_TYPE_V2, /* MCDIv2 commands */
50} efx_mcdi_header_type_t;
51
52/*
53 * Return the header format to use for sending an MCDI request.
54 *
55 * An MCDIv1 (Siena compatible) command should use MCDIv2 encapsulation if the
56 * request input buffer or response output buffer are too large for the MCDIv1
57 * format. An MCDIv2 command must always be sent using MCDIv2 encapsulation.
58 */
59#define EFX_MCDI_HEADER_TYPE(_cmd, _length) \
60 ((((_cmd) & ~EFX_MASK32(MCDI_HEADER_CODE)) || \
61 ((_length) & ~EFX_MASK32(MCDI_HEADER_DATALEN))) ? \
62 EFX_MCDI_HEADER_TYPE_V2 : EFX_MCDI_HEADER_TYPE_V1)
63
64
65/*
66 * MCDI Header NOT_EPOCH flag
67 * ==========================
68 * A new epoch begins at initial startup or after an MC reboot, and defines when
69 * the MC should reject stale MCDI requests.
70 *
71 * The first MCDI request sent by the host should contain NOT_EPOCH=0, and all
72 * subsequent requests (until the next MC reboot) should contain NOT_EPOCH=1.
73 *
74 * After rebooting the MC will fail all requests with NOT_EPOCH=1 by writing a
75 * response with ERROR=1 and DATALEN=0 until a request is seen with NOT_EPOCH=0.
76 */
77
78
79 __checkReturn efx_rc_t
80hunt_mcdi_init(
81 __in efx_nic_t *enp,
82 __in const efx_mcdi_transport_t *emtp)
83{
84 efsys_mem_t *esmp = emtp->emt_dma_mem;
85 efx_dword_t dword;
86 efx_rc_t rc;
87
88 EFSYS_ASSERT(enp->en_family == EFX_FAMILY_HUNTINGTON);
89 EFSYS_ASSERT(enp->en_features & EFX_FEATURE_MCDI_DMA);
90
91 /* A host DMA buffer is required for Huntington MCDI */
92 if (esmp == NULL) {
93 rc = EINVAL;
94 goto fail1;
95 }
96
97 /*
98 * Ensure that the MC doorbell is in a known state before issuing MCDI
99 * commands. The recovery algorithm requires that the MC command buffer
100 * must be 256 byte aligned. See bug24769.
101 */
102 if ((EFSYS_MEM_ADDR(esmp) & 0xFF) != 0) {
103 rc = EINVAL;
104 goto fail2;
105 }
106 EFX_POPULATE_DWORD_1(dword, EFX_DWORD_0, 1);
107 EFX_BAR_WRITED(enp, ER_DZ_MC_DB_HWRD_REG, &dword, B_FALSE);
108
109 /* Save initial MC reboot status */
110 (void) hunt_mcdi_poll_reboot(enp);
111
112 /* Start a new epoch (allow fresh MCDI requests to succeed) */
113 efx_mcdi_new_epoch(enp);
114
115 return (0);
116
117fail2:
118 EFSYS_PROBE(fail2);
119fail1:
120 EFSYS_PROBE1(fail1, efx_rc_t, rc);
121
122 return (rc);
123}
124
125 void
126hunt_mcdi_fini(
127 __in efx_nic_t *enp)
128{
129 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
130
131 emip->emi_new_epoch = B_FALSE;
132}
133
134 void
135hunt_mcdi_request_copyin(
136 __in efx_nic_t *enp,
137 __in efx_mcdi_req_t *emrp,
138 __in unsigned int seq,
139 __in boolean_t ev_cpl,
140 __in boolean_t new_epoch)
141{
142 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
143 efsys_mem_t *esmp = emtp->emt_dma_mem;
144 efx_mcdi_header_type_t hdr_type;
145 efx_dword_t dword;
146 efx_dword_t hdr[2];
147 unsigned int xflags;
148 unsigned int pos;
149 size_t offset;
150
151 EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_HUNTINGTON);
152
153 xflags = 0;
154 if (ev_cpl)
155 xflags |= MCDI_HEADER_XFLAGS_EVREQ;
156
157 offset = 0;
158
159 hdr_type = EFX_MCDI_HEADER_TYPE(emrp->emr_cmd,
160 MAX(emrp->emr_in_length, emrp->emr_out_length));
161
162 if (hdr_type == EFX_MCDI_HEADER_TYPE_V2) {
163 /* Construct MCDI v2 header */
164 EFX_POPULATE_DWORD_8(hdr[0],
165 MCDI_HEADER_CODE, MC_CMD_V2_EXTN,
166 MCDI_HEADER_RESYNC, 1,
167 MCDI_HEADER_DATALEN, 0,
168 MCDI_HEADER_SEQ, seq,
169 MCDI_HEADER_NOT_EPOCH, new_epoch ? 0 : 1,
170 MCDI_HEADER_ERROR, 0,
171 MCDI_HEADER_RESPONSE, 0,
172 MCDI_HEADER_XFLAGS, xflags);
173 EFSYS_MEM_WRITED(esmp, offset, &hdr[0]);
174 offset += sizeof (efx_dword_t);
175
176 EFX_POPULATE_DWORD_2(hdr[1],
177 MC_CMD_V2_EXTN_IN_EXTENDED_CMD, emrp->emr_cmd,
178 MC_CMD_V2_EXTN_IN_ACTUAL_LEN, emrp->emr_in_length);
179 EFSYS_MEM_WRITED(esmp, offset, &hdr[1]);
180 offset += sizeof (efx_dword_t);
181 } else {
182 /* Construct MCDI v1 header */
183 EFX_POPULATE_DWORD_8(hdr[0],
184 MCDI_HEADER_CODE, emrp->emr_cmd,
185 MCDI_HEADER_RESYNC, 1,
186 MCDI_HEADER_DATALEN, emrp->emr_in_length,
187 MCDI_HEADER_SEQ, seq,
188 MCDI_HEADER_NOT_EPOCH, new_epoch ? 0 : 1,
189 MCDI_HEADER_ERROR, 0,
190 MCDI_HEADER_RESPONSE, 0,
191 MCDI_HEADER_XFLAGS, xflags);
192 EFSYS_MEM_WRITED(esmp, 0, &hdr[0]);
193 offset += sizeof (efx_dword_t);
194 }
195
196#if EFSYS_OPT_MCDI_LOGGING
197 if (emtp->emt_logger != NULL) {
198 emtp->emt_logger(emtp->emt_context, EFX_LOG_MCDI_REQUEST,
199 &hdr, offset,
200 emrp->emr_in_buf, emrp->emr_in_length);
201 }
202#endif /* EFSYS_OPT_MCDI_LOGGING */
203
204 /* Construct the payload */
205 for (pos = 0; pos < emrp->emr_in_length; pos += sizeof (efx_dword_t)) {
206 memcpy(&dword, MCDI_IN(*emrp, efx_dword_t, pos),
207 MIN(sizeof (dword), emrp->emr_in_length - pos));
208 EFSYS_MEM_WRITED(esmp, offset + pos, &dword);
209 }
210
211 /* Ring the doorbell to post the command DMA address to the MC */
212 EFSYS_ASSERT((EFSYS_MEM_ADDR(esmp) & 0xFF) == 0);
213
214 /* Guarantee ordering of memory (MCDI request) and PIO (MC doorbell) */
215 EFSYS_DMA_SYNC_FOR_DEVICE(esmp, 0, offset + emrp->emr_in_length);
216 EFSYS_PIO_WRITE_BARRIER();
217
218 EFX_POPULATE_DWORD_1(dword,
219 EFX_DWORD_0, EFSYS_MEM_ADDR(esmp) >> 32);
220 EFX_BAR_WRITED(enp, ER_DZ_MC_DB_LWRD_REG, &dword, B_FALSE);
221
222 EFX_POPULATE_DWORD_1(dword,
223 EFX_DWORD_0, EFSYS_MEM_ADDR(esmp) & 0xffffffff);
224 EFX_BAR_WRITED(enp, ER_DZ_MC_DB_HWRD_REG, &dword, B_FALSE);
225}
226
227 void
228hunt_mcdi_request_copyout(
229 __in efx_nic_t *enp,
230 __in efx_mcdi_req_t *emrp)
231{
232#if EFSYS_OPT_MCDI_LOGGING
232 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
233 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
233 efsys_mem_t *esmp = emtp->emt_dma_mem;
234 unsigned int pos;
235 unsigned int offset;
234#endif /* EFSYS_OPT_MCDI_LOGGING */
236 efx_dword_t hdr[2];
235 efx_dword_t hdr[2];
237 efx_dword_t data;
236 unsigned int hdr_len;
238 size_t bytes;
239
240 if (emrp->emr_out_buf == NULL)
241 return;
242
243 /* Read the command header to detect MCDI response format */
237 size_t bytes;
238
239 if (emrp->emr_out_buf == NULL)
240 return;
241
242 /* Read the command header to detect MCDI response format */
244 EFSYS_MEM_READD(esmp, 0, &hdr[0]);
243 hdr_len = sizeof (hdr[0]);
244 hunt_mcdi_read_response(enp, &hdr[0], 0, hdr_len);
245 if (EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_CODE) == MC_CMD_V2_EXTN) {
245 if (EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_CODE) == MC_CMD_V2_EXTN) {
246 offset = 2 * sizeof (efx_dword_t);
247
248 /*
249 * Read the actual payload length. The length given in the event
250 * is only correct for responses with the V1 format.
251 */
246 /*
247 * Read the actual payload length. The length given in the event
248 * is only correct for responses with the V1 format.
249 */
252 EFSYS_MEM_READD(esmp, sizeof (efx_dword_t), &hdr[1]);
250 hunt_mcdi_read_response(enp, &hdr[1], hdr_len, sizeof (hdr[1]));
251 hdr_len += sizeof (hdr[1]);
252
253 emrp->emr_out_length_used = EFX_DWORD_FIELD(hdr[1],
254 MC_CMD_V2_EXTN_IN_ACTUAL_LEN);
253 emrp->emr_out_length_used = EFX_DWORD_FIELD(hdr[1],
254 MC_CMD_V2_EXTN_IN_ACTUAL_LEN);
255 } else {
256 offset = sizeof (efx_dword_t);
257 }
258
259 /* Copy payload out into caller supplied buffer */
260 bytes = MIN(emrp->emr_out_length_used, emrp->emr_out_length);
255 }
256
257 /* Copy payload out into caller supplied buffer */
258 bytes = MIN(emrp->emr_out_length_used, emrp->emr_out_length);
261 for (pos = 0; pos < bytes; pos += sizeof (efx_dword_t)) {
262 EFSYS_MEM_READD(esmp, offset + pos, &data);
263 memcpy(MCDI_OUT(*emrp, efx_dword_t, pos), &data,
264 MIN(sizeof (data), bytes - pos));
265 }
259 hunt_mcdi_read_response(enp, emrp->emr_out_buf, hdr_len, bytes);
266
267#if EFSYS_OPT_MCDI_LOGGING
268 if (emtp->emt_logger != NULL) {
269 emtp->emt_logger(emtp->emt_context,
270 EFX_LOG_MCDI_RESPONSE,
260
261#if EFSYS_OPT_MCDI_LOGGING
262 if (emtp->emt_logger != NULL) {
263 emtp->emt_logger(emtp->emt_context,
264 EFX_LOG_MCDI_RESPONSE,
271 &hdr, offset,
272 emrp->emr_out_buf, emrp->emr_out_length_used);
265 &hdr, hdr_len,
266 emrp->emr_out_buf, bytes);
273 }
274#endif /* EFSYS_OPT_MCDI_LOGGING */
275}
276
277static __checkReturn boolean_t
278hunt_mcdi_poll_response(
279 __in efx_nic_t *enp)
280{
281 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
282 efsys_mem_t *esmp = emtp->emt_dma_mem;
283 efx_dword_t hdr;
284
285 EFSYS_MEM_READD(esmp, 0, &hdr);
286 return (EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE) ? B_TRUE : B_FALSE);
287}
288
267 }
268#endif /* EFSYS_OPT_MCDI_LOGGING */
269}
270
271static __checkReturn boolean_t
272hunt_mcdi_poll_response(
273 __in efx_nic_t *enp)
274{
275 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
276 efsys_mem_t *esmp = emtp->emt_dma_mem;
277 efx_dword_t hdr;
278
279 EFSYS_MEM_READD(esmp, 0, &hdr);
280 return (EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE) ? B_TRUE : B_FALSE);
281}
282
283 void
284hunt_mcdi_read_response(
285 __in efx_nic_t *enp,
286 __out void *bufferp,
287 __in size_t offset,
288 __in size_t length)
289{
290 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
291 efsys_mem_t *esmp = emtp->emt_dma_mem;
292 unsigned int pos;
293 efx_dword_t data;
294
295 for (pos = 0; pos < length; pos += sizeof (efx_dword_t)) {
296 EFSYS_MEM_READD(esmp, offset + pos, &data);
297 memcpy((uint8_t *)bufferp + pos, &data,
298 MIN(sizeof (data), length - pos));
299 }
300}
301
289 __checkReturn boolean_t
290hunt_mcdi_request_poll(
291 __in efx_nic_t *enp)
292{
302 __checkReturn boolean_t
303hunt_mcdi_request_poll(
304 __in efx_nic_t *enp)
305{
293 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
306#if EFSYS_OPT_MCDI_LOGGING
294 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
307 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
295 efsys_mem_t *esmp = emtp->emt_dma_mem;
308#endif /* EFSYS_OPT_MCDI_LOGGING */
309 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
296 efx_mcdi_req_t *emrp;
297 efx_dword_t hdr[2];
310 efx_mcdi_req_t *emrp;
311 efx_dword_t hdr[2];
312 unsigned int hdr_len;
313 unsigned int data_len;
298 unsigned int seq;
299 unsigned int cmd;
314 unsigned int seq;
315 unsigned int cmd;
300 unsigned int length;
301 size_t offset;
302 int state;
303 efx_rc_t rc;
304
305 EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_HUNTINGTON);
306
307 /* Serialise against post-watchdog efx_mcdi_ev* */
308 EFSYS_LOCK(enp->en_eslp, state);
309
310 EFSYS_ASSERT(emip->emi_pending_req != NULL);
311 EFSYS_ASSERT(!emip->emi_ev_cpl);
312 emrp = emip->emi_pending_req;
313
316 int state;
317 efx_rc_t rc;
318
319 EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_HUNTINGTON);
320
321 /* Serialise against post-watchdog efx_mcdi_ev* */
322 EFSYS_LOCK(enp->en_eslp, state);
323
324 EFSYS_ASSERT(emip->emi_pending_req != NULL);
325 EFSYS_ASSERT(!emip->emi_ev_cpl);
326 emrp = emip->emi_pending_req;
327
314 offset = 0;
315
316 /* Check if a response is available */
317 if (hunt_mcdi_poll_response(enp) == B_FALSE) {
318 EFSYS_UNLOCK(enp->en_eslp, state);
319 return (B_FALSE);
320 }
321
322 /* Read the response header */
328 /* Check if a response is available */
329 if (hunt_mcdi_poll_response(enp) == B_FALSE) {
330 EFSYS_UNLOCK(enp->en_eslp, state);
331 return (B_FALSE);
332 }
333
334 /* Read the response header */
323 EFSYS_MEM_READD(esmp, offset, &hdr[0]);
324 offset += sizeof (efx_dword_t);
335 hdr_len = sizeof (hdr[0]);
336 hunt_mcdi_read_response(enp, &hdr[0], 0, hdr_len);
337
325 if (EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_CODE) == MC_CMD_V2_EXTN) {
338 if (EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_CODE) == MC_CMD_V2_EXTN) {
326 EFSYS_MEM_READD(esmp, offset, &hdr[1]);
327 offset += sizeof (efx_dword_t);
339 hunt_mcdi_read_response(enp, &hdr[1], hdr_len, sizeof (hdr[1]));
340 hdr_len += sizeof (hdr[1]);
328
329 cmd = EFX_DWORD_FIELD(hdr[1], MC_CMD_V2_EXTN_IN_EXTENDED_CMD);
341
342 cmd = EFX_DWORD_FIELD(hdr[1], MC_CMD_V2_EXTN_IN_EXTENDED_CMD);
330 length = EFX_DWORD_FIELD(hdr[1], MC_CMD_V2_EXTN_IN_ACTUAL_LEN);
343 data_len =
344 EFX_DWORD_FIELD(hdr[1], MC_CMD_V2_EXTN_IN_ACTUAL_LEN);
331 } else {
332 cmd = EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_CODE);
345 } else {
346 cmd = EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_CODE);
333 length = EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_DATALEN);
347 data_len = EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_DATALEN);
334 }
335
336 /* Request complete */
337 emip->emi_pending_req = NULL;
338 seq = (emip->emi_seq - 1) & EFX_MASK32(MCDI_HEADER_SEQ);
339
340 /* Check for synchronous reboot */
348 }
349
350 /* Request complete */
351 emip->emi_pending_req = NULL;
352 seq = (emip->emi_seq - 1) & EFX_MASK32(MCDI_HEADER_SEQ);
353
354 /* Check for synchronous reboot */
341 if (EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_ERROR) != 0 && length == 0) {
355 if (EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_ERROR) != 0 && data_len == 0) {
342 /* The MC has rebooted since the request was sent. */
343 EFSYS_SPIN(EFX_MCDI_STATUS_SLEEP_US);
344 hunt_mcdi_poll_reboot(enp);
345
346 EFSYS_UNLOCK(enp->en_eslp, state);
347 rc = EIO;
348 goto fail1;
349 }
350
351 /* Ensure stale MCDI requests fail after an MC reboot. */
352 emip->emi_new_epoch = B_FALSE;
353
354 EFSYS_UNLOCK(enp->en_eslp, state);
355
356 /* Check that the returned data is consistent */
357 if (cmd != emrp->emr_cmd ||
358 EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_SEQ) != seq) {
359 /* Response is for a different request */
360 rc = EIO;
361 goto fail2;
362 }
363 if (EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_ERROR)) {
364 efx_dword_t err[2];
356 /* The MC has rebooted since the request was sent. */
357 EFSYS_SPIN(EFX_MCDI_STATUS_SLEEP_US);
358 hunt_mcdi_poll_reboot(enp);
359
360 EFSYS_UNLOCK(enp->en_eslp, state);
361 rc = EIO;
362 goto fail1;
363 }
364
365 /* Ensure stale MCDI requests fail after an MC reboot. */
366 emip->emi_new_epoch = B_FALSE;
367
368 EFSYS_UNLOCK(enp->en_eslp, state);
369
370 /* Check that the returned data is consistent */
371 if (cmd != emrp->emr_cmd ||
372 EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_SEQ) != seq) {
373 /* Response is for a different request */
374 rc = EIO;
375 goto fail2;
376 }
377 if (EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_ERROR)) {
378 efx_dword_t err[2];
365 int errcode;
366 int argnum;
379 unsigned int err_len = MIN(data_len, sizeof (err));
380 int err_code = MC_CMD_ERR_EPROTO;
381 int err_arg = 0;
367
368 /* Read error code (and arg num for MCDI v2 commands) */
382
383 /* Read error code (and arg num for MCDI v2 commands) */
369 EFSYS_MEM_READD(esmp, offset + MC_CMD_ERR_CODE_OFST, &err[0]);
370 errcode = EFX_DWORD_FIELD(err[0], EFX_DWORD_0);
384 hunt_mcdi_read_response(enp, &err[0], hdr_len, err_len);
371
385
372 EFSYS_MEM_READD(esmp, offset + MC_CMD_ERR_ARG_OFST, &err[1]);
373 argnum = EFX_DWORD_FIELD(err[1], EFX_DWORD_0);
386 if (err_len >= MC_CMD_ERR_CODE_OFST + sizeof (efx_dword_t))
387 err_code = EFX_DWORD_FIELD(err[0], EFX_DWORD_0);
374
388
389 if (err_len >= MC_CMD_ERR_ARG_OFST + sizeof (efx_dword_t))
390 err_arg = EFX_DWORD_FIELD(err[1], EFX_DWORD_0);
391
375#if EFSYS_OPT_MCDI_LOGGING
376 if (emtp->emt_logger != NULL) {
377 emtp->emt_logger(emtp->emt_context,
378 EFX_LOG_MCDI_RESPONSE,
392#if EFSYS_OPT_MCDI_LOGGING
393 if (emtp->emt_logger != NULL) {
394 emtp->emt_logger(emtp->emt_context,
395 EFX_LOG_MCDI_RESPONSE,
379 &hdr, offset,
380 &err, sizeof (err));
396 &hdr, hdr_len,
397 &err, err_len);
381 }
382#endif /* EFSYS_OPT_MCDI_LOGGING */
383
398 }
399#endif /* EFSYS_OPT_MCDI_LOGGING */
400
384 rc = efx_mcdi_request_errcode(errcode);
401 rc = efx_mcdi_request_errcode(err_code);
385 if (!emrp->emr_quiet) {
386 EFSYS_PROBE3(mcdi_err_arg, int, emrp->emr_cmd,
402 if (!emrp->emr_quiet) {
403 EFSYS_PROBE3(mcdi_err_arg, int, emrp->emr_cmd,
387 int, errcode, int, argnum);
404 int, err_code, int, err_arg);
388 }
389 goto fail3;
390
391 } else {
405 }
406 goto fail3;
407
408 } else {
392 emrp->emr_out_length_used = length;
409 emrp->emr_out_length_used = data_len;
393 emrp->emr_rc = 0;
394 hunt_mcdi_request_copyout(enp, emrp);
395 }
396
397 goto out;
398
399fail3:
400 if (!emrp->emr_quiet)
401 EFSYS_PROBE(fail3);
402fail2:
403 if (!emrp->emr_quiet)
404 EFSYS_PROBE(fail2);
405fail1:
406 if (!emrp->emr_quiet)
407 EFSYS_PROBE1(fail1, efx_rc_t, rc);
408
409 /* Fill out error state */
410 emrp->emr_rc = rc;
411 emrp->emr_out_length_used = 0;
412
413 /* Reboot/Assertion */
414 if (rc == EIO || rc == EINTR)
415 efx_mcdi_raise_exception(enp, emrp, rc);
416
417out:
418 return (B_TRUE);
419}
420
421 efx_rc_t
422hunt_mcdi_poll_reboot(
423 __in efx_nic_t *enp)
424{
425 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
426 efx_dword_t dword;
427 uint32_t old_status;
428 uint32_t new_status;
429 efx_rc_t rc;
430
431 old_status = emip->emi_mc_reboot_status;
432
433 /* Update MC reboot status word */
434 EFX_BAR_TBL_READD(enp, ER_DZ_BIU_MC_SFT_STATUS_REG, 0, &dword, B_FALSE);
435 new_status = dword.ed_u32[0];
436
437 /* MC has rebooted if the value has changed */
438 if (new_status != old_status) {
439 emip->emi_mc_reboot_status = new_status;
440
441 /*
442 * FIXME: Ignore detected MC REBOOT for now.
443 *
444 * The Siena support for checking for MC reboot from status
445 * flags is broken - see comments in siena_mcdi_poll_reboot().
446 * As the generic MCDI code is shared the Huntington reboot
447 * detection suffers similar problems.
448 *
449 * Do not report an error when the boot status changes until
450 * this can be handled by common code drivers (and reworked to
451 * support Siena too).
452 */
453 if (B_FALSE) {
454 rc = EIO;
455 goto fail1;
456 }
457 }
458
459 return (0);
460
461fail1:
462 EFSYS_PROBE1(fail1, efx_rc_t, rc);
463
464 return (rc);
465}
466
467 __checkReturn efx_rc_t
468hunt_mcdi_fw_update_supported(
469 __in efx_nic_t *enp,
470 __out boolean_t *supportedp)
471{
472 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
473
474 EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_HUNTINGTON);
475
476 /*
477 * Use privilege mask state at MCDI attach.
478 * Admin privilege must be used prior to introduction of
479 * specific flag.
480 */
481 *supportedp = (encp->enc_privilege_mask &
482 MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN)
483 == MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN;
484
485 return (0);
486}
487
488 __checkReturn efx_rc_t
489hunt_mcdi_macaddr_change_supported(
490 __in efx_nic_t *enp,
491 __out boolean_t *supportedp)
492{
493 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
494 uint32_t privilege_mask = encp->enc_privilege_mask;
495
496 EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_HUNTINGTON);
497
498 /*
499 * Use privilege mask state at MCDI attach.
500 * Admin privilege must be used prior to introduction of
501 * specific flag (at v4.6).
502 */
503 *supportedp =
504 ((privilege_mask & MC_CMD_PRIVILEGE_MASK_IN_GRP_MAC_SPOOFING) ==
505 MC_CMD_PRIVILEGE_MASK_IN_GRP_MAC_SPOOFING) ||
506 ((privilege_mask & MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN) ==
507 MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN);
508
509 return (0);
510}
511
512 __checkReturn efx_rc_t
513hunt_mcdi_link_control_supported(
514 __in efx_nic_t *enp,
515 __out boolean_t *supportedp)
516{
517 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
518 uint32_t privilege_mask = encp->enc_privilege_mask;
519
520 EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_HUNTINGTON);
521
522 /*
523 * Use privilege mask state at MCDI attach.
524 * Admin privilege used prior to introduction of
525 * specific flag.
526 */
527 *supportedp =
528 ((privilege_mask & MC_CMD_PRIVILEGE_MASK_IN_GRP_LINK) ==
529 MC_CMD_PRIVILEGE_MASK_IN_GRP_LINK) ||
530 ((privilege_mask & MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN) ==
531 MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN);
532
533 return (0);
534}
535
536#endif /* EFSYS_OPT_MCDI */
537
538#endif /* EFSYS_OPT_HUNTINGTON */
410 emrp->emr_rc = 0;
411 hunt_mcdi_request_copyout(enp, emrp);
412 }
413
414 goto out;
415
416fail3:
417 if (!emrp->emr_quiet)
418 EFSYS_PROBE(fail3);
419fail2:
420 if (!emrp->emr_quiet)
421 EFSYS_PROBE(fail2);
422fail1:
423 if (!emrp->emr_quiet)
424 EFSYS_PROBE1(fail1, efx_rc_t, rc);
425
426 /* Fill out error state */
427 emrp->emr_rc = rc;
428 emrp->emr_out_length_used = 0;
429
430 /* Reboot/Assertion */
431 if (rc == EIO || rc == EINTR)
432 efx_mcdi_raise_exception(enp, emrp, rc);
433
434out:
435 return (B_TRUE);
436}
437
438 efx_rc_t
439hunt_mcdi_poll_reboot(
440 __in efx_nic_t *enp)
441{
442 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
443 efx_dword_t dword;
444 uint32_t old_status;
445 uint32_t new_status;
446 efx_rc_t rc;
447
448 old_status = emip->emi_mc_reboot_status;
449
450 /* Update MC reboot status word */
451 EFX_BAR_TBL_READD(enp, ER_DZ_BIU_MC_SFT_STATUS_REG, 0, &dword, B_FALSE);
452 new_status = dword.ed_u32[0];
453
454 /* MC has rebooted if the value has changed */
455 if (new_status != old_status) {
456 emip->emi_mc_reboot_status = new_status;
457
458 /*
459 * FIXME: Ignore detected MC REBOOT for now.
460 *
461 * The Siena support for checking for MC reboot from status
462 * flags is broken - see comments in siena_mcdi_poll_reboot().
463 * As the generic MCDI code is shared the Huntington reboot
464 * detection suffers similar problems.
465 *
466 * Do not report an error when the boot status changes until
467 * this can be handled by common code drivers (and reworked to
468 * support Siena too).
469 */
470 if (B_FALSE) {
471 rc = EIO;
472 goto fail1;
473 }
474 }
475
476 return (0);
477
478fail1:
479 EFSYS_PROBE1(fail1, efx_rc_t, rc);
480
481 return (rc);
482}
483
484 __checkReturn efx_rc_t
485hunt_mcdi_fw_update_supported(
486 __in efx_nic_t *enp,
487 __out boolean_t *supportedp)
488{
489 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
490
491 EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_HUNTINGTON);
492
493 /*
494 * Use privilege mask state at MCDI attach.
495 * Admin privilege must be used prior to introduction of
496 * specific flag.
497 */
498 *supportedp = (encp->enc_privilege_mask &
499 MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN)
500 == MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN;
501
502 return (0);
503}
504
505 __checkReturn efx_rc_t
506hunt_mcdi_macaddr_change_supported(
507 __in efx_nic_t *enp,
508 __out boolean_t *supportedp)
509{
510 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
511 uint32_t privilege_mask = encp->enc_privilege_mask;
512
513 EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_HUNTINGTON);
514
515 /*
516 * Use privilege mask state at MCDI attach.
517 * Admin privilege must be used prior to introduction of
518 * specific flag (at v4.6).
519 */
520 *supportedp =
521 ((privilege_mask & MC_CMD_PRIVILEGE_MASK_IN_GRP_MAC_SPOOFING) ==
522 MC_CMD_PRIVILEGE_MASK_IN_GRP_MAC_SPOOFING) ||
523 ((privilege_mask & MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN) ==
524 MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN);
525
526 return (0);
527}
528
529 __checkReturn efx_rc_t
530hunt_mcdi_link_control_supported(
531 __in efx_nic_t *enp,
532 __out boolean_t *supportedp)
533{
534 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
535 uint32_t privilege_mask = encp->enc_privilege_mask;
536
537 EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_HUNTINGTON);
538
539 /*
540 * Use privilege mask state at MCDI attach.
541 * Admin privilege used prior to introduction of
542 * specific flag.
543 */
544 *supportedp =
545 ((privilege_mask & MC_CMD_PRIVILEGE_MASK_IN_GRP_LINK) ==
546 MC_CMD_PRIVILEGE_MASK_IN_GRP_LINK) ||
547 ((privilege_mask & MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN) ==
548 MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN);
549
550 return (0);
551}
552
553#endif /* EFSYS_OPT_MCDI */
554
555#endif /* EFSYS_OPT_HUNTINGTON */