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,
--- 15 unchanged lines hidden (view full) ---
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 $");
33
34#include "efsys.h"
35#include "efx.h"
36#include "efx_impl.h"
37
38
39#if EFSYS_OPT_HUNTINGTON
40
--- 183 unchanged lines hidden (view full) ---
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 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;
236 efx_dword_t hdr[2];
237 efx_dword_t data;
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 */
244 EFSYS_MEM_READD(esmp, 0, &hdr[0]);
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 */
252 EFSYS_MEM_READD(esmp, sizeof (efx_dword_t), &hdr[1]);
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);
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 }
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,
271 &hdr, offset,
272 emrp->emr_out_buf, emrp->emr_out_length_used);
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
289 __checkReturn boolean_t
290hunt_mcdi_request_poll(
291 __in efx_nic_t *enp)
292{
293 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
294 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
295 efsys_mem_t *esmp = emtp->emt_dma_mem;
296 efx_mcdi_req_t *emrp;
297 efx_dword_t hdr[2];
298 unsigned int seq;
299 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
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 */
323 EFSYS_MEM_READD(esmp, offset, &hdr[0]);
324 offset += sizeof (efx_dword_t);
325 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);
328
329 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);
331 } else {
332 cmd = EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_CODE);
333 length = 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 */
341 if (EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_ERROR) != 0 && length == 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 }
--- 7 unchanged lines hidden (view full) ---
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];
365 int errcode;
366 int argnum;
367
368 /* 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);
371
372 EFSYS_MEM_READD(esmp, offset + MC_CMD_ERR_ARG_OFST, &err[1]);
373 argnum = EFX_DWORD_FIELD(err[1], EFX_DWORD_0);
374
375#if EFSYS_OPT_MCDI_LOGGING
376 if (emtp->emt_logger != NULL) {
377 emtp->emt_logger(emtp->emt_context,
378 EFX_LOG_MCDI_RESPONSE,
379 &hdr, offset,
380 &err, sizeof (err));
381 }
382#endif /* EFSYS_OPT_MCDI_LOGGING */
383
384 rc = efx_mcdi_request_errcode(errcode);
385 if (!emrp->emr_quiet) {
386 EFSYS_PROBE3(mcdi_err_arg, int, emrp->emr_cmd,
387 int, errcode, int, argnum);
388 }
389 goto fail3;
390
391 } else {
392 emrp->emr_out_length_used = length;
393 emrp->emr_rc = 0;
394 hunt_mcdi_request_copyout(enp, emrp);
395 }
396
397 goto out;
398
399fail3:
400 if (!emrp->emr_quiet)
--- 138 unchanged lines hidden ---
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,
--- 15 unchanged lines hidden (view full) ---
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 $");
33
34#include "efsys.h"
35#include "efx.h"
36#include "efx_impl.h"
37
38
39#if EFSYS_OPT_HUNTINGTON
40
--- 183 unchanged lines hidden (view full) ---
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 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;
236 efx_dword_t hdr[2];
237 efx_dword_t data;
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 */
244 EFSYS_MEM_READD(esmp, 0, &hdr[0]);
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 */
252 EFSYS_MEM_READD(esmp, sizeof (efx_dword_t), &hdr[1]);
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);
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 }
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,
271 &hdr, offset,
272 emrp->emr_out_buf, emrp->emr_out_length_used);
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
289 __checkReturn boolean_t
290hunt_mcdi_request_poll(
291 __in efx_nic_t *enp)
292{
293 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
294 const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
295 efsys_mem_t *esmp = emtp->emt_dma_mem;
296 efx_mcdi_req_t *emrp;
297 efx_dword_t hdr[2];
298 unsigned int seq;
299 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
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 */
323 EFSYS_MEM_READD(esmp, offset, &hdr[0]);
324 offset += sizeof (efx_dword_t);
325 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);
328
329 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);
331 } else {
332 cmd = EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_CODE);
333 length = 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 */
341 if (EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_ERROR) != 0 && length == 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 }
--- 7 unchanged lines hidden (view full) ---
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];
365 int errcode;
366 int argnum;
367
368 /* 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);
371
372 EFSYS_MEM_READD(esmp, offset + MC_CMD_ERR_ARG_OFST, &err[1]);
373 argnum = EFX_DWORD_FIELD(err[1], EFX_DWORD_0);
374
375#if EFSYS_OPT_MCDI_LOGGING
376 if (emtp->emt_logger != NULL) {
377 emtp->emt_logger(emtp->emt_context,
378 EFX_LOG_MCDI_RESPONSE,
379 &hdr, offset,
380 &err, sizeof (err));
381 }
382#endif /* EFSYS_OPT_MCDI_LOGGING */
383
384 rc = efx_mcdi_request_errcode(errcode);
385 if (!emrp->emr_quiet) {
386 EFSYS_PROBE3(mcdi_err_arg, int, emrp->emr_cmd,
387 int, errcode, int, argnum);
388 }
389 goto fail3;
390
391 } else {
392 emrp->emr_out_length_used = length;
393 emrp->emr_rc = 0;
394 hunt_mcdi_request_copyout(enp, emrp);
395 }
396
397 goto out;
398
399fail3:
400 if (!emrp->emr_quiet)
--- 138 unchanged lines hidden ---