32c32
< __FBSDID("$FreeBSD: head/sys/dev/sfxge/common/hunt_mcdi.c 291928 2015-12-07 07:22:21Z arybchik $");
---
> __FBSDID("$FreeBSD: head/sys/dev/sfxge/common/hunt_mcdi.c 291985 2015-12-08 06:25:52Z arybchik $");
231a232
> #if EFSYS_OPT_MCDI_LOGGING
233,235c234
< efsys_mem_t *esmp = emtp->emt_dma_mem;
< unsigned int pos;
< unsigned int offset;
---
> #endif /* EFSYS_OPT_MCDI_LOGGING */
237c236
< efx_dword_t data;
---
> unsigned int hdr_len;
244c243,244
< EFSYS_MEM_READD(esmp, 0, &hdr[0]);
---
> hdr_len = sizeof (hdr[0]);
> hunt_mcdi_read_response(enp, &hdr[0], 0, hdr_len);
246,247d245
< offset = 2 * sizeof (efx_dword_t);
<
252c250,252
< EFSYS_MEM_READD(esmp, sizeof (efx_dword_t), &hdr[1]);
---
> hunt_mcdi_read_response(enp, &hdr[1], hdr_len, sizeof (hdr[1]));
> hdr_len += sizeof (hdr[1]);
>
255,256d254
< } else {
< offset = sizeof (efx_dword_t);
261,265c259
< for (pos = 0; pos < bytes; pos += sizeof (efx_dword_t)) {
< EFSYS_MEM_READD(esmp, offset + pos, &data);
< memcpy(MCDI_OUT(*emrp, efx_dword_t, pos), &data,
< MIN(sizeof (data), bytes - pos));
< }
---
> hunt_mcdi_read_response(enp, emrp->emr_out_buf, hdr_len, bytes);
271,272c265,266
< &hdr, offset,
< emrp->emr_out_buf, emrp->emr_out_length_used);
---
> &hdr, hdr_len,
> emrp->emr_out_buf, bytes);
288a283,301
> void
> hunt_mcdi_read_response(
> __in efx_nic_t *enp,
> __out void *bufferp,
> __in size_t offset,
> __in size_t length)
> {
> const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
> efsys_mem_t *esmp = emtp->emt_dma_mem;
> unsigned int pos;
> efx_dword_t data;
>
> for (pos = 0; pos < length; pos += sizeof (efx_dword_t)) {
> EFSYS_MEM_READD(esmp, offset + pos, &data);
> memcpy((uint8_t *)bufferp + pos, &data,
> MIN(sizeof (data), length - pos));
> }
> }
>
293c306
< efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
---
> #if EFSYS_OPT_MCDI_LOGGING
295c308,309
< efsys_mem_t *esmp = emtp->emt_dma_mem;
---
> #endif /* EFSYS_OPT_MCDI_LOGGING */
> efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
297a312,313
> unsigned int hdr_len;
> unsigned int data_len;
300,301d315
< unsigned int length;
< size_t offset;
314,315d327
< offset = 0;
<
323,324c335,337
< EFSYS_MEM_READD(esmp, offset, &hdr[0]);
< offset += sizeof (efx_dword_t);
---
> hdr_len = sizeof (hdr[0]);
> hunt_mcdi_read_response(enp, &hdr[0], 0, hdr_len);
>
326,327c339,340
< EFSYS_MEM_READD(esmp, offset, &hdr[1]);
< offset += sizeof (efx_dword_t);
---
> hunt_mcdi_read_response(enp, &hdr[1], hdr_len, sizeof (hdr[1]));
> hdr_len += sizeof (hdr[1]);
330c343,344
< length = EFX_DWORD_FIELD(hdr[1], MC_CMD_V2_EXTN_IN_ACTUAL_LEN);
---
> data_len =
> EFX_DWORD_FIELD(hdr[1], MC_CMD_V2_EXTN_IN_ACTUAL_LEN);
333c347
< length = EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_DATALEN);
---
> data_len = EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_DATALEN);
341c355
< if (EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_ERROR) != 0 && length == 0) {
---
> if (EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_ERROR) != 0 && data_len == 0) {
365,366c379,381
< int errcode;
< int argnum;
---
> unsigned int err_len = MIN(data_len, sizeof (err));
> int err_code = MC_CMD_ERR_EPROTO;
> int err_arg = 0;
369,370c384
< EFSYS_MEM_READD(esmp, offset + MC_CMD_ERR_CODE_OFST, &err[0]);
< errcode = EFX_DWORD_FIELD(err[0], EFX_DWORD_0);
---
> hunt_mcdi_read_response(enp, &err[0], hdr_len, err_len);
372,373c386,387
< EFSYS_MEM_READD(esmp, offset + MC_CMD_ERR_ARG_OFST, &err[1]);
< argnum = EFX_DWORD_FIELD(err[1], EFX_DWORD_0);
---
> if (err_len >= MC_CMD_ERR_CODE_OFST + sizeof (efx_dword_t))
> err_code = EFX_DWORD_FIELD(err[0], EFX_DWORD_0);
374a389,391
> if (err_len >= MC_CMD_ERR_ARG_OFST + sizeof (efx_dword_t))
> err_arg = EFX_DWORD_FIELD(err[1], EFX_DWORD_0);
>
379,380c396,397
< &hdr, offset,
< &err, sizeof (err));
---
> &hdr, hdr_len,
> &err, err_len);
384c401
< rc = efx_mcdi_request_errcode(errcode);
---
> rc = efx_mcdi_request_errcode(err_code);
387c404
< int, errcode, int, argnum);
---
> int, err_code, int, err_arg);
392c409
< emrp->emr_out_length_used = length;
---
> emrp->emr_out_length_used = data_len;
< __FBSDID("$FreeBSD: head/sys/dev/sfxge/common/hunt_mcdi.c 291928 2015-12-07 07:22:21Z arybchik $");
---
> __FBSDID("$FreeBSD: head/sys/dev/sfxge/common/hunt_mcdi.c 291985 2015-12-08 06:25:52Z arybchik $");
231a232
> #if EFSYS_OPT_MCDI_LOGGING
233,235c234
< efsys_mem_t *esmp = emtp->emt_dma_mem;
< unsigned int pos;
< unsigned int offset;
---
> #endif /* EFSYS_OPT_MCDI_LOGGING */
237c236
< efx_dword_t data;
---
> unsigned int hdr_len;
244c243,244
< EFSYS_MEM_READD(esmp, 0, &hdr[0]);
---
> hdr_len = sizeof (hdr[0]);
> hunt_mcdi_read_response(enp, &hdr[0], 0, hdr_len);
246,247d245
< offset = 2 * sizeof (efx_dword_t);
<
252c250,252
< EFSYS_MEM_READD(esmp, sizeof (efx_dword_t), &hdr[1]);
---
> hunt_mcdi_read_response(enp, &hdr[1], hdr_len, sizeof (hdr[1]));
> hdr_len += sizeof (hdr[1]);
>
255,256d254
< } else {
< offset = sizeof (efx_dword_t);
261,265c259
< for (pos = 0; pos < bytes; pos += sizeof (efx_dword_t)) {
< EFSYS_MEM_READD(esmp, offset + pos, &data);
< memcpy(MCDI_OUT(*emrp, efx_dword_t, pos), &data,
< MIN(sizeof (data), bytes - pos));
< }
---
> hunt_mcdi_read_response(enp, emrp->emr_out_buf, hdr_len, bytes);
271,272c265,266
< &hdr, offset,
< emrp->emr_out_buf, emrp->emr_out_length_used);
---
> &hdr, hdr_len,
> emrp->emr_out_buf, bytes);
288a283,301
> void
> hunt_mcdi_read_response(
> __in efx_nic_t *enp,
> __out void *bufferp,
> __in size_t offset,
> __in size_t length)
> {
> const efx_mcdi_transport_t *emtp = enp->en_mcdi.em_emtp;
> efsys_mem_t *esmp = emtp->emt_dma_mem;
> unsigned int pos;
> efx_dword_t data;
>
> for (pos = 0; pos < length; pos += sizeof (efx_dword_t)) {
> EFSYS_MEM_READD(esmp, offset + pos, &data);
> memcpy((uint8_t *)bufferp + pos, &data,
> MIN(sizeof (data), length - pos));
> }
> }
>
293c306
< efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
---
> #if EFSYS_OPT_MCDI_LOGGING
295c308,309
< efsys_mem_t *esmp = emtp->emt_dma_mem;
---
> #endif /* EFSYS_OPT_MCDI_LOGGING */
> efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
297a312,313
> unsigned int hdr_len;
> unsigned int data_len;
300,301d315
< unsigned int length;
< size_t offset;
314,315d327
< offset = 0;
<
323,324c335,337
< EFSYS_MEM_READD(esmp, offset, &hdr[0]);
< offset += sizeof (efx_dword_t);
---
> hdr_len = sizeof (hdr[0]);
> hunt_mcdi_read_response(enp, &hdr[0], 0, hdr_len);
>
326,327c339,340
< EFSYS_MEM_READD(esmp, offset, &hdr[1]);
< offset += sizeof (efx_dword_t);
---
> hunt_mcdi_read_response(enp, &hdr[1], hdr_len, sizeof (hdr[1]));
> hdr_len += sizeof (hdr[1]);
330c343,344
< length = EFX_DWORD_FIELD(hdr[1], MC_CMD_V2_EXTN_IN_ACTUAL_LEN);
---
> data_len =
> EFX_DWORD_FIELD(hdr[1], MC_CMD_V2_EXTN_IN_ACTUAL_LEN);
333c347
< length = EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_DATALEN);
---
> data_len = EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_DATALEN);
341c355
< if (EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_ERROR) != 0 && length == 0) {
---
> if (EFX_DWORD_FIELD(hdr[0], MCDI_HEADER_ERROR) != 0 && data_len == 0) {
365,366c379,381
< int errcode;
< int argnum;
---
> unsigned int err_len = MIN(data_len, sizeof (err));
> int err_code = MC_CMD_ERR_EPROTO;
> int err_arg = 0;
369,370c384
< EFSYS_MEM_READD(esmp, offset + MC_CMD_ERR_CODE_OFST, &err[0]);
< errcode = EFX_DWORD_FIELD(err[0], EFX_DWORD_0);
---
> hunt_mcdi_read_response(enp, &err[0], hdr_len, err_len);
372,373c386,387
< EFSYS_MEM_READD(esmp, offset + MC_CMD_ERR_ARG_OFST, &err[1]);
< argnum = EFX_DWORD_FIELD(err[1], EFX_DWORD_0);
---
> if (err_len >= MC_CMD_ERR_CODE_OFST + sizeof (efx_dword_t))
> err_code = EFX_DWORD_FIELD(err[0], EFX_DWORD_0);
374a389,391
> if (err_len >= MC_CMD_ERR_ARG_OFST + sizeof (efx_dword_t))
> err_arg = EFX_DWORD_FIELD(err[1], EFX_DWORD_0);
>
379,380c396,397
< &hdr, offset,
< &err, sizeof (err));
---
> &hdr, hdr_len,
> &err, err_len);
384c401
< rc = efx_mcdi_request_errcode(errcode);
---
> rc = efx_mcdi_request_errcode(err_code);
387c404
< int, errcode, int, argnum);
---
> int, err_code, int, err_arg);
392c409
< emrp->emr_out_length_used = length;
---
> emrp->emr_out_length_used = data_len;