From patchwork Tue Apr 30 01:07:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13647915 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 0F8381843 for ; Tue, 30 Apr 2024 01:07:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714439261; cv=none; b=aEPI9F9DQOCy/Fp576BmTLHfug5W2pHco1kKbJqqn0ja9ZVhxWFuA0AOhmcByVBiHrUHoBn1dyMGkwxY3CPV2XrVKEyaLn2dfk+PSv/Bam9HBzDtlSm1NXhAUVB5d4efkOXmKxlc4fy5PubuYiRxuwGaKmYZa6FvvSeZVDtbRXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714439261; c=relaxed/simple; bh=hRahC05qUcU+0m0eSOW1zph58fnDiIqsApDhJ09ygIg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hpun5QzT1Iu0BlO8YLsOCmet0XitKx3MT1cyl6ux5CXr5z1+DLnf3UmdLf4IFl7kycUHbUZo3bUkGPE9FvZzWyaU59uKvO4mohq86Y1Ir9gKk2qMeMCb6QXnUDzbeK1Br3cyO87Cnylms3RtlxB0ERlV9JUFLaVY4pJ0nuDwgJU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk; spf=none smtp.mailfrom=davidwei.uk; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b=M4+/UcfH; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b="M4+/UcfH" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1e834159f40so41235785ad.2 for ; Mon, 29 Apr 2024 18:07:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1714439259; x=1715044059; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iA3wBji6kXO1gvhc5WiOn2jpTbW1Zi3NyOiJx7qmGsk=; b=M4+/UcfH2Y26qd7/gSc5OIbAyKr+LeFsDKxCj7cvd6b6ZZ/KMUZIj6mVbd39KO7aL8 fwqKSRb5E4kHPejLWN4rTn2cCT+1cN5mQK0k7O9QzIxy5wGP79h8dPKA6HMqWt3/1p4w uLESFImQAK1e/CymQU+zC0MVVJUsvZGjZEpkYCGLMBqpuyPz7DbuV8Jhs57Y04oC4mVo 0Lth2jOi1ddZjBXw9MMqs/1WMI1kPHm452MDrhkJpcBmF5ZGkbmGOXhPlZTcb6KGkWSg R2luTVGCyl+y4VfY5wldHWmACDRH2JHGF8x4zoUd5jIHfHCLiczUIqDwDtIxIP4waFwF jm2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714439259; x=1715044059; h=content-transfer-encoding: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=iA3wBji6kXO1gvhc5WiOn2jpTbW1Zi3NyOiJx7qmGsk=; b=E4p/Z7JbH3vEpOwcsuboR+H2PvD9xMezGCu+0F6m8KtLjkB3W7Gglchv+Kd75rGoVP gHCspnRFXnM9NrXtWcw3LhGbka8WXfNYYc3znzVGuyjNgaRgODfHMOTAIdj8xnl7M8Of dDItXi1cyNbz9yEB/yJjzVNcGh9nOxRdGqxoHiQVVvFwntkr6igTvKXRxRdaohj3L1El RcwoVoHy1vTkk4XYYNTzSN9RX5yL3LGRJsT1KAf5LOX3VNYPV1iNG4n8ArEd6Ef18rY9 xRBTg5pYjnTEKjg/9Ovk8iQ5yjicj+1d5bx5aSkWY6aFavfSH1cIYrDA4Svfqd3EVqB0 p5VQ== X-Gm-Message-State: AOJu0YzUU9QVF0fNJNUKTuK7sk2Bt2aqPrCmAZZZEVOaKb0uSyeGW9O3 Tm9x2U6JrN1XzEQFRReB4bz37vCmgBt4MHU3jfL9y7AdV1A36Uj8zG3EOXHZLM61P7DNDfvtuNZ s X-Google-Smtp-Source: AGHT+IHvZ7DWhklwvAxckgSO5ZRgSBHSojBB/VU2p5qCjEBq2UGy6fi0XzL+qOItblFmB+8E6ycg7g== X-Received: by 2002:a17:903:1249:b0:1e4:b1eb:7dee with SMTP id u9-20020a170903124900b001e4b1eb7deemr14339108plh.47.1714439258962; Mon, 29 Apr 2024 18:07:38 -0700 (PDT) Received: from localhost (fwdproxy-prn-017.fbsv.net. [2a03:2880:ff:11::face:b00c]) by smtp.gmail.com with ESMTPSA id s8-20020a170902ea0800b001e853d9bb42sm4973225plg.196.2024.04.29.18.07.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 18:07:38 -0700 (PDT) From: David Wei To: netdev@vger.kernel.org, Michael Chan , Pavan Chebbi , Andy Gospodarek , Mina Almasry , Shailend Chand Cc: Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni Subject: [RFC PATCH net-next v1 1/3] queue_api: define queue api Date: Mon, 29 Apr 2024 18:07:30 -0700 Message-ID: <20240430010732.666512-2-dw@davidwei.uk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240430010732.666512-1-dw@davidwei.uk> References: <20240430010732.666512-1-dw@davidwei.uk> 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 X-Patchwork-State: RFC From: Mina Almasry This API enables the net stack to reset the queues used for devmem TCP. Signed-off-by: Mina Almasry Signed-off-by: David Wei --- include/linux/netdevice.h | 3 +++ include/net/netdev_queues.h | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index f849e7d110ed..6a58ec73c5e8 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1957,6 +1957,7 @@ enum netdev_reg_state { * @sysfs_rx_queue_group: Space for optional per-rx queue attributes * @rtnl_link_ops: Rtnl_link_ops * @stat_ops: Optional ops for queue-aware statistics + * @queue_mgmt_ops: Optional ops for queue management * * @gso_max_size: Maximum size of generic segmentation offload * @tso_max_size: Device (as in HW) limit on the max TSO request size @@ -2340,6 +2341,8 @@ struct net_device { const struct netdev_stat_ops *stat_ops; + const struct netdev_queue_mgmt_ops *queue_mgmt_ops; + /* for setting kernel sock attribute on TCP connection setup */ #define GSO_MAX_SEGS 65535u #define GSO_LEGACY_MAX_SIZE 65536u diff --git a/include/net/netdev_queues.h b/include/net/netdev_queues.h index 1ec408585373..337df0860ae6 100644 --- a/include/net/netdev_queues.h +++ b/include/net/netdev_queues.h @@ -60,6 +60,33 @@ struct netdev_stat_ops { struct netdev_queue_stats_tx *tx); }; +/** + * struct netdev_queue_mgmt_ops - netdev ops for queue management + * + * @ndo_queue_mem_alloc: Allocate memory for an RX queue. The memory returned + * in the form of a void* can be passed to + * ndo_queue_mem_free() for freeing or to ndo_queue_start + * to create an RX queue with this memory. + * + * @ndo_queue_mem_free: Free memory from an RX queue. + * + * @ndo_queue_start: Start an RX queue at the specified index. + * + * @ndo_queue_stop: Stop the RX queue at the specified index. + */ +struct netdev_queue_mgmt_ops { + void * (*ndo_queue_mem_alloc)(struct net_device *dev, + int idx); + void (*ndo_queue_mem_free)(struct net_device *dev, + void *queue_mem); + int (*ndo_queue_start)(struct net_device *dev, + int idx, + void *queue_mem); + int (*ndo_queue_stop)(struct net_device *dev, + int idx, + void **out_queue_mem); +}; + /** * DOC: Lockless queue stopping / waking helpers. * From patchwork Tue Apr 30 01:07:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13647916 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 E66F11FAA for ; Tue, 30 Apr 2024 01:07:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714439262; cv=none; b=mIUJUghlFvUCG3A0hhzo9Vis7Xp0oPMOnKTdaW9dX4f7+XF5ZQPid1DEVm94TLgxoKTEoTysOmBFPkC0OKY7eH46yUv0NMXwz/KDqQSl40vd0d76TElmlcaOwPesjjT/BmKXZKXhPVv/6WuUtJ9qC4aH+43J1nlMLmw8oD8QDHU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714439262; c=relaxed/simple; bh=ulnp01jdTxgIRCr18Tn2JZfsVZNTyq1zlColj8gCddE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q4/wMin1+acucUi4yRyFEloEXHYextePvHk/fbTEA86zldNLCbJW91Qwj0WD9FPFXBBfHVKZJwoN+19soI8vdYE5ANrAW6B0Kgw2h26s1O3jnxaWN6pO2AgI71stM4nJiRruqg4l6TNPcDbNLrUJ3SwaNsb4nK4gJYIl0dSbOYU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk; spf=none smtp.mailfrom=davidwei.uk; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b=QGUI53s3; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b="QGUI53s3" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-6ed01c63657so4998899b3a.2 for ; Mon, 29 Apr 2024 18:07:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1714439260; x=1715044060; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=k3TV5L/JsIHMDJfGRMClntZErKHDDCQVMuxFiLMd8sM=; b=QGUI53s3iuDuZDuFAqzXoh7qO1JkNq0ksY/Wy2Y7FGSXYq60w1li537UCAxDFaZxD5 FJ5XOM7pu6HIdT4n1hCJI+cXnY8s4agJ5OfvCD+tDHFfKLXHINvz0S9YFqox1KXSaFCl C3F6Bc+MyedpeXpMExL4yF4hltkCMoWv23G4bgplpI3syHuvhnvoG5L3T0UciSWn/83t BsrcgA17Ka3h/B44gdgAUWUADda1tw2uYPx9VMzV3+2Whwe5Kc2lGGyAcZGAv/ms/uKd h+eeNphQ1nIxDQ8+w2VvS0NGeL9IGRxhOeZcqiX8/F/0MMNJyeUcvuAzIR9UCZWPiVXg Oz8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714439260; x=1715044060; h=content-transfer-encoding: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=k3TV5L/JsIHMDJfGRMClntZErKHDDCQVMuxFiLMd8sM=; b=mF0py57reEAib3igrQ40VNfnrjCgy52L5pndCUVMbtrrsrFOASGTppCVOjrmwWXOdM uVyJtwXpWNKnytqHCsGDT6BuOIvPmcepYPrLI/KUnJ/cI0ayVYSIKozPb04vxKDDGbwa whm2gB2vjawV8beYY5SqRzI22UD/GtqUpfAzh0rzhunoQJyxjafYfx2segi2oXy25Jfw 5CyEP0jmd6C/tQpDyMfEWpjxNPoTYSN1YCXoumCDLF6Nlz3psWy6y2j8x6OC9/V/JP+I CF2Jb3oAJbs5nYBB3PeipodvF3tZr4FQkqcNp9f/tvq9xNWe5x7lVxtWLt1XrfpYjGoY 8IQw== X-Gm-Message-State: AOJu0Yw2B6Z5ntXUhz6MZ2c0L9d5OR499dhKpnPfrIZcBbjIs0/GxMro E5VdAry8Gw21gKndUWB3lcB8y40WDQu5CPDN3BQnS03Qh8eJ2pZSiQLk8kTcAXHeeE6HqNpx88Z m X-Google-Smtp-Source: AGHT+IGV53ciGSViOUP6TXIPWOoxRe6UZqfsvpl/aSKVCuU5nD9vG7Kd71rZHqmJO9tNbVt4uC3Tig== X-Received: by 2002:a05:6300:8082:b0:1ad:3d93:b71e with SMTP id ap2-20020a056300808200b001ad3d93b71emr8648287pzc.59.1714439259963; Mon, 29 Apr 2024 18:07:39 -0700 (PDT) Received: from localhost (fwdproxy-prn-117.fbsv.net. [2a03:2880:ff:75::face:b00c]) by smtp.gmail.com with ESMTPSA id bf6-20020a170902b90600b001e86e5dcb81sm20946346plb.283.2024.04.29.18.07.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 18:07:39 -0700 (PDT) From: David Wei To: netdev@vger.kernel.org, Michael Chan , Pavan Chebbi , Andy Gospodarek , Mina Almasry , Shailend Chand Cc: Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni Subject: [RFC PATCH net-next v1 2/3] bnxt: implement queue api Date: Mon, 29 Apr 2024 18:07:31 -0700 Message-ID: <20240430010732.666512-3-dw@davidwei.uk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240430010732.666512-1-dw@davidwei.uk> References: <20240430010732.666512-1-dw@davidwei.uk> 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 X-Patchwork-State: RFC Implement the bare minimum queue API for bnxt. I'm essentially breaking up the existing bnxt_rx_ring_reset() into two steps: 1. bnxt_queue_stop() 2. bnxt_queue_start() The other two ndos are left as no-ops for now, so the queue mem is allocated after the queue has been stopped. Doing this before stopping the queue is a lot more work, so I'm looking for some feedback first. Signed-off-by: David Wei --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 62 +++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index 06b7a963bbbd..788c87271eb1 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -14810,6 +14810,67 @@ static const struct netdev_stat_ops bnxt_stat_ops = { .get_base_stats = bnxt_get_base_stats, }; +static void *bnxt_queue_mem_alloc(struct net_device *dev, int idx) +{ + struct bnxt *bp = netdev_priv(dev); + + return &bp->rx_ring[idx]; +} + +static void bnxt_queue_mem_free(struct net_device *dev, void *qmem) +{ +} + +static int bnxt_queue_start(struct net_device *dev, int idx, void *qmem) +{ + struct bnxt_rx_ring_info *rxr = qmem; + struct bnxt *bp = netdev_priv(dev); + + bnxt_alloc_one_rx_ring(bp, idx); + + if (bp->flags & BNXT_FLAG_AGG_RINGS) + bnxt_db_write(bp, &rxr->rx_agg_db, rxr->rx_agg_prod); + bnxt_db_write(bp, &rxr->rx_db, rxr->rx_prod); + + if (bp->flags & BNXT_FLAG_TPA) + bnxt_set_tpa(bp, true); + + return 0; +} + +static int bnxt_queue_stop(struct net_device *dev, int idx, void **out_qmem) +{ + struct bnxt *bp = netdev_priv(dev); + struct bnxt_rx_ring_info *rxr; + struct bnxt_cp_ring_info *cpr; + int rc; + + rc = bnxt_hwrm_rx_ring_reset(bp, idx); + if (rc) + return rc; + + bnxt_free_one_rx_ring_skbs(bp, idx); + rxr = &bp->rx_ring[idx]; + rxr->rx_prod = 0; + rxr->rx_agg_prod = 0; + rxr->rx_sw_agg_prod = 0; + rxr->rx_next_cons = 0; + + cpr = &rxr->bnapi->cp_ring; + cpr->sw_stats.rx.rx_resets++; + + *out_qmem = rxr; + + return 0; +} + +static const struct netdev_queue_mgmt_ops bnxt_queue_mgmt_ops = { + .ndo_queue_mem_alloc = bnxt_queue_mem_alloc, + .ndo_queue_mem_free = bnxt_queue_mem_free, + .ndo_queue_start = bnxt_queue_start, + .ndo_queue_stop = bnxt_queue_stop, +}; + static void bnxt_remove_one(struct pci_dev *pdev) { struct net_device *dev = pci_get_drvdata(pdev); @@ -15275,6 +15336,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) dev->stat_ops = &bnxt_stat_ops; dev->watchdog_timeo = BNXT_TX_TIMEOUT; dev->ethtool_ops = &bnxt_ethtool_ops; + dev->queue_mgmt_ops = &bnxt_queue_mgmt_ops; pci_set_drvdata(pdev, dev); rc = bnxt_alloc_hwrm_resources(bp); From patchwork Tue Apr 30 01:07:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13647917 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (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 1EB32205E32 for ; Tue, 30 Apr 2024 01:07:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714439263; cv=none; b=Q/2co/GDeuo1FESVhT+z7z7e6kuuzH8MHAbxqrdCYxrqqxpIcjQjgMRP+dO8dyozzT4ubwiHGIZlZMFnYjDu/zSMAKPgZ9BuDLSPm2eOvN57DEUFvi31SRNzjflBIFNjwg2tk94hRFIcnaQZmmvspEb2bnOwzRVvc3r73Vx/lYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714439263; c=relaxed/simple; bh=OYY5KT41NM5uN1HZKt+u1zzFIxSC++IQ3CLaeU7YVME=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cNldfPBzInmzGlJMJINkOzKGxskbO4Ejj1Ljzt6OCIEaP6Tax2ACw9lMgR1Yhh1haof27gR5bsmo1LHAE1uBi6LQMXrMHzMtIBJZ866SwWBHVgMOpXYPJZZopMd1G5J4uuxZ9uok0ypp4B/R9Nrg+569DLzFdECb4z2titRxENs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk; spf=none smtp.mailfrom=davidwei.uk; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b=0CxEzQ+M; arc=none smtp.client-ip=209.85.215.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b="0CxEzQ+M" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-6123726725eso1528049a12.3 for ; Mon, 29 Apr 2024 18:07:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1714439261; x=1715044061; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=V/ZJcAuW84ecF6scZWO7f0oLtlZZw7KnY0k3vPst4TE=; b=0CxEzQ+M+Qe3JEv1fCpMBa/CooTScM8p2h8uHFn4gODMtWFxs2MA8pN01/GaARJ7aS YTFAPyajK6PrkoaZSqAMIpXg1N9Ir8fXCaMdamgQy/Jm2K6/mWOZ9VXTQkXFvVTZkn6Y PCZSYVa5R2tqqaIEZMIaWhRFy92lxD3X+q+8tvEIb8LN5SpxpydYsxMkzh99gFyH5SeQ ilA+7NbpVoXufEmD6DadOrIrUlmZ6mWugVzBDUqhx477nGu9abtYfyirdOK02QWE9o4M zDChq0ZVdDyrXRbls2YnHnYI4JLNacMJ4XZy/rG8QaaQQBVTrCW3+V5aJgRDsF7zgJ35 zbUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714439261; x=1715044061; h=content-transfer-encoding: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=V/ZJcAuW84ecF6scZWO7f0oLtlZZw7KnY0k3vPst4TE=; b=ofdJA3YbphM4iZJb/vPrr3bfhFpVZ73wWEynxGD/m1XuCfegpGkDdVIp3V6OvpZ1pU XgQjAIQre8sJOTVRatFkKS19i/vAKSo4CvClY65p1NN8kGv7YDYcZprKq+MKbGyHGz6P BCosNlLRcg1atrH5d7CuOjIytgNubUofkA/1mVNp5RZmtbU3FfJoMkMkwFtaRlcr+NAV vIqBJ+zvTFsxg9KvakD0eu7dqNNB/QBSd/XBeQcIzu2d/3AWpT9BXnhDWo5fbBu+HfkG MBUs6kKO8euRQ+w3eMGeRJf2mq8ev0lbVrqVt96YhXm7l/+4jipC7C9nEFvfSpAEHFNT e7KA== X-Gm-Message-State: AOJu0Yzr9oB8mPnf+7Z2TKkjLpFs57drMPYNvK/inIbUGFB7/4A6yQod A3MU7q5am989HoMlPehO6JUbP9fpHtNpABKDjhQwUzCP3WKnFiXQDUFYFaqvICww40q3WwDauVU F X-Google-Smtp-Source: AGHT+IEOFfjoUzZArpr2emS+wl9sWvDsfTheiLzznCDSpGDqLxMk1ts1YjrGw/qO01nVaj2IwpCa1A== X-Received: by 2002:a17:90b:3ccf:b0:2b1:6686:dd7b with SMTP id qd15-20020a17090b3ccf00b002b16686dd7bmr4831853pjb.33.1714439260992; Mon, 29 Apr 2024 18:07:40 -0700 (PDT) Received: from localhost (fwdproxy-prn-118.fbsv.net. [2a03:2880:ff:76::face:b00c]) by smtp.gmail.com with ESMTPSA id gw3-20020a17090b0a4300b002b1ae6f26cbsm2697774pjb.53.2024.04.29.18.07.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 18:07:40 -0700 (PDT) From: David Wei To: netdev@vger.kernel.org, Michael Chan , Pavan Chebbi , Andy Gospodarek , Mina Almasry , Shailend Chand Cc: Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni Subject: [RFC PATCH net-next v1 3/3] netdev: add netdev_rx_queue_restart() Date: Mon, 29 Apr 2024 18:07:32 -0700 Message-ID: <20240430010732.666512-4-dw@davidwei.uk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240430010732.666512-1-dw@davidwei.uk> References: <20240430010732.666512-1-dw@davidwei.uk> 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 X-Patchwork-State: RFC From: Mina Almasry Add netdev_rx_queue_restart() function to netdev_rx_queue.h. This is taken from Mina's work in [1] with a slight modification of taking rtnl_lock() during the queue stop and start ops. For bnxt specifically, if the firmware doesn't support BNXT_RST_RING_SP_EVENT, then ndo_queue_stop() returns -EOPNOTSUPP and the whole restart fails. Unlike bnxt_rx_ring_reset(), there is no attempt to reset the whole device. [1]: https://lore.kernel.org/linux-kernel/20240403002053.2376017-6-almasrymina@google.com/#t Signed-off-by: David Wei --- include/net/netdev_rx_queue.h | 3 ++ net/core/Makefile | 1 + net/core/netdev_rx_queue.c | 58 +++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 net/core/netdev_rx_queue.c diff --git a/include/net/netdev_rx_queue.h b/include/net/netdev_rx_queue.h index aa1716fb0e53..e78ca52d67fb 100644 --- a/include/net/netdev_rx_queue.h +++ b/include/net/netdev_rx_queue.h @@ -54,4 +54,7 @@ get_netdev_rx_queue_index(struct netdev_rx_queue *queue) return index; } #endif + +int netdev_rx_queue_restart(struct net_device *dev, unsigned int rxq); + #endif diff --git a/net/core/Makefile b/net/core/Makefile index 21d6fbc7e884..f2aa63c167a3 100644 --- a/net/core/Makefile +++ b/net/core/Makefile @@ -19,6 +19,7 @@ obj-$(CONFIG_NETDEV_ADDR_LIST_TEST) += dev_addr_lists_test.o obj-y += net-sysfs.o obj-y += hotdata.o +obj-y += netdev_rx_queue.o obj-$(CONFIG_PAGE_POOL) += page_pool.o page_pool_user.o obj-$(CONFIG_PROC_FS) += net-procfs.o obj-$(CONFIG_NET_PKTGEN) += pktgen.o diff --git a/net/core/netdev_rx_queue.c b/net/core/netdev_rx_queue.c new file mode 100644 index 000000000000..9633fb36f6d1 --- /dev/null +++ b/net/core/netdev_rx_queue.c @@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include +#include +#include + +int netdev_rx_queue_restart(struct net_device *dev, unsigned int rxq) +{ + void *new_mem; + void *old_mem; + int err; + + if (!dev->queue_mgmt_ops->ndo_queue_stop || + !dev->queue_mgmt_ops->ndo_queue_mem_free || + !dev->queue_mgmt_ops->ndo_queue_mem_alloc || + !dev->queue_mgmt_ops->ndo_queue_start) + return -EOPNOTSUPP; + + new_mem = dev->queue_mgmt_ops->ndo_queue_mem_alloc(dev, rxq); + if (!new_mem) + return -ENOMEM; + + rtnl_lock(); + err = dev->queue_mgmt_ops->ndo_queue_stop(dev, rxq, &old_mem); + if (err) + goto err_free_new_mem; + + err = dev->queue_mgmt_ops->ndo_queue_start(dev, rxq, new_mem); + if (err) + goto err_start_queue; + rtnl_unlock(); + + dev->queue_mgmt_ops->ndo_queue_mem_free(dev, old_mem); + + return 0; + +err_start_queue: + /* Restarting the queue with old_mem should be successful as we haven't + * changed any of the queue configuration, and there is not much we can + * do to recover from a failure here. + * + * WARN if the we fail to recover the old rx queue, and at least free + * old_mem so we don't also leak that. + */ + if (dev->queue_mgmt_ops->ndo_queue_start(dev, rxq, old_mem)) { + WARN(1, + "Failed to restart old queue in error path. RX queue %d may be unhealthy.", + rxq); + dev->queue_mgmt_ops->ndo_queue_mem_free(dev, &old_mem); + } + +err_free_new_mem: + dev->queue_mgmt_ops->ndo_queue_mem_free(dev, new_mem); + rtnl_unlock(); + + return err; +} +EXPORT_SYMBOL_GPL(netdev_rx_queue_restart);