Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp110295ybj; Wed, 6 May 2020 12:46:58 -0700 (PDT) X-Google-Smtp-Source: APiQypK0eZ47hh1UG6BeofcRS776ZEu/VB78axLkIIPzeZV7Wornm1Bk67ysbmBsC4H+0/ugspY2 X-Received: by 2002:a50:d615:: with SMTP id x21mr8019078edi.62.1588794418448; Wed, 06 May 2020 12:46:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588794418; cv=none; d=google.com; s=arc-20160816; b=GZ9nZxDiR6jwV3bKiqjNKeKk6tnm4BQ/CCztLYavqQEMS3JpVCErnsmex8H3tr0XPx aCOyQi0FUv+ygAYdycELWy4rRSrb82ltFmgu8l2SNHB6CWYh+gWTBaxu67lUIIHVr8zw gwdD7OmM+jJXI0cLS7RsHwa7GlKvXvS6cm8rKgiRCbsrgCZrWWNP+vXFPR5xULsfalrH FpBRJp+JN7IBgJjWkwXl++P/N1Qe5z7mC8NJUdjbHLhFEmkrfeqWy3c6BK46/QWC9y9a wUkRtYy5iN+d/zexvOiNEnfIuvIhlZZmAHuQC2UngvN+fM2jkN+2ST7QklDB+OuwiT8R yIQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=rlCb1RER7LbxG0o0Kz+S2LzHMiQJpNjL8WZ8PG8eeXY=; b=lmNPIVku1un+WUfRMRN1+nkVJwhoV/GLVBbUNOZ71CSwPBfPf3VjYbNMjhrV5IpzsV +Sdz1kXGCnHfE546HpUbViLzFX5rUC4EF3RsY3MAizulTpseMJUL69DKfhpOIiptmxjO nDAAXvBiHMWqYyimJze6LyQZu17vAwjNvheaikMugh05H3WsTxCC4zW7RL+0kjJSj/9c ggR65aModgjtaNsTALVPKSWY5VtXcEoPbtzJgbRE7VTbzmM9VvJ0qoPTInXkYsgNiim0 /Ygddv0XqawH2woXUg4wC2PWPrhRg4QvzBmjZvv6ig5ExtjvTaoUgABYwp8gSzJ3S23s 7V5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iuGK0qrh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y7si1601106edv.512.2020.05.06.12.46.33; Wed, 06 May 2020 12:46:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iuGK0qrh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729122AbgEFRT4 (ORCPT + 99 others); Wed, 6 May 2020 13:19:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:39298 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728336AbgEFRT4 (ORCPT ); Wed, 6 May 2020 13:19:56 -0400 Received: from kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com (unknown [163.114.132.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 303CA20736; Wed, 6 May 2020 17:19:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588785595; bh=Vx2laojPRA9af0b+TlZJnd1rj8BT6IbkCPf9uW8twE8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=iuGK0qrhphha7crkNxqfd/exR5+vrUBVOQvCaqmSpI6mMtTv2Bb9e5KAxHVaNhOJf cqiBsvormrGZm4pmx0ZvNJS1V19n58ngNSsoNqdXvSsTy/98rlzZ+Y1iImcjRJgUcu qekIZfCuEXFEPE/QxUXdK/yglIY8ZHVMjybnLH2o= Date: Wed, 6 May 2020 10:19:53 -0700 From: Jakub Kicinski To: Bartosz Golaszewski Cc: Rob Herring , "David S . Miller" , Matthias Brugger , John Crispin , Sean Wang , Mark Lee , Arnd Bergmann , Fabien Parent , devicetree , Linux Kernel Mailing List , netdev , Linux ARM , linux-mediatek@lists.infradead.org, Bartosz Golaszewski Subject: Re: [PATCH 06/11] net: ethernet: mtk-eth-mac: new driver Message-ID: <20200506101953.208e5366@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> In-Reply-To: References: <20200505140231.16600-1-brgl@bgdev.pl> <20200505140231.16600-7-brgl@bgdev.pl> <20200505110447.2404985c@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 6 May 2020 09:09:52 +0200 Bartosz Golaszewski wrote: > > > +} > > > > Why do you clean the TX ring from a work rather than from the NAPI > > context? > > So this was unclear to me, that's why I went with a workqueue. The > budget argument in napi poll is for RX. Should I put some cap on the > number of TX descriptors processed in napi context? The prevailing wisdom is to not count the TX cleanup as work at all. I think the best practice is to first clean up all the TX you can, and then do at must @budget of RX. Perhaps one day we will come up with a good way of capping TX, but today not counting it towards budget is the safe choice. > > > +static int mtk_mac_receive_packet(struct mtk_mac_priv *priv) > > > +{ > > > + struct net_device *ndev = mtk_mac_get_netdev(priv); > > > + struct mtk_mac_ring *ring = &priv->rx_ring; > > > + struct device *dev = mtk_mac_get_dev(priv); > > > + struct mtk_mac_ring_desc_data desc_data; > > > + struct sk_buff *new_skb; > > > + int ret; > > > + > > > + mtk_mac_lock(priv); > > > + ret = mtk_mac_ring_pop_tail(ring, &desc_data); > > > + mtk_mac_unlock(priv); > > > + if (ret) > > > + return -1; > > > + > > > + mtk_mac_dma_unmap_rx(priv, &desc_data); > > > + > > > + if ((desc_data.flags & MTK_MAC_DESC_BIT_RX_CRCE) || > > > + (desc_data.flags & MTK_MAC_DESC_BIT_RX_OSIZE)) { > > > + /* Error packet -> drop and reuse skb. */ > > > + new_skb = desc_data.skb; > > > + goto map_skb; > > > + } > > > + > > > + new_skb = mtk_mac_alloc_skb(ndev); > > > + if (!new_skb) { > > > + netdev_err(ndev, "out of memory for skb\n"); > > > > No need for printing, kernel will complain loudly about oom. > > > > > + ndev->stats.rx_dropped++; > > > + new_skb = desc_data.skb; > > > + goto map_skb; > > > + } > > > + > > > + skb_put(desc_data.skb, desc_data.len); > > > + desc_data.skb->ip_summed = CHECKSUM_NONE; > > > + desc_data.skb->protocol = eth_type_trans(desc_data.skb, ndev); > > > + desc_data.skb->dev = ndev; > > > + netif_receive_skb(desc_data.skb); > > > + > > > +map_skb: > > > + desc_data.dma_addr = mtk_mac_dma_map_rx(priv, new_skb); > > > + if (dma_mapping_error(dev, desc_data.dma_addr)) { > > > + dev_kfree_skb(new_skb); > > > + netdev_err(ndev, "DMA mapping error of RX descriptor\n"); > > > + return -ENOMEM; > > > > In this case nothing will ever replenish the RX ring right? If we hit > > this condition 128 times the ring will be empty? > > Indeed. What should I do if this fails though? I think if you move things around it should work: skb = pop_tail(); if (!skb) return; new_skb = alloc(); if (!new_skb) goto reuse; dma_map(new_skb); if (error) goto reuse; dma_unmap(skb); if (do_packet_processing()) free(skb); else receive(skb); put_on_ring(new_skb);