Skip to content

Commit 79c57bf

Browse files
committed
Merge branch 'enetc-Support-extended-BD-rings-at-runtime'
Claudiu Manoil says: ==================== enetc: Support extended BD rings at runtime First two patches are just misc code cleanup. The 3rd patch prepares the Rx BD processing code to be extended to processing both normal and extended BDs. The last one adds extended Rx BD support for timestamping without the need of a static config. Finally, the config option FSL_ENETC_HW_TIMESTAMPING can be dropped. Care was taken not to impact non-timestamping usecases. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 1e09e58 + 434ceba commit 79c57bf

File tree

6 files changed

+88
-61
lines changed

6 files changed

+88
-61
lines changed

drivers/net/ethernet/freescale/enetc/Kconfig

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,6 @@ config FSL_ENETC_PTP_CLOCK
4242

4343
If compiled as module (M), the module name is fsl-enetc-ptp.
4444

45-
config FSL_ENETC_HW_TIMESTAMPING
46-
bool "ENETC hardware timestamping support"
47-
depends on FSL_ENETC || FSL_ENETC_VF
48-
help
49-
Enable hardware timestamping support on the Ethernet packets
50-
using the SO_TIMESTAMPING API. Because the RX BD ring dynamic
51-
allocation has not been supported and it is too expensive to use
52-
extended RX BDs if timestamping is not used, this option enables
53-
extended RX BDs in order to support hardware timestamping.
54-
5545
config FSL_ENETC_QOS
5646
bool "ENETC hardware Time-sensitive Network support"
5747
depends on (FSL_ENETC || FSL_ENETC_VF) && (NET_SCH_TAPRIO || NET_SCH_CBS)

drivers/net/ethernet/freescale/enetc/enetc.c

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ static int enetc_refill_rx_ring(struct enetc_bdr *rx_ring, const int buff_cnt)
451451

452452
i = rx_ring->next_to_use;
453453
rx_swbd = &rx_ring->rx_swbd[i];
454-
rxbd = ENETC_RXBD(*rx_ring, i);
454+
rxbd = enetc_rxbd(rx_ring, i);
455455

456456
for (j = 0; j < buff_cnt; j++) {
457457
/* try reuse page */
@@ -468,13 +468,12 @@ static int enetc_refill_rx_ring(struct enetc_bdr *rx_ring, const int buff_cnt)
468468
/* clear 'R" as well */
469469
rxbd->r.lstatus = 0;
470470

471+
rxbd = enetc_rxbd_next(rx_ring, rxbd, i);
471472
rx_swbd++;
472-
rxbd++;
473473
i++;
474474
if (unlikely(i == rx_ring->bd_count)) {
475475
i = 0;
476476
rx_swbd = rx_ring->rx_swbd;
477-
rxbd = ENETC_RXBD(*rx_ring, 0);
478477
}
479478
}
480479

@@ -488,7 +487,7 @@ static int enetc_refill_rx_ring(struct enetc_bdr *rx_ring, const int buff_cnt)
488487
return j;
489488
}
490489

