ethdev: remove useless parameter in callback process
[dpdk.git] / drivers / net / sfc / sfc_port.c
index be75480..a48388d 100644 (file)
@@ -1,30 +1,10 @@
-/*-
- * Copyright (c) 2016 Solarflare Communications Inc.
+/* SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2016-2018 Solarflare Communications Inc.
  * All rights reserved.
  *
  * This software was jointly developed between OKTET Labs (under contract
  * for Solarflare) and Solarflare Communications, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- *    this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- *    this list of conditions and the following disclaimer in the documentation
- *    and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include "efx.h"
@@ -67,8 +47,23 @@ sfc_port_update_mac_stats(struct sfc_adapter *sa)
        if (sa->state != SFC_ADAPTER_STARTED)
                return EINVAL;
 
-       /* If periodic statistics DMA'ing is off, request explicitly */
-       if (port->mac_stats_update_period_ms == 0) {
+       /*
+        * If periodic statistics DMA'ing is off or if not supported,
+        * make a manual request and keep an eye on timer if need be
+        */
+       if (!port->mac_stats_periodic_dma_supported ||
+           (port->mac_stats_update_period_ms == 0)) {
+               if (port->mac_stats_update_period_ms != 0) {
+                       uint64_t timestamp = sfc_get_system_msecs();
+
+                       if ((timestamp -
+                            port->mac_stats_last_request_timestamp) <
+                           port->mac_stats_update_period_ms)
+                               return 0;
+
+                       port->mac_stats_last_request_timestamp = timestamp;
+               }
+
                rc = efx_mac_stats_upload(sa->nic, esmp);
                if (rc != 0)
                        return rc;
@@ -134,6 +129,7 @@ sfc_port_start(struct sfc_adapter *sa)
        uint32_t phy_adv_cap;
        const uint32_t phy_pause_caps =
                ((1u << EFX_PHY_CAP_PAUSE) | (1u << EFX_PHY_CAP_ASYM));
+       unsigned int i;
 
        sfc_log_init(sa, "entry");
 
@@ -169,26 +165,29 @@ sfc_port_start(struct sfc_adapter *sa)
        if (rc != 0)
                goto fail_mac_pdu_set;
 
-       sfc_log_init(sa, "set MAC address");
-       rc = efx_mac_addr_set(sa->nic,
-                             sa->eth_dev->data->mac_addrs[0].addr_bytes);
-       if (rc != 0)
-               goto fail_mac_addr_set;
-
-       sfc_log_init(sa, "set MAC filters");
-       port->promisc = (sa->eth_dev->data->promiscuous != 0) ?
-                       B_TRUE : B_FALSE;
-       port->allmulti = (sa->eth_dev->data->all_multicast != 0) ?
-                        B_TRUE : B_FALSE;
-       rc = sfc_set_rx_mode(sa);
-       if (rc != 0)
-               goto fail_mac_filter_set;
+       if (!port->isolated) {
+               struct ether_addr *addr = &port->default_mac_addr;
 
-       sfc_log_init(sa, "set multicast address list");
-       rc = efx_mac_multicast_list_set(sa->nic, port->mcast_addrs,
-                                       port->nb_mcast_addrs);
-       if (rc != 0)
-               goto fail_mcast_address_list_set;
+               sfc_log_init(sa, "set MAC address");
+               rc = efx_mac_addr_set(sa->nic, addr->addr_bytes);
+               if (rc != 0)
+                       goto fail_mac_addr_set;
+
+               sfc_log_init(sa, "set MAC filters");
+               port->promisc = (sa->eth_dev->data->promiscuous != 0) ?
+                               B_TRUE : B_FALSE;
+               port->allmulti = (sa->eth_dev->data->all_multicast != 0) ?
+                                B_TRUE : B_FALSE;
+               rc = sfc_set_rx_mode(sa);
+               if (rc != 0)
+                       goto fail_mac_filter_set;
+
+               sfc_log_init(sa, "set multicast address list");
+               rc = efx_mac_multicast_list_set(sa->nic, port->mcast_addrs,
+                                               port->nb_mcast_addrs);
+               if (rc != 0)
+                       goto fail_mcast_address_list_set;
+       }
 
        if (port->mac_stats_reset_pending) {
                rc = sfc_port_reset_mac_stats(sa);
@@ -202,6 +201,10 @@ sfc_port_start(struct sfc_adapter *sa)
        efx_mac_stats_get_mask(sa->nic, port->mac_stats_mask,
                               sizeof(port->mac_stats_mask));
 
+       for (i = 0, port->mac_stats_nb_supported = 0; i < EFX_MAC_NSTATS; ++i)
+               if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i))
+                       port->mac_stats_nb_supported++;
+
        port->mac_stats_update_generation = 0;
 
        if (port->mac_stats_update_period_ms != 0) {
@@ -215,8 +218,26 @@ sfc_port_start(struct sfc_adapter *sa)
                rc = efx_mac_stats_periodic(sa->nic, &port->mac_stats_dma_mem,
                                            port->mac_stats_update_period_ms,
                                            B_FALSE);
-               if (rc != 0)
+               if (rc == 0) {
+                       port->mac_stats_periodic_dma_supported = B_TRUE;
+               } else if (rc == EOPNOTSUPP) {
+                       port->mac_stats_periodic_dma_supported = B_FALSE;
+                       port->mac_stats_last_request_timestamp = 0;
+               } else {
                        goto fail_mac_stats_periodic;
+               }
+       }
+
+       if ((port->mac_stats_update_period_ms != 0) &&
+           port->mac_stats_periodic_dma_supported) {
+               /*
+                * Request an explicit MAC stats upload immediately to
+                * preclude bogus figures readback if the user decides
+                * to read stats before periodic DMA is really started
+                */
+               rc = efx_mac_stats_upload(sa->nic, &port->mac_stats_dma_mem);
+               if (rc != 0)
+                       goto fail_mac_stats_upload;
        }
 
        sfc_log_init(sa, "disable MAC drain");
@@ -236,6 +257,7 @@ fail_port_init_dev_link:
        (void)efx_mac_drain(sa->nic, B_TRUE);
 
 fail_mac_drain:
+fail_mac_stats_upload:
        (void)efx_mac_stats_periodic(sa->nic, &port->mac_stats_dma_mem,
                                     0, B_FALSE);
 
@@ -273,23 +295,47 @@ sfc_port_stop(struct sfc_adapter *sa)
 }
 
 int
