Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp239817rdb; Thu, 30 Nov 2023 03:44:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IGXbc2YFz8si/Fa6ZXYssJaavVVd5efXOEVc6Hp49wfiSJZ7oQBvyQO5CpsXDceMFNxH6kA X-Received: by 2002:a9d:75cd:0:b0:6d4:80ee:f5b with SMTP id c13-20020a9d75cd000000b006d480ee0f5bmr22874184otl.35.1701344657441; Thu, 30 Nov 2023 03:44:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701344657; cv=none; d=google.com; s=arc-20160816; b=oZof4fwKSC1QRlUO2/JSQWrTe9p5CW0ydfZd+CUhfGJQoX0wCPVbTb73Kzl6GR9Dpu 2pOyGHEwBLXL6RZCzRKz/feahtWIn9bruOT0aa8qlXv/V9Eflr6dHWJWUpzbSh3EH2rA GWIihPAGwqvEAfT/1bmn2eQfLoMguPKh9wKiAv11S8zK5jwfTME3tXwJuTZX8UqALFOx FlcAJrJ6D2PYTa29gBU/6DUhxYf5mBebLX5Abwe81VTN8Vc0L4luQ3bJ7y8/DidSqTvz ZlRXg7PIlw79hDGHyf7+K4iUbui5VfRCuDrDSH37ijPdyg9TePAwiuNBx2dqPQTBYK+H PH+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=6fe8S6Q5h66YrXbkIodsPeomx75yjNYXOAUoPOAoJjc=; fh=J4St9tMjBInT3r1VVHSF1O7f2qS3KxSaZBHCVggmRHk=; b=KW56JF/bF8Yql2G5YIYBHHTbITwRMXV427JWFxLxLkxNgyOuRQaOQezZ6AtZ3OGUWy 7Uz+ctZTwxB7ruDh9z0qeIZ0pCyFzd0gvE2Ax/oFeMBbhbmEIqIGAGCc47PulMtHc7Sc Woi9xzHGqE3xxRqZM6oAaiDcsJsAAY+nBxmvKt+pgmzFXORrapQArIlnoq7+pRNLzh02 s6rhs7GEB1ZWA00vj1AzZRVhMA/TXvXchXi2gTh67PZLzoEuxovW67eLwXjH/osBuuOZ B0rgSRzDCcsSQ5b8C9QzvHKI/ZnvUoC16HSfG7/WerilSwDudG3w4C7nD2eIdDVln650 QlVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id z15-20020a63e54f000000b005c221909d4asi1130898pgj.830.2023.11.30.03.44.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 03:44:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 550068028E68; Thu, 30 Nov 2023 03:44:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235157AbjK3LoB (ORCPT + 99 others); Thu, 30 Nov 2023 06:44:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231784AbjK3Ln7 (ORCPT ); Thu, 30 Nov 2023 06:43:59 -0500 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 981B310D9; Thu, 30 Nov 2023 03:44:04 -0800 (PST) X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 3AUBhhXR33495125, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36505.realtek.com.tw[172.21.6.25]) by rtits2.realtek.com.tw (8.15.2/2.95/5.92) with ESMTPS id 3AUBhhXR33495125 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Nov 2023 19:43:43 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) by RTEXH36505.realtek.com.tw (172.21.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.32; Thu, 30 Nov 2023 19:43:43 +0800 Received: from RTDOMAIN (172.21.210.160) by RTEXMBS04.realtek.com.tw (172.21.6.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Thu, 30 Nov 2023 19:43:42 +0800 From: Justin Lai To: CC: , , , , , , , , Justin Lai Subject: [PATCH net-next v13 07/13] rtase: Implement a function to receive packets Date: Thu, 30 Nov 2023 19:43:21 +0800 Message-ID: <20231130114327.1530225-8-justinlai0215@realtek.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130114327.1530225-1-justinlai0215@realtek.com> References: <20231130114327.1530225-1-justinlai0215@realtek.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [172.21.210.160] X-ClientProxiedBy: RTEXH36505.realtek.com.tw (172.21.6.25) To RTEXMBS04.realtek.com.tw (172.21.6.97) X-KSE-ServerInfo: RTEXMBS04.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-ServerInfo: RTEXH36505.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 30 Nov 2023 03:44:16 -0800 (PST) Implement rx_handler to read the information of the rx descriptor, thereby checking the packet accordingly and storing the packet in the socket buffer to complete the reception of the packet. Signed-off-by: Justin Lai --- .../net/ethernet/realtek/rtase/rtase_main.c | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/drivers/net/ethernet/realtek/rtase/rtase_main.c b/drivers/net/ethernet/realtek/rtase/rtase_main.c index 00eb2e7dc7ba..16c1f92c4274 100644 --- a/drivers/net/ethernet/realtek/rtase/rtase_main.c +++ b/drivers/net/ethernet/realtek/rtase/rtase_main.c @@ -452,6 +452,154 @@ static void rtase_rx_ring_clear(struct rtase_ring *ring) } } +static int rtase_fragmented_frame(u32 status) +{ + return (status & (RX_FIRST_FRAG | RX_LAST_FRAG)) != + (RX_FIRST_FRAG | RX_LAST_FRAG); +} + +static void rtase_rx_csum(const struct rtase_private *tp, struct sk_buff *skb, + const union rx_desc *desc) +{ + u32 opts2 = le32_to_cpu(desc->desc_status.opts2); + + /* rx csum offload */ + if (((opts2 & RX_V4F) && !(opts2 & RX_IPF)) || (opts2 & RX_V6F)) { + if (((opts2 & RX_TCPT) && !(opts2 & RX_TCPF)) || + ((opts2 & RX_UDPT) && !(opts2 & RX_UDPF))) { + skb->ip_summed = CHECKSUM_UNNECESSARY; + } else { + skb->ip_summed = CHECKSUM_NONE; + } + } else { + skb->ip_summed = CHECKSUM_NONE; + } +} + +static void rtase_rx_vlan_skb(union rx_desc *desc, struct sk_buff *skb) +{ + u32 opts2 = le32_to_cpu(desc->desc_status.opts2); + + if (!(opts2 & RX_VLAN_TAG)) + return; + + __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), swab16(opts2 & VLAN_TAG_MASK)); +} + +static void rtase_rx_skb(const struct rtase_ring *ring, struct sk_buff *skb) +{ + struct rtase_int_vector *ivec = ring->ivec; + + napi_gro_receive(&ivec->napi, skb); +} + +static int rx_handler(struct rtase_ring *ring, int budget) +{ + const struct rtase_private *tp = ring->ivec->tp; + u32 pkt_size, cur_rx, delta, entry, status; + union rx_desc *desc_base = ring->desc; + struct net_device *dev = tp->dev; + struct sk_buff *skb; + union rx_desc *desc; + int workdone = 0; + + if (!ring->desc) + return workdone; + + cur_rx = ring->cur_idx; + entry = cur_rx % NUM_DESC; + desc = &desc_base[entry]; + + do { + /* make sure discriptor has been updated */ + rmb(); + status = le32_to_cpu(desc->desc_status.opts1); + + if (status & DESC_OWN) + break; + + if (unlikely(status & RX_RES)) { + if (net_ratelimit()) + netdev_warn(dev, "Rx ERROR. status = %08x\n", + status); + + dev->stats.rx_errors++; + + if (status & (RX_RWT | RX_RUNT)) + dev->stats.rx_length_errors++; + + if (status & RX_CRC) + dev->stats.rx_crc_errors++; + + if (dev->features & NETIF_F_RXALL) + goto process_pkt; + + rtase_mark_to_asic(desc, tp->rx_buf_sz); + goto skip_process_pkt; + } + +process_pkt: + pkt_size = status & RX_PKT_SIZE_MASK; + if (likely(!(dev->features & NETIF_F_RXFCS))) + pkt_size -= ETH_FCS_LEN; + + /* the driver does not support incoming fragmented + * frames. they are seen as a symptom of over-mtu + * sized frames + */ + if (unlikely(rtase_fragmented_frame(status))) { + dev->stats.rx_dropped++; + dev->stats.rx_length_errors++; + rtase_mark_to_asic(desc, tp->rx_buf_sz); + continue; + } + + skb = ring->skbuff[entry]; + dma_sync_single_for_cpu(&tp->pdev->dev, + ring->mis.data_phy_addr[entry], + tp->rx_buf_sz, DMA_FROM_DEVICE); + + ring->skbuff[entry] = NULL; + + if (dev->features & NETIF_F_RXCSUM) + rtase_rx_csum(tp, skb, desc); + + skb->dev = dev; + skb_put(skb, pkt_size); + skb_mark_for_recycle(skb); + skb->protocol = eth_type_trans(skb, dev); + + if (skb->pkt_type == PACKET_MULTICAST) + dev->stats.multicast++; + + rtase_rx_vlan_skb(desc, skb); + rtase_rx_skb(ring, skb); + + dev->stats.rx_bytes += pkt_size; + dev->stats.rx_packets++; + +skip_process_pkt: + workdone++; + cur_rx++; + entry = cur_rx % NUM_DESC; + desc = ring->desc + sizeof(union rx_desc) * entry; + prefetch(desc); + } while (workdone != budget); + + ring->cur_idx = cur_rx; + delta = rtase_rx_ring_fill(ring, ring->dirty_idx, ring->cur_idx, 1); + + if (!delta && workdone) + netdev_info(dev, "no Rx buffer allocated\n"); + + ring->dirty_idx += delta; + + if ((ring->dirty_idx + NUM_DESC) == ring->cur_idx) + netdev_emerg(dev, "Rx buffers exhausted\n"); + + return workdone; +} + static void rtase_rx_desc_init(struct rtase_private *tp, u16 idx) { struct rtase_ring *ring = &tp->rx_ring[idx]; -- 2.34.1