From patchwork Wed Jun 26 16:43:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 13713194 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 01C3119005C for ; Wed, 26 Jun 2024 16:43:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719420231; cv=none; b=MLbr9wDW1ZUjLaH5VGz0YywHWktjIr05xEu20tGFZ4DhdtvKGIfDbutsFyMCHpNdrUvl254gHHHc0MoVT6/phVeCyzYF4RCXFmRuR1vj4PfI70aU8mIGx8l6RX7Uj6d4bJQD7fpegwJcyPhUkq6qVEfnoSlLyY3Egrs411NQ+fs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719420231; c=relaxed/simple; bh=TYZihhcJLI9Jc2q8IoZj+IrpCL17UkK/hF5iG/wr9iE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pzvyu5qAbR/Ibq+tqMeuOczlR1F0BZfw95I282wkvAmR9QyFJtmES9v4BAAm50T4SKctkkncs6uExNWm6GtZsdnd/bvBBMUkLokQ+cvmdVjtC1XoDnjHBy6vbdbdO/p13FM8rWNd7jPF01C6It0kk/SfV/KQjkUGKNtKm01Sbj8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=Kr7hBLq5; arc=none smtp.client-ip=209.85.222.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="Kr7hBLq5" Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-79c03dbddb8so213240485a.1 for ; Wed, 26 Jun 2024 09:43:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1719420229; x=1720025029; darn=vger.kernel.org; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=lJTGUEIo8u1qOej4wyadsnCa5VyT8DqBoHdj7C7oF7k=; b=Kr7hBLq5+Pqd0tYiRZXhX5foM/yxbFTOZHcFktZBhXJykwAhm7BvMTn04AR2wxOtBc eAtsd7jJOihyx57rjHu4/9lvNX+wDEMTWAbpcuJbQSgOzK11oar0iWnC5rSHyzGgDkMk Re0/1UM2dUEfeKAINFkMuUGno3LaLFWK7nGvc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719420229; x=1720025029; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lJTGUEIo8u1qOej4wyadsnCa5VyT8DqBoHdj7C7oF7k=; b=HaCuU2KmHfsPabXG22fBr1dkg5EQySWjYQcahRgeber2z1hZ2PYV2gHIwd50gxCfxQ 3UFru/maT2Ox8zEbOoJbxHaXsyKvQxFhnP/9INR83DWElKDUnYGz1DiedTO1pe8r/Jq6 FJ6eZ9YGvq0QAIw0Gkj3a56Wmq8i88vfoVNFlG89PcKtGHKEZhJ+y4hfAGDL8zrF4ceA v1/W5rbNCP2LwZuH7CH3FzHTFvPIohfyzo8EqeACR6Em6U21aMEt+SqwIGU8S4AEYY3/ rb2HWGOe/2we3pmR9PO4eNmCM1w8zgg6DKBH9fW4jRxl0GaI40gL8DFw6Kv2OPV6mMBb 3RQQ== X-Gm-Message-State: AOJu0YzGf7xfYrS85SNks8Hk4wqAKgWWpn2griZLNwGQ4ErzcXNMLTy0 B7lldtTQPTfgi8w5jLhFOC59ajubt124A7PBSvXgd2PU8nOr1GUkSeth+qnu2A== X-Google-Smtp-Source: AGHT+IEd6IAO41h/+sp57VuozyNBm8RrPqtxSFFSmOrj63uAC5pMB9pmrrey7JKDqvlpJQ1DUQ3FOw== X-Received: by 2002:a05:620a:2951:b0:79d:5a77:aea8 with SMTP id af79cd13be357-79d5a77b290mr3419785a.1.1719420228554; Wed, 26 Jun 2024 09:43:48 -0700 (PDT) Received: from lvnvda5233.lvn.broadcom.net ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id af79cd13be357-79d53c42aafsm53570485a.58.2024.06.26.09.43.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Jun 2024 09:43:47 -0700 (PDT) From: Michael Chan To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, pavan.chebbi@broadcom.com, andrew.gospodarek@broadcom.com, richardcochran@gmail.com Subject: [PATCH net-next 10/10] bnxt_en: Remove atomic operations on ptp->tx_avail Date: Wed, 26 Jun 2024 09:43:07 -0700 Message-ID: <20240626164307.219568-11-michael.chan@broadcom.com> X-Mailer: git-send-email 2.43.4 In-Reply-To: <20240626164307.219568-1-michael.chan@broadcom.com> References: <20240626164307.219568-1-michael.chan@broadcom.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Pavan Chebbi 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 Signed-off-by: Michael Chan --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 20 +++------------- drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c | 23 +++++++++++++++---- drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.h | 10 +++++++- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index 0867861c14bd..33ba1964168b 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -518,34 +518,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); @@ -12184,7 +12170,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)) 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 @@ 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); diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.h b/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.h index a1910ce86cbb..a9a2f9a18c9c 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.h +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.h @@ -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,