-sfc_port_init(struct sfc_adapter *sa)
+sfc_port_configure(struct sfc_adapter *sa)
 {
        const struct rte_eth_dev_data *dev_data = sa->eth_dev->data;
        struct sfc_port *port = &sa->port;
+
+       sfc_log_init(sa, "entry");
+
+       if (dev_data->dev_conf.rxmode.jumbo_frame)
+               port->pdu = dev_data->dev_conf.rxmode.max_rx_pkt_len;
+       else
+               port->pdu = EFX_MAC_PDU(dev_data->mtu);
+
+       return 0;
+}
+
+void
+sfc_port_close(struct sfc_adapter *sa)
+{
+       sfc_log_init(sa, "entry");
+}
+
+int
+sfc_port_attach(struct sfc_adapter *sa)
+{
+       struct sfc_port *port = &sa->port;
+       const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
+       const struct ether_addr *from;
        long kvarg_stats_update_period_ms;
        int rc;
 
        sfc_log_init(sa, "entry");
 
+       efx_phy_adv_cap_get(sa->nic, EFX_PHY_CAP_PERM, &port->phy_adv_cap_mask);
+
        /* Enable flow control by default */
        port->flow_ctrl = EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE;
        port->flow_ctrl_autoneg = B_TRUE;
 
-       if (dev_data->dev_conf.rxmode.jumbo_frame)
-               port->pdu = dev_data->dev_conf.rxmode.max_rx_pkt_len;
-       else
-               port->pdu = EFX_MAC_PDU(dev_data->mtu);
+       RTE_BUILD_BUG_ON(sizeof(encp->enc_mac_addr) != sizeof(*from));
+       from = (const struct ether_addr *)(encp->enc_mac_addr);
+       ether_addr_copy(from, &port->default_mac_addr);
 
        port->max_mcast_addrs = EFX_MAC_MULTICAST_LIST_MAX;
        port->nb_mcast_addrs = 0;
@@ -342,16 +388,21 @@ sfc_port_init(struct sfc_adapter *sa)
        return 0;
 
 fail_kvarg_stats_update_period_ms:
+       sfc_dma_free(sa, &port->mac_stats_dma_mem);
+
 fail_mac_stats_dma_alloc:
        rte_free(port->mac_stats_buf);
+
 fail_mac_stats_buf_alloc:
+       rte_free(port->mcast_addrs);
+
 fail_mcast_addr_list_buf_alloc:
        sfc_log_init(sa, "failed %d", rc);
        return rc;
 }
 
 void
-sfc_port_fini(struct sfc_adapter *sa)
+sfc_port_detach(struct sfc_adapter *sa)
 {
        struct sfc_port *port = &sa->port;
 
@@ -360,6 +411,8 @@ sfc_port_fini(struct sfc_adapter *sa)
        sfc_dma_free(sa, &port->mac_stats_dma_mem);
        rte_free(port->mac_stats_buf);
 
+       rte_free(port->mcast_addrs);
+
        sfc_log_init(sa, "done");
 }