[PATCH net-next v6 2/3] net: cortina: Add CS7542 CPU network datapath

Andrew Lunn andrew at lunn.ch
Tue Dec 1 18:08:02 PST 2026


> +	ret = read_poll_timeout(readl, val,
> +				!(val & FE_HASH_STATUS_INIT_IN_PROGRESS),
> +				FE_HASH_INIT_POLL_US, FE_HASH_INIT_TIMEOUT_US,
> +				true, fe + FETOP_HASH_STATUS);
> +	if (ret) {
> +		dev_err(dev, "FE hash init timeout: 0x%08x\n", val);
> +		return ret;
> +	}
> +
> +	return 0;

This can be simplified to:

> +	if (ret)
> +		dev_err(dev, "FE hash init timeout: 0x%08x\n", val);
> +
> + 	return ret;
> +	}

> +static int fe_class_write(struct device *dev, void __iomem *fe,
> +			  unsigned int idx, unsigned int sdb_idx,
> +			  unsigned int lspid, unsigned int lspid_mask,
> +			  unsigned int rule_priority)
> +{
> +	u32 data[20];
> +	unsigned int i;

Reverse Christmas tree.

> +static int cs_ne_ni_init(struct cs_ne *ne)
> +{
> +	u32 val;
> +	int ret, i;

Ditto

> +/* Probe errors run before any RX address is published to hardware. */
> +static void cs_ne_rx_cleanup(void *data)
> +{
> +	struct cs_ne *ne = data;
> +	struct cs_ne_rx_buf *buf;
> +	unsigned long index;



> +static void cs_ne_tx_reap(struct cs_ne *ne);

No forward declarations. Put the functions in the correct order.

> +
> +static int cs_ne_rx_poll(struct napi_struct *napi, int budget)
> +{
> +	struct cs_ne_port *port = container_of(napi, struct cs_ne_port, napi);
> +	struct cs_ne *ne = port->ne;
> +	struct net_device *ndev = port->ndev;
> +	struct cs_ne_rx_buf *bufs[CS_NE_RX_MAX_BUFS];
> +	dma_addr_t dma[CS_NE_RX_MAX_BUFS];
> +	void __iomem *desc;
> +	struct sk_buff *skb;
> +	void *data;
> +	u32 wr, rd, next, w1, hdre_hi, hdre_lo, pkt_size;
> +	u32 off, total, dma_bytes, seg, nbufs, remaining;
> +	unsigned int i;
> +	int done = 0;
> +	bool valid, retry = false, defer = false;
> +	unsigned long flags;

More Reverse Christmas.

Also, given the number of local variables here, maybe this function
needs breaking up into helpers.

https://www.kernel.org/doc/html/latest/process/coding-style.html#functions

> +static netdev_tx_t cs_ne_xmit_sg(struct sk_buff *skb, struct net_device *ndev)
> +{
> +	struct cs_ne_port *port = netdev_priv(ndev);
> +	struct cs_ne *ne = port->ne;
> +	struct cs_ne_txq *txq = &ne->txq;
> +	int nfrags = skb_shinfo(skb)->nr_frags;
> +	u16 first = txq->head;
> +	struct cs_ne_tx_buf *buf;
> +	dma_addr_t dma;
> +	u32 free, len;
> +	int i;

> +static int cs_ne_stop(struct net_device *ndev)

Probably should be a void function. If anything goes wrong, there is
not much you can do about it.

> +static int cs_ne_set_mac_address(struct net_device *ndev, void *addr)
> +{
> +	struct cs_ne_port *port = netdev_priv(ndev);
> +	struct cs_ne *ne = port->ne;
> +	struct sockaddr *sa = addr;
> +	int ret, i;
> +
> +	ret = eth_prepare_mac_addr_change(ndev, addr);
> +	if (ret)
> +		return ret;
> +	/* NI_MAC_ADDR0/1 are shared; only the last byte is per-port. */

Can you explain that a bit more.

"ip link set address" lets you set the address on an interface, and
each interface should be independent of other interfaces.

> +		if (!ret) {
> +			if (fixed && memcmp(base, ne->addresses[id], ETH_ALEN - 1)) {
> +				of_node_put(np);
> +				return dev_err_probe(ne->dev, -EINVAL,
> +						     "MACs must share their first five bytes\n");

Why? Is the hardware broken?

> +static int cs_ne_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct device_node *np;
> +	struct cs_ne *ne;
> +	int ret, i, nports = 0;

	Andrew



More information about the linux-arm-kernel mailing list