i40e: Fix for extra Flow Director filter in table after error
[firefly-linux-kernel-4.4.55.git] / drivers / net / ethernet / intel / i40e / i40e_main.c
index 940744a7f936256e7dca7b95cc837b14973f1994..949535684fa9f1bc0fecfe1480296c39d24fa44f 100644 (file)
@@ -75,10 +75,13 @@ static const struct pci_device_id i40e_pci_tbl[] = {
        {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0},
        {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0},
        {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0},
+       {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0},
        {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
        {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0},
        {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0},
        {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0},
+       {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
+       {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0},
        /* required last entry */
        {0, }
 };
@@ -876,6 +879,7 @@ static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
        u32 rx_page, rx_buf;
        u64 bytes, packets;
        unsigned int start;
+       u64 tx_linearize;
        u64 rx_p, rx_b;
        u64 tx_p, tx_b;
        u16 q;
@@ -894,7 +898,7 @@ static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
         */
        rx_b = rx_p = 0;
        tx_b = tx_p = 0;
-       tx_restart = tx_busy = 0;
+       tx_restart = tx_busy = tx_linearize = 0;
        rx_page = 0;
        rx_buf = 0;
        rcu_read_lock();
@@ -911,6 +915,7 @@ static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
                tx_p += packets;
                tx_restart += p->tx_stats.restart_queue;
                tx_busy += p->tx_stats.tx_busy;
+               tx_linearize += p->tx_stats.tx_linearize;
 
                /* Rx queue is part of the same block as Tx queue */
                p = &p[1];
@@ -927,6 +932,7 @@ static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
        rcu_read_unlock();
        vsi->tx_restart = tx_restart;
        vsi->tx_busy = tx_busy;
+       vsi->tx_linearize = tx_linearize;
        vsi->rx_page_failed = rx_page;
        vsi->rx_buf_failed = rx_buf;
 
@@ -1723,36 +1729,27 @@ static void i40e_set_rx_mode(struct net_device *netdev)
 
        /* remove filter if not in netdev list */
        list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
-               bool found = false;
 
                if (!f->is_netdev)
                        continue;
 
-               if (is_multicast_ether_addr(f->macaddr)) {
-                       netdev_for_each_mc_addr(mca, netdev) {
-                               if (ether_addr_equal(mca->addr, f->macaddr)) {
-                                       found = true;
-                                       break;
-                               }
-                       }
-               } else {
-                       netdev_for_each_uc_addr(uca, netdev) {
-                               if (ether_addr_equal(uca->addr, f->macaddr)) {
-                                       found = true;
-                                       break;
-                               }
-                       }
+               netdev_for_each_mc_addr(mca, netdev)
+                       if (ether_addr_equal(mca->addr, f->macaddr))
+                               goto bottom_of_search_loop;
 
-                       for_each_dev_addr(netdev, ha) {
-                               if (ether_addr_equal(ha->addr, f->macaddr)) {
-                                       found = true;
-                                       break;
-                               }
-                       }
-               }
-               if (!found)
-                       i40e_del_filter(
-                          vsi, f->macaddr, I40E_VLAN_ANY, false, true);
+               netdev_for_each_uc_addr(uca, netdev)
+                       if (ether_addr_equal(uca->addr, f->macaddr))
+                               goto bottom_of_search_loop;
+
+               for_each_dev_addr(netdev, ha)
+                       if (ether_addr_equal(ha->addr, f->macaddr))
+                               goto bottom_of_search_loop;
+
+               /* f->macaddr wasn't found in uc, mc, or ha list so delete it */
+               i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY, false, true);
+
+bottom_of_search_loop:
+               continue;
        }
 
        /* check for other flag changes */
@@ -2689,7 +2686,8 @@ static int i40e_configure_rx_ring(struct i40e_ring *ring)
                rx_ctx.lrxqthresh = 2;
        rx_ctx.crcstrip = 1;
        rx_ctx.l2tsel = 1;
-       rx_ctx.showiv = 1;
+       /* this controls whether VLAN is stripped from inner headers */
+       rx_ctx.showiv = 0;
 #ifdef I40E_FCOE
        rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
 #endif
