/** * idpf_init_vector_stack - Fill the MSIX vector stack with vector index * @adapter: private data struct * * Return 0 on success, error on failure
*/ staticint idpf_init_vector_stack(struct idpf_adapter *adapter)
{ struct idpf_vector_lifo *stack;
u16 min_vec;
u32 i;
mutex_lock(&adapter->vector_lock);
min_vec = adapter->num_msix_entries - adapter->num_avail_msix;
stack = &adapter->vector_stack;
stack->size = adapter->num_msix_entries; /* set the base and top to point at start of the 'free pool' to * distribute the unused vectors on-demand basis
*/
stack->base = min_vec;
stack->top = min_vec;
stack->vec_idx = kcalloc(stack->size, sizeof(u16), GFP_KERNEL); if (!stack->vec_idx) {
mutex_unlock(&adapter->vector_lock);
return -ENOMEM;
}
for (i = 0; i < stack->size; i++)
stack->vec_idx[i] = i;
mutex_unlock(&adapter->vector_lock);
return 0;
}
/** * idpf_deinit_vector_stack - zero out the MSIX vector stack * @adapter: private data struct
*/ staticvoid idpf_deinit_vector_stack(struct idpf_adapter *adapter)
{ struct idpf_vector_lifo *stack;
/** * idpf_mb_intr_rel_irq - Free the IRQ association with the OS * @adapter: adapter structure * * This will also disable interrupt mode and queue up mailbox task. Mailbox * task will reschedule itself if not in interrupt mode.
*/ staticvoid idpf_mb_intr_rel_irq(struct idpf_adapter *adapter)
{
clear_bit(IDPF_MB_INTR_MODE, adapter->flags);
kfree(free_irq(adapter->msix_entries[0].vector, adapter));
queue_delayed_work(adapter->mbx_wq, &adapter->mbx_task, 0);
}
/** * idpf_intr_rel - Release interrupt capabilities and free memory * @adapter: adapter to disable interrupts on
*/ void idpf_intr_rel(struct idpf_adapter *adapter)
{ if (!adapter->msix_entries) return;
/** * idpf_mb_irq_enable - Enable MSIX interrupt for the mailbox * @adapter: adapter to get the hardware address for register write
*/ staticvoid idpf_mb_irq_enable(struct idpf_adapter *adapter)
{ struct idpf_intr_reg *intr = &adapter->mb_vector.intr_reg;
u32 val;
val = intr->dyn_ctl_intena_m | intr->dyn_ctl_itridx_m;
writel(val, intr->dyn_ctl);
writel(intr->icr_ena_ctlq_m, intr->icr_ena);
}
/** * idpf_mb_intr_req_irq - Request irq for the mailbox interrupt * @adapter: adapter structure to pass to the mailbox irq handler
*/ staticint idpf_mb_intr_req_irq(struct idpf_adapter *adapter)
{ int irq_num, mb_vidx = 0, err; char *name;
irq_num = adapter->msix_entries[mb_vidx].vector;
name = kasprintf(GFP_KERNEL, "%s-%s-%d",
dev_driver_string(&adapter->pdev->dev), "Mailbox", mb_vidx);
err = request_irq(irq_num, adapter->irq_mb_handler, 0, name, adapter); if (err) {
dev_err(&adapter->pdev->dev, "IRQ request for mailbox failed, error: %d\n", err);
return err;
}
set_bit(IDPF_MB_INTR_MODE, adapter->flags);
return 0;
}
/** * idpf_mb_intr_init - Initialize the mailbox interrupt * @adapter: adapter structure to store the mailbox vector
*/ staticint idpf_mb_intr_init(struct idpf_adapter *adapter)
{
adapter->dev_ops.reg_ops.mb_intr_reg_init(adapter);
adapter->irq_mb_handler = idpf_mb_intr_clean;
return idpf_mb_intr_req_irq(adapter);
}
/** * idpf_vector_lifo_push - push MSIX vector index onto stack * @adapter: private data struct * @vec_idx: vector index to store
*/ staticint idpf_vector_lifo_push(struct idpf_adapter *adapter, u16 vec_idx)
{ struct idpf_vector_lifo *stack = &adapter->vector_stack;
lockdep_assert_held(&adapter->vector_lock);
if (stack->top == stack->base) {
dev_err(&adapter->pdev->dev, "Exceeded the vector stack limit: %d\n",
stack->top); return -EINVAL;
}
stack->vec_idx[--stack->top] = vec_idx;
return 0;
}
/** * idpf_vector_lifo_pop - pop MSIX vector index from stack * @adapter: private data struct
*/ staticint idpf_vector_lifo_pop(struct idpf_adapter *adapter)
{ struct idpf_vector_lifo *stack = &adapter->vector_stack;
lockdep_assert_held(&adapter->vector_lock);
if (stack->top == stack->size) {
dev_err(&adapter->pdev->dev, "No interrupt vectors are available to distribute!\n");
return -EINVAL;
}
return stack->vec_idx[stack->top++];
}
/** * idpf_vector_stash - Store the vector indexes onto the stack * @adapter: private data struct * @q_vector_idxs: vector index array * @vec_info: info related to the number of vectors * * This function is a no-op if there are no vectors indexes to be stashed
*/ staticvoid idpf_vector_stash(struct idpf_adapter *adapter, u16 *q_vector_idxs, struct idpf_vector_info *vec_info)
{ int i, base = 0;
u16 vec_idx;
lockdep_assert_held(&adapter->vector_lock);
if (!vec_info->num_curr_vecs) return;
/* For default vports, no need to stash vector allocated from the * default pool onto the stack
*/ if (vec_info->default_vport)
base = IDPF_MIN_Q_VEC;
for (i = vec_info->num_curr_vecs - 1; i >= base ; i--) {
vec_idx = q_vector_idxs[i];
idpf_vector_lifo_push(adapter, vec_idx);
adapter->num_avail_msix++;
}
}
/** * idpf_req_rel_vector_indexes - Request or release MSIX vector indexes * @adapter: driver specific private structure * @q_vector_idxs: vector index array * @vec_info: info related to the number of vectors * * This is the core function to distribute the MSIX vectors acquired from the * OS. It expects the caller to pass the number of vectors required and * also previously allocated. First, it stashes previously allocated vector * indexes on to the stack and then figures out if it can allocate requested * vectors. It can wait on acquiring the mutex lock. If the caller passes 0 as * requested vectors, then this function just stashes the already allocated * vectors and returns 0. * * Returns actual number of vectors allocated on success, error value on failure * If 0 is returned, implies the stack has no vectors to allocate which is also * a failure case for the caller
*/ int idpf_req_rel_vector_indexes(struct idpf_adapter *adapter,
u16 *q_vector_idxs, struct idpf_vector_info *vec_info)
{
u16 num_req_vecs, num_alloc_vecs = 0, max_vecs; struct idpf_vector_lifo *stack; int i, j, vecid;
/* Stash interrupt vector indexes onto the stack if required */
idpf_vector_stash(adapter, q_vector_idxs, vec_info);
if (!num_req_vecs) goto rel_lock;
if (vec_info->default_vport) { /* As IDPF_MIN_Q_VEC per default vport is put aside in the * default pool of the stack, use them for default vports
*/
j = vec_info->index * IDPF_MIN_Q_VEC + IDPF_MBX_Q_VEC; for (i = 0; i < IDPF_MIN_Q_VEC; i++) {
q_vector_idxs[num_alloc_vecs++] = stack->vec_idx[j++];
num_req_vecs--;
}
}
/* Find if stack has enough vector to allocate */
max_vecs = min(adapter->num_avail_msix, num_req_vecs);
if (!num_rdma_vecs) { /* If idpf_get_reserved_rdma_vecs is 0, vectors are * pulled from the LAN pool.
*/
num_rdma_vecs = min_rdma_vecs;
} elseif (num_rdma_vecs < min_rdma_vecs) {
dev_err(&adapter->pdev->dev, "Not enough vectors reserved for RDMA (min: %u, current: %u)\n",
min_rdma_vecs, num_rdma_vecs); return -EINVAL;
}
}
num_q_vecs = total_vecs - IDPF_MBX_Q_VEC;
err = idpf_send_alloc_vectors_msg(adapter, num_q_vecs); if (err) {
dev_err(&adapter->pdev->dev, "Failed to allocate %d vectors: %d\n", num_q_vecs, err);
if (idpf_is_rdma_cap_ena(adapter)) { if (actual_vecs < total_vecs) {
dev_warn(&adapter->pdev->dev, "Warning: %d vectors requested, only %d available. Defaulting to minimum (%d) for RDMA and remaining for LAN.\n",
total_vecs, actual_vecs, IDPF_MIN_RDMA_VEC);
num_rdma_vecs = IDPF_MIN_RDMA_VEC;
}
for (vector = 0; vector < num_lan_vecs; vector++) {
adapter->msix_entries[vector].entry = vecids[vector];
adapter->msix_entries[vector].vector =
pci_irq_vector(adapter->pdev, vector);
} for (i = 0; i < num_rdma_vecs; vector++, i++) {
adapter->rdma_msix_entries[i].entry = vecids[vector];
adapter->rdma_msix_entries[i].vector =
pci_irq_vector(adapter->pdev, vector);
}
/* 'num_avail_msix' is used to distribute excess vectors to the vports * after considering the minimum vectors required per each default * vport
*/
adapter->num_avail_msix = num_lan_vecs - min_lan_vecs;
adapter->num_msix_entries = num_lan_vecs; if (idpf_is_rdma_cap_ena(adapter))
adapter->num_rdma_msix_entries = num_rdma_vecs;
/* Fill MSIX vector lifo stack with vector indexes */
err = idpf_init_vector_stack(adapter); if (err) goto free_vecids;
err = idpf_mb_intr_init(adapter); if (err) goto deinit_vec_stack;
idpf_mb_irq_enable(adapter);
kfree(vecids);
/** * idpf_find_mac_filter - Search filter list for specific mac filter * @vconfig: Vport config structure * @macaddr: The MAC address * * Returns ptr to the filter object or NULL. Must be called while holding the * mac_filter_list_lock.
**/ staticstruct idpf_mac_filter *idpf_find_mac_filter(struct idpf_vport_config *vconfig, const u8 *macaddr)
{ struct idpf_mac_filter *f;
if (!macaddr) return NULL;
list_for_each_entry(f, &vconfig->user_config.mac_filter_list, list) { if (ether_addr_equal(macaddr, f->macaddr)) return f;
}
return NULL;
}
/** * __idpf_del_mac_filter - Delete a MAC filter from the filter list * @vport_config: Vport config structure * @macaddr: The MAC address * * Returns 0 on success, error value on failure
**/ staticint __idpf_del_mac_filter(struct idpf_vport_config *vport_config, const u8 *macaddr)
{ struct idpf_mac_filter *f;
spin_lock_bh(&vport_config->mac_filter_list_lock);
f = idpf_find_mac_filter(vport_config, macaddr); if (f) {
list_del(&f->list);
kfree(f);
}
spin_unlock_bh(&vport_config->mac_filter_list_lock);
return 0;
}
/** * idpf_del_mac_filter - Delete a MAC filter from the filter list * @vport: Main vport structure * @np: Netdev private structure * @macaddr: The MAC address * @async: Don't wait for return message * * Removes filter from list and if interface is up, tells hardware about the * removed filter.
**/ staticint idpf_del_mac_filter(struct idpf_vport *vport, struct idpf_netdev_priv *np, const u8 *macaddr, bool async)
{ struct idpf_vport_config *vport_config; struct idpf_mac_filter *f;
/** * idpf_add_mac_filter - Add a mac filter to the filter list * @vport: Main vport structure * @np: Netdev private structure * @macaddr: The MAC address * @async: Don't wait for return message * * Returns 0 on success or error on failure. If interface is up, we'll also * send the virtchnl message to tell hardware about the filter.
**/ staticint idpf_add_mac_filter(struct idpf_vport *vport, struct idpf_netdev_priv *np, const u8 *macaddr, bool async)
{ struct idpf_vport_config *vport_config; int err;
/** * idpf_restore_mac_filters - Re-add all MAC filters in list * @vport: main vport struct * * Takes mac_filter_list_lock spinlock. Sets add field to true for filters to * resync filters back to HW.
*/ staticvoid idpf_restore_mac_filters(struct idpf_vport *vport)
{ struct idpf_vport_config *vport_config; struct idpf_mac_filter *f;
/** * idpf_remove_mac_filters - Remove all MAC filters in list * @vport: main vport struct * * Takes mac_filter_list_lock spinlock. Sets remove field to true for filters * to remove filters in HW.
*/ staticvoid idpf_remove_mac_filters(struct idpf_vport *vport)
{ struct idpf_vport_config *vport_config; struct idpf_mac_filter *f;
if (!idpf_is_cap_ena(adapter, IDPF_OTHER_CAPS,
VIRTCHNL2_CAP_MACFILTER)) {
dev_err(&adapter->pdev->dev, "MAC address is not provided and capability is not set\n");
dev_info(&adapter->pdev->dev, "Invalid MAC address %pM, using random %pM\n",
vport->default_mac_addr, netdev->dev_addr);
ether_addr_copy(vport->default_mac_addr, netdev->dev_addr);
return 0;
}
/** * idpf_cfg_netdev - Allocate, configure and register a netdev * @vport: main vport structure * * Returns 0 on success, negative value on failure.
*/ staticint idpf_cfg_netdev(struct idpf_vport *vport)
{ struct idpf_adapter *adapter = vport->adapter; struct idpf_vport_config *vport_config;
netdev_features_t other_offloads = 0;
netdev_features_t csum_offloads = 0;
netdev_features_t tso_offloads = 0;
netdev_features_t dflt_features; struct idpf_netdev_priv *np; struct net_device *netdev;
u16 idx = vport->idx; int err;
vport_config = adapter->vport_config[idx];
/* It's possible we already have a netdev allocated and registered for * this vport
*/ if (test_bit(IDPF_VPORT_REG_NETDEV, vport_config->flags)) {
netdev = adapter->netdevs[idx];
np = netdev_priv(netdev);
np->vport = vport;
np->vport_idx = vport->idx;
np->vport_id = vport->vport_id;
np->max_tx_hdr_size = idpf_get_max_tx_hdr_size(adapter);
vport->netdev = netdev;
return idpf_init_mac_addr(vport, netdev);
}
netdev = alloc_etherdev_mqs(sizeof(struct idpf_netdev_priv),
vport_config->max_q.max_txq,
vport_config->max_q.max_rxq); if (!netdev) return -ENOMEM;
/* carrier off on init to avoid Tx hangs */
netif_carrier_off(netdev);
/* make sure transmit queues start off as stopped */
netif_tx_stop_all_queues(netdev);
/* The vport can be arbitrarily released so we need to also track * netdevs in the adapter struct
*/
adapter->netdevs[idx] = netdev;
return 0;
}
/** * idpf_get_free_slot - get the next non-NULL location index in array * @adapter: adapter in which to look for a free vport slot
*/ staticint idpf_get_free_slot(struct idpf_adapter *adapter)
{ unsignedint i;
for (i = 0; i < adapter->max_vports; i++) { if (!adapter->vports[i]) return i;
}
idpf_send_disable_vport_msg(vport);
idpf_send_disable_queues_msg(vport);
idpf_send_map_unmap_queue_vector_msg(vport, false); /* Normally we ask for queues in create_vport, but if the number of * initially requested queues have changed, for example via ethtool * set channels, we do delete queues and then add the queues back * instead of deleting and reallocating the vport.
*/ if (test_and_clear_bit(IDPF_VPORT_DEL_QUEUES, vport->flags))
idpf_send_delete_queues_msg(vport);
/** * idpf_stop - Disables a network interface * @netdev: network interface device structure * * The stop entry point is called when an interface is de-activated by the OS, * and the netdevice enters the DOWN state. The hardware is still under the * driver's control, but the netdev interface is disabled. * * Returns success only - not allowed to fail
*/ staticint idpf_stop(struct net_device *netdev)
{ struct idpf_netdev_priv *np = netdev_priv(netdev); struct idpf_vport *vport;
if (test_bit(IDPF_REMOVE_IN_PROG, np->adapter->flags)) return 0;
/* Release all max queues allocated to the adapter's pool */
max_q.max_rxq = vport_config->max_q.max_rxq;
max_q.max_txq = vport_config->max_q.max_txq;
max_q.max_bufq = vport_config->max_q.max_bufq;
max_q.max_complq = vport_config->max_q.max_complq;
idpf_vport_dealloc_max_qs(adapter, &max_q);
/* Release all the allocated vectors on the stack */
vec_info.num_req_vecs = 0;
vec_info.num_curr_vecs = vport->num_q_vectors;
vec_info.default_vport = vport->default_vport;
if (!test_bit(IDPF_HR_RESET_IN_PROG, adapter->flags))
idpf_decfg_netdev(vport); if (test_bit(IDPF_REMOVE_IN_PROG, adapter->flags))
idpf_del_all_mac_filters(vport);
if (adapter->netdevs[i]) { struct idpf_netdev_priv *np = netdev_priv(adapter->netdevs[i]);
/** * idpf_is_hsplit_supported - check whether the header split is supported * @vport: virtual port to check the capability for * * Return: true if it's supported by the HW/FW, false if not.
*/ staticbool idpf_is_hsplit_supported(conststruct idpf_vport *vport)
{ return idpf_is_queue_model_split(vport->rxq_model) &&
idpf_is_cap_ena_all(vport->adapter, IDPF_HSPLIT_CAPS,
IDPF_CAP_HSPLIT);
}
/** * idpf_vport_get_hsplit - get the current header split feature state * @vport: virtual port to query the state for * * Return: ``ETHTOOL_TCP_DATA_SPLIT_UNKNOWN`` if not supported, * ``ETHTOOL_TCP_DATA_SPLIT_DISABLED`` if disabled, * ``ETHTOOL_TCP_DATA_SPLIT_ENABLED`` if active.
*/
u8 idpf_vport_get_hsplit(conststruct idpf_vport *vport)
{ conststruct idpf_vport_user_config_data *config;
if (!idpf_is_hsplit_supported(vport)) return ETHTOOL_TCP_DATA_SPLIT_UNKNOWN;
/** * idpf_vport_set_hsplit - enable or disable header split on a given vport * @vport: virtual port to configure * @val: Ethtool flag controlling the header split state * * Return: true on success, false if not supported by the HW.
*/ bool idpf_vport_set_hsplit(conststruct idpf_vport *vport, u8 val)
{ struct idpf_vport_user_config_data *config;
if (!idpf_is_hsplit_supported(vport)) return val == ETHTOOL_TCP_DATA_SPLIT_UNKNOWN;
switch (val) { case ETHTOOL_TCP_DATA_SPLIT_UNKNOWN: /* Default is to enable */ case ETHTOOL_TCP_DATA_SPLIT_ENABLED:
__set_bit(__IDPF_USER_FLAG_HSPLIT, config->user_flags); returntrue; case ETHTOOL_TCP_DATA_SPLIT_DISABLED:
__clear_bit(__IDPF_USER_FLAG_HSPLIT, config->user_flags); returntrue; default: returnfalse;
}
}
/** * idpf_vport_alloc - Allocates the next available struct vport in the adapter * @adapter: board private structure * @max_q: vport max queue info * * returns a pointer to a vport on success, NULL on failure.
*/ staticstruct idpf_vport *idpf_vport_alloc(struct idpf_adapter *adapter, struct idpf_vport_max_q *max_q)
{ struct idpf_rss_data *rss_data;
u16 idx = adapter->next_vport; struct idpf_vport *vport;
u16 num_max_q;
if (idx == IDPF_NO_FREE_SLOT) return NULL;
vport = kzalloc(sizeof(*vport), GFP_KERNEL); if (!vport) return vport;
vport->q_vector_idxs = kcalloc(num_max_q, sizeof(u16), GFP_KERNEL); if (!vport->q_vector_idxs) goto free_vport;
idpf_vport_init(vport, max_q);
/* This alloc is done separate from the LUT because it's not strictly * dependent on how many queues we have. If we change number of queues * and soft reset we'll need a new LUT but the key can remain the same * for as long as the vport exists.
*/
rss_data = &adapter->vport_config[idx]->user_config.rss_data;
rss_data->rss_key = kzalloc(rss_data->rss_key_size, GFP_KERNEL); if (!rss_data->rss_key) goto free_vector_idxs;
/** * idpf_statistics_task - Delayed task to get statistics over mailbox * @work: work_struct handle to our data
*/ void idpf_statistics_task(struct work_struct *work)
{ struct idpf_adapter *adapter; int i;
if (idpf_is_cap_ena(adapter, IDPF_OTHER_CAPS, VIRTCHNL2_CAP_MACFILTER))
idpf_restore_mac_filters(vport);
}
/** * idpf_set_real_num_queues - set number of queues for netdev * @vport: virtual port structure * * Returns 0 on success, negative on failure.
*/ staticint idpf_set_real_num_queues(struct idpf_vport *vport)
{ int err;
err = netif_set_real_num_rx_queues(vport->netdev, vport->num_rxq); if (err) return err;
/** * idpf_up_complete - Complete interface up sequence * @vport: virtual port structure * * Returns 0 on success, negative on failure.
*/ staticint idpf_up_complete(struct idpf_vport *vport)
{ struct idpf_netdev_priv *np = netdev_priv(vport->netdev);
if (vport->link_up && !netif_carrier_ok(vport->netdev)) {
netif_carrier_on(vport->netdev);
netif_tx_start_all_queues(vport->netdev);
}
np->state = __IDPF_VPORT_UP;
return 0;
}
/** * idpf_rx_init_buf_tail - Write initial buffer ring tail value * @vport: virtual port struct
*/ staticvoid idpf_rx_init_buf_tail(struct idpf_vport *vport)
{ int i, j;
for (i = 0; i < vport->num_rxq_grp; i++) { struct idpf_rxq_group *grp = &vport->rxq_grps[i];
if (idpf_is_queue_model_split(vport->rxq_model)) { for (j = 0; j < vport->num_bufqs_per_qgrp; j++) { conststruct idpf_buf_queue *q =
&grp->splitq.bufq_sets[j].bufq;
/** * idpf_init_task - Delayed initialization task * @work: work_struct handle to our data * * Init task finishes up pending work started in probe. Due to the asynchronous * nature in which the device communicates with hardware, we may have to wait * several milliseconds to get a response. Instead of busy polling in probe, * pulling it out into a delayed work task prevents us from bogging down the * whole system waiting for a response from hardware.
*/ void idpf_init_task(struct work_struct *work)
{ struct idpf_vport_config *vport_config; struct idpf_vport_max_q max_q; struct idpf_adapter *adapter; struct idpf_netdev_priv *np; struct idpf_vport *vport;
u16 num_default_vports; struct pci_dev *pdev; bool default_vport; int index, err;
err = idpf_check_supported_desc_ids(vport); if (err) {
dev_err(&pdev->dev, "failed to get required descriptor ids\n"); goto cfg_netdev_err;
}
if (idpf_cfg_netdev(vport)) goto cfg_netdev_err;
err = idpf_send_get_rx_ptype_msg(vport); if (err) goto handle_err;
/* Once state is put into DOWN, driver is ready for dev_open */
np = netdev_priv(vport->netdev);
np->state = __IDPF_VPORT_DOWN; if (test_and_clear_bit(IDPF_VPORT_UP_REQUESTED, vport_config->flags))
idpf_vport_open(vport, true);
/* Spawn and return 'idpf_init_task' work queue until all the * default vports are created
*/ if (adapter->num_alloc_vports < num_default_vports) {
queue_delayed_work(adapter->init_wq, &adapter->init_task,
msecs_to_jiffies(5 * (adapter->pdev->devfn & 0x07)));
return;
}
for (index = 0; index < adapter->max_vports; index++) { struct net_device *netdev = adapter->netdevs[index]; struct idpf_vport_config *vport_config;
vport_config = adapter->vport_config[index];
if (!netdev ||
test_bit(IDPF_VPORT_REG_NETDEV, vport_config->flags)) continue;
err = register_netdev(netdev); if (err) {
dev_err(&pdev->dev, "failed to register netdev for vport %d: %pe\n",
index, ERR_PTR(err)); continue;
}
set_bit(IDPF_VPORT_REG_NETDEV, vport_config->flags);
}
/* As all the required vports are created, clear the reset flag * unconditionally here in case we were in reset and the link was down.
*/
clear_bit(IDPF_HR_RESET_IN_PROG, adapter->flags); /* Start the statistics task now */
queue_delayed_work(adapter->stats_wq, &adapter->stats_task,
msecs_to_jiffies(10 * (pdev->devfn & 0x07)));
return;
handle_err:
idpf_decfg_netdev(vport);
cfg_netdev_err:
idpf_vport_rel(vport);
adapter->vports[index] = NULL;
unwind_vports: if (default_vport) { for (index = 0; index < adapter->max_vports; index++) { if (adapter->vports[index])
idpf_vport_dealloc(adapter->vports[index]);
}
}
clear_bit(IDPF_HR_RESET_IN_PROG, adapter->flags);
}
/** * idpf_sriov_ena - Enable or change number of VFs * @adapter: private data struct * @num_vfs: number of VFs to allocate
*/ staticint idpf_sriov_ena(struct idpf_adapter *adapter, int num_vfs)
{ struct device *dev = &adapter->pdev->dev; int err;
err = idpf_send_set_sriov_vfs_msg(adapter, num_vfs); if (err) {
dev_err(dev, "Failed to allocate VFs: %d\n", err);
return err;
}
err = pci_enable_sriov(adapter->pdev, num_vfs); if (err) {
idpf_send_set_sriov_vfs_msg(adapter, 0);
dev_err(dev, "Failed to enable SR-IOV: %d\n", err);
return err;
}
adapter->num_vfs = num_vfs;
return num_vfs;
}
/** * idpf_sriov_configure - Configure the requested VFs * @pdev: pointer to a pci_dev structure * @num_vfs: number of vfs to allocate * * Enable or change the number of VFs. Called when the user updates the number * of VFs in sysfs.
**/ int idpf_sriov_configure(struct pci_dev *pdev, int num_vfs)
{ struct idpf_adapter *adapter = pci_get_drvdata(pdev);
if (!idpf_is_cap_ena(adapter, IDPF_OTHER_CAPS, VIRTCHNL2_CAP_SRIOV)) {
dev_info(&pdev->dev, "SR-IOV is not supported on this device\n");
return -EOPNOTSUPP;
}
if (num_vfs) return idpf_sriov_ena(adapter, num_vfs);
if (pci_vfs_assigned(pdev)) {
dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs\n");
/** * idpf_deinit_task - Device deinit routine * @adapter: Driver specific private structure * * Extended remove logic which will be used for * hard reset as well
*/ void idpf_deinit_task(struct idpf_adapter *adapter)
{ unsignedint i;
/* Wait until the init_task is done else this thread might release * the resources first and the other thread might end up in a bad state
*/
cancel_delayed_work_sync(&adapter->init_task);
if (!adapter->vports) return;
cancel_delayed_work_sync(&adapter->stats_task);
for (i = 0; i < adapter->max_vports; i++) { if (adapter->vports[i])
idpf_vport_dealloc(adapter->vports[i]);
}
}
/** * idpf_check_reset_complete - check that reset is complete * @hw: pointer to hw struct * @reset_reg: struct with reset registers * * Returns 0 if device is ready to use, or -EBUSY if it's in reset.
**/ staticint idpf_check_reset_complete(struct idpf_hw *hw, struct idpf_reset_reg *reset_reg)
{ struct idpf_adapter *adapter = hw->back; int i;
for (i = 0; i < 2000; i++) {
u32 reg_val = readl(reset_reg->rstat);
/* 0xFFFFFFFF might be read if other side hasn't cleared the * register for us yet and 0xFFFFFFFF is not a valid value for * the register, so treat that as invalid.
*/ if (reg_val != 0xFFFFFFFF && (reg_val & reset_reg->rstat_m)) return 0;
usleep_range(5000, 10000);
}
dev_warn(&adapter->pdev->dev, "Device reset timeout!\n"); /* Clear the reset flag unconditionally here since the reset * technically isn't in progress anymore from the driver's perspective
*/
clear_bit(IDPF_HR_RESET_IN_PROG, adapter->flags);
return -EBUSY;
}
/** * idpf_set_vport_state - Set the vport state to be after the reset * @adapter: Driver specific private structure
*/ staticvoid idpf_set_vport_state(struct idpf_adapter *adapter)
{
u16 i;
for (i = 0; i < adapter->max_vports; i++) { struct idpf_netdev_priv *np;
/** * idpf_init_hard_reset - Initiate a hardware reset * @adapter: Driver specific private structure * * Deallocate the vports and all the resources associated with them and * reallocate. Also reinitialize the mailbox. Return 0 on success, * negative on failure.
*/ staticint idpf_init_hard_reset(struct idpf_adapter *adapter)
{ struct idpf_reg_ops *reg_ops = &adapter->dev_ops.reg_ops; struct device *dev = &adapter->pdev->dev; struct net_device *netdev; int err;
u16 i;
mutex_lock(&adapter->vport_ctrl_lock);
dev_info(dev, "Device HW Reset initiated\n");
/* Avoid TX hangs on reset */ for (i = 0; i < adapter->max_vports; i++) {
netdev = adapter->netdevs[i]; if (!netdev) continue;
/* Wait for reset to complete */
err = idpf_check_reset_complete(&adapter->hw, &adapter->reset_reg); if (err) {
dev_err(dev, "The driver was unable to contact the device's firmware. Check that the FW is running. Driver state= 0x%x\n",
adapter->state); goto unlock_mutex;
}
/* Reset is complete and so start building the driver resources again */
err = idpf_init_dflt_mbx(adapter); if (err) {
dev_err(dev, "Failed to initialize default mailbox: %d\n", err); goto unlock_mutex;
}
/* Initialize the state machine, also allocate memory and request * resources
*/
err = idpf_vc_core_init(adapter); if (err) {
cancel_delayed_work_sync(&adapter->mbx_task);
idpf_deinit_dflt_mbx(adapter); goto unlock_mutex;
}
/* Wait till all the vports are initialized to release the reset lock, * else user space callbacks may access uninitialized vports
*/ while (test_bit(IDPF_HR_RESET_IN_PROG, adapter->flags))
msleep(100);
/** * idpf_initiate_soft_reset - Initiate a software reset * @vport: virtual port data struct * @reset_cause: reason for the soft reset * * Soft reset only reallocs vport queue resources. Returns 0 on success, * negative on failure.
*/ int idpf_initiate_soft_reset(struct idpf_vport *vport, enum idpf_vport_reset_cause reset_cause)
{ struct idpf_netdev_priv *np = netdev_priv(vport->netdev); enum idpf_vport_state current_state = np->state; struct idpf_adapter *adapter = vport->adapter; struct idpf_vport *new_vport; int err;
/* If the system is low on memory, we can end up in bad state if we * free all the memory for queue resources and try to allocate them * again. Instead, we can pre-allocate the new resources before doing * anything and bailing if the alloc fails. * * Make a clone of the existing vport to mimic its current * configuration, then modify the new structure with any requested * changes. Once the allocation of the new resources is done, stop the * existing vport and copy the configuration to the main vport. If an * error occurred, the existing vport will be untouched. *
*/
new_vport = kzalloc(sizeof(*vport), GFP_KERNEL); if (!new_vport) return -ENOMEM;
/* This purposely avoids copying the end of the struct because it * contains wait_queues and mutexes and other stuff we don't want to * mess with. Nothing below should use those variables from new_vport * and should instead always refer to them in vport if they need to.
*/
memcpy(new_vport, vport, offsetof(struct idpf_vport, link_up));
/* Adjust resource parameters prior to reallocating resources */ switch (reset_cause) { case IDPF_SR_Q_CHANGE:
err = idpf_vport_adjust_qs(new_vport); if (err) goto free_vport; break; case IDPF_SR_Q_DESC_CHANGE: /* Update queue parameters before allocating resources */
idpf_vport_calc_num_q_desc(new_vport); break; case IDPF_SR_MTU_CHANGE:
idpf_idc_vdev_mtu_event(vport->vdev_info,
IIDC_RDMA_EVENT_BEFORE_MTU_CHANGE); break; case IDPF_SR_RSC_CHANGE: break; default:
dev_err(&adapter->pdev->dev, "Unhandled soft reset cause\n");
err = -EINVAL; goto free_vport;
}
idpf_deinit_rss(vport); /* We're passing in vport here because we need its wait_queue * to send a message and it should be getting all the vport * config data out of the adapter but we need to be careful not * to add code to add_queues to change the vport config within * vport itself as it will be wiped with a memcpy later.
*/
err = idpf_send_add_queues_msg(vport, new_vport->num_txq,
new_vport->num_complq,
new_vport->num_rxq,
new_vport->num_bufq); if (err) goto err_reset;
/* Same comment as above regarding avoiding copying the wait_queues and * mutexes applies here. We do not want to mess with those if possible.
*/
memcpy(vport, new_vport, offsetof(struct idpf_vport, link_up));
if (reset_cause == IDPF_SR_Q_CHANGE)
idpf_vport_alloc_vec_indexes(vport);
err = idpf_set_real_num_queues(vport); if (err) goto err_open;
if (current_state == __IDPF_VPORT_UP)
err = idpf_vport_open(vport, false);
err_open: if (current_state == __IDPF_VPORT_UP)
idpf_vport_open(vport, false);
free_vport:
kfree(new_vport);
if (reset_cause == IDPF_SR_MTU_CHANGE)
idpf_idc_vdev_mtu_event(vport->vdev_info,
IIDC_RDMA_EVENT_AFTER_MTU_CHANGE);
return err;
}
/** * idpf_addr_sync - Callback for dev_(mc|uc)_sync to add address * @netdev: the netdevice * @addr: address to add * * Called by __dev_(mc|uc)_sync when an address needs to be added. We call * __dev_(uc|mc)_sync from .set_rx_mode. Kernel takes addr_list_lock spinlock * meaning we cannot sleep in this context. Due to this, we have to add the * filter and send the virtchnl message asynchronously without waiting for the * response from the other side. We won't know whether or not the operation * actually succeeded until we get the message back. Returns 0 on success, * negative on failure.
*/ staticint idpf_addr_sync(struct net_device *netdev, const u8 *addr)
{ struct idpf_netdev_priv *np = netdev_priv(netdev);
/** * idpf_addr_unsync - Callback for dev_(mc|uc)_sync to remove address * @netdev: the netdevice * @addr: address to add * * Called by __dev_(mc|uc)_sync when an address needs to be added. We call * __dev_(uc|mc)_sync from .set_rx_mode. Kernel takes addr_list_lock spinlock * meaning we cannot sleep in this context. Due to this we have to delete the * filter and send the virtchnl message asynchronously without waiting for the * return from the other side. We won't know whether or not the operation * actually succeeded until we get the message back. Returns 0 on success, * negative on failure.
*/ staticint idpf_addr_unsync(struct net_device *netdev, const u8 *addr)
{ struct idpf_netdev_priv *np = netdev_priv(netdev);
/* Under some circumstances, we might receive a request to delete * our own device address from our uc list. Because we store the * device address in the VSI's MAC filter list, we need to ignore * such requests and not delete our device address from this list.
*/ if (ether_addr_equal(addr, netdev->dev_addr)) return 0;
idpf_del_mac_filter(np->vport, np, addr, true);
return 0;
}
/** * idpf_set_rx_mode - NDO callback to set the netdev filters * @netdev: network interface device structure * * Stack takes addr_list_lock spinlock before calling our .set_rx_mode. We * cannot sleep in this context.
*/ staticvoid idpf_set_rx_mode(struct net_device *netdev)
{ struct idpf_netdev_priv *np = netdev_priv(netdev); struct idpf_vport_user_config_data *config_data; struct idpf_adapter *adapter; bool changed = false; struct device *dev; int err;
err = idpf_set_promiscuous(adapter, config_data, np->vport_id); if (err)
dev_err(dev, "Failed to set promiscuous mode: %d\n", err);
}
/** * idpf_vport_manage_rss_lut - disable/enable RSS * @vport: the vport being changed * * In the event of disable request for RSS, this function will zero out RSS * LUT, while in the event of enable request for RSS, it will reconfigure RSS * LUT with the default LUT configuration.
*/ staticint idpf_vport_manage_rss_lut(struct idpf_vport *vport)
{ bool ena = idpf_is_feature_ena(vport, NETIF_F_RXHASH); struct idpf_rss_data *rss_data;
u16 idx = vport->idx; int lut_size;
if (ena) { /* This will contain the default or user configured LUT */
memcpy(rss_data->rss_lut, rss_data->cached_lut, lut_size);
} else { /* Save a copy of the current LUT to be restored later if * requested.
*/
memcpy(rss_data->cached_lut, rss_data->rss_lut, lut_size);
/* Zero out the current LUT to disable */
memset(rss_data->rss_lut, 0, lut_size);
}
return idpf_config_rss(vport);
}
/** * idpf_set_features - set the netdev feature flags * @netdev: ptr to the netdev being adjusted * @features: the feature set that the stack is suggesting
*/ staticint idpf_set_features(struct net_device *netdev,
netdev_features_t features)
{
netdev_features_t changed = netdev->features ^ features; struct idpf_adapter *adapter; struct idpf_vport *vport; int err = 0;
/** * idpf_open - Called when a network interface becomes active * @netdev: network interface device structure * * The open entry point is called when a network interface is made * active by the system (IFF_UP). At this point all resources needed * for transmit and receive operations are allocated, the interrupt * handler is registered with the OS, the netdev watchdog is enabled, * and the stack is notified that the interface is ready. * * Returns 0 on success, negative value on failure
*/ staticint idpf_open(struct net_device *netdev)
{ struct idpf_vport *vport; int err;
err = idpf_set_real_num_queues(vport); if (err) goto unlock;
err = idpf_vport_open(vport, false);
unlock:
idpf_vport_ctrl_unlock(netdev);
return err;
}
/** * idpf_change_mtu - NDO callback to change the MTU * @netdev: network interface device structure * @new_mtu: new value for maximum frame size * * Returns 0 on success, negative on failure
*/ staticint idpf_change_mtu(struct net_device *netdev, int new_mtu)
{ struct idpf_vport *vport; int err;
/** * idpf_chk_tso_segment - Check skb is not using too many buffers * @skb: send buffer * @max_bufs: maximum number of buffers * * For TSO we need to count the TSO header and segment payload separately. As * such we need to check cases where we have max_bufs-1 fragments or more as we * can potentially require max_bufs+1 DMA transactions, 1 for the TSO header, 1 * for the segment payload in the first descriptor, and another max_buf-1 for * the fragments. * * Returns true if the packet needs to be software segmented by core stack.
*/ staticbool idpf_chk_tso_segment(conststruct sk_buff *skb, unsignedint max_bufs)
{ conststruct skb_shared_info *shinfo = skb_shinfo(skb); const skb_frag_t *frag, *stale; int nr_frags, sum;
/* no need to check if number of frags is less than max_bufs - 1 */
nr_frags = shinfo->nr_frags; if (nr_frags < (max_bufs - 1)) returnfalse;
/* We need to walk through the list and validate that each group * of max_bufs-2 fragments totals at least gso_size.
*/
nr_frags -= max_bufs - 2;
frag = &shinfo->frags[0];
/* Initialize size to the negative value of gso_size minus 1. We use * this as the worst case scenario in which the frag ahead of us only * provides one byte which is why we are limited to max_bufs-2 * descriptors for a single transmit as the header and previous * fragment are already consuming 2 descriptors.
*/
sum = 1 - shinfo->gso_size;
/* Add size of frags 0 through 4 to create our initial sum */
sum += skb_frag_size(frag++);
sum += skb_frag_size(frag++);
sum += skb_frag_size(frag++);
sum += skb_frag_size(frag++);
sum += skb_frag_size(frag++);
/* Walk through fragments adding latest fragment, testing it, and * then removing stale fragments from the sum.
*/ for (stale = &shinfo->frags[0];; stale++) { int stale_size = skb_frag_size(stale);
sum += skb_frag_size(frag++);
/* The stale fragment may present us with a smaller * descriptor than the actual fragment size. To account * for that we need to remove all the data on the front and * figure out what the remainder would be in the last * descriptor associated with the fragment.
*/ if (stale_size > IDPF_TX_MAX_DESC_DATA) { int align_pad = -(skb_frag_off(stale)) &
(IDPF_TX_MAX_READ_REQ_SIZE - 1);
sum -= align_pad;
stale_size -= align_pad;
do {
sum -= IDPF_TX_MAX_DESC_DATA_ALIGNED;
stale_size -= IDPF_TX_MAX_DESC_DATA_ALIGNED;
} while (stale_size > IDPF_TX_MAX_DESC_DATA);
}
/* if sum is negative we failed to make sufficient progress */ if (sum < 0) returntrue;
if (!nr_frags--) break;
sum -= stale_size;
}
returnfalse;
}
/** * idpf_features_check - Validate packet conforms to limits * @skb: skb buffer * @netdev: This port's netdev * @features: Offload features that the stack believes apply
*/ static netdev_features_t idpf_features_check(struct sk_buff *skb, struct net_device *netdev,
--> --------------------
--> maximum size reached
--> --------------------
Messung V0.5
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet)
¤
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.