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>
35 #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)
87 return priv->tx_cons + priv->tx_ring_size - priv->tx_prod - 1; in tse_tx_avail()
94 struct net_device *ndev = bus->priv; in altera_tse_mdio_read()
98 csrwr32((mii_id & 0x1f), priv->mac_dev, in altera_tse_mdio_read()
102 return csrrd32(priv->mac_dev, in altera_tse_mdio_read()
109 struct net_device *ndev = bus->priv; in altera_tse_mdio_write()
113 csrwr32((mii_id & 0x1f), priv->mac_dev, in altera_tse_mdio_write()
117 csrwr32(value, priv->mac_dev, tse_csroffs(mdio_phy1) + regnum * 4); in altera_tse_mdio_write()
129 for_each_child_of_node(priv->device->of_node, child_node) { in altera_tse_mdio_create()
130 if (of_device_is_compatible(child_node, "altr,tse-mdio")) { in altera_tse_mdio_create()
146 ret = -ENOMEM; in altera_tse_mdio_create()
150 mdio->name = ALTERA_TSE_RESOURCE_NAME; in altera_tse_mdio_create()
151 mdio->read = &altera_tse_mdio_read; in altera_tse_mdio_create()
152 mdio->write = &altera_tse_mdio_write; in altera_tse_mdio_create()
153 snprintf(mdio->id, MII_BUS_ID_SIZE, "%s-%u", mdio->name, id); in altera_tse_mdio_create()
155 mdio->priv = dev; in altera_tse_mdio_create()
156 mdio->parent = priv->device; in altera_tse_mdio_create()
161 mdio->id); in altera_tse_mdio_create()
167 netdev_info(dev, "MDIO bus %s: created\n", mdio->id); in altera_tse_mdio_create()
169 priv->mdio = mdio; in altera_tse_mdio_create()
183 if (priv->mdio == NULL) in altera_tse_mdio_destroy()
188 priv->mdio->id); in altera_tse_mdio_destroy()
190 mdiobus_unregister(priv->mdio); in altera_tse_mdio_destroy()
191 mdiobus_free(priv->mdio); in altera_tse_mdio_destroy()
192 priv->mdio = NULL; in altera_tse_mdio_destroy()
198 rxbuffer->skb = netdev_alloc_skb_ip_align(priv->dev, len); in tse_init_rx_buffer()
199 if (!rxbuffer->skb) in tse_init_rx_buffer()
200 return -ENOMEM; in tse_init_rx_buffer()
202 rxbuffer->dma_addr = dma_map_single(priv->device, rxbuffer->skb->data, in tse_init_rx_buffer()
206 if (dma_mapping_error(priv->device, rxbuffer->dma_addr)) { in tse_init_rx_buffer()
207 netdev_err(priv->dev, "%s: DMA mapping error\n", __func__); in tse_init_rx_buffer()
208 dev_kfree_skb_any(rxbuffer->skb); in tse_init_rx_buffer()
209 return -EINVAL; in tse_init_rx_buffer()
211 rxbuffer->dma_addr &= (dma_addr_t)~3; in tse_init_rx_buffer()
212 rxbuffer->len = len; in tse_init_rx_buffer()
219 dma_addr_t dma_addr = rxbuffer->dma_addr; in tse_free_rx_buffer()
220 struct sk_buff *skb = rxbuffer->skb; in tse_free_rx_buffer()
224 dma_unmap_single(priv->device, dma_addr, in tse_free_rx_buffer()
225 rxbuffer->len, in tse_free_rx_buffer()
228 rxbuffer->skb = NULL; in tse_free_rx_buffer()
229 rxbuffer->dma_addr = 0; in tse_free_rx_buffer()
238 if (buffer->dma_addr) { in tse_free_tx_buffer()
239 if (buffer->mapped_as_page) in tse_free_tx_buffer()
240 dma_unmap_page(priv->device, buffer->dma_addr, in tse_free_tx_buffer()
241 buffer->len, DMA_TO_DEVICE); in tse_free_tx_buffer()
243 dma_unmap_single(priv->device, buffer->dma_addr, in tse_free_tx_buffer()
244 buffer->len, DMA_TO_DEVICE); in tse_free_tx_buffer()
245 buffer->dma_addr = 0; in tse_free_tx_buffer()
247 if (buffer->skb) { in tse_free_tx_buffer()
248 dev_kfree_skb_any(buffer->skb); in tse_free_tx_buffer()
249 buffer->skb = NULL; in tse_free_tx_buffer()
255 unsigned int rx_descs = priv->rx_ring_size; in alloc_init_skbufs()
256 unsigned int tx_descs = priv->tx_ring_size; in alloc_init_skbufs()
257 int ret = -ENOMEM; in alloc_init_skbufs()
260 /* Create Rx ring buffer */ in alloc_init_skbufs()
261 priv->rx_ring = kcalloc(rx_descs, sizeof(struct tse_buffer), in alloc_init_skbufs()
263 if (!priv->rx_ring) in alloc_init_skbufs()
267 priv->tx_ring = kcalloc(tx_descs, sizeof(struct tse_buffer), in alloc_init_skbufs()
269 if (!priv->tx_ring) in alloc_init_skbufs()
272 priv->tx_cons = 0; in alloc_init_skbufs()
273 priv->tx_prod = 0; in alloc_init_skbufs()
275 /* Init Rx ring */ in alloc_init_skbufs()
277 ret = tse_init_rx_buffer(priv, &priv->rx_ring[i], in alloc_init_skbufs()
278 priv->rx_dma_buf_sz); in alloc_init_skbufs()
283 priv->rx_cons = 0; in alloc_init_skbufs()
284 priv->rx_prod = 0; in alloc_init_skbufs()
288 while (--i >= 0) in alloc_init_skbufs()
289 tse_free_rx_buffer(priv, &priv->rx_ring[i]); in alloc_init_skbufs()
290 kfree(priv->tx_ring); in alloc_init_skbufs()
292 kfree(priv->rx_ring); in alloc_init_skbufs()
300 unsigned int rx_descs = priv->rx_ring_size; in free_skbufs()
301 unsigned int tx_descs = priv->tx_ring_size; in free_skbufs()
304 /* Release the DMA TX/RX socket buffers */ in free_skbufs()
306 tse_free_rx_buffer(priv, &priv->rx_ring[i]); in free_skbufs()
308 tse_free_tx_buffer(priv, &priv->tx_ring[i]); in free_skbufs()
311 kfree(priv->tx_ring); in free_skbufs()
318 unsigned int rxsize = priv->rx_ring_size; in tse_rx_refill()
322 for (; priv->rx_cons - priv->rx_prod > 0; in tse_rx_refill()
323 priv->rx_prod++) { in tse_rx_refill()
324 entry = priv->rx_prod % rxsize; in tse_rx_refill()
325 if (likely(priv->rx_ring[entry].skb == NULL)) { in tse_rx_refill()
326 ret = tse_init_rx_buffer(priv, &priv->rx_ring[entry], in tse_rx_refill()
327 priv->rx_dma_buf_sz); in tse_rx_refill()
330 priv->dmaops->add_rx_desc(priv, &priv->rx_ring[entry]); in tse_rx_refill()
342 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) && in tse_rx_vlan()
344 eth_hdr = (struct ethhdr *)skb->data; in tse_rx_vlan()
345 memmove(skb->data + VLAN_HLEN, eth_hdr, ETH_ALEN * 2); in tse_rx_vlan()
355 unsigned int entry = priv->rx_cons % priv->rx_ring_size; in tse_rx()
364 * the response-fifo so we must process the next packet in tse_rx()
369 ((rxstatus = priv->dmaops->get_rx_status(priv)) != 0)) { in tse_rx()
374 netdev_err(priv->dev, in tse_rx()
382 pktlength -= 2; in tse_rx()
385 next_entry = (++priv->rx_cons) % priv->rx_ring_size; in tse_rx()
387 skb = priv->rx_ring[entry].skb; in tse_rx()
389 netdev_err(priv->dev, in tse_rx()
390 "%s: Inconsistent Rx descriptor chain\n", in tse_rx()
392 priv->dev->stats.rx_dropped++; in tse_rx()
395 priv->rx_ring[entry].skb = NULL; in tse_rx()
399 dma_unmap_single(priv->device, priv->rx_ring[entry].dma_addr, in tse_rx()
400 priv->rx_ring[entry].len, DMA_FROM_DEVICE); in tse_rx()
403 netdev_info(priv->dev, "frame received %d bytes\n", in tse_rx()
406 16, 1, skb->data, pktlength, true); in tse_rx()
409 tse_rx_vlan(priv->dev, skb); in tse_rx()
411 skb->protocol = eth_type_trans(skb, priv->dev); in tse_rx()
414 napi_gro_receive(&priv->napi, skb); in tse_rx()
416 priv->dev->stats.rx_packets++; in tse_rx()
417 priv->dev->stats.rx_bytes += pktlength; in tse_rx()
431 unsigned int txsize = priv->tx_ring_size; in tse_tx_complete()
437 spin_lock(&priv->tx_lock); in tse_tx_complete()
439 ready = priv->dmaops->tx_completions(priv); in tse_tx_complete()
442 while (ready && (priv->tx_cons != priv->tx_prod)) { in tse_tx_complete()
443 entry = priv->tx_cons % txsize; in tse_tx_complete()
444 tx_buff = &priv->tx_ring[entry]; in tse_tx_complete()
447 netdev_dbg(priv->dev, "%s: curr %d, dirty %d\n", in tse_tx_complete()
448 __func__, priv->tx_prod, priv->tx_cons); in tse_tx_complete()
450 if (likely(tx_buff->skb)) in tse_tx_complete()
451 priv->dev->stats.tx_packets++; in tse_tx_complete()
454 priv->tx_cons++; in tse_tx_complete()
457 ready--; in tse_tx_complete()
460 if (unlikely(netif_queue_stopped(priv->dev) && in tse_tx_complete()
462 if (netif_queue_stopped(priv->dev) && in tse_tx_complete()
465 netdev_dbg(priv->dev, "%s: restart transmit\n", in tse_tx_complete()
467 netif_wake_queue(priv->dev); in tse_tx_complete()
471 spin_unlock(&priv->tx_lock); in tse_tx_complete()
492 netdev_dbg(priv->dev, in tse_poll()
496 spin_lock_irqsave(&priv->rxdma_irq_lock, flags); in tse_poll()
497 priv->dmaops->enable_rxirq(priv); in tse_poll()
498 priv->dmaops->enable_txirq(priv); in tse_poll()
499 spin_unlock_irqrestore(&priv->rxdma_irq_lock, flags); in tse_poll()
504 /* DMA TX & RX FIFO interrupt routing
517 spin_lock(&priv->rxdma_irq_lock); in altera_isr()
519 priv->dmaops->clear_rxirq(priv); in altera_isr()
520 priv->dmaops->clear_txirq(priv); in altera_isr()
521 spin_unlock(&priv->rxdma_irq_lock); in altera_isr()
523 if (likely(napi_schedule_prep(&priv->napi))) { in altera_isr()
524 spin_lock(&priv->rxdma_irq_lock); in altera_isr()
525 priv->dmaops->disable_rxirq(priv); in altera_isr()
526 priv->dmaops->disable_txirq(priv); in altera_isr()
527 spin_unlock(&priv->rxdma_irq_lock); in altera_isr()
528 __napi_schedule(&priv->napi); in altera_isr()
540 * skb->data, for length of skb_headlen(skb).
546 unsigned int txsize = priv->tx_ring_size; in tse_start_xmit()
547 int nfrags = skb_shinfo(skb)->nr_frags; in tse_start_xmit()
553 spin_lock_bh(&priv->tx_lock); in tse_start_xmit()
559 netdev_err(priv->dev, in tse_start_xmit()
568 entry = priv->tx_prod % txsize; in tse_start_xmit()
569 buffer = &priv->tx_ring[entry]; in tse_start_xmit()
571 dma_addr = dma_map_single(priv->device, skb->data, nopaged_len, in tse_start_xmit()
573 if (dma_mapping_error(priv->device, dma_addr)) { in tse_start_xmit()
574 netdev_err(priv->dev, "%s: DMA mapping error\n", __func__); in tse_start_xmit()
579 buffer->skb = skb; in tse_start_xmit()
580 buffer->dma_addr = dma_addr; in tse_start_xmit()
581 buffer->len = nopaged_len; in tse_start_xmit()
583 priv->dmaops->tx_buffer(priv, buffer); in tse_start_xmit()
587 priv->tx_prod++; in tse_start_xmit()
588 dev->stats.tx_bytes += skb->len; in tse_start_xmit()
592 netdev_dbg(priv->dev, "%s: stop transmitted packets\n", in tse_start_xmit()
598 spin_unlock_bh(&priv->tx_lock); in tse_start_xmit()
606 struct device_node *np = priv->device->of_node; in altera_tse_phy_get_addr_mdio_create()
609 ret = of_get_phy_mode(np, &priv->phy_iface); in altera_tse_phy_get_addr_mdio_create()
619 if (of_property_read_u32(priv->device->of_node, "phy-addr", in altera_tse_phy_get_addr_mdio_create()
620 &priv->phy_addr)) { in altera_tse_phy_get_addr_mdio_create()
621 priv->phy_addr = POLL_PHY; in altera_tse_phy_get_addr_mdio_create()
624 if (!((priv->phy_addr == POLL_PHY) || in altera_tse_phy_get_addr_mdio_create()
625 ((priv->phy_addr >= 0) && (priv->phy_addr < PHY_MAX_ADDR)))) { in altera_tse_phy_get_addr_mdio_create()
626 netdev_err(dev, "invalid phy-addr specified %d\n", in altera_tse_phy_get_addr_mdio_create()
627 priv->phy_addr); in altera_tse_phy_get_addr_mdio_create()
628 return -ENODEV; in altera_tse_phy_get_addr_mdio_create()
636 return -ENODEV; in altera_tse_phy_get_addr_mdio_create()
650 csrwr32(msb, priv->mac_dev, tse_csroffs(mac_addr_0)); in tse_update_mac_addr()
651 csrwr32(lsb, priv->mac_dev, tse_csroffs(mac_addr_1)); in tse_update_mac_addr()
665 dat = csrrd32(priv->mac_dev, tse_csroffs(command_config)); in reset_mac()
668 csrwr32(dat, priv->mac_dev, tse_csroffs(command_config)); in reset_mac()
672 if (tse_bit_is_clear(priv->mac_dev, tse_csroffs(command_config), in reset_mac()
679 dat = csrrd32(priv->mac_dev, tse_csroffs(command_config)); in reset_mac()
681 csrwr32(dat, priv->mac_dev, tse_csroffs(command_config)); in reset_mac()
682 return -1; in reset_mac()
694 /* Setup Rx FIFO */ in init_mac()
695 csrwr32(priv->rx_fifo_depth - ALTERA_TSE_RX_SECTION_EMPTY, in init_mac()
696 priv->mac_dev, tse_csroffs(rx_section_empty)); in init_mac()
698 csrwr32(ALTERA_TSE_RX_SECTION_FULL, priv->mac_dev, in init_mac()
701 csrwr32(ALTERA_TSE_RX_ALMOST_EMPTY, priv->mac_dev, in init_mac()
704 csrwr32(ALTERA_TSE_RX_ALMOST_FULL, priv->mac_dev, in init_mac()
708 csrwr32(priv->tx_fifo_depth - ALTERA_TSE_TX_SECTION_EMPTY, in init_mac()
709 priv->mac_dev, tse_csroffs(tx_section_empty)); in init_mac()
711 csrwr32(ALTERA_TSE_TX_SECTION_FULL, priv->mac_dev, in init_mac()
714 csrwr32(ALTERA_TSE_TX_ALMOST_EMPTY, priv->mac_dev, in init_mac()
717 csrwr32(ALTERA_TSE_TX_ALMOST_FULL, priv->mac_dev, in init_mac()
721 tse_update_mac_addr(priv, priv->dev->dev_addr); in init_mac()
724 frm_length = ETH_HLEN + priv->dev->mtu + ETH_FCS_LEN; in init_mac()
725 csrwr32(frm_length, priv->mac_dev, tse_csroffs(frm_length)); in init_mac()
727 csrwr32(ALTERA_TSE_TX_IPG_LENGTH, priv->mac_dev, in init_mac()
730 /* Disable RX/TX shift 16 for alignment of all received frames on 16-bit in init_mac()
733 tse_set_bit(priv->mac_dev, tse_csroffs(rx_cmd_stat), in init_mac()
736 tse_clear_bit(priv->mac_dev, tse_csroffs(tx_cmd_stat), in init_mac()
741 cmd = csrrd32(priv->mac_dev, tse_csroffs(command_config)); in init_mac()
756 csrwr32(cmd, priv->mac_dev, tse_csroffs(command_config)); in init_mac()
758 csrwr32(ALTERA_TSE_PAUSE_QUANTA, priv->mac_dev, in init_mac()
762 dev_dbg(priv->device, in init_mac()
763 "MAC post-initialization: CMD_CONFIG = 0x%08x\n", cmd); in init_mac()
772 u32 value = csrrd32(priv->mac_dev, tse_csroffs(command_config)); in tse_set_mac()
779 csrwr32(value, priv->mac_dev, tse_csroffs(command_config)); in tse_set_mac()
788 return -EBUSY; in tse_change_mtu()
791 WRITE_ONCE(dev->mtu, new_mtu); in tse_change_mtu()
805 csrwr32(0, priv->mac_dev, tse_csroffs(hash_table) + i * 4); in altera_tse_set_mcfilter()
811 for (mac_octet = 5; mac_octet >= 0; mac_octet--) { in altera_tse_set_mcfilter()
813 unsigned char octet = ha->addr[mac_octet]; in altera_tse_set_mcfilter()
821 csrwr32(1, priv->mac_dev, tse_csroffs(hash_table) + hash * 4); in altera_tse_set_mcfilter()
833 csrwr32(1, priv->mac_dev, tse_csroffs(hash_table) + i * 4); in altera_tse_set_mcfilterall()
842 spin_lock(&priv->mac_cfg_lock); in tse_set_rx_mode_hashfilter()
844 if (dev->flags & IFF_PROMISC) in tse_set_rx_mode_hashfilter()
845 tse_set_bit(priv->mac_dev, tse_csroffs(command_config), in tse_set_rx_mode_hashfilter()
848 if (dev->flags & IFF_ALLMULTI) in tse_set_rx_mode_hashfilter()
853 spin_unlock(&priv->mac_cfg_lock); in tse_set_rx_mode_hashfilter()
862 spin_lock(&priv->mac_cfg_lock); in tse_set_rx_mode()
864 if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) || in tse_set_rx_mode()
866 tse_set_bit(priv->mac_dev, tse_csroffs(command_config), in tse_set_rx_mode()
869 tse_clear_bit(priv->mac_dev, tse_csroffs(command_config), in tse_set_rx_mode()
872 spin_unlock(&priv->mac_cfg_lock); in tse_set_rx_mode()
885 ret = priv->dmaops->init_dma(priv); in tse_open()
893 dev->dev_addr); in tse_open()
895 if ((priv->revision < 0xd00) || (priv->revision > 0xe00)) in tse_open()
896 netdev_warn(dev, "TSE revision %x\n", priv->revision); in tse_open()
898 spin_lock(&priv->mac_cfg_lock); in tse_open()
909 spin_unlock(&priv->mac_cfg_lock); in tse_open()
915 priv->dmaops->reset_dma(priv); in tse_open()
917 /* Create and initialize the TX/RX descriptors chains. */ in tse_open()
918 priv->rx_ring_size = dma_rx_num; in tse_open()
919 priv->tx_ring_size = dma_tx_num; in tse_open()
927 /* Register RX interrupt */ in tse_open()
928 ret = request_irq(priv->rx_irq, altera_isr, IRQF_SHARED, in tse_open()
929 dev->name, dev); in tse_open()
931 netdev_err(dev, "Unable to register RX interrupt %d\n", in tse_open()
932 priv->rx_irq); in tse_open()
937 ret = request_irq(priv->tx_irq, altera_isr, IRQF_SHARED, in tse_open()
938 dev->name, dev); in tse_open()
941 priv->tx_irq); in tse_open()
946 spin_lock_irqsave(&priv->rxdma_irq_lock, flags); in tse_open()
947 priv->dmaops->enable_rxirq(priv); in tse_open()
948 priv->dmaops->enable_txirq(priv); in tse_open()
950 /* Setup RX descriptor chain */ in tse_open()
951 for (i = 0; i < priv->rx_ring_size; i++) in tse_open()
952 priv->dmaops->add_rx_desc(priv, &priv->rx_ring[i]); in tse_open()
954 spin_unlock_irqrestore(&priv->rxdma_irq_lock, flags); in tse_open()
956 ret = phylink_of_phy_connect(priv->phylink, priv->device->of_node, 0); in tse_open()
961 phylink_start(priv->phylink); in tse_open()
963 napi_enable(&priv->napi); in tse_open()
966 priv->dmaops->start_rxdma(priv); in tse_open()
968 /* Start MAC Rx/Tx */ in tse_open()
969 spin_lock(&priv->mac_cfg_lock); in tse_open()
971 spin_unlock(&priv->mac_cfg_lock); in tse_open()
976 free_irq(priv->rx_irq, dev); in tse_open()
992 phylink_stop(priv->phylink); in tse_shutdown()
993 phylink_disconnect_phy(priv->phylink); in tse_shutdown()
995 napi_disable(&priv->napi); in tse_shutdown()
998 spin_lock_irqsave(&priv->rxdma_irq_lock, flags); in tse_shutdown()
999 priv->dmaops->disable_rxirq(priv); in tse_shutdown()
1000 priv->dmaops->disable_txirq(priv); in tse_shutdown()
1001 spin_unlock_irqrestore(&priv->rxdma_irq_lock, flags); in tse_shutdown()
1004 free_irq(priv->rx_irq, dev); in tse_shutdown()
1005 free_irq(priv->tx_irq, dev); in tse_shutdown()
1008 spin_lock(&priv->mac_cfg_lock); in tse_shutdown()
1009 spin_lock(&priv->tx_lock); in tse_shutdown()
1018 priv->dmaops->reset_dma(priv); in tse_shutdown()
1021 spin_unlock(&priv->tx_lock); in tse_shutdown()
1022 spin_unlock(&priv->mac_cfg_lock); in tse_shutdown()
1024 priv->dmaops->uninit_dma(priv); in tse_shutdown()
1042 struct net_device *ndev = to_net_dev(config->dev); in alt_tse_mac_config()
1045 spin_lock(&priv->mac_cfg_lock); in alt_tse_mac_config()
1048 spin_unlock(&priv->mac_cfg_lock); in alt_tse_mac_config()
1061 struct net_device *ndev = to_net_dev(config->dev); in alt_tse_mac_link_up()
1065 ctrl = csrrd32(priv->mac_dev, tse_csroffs(command_config)); in alt_tse_mac_link_up()
1076 spin_lock(&priv->mac_cfg_lock); in alt_tse_mac_link_up()
1077 csrwr32(ctrl, priv->mac_dev, tse_csroffs(command_config)); in alt_tse_mac_link_up()
1078 spin_unlock(&priv->mac_cfg_lock); in alt_tse_mac_link_up()
1084 struct net_device *ndev = to_net_dev(config->dev); in alt_tse_select_pcs()
1089 return priv->pcs; in alt_tse_select_pcs()
1104 struct device *device = &pdev->dev; in request_and_map()
1110 return -ENODEV; in request_and_map()
1113 region = devm_request_mem_region(device, (*res)->start, in request_and_map()
1117 return -EBUSY; in request_and_map()
1120 *ptr = devm_ioremap(device, region->start, in request_and_map()
1124 return -ENOMEM; in request_and_map()
1144 int ret = -ENODEV; in altera_tse_probe()
1148 dev_err(&pdev->dev, "Could not allocate network device\n"); in altera_tse_probe()
1149 return -ENODEV; in altera_tse_probe()
1152 SET_NETDEV_DEV(ndev, &pdev->dev); in altera_tse_probe()
1155 priv->device = &pdev->dev; in altera_tse_probe()
1156 priv->dev = ndev; in altera_tse_probe()
1157 priv->msg_enable = netif_msg_init(debug, default_msg_level); in altera_tse_probe()
1159 priv->dmaops = device_get_match_data(&pdev->dev); in altera_tse_probe()
1161 if (priv->dmaops && in altera_tse_probe()
1162 priv->dmaops->altera_dtype == ALTERA_DTYPE_SGDMA) { in altera_tse_probe()
1169 priv->tx_dma_desc = descmap; in altera_tse_probe()
1172 priv->txdescmem = resource_size(dma_res)/2; in altera_tse_probe()
1174 priv->txdescmem_busaddr = (dma_addr_t)dma_res->start; in altera_tse_probe()
1176 priv->rx_dma_desc = (void __iomem *)((uintptr_t)(descmap + in altera_tse_probe()
1177 priv->txdescmem)); in altera_tse_probe()
1178 priv->rxdescmem = resource_size(dma_res)/2; in altera_tse_probe()
1179 priv->rxdescmem_busaddr = dma_res->start; in altera_tse_probe()
1180 priv->rxdescmem_busaddr += priv->txdescmem; in altera_tse_probe()
1182 if (upper_32_bits(priv->rxdescmem_busaddr)) { in altera_tse_probe()
1183 dev_dbg(priv->device, in altera_tse_probe()
1184 "SGDMA bus addresses greater than 32-bits\n"); in altera_tse_probe()
1185 ret = -EINVAL; in altera_tse_probe()
1188 if (upper_32_bits(priv->txdescmem_busaddr)) { in altera_tse_probe()
1189 dev_dbg(priv->device, in altera_tse_probe()
1190 "SGDMA bus addresses greater than 32-bits\n"); in altera_tse_probe()
1191 ret = -EINVAL; in altera_tse_probe()
1194 } else if (priv->dmaops && in altera_tse_probe()
1195 priv->dmaops->altera_dtype == ALTERA_DTYPE_MSGDMA) { in altera_tse_probe()
1197 &priv->rx_dma_resp); in altera_tse_probe()
1202 &priv->tx_dma_desc); in altera_tse_probe()
1206 priv->txdescmem = resource_size(dma_res); in altera_tse_probe()
1207 priv->txdescmem_busaddr = dma_res->start; in altera_tse_probe()
1210 &priv->rx_dma_desc); in altera_tse_probe()
1214 priv->rxdescmem = resource_size(dma_res); in altera_tse_probe()
1215 priv->rxdescmem_busaddr = dma_res->start; in altera_tse_probe()
1218 ret = -ENODEV; in altera_tse_probe()
1222 if (!dma_set_mask(priv->device, DMA_BIT_MASK(priv->dmaops->dmamask))) { in altera_tse_probe()
1223 dma_set_coherent_mask(priv->device, in altera_tse_probe()
1224 DMA_BIT_MASK(priv->dmaops->dmamask)); in altera_tse_probe()
1225 } else if (!dma_set_mask(priv->device, DMA_BIT_MASK(32))) { in altera_tse_probe()
1226 dma_set_coherent_mask(priv->device, DMA_BIT_MASK(32)); in altera_tse_probe()
1228 ret = -EIO; in altera_tse_probe()
1234 (void __iomem **)&priv->mac_dev); in altera_tse_probe()
1238 /* xSGDMA Rx Dispatcher address space */ in altera_tse_probe()
1240 &priv->rx_dma_csr); in altera_tse_probe()
1247 &priv->tx_dma_csr); in altera_tse_probe()
1253 /* SGMII PCS address space. The location can vary depending on how the in altera_tse_probe()
1258 ret = request_and_map(pdev, "pcs", &pcs_res, &priv->pcs_base); in altera_tse_probe()
1260 /* If we can't find a dedicated resource for the PCS, fallback in altera_tse_probe()
1261 * to the internal PCS, that has a different address stride in altera_tse_probe()
1263 priv->pcs_base = priv->mac_dev + tse_csroffs(mdio_phy0); in altera_tse_probe()
1265 /* Values are MDIO-like values, on 16 bits */ in altera_tse_probe()
1274 /* Create a regmap for the PCS so that it can be used by the PCS driver */ in altera_tse_probe()
1275 pcs_regmap = devm_regmap_init_mmio(&pdev->dev, priv->pcs_base, in altera_tse_probe()
1282 mrc.parent = &pdev->dev; in altera_tse_probe()
1286 /* Rx IRQ */ in altera_tse_probe()
1287 priv->rx_irq = platform_get_irq_byname(pdev, "rx_irq"); in altera_tse_probe()
1288 if (priv->rx_irq == -ENXIO) { in altera_tse_probe()
1289 dev_err(&pdev->dev, "cannot obtain Rx IRQ\n"); in altera_tse_probe()
1290 ret = -ENXIO; in altera_tse_probe()
1295 priv->tx_irq = platform_get_irq_byname(pdev, "tx_irq"); in altera_tse_probe()
1296 if (priv->tx_irq == -ENXIO) { in altera_tse_probe()
1297 dev_err(&pdev->dev, "cannot obtain Tx IRQ\n"); in altera_tse_probe()
1298 ret = -ENXIO; in altera_tse_probe()
1303 if (of_property_read_u32(pdev->dev.of_node, "rx-fifo-depth", in altera_tse_probe()
1304 &priv->rx_fifo_depth)) { in altera_tse_probe()
1305 dev_err(&pdev->dev, "cannot obtain rx-fifo-depth\n"); in altera_tse_probe()
1306 ret = -ENXIO; in altera_tse_probe()
1310 if (of_property_read_u32(pdev->dev.of_node, "tx-fifo-depth", in altera_tse_probe()
1311 &priv->tx_fifo_depth)) { in altera_tse_probe()
1312 dev_err(&pdev->dev, "cannot obtain tx-fifo-depth\n"); in altera_tse_probe()
1313 ret = -ENXIO; in altera_tse_probe()
1318 priv->hash_filter = in altera_tse_probe()
1319 of_property_read_bool(pdev->dev.of_node, in altera_tse_probe()
1320 "altr,has-hash-multicast-filter"); in altera_tse_probe()
1325 priv->hash_filter = 0; in altera_tse_probe()
1328 priv->added_unicast = in altera_tse_probe()
1329 of_property_read_bool(pdev->dev.of_node, in altera_tse_probe()
1330 "altr,has-supplementary-unicast"); in altera_tse_probe()
1332 priv->dev->min_mtu = ETH_ZLEN + ETH_FCS_LEN; in altera_tse_probe()
1334 priv->dev->max_mtu = ETH_DATA_LEN; in altera_tse_probe()
1337 * "max-frame-size" parameter is actually max mtu. Definition in altera_tse_probe()
1340 of_property_read_u32(pdev->dev.of_node, "max-frame-size", in altera_tse_probe()
1341 &priv->dev->max_mtu); in altera_tse_probe()
1346 priv->rx_dma_buf_sz = ALTERA_RXDMABUFFER_SIZE; in altera_tse_probe()
1349 ret = of_get_ethdev_address(pdev->dev.of_node, ndev); in altera_tse_probe()
1360 ndev->mem_start = control_port->start; in altera_tse_probe()
1361 ndev->mem_end = control_port->end; in altera_tse_probe()
1362 ndev->netdev_ops = &altera_tse_netdev_ops; in altera_tse_probe()
1367 if (priv->hash_filter) in altera_tse_probe()
1374 ndev->hw_features &= ~NETIF_F_SG; in altera_tse_probe()
1375 ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA; in altera_tse_probe()
1379 * extra 4-byte VLAN tag for processing by upper layers in altera_tse_probe()
1381 ndev->features |= NETIF_F_HW_VLAN_CTAG_RX; in altera_tse_probe()
1384 netif_napi_add(ndev, &priv->napi, tse_poll); in altera_tse_probe()
1386 spin_lock_init(&priv->mac_cfg_lock); in altera_tse_probe()
1387 spin_lock_init(&priv->tx_lock); in altera_tse_probe()
1388 spin_lock_init(&priv->rxdma_irq_lock); in altera_tse_probe()
1393 dev_err(&pdev->dev, "failed to register TSE net device\n"); in altera_tse_probe()
1399 priv->revision = ioread32(&priv->mac_dev->megacore_revision); in altera_tse_probe()
1402 dev_info(&pdev->dev, "Altera TSE MAC version %d.%d at 0x%08lx irq %d/%d\n", in altera_tse_probe()
1403 (priv->revision >> 8) & 0xff, in altera_tse_probe()
1404 priv->revision & 0xff, in altera_tse_probe()
1405 (unsigned long) control_port->start, priv->rx_irq, in altera_tse_probe()
1406 priv->tx_irq); in altera_tse_probe()
1408 snprintf(mrc.name, MII_BUS_ID_SIZE, "%s-pcs-mii", ndev->name); in altera_tse_probe()
1409 pcs_bus = devm_mdio_regmap_register(&pdev->dev, &mrc); in altera_tse_probe()
1415 priv->pcs = lynx_pcs_create_mdiodev(pcs_bus, 0); in altera_tse_probe()
1416 if (IS_ERR(priv->pcs)) { in altera_tse_probe()
1417 ret = PTR_ERR(priv->pcs); in altera_tse_probe()
1421 priv->phylink_config.dev = &ndev->dev; in altera_tse_probe()
1422 priv->phylink_config.type = PHYLINK_NETDEV; in altera_tse_probe()
1423 priv->phylink_config.mac_capabilities = MAC_SYM_PAUSE | MAC_10 | in altera_tse_probe()
1426 phy_interface_set_rgmii(priv->phylink_config.supported_interfaces); in altera_tse_probe()
1428 priv->phylink_config.supported_interfaces); in altera_tse_probe()
1430 priv->phylink_config.supported_interfaces); in altera_tse_probe()
1432 priv->phylink_config.supported_interfaces); in altera_tse_probe()
1434 priv->phylink_config.supported_interfaces); in altera_tse_probe()
1436 priv->phylink = phylink_create(&priv->phylink_config, in altera_tse_probe()
1437 of_fwnode_handle(priv->device->of_node), in altera_tse_probe()
1438 priv->phy_iface, &alt_tse_phylink_ops); in altera_tse_probe()
1439 if (IS_ERR(priv->phylink)) { in altera_tse_probe()
1440 dev_err(&pdev->dev, "failed to create phylink\n"); in altera_tse_probe()
1441 ret = PTR_ERR(priv->phylink); in altera_tse_probe()
1447 lynx_pcs_destroy(priv->pcs); in altera_tse_probe()
1451 netif_napi_del(&priv->napi); in altera_tse_probe()
1468 phylink_destroy(priv->phylink); in altera_tse_remove()
1469 lynx_pcs_destroy(priv->pcs); in altera_tse_remove()
1513 { .compatible = "altr,tse-msgdma-1.0", .data = &altera_dtype_msgdma, },
1514 { .compatible = "altr,tse-1.0", .data = &altera_dtype_sgdma, },
1515 { .compatible = "ALTR,tse-1.0", .data = &altera_dtype_sgdma, },