@@ -3061,24 +3059,6 @@ void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf)
        i40e_flush(hw);
 }
 
-/**
- * i40e_irq_dynamic_enable - Enable default interrupt generation settings
- * @vsi: pointer to a vsi
- * @vector: enable a particular Hw Interrupt vector
- **/
-void i40e_irq_dynamic_enable(struct i40e_vsi *vsi, int vector)
-{
-       struct i40e_pf *pf = vsi->back;
-       struct i40e_hw *hw = &pf->hw;
-       u32 val;
-
-       val = I40E_PFINT_DYN_CTLN_INTENA_MASK |
-             I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
-             (I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
-       wr32(hw, I40E_PFINT_DYN_CTLN(vector - 1), val);
-       /* skip the flush */
-}
-
 /**
  * i40e_irq_dynamic_disable - Disable default interrupt generation settings
  * @vsi: pointer to a vsi
@@ -3152,8 +3132,7 @@ static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
                                  q_vector);
                if (err) {
                        dev_info(&pf->pdev->dev,
-                                "%s: request_irq failed, error: %d\n",
-                                __func__, err);
+                                "MSIX request_irq failed, error: %d\n", err);
                        goto free_queue_irqs;
                }
                /* assign the mask for this irq */
@@ -3218,8 +3197,7 @@ static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
        int i;
 
        if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
-               for (i = vsi->base_vector;
-                    i < (vsi->num_q_vectors + vsi->base_vector); i++)
+               for (i = 0; i < vsi->num_q_vectors; i++)
                        i40e_irq_dynamic_enable(vsi, i);
        } else {
                i40e_irq_dynamic_enable_icr0(pf);
@@ -3451,8 +3429,7 @@ static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
        tx_ring->next_to_clean = i;
 
        if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) {
-               i40e_irq_dynamic_enable(vsi,
-                               tx_ring->q_vector->v_idx + vsi->base_vector);
+               i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
        }
        return budget > 0;
 }
@@ -3679,9 +3656,8 @@ static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
                ret = i40e_pf_txq_wait(pf, pf_q, enable);
                if (ret) {
                        dev_info(&pf->pdev->dev,
-                                "%s: VSI seid %d Tx ring %d %sable timeout\n",
-                                __func__, vsi->seid, pf_q,
-                                (enable ? "en" : "dis"));
+                                "VSI seid %d Tx ring %d %sable timeout\n",
+                                vsi->seid, pf_q, (enable ? "en" : "dis"));
                        break;
                }
        }
@@ -3757,9 +3733,8 @@ static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
                ret = i40e_pf_rxq_wait(pf, pf_q, enable);
                if (ret) {
                        dev_info(&pf->pdev->dev,
-                                "%s: VSI seid %d Rx ring %d %sable timeout\n",
-                                __func__, vsi->seid, pf_q,
-                                (enable ? "en" : "dis"));
+                                "VSI seid %d Rx ring %d %sable timeout\n",
+                                vsi->seid, pf_q, (enable ? "en" : "dis"));
                        break;
                }
        }
@@ -4054,8 +4029,7 @@ static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
        if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) &&
            vsi->type == I40E_VSI_FCOE) {
                dev_dbg(&vsi->back->pdev->dev,
-                       "%s: VSI seid %d skipping FCoE VSI disable\n",
-                        __func__, vsi->seid);
+                        "VSI seid %d skipping FCoE VSI disable\n", vsi->seid);
                return;
        }
 
@@ -4129,8 +4103,8 @@ static int i40e_vsi_wait_txq_disabled(struct i40e_vsi *vsi)
                ret = i40e_pf_txq_wait(pf, pf_q, false);
                if (ret) {
                        dev_info(&pf->pdev->dev,
-                                "%s: VSI seid %d Tx ring %d disable timeout\n",
-                                __func__, vsi->seid, pf_q);
+                                "VSI seid %d Tx ring %d disable timeout\n",
+                                vsi->seid, pf_q);
                        return ret;
                }
        }
@@ -5421,8 +5395,7 @@ bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
                dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
        }
 
