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

[PATCH] Gianfar update and sysfs support

This seems to have gotten lost, so I'll resend.

Signed-off-by: Andy Fleming <afleming@freescale.com>

* Added sysfs support to gianfar for modifying FIFO and stashing parameters
* Updated driver to support 10 Mbit, full duplex operation
* Improved comments throughout
* Cleaned up and optimized offloading code
* Fixed a bug where rx buffers were being improperly mapped and unmapped
* (only manifested if cache-coherency was off)
* Added support for using the eTSEC exact-match MAC registers
* Bumped the version to 1.3
* Added support for distinguishing between reduced 100 and 10 Mbit modes
* Modified default coalescing values to lower latency
* Added documentation
Signed-off-by: Jeff Garzik <jgarzik@pobox.com>

authored by

Andy Fleming and committed by
Jeff Garzik
7f7f5316 fed5eccd

+579 -112
+72
Documentation/networking/gianfar.txt
··· 1 + The Gianfar Ethernet Driver 2 + Sysfs File description 3 + 4 + Author: Andy Fleming <afleming@freescale.com> 5 + Updated: 2005-07-28 6 + 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 + 37 + CHECKSUM OFFLOADING 38 + 39 + The eTSEC controller (first included in parts from late 2005 like 40 + the 8548) has the ability to perform TCP, UDP, and IP checksums 41 + in hardware. The Linux kernel only offloads the TCP and UDP 42 + checksums (and always performs the pseudo header checksums), so 43 + the driver only supports checksumming for TCP/IP and UDP/IP 44 + packets. Use ethtool to enable or disable this feature for RX 45 + and TX. 46 + 47 + VLAN 48 + 49 + In order to use VLAN, please consult Linux documentation on 50 + configuring VLANs. The gianfar driver supports hardware insertion and 51 + extraction of VLAN headers, but not filtering. Filtering will be 52 + done by the kernel. 53 + 54 + MULTICASTING 55 + 56 + The gianfar driver supports using the group hash table on the 57 + TSEC (and the extended hash table on the eTSEC) for multicast 58 + filtering. On the eTSEC, the exact-match MAC registers are used 59 + before the hash tables. See Linux documentation on how to join 60 + multicast groups. 61 + 62 + PADDING 63 + 64 + The gianfar driver supports padding received frames with 2 bytes 65 + to align the IP header to a 16-byte boundary, when supported by 66 + hardware. 67 + 68 + ETHTOOL 69 + 70 + The gianfar driver supports the use of ethtool for many 71 + configuration options. You must run ethtool only on currently 72 + open interfaces. See ethtool documentation for details.
+4 -1
drivers/net/Makefile
··· 13 13 obj-$(CONFIG_BONDING) += bonding/ 14 14 obj-$(CONFIG_GIANFAR) += gianfar_driver.o 15 15 16 - gianfar_driver-objs := gianfar.o gianfar_ethtool.o gianfar_mii.o 16 + gianfar_driver-objs := gianfar.o \ 17 + gianfar_ethtool.o \ 18 + gianfar_mii.o \ 19 + gianfar_sysfs.o 17 20 18 21 # 19 22 # link order important here
+152 -79
drivers/net/gianfar.c
··· 2 2 * drivers/net/gianfar.c 3 3 * 4 4 * Gianfar Ethernet Driver 5 - * Driver for FEC on MPC8540 and TSEC on MPC8540/MPC8560 5 + * This driver is designed for the non-CPM ethernet controllers 6 + * on the 85xx and 83xx family of integrated processors 6 7 * Based on 8260_io/fcc_enet.c 7 8 * 8 9 * Author: Andy Fleming ··· 23 22 * B-V +1.62 24 23 * 25 24 * Theory of operation 26 - * This driver is designed for the non-CPM ethernet controllers 27 - * on the 85xx and 83xx family of integrated processors 28 25 * 29 26 * The driver is initialized through platform_device. Structures which 30 27 * define the configuration needed by the board are defined in a ··· 109 110 #endif 110 111 111 112 const char gfar_driver_name[] = "Gianfar Ethernet"; 112 - const char gfar_driver_version[] = "1.2"; 113 + const char gfar_driver_version[] = "1.3"; 113 114 114 115 static int gfar_enet_open(struct net_device *dev); 115 116 static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev); ··· 138 139 static void gfar_vlan_rx_register(struct net_device *netdev, 139 140 struct vlan_group *grp); 140 141 static void gfar_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid); 142 + void gfar_halt(struct net_device *dev); 143 + void gfar_start(struct net_device *dev); 144 + static void gfar_clear_exact_match(struct net_device *dev); 145 + static void gfar_set_mac_for_addr(struct net_device *dev, int num, u8 *addr); 141 146 142 147 extern struct ethtool_ops gfar_ethtool_ops; 143 148 ··· 149 146 MODULE_DESCRIPTION("Gianfar Ethernet Driver"); 150 147 MODULE_LICENSE("GPL"); 151 148 152 - int gfar_uses_fcb(struct gfar_private *priv) 149 + /* Returns 1 if incoming frames use an FCB */ 150 + static inline int gfar_uses_fcb(struct gfar_private *priv) 153 151 { 154 - if (priv->vlan_enable || priv->rx_csum_enable) 155 - return 1; 156 - else 157 - return 0; 152 + return (priv->vlan_enable || priv->rx_csum_enable); 158 153 } 159 154 160 155 /* Set up the ethernet device structure, private data, ··· 321 320 else 322 321 priv->padding = 0; 323 322 324 - dev->hard_header_len += priv->padding; 325 - 326 323 if (dev->features & NETIF_F_IP_CSUM) 327 324 dev->hard_header_len += GMAC_FCB_LEN; 328 325 329 326 priv->rx_buffer_size = DEFAULT_RX_BUFFER_SIZE; 330 - #ifdef CONFIG_GFAR_BUFSTASH 331 - priv->rx_stash_size = STASH_LENGTH; 332 - #endif 333 327 priv->tx_ring_size = DEFAULT_TX_RING_SIZE; 334 328 priv->rx_ring_size = DEFAULT_RX_RING_SIZE; 335 329 ··· 346 350 goto register_fail; 347 351 } 348 352 353 + /* Create all the sysfs files */ 354 + gfar_init_sysfs(dev); 355 + 349 356 /* Print out the device info */ 350 357 printk(KERN_INFO DEVICE_NAME, dev->name); 351 358 for (idx = 0; idx < 6; idx++) ··· 356 357 printk("\n"); 357 358 358 359 /* Even more device info helps when determining which kernel */ 359 - /* provided which set of benchmarks. Since this is global for all */ 360 - /* devices, we only print it once */ 360 + /* provided which set of benchmarks. */ 361 361 #ifdef CONFIG_GFAR_NAPI 362 362 printk(KERN_INFO "%s: Running with NAPI enabled\n", dev->name); 363 363 #else ··· 461 463 /* Initialize the max receive buffer length */ 462 464 gfar_write(&priv->regs->mrblr, priv->rx_buffer_size); 463 465 464 - #ifdef CONFIG_GFAR_BUFSTASH 465 - /* If we are stashing buffers, we need to set the 466 - * extraction length to the size of the buffer */ 467 - gfar_write(&priv->regs->attreli, priv->rx_stash_size << 16); 468 - #endif 469 - 470 466 /* Initialize the Minimum Frame Length Register */ 471 467 gfar_write(&priv->regs->minflr, MINFLR_INIT_SETTINGS); 472 - 473 - /* Setup Attributes so that snooping is on for rx */ 474 - gfar_write(&priv->regs->attr, ATTR_INIT_SETTINGS); 475 - gfar_write(&priv->regs->attreli, ATTRELI_INIT_SETTINGS); 476 468 477 469 /* Assign the TBI an address which won't conflict with the PHYs */ 478 470 gfar_write(&priv->regs->tbipa, TBIPA_VALUE); ··· 565 577 for (i = 0; i < priv->rx_ring_size; i++) { 566 578 if (priv->rx_skbuff[i]) { 567 579 dma_unmap_single(NULL, rxbdp->bufPtr, 568 - priv->rx_buffer_size 569 - + RXBUF_ALIGNMENT, 580 + priv->rx_buffer_size, 570 581 DMA_FROM_DEVICE); 571 582 572 583 dev_kfree_skb_any(priv->rx_skbuff[i]); ··· 623 636 struct gfar *regs = priv->regs; 624 637 int err = 0; 625 638 u32 rctrl = 0; 639 + u32 attrs = 0; 626 640 627 641 gfar_write(&regs->imask, IMASK_INIT_CLEAR); 628 642 ··· 783 795 if (priv->rx_csum_enable) 784 796 rctrl |= RCTRL_CHECKSUMMING; 785 797 786 - if (priv->extended_hash) 798 + if (priv->extended_hash) { 787 799 rctrl |= RCTRL_EXTHASH; 800 + 801 + gfar_clear_exact_match(dev); 802 + rctrl |= RCTRL_EMEN; 803 + } 788 804 789 805 if (priv->vlan_enable) 790 806 rctrl |= RCTRL_VLAN; 807 + 808 + if (priv->padding) { 809 + rctrl &= ~RCTRL_PAL_MASK; 810 + rctrl |= RCTRL_PADDING(priv->padding); 811 + } 791 812 792 813 /* Init rctrl based on our settings */ 793 814 gfar_write(&priv->regs->rctrl, rctrl); ··· 804 807 if (dev->features & NETIF_F_IP_CSUM) 805 808 gfar_write(&priv->regs->tctrl, TCTRL_INIT_CSUM); 806 809 810 + /* Set the extraction length and index */ 811 + attrs = ATTRELI_EL(priv->rx_stash_size) | 812 + ATTRELI_EI(priv->rx_stash_index); 813 + 814 + gfar_write(&priv->regs->attreli, attrs); 815 + 816 + /* Start with defaults, and add stashing or locking 817 + * depending on the approprate variables */ 818 + attrs = ATTR_INIT_SETTINGS; 819 + 820 + if (priv->bd_stash_en) 821 + attrs |= ATTR_BDSTASH; 822 + 823 + if (priv->rx_stash_size != 0) 824 + attrs |= ATTR_BUFSTASH; 825 + 826 + gfar_write(&priv->regs->attr, attrs); 827 + 828 + gfar_write(&priv->regs->fifo_tx_thr, priv->fifo_threshold); 829 + gfar_write(&priv->regs->fifo_tx_starve, priv->fifo_starve); 830 + gfar_write(&priv->regs->fifo_tx_starve_shutoff, priv->fifo_starve_off); 831 + 832 + /* Start the controller */ 807 833 gfar_start(dev); 808 834 809 835 return 0; ··· 871 851 return err; 872 852 } 873 853 874 - static struct txfcb *gfar_add_fcb(struct sk_buff *skb, struct txbd8 *bdp) 854 + static inline struct txfcb *gfar_add_fcb(struct sk_buff *skb, struct txbd8 *bdp) 875 855 { 876 856 struct txfcb *fcb = (struct txfcb *)skb_push (skb, GMAC_FCB_LEN); 877 857 878 858 memset(fcb, 0, GMAC_FCB_LEN); 879 - 880 - /* Flag the bd so the controller looks for the FCB */ 881 - bdp->status |= TXBD_TOE; 882 859 883 860 return fcb; 884 861 } 885 862 886 863 static inline void gfar_tx_checksum(struct sk_buff *skb, struct txfcb *fcb) 887 864 { 888 - int len; 865 + u8 flags = 0; 889 866 890 867 /* If we're here, it's a IP packet with a TCP or UDP 891 868 * payload. We set it to checksum, using a pseudo-header 892 869 * we provide 893 870 */ 894 - fcb->ip = 1; 895 - fcb->tup = 1; 896 - fcb->ctu = 1; 897 - fcb->nph = 1; 871 + flags = TXFCB_DEFAULT; 898 872 899 - /* Notify the controller what the protocol is */ 900 - if (skb->nh.iph->protocol == IPPROTO_UDP) 901 - fcb->udp = 1; 873 + /* Tell the controller what the protocol is */ 874 + /* And provide the already calculated phcs */ 875 + if (skb->nh.iph->protocol == IPPROTO_UDP) { 876 + flags |= TXFCB_UDP; 877 + fcb->phcs = skb->h.uh->check; 878 + } else 879 + fcb->phcs = skb->h.th->check; 902 880 903 881 /* l3os is the distance between the start of the 904 882 * frame (skb->data) and the start of the IP hdr. ··· 905 887 fcb->l3os = (u16)(skb->nh.raw - skb->data - GMAC_FCB_LEN); 906 888 fcb->l4os = (u16)(skb->h.raw - skb->nh.raw); 907 889 908 - len = skb->nh.iph->tot_len - fcb->l4os; 909 - 910 - /* Provide the pseudoheader csum */ 911 - fcb->phcs = ~csum_tcpudp_magic(skb->nh.iph->saddr, 912 - skb->nh.iph->daddr, len, 913 - skb->nh.iph->protocol, 0); 890 + fcb->flags = flags; 914 891 } 915 892 916 - void gfar_tx_vlan(struct sk_buff *skb, struct txfcb *fcb) 893 + void inline gfar_tx_vlan(struct sk_buff *skb, struct txfcb *fcb) 917 894 { 918 - fcb->vln = 1; 895 + fcb->flags |= TXFCB_VLN; 919 896 fcb->vlctl = vlan_tx_tag_get(skb); 920 897 } 921 898 ··· 921 908 struct gfar_private *priv = netdev_priv(dev); 922 909 struct txfcb *fcb = NULL; 923 910 struct txbd8 *txbdp; 911 + u16 status; 924 912 925 913 /* Update transmit stats */ 926 914 priv->stats.tx_bytes += skb->len; ··· 933 919 txbdp = priv->cur_tx; 934 920 935 921 /* Clear all but the WRAP status flags */ 936 - txbdp->status &= TXBD_WRAP; 922 + status = txbdp->status & TXBD_WRAP; 937 923 938 924 /* Set up checksumming */ 939 - if ((dev->features & NETIF_F_IP_CSUM) 940 - && (CHECKSUM_HW == skb->ip_summed)) { 925 + if (likely((dev->features & NETIF_F_IP_CSUM) 926 + && (CHECKSUM_HW == skb->ip_summed))) { 941 927 fcb = gfar_add_fcb(skb, txbdp); 928 + status |= TXBD_TOE; 942 929 gfar_tx_checksum(skb, fcb); 943 930 } 944 931 945 932 if (priv->vlan_enable && 946 933 unlikely(priv->vlgrp && vlan_tx_tag_present(skb))) { 947 - if (NULL == fcb) 934 + if (unlikely(NULL == fcb)) { 948 935 fcb = gfar_add_fcb(skb, txbdp); 936 + status |= TXBD_TOE; 937 + } 949 938 950 939 gfar_tx_vlan(skb, fcb); 951 940 } ··· 966 949 (priv->skb_curtx + 1) & TX_RING_MOD_MASK(priv->tx_ring_size); 967 950 968 951 /* Flag the BD as interrupt-causing */ 969 - txbdp->status |= TXBD_INTERRUPT; 952 + status |= TXBD_INTERRUPT; 970 953 971 954 /* Flag the BD as ready to go, last in frame, and */ 972 955 /* in need of CRC */ 973 - txbdp->status |= (TXBD_READY | TXBD_LAST | TXBD_CRC); 956 + status |= (TXBD_READY | TXBD_LAST | TXBD_CRC); 974 957 975 958 dev->trans_start = jiffies; 959 + 960 + txbdp->status = status; 976 961 977 962 /* If this was the last BD in the ring, the next one */ 978 963 /* is at the beginning of the ring */ ··· 1029 1010 /* Changes the mac address if the controller is not running. */ 1030 1011 int gfar_set_mac_address(struct net_device *dev) 1031 1012 { 1032 - struct gfar_private *priv = netdev_priv(dev); 1033 - int i; 1034 - char tmpbuf[MAC_ADDR_LEN]; 1035 - u32 tempval; 1036 - 1037 - /* Now copy it into the mac registers backwards, cuz */ 1038 - /* little endian is silly */ 1039 - for (i = 0; i < MAC_ADDR_LEN; i++) 1040 - tmpbuf[MAC_ADDR_LEN - 1 - i] = dev->dev_addr[i]; 1041 - 1042 - gfar_write(&priv->regs->macstnaddr1, *((u32 *) (tmpbuf))); 1043 - 1044 - tempval = *((u32 *) (tmpbuf + 4)); 1045 - 1046 - gfar_write(&priv->regs->macstnaddr2, tempval); 1013 + gfar_set_mac_for_addr(dev, 0, dev->dev_addr); 1047 1014 1048 1015 return 0; 1049 1016 } ··· 1115 1110 INCREMENTAL_BUFFER_SIZE; 1116 1111 1117 1112 /* Only stop and start the controller if it isn't already 1118 - * stopped */ 1113 + * stopped, and we changed something */ 1119 1114 if ((oldsize != tempsize) && (dev->flags & IFF_UP)) 1120 1115 stop_gfar(dev); 1121 1116 ··· 1225 1220 1226 1221 struct sk_buff * gfar_new_skb(struct net_device *dev, struct rxbd8 *bdp) 1227 1222 { 1223 + unsigned int alignamount; 1228 1224 struct gfar_private *priv = netdev_priv(dev); 1229 1225 struct sk_buff *skb = NULL; 1230 1226 unsigned int timeout = SKB_ALLOC_TIMEOUT; ··· 1237 1231 if (NULL == skb) 1238 1232 return NULL; 1239 1233 1234 + alignamount = RXBUF_ALIGNMENT - 1235 + (((unsigned) skb->data) & (RXBUF_ALIGNMENT - 1)); 1236 + 1240 1237 /* We need the data buffer to be aligned properly. We will reserve 1241 1238 * as many bytes as needed to align the data properly 1242 1239 */ 1243 - skb_reserve(skb, 1244 - RXBUF_ALIGNMENT - 1245 - (((unsigned) skb->data) & (RXBUF_ALIGNMENT - 1))); 1240 + skb_reserve(skb, alignamount); 1246 1241 1247 1242 skb->dev = dev; 1248 1243 1249 1244 bdp->bufPtr = dma_map_single(NULL, skb->data, 1250 - priv->rx_buffer_size + RXBUF_ALIGNMENT, 1251 - DMA_FROM_DEVICE); 1245 + priv->rx_buffer_size, DMA_FROM_DEVICE); 1252 1246 1253 1247 bdp->length = 0; 1254 1248 ··· 1356 1350 /* If valid headers were found, and valid sums 1357 1351 * were verified, then we tell the kernel that no 1358 1352 * checksumming is necessary. Otherwise, it is */ 1359 - if (fcb->cip && !fcb->eip && fcb->ctu && !fcb->etu) 1353 + if ((fcb->flags & RXFCB_CSUM_MASK) == (RXFCB_CIP | RXFCB_CTU)) 1360 1354 skb->ip_summed = CHECKSUM_UNNECESSARY; 1361 1355 else 1362 1356 skb->ip_summed = CHECKSUM_NONE; ··· 1407 1401 skb->protocol = eth_type_trans(skb, dev); 1408 1402 1409 1403 /* Send the packet up the stack */ 1410 - if (unlikely(priv->vlgrp && fcb->vln)) 1404 + if (unlikely(priv->vlgrp && (fcb->flags & RXFCB_VLN))) 1411 1405 ret = gfar_rx_vlan(skb, priv->vlgrp, fcb->vlctl); 1412 1406 else 1413 1407 ret = RECEIVE(skb); ··· 1626 1620 spin_lock_irqsave(&priv->lock, flags); 1627 1621 if (phydev->link) { 1628 1622 u32 tempval = gfar_read(&regs->maccfg2); 1623 + u32 ecntrl = gfar_read(&regs->ecntrl); 1629 1624 1630 1625 /* Now we make sure that we can be in full duplex mode. 1631 1626 * If not, we operate in half-duplex mode. */ ··· 1651 1644 case 10: 1652 1645 tempval = 1653 1646 ((tempval & ~(MACCFG2_IF)) | MACCFG2_MII); 1647 + 1648 + /* Reduced mode distinguishes 1649 + * between 10 and 100 */ 1650 + if (phydev->speed == SPEED_100) 1651 + ecntrl |= ECNTRL_R100; 1652 + else 1653 + ecntrl &= ~(ECNTRL_R100); 1654 1654 break; 1655 1655 default: 1656 1656 if (netif_msg_link(priv)) ··· 1671 1657 } 1672 1658 1673 1659 gfar_write(&regs->maccfg2, tempval); 1660 + gfar_write(&regs->ecntrl, ecntrl); 1674 1661 1675 1662 if (!priv->oldlink) { 1676 1663 new_state = 1; ··· 1736 1721 gfar_write(&regs->gaddr6, 0xffffffff); 1737 1722 gfar_write(&regs->gaddr7, 0xffffffff); 1738 1723 } else { 1724 + int em_num; 1725 + int idx; 1726 + 1739 1727 /* zero out the hash */ 1740 1728 gfar_write(&regs->igaddr0, 0x0); 1741 1729 gfar_write(&regs->igaddr1, 0x0); ··· 1757 1739 gfar_write(&regs->gaddr6, 0x0); 1758 1740 gfar_write(&regs->gaddr7, 0x0); 1759 1741 1742 + /* If we have extended hash tables, we need to 1743 + * clear the exact match registers to prepare for 1744 + * setting them */ 1745 + if (priv->extended_hash) { 1746 + em_num = GFAR_EM_NUM + 1; 1747 + gfar_clear_exact_match(dev); 1748 + idx = 1; 1749 + } else { 1750 + idx = 0; 1751 + em_num = 0; 1752 + } 1753 + 1760 1754 if(dev->mc_count == 0) 1761 1755 return; 1762 1756 1763 1757 /* Parse the list, and set the appropriate bits */ 1764 1758 for(mc_ptr = dev->mc_list; mc_ptr; mc_ptr = mc_ptr->next) { 1765 - gfar_set_hash_for_addr(dev, mc_ptr->dmi_addr); 1759 + if (idx < em_num) { 1760 + gfar_set_mac_for_addr(dev, idx, 1761 + mc_ptr->dmi_addr); 1762 + idx++; 1763 + } else 1764 + gfar_set_hash_for_addr(dev, mc_ptr->dmi_addr); 1766 1765 } 1767 1766 } 1768 1767 1769 1768 return; 1769 + } 1770 + 1771 + 1772 + /* Clears each of the exact match registers to zero, so they 1773 + * don't interfere with normal reception */ 1774 + static void gfar_clear_exact_match(struct net_device *dev) 1775 + { 1776 + int idx; 1777 + u8 zero_arr[MAC_ADDR_LEN] = {0,0,0,0,0,0}; 1778 + 1779 + for(idx = 1;idx < GFAR_EM_NUM + 1;idx++) 1780 + gfar_set_mac_for_addr(dev, idx, (u8 *)zero_arr); 1770 1781 } 1771 1782 1772 1783 /* Set the appropriate hash bit for the given addr */ ··· 1826 1779 gfar_write(priv->hash_regs[whichreg], tempval); 1827 1780 1828 1781 return; 1782 + } 1783 + 1784 + 1785 + /* There are multiple MAC Address register pairs on some controllers 1786 + * This function sets the numth pair to a given address 1787 + */ 1788 + static void gfar_set_mac_for_addr(struct net_device *dev, int num, u8 *addr) 1789 + { 1790 + struct gfar_private *priv = netdev_priv(dev); 1791 + int idx; 1792 + char tmpbuf[MAC_ADDR_LEN]; 1793 + u32 tempval; 1794 + u32 *macptr = &priv->regs->macstnaddr1; 1795 + 1796 + macptr += num*2; 1797 + 1798 + /* Now copy it into the mac registers backwards, cuz */ 1799 + /* little endian is silly */ 1800 + for (idx = 0; idx < MAC_ADDR_LEN; idx++) 1801 + tmpbuf[MAC_ADDR_LEN - 1 - idx] = addr[idx]; 1802 + 1803 + gfar_write(macptr, *((u32 *) (tmpbuf))); 1804 + 1805 + tempval = *((u32 *) (tmpbuf + 4)); 1806 + 1807 + gfar_write(macptr+1, tempval); 1829 1808 } 1830 1809 1831 1810 /* GFAR error interrupt handler */
+38 -31
drivers/net/gianfar.h
··· 90 90 #define GFAR_RX_MAX_RING_SIZE 256 91 91 #define GFAR_TX_MAX_RING_SIZE 256 92 92 93 + #define GFAR_MAX_FIFO_THRESHOLD 511 94 + #define GFAR_MAX_FIFO_STARVE 511 95 + #define GFAR_MAX_FIFO_STARVE_OFF 511 96 + 93 97 #define DEFAULT_RX_BUFFER_SIZE 1536 94 98 #define TX_RING_MOD_MASK(size) (size-1) 95 99 #define RX_RING_MOD_MASK(size) (size-1) 96 100 #define JUMBO_BUFFER_SIZE 9728 97 101 #define JUMBO_FRAME_SIZE 9600 102 + 103 + #define DEFAULT_FIFO_TX_THR 0x100 104 + #define DEFAULT_FIFO_TX_STARVE 0x40 105 + #define DEFAULT_FIFO_TX_STARVE_OFF 0x80 106 + #define DEFAULT_BD_STASH 1 107 + #define DEFAULT_STASH_LENGTH 64 108 + #define DEFAULT_STASH_INDEX 0 109 + 110 + /* The number of Exact Match registers */ 111 + #define GFAR_EM_NUM 15 98 112 99 113 /* Latency of interface clock in nanoseconds */ 100 114 /* Interface clock latency , in this case, means the ··· 126 112 127 113 #define DEFAULT_TX_COALESCE 1 128 114 #define DEFAULT_TXCOUNT 16 129 - #define DEFAULT_TXTIME 400 115 + #define DEFAULT_TXTIME 4 130 116 131 117 #define DEFAULT_RX_COALESCE 1 132 118 #define DEFAULT_RXCOUNT 16 133 - #define DEFAULT_RXTIME 400 119 + #define DEFAULT_RXTIME 4 134 120 135 121 #define TBIPA_VALUE 0x1f 136 122 #define MIIMCFG_INIT_VALUE 0x00000007 ··· 161 147 162 148 #define ECNTRL_INIT_SETTINGS 0x00001000 163 149 #define ECNTRL_TBI_MODE 0x00000020 150 + #define ECNTRL_R100 0x00000008 164 151 165 152 #define MRBLR_INIT_SETTINGS DEFAULT_RX_BUFFER_SIZE 166 153 ··· 196 181 #define RCTRL_PRSDEP_MASK 0x000000c0 197 182 #define RCTRL_PRSDEP_INIT 0x000000c0 198 183 #define RCTRL_PROM 0x00000008 184 + #define RCTRL_EMEN 0x00000002 199 185 #define RCTRL_CHECKSUMMING (RCTRL_IPCSEN \ 200 186 | RCTRL_TUCSEN | RCTRL_PRSDEP_INIT) 201 187 #define RCTRL_EXTHASH (RCTRL_GHTX) 202 188 #define RCTRL_VLAN (RCTRL_PRSDEP_INIT) 189 + #define RCTRL_PADDING(x) ((x << 16) & RCTRL_PAL_MASK) 203 190 204 191 205 192 #define RSTAT_CLEAR_RHALT 0x00800000 ··· 268 251 IMASK_XFUN | IMASK_RXC | IMASK_BABT | IMASK_DPE \ 269 252 | IMASK_PERR) 270 253 254 + /* Fifo management */ 255 + #define FIFO_TX_THR_MASK 0x01ff 256 + #define FIFO_TX_STARVE_MASK 0x01ff 257 + #define FIFO_TX_STARVE_OFF_MASK 0x01ff 271 258 272 259 /* Attribute fields */ 273 260 274 261 /* This enables rx snooping for buffers and descriptors */ 275 - #ifdef CONFIG_GFAR_BDSTASH 276 262 #define ATTR_BDSTASH 0x00000800 277 - #else 278 - #define ATTR_BDSTASH 0x00000000 279 - #endif 280 263 281 - #ifdef CONFIG_GFAR_BUFSTASH 282 264 #define ATTR_BUFSTASH 0x00004000 283 - #define STASH_LENGTH 64 284 - #else 285 - #define ATTR_BUFSTASH 0x00000000 286 - #endif 287 265 288 266 #define ATTR_SNOOPING 0x000000c0 289 - #define ATTR_INIT_SETTINGS (ATTR_SNOOPING \ 290 - | ATTR_BDSTASH | ATTR_BUFSTASH) 267 + #define ATTR_INIT_SETTINGS ATTR_SNOOPING 291 268 292 269 #define ATTRELI_INIT_SETTINGS 0x0 270 + #define ATTRELI_EL_MASK 0x3fff0000 271 + #define ATTRELI_EL(x) (x << 16) 272 + #define ATTRELI_EI_MASK 0x00003fff 273 + #define ATTRELI_EI(x) (x) 293 274 294 275 295 276 /* TxBD status field bits */ ··· 343 328 #define RXFCB_CTU 0x0400 344 329 #define RXFCB_EIP 0x0200 345 330 #define RXFCB_ETU 0x0100 331 + #define RXFCB_CSUM_MASK 0x0f00 346 332 #define RXFCB_PERR_MASK 0x000c 347 333 #define RXFCB_PERR_BADL3 0x0008 348 334 ··· 355 339 }; 356 340 357 341 struct txfcb { 358 - u8 vln:1, 359 - ip:1, 360 - ip6:1, 361 - tup:1, 362 - udp:1, 363 - cip:1, 364 - ctu:1, 365 - nph:1; 342 + u8 flags; 366 343 u8 reserved; 367 344 u8 l4os; /* Level 4 Header Offset */ 368 345 u8 l3os; /* Level 3 Header Offset */ ··· 371 362 }; 372 363 373 364 struct rxfcb { 374 - u16 vln:1, 375 - ip:1, 376 - ip6:1, 377 - tup:1, 378 - cip:1, 379 - ctu:1, 380 - eip:1, 381 - etu:1; 365 + u16 flags; 382 366 u8 rq; /* Receive Queue index */ 383 367 u8 pro; /* Layer 4 Protocol */ 384 368 u16 reserved; ··· 690 688 spinlock_t lock; 691 689 unsigned int rx_buffer_size; 692 690 unsigned int rx_stash_size; 691 + unsigned int rx_stash_index; 693 692 unsigned int tx_ring_size; 694 693 unsigned int rx_ring_size; 694 + unsigned int fifo_threshold; 695 + unsigned int fifo_starve; 696 + unsigned int fifo_starve_off; 695 697 696 698 unsigned char vlan_enable:1, 697 699 rx_csum_enable:1, 698 - extended_hash:1; 700 + extended_hash:1, 701 + bd_stash_en:1; 699 702 unsigned short padding; 700 703 struct vlan_group *vlgrp; 701 704 /* Info structure initialized by board setup code */ ··· 738 731 extern void gfar_halt(struct net_device *dev); 739 732 extern void gfar_phy_test(struct mii_bus *bus, struct phy_device *phydev, 740 733 int enable, u32 regnum, u32 read); 741 - void gfar_setup_stashing(struct net_device *dev); 734 + void gfar_init_sysfs(struct net_device *dev); 742 735 743 736 #endif /* __GIANFAR_H */
+1 -1
drivers/net/gianfar_ethtool.c
··· 125 125 static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf) 126 126 { 127 127 struct gfar_private *priv = netdev_priv(dev); 128 - 128 + 129 129 if (priv->einfo->device_flags & FSL_GIANFAR_DEV_HAS_RMON) 130 130 memcpy(buf, stat_gstrings, GFAR_STATS_LEN * ETH_GSTRING_LEN); 131 131 else
+1
drivers/net/gianfar_mii.h
··· 24 24 #define MII_READ_COMMAND 0x00000001 25 25 26 26 #define GFAR_SUPPORTED (SUPPORTED_10baseT_Half \ 27 + | SUPPORTED_10baseT_Full \ 27 28 | SUPPORTED_100baseT_Half \ 28 29 | SUPPORTED_100baseT_Full \ 29 30 | SUPPORTED_Autoneg \
+311
drivers/net/gianfar_sysfs.c
··· 1 + /* 2 + * drivers/net/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 (kumar.gala@freescale.com) 11 + * 12 + * Copyright (c) 2002-2005 Freescale Semiconductor, Inc. 13 + * 14 + * This program is free software; you can redistribute it and/or modify it 15 + * under the terms of the GNU General Public License as published by the 16 + * Free Software Foundation; either version 2 of the License, or (at your 17 + * option) any later version. 18 + * 19 + * Sysfs file creation and management 20 + */ 21 + 22 + #include <linux/config.h> 23 + #include <linux/kernel.h> 24 + #include <linux/sched.h> 25 + #include <linux/string.h> 26 + #include <linux/errno.h> 27 + #include <linux/unistd.h> 28 + #include <linux/slab.h> 29 + #include <linux/init.h> 30 + #include <linux/delay.h> 31 + #include <linux/etherdevice.h> 32 + #include <linux/spinlock.h> 33 + #include <linux/mm.h> 34 + #include <linux/device.h> 35 + 36 + #include <asm/uaccess.h> 37 + #include <linux/module.h> 38 + #include <linux/version.h> 39 + 40 + #include "gianfar.h" 41 + 42 + #define GFAR_ATTR(_name) \ 43 + static ssize_t gfar_show_##_name(struct class_device *cdev, char *buf); \ 44 + static ssize_t gfar_set_##_name(struct class_device *cdev, \ 45 + const char *buf, size_t count); \ 46 + static CLASS_DEVICE_ATTR(_name, 0644, gfar_show_##_name, gfar_set_##_name) 47 + 48 + #define GFAR_CREATE_FILE(_dev, _name) \ 49 + class_device_create_file(&_dev->class_dev, &class_device_attr_##_name) 50 + 51 + GFAR_ATTR(bd_stash); 52 + GFAR_ATTR(rx_stash_size); 53 + GFAR_ATTR(rx_stash_index); 54 + GFAR_ATTR(fifo_threshold); 55 + GFAR_ATTR(fifo_starve); 56 + GFAR_ATTR(fifo_starve_off); 57 + 58 + #define to_net_dev(cd) container_of(cd, struct net_device, class_dev) 59 + 60 + static ssize_t gfar_show_bd_stash(struct class_device *cdev, char *buf) 61 + { 62 + struct net_device *dev = to_net_dev(cdev); 63 + struct gfar_private *priv = netdev_priv(dev); 64 + 65 + return sprintf(buf, "%s\n", priv->bd_stash_en? "on" : "off"); 66 + } 67 + 68 + static ssize_t gfar_set_bd_stash(struct class_device *cdev, 69 + const char *buf, size_t count) 70 + { 71 + struct net_device *dev = to_net_dev(cdev); 72 + struct gfar_private *priv = netdev_priv(dev); 73 + int new_setting = 0; 74 + u32 temp; 75 + unsigned long flags; 76 + 77 + /* Find out the new setting */ 78 + if (!strncmp("on", buf, count-1) || !strncmp("1", buf, count-1)) 79 + new_setting = 1; 80 + else if (!strncmp("off", buf, count-1) || !strncmp("0", buf, count-1)) 81 + new_setting = 0; 82 + else 83 + return count; 84 + 85 + spin_lock_irqsave(&priv->lock, flags); 86 + 87 + /* Set the new stashing value */ 88 + priv->bd_stash_en = new_setting; 89 + 90 + temp = gfar_read(&priv->regs->attr); 91 + 92 + if (new_setting) 93 + temp |= ATTR_BDSTASH; 94 + else 95 + temp &= ~(ATTR_BDSTASH); 96 + 97 + gfar_write(&priv->regs->attr, temp); 98 + 99 + spin_unlock_irqrestore(&priv->lock, flags); 100 + 101 + return count; 102 + } 103 + 104 + static ssize_t gfar_show_rx_stash_size(struct class_device *cdev, char *buf) 105 + { 106 + struct net_device *dev = to_net_dev(cdev); 107 + struct gfar_private *priv = netdev_priv(dev); 108 + 109 + return sprintf(buf, "%d\n", priv->rx_stash_size); 110 + } 111 + 112 + static ssize_t gfar_set_rx_stash_size(struct class_device *cdev, 113 + const char *buf, size_t count) 114 + { 115 + struct net_device *dev = to_net_dev(cdev); 116 + struct gfar_private *priv = netdev_priv(dev); 117 + unsigned int length = simple_strtoul(buf, NULL, 0); 118 + u32 temp; 119 + unsigned long flags; 120 + 121 + spin_lock_irqsave(&priv->lock, flags); 122 + if (length > priv->rx_buffer_size) 123 + return count; 124 + 125 + if (length == priv->rx_stash_size) 126 + return count; 127 + 128 + priv->rx_stash_size = length; 129 + 130 + temp = gfar_read(&priv->regs->attreli); 131 + temp &= ~ATTRELI_EL_MASK; 132 + temp |= ATTRELI_EL(length); 133 + gfar_write(&priv->regs->attreli, temp); 134 + 135 + /* Turn stashing on/off as appropriate */ 136 + temp = gfar_read(&priv->regs->attr); 137 + 138 + if (length) 139 + temp |= ATTR_BUFSTASH; 140 + else 141 + temp &= ~(ATTR_BUFSTASH); 142 + 143 + gfar_write(&priv->regs->attr, temp); 144 + 145 + spin_unlock_irqrestore(&priv->lock, flags); 146 + 147 + return count; 148 + } 149 + 150 + 151 + /* Stashing will only be enabled when rx_stash_size != 0 */ 152 + static ssize_t gfar_show_rx_stash_index(struct class_device *cdev, char *buf) 153 + { 154 + struct net_device *dev = to_net_dev(cdev); 155 + struct gfar_private *priv = netdev_priv(dev); 156 + 157 + return sprintf(buf, "%d\n", priv->rx_stash_index); 158 + } 159 + 160 + static ssize_t gfar_set_rx_stash_index(struct class_device *cdev, 161 + const char *buf, size_t count) 162 + { 163 + struct net_device *dev = to_net_dev(cdev); 164 + struct gfar_private *priv = netdev_priv(dev); 165 + unsigned short index = simple_strtoul(buf, NULL, 0); 166 + u32 temp; 167 + unsigned long flags; 168 + 169 + spin_lock_irqsave(&priv->lock, flags); 170 + if (index > priv->rx_stash_size) 171 + return count; 172 + 173 + if (index == priv->rx_stash_index) 174 + return count; 175 + 176 + priv->rx_stash_index = index; 177 + 178 + temp = gfar_read(&priv->regs->attreli); 179 + temp &= ~ATTRELI_EI_MASK; 180 + temp |= ATTRELI_EI(index); 181 + gfar_write(&priv->regs->attreli, flags); 182 + 183 + spin_unlock_irqrestore(&priv->lock, flags); 184 + 185 + return count; 186 + } 187 + 188 + static ssize_t gfar_show_fifo_threshold(struct class_device *cdev, char *buf) 189 + { 190 + struct net_device *dev = to_net_dev(cdev); 191 + struct gfar_private *priv = netdev_priv(dev); 192 + 193 + return sprintf(buf, "%d\n", priv->fifo_threshold); 194 + } 195 + 196 + static ssize_t gfar_set_fifo_threshold(struct class_device *cdev, 197 + const char *buf, size_t count) 198 + { 199 + struct net_device *dev = to_net_dev(cdev); 200 + struct gfar_private *priv = netdev_priv(dev); 201 + unsigned int length = simple_strtoul(buf, NULL, 0); 202 + u32 temp; 203 + unsigned long flags; 204 + 205 + if (length > GFAR_MAX_FIFO_THRESHOLD) 206 + return count; 207 + 208 + spin_lock_irqsave(&priv->lock, flags); 209 + 210 + priv->fifo_threshold = length; 211 + 212 + temp = gfar_read(&priv->regs->fifo_tx_thr); 213 + temp &= ~FIFO_TX_THR_MASK; 214 + temp |= length; 215 + gfar_write(&priv->regs->fifo_tx_thr, temp); 216 + 217 + spin_unlock_irqrestore(&priv->lock, flags); 218 + 219 + return count; 220 + } 221 + 222 + static ssize_t gfar_show_fifo_starve(struct class_device *cdev, char *buf) 223 + { 224 + struct net_device *dev = to_net_dev(cdev); 225 + struct gfar_private *priv = netdev_priv(dev); 226 + 227 + return sprintf(buf, "%d\n", priv->fifo_starve); 228 + } 229 + 230 + 231 + static ssize_t gfar_set_fifo_starve(struct class_device *cdev, 232 + const char *buf, size_t count) 233 + { 234 + struct net_device *dev = to_net_dev(cdev); 235 + struct gfar_private *priv = netdev_priv(dev); 236 + unsigned int num = simple_strtoul(buf, NULL, 0); 237 + u32 temp; 238 + unsigned long flags; 239 + 240 + if (num > GFAR_MAX_FIFO_STARVE) 241 + return count; 242 + 243 + spin_lock_irqsave(&priv->lock, flags); 244 + 245 + priv->fifo_starve = num; 246 + 247 + temp = gfar_read(&priv->regs->fifo_tx_starve); 248 + temp &= ~FIFO_TX_STARVE_MASK; 249 + temp |= num; 250 + gfar_write(&priv->regs->fifo_tx_starve, temp); 251 + 252 + spin_unlock_irqrestore(&priv->lock, flags); 253 + 254 + return count; 255 + } 256 + 257 + static ssize_t gfar_show_fifo_starve_off(struct class_device *cdev, char *buf) 258 + { 259 + struct net_device *dev = to_net_dev(cdev); 260 + struct gfar_private *priv = netdev_priv(dev); 261 + 262 + return sprintf(buf, "%d\n", priv->fifo_starve_off); 263 + } 264 + 265 + static ssize_t gfar_set_fifo_starve_off(struct class_device *cdev, 266 + const char *buf, size_t count) 267 + { 268 + struct net_device *dev = to_net_dev(cdev); 269 + struct gfar_private *priv = netdev_priv(dev); 270 + unsigned int num = simple_strtoul(buf, NULL, 0); 271 + u32 temp; 272 + unsigned long flags; 273 + 274 + if (num > GFAR_MAX_FIFO_STARVE_OFF) 275 + return count; 276 + 277 + spin_lock_irqsave(&priv->lock, flags); 278 + 279 + priv->fifo_starve_off = num; 280 + 281 + temp = gfar_read(&priv->regs->fifo_tx_starve_shutoff); 282 + temp &= ~FIFO_TX_STARVE_OFF_MASK; 283 + temp |= num; 284 + gfar_write(&priv->regs->fifo_tx_starve_shutoff, temp); 285 + 286 + spin_unlock_irqrestore(&priv->lock, flags); 287 + 288 + return count; 289 + } 290 + 291 + void gfar_init_sysfs(struct net_device *dev) 292 + { 293 + struct gfar_private *priv = netdev_priv(dev); 294 + 295 + /* Initialize the default values */ 296 + priv->rx_stash_size = DEFAULT_STASH_LENGTH; 297 + priv->rx_stash_index = DEFAULT_STASH_INDEX; 298 + priv->fifo_threshold = DEFAULT_FIFO_TX_THR; 299 + priv->fifo_starve = DEFAULT_FIFO_TX_STARVE; 300 + priv->fifo_starve_off = DEFAULT_FIFO_TX_STARVE_OFF; 301 + priv->bd_stash_en = DEFAULT_BD_STASH; 302 + 303 + /* Create our sysfs files */ 304 + GFAR_CREATE_FILE(dev, bd_stash); 305 + GFAR_CREATE_FILE(dev, rx_stash_size); 306 + GFAR_CREATE_FILE(dev, rx_stash_index); 307 + GFAR_CREATE_FILE(dev, fifo_threshold); 308 + GFAR_CREATE_FILE(dev, fifo_starve); 309 + GFAR_CREATE_FILE(dev, fifo_starve_off); 310 + 311 + }