i40e: add hw struct local variable
[cascardo/linux.git] / drivers / net / ethernet / intel / i40e / i40e_main.c
index 5ea2200..9a26ecc 100644 (file)
 /* Local includes */
 #include "i40e.h"
 #include "i40e_diag.h"
-#if IS_ENABLED(CONFIG_VXLAN)
-#include <net/vxlan.h>
-#endif
-#if IS_ENABLED(CONFIG_GENEVE)
-#include <net/geneve.h>
-#endif
+#include <net/udp_tunnel.h>
 
 const char i40e_driver_name[] = "i40e";
 static const char i40e_driver_string[] =
@@ -1845,6 +1840,7 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
 {
        struct list_head tmp_del_list, tmp_add_list;
        struct i40e_mac_filter *f, *ftmp, *fclone;
+       struct i40e_hw *hw = &vsi->back->hw;
        bool promisc_forced_on = false;
        bool add_happened = false;
        int filter_list_len = 0;
@@ -1925,7 +1921,7 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
        if (!list_empty(&tmp_del_list)) {
                int del_list_size;
 
-               filter_list_len = pf->hw.aq.asq_buf_size /
+               filter_list_len = hw->aq.asq_buf_size /
                            sizeof(struct i40e_aqc_remove_macvlan_element_data);
                del_list_size = filter_list_len *
                            sizeof(struct i40e_aqc_remove_macvlan_element_data);
@@ -1957,12 +1953,11 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
 
                        /* flush a full buffer */
                        if (num_del == filter_list_len) {
-                               aq_ret = i40e_aq_remove_macvlan(&pf->hw,
-                                                               vsi->seid,
-                                                               del_list,
-                                                               num_del,
-                                                               NULL);
-                               aq_err = pf->hw.aq.asq_last_status;
+                               aq_ret =
+                                       i40e_aq_remove_macvlan(hw, vsi->seid,
+                                                              del_list,
+                                                              num_del, NULL);
+                               aq_err = hw->aq.asq_last_status;
                                num_del = 0;
                                memset(del_list, 0, del_list_size);
 
@@ -1970,8 +1965,9 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
                                        retval = -EIO;
                                        dev_err(&pf->pdev->dev,
                                                "ignoring delete macvlan error, err %s, aq_err %s while flushing a full buffer\n",
-                                               i40e_stat_str(&pf->hw, aq_ret),
-                                               i40e_aq_str(&pf->hw, aq_err));
+
+                                                i40e_stat_str(hw, aq_ret),
+                                                i40e_aq_str(hw, aq_err));
                                }
                        }
                        /* Release memory for MAC filter entries which were
@@ -1982,17 +1978,16 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
                }
 
                if (num_del) {
-                       aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid,
-                                                       del_list, num_del,
-                                                       NULL);
-                       aq_err = pf->hw.aq.asq_last_status;
+                       aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, del_list,
+                                                       num_del, NULL);
+                       aq_err = hw->aq.asq_last_status;
                        num_del = 0;
 
                        if (aq_ret && aq_err != I40E_AQ_RC_ENOENT)
                                dev_info(&pf->pdev->dev,
                                         "ignoring delete macvlan error, err %s aq_err %s\n",
-                                        i40e_stat_str(&pf->hw, aq_ret),
-                                        i40e_aq_str(&pf->hw, aq_err));
+                                        i40e_stat_str(hw, aq_ret),
+                                        i40e_aq_str(hw, aq_err));
                }
 
                kfree(del_list);
@@ -2003,7 +1998,7 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
                int add_list_size;
 
                /* do all the adds now */
-               filter_list_len = pf->hw.aq.asq_buf_size /
+               filter_list_len = hw->aq.asq_buf_size /
                               sizeof(struct i40e_aqc_add_macvlan_element_data),
                add_list_size = filter_list_len *
                               sizeof(struct i40e_aqc_add_macvlan_element_data);
@@ -2038,10 +2033,10 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
 
                        /* flush a full buffer */
                        if (num_add == filter_list_len) {
-                               aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
+                               aq_ret = i40e_aq_add_macvlan(hw, vsi->seid,
                                                             add_list, num_add,
                                                             NULL);
-                               aq_err = pf->hw.aq.asq_last_status;
+                               aq_err = hw->aq.asq_last_status;
                                num_add = 0;
 
                                if (aq_ret)
@@ -2056,9 +2051,9 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
                }
 
                if (num_add) {
-                       aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
+                       aq_ret = i40e_aq_add_macvlan(hw, vsi->seid,
                                                     add_list, num_add, NULL);
-                       aq_err = pf->hw.aq.asq_last_status;
+                       aq_err = hw->aq.asq_last_status;
                        num_add = 0;
                }
                kfree(add_list);