-       dev_dbg(&pf->pdev->dev, "%s: need_reconfig=%d\n", __func__,
-               need_reconfig);
+       dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
        return need_reconfig;
 }
 
@@ -5449,16 +5422,14 @@ static int i40e_handle_lldp_event(struct i40e_pf *pf,
        /* Ignore if event is not for Nearest Bridge */
        type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
                & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
-       dev_dbg(&pf->pdev->dev,
-               "%s: LLDP event mib bridge type 0x%x\n", __func__, type);
+       dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
        if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
                return ret;
 
        /* Check MIB Type and return if event for Remote MIB update */
        type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
        dev_dbg(&pf->pdev->dev,
-               "%s: LLDP event mib type %s\n", __func__,
-               type ? "remote" : "local");
+               "LLDP event mib type %s\n", type ? "remote" : "local");
        if (type == I40E_AQ_LLDP_MIB_REMOTE) {
                /* Update the remote cached instance and return */
                ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
@@ -5643,7 +5614,9 @@ u32 i40e_get_global_fd_count(struct i40e_pf *pf)
  **/
 void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
 {
+       struct i40e_fdir_filter *filter;
        u32 fcnt_prog, fcnt_avail;
+       struct hlist_node *node;
 
        if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
                return;
@@ -5672,6 +5645,18 @@ void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
                                dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table now\n");
                }
        }
+
+       /* if hw had a problem adding a filter, delete it */
+       if (pf->fd_inv > 0) {
+               hlist_for_each_entry_safe(filter, node,
+                                         &pf->fdir_filter_list, fdir_node) {
+                       if (filter->fd_id == pf->fd_inv) {
+                               hlist_del(&filter->fdir_node);
+                               kfree(filter);
+                               pf->fdir_pf_active_filters--;
+                       }
+               }
+       }
 }
 
 #define I40E_MIN_FD_FLUSH_INTERVAL 10
@@ -5841,15 +5826,23 @@ static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
  **/
 static void i40e_link_event(struct i40e_pf *pf)
 {
-       bool new_link, old_link;
        struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
        u8 new_link_speed, old_link_speed;
+       i40e_status status;
+       bool new_link, old_link;
 
        /* set this to force the get_link_status call to refresh state */
        pf->hw.phy.get_link_info = true;
 
        old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
-       new_link = i40e_get_link_status(&pf->hw);
+
+       status = i40e_get_link_status(&pf->hw, &new_link);
+       if (status) {
+               dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
+                       status);
+               return;
+       }
+
        old_link_speed = pf->hw.phy.link_info_old.link_speed;
        new_link_speed = pf->hw.phy.link_info.link_speed;
 
@@ -5905,10 +5898,12 @@ static void i40e_watchdog_subtask(struct i40e_pf *pf)
                if (pf->vsi[i] && pf->vsi[i]->netdev)
                        i40e_update_stats(pf->vsi[i]);
 
-       /* Update the stats for the active switching components */
-       for (i = 0; i < I40E_MAX_VEB; i++)
-               if (pf->veb[i])
-                       i40e_update_veb_stats(pf->veb[i]);
+       if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
+               /* Update the stats for the active switching components */
+               for (i = 0; i < I40E_MAX_VEB; i++)
+                       if (pf->veb[i])
+                               i40e_update_veb_stats(pf->veb[i]);
+       }
 
        i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]);
 }
@@ -6569,9 +6564,7 @@ static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit)
        }
 #endif /* CONFIG_I40E_DCB */
 #ifdef I40E_FCOE
-       ret = i40e_init_pf_fcoe(pf);
-       if (ret)
-               dev_info(&pf->pdev->dev, "init_pf_fcoe failed: %d\n", ret);
+       i40e_init_pf_fcoe(pf);
 
 #endif
        /* do basic switch setup */
@@ -7622,7 +7615,7 @@ static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed)
                         "Cannot set RSS key, err %s aq_err %s\n",
                         i40e_stat_str(&pf->hw, ret),
                         i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
-               return ret;
+               goto config_rss_aq_out;
        }
 
        if (vsi->type == I40E_VSI_MAIN)
