sfxge: simplify privilege checks with macro

Submitted by:   Richard Houldsworth <rhouldsworth at solarflare.com>
Sponsored by:   Solarflare Communications, Inc.
MFC after:      2 days
Differential Revision: https://reviews.freebsd.org/D4455
This commit is contained in:
arybchik 2015-12-10 07:17:46 +00:00
parent 2d559ff67c
commit b12f63b23f
2 changed files with 15 additions and 19 deletions

View File

@ -386,6 +386,11 @@ efx_mcdi_get_loopback_modes(
#define MCDI_CMD_DWORD_FIELD(_edp, _field) \ #define MCDI_CMD_DWORD_FIELD(_edp, _field) \
EFX_DWORD_FIELD(*_edp, MC_CMD_ ## _field) EFX_DWORD_FIELD(*_edp, MC_CMD_ ## _field)
#define EFX_MCDI_HAVE_PRIVILEGE(mask, priv) \
(((mask) & \
(MC_CMD_PRIVILEGE_MASK_IN_GRP_ ## priv)) == \
(MC_CMD_PRIVILEGE_MASK_IN_GRP_ ## priv))
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -412,9 +412,8 @@ hunt_mcdi_fw_update_supported(
* Admin privilege must be used prior to introduction of * Admin privilege must be used prior to introduction of
* specific flag. * specific flag.
*/ */
*supportedp = (encp->enc_privilege_mask & *supportedp =
MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN) EFX_MCDI_HAVE_PRIVILEGE(encp->enc_privilege_mask, ADMIN);
== MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN;
return (0); return (0);
} }
@ -436,12 +435,9 @@ hunt_mcdi_macaddr_change_supported(
* introduction of change mac spoofing privilege (at v4.7) * introduction of change mac spoofing privilege (at v4.7)
*/ */
*supportedp = *supportedp =
((privilege_mask & MC_CMD_PRIVILEGE_MASK_IN_GRP_CHANGE_MAC) == EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, CHANGE_MAC) ||
MC_CMD_PRIVILEGE_MASK_IN_GRP_CHANGE_MAC) || EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING) ||
((privilege_mask & MC_CMD_PRIVILEGE_MASK_IN_GRP_MAC_SPOOFING) == EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
MC_CMD_PRIVILEGE_MASK_IN_GRP_MAC_SPOOFING) ||
((privilege_mask & MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN) ==
MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN);
return (0); return (0);
} }
@ -463,12 +459,9 @@ hunt_mcdi_mac_spoofing_supported(
* introduction of mac spoofing TX privilege (at v4.7) * introduction of mac spoofing TX privilege (at v4.7)
*/ */
*supportedp = *supportedp =
((privilege_mask & MC_CMD_PRIVILEGE_MASK_IN_GRP_MAC_SPOOFING_TX) == EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING_TX) ||
MC_CMD_PRIVILEGE_MASK_IN_GRP_MAC_SPOOFING_TX) || EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, MAC_SPOOFING) ||
((privilege_mask & MC_CMD_PRIVILEGE_MASK_IN_GRP_MAC_SPOOFING) == EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
MC_CMD_PRIVILEGE_MASK_IN_GRP_MAC_SPOOFING) ||
((privilege_mask & MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN) ==
MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN);
return (0); return (0);
} }
@ -490,10 +483,8 @@ hunt_mcdi_link_control_supported(
* specific flag. * specific flag.
*/ */
*supportedp = *supportedp =
((privilege_mask & MC_CMD_PRIVILEGE_MASK_IN_GRP_LINK) == EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, LINK) ||
MC_CMD_PRIVILEGE_MASK_IN_GRP_LINK) || EFX_MCDI_HAVE_PRIVILEGE(privilege_mask, ADMIN);
((privilege_mask & MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN) ==
MC_CMD_PRIVILEGE_MASK_IN_GRP_ADMIN);
return (0); return (0);
} }