Lines 3663-3674
ixl_handle_nvmupd_cmd(struct ixl_pf *pf, struct ifdrv *ifd)
Link Here
|
3663 |
struct i40e_nvm_access *nvma; |
3663 |
struct i40e_nvm_access *nvma; |
3664 |
device_t dev = pf->dev; |
3664 |
device_t dev = pf->dev; |
3665 |
enum i40e_status_code status = 0; |
3665 |
enum i40e_status_code status = 0; |
|
|
3666 |
u32 max_data_len; |
3667 |
int error = 0; |
3666 |
int perrno; |
3668 |
int perrno; |
3667 |
|
3669 |
|
3668 |
DEBUGFUNC("ixl_handle_nvmupd_cmd"); |
3670 |
DEBUGFUNC("ixl_handle_nvmupd_cmd"); |
3669 |
|
3671 |
|
3670 |
/* Sanity checks */ |
3672 |
/* |
|
|
3673 |
* The maximum length of the ioctl data is the size of the struct i40e_nvm_access |
3674 |
* and the max of 4096 bytes in the data field contained in that struct. |
3675 |
*/ |
3676 |
max_data_len = (sizeof(struct i40e_nvm_access) - 1) + 4096; |
3677 |
|
3678 |
/* Sanity checks on ifdrv struct fields */ |
3671 |
if (ifd->ifd_len < sizeof(struct i40e_nvm_access) || |
3679 |
if (ifd->ifd_len < sizeof(struct i40e_nvm_access) || |
|
|
3680 |
ifd->ifd_len > max_data_len || |
3672 |
ifd->ifd_data == NULL) { |
3681 |
ifd->ifd_data == NULL) { |
3673 |
device_printf(dev, "%s: incorrect ifdrv length or data pointer\n", |
3682 |
device_printf(dev, "%s: incorrect ifdrv length or data pointer\n", |
3674 |
__func__); |
3683 |
__func__); |
Lines 3679-3685
ixl_handle_nvmupd_cmd(struct ixl_pf *pf, struct ifdrv *ifd)
Link Here
|
3679 |
return (EINVAL); |
3688 |
return (EINVAL); |
3680 |
} |
3689 |
} |
3681 |
|
3690 |
|
3682 |
nvma = (struct i40e_nvm_access *)ifd->ifd_data; |
3691 |
/* Copy in ioctl data to kernel space */ |
|
|
3692 |
nvma = malloc(max_data_len, M_IXL, M_NOWAIT); |
3693 |
if (nvma == NULL) { |
3694 |
device_printf(dev, "%s: failed to allocate kernel buffer for ioctl data\n", |
3695 |
__func__); |
3696 |
return (ENOMEM); |
3697 |
} |
3698 |
|
3699 |
error = copyin(ifd->ifd_data, nvma, max_data_len); |
3700 |
if (error != 0) { |
3701 |
device_printf(dev, "%s: failed to copyin ioctl data\n", |
3702 |
__func__); |
3703 |
free(nvma, M_IXL); |
3704 |
return (error); |
3705 |
} |
3683 |
|
3706 |
|
3684 |
if (pf->dbg_mask & IXL_DBG_NVMUPD) |
3707 |
if (pf->dbg_mask & IXL_DBG_NVMUPD) |
3685 |
ixl_print_nvm_cmd(dev, nvma); |
3708 |
ixl_print_nvm_cmd(dev, nvma); |
Lines 3693-3712
ixl_handle_nvmupd_cmd(struct ixl_pf *pf, struct ifdrv *ifd)
Link Here
|
3693 |
} |
3716 |
} |
3694 |
} |
3717 |
} |
3695 |
|
3718 |
|
3696 |
if (!(pf->state & IXL_PF_STATE_ADAPTER_RESETTING)) { |
3719 |
if (!(pf->state & IXL_PF_STATE_ADAPTER_RESETTING)) |
3697 |
// TODO: Might need a different lock here |
|
|
3698 |
// IXL_PF_LOCK(pf); |
3699 |
status = i40e_nvmupd_command(hw, nvma, nvma->data, &perrno); |
3720 |
status = i40e_nvmupd_command(hw, nvma, nvma->data, &perrno); |
3700 |
// IXL_PF_UNLOCK(pf); |
3721 |
else |
3701 |
} else { |
|
|
3702 |
perrno = -EBUSY; |
3722 |
perrno = -EBUSY; |
3703 |
} |
|
|
3704 |
|
3723 |
|
3705 |
/* Let the nvmupdate report errors, show them only when debug is enabled */ |
3724 |
/* Let the nvmupdate report errors, show them only when debug is enabled */ |
3706 |
if (status != 0 && (pf->dbg_mask & IXL_DBG_NVMUPD) != 0) |
3725 |
if (status != 0 && (pf->dbg_mask & IXL_DBG_NVMUPD) != 0) |
3707 |
device_printf(dev, "i40e_nvmupd_command status %s, perrno %d\n", |
3726 |
device_printf(dev, "i40e_nvmupd_command status %s, perrno %d\n", |
3708 |
i40e_stat_str(hw, status), perrno); |
3727 |
i40e_stat_str(hw, status), perrno); |
3709 |
|
3728 |
|
|
|
3729 |
/* Copy out ioctl data to user space */ |
3730 |
if (perrno == 0) { |
3731 |
error = copyout(nvma, ifd->ifd_data, max_data_len); |
3732 |
if (error != 0) { |
3733 |
device_printf(dev, "%s: failed to copyout ioctl data\n", |
3734 |
__func__); |
3735 |
free(nvma, M_IXL); |
3736 |
return (error); |
3737 |
} |
3738 |
} |
3739 |
|
3740 |
free(nvma, M_IXL); |
3741 |
|
3710 |
/* |
3742 |
/* |
3711 |
* -EPERM is actually ERESTART, which the kernel interprets as it needing |
3743 |
* -EPERM is actually ERESTART, which the kernel interprets as it needing |
3712 |
* to run this ioctl again. So use -EACCES for -EPERM instead. |
3744 |
* to run this ioctl again. So use -EACCES for -EPERM instead. |