devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafał Miłecki" <rafal@milecki.pl>
To: "Andrew Lunn" <andrew@lunn.ch>, "Rafał Miłecki" <zajec5@gmail.com>
Cc: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Rob Herring <robh+dt@kernel.org>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Randy Dunlap <rdunlap@infradead.org>,
	Masahiro Yamada <masahiroy@kernel.org>,
	netdev@vger.kernel.org, devicetree@vger.kernel.org,
	bcm-kernel-feedback-list@broadcom.com
Subject: Re: [PATCH V3 net-next 2/2] net: broadcom: bcm4908_enet: add BCM4908 controller driver
Date: Wed, 10 Feb 2021 08:57:50 +0100	[thread overview]
Message-ID: <b13c82b5-49fb-533d-dfd6-dcc2f4c9f90d@milecki.pl> (raw)
In-Reply-To: <YCNHU2g1m4dFahBd@lunn.ch>

On 10.02.2021 03:39, Andrew Lunn wrote:
>> +static inline u32 enet_read(struct bcm4908_enet *enet, u16 offset)
>> +{
>> +	return readl(enet->base + offset);
>> +}
> 
> No inline functions in C files please. Let the compiler decide.

According to the kernel's coding style (coding-style.rst) inline should
*not* be used for 3+ LOC functions in general. According to that, I should
only fix my enet_maskset() which isn't 1 LOC indeed.

If that Documentation is outdated and/or inaccurate, could you propose a
change for it, please? That rule comes from 2006 (a771f2b82aa2), so I
understand it may need updating. We should have that officially documented
though, to avoid per-tree or per-maintainer rules for stuff like this.

Personally I don't have enough compiler knowledge to propose and/or discuss
such stuff. That's why I prefer following Documentation written by smarter
ones ;)


>> +static int bcm4908_dma_alloc_buf_descs(struct bcm4908_enet *enet,
>> +				       struct bcm4908_enet_dma_ring *ring)
>> +{
>> +	int size = ring->length * sizeof(struct bcm4908_enet_dma_ring_bd);
>> +	struct device *dev = enet->dev;
>> +
>> +	ring->cpu_addr = dma_alloc_coherent(dev, size, &ring->dma_addr, GFP_KERNEL);
>> +	if (!ring->cpu_addr)
>> +		return -ENOMEM;
>> +
>> +	if (((uintptr_t)ring->cpu_addr) & (0x40 - 1)) {
>> +		dev_err(dev, "Invalid DMA ring alignment\n");
>> +		goto err_free_buf_descs;
>> +	}
>> +
>> +	ring->slots = kzalloc(ring->length * sizeof(*ring->slots), GFP_KERNEL);
>> +	if (!ring->slots)
>> +		goto err_free_buf_descs;
>> +
>> +	memset(ring->cpu_addr, 0, size);
> 
> It looks like dma_alloc_coherent() will perform a clear. See __dma_alloc_from_coherent()

Thanks!


>> +static void bcm4908_enet_dma_reset(struct bcm4908_enet *enet)
>> +{
>> +	struct bcm4908_enet_dma_ring *rings[] = { &enet->rx_ring, &enet->tx_ring };
>> +	int i;
>> +
>> +	/* Disable the DMA controller and channel */
>> +	for (i = 0; i < ARRAY_SIZE(rings); i++)
>> +		enet_write(enet, rings[i]->cfg_block + ENET_DMA_CH_CFG, 0);
>> +	enet_maskset(enet, ENET_DMA_CONTROLLER_CFG, ENET_DMA_CTRL_CFG_MASTER_EN, 0);
> 
> Is there a need to wait for any in flight DMA transfers to complete
> before you go further? Or is that what
> bcm4908_enet_dma_rx_ring_disable() is doing?

bcm4908_enet_dma_rx_ring_disable() checks for DMA to "confirm" it got stopped.


>> +
>> +	/* Reset channels state */
>> +	for (i = 0; i < ARRAY_SIZE(rings); i++) {
>> +		struct bcm4908_enet_dma_ring *ring = rings[i];
>> +
>> +		enet_write(enet, ring->st_ram_block + ENET_DMA_CH_STATE_RAM_BASE_DESC_PTR, 0);
>> +		enet_write(enet, ring->st_ram_block + ENET_DMA_CH_STATE_RAM_STATE_DATA, 0);
>> +		enet_write(enet, ring->st_ram_block + ENET_DMA_CH_STATE_RAM_DESC_LEN_STATUS, 0);
>> +		enet_write(enet, ring->st_ram_block + ENET_DMA_CH_STATE_RAM_DESC_BASE_BUFPTR, 0);
>> +	}
>> +}
>> +
>> +static void bcm4908_enet_dma_tx_ring_ensable(struct bcm4908_enet *enet,
>> +					     struct bcm4908_enet_dma_ring *ring)
> 
> enable not ensable?

Absolutely :)


