sfxge: consolidate privilege check functions
To reduce code duplication in common code, consolidate similar privilege check functions. Submitted by: Richard Houldsworth <rhouldsworth at solarflare.com> Reviewed by: gnn Sponsored by: Solarflare Communications, Inc. MFC after: 2 days Differential Revision: https://reviews.freebsd.org/D4480
This commit is contained in:
parent
9f09d81e0d
commit
af986c757a
@ -460,10 +460,7 @@ typedef struct efx_mcdi_ops_s {
|
||||
void (*emco_request_copyout)(efx_nic_t *, efx_mcdi_req_t *);
|
||||
efx_rc_t (*emco_poll_reboot)(efx_nic_t *);
|
||||
void (*emco_fini)(efx_nic_t *);
|
||||
efx_rc_t (*emco_fw_update_supported)(efx_nic_t *, boolean_t *);
|
||||
efx_rc_t (*emco_macaddr_change_supported)(efx_nic_t *, boolean_t *);
|
||||
efx_rc_t (*emco_link_control_supported)(efx_nic_t *, boolean_t *);
|
||||
efx_rc_t (*emco_mac_spoofing_supported)(efx_nic_t *, boolean_t *);
|
||||
efx_rc_t (*emco_feature_supported)(efx_nic_t *, efx_mcdi_feature_id_t, boolean_t *);
|
||||
void (*emco_read_response)(efx_nic_t *, void *, size_t, size_t);
|
||||
} efx_mcdi_ops_t;
|
||||
|
||||
|
@ -50,12 +50,7 @@ static efx_mcdi_ops_t __efx_mcdi_siena_ops = {
|
||||
siena_mcdi_request_copyout, /* emco_request_copyout */
|
||||
siena_mcdi_poll_reboot, /* emco_poll_reboot */
|
||||
siena_mcdi_fini, /* emco_fini */
|
||||
siena_mcdi_fw_update_supported, /* emco_fw_update_supported */
|
||||
siena_mcdi_macaddr_change_supported,
|
||||
/* emco_macaddr_change_supported */
|
||||
siena_mcdi_link_control_supported,
|
||||
/* emco_link_control_supported */
|
||||
NULL, /* emco_mac_spoofing_supported */
|
||||
siena_mcdi_feature_supported, /* emco_feature_supported */
|
||||
siena_mcdi_read_response, /* emco_read_response */
|
||||
};
|
||||
|
||||
@ -70,13 +65,7 @@ static efx_mcdi_ops_t __efx_mcdi_hunt_ops = {
|
||||
hunt_mcdi_request_copyout, /* emco_request_copyout */
|
||||
hunt_mcdi_poll_reboot, /* emco_poll_reboot */
|
||||
hunt_mcdi_fini, /* emco_fini */
|
||||
hunt_mcdi_fw_update_supported, /* emco_fw_update_supported */
|
||||
hunt_mcdi_macaddr_change_supported,
|
||||
/* emco_macaddr_change_supported */
|
||||
hunt_mcdi_link_control_supported,
|
||||
/* emco_link_control_supported */
|
||||
hunt_mcdi_mac_spoofing_supported,
|
||||
/* emco_mac_spoofing_supported */
|
||||
hunt_mcdi_feature_supported, /* emco_feature_supported */
|
||||
hunt_mcdi_read_response, /* emco_read_response */
|
||||
};
|
||||
|
||||
@ -1316,7 +1305,6 @@ fail1:
|
||||
return (rc);
|
||||
}
|
||||
|
||||
|
||||
__checkReturn efx_rc_t
|
||||
efx_mcdi_firmware_update_supported(
|
||||
__in efx_nic_t *enp,
|
||||
@ -1325,9 +1313,9 @@ efx_mcdi_firmware_update_supported(
|
||||
efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
|
||||
efx_rc_t rc;
|
||||
|
||||
if (emcop != NULL && emcop->emco_fw_update_supported != NULL) {
|
||||
if ((rc = emcop->emco_fw_update_supported(enp, supportedp))
|
||||
!= 0)
|
||||
if (emcop != NULL) {
|
||||
if ((rc = emcop->emco_feature_supported(enp,
|
||||
EFX_MCDI_FEATURE_FW_UPDATE, supportedp)) != 0)
|
||||
goto fail1;
|
||||
} else {
|
||||
/* Earlier devices always supported updates */
|
||||
@ -1350,9 +1338,9 @@ efx_mcdi_macaddr_change_supported(
|
||||
efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
|
||||
efx_rc_t rc;
|
||||
|
||||
if (emcop != NULL && emcop->emco_macaddr_change_supported != NULL) {
|
||||
if ((rc = emcop->emco_macaddr_change_supported(enp, supportedp))
|
||||
!= 0)
|
||||
if (emcop != NULL) {
|
||||
if ((rc = emcop->emco_feature_supported(enp,
|
||||
EFX_MCDI_FEATURE_MACADDR_CHANGE, supportedp)) != 0)
|
||||
goto fail1;
|
||||
} else {
|
||||
/* Earlier devices always supported MAC changes */
|
||||
@ -1375,9 +1363,9 @@ efx_mcdi_link_control_supported(
|
||||
efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
|
||||
efx_rc_t rc;
|
||||
|
||||
if (emcop != NULL && emcop->emco_link_control_supported != NULL) {
|
||||
if ((rc = emcop->emco_link_control_supported(enp, supportedp))
|
||||
!= 0)
|
||||
if (emcop != NULL) {
|
||||
if ((rc = emcop->emco_feature_supported(enp,
|
||||
EFX_MCDI_FEATURE_LINK_CONTROL, supportedp)) != 0)
|
||||
goto fail1;
|
||||
} else {
|
||||
/* Earlier devices always supported link control */
|
||||
@ -1400,9 +1388,9 @@ efx_mcdi_mac_spoofing_supported(
|
||||
efx_mcdi_ops_t *emcop = enp->en_mcdi.em_emcop;
|
||||
efx_rc_t rc;
|
||||
|
||||
if (emcop != NULL && emcop->emco_mac_spoofing_supported != NULL) {
|
||||
if ((rc = emcop->emco_mac_spoofing_supported(enp, supportedp))
|
||||
!= 0)
|
||||
if (emcop != NULL) {
|
||||
if ((rc = emcop->emco_feature_supported(enp,
|
||||
EFX_MCDI_FEATURE_MAC_SPOOFING, supportedp)) != 0)
|
||||
goto fail1;
|
||||
} else {
|
||||
/* Earlier devices always supported MAC spoofing */
|
||||
|
@ -386,11 +386,18 @@ efx_mcdi_get_loopback_modes(
|
||||
#define MCDI_CMD_DWORD_FIELD(_edp, _field) \
|
||||
EFX_DWORD_FIELD(*_edp, MC_CMD_ ## _field)
|
||||
|
||||
#define EFX_MCDI_HAVE_PRIVILEGE(mask, priv) \
|
||||
(((mask) & \
|
||||
(MC_CMD_PRIVILEGE_MASK_IN_GRP_ ## priv)) == \
|
||||
#define EFX_MCDI_HAVE_PRIVILEGE(mask, priv) \
|
||||
(((mask) & (MC_CMD_PRIVILEGE_MASK_IN_GRP_ ## priv)) == \
|
||||
(MC_CMD_PRIVILEGE_MASK_IN_GRP_ ## priv))
|
||||
|
||||
typedef enum efx_mcdi_feature_id_e {
|
||||
EFX_MCDI_FEATURE_FW_UPDATE = 0,
|
||||
EFX_MCDI_FEATURE_LINK_CONTROL,
|
||||
EFX_MCDI_FEATURE_MACADDR_CHANGE,
|
||||
EFX_MCDI_FEATURE_MAC_SPOOFING,
|
||||
EFX_MCDI_FEATURE_NIDS
|
||||
} efx_mcdi_feature_id_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -284,26 +284,11 @@ hunt_mcdi_poll_reboot(
|
||||
__in efx_nic_t *enp);
|
||||
|
||||
extern __checkReturn efx_rc_t
|
||||
hunt_mcdi_fw_update_supported(
|
||||
hunt_mcdi_feature_supported(
|
||||
__in efx_nic_t *enp,
|
||||
__in efx_mcdi_feature_id_t id,
|
||||
__out boolean_t *supportedp);
|
||||
|
||||
extern __checkReturn efx_rc_t
|
||||
hunt_mcdi_macaddr_change_supported(
|
||||
__in efx_nic_t *enp,
|
||||
__out boolean_t *supportedp);
|
||||
|
||||
extern __checkReturn efx_rc_t
|
||||
hunt_mcdi_link_control_supported(
|
||||
__in efx_nic_t *enp,
|
||||
__out boolean_t *supportedp);
|
||||
|
||||
extern __checkReturn efx_rc_t
|
||||
hunt_mcdi_mac_spoofing_supported(
|
||||
__in efx_nic_t *enp,
|
||||
__out boolean_t *supportedp);
|
||||
|
||||
|
||||
#endif /* EFSYS_OPT_MCDI */
|
||||
|
||||
/* NVRAM */
|
||||
@ -722,7 +707,7 @@ hunt_tx_qstats_update(
|
||||
|
||||
#define HUNT_MIN_PIO_ALLOC_SIZE (HUNT_PIOBUF_SIZE / 32)
|
||||
|
||||
#define HUNT_LEGACY_PF_PRIVILEGE_MASK \
|
||||
#define HUNT_LEGACY_PF_PRIVILEGE_MASK \
|
||||
(MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN | \
|
||||
MC_CMD_PRIVILEGE_MASK_IN_GRP_LINK | \
|
||||
MC_CMD_PRIVILEGE_MASK_IN_GRP_ONLOAD | \
|
||||
@ -735,7 +720,7 @@ hunt_tx_qstats_update(
|
||||
MC_CMD_PRIVILEGE_MASK_IN_GRP_ALL_MULTICAST | \
|
||||
MC_CMD_PRIVILEGE_MASK_IN_GRP_PROMISCUOUS)
|
||||
|
||||
#define HUNT_LEGACY_VF_PRIVILEGE_MASK 0
|
||||
#define HUNT_LEGACY_VF_PRIVILEGE_MASK 0
|
||||
|
||||
typedef uint32_t efx_piobuf_handle_t;
|
||||
|
||||
|
@ -399,94 +399,73 @@ fail1:
|
||||
}
|
||||
|
||||
__checkReturn efx_rc_t
|
||||
hunt_mcdi_fw_update_supported(
|
||||
__in efx_nic_t *enp,
|
||||
__out boolean_t *supportedp)
|
||||
{
|
||||
efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
|
||||
|
||||
EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_HUNTINGTON);
|
||||
|
||||
/*
|
||||
* Use privilege mask state at MCDI attach.
|
||||
* Admin privilege must be used prior to introduction of
|
||||
* specific flag.
|
||||
*/
|
||||
*supportedp =
|
||||
EFX_MCDI_HAVE_PRIVILEGE(encp->enc_privilege_mask, ADMIN);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
__checkReturn efx_rc_t
|
||||
hunt_mcdi_macaddr_change_supported(
|
||||
hunt_mcdi_feature_supported(
|
||||
__in efx_nic_t *enp,
|
||||
__in efx_mcdi_feature_id_t id,
|
||||
__out boolean_t *supportedp)
|
||||
{
|
||||
efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
|
||||
uint32_t privilege_mask = encp->enc_privilege_mask;
|
||||
efx_rc_t rc;
|
||||
|
||||
EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_HUNTINGTON);
|
||||
|
||||
/*
|
||||
* Use privilege mask state at MCDI attach.
|
||||
* Admin privilege must be used prior to introduction of
|
||||
* mac spoofing privilege (at v4.6), which is used up to
|
||||
* introduction of change mac spoofing privilege (at v4.7)
|
||||
*/
|
||||
*supportedp =
|
||||
EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, CHANGE_MAC) ||
|
||||
EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING) ||
|
||||
EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
|
||||
|
||||
switch (id) {
|
||||
case EFX_MCDI_FEATURE_FW_UPDATE:
|
||||
/*
|
||||
* Admin privilege must be used prior to introduction of
|
||||
* specific flag.
|
||||
*/
|
||||
*supportedp =
|
||||
EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
|
||||
break;
|
||||
case EFX_MCDI_FEATURE_LINK_CONTROL:
|
||||
/*
|
||||
* Admin privilege used prior to introduction of
|
||||
* specific flag.
|
||||
*/
|
||||
*supportedp =
|
||||
EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, LINK) ||
|
||||
EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
|
||||
break;
|
||||
case EFX_MCDI_FEATURE_MACADDR_CHANGE:
|
||||
/*
|
||||
* Admin privilege must be used prior to introduction of
|
||||
* mac spoofing privilege (at v4.6), which is used up to
|
||||
* introduction of change mac spoofing privilege (at v4.7)
|
||||
*/
|
||||
*supportedp =
|
||||
EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, CHANGE_MAC) ||
|
||||
EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING) ||
|
||||
EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
|
||||
break;
|
||||
case EFX_MCDI_FEATURE_MAC_SPOOFING:
|
||||
/*
|
||||
* Admin privilege must be used prior to introduction of
|
||||
* mac spoofing privilege (at v4.6), which is used up to
|
||||
* introduction of mac spoofing TX privilege (at v4.7)
|
||||
*/
|
||||
*supportedp =
|
||||
EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING_TX) ||
|
||||
EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING) ||
|
||||
EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
|
||||
break;
|
||||
default:
|
||||
rc = ENOTSUP;
|
||||
goto fail1;
|
||||
break;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
__checkReturn efx_rc_t
|
||||
hunt_mcdi_mac_spoofing_supported(
|
||||
__in efx_nic_t *enp,
|
||||
__out boolean_t *supportedp)
|
||||
{
|
||||
efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
|
||||
uint32_t privilege_mask = encp->enc_privilege_mask;
|
||||
fail1:
|
||||
EFSYS_PROBE1(fail1, efx_rc_t, rc);
|
||||
|
||||
EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_HUNTINGTON);
|
||||
|
||||
/*
|
||||
* Use privilege mask state at MCDI attach.
|
||||
* Admin privilege must be used prior to introduction of
|
||||
* mac spoofing privilege (at v4.6), which is used up to
|
||||
* introduction of mac spoofing TX privilege (at v4.7)
|
||||
*/
|
||||
*supportedp =
|
||||
EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING_TX) ||
|
||||
EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING) ||
|
||||
EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
__checkReturn efx_rc_t
|
||||
hunt_mcdi_link_control_supported(
|
||||
__in efx_nic_t *enp,
|
||||
__out boolean_t *supportedp)
|
||||
{
|
||||
efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
|
||||
uint32_t privilege_mask = encp->enc_privilege_mask;
|
||||
|
||||
EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_HUNTINGTON);
|
||||
|
||||
/*
|
||||
* Use privilege mask state at MCDI attach.
|
||||
* Admin privilege used prior to introduction of
|
||||
* specific flag.
|
||||
*/
|
||||
*supportedp =
|
||||
EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, LINK) ||
|
||||
EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
|
||||
|
||||
return (0);
|
||||
return (rc);
|
||||
}
|
||||
|
||||
#endif /* EFSYS_OPT_MCDI */
|
||||
|
@ -146,18 +146,9 @@ siena_mcdi_fini(
|
||||
__in efx_nic_t *enp);
|
||||
|
||||
extern __checkReturn efx_rc_t
|
||||
siena_mcdi_fw_update_supported(
|
||||
__in efx_nic_t *enp,
|
||||
__out boolean_t *supportedp);
|
||||
|
||||
extern __checkReturn efx_rc_t
|
||||
siena_mcdi_macaddr_change_supported(
|
||||
__in efx_nic_t *enp,
|
||||
__out boolean_t *supportedp);
|
||||
|
||||
extern __checkReturn efx_rc_t
|
||||
siena_mcdi_link_control_supported(
|
||||
siena_mcdi_feature_supported(
|
||||
__in efx_nic_t *enp,
|
||||
__in efx_mcdi_feature_id_t id,
|
||||
__out boolean_t *supportedp);
|
||||
|
||||
#endif /* EFSYS_OPT_MCDI */
|
||||
|
@ -329,39 +329,34 @@ siena_mcdi_fini(
|
||||
}
|
||||
|
||||
__checkReturn efx_rc_t
|
||||
siena_mcdi_fw_update_supported(
|
||||
siena_mcdi_feature_supported(
|
||||
__in efx_nic_t *enp,
|
||||
__in efx_mcdi_feature_id_t id,
|
||||
__out boolean_t *supportedp)
|
||||
{
|
||||
efx_rc_t rc;
|
||||
|
||||
EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_SIENA);
|
||||
|
||||
*supportedp = B_TRUE;
|
||||
switch (id) {
|
||||
case EFX_MCDI_FEATURE_FW_UPDATE:
|
||||
case EFX_MCDI_FEATURE_LINK_CONTROL:
|
||||
case EFX_MCDI_FEATURE_MACADDR_CHANGE:
|
||||
case EFX_MCDI_FEATURE_MAC_SPOOFING:
|
||||
*supportedp = B_TRUE;
|
||||
break;
|
||||
default:
|
||||
rc = ENOTSUP;
|
||||
goto fail1;
|
||||
break;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
__checkReturn efx_rc_t
|
||||
siena_mcdi_macaddr_change_supported(
|
||||
__in efx_nic_t *enp,
|
||||
__out boolean_t *supportedp)
|
||||
{
|
||||
EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_SIENA);
|
||||
fail1:
|
||||
EFSYS_PROBE1(fail1, efx_rc_t, rc);
|
||||
|
||||
*supportedp = B_TRUE;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
__checkReturn efx_rc_t
|
||||
siena_mcdi_link_control_supported(
|
||||
__in efx_nic_t *enp,
|
||||
__out boolean_t *supportedp)
|
||||
{
|
||||
EFSYS_ASSERT3U(enp->en_family, ==, EFX_FAMILY_SIENA);
|
||||
|
||||
*supportedp = B_TRUE;
|
||||
|
||||
return (0);
|
||||
return (rc);
|
||||
}
|
||||
|
||||
#endif /* EFSYS_OPT_SIENA && EFSYS_OPT_MCDI */
|
||||
|
Loading…
x
Reference in New Issue
Block a user