Skip to content

Commit 769c500

Browse files
aabodunrinanguy11
authored andcommitted
ice: Add advanced power mgmt for WoL
Add callbacks needed to support advanced power management for Wake on LAN. Also make ice_pf_state_is_nominal function available for all configurations not just CONFIG_PCI_IOV. Signed-off-by: Akeem G Abodunrin <[email protected]> Signed-off-by: Jesse Brandeburg <[email protected]> Tested-by: Andrew Bowers <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 81aed64 commit 769c500

File tree

10 files changed

+458
-29
lines changed

10 files changed

+458
-29
lines changed

drivers/net/ethernet/intel/ice/ice.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ struct ice_pf {
423423
u16 empr_count; /* EMP reset count */
424424
u16 pfr_count; /* PF reset count */
425425

426+
u8 wol_ena : 1; /* software state of WoL */
427+
u32 wakeup_reason; /* last wakeup reason */
426428
struct ice_hw_port_stats stats;
427429
struct ice_hw_port_stats stats_prev;
428430
struct ice_hw hw;
@@ -568,6 +570,7 @@ int ice_schedule_reset(struct ice_pf *pf, enum ice_reset_req reset);
568570
void ice_print_link_msg(struct ice_vsi *vsi, bool isup);
569571
const char *ice_stat_str(enum ice_status stat_err);
570572
const char *ice_aq_str(enum ice_aq_err aq_err);
573+
bool ice_is_wol_supported(struct ice_pf *pf);
571574
int
572575
ice_fdir_write_fltr(struct ice_pf *pf, struct ice_fdir_fltr *input, bool add,
573576
bool is_tun);

drivers/net/ethernet/intel/ice/ice_ethtool.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3322,6 +3322,58 @@ static int ice_set_channels(struct net_device *dev, struct ethtool_channels *ch)
33223322
return 0;
33233323
}
33243324

