Lines Matching +full:xrx200 +full:- +full:net

1 // SPDX-License-Identifier: GPL-2.0
3 * Lantiq / Intel PMAC driver for XRX200 SoCs
7 * Copyright (C) 2017 - 2018 Hauke Mehrtens <hauke@hauke-m.de>
25 #define XRX200_DMA_DATA_LEN (SZ_64K - 1)
48 /* Remove Layer-2 header from packets from PMAC to DMA */
95 return __raw_readl(priv->pmac_reg + offset); in xrx200_pmac_r32()
100 __raw_writel(val, priv->pmac_reg + offset); in xrx200_pmac_w32()
135 struct ltq_dma_desc *desc = &ch->dma.desc_base[ch->dma.desc]; in xrx200_flush_dma()
137 if ((desc->ctl & (LTQ_DMA_OWN | LTQ_DMA_C)) != LTQ_DMA_C) in xrx200_flush_dma()
140 desc->ctl = LTQ_DMA_OWN | LTQ_DMA_RX_OFFSET(NET_IP_ALIGN) | in xrx200_flush_dma()
141 ch->priv->rx_buf_size; in xrx200_flush_dma()
142 ch->dma.desc++; in xrx200_flush_dma()
143 ch->dma.desc %= LTQ_DESC_NUM; in xrx200_flush_dma()
151 napi_enable(&priv->chan_tx.napi); in xrx200_open()
152 ltq_dma_open(&priv->chan_tx.dma); in xrx200_open()
153 ltq_dma_enable_irq(&priv->chan_tx.dma); in xrx200_open()
155 napi_enable(&priv->chan_rx.napi); in xrx200_open()
156 ltq_dma_open(&priv->chan_rx.dma); in xrx200_open()
164 xrx200_flush_dma(&priv->chan_rx); in xrx200_open()
165 ltq_dma_enable_irq(&priv->chan_rx.dma); in xrx200_open()
178 napi_disable(&priv->chan_rx.napi); in xrx200_close()
179 ltq_dma_close(&priv->chan_rx.dma); in xrx200_close()
181 napi_disable(&priv->chan_tx.napi); in xrx200_close()
182 ltq_dma_close(&priv->chan_tx.dma); in xrx200_close()
189 void *buf = ch->rx_buff[ch->dma.desc]; in xrx200_alloc_buf()
190 struct xrx200_priv *priv = ch->priv; in xrx200_alloc_buf()
194 ch->rx_buff[ch->dma.desc] = alloc(priv->rx_skb_size); in xrx200_alloc_buf()
195 if (!ch->rx_buff[ch->dma.desc]) { in xrx200_alloc_buf()
196 ch->rx_buff[ch->dma.desc] = buf; in xrx200_alloc_buf()
197 ret = -ENOMEM; in xrx200_alloc_buf()
201 mapping = dma_map_single(priv->dev, ch->rx_buff[ch->dma.desc], in xrx200_alloc_buf()
202 priv->rx_buf_size, DMA_FROM_DEVICE); in xrx200_alloc_buf()
203 if (unlikely(dma_mapping_error(priv->dev, mapping))) { in xrx200_alloc_buf()
204 skb_free_frag(ch->rx_buff[ch->dma.desc]); in xrx200_alloc_buf()
205 ch->rx_buff[ch->dma.desc] = buf; in xrx200_alloc_buf()
206 ret = -ENOMEM; in xrx200_alloc_buf()
210 ch->dma.desc_base[ch->dma.desc].addr = mapping + NET_SKB_PAD + NET_IP_ALIGN; in xrx200_alloc_buf()
214 ch->dma.desc_base[ch->dma.desc].ctl = in xrx200_alloc_buf()
215 LTQ_DMA_OWN | LTQ_DMA_RX_OFFSET(NET_IP_ALIGN) | priv->rx_buf_size; in xrx200_alloc_buf()
222 struct xrx200_priv *priv = ch->priv; in xrx200_hw_receive()
223 struct ltq_dma_desc *desc = &ch->dma.desc_base[ch->dma.desc]; in xrx200_hw_receive()
224 void *buf = ch->rx_buff[ch->dma.desc]; in xrx200_hw_receive()
225 u32 ctl = desc->ctl; in xrx200_hw_receive()
227 struct net_device *net_dev = priv->net_dev; in xrx200_hw_receive()
233 ch->dma.desc++; in xrx200_hw_receive()
234 ch->dma.desc %= LTQ_DESC_NUM; in xrx200_hw_receive()
237 net_dev->stats.rx_dropped++; in xrx200_hw_receive()
242 skb = build_skb(buf, priv->rx_skb_size); in xrx200_hw_receive()
245 net_dev->stats.rx_dropped++; in xrx200_hw_receive()
246 return -ENOMEM; in xrx200_hw_receive()
252 /* add buffers to skb via skb->frag_list */ in xrx200_hw_receive()
254 ch->skb_head = skb; in xrx200_hw_receive()
255 ch->skb_tail = skb; in xrx200_hw_receive()
257 } else if (ch->skb_head) { in xrx200_hw_receive()
258 if (ch->skb_head == ch->skb_tail) in xrx200_hw_receive()
259 skb_shinfo(ch->skb_tail)->frag_list = skb; in xrx200_hw_receive()
261 ch->skb_tail->next = skb; in xrx200_hw_receive()
262 ch->skb_tail = skb; in xrx200_hw_receive()
263 ch->skb_head->len += skb->len; in xrx200_hw_receive()
264 ch->skb_head->data_len += skb->len; in xrx200_hw_receive()
265 ch->skb_head->truesize += skb->truesize; in xrx200_hw_receive()
269 ch->skb_head->protocol = eth_type_trans(ch->skb_head, net_dev); in xrx200_hw_receive()
270 net_dev->stats.rx_packets++; in xrx200_hw_receive()
271 net_dev->stats.rx_bytes += ch->skb_head->len; in xrx200_hw_receive()
272 netif_receive_skb(ch->skb_head); in xrx200_hw_receive()
273 ch->skb_head = NULL; in xrx200_hw_receive()
274 ch->skb_tail = NULL; in xrx200_hw_receive()
291 struct ltq_dma_desc *desc = &ch->dma.desc_base[ch->dma.desc]; in xrx200_poll_rx()
293 if ((desc->ctl & (LTQ_DMA_OWN | LTQ_DMA_C)) == LTQ_DMA_C) { in xrx200_poll_rx()
306 if (napi_complete_done(&ch->napi, rx)) in xrx200_poll_rx()
307 ltq_dma_enable_irq(&ch->dma); in xrx200_poll_rx()
317 struct net_device *net_dev = ch->priv->net_dev; in xrx200_tx_housekeeping()
323 struct ltq_dma_desc *desc = &ch->dma.desc_base[ch->tx_free]; in xrx200_tx_housekeeping()
325 if ((desc->ctl & (LTQ_DMA_OWN | LTQ_DMA_C)) == LTQ_DMA_C) { in xrx200_tx_housekeeping()
326 struct sk_buff *skb = ch->skb[ch->tx_free]; in xrx200_tx_housekeeping()
329 bytes += skb->len; in xrx200_tx_housekeeping()
330 ch->skb[ch->tx_free] = NULL; in xrx200_tx_housekeeping()
332 memset(&ch->dma.desc_base[ch->tx_free], 0, in xrx200_tx_housekeeping()
334 ch->tx_free++; in xrx200_tx_housekeeping()
335 ch->tx_free %= LTQ_DESC_NUM; in xrx200_tx_housekeeping()
341 net_dev->stats.tx_packets += pkts; in xrx200_tx_housekeeping()
342 net_dev->stats.tx_bytes += bytes; in xrx200_tx_housekeeping()
343 netdev_completed_queue(ch->priv->net_dev, pkts, bytes); in xrx200_tx_housekeeping()
350 if (napi_complete_done(&ch->napi, pkts)) in xrx200_tx_housekeeping()
351 ltq_dma_enable_irq(&ch->dma); in xrx200_tx_housekeeping()
361 struct xrx200_chan *ch = &priv->chan_tx; in xrx200_start_xmit()
362 struct ltq_dma_desc *desc = &ch->dma.desc_base[ch->dma.desc]; in xrx200_start_xmit()
367 skb->dev = net_dev; in xrx200_start_xmit()
369 net_dev->stats.tx_dropped++; in xrx200_start_xmit()
373 len = skb->len; in xrx200_start_xmit()
375 if ((desc->ctl & (LTQ_DMA_OWN | LTQ_DMA_C)) || ch->skb[ch->dma.desc]) { in xrx200_start_xmit()
381 ch->skb[ch->dma.desc] = skb; in xrx200_start_xmit()
383 mapping = dma_map_single(priv->dev, skb->data, len, DMA_TO_DEVICE); in xrx200_start_xmit()
384 if (unlikely(dma_mapping_error(priv->dev, mapping))) in xrx200_start_xmit()
390 desc->addr = mapping - byte_offset; in xrx200_start_xmit()
393 desc->ctl = LTQ_DMA_OWN | LTQ_DMA_SOP | LTQ_DMA_EOP | in xrx200_start_xmit()
395 ch->dma.desc++; in xrx200_start_xmit()
396 ch->dma.desc %= LTQ_DESC_NUM; in xrx200_start_xmit()
397 if (ch->dma.desc == ch->tx_free) in xrx200_start_xmit()
406 net_dev->stats.tx_dropped++; in xrx200_start_xmit()
407 net_dev->stats.tx_errors++; in xrx200_start_xmit()
415 struct xrx200_chan *ch_rx = &priv->chan_rx; in xrx200_change_mtu()
416 int old_mtu = net_dev->mtu; in xrx200_change_mtu()
422 net_dev->mtu = new_mtu; in xrx200_change_mtu()
423 priv->rx_buf_size = xrx200_buffer_size(new_mtu); in xrx200_change_mtu()
424 priv->rx_skb_size = xrx200_skb_size(priv->rx_buf_size); in xrx200_change_mtu()
431 napi_disable(&ch_rx->napi); in xrx200_change_mtu()
432 ltq_dma_close(&ch_rx->dma); in xrx200_change_mtu()
435 xrx200_poll_rx(&ch_rx->napi, LTQ_DESC_NUM); in xrx200_change_mtu()
436 curr_desc = ch_rx->dma.desc; in xrx200_change_mtu()
438 for (ch_rx->dma.desc = 0; ch_rx->dma.desc < LTQ_DESC_NUM; in xrx200_change_mtu()
439 ch_rx->dma.desc++) { in xrx200_change_mtu()
440 buff = ch_rx->rx_buff[ch_rx->dma.desc]; in xrx200_change_mtu()
443 net_dev->mtu = old_mtu; in xrx200_change_mtu()
444 priv->rx_buf_size = xrx200_buffer_size(old_mtu); in xrx200_change_mtu()
445 priv->rx_skb_size = xrx200_skb_size(priv->rx_buf_size); in xrx200_change_mtu()
451 ch_rx->dma.desc = curr_desc; in xrx200_change_mtu()
453 napi_enable(&ch_rx->napi); in xrx200_change_mtu()
454 ltq_dma_open(&ch_rx->dma); in xrx200_change_mtu()
455 ltq_dma_enable_irq(&ch_rx->dma); in xrx200_change_mtu()
474 if (napi_schedule_prep(&ch->napi)) { in xrx200_dma_irq()
475 ltq_dma_disable_irq(&ch->dma); in xrx200_dma_irq()
476 __napi_schedule(&ch->napi); in xrx200_dma_irq()
479 ltq_dma_ack_irq(&ch->dma); in xrx200_dma_irq()
486 struct xrx200_chan *ch_rx = &priv->chan_rx; in xrx200_dma_init()
487 struct xrx200_chan *ch_tx = &priv->chan_tx; in xrx200_dma_init()
494 ch_rx->dma.nr = XRX200_DMA_RX; in xrx200_dma_init()
495 ch_rx->dma.dev = priv->dev; in xrx200_dma_init()
496 ch_rx->priv = priv; in xrx200_dma_init()
498 ltq_dma_alloc_rx(&ch_rx->dma); in xrx200_dma_init()
499 for (ch_rx->dma.desc = 0; ch_rx->dma.desc < LTQ_DESC_NUM; in xrx200_dma_init()
500 ch_rx->dma.desc++) { in xrx200_dma_init()
505 ch_rx->dma.desc = 0; in xrx200_dma_init()
506 ret = devm_request_irq(priv->dev, ch_rx->dma.irq, xrx200_dma_irq, 0, in xrx200_dma_init()
507 "xrx200_net_rx", &priv->chan_rx); in xrx200_dma_init()
509 dev_err(priv->dev, "failed to request RX irq %d\n", in xrx200_dma_init()
510 ch_rx->dma.irq); in xrx200_dma_init()
514 ch_tx->dma.nr = XRX200_DMA_TX; in xrx200_dma_init()
515 ch_tx->dma.dev = priv->dev; in xrx200_dma_init()
516 ch_tx->priv = priv; in xrx200_dma_init()
518 ltq_dma_alloc_tx(&ch_tx->dma); in xrx200_dma_init()
519 ret = devm_request_irq(priv->dev, ch_tx->dma.irq, xrx200_dma_irq, 0, in xrx200_dma_init()
520 "xrx200_net_tx", &priv->chan_tx); in xrx200_dma_init()
522 dev_err(priv->dev, "failed to request TX irq %d\n", in xrx200_dma_init()
523 ch_tx->dma.irq); in xrx200_dma_init()
530 ltq_dma_free(&ch_tx->dma); in xrx200_dma_init()
535 if (priv->chan_rx.skb[i]) in xrx200_dma_init()
536 skb_free_frag(priv->chan_rx.rx_buff[i]); in xrx200_dma_init()
540 ltq_dma_free(&ch_rx->dma); in xrx200_dma_init()
548 ltq_dma_free(&priv->chan_tx.dma); in xrx200_hw_cleanup()
549 ltq_dma_free(&priv->chan_rx.dma); in xrx200_hw_cleanup()
553 skb_free_frag(priv->chan_rx.rx_buff[i]); in xrx200_hw_cleanup()
558 struct device *dev = &pdev->dev; in xrx200_probe()
559 struct device_node *np = dev->of_node; in xrx200_probe()
567 return -ENOMEM; in xrx200_probe()
570 priv->net_dev = net_dev; in xrx200_probe()
571 priv->dev = dev; in xrx200_probe()
573 net_dev->netdev_ops = &xrx200_netdev_ops; in xrx200_probe()
575 net_dev->min_mtu = ETH_ZLEN; in xrx200_probe()
576 net_dev->max_mtu = XRX200_DMA_DATA_LEN - xrx200_max_frame_len(0); in xrx200_probe()
577 priv->rx_buf_size = xrx200_buffer_size(ETH_DATA_LEN); in xrx200_probe()
578 priv->rx_skb_size = xrx200_skb_size(priv->rx_buf_size); in xrx200_probe()
581 priv->pmac_reg = devm_platform_get_and_ioremap_resource(pdev, 0, NULL); in xrx200_probe()
582 if (IS_ERR(priv->pmac_reg)) in xrx200_probe()
583 return PTR_ERR(priv->pmac_reg); in xrx200_probe()
585 priv->chan_rx.dma.irq = platform_get_irq_byname(pdev, "rx"); in xrx200_probe()
586 if (priv->chan_rx.dma.irq < 0) in xrx200_probe()
587 return -ENOENT; in xrx200_probe()
588 priv->chan_tx.dma.irq = platform_get_irq_byname(pdev, "tx"); in xrx200_probe()
589 if (priv->chan_tx.dma.irq < 0) in xrx200_probe()
590 return -ENOENT; in xrx200_probe()
593 priv->clk = devm_clk_get(dev, NULL); in xrx200_probe()
594 if (IS_ERR(priv->clk)) { in xrx200_probe()
596 return PTR_ERR(priv->clk); in xrx200_probe()
609 err = clk_prepare_enable(priv->clk); in xrx200_probe()
623 netif_napi_add(net_dev, &priv->chan_rx.napi, xrx200_poll_rx); in xrx200_probe()
624 netif_napi_add_tx(net_dev, &priv->chan_tx.napi, in xrx200_probe()
636 clk_disable_unprepare(priv->clk); in xrx200_probe()
647 struct net_device *net_dev = priv->net_dev; in xrx200_remove()
651 netif_napi_del(&priv->chan_tx.napi); in xrx200_remove()
652 netif_napi_del(&priv->chan_rx.napi); in xrx200_remove()
658 clk_disable_unprepare(priv->clk); in xrx200_remove()
667 { .compatible = "lantiq,xrx200-net" },
676 .name = "lantiq,xrx200-net",
684 MODULE_DESCRIPTION("Lantiq SoC XRX200 ethernet");