ethdev: use constants for link state
[dpdk.git] / drivers / net / e1000 / em_ethdev.c
index a009bc2..9c50674 100644 (file)
@@ -231,6 +231,32 @@ rte_em_dev_atomic_write_link_status(struct rte_eth_dev *dev,
        return 0;
 }
 
+/**
+ *  eth_em_dev_is_ich8 - Check for ICH8 device
+ *  @hw: pointer to the HW structure
+ *
+ *  return TRUE for ICH8, otherwise FALSE
+ **/
+static bool
+eth_em_dev_is_ich8(struct e1000_hw *hw)
+{
+       DEBUGFUNC("eth_em_dev_is_ich8");
+
+       switch (hw->device_id) {
+       case E1000_DEV_ID_PCH_LPT_I217_LM:
+       case E1000_DEV_ID_PCH_LPT_I217_V:
+       case E1000_DEV_ID_PCH_LPTLP_I218_LM:
+       case E1000_DEV_ID_PCH_LPTLP_I218_V:
+       case E1000_DEV_ID_PCH_I218_V2:
+       case E1000_DEV_ID_PCH_I218_LM2:
+       case E1000_DEV_ID_PCH_I218_V3:
+       case E1000_DEV_ID_PCH_I218_LM3:
+               return 1;
+       default:
+               return 0;
+       }
+}
+
 static int
 eth_em_dev_init(struct rte_eth_dev *eth_dev)
 {
@@ -243,6 +269,7 @@ eth_em_dev_init(struct rte_eth_dev *eth_dev)
                E1000_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
 
        pci_dev = eth_dev->pci_dev;
+
        eth_dev->dev_ops = &eth_em_ops;
        eth_dev->rx_pkt_burst = (eth_rx_burst_t)&eth_em_recv_pkts;
        eth_dev->tx_pkt_burst = (eth_tx_burst_t)&eth_em_xmit_pkts;
@@ -257,11 +284,15 @@ eth_em_dev_init(struct rte_eth_dev *eth_dev)
                return 0;
        }
 
+       rte_eth_copy_pci_info(eth_dev, pci_dev);
+
        hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
        hw->device_id = pci_dev->id.device_id;
        adapter->stopped = 0;
 
        /* For ICH8 support we'll need to map the flash memory BAR */
+       if (eth_em_dev_is_ich8(hw))
+               hw->flash_address = (void *)pci_dev->mem_resource[1].addr;
 
        if (e1000_setup_init_funcs(hw, TRUE) != E1000_SUCCESS ||
                        em_hw_init(hw) != 0) {
@@ -269,7 +300,7 @@ eth_em_dev_init(struct rte_eth_dev *eth_dev)
                        "failed to init HW",
                        eth_dev->data->port_id, pci_dev->id.vendor_id,
                        pci_dev->id.device_id);
-               return -(ENODEV);
+               return -ENODEV;
        }
 
        /* Allocate memory for storing MAC addresses */
@@ -279,7 +310,7 @@ eth_em_dev_init(struct rte_eth_dev *eth_dev)
                PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to "
                        "store MAC addresses",
                        ETHER_ADDR_LEN * hw->mac.rar_entry_count);
-               return -(ENOMEM);
+               return -ENOMEM;
        }
 
        /* Copy the permanent MAC address */
@@ -296,7 +327,7 @@ eth_em_dev_init(struct rte_eth_dev *eth_dev)
        rte_intr_callback_register(&(pci_dev->intr_handle),
                eth_em_interrupt_handler, (void *)eth_dev);
 
-       return (0);
+       return 0;
 }
 
 static int
@@ -428,11 +459,11 @@ em_hw_init(struct e1000_hw *hw)
                PMD_INIT_LOG(ERR, "PHY reset is blocked due to "
                        "SOL/IDER session");
        }
-       return (0);
+       return 0;
 
 error:
        em_hw_control_release(hw);
-       return (diag);
+       return diag;
 }
 
 static int
@@ -445,7 +476,7 @@ eth_em_configure(struct rte_eth_dev *dev)
        intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
        PMD_INIT_FUNC_TRACE();
 
-       return (0);
+       return 0;
 }
 
 static void
@@ -487,6 +518,7 @@ em_set_pba(struct e1000_hw *hw)
                        break;
                case e1000_pchlan:
                case e1000_pch2lan:
+               case e1000_pch_lpt:
                        pba = E1000_PBA_26K;
                        break;
                default:
@@ -533,7 +565,7 @@ eth_em_start(struct rte_eth_dev *dev)
        /* Initialize the hardware */
        if (em_hardware_init(hw)) {
                PMD_INIT_LOG(ERR, "Unable to initialize the hardware");
-               return (-EIO);
+               return -EIO;
        }
 
        E1000_WRITE_REG(hw, E1000_VET, ETHER_TYPE_VLAN);