@@ -2068,9 +2063,9 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
                        retval = i40e_aq_rc_to_posix(aq_ret, aq_err);
                        dev_info(&pf->pdev->dev,
                                 "add filter failed, err %s aq_err %s\n",
-                                i40e_stat_str(&pf->hw, aq_ret),
-                                i40e_aq_str(&pf->hw, aq_err));
-                       if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOSPC) &&
+                                i40e_stat_str(hw, aq_ret),
+                                i40e_aq_str(hw, aq_err));
+                       if ((hw->aq.asq_last_status == I40E_AQ_RC_ENOSPC) &&
                            !test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
                                      &vsi->state)) {
                                promisc_forced_on = true;
@@ -2098,12 +2093,11 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
                                                               NULL);
                if (aq_ret) {
                        retval = i40e_aq_rc_to_posix(aq_ret,
-                                                    pf->hw.aq.asq_last_status);
+                                                    hw->aq.asq_last_status);
                        dev_info(&pf->pdev->dev,
                                 "set multi promisc failed, err %s aq_err %s\n",
-                                i40e_stat_str(&pf->hw, aq_ret),
-                                i40e_aq_str(&pf->hw,
-                                            pf->hw.aq.asq_last_status));
+                                i40e_stat_str(hw, aq_ret),
+                                i40e_aq_str(hw, hw->aq.asq_last_status));
                }
        }
        if ((changed_flags & IFF_PROMISC) || promisc_forced_on) {
@@ -2126,29 +2120,33 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
                        }
                } else {
                        aq_ret = i40e_aq_set_vsi_unicast_promiscuous(
-                                                         &vsi->back->hw,
+                                                         hw,
                                                          vsi->seid,
                                                          cur_promisc, NULL,
                                                          true);
                        if (aq_ret) {
                                retval =
                                i40e_aq_rc_to_posix(aq_ret,
-                                                   pf->hw.aq.asq_last_status);
+                                                   hw->aq.asq_last_status);
                                dev_info(&pf->pdev->dev,
-                                        "set unicast promisc failed, err %d, aq_err %d\n",
-                                        aq_ret, pf->hw.aq.asq_last_status);
+                                        "set unicast promisc failed, err %s, aq_err %s\n",
+                                        i40e_stat_str(hw, aq_ret),
+                                        i40e_aq_str(hw,
+                                                    hw->aq.asq_last_status));
                        }
                        aq_ret = i40e_aq_set_vsi_multicast_promiscuous(
-                                                         &vsi->back->hw,
+                                                         hw,
                                                          vsi->seid,
                                                          cur_promisc, NULL);
                        if (aq_ret) {
                                retval =
                                i40e_aq_rc_to_posix(aq_ret,
-                                                   pf->hw.aq.asq_last_status);
+                                                   hw->aq.asq_last_status);
                                dev_info(&pf->pdev->dev,
-                                        "set multicast promisc failed, err %d, aq_err %d\n",
-                                        aq_ret, pf->hw.aq.asq_last_status);
+                                        "set multicast promisc failed, err %s, aq_err %s\n",
+                                        i40e_stat_str(hw, aq_ret),
+                                        i40e_aq_str(hw,
+                                                    hw->aq.asq_last_status));
                        }
                }
                aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw,
@@ -2159,9 +2157,9 @@ int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
                                                     pf->hw.aq.asq_last_status);
                        dev_info(&pf->pdev->dev,
                                 "set brdcast promisc failed, err %s, aq_err %s\n",
-                                i40e_stat_str(&pf->hw, aq_ret),
-                                i40e_aq_str(&pf->hw,
-                                            pf->hw.aq.asq_last_status));
+                                        i40e_stat_str(hw, aq_ret),
+                                        i40e_aq_str(hw,
+                                                    hw->aq.asq_last_status));
                }
        }
 out:
@@ -5342,14 +5340,7 @@ int i40e_open(struct net_device *netdev)
                                                       TCP_FLAG_CWR) >> 16);
        wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
 
-#ifdef CONFIG_I40E_VXLAN
-       vxlan_get_rx_port(netdev);
-#endif
-#ifdef CONFIG_I40E_GENEVE
-       if (pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE)
-               geneve_get_rx_port(netdev);
-#endif
-
+       udp_tunnel_get_rx_info(netdev);
        i40e_notify_client_of_netdev_open(vsi);
 
        return 0;
@@ -7057,7 +7048,6 @@ static void i40e_handle_mdd_event(struct i40e_pf *pf)
  **/
 static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf)
 {
-#if IS_ENABLED(CONFIG_VXLAN) || IS_ENABLED(CONFIG_GENEVE)
        struct i40e_hw *hw = &pf->hw;
        i40e_status ret;
        __be16 port;
@@ -7092,7 +7082,6 @@ static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf)
                        }
                }
        }
