Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp780382lqo; Fri, 17 May 2024 00:57:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUSiZlQ0wWCkHFXJIYMBETihN4sOwDUTXyHZlJReIAsSbZSyzDJP/6770k+3lJZuF7exBxfuDVCNPfLuMo7t3nkh3FTRMg4hdTicLScGQ== X-Google-Smtp-Source: AGHT+IFYxN8h/WOLr8ymj06JIfROiYq9pyc9lG5fZ3VD0Hxz1hHuQ8pslUPtH7BmiI7VrA51QfRP X-Received: by 2002:a17:907:3595:b0:a5a:8bde:8300 with SMTP id a640c23a62f3a-a5a8bde992cmr631230566b.30.1715932655371; Fri, 17 May 2024 00:57:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715932655; cv=pass; d=google.com; s=arc-20160816; b=vt+w4y1Ould0XrDop25vQdxs2hot3Sg3TK4spn4eYz/y/Gv4mjFDh1HkodU1gnm5mn EgmogyXZvez6/UFcZIjhfucwIPOONsIr8YoqYhD/2JkjDqY6Mm3PbCsXc1ghSTNBY29D RZTdJS8gg/3CUB+psrJmokqHqnf+8QdtJ1diPrcEbNasPw5xk7uQwv2PmSgokfjdty5i pfAj2zb85i3SgMBMimkES8QflYsmX380E+PqsAQcFvQQaqkc6gjmzvD6SoNAZDSFjBJp BmCdY+cwTFBMRbUxm8FUnN6YjudPIr3hy4XfqxIBE84n6b31v+KqQPtMvAWSFpM4arPH OVEw== 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=oK4/6v4/z8zo+lKMQiGWMPnSqKzJQjP6kabUkcaTAnk=; fh=HTx+hWhxW7A9pmX86MXapJNyGhFtaRFzfw4H4nFStD4=; b=KhP6rjDKJgybn3JnBxvxLGFd7bfKfLfeIe6FzwsYLWQR3PMiwPItF+RP5Gp/jvkgcJ D23+L1k9IoWrvhgncvlzdbwli6rQilCX02c3iuUnNFdnFZUt9vjc8NXh75nAnzb0/vuL FOAXGlaFZXDxDzl+XPzBJrBwDGnaYz8vSY48bn8G5GNnU94iUlhudvEhmKLDREOikvLt mR22q8EkCPdhIb+F9ENLb0qDc3XQin9afq/6wQzOAEyl4qP0uSA7/HLIQl80s1iImD0r dmjGmEwXYI9JRrYYI2Uxf+Wv00eV8EaTgQ58pEqAyKavNEnkzvaKP935qKE2IdObCDrw hr4A==; 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-181827-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181827-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17b21e33si986550866b.304.2024.05.17.00.57.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 00:57:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181827-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=realtek.com); spf=pass (google.com: domain of linux-kernel+bounces-181827-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181827-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 am.mirrors.kernel.org (Postfix) with ESMTPS id F07711F21898 for ; Fri, 17 May 2024 07:57:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4D5BE24215; Fri, 17 May 2024 07:57:07 +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 DF89B1803A; Fri, 17 May 2024 07:57:04 +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=1715932626; cv=none; b=YAnLmhw3sKbcXA/3llbmp4WkIfa9vu9WMgPhA+LEhgZxkUHlt2telf7+xF0FU1LhOpxNHfFGTl5h64BoOHT5O4q5A5W5VMjNspq96qaCvqebiJjJaPtbmgF291GQuFSgGVAdQqut1XtB3w+DwmMh7iIs3+hnhyN4P93vmC2sZso= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715932626; c=relaxed/simple; bh=nRXR2LjG3zEYoBYs/eBWZZzXBm17qacK7QdMd8NBzuk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=A5ysY7O/LHR2R+kNC7DC1Y1l2/PQQvk11fYQhGKysR1qVf1B1jQn265ErCcR+vBE0EndmXas2S85zLCI5nCYZMG/drMnyNrt0wMylFpY52Rs2ni1FGlxWxMb0ZVZ0QemYdH26EOz+i9zWyAsxiVrRTok0jQoUGU5aDFPIvVOLZo= 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 44H7uhIE32159345, 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 44H7uhIE32159345 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 May 2024 15:56: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_256_GCM_SHA384) id 15.1.2507.39; Fri, 17 May 2024 15:56: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_256_GCM_SHA384) id 15.1.2507.35; Fri, 17 May 2024 15:56:42 +0800 From: Justin Lai To: CC: , , , , , , , , , , , Justin Lai Subject: [PATCH net-next v19 07/13] rtase: Implement a function to receive packets Date: Fri, 17 May 2024 15:52:56 +0800 Message-ID: <20240517075302.7653-8-justinlai0215@realtek.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240517075302.7653-1-justinlai0215@realtek.com> References: <20240517075302.7653-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 fe9a5bd645e2..266272d8e0ab 100644 --- a/drivers/net/ethernet/realtek/rtase/rtase_main.c +++ b/drivers/net/ethernet/realtek/rtase/rtase_main.c @@ -457,6 +457,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