// 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.
*/
/* This is the first interrupt mode to try out of: * 0 => MSI-X * 1 => MSI * 2 => legacy
*/ unsignedint efx_interrupt_mode = EFX_INT_MODE_MSIX;
/* This is the requested number of CPUs to use for Receive-Side Scaling (RSS), * i.e. the number of CPUs among which we may distribute simultaneous * interrupt handling. * * Cards without MSI-X will only target one CPU via legacy or MSI interrupt. * The default (0) means to assign an interrupt to each core.
*/ unsignedint rss_cpus;
/* If no online CPUs in local node, fallback to any online CPUs */ if (count == 0)
count = count_online_cores(efx, false);
}
if (count > EFX_MAX_RX_QUEUES) {
netif_cond_dbg(efx, probe, efx->net_dev, !rss_cpus, warn, "Reducing number of rx queues from %u to %u.\n",
count, EFX_MAX_RX_QUEUES);
count = EFX_MAX_RX_QUEUES;
}
/* If RSS is requested for the PF *and* VFs then we can't write RSS * table entries that are inaccessible to VFs
*/ #ifdef CONFIG_SFC_SRIOV if (efx->type->sriov_wanted) { if (efx->type->sriov_wanted(efx) && efx_vf_size(efx) > 1 &&
count > efx_vf_size(efx)) {
netif_warn(efx, probe, efx->net_dev, "Reducing number of RSS channels from %u to %u for " "VF support. Increase vf-msix-limit to use more " "channels on the PF.\n",
count, efx_vf_size(efx));
count = efx_vf_size(efx);
}
} #endif
return count;
}
staticint efx_allocate_msix_channels(struct efx_nic *efx, unsignedint max_channels, unsignedint extra_channels, unsignedint parallelism)
{ unsignedint n_channels = parallelism; int vec_count; int tx_per_ev; int n_xdp_tx; int n_xdp_ev;
if (efx_separate_tx_channels)
n_channels *= 2;
n_channels += extra_channels;
/* To allow XDP transmit to happen from arbitrary NAPI contexts * we allocate a TX queue per CPU. We share event queues across * multiple tx queues, assuming tx and ev queues are both * maximum size.
*/
tx_per_ev = EFX_MAX_EVQ_SIZE / EFX_TXQ_MAX_ENT(efx);
tx_per_ev = min(tx_per_ev, EFX_MAX_TXQ_PER_CHANNEL);
n_xdp_tx = num_possible_cpus();
n_xdp_ev = DIV_ROUND_UP(n_xdp_tx, tx_per_ev);
vec_count = pci_msix_vec_count(efx->pci_dev); if (vec_count < 0) return vec_count;
/* Check resources. * We need a channel per event queue, plus a VI per tx queue. * This may be more pessimistic than it needs to be.
*/ if (n_channels >= max_channels) {
efx->xdp_txq_queues_mode = EFX_XDP_TX_QUEUES_BORROWED;
netif_warn(efx, drv, efx->net_dev, "Insufficient resources for %d XDP event queues (%d other channels, max %d)\n",
n_xdp_ev, n_channels, max_channels);
netif_warn(efx, drv, efx->net_dev, "XDP_TX and XDP_REDIRECT might decrease device's performance\n");
} elseif (n_channels + n_xdp_tx > efx->max_vis) {
efx->xdp_txq_queues_mode = EFX_XDP_TX_QUEUES_BORROWED;
netif_warn(efx, drv, efx->net_dev, "Insufficient resources for %d XDP TX queues (%d other channels, max VIs %d)\n",
n_xdp_tx, n_channels, efx->max_vis);
netif_warn(efx, drv, efx->net_dev, "XDP_TX and XDP_REDIRECT might decrease device's performance\n");
} elseif (n_channels + n_xdp_ev > max_channels) {
efx->xdp_txq_queues_mode = EFX_XDP_TX_QUEUES_SHARED;
netif_warn(efx, drv, efx->net_dev, "Insufficient resources for %d XDP event queues (%d other channels, max %d)\n",
n_xdp_ev, n_channels, max_channels);
n_xdp_ev = max_channels - n_channels;
netif_warn(efx, drv, efx->net_dev, "XDP_TX and XDP_REDIRECT will work with reduced performance (%d cpus/tx_queue)\n",
DIV_ROUND_UP(n_xdp_tx, tx_per_ev * n_xdp_ev));
} else {
efx->xdp_txq_queues_mode = EFX_XDP_TX_QUEUES_DEDICATED;
}
/* Probe the number and type of interrupts we are able to obtain, and * the resulting numbers of channels and RX queues.
*/ int efx_probe_interrupts(struct efx_nic *efx)
{ unsignedint extra_channels = 0; unsignedint rss_spread; unsignedint i, j; int rc;
for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) if (efx->extra_channel_type[i])
++extra_channels;
/* Assign extra channels if possible, before XDP channels */
efx->n_extra_tx_channels = 0;
j = efx->xdp_channel_offset; for (i = 0; i < EFX_MAX_EXTRA_CHANNELS; i++) { if (!efx->extra_channel_type[i]) continue; if (j <= efx->tx_channel_offset + efx->n_tx_channels) {
efx->extra_channel_type[i]->handle_no_channel(efx);
} else {
--j;
efx_get_channel(efx, j)->type =
efx->extra_channel_type[i]; if (efx_channel_has_tx_queues(efx_get_channel(efx, j)))
efx->n_extra_tx_channels++;
}
}
rss_spread = efx->n_rx_channels; /* RSS might be usable on VFs even if it is disabled on the PF */ #ifdef CONFIG_SFC_SRIOV if (efx->type->sriov_wanted) {
efx->rss_spread = ((rss_spread > 1 ||
!efx->type->sriov_wanted(efx)) ?
rss_spread : efx_vf_size(efx)); return 0;
} #endif
efx->rss_spread = rss_spread;
/* If no online CPUs in local node, fallback to any online CPU */ if (cpumask_first_and(cpu_online_mask, numa_mask) >= nr_cpu_ids)
numa_mask = cpu_online_mask;
cpu = -1;
efx_for_each_channel(channel, efx) {
cpu = cpumask_next_and(cpu, cpu_online_mask, numa_mask); if (cpu >= nr_cpu_ids)
cpu = cpumask_first_and(cpu_online_mask, numa_mask);
irq_set_affinity_hint(channel->irq, cpumask_of(cpu));
}
}
/* Create event queue * Event queue memory allocations are done only once. If the channel * is reset, the memory buffer will be reused; this guards against * errors during channel reset and also simplifies interrupt handling.
*/ int efx_probe_eventq(struct efx_channel *channel)
{ struct efx_nic *efx = channel->efx; unsignedlong entries;
/* Build an event queue with room for one event per tx and rx buffer, * plus some extra for link state events and MCDI completions.
*/
entries = roundup_pow_of_two(efx->rxq_entries + efx->txq_entries + 128);
EFX_WARN_ON_PARANOID(entries > EFX_MAX_EVQ_SIZE);
channel->eventq_mask = max(entries, EFX_MIN_EVQ_SIZE) - 1;
return efx_nic_probe_eventq(channel);
}
/* Prepare channel's event queue */ int efx_init_eventq(struct efx_channel *channel)
{ struct efx_nic *efx = channel->efx; int rc;
channel = container_of(dwork, struct efx_channel, filter_work);
time = jiffies - channel->rfs_last_expiry;
quota = channel->rfs_filter_count * time / (30 * HZ); if (quota >= 20 && __efx_filter_rfs_expire(channel, min(channel->rfs_filter_count, quota)))
channel->rfs_last_expiry += time; /* Ensure we do more work eventually even if NAPI poll is not happening */
schedule_delayed_work(dwork, 30 * HZ);
} #endif
/* Allocate and initialise a channel structure. */ staticstruct efx_channel *efx_alloc_channel(struct efx_nic *efx, int i)
{ struct efx_rx_queue *rx_queue; struct efx_tx_queue *tx_queue; struct efx_channel *channel; int j;
channel = kzalloc(sizeof(*channel), GFP_KERNEL); if (!channel) return NULL;
int efx_probe_channels(struct efx_nic *efx)
{ struct efx_channel *channel; int rc;
/* Probe channels in reverse, so that any 'extra' channels * use the start of the buffer table. This allows the traffic * channels to be resized without moving them or wasting the * entries before them.
*/
efx_for_each_channel_rev(channel, efx) {
rc = efx_probe_channel(channel); if (rc) {
netif_err(efx, probe, efx->net_dev, "failed to create channel %d\n",
channel->channel); goto fail;
}
}
efx_set_channel_names(efx);
/* We need to mark which channels really have RX and TX * queues, and adjust the TX queue numbers if we have separate * RX-only and TX-only channels.
*/
efx_for_each_channel(channel, efx) { if (channel->channel < efx->tx_channel_offset) continue;
/* If XDP is borrowing queues from net stack, it must * use the queue with no csum offload, which is the * first one of the channel * (note: tx_queue_by_type is not initialized yet)
*/ if (efx->xdp_txq_queues_mode ==
EFX_XDP_TX_QUEUES_BORROWED) {
tx_queue = &channel->tx_queue[0];
rc = efx_set_xdp_tx_queue(efx, xdp_queue_number,
tx_queue); if (rc == 0)
xdp_queue_number++;
}
}
}
WARN_ON(efx->xdp_txq_queues_mode == EFX_XDP_TX_QUEUES_DEDICATED &&
xdp_queue_number != efx->xdp_tx_queue_count);
WARN_ON(efx->xdp_txq_queues_mode != EFX_XDP_TX_QUEUES_DEDICATED &&
xdp_queue_number > efx->xdp_tx_queue_count);
/* If we have more CPUs than assigned XDP TX queues, assign the already * existing queues to the exceeding CPUs
*/
next_queue = 0; while (xdp_queue_number < efx->xdp_tx_queue_count) {
tx_queue = efx->xdp_tx_queues[next_queue++];
rc = efx_set_xdp_tx_queue(efx, xdp_queue_number, tx_queue); if (rc == 0)
xdp_queue_number++;
}
}
/* Clone channels (where possible) */
memset(other_channel, 0, sizeof(other_channel)); for (i = 0; i < efx->n_channels; i++) {
channel = efx->channel[i]; if (channel->type->copy)
channel = channel->type->copy(channel); if (!channel) {
rc = -ENOMEM; goto out;
}
other_channel[i] = channel;
}
/* Swap entry counts and channel pointers */
old_rxq_entries = efx->rxq_entries;
old_txq_entries = efx->txq_entries;
efx->rxq_entries = rxq_entries;
efx->txq_entries = txq_entries; for (i = 0; i < efx->n_channels; i++)
swap(efx->channel[i], other_channel[i]);
for (i = 0; i < efx->n_channels; i++) {
channel = efx->channel[i]; if (!channel->type->copy) continue;
rc = efx_probe_channel(channel); if (rc) goto rollback;
efx_init_napi_channel(efx->channel[i]);
}
efx_set_xdp_channels(efx);
out:
efx->ptp_data = NULL; /* Destroy unused channel structures */ for (i = 0; i < efx->n_channels; i++) {
channel = other_channel[i]; if (channel && channel->type->copy) {
efx_fini_napi_channel(channel);
efx_remove_channel(channel);
kfree(channel);
}
}
/* Stop special channels and RX refill. * The channel's stop has to be called first, since it might wait * for a sentinel RX to indicate the channel has fully drained.
*/
efx_for_each_channel(channel, efx) { if (channel->type->stop)
channel->type->stop(channel);
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");
}
/************************************************************************** * * NAPI interface *
*************************************************************************/
/* Process channel's event queue * * This function is responsible for processing the event queue of a * single channel. The caller must guarantee that this function will * never be concurrently called more than once on the same channel, * though different channels may be being processed concurrently.
*/ staticint efx_process_channel(struct efx_channel *channel, int budget)
{ struct efx_tx_queue *tx_queue; struct list_head rx_list; int spent;
if (unlikely(!channel->enabled)) return 0;
/* Prepare the batch receive list */
EFX_WARN_ON_PARANOID(channel->rx_list != NULL);
INIT_LIST_HEAD(&rx_list);
channel->rx_list = &rx_list;
/* NAPI poll handler * * NAPI guarantees serialisation of polls of the same device, which * provides the guarantee required by efx_process_channel().
*/ staticint efx_poll(struct napi_struct *napi, int budget)
{ struct efx_channel *channel =
container_of(napi, struct efx_channel, napi_str); struct efx_nic *efx = channel->efx; #ifdef CONFIG_RFS_ACCEL unsignedint time; #endif int spent;
netif_vdbg(efx, intr, efx->net_dev, "channel %d NAPI poll executing on CPU %d\n",
channel->channel, raw_smp_processor_id());
spent = efx_process_channel(channel, budget);
if (budget)
xdp_do_flush();
if (spent < budget) { if (efx_channel_has_rx_queue(channel) &&
efx->irq_rx_adaptive &&
unlikely(++channel->irq_count == 1000)) {
efx_update_irq_mod(efx, channel);
}
#ifdef CONFIG_RFS_ACCEL /* Perhaps expire some ARFS filters */
time = jiffies - channel->rfs_last_expiry; /* Would our quota be >= 20? */ if (channel->rfs_filter_count * time >= 600 * HZ)
mod_delayed_work(system_wq, &channel->filter_work, 0); #endif
/* There is no race here; although napi_disable() will * only wait for napi_complete(), this isn't a problem * since efx_nic_eventq_read_ack() will have no effect if * interrupts have already been disabled.
*/ if (napi_complete_done(napi, spent))
efx_nic_eventq_read_ack(channel);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.