-#endif
 }
 
 /**
@@ -8628,7 +8617,6 @@ static int i40e_set_features(struct net_device *netdev,
        return 0;
 }
 
-#if IS_ENABLED(CONFIG_VXLAN) || IS_ENABLED(CONFIG_GENEVE)
 /**
  * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port
  * @pf: board private structure
@@ -8648,21 +8636,18 @@ static u8 i40e_get_udp_port_idx(struct i40e_pf *pf, __be16 port)
        return i;
 }
 
-#endif
-
-#if IS_ENABLED(CONFIG_VXLAN)
 /**
- * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up
+ * i40e_udp_tunnel_add - Get notifications about UDP tunnel ports that come up
  * @netdev: This physical port's netdev
- * @sa_family: Socket Family that VXLAN is notifying us about
- * @port: New UDP port number that VXLAN started listening to
+ * @ti: Tunnel endpoint information
  **/
-static void i40e_add_vxlan_port(struct net_device *netdev,
-                               sa_family_t sa_family, __be16 port)
+static void i40e_udp_tunnel_add(struct net_device *netdev,
+                               struct udp_tunnel_info *ti)
 {
        struct i40e_netdev_priv *np = netdev_priv(netdev);
        struct i40e_vsi *vsi = np->vsi;
        struct i40e_pf *pf = vsi->back;
+       __be16 port = ti->port;
        u8 next_idx;
        u8 idx;
 
@@ -8670,7 +8655,7 @@ static void i40e_add_vxlan_port(struct net_device *netdev,
 
        /* Check if port already exists */
        if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
-               netdev_info(netdev, "vxlan port %d already offloaded\n",
+               netdev_info(netdev, "port %d already offloaded\n",
                            ntohs(port));
                return;
        }
@@ -8679,131 +8664,75 @@ static void i40e_add_vxlan_port(struct net_device *netdev,
        next_idx = i40e_get_udp_port_idx(pf, 0);
 
        if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
-               netdev_info(netdev, "maximum number of vxlan UDP ports reached, not adding port %d\n",
+               netdev_info(netdev, "maximum number of offloaded UDP ports reached, not adding port %d\n",
                            ntohs(port));
                return;
        }
 
-       /* New port: add it and mark its index in the bitmap */
-       pf->udp_ports[next_idx].index = port;
-       pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN;
-       pf->pending_udp_bitmap |= BIT_ULL(next_idx);
-       pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
-}
-
-/**
- * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away
- * @netdev: This physical port's netdev
- * @sa_family: Socket Family that VXLAN is notifying us about
- * @port: UDP port number that VXLAN stopped listening to
- **/
-static void i40e_del_vxlan_port(struct net_device *netdev,
-                               sa_family_t sa_family, __be16 port)
-{
-       struct i40e_netdev_priv *np = netdev_priv(netdev);
-       struct i40e_vsi *vsi = np->vsi;
-       struct i40e_pf *pf = vsi->back;
-       u8 idx;
-
-       idx = i40e_get_udp_port_idx(pf, port);
-
-       /* Check if port already exists */
-       if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
-               /* if port exists, set it to 0 (mark for deletion)
-                * and make it pending
-                */
-               pf->udp_ports[idx].index = 0;
-               pf->pending_udp_bitmap |= BIT_ULL(idx);
-               pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
-       } else {
-               netdev_warn(netdev, "vxlan port %d was not found, not deleting\n",
-                           ntohs(port));
-       }
-}
-#endif
-
-#if IS_ENABLED(CONFIG_GENEVE)
-/**
- * i40e_add_geneve_port - Get notifications about GENEVE ports that come up
- * @netdev: This physical port's netdev
- * @sa_family: Socket Family that GENEVE is notifying us about
- * @port: New UDP port number that GENEVE started listening to
- **/
-static void i40e_add_geneve_port(struct net_device *netdev,
-                                sa_family_t sa_family, __be16 port)
-{
-       struct i40e_netdev_priv *np = netdev_priv(netdev);
-       struct i40e_vsi *vsi = np->vsi;
-       struct i40e_pf *pf = vsi->back;
-       u8 next_idx;
-       u8 idx;
-
-       if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE))
-               return;
-
-       idx = i40e_get_udp_port_idx(pf, port);
-
-       /* Check if port already exists */
-       if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
-               netdev_info(netdev, "udp port %d already offloaded\n",
-                           ntohs(port));
-               return;
-       }
-
-       /* Now check if there is space to add the new port */
-       next_idx = i40e_get_udp_port_idx(pf, 0);
-
-       if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
-               netdev_info(netdev, "maximum number of UDP ports reached, not adding port %d\n",
-                           ntohs(port));
+       switch (ti->type) {
+       case UDP_TUNNEL_TYPE_VXLAN:
+               pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN;
+               break;
+       case UDP_TUNNEL_TYPE_GENEVE:
+               if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE))
+                       return;
+               pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE;
+               break;
+       default:
                return;
        }
 
        /* New port: add it and mark its index in the bitmap */
        pf->udp_ports[next_idx].index = port;
