X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fsfc%2Fsfc_port.c;h=c1466a77bf69d4839b672c263f5c5653ea906a15;hb=975ffea6f67152088dc941426a1f3ef631cece85;hp=e77848d426b650684e24b2d8c9660eccb283f76d;hpb=295f647a38a2680de89f299adc1a50681240405a;p=dpdk.git diff --git a/drivers/net/sfc/sfc_port.c b/drivers/net/sfc/sfc_port.c index e77848d426..c1466a77bf 100644 --- a/drivers/net/sfc/sfc_port.c +++ b/drivers/net/sfc/sfc_port.c @@ -1,5 +1,7 @@ /*- - * Copyright (c) 2016 Solarflare Communications Inc. + * BSD LICENSE + * + * Copyright (c) 2016-2017 Solarflare Communications Inc. * All rights reserved. * * This software was jointly developed between OKTET Labs (under contract @@ -31,6 +33,16 @@ #include "sfc.h" #include "sfc_log.h" +#include "sfc_kvargs.h" + +/** Default MAC statistics update period is 1 second */ +#define SFC_MAC_STATS_UPDATE_PERIOD_MS_DEF MS_PER_S + +/** The number of microseconds to sleep on attempt to get statistics update */ +#define SFC_MAC_STATS_UPDATE_RETRY_INTERVAL_US 10 + +/** The number of attempts to await arrival of freshly generated statistics */ +#define SFC_MAC_STATS_UPDATE_NB_ATTEMPTS 50 /** * Update MAC statistics in the buffer. @@ -46,6 +58,10 @@ int sfc_port_update_mac_stats(struct sfc_adapter *sa) { struct sfc_port *port = &sa->port; + efsys_mem_t *esmp = &port->mac_stats_dma_mem; + uint32_t *genp = NULL; + uint32_t gen_old; + unsigned int nb_attempts = 0; int rc; SFC_ASSERT(rte_spinlock_is_locked(&port->mac_stats_lock)); @@ -53,10 +69,42 @@ sfc_port_update_mac_stats(struct sfc_adapter *sa) if (sa->state != SFC_ADAPTER_STARTED) return EINVAL; - rc = efx_mac_stats_update(sa->nic, &port->mac_stats_dma_mem, - port->mac_stats_buf, NULL); - if (rc != 0) - return rc; + /* + * 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; + + genp = &port->mac_stats_update_generation; + gen_old = *genp; + } + + do { + if (nb_attempts > 0) + rte_delay_us(SFC_MAC_STATS_UPDATE_RETRY_INTERVAL_US); + + rc = efx_mac_stats_update(sa->nic, esmp, + port->mac_stats_buf, genp); + if (rc != 0) + return rc; + + } while ((genp != NULL) && (*genp == gen_old) && + (++nb_attempts < SFC_MAC_STATS_UPDATE_NB_ATTEMPTS)); return 0; } @@ -103,6 +151,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"); @@ -138,26 +187,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 *mac_addrs = sa->eth_dev->data->mac_addrs; - 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, 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; + + 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); @@ -171,15 +223,44 @@ sfc_port_start(struct sfc_adapter *sa) efx_mac_stats_get_mask(sa->nic, port->mac_stats_mask, sizeof(port->mac_stats_mask)); - /* Update MAC stats using periodic DMA. - * Common code always uses 1000ms update period, so period_ms - * parameter only needs to be non-zero to start updates. - */ - sfc_log_init(sa, "request MAC stats DMA'ing"); - rc = efx_mac_stats_periodic(sa->nic, &port->mac_stats_dma_mem, - 1000, B_FALSE); - if (rc != 0) - goto fail_mac_stats_periodic; + 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) { + /* + * Update MAC stats using periodic DMA; + * any positive update interval different from + * 1000 ms can be set only on SFN8xxx provided + * that FW version is 6.2.1.1033 or higher + */ + sfc_log_init(sa, "request MAC stats DMA'ing"); + rc = efx_mac_stats_periodic(sa->nic, &port->mac_stats_dma_mem, + port->mac_stats_update_period_ms, + B_FALSE); + 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"); rc = efx_mac_drain(sa->nic, B_FALSE); @@ -201,6 +282,7 @@ fail_mac_drain: (void)efx_mac_stats_periodic(sa->nic, &port->mac_stats_dma_mem, 0, B_FALSE); +fail_mac_stats_upload: fail_mac_stats_periodic: fail_mcast_address_list_set: fail_mac_filter_set: @@ -235,23 +317,42 @@ 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; - int rc; sfc_log_init(sa, "entry"); - /* 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); + 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; + 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; + port->max_mcast_addrs = EFX_MAC_MULTICAST_LIST_MAX; port->nb_mcast_addrs = 0; port->mcast_addrs = rte_calloc_socket("mcast_addr_list_buf", @@ -279,9 +380,30 @@ sfc_port_init(struct sfc_adapter *sa) port->mac_stats_reset_pending = B_FALSE; + kvarg_stats_update_period_ms = SFC_MAC_STATS_UPDATE_PERIOD_MS_DEF; + + rc = sfc_kvargs_process(sa, SFC_KVARG_STATS_UPDATE_PERIOD_MS, + sfc_kvarg_long_handler, + &kvarg_stats_update_period_ms); + if ((rc == 0) && + ((kvarg_stats_update_period_ms < 0) || + (kvarg_stats_update_period_ms > UINT16_MAX))) { + sfc_err(sa, "wrong '" SFC_KVARG_STATS_UPDATE_PERIOD_MS "' " + "was set (%ld);", kvarg_stats_update_period_ms); + sfc_err(sa, "it must not be less than 0 " + "or greater than %" PRIu16, UINT16_MAX); + rc = EINVAL; + goto fail_kvarg_stats_update_period_ms; + } else if (rc != 0) { + goto fail_kvarg_stats_update_period_ms; + } + + port->mac_stats_update_period_ms = kvarg_stats_update_period_ms; + sfc_log_init(sa, "done"); return 0; +fail_kvarg_stats_update_period_ms: fail_mac_stats_dma_alloc: rte_free(port->mac_stats_buf); fail_mac_stats_buf_alloc: @@ -291,7 +413,7 @@ fail_mcast_addr_list_buf_alloc: } void -sfc_port_fini(struct sfc_adapter *sa) +sfc_port_detach(struct sfc_adapter *sa) { struct sfc_port *port = &sa->port;