atl1: Ancillary C files for Attansic L1 driver
Subsystems (2)
PATCH 4/4 atl1: Ancillary C files for Attansic L1 driver
From: Jay Cliburn <[email protected]>
This patch contains auxiliary C files for the Attansic L1 gigabit ethernet adapter driver.
Signed-off-by Jay Cliburn <[email protected]>
---
atl1_ethtool.c | 530 +++++++++++++++++++++++++++++++++++ atl1_hw.c | 840 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ atl1_param.c | 203 +++++++++++++ 3 files changed, 1573 insertions(+)
drivers/net/atl1/atl1_ethtool.c new file +530 -0
@@ -0,0 +1,530 @@ +/** atl1_ethtool.c - atl1 ethtool support + +Copyright(c) 2005 - 2006 Attansic Corporation. All rights reserved. +Copyright(c) 2006 Chris Snook <[email protected]> +Copyright(c) 2006 Jay Cliburn <[email protected]> + +Derived from Intel e1000 driver +Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved. + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2 of the License, or (at your option) +any later version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 +Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include <linux/netdevice.h> + +#include "atl1.h" + +#ifdef SIOCETHTOOL +#include <asm/uaccess.h> + +extern char at_driver_name[]; +extern char at_driver_version[]; +extern s32 at_up (struct at_adapter *adapter); +extern void at_down (struct at_adapter *adapter); +extern void at_reset (struct at_adapter *adapter); +extern s32 at_setup_ring_resources (struct at_adapter *adapter); +extern void at_free_ring_resources (struct at_adapter *adapter); +extern s32 at_phy_setup_autoneg_adv (struct at_hw *hw); +extern s32 at_write_phy_reg (struct at_hw *hw,u32 reg_addr,u16 phy_data); +extern s32 at_get_speed_and_duplex (struct at_hw *hw,u16 * speed,u16 * duplex); + +#ifdef ETHTOOL_GSTATS +struct at_stats { +char stat_string[ETH_GSTRING_LEN ]; +int sizeof_stat; +int stat_offset; +}; + +#define AT_STAT (m) sizeof(((struct at_adapter *)0)->m), \ + offsetof(struct at_adapter, m) + +static struct at_stats at_gstrings_stats[] = { + {"rx_packets" ,AT_STAT (soft_stats.rx_packets)}, + {"tx_packets" ,AT_STAT (soft_stats.tx_packets)}, + {"rx_bytes" ,AT_STAT (soft_stats.rx_bytes)}, + {"tx_bytes" ,AT_STAT (soft_stats.tx_bytes)}, + {"rx_errors" ,AT_STAT (soft_stats.rx_errors)}, + {"tx_errors" ,AT_STAT (soft_stats.tx_errors)}, + {"rx_dropped" ,AT_STAT (net_stats.rx_dropped)}, + {"tx_dropped" ,AT_STAT (net_stats.tx_dropped)}, + {"multicast" ,AT_STAT (soft_stats.multicast)}, + {"collisions" ,AT_STAT (soft_stats.collisions)}, + {"rx_length_errors" ,AT_STAT (soft_stats.rx_length_errors)}, + {"rx_over_errors" ,AT_STAT (soft_stats.rx_missed_errors)}, + {"rx_crc_errors" ,AT_STAT (soft_stats.rx_crc_errors)}, + {"rx_frame_errors" ,AT_STAT (soft_stats.rx_frame_errors)}, + {"rx_fifo_errors" ,AT_STAT (soft_stats.rx_fifo_errors)}, + {"rx_missed_errors" ,AT_STAT (soft_stats.rx_missed_errors)}, + {"tx_aborted_errors" ,AT_STAT (soft_stats.tx_aborted_errors)}, + {"tx_carrier_errors" ,AT_STAT (soft_stats.tx_carrier_errors)}, + {"tx_fifo_errors" ,AT_STAT (soft_stats.tx_fifo_errors)}, + {"tx_window_errors" ,AT_STAT (soft_stats.tx_window_errors)}, + {"tx_abort_exce_coll" ,AT_STAT (soft_stats.excecol)}, + {"tx_abort_late_coll" ,AT_STAT (soft_stats.latecol)}, + {"tx_deferred_ok" ,AT_STAT (soft_stats.deffer)}, + {"tx_single_coll_ok" ,AT_STAT (soft_stats.scc)}, + {"tx_multi_coll_ok" ,AT_STAT (soft_stats.mcc)}, + {"tx_underun" ,AT_STAT (soft_stats.tx_underun)}, + {"tx_trunc" ,AT_STAT (soft_stats.tx_trunc)}, + {"tx_pause" ,AT_STAT (soft_stats.tx_pause)}, + {"rx_pause" ,AT_STAT (soft_stats.rx_pause)}, + {"rx_rrd_ov" ,AT_STAT (soft_stats.rx_rrd_ov)}, + {"rx_trunc" ,AT_STAT (soft_stats.rx_trunc)} +}; + +#define AT_STATS_LEN sizeof(at_gstrings_stats) / sizeof(struct at_stats) +#endif /* ETHTOOL_GSTATS */ + +static int at_get_settings (struct net_device *netdev,struct ethtool_cmd *ecmd) +{ +struct at_adapter *adapter =netdev_priv (netdev); +struct at_hw *hw = &adapter->hw; + + ecmd->supported = (SUPPORTED_10baseT_Half | + SUPPORTED_10baseT_Full | + SUPPORTED_100baseT_Half | + SUPPORTED_100baseT_Full | + SUPPORTED_1000baseT_Full | + SUPPORTED_Autoneg |SUPPORTED_TP ); + ecmd->advertising =ADVERTISED_TP ; +if (hw->media_type ==MEDIA_TYPE_AUTO_SENSOR || + hw->media_type ==MEDIA_TYPE_1000M_FULL ) { + ecmd->advertising |= ADVERTISED_Autoneg; +if (hw->media_type ==MEDIA_TYPE_AUTO_SENSOR ) { + ecmd->advertising |= ADVERTISED_Autoneg; + ecmd->advertising |= + (ADVERTISED_10baseT_Half | + ADVERTISED_10baseT_Full | + ADVERTISED_100baseT_Half | + ADVERTISED_100baseT_Full | + ADVERTISED_1000baseT_Full); + }else { + ecmd->advertising |= (ADVERTISED_1000baseT_Full); + } + } + ecmd->port =PORT_TP ; + ecmd->phy_address =0 ; + ecmd->transceiver =XCVR_INTERNAL ; + +if (netif_carrier_ok (adapter->netdev)) { +u16 link_speed, link_duplex; +at_get_speed_and_duplex (hw, &link_speed, &link_duplex); + ecmd->speed = link_speed; +if (link_duplex ==FULL_DUPLEX ) + ecmd->duplex =DUPLEX_FULL ; +else + ecmd->duplex =DUPLEX_HALF ; + }else { + ecmd->speed =-1 ; + ecmd->duplex =-1 ; + } +if (hw->media_type ==MEDIA_TYPE_AUTO_SENSOR || + hw->media_type ==MEDIA_TYPE_1000M_FULL ) { + ecmd->autoneg =AUTONEG_ENABLE ; + }else { + ecmd->autoneg =AUTONEG_DISABLE ; + } + +return 0 ; +} + +static int at_set_settings (struct net_device *netdev,struct ethtool_cmd *ecmd) +{ +struct at_adapter *adapter =netdev_priv (netdev); +struct at_hw *hw = &adapter->hw; +u16 phy_data; +int ret_val =0 ; +u16 old_media_type = hw->media_type; + +if (netif_running (adapter->netdev)) { +printk (KERN_DEBUG "%s: ethtool shutting down link adapter\n" , + at_driver_name); +at_down (adapter); + } + +if (ecmd->autoneg ==AUTONEG_ENABLE ) { + hw->media_type =MEDIA_TYPE_AUTO_SENSOR ; + }else { +if (ecmd->speed ==SPEED_1000 ) { +if (ecmd->duplex !=DUPLEX_FULL ) { +printk (KERN_WARNING +"%s: can't force to 1000M half duplex\n" , + at_driver_name); + ret_val = -EINVAL ; + goto exit_sset; + } + hw->media_type =MEDIA_TYPE_1000M_FULL ; + }else if (ecmd->speed ==SPEED_100 ) { +if (ecmd->duplex ==DUPLEX_FULL ) { + hw->media_type =MEDIA_TYPE_100M_FULL ; + }else { + hw->media_type =MEDIA_TYPE_100M_HALF ; + } + }else { +if (ecmd->duplex ==DUPLEX_FULL ) { + hw->media_type =MEDIA_TYPE_10M_FULL ; + }else { + hw->media_type =MEDIA_TYPE_10M_HALF ; + } + } + } +switch (hw->media_type) { +case MEDIA_TYPE_AUTO_SENSOR : + ecmd->advertising = + ADVERTISED_10baseT_Half | + ADVERTISED_10baseT_Full | + ADVERTISED_100baseT_Half | + ADVERTISED_100baseT_Full | + ADVERTISED_1000baseT_Full | + ADVERTISED_Autoneg |ADVERTISED_TP ; +break ; +case MEDIA_TYPE_1000M_FULL : + ecmd->advertising = + ADVERTISED_1000baseT_Full | + ADVERTISED_Autoneg |ADVERTISED_TP ; +break ; +default : + ecmd->advertising =0 ; +break ; + } +if (at_phy_setup_autoneg_adv (hw)) { + ret_val = -EINVAL ; +printk (KERN_WARNING +"%s: invalid ethtool speed/duplex setting\n" , + at_driver_name); + goto exit_sset; + } +if (hw->media_type ==MEDIA_TYPE_AUTO_SENSOR || + hw->media_type ==MEDIA_TYPE_1000M_FULL ) { + phy_data =MII_CR_RESET |MII_CR_AUTO_NEG_EN ; + }else { +switch (hw->media_type) { +case MEDIA_TYPE_100M_FULL : + phy_data = +MII_CR_FULL_DUPLEX |MII_CR_SPEED_100 | +MII_CR_RESET ; +break ; +case MEDIA_TYPE_100M_HALF : + phy_data =MII_CR_SPEED_100 |MII_CR_RESET ; +break ; +case MEDIA_TYPE_10M_FULL : + phy_data = +MII_CR_FULL_DUPLEX |MII_CR_SPEED_10 |MII_CR_RESET ; +break ; +default :/* MEDIA_TYPE_10M_HALF: */ + phy_data =MII_CR_SPEED_10 |MII_CR_RESET ; +break ; + } + } +at_write_phy_reg (hw,MII_BMCR , phy_data); +exit_sset: +if (ret_val) { + hw->media_type = old_media_type; + } +if (netif_running (adapter->netdev)) { +printk (KERN_DEBUG "%s: ethtool starting link adapter\n" , + at_driver_name); +at_up (adapter); + }else if (!ret_val) { +printk (KERN_DEBUG "%s: ethtool resetting link adapter\n" , + at_driver_name); +at_reset (adapter); + } +return ret_val; +} + +static void at_get_drvinfo (struct net_device *netdev, +struct ethtool_drvinfo *drvinfo) +{ +struct at_adapter *adapter =netdev_priv (netdev); + +strncpy (drvinfo->driver, at_driver_name,32 ); +strncpy (drvinfo->version, at_driver_version,32 ); +strncpy (drvinfo->fw_version,"N/A" ,32 ); +strncpy (drvinfo->bus_info,pci_name (adapter->pdev),32 ); +#ifdef ETHTOOL_GEEPROM + drvinfo->eedump_len =48 ; +#endif /* ETHTOOL_GEEPROM */ +} + +static void at_get_wol (struct net_device *netdev, +struct ethtool_wolinfo *wol) +{ +struct at_adapter *adapter =netdev_priv (netdev); + + wol->supported =WAKE_UCAST |WAKE_MCAST |WAKE_BCAST |WAKE_MAGIC ; + wol->wolopts =0 ; +if (adapter->wol &AT_WUFC_EX ) + wol->wolopts |=WAKE_UCAST ; +if (adapter->wol &AT_WUFC_MC ) + wol->wolopts |=WAKE_MCAST ; +if (adapter->wol &AT_WUFC_BC ) + wol->wolopts |=WAKE_BCAST ; +if (adapter->wol &AT_WUFC_MAG ) + wol->wolopts |=WAKE_MAGIC ; +return ; +} + +static int at_set_wol (struct net_device *netdev, +struct ethtool_wolinfo *wol) +{ +struct at_adapter *adapter =netdev_priv (netdev); + +if (wol->wolopts & (WAKE_PHY |WAKE_ARP |WAKE_MAGICSECURE )) +return -EOPNOTSUPP ; + adapter->wol =0 ; +if (wol->wolopts &WAKE_UCAST ) + adapter->wol |=AT_WUFC_EX ; +if (wol->wolopts &WAKE_MCAST ) + adapter->wol |=AT_WUFC_MC ; +if (wol->wolopts &WAKE_BCAST ) + adapter->wol |=AT_WUFC_BC ; +if (wol->wolopts &WAKE_MAGIC ) + adapter->wol |=AT_WUFC_MAG ; +return 0 ; +} + +static void at_get_ringparam (struct net_device *netdev, +struct ethtool_ringparam *ring) +{ +struct at_adapter *adapter =netdev_priv (netdev); +struct at_tpd_ring *txdr = &adapter->tpd_ring; +struct at_rfd_ring *rxdr = &adapter->rfd_ring; + + ring->rx_max_pending =2048 ; + ring->tx_max_pending =1024 ; + ring->rx_mini_max_pending =0 ; + ring->rx_jumbo_max_pending =0 ; + ring->rx_pending = rxdr->count; + ring->tx_pending = txdr->count; + ring->rx_mini_pending =0 ; + ring->rx_jumbo_pending =0 ; +} + +static int at_set_ringparam (struct net_device *netdev, +struct ethtool_ringparam *ring) +{ +struct at_adapter *adapter =netdev_priv (netdev); +int err; +struct at_tpd_ring *tpdr = &adapter->tpd_ring; +struct at_rrd_ring *rrdr = &adapter->rrd_ring; +struct at_rfd_ring *rfdr = &adapter->rfd_ring; + +struct at_tpd_ring tpd_old, tpd_new; +struct at_rfd_ring rfd_old, rfd_new; +struct at_rrd_ring rrd_old, rrd_new; + + tpd_old = adapter->tpd_ring; + rfd_old = adapter->rfd_ring; + rrd_old = adapter->rrd_ring; + +if (netif_running (adapter->netdev)) +at_down (adapter); + + rfdr->count = (u16 )max (ring->rx_pending, (u32 )32 ); + rfdr->count = rfdr->count >2048 ?2048 : rfdr->count; + rfdr->count = (rfdr->count +3 ) & ~3 ; + rrdr->count = rfdr->count; + + tpdr->count = (u16 )max (ring->tx_pending, (u32 )16 ); + tpdr->count = tpdr->count >1024 ?1024 : tpdr->count; + tpdr->count = (tpdr->count +3 ) & ~3 ; + +if (netif_running (adapter->netdev)) { +/* try to get new resources before deleting old */ +if ((err =at_setup_ring_resources (adapter))) + goto err_setup_ring; + +/* save the new, restore the old in order to free it, +* then restore the new back again */ + rfd_new = adapter->rfd_ring; + rrd_new = adapter->rrd_ring; + tpd_new = adapter->tpd_ring; + adapter->rfd_ring = rfd_old; + adapter->rrd_ring = rrd_old; + adapter->tpd_ring = tpd_old; +at_free_ring_resources (adapter); + adapter->rfd_ring = rfd_new; + adapter->rrd_ring = rrd_new; + adapter->tpd_ring = tpd_new; + +if ((err =at_up (adapter))) +return err; + } +return 0 ; + + err_setup_ring: + adapter->rfd_ring = rfd_old; + adapter->rrd_ring = rrd_old; + adapter->tpd_ring = tpd_old; +at_up (adapter); +return err; +} + +static void at_get_pauseparam (struct net_device *netdev, +struct ethtool_pauseparam *epause) +{ +struct at_adapter *adapter =netdev_priv (netdev); +struct at_hw *hw = &adapter->hw; + +if (hw->media_type ==MEDIA_TYPE_AUTO_SENSOR || + hw->media_type ==MEDIA_TYPE_1000M_FULL ) { + epause->autoneg =AUTONEG_ENABLE ; + }else { + epause->autoneg =AUTONEG_DISABLE ; + } + epause->rx_pause =1 ; + epause->tx_pause =1 ; +} + +static int at_set_pauseparam (struct net_device *netdev, +struct ethtool_pauseparam *epause) +{ +struct at_adapter *adapter =netdev_priv (netdev); +struct at_hw *hw = &adapter->hw; + +if (hw->media_type ==MEDIA_TYPE_AUTO_SENSOR || + hw->media_type ==MEDIA_TYPE_1000M_FULL ) { + epause->autoneg =AUTONEG_ENABLE ; + }else { + epause->autoneg =AUTONEG_DISABLE ; + } + + epause->rx_pause =1 ; + epause->tx_pause =1 ; + +return 0 ; +} + +static u32 at_get_tx_csum (struct net_device *netdev) +{ +return (netdev->features &NETIF_F_HW_CSUM ) !=0 ; +} + +static int at_set_tx_csum (struct net_device *netdev,u32 data) +{ +if (data) + netdev->features |=NETIF_F_HW_CSUM ; +else + netdev->features &= ~NETIF_F_HW_CSUM ; + +return 0 ; +} + +#ifdef NETIF_F_TSO +static int at_set_tso (struct net_device *netdev,u32 data) +{ +if (data) + netdev->features |=NETIF_F_TSO ; +else + netdev->features &= ~NETIF_F_TSO ; +return 0 ; +} +#endif /* NETIF_F_TSO */ + +static void at_get_strings (struct net_device *netdev,u32 stringset,u8 *data) +{ +u8 *p = data; +int i; + +switch (stringset) { +case ETH_SS_STATS : +for (i =0 ; i <AT_STATS_LEN ; i++) { +memcpy (p, at_gstrings_stats[i].stat_string, +ETH_GSTRING_LEN ); + p +=ETH_GSTRING_LEN ; + } +break ; + } +} + +static int at_nway_reset (struct net_device *netdev) +{ +struct at_adapter *adapter =netdev_priv (netdev); +struct at_hw *hw = &adapter->hw; + +if (netif_running (netdev)) { +u16 phy_data; +at_down (adapter); + +if (hw->media_type ==MEDIA_TYPE_AUTO_SENSOR || + hw->media_type ==MEDIA_TYPE_1000M_FULL ) { + phy_data =MII_CR_RESET |MII_CR_AUTO_NEG_EN ; + }else { +switch (hw->media_type) { +case MEDIA_TYPE_100M_FULL : + phy_data =MII_CR_FULL_DUPLEX | +MII_CR_SPEED_100 |MII_CR_RESET ; +break ; +case MEDIA_TYPE_100M_HALF : + phy_data =MII_CR_SPEED_100 |MII_CR_RESET ; +break ; +case MEDIA_TYPE_10M_FULL : + phy_data =MII_CR_FULL_DUPLEX | +MII_CR_SPEED_10 |MII_CR_RESET ; +break ; +default :/* MEDIA_TYPE_10M_HALF */ + phy_data =MII_CR_SPEED_10 |MII_CR_RESET ; + } + } +at_write_phy_reg (hw,MII_BMCR , phy_data); +at_up (adapter); + } +return 0 ; +} + +static void at_get_ethtool_stats (struct net_device *netdev, +struct ethtool_stats *stats,u64 *data) +{ +struct at_adapter *adapter =netdev_priv (netdev); +int i; + +for (i =0 ; i <AT_STATS_LEN ; i++) { +char *p = (char *)adapter+at_gstrings_stats[i].stat_offset; + data[i] = (at_gstrings_stats[i].sizeof_stat == +sizeof (u64)) ? *(u64 *)p : *(u32 *)p; + } + +} + +static const struct ethtool_ops at_ethtool_ops = { + .get_settings = at_get_settings, + .set_settings = at_set_settings, + .get_drvinfo = at_get_drvinfo, + .get_wol = at_get_wol, + .set_wol = at_set_wol, + .get_ringparam = at_get_ringparam, + .set_ringparam = at_set_ringparam, + .get_pauseparam = at_get_pauseparam, + .set_pauseparam = at_set_pauseparam, + .get_tx_csum = at_get_tx_csum, + .set_tx_csum = at_set_tx_csum, + .get_link = ethtool_op_get_link, + .get_sg = ethtool_op_get_sg, + .set_sg = ethtool_op_set_sg, + .get_strings = at_get_strings, + .nway_reset = at_nway_reset, + .get_ethtool_stats = at_get_ethtool_stats, +#ifdef NETIF_F_TSO + .get_tso = ethtool_op_get_tso, + .set_tso = at_set_tso, +#endif +}; + +void at_set_ethtool_ops (struct net_device *netdev) +{ +SET_ETHTOOL_OPS (netdev, &at_ethtool_ops); +} +#endif /* SIOCETHTOOL */
drivers/net/atl1/atl1_hw.c new file +840 -0
840 lines not on this page · raw message
drivers/net/atl1/atl1_param.c new file +203 -0
203 lines not on this page · raw message
Quoted 7 lines · Jay Cliburn
From: Jay Cliburn <[email protected]>
This patch contains auxiliary C files for the Attansic L1 gigabit ethernet adapter driver.
Signed-off-by Jay Cliburn <[email protected]>---
I've been working with Jay on a lot of the cleanup of this driver since his original submission.
Signed-off-by Chris Snook <[email protected]>