-       pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE;
        pf->pending_udp_bitmap |= BIT_ULL(next_idx);
        pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
-
-       dev_info(&pf->pdev->dev, "adding geneve port %d\n", ntohs(port));
 }
 
 /**
- * i40e_del_geneve_port - Get notifications about GENEVE ports that go away
+ * i40e_udp_tunnel_del - Get notifications about UDP tunnel ports that go away
  * @netdev: This physical port's netdev
- * @sa_family: Socket Family that GENEVE is notifying us about
- * @port: UDP port number that GENEVE stopped listening to
+ * @ti: Tunnel endpoint information
  **/
-static void i40e_del_geneve_port(struct net_device *netdev,
-                                sa_family_t sa_family, __be16 port)
+static void i40e_udp_tunnel_del(struct net_device *netdev,
+                               struct udp_tunnel_info *ti)
 {
        struct i40e_netdev_priv *np = netdev_priv(netdev);
        struct i40e_vsi *vsi = np->vsi;
        struct i40e_pf *pf = vsi->back;
+       __be16 port = ti->port;
        u8 idx;
 
-       if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE))
-               return;
-
        idx = i40e_get_udp_port_idx(pf, port);
 
        /* Check if port already exists */
-       if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
-               /* if port exists, set it to 0 (mark for deletion)
-                * and make it pending
-                */
-               pf->udp_ports[idx].index = 0;
-               pf->pending_udp_bitmap |= BIT_ULL(idx);
-               pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
+       if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS)
+               goto not_found;
 
-               dev_info(&pf->pdev->dev, "deleting geneve port %d\n",
-                        ntohs(port));
-       } else {
-               netdev_warn(netdev, "geneve port %d was not found, not deleting\n",
-                           ntohs(port));
+       switch (ti->type) {
+       case UDP_TUNNEL_TYPE_VXLAN:
+               if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN)
+                       goto not_found;
+               break;
+       case UDP_TUNNEL_TYPE_GENEVE:
+               if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE)
+                       goto not_found;
+               break;
+       default:
+               goto not_found;
        }
+
+       /* if port exists, set it to 0 (mark for deletion)
+        * and make it pending
+        */
+       pf->udp_ports[idx].index = 0;
+       pf->pending_udp_bitmap |= BIT_ULL(idx);
+       pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
+
+       return;
+not_found:
+       netdev_warn(netdev, "UDP port %d was not found, not deleting\n",
+                   ntohs(port));
 }
-#endif
 
 static int i40e_get_phys_port_id(struct net_device *netdev,
                                 struct netdev_phys_item_id *ppid)
@@ -9033,14 +8962,8 @@ static const struct net_device_ops i40e_netdev_ops = {
        .ndo_set_vf_link_state  = i40e_ndo_set_vf_link_state,
        .ndo_set_vf_spoofchk    = i40e_ndo_set_vf_spoofchk,
        .ndo_set_vf_trust       = i40e_ndo_set_vf_trust,
-#if IS_ENABLED(CONFIG_VXLAN)
-       .ndo_add_vxlan_port     = i40e_add_vxlan_port,
-       .ndo_del_vxlan_port     = i40e_del_vxlan_port,
-#endif
-#if IS_ENABLED(CONFIG_GENEVE)
-       .ndo_add_geneve_port    = i40e_add_geneve_port,
-       .ndo_del_geneve_port    = i40e_del_geneve_port,
-#endif
+       .ndo_udp_tunnel_add     = i40e_udp_tunnel_add,
+       .ndo_udp_tunnel_del     = i40e_udp_tunnel_del,
        .ndo_get_phys_port_id   = i40e_get_phys_port_id,
        .ndo_fdb_add            = i40e_ndo_fdb_add,
        .ndo_features_check     = i40e_features_check,
@@ -10689,12 +10612,8 @@ static void i40e_print_features(struct i40e_pf *pf)
        }
        if (pf->flags & I40E_FLAG_DCB_CAPABLE)
                i += snprintf(&buf[i], REMAIN(i), " DCB");
-#if IS_ENABLED(CONFIG_VXLAN)
        i += snprintf(&buf[i], REMAIN(i), " VxLAN");
-#endif
-#if IS_ENABLED(CONFIG_GENEVE)
        i += snprintf(&buf[i], REMAIN(i), " Geneve");
-#endif
        if (pf->flags & I40E_FLAG_PTP)
                i += snprintf(&buf[i], REMAIN(i), " PTP");
 #ifdef I40E_FCOE