491-
#ifdef CONFIG_FSL_ENETC_HW_TIMESTAMPING
490+
#ifdef CONFIG_FSL_ENETC_PTP_CLOCK
492491
static void enetc_get_rx_tstamp(struct net_device *ndev,
493492
union enetc_rx_bd *rxbd,
494493
struct sk_buff *skb)
@@ -502,7 +501,8 @@ static void enetc_get_rx_tstamp(struct net_device *ndev,
502501
if (le16_to_cpu(rxbd->r.flags) & ENETC_RXBD_FLAG_TSTMP) {
503502
lo = enetc_rd(hw, ENETC_SICTR0);
504503
hi = enetc_rd(hw, ENETC_SICTR1);
505-
tstamp_lo = le32_to_cpu(rxbd->r.tstamp);
504+
rxbd = enetc_rxbd_ext(rxbd);
505+
tstamp_lo = le32_to_cpu(rxbd->ext.tstamp);
506506
if (lo <= tstamp_lo)
507507
hi -= 1;
508508

@@ -516,7 +516,7 @@ static void enetc_get_rx_tstamp(struct net_device *ndev,
516516
static void enetc_get_offloads(struct enetc_bdr *rx_ring,
517517
union enetc_rx_bd *rxbd, struct sk_buff *skb)
518518
{
519-
#ifdef CONFIG_FSL_ENETC_HW_TIMESTAMPING
519+
#ifdef CONFIG_FSL_ENETC_PTP_CLOCK
520520
struct enetc_ndev_priv *priv = netdev_priv(rx_ring->ndev);
521521
#endif
522522
/* TODO: hashing */
@@ -533,7 +533,7 @@ static void enetc_get_offloads(struct enetc_bdr *rx_ring,
533533
if (le16_to_cpu(rxbd->r.flags) & ENETC_RXBD_FLAG_VLAN)
534534
__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
535535
le16_to_cpu(rxbd->r.vlan_opt));
536-
#ifdef CONFIG_FSL_ENETC_HW_TIMESTAMPING
536+
#ifdef CONFIG_FSL_ENETC_PTP_CLOCK
537537
if (priv->active_offloads & ENETC_F_RX_TSTAMP)
538538
enetc_get_rx_tstamp(rx_ring->ndev, rxbd, skb);
539539
#endif
@@ -655,7 +655,7 @@ static int enetc_clean_rx_ring(struct enetc_bdr *rx_ring,
655655
cleaned_cnt -= count;
656656
}
657657

658-
rxbd = ENETC_RXBD(*rx_ring, i);
658+
rxbd = enetc_rxbd(rx_ring, i);
659659
bd_status = le32_to_cpu(rxbd->r.lstatus);
660660
if (!bd_status)
661661
break;
@@ -670,25 +670,21 @@ static int enetc_clean_rx_ring(struct enetc_bdr *rx_ring,
670670
enetc_get_offloads(rx_ring, rxbd, skb);
671671

672672
cleaned_cnt++;
673-
rxbd++;
674-
i++;
675-
if (unlikely(i == rx_ring->bd_count)) {
673+
674+
rxbd = enetc_rxbd_next(rx_ring, rxbd, i);
675+
if (unlikely(++i == rx_ring->bd_count))
676676
i = 0;
677-
rxbd = ENETC_RXBD(*rx_ring, 0);
678-
}
679677

680678
if (unlikely(bd_status &
681679
ENETC_RXBD_LSTATUS(ENETC_RXBD_ERR_MASK))) {
682680
dev_kfree_skb(skb);
683681
while (!(bd_status & ENETC_RXBD_LSTATUS_F)) {
684682
dma_rmb();
685683
bd_status = le32_to_cpu(rxbd->r.lstatus);
686-
rxbd++;
687-
i++;
688-
if (unlikely(i == rx_ring->bd_count)) {
684+
685+
rxbd = enetc_rxbd_next(rx_ring, rxbd, i);
686+
if (unlikely(++i == rx_ring->bd_count))
689687
i = 0;
690-
rxbd = ENETC_RXBD(*rx_ring, 0);
691-
}
692688
}
693689

694690
rx_ring->ndev->stats.rx_dropped++;
@@ -710,12 +706,10 @@ static int enetc_clean_rx_ring(struct enetc_bdr *rx_ring,
710706
enetc_add_rx_buff_to_skb(rx_ring, i, size, skb);
711707

712708
cleaned_cnt++;
713-
rxbd++;
714-
i++;
715-
if (unlikely(i == rx_ring->bd_count)) {
709+
710+
rxbd = enetc_rxbd_next(rx_ring, rxbd, i);
711+
if (unlikely(++i == rx_ring->bd_count))
716712
i = 0;
717-
rxbd = ENETC_RXBD(*rx_ring, 0);
718-
}
719713
}
720714

721715
rx_byte_cnt += skb->len;
@@ -845,15 +839,19 @@ static void enetc_free_tx_resources(struct enetc_ndev_priv *priv)
845839
enetc_free_txbdr(priv->tx_ring[i]);
846840
}
847841

848-
static int enetc_alloc_rxbdr(struct enetc_bdr *rxr)
842+
static int enetc_alloc_rxbdr(struct enetc_bdr *rxr, bool extended)
849843
{
844+
size_t size = sizeof(union enetc_rx_bd);
850845
int err;
851846

852847
rxr->rx_swbd = vzalloc(rxr->bd_count * sizeof(struct enetc_rx_swbd));
853848
if (!rxr->rx_swbd)
854849
return -ENOMEM;
855850

856-
err = enetc_dma_alloc_bdr(rxr, sizeof(union enetc_rx_bd));
851+
if (extended)
852+
size *= 2;
853+
854+
err = enetc_dma_alloc_bdr(rxr, size);
857855
if (err) {
858856
vfree(rxr->rx_swbd);
859857
return err;
@@ -862,6 +860,7 @@ static int enetc_alloc_rxbdr(struct enetc_bdr *rxr)
862860
rxr->next_to_clean = 0;
863861
rxr->next_to_use = 0;
864862
rxr->next_to_alloc = 0;
863+
rxr->ext_en = extended;
865864

866865
return 0;
867866
}
@@ -881,10 +880,11 @@ static void enetc_free_rxbdr(struct enetc_bdr *rxr)
881880

882881
static int enetc_alloc_rx_resources(struct enetc_ndev_priv *priv)
883882
{
883+
bool extended = !!(priv->active_offloads & ENETC_F_RX_TSTAMP);
884884
int i, err;
885885

886886
for (i = 0; i < priv->num_rx_rings; i++) {
887-
err = enetc_alloc_rxbdr(priv->rx_ring[i]);
887+
err = enetc_alloc_rxbdr(priv->rx_ring[i], extended);
888888

889889
if (err)
890890
goto fail;
@@ -1174,9 +1174,10 @@ static void enetc_setup_rxbdr(struct enetc_hw *hw, struct enetc_bdr *rx_ring)
11741174
enetc_rxbdr_wr(hw, idx, ENETC_RBICIR0, ENETC_RBICIR0_ICEN | 0x1);
11751175

11761176
rbmr = ENETC_RBMR_EN;
1177-
#ifdef CONFIG_FSL_ENETC_HW_TIMESTAMPING
1178-
rbmr |= ENETC_RBMR_BDS;
1179-
#endif
1177+
1178+
if (rx_ring->ext_en)
1179+
rbmr |= ENETC_RBMR_BDS;
1180+
11801181
if (rx_ring->ndev->features & NETIF_F_HW_VLAN_CTAG_RX)
11811182
rbmr |= ENETC_RBMR_VTE;
11821183

@@ -1577,11 +1578,12 @@ int enetc_set_features(struct net_device *ndev,
15771578
return 0;
15781579
}
15791580

1580-
#ifdef CONFIG_FSL_ENETC_HW_TIMESTAMPING
1581+
#ifdef CONFIG_FSL_ENETC_PTP_CLOCK
15811582
static int enetc_hwtstamp_set(struct net_device *ndev, struct ifreq *ifr)
15821583
{
15831584
struct enetc_ndev_priv *priv = netdev_priv(ndev);
15841585
struct hwtstamp_config config;
1586+
int ao;
15851587

15861588
if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
15871589
return -EFAULT;
@@ -1597,6 +1599,7 @@ static int enetc_hwtstamp_set(struct net_device *ndev, struct ifreq *ifr)
15971599
return -ERANGE;
15981600
}
15991601

1602+
ao = priv->active_offloads;
16001603
switch (config.rx_filter) {
16011604
case HWTSTAMP_FILTER_NONE:
16021605
priv->active_offloads &= ~ENETC_F_RX_TSTAMP;
@@ -1606,6 +1609,11 @@ static int enetc_hwtstamp_set(struct net_device *ndev, struct ifreq *ifr)
16061609
config.rx_filter = HWTSTAMP_FILTER_ALL;
16071610
}
16081611

1612+
if (netif_running(ndev) && ao != priv->active_offloads) {
1613+
enetc_close(ndev);
1614+
enetc_open(ndev);
1615+
}
1616+
16091617
return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
16101618
-EFAULT : 0;
16111619
}
@@ -1632,7 +1640,7 @@ static int enetc_hwtstamp_get(struct net_device *ndev, struct ifreq *ifr)
16321640

16331641
int enetc_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
16341642
{
1635-
#ifdef CONFIG_FSL_ENETC_HW_TIMESTAMPING
1643+
#ifdef CONFIG_FSL_ENETC_PTP_CLOCK
16361644
if (cmd == SIOCSHWTSTAMP)
16371645
return enetc_hwtstamp_set(ndev, rq);
16381646
if (cmd == SIOCGHWTSTAMP)

drivers/net/ethernet/freescale/enetc/enetc.h

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ struct enetc_bdr {
7373

7474
dma_addr_t bd_dma_base;
7575
u8 tsd_enable; /* Time specific departure */
76+
bool ext_en; /* enable h/w descriptor extensions */
7677
} ____cacheline_aligned_in_smp;
7778

7879
static inline void enetc_bdr_idx_inc(struct enetc_bdr *bdr, int *i)
@@ -104,7 +105,37 @@ struct enetc_cbdr {
104105
};
105106

106107
#define ENETC_TXBD(BDR, i) (&(((union enetc_tx_bd *)((BDR).bd_base))[i]))
107-
#define ENETC_RXBD(BDR, i) (&(((union enetc_rx_bd *)((BDR).bd_base))[i]))
108+
109+
static inline union enetc_rx_bd *enetc_rxbd(struct enetc_bdr *rx_ring, int i)
110+
{
111+
int hw_idx = i;
112+
113+
#ifdef CONFIG_FSL_ENETC_PTP_CLOCK
114+
if (rx_ring->ext_en)
115+
hw_idx = 2 * i;
116+
#endif
117+
return &(((union enetc_rx_bd *)rx_ring->bd_base)[hw_idx]);
118+
}
119+
120+
static inline union enetc_rx_bd *enetc_rxbd_next(struct enetc_bdr *rx_ring,
121+
union enetc_rx_bd *rxbd,
122+
int i)
123+
{
124+
rxbd++;
125+
#ifdef CONFIG_FSL_ENETC_PTP_CLOCK
126+
if (rx_ring->ext_en)
127+
rxbd++;
128+
#endif
129+
if (unlikely(++i == rx_ring->bd_count))
130+
rxbd = rx_ring->bd_base;
131+
132+
return rxbd;
133+
}
134+
135+
static inline union enetc_rx_bd *enetc_rxbd_ext(union enetc_rx_bd *rxbd)
136+
{
137+
return ++rxbd;
138+
}
108139

109140
struct enetc_msg_swbd {
110141
void *vaddr;

drivers/net/ethernet/freescale/enetc/enetc_ethtool.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,21 @@ static const char tx_ring_stats[][ETH_GSTRING_LEN] = {
195195
static int enetc_get_sset_count(struct net_device *ndev, int sset)
196196
{
197197
struct enetc_ndev_priv *priv = netdev_priv(ndev);
198+
int len;
199+
200+
if (sset != ETH_SS_STATS)
201+
return -EOPNOTSUPP;
198202

199-
if (sset == ETH_SS_STATS)
200-
return ARRAY_SIZE(enetc_si_counters) +
201-
ARRAY_SIZE(tx_ring_stats) * priv->num_tx_rings +
202-
ARRAY_SIZE(rx_ring_stats) * priv->num_rx_rings +
203-
(enetc_si_is_pf(priv->si) ?
204-
ARRAY_SIZE(enetc_port_counters) : 0);
203+
len = ARRAY_SIZE(enetc_si_counters) +
204+
ARRAY_SIZE(tx_ring_stats) * priv->num_tx_rings +
205+
ARRAY_SIZE(rx_ring_stats) * priv->num_rx_rings;
205206

206-
return -EOPNOTSUPP;
207+
if (!enetc_si_is_pf(priv->si))
208+
return len;
209+
210+
len += ARRAY_SIZE(enetc_port_counters);
211+
212+
return len;
207213
}
208214

209215
static void enetc_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
@@ -568,7 +574,7 @@ static int enetc_get_ts_info(struct net_device *ndev,
568574
info->phc_index = -1;
569575
}
570576

571-
#ifdef CONFIG_FSL_ENETC_HW_TIMESTAMPING
577+
#ifdef CONFIG_FSL_ENETC_PTP_CLOCK
572578
info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE |
573579
SOF_TIMESTAMPING_RX_HARDWARE |
574580
SOF_TIMESTAMPING_RAW_HARDWARE;

drivers/net/ethernet/freescale/enetc/enetc_hw.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,6 @@ union enetc_rx_bd {
418418
struct {
419419
__le64 addr;
420420
u8 reserved[8];
421-
#ifdef CONFIG_FSL_ENETC_HW_TIMESTAMPING
422-
u8 reserved1[16];
423-
#endif
424421
} w;
425422
struct {
426423
__le16 inet_csum;
@@ -435,11 +432,11 @@ union enetc_rx_bd {
435432
};
436433
__le32 lstatus;
437434
};
438-
#ifdef CONFIG_FSL_ENETC_HW_TIMESTAMPING
435+
} r;
436+
struct {
439437
__le32 tstamp;
440438
u8 reserved[12];
441-
#endif
442-
} r;
439+
} ext;
443440
};
444441

445442
#define ENETC_RXBD_LSTATUS_R BIT(30)

drivers/net/ethernet/freescale/enetc/enetc_pf.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -797,11 +797,6 @@ static int enetc_of_get_phy(struct enetc_ndev_priv *priv)
797797
struct device_node *mdio_np;
798798
int err;
799799

800-
if (!np) {
801-
dev_err(priv->dev, "missing ENETC port node\n");
802-
return -ENODEV;
803-
}
804-
805800
priv->phy_node = of_parse_phandle(np, "phy-handle", 0);
806801
if (!priv->phy_node) {
807802
if (!of_phy_is_fixed_link(np)) {

0 commit comments

Comments
 (0)