From nobody Mon Jan 31 08:00:03 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 796CD1991B8F; Mon, 31 Jan 2022 08:00:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JnL836kN9z4yH8; Mon, 31 Jan 2022 08:00:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643616004; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mhUnr8bd6yCbRBn/9V1aB9mQvS5Fz9kdkrefQ8N94N0=; b=DoHtJUQ+Cuunxu9LOijpqFDbwbWjffjhYJotyzogM13/vWINYbqJHxPa5r4TuEYgtICsCP vnB9biQc+U04Ziol2o27vynBPYxrt3RlQyMehNo2XlPgeuMLITeRWtWN5KPdrKG/Ro8HgP HwDTbXaV3nyxaxThPqucxtfxVIV4ERywENMEoxz/LKnzh/Dwh2nYRpEAlWr9P1Ccy9RBMC osZVrzkU6my6XB+7SDZzd9qHmBdBkYhvuG/d1ftOdLAMU/Yz/GxuHJ5bG6IeUVqZHIB13w dmjTJGs+pdNA3RLizleqLiwyeKNXkDTmRkZONPievDRMa4//+dRuGrgBFLjIWg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 85A5018B1E; Mon, 31 Jan 2022 08:00:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20V803fk024712; Mon, 31 Jan 2022 08:00:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20V803FF024709; Mon, 31 Jan 2022 08:00:03 GMT (envelope-from git) Date: Mon, 31 Jan 2022 08:00:03 GMT Message-Id: <202201310800.20V803FF024709@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Wojciech Macek Subject: git: a6bda3e1ef4d - main - enetc: Simply TX ring credits counting logic List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wma X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a6bda3e1ef4d06e3243a65533f9faf678816a48e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643616004; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mhUnr8bd6yCbRBn/9V1aB9mQvS5Fz9kdkrefQ8N94N0=; b=O5NHxclXfCqtRrXuFufD8nM5nj7UUDO+vag0+uFoPxoE93XewdLWxYb3ZFqcVgICC8uOC2 9dQz22AqVo1x01/6z6uWncPbSNWbD/fM20Khiu5qt8o6Wj6futHL+/9fyoWRN+83P7YwS3 WJxKeTms/6wVup5XrcG/wKiuOrHKyvEJjssap91Pw0pcr4ehU//Pjj4rDfHcKrQ/Ex5ffE nqBDrUXM8ElluK+rUqZyKU8bWistHZ4kERagJ9azS72FV58Z2jSXNjeIRGyVHnFK6vxkOo X6gQxueThOiVolhRb9vcoXa9KZRFTgeQRvzvurt43G522GHdamfxfWcsFxuKQA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1643616004; a=rsa-sha256; cv=none; b=eeRZ1qiozq8GhGob8UbcUAb+9Zu2aYl1aO486p1Qt2iLWgjnGH3wNsYZTame+Wx877jWK1 9ISekQMRERaDA4FcIT6WI6w/9wICLwnB2N6LwPfVUp5QyR9mhulIyNJUcO32DwUBCPsRfz 3wBRsmIlWQT/DCC6yTm5ZaEeIeux0uOElRTsUFvda1gfh4G1wQZm42OCKCrfVAIMAvLEhv +NXFvBqNqltwFHr/6elPL9Qiv4KwHnPZ57dAfi25Iv52pST53DYXxLZ9RO5HFuCamc112l pAxtSiMxq8yMSKtoM5y7PLOFl5kyGfGIDTMGWdc3w7r5f/seNgwHlCLTH/cXDg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by wma: URL: https://cgit.FreeBSD.org/src/commit/?id=a6bda3e1ef4d06e3243a65533f9faf678816a48e commit a6bda3e1ef4d06e3243a65533f9faf678816a48e Author: Kornel Duleba AuthorDate: 2022-01-27 09:24:26 +0000 Commit: Wojciech Macek CommitDate: 2022-01-31 07:57:48 +0000 enetc: Simply TX ring credits counting logic According to the RM rings can hold at most ring_size - 1 descriptors at any time. No additional logic is needed since iflib already respects this constrain. Thanks to that the pidx == cidx situation is not ambiguous and indicates an empty ring. Use that to simplify the logic that calculates the amount of processed frames. Obtained from: Semihalf Sponsored by: Alstom Group --- sys/dev/enetc/enetc.h | 3 +-- sys/dev/enetc/if_enetc.c | 36 ++++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/sys/dev/enetc/enetc.h b/sys/dev/enetc/enetc.h index 57edc2b26f2c..84b109a3e144 100644 --- a/sys/dev/enetc/enetc.h +++ b/sys/dev/enetc/enetc.h @@ -52,8 +52,7 @@ struct enetc_tx_queue { union enetc_tx_bd *ring; uint64_t ring_paddr; - qidx_t next_to_clean; - bool ring_full; + qidx_t cidx; struct if_irq irq; }; diff --git a/sys/dev/enetc/if_enetc.c b/sys/dev/enetc/if_enetc.c index 6f15db3ffe6c..75c582e81696 100644 --- a/sys/dev/enetc/if_enetc.c +++ b/sys/dev/enetc/if_enetc.c @@ -503,8 +503,7 @@ enetc_tx_queues_alloc(if_ctx_t ctx, caddr_t *vaddrs, uint64_t *paddrs, queue->sc = sc; queue->ring = (union enetc_tx_bd*)(vaddrs[i]); queue->ring_paddr = paddrs[i]; - queue->next_to_clean = 0; - queue->ring_full = false; + queue->cidx = 0; } return (0); @@ -1125,8 +1124,6 @@ enetc_isc_txd_encap(void *data, if_pkt_info_t ipi) desc->flags |= ENETC_TXBD_FLAGS_F; ipi->ipi_new_pidx = pidx; - if (pidx == queue->next_to_clean) - queue->ring_full = true; return (0); } @@ -1144,28 +1141,35 @@ enetc_isc_txd_credits_update(void *data, uint16_t qid, bool clear) { struct enetc_softc *sc = data; struct enetc_tx_queue *queue; - qidx_t next_to_clean, next_to_process; - int clean_count; + int cidx, hw_cidx, count; queue = &sc->tx_queues[qid]; - next_to_process = - ENETC_TXQ_RD4(sc, qid, ENETC_TBCIR) & ENETC_TBCIR_IDX_MASK; - next_to_clean = queue->next_to_clean; + hw_cidx = ENETC_TXQ_RD4(sc, qid, ENETC_TBCIR) & ENETC_TBCIR_IDX_MASK; + cidx = queue->cidx; - if (next_to_clean == next_to_process && !queue->ring_full) + /* + * RM states that the ring can hold at most ring_size - 1 descriptors. + * Thanks to that we can assume that the ring is empty if cidx == pidx. + * This requirement is guaranteed implicitly by iflib as it will only + * encap a new frame if we have at least nfrags + 2 descriptors available + * on the ring. This driver uses at most one additional descriptor for + * VLAN tag insertion. + * Also RM states that the TBCIR register is only updated once all + * descriptors in the chain have been processed. + */ + if (cidx == hw_cidx) return (0); if (!clear) return (1); - clean_count = next_to_process - next_to_clean; - if (clean_count <= 0) - clean_count += sc->tx_queue_size; + count = hw_cidx - cidx; + if (count < 0) + count += sc->tx_queue_size; - queue->next_to_clean = next_to_process; - queue->ring_full = false; + queue->cidx = hw_cidx; - return (clean_count); + return (count); } static int