patch-2.4.27 linux-2.4.27/drivers/net/e1000/e1000_ethtool.c
Next file: linux-2.4.27/drivers/net/e1000/e1000_hw.c
Previous file: linux-2.4.27/drivers/net/e1000/e1000.h
Back to the patch index
Back to the overall index
- Lines: 981
- Date:
2004-08-07 16:26:05.094364857 -0700
- Orig file:
linux-2.4.26/drivers/net/e1000/e1000_ethtool.c
- Orig date:
2004-04-14 06:05:30.000000000 -0700
diff -urN linux-2.4.26/drivers/net/e1000/e1000_ethtool.c linux-2.4.27/drivers/net/e1000/e1000_ethtool.c
@@ -53,7 +53,7 @@
#define E1000_STAT(m) sizeof(((struct e1000_adapter *)0)->m), \
offsetof(struct e1000_adapter, m)
-static struct e1000_stats e1000_gstrings_stats[] = {
+static const struct e1000_stats e1000_gstrings_stats[] = {
{ "rx_packets", E1000_STAT(net_stats.rx_packets) },
{ "tx_packets", E1000_STAT(net_stats.tx_packets) },
{ "rx_bytes", E1000_STAT(net_stats.rx_bytes) },
@@ -89,7 +89,8 @@
{ "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
{ "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
{ "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
- { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) }
+ { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
+ { "rx_long_byte_count", E1000_STAT(stats.gorcl) }
};
#define E1000_STATS_LEN \
sizeof(e1000_gstrings_stats) / sizeof(struct e1000_stats)
@@ -100,9 +101,10 @@
};
#define E1000_TEST_LEN sizeof(e1000_gstrings_test) / ETH_GSTRING_LEN
-static void
-e1000_ethtool_gset(struct e1000_adapter *adapter, struct ethtool_cmd *ecmd)
+static int
+e1000_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
{
+ struct e1000_adapter *adapter = netdev->priv;
struct e1000_hw *hw = &adapter->hw;
if(hw->media_type == e1000_media_type_copper) {
@@ -169,11 +171,13 @@
}
ecmd->autoneg = (hw->autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
+ return 0;
}
static int
-e1000_ethtool_sset(struct e1000_adapter *adapter, struct ethtool_cmd *ecmd)
+e1000_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
{
+ struct e1000_adapter *adapter = netdev->priv;
struct e1000_hw *hw = &adapter->hw;
if(ecmd->autoneg == AUTONEG_ENABLE) {
@@ -195,42 +199,41 @@
return 0;
}
-static int
-e1000_ethtool_gpause(struct e1000_adapter *adapter,
- struct ethtool_pauseparam *epause)
+static void
+e1000_get_pauseparam(struct net_device *netdev,
+ struct ethtool_pauseparam *pause)
{
+ struct e1000_adapter *adapter = netdev->priv;
struct e1000_hw *hw = &adapter->hw;
-
- epause->autoneg =
+ pause->autoneg =
(adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
if(hw->fc == e1000_fc_rx_pause)
- epause->rx_pause = 1;
+ pause->rx_pause = 1;
else if(hw->fc == e1000_fc_tx_pause)
- epause->tx_pause = 1;
+ pause->tx_pause = 1;
else if(hw->fc == e1000_fc_full) {
- epause->rx_pause = 1;
- epause->tx_pause = 1;
+ pause->rx_pause = 1;
+ pause->tx_pause = 1;
}
-
- return 0;
}
-static int
-e1000_ethtool_spause(struct e1000_adapter *adapter,
- struct ethtool_pauseparam *epause)
+static int
+e1000_set_pauseparam(struct net_device *netdev,
+ struct ethtool_pauseparam *pause)
{
+ struct e1000_adapter *adapter = netdev->priv;
struct e1000_hw *hw = &adapter->hw;
- adapter->fc_autoneg = epause->autoneg;
+ adapter->fc_autoneg = pause->autoneg;
- if(epause->rx_pause && epause->tx_pause)
+ if(pause->rx_pause && pause->tx_pause)
hw->fc = e1000_fc_full;
- else if(epause->rx_pause && !epause->tx_pause)
+ else if(pause->rx_pause && !pause->tx_pause)
hw->fc = e1000_fc_rx_pause;
- else if(!epause->rx_pause && epause->tx_pause)
+ else if(!pause->rx_pause && pause->tx_pause)
hw->fc = e1000_fc_tx_pause;
- else if(!epause->rx_pause && !epause->tx_pause)
+ else if(!pause->rx_pause && !pause->tx_pause)
hw->fc = e1000_fc_none;
hw->original_fc = hw->fc;
@@ -248,28 +251,101 @@
return 0;
}
+static uint32_t
+e1000_get_rx_csum(struct net_device *netdev)
+{
+ struct e1000_adapter *adapter = netdev->priv;
+ return adapter->rx_csum;
+}
+
+static int
+e1000_set_rx_csum(struct net_device *netdev, uint32_t data)
+{
+ struct e1000_adapter *adapter = netdev->priv;
+ adapter->rx_csum = data;
+
+ if(netif_running(netdev)) {
+ e1000_down(adapter);
+ e1000_up(adapter);
+ } else
+ e1000_reset(adapter);
+ return 0;
+}
+
+static uint32_t
+e1000_get_tx_csum(struct net_device *netdev)
+{
+ return (netdev->features & NETIF_F_HW_CSUM) != 0;
+}
+
+static int
+e1000_set_tx_csum(struct net_device *netdev, uint32_t data)
+{
+ struct e1000_adapter *adapter = netdev->priv;
+
+ if(adapter->hw.mac_type < e1000_82543) {
+ if (!data)
+ return -EINVAL;
+ return 0;
+ }
+
+ if (data)
+ netdev->features |= NETIF_F_HW_CSUM;
+ else
+ netdev->features &= ~NETIF_F_HW_CSUM;
+
+ return 0;
+}
+
+#ifdef NETIF_F_TSO
+static int
+e1000_set_tso(struct net_device *netdev, uint32_t data)
+{
+ struct e1000_adapter *adapter = netdev->priv;
+ if ((adapter->hw.mac_type < e1000_82544) ||
+ (adapter->hw.mac_type == e1000_82547))
+ return data ? -EINVAL : 0;
+
+ if (data)
+ netdev->features |= NETIF_F_TSO;
+ else
+ netdev->features &= ~NETIF_F_TSO;
+ return 0;
+}
+#endif /* NETIF_F_TSO */
+
+static uint32_t
+e1000_get_msglevel(struct net_device *netdev)
+{
+ struct e1000_adapter *adapter = netdev->priv;
+ return adapter->msg_enable;
+}
+
static void
-e1000_ethtool_gdrvinfo(struct e1000_adapter *adapter,
- struct ethtool_drvinfo *drvinfo)
+e1000_set_msglevel(struct net_device *netdev, uint32_t data)
+{
+ struct e1000_adapter *adapter = netdev->priv;
+ adapter->msg_enable = data;
+}
+
+static int
+e1000_get_regs_len(struct net_device *netdev)
{
- strncpy(drvinfo->driver, e1000_driver_name, 32);
- strncpy(drvinfo->version, e1000_driver_version, 32);
- strncpy(drvinfo->fw_version, "N/A", 32);
- strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
- drvinfo->n_stats = E1000_STATS_LEN;
- drvinfo->testinfo_len = E1000_TEST_LEN;
#define E1000_REGS_LEN 32
- drvinfo->regdump_len = E1000_REGS_LEN * sizeof(uint32_t);
- drvinfo->eedump_len = adapter->hw.eeprom.word_size * 2;
+ return E1000_REGS_LEN * sizeof(uint32_t);
}
static void
-e1000_ethtool_gregs(struct e1000_adapter *adapter,
- struct ethtool_regs *regs, uint32_t *regs_buff)
+e1000_get_regs(struct net_device *netdev,
+ struct ethtool_regs *regs, void *p)
{
+ struct e1000_adapter *adapter = netdev->priv;
struct e1000_hw *hw = &adapter->hw;
+ uint32_t *regs_buff = p;
uint16_t phy_data;
+ memset(p, 0, E1000_REGS_LEN * sizeof(uint32_t));
+
regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
regs_buff[0] = E1000_READ_REG(hw, CTRL);
@@ -342,59 +418,72 @@
e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
regs_buff[24] = (uint32_t)phy_data; /* phy local receiver status */
regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
+}
- return;
+static int
+e1000_get_eeprom_len(struct net_device *netdev)
+{
+ struct e1000_adapter *adapter = netdev->priv;
+ return adapter->hw.eeprom.word_size * 2;
}
static int
-e1000_ethtool_geeprom(struct e1000_adapter *adapter,
- struct ethtool_eeprom *eeprom, uint16_t *eeprom_buff)
+e1000_get_eeprom(struct net_device *netdev,
+ struct ethtool_eeprom *eeprom, uint8_t *bytes)
{
+ struct e1000_adapter *adapter = netdev->priv;
struct e1000_hw *hw = &adapter->hw;
+ uint16_t *eeprom_buff;
int first_word, last_word;
int ret_val = 0;
+ uint16_t i;
- if(eeprom->len == 0) {
- ret_val = -EINVAL;
- goto geeprom_error;
- }
+ if(eeprom->len == 0)
+ return -EINVAL;
eeprom->magic = hw->vendor_id | (hw->device_id << 16);
- if(eeprom->offset > eeprom->offset + eeprom->len) {
- ret_val = -EINVAL;
- goto geeprom_error;
- }
-
- if((eeprom->offset + eeprom->len) > (hw->eeprom.word_size * 2))
- eeprom->len = ((hw->eeprom.word_size * 2) - eeprom->offset);
-
first_word = eeprom->offset >> 1;
last_word = (eeprom->offset + eeprom->len - 1) >> 1;
+ eeprom_buff = kmalloc(sizeof(uint16_t) *
+ (last_word - first_word + 1), GFP_KERNEL);
+ if (!eeprom_buff)
+ return -ENOMEM;
+
if(hw->eeprom.type == e1000_eeprom_spi)
ret_val = e1000_read_eeprom(hw, first_word,
last_word - first_word + 1,
eeprom_buff);
else {
- uint16_t i;
for (i = 0; i < last_word - first_word + 1; i++)
if((ret_val = e1000_read_eeprom(hw, first_word + i, 1,
&eeprom_buff[i])))
break;
}
-geeprom_error:
+
+ /* Device's eeprom is always little-endian, word addressable */
+ for (i = 0; i < last_word - first_word + 1; i++)
+ le16_to_cpus(&eeprom_buff[i]);
+
+
+ memcpy(bytes, (uint8_t *)eeprom_buff + (eeprom->offset%2),
+ eeprom->len);
+ kfree(eeprom_buff);
+
return ret_val;
}
static int
-e1000_ethtool_seeprom(struct e1000_adapter *adapter,
- struct ethtool_eeprom *eeprom, void *user_data)
+e1000_set_eeprom(struct net_device *netdev,
+ struct ethtool_eeprom *eeprom, uint8_t *bytes)
{
+ struct e1000_adapter *adapter = netdev->priv;
struct e1000_hw *hw = &adapter->hw;
uint16_t *eeprom_buff;
void *ptr;
int max_len, first_word, last_word, ret_val = 0;
+ uint16_t i;
if(eeprom->len == 0)
return -EOPNOTSUPP;
@@ -404,9 +493,6 @@
max_len = hw->eeprom.word_size * 2;
- if((eeprom->offset + eeprom->len) > max_len)
- eeprom->len = (max_len - eeprom->offset);
-
first_word = eeprom->offset >> 1;
last_word = (eeprom->offset + eeprom->len - 1) >> 1;
eeprom_buff = kmalloc(max_len, GFP_KERNEL);
@@ -428,10 +514,14 @@
ret_val = e1000_read_eeprom(hw, last_word, 1,
&eeprom_buff[last_word - first_word]);
}
- if((ret_val != 0) || copy_from_user(ptr, user_data, eeprom->len)) {
- ret_val = -EFAULT;
- goto seeprom_error;
- }
+
+ /* Device's eeprom is always little-endian, word addressable */
+ for (i = 0; i < last_word - first_word + 1; i++)
+ le16_to_cpus(&eeprom_buff[i]);
+
+ memcpy(ptr, bytes, eeprom->len);
+ for (i = 0; i < last_word - first_word + 1; i++)
+ eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
ret_val = e1000_write_eeprom(hw, first_word,
last_word - first_word + 1, eeprom_buff);
@@ -440,11 +530,107 @@
if((ret_val == 0) && first_word <= EEPROM_CHECKSUM_REG)
e1000_update_eeprom_checksum(hw);
-seeprom_error:
kfree(eeprom_buff);
return ret_val;
}
+static void
+e1000_get_drvinfo(struct net_device *netdev,
+ struct ethtool_drvinfo *drvinfo)
+{
+ struct e1000_adapter *adapter = netdev->priv;
+
+ strncpy(drvinfo->driver, e1000_driver_name, 32);
+ strncpy(drvinfo->version, e1000_driver_version, 32);
+ strncpy(drvinfo->fw_version, "N/A", 32);
+ strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
+ drvinfo->n_stats = E1000_STATS_LEN;
+ drvinfo->testinfo_len = E1000_TEST_LEN;
+ drvinfo->regdump_len = e1000_get_regs_len(netdev);
+ drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
+}
+
+static void
+e1000_get_ringparam(struct net_device *netdev,
+ struct ethtool_ringparam *ring)
+{
+ struct e1000_adapter *adapter = netdev->priv;
+ e1000_mac_type mac_type = adapter->hw.mac_type;
+ struct e1000_desc_ring *txdr = &adapter->tx_ring;
+ struct e1000_desc_ring *rxdr = &adapter->rx_ring;
+
+ ring->rx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_RXD :
+ E1000_MAX_82544_RXD;
+ ring->tx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_TXD :
+ E1000_MAX_82544_TXD;
+ 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
+e1000_set_ringparam(struct net_device *netdev,
+ struct ethtool_ringparam *ring)
+{
+ int err;
+ struct e1000_adapter *adapter = netdev->priv;
+ e1000_mac_type mac_type = adapter->hw.mac_type;
+ struct e1000_desc_ring *txdr = &adapter->tx_ring;
+ struct e1000_desc_ring *rxdr = &adapter->rx_ring;
+ struct e1000_desc_ring tx_old, tx_new;
+ struct e1000_desc_ring rx_old, rx_new;
+
+ tx_old = adapter->tx_ring;
+ rx_old = adapter->rx_ring;
+
+ if(netif_running(adapter->netdev))
+ e1000_down(adapter);
+
+ rxdr->count = max(ring->rx_pending,(uint32_t)E1000_MIN_RXD);
+ rxdr->count = min(rxdr->count,(uint32_t)(mac_type < e1000_82544 ?
+ E1000_MAX_RXD : E1000_MAX_82544_RXD));
+ E1000_ROUNDUP(rxdr->count, REQ_RX_DESCRIPTOR_MULTIPLE);
+
+ txdr->count = max(ring->tx_pending,(uint32_t)E1000_MIN_TXD);
+ txdr->count = min(txdr->count,(uint32_t)(mac_type < e1000_82544 ?
+ E1000_MAX_TXD : E1000_MAX_82544_TXD));
+ E1000_ROUNDUP(txdr->count, REQ_TX_DESCRIPTOR_MULTIPLE);
+
+ if(netif_running(adapter->netdev)) {
+ /* try to get new resources before deleting old */
+ if((err = e1000_setup_rx_resources(adapter)))
+ goto err_setup_rx;
+ if((err = e1000_setup_tx_resources(adapter)))
+ goto err_setup_tx;
+
+ /* save the new, restore the old in order to free it,
+ * then restore the new back again */
+
+ rx_new = adapter->rx_ring;
+ tx_new = adapter->tx_ring;
+ adapter->rx_ring = rx_old;
+ adapter->tx_ring = tx_old;
+ e1000_free_rx_resources(adapter);
+ e1000_free_tx_resources(adapter);
+ adapter->rx_ring = rx_new;
+ adapter->tx_ring = tx_new;
+ if((err = e1000_up(adapter)))
+ return err;
+ }
+ return 0;
+err_setup_tx:
+ e1000_free_rx_resources(adapter);
+err_setup_rx:
+ adapter->rx_ring = rx_old;
+ adapter->tx_ring = tx_old;
+ e1000_up(adapter);
+ return err;
+}
+
+
#define REG_PATTERN_TEST(R, M, W) \
{ \
uint32_t pat, value; \
@@ -535,6 +721,7 @@
for(i = 0; i < E1000_MC_TBL_SIZE; i++)
REG_PATTERN_TEST(MTA + (i << 2), 0xFFFFFFFF, 0xFFFFFFFF);
+ *data = 0;
return 0;
}
@@ -846,8 +1033,6 @@
e1000_write_phy_reg(&adapter->hw, 30, 0x8FFC);
e1000_write_phy_reg(&adapter->hw, 29, 0x001A);
e1000_write_phy_reg(&adapter->hw, 30, 0x8FF0);
-
- return;
}
static void
@@ -1164,15 +1349,27 @@
return *data;
}
-static int
-e1000_ethtool_test(struct e1000_adapter *adapter,
+static int
+e1000_diag_test_count(struct net_device *netdev)
+{
+ return E1000_TEST_LEN;
+}
+
+static void
+e1000_diag_test(struct net_device *netdev,
struct ethtool_test *eth_test, uint64_t *data)
{
- boolean_t if_running = netif_running(adapter->netdev);
+ struct e1000_adapter *adapter = netdev->priv;
+ boolean_t if_running = netif_running(netdev);
if(eth_test->flags == ETH_TEST_FL_OFFLINE) {
/* Offline tests */
+ /* save speed, duplex, autoneg settings */
+ uint16_t autoneg_advertised = adapter->hw.autoneg_advertised;
+ uint8_t forced_speed_duplex = adapter->hw.forced_speed_duplex;
+ uint8_t autoneg = adapter->hw.autoneg;
+
/* Link test performed before hardware reset so autoneg doesn't
* interfere with test result */
if(e1000_link_test(adapter, &data[4]))
@@ -1198,6 +1395,10 @@
if(e1000_loopback_test(adapter, &data[3]))
eth_test->flags |= ETH_TEST_FL_FAILED;
+ /* restore Autoneg/speed/duplex settings */
+ adapter->hw.autoneg_advertised = autoneg_advertised;
+ adapter->hw.forced_speed_duplex = forced_speed_duplex;
+ adapter->hw.autoneg = autoneg;
e1000_reset(adapter);
if(if_running)
e1000_up(adapter);
@@ -1212,12 +1413,12 @@
data[2] = 0;
data[3] = 0;
}
- return 0;
}
static void
-e1000_ethtool_gwol(struct e1000_adapter *adapter, struct ethtool_wolinfo *wol)
+e1000_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
{
+ struct e1000_adapter *adapter = netdev->priv;
struct e1000_hw *hw = &adapter->hw;
switch(adapter->hw.device_id) {
@@ -1257,8 +1458,9 @@
}
static int
-e1000_ethtool_swol(struct e1000_adapter *adapter, struct ethtool_wolinfo *wol)
+e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
{
+ struct e1000_adapter *adapter = netdev->priv;
struct e1000_hw *hw = &adapter->hw;
switch(adapter->hw.device_id) {
@@ -1294,7 +1496,6 @@
return 0;
}
-
/* toggle LED 4 times per second = 2 "blinks" per second */
#define E1000_ID_INTERVAL (HZ/4)
@@ -1315,8 +1516,13 @@
}
static int
-e1000_ethtool_led_blink(struct e1000_adapter *adapter, struct ethtool_value *id)
+e1000_phys_id(struct net_device *netdev, uint32_t data)
{
+ struct e1000_adapter *adapter = netdev->priv;
+
+ if(!data || data > (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ))
+ data = (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ);
+
if(!adapter->blink_timer.function) {
init_timer(&adapter->blink_timer);
adapter->blink_timer.function = e1000_led_blink_callback;
@@ -1327,11 +1533,8 @@
mod_timer(&adapter->blink_timer, jiffies);
set_current_state(TASK_INTERRUPTIBLE);
- if(id->data)
- schedule_timeout(id->data * HZ);
- else
- schedule_timeout(MAX_SCHEDULE_TIMEOUT);
+ schedule_timeout(data * HZ);
del_timer_sync(&adapter->blink_timer);
e1000_led_off(&adapter->hw);
clear_bit(E1000_LED_ON, &adapter->led_status);
@@ -1340,329 +1543,96 @@
return 0;
}
-int
-e1000_ethtool_ioctl(struct net_device *netdev, struct ifreq *ifr)
+static int
+e1000_nway_reset(struct net_device *netdev)
{
struct e1000_adapter *adapter = netdev->priv;
- void *addr = ifr->ifr_data;
- uint32_t cmd;
-
- if(get_user(cmd, (uint32_t *) addr))
- return -EFAULT;
-
- switch(cmd) {
- case ETHTOOL_GSET: {
- struct ethtool_cmd ecmd = {ETHTOOL_GSET};
- e1000_ethtool_gset(adapter, &ecmd);
- if(copy_to_user(addr, &ecmd, sizeof(ecmd)))
- return -EFAULT;
- return 0;
- }
- case ETHTOOL_SSET: {
- struct ethtool_cmd ecmd;
- if(copy_from_user(&ecmd, addr, sizeof(ecmd)))
- return -EFAULT;
- return e1000_ethtool_sset(adapter, &ecmd);
- }
- case ETHTOOL_GDRVINFO: {
- struct ethtool_drvinfo drvinfo = {ETHTOOL_GDRVINFO};
- e1000_ethtool_gdrvinfo(adapter, &drvinfo);
- if(copy_to_user(addr, &drvinfo, sizeof(drvinfo)))
- return -EFAULT;
- return 0;
- }
- case ETHTOOL_GSTRINGS: {
- struct ethtool_gstrings gstrings = { ETHTOOL_GSTRINGS };
- char *strings = NULL;
- int err = 0;
-
- if(copy_from_user(&gstrings, addr, sizeof(gstrings)))
- return -EFAULT;
- switch(gstrings.string_set) {
- case ETH_SS_TEST:
- gstrings.len = E1000_TEST_LEN;
- strings = kmalloc(E1000_TEST_LEN * ETH_GSTRING_LEN,
- GFP_KERNEL);
- if(!strings)
- return -ENOMEM;
- memcpy(strings, e1000_gstrings_test, E1000_TEST_LEN *
- ETH_GSTRING_LEN);
- break;
- case ETH_SS_STATS: {
- int i;
- gstrings.len = E1000_STATS_LEN;
- strings = kmalloc(E1000_STATS_LEN * ETH_GSTRING_LEN,
- GFP_KERNEL);
- if(!strings)
- return -ENOMEM;
- for(i=0; i < E1000_STATS_LEN; i++) {
- memcpy(&strings[i * ETH_GSTRING_LEN],
- e1000_gstrings_stats[i].stat_string,
- ETH_GSTRING_LEN);
- }
- break;
- }
- default:
- return -EOPNOTSUPP;
- }
- if(copy_to_user(addr, &gstrings, sizeof(gstrings)))
- err = -EFAULT;
- addr += offsetof(struct ethtool_gstrings, data);
- if(!err && copy_to_user(addr, strings,
- gstrings.len * ETH_GSTRING_LEN))
- err = -EFAULT;
-
- kfree(strings);
- return err;
- }
- case ETHTOOL_GREGS: {
- struct ethtool_regs regs = {ETHTOOL_GREGS};
- uint32_t regs_buff[E1000_REGS_LEN];
-
- if(copy_from_user(®s, addr, sizeof(regs)))
- return -EFAULT;
- e1000_ethtool_gregs(adapter, ®s, regs_buff);
- if(copy_to_user(addr, ®s, sizeof(regs)))
- return -EFAULT;
-
- addr += offsetof(struct ethtool_regs, data);
- if(copy_to_user(addr, regs_buff, regs.len))
- return -EFAULT;
-
- return 0;
- }
- case ETHTOOL_NWAY_RST: {
- if(netif_running(netdev)) {
- e1000_down(adapter);
- e1000_up(adapter);
- }
- return 0;
- }
- case ETHTOOL_PHYS_ID: {
- struct ethtool_value id;
- if(copy_from_user(&id, addr, sizeof(id)))
- return -EFAULT;
- return e1000_ethtool_led_blink(adapter, &id);
- }
- case ETHTOOL_GLINK: {
- struct ethtool_value link = {ETHTOOL_GLINK};
- link.data = netif_carrier_ok(netdev);
- if(copy_to_user(addr, &link, sizeof(link)))
- return -EFAULT;
- return 0;
- }
- case ETHTOOL_GWOL: {
- struct ethtool_wolinfo wol = {ETHTOOL_GWOL};
- e1000_ethtool_gwol(adapter, &wol);
- if(copy_to_user(addr, &wol, sizeof(wol)) != 0)
- return -EFAULT;
- return 0;
- }
- case ETHTOOL_SWOL: {
- struct ethtool_wolinfo wol;
- if(copy_from_user(&wol, addr, sizeof(wol)) != 0)
- return -EFAULT;
- return e1000_ethtool_swol(adapter, &wol);
- }
- case ETHTOOL_GEEPROM: {
- struct ethtool_eeprom eeprom = {ETHTOOL_GEEPROM};
- struct e1000_hw *hw = &adapter->hw;
- uint16_t *eeprom_buff;
- void *ptr;
- int err = 0;
-
- if(copy_from_user(&eeprom, addr, sizeof(eeprom)))
- return -EFAULT;
-
- eeprom_buff = kmalloc(hw->eeprom.word_size * 2, GFP_KERNEL);
-
- if(!eeprom_buff)
- return -ENOMEM;
-
- if((err = e1000_ethtool_geeprom(adapter, &eeprom,
- eeprom_buff)))
- goto err_geeprom_ioctl;
-
- if(copy_to_user(addr, &eeprom, sizeof(eeprom))) {
- err = -EFAULT;
- goto err_geeprom_ioctl;
- }
-
- addr += offsetof(struct ethtool_eeprom, data);
- ptr = ((void *)eeprom_buff) + (eeprom.offset & 1);
-
- if(copy_to_user(addr, ptr, eeprom.len))
- err = -EFAULT;
-
-err_geeprom_ioctl:
- kfree(eeprom_buff);
- return err;
- }
- case ETHTOOL_SEEPROM: {
- struct ethtool_eeprom eeprom;
-
- if(copy_from_user(&eeprom, addr, sizeof(eeprom)))
- return -EFAULT;
-
- addr += offsetof(struct ethtool_eeprom, data);
- return e1000_ethtool_seeprom(adapter, &eeprom, addr);
- }
- case ETHTOOL_GPAUSEPARAM: {
- struct ethtool_pauseparam epause = {ETHTOOL_GPAUSEPARAM};
- e1000_ethtool_gpause(adapter, &epause);
- if(copy_to_user(addr, &epause, sizeof(epause)))
- return -EFAULT;
- return 0;
- }
- case ETHTOOL_SPAUSEPARAM: {
- struct ethtool_pauseparam epause;
- if(copy_from_user(&epause, addr, sizeof(epause)))
- return -EFAULT;
- return e1000_ethtool_spause(adapter, &epause);
- }
- case ETHTOOL_GSTATS: {
- struct {
- struct ethtool_stats eth_stats;
- uint64_t data[E1000_STATS_LEN];
- } stats = { {ETHTOOL_GSTATS, E1000_STATS_LEN} };
- int i;
-
- e1000_update_stats(adapter);
- for(i = 0; i < E1000_STATS_LEN; i++)
- stats.data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
- sizeof(uint64_t)) ?
- *(uint64_t *)((char *)adapter +
- e1000_gstrings_stats[i].stat_offset) :
- *(uint32_t *)((char *)adapter +
- e1000_gstrings_stats[i].stat_offset);
- if(copy_to_user(addr, &stats, sizeof(stats)))
- return -EFAULT;
- return 0;
- }
- case ETHTOOL_TEST: {
- struct {
- struct ethtool_test eth_test;
- uint64_t data[E1000_TEST_LEN];
- } test = { {ETHTOOL_TEST} };
- int err;
-
- if(copy_from_user(&test.eth_test, addr, sizeof(test.eth_test)))
- return -EFAULT;
-
- test.eth_test.len = E1000_TEST_LEN;
-
- if((err = e1000_ethtool_test(adapter, &test.eth_test,
- test.data)))
- return err;
-
- if(copy_to_user(addr, &test, sizeof(test)) != 0)
- return -EFAULT;
- return 0;
+ if(netif_running(netdev)) {
+ e1000_down(adapter);
+ e1000_up(adapter);
}
- case ETHTOOL_GRXCSUM: {
- struct ethtool_value edata = { ETHTOOL_GRXCSUM };
+ return 0;
+}
- edata.data = adapter->rx_csum;
- if (copy_to_user(addr, &edata, sizeof(edata)))
- return -EFAULT;
- return 0;
- }
- case ETHTOOL_SRXCSUM: {
- struct ethtool_value edata;
+static int
+e1000_get_stats_count(struct net_device *netdev)
+{
+ return E1000_STATS_LEN;
+}
- if (copy_from_user(&edata, addr, sizeof(edata)))
- return -EFAULT;
- adapter->rx_csum = edata.data;
- if(netif_running(netdev)) {
- e1000_down(adapter);
- e1000_up(adapter);
- } else
- e1000_reset(adapter);
- return 0;
- }
- case ETHTOOL_GTXCSUM: {
- struct ethtool_value edata = { ETHTOOL_GTXCSUM };
+static void
+e1000_get_ethtool_stats(struct net_device *netdev,
+ struct ethtool_stats *stats, uint64_t *data)
+{
+ struct e1000_adapter *adapter = netdev->priv;
+ int i;
- edata.data =
- (netdev->features & NETIF_F_HW_CSUM) != 0;
- if (copy_to_user(addr, &edata, sizeof(edata)))
- return -EFAULT;
- return 0;
+ e1000_update_stats(adapter);
+ for(i = 0; i < E1000_STATS_LEN; i++) {
+ char *p = (char *)adapter+e1000_gstrings_stats[i].stat_offset;
+ data[i] = (e1000_gstrings_stats[i].sizeof_stat == sizeof(uint64_t))
+ ? *(uint64_t *)p : *(uint32_t *)p;
}
- case ETHTOOL_STXCSUM: {
- struct ethtool_value edata;
+}
- if (copy_from_user(&edata, addr, sizeof(edata)))
- return -EFAULT;
+static void
+e1000_get_strings(struct net_device *netdev, uint32_t stringset, uint8_t *data)
+{
+ int i;
- if(adapter->hw.mac_type < e1000_82543) {
- if (edata.data != 0)
- return -EINVAL;
- return 0;
+ switch(stringset) {
+ case ETH_SS_TEST:
+ memcpy(data, *e1000_gstrings_test,
+ E1000_TEST_LEN*ETH_GSTRING_LEN);
+ break;
+ case ETH_SS_STATS:
+ for (i=0; i < E1000_STATS_LEN; i++) {
+ memcpy(data + i * ETH_GSTRING_LEN,
+ e1000_gstrings_stats[i].stat_string,
+ ETH_GSTRING_LEN);
}
-
- if (edata.data)
- netdev->features |= NETIF_F_HW_CSUM;
- else
- netdev->features &= ~NETIF_F_HW_CSUM;
-
- return 0;
- }
- case ETHTOOL_GSG: {
- struct ethtool_value edata = { ETHTOOL_GSG };
-
- edata.data =
- (netdev->features & NETIF_F_SG) != 0;
- if (copy_to_user(addr, &edata, sizeof(edata)))
- return -EFAULT;
- return 0;
+ break;
}
- case ETHTOOL_SSG: {
- struct ethtool_value edata;
-
- if (copy_from_user(&edata, addr, sizeof(edata)))
- return -EFAULT;
-
- if (edata.data)
- netdev->features |= NETIF_F_SG;
- else
- netdev->features &= ~NETIF_F_SG;
+}
- return 0;
- }
+struct ethtool_ops e1000_ethtool_ops = {
+ .get_settings = e1000_get_settings,
+ .set_settings = e1000_set_settings,
+ .get_drvinfo = e1000_get_drvinfo,
+ .get_regs_len = e1000_get_regs_len,
+ .get_regs = e1000_get_regs,
+ .get_wol = e1000_get_wol,
+ .set_wol = e1000_set_wol,
+ .get_msglevel = e1000_get_msglevel,
+ .set_msglevel = e1000_set_msglevel,
+ .nway_reset = e1000_nway_reset,
+ .get_link = ethtool_op_get_link,
+ .get_eeprom_len = e1000_get_eeprom_len,
+ .get_eeprom = e1000_get_eeprom,
+ .set_eeprom = e1000_set_eeprom,
+ .get_ringparam = e1000_get_ringparam,
+ .set_ringparam = e1000_set_ringparam,
+ .get_pauseparam = e1000_get_pauseparam,
+ .set_pauseparam = e1000_set_pauseparam,
+ .get_rx_csum = e1000_get_rx_csum,
+ .set_rx_csum = e1000_set_rx_csum,
+ .get_tx_csum = e1000_get_tx_csum,
+ .set_tx_csum = e1000_set_tx_csum,
+ .get_sg = ethtool_op_get_sg,
+ .set_sg = ethtool_op_set_sg,
#ifdef NETIF_F_TSO
- case ETHTOOL_GTSO: {
- struct ethtool_value edata = { ETHTOOL_GTSO };
-
- edata.data = (netdev->features & NETIF_F_TSO) != 0;
- if (copy_to_user(addr, &edata, sizeof(edata)))
- return -EFAULT;
- return 0;
- }
- case ETHTOOL_STSO: {
- struct ethtool_value edata;
-
- if (copy_from_user(&edata, addr, sizeof(edata)))
- return -EFAULT;
-
- if ((adapter->hw.mac_type < e1000_82544) ||
- (adapter->hw.mac_type == e1000_82547)) {
- if (edata.data != 0)
- return -EINVAL;
- return 0;
- }
-
- if (edata.data)
- netdev->features |= NETIF_F_TSO;
- else
- netdev->features &= ~NETIF_F_TSO;
-
- return 0;
- }
+ .get_tso = ethtool_op_get_tso,
+ .set_tso = e1000_set_tso,
#endif
- default:
- return -EOPNOTSUPP;
- }
-}
-
+ .self_test_count = e1000_diag_test_count,
+ .self_test = e1000_diag_test,
+ .get_strings = e1000_get_strings,
+ .phys_id = e1000_phys_id,
+ .get_stats_count = e1000_get_stats_count,
+ .get_ethtool_stats = e1000_get_ethtool_stats,
+};
+void set_ethtool_ops(struct net_device *netdev)
+{
+ SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
+}
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)