>> +static int bcm4908_enet_open(struct net_device *netdev)
>> +{
>> +	struct bcm4908_enet *enet = netdev_priv(netdev);
>> +	struct device *dev = enet->dev;
>> +	int err;
>> +
>> +	err = request_irq(netdev->irq, bcm4908_enet_irq_handler, 0, "enet", enet);
>> +	if (err) {
>> +		dev_err(dev, "Failed to request IRQ %d: %d\n", netdev->irq, err);
>> +		return err;
>> +	}
>> +
>> +	bcm4908_enet_gmac_init(enet);
>> +	bcm4908_enet_dma_reset(enet);
>> +	bcm4908_enet_dma_init(enet);
>> +
>> +	enet_umac_set(enet, UMAC_CMD, CMD_TX_EN | CMD_RX_EN);
>> +
>> +	enet_set(enet, ENET_DMA_CONTROLLER_CFG, ENET_DMA_CTRL_CFG_MASTER_EN);
>> +	enet_maskset(enet, ENET_DMA_CONTROLLER_CFG, ENET_DMA_CTRL_CFG_FLOWC_CH1_EN, 0);
>> +	bcm4908_enet_dma_rx_ring_enable(enet, &enet->rx_ring);
>> +
>> +	napi_enable(&enet->napi);
>> +	netif_carrier_on(netdev);
>> +	netif_start_queue(netdev);
>> +
>> +	bcm4908_enet_intrs_ack(enet);
>> +	bcm4908_enet_intrs_on(enet);
>> +
>> +	return 0;
>> +}
> 
> No PHY handling? It would be normal to connect the phy in open.

I believe so, this controller is integrated into SoC and is always connected
to the (internal) switch port. It uses a fixed link.

  reply	other threads:[~2021-02-10  8:09 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05 21:44 [PATCH net-next 1/2] dt-bindings: net: document BCM4908 Ethernet controller Rafał Miłecki
2021-02-05 21:44 ` [PATCH net-next 2/2] net: broadcom: bcm4908enet: add BCM4908 controller driver Rafał Miłecki
2021-02-05 23:47   ` kernel test robot
2021-02-07 22:26 ` [PATCH V2 net-next 1/2] dt-bindings: net: document BCM4908 Ethernet controller Rafał Miłecki
2021-02-07 22:26   ` [PATCH V2 net-next 2/2] net: broadcom: bcm4908enet: add BCM4908 controller driver Rafał Miłecki
2021-02-09 23:01     ` [PATCH V3 net-next 1/2] dt-bindings: net: document BCM4908 Ethernet controller Rafał Miłecki
2021-02-09 23:01       ` [PATCH V3 net-next 2/2] net: broadcom: bcm4908_enet: add BCM4908 controller driver Rafał Miłecki
2021-02-10  2:39         ` Andrew Lunn
2021-02-10  7:57           ` Rafał Miłecki [this message]
2021-02-10  9:47         ` [PATCH V4 net-next 1/2] dt-bindings: net: document BCM4908 Ethernet controller Rafał Miłecki
2021-02-10  9:47           ` [PATCH V4 net-next 2/2] net: broadcom: bcm4908_enet: add BCM4908 controller driver Rafał Miłecki
2021-02-11  0:44             ` Andrew Lunn
2021-02-11 12:12         ` [PATCH net-next 5.12 0/8] bcm4908_enet: post-review fixes Rafał Miłecki
2021-02-11 12:12           ` [PATCH net-next 5.12 1/8] dt-bindings: net: rename BCM4908 Ethernet binding Rafał Miłecki
2021-02-11 17:44             ` Florian Fainelli
2021-02-11 12:12           ` [PATCH net-next 5.12 2/8] dt-bindings: net: bcm4908-enet: include ethernet-controller.yaml Rafał Miłecki
2021-02-11 17:44             ` Florian Fainelli
2021-02-11 12:12           ` [PATCH net-next 5.12 3/8] net: broadcom: rename BCM4908 driver & update DT binding Rafał Miłecki
2021-02-11 17:44             ` Florian Fainelli
2021-02-11 12:12           ` [PATCH net-next 5.12 4/8] net: broadcom: bcm4908_enet: drop unneeded memset() Rafał Miłecki
2021-02-11 17:45             ` Florian Fainelli
2021-02-11 12:12           ` [PATCH net-next 5.12 5/8] net: broadcom: bcm4908_enet: drop "inline" from C functions Rafał Miłecki
2021-02-11 17:45             ` Florian Fainelli
2021-02-11 12:12           ` [PATCH net-next 5.12 6/8] net: broadcom: bcm4908_enet: fix minor typos Rafał Miłecki
2021-02-11 17:46             ` Florian Fainelli
2021-02-11 12:12           ` [PATCH net-next 5.12 7/8] net: broadcom: bcm4908_enet: fix received skb length Rafał Miłecki
2021-02-11 17:46             ` Florian Fainelli
2021-02-11 12:12           ` [PATCH net-next 5.12 8/8] net: broadcom: bcm4908_enet: fix endianness in xmit code Rafał Miłecki
2021-02-11 17:46             ` Florian Fainelli
2021-02-11 23:10           ` [PATCH net-next 5.12 0/8] bcm4908_enet: post-review fixes patchwork-bot+netdevbpf
2021-02-09 21:43   ` [PATCH V2 net-next 1/2] dt-bindings: net: document BCM4908 Ethernet controller Rob Herring
2021-02-09 22:07     ` Rafał Miłecki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b13c82b5-49fb-533d-dfd6-dcc2f4c9f90d@milecki.pl \
    --to=rafal@milecki.pl \
    --cc=andrew@lunn.ch \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=kuba@kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=robh+dt@kernel.org \
    --cc=zajec5@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).