Lines Matching +full:bd +full:- +full:address
1 // SPDX-License-Identifier: GPL-2.0-only
6 * Copyright (c) 2005-2008 DLA Systems, David H. Lynch Jr. <[email protected]>
7 * Copyright (c) 2008-2009 Secret Lab Technologies Ltd.
13 * - The ll_temac hardware uses indirect access for many of the TEMAC
24 * - Factor out locallink DMA code into separate driver
25 * - Fix support for hardware checksumming.
26 * - Testing. Lots and lots of testing.
53 #include <linux/dma-mapping.h>
55 #include <linux/platform_data/xilinx-ll-temac.h>
65 /* ---------------------------------------------------------------------
71 return ioread32be(lp->regs + offset); in _temac_ior_be()
76 return iowrite32be(value, lp->regs + offset); in _temac_iow_be()
81 return ioread32(lp->regs + offset); in _temac_ior_le()
86 return iowrite32(value, lp->regs + offset); in _temac_iow_le()
108 * temac_indirect_busywait - Wait for current indirect register access
117 return -ETIMEDOUT; in temac_indirect_busywait()
123 * temac_indirect_in32 - Indirect register read access. This function
124 * must be called without lp->indirect_lock being held.
131 spin_lock_irqsave(lp->indirect_lock, flags); in temac_indirect_in32()
133 spin_unlock_irqrestore(lp->indirect_lock, flags); in temac_indirect_in32()
138 * temac_indirect_in32_locked - Indirect register read access. This
139 * function must be called with lp->indirect_lock being held. Use
151 return -ETIMEDOUT; in temac_indirect_in32_locked()
160 return -ETIMEDOUT; in temac_indirect_in32_locked()
166 * temac_indirect_out32 - Indirect register write access. This function
167 * must be called without lp->indirect_lock being held.
173 spin_lock_irqsave(lp->indirect_lock, flags); in temac_indirect_out32()
175 spin_unlock_irqrestore(lp->indirect_lock, flags); in temac_indirect_out32()
179 * temac_indirect_out32_locked - Indirect register write access. This
180 * function must be called with lp->indirect_lock being held. Use
204 * temac_dma_in32_* - Memory mapped DMA read, these function expects a
207 * lp->dma_in32.
211 return ioread32be(lp->sdma_regs + (reg << 2)); in temac_dma_in32_be()
216 return ioread32(lp->sdma_regs + (reg << 2)); in temac_dma_in32_le()
220 * temac_dma_out32_* - Memory mapped DMA read, these function expects
223 * lp->dma_out32.
227 iowrite32be(value, lp->sdma_regs + (reg << 2)); in temac_dma_out32_be()
232 iowrite32(value, lp->sdma_regs + (reg << 2)); in temac_dma_out32_le()
242 * temac_dma_dcr_in32 - DCR based DMA read
246 return dcr_read(lp->sdma_dcrs, reg); in temac_dma_dcr_in()
250 * temac_dma_dcr_out32 - DCR based DMA write
254 dcr_write(lp->sdma_dcrs, reg, value); in temac_dma_dcr_out()
258 * temac_dcr_setup - If the DMA is DCR based, then setup the address and
266 /* setup the dcr address mapping if it's in the device tree */ in temac_dcr_setup()
270 lp->sdma_dcrs = dcr_map(np, dcrs, dcr_resource_len(np, 0)); in temac_dcr_setup()
271 lp->dma_in = temac_dma_dcr_in; in temac_dcr_setup()
272 lp->dma_out = temac_dma_dcr_out; in temac_dcr_setup()
273 dev_dbg(&op->dev, "DCR base: %x\n", dcrs); in temac_dcr_setup()
277 return -1; in temac_dcr_setup()
283 * temac_dcr_setup - This is a stub for when DCR is not supported,
289 return -1; in temac_dcr_setup()
295 * temac_dma_bd_release - Release buffer descriptor rings
303 lp->dma_out(lp, DMA_CONTROL_REG, DMA_CONTROL_RST); in temac_dma_bd_release()
305 for (i = 0; i < lp->rx_bd_num; i++) { in temac_dma_bd_release()
306 if (!lp->rx_skb[i]) in temac_dma_bd_release()
308 dma_unmap_single(ndev->dev.parent, lp->rx_bd_v[i].phys, in temac_dma_bd_release()
310 dev_kfree_skb(lp->rx_skb[i]); in temac_dma_bd_release()
312 if (lp->rx_bd_v) in temac_dma_bd_release()
313 dma_free_coherent(ndev->dev.parent, in temac_dma_bd_release()
314 sizeof(*lp->rx_bd_v) * lp->rx_bd_num, in temac_dma_bd_release()
315 lp->rx_bd_v, lp->rx_bd_p); in temac_dma_bd_release()
316 if (lp->tx_bd_v) in temac_dma_bd_release()
317 dma_free_coherent(ndev->dev.parent, in temac_dma_bd_release()
318 sizeof(*lp->tx_bd_v) * lp->tx_bd_num, in temac_dma_bd_release()
319 lp->tx_bd_v, lp->tx_bd_p); in temac_dma_bd_release()
323 * temac_dma_bd_init - Setup buffer descriptor rings
332 lp->rx_skb = devm_kcalloc(&ndev->dev, lp->rx_bd_num, in temac_dma_bd_init()
333 sizeof(*lp->rx_skb), GFP_KERNEL); in temac_dma_bd_init()
334 if (!lp->rx_skb) in temac_dma_bd_init()
338 /* returns a virtual address and a physical address. */ in temac_dma_bd_init()
339 lp->tx_bd_v = dma_alloc_coherent(ndev->dev.parent, in temac_dma_bd_init()
340 sizeof(*lp->tx_bd_v) * lp->tx_bd_num, in temac_dma_bd_init()
341 &lp->tx_bd_p, GFP_KERNEL); in temac_dma_bd_init()
342 if (!lp->tx_bd_v) in temac_dma_bd_init()
345 lp->rx_bd_v = dma_alloc_coherent(ndev->dev.parent, in temac_dma_bd_init()
346 sizeof(*lp->rx_bd_v) * lp->rx_bd_num, in temac_dma_bd_init()
347 &lp->rx_bd_p, GFP_KERNEL); in temac_dma_bd_init()
348 if (!lp->rx_bd_v) in temac_dma_bd_init()
351 for (i = 0; i < lp->tx_bd_num; i++) { in temac_dma_bd_init()
352 lp->tx_bd_v[i].next = cpu_to_be32(lp->tx_bd_p in temac_dma_bd_init()
353 + sizeof(*lp->tx_bd_v) * ((i + 1) % lp->tx_bd_num)); in temac_dma_bd_init()
356 for (i = 0; i < lp->rx_bd_num; i++) { in temac_dma_bd_init()
357 lp->rx_bd_v[i].next = cpu_to_be32(lp->rx_bd_p in temac_dma_bd_init()
358 + sizeof(*lp->rx_bd_v) * ((i + 1) % lp->rx_bd_num)); in temac_dma_bd_init()
366 lp->rx_skb[i] = skb; in temac_dma_bd_init()
367 /* returns physical address of skb->data */ in temac_dma_bd_init()
368 skb_dma_addr = dma_map_single(ndev->dev.parent, skb->data, in temac_dma_bd_init()
371 if (dma_mapping_error(ndev->dev.parent, skb_dma_addr)) in temac_dma_bd_init()
373 lp->rx_bd_v[i].phys = cpu_to_be32(skb_dma_addr); in temac_dma_bd_init()
374 lp->rx_bd_v[i].len = cpu_to_be32(XTE_MAX_JUMBO_FRAME_SIZE); in temac_dma_bd_init()
375 lp->rx_bd_v[i].app0 = cpu_to_be32(STS_CTRL_APP0_IRQONEND); in temac_dma_bd_init()
379 lp->dma_out(lp, TX_CHNL_CTRL, in temac_dma_bd_init()
380 lp->coalesce_delay_tx << 24 | lp->coalesce_count_tx << 16 | in temac_dma_bd_init()
384 lp->dma_out(lp, RX_CHNL_CTRL, in temac_dma_bd_init()
385 lp->coalesce_delay_rx << 24 | lp->coalesce_count_rx << 16 | in temac_dma_bd_init()
391 lp->tx_bd_ci = 0; in temac_dma_bd_init()
392 lp->tx_bd_tail = 0; in temac_dma_bd_init()
393 lp->rx_bd_ci = 0; in temac_dma_bd_init()
394 lp->rx_bd_tail = lp->rx_bd_num - 1; in temac_dma_bd_init()
398 lp->dma_out(lp, RX_CURDESC_PTR, lp->rx_bd_p); in temac_dma_bd_init()
399 lp->dma_out(lp, RX_TAILDESC_PTR, in temac_dma_bd_init()
400 lp->rx_bd_p + (sizeof(*lp->rx_bd_v) * lp->rx_bd_tail)); in temac_dma_bd_init()
403 lp->dma_out(lp, TX_CURDESC_PTR, lp->tx_bd_p); in temac_dma_bd_init()
409 return -ENOMEM; in temac_dma_bd_init()
412 /* ---------------------------------------------------------------------
421 /* set up unicast MAC address filter set its mac address */ in temac_do_set_mac_address()
422 spin_lock_irqsave(lp->indirect_lock, flags); in temac_do_set_mac_address()
424 (ndev->dev_addr[0]) | in temac_do_set_mac_address()
425 (ndev->dev_addr[1] << 8) | in temac_do_set_mac_address()
426 (ndev->dev_addr[2] << 16) | in temac_do_set_mac_address()
427 (ndev->dev_addr[3] << 24)); in temac_do_set_mac_address()
432 (ndev->dev_addr[4] & 0x000000ff) | in temac_do_set_mac_address()
433 (ndev->dev_addr[5] << 8)); in temac_do_set_mac_address()
434 spin_unlock_irqrestore(lp->indirect_lock, flags); in temac_do_set_mac_address()
437 static int temac_init_mac_address(struct net_device *ndev, const void *address) in temac_init_mac_address() argument
439 eth_hw_addr_set(ndev, address); in temac_init_mac_address()
440 if (!is_valid_ether_addr(ndev->dev_addr)) in temac_init_mac_address()
450 if (!is_valid_ether_addr(addr->sa_data)) in temac_set_mac_address()
451 return -EADDRNOTAVAIL; in temac_set_mac_address()
452 eth_hw_addr_set(ndev, addr->sa_data); in temac_set_mac_address()
465 if (ndev->flags & (IFF_PROMISC | IFF_ALLMULTI) || in temac_set_multicast_list()
468 dev_info(&ndev->dev, "Promiscuous mode enabled.\n"); in temac_set_multicast_list()
472 spin_lock_irqsave(lp->indirect_lock, flags); in temac_set_multicast_list()
480 multi_addr_msw = ((ha->addr[3] << 24) | in temac_set_multicast_list()
481 (ha->addr[2] << 16) | in temac_set_multicast_list()
482 (ha->addr[1] << 8) | in temac_set_multicast_list()
483 (ha->addr[0])); in temac_set_multicast_list()
486 multi_addr_lsw = ((ha->addr[5] << 8) | in temac_set_multicast_list()
487 (ha->addr[4]) | (i << 16)); in temac_set_multicast_list()
494 /* Clear all or remaining/unused address table entries */ in temac_set_multicast_list()
501 /* Enable address filter block if currently disabled */ in temac_set_multicast_list()
508 spin_unlock_irqrestore(lp->indirect_lock, flags); in temac_set_multicast_list()
511 dev_info(&ndev->dev, "Promiscuous mode disabled.\n"); in temac_set_multicast_list()
604 spin_lock_irqsave(lp->indirect_lock, flags); in temac_setoptions()
605 while (tp->opt) { in temac_setoptions()
606 reg = temac_indirect_in32_locked(lp, tp->reg) & ~tp->m_or; in temac_setoptions()
607 if (options & tp->opt) { in temac_setoptions()
608 reg |= tp->m_or; in temac_setoptions()
609 temac_indirect_out32_locked(lp, tp->reg, reg); in temac_setoptions()
613 spin_unlock_irqrestore(lp->indirect_lock, flags); in temac_setoptions()
614 lp->options |= options; in temac_setoptions()
632 dev_dbg(&ndev->dev, "%s()\n", __func__); in temac_device_reset()
639 if (--timeout == 0) { in temac_device_reset()
640 dev_err(&ndev->dev, in temac_device_reset()
651 if (--timeout == 0) { in temac_device_reset()
652 dev_err(&ndev->dev, in temac_device_reset()
659 spin_lock_irqsave(lp->indirect_lock, flags); in temac_device_reset()
663 spin_unlock_irqrestore(lp->indirect_lock, flags); in temac_device_reset()
666 lp->dma_out(lp, DMA_CONTROL_REG, DMA_CONTROL_RST); in temac_device_reset()
668 while (lp->dma_in(lp, DMA_CONTROL_REG) & DMA_CONTROL_RST) { in temac_device_reset()
670 if (--timeout == 0) { in temac_device_reset()
671 dev_err(&ndev->dev, in temac_device_reset()
676 lp->dma_out(lp, DMA_CONTROL_REG, DMA_TAIL_ENABLE); in temac_device_reset()
679 dev_err(&ndev->dev, in temac_device_reset()
683 spin_lock_irqsave(lp->indirect_lock, flags); in temac_device_reset()
688 spin_unlock_irqrestore(lp->indirect_lock, flags); in temac_device_reset()
694 lp->options & ~(XTE_OPTION_TXEN | XTE_OPTION_RXEN)); in temac_device_reset()
698 /* Set address filter table */ in temac_device_reset()
700 if (temac_setoptions(ndev, lp->options)) in temac_device_reset()
701 dev_err(&ndev->dev, "Error setting TEMAC options\n"); in temac_device_reset()
710 struct phy_device *phy = ndev->phydev; in temac_adjust_link()
716 link_state = phy->speed | (phy->duplex << 1) | phy->link; in temac_adjust_link()
718 if (lp->last_link != link_state) { in temac_adjust_link()
719 spin_lock_irqsave(lp->indirect_lock, flags); in temac_adjust_link()
723 switch (phy->speed) { in temac_adjust_link()
737 spin_unlock_irqrestore(lp->indirect_lock, flags); in temac_adjust_link()
739 lp->last_link = link_state; in temac_adjust_link()
746 static void ptr_to_txbd(void *p, struct cdmac_bd *bd) in ptr_to_txbd() argument
748 bd->app3 = (u32)(((u64)p) >> 32); in ptr_to_txbd()
749 bd->app4 = (u32)((u64)p & 0xFFFFFFFF); in ptr_to_txbd()
752 static void *ptr_from_txbd(struct cdmac_bd *bd) in ptr_from_txbd() argument
754 return (void *)(((u64)(bd->app3) << 32) | bd->app4); in ptr_from_txbd()
759 static void ptr_to_txbd(void *p, struct cdmac_bd *bd) in ptr_to_txbd() argument
761 bd->app4 = (u32)p; in ptr_to_txbd()
764 static void *ptr_from_txbd(struct cdmac_bd *bd) in ptr_from_txbd() argument
766 return (void *)(bd->app4); in ptr_from_txbd()
778 cur_p = &lp->tx_bd_v[lp->tx_bd_ci]; in temac_start_xmit_done()
779 stat = be32_to_cpu(cur_p->app0); in temac_start_xmit_done()
782 /* Make sure that the other fields are read after bd is in temac_start_xmit_done()
786 dma_unmap_single(ndev->dev.parent, be32_to_cpu(cur_p->phys), in temac_start_xmit_done()
787 be32_to_cpu(cur_p->len), DMA_TO_DEVICE); in temac_start_xmit_done()
791 cur_p->app1 = 0; in temac_start_xmit_done()
792 cur_p->app2 = 0; in temac_start_xmit_done()
793 cur_p->app3 = 0; in temac_start_xmit_done()
794 cur_p->app4 = 0; in temac_start_xmit_done()
796 ndev->stats.tx_packets++; in temac_start_xmit_done()
797 ndev->stats.tx_bytes += be32_to_cpu(cur_p->len); in temac_start_xmit_done()
800 * availability of the bd in temac_start_xmit_done()
803 cur_p->app0 = 0; in temac_start_xmit_done()
805 lp->tx_bd_ci++; in temac_start_xmit_done()
806 if (lp->tx_bd_ci >= lp->tx_bd_num) in temac_start_xmit_done()
807 lp->tx_bd_ci = 0; in temac_start_xmit_done()
809 cur_p = &lp->tx_bd_v[lp->tx_bd_ci]; in temac_start_xmit_done()
810 stat = be32_to_cpu(cur_p->app0); in temac_start_xmit_done()
824 tail = lp->tx_bd_tail; in temac_check_tx_bd_space()
825 cur_p = &lp->tx_bd_v[tail]; in temac_check_tx_bd_space()
828 if (cur_p->app0) in temac_check_tx_bd_space()
831 /* Make sure to read next bd app0 after this one */ in temac_check_tx_bd_space()
835 if (tail >= lp->tx_bd_num) in temac_check_tx_bd_space()
838 cur_p = &lp->tx_bd_v[tail]; in temac_check_tx_bd_space()
839 num_frag--; in temac_check_tx_bd_space()
855 num_frag = skb_shinfo(skb)->nr_frags; in temac_start_xmit()
856 frag = &skb_shinfo(skb)->frags[0]; in temac_start_xmit()
857 cur_p = &lp->tx_bd_v[lp->tx_bd_tail]; in temac_start_xmit()
868 /* Space might have just been freed - check again */ in temac_start_xmit()
875 cur_p->app0 = 0; in temac_start_xmit()
876 if (skb->ip_summed == CHECKSUM_PARTIAL) { in temac_start_xmit()
878 unsigned int csum_index_off = csum_start_off + skb->csum_offset; in temac_start_xmit()
880 cur_p->app0 |= cpu_to_be32(0x000001); /* TX Checksum Enabled */ in temac_start_xmit()
881 cur_p->app1 = cpu_to_be32((csum_start_off << 16) in temac_start_xmit()
883 cur_p->app2 = 0; /* initial checksum seed */ in temac_start_xmit()
886 cur_p->app0 |= cpu_to_be32(STS_CTRL_APP0_SOP); in temac_start_xmit()
887 skb_dma_addr = dma_map_single(ndev->dev.parent, skb->data, in temac_start_xmit()
889 cur_p->len = cpu_to_be32(skb_headlen(skb)); in temac_start_xmit()
890 if (WARN_ON_ONCE(dma_mapping_error(ndev->dev.parent, skb_dma_addr))) { in temac_start_xmit()
892 ndev->stats.tx_dropped++; in temac_start_xmit()
895 cur_p->phys = cpu_to_be32(skb_dma_addr); in temac_start_xmit()
898 if (++lp->tx_bd_tail >= lp->tx_bd_num) in temac_start_xmit()
899 lp->tx_bd_tail = 0; in temac_start_xmit()
901 cur_p = &lp->tx_bd_v[lp->tx_bd_tail]; in temac_start_xmit()
902 skb_dma_addr = dma_map_single(ndev->dev.parent, in temac_start_xmit()
906 if (dma_mapping_error(ndev->dev.parent, skb_dma_addr)) { in temac_start_xmit()
907 if (--lp->tx_bd_tail < 0) in temac_start_xmit()
908 lp->tx_bd_tail = lp->tx_bd_num - 1; in temac_start_xmit()
909 cur_p = &lp->tx_bd_v[lp->tx_bd_tail]; in temac_start_xmit()
910 while (--ii >= 0) { in temac_start_xmit()
911 --frag; in temac_start_xmit()
912 dma_unmap_single(ndev->dev.parent, in temac_start_xmit()
913 be32_to_cpu(cur_p->phys), in temac_start_xmit()
916 if (--lp->tx_bd_tail < 0) in temac_start_xmit()
917 lp->tx_bd_tail = lp->tx_bd_num - 1; in temac_start_xmit()
918 cur_p = &lp->tx_bd_v[lp->tx_bd_tail]; in temac_start_xmit()
920 dma_unmap_single(ndev->dev.parent, in temac_start_xmit()
921 be32_to_cpu(cur_p->phys), in temac_start_xmit()
924 ndev->stats.tx_dropped++; in temac_start_xmit()
927 cur_p->phys = cpu_to_be32(skb_dma_addr); in temac_start_xmit()
928 cur_p->len = cpu_to_be32(skb_frag_size(frag)); in temac_start_xmit()
929 cur_p->app0 = 0; in temac_start_xmit()
932 cur_p->app0 |= cpu_to_be32(STS_CTRL_APP0_EOP); in temac_start_xmit()
934 /* Mark last fragment with skb address, so it can be consumed in temac_start_xmit()
939 tail_p = lp->tx_bd_p + sizeof(*lp->tx_bd_v) * lp->tx_bd_tail; in temac_start_xmit()
940 lp->tx_bd_tail++; in temac_start_xmit()
941 if (lp->tx_bd_tail >= lp->tx_bd_num) in temac_start_xmit()
942 lp->tx_bd_tail = 0; in temac_start_xmit()
948 lp->dma_out(lp, TX_TAILDESC_PTR, tail_p); /* DMA start */ in temac_start_xmit()
960 if (!lp->rx_skb[lp->rx_bd_ci]) in ll_temac_recv_buffers_available()
962 available = 1 + lp->rx_bd_tail - lp->rx_bd_ci; in ll_temac_recv_buffers_available()
964 available += lp->rx_bd_num; in ll_temac_recv_buffers_available()
975 spin_lock_irqsave(&lp->rx_lock, flags); in ll_temac_recv()
979 * un-allocated stage, where no skb is allocated for it, and in ll_temac_recv()
983 struct cdmac_bd *bd = &lp->rx_bd_v[lp->rx_bd_ci]; in ll_temac_recv() local
984 struct sk_buff *skb = lp->rx_skb[lp->rx_bd_ci]; in ll_temac_recv()
985 unsigned int bdstat = be32_to_cpu(bd->app0); in ll_temac_recv()
990 * therefore have un-allocated buffers. in ll_temac_recv()
999 dma_unmap_single(ndev->dev.parent, be32_to_cpu(bd->phys), in ll_temac_recv()
1002 bd->phys = 0; in ll_temac_recv()
1003 bd->len = 0; in ll_temac_recv()
1005 length = be32_to_cpu(bd->app4) & 0x3FFF; in ll_temac_recv()
1007 skb->protocol = eth_type_trans(skb, ndev); in ll_temac_recv()
1011 if (((lp->temac_features & TEMAC_FEATURE_RX_CSUM) != 0) && in ll_temac_recv()
1012 (skb->protocol == htons(ETH_P_IP)) && in ll_temac_recv()
1013 (skb->len > 64)) { in ll_temac_recv()
1019 skb->csum = htons(be32_to_cpu(bd->app3) & 0xFFFF); in ll_temac_recv()
1020 skb->ip_summed = CHECKSUM_COMPLETE; in ll_temac_recv()
1026 lp->rx_skb[lp->rx_bd_ci] = NULL; in ll_temac_recv()
1028 ndev->stats.rx_packets++; in ll_temac_recv()
1029 ndev->stats.rx_bytes += length; in ll_temac_recv()
1031 rx_bd = lp->rx_bd_ci; in ll_temac_recv()
1032 if (++lp->rx_bd_ci >= lp->rx_bd_num) in ll_temac_recv()
1033 lp->rx_bd_ci = 0; in ll_temac_recv()
1034 } while (rx_bd != lp->rx_bd_tail); in ll_temac_recv()
1042 * will call this function, and thus re-schedule itself until in ll_temac_recv()
1045 if (ll_temac_recv_buffers_available(lp) < lp->coalesce_count_rx) in ll_temac_recv()
1046 schedule_delayed_work(&lp->restart_work, HZ / 1000); in ll_temac_recv()
1059 struct cdmac_bd *bd; in ll_temac_recv() local
1062 rx_bd = lp->rx_bd_tail + 1; in ll_temac_recv()
1063 if (rx_bd >= lp->rx_bd_num) in ll_temac_recv()
1065 bd = &lp->rx_bd_v[rx_bd]; in ll_temac_recv()
1067 if (bd->phys) in ll_temac_recv()
1072 dev_warn(&ndev->dev, "skb alloc failed\n"); in ll_temac_recv()
1076 skb_dma_addr = dma_map_single(ndev->dev.parent, skb->data, in ll_temac_recv()
1079 if (WARN_ON_ONCE(dma_mapping_error(ndev->dev.parent, in ll_temac_recv()
1085 bd->phys = cpu_to_be32(skb_dma_addr); in ll_temac_recv()
1086 bd->len = cpu_to_be32(XTE_MAX_JUMBO_FRAME_SIZE); in ll_temac_recv()
1087 bd->app0 = cpu_to_be32(STS_CTRL_APP0_IRQONEND); in ll_temac_recv()
1088 lp->rx_skb[rx_bd] = skb; in ll_temac_recv()
1090 lp->rx_bd_tail = rx_bd; in ll_temac_recv()
1096 lp->dma_out(lp, RX_TAILDESC_PTR, in ll_temac_recv()
1097 lp->rx_bd_p + sizeof(*lp->rx_bd_v) * lp->rx_bd_tail); in ll_temac_recv()
1100 spin_unlock_irqrestore(&lp->rx_lock, flags); in ll_temac_recv()
1110 struct net_device *ndev = lp->ndev; in ll_temac_restart_work_func()
1121 status = lp->dma_in(lp, TX_IRQ_REG); in ll_temac_tx_irq()
1122 lp->dma_out(lp, TX_IRQ_REG, status); in ll_temac_tx_irq()
1125 temac_start_xmit_done(lp->ndev); in ll_temac_tx_irq()
1127 dev_err_ratelimited(&ndev->dev, in ll_temac_tx_irq()
1129 status, lp->dma_in(lp, TX_CHNL_STS)); in ll_temac_tx_irq()
1141 status = lp->dma_in(lp, RX_IRQ_REG); in ll_temac_rx_irq()
1142 lp->dma_out(lp, RX_IRQ_REG, status); in ll_temac_rx_irq()
1145 ll_temac_recv(lp->ndev); in ll_temac_rx_irq()
1147 dev_err_ratelimited(&ndev->dev, in ll_temac_rx_irq()
1149 status, lp->dma_in(lp, RX_CHNL_STS)); in ll_temac_rx_irq()
1160 dev_dbg(&ndev->dev, "temac_open()\n"); in temac_open()
1162 if (lp->phy_node) { in temac_open()
1163 phydev = of_phy_connect(lp->ndev, lp->phy_node, in temac_open()
1166 dev_err(lp->dev, "of_phy_connect() failed\n"); in temac_open()
1167 return -ENODEV; in temac_open()
1170 } else if (strlen(lp->phy_name) > 0) { in temac_open()
1171 phydev = phy_connect(lp->ndev, lp->phy_name, temac_adjust_link, in temac_open()
1172 lp->phy_interface); in temac_open()
1174 dev_err(lp->dev, "phy_connect() failed\n"); in temac_open()
1182 rc = request_irq(lp->tx_irq, ll_temac_tx_irq, 0, ndev->name, ndev); in temac_open()
1185 rc = request_irq(lp->rx_irq, ll_temac_rx_irq, 0, ndev->name, ndev); in temac_open()
1192 free_irq(lp->tx_irq, ndev); in temac_open()
1196 dev_err(lp->dev, "request_irq() failed\n"); in temac_open()
1203 struct phy_device *phydev = ndev->phydev; in temac_stop()
1205 dev_dbg(&ndev->dev, "temac_close()\n"); in temac_stop()
1207 cancel_delayed_work_sync(&lp->restart_work); in temac_stop()
1209 free_irq(lp->tx_irq, ndev); in temac_stop()
1210 free_irq(lp->rx_irq, ndev); in temac_stop()
1226 disable_irq(lp->tx_irq); in temac_poll_controller()
1227 disable_irq(lp->rx_irq); in temac_poll_controller()
1229 ll_temac_rx_irq(lp->tx_irq, ndev); in temac_poll_controller()
1230 ll_temac_tx_irq(lp->rx_irq, ndev); in temac_poll_controller()
1232 enable_irq(lp->tx_irq); in temac_poll_controller()
1233 enable_irq(lp->rx_irq); in temac_poll_controller()
1250 /* ---------------------------------------------------------------------
1261 len += sprintf(buf + len, "%.8x%s", lp->dma_in(lp, i), in temac_show_llink_regs()
1279 /* ---------------------------------------------------------------------
1291 ering->rx_max_pending = RX_BD_NUM_MAX; in ll_temac_ethtools_get_ringparam()
1292 ering->rx_mini_max_pending = 0; in ll_temac_ethtools_get_ringparam()
1293 ering->rx_jumbo_max_pending = 0; in ll_temac_ethtools_get_ringparam()
1294 ering->tx_max_pending = TX_BD_NUM_MAX; in ll_temac_ethtools_get_ringparam()
1295 ering->rx_pending = lp->rx_bd_num; in ll_temac_ethtools_get_ringparam()
1296 ering->rx_mini_pending = 0; in ll_temac_ethtools_get_ringparam()
1297 ering->rx_jumbo_pending = 0; in ll_temac_ethtools_get_ringparam()
1298 ering->tx_pending = lp->tx_bd_num; in ll_temac_ethtools_get_ringparam()
1309 if (ering->rx_pending > RX_BD_NUM_MAX || in ll_temac_ethtools_set_ringparam()
1310 ering->rx_mini_pending || in ll_temac_ethtools_set_ringparam()
1311 ering->rx_jumbo_pending || in ll_temac_ethtools_set_ringparam()
1312 ering->rx_pending > TX_BD_NUM_MAX) in ll_temac_ethtools_set_ringparam()
1313 return -EINVAL; in ll_temac_ethtools_set_ringparam()
1316 return -EBUSY; in ll_temac_ethtools_set_ringparam()
1318 lp->rx_bd_num = ering->rx_pending; in ll_temac_ethtools_set_ringparam()
1319 lp->tx_bd_num = ering->tx_pending; in ll_temac_ethtools_set_ringparam()
1331 ec->rx_max_coalesced_frames = lp->coalesce_count_rx; in ll_temac_ethtools_get_coalesce()
1332 ec->tx_max_coalesced_frames = lp->coalesce_count_tx; in ll_temac_ethtools_get_coalesce()
1333 ec->rx_coalesce_usecs = (lp->coalesce_delay_rx * 512) / 100; in ll_temac_ethtools_get_coalesce()
1334 ec->tx_coalesce_usecs = (lp->coalesce_delay_tx * 512) / 100; in ll_temac_ethtools_get_coalesce()
1349 return -EFAULT; in ll_temac_ethtools_set_coalesce()
1352 if (ec->rx_max_coalesced_frames) in ll_temac_ethtools_set_coalesce()
1353 lp->coalesce_count_rx = ec->rx_max_coalesced_frames; in ll_temac_ethtools_set_coalesce()
1354 if (ec->tx_max_coalesced_frames) in ll_temac_ethtools_set_coalesce()
1355 lp->coalesce_count_tx = ec->tx_max_coalesced_frames; in ll_temac_ethtools_set_coalesce()
1359 if (ec->rx_coalesce_usecs) in ll_temac_ethtools_set_coalesce()
1360 lp->coalesce_delay_rx = in ll_temac_ethtools_set_coalesce()
1361 min(255U, (ec->rx_coalesce_usecs * 100) / 512); in ll_temac_ethtools_set_coalesce()
1362 if (ec->tx_coalesce_usecs) in ll_temac_ethtools_set_coalesce()
1363 lp->coalesce_delay_tx = in ll_temac_ethtools_set_coalesce()
1364 min(255U, (ec->tx_coalesce_usecs * 100) / 512); in ll_temac_ethtools_set_coalesce()
1385 struct ll_temac_platform_data *pdata = dev_get_platdata(&pdev->dev); in temac_probe()
1386 struct device_node *temac_np = dev_of_node(&pdev->dev), *dma_np; in temac_probe()
1395 ndev = devm_alloc_etherdev(&pdev->dev, sizeof(*lp)); in temac_probe()
1397 return -ENOMEM; in temac_probe()
1400 SET_NETDEV_DEV(ndev, &pdev->dev); in temac_probe()
1401 ndev->features = NETIF_F_SG; in temac_probe()
1402 ndev->netdev_ops = &temac_netdev_ops; in temac_probe()
1403 ndev->ethtool_ops = &temac_ethtool_ops; in temac_probe()
1405 ndev->features |= NETIF_F_IP_CSUM; /* Can checksum TCP/UDP over IPv4. */ in temac_probe()
1406 ndev->features |= NETIF_F_HW_CSUM; /* Can checksum all the packets. */ in temac_probe()
1407 ndev->features |= NETIF_F_IPV6_CSUM; /* Can checksum IPV6 TCP/UDP */ in temac_probe()
1408 ndev->features |= NETIF_F_HIGHDMA; /* Can DMA to high memory. */ in temac_probe()
1409 ndev->features |= NETIF_F_HW_VLAN_CTAG_TX; /* Transmit VLAN hw accel */ in temac_probe()
1410 ndev->features |= NETIF_F_HW_VLAN_CTAG_RX; /* Receive VLAN hw acceleration */ in temac_probe()
1411 ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; /* Receive VLAN filtering */ in temac_probe()
1412 ndev->features |= NETIF_F_VLAN_CHALLENGED; /* cannot handle VLAN pkts */ in temac_probe()
1413 ndev->features |= NETIF_F_GSO; /* Enable software GSO. */ in temac_probe()
1414 ndev->features |= NETIF_F_MULTI_QUEUE; /* Has multiple TX/RX queues */ in temac_probe()
1415 ndev->features |= NETIF_F_LRO; /* large receive offload */ in temac_probe()
1420 lp->ndev = ndev; in temac_probe()
1421 lp->dev = &pdev->dev; in temac_probe()
1422 lp->options = XTE_OPTION_DEFAULTS; in temac_probe()
1423 lp->rx_bd_num = RX_BD_NUM_DEFAULT; in temac_probe()
1424 lp->tx_bd_num = TX_BD_NUM_DEFAULT; in temac_probe()
1425 spin_lock_init(&lp->rx_lock); in temac_probe()
1426 INIT_DELAYED_WORK(&lp->restart_work, ll_temac_restart_work_func); in temac_probe()
1430 if (!pdata->indirect_lock) { in temac_probe()
1431 dev_err(&pdev->dev, in temac_probe()
1433 return -EINVAL; in temac_probe()
1435 lp->indirect_lock = pdata->indirect_lock; in temac_probe()
1437 lp->indirect_lock = devm_kmalloc(&pdev->dev, in temac_probe()
1438 sizeof(*lp->indirect_lock), in temac_probe()
1440 if (!lp->indirect_lock) in temac_probe()
1441 return -ENOMEM; in temac_probe()
1442 spin_lock_init(lp->indirect_lock); in temac_probe()
1446 lp->regs = devm_platform_ioremap_resource(pdev, 0); in temac_probe()
1447 if (IS_ERR(lp->regs)) { in temac_probe()
1448 dev_err(&pdev->dev, "could not map TEMAC registers\n"); in temac_probe()
1449 return -ENOMEM; in temac_probe()
1453 * endianness mode. Default for OF devices is big-endian. in temac_probe()
1457 little_endian = of_property_read_bool(temac_np, "little-endian"); in temac_probe()
1459 little_endian = pdata->reg_little_endian; in temac_probe()
1462 lp->temac_ior = _temac_ior_le; in temac_probe()
1463 lp->temac_iow = _temac_iow_le; in temac_probe()
1465 lp->temac_ior = _temac_ior_be; in temac_probe()
1466 lp->temac_iow = _temac_iow_be; in temac_probe()
1470 lp->temac_features = 0; in temac_probe()
1474 lp->temac_features |= TEMAC_FEATURE_TX_CSUM; in temac_probe()
1477 lp->temac_features |= TEMAC_FEATURE_RX_CSUM; in temac_probe()
1479 if (pdata->txcsum) in temac_probe()
1480 lp->temac_features |= TEMAC_FEATURE_TX_CSUM; in temac_probe()
1481 if (pdata->rxcsum) in temac_probe()
1482 lp->temac_features |= TEMAC_FEATURE_RX_CSUM; in temac_probe()
1484 if (lp->temac_features & TEMAC_FEATURE_TX_CSUM) in temac_probe()
1486 ndev->features |= NETIF_F_IP_CSUM; in temac_probe()
1489 * configuration values, so does not belong in device-tree. in temac_probe()
1491 lp->coalesce_delay_tx = 0x10; in temac_probe()
1492 lp->coalesce_count_tx = 0x22; in temac_probe()
1493 lp->coalesce_delay_rx = 0xff; in temac_probe()
1494 lp->coalesce_count_rx = 0x07; in temac_probe()
1501 dma_np = of_parse_phandle(temac_np, "llink-connected", 0); in temac_probe()
1503 dev_err(&pdev->dev, "could not find DMA node\n"); in temac_probe()
1504 return -ENODEV; in temac_probe()
1511 /* no DCR in the device tree, try non-DCR */ in temac_probe()
1512 lp->sdma_regs = devm_of_iomap(&pdev->dev, dma_np, 0, in temac_probe()
1514 if (IS_ERR(lp->sdma_regs)) { in temac_probe()
1515 dev_err(&pdev->dev, in temac_probe()
1518 return PTR_ERR(lp->sdma_regs); in temac_probe()
1520 if (of_property_read_bool(dma_np, "little-endian")) { in temac_probe()
1521 lp->dma_in = temac_dma_in32_le; in temac_probe()
1522 lp->dma_out = temac_dma_out32_le; in temac_probe()
1524 lp->dma_in = temac_dma_in32_be; in temac_probe()
1525 lp->dma_out = temac_dma_out32_be; in temac_probe()
1527 dev_dbg(&pdev->dev, "MEM base: %p\n", lp->sdma_regs); in temac_probe()
1531 lp->rx_irq = irq_of_parse_and_map(dma_np, 0); in temac_probe()
1532 lp->tx_irq = irq_of_parse_and_map(dma_np, 1); in temac_probe()
1538 lp->sdma_regs = devm_platform_ioremap_resource(pdev, 1); in temac_probe()
1539 if (IS_ERR(lp->sdma_regs)) { in temac_probe()
1540 dev_err(&pdev->dev, in temac_probe()
1542 return PTR_ERR(lp->sdma_regs); in temac_probe()
1544 if (pdata->dma_little_endian) { in temac_probe()
1545 lp->dma_in = temac_dma_in32_le; in temac_probe()
1546 lp->dma_out = temac_dma_out32_le; in temac_probe()
1548 lp->dma_in = temac_dma_in32_be; in temac_probe()
1549 lp->dma_out = temac_dma_out32_be; in temac_probe()
1553 lp->rx_irq = platform_get_irq(pdev, 0); in temac_probe()
1554 lp->tx_irq = platform_get_irq(pdev, 1); in temac_probe()
1557 if (pdata->tx_irq_timeout || pdata->tx_irq_count) { in temac_probe()
1558 lp->coalesce_delay_tx = pdata->tx_irq_timeout; in temac_probe()
1559 lp->coalesce_count_tx = pdata->tx_irq_count; in temac_probe()
1561 if (pdata->rx_irq_timeout || pdata->rx_irq_count) { in temac_probe()
1562 lp->coalesce_delay_rx = pdata->rx_irq_timeout; in temac_probe()
1563 lp->coalesce_count_rx = pdata->rx_irq_count; in temac_probe()
1568 if (lp->rx_irq <= 0) { in temac_probe()
1569 rc = lp->rx_irq ?: -EINVAL; in temac_probe()
1570 return dev_err_probe(&pdev->dev, rc, in temac_probe()
1573 if (lp->tx_irq <= 0) { in temac_probe()
1574 rc = lp->tx_irq ?: -EINVAL; in temac_probe()
1575 return dev_err_probe(&pdev->dev, rc, in temac_probe()
1580 /* Retrieve the MAC address */ in temac_probe()
1583 dev_err(&pdev->dev, "could not find MAC address\n"); in temac_probe()
1584 return -ENODEV; in temac_probe()
1588 temac_init_mac_address(ndev, pdata->mac_addr); in temac_probe()
1593 dev_warn(&pdev->dev, "error registering MDIO bus\n"); in temac_probe()
1596 lp->phy_node = of_parse_phandle(temac_np, "phy-handle", 0); in temac_probe()
1597 if (lp->phy_node) in temac_probe()
1598 dev_dbg(lp->dev, "using PHY node %pOF\n", temac_np); in temac_probe()
1600 snprintf(lp->phy_name, sizeof(lp->phy_name), in temac_probe()
1601 PHY_ID_FMT, lp->mii_bus->id, pdata->phy_addr); in temac_probe()
1602 lp->phy_interface = pdata->phy_interface; in temac_probe()
1606 rc = sysfs_create_group(&lp->dev->kobj, &temac_attr_group); in temac_probe()
1608 dev_err(lp->dev, "Error creating sysfs files\n"); in temac_probe()
1612 rc = register_netdev(lp->ndev); in temac_probe()
1614 dev_err(lp->dev, "register_netdev() error (%i)\n", rc); in temac_probe()
1621 sysfs_remove_group(&lp->dev->kobj, &temac_attr_group); in temac_probe()
1623 if (lp->phy_node) in temac_probe()
1624 of_node_put(lp->phy_node); in temac_probe()
1635 sysfs_remove_group(&lp->dev->kobj, &temac_attr_group); in temac_remove()
1636 if (lp->phy_node) in temac_remove()
1637 of_node_put(lp->phy_node); in temac_remove()
1642 { .compatible = "xlnx,xps-ll-temac-1.01.b", },
1643 { .compatible = "xlnx,xps-ll-temac-2.00.a", },
1644 { .compatible = "xlnx,xps-ll-temac-2.02.a", },
1645 { .compatible = "xlnx,xps-ll-temac-2.03.a", },