@@ -634,13 +666,14 @@ eth_em_start(struct rte_eth_dev *dev)
 
        if (rte_intr_allow_others(intr_handle)) {
                /* check if lsc interrupt is enabled */
-               if (dev->data->dev_conf.intr_conf.lsc != 0)
+               if (dev->data->dev_conf.intr_conf.lsc != 0) {
                        ret = eth_em_interrupt_setup(dev);
                        if (ret) {
                                PMD_INIT_LOG(ERR, "Unable to setup interrupts");
                                em_dev_clear_queues(dev);
                                return ret;
                        }
+               }
        } else {
                rte_intr_callback_unregister(intr_handle,
                                                eth_em_interrupt_handler,
@@ -659,14 +692,14 @@ eth_em_start(struct rte_eth_dev *dev)
 
        PMD_INIT_LOG(DEBUG, "<<");
 
-       return (0);
+       return 0;
 
 error_invalid_config:
        PMD_INIT_LOG(ERR, "Invalid link_speed/link_duplex (%u/%u) for port %u",
                     dev->data->dev_conf.link_speed,
                     dev->data->dev_conf.link_duplex, dev->data->port_id);
        em_dev_clear_queues(dev);
-       return (-EINVAL);
+       return -EINVAL;
 }
 
 /*********************************************************************
@@ -795,13 +828,15 @@ em_hardware_init(struct e1000_hw *hw)
                hw->fc.low_water = 0x5048;
                hw->fc.pause_time = 0x0650;
                hw->fc.refresh_time = 0x0400;
+       } else if (hw->mac.type == e1000_pch_lpt) {
+               hw->fc.requested_mode = e1000_fc_full;
        }
 
        diag = e1000_init_hw(hw);
        if (diag < 0)
-               return (diag);
+               return diag;
        e1000_check_for_link(hw);
-       return (0);
+       return 0;
 }
 
 /* This function is based on em_update_stats_counters() in e1000/if_em.c */
@@ -908,12 +943,9 @@ eth_em_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
                return;
 
        /* Rx Errors */
-       rte_stats->ibadcrc = stats->crcerrs;
-       rte_stats->ibadlen = stats->rlec + stats->ruc + stats->roc;
        rte_stats->imissed = stats->mpc;
-       rte_stats->ierrors = rte_stats->ibadcrc +
-                            rte_stats->ibadlen +
-                            rte_stats->imissed +
+       rte_stats->ierrors = stats->crcerrs +
+                            stats->rlec + stats->ruc + stats->roc +
                             stats->rxerrc + stats->algnerrc + stats->cexterr;
 
        /* Tx Errors */
@@ -923,12 +955,6 @@ eth_em_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
        rte_stats->opackets = stats->gptc;
        rte_stats->ibytes   = stats->gorc;
        rte_stats->obytes   = stats->gotc;
-
-       /* XON/XOFF pause frames stats registers */
-       rte_stats->tx_pause_xon  = stats->xontxc;
-       rte_stats->rx_pause_xon  = stats->xonrxc;
-       rte_stats->tx_pause_xoff = stats->xofftxc;
-       rte_stats->rx_pause_xoff = stats->xoffrxc;
 }
 
 static void
@@ -974,17 +1000,18 @@ em_get_max_pktlen(const struct e1000_hw *hw)
        case e1000_ich9lan:
        case e1000_ich10lan:
        case e1000_pch2lan:
+       case e1000_pch_lpt:
        case e1000_82574:
        case e1000_80003es2lan: /* 9K Jumbo Frame size */
        case e1000_82583:
-               return (0x2412);
+               return 0x2412;
        case e1000_pchlan:
-               return (0x1000);
+               return 0x1000;
        /* Adapters that do not support jumbo frames */
        case e1000_ich8lan:
-               return (ETHER_MAX_LEN);
+               return ETHER_MAX_LEN;
        default:
-               return (MAX_JUMBO_FRAME_SIZE);
+               return MAX_JUMBO_FRAME_SIZE;
        }
 }
 
@@ -1075,14 +1102,14 @@ eth_em_link_update(struct rte_eth_dev *dev, int wait_to_complete)
        old = link;
 
        /* Now we check if a transition has happened */
-       if (link_check && (link.link_status == 0)) {
+       if (link_check && (link.link_status == ETH_LINK_DOWN)) {
                hw->mac.ops.get_link_up_info(hw, &link.link_speed,
                        &link.link_duplex);
-               link.link_status = 1;
-       } else if (!link_check && (link.link_status == 1)) {
+               link.link_status = ETH_LINK_UP;
+       } else if (!link_check && (link.link_status == ETH_LINK_UP)) {
                link.link_speed = 0;
                link.link_duplex = 0;
-               link.link_status = 0;
+               link.link_status = ETH_LINK_DOWN;
        }
        rte_em_dev_atomic_write_link_status(dev, &link);
 
@@ -1365,7 +1392,7 @@ eth_em_interrupt_setup(struct rte_eth_dev *dev)
        E1000_READ_REG(hw, E1000_ICR);
        regval = E1000_READ_REG(hw, E1000_IMS);
        E1000_WRITE_REG(hw, E1000_IMS, regval | E1000_ICR_LSC);
-       return (0);
+       return 0;
 }
 
 /*
@@ -1557,7 +1584,7 @@ eth_em_led_on(struct rte_eth_dev *dev)
        struct e1000_hw *hw;
 
        hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-       return (e1000_led_on(hw) == E1000_SUCCESS ? 0 : -ENOTSUP);
+       return e1000_led_on(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
 }
 
 static int
@@ -1566,7 +1593,7 @@ eth_em_led_off(struct rte_eth_dev *dev)
        struct e1000_hw *hw;
 
        hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
-       return (e1000_led_off(hw) == E1000_SUCCESS ? 0 : -ENOTSUP);
+       return e1000_led_off(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
 }
 
 static int
@@ -1638,7 +1665,7 @@ eth_em_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
            (fc_conf->high_water < fc_conf->low_water)) {
                PMD_INIT_LOG(ERR, "e1000 incorrect high/low water value");
                PMD_INIT_LOG(ERR, "high water must <= 0x%x", max_high_water);
-               return (-EINVAL);
+               return -EINVAL;
        }
 
        hw->fc.requested_mode = rte_fcmode_2_e1000_fcmode[fc_conf->mode];
@@ -1668,7 +1695,7 @@ eth_em_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
        }
 
        PMD_INIT_LOG(ERR, "e1000_setup_link_generic = 0x%x", err);
-       return (-EIO);
+       return -EIO;
 }
 
 static void