Skip to content

Commit 43e8fe9

Browse files
BryanW11731-MCHPdavem330
authored andcommitted
lan743x: Add RSS support
Implement RSS support Signed-off-by: Bryan Whitehead <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c9cf96b commit 43e8fe9

File tree

3 files changed

+171
-0
lines changed

3 files changed

+171
-0
lines changed

drivers/net/ethernet/microchip/lan743x_ethtool.c

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,133 @@ static int lan743x_ethtool_get_sset_count(struct net_device *netdev, int sset)
415415
}
416416
}
417417

418+
static int lan743x_ethtool_get_rxnfc(struct net_device *netdev,
419+
struct ethtool_rxnfc *rxnfc,
420+
u32 *rule_locs)
421+
{
422+
switch (rxnfc->cmd) {
423+
case ETHTOOL_GRXFH:
424+
rxnfc->data = 0;
425+
switch (rxnfc->flow_type) {
426+
case TCP_V4_FLOW:case UDP_V4_FLOW:
427+
case TCP_V6_FLOW:case UDP_V6_FLOW:
428+
rxnfc->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
429+
/* fall through */
430+
case IPV4_FLOW: case IPV6_FLOW:
431+
rxnfc->data |= RXH_IP_SRC | RXH_IP_DST;
432+
return 0;
433+
}
434+
break;
435+
case ETHTOOL_GRXRINGS:
436+
rxnfc->data = LAN743X_USED_RX_CHANNELS;
437+
return 0;
438+
}
439+
return -EOPNOTSUPP;
440+
}
441+
442+
static u32 lan743x_ethtool_get_rxfh_key_size(struct net_device *netdev)
443+
{
444+
return 40;
445+
}
446+
447+
static u32 lan743x_ethtool_get_rxfh_indir_size(struct net_device *netdev)
448+
{
449+
return 128;
450+
}
451+
452+
static int lan743x_ethtool_get_rxfh(struct net_device *netdev,
453+
u32 *indir, u8 *key, u8 *hfunc)
454+
{
455+
struct lan743x_adapter *adapter = netdev_priv(netdev);
456+
457+
if (indir) {
458+
int dw_index;
459+
int byte_index = 0;
460+
461+
for (dw_index = 0; dw_index < 32; dw_index++) {
462+
u32 four_entries =
463+
lan743x_csr_read(adapter, RFE_INDX(dw_index));
464+
465+
byte_index = dw_index << 2;
466+
indir[byte_index + 0] =
467+
((four_entries >> 0) & 0x000000FF);
468+
indir[byte_index + 1] =
469+
((four_entries >> 8) & 0x000000FF);
470+
indir[byte_index + 2] =
471+
((four_entries >> 16) & 0x000000FF);
472+
indir[byte_index + 3] =
473+
((four_entries >> 24) & 0x000000FF);
474+
}
475+
}
476+
if (key) {
477+
int dword_index;
478+
int byte_index = 0;
479+
480+
for (dword_index = 0; dword_index < 10; dword_index++) {
481+
u32 four_entries =
482+
lan743x_csr_read(adapter,
483+
RFE_HASH_KEY(dword_index));
484+
485+
byte_index = dword_index << 2;
486+
key[byte_index + 0] =
487+
((four_entries >> 0) & 0x000000FF);
488+
key[byte_index + 1] =
489+
((four_entries >> 8) & 0x000000FF);
490+
key[byte_index + 2] =
491+
((four_entries >> 16) & 0x000000FF);
492+
key[byte_index + 3] =
493+
((four_entries >> 24) & 0x000000FF);
494+
}
495+
}
496+
if (hfunc)
497+
(*hfunc) = ETH_RSS_HASH_TOP;
498+
return 0;
499+
}
500+
501+
static int lan743x_ethtool_set_rxfh(struct net_device *netdev,
502+
const u32 *indir, const u8 *key,
503+
const u8 hfunc)
504+
{
505+
struct lan743x_adapter *adapter = netdev_priv(netdev);
506+
507+
if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
508+
return -EOPNOTSUPP;
509+
510+
if (indir) {
511+
u32 indir_value = 0;
512+
int dword_index = 0;
513+
int byte_index = 0;
514+
515+
for (dword_index = 0; dword_index < 32; dword_index++) {
516+
byte_index = dword_index << 2;
517+
indir_value =
518+
(((indir[byte_index + 0] & 0x000000FF) << 0) |
519+
((indir[byte_index + 1] & 0x000000FF) << 8) |
520+
((indir[byte_index + 2] & 0x000000FF) << 16) |
521+
((indir[byte_index + 3] & 0x000000FF) << 24));
522+
lan743x_csr_write(adapter, RFE_INDX(dword_index),
523+
indir_value);
524+
}
525+
}
526+
if (key) {
527+
int dword_index = 0;
528+
int byte_index = 0;
529+
u32 key_value = 0;
530+
531+
for (dword_index = 0; dword_index < 10; dword_index++) {
532+
byte_index = dword_index << 2;
533+
key_value =
534+
((((u32)(key[byte_index + 0])) << 0) |
535+
(((u32)(key[byte_index + 1])) << 8) |
536+
(((u32)(key[byte_index + 2])) << 16) |
537+
(((u32)(key[byte_index + 3])) << 24));
538+
lan743x_csr_write(adapter, RFE_HASH_KEY(dword_index),
539+
key_value);
540+
}
541+
}
542+
return 0;
543+
}
544+
418545
static int lan743x_ethtool_get_eee(struct net_device *netdev,
419546
struct ethtool_eee *eee)
420547
{
@@ -553,6 +680,11 @@ const struct ethtool_ops lan743x_ethtool_ops = {
553680
.get_strings = lan743x_ethtool_get_strings,
554681
.get_ethtool_stats = lan743x_ethtool_get_ethtool_stats,
555682
.get_sset_count = lan743x_ethtool_get_sset_count,
683+
.get_rxnfc = lan743x_ethtool_get_rxnfc,
684+
.get_rxfh_key_size = lan743x_ethtool_get_rxfh_key_size,
685+
.get_rxfh_indir_size = lan743x_ethtool_get_rxfh_indir_size,
686+
.get_rxfh = lan743x_ethtool_get_rxfh,
687+
.set_rxfh = lan743x_ethtool_set_rxfh,
556688
.get_eee = lan743x_ethtool_get_eee,
557689
.set_eee = lan743x_ethtool_set_eee,
558690
.get_link_ksettings = phy_ethtool_get_link_ksettings,

drivers/net/ethernet/microchip/lan743x_main.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,24 @@ static int lan743x_phy_open(struct lan743x_adapter *adapter)
10251025
return ret;
10261026
}
10271027

1028+
static void lan743x_rfe_open(struct lan743x_adapter *adapter)
1029+
{
1030+
lan743x_csr_write(adapter, RFE_RSS_CFG,
1031+
RFE_RSS_CFG_UDP_IPV6_EX_ |
1032+
RFE_RSS_CFG_TCP_IPV6_EX_ |
1033+
RFE_RSS_CFG_IPV6_EX_ |
1034+
RFE_RSS_CFG_UDP_IPV6_ |
1035+
RFE_RSS_CFG_TCP_IPV6_ |
1036+
RFE_RSS_CFG_IPV6_ |
1037+
RFE_RSS_CFG_UDP_IPV4_ |
1038+
RFE_RSS_CFG_TCP_IPV4_ |
1039+
RFE_RSS_CFG_IPV4_ |
1040+
RFE_RSS_CFG_VALID_HASH_BITS_ |
1041+
RFE_RSS_CFG_RSS_QUEUE_ENABLE_ |
1042+
RFE_RSS_CFG_RSS_HASH_STORE_ |
1043+
RFE_RSS_CFG_RSS_ENABLE_);
1044+
}
1045+
10281046
static void lan743x_rfe_update_mac_address(struct lan743x_adapter *adapter)
10291047
{
10301048
u8 *mac_addr;
@@ -2419,6 +2437,8 @@ static int lan743x_netdev_open(struct net_device *netdev)
24192437
if (ret)
24202438
goto close_mac;
24212439

2440+
lan743x_rfe_open(adapter);
2441+
24222442
for (index = 0; index < LAN743X_USED_RX_CHANNELS; index++) {
24232443
ret = lan743x_rx_open(&adapter->rx[index]);
24242444
if (ret)

drivers/net/ethernet/microchip/lan743x_main.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,25 @@
166166
#define RFE_CTL_MCAST_HASH_ BIT(3)
167167
#define RFE_CTL_DA_PERFECT_ BIT(1)
168168

169+
#define RFE_RSS_CFG (0x554)
170+
#define RFE_RSS_CFG_UDP_IPV6_EX_ BIT(16)
171+
#define RFE_RSS_CFG_TCP_IPV6_EX_ BIT(15)
172+
#define RFE_RSS_CFG_IPV6_EX_ BIT(14)
173+
#define RFE_RSS_CFG_UDP_IPV6_ BIT(13)
174+
#define RFE_RSS_CFG_TCP_IPV6_ BIT(12)
175+
#define RFE_RSS_CFG_IPV6_ BIT(11)
176+
#define RFE_RSS_CFG_UDP_IPV4_ BIT(10)
177+
#define RFE_RSS_CFG_TCP_IPV4_ BIT(9)
178+
#define RFE_RSS_CFG_IPV4_ BIT(8)
179+
#define RFE_RSS_CFG_VALID_HASH_BITS_ (0x000000E0)
180+
#define RFE_RSS_CFG_RSS_QUEUE_ENABLE_ BIT(2)
181+
#define RFE_RSS_CFG_RSS_HASH_STORE_ BIT(1)
182+
#define RFE_RSS_CFG_RSS_ENABLE_ BIT(0)
183+
184+
#define RFE_HASH_KEY(index) (0x558 + (index << 2))
185+
186+
#define RFE_INDX(index) (0x580 + (index << 2))
187+
169188
#define MAC_WUCSR2 (0x600)
170189

171190
#define INT_STS (0x780)

0 commit comments

Comments
 (0)