Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp896965lqt; Fri, 7 Jun 2024 01:49:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW6ItWdBsMmV+YAQlI2XXZO/c80yQ8hEdKBBKZlkd/CUSh7d9W0yKME8Aodv71dd3iAN+fNuQGg3iaIB8Npol0jTpNTFRqqTgveqgSwGQ== X-Google-Smtp-Source: AGHT+IGFGhkWfjUtZzcXs6tQFQn9NuPfXsAfzL0kRFqKCbMfwqZCSLXrIAwr3gaXnKtbrfRVohzl X-Received: by 2002:a05:6214:398d:b0:6b0:58ce:1e24 with SMTP id 6a1803df08f44-6b059f975abmr16434896d6.57.1717750143996; Fri, 07 Jun 2024 01:49:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717750143; cv=pass; d=google.com; s=arc-20160816; b=uN9diSc4XBv4w3Ko4iJN7swZjVLOnPoK9uZkvDoDj5z6Uv1pMWVejW7SvlGQxlVwmc yU6gOIcBTkrHrwd11aDcw+xFrYhlpv0P3gvkNbniV7vtefZxVPAZm8gm8p9OoVVQGFYS ZpwVPZ90tS99Ujcex+L8fa86lpP0rgvnf/c/XBT3bv23/ykye5u4UZx5OoQs8+OJ+e/L 2o7B6o5xHwE98/rFMWTdK67ZkIZZAuZdSGcd4glxD1tHrlRt52T/0yBJzi4oOjr/J7oN 7aPkepb2UWZqg9anmicIk8IfeiwHeQjiWehbArgfz82+0mJuxlhJwaVJeiQiMydlp96m SEYg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=qglmNYi97n95S+hbJ7rPRKEMYq2eisGhF2QCWCSdlKQ=; fh=HTx+hWhxW7A9pmX86MXapJNyGhFtaRFzfw4H4nFStD4=; b=lJqTqc24FKCCpXAAP/53mSwAW9unpM1yTRPnLodYkvZfwiWlo5KsRNWVBJ5bGuaqYF 0FYulu7q0iMS/u2qzkoSoaytEGKv618wlgez46k56fnt9/4hhxEZU1st1ZO8yRWmcJ8R aEJZsVhHxUHlZQ435LC5gHI5lRgCm4Zn6qOHIGJZR/KC/lsMWb83SEDCA42PyNtS103e TSI/PNxwrt7Js42f7nwzLezi0JhlOEKTe0WIfPQUndpJOmiVBsbQdrC0QmfNri0CWpLH Tyr6jIVOQbqFiHwjI2dLbWjU7VGdoBPUQNkR61nG1L/3nmhciXBCa88amhE75pklp5o+ R1kg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=realtek.com); spf=pass (google.com: domain of linux-kernel+bounces-205636-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205636-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6b061aca51dsi4413716d6.447.2024.06.07.01.49.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 01:49:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205636-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=realtek.com); spf=pass (google.com: domain of linux-kernel+bounces-205636-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205636-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4101C1C20B7F for ; Fri, 7 Jun 2024 08:49:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D5BC715B12D; Fri, 7 Jun 2024 08:48:53 +0000 (UTC) Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) (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 B028447A6B; Fri, 7 Jun 2024 08:48:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=211.75.126.72 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717750133; cv=none; b=PTnraYeNRgO/kDc414d6SfskfK6I3CoDUJjlZdPSCjWIpdedxhn4DHFKy5BnC7DwE0t6xmQASxPbP6GjF0DnJx2wS9pQrX8IhL7Ep76vpK8nGSrtficfzWKOVWd6pMcht8NqUSklpzdsnlulHpT3nrT8QhPo928Iw9hN548fa0E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717750133; c=relaxed/simple; bh=Zmtu36yPX7kyY0bWaQJ4r2bDQd2aAvevMd9QiRHwjQI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Tp1K/+LPmS49Ma0l85J9BZXkTmrDIwao9vQuAO9aALaPbn2XL+whFWya4sv6PrzEF8qp4XZzjsczd85xK+dvPhYRbvVF+B0PNAPy7rCS3Z31Cx/3hNFP0TVTX6IVYVnH1e0GIokoa0Yymq87uNitRWSuGolYaZb7Cd5mmL3JJKE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=realtek.com; spf=pass smtp.mailfrom=realtek.com; arc=none smtp.client-ip=211.75.126.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=realtek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=realtek.com X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 4578mUviD3817535, 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 4578mUviD3817535 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 7 Jun 2024 16:48:30 +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_256_GCM_SHA384) id 15.1.2507.39; Fri, 7 Jun 2024 16:48:30 +0800 Received: from RTDOMAIN (172.21.210.98) by RTEXMBS04.realtek.com.tw (172.21.6.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Fri, 7 Jun 2024 16:48:29 +0800 From: Justin Lai To: CC: , , , , , , , , , , , Justin Lai Subject: [PATCH net-next v20 07/13] rtase: Implement a function to receive packets Date: Fri, 7 Jun 2024 16:43:15 +0800 Message-ID: <20240607084321.7254-8-justinlai0215@realtek.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240607084321.7254-1-justinlai0215@realtek.com> References: <20240607084321.7254-1-justinlai0215@realtek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: RTEXH36505.realtek.com.tw (172.21.6.25) To RTEXMBS04.realtek.com.tw (172.21.6.97) 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 | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) diff --git a/drivers/net/ethernet/realtek/rtase/rtase_main.c b/drivers/net/ethernet/realtek/rtase/rtase_main.c index 6bdb4edbfbc1..9ee9f30444f3 100644 --- a/drivers/net/ethernet/realtek/rtase/rtase_main.c +++ b/drivers/net/ethernet/realtek/rtase/rtase_main.c @@ -458,6 +458,152 @@ static void rtase_rx_ring_clear(struct rtase_ring *ring) } } +static int rtase_fragmented_frame(u32 status) +{ + return (status & (RTASE_RX_FIRST_FRAG | RTASE_RX_LAST_FRAG)) != + (RTASE_RX_FIRST_FRAG | RTASE_RX_LAST_FRAG); +} + +static void rtase_rx_csum(const struct rtase_private *tp, struct sk_buff *skb, + const union rtase_rx_desc *desc) +{ + u32 opts2 = le32_to_cpu(desc->desc_status.opts2); + + /* rx csum offload */ + if (((opts2 & RTASE_RX_V4F) && !(opts2 & RTASE_RX_IPF)) || + (opts2 & RTASE_RX_V6F)) { + if (((opts2 & RTASE_RX_TCPT) && !(opts2 & RTASE_RX_TCPF)) || + ((opts2 & RTASE_RX_UDPT) && !(opts2 & RTASE_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 rtase_rx_desc *desc, struct sk_buff *skb) +{ + u32 opts2 = le32_to_cpu(desc->desc_status.opts2); + + if (!(opts2 & RTASE_RX_VLAN_TAG)) + return; + + __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), + swab16(opts2 & RTASE_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; + union rtase_rx_desc *desc_base = ring->desc; + u32 pkt_size, cur_rx, delta, entry, status; + struct net_device *dev = tp->dev; + union rtase_rx_desc *desc; + struct sk_buff *skb; + int workdone = 0; + + cur_rx = ring->cur_idx; + entry = cur_rx % RTASE_NUM_DESC; + desc = &desc_base[entry]; + + do { + /* make sure discriptor has been updated */ + rmb(); + status = le32_to_cpu(desc->desc_status.opts1); + + if (status & RTASE_DESC_OWN) + break; + + if (unlikely(status & RTASE_RX_RES)) { + if (net_ratelimit()) + netdev_warn(dev, "Rx ERROR. status = %08x\n", + status); + + dev->stats.rx_errors++; + + if (status & (RTASE_RX_RWT | RTASE_RX_RUNT)) + dev->stats.rx_length_errors++; + + if (status & RTASE_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 & RTASE_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_sw_netstats_rx_add(dev, pkt_size); + +skip_process_pkt: + workdone++; + cur_rx++; + entry = cur_rx % RTASE_NUM_DESC; + desc = ring->desc + sizeof(union rtase_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 + RTASE_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