Lines Matching +full:rx +full:- +full:pcs

1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Altera Triple-Speed Ethernet MAC driver
3 * Copyright (C) 2008-2014 Altera Corporation. All rights reserved
30 #include <linux/mdio/mdio-regmap.h>
36 #include <linux/pcs-lynx.h>
50 static int debug = -1;
52 MODULE_PARM_DESC(debug, "Message Level (-1: default, 0: no output, 16: all)");
61 MODULE_PARM_DESC(dma_rx_num, "Number of descriptors in the RX list");
69 #define POLL_PHY (-1)
81 #define TSE_TX_THRESH(x) (x->tx_ring_size / 4)
89 return priv->tx_cons + priv->tx_ring_size - priv->tx_prod - 1; in tse_tx_avail()
96 struct net_device *ndev = bus->priv; in altera_tse_mdio_read()
100 csrwr32((mii_id & 0x1f), priv->mac_dev, in altera_tse_mdio_read()
104 return csrrd32(priv->mac_dev, in altera_tse_mdio_read()
111 struct net_device *ndev = bus->priv; in altera_tse_mdio_write()
115 csrwr32((mii_id & 0x1f), priv->mac_dev, in altera_tse_mdio_write()
119 csrwr32(value, priv->mac_dev, tse_csroffs(mdio_phy1) + regnum * 4); in altera_tse_mdio_write()
131 for_each_child_of_node(priv->device->of_node, child_node) { in altera_tse_mdio_create()
132 if (of_device_is_compatible(child_node, "altr,tse-mdio")) { in altera_tse_mdio_create()
148 ret = -ENOMEM; in altera_tse_mdio_create()
152 mdio->name = ALTERA_TSE_RESOURCE_NAME; in altera_tse_mdio_create()
153 mdio->read = &altera_tse_mdio_read; in altera_tse_mdio_create()
154 mdio->write = &altera_tse_mdio_write; in altera_tse_mdio_create()
155 snprintf(mdio->id, MII_BUS_ID_SIZE, "%s-%u", mdio->name, id); in altera_tse_mdio_create()
157 mdio->priv = dev; in altera_tse_mdio_create()
158 mdio->parent = priv->device; in altera_tse_mdio_create()
163 mdio->id); in altera_tse_mdio_create()
169 netdev_info(dev, "MDIO bus %s: created\n", mdio->id); in altera_tse_mdio_create()
171 priv->mdio = mdio; in altera_tse_mdio_create()
185 if (priv->mdio == NULL) in altera_tse_mdio_destroy()
190 priv->mdio->id); in altera_tse_mdio_destroy()
192 mdiobus_unregister(priv->mdio); in altera_tse_mdio_destroy()
193 mdiobus_free(priv->mdio); in altera_tse_mdio_destroy()
194 priv->mdio = NULL; in altera_tse_mdio_destroy()
200 rxbuffer->skb = netdev_alloc_skb_ip_align(priv->dev, len); in tse_init_rx_buffer()
201 if (!rxbuffer->skb) in tse_init_rx_buffer()
202 return -ENOMEM; in tse_init_rx_buffer()
204 rxbuffer->dma_addr = dma_map_single(priv->device, rxbuffer->skb->data, in tse_init_rx_buffer()
208 if (dma_mapping_error(priv->device, rxbuffer->dma_addr)) { in tse_init_rx_buffer()
209 netdev_err(priv->dev, "%s: DMA mapping error\n", __func__); in tse_init_rx_buffer()
210 dev_kfree_skb_any(rxbuffer->skb); in tse_init_rx_buffer()
211 return -EINVAL; in tse_init_rx_buffer()
213 rxbuffer->dma_addr &= (dma_addr_t)~3; in tse_init_rx_buffer()
214 rxbuffer->len = len; in tse_init_rx_buffer()
221 dma_addr_t dma_addr = rxbuffer->dma_addr; in tse_free_rx_buffer()
222 struct sk_buff *skb = rxbuffer->skb; in tse_free_rx_buffer()
226 dma_unmap_single(priv->device, dma_addr, in tse_free_rx_buffer()
227 rxbuffer->len, in tse_free_rx_buffer()
230 rxbuffer->skb = NULL; in tse_free_rx_buffer()
231 rxbuffer->dma_addr = 0; in tse_free_rx_buffer()
240 if (buffer->dma_addr) { in tse_free_tx_buffer()
241 if (buffer->mapped_as_page) in tse_free_tx_buffer()
242 dma_unmap_page(priv->device, buffer->dma_addr, in tse_free_tx_buffer()
243 buffer->len, DMA_TO_DEVICE); in tse_free_tx_buffer()
245 dma_unmap_single(priv->device, buffer->dma_addr, in tse_free_tx_buffer()
246 buffer->len, DMA_TO_DEVICE); in tse_free_tx_buffer()
247 buffer->dma_addr = 0; in tse_free_tx_buffer()
249 if (buffer->skb) { in tse_free_tx_buffer()
250 dev_kfree_skb_any(buffer->skb); in tse_free_tx_buffer()
251 buffer->skb = NULL; in tse_free_tx_buffer()
257 unsigned int rx_descs = priv->rx_ring_size; in alloc_init_skbufs()
258 unsigned int tx_descs = priv->tx_ring_size; in alloc_init_skbufs()
259 int ret = -ENOMEM; in alloc_init_skbufs()
262 /* Create Rx ring buffer */ in alloc_init_skbufs()
263 priv->rx_ring = kcalloc(rx_descs, sizeof(struct tse_buffer), in alloc_init_skbufs()
265 if (!priv->rx_ring) in alloc_init_skbufs()
269 priv->tx_ring = kcalloc(tx_descs, sizeof(struct tse_buffer), in alloc_init_skbufs()
271 if (!priv->tx_ring) in alloc_init_skbufs()
274 priv->tx_cons = 0; in alloc_init_skbufs()
275 priv->tx_prod = 0; in alloc_init_skbufs()
277 /* Init Rx ring */ in alloc_init_skbufs()
279 ret = tse_init_rx_buffer(priv, &priv->rx_ring[i], in alloc_init_skbufs()
280 priv->rx_dma_buf_sz); in alloc_init_skbufs()
285 priv->rx_cons = 0; in alloc_init_skbufs()
286 priv->rx_prod = 0; in alloc_init_skbufs()
290 while (--i >= 0) in alloc_init_skbufs()
291 tse_free_rx_buffer(priv, &priv->rx_ring[i]); in alloc_init_skbufs()
292 kfree(priv->tx_ring); in alloc_init_skbufs()
294 kfree(priv->rx_ring); in alloc_init_skbufs()
302 unsigned int rx_descs = priv->rx_ring_size; in free_skbufs()
303 unsigned int tx_descs = priv->tx_ring_size; in free_skbufs()
306 /* Release the DMA TX/RX socket buffers */ in free_skbufs()
308 tse_free_rx_buffer(priv, &priv->rx_ring[i]); in free_skbufs()
310 tse_free_tx_buffer(priv, &priv->tx_ring[i]); in free_skbufs()
313 kfree(priv->tx_ring); in free_skbufs()
320 unsigned int rxsize = priv->rx_ring_size; in tse_rx_refill()
324 for (; priv->rx_cons - priv->rx_prod > 0; in tse_rx_refill()
325 priv->rx_prod++) { in tse_rx_refill()
326 entry = priv->rx_prod % rxsize; in tse_rx_refill()
327 if (likely(priv->rx_ring[entry].skb == NULL)) { in tse_rx_refill()
328 ret = tse_init_rx_buffer(priv, &priv->rx_ring[entry], in tse_rx_refill()
329 priv->rx_dma_buf_sz); in tse_rx_refill()
332 priv->dmaops->add_rx_desc(priv, &priv->rx_ring[entry]); in tse_rx_refill()
344 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) && in tse_rx_vlan()
346 eth_hdr = (struct ethhdr *)skb->data; in tse_rx_vlan()
347 memmove(skb->data + VLAN_HLEN, eth_hdr, ETH_ALEN * 2); in tse_rx_vlan()
357 unsigned int entry = priv->rx_cons % priv->rx_ring_size; in tse_rx()
366 * the response-fifo so we must process the next packet in tse_rx()
371 ((rxstatus = priv->dmaops->get_rx_status(priv)) != 0)) { in tse_rx()
376 netdev_err(priv->dev, in tse_rx()
384 pktlength -= 2; in tse_rx()
387 next_entry = (++priv->rx_cons) % priv->rx_ring_size; in tse_rx()
389 skb = priv->rx_ring[entry].skb; in tse_rx()
391 netdev_err(priv->dev, in tse_rx()
392 "%s: Inconsistent Rx descriptor chain\n", in tse_rx()
394 priv->dev->stats.rx_dropped++; in tse_rx()
397 priv->rx_ring[entry].skb = NULL; in tse_rx()
401 dma_unmap_single(priv->device, priv->rx_ring[entry].dma_addr, in tse_rx()
402 priv->rx_ring[entry].len, DMA_FROM_DEVICE); in tse_rx()
405 netdev_info(priv->dev, "frame received %d bytes\n", in tse_rx()
408 16, 1, skb->data, pktlength, true); in tse_rx()
411 tse_rx_vlan(priv->dev, skb); in tse_rx()
413 skb->protocol = eth_type_trans(skb, priv->dev); in tse_rx()
416 napi_gro_receive(&priv->napi, skb); in tse_rx()
418 priv->dev->stats.rx_packets++; in tse_rx()
419 priv->dev->stats.rx_bytes += pktlength; in tse_rx()
433 unsigned int txsize = priv->tx_ring_size; in tse_tx_complete()
439 spin_lock(&priv->tx_lock); in tse_tx_complete()
441 ready = priv->dmaops->tx_completions(priv); in tse_tx_complete()
444 while (ready && (priv->tx_cons != priv->tx_prod)) { in tse_tx_complete()
445 entry = priv->tx_cons % txsize; in tse_tx_complete()
446 tx_buff = &priv->tx_ring[entry]; in tse_tx_complete()
449 netdev_dbg(priv->dev, "%s: curr %d, dirty %d\n", in tse_tx_complete()
450 __func__, priv->tx_prod, priv->tx_cons); in tse_tx_complete()
452 if (likely(tx_buff->skb)) in tse_tx_complete()
453 priv->dev->stats.tx_packets++; in tse_tx_complete()
456 priv->tx_cons++; in tse_tx_complete()
459 ready--; in tse_tx_complete()
462 if (unlikely(netif_queue_stopped(priv->dev) && in tse_tx_complete()
464 if (netif_queue_stopped(priv->dev) && in tse_tx_complete()
467 netdev_dbg(priv->dev, "%s: restart transmit\n", in tse_tx_complete()
469 netif_wake_queue(priv->dev); in tse_tx_complete()
473 spin_unlock(&priv->tx_lock); in tse_tx_complete()
494 netdev_dbg(priv->dev, in tse_poll()
498 spin_lock_irqsave(&priv->rxdma_irq_lock, flags); in tse_poll()
499 priv->dmaops->enable_rxirq(priv); in tse_poll()
500 priv->dmaops->enable_txirq(priv); in tse_poll()
501 spin_unlock_irqrestore(&priv->rxdma_irq_lock, flags); in tse_poll()
506 /* DMA TX & RX FIFO interrupt routing
519 spin_lock(&priv->rxdma_irq_lock); in altera_isr()
521 priv->dmaops->clear_rxirq(priv); in altera_isr()
522 priv->dmaops->clear_txirq(priv); in altera_isr()
523 spin_unlock(&priv->rxdma_irq_lock); in altera_isr()
525 if (likely(napi_schedule_prep(&priv->napi))) { in altera_isr()
526 spin_lock(&priv->rxdma_irq_lock); in altera_isr()
527 priv->dmaops->disable_rxirq(priv); in altera_isr()
528 priv->dmaops->disable_txirq(priv); in altera_isr()
529 spin_unlock(&priv->rxdma_irq_lock); in altera_isr()
530 __napi_schedule(&priv->napi); in altera_isr()
542 * skb->data, for length of skb_headlen(skb).
548 unsigned int txsize = priv->tx_ring_size; in tse_start_xmit()
549 int nfrags = skb_shinfo(skb)->nr_frags; in tse_start_xmit()
555 spin_lock_bh(&priv->tx_lock); in tse_start_xmit()
561 netdev_err(priv->dev, in tse_start_xmit()
570 entry = priv->tx_prod % txsize; in tse_start_xmit()
571 buffer = &priv->tx_ring[entry]; in tse_start_xmit()
573 dma_addr = dma_map_single(priv->device, skb->data, nopaged_len, in tse_start_xmit()
575 if (dma_mapping_error(priv->device, dma_addr)) { in tse_start_xmit()
576 netdev_err(priv->dev, "%s: DMA mapping error\n", __func__); in tse_start_xmit()
581 buffer->skb = skb; in tse_start_xmit()
582 buffer->dma_addr = dma_addr; in tse_start_xmit()
583 buffer->len = nopaged_len; in tse_start_xmit()
585 priv->dmaops->tx_buffer(priv, buffer); in tse_start_xmit()
589 priv->tx_prod++; in tse_start_xmit()
590 dev->stats.tx_bytes += skb->len; in tse_start_xmit()
594 netdev_dbg(priv->dev, "%s: stop transmitted packets\n", in tse_start_xmit()
600 spin_unlock_bh(&priv->tx_lock); in tse_start_xmit()
608 struct device_node *np = priv->device->of_node; in altera_tse_phy_get_addr_mdio_create()
611 ret = of_get_phy_mode(np, &priv->phy_iface); in altera_tse_phy_get_addr_mdio_create()
621 if (of_property_read_u32(priv->device->of_node, "phy-addr", in altera_tse_phy_get_addr_mdio_create()
622 &priv->phy_addr)) { in altera_tse_phy_get_addr_mdio_create()
623 priv->phy_addr = POLL_PHY; in altera_tse_phy_get_addr_mdio_create()
626 if (!((priv->phy_addr == POLL_PHY) || in altera_tse_phy_get_addr_mdio_create()
627 ((priv->phy_addr >= 0) && (priv->phy_addr < PHY_MAX_ADDR)))) { in altera_tse_phy_get_addr_mdio_create()
628 netdev_err(dev, "invalid phy-addr specified %d\n", in altera_tse_phy_get_addr_mdio_create()
629 priv->phy_addr); in altera_tse_phy_get_addr_mdio_create()
630 return -ENODEV; in altera_tse_phy_get_addr_mdio_create()
638 return -ENODEV; in altera_tse_phy_get_addr_mdio_create()
652 csrwr32(msb, priv->mac_dev, tse_csroffs(mac_addr_0)); in tse_update_mac_addr()
653 csrwr32(lsb, priv->mac_dev, tse_csroffs(mac_addr_1)); in tse_update_mac_addr()
667 dat = csrrd32(priv->mac_dev, tse_csroffs(command_config)); in reset_mac()
670 csrwr32(dat, priv->mac_dev, tse_csroffs(command_config)); in reset_mac()
674 if (tse_bit_is_clear(priv->mac_dev, tse_csroffs(command_config), in reset_mac()
681 dat = csrrd32(priv->mac_dev, tse_csroffs(command_config)); in reset_mac()
683 csrwr32(dat, priv->mac_dev, tse_csroffs(command_config)); in reset_mac()
684 return -1; in reset_mac()
696 /* Setup Rx FIFO */ in init_mac()
697 csrwr32(priv->rx_fifo_depth - ALTERA_TSE_RX_SECTION_EMPTY, in init_mac()
698 priv->mac_dev, tse_csroffs(rx_section_empty)); in init_mac()
700 csrwr32(ALTERA_TSE_RX_SECTION_FULL, priv->mac_dev, in init_mac()
703 csrwr32(ALTERA_TSE_RX_ALMOST_EMPTY, priv->mac_dev, in init_mac()
706 csrwr32(ALTERA_TSE_RX_ALMOST_FULL, priv->mac_dev, in init_mac()
710 csrwr32(priv->tx_fifo_depth - ALTERA_TSE_TX_SECTION_EMPTY, in init_mac()
711 priv->mac_dev, tse_csroffs(tx_section_empty)); in init_mac()
713 csrwr32(ALTERA_TSE_TX_SECTION_FULL, priv->mac_dev, in init_mac()
716 csrwr32(ALTERA_TSE_TX_ALMOST_EMPTY, priv->mac_dev, in init_mac()
719 csrwr32(ALTERA_TSE_TX_ALMOST_FULL, priv->mac_dev, in init_mac()
723 tse_update_mac_addr(priv, priv->dev->dev_addr); in init_mac()
726 frm_length = ETH_HLEN + priv->dev->mtu + ETH_FCS_LEN; in init_mac()
727 csrwr32(frm_length, priv->mac_dev, tse_csroffs(frm_length)); in init_mac()
729 csrwr32(ALTERA_TSE_TX_IPG_LENGTH, priv->mac_dev, in init_mac()
732 /* Disable RX/TX shift 16 for alignment of all received frames on 16-bit in init_mac()
735 tse_set_bit(priv->mac_dev, tse_csroffs(rx_cmd_stat), in init_mac()
738 tse_clear_bit(priv->mac_dev, tse_csroffs(tx_cmd_stat), in init_mac()
743 cmd = csrrd32(priv->mac_dev, tse_csroffs(command_config)); in init_mac()
758 csrwr32(cmd, priv->mac_dev, tse_csroffs(command_config)); in init_mac()
760 csrwr32(ALTERA_TSE_PAUSE_QUANTA, priv->mac_dev, in init_mac()
764 dev_dbg(priv->device, in init_mac()
765 "MAC post-initialization: CMD_CONFIG = 0x%08x\n", cmd); in init_mac()
774 u32 value = csrrd32(priv->mac_dev, tse_csroffs(command_config)); in tse_set_mac()
781 csrwr32(value, priv->mac_dev, tse_csroffs(command_config)); in tse_set_mac()
790 return -EBUSY; in tse_change_mtu()
793 dev->mtu = new_mtu; in tse_change_mtu()
807 csrwr32(0, priv->mac_dev, tse_csroffs(hash_table) + i * 4); in altera_tse_set_mcfilter()
813 for (mac_octet = 5; mac_octet >= 0; mac_octet--) { in altera_tse_set_mcfilter()
815 unsigned char octet = ha->addr[mac_octet]; in altera_tse_set_mcfilter()
823 csrwr32(1, priv->mac_dev, tse_csroffs(hash_table) + hash * 4); in altera_tse_set_mcfilter()
835 csrwr32(1, priv->mac_dev, tse_csroffs(hash_table) + i * 4); in altera_tse_set_mcfilterall()
844 spin_lock(&priv->mac_cfg_lock); in tse_set_rx_mode_hashfilter()
846 if (dev->flags & IFF_PROMISC) in tse_set_rx_mode_hashfilter()
847 tse_set_bit(priv->mac_dev, tse_csroffs(command_config), in tse_set_rx_mode_hashfilter()
850 if (dev->flags & IFF_ALLMULTI) in tse_set_rx_mode_hashfilter()
855 spin_unlock(&priv->mac_cfg_lock); in tse_set_rx_mode_hashfilter()
864 spin_lock(&priv->mac_cfg_lock); in tse_set_rx_mode()
866 if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) || in tse_set_rx_mode()
868 tse_set_bit(priv->mac_dev, tse_csroffs(command_config), in tse_set_rx_mode()
871 tse_clear_bit(priv->mac_dev, tse_csroffs(command_config), in tse_set_rx_mode()
874 spin_unlock(&priv->mac_cfg_lock); in tse_set_rx_mode()
887 ret = priv->dmaops->init_dma(priv); in tse_open()
895 dev->dev_addr); in tse_open()
897 if ((priv->revision < 0xd00) || (priv->revision > 0xe00)) in tse_open()
898 netdev_warn(dev, "TSE revision %x\n", priv->revision); in tse_open()
900 spin_lock(&priv->mac_cfg_lock); in tse_open()
911 spin_unlock(&priv->mac_cfg_lock); in tse_open()
917 priv->dmaops->reset_dma(priv); in tse_open()
919 /* Create and initialize the TX/RX descriptors chains. */ in tse_open()
920 priv->rx_ring_size = dma_rx_num; in tse_open()
921 priv->tx_ring_size = dma_tx_num; in tse_open()
929 /* Register RX interrupt */ in tse_open()
930 ret = request_irq(priv->rx_irq, altera_isr, IRQF_SHARED, in tse_open()
931 dev->name, dev); in tse_open()
933 netdev_err(dev, "Unable to register RX interrupt %d\n", in tse_open()
934 priv->rx_irq); in tse_open()
939 ret = request_irq(priv->tx_irq, altera_isr, IRQF_SHARED, in tse_open()
940 dev->name, dev); in tse_open()
943 priv->tx_irq); in tse_open()
948 spin_lock_irqsave(&priv->rxdma_irq_lock, flags); in tse_open()
949 priv->dmaops->enable_rxirq(priv); in tse_open()
950 priv->dmaops->enable_txirq(priv); in tse_open()
952 /* Setup RX descriptor chain */ in tse_open()
953 for (i = 0; i < priv->rx_ring_size; i++) in tse_open()
954 priv->dmaops->add_rx_desc(priv, &priv->rx_ring[i]); in tse_open()
956 spin_unlock_irqrestore(&priv->rxdma_irq_lock, flags); in tse_open()
958 ret = phylink_of_phy_connect(priv->phylink, priv->device->of_node, 0); in tse_open()
963 phylink_start(priv->phylink); in tse_open()
965 napi_enable(&priv->napi); in tse_open()
968 priv->dmaops->start_rxdma(priv); in tse_open()
970 /* Start MAC Rx/Tx */ in tse_open()
971 spin_lock(&priv->mac_cfg_lock); in tse_open()
973 spin_unlock(&priv->mac_cfg_lock); in tse_open()
978 free_irq(priv->rx_irq, dev); in tse_open()
994 phylink_stop(priv->phylink); in tse_shutdown()
995 phylink_disconnect_phy(priv->phylink); in tse_shutdown()
997 napi_disable(&priv->napi); in tse_shutdown()
1000 spin_lock_irqsave(&priv->rxdma_irq_lock, flags); in tse_shutdown()
1001 priv->dmaops->disable_rxirq(priv); in tse_shutdown()
1002 priv->dmaops->disable_txirq(priv); in tse_shutdown()
1003 spin_unlock_irqrestore(&priv->rxdma_irq_lock, flags); in tse_shutdown()
1006 free_irq(priv->rx_irq, dev); in tse_shutdown()
1007 free_irq(priv->tx_irq, dev); in tse_shutdown()
1010 spin_lock(&priv->mac_cfg_lock); in tse_shutdown()
1011 spin_lock(&priv->tx_lock); in tse_shutdown()
1020 priv->dmaops->reset_dma(priv); in tse_shutdown()
1023 spin_unlock(&priv->tx_lock); in tse_shutdown()
1024 spin_unlock(&priv->mac_cfg_lock); in tse_shutdown()
1026 priv->dmaops->uninit_dma(priv); in tse_shutdown()
1044 struct net_device *ndev = to_net_dev(config->dev); in alt_tse_mac_config()
1047 spin_lock(&priv->mac_cfg_lock); in alt_tse_mac_config()
1050 spin_unlock(&priv->mac_cfg_lock); in alt_tse_mac_config()
1063 struct net_device *ndev = to_net_dev(config->dev); in alt_tse_mac_link_up()
1067 ctrl = csrrd32(priv->mac_dev, tse_csroffs(command_config)); in alt_tse_mac_link_up()
1078 spin_lock(&priv->mac_cfg_lock); in alt_tse_mac_link_up()
1079 csrwr32(ctrl, priv->mac_dev, tse_csroffs(command_config)); in alt_tse_mac_link_up()
1080 spin_unlock(&priv->mac_cfg_lock); in alt_tse_mac_link_up()
1086 struct net_device *ndev = to_net_dev(config->dev); in alt_tse_select_pcs()
1091 return priv->pcs; in alt_tse_select_pcs()
1106 struct device *device = &pdev->dev; in request_and_map()
1112 return -ENODEV; in request_and_map()
1115 region = devm_request_mem_region(device, (*res)->start, in request_and_map()
1119 return -EBUSY; in request_and_map()
1122 *ptr = devm_ioremap(device, region->start, in request_and_map()
1126 return -ENOMEM; in request_and_map()
1147 int ret = -ENODEV; in altera_tse_probe()
1151 dev_err(&pdev->dev, "Could not allocate network device\n"); in altera_tse_probe()
1152 return -ENODEV; in altera_tse_probe()
1155 SET_NETDEV_DEV(ndev, &pdev->dev); in altera_tse_probe()
1158 priv->device = &pdev->dev; in altera_tse_probe()
1159 priv->dev = ndev; in altera_tse_probe()
1160 priv->msg_enable = netif_msg_init(debug, default_msg_level); in altera_tse_probe()
1162 of_id = of_match_device(altera_tse_ids, &pdev->dev); in altera_tse_probe()
1165 priv->dmaops = (struct altera_dmaops *)of_id->data; in altera_tse_probe()
1168 if (priv->dmaops && in altera_tse_probe()
1169 priv->dmaops->altera_dtype == ALTERA_DTYPE_SGDMA) { in altera_tse_probe()
1176 priv->tx_dma_desc = descmap; in altera_tse_probe()
1179 priv->txdescmem = resource_size(dma_res)/2; in altera_tse_probe()
1181 priv->txdescmem_busaddr = (dma_addr_t)dma_res->start; in altera_tse_probe()
1183 priv->rx_dma_desc = (void __iomem *)((uintptr_t)(descmap + in altera_tse_probe()
1184 priv->txdescmem)); in altera_tse_probe()
1185 priv->rxdescmem = resource_size(dma_res)/2; in altera_tse_probe()
1186 priv->rxdescmem_busaddr = dma_res->start; in altera_tse_probe()
1187 priv->rxdescmem_busaddr += priv->txdescmem; in altera_tse_probe()
1189 if (upper_32_bits(priv->rxdescmem_busaddr)) { in altera_tse_probe()
1190 dev_dbg(priv->device, in altera_tse_probe()
1191 "SGDMA bus addresses greater than 32-bits\n"); in altera_tse_probe()
1192 ret = -EINVAL; in altera_tse_probe()
1195 if (upper_32_bits(priv->txdescmem_busaddr)) { in altera_tse_probe()
1196 dev_dbg(priv->device, in altera_tse_probe()
1197 "SGDMA bus addresses greater than 32-bits\n"); in altera_tse_probe()
1198 ret = -EINVAL; in altera_tse_probe()
1201 } else if (priv->dmaops && in altera_tse_probe()
1202 priv->dmaops->altera_dtype == ALTERA_DTYPE_MSGDMA) { in altera_tse_probe()
1204 &priv->rx_dma_resp); in altera_tse_probe()
1209 &priv->tx_dma_desc); in altera_tse_probe()
1213 priv->txdescmem = resource_size(dma_res); in altera_tse_probe()
1214 priv->txdescmem_busaddr = dma_res->start; in altera_tse_probe()
1217 &priv->rx_dma_desc); in altera_tse_probe()
1221 priv->rxdescmem = resource_size(dma_res); in altera_tse_probe()
1222 priv->rxdescmem_busaddr = dma_res->start; in altera_tse_probe()
1225 ret = -ENODEV; in altera_tse_probe()
1229 if (!dma_set_mask(priv->device, DMA_BIT_MASK(priv->dmaops->dmamask))) { in altera_tse_probe()
1230 dma_set_coherent_mask(priv->device, in altera_tse_probe()
1231 DMA_BIT_MASK(priv->dmaops->dmamask)); in altera_tse_probe()
1232 } else if (!dma_set_mask(priv->device, DMA_BIT_MASK(32))) { in altera_tse_probe()
1233 dma_set_coherent_mask(priv->device, DMA_BIT_MASK(32)); in altera_tse_probe()
1235 ret = -EIO; in altera_tse_probe()
1241 (void __iomem **)&priv->mac_dev); in altera_tse_probe()
1245 /* xSGDMA Rx Dispatcher address space */ in altera_tse_probe()
1247 &priv->rx_dma_csr); in altera_tse_probe()
1254 &priv->tx_dma_csr); in altera_tse_probe()
1260 /* SGMII PCS address space. The location can vary depending on how the in altera_tse_probe()
1265 ret = request_and_map(pdev, "pcs", &pcs_res, &priv->pcs_base); in altera_tse_probe()
1267 /* If we can't find a dedicated resource for the PCS, fallback in altera_tse_probe()
1268 * to the internal PCS, that has a different address stride in altera_tse_probe()
1270 priv->pcs_base = priv->mac_dev + tse_csroffs(mdio_phy0); in altera_tse_probe()
1272 /* Values are MDIO-like values, on 16 bits */ in altera_tse_probe()
1281 /* Create a regmap for the PCS so that it can be used by the PCS driver */ in altera_tse_probe()
1282 pcs_regmap = devm_regmap_init_mmio(&pdev->dev, priv->pcs_base, in altera_tse_probe()
1289 mrc.parent = &pdev->dev; in altera_tse_probe()
1293 /* Rx IRQ */ in altera_tse_probe()
1294 priv->rx_irq = platform_get_irq_byname(pdev, "rx_irq"); in altera_tse_probe()
1295 if (priv->rx_irq == -ENXIO) { in altera_tse_probe()
1296 dev_err(&pdev->dev, "cannot obtain Rx IRQ\n"); in altera_tse_probe()
1297 ret = -ENXIO; in altera_tse_probe()
1302 priv->tx_irq = platform_get_irq_byname(pdev, "tx_irq"); in altera_tse_probe()
1303 if (priv->tx_irq == -ENXIO) { in altera_tse_probe()
1304 dev_err(&pdev->dev, "cannot obtain Tx IRQ\n"); in altera_tse_probe()
1305 ret = -ENXIO; in altera_tse_probe()
1310 if (of_property_read_u32(pdev->dev.of_node, "rx-fifo-depth", in altera_tse_probe()
1311 &priv->rx_fifo_depth)) { in altera_tse_probe()
1312 dev_err(&pdev->dev, "cannot obtain rx-fifo-depth\n"); in altera_tse_probe()
1313 ret = -ENXIO; in altera_tse_probe()
1317 if (of_property_read_u32(pdev->dev.of_node, "tx-fifo-depth", in altera_tse_probe()
1318 &priv->tx_fifo_depth)) { in altera_tse_probe()
1319 dev_err(&pdev->dev, "cannot obtain tx-fifo-depth\n"); in altera_tse_probe()
1320 ret = -ENXIO; in altera_tse_probe()
1325 priv->hash_filter = in altera_tse_probe()
1326 of_property_read_bool(pdev->dev.of_node, in altera_tse_probe()
1327 "altr,has-hash-multicast-filter"); in altera_tse_probe()
1332 priv->hash_filter = 0; in altera_tse_probe()
1335 priv->added_unicast = in altera_tse_probe()
1336 of_property_read_bool(pdev->dev.of_node, in altera_tse_probe()
1337 "altr,has-supplementary-unicast"); in altera_tse_probe()
1339 priv->dev->min_mtu = ETH_ZLEN + ETH_FCS_LEN; in altera_tse_probe()
1341 priv->dev->max_mtu = ETH_DATA_LEN; in altera_tse_probe()
1344 * "max-frame-size" parameter is actually max mtu. Definition in altera_tse_probe()
1347 of_property_read_u32(pdev->dev.of_node, "max-frame-size", in altera_tse_probe()
1348 &priv->dev->max_mtu); in altera_tse_probe()
1353 priv->rx_dma_buf_sz = ALTERA_RXDMABUFFER_SIZE; in altera_tse_probe()
1356 ret = of_get_ethdev_address(pdev->dev.of_node, ndev); in altera_tse_probe()
1367 ndev->mem_start = control_port->start; in altera_tse_probe()
1368 ndev->mem_end = control_port->end; in altera_tse_probe()
1369 ndev->netdev_ops = &altera_tse_netdev_ops; in altera_tse_probe()
1374 if (priv->hash_filter) in altera_tse_probe()
1381 ndev->hw_features &= ~NETIF_F_SG; in altera_tse_probe()
1382 ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA; in altera_tse_probe()
1386 * extra 4-byte VLAN tag for processing by upper layers in altera_tse_probe()
1388 ndev->features |= NETIF_F_HW_VLAN_CTAG_RX; in altera_tse_probe()
1391 netif_napi_add(ndev, &priv->napi, tse_poll); in altera_tse_probe()
1393 spin_lock_init(&priv->mac_cfg_lock); in altera_tse_probe()
1394 spin_lock_init(&priv->tx_lock); in altera_tse_probe()
1395 spin_lock_init(&priv->rxdma_irq_lock); in altera_tse_probe()
1400 dev_err(&pdev->dev, "failed to register TSE net device\n"); in altera_tse_probe()
1406 priv->revision = ioread32(&priv->mac_dev->megacore_revision); in altera_tse_probe()
1409 dev_info(&pdev->dev, "Altera TSE MAC version %d.%d at 0x%08lx irq %d/%d\n", in altera_tse_probe()
1410 (priv->revision >> 8) & 0xff, in altera_tse_probe()
1411 priv->revision & 0xff, in altera_tse_probe()
1412 (unsigned long) control_port->start, priv->rx_irq, in altera_tse_probe()
1413 priv->tx_irq); in altera_tse_probe()
1415 snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-pcs-mii", ndev->name); in altera_tse_probe()
1416 pcs_bus = devm_mdio_regmap_register(&pdev->dev, &mrc); in altera_tse_probe()
1422 priv->pcs = lynx_pcs_create_mdiodev(pcs_bus, 0); in altera_tse_probe()
1423 if (IS_ERR(priv->pcs)) { in altera_tse_probe()
1424 ret = PTR_ERR(priv->pcs); in altera_tse_probe()
1428 priv->phylink_config.dev = &ndev->dev; in altera_tse_probe()
1429 priv->phylink_config.type = PHYLINK_NETDEV; in altera_tse_probe()
1430 priv->phylink_config.mac_capabilities = MAC_SYM_PAUSE | MAC_10 | in altera_tse_probe()
1433 phy_interface_set_rgmii(priv->phylink_config.supported_interfaces); in altera_tse_probe()
1435 priv->phylink_config.supported_interfaces); in altera_tse_probe()
1437 priv->phylink_config.supported_interfaces); in altera_tse_probe()
1439 priv->phylink_config.supported_interfaces); in altera_tse_probe()
1441 priv->phylink_config.supported_interfaces); in altera_tse_probe()
1443 priv->phylink = phylink_create(&priv->phylink_config, in altera_tse_probe()
1444 of_fwnode_handle(priv->device->of_node), in altera_tse_probe()
1445 priv->phy_iface, &alt_tse_phylink_ops); in altera_tse_probe()
1446 if (IS_ERR(priv->phylink)) { in altera_tse_probe()
1447 dev_err(&pdev->dev, "failed to create phylink\n"); in altera_tse_probe()
1448 ret = PTR_ERR(priv->phylink); in altera_tse_probe()
1454 lynx_pcs_destroy(priv->pcs); in altera_tse_probe()
1458 netif_napi_del(&priv->napi); in altera_tse_probe()
1475 phylink_destroy(priv->phylink); in altera_tse_remove()
1476 lynx_pcs_destroy(priv->pcs); in altera_tse_remove()
1522 { .compatible = "altr,tse-msgdma-1.0", .data = &altera_dtype_msgdma, },
1523 { .compatible = "altr,tse-1.0", .data = &altera_dtype_sgdma, },
1524 { .compatible = "ALTR,tse-1.0", .data = &altera_dtype_sgdma, },