Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'gianfar'

Claudiu Manoil says:

====================
gianfar: Device configuration fixes

This patchset represents the first part of an effort
to solve some old device configuration issues in gianfar,
especially run-time reset and re-configuration problems.
I'm referring to "on-the-fly" configuration of registers
against HW specification, concurrency issues during device
reset / re-configuration operations, and implementing HW
advisories for these operations.

There's also a good deal of code cleanup and refactoring,
and some other (minor) fixes as well.

v2: Remove sysfs stubs w/o replacing them with module
params (patch 2).
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+281 -706
-30
Documentation/networking/gianfar.txt
··· 1 1 The Gianfar Ethernet Driver 2 - Sysfs File description 3 2 4 3 Author: Andy Fleming <afleming@freescale.com> 5 4 Updated: 2005-07-28 6 5 7 - SYSFS 8 - 9 - Several of the features of the gianfar driver are controlled 10 - through sysfs files. These are: 11 - 12 - bd_stash: 13 - To stash RX Buffer Descriptors in the L2, echo 'on' or '1' to 14 - bd_stash, echo 'off' or '0' to disable 15 - 16 - rx_stash_len: 17 - To stash the first n bytes of the packet in L2, echo the number 18 - of bytes to buf_stash_len. echo 0 to disable. 19 - 20 - WARNING: You could really screw these up if you set them too low or high! 21 - fifo_threshold: 22 - To change the number of bytes the controller needs in the 23 - fifo before it starts transmission, echo the number of bytes to 24 - fifo_thresh. Range should be 0-511. 25 - 26 - fifo_starve: 27 - When the FIFO has less than this many bytes during a transmit, it 28 - enters starve mode, and increases the priority of TX memory 29 - transactions. To change, echo the number of bytes to 30 - fifo_starve. Range should be 0-511. 31 - 32 - fifo_starve_off: 33 - Once in starve mode, the FIFO remains there until it has this 34 - many bytes. To change, echo the number of bytes to 35 - fifo_starve_off. Range should be 0-511. 36 6 37 7 CHECKSUM OFFLOADING 38 8
+1 -2
drivers/net/ethernet/freescale/Makefile
··· 14 14 obj-$(CONFIG_GIANFAR) += gianfar_driver.o 15 15 obj-$(CONFIG_PTP_1588_CLOCK_GIANFAR) += gianfar_ptp.o 16 16 gianfar_driver-objs := gianfar.o \ 17 - gianfar_ethtool.o \ 18 - gianfar_sysfs.o 17 + gianfar_ethtool.o 19 18 obj-$(CONFIG_UCC_GETH) += ucc_geth_driver.o 20 19 ucc_geth_driver-objs := ucc_geth.o ucc_geth_ethtool.o
+239 -267
drivers/net/ethernet/freescale/gianfar.c
··· 9 9 * Maintainer: Kumar Gala 10 10 * Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com> 11 11 * 12 - * Copyright 2002-2009, 2011 Freescale Semiconductor, Inc. 12 + * Copyright 2002-2009, 2011-2013 Freescale Semiconductor, Inc. 13 13 * Copyright 2007 MontaVista Software, Inc. 14 14 * 15 15 * This program is free software; you can redistribute it and/or modify it ··· 138 138 static void gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue); 139 139 static void gfar_process_frame(struct net_device *dev, struct sk_buff *skb, 140 140 int amount_pull, struct napi_struct *napi); 141 - void gfar_halt(struct net_device *dev); 142 - static void gfar_halt_nodisable(struct net_device *dev); 143 - void gfar_start(struct net_device *dev); 141 + static void gfar_halt_nodisable(struct gfar_private *priv); 144 142 static void gfar_clear_exact_match(struct net_device *dev); 145 143 static void gfar_set_mac_for_addr(struct net_device *dev, int num, 146 144 const u8 *addr); ··· 336 338 struct gfar __iomem *regs = priv->gfargrp[0].regs; 337 339 u32 rctrl = 0; 338 340 u32 tctrl = 0; 339 - u32 attrs = 0; 340 341 341 342 /* write the tx/rx base registers */ 342 343 gfar_init_tx_rx_base(priv); ··· 373 376 rctrl |= RCTRL_PADDING(priv->padding); 374 377 } 375 378 376 - /* Insert receive time stamps into padding alignment bytes */ 377 - if (priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER) { 378 - rctrl &= ~RCTRL_PAL_MASK; 379 - rctrl |= RCTRL_PADDING(8); 380 - priv->padding = 8; 381 - } 382 - 383 379 /* Enable HW time stamping if requested from user space */ 384 380 if (priv->hwts_rx_en) { 385 381 rctrl |= RCTRL_PRSDEP_INIT | RCTRL_TS_ENABLE; ··· 399 409 } 400 410 401 411 gfar_write(&regs->tctrl, tctrl); 402 - 403 - /* Set the extraction length and index */ 404 - attrs = ATTRELI_EL(priv->rx_stash_size) | 405 - ATTRELI_EI(priv->rx_stash_index); 406 - 407 - gfar_write(&regs->attreli, attrs); 408 - 409 - /* Start with defaults, and add stashing or locking 410 - * depending on the approprate variables 411 - */ 412 - attrs = ATTR_INIT_SETTINGS; 413 - 414 - if (priv->bd_stash_en) 415 - attrs |= ATTR_BDSTASH; 416 - 417 - if (priv->rx_stash_size != 0) 418 - attrs |= ATTR_BUFSTASH; 419 - 420 - gfar_write(&regs->attr, attrs); 421 - 422 - gfar_write(&regs->fifo_tx_thr, priv->fifo_threshold); 423 - gfar_write(&regs->fifo_tx_starve, priv->fifo_starve); 424 - gfar_write(&regs->fifo_tx_starve_shutoff, priv->fifo_starve_off); 425 412 } 426 413 427 414 static struct net_device_stats *gfar_get_stats(struct net_device *dev) ··· 446 479 #endif 447 480 }; 448 481 482 + static void gfar_ints_disable(struct gfar_private *priv) 483 + { 484 + int i; 485 + for (i = 0; i < priv->num_grps; i++) { 486 + struct gfar __iomem *regs = priv->gfargrp[i].regs; 487 + /* Clear IEVENT */ 488 + gfar_write(&regs->ievent, IEVENT_INIT_CLEAR); 489 + 490 + /* Initialize IMASK */ 491 + gfar_write(&regs->imask, IMASK_INIT_CLEAR); 492 + } 493 + } 494 + 495 + static void gfar_ints_enable(struct gfar_private *priv) 496 + { 497 + int i; 498 + for (i = 0; i < priv->num_grps; i++) { 499 + struct gfar __iomem *regs = priv->gfargrp[i].regs; 500 + /* Unmask the interrupts we look for */ 501 + gfar_write(&regs->imask, IMASK_DEFAULT); 502 + } 503 + } 504 + 449 505 void lock_rx_qs(struct gfar_private *priv) 450 506 { 451 507 int i; ··· 501 511 spin_unlock(&priv->tx_queue[i]->txlock); 502 512 } 503 513 504 - static void free_tx_pointers(struct gfar_private *priv) 514 + static int gfar_alloc_tx_queues(struct gfar_private *priv) 515 + { 516 + int i; 517 + 518 + for (i = 0; i < priv->num_tx_queues; i++) { 519 + priv->tx_queue[i] = kzalloc(sizeof(struct gfar_priv_tx_q), 520 + GFP_KERNEL); 521 + if (!priv->tx_queue[i]) 522 + return -ENOMEM; 523 + 524 + priv->tx_queue[i]->tx_skbuff = NULL; 525 + priv->tx_queue[i]->qindex = i; 526 + priv->tx_queue[i]->dev = priv->ndev; 527 + spin_lock_init(&(priv->tx_queue[i]->txlock)); 528 + } 529 + return 0; 530 + } 531 + 532 + static int gfar_alloc_rx_queues(struct gfar_private *priv) 533 + { 534 + int i; 535 + 536 + for (i = 0; i < priv->num_rx_queues; i++) { 537 + priv->rx_queue[i] = kzalloc(sizeof(struct gfar_priv_rx_q), 538 + GFP_KERNEL); 539 + if (!priv->rx_queue[i]) 540 + return -ENOMEM; 541 + 542 + priv->rx_queue[i]->rx_skbuff = NULL; 543 + priv->rx_queue[i]->qindex = i; 544 + priv->rx_queue[i]->dev = priv->ndev; 545 + spin_lock_init(&(priv->rx_queue[i]->rxlock)); 546 + } 547 + return 0; 548 + } 549 + 550 + static void gfar_free_tx_queues(struct gfar_private *priv) 505 551 { 506 552 int i; 507 553 ··· 545 519 kfree(priv->tx_queue[i]); 546 520 } 547 521 548 - static void free_rx_pointers(struct gfar_private *priv) 522 + static void gfar_free_rx_queues(struct gfar_private *priv) 549 523 { 550 524 int i; 551 525 ··· 634 608 grp->rx_bit_map = 0xFF; 635 609 grp->tx_bit_map = 0xFF; 636 610 } 611 + 612 + /* bit_map's MSB is q0 (from q0 to q7) but, for_each_set_bit parses 613 + * right to left, so we need to revert the 8 bits to get the q index 614 + */ 615 + grp->rx_bit_map = bitrev8(grp->rx_bit_map); 616 + grp->tx_bit_map = bitrev8(grp->tx_bit_map); 617 + 618 + /* Calculate RSTAT, TSTAT, RQUEUE and TQUEUE values, 619 + * also assign queues to groups 620 + */ 621 + for_each_set_bit(i, &grp->rx_bit_map, priv->num_rx_queues) { 622 + grp->num_rx_queues++; 623 + grp->rstat |= (RSTAT_CLEAR_RHALT >> i); 624 + priv->rqueue |= ((RQUEUE_EN0 | RQUEUE_EX0) >> i); 625 + priv->rx_queue[i]->grp = grp; 626 + } 627 + 628 + for_each_set_bit(i, &grp->tx_bit_map, priv->num_tx_queues) { 629 + grp->num_tx_queues++; 630 + grp->tstat |= (TSTAT_CLEAR_THALT >> i); 631 + priv->tqueue |= (TQUEUE_EN0 >> i); 632 + priv->tx_queue[i]->grp = grp; 633 + } 634 + 637 635 priv->num_grps++; 638 636 639 637 return 0; ··· 714 664 priv->num_tx_queues = num_tx_qs; 715 665 netif_set_real_num_rx_queues(dev, num_rx_qs); 716 666 priv->num_rx_queues = num_rx_qs; 717 - priv->num_grps = 0x0; 667 + 668 + err = gfar_alloc_tx_queues(priv); 669 + if (err) 670 + goto tx_alloc_failed; 671 + 672 + err = gfar_alloc_rx_queues(priv); 673 + if (err) 674 + goto rx_alloc_failed; 718 675 719 676 /* Init Rx queue filer rule set linked list */ 720 677 INIT_LIST_HEAD(&priv->rx_list.list); ··· 747 690 if (err) 748 691 goto err_grp_init; 749 692 } 750 - 751 - for (i = 0; i < priv->num_tx_queues; i++) 752 - priv->tx_queue[i] = NULL; 753 - for (i = 0; i < priv->num_rx_queues; i++) 754 - priv->rx_queue[i] = NULL; 755 - 756 - for (i = 0; i < priv->num_tx_queues; i++) { 757 - priv->tx_queue[i] = kzalloc(sizeof(struct gfar_priv_tx_q), 758 - GFP_KERNEL); 759 - if (!priv->tx_queue[i]) { 760 - err = -ENOMEM; 761 - goto tx_alloc_failed; 762 - } 763 - priv->tx_queue[i]->tx_skbuff = NULL; 764 - priv->tx_queue[i]->qindex = i; 765 - priv->tx_queue[i]->dev = dev; 766 - spin_lock_init(&(priv->tx_queue[i]->txlock)); 767 - } 768 - 769 - for (i = 0; i < priv->num_rx_queues; i++) { 770 - priv->rx_queue[i] = kzalloc(sizeof(struct gfar_priv_rx_q), 771 - GFP_KERNEL); 772 - if (!priv->rx_queue[i]) { 773 - err = -ENOMEM; 774 - goto rx_alloc_failed; 775 - } 776 - priv->rx_queue[i]->rx_skbuff = NULL; 777 - priv->rx_queue[i]->qindex = i; 778 - priv->rx_queue[i]->dev = dev; 779 - spin_lock_init(&(priv->rx_queue[i]->rxlock)); 780 - } 781 - 782 693 783 694 stash = of_get_property(np, "bd-stash", NULL); 784 695 ··· 774 749 memcpy(dev->dev_addr, mac_addr, ETH_ALEN); 775 750 776 751 if (model && !strcasecmp(model, "TSEC")) 777 - priv->device_flags = FSL_GIANFAR_DEV_HAS_GIGABIT | 752 + priv->device_flags |= FSL_GIANFAR_DEV_HAS_GIGABIT | 778 753 FSL_GIANFAR_DEV_HAS_COALESCE | 779 754 FSL_GIANFAR_DEV_HAS_RMON | 780 755 FSL_GIANFAR_DEV_HAS_MULTI_INTR; 781 756 782 757 if (model && !strcasecmp(model, "eTSEC")) 783 - priv->device_flags = FSL_GIANFAR_DEV_HAS_GIGABIT | 758 + priv->device_flags |= FSL_GIANFAR_DEV_HAS_GIGABIT | 784 759 FSL_GIANFAR_DEV_HAS_COALESCE | 785 760 FSL_GIANFAR_DEV_HAS_RMON | 786 761 FSL_GIANFAR_DEV_HAS_MULTI_INTR | 787 - FSL_GIANFAR_DEV_HAS_PADDING | 788 762 FSL_GIANFAR_DEV_HAS_CSUM | 789 763 FSL_GIANFAR_DEV_HAS_VLAN | 790 764 FSL_GIANFAR_DEV_HAS_MAGIC_PACKET | ··· 808 784 809 785 return 0; 810 786 811 - rx_alloc_failed: 812 - free_rx_pointers(priv); 813 - tx_alloc_failed: 814 - free_tx_pointers(priv); 815 787 err_grp_init: 816 788 unmap_group_regs(priv); 789 + rx_alloc_failed: 790 + gfar_free_rx_queues(priv); 791 + tx_alloc_failed: 792 + gfar_free_tx_queues(priv); 817 793 free_gfar_dev(priv); 818 794 return err; 819 795 } ··· 897 873 return -ENODEV; 898 874 899 875 return phy_mii_ioctl(priv->phydev, rq, cmd); 900 - } 901 - 902 - static unsigned int reverse_bitmap(unsigned int bit_map, unsigned int max_qs) 903 - { 904 - unsigned int new_bit_map = 0x0; 905 - int mask = 0x1 << (max_qs - 1), i; 906 - 907 - for (i = 0; i < max_qs; i++) { 908 - if (bit_map & mask) 909 - new_bit_map = new_bit_map + (1 << i); 910 - mask = mask >> 0x1; 911 - } 912 - return new_bit_map; 913 876 } 914 877 915 878 static u32 cluster_entry_per_class(struct gfar_private *priv, u32 rqfar, ··· 1016 1005 priv->errata); 1017 1006 } 1018 1007 1019 - /* Set up the ethernet device structure, private data, 1020 - * and anything else we need before we start 1021 - */ 1022 - static int gfar_probe(struct platform_device *ofdev) 1008 + static void gfar_hw_init(struct gfar_private *priv) 1023 1009 { 1024 - u32 tempval; 1025 - struct net_device *dev = NULL; 1026 - struct gfar_private *priv = NULL; 1027 - struct gfar __iomem *regs = NULL; 1028 - int err = 0, i, grp_idx = 0; 1029 - u32 rstat = 0, tstat = 0, rqueue = 0, tqueue = 0; 1030 - u32 isrg = 0; 1031 - u32 __iomem *baddr; 1032 - 1033 - err = gfar_of_init(ofdev, &dev); 1034 - 1035 - if (err) 1036 - return err; 1037 - 1038 - priv = netdev_priv(dev); 1039 - priv->ndev = dev; 1040 - priv->ofdev = ofdev; 1041 - priv->dev = &ofdev->dev; 1042 - SET_NETDEV_DEV(dev, &ofdev->dev); 1043 - 1044 - spin_lock_init(&priv->bflock); 1045 - INIT_WORK(&priv->reset_task, gfar_reset_task); 1046 - 1047 - platform_set_drvdata(ofdev, priv); 1048 - regs = priv->gfargrp[0].regs; 1049 - 1050 - gfar_detect_errata(priv); 1051 - 1052 - /* Stop the DMA engine now, in case it was running before 1053 - * (The firmware could have used it, and left it running). 1054 - */ 1055 - gfar_halt(dev); 1010 + struct gfar __iomem *regs = priv->gfargrp[0].regs; 1011 + u32 tempval, attrs; 1056 1012 1057 1013 /* Reset MAC layer */ 1058 1014 gfar_write(&regs->maccfg1, MACCFG1_SOFT_RESET); ··· 1027 1049 /* We need to delay at least 3 TX clocks */ 1028 1050 udelay(2); 1029 1051 1030 - tempval = 0; 1031 - if (!priv->pause_aneg_en && priv->tx_pause_en) 1032 - tempval |= MACCFG1_TX_FLOW; 1033 - if (!priv->pause_aneg_en && priv->rx_pause_en) 1034 - tempval |= MACCFG1_RX_FLOW; 1035 1052 /* the soft reset bit is not self-resetting, so we need to 1036 1053 * clear it before resuming normal operation 1037 1054 */ 1038 - gfar_write(&regs->maccfg1, tempval); 1055 + gfar_write(&regs->maccfg1, 0); 1039 1056 1040 1057 /* Initialize MACCFG2. */ 1041 1058 tempval = MACCFG2_INIT_SETTINGS; ··· 1041 1068 /* Initialize ECNTRL */ 1042 1069 gfar_write(&regs->ecntrl, ECNTRL_INIT_SETTINGS); 1043 1070 1044 - /* Set the dev->base_addr to the gfar reg region */ 1045 - dev->base_addr = (unsigned long) regs; 1071 + /* Set the extraction length and index */ 1072 + attrs = ATTRELI_EL(priv->rx_stash_size) | 1073 + ATTRELI_EI(priv->rx_stash_index); 1046 1074 1047 - /* Fill in the dev structure */ 1048 - dev->watchdog_timeo = TX_TIMEOUT; 1049 - dev->mtu = 1500; 1050 - dev->netdev_ops = &gfar_netdev_ops; 1051 - dev->ethtool_ops = &gfar_ethtool_ops; 1075 + gfar_write(&regs->attreli, attrs); 1052 1076 1053 - /* Register for napi ...We are registering NAPI for each grp */ 1054 - if (priv->mode == SQ_SG_MODE) 1055 - netif_napi_add(dev, &priv->gfargrp[0].napi, gfar_poll_sq, 1056 - GFAR_DEV_WEIGHT); 1057 - else 1058 - for (i = 0; i < priv->num_grps; i++) 1059 - netif_napi_add(dev, &priv->gfargrp[i].napi, gfar_poll, 1060 - GFAR_DEV_WEIGHT); 1077 + /* Start with defaults, and add stashing 1078 + * depending on driver parameters 1079 + */ 1080 + attrs = ATTR_INIT_SETTINGS; 1061 1081 1062 - if (priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM) { 1063 - dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG | 1064 - NETIF_F_RXCSUM; 1065 - dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG | 1066 - NETIF_F_RXCSUM | NETIF_F_HIGHDMA; 1067 - } 1082 + if (priv->bd_stash_en) 1083 + attrs |= ATTR_BDSTASH; 1068 1084 1069 - if (priv->device_flags & FSL_GIANFAR_DEV_HAS_VLAN) { 1070 - dev->hw_features |= NETIF_F_HW_VLAN_CTAG_TX | 1071 - NETIF_F_HW_VLAN_CTAG_RX; 1072 - dev->features |= NETIF_F_HW_VLAN_CTAG_RX; 1073 - } 1085 + if (priv->rx_stash_size != 0) 1086 + attrs |= ATTR_BUFSTASH; 1087 + 1088 + gfar_write(&regs->attr, attrs); 1089 + 1090 + /* FIFO configs */ 1091 + gfar_write(&regs->fifo_tx_thr, DEFAULT_FIFO_TX_THR); 1092 + gfar_write(&regs->fifo_tx_starve, DEFAULT_FIFO_TX_STARVE); 1093 + gfar_write(&regs->fifo_tx_starve_shutoff, DEFAULT_FIFO_TX_STARVE_OFF); 1094 + 1095 + /* Program the interrupt steering regs, only for MG devices */ 1096 + if (priv->num_grps > 1) 1097 + gfar_write_isrg(priv); 1098 + } 1099 + 1100 + static void __init gfar_init_addr_hash_table(struct gfar_private *priv) 1101 + { 1102 + struct gfar __iomem *regs = priv->gfargrp[0].regs; 1074 1103 1075 1104 if (priv->device_flags & FSL_GIANFAR_DEV_HAS_EXTENDED_HASH) { 1076 1105 priv->extended_hash = 1; ··· 1108 1133 priv->hash_regs[6] = &regs->gaddr6; 1109 1134 priv->hash_regs[7] = &regs->gaddr7; 1110 1135 } 1136 + } 1111 1137 1112 - if (priv->device_flags & FSL_GIANFAR_DEV_HAS_PADDING) 1113 - priv->padding = DEFAULT_PADDING; 1138 + /* Set up the ethernet device structure, private data, 1139 + * and anything else we need before we start 1140 + */ 1141 + static int gfar_probe(struct platform_device *ofdev) 1142 + { 1143 + struct net_device *dev = NULL; 1144 + struct gfar_private *priv = NULL; 1145 + int err = 0, i; 1146 + 1147 + err = gfar_of_init(ofdev, &dev); 1148 + 1149 + if (err) 1150 + return err; 1151 + 1152 + priv = netdev_priv(dev); 1153 + priv->ndev = dev; 1154 + priv->ofdev = ofdev; 1155 + priv->dev = &ofdev->dev; 1156 + SET_NETDEV_DEV(dev, &ofdev->dev); 1157 + 1158 + spin_lock_init(&priv->bflock); 1159 + INIT_WORK(&priv->reset_task, gfar_reset_task); 1160 + 1161 + platform_set_drvdata(ofdev, priv); 1162 + 1163 + gfar_detect_errata(priv); 1164 + 1165 + /* Stop the DMA engine now, in case it was running before 1166 + * (The firmware could have used it, and left it running). 1167 + */ 1168 + gfar_halt(priv); 1169 + 1170 + gfar_hw_init(priv); 1171 + 1172 + /* Set the dev->base_addr to the gfar reg region */ 1173 + dev->base_addr = (unsigned long) priv->gfargrp[0].regs; 1174 + 1175 + /* Fill in the dev structure */ 1176 + dev->watchdog_timeo = TX_TIMEOUT; 1177 + dev->mtu = 1500; 1178 + dev->netdev_ops = &gfar_netdev_ops; 1179 + dev->ethtool_ops = &gfar_ethtool_ops; 1180 + 1181 + /* Register for napi ...We are registering NAPI for each grp */ 1182 + if (priv->mode == SQ_SG_MODE) 1183 + netif_napi_add(dev, &priv->gfargrp[0].napi, gfar_poll_sq, 1184 + GFAR_DEV_WEIGHT); 1114 1185 else 1115 - priv->padding = 0; 1186 + for (i = 0; i < priv->num_grps; i++) 1187 + netif_napi_add(dev, &priv->gfargrp[i].napi, gfar_poll, 1188 + GFAR_DEV_WEIGHT); 1189 + 1190 + if (priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM) { 1191 + dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG | 1192 + NETIF_F_RXCSUM; 1193 + dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG | 1194 + NETIF_F_RXCSUM | NETIF_F_HIGHDMA; 1195 + } 1196 + 1197 + if (priv->device_flags & FSL_GIANFAR_DEV_HAS_VLAN) { 1198 + dev->hw_features |= NETIF_F_HW_VLAN_CTAG_TX | 1199 + NETIF_F_HW_VLAN_CTAG_RX; 1200 + dev->features |= NETIF_F_HW_VLAN_CTAG_RX; 1201 + } 1202 + 1203 + gfar_init_addr_hash_table(priv); 1204 + 1205 + /* Insert receive time stamps into padding alignment bytes */ 1206 + if (priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER) 1207 + priv->padding = 8; 1116 1208 1117 1209 if (dev->features & NETIF_F_IP_CSUM || 1118 1210 priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER) 1119 1211 dev->needed_headroom = GMAC_FCB_LEN; 1120 - 1121 - /* Program the isrg regs only if number of grps > 1 */ 1122 - if (priv->num_grps > 1) { 1123 - baddr = &regs->isrg0; 1124 - for (i = 0; i < priv->num_grps; i++) { 1125 - isrg |= (priv->gfargrp[i].rx_bit_map << ISRG_SHIFT_RX); 1126 - isrg |= (priv->gfargrp[i].tx_bit_map << ISRG_SHIFT_TX); 1127 - gfar_write(baddr, isrg); 1128 - baddr++; 1129 - isrg = 0x0; 1130 - } 1131 - } 1132 - 1133 - /* Need to reverse the bit maps as bit_map's MSB is q0 1134 - * but, for_each_set_bit parses from right to left, which 1135 - * basically reverses the queue numbers 1136 - */ 1137 - for (i = 0; i< priv->num_grps; i++) { 1138 - priv->gfargrp[i].tx_bit_map = 1139 - reverse_bitmap(priv->gfargrp[i].tx_bit_map, MAX_TX_QS); 1140 - priv->gfargrp[i].rx_bit_map = 1141 - reverse_bitmap(priv->gfargrp[i].rx_bit_map, MAX_RX_QS); 1142 - } 1143 - 1144 - /* Calculate RSTAT, TSTAT, RQUEUE and TQUEUE values, 1145 - * also assign queues to groups 1146 - */ 1147 - for (grp_idx = 0; grp_idx < priv->num_grps; grp_idx++) { 1148 - priv->gfargrp[grp_idx].num_rx_queues = 0x0; 1149 - 1150 - for_each_set_bit(i, &priv->gfargrp[grp_idx].rx_bit_map, 1151 - priv->num_rx_queues) { 1152 - priv->gfargrp[grp_idx].num_rx_queues++; 1153 - priv->rx_queue[i]->grp = &priv->gfargrp[grp_idx]; 1154 - rstat = rstat | (RSTAT_CLEAR_RHALT >> i); 1155 - rqueue = rqueue | ((RQUEUE_EN0 | RQUEUE_EX0) >> i); 1156 - } 1157 - priv->gfargrp[grp_idx].num_tx_queues = 0x0; 1158 - 1159 - for_each_set_bit(i, &priv->gfargrp[grp_idx].tx_bit_map, 1160 - priv->num_tx_queues) { 1161 - priv->gfargrp[grp_idx].num_tx_queues++; 1162 - priv->tx_queue[i]->grp = &priv->gfargrp[grp_idx]; 1163 - tstat = tstat | (TSTAT_CLEAR_THALT >> i); 1164 - tqueue = tqueue | (TQUEUE_EN0 >> i); 1165 - } 1166 - priv->gfargrp[grp_idx].rstat = rstat; 1167 - priv->gfargrp[grp_idx].tstat = tstat; 1168 - rstat = tstat =0; 1169 - } 1170 - 1171 - gfar_write(&regs->rqueue, rqueue); 1172 - gfar_write(&regs->tqueue, tqueue); 1173 1212 1174 1213 priv->rx_buffer_size = DEFAULT_RX_BUFFER_SIZE; 1175 1214 ··· 1240 1251 /* Initialize the filer table */ 1241 1252 gfar_init_filer_table(priv); 1242 1253 1243 - /* Create all the sysfs files */ 1244 - gfar_init_sysfs(dev); 1245 - 1246 1254 /* Print out the device info */ 1247 1255 netdev_info(dev, "mac: %pM\n", dev->dev_addr); 1248 1256 ··· 1258 1272 1259 1273 register_fail: 1260 1274 unmap_group_regs(priv); 1261 - free_tx_pointers(priv); 1262 - free_rx_pointers(priv); 1275 + gfar_free_rx_queues(priv); 1276 + gfar_free_tx_queues(priv); 1263 1277 if (priv->phy_node) 1264 1278 of_node_put(priv->phy_node); 1265 1279 if (priv->tbi_node) ··· 1279 1293 1280 1294 unregister_netdev(priv->ndev); 1281 1295 unmap_group_regs(priv); 1296 + gfar_free_rx_queues(priv); 1297 + gfar_free_tx_queues(priv); 1282 1298 free_gfar_dev(priv); 1283 1299 1284 1300 return 0; ··· 1308 1320 lock_tx_qs(priv); 1309 1321 lock_rx_qs(priv); 1310 1322 1311 - gfar_halt_nodisable(ndev); 1323 + gfar_halt_nodisable(priv); 1312 1324 1313 1325 /* Disable Tx, and Rx if wake-on-LAN is disabled. */ 1314 1326 tempval = gfar_read(&regs->maccfg1); ··· 1372 1384 tempval &= ~MACCFG2_MPEN; 1373 1385 gfar_write(&regs->maccfg2, tempval); 1374 1386 1375 - gfar_start(ndev); 1387 + gfar_start(priv); 1376 1388 1377 1389 unlock_rx_qs(priv); 1378 1390 unlock_tx_qs(priv); ··· 1404 1416 init_registers(ndev); 1405 1417 gfar_set_mac_address(ndev); 1406 1418 gfar_init_mac(ndev); 1407 - gfar_start(ndev); 1419 + gfar_start(priv); 1408 1420 1409 1421 priv->oldlink = 0; 1410 1422 priv->oldspeed = 0; ··· 1565 1577 static void init_registers(struct net_device *dev) 1566 1578 { 1567 1579 struct gfar_private *priv = netdev_priv(dev); 1568 - struct gfar __iomem *regs = NULL; 1569 - int i; 1580 + struct gfar __iomem *regs = priv->gfargrp[0].regs; 1570 1581 1571 - for (i = 0; i < priv->num_grps; i++) { 1572 - regs = priv->gfargrp[i].regs; 1573 - /* Clear IEVENT */ 1574 - gfar_write(&regs->ievent, IEVENT_INIT_CLEAR); 1582 + gfar_ints_disable(priv); 1575 1583 1576 - /* Initialize IMASK */ 1577 - gfar_write(&regs->imask, IMASK_INIT_CLEAR); 1578 - } 1579 - 1580 - regs = priv->gfargrp[0].regs; 1581 1584 /* Init hash registers to zero */ 1582 1585 gfar_write(&regs->igaddr0, 0); 1583 1586 gfar_write(&regs->igaddr1, 0); ··· 1627 1648 } 1628 1649 1629 1650 /* Halt the receive and transmit queues */ 1630 - static void gfar_halt_nodisable(struct net_device *dev) 1651 + static void gfar_halt_nodisable(struct gfar_private *priv) 1631 1652 { 1632 - struct gfar_private *priv = netdev_priv(dev); 1633 - struct gfar __iomem *regs = NULL; 1653 + struct gfar __iomem *regs = priv->gfargrp[0].regs; 1634 1654 u32 tempval; 1635 - int i; 1636 1655 1637 - for (i = 0; i < priv->num_grps; i++) { 1638 - regs = priv->gfargrp[i].regs; 1639 - /* Mask all interrupts */ 1640 - gfar_write(&regs->imask, IMASK_INIT_CLEAR); 1656 + gfar_ints_disable(priv); 1641 1657 1642 - /* Clear all interrupts */ 1643 - gfar_write(&regs->ievent, IEVENT_INIT_CLEAR); 1644 - } 1645 - 1646 - regs = priv->gfargrp[0].regs; 1647 1658 /* Stop the DMA, and wait for it to stop */ 1648 1659 tempval = gfar_read(&regs->dmactrl); 1649 1660 if ((tempval & (DMACTRL_GRS | DMACTRL_GTS)) != ··· 1654 1685 } 1655 1686 1656 1687 /* Halt the receive and transmit queues */ 1657 - void gfar_halt(struct net_device *dev) 1688 + void gfar_halt(struct gfar_private *priv) 1658 1689 { 1659 - struct gfar_private *priv = netdev_priv(dev); 1660 1690 struct gfar __iomem *regs = priv->gfargrp[0].regs; 1661 1691 u32 tempval; 1662 1692 1663 - gfar_halt_nodisable(dev); 1693 + /* Dissable the Rx/Tx hw queues */ 1694 + gfar_write(&regs->rqueue, 0); 1695 + gfar_write(&regs->tqueue, 0); 1664 1696 1665 - /* Disable Rx and Tx */ 1697 + mdelay(10); 1698 + 1699 + gfar_halt_nodisable(priv); 1700 + 1701 + /* Disable Rx/Tx DMA */ 1666 1702 tempval = gfar_read(&regs->maccfg1); 1667 1703 tempval &= ~(MACCFG1_RX_EN | MACCFG1_TX_EN); 1668 1704 gfar_write(&regs->maccfg1, tempval); ··· 1694 1720 lock_tx_qs(priv); 1695 1721 lock_rx_qs(priv); 1696 1722 1697 - gfar_halt(dev); 1723 + gfar_halt(priv); 1698 1724 1699 1725 unlock_rx_qs(priv); 1700 1726 unlock_tx_qs(priv); ··· 1799 1825 priv->tx_queue[0]->tx_bd_dma_base); 1800 1826 } 1801 1827 1802 - void gfar_start(struct net_device *dev) 1828 + void gfar_start(struct gfar_private *priv) 1803 1829 { 1804 - struct gfar_private *priv = netdev_priv(dev); 1805 1830 struct gfar __iomem *regs = priv->gfargrp[0].regs; 1806 1831 u32 tempval; 1807 1832 int i = 0; 1808 1833 1809 - /* Enable Rx and Tx in MACCFG1 */ 1810 - tempval = gfar_read(&regs->maccfg1); 1811 - tempval |= (MACCFG1_RX_EN | MACCFG1_TX_EN); 1812 - gfar_write(&regs->maccfg1, tempval); 1834 + /* Enable Rx/Tx hw queues */ 1835 + gfar_write(&regs->rqueue, priv->rqueue); 1836 + gfar_write(&regs->tqueue, priv->tqueue); 1813 1837 1814 1838 /* Initialize DMACTRL to have WWR and WOP */ 1815 1839 tempval = gfar_read(&regs->dmactrl); ··· 1824 1852 /* Clear THLT/RHLT, so that the DMA starts polling now */ 1825 1853 gfar_write(&regs->tstat, priv->gfargrp[i].tstat); 1826 1854 gfar_write(&regs->rstat, priv->gfargrp[i].rstat); 1827 - /* Unmask the interrupts we look for */ 1828 - gfar_write(&regs->imask, IMASK_DEFAULT); 1829 1855 } 1830 1856 1831 - dev->trans_start = jiffies; /* prevent tx timeout */ 1857 + /* Enable Rx/Tx DMA */ 1858 + tempval = gfar_read(&regs->maccfg1); 1859 + tempval |= (MACCFG1_RX_EN | MACCFG1_TX_EN); 1860 + gfar_write(&regs->maccfg1, tempval); 1861 + 1862 + gfar_ints_enable(priv); 1863 + 1864 + priv->ndev->trans_start = jiffies; /* prevent tx timeout */ 1832 1865 } 1833 1866 1834 1867 static void gfar_configure_coalescing(struct gfar_private *priv, ··· 1937 1960 int startup_gfar(struct net_device *ndev) 1938 1961 { 1939 1962 struct gfar_private *priv = netdev_priv(ndev); 1940 - struct gfar __iomem *regs = NULL; 1941 1963 int err, i, j; 1942 1964 1943 - for (i = 0; i < priv->num_grps; i++) { 1944 - regs= priv->gfargrp[i].regs; 1945 - gfar_write(&regs->imask, IMASK_INIT_CLEAR); 1946 - } 1965 + gfar_ints_disable(priv); 1947 1966 1948 - regs= priv->gfargrp[0].regs; 1949 1967 err = gfar_alloc_skb_resources(ndev); 1950 1968 if (err) 1951 1969 return err; ··· 1957 1985 } 1958 1986 1959 1987 /* Start the controller */ 1960 - gfar_start(ndev); 1988 + gfar_start(priv); 1961 1989 1962 1990 phy_start(priv->phydev); 1963 1991
+33 -11
drivers/net/ethernet/freescale/gianfar.h
··· 9 9 * Maintainer: Kumar Gala 10 10 * Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com> 11 11 * 12 - * Copyright 2002-2009, 2011 Freescale Semiconductor, Inc. 12 + * Copyright 2002-2009, 2011-2013 Freescale Semiconductor, Inc. 13 13 * 14 14 * This program is free software; you can redistribute it and/or modify it 15 15 * under the terms of the GNU General Public License as published by the ··· 880 880 #define FSL_GIANFAR_DEV_HAS_CSUM 0x00000010 881 881 #define FSL_GIANFAR_DEV_HAS_VLAN 0x00000020 882 882 #define FSL_GIANFAR_DEV_HAS_EXTENDED_HASH 0x00000040 883 - #define FSL_GIANFAR_DEV_HAS_PADDING 0x00000080 884 883 #define FSL_GIANFAR_DEV_HAS_MAGIC_PACKET 0x00000100 885 884 #define FSL_GIANFAR_DEV_HAS_BD_STASHING 0x00000200 886 885 #define FSL_GIANFAR_DEV_HAS_BUF_STASHING 0x00000400 ··· 891 892 #define DEFAULT_MAPPING 0xFF 892 893 #endif 893 894 894 - #define ISRG_SHIFT_TX 0x10 895 - #define ISRG_SHIFT_RX 0x18 895 + #define ISRG_RR0 0x80000000 896 + #define ISRG_TR0 0x00800000 896 897 897 898 /* The same driver can operate in two modes */ 898 899 /* SQ_SG_MODE: Single Queue Single Group Mode ··· 1112 1113 unsigned int total_tx_ring_size; 1113 1114 unsigned int total_rx_ring_size; 1114 1115 1116 + u32 rqueue; 1117 + u32 tqueue; 1118 + 1115 1119 /* RX per device parameters */ 1116 1120 unsigned int rx_stash_size; 1117 1121 unsigned int rx_stash_index; ··· 1128 1126 /* Hash registers and their width */ 1129 1127 u32 __iomem *hash_regs[16]; 1130 1128 int hash_width; 1131 - 1132 - /* global parameters */ 1133 - unsigned int fifo_threshold; 1134 - unsigned int fifo_starve; 1135 - unsigned int fifo_starve_off; 1136 1129 1137 1130 /*Filer table*/ 1138 1131 unsigned int ftp_rqfpr[MAX_FILER_IDX + 1]; ··· 1173 1176 *fpr = gfar_read(&regs->rqfpr); 1174 1177 } 1175 1178 1179 + static inline void gfar_write_isrg(struct gfar_private *priv) 1180 + { 1181 + struct gfar __iomem *regs = priv->gfargrp[0].regs; 1182 + u32 __iomem *baddr = &regs->isrg0; 1183 + u32 isrg = 0; 1184 + int grp_idx, i; 1185 + 1186 + for (grp_idx = 0; grp_idx < priv->num_grps; grp_idx++) { 1187 + struct gfar_priv_grp *grp = &priv->gfargrp[grp_idx]; 1188 + 1189 + for_each_set_bit(i, &grp->rx_bit_map, priv->num_rx_queues) { 1190 + isrg |= (ISRG_RR0 >> i); 1191 + } 1192 + 1193 + for_each_set_bit(i, &grp->tx_bit_map, priv->num_tx_queues) { 1194 + isrg |= (ISRG_TR0 >> i); 1195 + } 1196 + 1197 + gfar_write(baddr, isrg); 1198 + 1199 + baddr++; 1200 + isrg = 0; 1201 + } 1202 + } 1203 + 1176 1204 void lock_rx_qs(struct gfar_private *priv); 1177 1205 void lock_tx_qs(struct gfar_private *priv); 1178 1206 void unlock_rx_qs(struct gfar_private *priv); ··· 1205 1183 irqreturn_t gfar_receive(int irq, void *dev_id); 1206 1184 int startup_gfar(struct net_device *dev); 1207 1185 void stop_gfar(struct net_device *dev); 1208 - void gfar_halt(struct net_device *dev); 1186 + void gfar_halt(struct gfar_private *priv); 1187 + void gfar_start(struct gfar_private *priv); 1209 1188 void gfar_phy_test(struct mii_bus *bus, struct phy_device *phydev, int enable, 1210 1189 u32 regnum, u32 read); 1211 1190 void gfar_configure_coalescing_all(struct gfar_private *priv); 1212 - void gfar_init_sysfs(struct net_device *dev); 1213 1191 int gfar_set_features(struct net_device *dev, netdev_features_t features); 1214 1192 void gfar_check_rx_parser_mode(struct gfar_private *priv); 1215 1193 void gfar_vlan_mode(struct net_device *dev, netdev_features_t features);
+8 -56
drivers/net/ethernet/freescale/gianfar_ethtool.c
··· 44 44 45 45 #include "gianfar.h" 46 46 47 - extern void gfar_start(struct net_device *dev); 48 - extern int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, 49 - int rx_work_limit); 50 - 51 47 #define GFAR_MAX_COAL_USECS 0xffff 52 48 #define GFAR_MAX_COAL_FRAMES 0xff 53 49 static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy, ··· 463 467 } 464 468 465 469 /* Change the current ring parameters, stopping the controller if 466 - * necessary so that we don't mess things up while we're in 467 - * motion. We wait for the ring to be clean before reallocating 468 - * the rings. 470 + * necessary so that we don't mess things up while we're in motion. 469 471 */ 470 472 static int gfar_sringparam(struct net_device *dev, 471 473 struct ethtool_ringparam *rvals) 472 474 { 473 475 struct gfar_private *priv = netdev_priv(dev); 474 - int err = 0, i = 0; 476 + int err = 0, i; 475 477 476 478 if (rvals->rx_pending > GFAR_RX_MAX_RING_SIZE) 477 479 return -EINVAL; ··· 487 493 return -EINVAL; 488 494 } 489 495 490 - 491 - if (dev->flags & IFF_UP) { 492 - unsigned long flags; 493 - 494 - /* Halt TX and RX, and process the frames which 495 - * have already been received 496 - */ 497 - local_irq_save(flags); 498 - lock_tx_qs(priv); 499 - lock_rx_qs(priv); 500 - 501 - gfar_halt(dev); 502 - 503 - unlock_rx_qs(priv); 504 - unlock_tx_qs(priv); 505 - local_irq_restore(flags); 506 - 507 - for (i = 0; i < priv->num_rx_queues; i++) 508 - gfar_clean_rx_ring(priv->rx_queue[i], 509 - priv->rx_queue[i]->rx_ring_size); 510 - 511 - /* Now we take down the rings to rebuild them */ 496 + if (dev->flags & IFF_UP) 512 497 stop_gfar(dev); 513 - } 514 498 515 - /* Change the size */ 516 - for (i = 0; i < priv->num_rx_queues; i++) { 499 + /* Change the sizes */ 500 + for (i = 0; i < priv->num_rx_queues; i++) 517 501 priv->rx_queue[i]->rx_ring_size = rvals->rx_pending; 502 + 503 + for (i = 0; i < priv->num_tx_queues; i++) 518 504 priv->tx_queue[i]->tx_ring_size = rvals->tx_pending; 519 - priv->tx_queue[i]->num_txbdfree = 520 - priv->tx_queue[i]->tx_ring_size; 521 - } 522 505 523 506 /* Rebuild the rings with the new size */ 524 507 if (dev->flags & IFF_UP) { ··· 579 608 580 609 int gfar_set_features(struct net_device *dev, netdev_features_t features) 581 610 { 582 - struct gfar_private *priv = netdev_priv(dev); 583 - unsigned long flags; 584 - int err = 0, i = 0; 585 611 netdev_features_t changed = dev->features ^ features; 612 + int err = 0; 586 613 587 614 if (changed & (NETIF_F_HW_VLAN_CTAG_TX|NETIF_F_HW_VLAN_CTAG_RX)) 588 615 gfar_vlan_mode(dev, features); ··· 589 620 return 0; 590 621 591 622 if (dev->flags & IFF_UP) { 592 - /* Halt TX and RX, and process the frames which 593 - * have already been received 594 - */ 595 - local_irq_save(flags); 596 - lock_tx_qs(priv); 597 - lock_rx_qs(priv); 598 - 599 - gfar_halt(dev); 600 - 601 - unlock_tx_qs(priv); 602 - unlock_rx_qs(priv); 603 - local_irq_restore(flags); 604 - 605 - for (i = 0; i < priv->num_rx_queues; i++) 606 - gfar_clean_rx_ring(priv->rx_queue[i], 607 - priv->rx_queue[i]->rx_ring_size); 608 - 609 623 /* Now we take down the rings to rebuild them */ 610 624 stop_gfar(dev); 611 625
-340
drivers/net/ethernet/freescale/gianfar_sysfs.c
··· 1 - /* 2 - * drivers/net/ethernet/freescale/gianfar_sysfs.c 3 - * 4 - * Gianfar Ethernet Driver 5 - * This driver is designed for the non-CPM ethernet controllers 6 - * on the 85xx and 83xx family of integrated processors 7 - * Based on 8260_io/fcc_enet.c 8 - * 9 - * Author: Andy Fleming 10 - * Maintainer: Kumar Gala (galak@kernel.crashing.org) 11 - * Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com> 12 - * 13 - * Copyright 2002-2009 Freescale Semiconductor, Inc. 14 - * 15 - * This program is free software; you can redistribute it and/or modify it 16 - * under the terms of the GNU General Public License as published by the 17 - * Free Software Foundation; either version 2 of the License, or (at your 18 - * option) any later version. 19 - * 20 - * Sysfs file creation and management 21 - */ 22 - 23 - #include <linux/kernel.h> 24 - #include <linux/string.h> 25 - #include <linux/errno.h> 26 - #include <linux/unistd.h> 27 - #include <linux/delay.h> 28 - #include <linux/etherdevice.h> 29 - #include <linux/spinlock.h> 30 - #include <linux/mm.h> 31 - #include <linux/device.h> 32 - 33 - #include <asm/uaccess.h> 34 - #include <linux/module.h> 35 - 36 - #include "gianfar.h" 37 - 38 - static ssize_t gfar_show_bd_stash(struct device *dev, 39 - struct device_attribute *attr, char *buf) 40 - { 41 - struct gfar_private *priv = netdev_priv(to_net_dev(dev)); 42 - 43 - return sprintf(buf, "%s\n", priv->bd_stash_en ? "on" : "off"); 44 - } 45 - 46 - static ssize_t gfar_set_bd_stash(struct device *dev, 47 - struct device_attribute *attr, 48 - const char *buf, size_t count) 49 - { 50 - struct gfar_private *priv = netdev_priv(to_net_dev(dev)); 51 - struct gfar __iomem *regs = priv->gfargrp[0].regs; 52 - int new_setting = 0; 53 - u32 temp; 54 - unsigned long flags; 55 - 56 - if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BD_STASHING)) 57 - return count; 58 - 59 - 60 - /* Find out the new setting */ 61 - if (!strncmp("on", buf, count - 1) || !strncmp("1", buf, count - 1)) 62 - new_setting = 1; 63 - else if (!strncmp("off", buf, count - 1) || 64 - !strncmp("0", buf, count - 1)) 65 - new_setting = 0; 66 - else 67 - return count; 68 - 69 - 70 - local_irq_save(flags); 71 - lock_rx_qs(priv); 72 - 73 - /* Set the new stashing value */ 74 - priv->bd_stash_en = new_setting; 75 - 76 - temp = gfar_read(&regs->attr); 77 - 78 - if (new_setting) 79 - temp |= ATTR_BDSTASH; 80 - else 81 - temp &= ~(ATTR_BDSTASH); 82 - 83 - gfar_write(&regs->attr, temp); 84 - 85 - unlock_rx_qs(priv); 86 - local_irq_restore(flags); 87 - 88 - return count; 89 - } 90 - 91 - static DEVICE_ATTR(bd_stash, 0644, gfar_show_bd_stash, gfar_set_bd_stash); 92 - 93 - static ssize_t gfar_show_rx_stash_size(struct device *dev, 94 - struct device_attribute *attr, char *buf) 95 - { 96 - struct gfar_private *priv = netdev_priv(to_net_dev(dev)); 97 - 98 - return sprintf(buf, "%d\n", priv->rx_stash_size); 99 - } 100 - 101 - static ssize_t gfar_set_rx_stash_size(struct device *dev, 102 - struct device_attribute *attr, 103 - const char *buf, size_t count) 104 - { 105 - struct gfar_private *priv = netdev_priv(to_net_dev(dev)); 106 - struct gfar __iomem *regs = priv->gfargrp[0].regs; 107 - unsigned int length = simple_strtoul(buf, NULL, 0); 108 - u32 temp; 109 - unsigned long flags; 110 - 111 - if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING)) 112 - return count; 113 - 114 - local_irq_save(flags); 115 - lock_rx_qs(priv); 116 - 117 - if (length > priv->rx_buffer_size) 118 - goto out; 119 - 120 - if (length == priv->rx_stash_size) 121 - goto out; 122 - 123 - priv->rx_stash_size = length; 124 - 125 - temp = gfar_read(&regs->attreli); 126 - temp &= ~ATTRELI_EL_MASK; 127 - temp |= ATTRELI_EL(length); 128 - gfar_write(&regs->attreli, temp); 129 - 130 - /* Turn stashing on/off as appropriate */ 131 - temp = gfar_read(&regs->attr); 132 - 133 - if (length) 134 - temp |= ATTR_BUFSTASH; 135 - else 136 - temp &= ~(ATTR_BUFSTASH); 137 - 138 - gfar_write(&regs->attr, temp); 139 - 140 - out: 141 - unlock_rx_qs(priv); 142 - local_irq_restore(flags); 143 - 144 - return count; 145 - } 146 - 147 - static DEVICE_ATTR(rx_stash_size, 0644, gfar_show_rx_stash_size, 148 - gfar_set_rx_stash_size); 149 - 150 - /* Stashing will only be enabled when rx_stash_size != 0 */ 151 - static ssize_t gfar_show_rx_stash_index(struct device *dev, 152 - struct device_attribute *attr, 153 - char *buf) 154 - { 155 - struct gfar_private *priv = netdev_priv(to_net_dev(dev)); 156 - 157 - return sprintf(buf, "%d\n", priv->rx_stash_index); 158 - } 159 - 160 - static ssize_t gfar_set_rx_stash_index(struct device *dev, 161 - struct device_attribute *attr, 162 - const char *buf, size_t count) 163 - { 164 - struct gfar_private *priv = netdev_priv(to_net_dev(dev)); 165 - struct gfar __iomem *regs = priv->gfargrp[0].regs; 166 - unsigned short index = simple_strtoul(buf, NULL, 0); 167 - u32 temp; 168 - unsigned long flags; 169 - 170 - if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING)) 171 - return count; 172 - 173 - local_irq_save(flags); 174 - lock_rx_qs(priv); 175 - 176 - if (index > priv->rx_stash_size) 177 - goto out; 178 - 179 - if (index == priv->rx_stash_index) 180 - goto out; 181 - 182 - priv->rx_stash_index = index; 183 - 184 - temp = gfar_read(&regs->attreli); 185 - temp &= ~ATTRELI_EI_MASK; 186 - temp |= ATTRELI_EI(index); 187 - gfar_write(&regs->attreli, temp); 188 - 189 - out: 190 - unlock_rx_qs(priv); 191 - local_irq_restore(flags); 192 - 193 - return count; 194 - } 195 - 196 - static DEVICE_ATTR(rx_stash_index, 0644, gfar_show_rx_stash_index, 197 - gfar_set_rx_stash_index); 198 - 199 - static ssize_t gfar_show_fifo_threshold(struct device *dev, 200 - struct device_attribute *attr, 201 - char *buf) 202 - { 203 - struct gfar_private *priv = netdev_priv(to_net_dev(dev)); 204 - 205 - return sprintf(buf, "%d\n", priv->fifo_threshold); 206 - } 207 - 208 - static ssize_t gfar_set_fifo_threshold(struct device *dev, 209 - struct device_attribute *attr, 210 - const char *buf, size_t count) 211 - { 212 - struct gfar_private *priv = netdev_priv(to_net_dev(dev)); 213 - struct gfar __iomem *regs = priv->gfargrp[0].regs; 214 - unsigned int length = simple_strtoul(buf, NULL, 0); 215 - u32 temp; 216 - unsigned long flags; 217 - 218 - if (length > GFAR_MAX_FIFO_THRESHOLD) 219 - return count; 220 - 221 - local_irq_save(flags); 222 - lock_tx_qs(priv); 223 - 224 - priv->fifo_threshold = length; 225 - 226 - temp = gfar_read(&regs->fifo_tx_thr); 227 - temp &= ~FIFO_TX_THR_MASK; 228 - temp |= length; 229 - gfar_write(&regs->fifo_tx_thr, temp); 230 - 231 - unlock_tx_qs(priv); 232 - local_irq_restore(flags); 233 - 234 - return count; 235 - } 236 - 237 - static DEVICE_ATTR(fifo_threshold, 0644, gfar_show_fifo_threshold, 238 - gfar_set_fifo_threshold); 239 - 240 - static ssize_t gfar_show_fifo_starve(struct device *dev, 241 - struct device_attribute *attr, char *buf) 242 - { 243 - struct gfar_private *priv = netdev_priv(to_net_dev(dev)); 244 - 245 - return sprintf(buf, "%d\n", priv->fifo_starve); 246 - } 247 - 248 - static ssize_t gfar_set_fifo_starve(struct device *dev, 249 - struct device_attribute *attr, 250 - const char *buf, size_t count) 251 - { 252 - struct gfar_private *priv = netdev_priv(to_net_dev(dev)); 253 - struct gfar __iomem *regs = priv->gfargrp[0].regs; 254 - unsigned int num = simple_strtoul(buf, NULL, 0); 255 - u32 temp; 256 - unsigned long flags; 257 - 258 - if (num > GFAR_MAX_FIFO_STARVE) 259 - return count; 260 - 261 - local_irq_save(flags); 262 - lock_tx_qs(priv); 263 - 264 - priv->fifo_starve = num; 265 - 266 - temp = gfar_read(&regs->fifo_tx_starve); 267 - temp &= ~FIFO_TX_STARVE_MASK; 268 - temp |= num; 269 - gfar_write(&regs->fifo_tx_starve, temp); 270 - 271 - unlock_tx_qs(priv); 272 - local_irq_restore(flags); 273 - 274 - return count; 275 - } 276 - 277 - static DEVICE_ATTR(fifo_starve, 0644, gfar_show_fifo_starve, 278 - gfar_set_fifo_starve); 279 - 280 - static ssize_t gfar_show_fifo_starve_off(struct device *dev, 281 - struct device_attribute *attr, 282 - char *buf) 283 - { 284 - struct gfar_private *priv = netdev_priv(to_net_dev(dev)); 285 - 286 - return sprintf(buf, "%d\n", priv->fifo_starve_off); 287 - } 288 - 289 - static ssize_t gfar_set_fifo_starve_off(struct device *dev, 290 - struct device_attribute *attr, 291 - const char *buf, size_t count) 292 - { 293 - struct gfar_private *priv = netdev_priv(to_net_dev(dev)); 294 - struct gfar __iomem *regs = priv->gfargrp[0].regs; 295 - unsigned int num = simple_strtoul(buf, NULL, 0); 296 - u32 temp; 297 - unsigned long flags; 298 - 299 - if (num > GFAR_MAX_FIFO_STARVE_OFF) 300 - return count; 301 - 302 - local_irq_save(flags); 303 - lock_tx_qs(priv); 304 - 305 - priv->fifo_starve_off = num; 306 - 307 - temp = gfar_read(&regs->fifo_tx_starve_shutoff); 308 - temp &= ~FIFO_TX_STARVE_OFF_MASK; 309 - temp |= num; 310 - gfar_write(&regs->fifo_tx_starve_shutoff, temp); 311 - 312 - unlock_tx_qs(priv); 313 - local_irq_restore(flags); 314 - 315 - return count; 316 - } 317 - 318 - static DEVICE_ATTR(fifo_starve_off, 0644, gfar_show_fifo_starve_off, 319 - gfar_set_fifo_starve_off); 320 - 321 - void gfar_init_sysfs(struct net_device *dev) 322 - { 323 - struct gfar_private *priv = netdev_priv(dev); 324 - int rc; 325 - 326 - /* Initialize the default values */ 327 - priv->fifo_threshold = DEFAULT_FIFO_TX_THR; 328 - priv->fifo_starve = DEFAULT_FIFO_TX_STARVE; 329 - priv->fifo_starve_off = DEFAULT_FIFO_TX_STARVE_OFF; 330 - 331 - /* Create our sysfs files */ 332 - rc = device_create_file(&dev->dev, &dev_attr_bd_stash); 333 - rc |= device_create_file(&dev->dev, &dev_attr_rx_stash_size); 334 - rc |= device_create_file(&dev->dev, &dev_attr_rx_stash_index); 335 - rc |= device_create_file(&dev->dev, &dev_attr_fifo_threshold); 336 - rc |= device_create_file(&dev->dev, &dev_attr_fifo_starve); 337 - rc |= device_create_file(&dev->dev, &dev_attr_fifo_starve_off); 338 - if (rc) 339 - dev_err(&dev->dev, "Error creating gianfar sysfs files\n"); 340 - }