Skip to content

Commit b049da1

Browse files
yangbolu1991davem330
authored andcommitted
net: mscc: ocelot: use skb queue instead of skbs list
Convert to use skb queue instead of the list of skbs. The skb queue could provide protection with lock. Signed-off-by: Yangbo Lu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent fc62c09 commit b049da1

File tree

2 files changed

+19
-44
lines changed

2 files changed

+19
-44
lines changed

drivers/net/ethernet/mscc/ocelot.c

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -583,18 +583,10 @@ int ocelot_port_add_txtstamp_skb(struct ocelot_port *ocelot_port,
583583

584584
if (ocelot->ptp && shinfo->tx_flags & SKBTX_HW_TSTAMP &&
585585
ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP) {
586-
struct ocelot_skb *oskb =
587-
kzalloc(sizeof(struct ocelot_skb), GFP_ATOMIC);
588-
589-
if (unlikely(!oskb))
590-
return -ENOMEM;
591-
592586
shinfo->tx_flags |= SKBTX_IN_PROGRESS;
593-
594-
oskb->skb = skb;
595-
oskb->id = ocelot_port->ts_id % 4;
596-
597-
list_add_tail(&oskb->head, &ocelot_port->skbs);
587+
/* Store timestamp ID in cb[0] of sk_buff */
588+
skb->cb[0] = ocelot_port->ts_id % 4;
589+
skb_queue_tail(&ocelot_port->tx_skbs, skb);
598590
return 0;
599591
}
600592
return -ENODATA;
@@ -704,12 +696,11 @@ void ocelot_get_txtstamp(struct ocelot *ocelot)
704696
int budget = OCELOT_PTP_QUEUE_SZ;
705697

706698
while (budget--) {
699+
struct sk_buff *skb, *skb_tmp, *skb_match = NULL;
707700
struct skb_shared_hwtstamps shhwtstamps;
708-
struct list_head *pos, *tmp;
709-
struct sk_buff *skb = NULL;
710-
struct ocelot_skb *entry;
711701
struct ocelot_port *port;
712702
struct timespec64 ts;
703+
unsigned long flags;
713704
u32 val, id, txport;
714705

715706
val = ocelot_read(ocelot, SYS_PTP_STATUS);
@@ -727,22 +718,22 @@ void ocelot_get_txtstamp(struct ocelot *ocelot)
727718
/* Retrieve its associated skb */
728719
port = ocelot->ports[txport];
729720

730-
list_for_each_safe(pos, tmp, &port->skbs) {
731-
entry = list_entry(pos, struct ocelot_skb, head);
732-
if (entry->id != id)
733-
continue;
721+
spin_lock_irqsave(&port->tx_skbs.lock, flags);
734722

735-
skb = entry->skb;
736-
737-
list_del(pos);
738-
kfree(entry);
723+
skb_queue_walk_safe(&port->tx_skbs, skb, skb_tmp) {
724+
if (skb->cb[0] != id)
725+
continue;
726+
__skb_unlink(skb, &port->tx_skbs);
727+
skb_match = skb;
739728
break;
740729
}
741730

731+
spin_unlock_irqrestore(&port->tx_skbs.lock, flags);
732+
742733
/* Next ts */
743734
ocelot_write(ocelot, SYS_PTP_NXT_PTP_NXT, SYS_PTP_NXT);
744735

745-
if (unlikely(!skb))
736+
if (unlikely(!skb_match))
746737
continue;
747738

748739
/* Get the h/w timestamp */
@@ -751,9 +742,9 @@ void ocelot_get_txtstamp(struct ocelot *ocelot)
751742
/* Set the timestamp into the skb */
752743
memset(&shhwtstamps, 0, sizeof(shhwtstamps));
753744
shhwtstamps.hwtstamp = ktime_set(ts.tv_sec, ts.tv_nsec);
754-
skb_tstamp_tx(skb, &shhwtstamps);
745+
skb_tstamp_tx(skb_match, &shhwtstamps);
755746

756-
dev_kfree_skb_any(skb);
747+
dev_kfree_skb_any(skb_match);
757748
}
758749
}
759750
EXPORT_SYMBOL(ocelot_get_txtstamp);
@@ -2206,7 +2197,7 @@ void ocelot_init_port(struct ocelot *ocelot, int port)
22062197
{
22072198
struct ocelot_port *ocelot_port = ocelot->ports[port];
22082199

2209-
INIT_LIST_HEAD(&ocelot_port->skbs);
2200+
skb_queue_head_init(&ocelot_port->tx_skbs);
22102201

22112202
/* Basic L2 initialization */
22122203

@@ -2491,9 +2482,7 @@ EXPORT_SYMBOL(ocelot_init);
24912482

24922483
void ocelot_deinit(struct ocelot *ocelot)
24932484
{
2494-
struct list_head *pos, *tmp;
24952485
struct ocelot_port *port;
2496-
struct ocelot_skb *entry;
24972486
int i;
24982487

24992488
cancel_delayed_work(&ocelot->stats_work);
@@ -2503,14 +2492,7 @@ void ocelot_deinit(struct ocelot *ocelot)
25032492

25042493
for (i = 0; i < ocelot->num_phys_ports; i++) {
25052494
port = ocelot->ports[i];
2506-
2507-
list_for_each_safe(pos, tmp, &port->skbs) {
2508-
entry = list_entry(pos, struct ocelot_skb, head);
2509-
2510-
list_del(pos);
2511-
dev_kfree_skb_any(entry->skb);
2512-
kfree(entry);
2513-
}
2495+
skb_queue_purge(&port->tx_skbs);
25142496
}
25152497
}
25162498
EXPORT_SYMBOL(ocelot_deinit);

include/soc/mscc/ocelot.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,6 @@ struct ocelot_ops {
406406
int (*reset)(struct ocelot *ocelot);
407407
};
408408

409-
struct ocelot_skb {
410-
struct list_head head;
411-
struct sk_buff *skb;
412-
u8 id;
413-
};
414-
415-
416409
struct ocelot_port {
417410
struct ocelot *ocelot;
418411

@@ -425,7 +418,7 @@ struct ocelot_port {
425418
u16 vid;
426419

427420
u8 ptp_cmd;
428-
struct list_head skbs;
421+
struct sk_buff_head tx_skbs;
429422
u8 ts_id;
430423
};
431424

0 commit comments

Comments
 (0)