3325+
/**
3326+
* ice_get_wol - get current Wake on LAN configuration
3327+
* @netdev: network interface device structure
3328+
* @wol: Ethtool structure to retrieve WoL settings
3329+
*/
3330+
static void ice_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
3331+
{
3332+
struct ice_netdev_priv *np = netdev_priv(netdev);
3333+
struct ice_pf *pf = np->vsi->back;
3334+
3335+
if (np->vsi->type != ICE_VSI_PF)
3336+
netdev_warn(netdev, "Wake on LAN is not supported on this interface!\n");
3337+
3338+
/* Get WoL settings based on the HW capability */
3339+
if (ice_is_wol_supported(pf)) {
3340+
wol->supported = WAKE_MAGIC;
3341+
wol->wolopts = pf->wol_ena ? WAKE_MAGIC : 0;
3342+
} else {
3343+
wol->supported = 0;
3344+
wol->wolopts = 0;
3345+
}
3346+
}
3347+
3348+
/**
3349+
* ice_set_wol - set Wake on LAN on supported device
3350+
* @netdev: network interface device structure
3351+
* @wol: Ethtool structure to set WoL
3352+
*/
3353+
static int ice_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
3354+
{
3355+
struct ice_netdev_priv *np = netdev_priv(netdev);
3356+
struct ice_vsi *vsi = np->vsi;
3357+
struct ice_pf *pf = vsi->back;
3358+
3359+
if (vsi->type != ICE_VSI_PF || !ice_is_wol_supported(pf))
3360+
return -EOPNOTSUPP;
3361+
3362+
/* only magic packet is supported */
3363+
if (wol->wolopts && wol->wolopts != WAKE_MAGIC)
3364+
return -EOPNOTSUPP;
3365+
3366+
/* Set WoL only if there is a new value */
3367+
if (pf->wol_ena != !!wol->wolopts) {
3368+
pf->wol_ena = !!wol->wolopts;
3369+
device_set_wakeup_enable(ice_pf_to_dev(pf), pf->wol_ena);
3370+
netdev_dbg(netdev, "WoL magic packet %sabled\n",
3371+
pf->wol_ena ? "en" : "dis");
3372+
}
3373+
3374+
return 0;
3375+
}
3376+
33253377
enum ice_container_type {
33263378
ICE_RX_CONTAINER,
33273379
ICE_TX_CONTAINER,
@@ -3805,6 +3857,8 @@ static const struct ethtool_ops ice_ethtool_ops = {
38053857
.get_drvinfo = ice_get_drvinfo,
38063858
.get_regs_len = ice_get_regs_len,
38073859
.get_regs = ice_get_regs,
3860+
.get_wol = ice_get_wol,
3861+
.set_wol = ice_set_wol,
38083862
.get_msglevel = ice_get_msglevel,
38093863
.set_msglevel = ice_set_msglevel,
38103864
.self_test = ice_self_test,
@@ -3847,6 +3901,8 @@ static const struct ethtool_ops ice_ethtool_safe_mode_ops = {
38473901
.get_drvinfo = ice_get_drvinfo,
38483902
.get_regs_len = ice_get_regs_len,
38493903
.get_regs = ice_get_regs,
3904+
.get_wol = ice_get_wol,
3905+
.set_wol = ice_set_wol,
38503906
.get_msglevel = ice_get_msglevel,
38513907
.set_msglevel = ice_set_msglevel,
38523908
.get_link = ethtool_op_get_link,

drivers/net/ethernet/intel/ice/ice_hw_autogen.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,15 @@
367367
#define VSIQF_FD_CNT_FD_GCNT_M ICE_M(0x3FFF, 0)
368368
#define VSIQF_HKEY_MAX_INDEX 12
369369
#define VSIQF_HLUT_MAX_INDEX 15
370+
#define PFPM_APM 0x000B8080
371+
#define PFPM_APM_APME_M BIT(0)
372+
#define PFPM_WUFC 0x0009DC00
373+
#define PFPM_WUFC_MAG_M BIT(1)
374+
#define PFPM_WUS 0x0009DB80
375+
#define PFPM_WUS_LNKC_M BIT(0)
376+
#define PFPM_WUS_MAG_M BIT(1)
377+
#define PFPM_WUS_MNG_M BIT(3)
378+
#define PFPM_WUS_FW_RST_WK_M BIT(31)
370379
#define VFINT_DYN_CTLN(_i) (0x00003800 + ((_i) * 4))
371380
#define VFINT_DYN_CTLN_CLEARPBA_M BIT(1)
372381
#define PRTRPB_RDPC 0x000AC260

drivers/net/ethernet/intel/ice/ice_lib.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,30 @@ static void ice_vsi_set_rss_flow_fld(struct ice_vsi *vsi)
14671467
vsi_num, ice_stat_str(status));
14681468
}
14691469

1470+
/**
1471+
* ice_pf_state_is_nominal - checks the PF for nominal state
1472+
* @pf: pointer to PF to check
1473+
*
1474+
* Check the PF's state for a collection of bits that would indicate
1475+
* the PF is in a state that would inhibit normal operation for
1476+
* driver functionality.
1477+
*
1478+
* Returns true if PF is in a nominal state, false otherwise
1479+
*/
1480+
bool ice_pf_state_is_nominal(struct ice_pf *pf)
1481+
{
1482+
DECLARE_BITMAP(check_bits, __ICE_STATE_NBITS) = { 0 };
1483+
1484+
if (!pf)
1485+
return false;
1486+
1487+
bitmap_set(check_bits, 0, __ICE_STATE_NOMINAL_CHECK_BITS);
1488+
if (bitmap_intersects(pf->state, check_bits, __ICE_STATE_NBITS))
1489+
return false;
1490+
1491+
return true;
1492+
}
1493+
14701494
/**
14711495
* ice_update_eth_stats - Update VSI-specific ethernet statistics counters
14721496
* @vsi: the VSI to be updated

drivers/net/ethernet/intel/ice/ice_lib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
const char *ice_vsi_type_str(enum ice_vsi_type vsi_type);
1010

11+
bool ice_pf_state_is_nominal(struct ice_pf *pf);
12+
1113
void ice_update_eth_stats(struct ice_vsi *vsi);
1214

1315
int ice_vsi_cfg_rxqs(struct ice_vsi *vsi);

0 commit comments

Comments
 (0)