12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
23401299aSJeff Kirsher /* D-Link DL2000-based Gigabit Ethernet Adapter Linux driver */
33401299aSJeff Kirsher /*
43401299aSJeff Kirsher Copyright (c) 2001, 2002 by D-Link Corporation
53401299aSJeff Kirsher Written by Edward Peng.<edward_peng@dlink.com.tw>
63401299aSJeff Kirsher Created 03-May-2001, base on Linux' sundance.c.
73401299aSJeff Kirsher
83401299aSJeff Kirsher */
93401299aSJeff Kirsher
103401299aSJeff Kirsher #include "dl2k.h"
113401299aSJeff Kirsher #include <linux/dma-mapping.h>
123401299aSJeff Kirsher
135e3cc4e3SFrancois Romieu #define dw32(reg, val) iowrite32(val, ioaddr + (reg))
145e3cc4e3SFrancois Romieu #define dw16(reg, val) iowrite16(val, ioaddr + (reg))
155e3cc4e3SFrancois Romieu #define dw8(reg, val) iowrite8(val, ioaddr + (reg))
165e3cc4e3SFrancois Romieu #define dr32(reg) ioread32(ioaddr + (reg))
175e3cc4e3SFrancois Romieu #define dr16(reg) ioread16(ioaddr + (reg))
185e3cc4e3SFrancois Romieu #define dr8(reg) ioread8(ioaddr + (reg))
195e3cc4e3SFrancois Romieu
203401299aSJeff Kirsher #define MAX_UNITS 8
213401299aSJeff Kirsher static int mtu[MAX_UNITS];
223401299aSJeff Kirsher static int vlan[MAX_UNITS];
233401299aSJeff Kirsher static int jumbo[MAX_UNITS];
243401299aSJeff Kirsher static char *media[MAX_UNITS];
253401299aSJeff Kirsher static int tx_flow=-1;
263401299aSJeff Kirsher static int rx_flow=-1;
273401299aSJeff Kirsher static int copy_thresh;
283401299aSJeff Kirsher static int rx_coalesce=10; /* Rx frame count each interrupt */
293401299aSJeff Kirsher static int rx_timeout=200; /* Rx DMA wait time in 640ns increments */
303401299aSJeff Kirsher static int tx_coalesce=16; /* HW xmit count each TxDMAComplete */
313401299aSJeff Kirsher
323401299aSJeff Kirsher
333401299aSJeff Kirsher MODULE_AUTHOR ("Edward Peng");
343401299aSJeff Kirsher MODULE_DESCRIPTION ("D-Link DL2000-based Gigabit Ethernet Adapter");
353401299aSJeff Kirsher MODULE_LICENSE("GPL");
363401299aSJeff Kirsher module_param_array(mtu, int, NULL, 0);
373401299aSJeff Kirsher module_param_array(media, charp, NULL, 0);
383401299aSJeff Kirsher module_param_array(vlan, int, NULL, 0);
393401299aSJeff Kirsher module_param_array(jumbo, int, NULL, 0);
403401299aSJeff Kirsher module_param(tx_flow, int, 0);
413401299aSJeff Kirsher module_param(rx_flow, int, 0);
423401299aSJeff Kirsher module_param(copy_thresh, int, 0);
433401299aSJeff Kirsher module_param(rx_coalesce, int, 0); /* Rx frame count each interrupt */
443401299aSJeff Kirsher module_param(rx_timeout, int, 0); /* Rx DMA wait time in 64ns increments */
453401299aSJeff Kirsher module_param(tx_coalesce, int, 0); /* HW xmit count each TxDMAComplete */
463401299aSJeff Kirsher
473401299aSJeff Kirsher
483401299aSJeff Kirsher /* Enable the default interrupts */
493401299aSJeff Kirsher #define DEFAULT_INTR (RxDMAComplete | HostError | IntRequested | TxDMAComplete| \
503401299aSJeff Kirsher UpdateStats | LinkEvent)
515e3cc4e3SFrancois Romieu
dl2k_enable_int(struct netdev_private * np)525e3cc4e3SFrancois Romieu static void dl2k_enable_int(struct netdev_private *np)
535e3cc4e3SFrancois Romieu {
545e3cc4e3SFrancois Romieu void __iomem *ioaddr = np->ioaddr;
555e3cc4e3SFrancois Romieu
565e3cc4e3SFrancois Romieu dw16(IntEnable, DEFAULT_INTR);
575e3cc4e3SFrancois Romieu }
583401299aSJeff Kirsher
593401299aSJeff Kirsher static const int max_intrloop = 50;
603401299aSJeff Kirsher static const int multicast_filter_limit = 0x40;
613401299aSJeff Kirsher
623401299aSJeff Kirsher static int rio_open (struct net_device *dev);
636fa35bd0SKees Cook static void rio_timer (struct timer_list *t);
640290bd29SMichael S. Tsirkin static void rio_tx_timeout (struct net_device *dev, unsigned int txqueue);
653401299aSJeff Kirsher static netdev_tx_t start_xmit (struct sk_buff *skb, struct net_device *dev);
663401299aSJeff Kirsher static irqreturn_t rio_interrupt (int irq, void *dev_instance);
673401299aSJeff Kirsher static void rio_free_tx (struct net_device *dev, int irq);
683401299aSJeff Kirsher static void tx_error (struct net_device *dev, int tx_status);
693401299aSJeff Kirsher static int receive_packet (struct net_device *dev);
703401299aSJeff Kirsher static void rio_error (struct net_device *dev, int int_status);
713401299aSJeff Kirsher static void set_multicast (struct net_device *dev);
723401299aSJeff Kirsher static struct net_device_stats *get_stats (struct net_device *dev);
733401299aSJeff Kirsher static int clear_stats (struct net_device *dev);
743401299aSJeff Kirsher static int rio_ioctl (struct net_device *dev, struct ifreq *rq, int cmd);
753401299aSJeff Kirsher static int rio_close (struct net_device *dev);
763401299aSJeff Kirsher static int find_miiphy (struct net_device *dev);
773401299aSJeff Kirsher static int parse_eeprom (struct net_device *dev);
785e3cc4e3SFrancois Romieu static int read_eeprom (struct netdev_private *, int eep_addr);
793401299aSJeff Kirsher static int mii_wait_link (struct net_device *dev, int wait);
803401299aSJeff Kirsher static int mii_set_media (struct net_device *dev);
813401299aSJeff Kirsher static int mii_get_media (struct net_device *dev);
823401299aSJeff Kirsher static int mii_set_media_pcs (struct net_device *dev);
833401299aSJeff Kirsher static int mii_get_media_pcs (struct net_device *dev);
843401299aSJeff Kirsher static int mii_read (struct net_device *dev, int phy_addr, int reg_num);
853401299aSJeff Kirsher static int mii_write (struct net_device *dev, int phy_addr, int reg_num,
863401299aSJeff Kirsher u16 data);
873401299aSJeff Kirsher
883401299aSJeff Kirsher static const struct ethtool_ops ethtool_ops;
893401299aSJeff Kirsher
903401299aSJeff Kirsher static const struct net_device_ops netdev_ops = {
913401299aSJeff Kirsher .ndo_open = rio_open,
923401299aSJeff Kirsher .ndo_start_xmit = start_xmit,
933401299aSJeff Kirsher .ndo_stop = rio_close,
943401299aSJeff Kirsher .ndo_get_stats = get_stats,
953401299aSJeff Kirsher .ndo_validate_addr = eth_validate_addr,
963401299aSJeff Kirsher .ndo_set_mac_address = eth_mac_addr,
97afc4b13dSJiri Pirko .ndo_set_rx_mode = set_multicast,
98a7605370SArnd Bergmann .ndo_eth_ioctl = rio_ioctl,
993401299aSJeff Kirsher .ndo_tx_timeout = rio_tx_timeout,
1003401299aSJeff Kirsher };
1013401299aSJeff Kirsher
10264bc40deSBill Pemberton static int
rio_probe1(struct pci_dev * pdev,const struct pci_device_id * ent)1033401299aSJeff Kirsher rio_probe1 (struct pci_dev *pdev, const struct pci_device_id *ent)
1043401299aSJeff Kirsher {
1053401299aSJeff Kirsher struct net_device *dev;
1063401299aSJeff Kirsher struct netdev_private *np;
1073401299aSJeff Kirsher static int card_idx;
1083401299aSJeff Kirsher int chip_idx = ent->driver_data;
1093401299aSJeff Kirsher int err, irq;
1105e3cc4e3SFrancois Romieu void __iomem *ioaddr;
1113401299aSJeff Kirsher void *ring_space;
1123401299aSJeff Kirsher dma_addr_t ring_dma;
1133401299aSJeff Kirsher
1143401299aSJeff Kirsher err = pci_enable_device (pdev);
1153401299aSJeff Kirsher if (err)
1163401299aSJeff Kirsher return err;
1173401299aSJeff Kirsher
1183401299aSJeff Kirsher irq = pdev->irq;
1193401299aSJeff Kirsher err = pci_request_regions (pdev, "dl2k");
1203401299aSJeff Kirsher if (err)
1213401299aSJeff Kirsher goto err_out_disable;
1223401299aSJeff Kirsher
1233401299aSJeff Kirsher pci_set_master (pdev);
1245e3cc4e3SFrancois Romieu
1253401299aSJeff Kirsher err = -ENOMEM;
1265e3cc4e3SFrancois Romieu
1275e3cc4e3SFrancois Romieu dev = alloc_etherdev (sizeof (*np));
1285e3cc4e3SFrancois Romieu if (!dev)
1293401299aSJeff Kirsher goto err_out_res;
1303401299aSJeff Kirsher SET_NETDEV_DEV(dev, &pdev->dev);
1313401299aSJeff Kirsher
1323401299aSJeff Kirsher np = netdev_priv(dev);
1335e3cc4e3SFrancois Romieu
1345e3cc4e3SFrancois Romieu /* IO registers range. */
1355e3cc4e3SFrancois Romieu ioaddr = pci_iomap(pdev, 0, 0);
1365e3cc4e3SFrancois Romieu if (!ioaddr)
1375e3cc4e3SFrancois Romieu goto err_out_dev;
1385e3cc4e3SFrancois Romieu np->eeprom_addr = ioaddr;
1395e3cc4e3SFrancois Romieu
1405e3cc4e3SFrancois Romieu #ifdef MEM_MAPPING
1415e3cc4e3SFrancois Romieu /* MM registers range. */
1425e3cc4e3SFrancois Romieu ioaddr = pci_iomap(pdev, 1, 0);
1435e3cc4e3SFrancois Romieu if (!ioaddr)
1445e3cc4e3SFrancois Romieu goto err_out_iounmap;
1455e3cc4e3SFrancois Romieu #endif
1465e3cc4e3SFrancois Romieu np->ioaddr = ioaddr;
1473401299aSJeff Kirsher np->chip_id = chip_idx;
1483401299aSJeff Kirsher np->pdev = pdev;
1493401299aSJeff Kirsher spin_lock_init (&np->tx_lock);
1503401299aSJeff Kirsher spin_lock_init (&np->rx_lock);
1513401299aSJeff Kirsher
1523401299aSJeff Kirsher /* Parse manual configuration */
1533401299aSJeff Kirsher np->an_enable = 1;
1543401299aSJeff Kirsher np->tx_coalesce = 1;
1553401299aSJeff Kirsher if (card_idx < MAX_UNITS) {
1563401299aSJeff Kirsher if (media[card_idx] != NULL) {
1573401299aSJeff Kirsher np->an_enable = 0;
1583401299aSJeff Kirsher if (strcmp (media[card_idx], "auto") == 0 ||
1593401299aSJeff Kirsher strcmp (media[card_idx], "autosense") == 0 ||
1603401299aSJeff Kirsher strcmp (media[card_idx], "0") == 0 ) {
1613401299aSJeff Kirsher np->an_enable = 2;
1623401299aSJeff Kirsher } else if (strcmp (media[card_idx], "100mbps_fd") == 0 ||
1633401299aSJeff Kirsher strcmp (media[card_idx], "4") == 0) {
1643401299aSJeff Kirsher np->speed = 100;
1653401299aSJeff Kirsher np->full_duplex = 1;
1663401299aSJeff Kirsher } else if (strcmp (media[card_idx], "100mbps_hd") == 0 ||
1673401299aSJeff Kirsher strcmp (media[card_idx], "3") == 0) {
1683401299aSJeff Kirsher np->speed = 100;
1693401299aSJeff Kirsher np->full_duplex = 0;
1703401299aSJeff Kirsher } else if (strcmp (media[card_idx], "10mbps_fd") == 0 ||
1713401299aSJeff Kirsher strcmp (media[card_idx], "2") == 0) {
1723401299aSJeff Kirsher np->speed = 10;
1733401299aSJeff Kirsher np->full_duplex = 1;
1743401299aSJeff Kirsher } else if (strcmp (media[card_idx], "10mbps_hd") == 0 ||
1753401299aSJeff Kirsher strcmp (media[card_idx], "1") == 0) {
1763401299aSJeff Kirsher np->speed = 10;
1773401299aSJeff Kirsher np->full_duplex = 0;
1783401299aSJeff Kirsher } else if (strcmp (media[card_idx], "1000mbps_fd") == 0 ||
1793401299aSJeff Kirsher strcmp (media[card_idx], "6") == 0) {
1803401299aSJeff Kirsher np->speed=1000;
1813401299aSJeff Kirsher np->full_duplex=1;
1823401299aSJeff Kirsher } else if (strcmp (media[card_idx], "1000mbps_hd") == 0 ||
1833401299aSJeff Kirsher strcmp (media[card_idx], "5") == 0) {
1843401299aSJeff Kirsher np->speed = 1000;
1853401299aSJeff Kirsher np->full_duplex = 0;
1863401299aSJeff Kirsher } else {
1873401299aSJeff Kirsher np->an_enable = 1;
1883401299aSJeff Kirsher }
1893401299aSJeff Kirsher }
1903401299aSJeff Kirsher if (jumbo[card_idx] != 0) {
1913401299aSJeff Kirsher np->jumbo = 1;
1923401299aSJeff Kirsher dev->mtu = MAX_JUMBO;
1933401299aSJeff Kirsher } else {
1943401299aSJeff Kirsher np->jumbo = 0;
1953401299aSJeff Kirsher if (mtu[card_idx] > 0 && mtu[card_idx] < PACKET_SIZE)
1963401299aSJeff Kirsher dev->mtu = mtu[card_idx];
1973401299aSJeff Kirsher }
1983401299aSJeff Kirsher np->vlan = (vlan[card_idx] > 0 && vlan[card_idx] < 4096) ?
1993401299aSJeff Kirsher vlan[card_idx] : 0;
2003401299aSJeff Kirsher if (rx_coalesce > 0 && rx_timeout > 0) {
2013401299aSJeff Kirsher np->rx_coalesce = rx_coalesce;
2023401299aSJeff Kirsher np->rx_timeout = rx_timeout;
2033401299aSJeff Kirsher np->coalesce = 1;
2043401299aSJeff Kirsher }
2053401299aSJeff Kirsher np->tx_flow = (tx_flow == 0) ? 0 : 1;
2063401299aSJeff Kirsher np->rx_flow = (rx_flow == 0) ? 0 : 1;
2073401299aSJeff Kirsher
2083401299aSJeff Kirsher if (tx_coalesce < 1)
2093401299aSJeff Kirsher tx_coalesce = 1;
2103401299aSJeff Kirsher else if (tx_coalesce > TX_RING_SIZE-1)
2113401299aSJeff Kirsher tx_coalesce = TX_RING_SIZE - 1;
2123401299aSJeff Kirsher }
2133401299aSJeff Kirsher dev->netdev_ops = &netdev_ops;
2143401299aSJeff Kirsher dev->watchdog_timeo = TX_TIMEOUT;
2157ad24ea4SWilfried Klaebe dev->ethtool_ops = ðtool_ops;
2163401299aSJeff Kirsher #if 0
2173401299aSJeff Kirsher dev->features = NETIF_F_IP_CSUM;
2183401299aSJeff Kirsher #endif
219f7ad72bfSJarod Wilson /* MTU range: 68 - 1536 or 8000 */
220f7ad72bfSJarod Wilson dev->min_mtu = ETH_MIN_MTU;
221f7ad72bfSJarod Wilson dev->max_mtu = np->jumbo ? MAX_JUMBO : PACKET_SIZE;
222f7ad72bfSJarod Wilson
2233401299aSJeff Kirsher pci_set_drvdata (pdev, dev);
2243401299aSJeff Kirsher
225b49db89eSChristophe JAILLET ring_space = dma_alloc_coherent(&pdev->dev, TX_TOTAL_SIZE, &ring_dma,
226b49db89eSChristophe JAILLET GFP_KERNEL);
2273401299aSJeff Kirsher if (!ring_space)
2283401299aSJeff Kirsher goto err_out_iounmap;
2293401299aSJeff Kirsher np->tx_ring = ring_space;
2303401299aSJeff Kirsher np->tx_ring_dma = ring_dma;
2313401299aSJeff Kirsher
232b49db89eSChristophe JAILLET ring_space = dma_alloc_coherent(&pdev->dev, RX_TOTAL_SIZE, &ring_dma,
233b49db89eSChristophe JAILLET GFP_KERNEL);
2343401299aSJeff Kirsher if (!ring_space)
2353401299aSJeff Kirsher goto err_out_unmap_tx;
2363401299aSJeff Kirsher np->rx_ring = ring_space;
2373401299aSJeff Kirsher np->rx_ring_dma = ring_dma;
2383401299aSJeff Kirsher
2393401299aSJeff Kirsher /* Parse eeprom data */
2403401299aSJeff Kirsher parse_eeprom (dev);
2413401299aSJeff Kirsher
2423401299aSJeff Kirsher /* Find PHY address */
2433401299aSJeff Kirsher err = find_miiphy (dev);
2443401299aSJeff Kirsher if (err)
2453401299aSJeff Kirsher goto err_out_unmap_rx;
2463401299aSJeff Kirsher
2473401299aSJeff Kirsher /* Fiber device? */
2485e3cc4e3SFrancois Romieu np->phy_media = (dr16(ASICCtrl) & PhyMedia) ? 1 : 0;
2493401299aSJeff Kirsher np->link_status = 0;
2503401299aSJeff Kirsher /* Set media and reset PHY */
2513401299aSJeff Kirsher if (np->phy_media) {
2523401299aSJeff Kirsher /* default Auto-Negotiation for fiber deivices */
2533401299aSJeff Kirsher if (np->an_enable == 2) {
2543401299aSJeff Kirsher np->an_enable = 1;
2553401299aSJeff Kirsher }
2563401299aSJeff Kirsher } else {
2573401299aSJeff Kirsher /* Auto-Negotiation is mandatory for 1000BASE-T,
2583401299aSJeff Kirsher IEEE 802.3ab Annex 28D page 14 */
2593401299aSJeff Kirsher if (np->speed == 1000)
2603401299aSJeff Kirsher np->an_enable = 1;
2613401299aSJeff Kirsher }
2623401299aSJeff Kirsher
2633401299aSJeff Kirsher err = register_netdev (dev);
2643401299aSJeff Kirsher if (err)
2653401299aSJeff Kirsher goto err_out_unmap_rx;
2663401299aSJeff Kirsher
2673401299aSJeff Kirsher card_idx++;
2683401299aSJeff Kirsher
2693401299aSJeff Kirsher printk (KERN_INFO "%s: %s, %pM, IRQ %d\n",
2703401299aSJeff Kirsher dev->name, np->name, dev->dev_addr, irq);
2713401299aSJeff Kirsher if (tx_coalesce > 1)
2723401299aSJeff Kirsher printk(KERN_INFO "tx_coalesce:\t%d packets\n",
2733401299aSJeff Kirsher tx_coalesce);
2743401299aSJeff Kirsher if (np->coalesce)
2753401299aSJeff Kirsher printk(KERN_INFO
2763401299aSJeff Kirsher "rx_coalesce:\t%d packets\n"
2773401299aSJeff Kirsher "rx_timeout: \t%d ns\n",
2783401299aSJeff Kirsher np->rx_coalesce, np->rx_timeout*640);
2793401299aSJeff Kirsher if (np->vlan)
2803401299aSJeff Kirsher printk(KERN_INFO "vlan(id):\t%d\n", np->vlan);
2813401299aSJeff Kirsher return 0;
2823401299aSJeff Kirsher
2833401299aSJeff Kirsher err_out_unmap_rx:
284b49db89eSChristophe JAILLET dma_free_coherent(&pdev->dev, RX_TOTAL_SIZE, np->rx_ring,
285b49db89eSChristophe JAILLET np->rx_ring_dma);
2863401299aSJeff Kirsher err_out_unmap_tx:
287b49db89eSChristophe JAILLET dma_free_coherent(&pdev->dev, TX_TOTAL_SIZE, np->tx_ring,
288b49db89eSChristophe JAILLET np->tx_ring_dma);
2893401299aSJeff Kirsher err_out_iounmap:
2903401299aSJeff Kirsher #ifdef MEM_MAPPING
2915e3cc4e3SFrancois Romieu pci_iounmap(pdev, np->ioaddr);
2923401299aSJeff Kirsher #endif
2935e3cc4e3SFrancois Romieu pci_iounmap(pdev, np->eeprom_addr);
2945e3cc4e3SFrancois Romieu err_out_dev:
2953401299aSJeff Kirsher free_netdev (dev);
2963401299aSJeff Kirsher err_out_res:
2973401299aSJeff Kirsher pci_release_regions (pdev);
2983401299aSJeff Kirsher err_out_disable:
2993401299aSJeff Kirsher pci_disable_device (pdev);
3003401299aSJeff Kirsher return err;
3013401299aSJeff Kirsher }
3023401299aSJeff Kirsher
3033401299aSJeff Kirsher static int
find_miiphy(struct net_device * dev)3043401299aSJeff Kirsher find_miiphy (struct net_device *dev)
3053401299aSJeff Kirsher {
3065e3cc4e3SFrancois Romieu struct netdev_private *np = netdev_priv(dev);
3073401299aSJeff Kirsher int i, phy_found = 0;
3085618c8e2SColin Ian King
3093401299aSJeff Kirsher np->phy_addr = 1;
3103401299aSJeff Kirsher
3113401299aSJeff Kirsher for (i = 31; i >= 0; i--) {
3123401299aSJeff Kirsher int mii_status = mii_read (dev, i, 1);
3133401299aSJeff Kirsher if (mii_status != 0xffff && mii_status != 0x0000) {
3143401299aSJeff Kirsher np->phy_addr = i;
3153401299aSJeff Kirsher phy_found++;
3163401299aSJeff Kirsher }
3173401299aSJeff Kirsher }
3183401299aSJeff Kirsher if (!phy_found) {
3193401299aSJeff Kirsher printk (KERN_ERR "%s: No MII PHY found!\n", dev->name);
3203401299aSJeff Kirsher return -ENODEV;
3213401299aSJeff Kirsher }
3223401299aSJeff Kirsher return 0;
3233401299aSJeff Kirsher }
3243401299aSJeff Kirsher
3253401299aSJeff Kirsher static int
parse_eeprom(struct net_device * dev)3263401299aSJeff Kirsher parse_eeprom (struct net_device *dev)
3273401299aSJeff Kirsher {
3285e3cc4e3SFrancois Romieu struct netdev_private *np = netdev_priv(dev);
3295e3cc4e3SFrancois Romieu void __iomem *ioaddr = np->ioaddr;
3303401299aSJeff Kirsher int i, j;
3313401299aSJeff Kirsher u8 sromdata[256];
3323401299aSJeff Kirsher u8 *psib;
3333401299aSJeff Kirsher u32 crc;
3343401299aSJeff Kirsher PSROM_t psrom = (PSROM_t) sromdata;
3353401299aSJeff Kirsher
3363401299aSJeff Kirsher int cid, next;
3373401299aSJeff Kirsher
3385e3cc4e3SFrancois Romieu for (i = 0; i < 128; i++)
3395e3cc4e3SFrancois Romieu ((__le16 *) sromdata)[i] = cpu_to_le16(read_eeprom(np, i));
3405e3cc4e3SFrancois Romieu
3413401299aSJeff Kirsher if (np->pdev->vendor == PCI_VENDOR_ID_DLINK) { /* D-Link Only */
3423401299aSJeff Kirsher /* Check CRC */
3433401299aSJeff Kirsher crc = ~ether_crc_le (256 - 4, sromdata);
3443401299aSJeff Kirsher if (psrom->crc != cpu_to_le32(crc)) {
3453401299aSJeff Kirsher printk (KERN_ERR "%s: EEPROM data CRC error.\n",
3463401299aSJeff Kirsher dev->name);
3473401299aSJeff Kirsher return -1;
3483401299aSJeff Kirsher }
3493401299aSJeff Kirsher }
3503401299aSJeff Kirsher
3513401299aSJeff Kirsher /* Set MAC address */
352562ef98aSJakub Kicinski eth_hw_addr_set(dev, psrom->mac_addr);
3533401299aSJeff Kirsher
354c3f45d32SOndrej Zary if (np->chip_id == CHIP_IP1000A) {
355c3f45d32SOndrej Zary np->led_mode = psrom->led_mode;
356c3f45d32SOndrej Zary return 0;
357c3f45d32SOndrej Zary }
358c3f45d32SOndrej Zary
3593401299aSJeff Kirsher if (np->pdev->vendor != PCI_VENDOR_ID_DLINK) {
3603401299aSJeff Kirsher return 0;
3613401299aSJeff Kirsher }
3623401299aSJeff Kirsher
3633401299aSJeff Kirsher /* Parse Software Information Block */
3643401299aSJeff Kirsher i = 0x30;
3653401299aSJeff Kirsher psib = (u8 *) sromdata;
3663401299aSJeff Kirsher do {
3673401299aSJeff Kirsher cid = psib[i++];
3683401299aSJeff Kirsher next = psib[i++];
3693401299aSJeff Kirsher if ((cid == 0 && next == 0) || (cid == 0xff && next == 0xff)) {
3703401299aSJeff Kirsher printk (KERN_ERR "Cell data error\n");
3713401299aSJeff Kirsher return -1;
3723401299aSJeff Kirsher }
3733401299aSJeff Kirsher switch (cid) {
3743401299aSJeff Kirsher case 0: /* Format version */
3753401299aSJeff Kirsher break;
3763401299aSJeff Kirsher case 1: /* End of cell */
3773401299aSJeff Kirsher return 0;
3783401299aSJeff Kirsher case 2: /* Duplex Polarity */
3793401299aSJeff Kirsher np->duplex_polarity = psib[i];
3805e3cc4e3SFrancois Romieu dw8(PhyCtrl, dr8(PhyCtrl) | psib[i]);
3813401299aSJeff Kirsher break;
3823401299aSJeff Kirsher case 3: /* Wake Polarity */
3833401299aSJeff Kirsher np->wake_polarity = psib[i];
3843401299aSJeff Kirsher break;
3853401299aSJeff Kirsher case 9: /* Adapter description */
3863401299aSJeff Kirsher j = (next - i > 255) ? 255 : next - i;
3873401299aSJeff Kirsher memcpy (np->name, &(psib[i]), j);
3883401299aSJeff Kirsher break;
3893401299aSJeff Kirsher case 4:
3903401299aSJeff Kirsher case 5:
3913401299aSJeff Kirsher case 6:
3923401299aSJeff Kirsher case 7:
3933401299aSJeff Kirsher case 8: /* Reversed */
3943401299aSJeff Kirsher break;
3953401299aSJeff Kirsher default: /* Unknown cell */
3963401299aSJeff Kirsher return -1;
3973401299aSJeff Kirsher }
3983401299aSJeff Kirsher i = next;
3993401299aSJeff Kirsher } while (1);
4003401299aSJeff Kirsher
4013401299aSJeff Kirsher return 0;
4023401299aSJeff Kirsher }
4033401299aSJeff Kirsher
rio_set_led_mode(struct net_device * dev)404c3f45d32SOndrej Zary static void rio_set_led_mode(struct net_device *dev)
405c3f45d32SOndrej Zary {
406c3f45d32SOndrej Zary struct netdev_private *np = netdev_priv(dev);
407c3f45d32SOndrej Zary void __iomem *ioaddr = np->ioaddr;
408c3f45d32SOndrej Zary u32 mode;
409c3f45d32SOndrej Zary
410c3f45d32SOndrej Zary if (np->chip_id != CHIP_IP1000A)
411c3f45d32SOndrej Zary return;
412c3f45d32SOndrej Zary
413c3f45d32SOndrej Zary mode = dr32(ASICCtrl);
414c3f45d32SOndrej Zary mode &= ~(IPG_AC_LED_MODE_BIT_1 | IPG_AC_LED_MODE | IPG_AC_LED_SPEED);
415c3f45d32SOndrej Zary
416c3f45d32SOndrej Zary if (np->led_mode & 0x01)
417c3f45d32SOndrej Zary mode |= IPG_AC_LED_MODE;
418c3f45d32SOndrej Zary if (np->led_mode & 0x02)
419c3f45d32SOndrej Zary mode |= IPG_AC_LED_MODE_BIT_1;
420c3f45d32SOndrej Zary if (np->led_mode & 0x08)
421c3f45d32SOndrej Zary mode |= IPG_AC_LED_SPEED;
422c3f45d32SOndrej Zary
423c3f45d32SOndrej Zary dw32(ASICCtrl, mode);
424c3f45d32SOndrej Zary }
425c3f45d32SOndrej Zary
desc_to_dma(struct netdev_desc * desc)42639536ff8SOndrej Zary static inline dma_addr_t desc_to_dma(struct netdev_desc *desc)
42739536ff8SOndrej Zary {
42839536ff8SOndrej Zary return le64_to_cpu(desc->fraginfo) & DMA_BIT_MASK(48);
42939536ff8SOndrej Zary }
43039536ff8SOndrej Zary
free_list(struct net_device * dev)43139536ff8SOndrej Zary static void free_list(struct net_device *dev)
43239536ff8SOndrej Zary {
43339536ff8SOndrej Zary struct netdev_private *np = netdev_priv(dev);
43439536ff8SOndrej Zary struct sk_buff *skb;
43539536ff8SOndrej Zary int i;
43639536ff8SOndrej Zary
43739536ff8SOndrej Zary /* Free all the skbuffs in the queue. */
43839536ff8SOndrej Zary for (i = 0; i < RX_RING_SIZE; i++) {
43939536ff8SOndrej Zary skb = np->rx_skbuff[i];
44039536ff8SOndrej Zary if (skb) {
441b49db89eSChristophe JAILLET dma_unmap_single(&np->pdev->dev,
442b49db89eSChristophe JAILLET desc_to_dma(&np->rx_ring[i]),
443b49db89eSChristophe JAILLET skb->len, DMA_FROM_DEVICE);
44439536ff8SOndrej Zary dev_kfree_skb(skb);
44539536ff8SOndrej Zary np->rx_skbuff[i] = NULL;
44639536ff8SOndrej Zary }
44739536ff8SOndrej Zary np->rx_ring[i].status = 0;
44839536ff8SOndrej Zary np->rx_ring[i].fraginfo = 0;
44939536ff8SOndrej Zary }
45039536ff8SOndrej Zary for (i = 0; i < TX_RING_SIZE; i++) {
45139536ff8SOndrej Zary skb = np->tx_skbuff[i];
45239536ff8SOndrej Zary if (skb) {
453b49db89eSChristophe JAILLET dma_unmap_single(&np->pdev->dev,
454b49db89eSChristophe JAILLET desc_to_dma(&np->tx_ring[i]),
455b49db89eSChristophe JAILLET skb->len, DMA_TO_DEVICE);
45639536ff8SOndrej Zary dev_kfree_skb(skb);
45739536ff8SOndrej Zary np->tx_skbuff[i] = NULL;
45839536ff8SOndrej Zary }
45939536ff8SOndrej Zary }
46039536ff8SOndrej Zary }
46139536ff8SOndrej Zary
rio_reset_ring(struct netdev_private * np)4621777ddb8SOndrej Zary static void rio_reset_ring(struct netdev_private *np)
4631777ddb8SOndrej Zary {
4641777ddb8SOndrej Zary int i;
4651777ddb8SOndrej Zary
4661777ddb8SOndrej Zary np->cur_rx = 0;
4671777ddb8SOndrej Zary np->cur_tx = 0;
4681777ddb8SOndrej Zary np->old_rx = 0;
4691777ddb8SOndrej Zary np->old_tx = 0;
4701777ddb8SOndrej Zary
4711777ddb8SOndrej Zary for (i = 0; i < TX_RING_SIZE; i++)
4721777ddb8SOndrej Zary np->tx_ring[i].status = cpu_to_le64(TFDDone);
4731777ddb8SOndrej Zary
4741777ddb8SOndrej Zary for (i = 0; i < RX_RING_SIZE; i++)
4751777ddb8SOndrej Zary np->rx_ring[i].status = 0;
4761777ddb8SOndrej Zary }
4771777ddb8SOndrej Zary
47839536ff8SOndrej Zary /* allocate and initialize Tx and Rx descriptors */
alloc_list(struct net_device * dev)47939536ff8SOndrej Zary static int alloc_list(struct net_device *dev)
48039536ff8SOndrej Zary {
48139536ff8SOndrej Zary struct netdev_private *np = netdev_priv(dev);
48239536ff8SOndrej Zary int i;
48339536ff8SOndrej Zary
4841777ddb8SOndrej Zary rio_reset_ring(np);
48539536ff8SOndrej Zary np->rx_buf_sz = (dev->mtu <= 1500 ? PACKET_SIZE : dev->mtu + 32);
48639536ff8SOndrej Zary
48739536ff8SOndrej Zary /* Initialize Tx descriptors, TFDListPtr leaves in start_xmit(). */
48839536ff8SOndrej Zary for (i = 0; i < TX_RING_SIZE; i++) {
48939536ff8SOndrej Zary np->tx_skbuff[i] = NULL;
49039536ff8SOndrej Zary np->tx_ring[i].next_desc = cpu_to_le64(np->tx_ring_dma +
49139536ff8SOndrej Zary ((i + 1) % TX_RING_SIZE) *
49239536ff8SOndrej Zary sizeof(struct netdev_desc));
49339536ff8SOndrej Zary }
49439536ff8SOndrej Zary
4951777ddb8SOndrej Zary /* Initialize Rx descriptors & allocate buffers */
49639536ff8SOndrej Zary for (i = 0; i < RX_RING_SIZE; i++) {
49739536ff8SOndrej Zary /* Allocated fixed size of skbuff */
49839536ff8SOndrej Zary struct sk_buff *skb;
49939536ff8SOndrej Zary
50039536ff8SOndrej Zary skb = netdev_alloc_skb_ip_align(dev, np->rx_buf_sz);
50139536ff8SOndrej Zary np->rx_skbuff[i] = skb;
50239536ff8SOndrej Zary if (!skb) {
50339536ff8SOndrej Zary free_list(dev);
50439536ff8SOndrej Zary return -ENOMEM;
50539536ff8SOndrej Zary }
50639536ff8SOndrej Zary
5071777ddb8SOndrej Zary np->rx_ring[i].next_desc = cpu_to_le64(np->rx_ring_dma +
5081777ddb8SOndrej Zary ((i + 1) % RX_RING_SIZE) *
5091777ddb8SOndrej Zary sizeof(struct netdev_desc));
51039536ff8SOndrej Zary /* Rubicon now supports 40 bits of addressing space. */
51139536ff8SOndrej Zary np->rx_ring[i].fraginfo =
512b49db89eSChristophe JAILLET cpu_to_le64(dma_map_single(&np->pdev->dev, skb->data,
513b49db89eSChristophe JAILLET np->rx_buf_sz, DMA_FROM_DEVICE));
51439536ff8SOndrej Zary np->rx_ring[i].fraginfo |= cpu_to_le64((u64)np->rx_buf_sz << 48);
51539536ff8SOndrej Zary }
51639536ff8SOndrej Zary
51739536ff8SOndrej Zary return 0;
51839536ff8SOndrej Zary }
51939536ff8SOndrej Zary
rio_hw_init(struct net_device * dev)520966e07f4SOndrej Zary static void rio_hw_init(struct net_device *dev)
5213401299aSJeff Kirsher {
5223401299aSJeff Kirsher struct netdev_private *np = netdev_priv(dev);
5235e3cc4e3SFrancois Romieu void __iomem *ioaddr = np->ioaddr;
5243401299aSJeff Kirsher int i;
5253401299aSJeff Kirsher u16 macctrl;
5263401299aSJeff Kirsher
5273401299aSJeff Kirsher /* Reset all logic functions */
5285e3cc4e3SFrancois Romieu dw16(ASICCtrl + 2,
5295e3cc4e3SFrancois Romieu GlobalReset | DMAReset | FIFOReset | NetworkReset | HostReset);
5303401299aSJeff Kirsher mdelay(10);
5313401299aSJeff Kirsher
532c3f45d32SOndrej Zary rio_set_led_mode(dev);
533c3f45d32SOndrej Zary
5343401299aSJeff Kirsher /* DebugCtrl bit 4, 5, 9 must set */
5355e3cc4e3SFrancois Romieu dw32(DebugCtrl, dr32(DebugCtrl) | 0x0230);
5363401299aSJeff Kirsher
537966e07f4SOndrej Zary if (np->chip_id == CHIP_IP1000A &&
538966e07f4SOndrej Zary (np->pdev->revision == 0x40 || np->pdev->revision == 0x41)) {
539966e07f4SOndrej Zary /* PHY magic taken from ipg driver, undocumented registers */
540966e07f4SOndrej Zary mii_write(dev, np->phy_addr, 31, 0x0001);
541966e07f4SOndrej Zary mii_write(dev, np->phy_addr, 27, 0x01e0);
542966e07f4SOndrej Zary mii_write(dev, np->phy_addr, 31, 0x0002);
543966e07f4SOndrej Zary mii_write(dev, np->phy_addr, 27, 0xeb8e);
544966e07f4SOndrej Zary mii_write(dev, np->phy_addr, 31, 0x0000);
545966e07f4SOndrej Zary mii_write(dev, np->phy_addr, 30, 0x005e);
546966e07f4SOndrej Zary /* advertise 1000BASE-T half & full duplex, prefer MASTER */
547966e07f4SOndrej Zary mii_write(dev, np->phy_addr, MII_CTRL1000, 0x0700);
548966e07f4SOndrej Zary }
549966e07f4SOndrej Zary
550966e07f4SOndrej Zary if (np->phy_media)
551966e07f4SOndrej Zary mii_set_media_pcs(dev);
552966e07f4SOndrej Zary else
553966e07f4SOndrej Zary mii_set_media(dev);
554966e07f4SOndrej Zary
5553401299aSJeff Kirsher /* Jumbo frame */
5563401299aSJeff Kirsher if (np->jumbo != 0)
5575e3cc4e3SFrancois Romieu dw16(MaxFrameSize, MAX_JUMBO+14);
5583401299aSJeff Kirsher
55939536ff8SOndrej Zary /* Set RFDListPtr */
56039536ff8SOndrej Zary dw32(RFDListPtr0, np->rx_ring_dma);
56139536ff8SOndrej Zary dw32(RFDListPtr1, 0);
5623401299aSJeff Kirsher
563c3f45d32SOndrej Zary /* Set station address */
564c3f45d32SOndrej Zary /* 16 or 32-bit access is required by TC9020 datasheet but 8-bit works
565c3f45d32SOndrej Zary * too. However, it doesn't work on IP1000A so we use 16-bit access.
566c3f45d32SOndrej Zary */
567c3f45d32SOndrej Zary for (i = 0; i < 3; i++)
568c3f45d32SOndrej Zary dw16(StationAddr0 + 2 * i,
56976660757SJakub Kicinski cpu_to_le16(((const u16 *)dev->dev_addr)[i]));
5703401299aSJeff Kirsher
5713401299aSJeff Kirsher set_multicast (dev);
5723401299aSJeff Kirsher if (np->coalesce) {
5735e3cc4e3SFrancois Romieu dw32(RxDMAIntCtrl, np->rx_coalesce | np->rx_timeout << 16);
5743401299aSJeff Kirsher }
5753401299aSJeff Kirsher /* Set RIO to poll every N*320nsec. */
5765e3cc4e3SFrancois Romieu dw8(RxDMAPollPeriod, 0x20);
5775e3cc4e3SFrancois Romieu dw8(TxDMAPollPeriod, 0xff);
5785e3cc4e3SFrancois Romieu dw8(RxDMABurstThresh, 0x30);
5795e3cc4e3SFrancois Romieu dw8(RxDMAUrgentThresh, 0x30);
5805e3cc4e3SFrancois Romieu dw32(RmonStatMask, 0x0007ffff);
5813401299aSJeff Kirsher /* clear statistics */
5823401299aSJeff Kirsher clear_stats (dev);
5833401299aSJeff Kirsher
5843401299aSJeff Kirsher /* VLAN supported */
5853401299aSJeff Kirsher if (np->vlan) {
5863401299aSJeff Kirsher /* priority field in RxDMAIntCtrl */
5875e3cc4e3SFrancois Romieu dw32(RxDMAIntCtrl, dr32(RxDMAIntCtrl) | 0x7 << 10);
5883401299aSJeff Kirsher /* VLANId */
5895e3cc4e3SFrancois Romieu dw16(VLANId, np->vlan);
5903401299aSJeff Kirsher /* Length/Type should be 0x8100 */
5915e3cc4e3SFrancois Romieu dw32(VLANTag, 0x8100 << 16 | np->vlan);
5923401299aSJeff Kirsher /* Enable AutoVLANuntagging, but disable AutoVLANtagging.
5933401299aSJeff Kirsher VLAN information tagged by TFC' VID, CFI fields. */
5945e3cc4e3SFrancois Romieu dw32(MACCtrl, dr32(MACCtrl) | AutoVLANuntagging);
5953401299aSJeff Kirsher }
5963401299aSJeff Kirsher
5973401299aSJeff Kirsher /* Start Tx/Rx */
5985e3cc4e3SFrancois Romieu dw32(MACCtrl, dr32(MACCtrl) | StatsEnable | RxEnable | TxEnable);
5993401299aSJeff Kirsher
6003401299aSJeff Kirsher macctrl = 0;
6013401299aSJeff Kirsher macctrl |= (np->vlan) ? AutoVLANuntagging : 0;
6023401299aSJeff Kirsher macctrl |= (np->full_duplex) ? DuplexSelect : 0;
6033401299aSJeff Kirsher macctrl |= (np->tx_flow) ? TxFlowControlEnable : 0;
6043401299aSJeff Kirsher macctrl |= (np->rx_flow) ? RxFlowControlEnable : 0;
6055e3cc4e3SFrancois Romieu dw16(MACCtrl, macctrl);
606966e07f4SOndrej Zary }
607966e07f4SOndrej Zary
rio_hw_stop(struct net_device * dev)608966e07f4SOndrej Zary static void rio_hw_stop(struct net_device *dev)
609966e07f4SOndrej Zary {
610966e07f4SOndrej Zary struct netdev_private *np = netdev_priv(dev);
611966e07f4SOndrej Zary void __iomem *ioaddr = np->ioaddr;
612966e07f4SOndrej Zary
613966e07f4SOndrej Zary /* Disable interrupts */
614966e07f4SOndrej Zary dw16(IntEnable, 0);
615966e07f4SOndrej Zary
616966e07f4SOndrej Zary /* Stop Tx and Rx logics */
617966e07f4SOndrej Zary dw32(MACCtrl, TxDisable | RxDisable | StatsDisable);
618966e07f4SOndrej Zary }
619966e07f4SOndrej Zary
rio_open(struct net_device * dev)620966e07f4SOndrej Zary static int rio_open(struct net_device *dev)
621966e07f4SOndrej Zary {
622966e07f4SOndrej Zary struct netdev_private *np = netdev_priv(dev);
623966e07f4SOndrej Zary const int irq = np->pdev->irq;
624966e07f4SOndrej Zary int i;
625966e07f4SOndrej Zary
626966e07f4SOndrej Zary i = alloc_list(dev);
627966e07f4SOndrej Zary if (i)
628966e07f4SOndrej Zary return i;
629966e07f4SOndrej Zary
630966e07f4SOndrej Zary rio_hw_init(dev);
631966e07f4SOndrej Zary
632966e07f4SOndrej Zary i = request_irq(irq, rio_interrupt, IRQF_SHARED, dev->name, dev);
633966e07f4SOndrej Zary if (i) {
634966e07f4SOndrej Zary rio_hw_stop(dev);
635966e07f4SOndrej Zary free_list(dev);
636966e07f4SOndrej Zary return i;
637966e07f4SOndrej Zary }
638966e07f4SOndrej Zary
6396fa35bd0SKees Cook timer_setup(&np->timer, rio_timer, 0);
640966e07f4SOndrej Zary np->timer.expires = jiffies + 1 * HZ;
641966e07f4SOndrej Zary add_timer(&np->timer);
6423401299aSJeff Kirsher
6433401299aSJeff Kirsher netif_start_queue (dev);
6443401299aSJeff Kirsher
6455e3cc4e3SFrancois Romieu dl2k_enable_int(np);
6463401299aSJeff Kirsher return 0;
6473401299aSJeff Kirsher }
6483401299aSJeff Kirsher
6493401299aSJeff Kirsher static void
rio_timer(struct timer_list * t)6506fa35bd0SKees Cook rio_timer (struct timer_list *t)
6513401299aSJeff Kirsher {
6526fa35bd0SKees Cook struct netdev_private *np = from_timer(np, t, timer);
6536fa35bd0SKees Cook struct net_device *dev = pci_get_drvdata(np->pdev);
6543401299aSJeff Kirsher unsigned int entry;
6553401299aSJeff Kirsher int next_tick = 1*HZ;
6563401299aSJeff Kirsher unsigned long flags;
6573401299aSJeff Kirsher
6583401299aSJeff Kirsher spin_lock_irqsave(&np->rx_lock, flags);
6593401299aSJeff Kirsher /* Recover rx ring exhausted error */
6603401299aSJeff Kirsher if (np->cur_rx - np->old_rx >= RX_RING_SIZE) {
6613401299aSJeff Kirsher printk(KERN_INFO "Try to recover rx ring exhausted...\n");
6623401299aSJeff Kirsher /* Re-allocate skbuffs to fill the descriptor ring */
6633401299aSJeff Kirsher for (; np->cur_rx - np->old_rx > 0; np->old_rx++) {
6643401299aSJeff Kirsher struct sk_buff *skb;
6653401299aSJeff Kirsher entry = np->old_rx % RX_RING_SIZE;
6663401299aSJeff Kirsher /* Dropped packets don't need to re-allocate */
6673401299aSJeff Kirsher if (np->rx_skbuff[entry] == NULL) {
6683401299aSJeff Kirsher skb = netdev_alloc_skb_ip_align(dev,
6693401299aSJeff Kirsher np->rx_buf_sz);
6703401299aSJeff Kirsher if (skb == NULL) {
6713401299aSJeff Kirsher np->rx_ring[entry].fraginfo = 0;
6723401299aSJeff Kirsher printk (KERN_INFO
6733401299aSJeff Kirsher "%s: Still unable to re-allocate Rx skbuff.#%d\n",
6743401299aSJeff Kirsher dev->name, entry);
6753401299aSJeff Kirsher break;
6763401299aSJeff Kirsher }
6773401299aSJeff Kirsher np->rx_skbuff[entry] = skb;
6783401299aSJeff Kirsher np->rx_ring[entry].fraginfo =
679b49db89eSChristophe JAILLET cpu_to_le64 (dma_map_single(&np->pdev->dev, skb->data,
680b49db89eSChristophe JAILLET np->rx_buf_sz, DMA_FROM_DEVICE));
6813401299aSJeff Kirsher }
6823401299aSJeff Kirsher np->rx_ring[entry].fraginfo |=
6833401299aSJeff Kirsher cpu_to_le64((u64)np->rx_buf_sz << 48);
6843401299aSJeff Kirsher np->rx_ring[entry].status = 0;
6853401299aSJeff Kirsher } /* end for */
6863401299aSJeff Kirsher } /* end if */
6873401299aSJeff Kirsher spin_unlock_irqrestore (&np->rx_lock, flags);
6883401299aSJeff Kirsher np->timer.expires = jiffies + next_tick;
6893401299aSJeff Kirsher add_timer(&np->timer);
6903401299aSJeff Kirsher }
6913401299aSJeff Kirsher
6923401299aSJeff Kirsher static void
rio_tx_timeout(struct net_device * dev,unsigned int txqueue)6930290bd29SMichael S. Tsirkin rio_tx_timeout (struct net_device *dev, unsigned int txqueue)
6943401299aSJeff Kirsher {
6955e3cc4e3SFrancois Romieu struct netdev_private *np = netdev_priv(dev);
6965e3cc4e3SFrancois Romieu void __iomem *ioaddr = np->ioaddr;
6973401299aSJeff Kirsher
6983401299aSJeff Kirsher printk (KERN_INFO "%s: Tx timed out (%4.4x), is buffer full?\n",
6995e3cc4e3SFrancois Romieu dev->name, dr32(TxStatus));
7003401299aSJeff Kirsher rio_free_tx(dev, 0);
7013401299aSJeff Kirsher dev->if_port = 0;
702860e9538SFlorian Westphal netif_trans_update(dev); /* prevent tx timeout */
7033401299aSJeff Kirsher }
7043401299aSJeff Kirsher
7053401299aSJeff Kirsher static netdev_tx_t
start_xmit(struct sk_buff * skb,struct net_device * dev)7063401299aSJeff Kirsher start_xmit (struct sk_buff *skb, struct net_device *dev)
7073401299aSJeff Kirsher {
7083401299aSJeff Kirsher struct netdev_private *np = netdev_priv(dev);
7095e3cc4e3SFrancois Romieu void __iomem *ioaddr = np->ioaddr;
7103401299aSJeff Kirsher struct netdev_desc *txdesc;
7113401299aSJeff Kirsher unsigned entry;
7123401299aSJeff Kirsher u64 tfc_vlan_tag = 0;
7133401299aSJeff Kirsher
7143401299aSJeff Kirsher if (np->link_status == 0) { /* Link Down */
7153401299aSJeff Kirsher dev_kfree_skb(skb);
7163401299aSJeff Kirsher return NETDEV_TX_OK;
7173401299aSJeff Kirsher }
7183401299aSJeff Kirsher entry = np->cur_tx % TX_RING_SIZE;
7193401299aSJeff Kirsher np->tx_skbuff[entry] = skb;
7203401299aSJeff Kirsher txdesc = &np->tx_ring[entry];
7213401299aSJeff Kirsher
7223401299aSJeff Kirsher #if 0
7233401299aSJeff Kirsher if (skb->ip_summed == CHECKSUM_PARTIAL) {
7243401299aSJeff Kirsher txdesc->status |=
7253401299aSJeff Kirsher cpu_to_le64 (TCPChecksumEnable | UDPChecksumEnable |
7263401299aSJeff Kirsher IPChecksumEnable);
7273401299aSJeff Kirsher }
7283401299aSJeff Kirsher #endif
7293401299aSJeff Kirsher if (np->vlan) {
7303401299aSJeff Kirsher tfc_vlan_tag = VLANTagInsert |
7313401299aSJeff Kirsher ((u64)np->vlan << 32) |
7323401299aSJeff Kirsher ((u64)skb->priority << 45);
7333401299aSJeff Kirsher }
734b49db89eSChristophe JAILLET txdesc->fraginfo = cpu_to_le64 (dma_map_single(&np->pdev->dev, skb->data,
735b49db89eSChristophe JAILLET skb->len, DMA_TO_DEVICE));
7363401299aSJeff Kirsher txdesc->fraginfo |= cpu_to_le64((u64)skb->len << 48);
7373401299aSJeff Kirsher
7383401299aSJeff Kirsher /* DL2K bug: DMA fails to get next descriptor ptr in 10Mbps mode
7393401299aSJeff Kirsher * Work around: Always use 1 descriptor in 10Mbps mode */
7403401299aSJeff Kirsher if (entry % np->tx_coalesce == 0 || np->speed == 10)
7413401299aSJeff Kirsher txdesc->status = cpu_to_le64 (entry | tfc_vlan_tag |
7423401299aSJeff Kirsher WordAlignDisable |
7433401299aSJeff Kirsher TxDMAIndicate |
7443401299aSJeff Kirsher (1 << FragCountShift));
7453401299aSJeff Kirsher else
7463401299aSJeff Kirsher txdesc->status = cpu_to_le64 (entry | tfc_vlan_tag |
7473401299aSJeff Kirsher WordAlignDisable |
7483401299aSJeff Kirsher (1 << FragCountShift));
7493401299aSJeff Kirsher
7503401299aSJeff Kirsher /* TxDMAPollNow */
7515e3cc4e3SFrancois Romieu dw32(DMACtrl, dr32(DMACtrl) | 0x00001000);
7523401299aSJeff Kirsher /* Schedule ISR */
7535e3cc4e3SFrancois Romieu dw32(CountDown, 10000);
7543401299aSJeff Kirsher np->cur_tx = (np->cur_tx + 1) % TX_RING_SIZE;
7553401299aSJeff Kirsher if ((np->cur_tx - np->old_tx + TX_RING_SIZE) % TX_RING_SIZE
7563401299aSJeff Kirsher < TX_QUEUE_LEN - 1 && np->speed != 10) {
7573401299aSJeff Kirsher /* do nothing */
7583401299aSJeff Kirsher } else if (!netif_queue_stopped(dev)) {
7593401299aSJeff Kirsher netif_stop_queue (dev);
7603401299aSJeff Kirsher }
7613401299aSJeff Kirsher
7623401299aSJeff Kirsher /* The first TFDListPtr */
7635e3cc4e3SFrancois Romieu if (!dr32(TFDListPtr0)) {
7645e3cc4e3SFrancois Romieu dw32(TFDListPtr0, np->tx_ring_dma +
7655e3cc4e3SFrancois Romieu entry * sizeof (struct netdev_desc));
7665e3cc4e3SFrancois Romieu dw32(TFDListPtr1, 0);
7673401299aSJeff Kirsher }
7683401299aSJeff Kirsher
7693401299aSJeff Kirsher return NETDEV_TX_OK;
7703401299aSJeff Kirsher }
7713401299aSJeff Kirsher
7723401299aSJeff Kirsher static irqreturn_t
rio_interrupt(int irq,void * dev_instance)7733401299aSJeff Kirsher rio_interrupt (int irq, void *dev_instance)
7743401299aSJeff Kirsher {
7753401299aSJeff Kirsher struct net_device *dev = dev_instance;
7765e3cc4e3SFrancois Romieu struct netdev_private *np = netdev_priv(dev);
7775e3cc4e3SFrancois Romieu void __iomem *ioaddr = np->ioaddr;
7783401299aSJeff Kirsher unsigned int_status;
7793401299aSJeff Kirsher int cnt = max_intrloop;
7803401299aSJeff Kirsher int handled = 0;
7813401299aSJeff Kirsher
7823401299aSJeff Kirsher while (1) {
7835e3cc4e3SFrancois Romieu int_status = dr16(IntStatus);
7845e3cc4e3SFrancois Romieu dw16(IntStatus, int_status);
7853401299aSJeff Kirsher int_status &= DEFAULT_INTR;
7863401299aSJeff Kirsher if (int_status == 0 || --cnt < 0)
7873401299aSJeff Kirsher break;
7883401299aSJeff Kirsher handled = 1;
7893401299aSJeff Kirsher /* Processing received packets */
7903401299aSJeff Kirsher if (int_status & RxDMAComplete)
7913401299aSJeff Kirsher receive_packet (dev);
7923401299aSJeff Kirsher /* TxDMAComplete interrupt */
7933401299aSJeff Kirsher if ((int_status & (TxDMAComplete|IntRequested))) {
7943401299aSJeff Kirsher int tx_status;
7955e3cc4e3SFrancois Romieu tx_status = dr32(TxStatus);
7963401299aSJeff Kirsher if (tx_status & 0x01)
7973401299aSJeff Kirsher tx_error (dev, tx_status);
7983401299aSJeff Kirsher /* Free used tx skbuffs */
7993401299aSJeff Kirsher rio_free_tx (dev, 1);
8003401299aSJeff Kirsher }
8013401299aSJeff Kirsher
8023401299aSJeff Kirsher /* Handle uncommon events */
8033401299aSJeff Kirsher if (int_status &
8043401299aSJeff Kirsher (HostError | LinkEvent | UpdateStats))
8053401299aSJeff Kirsher rio_error (dev, int_status);
8063401299aSJeff Kirsher }
8073401299aSJeff Kirsher if (np->cur_tx != np->old_tx)
8085e3cc4e3SFrancois Romieu dw32(CountDown, 100);
8093401299aSJeff Kirsher return IRQ_RETVAL(handled);
8103401299aSJeff Kirsher }
8113401299aSJeff Kirsher
8123401299aSJeff Kirsher static void
rio_free_tx(struct net_device * dev,int irq)8133401299aSJeff Kirsher rio_free_tx (struct net_device *dev, int irq)
8143401299aSJeff Kirsher {
8153401299aSJeff Kirsher struct netdev_private *np = netdev_priv(dev);
8163401299aSJeff Kirsher int entry = np->old_tx % TX_RING_SIZE;
8173401299aSJeff Kirsher unsigned long flag = 0;
8183401299aSJeff Kirsher
8193401299aSJeff Kirsher if (irq)
8203401299aSJeff Kirsher spin_lock(&np->tx_lock);
8213401299aSJeff Kirsher else
8223401299aSJeff Kirsher spin_lock_irqsave(&np->tx_lock, flag);
8233401299aSJeff Kirsher
8243401299aSJeff Kirsher /* Free used tx skbuffs */
8253401299aSJeff Kirsher while (entry != np->cur_tx) {
8263401299aSJeff Kirsher struct sk_buff *skb;
8273401299aSJeff Kirsher
8283401299aSJeff Kirsher if (!(np->tx_ring[entry].status & cpu_to_le64(TFDDone)))
8293401299aSJeff Kirsher break;
8303401299aSJeff Kirsher skb = np->tx_skbuff[entry];
831b49db89eSChristophe JAILLET dma_unmap_single(&np->pdev->dev,
832b49db89eSChristophe JAILLET desc_to_dma(&np->tx_ring[entry]), skb->len,
833b49db89eSChristophe JAILLET DMA_TO_DEVICE);
8343401299aSJeff Kirsher if (irq)
83562f25898SHuang Zijiang dev_consume_skb_irq(skb);
8363401299aSJeff Kirsher else
8373401299aSJeff Kirsher dev_kfree_skb(skb);
8383401299aSJeff Kirsher
8393401299aSJeff Kirsher np->tx_skbuff[entry] = NULL;
8403401299aSJeff Kirsher entry = (entry + 1) % TX_RING_SIZE;
8413401299aSJeff Kirsher }
8423401299aSJeff Kirsher if (irq)
8433401299aSJeff Kirsher spin_unlock(&np->tx_lock);
8443401299aSJeff Kirsher else
8453401299aSJeff Kirsher spin_unlock_irqrestore(&np->tx_lock, flag);
8463401299aSJeff Kirsher np->old_tx = entry;
8473401299aSJeff Kirsher
8483401299aSJeff Kirsher /* If the ring is no longer full, clear tx_full and
8493401299aSJeff Kirsher call netif_wake_queue() */
8503401299aSJeff Kirsher
8513401299aSJeff Kirsher if (netif_queue_stopped(dev) &&
8523401299aSJeff Kirsher ((np->cur_tx - np->old_tx + TX_RING_SIZE) % TX_RING_SIZE
8533401299aSJeff Kirsher < TX_QUEUE_LEN - 1 || np->speed == 10)) {
8543401299aSJeff Kirsher netif_wake_queue (dev);
8553401299aSJeff Kirsher }
8563401299aSJeff Kirsher }
8573401299aSJeff Kirsher
8583401299aSJeff Kirsher static void
tx_error(struct net_device * dev,int tx_status)8593401299aSJeff Kirsher tx_error (struct net_device *dev, int tx_status)
8603401299aSJeff Kirsher {
8615e3cc4e3SFrancois Romieu struct netdev_private *np = netdev_priv(dev);
8625e3cc4e3SFrancois Romieu void __iomem *ioaddr = np->ioaddr;
8633401299aSJeff Kirsher int frame_id;
8643401299aSJeff Kirsher int i;
8653401299aSJeff Kirsher
8663401299aSJeff Kirsher frame_id = (tx_status & 0xffff0000);
8673401299aSJeff Kirsher printk (KERN_ERR "%s: Transmit error, TxStatus %4.4x, FrameId %d.\n",
8683401299aSJeff Kirsher dev->name, tx_status, frame_id);
869a548779bSTobias Klauser dev->stats.tx_errors++;
8703401299aSJeff Kirsher /* Ttransmit Underrun */
8713401299aSJeff Kirsher if (tx_status & 0x10) {
872a548779bSTobias Klauser dev->stats.tx_fifo_errors++;
8735e3cc4e3SFrancois Romieu dw16(TxStartThresh, dr16(TxStartThresh) + 0x10);
8743401299aSJeff Kirsher /* Transmit Underrun need to set TxReset, DMARest, FIFOReset */
8755e3cc4e3SFrancois Romieu dw16(ASICCtrl + 2,
8765e3cc4e3SFrancois Romieu TxReset | DMAReset | FIFOReset | NetworkReset);
8773401299aSJeff Kirsher /* Wait for ResetBusy bit clear */
8783401299aSJeff Kirsher for (i = 50; i > 0; i--) {
8795e3cc4e3SFrancois Romieu if (!(dr16(ASICCtrl + 2) & ResetBusy))
8803401299aSJeff Kirsher break;
8813401299aSJeff Kirsher mdelay (1);
8823401299aSJeff Kirsher }
883c3f45d32SOndrej Zary rio_set_led_mode(dev);
8843401299aSJeff Kirsher rio_free_tx (dev, 1);
8853401299aSJeff Kirsher /* Reset TFDListPtr */
8865e3cc4e3SFrancois Romieu dw32(TFDListPtr0, np->tx_ring_dma +
8875e3cc4e3SFrancois Romieu np->old_tx * sizeof (struct netdev_desc));
8885e3cc4e3SFrancois Romieu dw32(TFDListPtr1, 0);
8893401299aSJeff Kirsher
8903401299aSJeff Kirsher /* Let TxStartThresh stay default value */
8913401299aSJeff Kirsher }
8923401299aSJeff Kirsher /* Late Collision */
8933401299aSJeff Kirsher if (tx_status & 0x04) {
894a548779bSTobias Klauser dev->stats.tx_fifo_errors++;
8953401299aSJeff Kirsher /* TxReset and clear FIFO */
8965e3cc4e3SFrancois Romieu dw16(ASICCtrl + 2, TxReset | FIFOReset);
8973401299aSJeff Kirsher /* Wait reset done */
8983401299aSJeff Kirsher for (i = 50; i > 0; i--) {
8995e3cc4e3SFrancois Romieu if (!(dr16(ASICCtrl + 2) & ResetBusy))
9003401299aSJeff Kirsher break;
9013401299aSJeff Kirsher mdelay (1);
9023401299aSJeff Kirsher }
903c3f45d32SOndrej Zary rio_set_led_mode(dev);
9043401299aSJeff Kirsher /* Let TxStartThresh stay default value */
9053401299aSJeff Kirsher }
9063401299aSJeff Kirsher /* Maximum Collisions */
9073401299aSJeff Kirsher if (tx_status & 0x08)
908a548779bSTobias Klauser dev->stats.collisions++;
9093401299aSJeff Kirsher /* Restart the Tx */
9105e3cc4e3SFrancois Romieu dw32(MACCtrl, dr16(MACCtrl) | TxEnable);
9113401299aSJeff Kirsher }
9123401299aSJeff Kirsher
9133401299aSJeff Kirsher static int
receive_packet(struct net_device * dev)9143401299aSJeff Kirsher receive_packet (struct net_device *dev)
9153401299aSJeff Kirsher {
9163401299aSJeff Kirsher struct netdev_private *np = netdev_priv(dev);
9173401299aSJeff Kirsher int entry = np->cur_rx % RX_RING_SIZE;
9183401299aSJeff Kirsher int cnt = 30;
9193401299aSJeff Kirsher
9203401299aSJeff Kirsher /* If RFDDone, FrameStart and FrameEnd set, there is a new packet in. */
9213401299aSJeff Kirsher while (1) {
9223401299aSJeff Kirsher struct netdev_desc *desc = &np->rx_ring[entry];
9233401299aSJeff Kirsher int pkt_len;
9243401299aSJeff Kirsher u64 frame_status;
9253401299aSJeff Kirsher
9263401299aSJeff Kirsher if (!(desc->status & cpu_to_le64(RFDDone)) ||
9273401299aSJeff Kirsher !(desc->status & cpu_to_le64(FrameStart)) ||
9283401299aSJeff Kirsher !(desc->status & cpu_to_le64(FrameEnd)))
9293401299aSJeff Kirsher break;
9303401299aSJeff Kirsher
9313401299aSJeff Kirsher /* Chip omits the CRC. */
9323401299aSJeff Kirsher frame_status = le64_to_cpu(desc->status);
9333401299aSJeff Kirsher pkt_len = frame_status & 0xffff;
9343401299aSJeff Kirsher if (--cnt < 0)
9353401299aSJeff Kirsher break;
9363401299aSJeff Kirsher /* Update rx error statistics, drop packet. */
9373401299aSJeff Kirsher if (frame_status & RFS_Errors) {
938a548779bSTobias Klauser dev->stats.rx_errors++;
9393401299aSJeff Kirsher if (frame_status & (RxRuntFrame | RxLengthError))
940a548779bSTobias Klauser dev->stats.rx_length_errors++;
9413401299aSJeff Kirsher if (frame_status & RxFCSError)
942a548779bSTobias Klauser dev->stats.rx_crc_errors++;
9433401299aSJeff Kirsher if (frame_status & RxAlignmentError && np->speed != 1000)
944a548779bSTobias Klauser dev->stats.rx_frame_errors++;
9453401299aSJeff Kirsher if (frame_status & RxFIFOOverrun)
946a548779bSTobias Klauser dev->stats.rx_fifo_errors++;
9473401299aSJeff Kirsher } else {
9483401299aSJeff Kirsher struct sk_buff *skb;
9493401299aSJeff Kirsher
9503401299aSJeff Kirsher /* Small skbuffs for short packets */
9513401299aSJeff Kirsher if (pkt_len > copy_thresh) {
952b49db89eSChristophe JAILLET dma_unmap_single(&np->pdev->dev,
9533401299aSJeff Kirsher desc_to_dma(desc),
9543401299aSJeff Kirsher np->rx_buf_sz,
955b49db89eSChristophe JAILLET DMA_FROM_DEVICE);
9563401299aSJeff Kirsher skb_put (skb = np->rx_skbuff[entry], pkt_len);
9573401299aSJeff Kirsher np->rx_skbuff[entry] = NULL;
9583401299aSJeff Kirsher } else if ((skb = netdev_alloc_skb_ip_align(dev, pkt_len))) {
959b49db89eSChristophe JAILLET dma_sync_single_for_cpu(&np->pdev->dev,
9603401299aSJeff Kirsher desc_to_dma(desc),
9613401299aSJeff Kirsher np->rx_buf_sz,
962b49db89eSChristophe JAILLET DMA_FROM_DEVICE);
9633401299aSJeff Kirsher skb_copy_to_linear_data (skb,
9643401299aSJeff Kirsher np->rx_skbuff[entry]->data,
9653401299aSJeff Kirsher pkt_len);
9663401299aSJeff Kirsher skb_put (skb, pkt_len);
967b49db89eSChristophe JAILLET dma_sync_single_for_device(&np->pdev->dev,
9683401299aSJeff Kirsher desc_to_dma(desc),
9693401299aSJeff Kirsher np->rx_buf_sz,
970b49db89eSChristophe JAILLET DMA_FROM_DEVICE);
9713401299aSJeff Kirsher }
9723401299aSJeff Kirsher skb->protocol = eth_type_trans (skb, dev);
9733401299aSJeff Kirsher #if 0
9743401299aSJeff Kirsher /* Checksum done by hw, but csum value unavailable. */
9753401299aSJeff Kirsher if (np->pdev->pci_rev_id >= 0x0c &&
9763401299aSJeff Kirsher !(frame_status & (TCPError | UDPError | IPError))) {
9773401299aSJeff Kirsher skb->ip_summed = CHECKSUM_UNNECESSARY;
9783401299aSJeff Kirsher }
9793401299aSJeff Kirsher #endif
9803401299aSJeff Kirsher netif_rx (skb);
9813401299aSJeff Kirsher }
9823401299aSJeff Kirsher entry = (entry + 1) % RX_RING_SIZE;
9833401299aSJeff Kirsher }
9843401299aSJeff Kirsher spin_lock(&np->rx_lock);
9853401299aSJeff Kirsher np->cur_rx = entry;
9863401299aSJeff Kirsher /* Re-allocate skbuffs to fill the descriptor ring */
9873401299aSJeff Kirsher entry = np->old_rx;
9883401299aSJeff Kirsher while (entry != np->cur_rx) {
9893401299aSJeff Kirsher struct sk_buff *skb;
9903401299aSJeff Kirsher /* Dropped packets don't need to re-allocate */
9913401299aSJeff Kirsher if (np->rx_skbuff[entry] == NULL) {
9923401299aSJeff Kirsher skb = netdev_alloc_skb_ip_align(dev, np->rx_buf_sz);
9933401299aSJeff Kirsher if (skb == NULL) {
9943401299aSJeff Kirsher np->rx_ring[entry].fraginfo = 0;
9953401299aSJeff Kirsher printk (KERN_INFO
9963401299aSJeff Kirsher "%s: receive_packet: "
9973401299aSJeff Kirsher "Unable to re-allocate Rx skbuff.#%d\n",
9983401299aSJeff Kirsher dev->name, entry);
9993401299aSJeff Kirsher break;
10003401299aSJeff Kirsher }
10013401299aSJeff Kirsher np->rx_skbuff[entry] = skb;
10023401299aSJeff Kirsher np->rx_ring[entry].fraginfo =
1003b49db89eSChristophe JAILLET cpu_to_le64(dma_map_single(&np->pdev->dev, skb->data,
1004b49db89eSChristophe JAILLET np->rx_buf_sz, DMA_FROM_DEVICE));
10053401299aSJeff Kirsher }
10063401299aSJeff Kirsher np->rx_ring[entry].fraginfo |=
10073401299aSJeff Kirsher cpu_to_le64((u64)np->rx_buf_sz << 48);
10083401299aSJeff Kirsher np->rx_ring[entry].status = 0;
10093401299aSJeff Kirsher entry = (entry + 1) % RX_RING_SIZE;
10103401299aSJeff Kirsher }
10113401299aSJeff Kirsher np->old_rx = entry;
10123401299aSJeff Kirsher spin_unlock(&np->rx_lock);
10133401299aSJeff Kirsher return 0;
10143401299aSJeff Kirsher }
10153401299aSJeff Kirsher
10163401299aSJeff Kirsher static void
rio_error(struct net_device * dev,int int_status)10173401299aSJeff Kirsher rio_error (struct net_device *dev, int int_status)
10183401299aSJeff Kirsher {
10193401299aSJeff Kirsher struct netdev_private *np = netdev_priv(dev);
10205e3cc4e3SFrancois Romieu void __iomem *ioaddr = np->ioaddr;
10213401299aSJeff Kirsher u16 macctrl;
10223401299aSJeff Kirsher
10233401299aSJeff Kirsher /* Link change event */
10243401299aSJeff Kirsher if (int_status & LinkEvent) {
10253401299aSJeff Kirsher if (mii_wait_link (dev, 10) == 0) {
10263401299aSJeff Kirsher printk (KERN_INFO "%s: Link up\n", dev->name);
10273401299aSJeff Kirsher if (np->phy_media)
10283401299aSJeff Kirsher mii_get_media_pcs (dev);
10293401299aSJeff Kirsher else
10303401299aSJeff Kirsher mii_get_media (dev);
10313401299aSJeff Kirsher if (np->speed == 1000)
10323401299aSJeff Kirsher np->tx_coalesce = tx_coalesce;
10333401299aSJeff Kirsher else
10343401299aSJeff Kirsher np->tx_coalesce = 1;
10353401299aSJeff Kirsher macctrl = 0;
10363401299aSJeff Kirsher macctrl |= (np->vlan) ? AutoVLANuntagging : 0;
10373401299aSJeff Kirsher macctrl |= (np->full_duplex) ? DuplexSelect : 0;
10383401299aSJeff Kirsher macctrl |= (np->tx_flow) ?
10393401299aSJeff Kirsher TxFlowControlEnable : 0;
10403401299aSJeff Kirsher macctrl |= (np->rx_flow) ?
10413401299aSJeff Kirsher RxFlowControlEnable : 0;
10425e3cc4e3SFrancois Romieu dw16(MACCtrl, macctrl);
10433401299aSJeff Kirsher np->link_status = 1;
10443401299aSJeff Kirsher netif_carrier_on(dev);
10453401299aSJeff Kirsher } else {
10463401299aSJeff Kirsher printk (KERN_INFO "%s: Link off\n", dev->name);
10473401299aSJeff Kirsher np->link_status = 0;
10483401299aSJeff Kirsher netif_carrier_off(dev);
10493401299aSJeff Kirsher }
10503401299aSJeff Kirsher }
10513401299aSJeff Kirsher
10523401299aSJeff Kirsher /* UpdateStats statistics registers */
10533401299aSJeff Kirsher if (int_status & UpdateStats) {
10543401299aSJeff Kirsher get_stats (dev);
10553401299aSJeff Kirsher }
10563401299aSJeff Kirsher
10573401299aSJeff Kirsher /* PCI Error, a catastronphic error related to the bus interface
10583401299aSJeff Kirsher occurs, set GlobalReset and HostReset to reset. */
10593401299aSJeff Kirsher if (int_status & HostError) {
10603401299aSJeff Kirsher printk (KERN_ERR "%s: HostError! IntStatus %4.4x.\n",
10613401299aSJeff Kirsher dev->name, int_status);
10625e3cc4e3SFrancois Romieu dw16(ASICCtrl + 2, GlobalReset | HostReset);
10633401299aSJeff Kirsher mdelay (500);
1064c3f45d32SOndrej Zary rio_set_led_mode(dev);
10653401299aSJeff Kirsher }
10663401299aSJeff Kirsher }
10673401299aSJeff Kirsher
10683401299aSJeff Kirsher static struct net_device_stats *
get_stats(struct net_device * dev)10693401299aSJeff Kirsher get_stats (struct net_device *dev)
10703401299aSJeff Kirsher {
10713401299aSJeff Kirsher struct netdev_private *np = netdev_priv(dev);
10725e3cc4e3SFrancois Romieu void __iomem *ioaddr = np->ioaddr;
10733401299aSJeff Kirsher #ifdef MEM_MAPPING
10743401299aSJeff Kirsher int i;
10753401299aSJeff Kirsher #endif
10763401299aSJeff Kirsher unsigned int stat_reg;
10773401299aSJeff Kirsher
10783401299aSJeff Kirsher /* All statistics registers need to be acknowledged,
10793401299aSJeff Kirsher else statistic overflow could cause problems */
10803401299aSJeff Kirsher
1081a548779bSTobias Klauser dev->stats.rx_packets += dr32(FramesRcvOk);
1082a548779bSTobias Klauser dev->stats.tx_packets += dr32(FramesXmtOk);
1083a548779bSTobias Klauser dev->stats.rx_bytes += dr32(OctetRcvOk);
1084a548779bSTobias Klauser dev->stats.tx_bytes += dr32(OctetXmtOk);
10853401299aSJeff Kirsher
1086a548779bSTobias Klauser dev->stats.multicast = dr32(McstFramesRcvdOk);
1087a548779bSTobias Klauser dev->stats.collisions += dr32(SingleColFrames)
10885e3cc4e3SFrancois Romieu + dr32(MultiColFrames);
10893401299aSJeff Kirsher
10903401299aSJeff Kirsher /* detailed tx errors */
10915e3cc4e3SFrancois Romieu stat_reg = dr16(FramesAbortXSColls);
1092a548779bSTobias Klauser dev->stats.tx_aborted_errors += stat_reg;
1093a548779bSTobias Klauser dev->stats.tx_errors += stat_reg;
10943401299aSJeff Kirsher
10955e3cc4e3SFrancois Romieu stat_reg = dr16(CarrierSenseErrors);
1096a548779bSTobias Klauser dev->stats.tx_carrier_errors += stat_reg;
1097a548779bSTobias Klauser dev->stats.tx_errors += stat_reg;
10983401299aSJeff Kirsher
10993401299aSJeff Kirsher /* Clear all other statistic register. */
11005e3cc4e3SFrancois Romieu dr32(McstOctetXmtOk);
11015e3cc4e3SFrancois Romieu dr16(BcstFramesXmtdOk);
11025e3cc4e3SFrancois Romieu dr32(McstFramesXmtdOk);
11035e3cc4e3SFrancois Romieu dr16(BcstFramesRcvdOk);
11045e3cc4e3SFrancois Romieu dr16(MacControlFramesRcvd);
11055e3cc4e3SFrancois Romieu dr16(FrameTooLongErrors);
11065e3cc4e3SFrancois Romieu dr16(InRangeLengthErrors);
11075e3cc4e3SFrancois Romieu dr16(FramesCheckSeqErrors);
11085e3cc4e3SFrancois Romieu dr16(FramesLostRxErrors);
11095e3cc4e3SFrancois Romieu dr32(McstOctetXmtOk);
11105e3cc4e3SFrancois Romieu dr32(BcstOctetXmtOk);
11115e3cc4e3SFrancois Romieu dr32(McstFramesXmtdOk);
11125e3cc4e3SFrancois Romieu dr32(FramesWDeferredXmt);
11135e3cc4e3SFrancois Romieu dr32(LateCollisions);
11145e3cc4e3SFrancois Romieu dr16(BcstFramesXmtdOk);
11155e3cc4e3SFrancois Romieu dr16(MacControlFramesXmtd);
11165e3cc4e3SFrancois Romieu dr16(FramesWEXDeferal);
11173401299aSJeff Kirsher
11183401299aSJeff Kirsher #ifdef MEM_MAPPING
11193401299aSJeff Kirsher for (i = 0x100; i <= 0x150; i += 4)
11205e3cc4e3SFrancois Romieu dr32(i);
11213401299aSJeff Kirsher #endif
11225e3cc4e3SFrancois Romieu dr16(TxJumboFrames);
11235e3cc4e3SFrancois Romieu dr16(RxJumboFrames);
11245e3cc4e3SFrancois Romieu dr16(TCPCheckSumErrors);
11255e3cc4e3SFrancois Romieu dr16(UDPCheckSumErrors);
11265e3cc4e3SFrancois Romieu dr16(IPCheckSumErrors);
1127a548779bSTobias Klauser return &dev->stats;
11283401299aSJeff Kirsher }
11293401299aSJeff Kirsher
11303401299aSJeff Kirsher static int
clear_stats(struct net_device * dev)11313401299aSJeff Kirsher clear_stats (struct net_device *dev)
11323401299aSJeff Kirsher {
11335e3cc4e3SFrancois Romieu struct netdev_private *np = netdev_priv(dev);
11345e3cc4e3SFrancois Romieu void __iomem *ioaddr = np->ioaddr;
11353401299aSJeff Kirsher #ifdef MEM_MAPPING
11363401299aSJeff Kirsher int i;
11373401299aSJeff Kirsher #endif
11383401299aSJeff Kirsher
11393401299aSJeff Kirsher /* All statistics registers need to be acknowledged,
11403401299aSJeff Kirsher else statistic overflow could cause problems */
11415e3cc4e3SFrancois Romieu dr32(FramesRcvOk);
11425e3cc4e3SFrancois Romieu dr32(FramesXmtOk);
11435e3cc4e3SFrancois Romieu dr32(OctetRcvOk);
11445e3cc4e3SFrancois Romieu dr32(OctetXmtOk);
11453401299aSJeff Kirsher
11465e3cc4e3SFrancois Romieu dr32(McstFramesRcvdOk);
11475e3cc4e3SFrancois Romieu dr32(SingleColFrames);
11485e3cc4e3SFrancois Romieu dr32(MultiColFrames);
11495e3cc4e3SFrancois Romieu dr32(LateCollisions);
11503401299aSJeff Kirsher /* detailed rx errors */
11515e3cc4e3SFrancois Romieu dr16(FrameTooLongErrors);
11525e3cc4e3SFrancois Romieu dr16(InRangeLengthErrors);
11535e3cc4e3SFrancois Romieu dr16(FramesCheckSeqErrors);
11545e3cc4e3SFrancois Romieu dr16(FramesLostRxErrors);
11553401299aSJeff Kirsher
11563401299aSJeff Kirsher /* detailed tx errors */
11575e3cc4e3SFrancois Romieu dr16(FramesAbortXSColls);
11585e3cc4e3SFrancois Romieu dr16(CarrierSenseErrors);
11593401299aSJeff Kirsher
11603401299aSJeff Kirsher /* Clear all other statistic register. */
11615e3cc4e3SFrancois Romieu dr32(McstOctetXmtOk);
11625e3cc4e3SFrancois Romieu dr16(BcstFramesXmtdOk);
11635e3cc4e3SFrancois Romieu dr32(McstFramesXmtdOk);
11645e3cc4e3SFrancois Romieu dr16(BcstFramesRcvdOk);
11655e3cc4e3SFrancois Romieu dr16(MacControlFramesRcvd);
11665e3cc4e3SFrancois Romieu dr32(McstOctetXmtOk);
11675e3cc4e3SFrancois Romieu dr32(BcstOctetXmtOk);
11685e3cc4e3SFrancois Romieu dr32(McstFramesXmtdOk);
11695e3cc4e3SFrancois Romieu dr32(FramesWDeferredXmt);
11705e3cc4e3SFrancois Romieu dr16(BcstFramesXmtdOk);
11715e3cc4e3SFrancois Romieu dr16(MacControlFramesXmtd);
11725e3cc4e3SFrancois Romieu dr16(FramesWEXDeferal);
11733401299aSJeff Kirsher #ifdef MEM_MAPPING
11743401299aSJeff Kirsher for (i = 0x100; i <= 0x150; i += 4)
11755e3cc4e3SFrancois Romieu dr32(i);
11763401299aSJeff Kirsher #endif
11775e3cc4e3SFrancois Romieu dr16(TxJumboFrames);
11785e3cc4e3SFrancois Romieu dr16(RxJumboFrames);
11795e3cc4e3SFrancois Romieu dr16(TCPCheckSumErrors);
11805e3cc4e3SFrancois Romieu dr16(UDPCheckSumErrors);
11815e3cc4e3SFrancois Romieu dr16(IPCheckSumErrors);
11823401299aSJeff Kirsher return 0;
11833401299aSJeff Kirsher }
11843401299aSJeff Kirsher
11853401299aSJeff Kirsher static void
set_multicast(struct net_device * dev)11863401299aSJeff Kirsher set_multicast (struct net_device *dev)
11873401299aSJeff Kirsher {
11885e3cc4e3SFrancois Romieu struct netdev_private *np = netdev_priv(dev);
11895e3cc4e3SFrancois Romieu void __iomem *ioaddr = np->ioaddr;
11903401299aSJeff Kirsher u32 hash_table[2];
11913401299aSJeff Kirsher u16 rx_mode = 0;
11923401299aSJeff Kirsher
11933401299aSJeff Kirsher hash_table[0] = hash_table[1] = 0;
11943401299aSJeff Kirsher /* RxFlowcontrol DA: 01-80-C2-00-00-01. Hash index=0x39 */
11953401299aSJeff Kirsher hash_table[1] |= 0x02000000;
11963401299aSJeff Kirsher if (dev->flags & IFF_PROMISC) {
11973401299aSJeff Kirsher /* Receive all frames promiscuously. */
11983401299aSJeff Kirsher rx_mode = ReceiveAllFrames;
11993401299aSJeff Kirsher } else if ((dev->flags & IFF_ALLMULTI) ||
12003401299aSJeff Kirsher (netdev_mc_count(dev) > multicast_filter_limit)) {
12013401299aSJeff Kirsher /* Receive broadcast and multicast frames */
12023401299aSJeff Kirsher rx_mode = ReceiveBroadcast | ReceiveMulticast | ReceiveUnicast;
12033401299aSJeff Kirsher } else if (!netdev_mc_empty(dev)) {
12043401299aSJeff Kirsher struct netdev_hw_addr *ha;
12053401299aSJeff Kirsher /* Receive broadcast frames and multicast frames filtering
12063401299aSJeff Kirsher by Hashtable */
12073401299aSJeff Kirsher rx_mode =
12083401299aSJeff Kirsher ReceiveBroadcast | ReceiveMulticastHash | ReceiveUnicast;
12093401299aSJeff Kirsher netdev_for_each_mc_addr(ha, dev) {
12103401299aSJeff Kirsher int bit, index = 0;
12113401299aSJeff Kirsher int crc = ether_crc_le(ETH_ALEN, ha->addr);
12123401299aSJeff Kirsher /* The inverted high significant 6 bits of CRC are
12133401299aSJeff Kirsher used as an index to hashtable */
12143401299aSJeff Kirsher for (bit = 0; bit < 6; bit++)
12153401299aSJeff Kirsher if (crc & (1 << (31 - bit)))
12163401299aSJeff Kirsher index |= (1 << bit);
12173401299aSJeff Kirsher hash_table[index / 32] |= (1 << (index % 32));
12183401299aSJeff Kirsher }
12193401299aSJeff Kirsher } else {
12203401299aSJeff Kirsher rx_mode = ReceiveBroadcast | ReceiveUnicast;
12213401299aSJeff Kirsher }
12223401299aSJeff Kirsher if (np->vlan) {
12233401299aSJeff Kirsher /* ReceiveVLANMatch field in ReceiveMode */
12243401299aSJeff Kirsher rx_mode |= ReceiveVLANMatch;
12253401299aSJeff Kirsher }
12263401299aSJeff Kirsher
12275e3cc4e3SFrancois Romieu dw32(HashTable0, hash_table[0]);
12285e3cc4e3SFrancois Romieu dw32(HashTable1, hash_table[1]);
12295e3cc4e3SFrancois Romieu dw16(ReceiveMode, rx_mode);
12303401299aSJeff Kirsher }
12313401299aSJeff Kirsher
rio_get_drvinfo(struct net_device * dev,struct ethtool_drvinfo * info)12323401299aSJeff Kirsher static void rio_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
12333401299aSJeff Kirsher {
12343401299aSJeff Kirsher struct netdev_private *np = netdev_priv(dev);
12357826d43fSJiri Pirko
1236*f029c781SWolfram Sang strscpy(info->driver, "dl2k", sizeof(info->driver));
1237*f029c781SWolfram Sang strscpy(info->bus_info, pci_name(np->pdev), sizeof(info->bus_info));
12383401299aSJeff Kirsher }
12393401299aSJeff Kirsher
rio_get_link_ksettings(struct net_device * dev,struct ethtool_link_ksettings * cmd)124090222550SPhilippe Reynes static int rio_get_link_ksettings(struct net_device *dev,
124190222550SPhilippe Reynes struct ethtool_link_ksettings *cmd)
12423401299aSJeff Kirsher {
12433401299aSJeff Kirsher struct netdev_private *np = netdev_priv(dev);
124490222550SPhilippe Reynes u32 supported, advertising;
124590222550SPhilippe Reynes
12463401299aSJeff Kirsher if (np->phy_media) {
12473401299aSJeff Kirsher /* fiber device */
124890222550SPhilippe Reynes supported = SUPPORTED_Autoneg | SUPPORTED_FIBRE;
124990222550SPhilippe Reynes advertising = ADVERTISED_Autoneg | ADVERTISED_FIBRE;
125090222550SPhilippe Reynes cmd->base.port = PORT_FIBRE;
12513401299aSJeff Kirsher } else {
12523401299aSJeff Kirsher /* copper device */
125390222550SPhilippe Reynes supported = SUPPORTED_10baseT_Half |
12543401299aSJeff Kirsher SUPPORTED_10baseT_Full | SUPPORTED_100baseT_Half
12553401299aSJeff Kirsher | SUPPORTED_100baseT_Full | SUPPORTED_1000baseT_Full |
12563401299aSJeff Kirsher SUPPORTED_Autoneg | SUPPORTED_MII;
125790222550SPhilippe Reynes advertising = ADVERTISED_10baseT_Half |
12583401299aSJeff Kirsher ADVERTISED_10baseT_Full | ADVERTISED_100baseT_Half |
12593401299aSJeff Kirsher ADVERTISED_100baseT_Full | ADVERTISED_1000baseT_Full |
12603401299aSJeff Kirsher ADVERTISED_Autoneg | ADVERTISED_MII;
126190222550SPhilippe Reynes cmd->base.port = PORT_MII;
12623401299aSJeff Kirsher }
12633401299aSJeff Kirsher if (np->link_status) {
126490222550SPhilippe Reynes cmd->base.speed = np->speed;
126590222550SPhilippe Reynes cmd->base.duplex = np->full_duplex ? DUPLEX_FULL : DUPLEX_HALF;
12663401299aSJeff Kirsher } else {
126790222550SPhilippe Reynes cmd->base.speed = SPEED_UNKNOWN;
126890222550SPhilippe Reynes cmd->base.duplex = DUPLEX_UNKNOWN;
12693401299aSJeff Kirsher }
12703401299aSJeff Kirsher if (np->an_enable)
127190222550SPhilippe Reynes cmd->base.autoneg = AUTONEG_ENABLE;
12723401299aSJeff Kirsher else
127390222550SPhilippe Reynes cmd->base.autoneg = AUTONEG_DISABLE;
12743401299aSJeff Kirsher
127590222550SPhilippe Reynes cmd->base.phy_address = np->phy_addr;
127690222550SPhilippe Reynes
127790222550SPhilippe Reynes ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
127890222550SPhilippe Reynes supported);
127990222550SPhilippe Reynes ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
128090222550SPhilippe Reynes advertising);
128190222550SPhilippe Reynes
12823401299aSJeff Kirsher return 0;
12833401299aSJeff Kirsher }
12843401299aSJeff Kirsher
rio_set_link_ksettings(struct net_device * dev,const struct ethtool_link_ksettings * cmd)128590222550SPhilippe Reynes static int rio_set_link_ksettings(struct net_device *dev,
128690222550SPhilippe Reynes const struct ethtool_link_ksettings *cmd)
12873401299aSJeff Kirsher {
12883401299aSJeff Kirsher struct netdev_private *np = netdev_priv(dev);
128990222550SPhilippe Reynes u32 speed = cmd->base.speed;
129090222550SPhilippe Reynes u8 duplex = cmd->base.duplex;
129190222550SPhilippe Reynes
12923401299aSJeff Kirsher netif_carrier_off(dev);
129390222550SPhilippe Reynes if (cmd->base.autoneg == AUTONEG_ENABLE) {
129490222550SPhilippe Reynes if (np->an_enable) {
12953401299aSJeff Kirsher return 0;
129690222550SPhilippe Reynes } else {
12973401299aSJeff Kirsher np->an_enable = 1;
12983401299aSJeff Kirsher mii_set_media(dev);
12993401299aSJeff Kirsher return 0;
13003401299aSJeff Kirsher }
13013401299aSJeff Kirsher } else {
13023401299aSJeff Kirsher np->an_enable = 0;
13033401299aSJeff Kirsher if (np->speed == 1000) {
130490222550SPhilippe Reynes speed = SPEED_100;
130590222550SPhilippe Reynes duplex = DUPLEX_FULL;
13063401299aSJeff Kirsher printk("Warning!! Can't disable Auto negotiation in 1000Mbps, change to Manual 100Mbps, Full duplex.\n");
13073401299aSJeff Kirsher }
130890222550SPhilippe Reynes switch (speed) {
13093401299aSJeff Kirsher case SPEED_10:
13103401299aSJeff Kirsher np->speed = 10;
131190222550SPhilippe Reynes np->full_duplex = (duplex == DUPLEX_FULL);
13123401299aSJeff Kirsher break;
13133401299aSJeff Kirsher case SPEED_100:
13143401299aSJeff Kirsher np->speed = 100;
131590222550SPhilippe Reynes np->full_duplex = (duplex == DUPLEX_FULL);
13163401299aSJeff Kirsher break;
13173401299aSJeff Kirsher case SPEED_1000: /* not supported */
13183401299aSJeff Kirsher default:
13193401299aSJeff Kirsher return -EINVAL;
13203401299aSJeff Kirsher }
13213401299aSJeff Kirsher mii_set_media(dev);
13223401299aSJeff Kirsher }
13233401299aSJeff Kirsher return 0;
13243401299aSJeff Kirsher }
13253401299aSJeff Kirsher
rio_get_link(struct net_device * dev)13263401299aSJeff Kirsher static u32 rio_get_link(struct net_device *dev)
13273401299aSJeff Kirsher {
13283401299aSJeff Kirsher struct netdev_private *np = netdev_priv(dev);
13293401299aSJeff Kirsher return np->link_status;
13303401299aSJeff Kirsher }
13313401299aSJeff Kirsher
13323401299aSJeff Kirsher static const struct ethtool_ops ethtool_ops = {
13333401299aSJeff Kirsher .get_drvinfo = rio_get_drvinfo,
13343401299aSJeff Kirsher .get_link = rio_get_link,
133590222550SPhilippe Reynes .get_link_ksettings = rio_get_link_ksettings,
133690222550SPhilippe Reynes .set_link_ksettings = rio_set_link_ksettings,
13373401299aSJeff Kirsher };
13383401299aSJeff Kirsher
13393401299aSJeff Kirsher static int
rio_ioctl(struct net_device * dev,struct ifreq * rq,int cmd)13403401299aSJeff Kirsher rio_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
13413401299aSJeff Kirsher {
13423401299aSJeff Kirsher int phy_addr;
13433401299aSJeff Kirsher struct netdev_private *np = netdev_priv(dev);
13441bb57e94SJeff Mahoney struct mii_ioctl_data *miidata = if_mii(rq);
13453401299aSJeff Kirsher
13463401299aSJeff Kirsher phy_addr = np->phy_addr;
13473401299aSJeff Kirsher switch (cmd) {
13481bb57e94SJeff Mahoney case SIOCGMIIPHY:
13491bb57e94SJeff Mahoney miidata->phy_id = phy_addr;
13503401299aSJeff Kirsher break;
13511bb57e94SJeff Mahoney case SIOCGMIIREG:
13521bb57e94SJeff Mahoney miidata->val_out = mii_read (dev, phy_addr, miidata->reg_num);
13533401299aSJeff Kirsher break;
13541bb57e94SJeff Mahoney case SIOCSMIIREG:
13551bb57e94SJeff Mahoney if (!capable(CAP_NET_ADMIN))
13561bb57e94SJeff Mahoney return -EPERM;
13571bb57e94SJeff Mahoney mii_write (dev, phy_addr, miidata->reg_num, miidata->val_in);
13583401299aSJeff Kirsher break;
13593401299aSJeff Kirsher default:
13603401299aSJeff Kirsher return -EOPNOTSUPP;
13613401299aSJeff Kirsher }
13623401299aSJeff Kirsher return 0;
13633401299aSJeff Kirsher }
13643401299aSJeff Kirsher
13653401299aSJeff Kirsher #define EEP_READ 0x0200
13663401299aSJeff Kirsher #define EEP_BUSY 0x8000
13673401299aSJeff Kirsher /* Read the EEPROM word */
13683401299aSJeff Kirsher /* We use I/O instruction to read/write eeprom to avoid fail on some machines */
read_eeprom(struct netdev_private * np,int eep_addr)13695e3cc4e3SFrancois Romieu static int read_eeprom(struct netdev_private *np, int eep_addr)
13703401299aSJeff Kirsher {
13715e3cc4e3SFrancois Romieu void __iomem *ioaddr = np->eeprom_addr;
13723401299aSJeff Kirsher int i = 1000;
13735e3cc4e3SFrancois Romieu
13745e3cc4e3SFrancois Romieu dw16(EepromCtrl, EEP_READ | (eep_addr & 0xff));
13753401299aSJeff Kirsher while (i-- > 0) {
13765e3cc4e3SFrancois Romieu if (!(dr16(EepromCtrl) & EEP_BUSY))
13775e3cc4e3SFrancois Romieu return dr16(EepromData);
13783401299aSJeff Kirsher }
13793401299aSJeff Kirsher return 0;
13803401299aSJeff Kirsher }
13813401299aSJeff Kirsher
13823401299aSJeff Kirsher enum phy_ctrl_bits {
13833401299aSJeff Kirsher MII_READ = 0x00, MII_CLK = 0x01, MII_DATA1 = 0x02, MII_WRITE = 0x04,
13843401299aSJeff Kirsher MII_DUPLEX = 0x08,
13853401299aSJeff Kirsher };
13863401299aSJeff Kirsher
13875e3cc4e3SFrancois Romieu #define mii_delay() dr8(PhyCtrl)
13883401299aSJeff Kirsher static void
mii_sendbit(struct net_device * dev,u32 data)13893401299aSJeff Kirsher mii_sendbit (struct net_device *dev, u32 data)
13903401299aSJeff Kirsher {
13915e3cc4e3SFrancois Romieu struct netdev_private *np = netdev_priv(dev);
13925e3cc4e3SFrancois Romieu void __iomem *ioaddr = np->ioaddr;
13935e3cc4e3SFrancois Romieu
13945e3cc4e3SFrancois Romieu data = ((data) ? MII_DATA1 : 0) | (dr8(PhyCtrl) & 0xf8) | MII_WRITE;
13955e3cc4e3SFrancois Romieu dw8(PhyCtrl, data);
13963401299aSJeff Kirsher mii_delay ();
13975e3cc4e3SFrancois Romieu dw8(PhyCtrl, data | MII_CLK);
13983401299aSJeff Kirsher mii_delay ();
13993401299aSJeff Kirsher }
14003401299aSJeff Kirsher
14013401299aSJeff Kirsher static int
mii_getbit(struct net_device * dev)14023401299aSJeff Kirsher mii_getbit (struct net_device *dev)
14033401299aSJeff Kirsher {
14045e3cc4e3SFrancois Romieu struct netdev_private *np = netdev_priv(dev);
14055e3cc4e3SFrancois Romieu void __iomem *ioaddr = np->ioaddr;
14063401299aSJeff Kirsher u8 data;
14073401299aSJeff Kirsher
14085e3cc4e3SFrancois Romieu data = (dr8(PhyCtrl) & 0xf8) | MII_READ;
14095e3cc4e3SFrancois Romieu dw8(PhyCtrl, data);
14103401299aSJeff Kirsher mii_delay ();
14115e3cc4e3SFrancois Romieu dw8(PhyCtrl, data | MII_CLK);
14123401299aSJeff Kirsher mii_delay ();
14135e3cc4e3SFrancois Romieu return (dr8(PhyCtrl) >> 1) & 1;
14143401299aSJeff Kirsher }
14153401299aSJeff Kirsher
14163401299aSJeff Kirsher static void
mii_send_bits(struct net_device * dev,u32 data,int len)14173401299aSJeff Kirsher mii_send_bits (struct net_device *dev, u32 data, int len)
14183401299aSJeff Kirsher {
14193401299aSJeff Kirsher int i;
14205e3cc4e3SFrancois Romieu
14213401299aSJeff Kirsher for (i = len - 1; i >= 0; i--) {
14223401299aSJeff Kirsher mii_sendbit (dev, data & (1 << i));
14233401299aSJeff Kirsher }
14243401299aSJeff Kirsher }
14253401299aSJeff Kirsher
14263401299aSJeff Kirsher static int
mii_read(struct net_device * dev,int phy_addr,int reg_num)14273401299aSJeff Kirsher mii_read (struct net_device *dev, int phy_addr, int reg_num)
14283401299aSJeff Kirsher {
14293401299aSJeff Kirsher u32 cmd;
14303401299aSJeff Kirsher int i;
14313401299aSJeff Kirsher u32 retval = 0;
14323401299aSJeff Kirsher
14333401299aSJeff Kirsher /* Preamble */
14343401299aSJeff Kirsher mii_send_bits (dev, 0xffffffff, 32);
14353401299aSJeff Kirsher /* ST(2), OP(2), ADDR(5), REG#(5), TA(2), Data(16) total 32 bits */
14363401299aSJeff Kirsher /* ST,OP = 0110'b for read operation */
14373401299aSJeff Kirsher cmd = (0x06 << 10 | phy_addr << 5 | reg_num);
14383401299aSJeff Kirsher mii_send_bits (dev, cmd, 14);
14393401299aSJeff Kirsher /* Turnaround */
14403401299aSJeff Kirsher if (mii_getbit (dev))
14413401299aSJeff Kirsher goto err_out;
14423401299aSJeff Kirsher /* Read data */
14433401299aSJeff Kirsher for (i = 0; i < 16; i++) {
14443401299aSJeff Kirsher retval |= mii_getbit (dev);
14453401299aSJeff Kirsher retval <<= 1;
14463401299aSJeff Kirsher }
14473401299aSJeff Kirsher /* End cycle */
14483401299aSJeff Kirsher mii_getbit (dev);
14493401299aSJeff Kirsher return (retval >> 1) & 0xffff;
14503401299aSJeff Kirsher
14513401299aSJeff Kirsher err_out:
14523401299aSJeff Kirsher return 0;
14533401299aSJeff Kirsher }
14543401299aSJeff Kirsher static int
mii_write(struct net_device * dev,int phy_addr,int reg_num,u16 data)14553401299aSJeff Kirsher mii_write (struct net_device *dev, int phy_addr, int reg_num, u16 data)
14563401299aSJeff Kirsher {
14573401299aSJeff Kirsher u32 cmd;
14583401299aSJeff Kirsher
14593401299aSJeff Kirsher /* Preamble */
14603401299aSJeff Kirsher mii_send_bits (dev, 0xffffffff, 32);
14613401299aSJeff Kirsher /* ST(2), OP(2), ADDR(5), REG#(5), TA(2), Data(16) total 32 bits */
14623401299aSJeff Kirsher /* ST,OP,AAAAA,RRRRR,TA = 0101xxxxxxxxxx10'b = 0x5002 for write */
14633401299aSJeff Kirsher cmd = (0x5002 << 16) | (phy_addr << 23) | (reg_num << 18) | data;
14643401299aSJeff Kirsher mii_send_bits (dev, cmd, 32);
14653401299aSJeff Kirsher /* End cycle */
14663401299aSJeff Kirsher mii_getbit (dev);
14673401299aSJeff Kirsher return 0;
14683401299aSJeff Kirsher }
14693401299aSJeff Kirsher static int
mii_wait_link(struct net_device * dev,int wait)14703401299aSJeff Kirsher mii_wait_link (struct net_device *dev, int wait)
14713401299aSJeff Kirsher {
14723401299aSJeff Kirsher __u16 bmsr;
14733401299aSJeff Kirsher int phy_addr;
14743401299aSJeff Kirsher struct netdev_private *np;
14753401299aSJeff Kirsher
14763401299aSJeff Kirsher np = netdev_priv(dev);
14773401299aSJeff Kirsher phy_addr = np->phy_addr;
14783401299aSJeff Kirsher
14793401299aSJeff Kirsher do {
14803401299aSJeff Kirsher bmsr = mii_read (dev, phy_addr, MII_BMSR);
148178f6a6bdSFrancois Romieu if (bmsr & BMSR_LSTATUS)
14823401299aSJeff Kirsher return 0;
14833401299aSJeff Kirsher mdelay (1);
14843401299aSJeff Kirsher } while (--wait > 0);
14853401299aSJeff Kirsher return -1;
14863401299aSJeff Kirsher }
14873401299aSJeff Kirsher static int
mii_get_media(struct net_device * dev)14883401299aSJeff Kirsher mii_get_media (struct net_device *dev)
14893401299aSJeff Kirsher {
14903401299aSJeff Kirsher __u16 negotiate;
14913401299aSJeff Kirsher __u16 bmsr;
14923401299aSJeff Kirsher __u16 mscr;
14933401299aSJeff Kirsher __u16 mssr;
14943401299aSJeff Kirsher int phy_addr;
14953401299aSJeff Kirsher struct netdev_private *np;
14963401299aSJeff Kirsher
14973401299aSJeff Kirsher np = netdev_priv(dev);
14983401299aSJeff Kirsher phy_addr = np->phy_addr;
14993401299aSJeff Kirsher
15003401299aSJeff Kirsher bmsr = mii_read (dev, phy_addr, MII_BMSR);
15013401299aSJeff Kirsher if (np->an_enable) {
150278f6a6bdSFrancois Romieu if (!(bmsr & BMSR_ANEGCOMPLETE)) {
15033401299aSJeff Kirsher /* Auto-Negotiation not completed */
15043401299aSJeff Kirsher return -1;
15053401299aSJeff Kirsher }
150678f6a6bdSFrancois Romieu negotiate = mii_read (dev, phy_addr, MII_ADVERTISE) &
150778f6a6bdSFrancois Romieu mii_read (dev, phy_addr, MII_LPA);
150878f6a6bdSFrancois Romieu mscr = mii_read (dev, phy_addr, MII_CTRL1000);
150978f6a6bdSFrancois Romieu mssr = mii_read (dev, phy_addr, MII_STAT1000);
151078f6a6bdSFrancois Romieu if (mscr & ADVERTISE_1000FULL && mssr & LPA_1000FULL) {
15113401299aSJeff Kirsher np->speed = 1000;
15123401299aSJeff Kirsher np->full_duplex = 1;
15133401299aSJeff Kirsher printk (KERN_INFO "Auto 1000 Mbps, Full duplex\n");
151478f6a6bdSFrancois Romieu } else if (mscr & ADVERTISE_1000HALF && mssr & LPA_1000HALF) {
15153401299aSJeff Kirsher np->speed = 1000;
15163401299aSJeff Kirsher np->full_duplex = 0;
15173401299aSJeff Kirsher printk (KERN_INFO "Auto 1000 Mbps, Half duplex\n");
151878f6a6bdSFrancois Romieu } else if (negotiate & ADVERTISE_100FULL) {
15193401299aSJeff Kirsher np->speed = 100;
15203401299aSJeff Kirsher np->full_duplex = 1;
15213401299aSJeff Kirsher printk (KERN_INFO "Auto 100 Mbps, Full duplex\n");
152278f6a6bdSFrancois Romieu } else if (negotiate & ADVERTISE_100HALF) {
15233401299aSJeff Kirsher np->speed = 100;
15243401299aSJeff Kirsher np->full_duplex = 0;
15253401299aSJeff Kirsher printk (KERN_INFO "Auto 100 Mbps, Half duplex\n");
152678f6a6bdSFrancois Romieu } else if (negotiate & ADVERTISE_10FULL) {
15273401299aSJeff Kirsher np->speed = 10;
15283401299aSJeff Kirsher np->full_duplex = 1;
15293401299aSJeff Kirsher printk (KERN_INFO "Auto 10 Mbps, Full duplex\n");
153078f6a6bdSFrancois Romieu } else if (negotiate & ADVERTISE_10HALF) {
15313401299aSJeff Kirsher np->speed = 10;
15323401299aSJeff Kirsher np->full_duplex = 0;
15333401299aSJeff Kirsher printk (KERN_INFO "Auto 10 Mbps, Half duplex\n");
15343401299aSJeff Kirsher }
153578f6a6bdSFrancois Romieu if (negotiate & ADVERTISE_PAUSE_CAP) {
15363401299aSJeff Kirsher np->tx_flow &= 1;
15373401299aSJeff Kirsher np->rx_flow &= 1;
153878f6a6bdSFrancois Romieu } else if (negotiate & ADVERTISE_PAUSE_ASYM) {
15393401299aSJeff Kirsher np->tx_flow = 0;
15403401299aSJeff Kirsher np->rx_flow &= 1;
15413401299aSJeff Kirsher }
15423401299aSJeff Kirsher /* else tx_flow, rx_flow = user select */
15433401299aSJeff Kirsher } else {
15443401299aSJeff Kirsher __u16 bmcr = mii_read (dev, phy_addr, MII_BMCR);
154578f6a6bdSFrancois Romieu switch (bmcr & (BMCR_SPEED100 | BMCR_SPEED1000)) {
154678f6a6bdSFrancois Romieu case BMCR_SPEED1000:
15473401299aSJeff Kirsher printk (KERN_INFO "Operating at 1000 Mbps, ");
15483401299aSJeff Kirsher break;
154978f6a6bdSFrancois Romieu case BMCR_SPEED100:
15503401299aSJeff Kirsher printk (KERN_INFO "Operating at 100 Mbps, ");
15513401299aSJeff Kirsher break;
15523401299aSJeff Kirsher case 0:
15533401299aSJeff Kirsher printk (KERN_INFO "Operating at 10 Mbps, ");
15543401299aSJeff Kirsher }
155578f6a6bdSFrancois Romieu if (bmcr & BMCR_FULLDPLX) {
15563401299aSJeff Kirsher printk (KERN_CONT "Full duplex\n");
15573401299aSJeff Kirsher } else {
15583401299aSJeff Kirsher printk (KERN_CONT "Half duplex\n");
15593401299aSJeff Kirsher }
15603401299aSJeff Kirsher }
15613401299aSJeff Kirsher if (np->tx_flow)
15623401299aSJeff Kirsher printk(KERN_INFO "Enable Tx Flow Control\n");
15633401299aSJeff Kirsher else
15643401299aSJeff Kirsher printk(KERN_INFO "Disable Tx Flow Control\n");
15653401299aSJeff Kirsher if (np->rx_flow)
15663401299aSJeff Kirsher printk(KERN_INFO "Enable Rx Flow Control\n");
15673401299aSJeff Kirsher else
15683401299aSJeff Kirsher printk(KERN_INFO "Disable Rx Flow Control\n");
15693401299aSJeff Kirsher
15703401299aSJeff Kirsher return 0;
15713401299aSJeff Kirsher }
15723401299aSJeff Kirsher
15733401299aSJeff Kirsher static int
mii_set_media(struct net_device * dev)15743401299aSJeff Kirsher mii_set_media (struct net_device *dev)
15753401299aSJeff Kirsher {
15763401299aSJeff Kirsher __u16 pscr;
15773401299aSJeff Kirsher __u16 bmcr;
15783401299aSJeff Kirsher __u16 bmsr;
15793401299aSJeff Kirsher __u16 anar;
15803401299aSJeff Kirsher int phy_addr;
15813401299aSJeff Kirsher struct netdev_private *np;
15823401299aSJeff Kirsher np = netdev_priv(dev);
15833401299aSJeff Kirsher phy_addr = np->phy_addr;
15843401299aSJeff Kirsher
15853401299aSJeff Kirsher /* Does user set speed? */
15863401299aSJeff Kirsher if (np->an_enable) {
15873401299aSJeff Kirsher /* Advertise capabilities */
15883401299aSJeff Kirsher bmsr = mii_read (dev, phy_addr, MII_BMSR);
158978f6a6bdSFrancois Romieu anar = mii_read (dev, phy_addr, MII_ADVERTISE) &
159078f6a6bdSFrancois Romieu ~(ADVERTISE_100FULL | ADVERTISE_10FULL |
159178f6a6bdSFrancois Romieu ADVERTISE_100HALF | ADVERTISE_10HALF |
159278f6a6bdSFrancois Romieu ADVERTISE_100BASE4);
159378f6a6bdSFrancois Romieu if (bmsr & BMSR_100FULL)
159478f6a6bdSFrancois Romieu anar |= ADVERTISE_100FULL;
159578f6a6bdSFrancois Romieu if (bmsr & BMSR_100HALF)
159678f6a6bdSFrancois Romieu anar |= ADVERTISE_100HALF;
159778f6a6bdSFrancois Romieu if (bmsr & BMSR_100BASE4)
159878f6a6bdSFrancois Romieu anar |= ADVERTISE_100BASE4;
159978f6a6bdSFrancois Romieu if (bmsr & BMSR_10FULL)
160078f6a6bdSFrancois Romieu anar |= ADVERTISE_10FULL;
160178f6a6bdSFrancois Romieu if (bmsr & BMSR_10HALF)
160278f6a6bdSFrancois Romieu anar |= ADVERTISE_10HALF;
160378f6a6bdSFrancois Romieu anar |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
160478f6a6bdSFrancois Romieu mii_write (dev, phy_addr, MII_ADVERTISE, anar);
16053401299aSJeff Kirsher
16063401299aSJeff Kirsher /* Enable Auto crossover */
16073401299aSJeff Kirsher pscr = mii_read (dev, phy_addr, MII_PHY_SCR);
16083401299aSJeff Kirsher pscr |= 3 << 5; /* 11'b */
16093401299aSJeff Kirsher mii_write (dev, phy_addr, MII_PHY_SCR, pscr);
16103401299aSJeff Kirsher
16113401299aSJeff Kirsher /* Soft reset PHY */
161278f6a6bdSFrancois Romieu mii_write (dev, phy_addr, MII_BMCR, BMCR_RESET);
161378f6a6bdSFrancois Romieu bmcr = BMCR_ANENABLE | BMCR_ANRESTART | BMCR_RESET;
16143401299aSJeff Kirsher mii_write (dev, phy_addr, MII_BMCR, bmcr);
16153401299aSJeff Kirsher mdelay(1);
16163401299aSJeff Kirsher } else {
16173401299aSJeff Kirsher /* Force speed setting */
16183401299aSJeff Kirsher /* 1) Disable Auto crossover */
16193401299aSJeff Kirsher pscr = mii_read (dev, phy_addr, MII_PHY_SCR);
16203401299aSJeff Kirsher pscr &= ~(3 << 5);
16213401299aSJeff Kirsher mii_write (dev, phy_addr, MII_PHY_SCR, pscr);
16223401299aSJeff Kirsher
16233401299aSJeff Kirsher /* 2) PHY Reset */
16243401299aSJeff Kirsher bmcr = mii_read (dev, phy_addr, MII_BMCR);
162578f6a6bdSFrancois Romieu bmcr |= BMCR_RESET;
16263401299aSJeff Kirsher mii_write (dev, phy_addr, MII_BMCR, bmcr);
16273401299aSJeff Kirsher
16283401299aSJeff Kirsher /* 3) Power Down */
16293401299aSJeff Kirsher bmcr = 0x1940; /* must be 0x1940 */
16303401299aSJeff Kirsher mii_write (dev, phy_addr, MII_BMCR, bmcr);
16313401299aSJeff Kirsher mdelay (100); /* wait a certain time */
16323401299aSJeff Kirsher
16333401299aSJeff Kirsher /* 4) Advertise nothing */
163478f6a6bdSFrancois Romieu mii_write (dev, phy_addr, MII_ADVERTISE, 0);
16353401299aSJeff Kirsher
16363401299aSJeff Kirsher /* 5) Set media and Power Up */
163778f6a6bdSFrancois Romieu bmcr = BMCR_PDOWN;
16383401299aSJeff Kirsher if (np->speed == 100) {
163978f6a6bdSFrancois Romieu bmcr |= BMCR_SPEED100;
16403401299aSJeff Kirsher printk (KERN_INFO "Manual 100 Mbps, ");
16413401299aSJeff Kirsher } else if (np->speed == 10) {
16423401299aSJeff Kirsher printk (KERN_INFO "Manual 10 Mbps, ");
16433401299aSJeff Kirsher }
16443401299aSJeff Kirsher if (np->full_duplex) {
164578f6a6bdSFrancois Romieu bmcr |= BMCR_FULLDPLX;
16463401299aSJeff Kirsher printk (KERN_CONT "Full duplex\n");
16473401299aSJeff Kirsher } else {
16483401299aSJeff Kirsher printk (KERN_CONT "Half duplex\n");
16493401299aSJeff Kirsher }
16503401299aSJeff Kirsher #if 0
16513401299aSJeff Kirsher /* Set 1000BaseT Master/Slave setting */
165278f6a6bdSFrancois Romieu mscr = mii_read (dev, phy_addr, MII_CTRL1000);
16533401299aSJeff Kirsher mscr |= MII_MSCR_CFG_ENABLE;
16543401299aSJeff Kirsher mscr &= ~MII_MSCR_CFG_VALUE = 0;
16553401299aSJeff Kirsher #endif
16563401299aSJeff Kirsher mii_write (dev, phy_addr, MII_BMCR, bmcr);
16573401299aSJeff Kirsher mdelay(10);
16583401299aSJeff Kirsher }
16593401299aSJeff Kirsher return 0;
16603401299aSJeff Kirsher }
16613401299aSJeff Kirsher
16623401299aSJeff Kirsher static int
mii_get_media_pcs(struct net_device * dev)16633401299aSJeff Kirsher mii_get_media_pcs (struct net_device *dev)
16643401299aSJeff Kirsher {
16653401299aSJeff Kirsher __u16 negotiate;
16663401299aSJeff Kirsher __u16 bmsr;
16673401299aSJeff Kirsher int phy_addr;
16683401299aSJeff Kirsher struct netdev_private *np;
16693401299aSJeff Kirsher
16703401299aSJeff Kirsher np = netdev_priv(dev);
16713401299aSJeff Kirsher phy_addr = np->phy_addr;
16723401299aSJeff Kirsher
16733401299aSJeff Kirsher bmsr = mii_read (dev, phy_addr, PCS_BMSR);
16743401299aSJeff Kirsher if (np->an_enable) {
167578f6a6bdSFrancois Romieu if (!(bmsr & BMSR_ANEGCOMPLETE)) {
16763401299aSJeff Kirsher /* Auto-Negotiation not completed */
16773401299aSJeff Kirsher return -1;
16783401299aSJeff Kirsher }
16793401299aSJeff Kirsher negotiate = mii_read (dev, phy_addr, PCS_ANAR) &
16803401299aSJeff Kirsher mii_read (dev, phy_addr, PCS_ANLPAR);
16813401299aSJeff Kirsher np->speed = 1000;
16823401299aSJeff Kirsher if (negotiate & PCS_ANAR_FULL_DUPLEX) {
16833401299aSJeff Kirsher printk (KERN_INFO "Auto 1000 Mbps, Full duplex\n");
16843401299aSJeff Kirsher np->full_duplex = 1;
16853401299aSJeff Kirsher } else {
16863401299aSJeff Kirsher printk (KERN_INFO "Auto 1000 Mbps, half duplex\n");
16873401299aSJeff Kirsher np->full_duplex = 0;
16883401299aSJeff Kirsher }
16893401299aSJeff Kirsher if (negotiate & PCS_ANAR_PAUSE) {
16903401299aSJeff Kirsher np->tx_flow &= 1;
16913401299aSJeff Kirsher np->rx_flow &= 1;
16923401299aSJeff Kirsher } else if (negotiate & PCS_ANAR_ASYMMETRIC) {
16933401299aSJeff Kirsher np->tx_flow = 0;
16943401299aSJeff Kirsher np->rx_flow &= 1;
16953401299aSJeff Kirsher }
16963401299aSJeff Kirsher /* else tx_flow, rx_flow = user select */
16973401299aSJeff Kirsher } else {
16983401299aSJeff Kirsher __u16 bmcr = mii_read (dev, phy_addr, PCS_BMCR);
16993401299aSJeff Kirsher printk (KERN_INFO "Operating at 1000 Mbps, ");
170078f6a6bdSFrancois Romieu if (bmcr & BMCR_FULLDPLX) {
17013401299aSJeff Kirsher printk (KERN_CONT "Full duplex\n");
17023401299aSJeff Kirsher } else {
17033401299aSJeff Kirsher printk (KERN_CONT "Half duplex\n");
17043401299aSJeff Kirsher }
17053401299aSJeff Kirsher }
17063401299aSJeff Kirsher if (np->tx_flow)
17073401299aSJeff Kirsher printk(KERN_INFO "Enable Tx Flow Control\n");
17083401299aSJeff Kirsher else
17093401299aSJeff Kirsher printk(KERN_INFO "Disable Tx Flow Control\n");
17103401299aSJeff Kirsher if (np->rx_flow)
17113401299aSJeff Kirsher printk(KERN_INFO "Enable Rx Flow Control\n");
17123401299aSJeff Kirsher else
17133401299aSJeff Kirsher printk(KERN_INFO "Disable Rx Flow Control\n");
17143401299aSJeff Kirsher
17153401299aSJeff Kirsher return 0;
17163401299aSJeff Kirsher }
17173401299aSJeff Kirsher
17183401299aSJeff Kirsher static int
mii_set_media_pcs(struct net_device * dev)17193401299aSJeff Kirsher mii_set_media_pcs (struct net_device *dev)
17203401299aSJeff Kirsher {
17213401299aSJeff Kirsher __u16 bmcr;
17223401299aSJeff Kirsher __u16 esr;
17233401299aSJeff Kirsher __u16 anar;
17243401299aSJeff Kirsher int phy_addr;
17253401299aSJeff Kirsher struct netdev_private *np;
17263401299aSJeff Kirsher np = netdev_priv(dev);
17273401299aSJeff Kirsher phy_addr = np->phy_addr;
17283401299aSJeff Kirsher
17293401299aSJeff Kirsher /* Auto-Negotiation? */
17303401299aSJeff Kirsher if (np->an_enable) {
17313401299aSJeff Kirsher /* Advertise capabilities */
17323401299aSJeff Kirsher esr = mii_read (dev, phy_addr, PCS_ESR);
173378f6a6bdSFrancois Romieu anar = mii_read (dev, phy_addr, MII_ADVERTISE) &
17343401299aSJeff Kirsher ~PCS_ANAR_HALF_DUPLEX &
17353401299aSJeff Kirsher ~PCS_ANAR_FULL_DUPLEX;
17363401299aSJeff Kirsher if (esr & (MII_ESR_1000BT_HD | MII_ESR_1000BX_HD))
17373401299aSJeff Kirsher anar |= PCS_ANAR_HALF_DUPLEX;
17383401299aSJeff Kirsher if (esr & (MII_ESR_1000BT_FD | MII_ESR_1000BX_FD))
17393401299aSJeff Kirsher anar |= PCS_ANAR_FULL_DUPLEX;
17403401299aSJeff Kirsher anar |= PCS_ANAR_PAUSE | PCS_ANAR_ASYMMETRIC;
174178f6a6bdSFrancois Romieu mii_write (dev, phy_addr, MII_ADVERTISE, anar);
17423401299aSJeff Kirsher
17433401299aSJeff Kirsher /* Soft reset PHY */
174478f6a6bdSFrancois Romieu mii_write (dev, phy_addr, MII_BMCR, BMCR_RESET);
174578f6a6bdSFrancois Romieu bmcr = BMCR_ANENABLE | BMCR_ANRESTART | BMCR_RESET;
17463401299aSJeff Kirsher mii_write (dev, phy_addr, MII_BMCR, bmcr);
17473401299aSJeff Kirsher mdelay(1);
17483401299aSJeff Kirsher } else {
17493401299aSJeff Kirsher /* Force speed setting */
17503401299aSJeff Kirsher /* PHY Reset */
175178f6a6bdSFrancois Romieu bmcr = BMCR_RESET;
17523401299aSJeff Kirsher mii_write (dev, phy_addr, MII_BMCR, bmcr);
17533401299aSJeff Kirsher mdelay(10);
17543401299aSJeff Kirsher if (np->full_duplex) {
175578f6a6bdSFrancois Romieu bmcr = BMCR_FULLDPLX;
17563401299aSJeff Kirsher printk (KERN_INFO "Manual full duplex\n");
17573401299aSJeff Kirsher } else {
17583401299aSJeff Kirsher bmcr = 0;
17593401299aSJeff Kirsher printk (KERN_INFO "Manual half duplex\n");
17603401299aSJeff Kirsher }
17613401299aSJeff Kirsher mii_write (dev, phy_addr, MII_BMCR, bmcr);
17623401299aSJeff Kirsher mdelay(10);
17633401299aSJeff Kirsher
17643401299aSJeff Kirsher /* Advertise nothing */
176578f6a6bdSFrancois Romieu mii_write (dev, phy_addr, MII_ADVERTISE, 0);
17663401299aSJeff Kirsher }
17673401299aSJeff Kirsher return 0;
17683401299aSJeff Kirsher }
17693401299aSJeff Kirsher
17703401299aSJeff Kirsher
17713401299aSJeff Kirsher static int
rio_close(struct net_device * dev)17723401299aSJeff Kirsher rio_close (struct net_device *dev)
17733401299aSJeff Kirsher {
17743401299aSJeff Kirsher struct netdev_private *np = netdev_priv(dev);
17755e3cc4e3SFrancois Romieu struct pci_dev *pdev = np->pdev;
17763401299aSJeff Kirsher
17773401299aSJeff Kirsher netif_stop_queue (dev);
17783401299aSJeff Kirsher
1779966e07f4SOndrej Zary rio_hw_stop(dev);
17803401299aSJeff Kirsher
17815e3cc4e3SFrancois Romieu free_irq(pdev->irq, dev);
17823401299aSJeff Kirsher del_timer_sync (&np->timer);
17833401299aSJeff Kirsher
178439536ff8SOndrej Zary free_list(dev);
17853401299aSJeff Kirsher
17863401299aSJeff Kirsher return 0;
17873401299aSJeff Kirsher }
17883401299aSJeff Kirsher
178964bc40deSBill Pemberton static void
rio_remove1(struct pci_dev * pdev)17903401299aSJeff Kirsher rio_remove1 (struct pci_dev *pdev)
17913401299aSJeff Kirsher {
17923401299aSJeff Kirsher struct net_device *dev = pci_get_drvdata (pdev);
17933401299aSJeff Kirsher
17943401299aSJeff Kirsher if (dev) {
17953401299aSJeff Kirsher struct netdev_private *np = netdev_priv(dev);
17963401299aSJeff Kirsher
17973401299aSJeff Kirsher unregister_netdev (dev);
1798b49db89eSChristophe JAILLET dma_free_coherent(&pdev->dev, RX_TOTAL_SIZE, np->rx_ring,
17993401299aSJeff Kirsher np->rx_ring_dma);
1800b49db89eSChristophe JAILLET dma_free_coherent(&pdev->dev, TX_TOTAL_SIZE, np->tx_ring,
18013401299aSJeff Kirsher np->tx_ring_dma);
18023401299aSJeff Kirsher #ifdef MEM_MAPPING
18035e3cc4e3SFrancois Romieu pci_iounmap(pdev, np->ioaddr);
18043401299aSJeff Kirsher #endif
18055e3cc4e3SFrancois Romieu pci_iounmap(pdev, np->eeprom_addr);
18063401299aSJeff Kirsher free_netdev (dev);
18073401299aSJeff Kirsher pci_release_regions (pdev);
18083401299aSJeff Kirsher pci_disable_device (pdev);
18093401299aSJeff Kirsher }
18103401299aSJeff Kirsher }
18113401299aSJeff Kirsher
18121777ddb8SOndrej Zary #ifdef CONFIG_PM_SLEEP
rio_suspend(struct device * device)18131777ddb8SOndrej Zary static int rio_suspend(struct device *device)
18141777ddb8SOndrej Zary {
18151777ddb8SOndrej Zary struct net_device *dev = dev_get_drvdata(device);
18161777ddb8SOndrej Zary struct netdev_private *np = netdev_priv(dev);
18171777ddb8SOndrej Zary
18181777ddb8SOndrej Zary if (!netif_running(dev))
18191777ddb8SOndrej Zary return 0;
18201777ddb8SOndrej Zary
18211777ddb8SOndrej Zary netif_device_detach(dev);
18221777ddb8SOndrej Zary del_timer_sync(&np->timer);
18231777ddb8SOndrej Zary rio_hw_stop(dev);
18241777ddb8SOndrej Zary
18251777ddb8SOndrej Zary return 0;
18261777ddb8SOndrej Zary }
18271777ddb8SOndrej Zary
rio_resume(struct device * device)18281777ddb8SOndrej Zary static int rio_resume(struct device *device)
18291777ddb8SOndrej Zary {
18301777ddb8SOndrej Zary struct net_device *dev = dev_get_drvdata(device);
18311777ddb8SOndrej Zary struct netdev_private *np = netdev_priv(dev);
18321777ddb8SOndrej Zary
18331777ddb8SOndrej Zary if (!netif_running(dev))
18341777ddb8SOndrej Zary return 0;
18351777ddb8SOndrej Zary
18361777ddb8SOndrej Zary rio_reset_ring(np);
18371777ddb8SOndrej Zary rio_hw_init(dev);
18381777ddb8SOndrej Zary np->timer.expires = jiffies + 1 * HZ;
18391777ddb8SOndrej Zary add_timer(&np->timer);
18401777ddb8SOndrej Zary netif_device_attach(dev);
18411777ddb8SOndrej Zary dl2k_enable_int(np);
18421777ddb8SOndrej Zary
18431777ddb8SOndrej Zary return 0;
18441777ddb8SOndrej Zary }
18451777ddb8SOndrej Zary
18461777ddb8SOndrej Zary static SIMPLE_DEV_PM_OPS(rio_pm_ops, rio_suspend, rio_resume);
18471777ddb8SOndrej Zary #define RIO_PM_OPS (&rio_pm_ops)
18481777ddb8SOndrej Zary
18491777ddb8SOndrej Zary #else
18501777ddb8SOndrej Zary
18511777ddb8SOndrej Zary #define RIO_PM_OPS NULL
18521777ddb8SOndrej Zary
18531777ddb8SOndrej Zary #endif /* CONFIG_PM_SLEEP */
18541777ddb8SOndrej Zary
18553401299aSJeff Kirsher static struct pci_driver rio_driver = {
18563401299aSJeff Kirsher .name = "dl2k",
18573401299aSJeff Kirsher .id_table = rio_pci_tbl,
18583401299aSJeff Kirsher .probe = rio_probe1,
185964bc40deSBill Pemberton .remove = rio_remove1,
18601777ddb8SOndrej Zary .driver.pm = RIO_PM_OPS,
18613401299aSJeff Kirsher };
18623401299aSJeff Kirsher
18639add4d81SDevendra Naga module_pci_driver(rio_driver);
18643401299aSJeff Kirsher
1865132db935SJakub Kicinski /* Read Documentation/networking/device_drivers/ethernet/dlink/dl2k.rst. */
1866