2021-08-19 17:08:50 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/* Copyright (C) 2019-2021, Intel Corporation. */
|
|
|
|
|
|
|
|
#include "ice.h"
|
|
|
|
#include "ice_eswitch.h"
|
|
|
|
#include "ice_devlink.h"
|
2022-02-22 16:26:49 -08:00
|
|
|
#include "ice_sriov.h"
|
2021-08-06 10:49:06 +02:00
|
|
|
#include "ice_tc_lib.h"
|
2022-11-15 11:48:23 +01:00
|
|
|
#include "ice_dcb_lib.h"
|
2021-08-19 17:08:50 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ice_repr_get_sw_port_id - get port ID associated with representor
|
|
|
|
* @repr: pointer to port representor
|
|
|
|
*/
|
|
|
|
static int ice_repr_get_sw_port_id(struct ice_repr *repr)
|
|
|
|
{
|
|
|
|
return repr->vf->pf->hw.port_info->lport;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ice_repr_get_phys_port_name - get phys port name
|
|
|
|
* @netdev: pointer to port representor netdev
|
|
|
|
* @buf: write here port name
|
|
|
|
* @len: max length of buf
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ice_repr_get_phys_port_name(struct net_device *netdev, char *buf, size_t len)
|
|
|
|
{
|
|
|
|
struct ice_netdev_priv *np = netdev_priv(netdev);
|
|
|
|
struct ice_repr *repr = np->repr;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
/* Devlink port is registered and devlink core is taking care of name formatting. */
|
|
|
|
if (repr->vf->devlink_port.devlink)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
res = snprintf(buf, len, "pf%dvfr%d", ice_repr_get_sw_port_id(repr),
|
|
|
|
repr->vf->vf_id);
|
|
|
|
if (res <= 0)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-08-19 17:08:59 -07:00
|
|
|
/**
|
|
|
|
* ice_repr_get_stats64 - get VF stats for VFPR use
|
|
|
|
* @netdev: pointer to port representor netdev
|
|
|
|
* @stats: pointer to struct where stats can be stored
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ice_repr_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
|
|
|
|
{
|
|
|
|
struct ice_netdev_priv *np = netdev_priv(netdev);
|
|
|
|
struct ice_eth_stats *eth_stats;
|
|
|
|
struct ice_vsi *vsi;
|
|
|
|
|
|
|
|
if (ice_is_vf_disabled(np->repr->vf))
|
|
|
|
return;
|
|
|
|
vsi = np->repr->src_vsi;
|
|
|
|
|
|
|
|
ice_update_vsi_stats(vsi);
|
|
|
|
eth_stats = &vsi->eth_stats;
|
|
|
|
|
|
|
|
stats->tx_packets = eth_stats->tx_unicast + eth_stats->tx_broadcast +
|
|
|
|
eth_stats->tx_multicast;
|
|
|
|
stats->rx_packets = eth_stats->rx_unicast + eth_stats->rx_broadcast +
|
|
|
|
eth_stats->rx_multicast;
|
|
|
|
stats->tx_bytes = eth_stats->tx_bytes;
|
|
|
|
stats->rx_bytes = eth_stats->rx_bytes;
|
|
|
|
stats->multicast = eth_stats->rx_multicast;
|
|
|
|
stats->tx_errors = eth_stats->tx_errors;
|
|
|
|
stats->tx_dropped = eth_stats->tx_discards;
|
|
|
|
stats->rx_dropped = eth_stats->rx_discards;
|
|
|
|
}
|
|
|
|
|
2021-08-19 17:08:50 -07:00
|
|
|
/**
|
|
|
|
* ice_netdev_to_repr - Get port representor for given netdevice
|
|
|
|
* @netdev: pointer to port representor netdev
|
|
|
|
*/
|
|
|
|
struct ice_repr *ice_netdev_to_repr(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
struct ice_netdev_priv *np = netdev_priv(netdev);
|
|
|
|
|
|
|
|
return np->repr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ice_repr_open - Enable port representor's network interface
|
|
|
|
* @netdev: network interface device structure
|
|
|
|
*
|
|
|
|
* The open entry point is called when a port representor's network
|
|
|
|
* interface is made active by the system (IFF_UP). Corresponding
|
|
|
|
* VF is notified about link status change.
|
|
|
|
*
|
|
|
|
* Returns 0 on success
|
|
|
|
*/
|
|
|
|
static int ice_repr_open(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
struct ice_repr *repr = ice_netdev_to_repr(netdev);
|
|
|
|
struct ice_vf *vf;
|
|
|
|
|
|
|
|
vf = repr->vf;
|
|
|
|
vf->link_forced = true;
|
|
|
|
vf->link_up = true;
|
|
|
|
ice_vc_notify_vf_link_state(vf);
|
|
|
|
|
|
|
|
netif_carrier_on(netdev);
|
|
|
|
netif_tx_start_all_queues(netdev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ice_repr_stop - Disable port representor's network interface
|
|
|
|
* @netdev: network interface device structure
|
|
|
|
*
|
|
|
|
* The stop entry point is called when a port representor's network
|
|
|
|
* interface is de-activated by the system. Corresponding
|
|
|
|
* VF is notified about link status change.
|
|
|
|
*
|
|
|
|
* Returns 0 on success
|
|
|
|
*/
|
|
|
|
static int ice_repr_stop(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
struct ice_repr *repr = ice_netdev_to_repr(netdev);
|
|
|
|
struct ice_vf *vf;
|
|
|
|
|
|
|
|
vf = repr->vf;
|
|
|
|
vf->link_forced = true;
|
|
|
|
vf->link_up = false;
|
|
|
|
ice_vc_notify_vf_link_state(vf);
|
|
|
|
|
|
|
|
netif_carrier_off(netdev);
|
|
|
|
netif_tx_stop_all_queues(netdev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-01-27 16:04:26 +01:00
|
|
|
/**
|
|
|
|
* ice_repr_sp_stats64 - get slow path stats for port representor
|
|
|
|
* @dev: network interface device structure
|
|
|
|
* @stats: netlink stats structure
|
|
|
|
*
|
|
|
|
* RX/TX stats are being swapped here to be consistent with VF stats. In slow
|
|
|
|
* path, port representor receives data when the corresponding VF is sending it
|
|
|
|
* (and vice versa), TX and RX bytes/packets are effectively swapped on port
|
|
|
|
* representor.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ice_repr_sp_stats64(const struct net_device *dev,
|
|
|
|
struct rtnl_link_stats64 *stats)
|
|
|
|
{
|
|
|
|
struct ice_netdev_priv *np = netdev_priv(dev);
|
|
|
|
int vf_id = np->repr->vf->vf_id;
|
|
|
|
struct ice_tx_ring *tx_ring;
|
|
|
|
struct ice_rx_ring *rx_ring;
|
|
|
|
u64 pkts, bytes;
|
|
|
|
|
|
|
|
tx_ring = np->vsi->tx_rings[vf_id];
|
ice: Accumulate ring statistics over reset
Resets may occur with or without user interaction. For example, a TX hang
or reconfiguration of parameters will result in a reset. During reset, the
VSI is freed, freeing any statistics structures inside as well. This would
create an issue for the user where a reset happens in the background,
statistics set to zero, and the user checks ring statistics expecting them
to be populated.
To ensure this doesn't happen, accumulate ring statistics over reset.
Define a new ring statistics structure, ice_ring_stats. The new structure
lives in the VSI's parent, preserving ring statistics when VSI is freed.
1. Define a new structure vsi_ring_stats in the PF scope
2. Allocate/free stats only during probe, unload, or change in ring size
3. Replace previous ring statistics functionality with new structure
Signed-off-by: Benjamin Mikailenko <benjamin.mikailenko@intel.com>
Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
2022-11-18 16:20:02 -05:00
|
|
|
ice_fetch_u64_stats_per_ring(&tx_ring->ring_stats->syncp,
|
|
|
|
tx_ring->ring_stats->stats,
|
2022-01-27 16:04:26 +01:00
|
|
|
&pkts, &bytes);
|
|
|
|
stats->rx_packets = pkts;
|
|
|
|
stats->rx_bytes = bytes;
|
|
|
|
|
|
|
|
rx_ring = np->vsi->rx_rings[vf_id];
|
ice: Accumulate ring statistics over reset
Resets may occur with or without user interaction. For example, a TX hang
or reconfiguration of parameters will result in a reset. During reset, the
VSI is freed, freeing any statistics structures inside as well. This would
create an issue for the user where a reset happens in the background,
statistics set to zero, and the user checks ring statistics expecting them
to be populated.
To ensure this doesn't happen, accumulate ring statistics over reset.
Define a new ring statistics structure, ice_ring_stats. The new structure
lives in the VSI's parent, preserving ring statistics when VSI is freed.
1. Define a new structure vsi_ring_stats in the PF scope
2. Allocate/free stats only during probe, unload, or change in ring size
3. Replace previous ring statistics functionality with new structure
Signed-off-by: Benjamin Mikailenko <benjamin.mikailenko@intel.com>
Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
2022-11-18 16:20:02 -05:00
|
|
|
ice_fetch_u64_stats_per_ring(&rx_ring->ring_stats->syncp,
|
|
|
|
rx_ring->ring_stats->stats,
|
2022-01-27 16:04:26 +01:00
|
|
|
&pkts, &bytes);
|
|
|
|
stats->tx_packets = pkts;
|
|
|
|
stats->tx_bytes = bytes;
|
ice: Accumulate ring statistics over reset
Resets may occur with or without user interaction. For example, a TX hang
or reconfiguration of parameters will result in a reset. During reset, the
VSI is freed, freeing any statistics structures inside as well. This would
create an issue for the user where a reset happens in the background,
statistics set to zero, and the user checks ring statistics expecting them
to be populated.
To ensure this doesn't happen, accumulate ring statistics over reset.
Define a new ring statistics structure, ice_ring_stats. The new structure
lives in the VSI's parent, preserving ring statistics when VSI is freed.
1. Define a new structure vsi_ring_stats in the PF scope
2. Allocate/free stats only during probe, unload, or change in ring size
3. Replace previous ring statistics functionality with new structure
Signed-off-by: Benjamin Mikailenko <benjamin.mikailenko@intel.com>
Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
2022-11-18 16:20:02 -05:00
|
|
|
stats->tx_dropped = rx_ring->ring_stats->rx_stats.alloc_page_failed +
|
|
|
|
rx_ring->ring_stats->rx_stats.alloc_buf_failed;
|
2022-01-27 16:04:26 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
ice_repr_ndo_has_offload_stats(const struct net_device *dev, int attr_id)
|
|
|
|
{
|
|
|
|
return attr_id == IFLA_OFFLOAD_XSTATS_CPU_HIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ice_repr_ndo_get_offload_stats(int attr_id, const struct net_device *dev,
|
|
|
|
void *sp)
|
|
|
|
{
|
|
|
|
if (attr_id == IFLA_OFFLOAD_XSTATS_CPU_HIT)
|
|
|
|
return ice_repr_sp_stats64(dev, (struct rtnl_link_stats64 *)sp);
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-08-06 10:49:06 +02:00
|
|
|
static int
|
|
|
|
ice_repr_setup_tc_cls_flower(struct ice_repr *repr,
|
|
|
|
struct flow_cls_offload *flower)
|
|
|
|
{
|
|
|
|
switch (flower->command) {
|
|
|
|
case FLOW_CLS_REPLACE:
|
|
|
|
return ice_add_cls_flower(repr->netdev, repr->src_vsi, flower);
|
|
|
|
case FLOW_CLS_DESTROY:
|
|
|
|
return ice_del_cls_flower(repr->src_vsi, flower);
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ice_repr_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
|
|
|
|
void *cb_priv)
|
|
|
|
{
|
|
|
|
struct flow_cls_offload *flower = (struct flow_cls_offload *)type_data;
|
|
|
|
struct ice_netdev_priv *np = (struct ice_netdev_priv *)cb_priv;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case TC_SETUP_CLSFLOWER:
|
|
|
|
return ice_repr_setup_tc_cls_flower(np->repr, flower);
|
|
|
|
default:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static LIST_HEAD(ice_repr_block_cb_list);
|
|
|
|
|
|
|
|
static int
|
|
|
|
ice_repr_setup_tc(struct net_device *netdev, enum tc_setup_type type,
|
|
|
|
void *type_data)
|
|
|
|
{
|
|
|
|
struct ice_netdev_priv *np = netdev_priv(netdev);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case TC_SETUP_BLOCK:
|
|
|
|
return flow_block_cb_setup_simple((struct flow_block_offload *)
|
|
|
|
type_data,
|
|
|
|
&ice_repr_block_cb_list,
|
|
|
|
ice_repr_setup_tc_block_cb,
|
|
|
|
np, np, true);
|
|
|
|
default:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-19 17:08:50 -07:00
|
|
|
static const struct net_device_ops ice_repr_netdev_ops = {
|
|
|
|
.ndo_get_phys_port_name = ice_repr_get_phys_port_name,
|
2021-08-19 17:08:59 -07:00
|
|
|
.ndo_get_stats64 = ice_repr_get_stats64,
|
2021-08-19 17:08:50 -07:00
|
|
|
.ndo_open = ice_repr_open,
|
|
|
|
.ndo_stop = ice_repr_stop,
|
2021-08-19 17:08:58 -07:00
|
|
|
.ndo_start_xmit = ice_eswitch_port_start_xmit,
|
2021-08-06 10:49:06 +02:00
|
|
|
.ndo_setup_tc = ice_repr_setup_tc,
|
2022-01-27 16:04:26 +01:00
|
|
|
.ndo_has_offload_stats = ice_repr_ndo_has_offload_stats,
|
|
|
|
.ndo_get_offload_stats = ice_repr_ndo_get_offload_stats,
|
2021-08-19 17:08:50 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ice_is_port_repr_netdev - Check if a given netdevice is a port representor netdev
|
|
|
|
* @netdev: pointer to netdev
|
|
|
|
*/
|
2023-07-12 13:03:31 +02:00
|
|
|
bool ice_is_port_repr_netdev(const struct net_device *netdev)
|
2021-08-19 17:08:50 -07:00
|
|
|
{
|
|
|
|
return netdev && (netdev->netdev_ops == &ice_repr_netdev_ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ice_repr_reg_netdev - register port representor netdev
|
|
|
|
* @netdev: pointer to port representor netdev
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ice_repr_reg_netdev(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
eth_hw_addr_random(netdev);
|
|
|
|
netdev->netdev_ops = &ice_repr_netdev_ops;
|
2021-08-19 17:08:59 -07:00
|
|
|
ice_set_ethtool_repr_ops(netdev);
|
2021-08-19 17:08:50 -07:00
|
|
|
|
2021-08-06 10:49:06 +02:00
|
|
|
netdev->hw_features |= NETIF_F_HW_TC;
|
|
|
|
|
2021-08-19 17:08:50 -07:00
|
|
|
netif_carrier_off(netdev);
|
|
|
|
netif_tx_stop_all_queues(netdev);
|
|
|
|
|
|
|
|
return register_netdev(netdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ice_repr_add - add representor for VF
|
|
|
|
* @vf: pointer to VF structure
|
|
|
|
*/
|
|
|
|
static int ice_repr_add(struct ice_vf *vf)
|
|
|
|
{
|
|
|
|
struct ice_q_vector *q_vector;
|
|
|
|
struct ice_netdev_priv *np;
|
|
|
|
struct ice_repr *repr;
|
2022-04-11 16:29:03 -07:00
|
|
|
struct ice_vsi *vsi;
|
2021-08-19 17:08:50 -07:00
|
|
|
int err;
|
|
|
|
|
2022-04-11 16:29:03 -07:00
|
|
|
vsi = ice_get_vf_vsi(vf);
|
|
|
|
if (!vsi)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2021-08-19 17:08:50 -07:00
|
|
|
repr = kzalloc(sizeof(*repr), GFP_KERNEL);
|
|
|
|
if (!repr)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
repr->netdev = alloc_etherdev(sizeof(struct ice_netdev_priv));
|
|
|
|
if (!repr->netdev) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto err_alloc;
|
|
|
|
}
|
|
|
|
|
2022-04-11 16:29:03 -07:00
|
|
|
repr->src_vsi = vsi;
|
2021-08-19 17:08:50 -07:00
|
|
|
repr->vf = vf;
|
2023-10-24 13:09:18 +02:00
|
|
|
repr->q_id = vf->vf_id;
|
2021-08-19 17:08:50 -07:00
|
|
|
vf->repr = repr;
|
|
|
|
np = netdev_priv(repr->netdev);
|
|
|
|
np->repr = repr;
|
|
|
|
|
|
|
|
q_vector = kzalloc(sizeof(*q_vector), GFP_KERNEL);
|
|
|
|
if (!q_vector) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto err_alloc_q_vector;
|
|
|
|
}
|
|
|
|
repr->q_vector = q_vector;
|
|
|
|
|
2023-10-24 13:09:20 +02:00
|
|
|
err = xa_alloc(&vf->pf->eswitch.reprs, &repr->id, repr,
|
|
|
|
xa_limit_32b, GFP_KERNEL);
|
|
|
|
if (err)
|
|
|
|
goto err_xa_alloc;
|
|
|
|
|
2021-08-19 17:08:50 -07:00
|
|
|
err = ice_devlink_create_vf_port(vf);
|
|
|
|
if (err)
|
|
|
|
goto err_devlink;
|
|
|
|
|
2021-10-18 13:30:32 +02:00
|
|
|
repr->netdev->min_mtu = ETH_MIN_MTU;
|
|
|
|
repr->netdev->max_mtu = ICE_MAX_MTU;
|
|
|
|
|
2022-03-28 16:58:27 +02:00
|
|
|
SET_NETDEV_DEV(repr->netdev, ice_pf_to_dev(vf->pf));
|
2022-11-02 17:02:04 +01:00
|
|
|
SET_NETDEV_DEVLINK_PORT(repr->netdev, &vf->devlink_port);
|
2021-08-19 17:08:50 -07:00
|
|
|
err = ice_repr_reg_netdev(repr->netdev);
|
|
|
|
if (err)
|
|
|
|
goto err_netdev;
|
|
|
|
|
2023-10-24 13:09:21 +02:00
|
|
|
ether_addr_copy(repr->parent_mac, vf->hw_lan_addr);
|
2022-02-22 16:26:51 -08:00
|
|
|
ice_virtchnl_set_repr_ops(vf);
|
2022-02-16 13:37:28 -08:00
|
|
|
|
2021-08-19 17:08:50 -07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_netdev:
|
|
|
|
ice_devlink_destroy_vf_port(vf);
|
|
|
|
err_devlink:
|
2023-10-24 13:09:20 +02:00
|
|
|
xa_erase(&vf->pf->eswitch.reprs, repr->id);
|
|
|
|
err_xa_alloc:
|
2021-08-19 17:08:50 -07:00
|
|
|
kfree(repr->q_vector);
|
|
|
|
vf->repr->q_vector = NULL;
|
|
|
|
err_alloc_q_vector:
|
|
|
|
free_netdev(repr->netdev);
|
|
|
|
repr->netdev = NULL;
|
|
|
|
err_alloc:
|
|
|
|
kfree(repr);
|
|
|
|
vf->repr = NULL;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ice_repr_rem - remove representor from VF
|
|
|
|
* @vf: pointer to VF structure
|
|
|
|
*/
|
|
|
|
static void ice_repr_rem(struct ice_vf *vf)
|
|
|
|
{
|
2023-10-24 13:09:19 +02:00
|
|
|
struct ice_repr *repr = vf->repr;
|
|
|
|
|
|
|
|
if (!repr)
|
2022-02-16 13:37:28 -08:00
|
|
|
return;
|
|
|
|
|
2023-10-24 13:09:19 +02:00
|
|
|
kfree(repr->q_vector);
|
|
|
|
unregister_netdev(repr->netdev);
|
2022-09-26 13:09:37 +02:00
|
|
|
ice_devlink_destroy_vf_port(vf);
|
2023-10-24 13:09:20 +02:00
|
|
|
xa_erase(&vf->pf->eswitch.reprs, repr->id);
|
2023-10-24 13:09:19 +02:00
|
|
|
free_netdev(repr->netdev);
|
|
|
|
kfree(repr);
|
2021-08-19 17:08:50 -07:00
|
|
|
vf->repr = NULL;
|
2022-02-16 13:37:28 -08:00
|
|
|
|
2022-02-22 16:26:51 -08:00
|
|
|
ice_virtchnl_set_dflt_ops(vf);
|
2021-08-19 17:08:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-02-16 13:37:28 -08:00
|
|
|
* ice_repr_rem_from_all_vfs - remove port representor for all VFs
|
2021-08-19 17:08:50 -07:00
|
|
|
* @pf: pointer to PF structure
|
|
|
|
*/
|
2022-02-16 13:37:28 -08:00
|
|
|
void ice_repr_rem_from_all_vfs(struct ice_pf *pf)
|
2021-08-19 17:08:50 -07:00
|
|
|
{
|
2022-11-15 11:48:22 +01:00
|
|
|
struct devlink *devlink;
|
2022-02-16 13:37:35 -08:00
|
|
|
struct ice_vf *vf;
|
|
|
|
unsigned int bkt;
|
2021-08-19 17:08:51 -07:00
|
|
|
|
ice: convert VF storage to hash table with krefs and RCU
The ice driver stores VF structures in a simple array which is allocated
once at the time of VF creation. The VF structures are then accessed
from the array by their VF ID. The ID must be between 0 and the number
of allocated VFs.
Multiple threads can access this table:
* .ndo operations such as .ndo_get_vf_cfg or .ndo_set_vf_trust
* interrupts, such as due to messages from the VF using the virtchnl
communication
* processing such as device reset
* commands to add or remove VFs
The current implementation does not keep track of when all threads are
done operating on a VF and can potentially result in use-after-free
issues caused by one thread accessing a VF structure after it has been
released when removing VFs. Some of these are prevented with various
state flags and checks.
In addition, this structure is quite static and does not support a
planned future where virtualization can be more dynamic. As we begin to
look at supporting Scalable IOV with the ice driver (as opposed to just
supporting Single Root IOV), this structure is not sufficient.
In the future, VFs will be able to be added and removed individually and
dynamically.
To allow for this, and to better protect against a whole class of
use-after-free bugs, replace the VF storage with a combination of a hash
table and krefs to reference track all of the accesses to VFs through
the hash table.
A hash table still allows efficient look up of the VF given its ID, but
also allows adding and removing VFs. It does not require contiguous VF
IDs.
The use of krefs allows the cleanup of the VF memory to be delayed until
after all threads have released their reference (by calling ice_put_vf).
To prevent corruption of the hash table, a combination of RCU and the
mutex table_lock are used. Addition and removal from the hash table use
the RCU-aware hash macros. This allows simple read-only look ups that
iterate to locate a single VF can be fast using RCU. Accesses which
modify the hash table, or which can't take RCU because they sleep, will
hold the mutex lock.
By using this design, we have a stronger guarantee that the VF structure
can't be released until after all threads are finished operating on it.
We also pave the way for the more dynamic Scalable IOV implementation in
the future.
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Tested-by: Konrad Jankowski <konrad0.jankowski@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
2022-02-16 13:37:38 -08:00
|
|
|
lockdep_assert_held(&pf->vfs.table_lock);
|
|
|
|
|
2022-02-16 13:37:35 -08:00
|
|
|
ice_for_each_vf(pf, bkt, vf)
|
2021-08-19 17:08:51 -07:00
|
|
|
ice_repr_rem(vf);
|
2022-11-15 11:48:22 +01:00
|
|
|
|
|
|
|
/* since all port representors are destroyed, there is
|
|
|
|
* no point in keeping the nodes
|
|
|
|
*/
|
|
|
|
devlink = priv_to_devlink(pf);
|
|
|
|
devl_lock(devlink);
|
|
|
|
devl_rate_nodes_destroy(devlink);
|
|
|
|
devl_unlock(devlink);
|
2021-08-19 17:08:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-02-16 13:37:28 -08:00
|
|
|
* ice_repr_add_for_all_vfs - add port representor for all VFs
|
2021-08-19 17:08:50 -07:00
|
|
|
* @pf: pointer to PF structure
|
|
|
|
*/
|
2022-02-16 13:37:28 -08:00
|
|
|
int ice_repr_add_for_all_vfs(struct ice_pf *pf)
|
2021-08-19 17:08:50 -07:00
|
|
|
{
|
2022-11-15 11:48:22 +01:00
|
|
|
struct devlink *devlink;
|
2022-02-16 13:37:35 -08:00
|
|
|
struct ice_vf *vf;
|
|
|
|
unsigned int bkt;
|
2022-02-16 13:37:28 -08:00
|
|
|
int err;
|
2021-08-19 17:08:51 -07:00
|
|
|
|
ice: convert VF storage to hash table with krefs and RCU
The ice driver stores VF structures in a simple array which is allocated
once at the time of VF creation. The VF structures are then accessed
from the array by their VF ID. The ID must be between 0 and the number
of allocated VFs.
Multiple threads can access this table:
* .ndo operations such as .ndo_get_vf_cfg or .ndo_set_vf_trust
* interrupts, such as due to messages from the VF using the virtchnl
communication
* processing such as device reset
* commands to add or remove VFs
The current implementation does not keep track of when all threads are
done operating on a VF and can potentially result in use-after-free
issues caused by one thread accessing a VF structure after it has been
released when removing VFs. Some of these are prevented with various
state flags and checks.
In addition, this structure is quite static and does not support a
planned future where virtualization can be more dynamic. As we begin to
look at supporting Scalable IOV with the ice driver (as opposed to just
supporting Single Root IOV), this structure is not sufficient.
In the future, VFs will be able to be added and removed individually and
dynamically.
To allow for this, and to better protect against a whole class of
use-after-free bugs, replace the VF storage with a combination of a hash
table and krefs to reference track all of the accesses to VFs through
the hash table.
A hash table still allows efficient look up of the VF given its ID, but
also allows adding and removing VFs. It does not require contiguous VF
IDs.
The use of krefs allows the cleanup of the VF memory to be delayed until
after all threads have released their reference (by calling ice_put_vf).
To prevent corruption of the hash table, a combination of RCU and the
mutex table_lock are used. Addition and removal from the hash table use
the RCU-aware hash macros. This allows simple read-only look ups that
iterate to locate a single VF can be fast using RCU. Accesses which
modify the hash table, or which can't take RCU because they sleep, will
hold the mutex lock.
By using this design, we have a stronger guarantee that the VF structure
can't be released until after all threads are finished operating on it.
We also pave the way for the more dynamic Scalable IOV implementation in
the future.
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Tested-by: Konrad Jankowski <konrad0.jankowski@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
2022-02-16 13:37:38 -08:00
|
|
|
lockdep_assert_held(&pf->vfs.table_lock);
|
|
|
|
|
2022-02-16 13:37:35 -08:00
|
|
|
ice_for_each_vf(pf, bkt, vf) {
|
2022-02-16 13:37:28 -08:00
|
|
|
err = ice_repr_add(vf);
|
|
|
|
if (err)
|
|
|
|
goto err;
|
2021-08-19 17:08:51 -07:00
|
|
|
}
|
2022-02-16 13:37:28 -08:00
|
|
|
|
2022-11-15 11:48:23 +01:00
|
|
|
/* only export if ADQ and DCB disabled */
|
|
|
|
if (ice_is_adq_active(pf) || ice_is_dcb_active(pf))
|
|
|
|
return 0;
|
|
|
|
|
2022-11-15 11:48:22 +01:00
|
|
|
devlink = priv_to_devlink(pf);
|
|
|
|
ice_devlink_rate_init_tx_topology(devlink, ice_get_main_vsi(pf));
|
|
|
|
|
2022-02-16 13:37:28 -08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
ice_repr_rem_from_all_vfs(pf);
|
|
|
|
|
|
|
|
return err;
|
2021-08-19 17:08:50 -07:00
|
|
|
}
|
2021-08-19 17:08:54 -07:00
|
|
|
|
2021-08-19 17:08:57 -07:00
|
|
|
/**
|
|
|
|
* ice_repr_start_tx_queues - start Tx queues of port representor
|
|
|
|
* @repr: pointer to repr structure
|
|
|
|
*/
|
|
|
|
void ice_repr_start_tx_queues(struct ice_repr *repr)
|
|
|
|
{
|
|
|
|
netif_carrier_on(repr->netdev);
|
|
|
|
netif_tx_start_all_queues(repr->netdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ice_repr_stop_tx_queues - stop Tx queues of port representor
|
|
|
|
* @repr: pointer to repr structure
|
|
|
|
*/
|
|
|
|
void ice_repr_stop_tx_queues(struct ice_repr *repr)
|
|
|
|
{
|
|
|
|
netif_carrier_off(repr->netdev);
|
|
|
|
netif_tx_stop_all_queues(repr->netdev);
|
|
|
|
}
|
|
|
|
|
2021-08-19 17:08:54 -07:00
|
|
|
/**
|
|
|
|
* ice_repr_set_traffic_vsi - set traffic VSI for port representor
|
|
|
|
* @repr: repr on with VSI will be set
|
|
|
|
* @vsi: pointer to VSI that will be used by port representor to pass traffic
|
|
|
|
*/
|
|
|
|
void ice_repr_set_traffic_vsi(struct ice_repr *repr, struct ice_vsi *vsi)
|
|
|
|
{
|
|
|
|
struct ice_netdev_priv *np = netdev_priv(repr->netdev);
|
|
|
|
|
|
|
|
np->vsi = vsi;
|
|
|
|
}
|