@@ -7636,6 +7629,8 @@ static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed)
                         i40e_stat_str(&pf->hw, ret),
                         i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
 
+config_rss_aq_out:
+       kfree(rss_lut);
        return ret;
 }
 
@@ -7970,9 +7965,7 @@ static int i40e_sw_init(struct i40e_pf *pf)
        }
 
 #ifdef I40E_FCOE
-       err = i40e_init_pf_fcoe(pf);
-       if (err)
-               dev_info(&pf->pdev->dev, "init_pf_fcoe failed: %d\n", err);
+       i40e_init_pf_fcoe(pf);
 
 #endif /* I40E_FCOE */
 #ifdef CONFIG_PCI_IOV
@@ -7996,6 +7989,9 @@ static int i40e_sw_init(struct i40e_pf *pf)
        pf->lan_veb = I40E_NO_VEB;
        pf->lan_vsi = I40E_NO_VSI;
 
+       /* By default FW has this off for performance reasons */
+       pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
+
        /* set up queue assignment tracking */
        size = sizeof(struct i40e_lump_tracking)
                + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
@@ -8175,9 +8171,6 @@ static void i40e_del_vxlan_port(struct net_device *netdev,
                pf->vxlan_ports[idx] = 0;
                pf->pending_vxlan_bitmap |= BIT_ULL(idx);
                pf->flags |= I40E_FLAG_VXLAN_FILTER_SYNC;
-
-               dev_info(&pf->pdev->dev, "deleting vxlan port %d\n",
-                        ntohs(port));
        } else {
                netdev_warn(netdev, "vxlan port %d was not found, not deleting\n",
                            ntohs(port));
@@ -9052,8 +9045,7 @@ struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
                if (veb) {
                        if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) {
                                dev_info(&vsi->back->pdev->dev,
-                                        "%s: New VSI creation error, uplink seid of LAN VSI expected.\n",
-                                        __func__);
+                                        "New VSI creation error, uplink seid of LAN VSI expected.\n");
                                return NULL;
                        }
                        /* We come up by default in VEPA mode if SRIOV is not
@@ -9942,6 +9934,7 @@ static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        struct i40e_pf *pf;
        struct i40e_hw *hw;
        static u16 pfs_found;
+       u16 wol_nvm_bits;
        u16 link_status;
        int err = 0;
        u32 len;
@@ -10158,8 +10151,12 @@ static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        clear_bit(__I40E_SERVICE_SCHED, &pf->state);
        pf->flags |= I40E_FLAG_NEED_LINK_UPDATE;
 
-       /* WoL defaults to disabled */
-       pf->wol_en = false;
+       /* NVM bit on means WoL disabled for the port */
+       i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
+       if ((1 << hw->port) & wol_nvm_bits || hw->partition_id != 1)
+               pf->wol_en = false;
+       else
+               pf->wol_en = true;
        device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
 
        /* set up the main switch operations */
@@ -10491,7 +10488,7 @@ static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
        int err;
        u32 reg;
 
-       dev_info(&pdev->dev, "%s\n", __func__);
+       dev_dbg(&pdev->dev, "%s\n", __func__);
        if (pci_enable_device_mem(pdev)) {
                dev_info(&pdev->dev,
                         "Cannot re-enable PCI device after reset.\n");
@@ -10531,7 +10528,7 @@ static void i40e_pci_error_resume(struct pci_dev *pdev)
 {
        struct i40e_pf *pf = pci_get_drvdata(pdev);
 
-       dev_info(&pdev->dev, "%s\n", __func__);
+       dev_dbg(&pdev->dev, "%s\n", __func__);
        if (test_bit(__I40E_SUSPENDED, &pf->state))
                return;
 
@@ -10623,9 +10620,7 @@ static int i40e_resume(struct pci_dev *pdev)
 
        err = pci_enable_device_mem(pdev);
        if (err) {
-               dev_err(&pdev->dev,
-                       "%s: Cannot enable PCI device from suspend\n",
-                       __func__);
+               dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
                return err;
        }
        pci_set_master(pdev);