Commit 06033839 authored by Pavan Chebbi's avatar Pavan Chebbi Committed by David S. Miller
Browse files

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: default avatarPavan Chebbi <pavan.chebbi@broadcom.com>
Signed-off-by: default avatarMichael Chan <michael.chan@broadcom.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8aa2a79e
Loading
Loading
Loading
Loading
+3 −17
Original line number Diff line number Diff line
@@ -519,34 +519,20 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
		} else if (!skb_is_gso(skb)) {
			u16 seq_id, hdr_off;

			if (atomic_dec_if_positive(&ptp->tx_avail) < 0) {
				atomic64_inc(&ptp->stats.ts_err);
				goto tx_no_ts;
			}

			if (!bnxt_ptp_parse(skb, &seq_id, &hdr_off)) {
			if (!bnxt_ptp_parse(skb, &seq_id, &hdr_off) &&
			    !bnxt_ptp_get_txts_prod(ptp, &txts_prod)) {
				if (vlan_tag_flags)
					hdr_off += VLAN_HLEN;
				lflags |= cpu_to_le32(TX_BD_FLAGS_STAMP);
				tx_buf->is_ts_pkt = 1;
				skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;

				spin_lock_bh(&ptp->ptp_tx_lock);
				txts_prod = ptp->txts_prod;
				ptp->txts_prod = NEXT_TXTS(txts_prod);
				spin_unlock_bh(&ptp->ptp_tx_lock);

				ptp->txts_req[txts_prod].tx_seqid = seq_id;
				ptp->txts_req[txts_prod].tx_hdr_off = hdr_off;
				tx_buf->txts_prod = txts_prod;

			} else {
				atomic_inc(&bp->ptp_cfg->tx_avail);
			}
		}
	}

tx_no_ts:
	if (unlikely(skb->no_fcs))
		lflags |= cpu_to_le32(TX_BD_FLAGS_NO_CRC);

@@ -12183,7 +12169,7 @@ static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
	if (BNXT_PF(bp))
		bnxt_vf_reps_open(bp);
	if (bp->ptp_cfg && !(bp->fw_cap & BNXT_FW_CAP_TX_TS_CMP))
		atomic_set(&bp->ptp_cfg->tx_avail, BNXT_MAX_TX_TS);
		WRITE_ONCE(bp->ptp_cfg->tx_avail, BNXT_MAX_TX_TS);
	bnxt_ptp_init_rtc(bp, true);
	bnxt_ptp_cfg_tstamp_filters(bp);
	if (BNXT_SUPPORTS_MULTI_RSS_CTX(bp))
+19 −4
Original line number Diff line number Diff line
@@ -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 @@ static long bnxt_ptp_ts_aux_work(struct ptp_clock_info *ptp_info)
	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);

+9 −1
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ struct bnxt_ptp_cfg {
	struct bnxt_ptp_tx_req	txts_req[BNXT_MAX_TX_TS];

	struct bnxt		*bp;
	atomic_t		tx_avail;
	u32			tx_avail;
	u16			rxctl;
#define BNXT_PTP_MSG_SYNC			(1 << 0)
#define BNXT_PTP_MSG_DELAY_REQ			(1 << 1)
@@ -157,6 +157,13 @@ do { \
	((dst) = READ_ONCE(src))
#endif

#define BNXT_PTP_INC_TX_AVAIL(ptp)		\
do {						\
	spin_lock_bh(&(ptp)->ptp_tx_lock);	\
	(ptp)->tx_avail++;			\
	spin_unlock_bh(&(ptp)->ptp_tx_lock);	\
} while (0)

int bnxt_ptp_parse(struct sk_buff *skb, u16 *seq_id, u16 *hdr_off);
void bnxt_ptp_update_current_time(struct bnxt *bp);
void bnxt_ptp_pps_event(struct bnxt *bp, u32 data1, u32 data2);
@@ -164,6 +171,7 @@ int bnxt_ptp_cfg_tstamp_filters(struct bnxt *bp);
void bnxt_ptp_reapply_pps(struct bnxt *bp);
int bnxt_hwtstamp_set(struct net_device *dev, struct ifreq *ifr);
int bnxt_hwtstamp_get(struct net_device *dev, struct ifreq *ifr);
int bnxt_ptp_get_txts_prod(struct bnxt_ptp_cfg *ptp, u16 *prod);
void bnxt_get_tx_ts_p5(struct bnxt *bp, struct sk_buff *skb, u16 prod);
int bnxt_get_rx_ts_p5(struct bnxt *bp, u64 *ts, u32 pkt_ts);
void bnxt_tx_ts_cmp(struct bnxt *bp, struct bnxt_napi *bnapi,