aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/gianfar.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/gianfar.c')
-rw-r--r--drivers/net/gianfar.c191
1 files changed, 163 insertions, 28 deletions
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index 4e97ca18299..5267c27e317 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -82,6 +82,7 @@
82#include <linux/tcp.h> 82#include <linux/tcp.h>
83#include <linux/udp.h> 83#include <linux/udp.h>
84#include <linux/in.h> 84#include <linux/in.h>
85#include <linux/net_tstamp.h>
85 86
86#include <asm/io.h> 87#include <asm/io.h>
87#include <asm/irq.h> 88#include <asm/irq.h>
@@ -377,6 +378,13 @@ static void gfar_init_mac(struct net_device *ndev)
377 rctrl |= RCTRL_PADDING(priv->padding); 378 rctrl |= RCTRL_PADDING(priv->padding);
378 } 379 }
379 380
381 /* Insert receive time stamps into padding alignment bytes */
382 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER) {
383 rctrl &= ~RCTRL_PAL_MASK;
384 rctrl |= RCTRL_PRSDEP_INIT | RCTRL_TS_ENABLE | RCTRL_PADDING(8);
385 priv->padding = 8;
386 }
387
380 /* keep vlan related bits if it's enabled */ 388 /* keep vlan related bits if it's enabled */
381 if (priv->vlgrp) { 389 if (priv->vlgrp) {
382 rctrl |= RCTRL_VLEX | RCTRL_PRSDEP_INIT; 390 rctrl |= RCTRL_VLEX | RCTRL_PRSDEP_INIT;
@@ -501,7 +509,8 @@ void unlock_tx_qs(struct gfar_private *priv)
501/* Returns 1 if incoming frames use an FCB */ 509/* Returns 1 if incoming frames use an FCB */
502static inline int gfar_uses_fcb(struct gfar_private *priv) 510static inline int gfar_uses_fcb(struct gfar_private *priv)
503{ 511{
504 return priv->vlgrp || priv->rx_csum_enable; 512 return priv->vlgrp || priv->rx_csum_enable ||
513 (priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER);
505} 514}
506 515
507static void free_tx_pointers(struct gfar_private *priv) 516static void free_tx_pointers(struct gfar_private *priv)
@@ -738,7 +747,8 @@ static int gfar_of_init(struct of_device *ofdev, struct net_device **pdev)
738 FSL_GIANFAR_DEV_HAS_CSUM | 747 FSL_GIANFAR_DEV_HAS_CSUM |
739 FSL_GIANFAR_DEV_HAS_VLAN | 748 FSL_GIANFAR_DEV_HAS_VLAN |
740 FSL_GIANFAR_DEV_HAS_MAGIC_PACKET | 749 FSL_GIANFAR_DEV_HAS_MAGIC_PACKET |
741 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH; 750 FSL_GIANFAR_DEV_HAS_EXTENDED_HASH |
751 FSL_GIANFAR_DEV_HAS_TIMER;
742 752
743 ctype = of_get_property(np, "phy-connection-type", NULL); 753 ctype = of_get_property(np, "phy-connection-type", NULL);
744 754
@@ -768,6 +778,48 @@ err_grp_init:
768 return err; 778 return err;
769} 779}
770 780
781static int gfar_hwtstamp_ioctl(struct net_device *netdev,
782 struct ifreq *ifr, int cmd)
783{
784 struct hwtstamp_config config;
785 struct gfar_private *priv = netdev_priv(netdev);
786
787 if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
788 return -EFAULT;
789
790 /* reserved for future extensions */
791 if (config.flags)
792 return -EINVAL;
793
794 switch (config.tx_type) {
795 case HWTSTAMP_TX_OFF:
796 priv->hwts_tx_en = 0;
797 break;
798 case HWTSTAMP_TX_ON:
799 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER))
800 return -ERANGE;
801 priv->hwts_tx_en = 1;
802 break;
803 default:
804 return -ERANGE;
805 }
806
807 switch (config.rx_filter) {
808 case HWTSTAMP_FILTER_NONE:
809 priv->hwts_rx_en = 0;
810 break;
811 default:
812 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER))
813 return -ERANGE;
814 priv->hwts_rx_en = 1;
815 config.rx_filter = HWTSTAMP_FILTER_ALL;
816 break;
817 }
818
819 return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
820 -EFAULT : 0;
821}
822
771/* Ioctl MII Interface */ 823/* Ioctl MII Interface */
772static int gfar_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 824static int gfar_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
773{ 825{
@@ -776,6 +828,9 @@ static int gfar_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
776 if (!netif_running(dev)) 828 if (!netif_running(dev))
777 return -EINVAL; 829 return -EINVAL;
778 830
831 if (cmd == SIOCSHWTSTAMP)
832 return gfar_hwtstamp_ioctl(dev, rq, cmd);
833
779 if (!priv->phydev) 834 if (!priv->phydev)
780 return -ENODEV; 835 return -ENODEV;
781 836
@@ -978,7 +1033,8 @@ static int gfar_probe(struct of_device *ofdev,
978 else 1033 else
979 priv->padding = 0; 1034 priv->padding = 0;
980 1035
981 if (dev->features & NETIF_F_IP_CSUM) 1036 if (dev->features & NETIF_F_IP_CSUM ||
1037 priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER)
982 dev->hard_header_len += GMAC_FCB_LEN; 1038 dev->hard_header_len += GMAC_FCB_LEN;
983 1039
984 /* Program the isrg regs only if number of grps > 1 */ 1040 /* Program the isrg regs only if number of grps > 1 */
@@ -1922,23 +1978,29 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
1922 struct netdev_queue *txq; 1978 struct netdev_queue *txq;
1923 struct gfar __iomem *regs = NULL; 1979 struct gfar __iomem *regs = NULL;
1924 struct txfcb *fcb = NULL; 1980 struct txfcb *fcb = NULL;
1925 struct txbd8 *txbdp, *txbdp_start, *base; 1981 struct txbd8 *txbdp, *txbdp_start, *base, *txbdp_tstamp = NULL;
1926 u32 lstatus; 1982 u32 lstatus;
1927 int i, rq = 0; 1983 int i, rq = 0, do_tstamp = 0;
1928 u32 bufaddr; 1984 u32 bufaddr;
1929 unsigned long flags; 1985 unsigned long flags;
1930 unsigned int nr_frags, length; 1986 unsigned int nr_frags, nr_txbds, length;
1931 1987 union skb_shared_tx *shtx;
1932 1988
1933 rq = skb->queue_mapping; 1989 rq = skb->queue_mapping;
1934 tx_queue = priv->tx_queue[rq]; 1990 tx_queue = priv->tx_queue[rq];
1935 txq = netdev_get_tx_queue(dev, rq); 1991 txq = netdev_get_tx_queue(dev, rq);
1936 base = tx_queue->tx_bd_base; 1992 base = tx_queue->tx_bd_base;
1937 regs = tx_queue->grp->regs; 1993 regs = tx_queue->grp->regs;
1994 shtx = skb_tx(skb);
1995
1996 /* check if time stamp should be generated */
1997 if (unlikely(shtx->hardware && priv->hwts_tx_en))
1998 do_tstamp = 1;
1938 1999
1939 /* make space for additional header when fcb is needed */ 2000 /* make space for additional header when fcb is needed */
1940 if (((skb->ip_summed == CHECKSUM_PARTIAL) || 2001 if (((skb->ip_summed == CHECKSUM_PARTIAL) ||
1941 (priv->vlgrp && vlan_tx_tag_present(skb))) && 2002 (priv->vlgrp && vlan_tx_tag_present(skb)) ||
2003 unlikely(do_tstamp)) &&
1942 (skb_headroom(skb) < GMAC_FCB_LEN)) { 2004 (skb_headroom(skb) < GMAC_FCB_LEN)) {
1943 struct sk_buff *skb_new; 2005 struct sk_buff *skb_new;
1944 2006
@@ -1955,8 +2017,14 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
1955 /* total number of fragments in the SKB */ 2017 /* total number of fragments in the SKB */
1956 nr_frags = skb_shinfo(skb)->nr_frags; 2018 nr_frags = skb_shinfo(skb)->nr_frags;
1957 2019
2020 /* calculate the required number of TxBDs for this skb */
2021 if (unlikely(do_tstamp))
2022 nr_txbds = nr_frags + 2;
2023 else
2024 nr_txbds = nr_frags + 1;
2025
1958 /* check if there is space to queue this packet */ 2026 /* check if there is space to queue this packet */
1959 if ((nr_frags+1) > tx_queue->num_txbdfree) { 2027 if (nr_txbds > tx_queue->num_txbdfree) {
1960 /* no space, stop the queue */ 2028 /* no space, stop the queue */
1961 netif_tx_stop_queue(txq); 2029 netif_tx_stop_queue(txq);
1962 dev->stats.tx_fifo_errors++; 2030 dev->stats.tx_fifo_errors++;
@@ -1968,9 +2036,19 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
1968 txq->tx_packets ++; 2036 txq->tx_packets ++;
1969 2037
1970 txbdp = txbdp_start = tx_queue->cur_tx; 2038 txbdp = txbdp_start = tx_queue->cur_tx;
2039 lstatus = txbdp->lstatus;
2040
2041 /* Time stamp insertion requires one additional TxBD */
2042 if (unlikely(do_tstamp))
2043 txbdp_tstamp = txbdp = next_txbd(txbdp, base,
2044 tx_queue->tx_ring_size);
1971 2045
1972 if (nr_frags == 0) { 2046 if (nr_frags == 0) {
1973 lstatus = txbdp->lstatus | BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT); 2047 if (unlikely(do_tstamp))
2048 txbdp_tstamp->lstatus |= BD_LFLAG(TXBD_LAST |
2049 TXBD_INTERRUPT);
2050 else
2051 lstatus |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT);
1974 } else { 2052 } else {
1975 /* Place the fragment addresses and lengths into the TxBDs */ 2053 /* Place the fragment addresses and lengths into the TxBDs */
1976 for (i = 0; i < nr_frags; i++) { 2054 for (i = 0; i < nr_frags; i++) {
@@ -2016,11 +2094,32 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
2016 gfar_tx_vlan(skb, fcb); 2094 gfar_tx_vlan(skb, fcb);
2017 } 2095 }
2018 2096
2019 /* setup the TxBD length and buffer pointer for the first BD */ 2097 /* Setup tx hardware time stamping if requested */
2098 if (unlikely(do_tstamp)) {
2099 shtx->in_progress = 1;
2100 if (fcb == NULL)
2101 fcb = gfar_add_fcb(skb);
2102 fcb->ptp = 1;
2103 lstatus |= BD_LFLAG(TXBD_TOE);
2104 }
2105
2020 txbdp_start->bufPtr = dma_map_single(&priv->ofdev->dev, skb->data, 2106 txbdp_start->bufPtr = dma_map_single(&priv->ofdev->dev, skb->data,
2021 skb_headlen(skb), DMA_TO_DEVICE); 2107 skb_headlen(skb), DMA_TO_DEVICE);
2022 2108
2023 lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | skb_headlen(skb); 2109 /*
2110 * If time stamping is requested one additional TxBD must be set up. The
2111 * first TxBD points to the FCB and must have a data length of
2112 * GMAC_FCB_LEN. The second TxBD points to the actual frame data with
2113 * the full frame length.
2114 */
2115 if (unlikely(do_tstamp)) {
2116 txbdp_tstamp->bufPtr = txbdp_start->bufPtr + GMAC_FCB_LEN;
2117 txbdp_tstamp->lstatus |= BD_LFLAG(TXBD_READY) |
2118 (skb_headlen(skb) - GMAC_FCB_LEN);
2119 lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | GMAC_FCB_LEN;
2120 } else {
2121 lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | skb_headlen(skb);
2122 }
2024 2123
2025 /* 2124 /*
2026 * We can work in parallel with gfar_clean_tx_ring(), except 2125 * We can work in parallel with gfar_clean_tx_ring(), except
@@ -2060,7 +2159,7 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
2060 tx_queue->cur_tx = next_txbd(txbdp, base, tx_queue->tx_ring_size); 2159 tx_queue->cur_tx = next_txbd(txbdp, base, tx_queue->tx_ring_size);
2061 2160
2062 /* reduce TxBD free count */ 2161 /* reduce TxBD free count */
2063 tx_queue->num_txbdfree -= (nr_frags + 1); 2162 tx_queue->num_txbdfree -= (nr_txbds);
2064 2163
2065 dev->trans_start = jiffies; 2164 dev->trans_start = jiffies;
2066 2165
@@ -2251,16 +2350,18 @@ static int gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue)
2251 struct net_device *dev = tx_queue->dev; 2350 struct net_device *dev = tx_queue->dev;
2252 struct gfar_private *priv = netdev_priv(dev); 2351 struct gfar_private *priv = netdev_priv(dev);
2253 struct gfar_priv_rx_q *rx_queue = NULL; 2352 struct gfar_priv_rx_q *rx_queue = NULL;
2254 struct txbd8 *bdp; 2353 struct txbd8 *bdp, *next = NULL;
2255 struct txbd8 *lbdp = NULL; 2354 struct txbd8 *lbdp = NULL;
2256 struct txbd8 *base = tx_queue->tx_bd_base; 2355 struct txbd8 *base = tx_queue->tx_bd_base;
2257 struct sk_buff *skb; 2356 struct sk_buff *skb;
2258 int skb_dirtytx; 2357 int skb_dirtytx;
2259 int tx_ring_size = tx_queue->tx_ring_size; 2358 int tx_ring_size = tx_queue->tx_ring_size;
2260 int frags = 0; 2359 int frags = 0, nr_txbds = 0;
2261 int i; 2360 int i;
2262 int howmany = 0; 2361 int howmany = 0;
2263 u32 lstatus; 2362 u32 lstatus;
2363 size_t buflen;
2364 union skb_shared_tx *shtx;
2264 2365
2265 rx_queue = priv->rx_queue[tx_queue->qindex]; 2366 rx_queue = priv->rx_queue[tx_queue->qindex];
2266 bdp = tx_queue->dirty_tx; 2367 bdp = tx_queue->dirty_tx;
@@ -2270,7 +2371,18 @@ static int gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue)
2270 unsigned long flags; 2371 unsigned long flags;
2271 2372
2272 frags = skb_shinfo(skb)->nr_frags; 2373 frags = skb_shinfo(skb)->nr_frags;
2273 lbdp = skip_txbd(bdp, frags, base, tx_ring_size); 2374
2375 /*
2376 * When time stamping, one additional TxBD must be freed.
2377 * Also, we need to dma_unmap_single() the TxPAL.
2378 */
2379 shtx = skb_tx(skb);
2380 if (unlikely(shtx->in_progress))
2381 nr_txbds = frags + 2;
2382 else
2383 nr_txbds = frags + 1;
2384
2385 lbdp = skip_txbd(bdp, nr_txbds - 1, base, tx_ring_size);
2274 2386
2275 lstatus = lbdp->lstatus; 2387 lstatus = lbdp->lstatus;
2276 2388
@@ -2279,10 +2391,24 @@ static int gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue)
2279 (lstatus & BD_LENGTH_MASK)) 2391 (lstatus & BD_LENGTH_MASK))
2280 break; 2392 break;
2281 2393
2282 dma_unmap_single(&priv->ofdev->dev, 2394 if (unlikely(shtx->in_progress)) {
2283 bdp->bufPtr, 2395 next = next_txbd(bdp, base, tx_ring_size);
2284 bdp->length, 2396 buflen = next->length + GMAC_FCB_LEN;
2285 DMA_TO_DEVICE); 2397 } else
2398 buflen = bdp->length;
2399
2400 dma_unmap_single(&priv->ofdev->dev, bdp->bufPtr,
2401 buflen, DMA_TO_DEVICE);
2402
2403 if (unlikely(shtx->in_progress)) {
2404 struct skb_shared_hwtstamps shhwtstamps;
2405 u64 *ns = (u64*) (((u32)skb->data + 0x10) & ~0x7);
2406 memset(&shhwtstamps, 0, sizeof(shhwtstamps));
2407 shhwtstamps.hwtstamp = ns_to_ktime(*ns);
2408 skb_tstamp_tx(skb, &shhwtstamps);
2409 bdp->lstatus &= BD_LFLAG(TXBD_WRAP);
2410 bdp = next;
2411 }
2286 2412
2287 bdp->lstatus &= BD_LFLAG(TXBD_WRAP); 2413 bdp->lstatus &= BD_LFLAG(TXBD_WRAP);
2288 bdp = next_txbd(bdp, base, tx_ring_size); 2414 bdp = next_txbd(bdp, base, tx_ring_size);
@@ -2314,7 +2440,7 @@ static int gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue)
2314 2440
2315 howmany++; 2441 howmany++;
2316 spin_lock_irqsave(&tx_queue->txlock, flags); 2442 spin_lock_irqsave(&tx_queue->txlock, flags);
2317 tx_queue->num_txbdfree += frags + 1; 2443 tx_queue->num_txbdfree += nr_txbds;
2318 spin_unlock_irqrestore(&tx_queue->txlock, flags); 2444 spin_unlock_irqrestore(&tx_queue->txlock, flags);
2319 } 2445 }
2320 2446
@@ -2470,6 +2596,17 @@ static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb,
2470 skb_pull(skb, amount_pull); 2596 skb_pull(skb, amount_pull);
2471 } 2597 }
2472 2598
2599 /* Get receive timestamp from the skb */
2600 if (priv->hwts_rx_en) {
2601 struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb);
2602 u64 *ns = (u64 *) skb->data;
2603 memset(shhwtstamps, 0, sizeof(*shhwtstamps));
2604 shhwtstamps->hwtstamp = ns_to_ktime(*ns);
2605 }
2606
2607 if (priv->padding)
2608 skb_pull(skb, priv->padding);
2609
2473 if (priv->rx_csum_enable) 2610 if (priv->rx_csum_enable)
2474 gfar_rx_checksum(skb, fcb); 2611 gfar_rx_checksum(skb, fcb);
2475 2612
@@ -2506,8 +2643,7 @@ int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, int rx_work_limit)
2506 bdp = rx_queue->cur_rx; 2643 bdp = rx_queue->cur_rx;
2507 base = rx_queue->rx_bd_base; 2644 base = rx_queue->rx_bd_base;
2508 2645
2509 amount_pull = (gfar_uses_fcb(priv) ? GMAC_FCB_LEN : 0) + 2646 amount_pull = (gfar_uses_fcb(priv) ? GMAC_FCB_LEN : 0);
2510 priv->padding;
2511 2647
2512 while (!((bdp->status & RXBD_EMPTY) || (--rx_work_limit < 0))) { 2648 while (!((bdp->status & RXBD_EMPTY) || (--rx_work_limit < 0))) {
2513 struct sk_buff *newskb; 2649 struct sk_buff *newskb;
@@ -2794,7 +2930,7 @@ static void adjust_link(struct net_device *dev)
2794 * whenever dev->flags is changed */ 2930 * whenever dev->flags is changed */
2795static void gfar_set_multi(struct net_device *dev) 2931static void gfar_set_multi(struct net_device *dev)
2796{ 2932{
2797 struct dev_mc_list *mc_ptr; 2933 struct netdev_hw_addr *ha;
2798 struct gfar_private *priv = netdev_priv(dev); 2934 struct gfar_private *priv = netdev_priv(dev);
2799 struct gfar __iomem *regs = priv->gfargrp[0].regs; 2935 struct gfar __iomem *regs = priv->gfargrp[0].regs;
2800 u32 tempval; 2936 u32 tempval;
@@ -2867,13 +3003,12 @@ static void gfar_set_multi(struct net_device *dev)
2867 return; 3003 return;
2868 3004
2869 /* Parse the list, and set the appropriate bits */ 3005 /* Parse the list, and set the appropriate bits */
2870 netdev_for_each_mc_addr(mc_ptr, dev) { 3006 netdev_for_each_mc_addr(ha, dev) {
2871 if (idx < em_num) { 3007 if (idx < em_num) {
2872 gfar_set_mac_for_addr(dev, idx, 3008 gfar_set_mac_for_addr(dev, idx, ha->addr);
2873 mc_ptr->dmi_addr);
2874 idx++; 3009 idx++;
2875 } else 3010 } else
2876 gfar_set_hash_for_addr(dev, mc_ptr->dmi_addr); 3011 gfar_set_hash_for_addr(dev, ha->addr);
2877 } 3012 }
2878 } 3013 }
2879 3014