summaryrefslogtreecommitdiff
path: root/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c
diff options
context:
space:
mode:
authorPavan Chebbi <pavan.chebbi@broadcom.com>2024-06-28 12:30:05 -0700
committerDavid S. Miller <davem@davemloft.net>2024-07-01 11:23:22 +0100
commit060338390787ccbfd71f0796d420b7cd063bcac6 (patch)
treef407e8ebf4907278a4d4179483e836a06c28ac24 /drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c
parent8aa2a79e9b95eadec5c2a97662adb5b0a8f333ad (diff)
bnxt_en: Remove atomic operations on ptp->tx_avail
Now that we require the spinlock to protect ptp->txts_prod, change ptp->tx_avail to non-atomic and protect it under the same spinlock. Add a new helper function bnxt_ptp_get_txts_prod() to decrement ptp->tx_avail under spinlock and return the producer. Signed-off-by: Pavan Chebbi <pavan.chebbi@broadcom.com> Signed-off-by: Michael Chan <michael.chan@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c')
-rw-r--r--drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c
index 9e93dc8b2b57..37d42423459c 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c
@@ -730,10 +730,10 @@ static long bnxt_ptp_ts_aux_work(struct ptp_clock_info *ptp_info)
unsigned long now = jiffies;
struct bnxt *bp = ptp->bp;
u16 cons = ptp->txts_cons;
- u8 num_requests;
+ u32 num_requests;
int rc = 0;
- num_requests = BNXT_MAX_TX_TS - atomic_read(&ptp->tx_avail);
+ num_requests = BNXT_MAX_TX_TS - READ_ONCE(ptp->tx_avail);
while (num_requests--) {
if (IS_ERR(ptp->txts_req[cons].tx_skb))
goto next_slot;
@@ -743,7 +743,7 @@ static long bnxt_ptp_ts_aux_work(struct ptp_clock_info *ptp_info)
if (rc == -EAGAIN)
break;
next_slot:
- atomic_inc(&ptp->tx_avail);
+ BNXT_PTP_INC_TX_AVAIL(ptp);
cons = NEXT_TXTS(cons);
}
ptp->txts_cons = cons;
@@ -767,6 +767,21 @@ next_slot:
return HZ;
}
+int bnxt_ptp_get_txts_prod(struct bnxt_ptp_cfg *ptp, u16 *prod)
+{
+ spin_lock_bh(&ptp->ptp_tx_lock);
+ if (ptp->tx_avail) {
+ *prod = ptp->txts_prod;
+ ptp->txts_prod = NEXT_TXTS(*prod);
+ ptp->tx_avail--;
+ spin_unlock_bh(&ptp->ptp_tx_lock);
+ return 0;
+ }
+ spin_unlock_bh(&ptp->ptp_tx_lock);
+ atomic64_inc(&ptp->stats.ts_err);
+ return -ENOSPC;
+}
+
void bnxt_get_tx_ts_p5(struct bnxt *bp, struct sk_buff *skb, u16 prod)
{
struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
@@ -1014,7 +1029,7 @@ int bnxt_ptp_init(struct bnxt *bp, bool phc_cfg)
bnxt_ptp_free(bp);
- atomic_set(&ptp->tx_avail, BNXT_MAX_TX_TS);
+ WRITE_ONCE(ptp->tx_avail, BNXT_MAX_TX_TS);
spin_lock_init(&ptp->ptp_lock);
spin_lock_init(&ptp->ptp_tx_lock);