Commit 7e1af4d6 authored by Wei Fang's avatar Wei Fang Committed by Jakub Kicinski
Browse files

net: enetc: make enetc_set_rss_key() reusable



Since the offset of the RSS key registers of i.MX95 ENETC is different
from that of LS1028A, so add enetc_get_rss_key_base() to get the base
offset for the different chips, so that enetc_set_rss_key() can be
reused for this trivial thing.

Signed-off-by: default avatarWei Fang <wei.fang@nxp.com>
Reviewed-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Link: https://patch.msgid.link/20250506080735.3444381-8-wei.fang@nxp.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 66b3fb00
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -537,7 +537,7 @@ int enetc_set_mac_flt_entry(struct enetc_si *si, int index,
int enetc_clear_mac_flt_entry(struct enetc_si *si, int index);
int enetc_set_fs_entry(struct enetc_si *si, struct enetc_cmd_rfse *rfse,
		       int index);
void enetc_set_rss_key(struct enetc_hw *hw, const u8 *bytes);
void enetc_set_rss_key(struct enetc_si *si, const u8 *bytes);
int enetc_get_rss_table(struct enetc_si *si, u32 *table, int count);
int enetc_set_rss_table(struct enetc_si *si, const u32 *table, int count);
int enetc_send_cmd(struct enetc_si *si, struct enetc_cbd *cbd);
+1 −19
Original line number Diff line number Diff line
@@ -418,24 +418,6 @@ static void enetc4_set_trx_frame_size(struct enetc_pf *pf)
	enetc4_pf_reset_tc_msdu(&si->hw);
}

static void enetc4_set_rss_key(struct enetc_hw *hw, const u8 *bytes)
{
	int i;

	for (i = 0; i < ENETC_RSSHASH_KEY_SIZE / 4; i++)
		enetc_port_wr(hw, ENETC4_PRSSKR(i), ((u32 *)bytes)[i]);
}

static void enetc4_set_default_rss_key(struct enetc_pf *pf)
{
	u8 hash_key[ENETC_RSSHASH_KEY_SIZE] = {0};
	struct enetc_hw *hw = &pf->si->hw;

	/* set up hash key */
	get_random_bytes(hash_key, ENETC_RSSHASH_KEY_SIZE);
	enetc4_set_rss_key(hw, hash_key);
}

static void enetc4_enable_trx(struct enetc_pf *pf)
{
	struct enetc_hw *hw = &pf->si->hw;
@@ -448,7 +430,7 @@ static void enetc4_configure_port(struct enetc_pf *pf)
{
	enetc4_configure_port_si(pf);
	enetc4_set_trx_frame_size(pf);
	enetc4_set_default_rss_key(pf);
	enetc_set_default_rss_key(pf);
	enetc4_enable_trx(pf);
}

+14 −5
Original line number Diff line number Diff line
@@ -677,6 +677,14 @@ static u32 enetc_get_rxfh_indir_size(struct net_device *ndev)
	return priv->si->num_rss;
}

static int enetc_get_rss_key_base(struct enetc_si *si)
{
	if (is_enetc_rev1(si))
		return ENETC_PRSSK(0);

	return ENETC4_PRSSKR(0);
}

static int enetc_get_rxfh(struct net_device *ndev,
			  struct ethtool_rxfh_param *rxfh)
{
@@ -701,12 +709,14 @@ static int enetc_get_rxfh(struct net_device *ndev,
	return err;
}

void enetc_set_rss_key(struct enetc_hw *hw, const u8 *bytes)
void enetc_set_rss_key(struct enetc_si *si, const u8 *bytes)
{
	int base = enetc_get_rss_key_base(si);
	struct enetc_hw *hw = &si->hw;
	int i;

	for (i = 0; i < ENETC_RSSHASH_KEY_SIZE / 4; i++)
		enetc_port_wr(hw, ENETC_PRSSK(i), ((u32 *)bytes)[i]);
		enetc_port_wr(hw, base + i * 4, ((u32 *)bytes)[i]);
}
EXPORT_SYMBOL_GPL(enetc_set_rss_key);

@@ -716,12 +726,11 @@ static int enetc_set_rxfh(struct net_device *ndev,
{
	struct enetc_ndev_priv *priv = netdev_priv(ndev);
	struct enetc_si *si = priv->si;
	struct enetc_hw *hw = &si->hw;
	int err = 0;

	/* set hash key, if PF */
	if (rxfh->key && hw->port)
		enetc_set_rss_key(hw, rxfh->key);
	if (rxfh->key && enetc_si_is_pf(si))
		enetc_set_rss_key(si, rxfh->key);

	/* set RSS table */
	if (rxfh->indir)
+1 −3
Original line number Diff line number Diff line
@@ -515,7 +515,6 @@ static void enetc_mac_enable(struct enetc_si *si, bool en)

static void enetc_configure_port(struct enetc_pf *pf)
{
	u8 hash_key[ENETC_RSSHASH_KEY_SIZE];
	struct enetc_hw *hw = &pf->si->hw;

	enetc_configure_port_mac(pf->si);
@@ -523,8 +522,7 @@ static void enetc_configure_port(struct enetc_pf *pf)
	enetc_port_si_configure(pf->si);

	/* set up hash key */
	get_random_bytes(hash_key, ENETC_RSSHASH_KEY_SIZE);
	enetc_set_rss_key(hw, hash_key);
	enetc_set_default_rss_key(pf);

	/* split up RFS entries */
	enetc_port_assign_rfs_entries(pf->si);
+10 −0
Original line number Diff line number Diff line
@@ -341,5 +341,15 @@ void enetc_phylink_destroy(struct enetc_ndev_priv *priv)
}
EXPORT_SYMBOL_GPL(enetc_phylink_destroy);

void enetc_set_default_rss_key(struct enetc_pf *pf)
{
	u8 hash_key[ENETC_RSSHASH_KEY_SIZE] = {0};

	/* set up hash key */
	get_random_bytes(hash_key, ENETC_RSSHASH_KEY_SIZE);
	enetc_set_rss_key(pf->si, hash_key);
}
EXPORT_SYMBOL_GPL(enetc_set_default_rss_key);

MODULE_DESCRIPTION("NXP ENETC PF common functionality driver");
MODULE_LICENSE("Dual BSD/GPL");
Loading