2020-01-08 23:10:59 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
/****************************************************************************
|
|
|
|
* Driver for Solarflare network controllers and boards
|
|
|
|
* Copyright 2018 Solarflare Communications Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 as published
|
|
|
|
* by the Free Software Foundation, incorporated herein by reference.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "net_driver.h"
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include "efx_common.h"
|
|
|
|
#include "efx_channels.h"
|
|
|
|
#include "efx.h"
|
|
|
|
#include "mcdi.h"
|
|
|
|
#include "selftest.h"
|
|
|
|
#include "rx_common.h"
|
|
|
|
#include "tx_common.h"
|
|
|
|
#include "nic.h"
|
|
|
|
#include "io.h"
|
|
|
|
#include "mcdi_pcol.h"
|
|
|
|
|
|
|
|
/* Reset workqueue. If any NIC has a hardware failure then a reset will be
|
|
|
|
* queued onto this work queue. This is not a per-nic work queue, because
|
|
|
|
* efx_reset_work() acquires the rtnl lock, so resets are naturally serialised.
|
|
|
|
*/
|
|
|
|
static struct workqueue_struct *reset_workqueue;
|
|
|
|
|
|
|
|
int efx_create_reset_workqueue(void)
|
|
|
|
{
|
|
|
|
reset_workqueue = create_singlethread_workqueue("sfc_reset");
|
|
|
|
if (!reset_workqueue) {
|
|
|
|
printk(KERN_ERR "Failed to create reset workqueue\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void efx_queue_reset_work(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
queue_work(reset_workqueue, &efx->reset_work);
|
|
|
|
}
|
|
|
|
|
|
|
|
void efx_flush_reset_workqueue(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
cancel_work_sync(&efx->reset_work);
|
|
|
|
}
|
|
|
|
|
|
|
|
void efx_destroy_reset_workqueue(void)
|
|
|
|
{
|
|
|
|
if (reset_workqueue) {
|
|
|
|
destroy_workqueue(reset_workqueue);
|
|
|
|
reset_workqueue = NULL;
|
|
|
|
}
|
|
|
|
}
|
2020-01-08 23:11:13 +07:00
|
|
|
|
|
|
|
/* We assume that efx->type->reconfigure_mac will always try to sync RX
|
|
|
|
* filters and therefore needs to read-lock the filter table against freeing
|
|
|
|
*/
|
|
|
|
void efx_mac_reconfigure(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
down_read(&efx->filter_sem);
|
|
|
|
efx->type->reconfigure_mac(efx);
|
|
|
|
up_read(&efx->filter_sem);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This ensures that the kernel is kept informed (via
|
|
|
|
* netif_carrier_on/off) of the link status, and also maintains the
|
|
|
|
* link status's stop on the port's TX queue.
|
|
|
|
*/
|
|
|
|
void efx_link_status_changed(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
struct efx_link_state *link_state = &efx->link_state;
|
|
|
|
|
|
|
|
/* SFC Bug 5356: A net_dev notifier is registered, so we must ensure
|
|
|
|
* that no events are triggered between unregister_netdev() and the
|
|
|
|
* driver unloading. A more general condition is that NETDEV_CHANGE
|
|
|
|
* can only be generated between NETDEV_UP and NETDEV_DOWN
|
|
|
|
*/
|
|
|
|
if (!netif_running(efx->net_dev))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (link_state->up != netif_carrier_ok(efx->net_dev)) {
|
|
|
|
efx->n_link_state_changes++;
|
|
|
|
|
|
|
|
if (link_state->up)
|
|
|
|
netif_carrier_on(efx->net_dev);
|
|
|
|
else
|
|
|
|
netif_carrier_off(efx->net_dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Status message for kernel log */
|
|
|
|
if (link_state->up)
|
|
|
|
netif_info(efx, link, efx->net_dev,
|
|
|
|
"link up at %uMbps %s-duplex (MTU %d)\n",
|
|
|
|
link_state->speed, link_state->fd ? "full" : "half",
|
|
|
|
efx->net_dev->mtu);
|
|
|
|
else
|
|
|
|
netif_info(efx, link, efx->net_dev, "link down\n");
|
|
|
|
}
|
2020-01-08 23:11:29 +07:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Event queue processing
|
|
|
|
*
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
void efx_start_channels(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
struct efx_tx_queue *tx_queue;
|
|
|
|
struct efx_rx_queue *rx_queue;
|
|
|
|
struct efx_channel *channel;
|
|
|
|
|
|
|
|
efx_for_each_channel(channel, efx) {
|
|
|
|
efx_for_each_channel_tx_queue(tx_queue, channel) {
|
|
|
|
efx_init_tx_queue(tx_queue);
|
|
|
|
atomic_inc(&efx->active_queues);
|
|
|
|
}
|
|
|
|
|
|
|
|
efx_for_each_channel_rx_queue(rx_queue, channel) {
|
|
|
|
efx_init_rx_queue(rx_queue);
|
|
|
|
atomic_inc(&efx->active_queues);
|
|
|
|
efx_stop_eventq(channel);
|
|
|
|
efx_fast_push_rx_descriptors(rx_queue, false);
|
|
|
|
efx_start_eventq(channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN_ON(channel->rx_pkt_n_frags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Channels are shutdown and reinitialised whilst the NIC is running
|
|
|
|
* to propagate configuration changes (mtu, checksum offload), or
|
|
|
|
* to clear hardware error conditions
|
|
|
|
*/
|
|
|
|
static void efx_start_datapath(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
netdev_features_t old_features = efx->net_dev->features;
|
|
|
|
bool old_rx_scatter = efx->rx_scatter;
|
|
|
|
size_t rx_buf_len;
|
|
|
|
|
|
|
|
/* Calculate the rx buffer allocation parameters required to
|
|
|
|
* support the current MTU, including padding for header
|
|
|
|
* alignment and overruns.
|
|
|
|
*/
|
|
|
|
efx->rx_dma_len = (efx->rx_prefix_size +
|
|
|
|
EFX_MAX_FRAME_LEN(efx->net_dev->mtu) +
|
|
|
|
efx->type->rx_buffer_padding);
|
|
|
|
rx_buf_len = (sizeof(struct efx_rx_page_state) + XDP_PACKET_HEADROOM +
|
|
|
|
efx->rx_ip_align + efx->rx_dma_len);
|
|
|
|
if (rx_buf_len <= PAGE_SIZE) {
|
|
|
|
efx->rx_scatter = efx->type->always_rx_scatter;
|
|
|
|
efx->rx_buffer_order = 0;
|
|
|
|
} else if (efx->type->can_rx_scatter) {
|
|
|
|
BUILD_BUG_ON(EFX_RX_USR_BUF_SIZE % L1_CACHE_BYTES);
|
|
|
|
BUILD_BUG_ON(sizeof(struct efx_rx_page_state) +
|
|
|
|
2 * ALIGN(NET_IP_ALIGN + EFX_RX_USR_BUF_SIZE,
|
|
|
|
EFX_RX_BUF_ALIGNMENT) >
|
|
|
|
PAGE_SIZE);
|
|
|
|
efx->rx_scatter = true;
|
|
|
|
efx->rx_dma_len = EFX_RX_USR_BUF_SIZE;
|
|
|
|
efx->rx_buffer_order = 0;
|
|
|
|
} else {
|
|
|
|
efx->rx_scatter = false;
|
|
|
|
efx->rx_buffer_order = get_order(rx_buf_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
efx_rx_config_page_split(efx);
|
|
|
|
if (efx->rx_buffer_order)
|
|
|
|
netif_dbg(efx, drv, efx->net_dev,
|
|
|
|
"RX buf len=%u; page order=%u batch=%u\n",
|
|
|
|
efx->rx_dma_len, efx->rx_buffer_order,
|
|
|
|
efx->rx_pages_per_batch);
|
|
|
|
else
|
|
|
|
netif_dbg(efx, drv, efx->net_dev,
|
|
|
|
"RX buf len=%u step=%u bpp=%u; page batch=%u\n",
|
|
|
|
efx->rx_dma_len, efx->rx_page_buf_step,
|
|
|
|
efx->rx_bufs_per_page, efx->rx_pages_per_batch);
|
|
|
|
|
|
|
|
/* Restore previously fixed features in hw_features and remove
|
|
|
|
* features which are fixed now
|
|
|
|
*/
|
|
|
|
efx->net_dev->hw_features |= efx->net_dev->features;
|
|
|
|
efx->net_dev->hw_features &= ~efx->fixed_features;
|
|
|
|
efx->net_dev->features |= efx->fixed_features;
|
|
|
|
if (efx->net_dev->features != old_features)
|
|
|
|
netdev_features_change(efx->net_dev);
|
|
|
|
|
|
|
|
/* RX filters may also have scatter-enabled flags */
|
|
|
|
if (efx->rx_scatter != old_rx_scatter)
|
|
|
|
efx->type->filter_update_rx_scatter(efx);
|
|
|
|
|
|
|
|
/* We must keep at least one descriptor in a TX ring empty.
|
|
|
|
* We could avoid this when the queue size does not exactly
|
|
|
|
* match the hardware ring size, but it's not that important.
|
|
|
|
* Therefore we stop the queue when one more skb might fill
|
|
|
|
* the ring completely. We wake it when half way back to
|
|
|
|
* empty.
|
|
|
|
*/
|
|
|
|
efx->txq_stop_thresh = efx->txq_entries - efx_tx_max_skb_descs(efx);
|
|
|
|
efx->txq_wake_thresh = efx->txq_stop_thresh / 2;
|
|
|
|
|
|
|
|
/* Initialise the channels */
|
|
|
|
efx_start_channels(efx);
|
|
|
|
|
|
|
|
efx_ptp_start_datapath(efx);
|
|
|
|
|
|
|
|
if (netif_device_present(efx->net_dev))
|
|
|
|
netif_tx_wake_all_queues(efx->net_dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void efx_stop_channels(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
struct efx_tx_queue *tx_queue;
|
|
|
|
struct efx_rx_queue *rx_queue;
|
|
|
|
struct efx_channel *channel;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
/* Stop RX refill */
|
|
|
|
efx_for_each_channel(channel, efx) {
|
|
|
|
efx_for_each_channel_rx_queue(rx_queue, channel)
|
|
|
|
rx_queue->refill_enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
efx_for_each_channel(channel, efx) {
|
|
|
|
/* RX packet processing is pipelined, so wait for the
|
|
|
|
* NAPI handler to complete. At least event queue 0
|
|
|
|
* might be kept active by non-data events, so don't
|
|
|
|
* use napi_synchronize() but actually disable NAPI
|
|
|
|
* temporarily.
|
|
|
|
*/
|
|
|
|
if (efx_channel_has_rx_queue(channel)) {
|
|
|
|
efx_stop_eventq(channel);
|
|
|
|
efx_start_eventq(channel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (efx->type->fini_dmaq)
|
|
|
|
rc = efx->type->fini_dmaq(efx);
|
|
|
|
|
|
|
|
if (rc) {
|
|
|
|
netif_err(efx, drv, efx->net_dev, "failed to flush queues\n");
|
|
|
|
} else {
|
|
|
|
netif_dbg(efx, drv, efx->net_dev,
|
|
|
|
"successfully flushed all queues\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
efx_for_each_channel(channel, efx) {
|
|
|
|
efx_for_each_channel_rx_queue(rx_queue, channel)
|
|
|
|
efx_fini_rx_queue(rx_queue);
|
|
|
|
efx_for_each_possible_channel_tx_queue(tx_queue, channel)
|
|
|
|
efx_fini_tx_queue(tx_queue);
|
|
|
|
}
|
|
|
|
efx->xdp_rxq_info_failed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void efx_stop_datapath(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
EFX_ASSERT_RESET_SERIALISED(efx);
|
|
|
|
BUG_ON(efx->port_enabled);
|
|
|
|
|
|
|
|
efx_ptp_stop_datapath(efx);
|
|
|
|
|
|
|
|
efx_stop_channels(efx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Port handling
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
static void efx_start_port(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
netif_dbg(efx, ifup, efx->net_dev, "start port\n");
|
|
|
|
BUG_ON(efx->port_enabled);
|
|
|
|
|
|
|
|
mutex_lock(&efx->mac_lock);
|
|
|
|
efx->port_enabled = true;
|
|
|
|
|
|
|
|
/* Ensure MAC ingress/egress is enabled */
|
|
|
|
efx_mac_reconfigure(efx);
|
|
|
|
|
|
|
|
mutex_unlock(&efx->mac_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Cancel work for MAC reconfiguration, periodic hardware monitoring
|
|
|
|
* and the async self-test, wait for them to finish and prevent them
|
|
|
|
* being scheduled again. This doesn't cover online resets, which
|
|
|
|
* should only be cancelled when removing the device.
|
|
|
|
*/
|
|
|
|
static void efx_stop_port(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
netif_dbg(efx, ifdown, efx->net_dev, "stop port\n");
|
|
|
|
|
|
|
|
EFX_ASSERT_RESET_SERIALISED(efx);
|
|
|
|
|
|
|
|
mutex_lock(&efx->mac_lock);
|
|
|
|
efx->port_enabled = false;
|
|
|
|
mutex_unlock(&efx->mac_lock);
|
|
|
|
|
|
|
|
/* Serialise against efx_set_multicast_list() */
|
|
|
|
netif_addr_lock_bh(efx->net_dev);
|
|
|
|
netif_addr_unlock_bh(efx->net_dev);
|
|
|
|
|
|
|
|
cancel_delayed_work_sync(&efx->monitor_work);
|
|
|
|
efx_selftest_async_cancel(efx);
|
|
|
|
cancel_work_sync(&efx->mac_work);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the interface is supposed to be running but is not, start
|
|
|
|
* the hardware and software data path, regular activity for the port
|
|
|
|
* (MAC statistics, link polling, etc.) and schedule the port to be
|
|
|
|
* reconfigured. Interrupts must already be enabled. This function
|
|
|
|
* is safe to call multiple times, so long as the NIC is not disabled.
|
|
|
|
* Requires the RTNL lock.
|
|
|
|
*/
|
|
|
|
void efx_start_all(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
EFX_ASSERT_RESET_SERIALISED(efx);
|
|
|
|
BUG_ON(efx->state == STATE_DISABLED);
|
|
|
|
|
|
|
|
/* Check that it is appropriate to restart the interface. All
|
|
|
|
* of these flags are safe to read under just the rtnl lock
|
|
|
|
*/
|
|
|
|
if (efx->port_enabled || !netif_running(efx->net_dev) ||
|
|
|
|
efx->reset_pending)
|
|
|
|
return;
|
|
|
|
|
|
|
|
efx_start_port(efx);
|
|
|
|
efx_start_datapath(efx);
|
|
|
|
|
|
|
|
/* Start the hardware monitor if there is one */
|
|
|
|
efx_start_monitor(efx);
|
|
|
|
|
|
|
|
/* Link state detection is normally event-driven; we have
|
|
|
|
* to poll now because we could have missed a change
|
|
|
|
*/
|
|
|
|
mutex_lock(&efx->mac_lock);
|
|
|
|
if (efx->phy_op->poll(efx))
|
|
|
|
efx_link_status_changed(efx);
|
|
|
|
mutex_unlock(&efx->mac_lock);
|
|
|
|
|
|
|
|
efx->type->start_stats(efx);
|
|
|
|
efx->type->pull_stats(efx);
|
|
|
|
spin_lock_bh(&efx->stats_lock);
|
|
|
|
efx->type->update_stats(efx, NULL, NULL);
|
|
|
|
spin_unlock_bh(&efx->stats_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Quiesce the hardware and software data path, and regular activity
|
|
|
|
* for the port without bringing the link down. Safe to call multiple
|
|
|
|
* times with the NIC in almost any state, but interrupts should be
|
|
|
|
* enabled. Requires the RTNL lock.
|
|
|
|
*/
|
|
|
|
void efx_stop_all(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
EFX_ASSERT_RESET_SERIALISED(efx);
|
|
|
|
|
|
|
|
/* port_enabled can be read safely under the rtnl lock */
|
|
|
|
if (!efx->port_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* update stats before we go down so we can accurately count
|
|
|
|
* rx_nodesc_drops
|
|
|
|
*/
|
|
|
|
efx->type->pull_stats(efx);
|
|
|
|
spin_lock_bh(&efx->stats_lock);
|
|
|
|
efx->type->update_stats(efx, NULL, NULL);
|
|
|
|
spin_unlock_bh(&efx->stats_lock);
|
|
|
|
efx->type->stop_stats(efx);
|
|
|
|
efx_stop_port(efx);
|
|
|
|
|
|
|
|
/* Stop the kernel transmit interface. This is only valid if
|
|
|
|
* the device is stopped or detached; otherwise the watchdog
|
|
|
|
* may fire immediately.
|
|
|
|
*/
|
|
|
|
WARN_ON(netif_running(efx->net_dev) &&
|
|
|
|
netif_device_present(efx->net_dev));
|
|
|
|
netif_tx_disable(efx->net_dev);
|
|
|
|
|
|
|
|
efx_stop_datapath(efx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Push loopback/power/transmit disable settings to the PHY, and reconfigure
|
|
|
|
* the MAC appropriately. All other PHY configuration changes are pushed
|
|
|
|
* through phy_op->set_settings(), and pushed asynchronously to the MAC
|
|
|
|
* through efx_monitor().
|
|
|
|
*
|
|
|
|
* Callers must hold the mac_lock
|
|
|
|
*/
|
|
|
|
int __efx_reconfigure_port(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
enum efx_phy_mode phy_mode;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
WARN_ON(!mutex_is_locked(&efx->mac_lock));
|
|
|
|
|
|
|
|
/* Disable PHY transmit in mac level loopbacks */
|
|
|
|
phy_mode = efx->phy_mode;
|
|
|
|
if (LOOPBACK_INTERNAL(efx))
|
|
|
|
efx->phy_mode |= PHY_MODE_TX_DISABLED;
|
|
|
|
else
|
|
|
|
efx->phy_mode &= ~PHY_MODE_TX_DISABLED;
|
|
|
|
|
|
|
|
rc = efx->type->reconfigure_port(efx);
|
|
|
|
|
|
|
|
if (rc)
|
|
|
|
efx->phy_mode = phy_mode;
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reinitialise the MAC to pick up new PHY settings, even if the port is
|
|
|
|
* disabled.
|
|
|
|
*/
|
|
|
|
int efx_reconfigure_port(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
EFX_ASSERT_RESET_SERIALISED(efx);
|
|
|
|
|
|
|
|
mutex_lock(&efx->mac_lock);
|
|
|
|
rc = __efx_reconfigure_port(efx);
|
|
|
|
mutex_unlock(&efx->mac_lock);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
2020-01-08 23:11:46 +07:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Device reset and suspend
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/* Try recovery mechanisms.
|
|
|
|
* For now only EEH is supported.
|
|
|
|
* Returns 0 if the recovery mechanisms are unsuccessful.
|
|
|
|
* Returns a non-zero value otherwise.
|
|
|
|
*/
|
|
|
|
int efx_try_recovery(struct efx_nic *efx)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_EEH
|
|
|
|
/* A PCI error can occur and not be seen by EEH because nothing
|
|
|
|
* happens on the PCI bus. In this case the driver may fail and
|
|
|
|
* schedule a 'recover or reset', leading to this recovery handler.
|
|
|
|
* Manually call the eeh failure check function.
|
|
|
|
*/
|
|
|
|
struct eeh_dev *eehdev = pci_dev_to_eeh_dev(efx->pci_dev);
|
|
|
|
if (eeh_dev_check_failure(eehdev)) {
|
|
|
|
/* The EEH mechanisms will handle the error and reset the
|
|
|
|
* device if necessary.
|
|
|
|
*/
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Tears down the entire software state and most of the hardware state
|
|
|
|
* before reset.
|
|
|
|
*/
|
|
|
|
void efx_reset_down(struct efx_nic *efx, enum reset_type method)
|
|
|
|
{
|
|
|
|
EFX_ASSERT_RESET_SERIALISED(efx);
|
|
|
|
|
|
|
|
if (method == RESET_TYPE_MCDI_TIMEOUT)
|
|
|
|
efx->type->prepare_flr(efx);
|
|
|
|
|
|
|
|
efx_stop_all(efx);
|
|
|
|
efx_disable_interrupts(efx);
|
|
|
|
|
|
|
|
mutex_lock(&efx->mac_lock);
|
|
|
|
down_write(&efx->filter_sem);
|
|
|
|
mutex_lock(&efx->rss_lock);
|
|
|
|
if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
|
|
|
|
method != RESET_TYPE_DATAPATH)
|
|
|
|
efx->phy_op->fini(efx);
|
|
|
|
efx->type->fini(efx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This function will always ensure that the locks acquired in
|
|
|
|
* efx_reset_down() are released. A failure return code indicates
|
|
|
|
* that we were unable to reinitialise the hardware, and the
|
|
|
|
* driver should be disabled. If ok is false, then the rx and tx
|
|
|
|
* engines are not restarted, pending a RESET_DISABLE.
|
|
|
|
*/
|
|
|
|
int efx_reset_up(struct efx_nic *efx, enum reset_type method, bool ok)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
EFX_ASSERT_RESET_SERIALISED(efx);
|
|
|
|
|
|
|
|
if (method == RESET_TYPE_MCDI_TIMEOUT)
|
|
|
|
efx->type->finish_flr(efx);
|
|
|
|
|
|
|
|
/* Ensure that SRAM is initialised even if we're disabling the device */
|
|
|
|
rc = efx->type->init(efx);
|
|
|
|
if (rc) {
|
|
|
|
netif_err(efx, drv, efx->net_dev, "failed to initialise NIC\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (efx->port_initialized && method != RESET_TYPE_INVISIBLE &&
|
|
|
|
method != RESET_TYPE_DATAPATH) {
|
|
|
|
rc = efx->phy_op->init(efx);
|
|
|
|
if (rc)
|
|
|
|
goto fail;
|
|
|
|
rc = efx->phy_op->reconfigure(efx);
|
|
|
|
if (rc && rc != -EPERM)
|
|
|
|
netif_err(efx, drv, efx->net_dev,
|
|
|
|
"could not restore PHY settings\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = efx_enable_interrupts(efx);
|
|
|
|
if (rc)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
#ifdef CONFIG_SFC_SRIOV
|
|
|
|
rc = efx->type->vswitching_restore(efx);
|
|
|
|
if (rc) /* not fatal; the PF will still work fine */
|
|
|
|
netif_warn(efx, probe, efx->net_dev,
|
|
|
|
"failed to restore vswitching rc=%d;"
|
|
|
|
" VFs may not function\n", rc);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (efx->type->rx_restore_rss_contexts)
|
|
|
|
efx->type->rx_restore_rss_contexts(efx);
|
|
|
|
mutex_unlock(&efx->rss_lock);
|
|
|
|
efx->type->filter_table_restore(efx);
|
|
|
|
up_write(&efx->filter_sem);
|
|
|
|
if (efx->type->sriov_reset)
|
|
|
|
efx->type->sriov_reset(efx);
|
|
|
|
|
|
|
|
mutex_unlock(&efx->mac_lock);
|
|
|
|
|
|
|
|
efx_start_all(efx);
|
|
|
|
|
|
|
|
if (efx->type->udp_tnl_push_ports)
|
|
|
|
efx->type->udp_tnl_push_ports(efx);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
efx->port_initialized = false;
|
|
|
|
|
|
|
|
mutex_unlock(&efx->rss_lock);
|
|
|
|
up_write(&efx->filter_sem);
|
|
|
|
mutex_unlock(&efx->mac_lock);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset the NIC using the specified method. Note that the reset may
|
|
|
|
* fail, in which case the card will be left in an unusable state.
|
|
|
|
*
|
|
|
|
* Caller must hold the rtnl_lock.
|
|
|
|
*/
|
|
|
|
int efx_reset(struct efx_nic *efx, enum reset_type method)
|
|
|
|
{
|
|
|
|
bool disabled;
|
|
|
|
int rc, rc2;
|
|
|
|
|
|
|
|
netif_info(efx, drv, efx->net_dev, "resetting (%s)\n",
|
|
|
|
RESET_TYPE(method));
|
|
|
|
|
|
|
|
efx_device_detach_sync(efx);
|
|
|
|
efx_reset_down(efx, method);
|
|
|
|
|
|
|
|
rc = efx->type->reset(efx, method);
|
|
|
|
if (rc) {
|
|
|
|
netif_err(efx, drv, efx->net_dev, "failed to reset hardware\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear flags for the scopes we covered. We assume the NIC and
|
|
|
|
* driver are now quiescent so that there is no race here.
|
|
|
|
*/
|
|
|
|
if (method < RESET_TYPE_MAX_METHOD)
|
|
|
|
efx->reset_pending &= -(1 << (method + 1));
|
|
|
|
else /* it doesn't fit into the well-ordered scope hierarchy */
|
|
|
|
__clear_bit(method, &efx->reset_pending);
|
|
|
|
|
|
|
|
/* Reinitialise bus-mastering, which may have been turned off before
|
|
|
|
* the reset was scheduled. This is still appropriate, even in the
|
|
|
|
* RESET_TYPE_DISABLE since this driver generally assumes the hardware
|
|
|
|
* can respond to requests.
|
|
|
|
*/
|
|
|
|
pci_set_master(efx->pci_dev);
|
|
|
|
|
|
|
|
out:
|
|
|
|
/* Leave device stopped if necessary */
|
|
|
|
disabled = rc ||
|
|
|
|
method == RESET_TYPE_DISABLE ||
|
|
|
|
method == RESET_TYPE_RECOVER_OR_DISABLE;
|
|
|
|
rc2 = efx_reset_up(efx, method, !disabled);
|
|
|
|
if (rc2) {
|
|
|
|
disabled = true;
|
|
|
|
if (!rc)
|
|
|
|
rc = rc2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (disabled) {
|
|
|
|
dev_close(efx->net_dev);
|
|
|
|
netif_err(efx, drv, efx->net_dev, "has been disabled\n");
|
|
|
|
efx->state = STATE_DISABLED;
|
|
|
|
} else {
|
|
|
|
netif_dbg(efx, drv, efx->net_dev, "reset complete\n");
|
|
|
|
efx_device_attach_if_not_resetting(efx);
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void efx_schedule_reset(struct efx_nic *efx, enum reset_type type)
|
|
|
|
{
|
|
|
|
enum reset_type method;
|
|
|
|
|
|
|
|
if (efx->state == STATE_RECOVERY) {
|
|
|
|
netif_dbg(efx, drv, efx->net_dev,
|
|
|
|
"recovering: skip scheduling %s reset\n",
|
|
|
|
RESET_TYPE(type));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case RESET_TYPE_INVISIBLE:
|
|
|
|
case RESET_TYPE_ALL:
|
|
|
|
case RESET_TYPE_RECOVER_OR_ALL:
|
|
|
|
case RESET_TYPE_WORLD:
|
|
|
|
case RESET_TYPE_DISABLE:
|
|
|
|
case RESET_TYPE_RECOVER_OR_DISABLE:
|
|
|
|
case RESET_TYPE_DATAPATH:
|
|
|
|
case RESET_TYPE_MC_BIST:
|
|
|
|
case RESET_TYPE_MCDI_TIMEOUT:
|
|
|
|
method = type;
|
|
|
|
netif_dbg(efx, drv, efx->net_dev, "scheduling %s reset\n",
|
|
|
|
RESET_TYPE(method));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
method = efx->type->map_reset_reason(type);
|
|
|
|
netif_dbg(efx, drv, efx->net_dev,
|
|
|
|
"scheduling %s reset for %s\n",
|
|
|
|
RESET_TYPE(method), RESET_TYPE(type));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_bit(method, &efx->reset_pending);
|
|
|
|
smp_mb(); /* ensure we change reset_pending before checking state */
|
|
|
|
|
|
|
|
/* If we're not READY then just leave the flags set as the cue
|
|
|
|
* to abort probing or reschedule the reset later.
|
|
|
|
*/
|
|
|
|
if (READ_ONCE(efx->state) != STATE_READY)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* efx_process_channel() will no longer read events once a
|
|
|
|
* reset is scheduled. So switch back to poll'd MCDI completions.
|
|
|
|
*/
|
|
|
|
efx_mcdi_mode_poll(efx);
|
|
|
|
|
|
|
|
efx_queue_reset_work(efx);
|
|
|
|
}
|