/** * ice_lag_set_primary - set PF LAG state as Primary * @lag: LAG info struct
*/ staticvoid ice_lag_set_primary(struct ice_lag *lag)
{ struct ice_pf *pf = lag->pf;
if (!pf) return;
if (lag->role != ICE_LAG_UNSET && lag->role != ICE_LAG_BACKUP) {
dev_warn(ice_pf_to_dev(pf), "%s: Attempt to be Primary, but incompatible state.\n",
netdev_name(lag->netdev)); return;
}
lag->role = ICE_LAG_PRIMARY;
}
/** * ice_lag_set_backup - set PF LAG state to Backup * @lag: LAG info struct
*/ staticvoid ice_lag_set_backup(struct ice_lag *lag)
{ struct ice_pf *pf = lag->pf;
if (!pf) return;
if (lag->role != ICE_LAG_UNSET && lag->role != ICE_LAG_PRIMARY) {
dev_dbg(ice_pf_to_dev(pf), "%s: Attempt to be Backup, but incompatible state\n",
netdev_name(lag->netdev)); return;
}
lag->role = ICE_LAG_BACKUP;
}
/** * netif_is_same_ice - determine if netdev is on the same ice NIC as local PF * @pf: local PF struct * @netdev: netdev we are evaluating
*/ staticbool netif_is_same_ice(struct ice_pf *pf, struct net_device *netdev)
{ struct ice_netdev_priv *np; struct ice_pf *test_pf; struct ice_vsi *vsi;
if (!netif_is_ice(netdev)) returnfalse;
np = netdev_priv(netdev); if (!np) returnfalse;
vsi = np->vsi; if (!vsi) returnfalse;
test_pf = vsi->back; if (!test_pf) returnfalse;
if (pf->pdev->bus != test_pf->pdev->bus ||
pf->pdev->slot != test_pf->pdev->slot) returnfalse;
returntrue;
}
/** * ice_netdev_to_lag - return pointer to associated lag struct from netdev * @netdev: pointer to net_device struct to query
*/ staticstruct ice_lag *ice_netdev_to_lag(struct net_device *netdev)
{ struct ice_netdev_priv *np; struct ice_vsi *vsi;
if (!netif_is_ice(netdev)) return NULL;
np = netdev_priv(netdev); if (!np) return NULL;
vsi = np->vsi; if (!vsi) return NULL;
return vsi->back->lag;
}
/** * ice_lag_find_hw_by_lport - return an hw struct from bond members lport * @lag: lag struct * @lport: lport value to search for
*/ staticstruct ice_hw *
ice_lag_find_hw_by_lport(struct ice_lag *lag, u8 lport)
{ struct ice_lag_netdev_list *entry; struct net_device *tmp_netdev; struct ice_netdev_priv *np; struct ice_hw *hw;
/** * ice_lag_cfg_fltr - Add/Remove rule for LAG * @lag: lag struct for local interface * @act: rule action * @recipe_id: recipe id for the new rule * @rule_idx: pointer to rule index * @direction: ICE_FLTR_RX or ICE_FLTR_TX * @add: boolean on whether we are adding filters
*/ staticint
ice_lag_cfg_fltr(struct ice_lag *lag, u32 act, u16 recipe_id, u16 *rule_idx,
u8 direction, bool add)
{ struct ice_sw_rule_lkup_rx_tx *s_rule;
u16 s_rule_sz, vsi_num; struct ice_hw *hw;
u8 *eth_hdr;
u32 opc; int err;
if (add)
*rule_idx = le16_to_cpu(s_rule->index); else
*rule_idx = 0;
dflt_fltr_free:
kfree(s_rule); return err;
}
/** * ice_lag_cfg_dflt_fltr - Add/Remove default VSI rule for LAG * @lag: lag struct for local interface * @add: boolean on whether to add filter
*/ staticint
ice_lag_cfg_dflt_fltr(struct ice_lag *lag, bool add)
{
u32 act = ICE_SINGLE_ACT_VSI_FORWARDING |
ICE_SINGLE_ACT_VALID_BIT | ICE_SINGLE_ACT_LAN_ENABLE; int err;
/** * ice_lag_cfg_pf_fltrs - set filters up for new active port * @lag: local interfaces lag struct * @ptr: opaque data containing notifier event
*/ staticvoid
ice_lag_cfg_pf_fltrs(struct ice_lag *lag, void *ptr)
{ struct netdev_notifier_bonding_info *info; struct netdev_bonding_info *bonding_info; struct net_device *event_netdev; struct device *dev;
event_netdev = netdev_notifier_info_to_dev(ptr); /* not for this netdev */ if (event_netdev != lag->netdev) return;
info = (struct netdev_notifier_bonding_info *)ptr;
bonding_info = &info->bonding_info;
dev = ice_pf_to_dev(lag->pf);
/* interface not active - remove old default VSI rule */ if (bonding_info->slave.state && lag->pf_rx_rule_id) { if (ice_lag_cfg_dflt_fltr(lag, false))
dev_err(dev, "Error removing old default VSI filter\n"); if (ice_lag_cfg_drop_fltr(lag, true))
dev_err(dev, "Error adding new drop filter\n"); return;
}
/* interface becoming active - add new default VSI rule */ if (!bonding_info->slave.state && !lag->pf_rx_rule_id) { if (ice_lag_cfg_dflt_fltr(lag, true))
dev_err(dev, "Error adding new default VSI filter\n"); if (lag->lport_rule_idx && ice_lag_cfg_drop_fltr(lag, false))
dev_err(dev, "Error removing old drop filter\n");
}
}
/** * ice_display_lag_info - print LAG info * @lag: LAG info struct
*/ staticvoid ice_display_lag_info(struct ice_lag *lag)
{ constchar *name, *upper, *role, *bonded, *primary; struct device *dev = &lag->pf->pdev->dev;
switch (lag->role) { case ICE_LAG_NONE:
role = "NONE"; break; case ICE_LAG_PRIMARY:
role = "PRIMARY"; break; case ICE_LAG_BACKUP:
role = "BACKUP"; break; case ICE_LAG_UNSET:
role = "UNSET"; break; default:
role = "ERROR";
}
/** * ice_lag_qbuf_recfg - generate a buffer of queues for a reconfigure command * @hw: HW struct that contains the queue contexts * @qbuf: pointer to buffer to populate * @vsi_num: index of the VSI in PF space * @numq: number of queues to search for * @tc: traffic class that contains the queues * * function returns the number of valid queues in buffer
*/ static u16
ice_lag_qbuf_recfg(struct ice_hw *hw, struct ice_aqc_cfg_txqs_buf *qbuf,
u16 vsi_num, u16 numq, u8 tc)
{ struct ice_q_ctx *q_ctx;
u16 qid, count = 0; struct ice_pf *pf; int i;
pf = hw->back; for (i = 0; i < numq; i++) {
q_ctx = ice_get_lan_q_ctx(hw, vsi_num, tc, i); if (!q_ctx) {
dev_dbg(ice_hw_to_dev(hw), "%s queue %d NO Q CONTEXT\n",
__func__, i); continue;
} if (q_ctx->q_teid == ICE_INVAL_TEID) {
dev_dbg(ice_hw_to_dev(hw), "%s queue %d INVAL TEID\n",
__func__, i); continue;
} if (q_ctx->q_handle == ICE_INVAL_Q_HANDLE) {
dev_dbg(ice_hw_to_dev(hw), "%s queue %d INVAL Q HANDLE\n",
__func__, i); continue;
}
/** * ice_lag_get_sched_parent - locate or create a sched node parent * @hw: HW struct for getting parent in * @tc: traffic class on parent/node
*/ staticstruct ice_sched_node *
ice_lag_get_sched_parent(struct ice_hw *hw, u8 tc)
{ struct ice_sched_node *tc_node, *aggnode, *parent = NULL;
u16 num_nodes[ICE_AQC_TOPO_MAX_LEVEL_NUM] = { 0 }; struct ice_port_info *pi = hw->port_info; struct device *dev;
u8 aggl, vsil; int n;
dev = ice_hw_to_dev(hw);
tc_node = ice_sched_get_tc_node(pi, tc); if (!tc_node) {
dev_warn(dev, "Failure to find TC node for LAG move\n"); return parent;
}
aggnode = ice_sched_get_agg_node(pi, tc_node, ICE_DFLT_AGG_ID); if (!aggnode) {
dev_warn(dev, "Failure to find aggregate node for LAG move\n"); return parent;
}
for (n = aggl + 1; n < vsil; n++)
num_nodes[n] = 1;
for (n = 0; n < aggnode->num_children; n++) {
parent = ice_sched_get_free_vsi_parent(hw, aggnode->children[n],
num_nodes); if (parent) return parent;
}
/* if free parent not found - add one */
parent = aggnode; for (n = aggl + 1; n < vsil; n++) {
u16 num_nodes_added;
u32 first_teid; int err;
err = ice_sched_add_nodes_to_layer(pi, tc_node, parent, n,
num_nodes[n], &first_teid,
&num_nodes_added); if (err || num_nodes[n] != num_nodes_added) return NULL;
if (num_nodes_added)
parent = ice_sched_find_node_by_teid(tc_node,
first_teid); else
parent = parent->children[0]; if (!parent) {
dev_warn(dev, "Failure to add new parent for LAG move\n"); return parent;
}
}
return parent;
}
/** * ice_lag_move_vf_node_tc - move scheduling nodes for one VF on one TC * @lag: lag info struct * @oldport: lport of previous nodes location * @newport: lport of destination nodes location * @vsi_num: array index of VSI in PF space * @tc: traffic class to move
*/ staticvoid
ice_lag_move_vf_node_tc(struct ice_lag *lag, u8 oldport, u8 newport,
u16 vsi_num, u8 tc)
{
DEFINE_RAW_FLEX(struct ice_aqc_move_elem, buf, teid, 1); struct device *dev = ice_pf_to_dev(lag->pf);
u16 numq, valq, num_moved, qbuf_size;
u16 buf_size = __struct_size(buf); struct ice_aqc_cfg_txqs_buf *qbuf; struct ice_sched_node *n_prt; struct ice_hw *new_hw = NULL;
__le32 teid, parent_teid; struct ice_vsi_ctx *ctx;
u32 tmp_teid;
ctx = ice_get_vsi_ctx(&lag->pf->hw, vsi_num); if (!ctx) {
dev_warn(dev, "Unable to locate VSI context for LAG failover\n"); return;
}
/* check to see if this VF is enabled on this TC */ if (!ctx->sched.vsi_node[tc]) return;
/* locate HW struct for destination port */
new_hw = ice_lag_find_hw_by_lport(lag, newport); if (!new_hw) {
dev_warn(dev, "Unable to locate HW struct for LAG node destination\n"); return;
}
numq = ctx->num_lan_q_entries[tc];
teid = ctx->sched.vsi_node[tc]->info.node_teid;
tmp_teid = le32_to_cpu(teid);
parent_teid = ctx->sched.vsi_node[tc]->info.parent_teid; /* if no teid assigned or numq == 0, then this TC is not active */ if (!tmp_teid || !numq) return;
/* suspend VSI subtree for Traffic Class "tc" on * this VF's VSI
*/ if (ice_sched_suspend_resume_elems(&lag->pf->hw, 1, &tmp_teid, true))
dev_dbg(dev, "Problem suspending traffic for LAG node move\n");
/* reconfigure all VF's queues on this Traffic Class * to new port
*/
qbuf_size = struct_size(qbuf, queue_info, numq);
qbuf = kzalloc(qbuf_size, GFP_KERNEL); if (!qbuf) {
dev_warn(dev, "Failure allocating memory for VF queue recfg buffer\n"); goto resume_traffic;
}
/* add the per queue info for the reconfigure command buffer */
valq = ice_lag_qbuf_recfg(&lag->pf->hw, qbuf, vsi_num, numq, tc); if (!valq) {
dev_dbg(dev, "No valid queues found for LAG failover\n"); goto qbuf_none;
}
if (ice_aq_cfg_lan_txq(&lag->pf->hw, qbuf, qbuf_size, valq, oldport,
newport, NULL)) {
dev_warn(dev, "Failure to configure queues for LAG failover\n"); goto qbuf_err;
}
qbuf_none:
kfree(qbuf);
/* find new parent in destination port's tree for VF VSI node on this * Traffic Class
*/
n_prt = ice_lag_get_sched_parent(new_hw, tc); if (!n_prt) goto resume_traffic;
/* Move Vf's VSI node for this TC to newport's scheduler tree */
buf->hdr.src_parent_teid = parent_teid;
buf->hdr.dest_parent_teid = n_prt->info.node_teid;
buf->hdr.num_elems = cpu_to_le16(1);
buf->hdr.mode = ICE_AQC_MOVE_ELEM_MODE_KEEP_OWN;
buf->teid[0] = teid;
if (ice_aq_move_sched_elems(&lag->pf->hw, buf, buf_size, &num_moved))
dev_warn(dev, "Failure to move VF nodes for failover\n"); else
ice_sched_update_parent(n_prt, ctx->sched.vsi_node[tc]);
goto resume_traffic;
qbuf_err:
kfree(qbuf);
resume_traffic: /* restart traffic for VSI node */ if (ice_sched_suspend_resume_elems(&lag->pf->hw, 1, &tmp_teid, false))
dev_dbg(dev, "Problem restarting traffic for LAG node move\n");
}
/** * ice_lag_build_netdev_list - populate the lag struct's netdev list * @lag: local lag struct * @ndlist: pointer to netdev list to populate
*/ staticvoid ice_lag_build_netdev_list(struct ice_lag *lag, struct ice_lag_netdev_list *ndlist)
{ struct ice_lag_netdev_list *nl; struct net_device *tmp_nd;
/** * ice_lag_destroy_netdev_list - free lag struct's netdev list * @lag: pointer to local lag struct * @ndlist: pointer to lag struct netdev list
*/ staticvoid ice_lag_destroy_netdev_list(struct ice_lag *lag, struct ice_lag_netdev_list *ndlist)
{ struct ice_lag_netdev_list *entry, *n;
/** * ice_lag_move_new_vf_nodes - Move Tx scheduling nodes for a VF if required * @vf: the VF to move Tx nodes for * * Called just after configuring new VF queues. Check whether the VF Tx * scheduling nodes need to be updated to fail over to the active port. If so, * move them now.
*/ void ice_lag_move_new_vf_nodes(struct ice_vf *vf)
{ struct ice_lag_netdev_list ndlist;
u8 pri_port, act_port; struct ice_lag *lag; struct ice_vsi *vsi; struct ice_pf *pf;
vsi = ice_get_vf_vsi(vf);
if (WARN_ON(!vsi)) return;
if (WARN_ON(vsi->type != ICE_VSI_VF)) return;
pf = vf->pf;
lag = pf->lag;
mutex_lock(&pf->lag_mutex); if (!lag->bonded) goto new_vf_unlock;
/** * ice_lag_move_vf_nodes - move Tx scheduling nodes for all VFs to new port * @lag: lag info struct * @oldport: lport of previous interface * @newport: lport of destination interface
*/ staticvoid ice_lag_move_vf_nodes(struct ice_lag *lag, u8 oldport, u8 newport)
{ struct ice_pf *pf; int i;
/** * ice_lag_move_vf_nodes_cfg - move vf nodes outside LAG netdev event context * @lag: local lag struct * @src_prt: lport value for source port * @dst_prt: lport value for destination port * * This function is used to move nodes during an out-of-netdev-event situation, * primarily when the driver needs to reconfigure or recreate resources. * * Must be called while holding the lag_mutex to avoid lag events from * processing while out-of-sync moves are happening. Also, paired moves, * such as used in a reset flow, should both be called under the same mutex * lock to avoid changes between start of reset and end of reset.
*/ void ice_lag_move_vf_nodes_cfg(struct ice_lag *lag, u8 src_prt, u8 dst_prt)
{ struct ice_lag_netdev_list ndlist;
if (add)
lag->cp_rule_idx = le16_to_cpu(s_rule->index); else
lag->cp_rule_idx = 0;
cp_free:
kfree(s_rule);
}
/** * ice_lag_prepare_vf_reset - helper to adjust vf lag for reset * @lag: lag struct for interface that owns VF * * Context: must be called with the lag_mutex lock held. * * Return: active lport value or ICE_LAG_INVALID_PORT if nothing moved.
*/
u8 ice_lag_prepare_vf_reset(struct ice_lag *lag)
{
u8 pri_prt, act_prt;
/** * ice_lag_complete_vf_reset - helper for lag after reset * @lag: lag struct for primary interface * @act_prt: which port should be active for lag * * Context: must be called while holding the lag_mutex.
*/ void ice_lag_complete_vf_reset(struct ice_lag *lag, u8 act_prt)
{
u8 pri_prt;
if (event_netdev != lag->netdev || !lag->bonded || !lag->upper_netdev) return;
if (bonding_info->master.bond_mode != BOND_MODE_ACTIVEBACKUP) {
netdev_dbg(lag->netdev, "Bonding event recv, but mode not active/backup\n"); goto lag_out;
}
if (strcmp(bonding_info->slave.slave_name, lag_netdev_name)) {
netdev_dbg(lag->netdev, "Bonding event recv, but secondary info not for us\n"); goto lag_out;
}
if (bonding_info->slave.state)
ice_lag_set_backup(lag); else
ice_lag_set_primary(lag);
lag_out:
ice_display_lag_info(lag);
}
/** * ice_lag_reclaim_vf_tc - move scheduling nodes back to primary interface * @lag: primary interface lag struct * @src_hw: HW struct current node location * @vsi_num: VSI index in PF space * @tc: traffic class to move
*/ staticvoid
ice_lag_reclaim_vf_tc(struct ice_lag *lag, struct ice_hw *src_hw, u16 vsi_num,
u8 tc)
{
DEFINE_RAW_FLEX(struct ice_aqc_move_elem, buf, teid, 1); struct device *dev = ice_pf_to_dev(lag->pf);
u16 numq, valq, num_moved, qbuf_size;
u16 buf_size = __struct_size(buf); struct ice_aqc_cfg_txqs_buf *qbuf; struct ice_sched_node *n_prt;
__le32 teid, parent_teid; struct ice_vsi_ctx *ctx; struct ice_hw *hw;
u32 tmp_teid;
hw = &lag->pf->hw;
ctx = ice_get_vsi_ctx(hw, vsi_num); if (!ctx) {
dev_warn(dev, "Unable to locate VSI context for LAG reclaim\n"); return;
}
/* check to see if this VF is enabled on this TC */ if (!ctx->sched.vsi_node[tc]) return;
/* if !teid or !numq, then this TC is not active */ if (!tmp_teid || !numq) return;
/* suspend traffic */ if (ice_sched_suspend_resume_elems(hw, 1, &tmp_teid, true))
dev_dbg(dev, "Problem suspending traffic for LAG node move\n");
/* reconfig queues for new port */
qbuf_size = struct_size(qbuf, queue_info, numq);
qbuf = kzalloc(qbuf_size, GFP_KERNEL); if (!qbuf) {
dev_warn(dev, "Failure allocating memory for VF queue recfg buffer\n"); goto resume_reclaim;
}
/* add the per queue info for the reconfigure command buffer */
valq = ice_lag_qbuf_recfg(hw, qbuf, vsi_num, numq, tc); if (!valq) {
dev_dbg(dev, "No valid queues found for LAG reclaim\n"); goto reclaim_none;
}
if (ice_aq_cfg_lan_txq(hw, qbuf, qbuf_size, numq,
src_hw->port_info->lport, hw->port_info->lport,
NULL)) {
dev_warn(dev, "Failure to configure queues for LAG failover\n"); goto reclaim_qerr;
}
reclaim_none:
kfree(qbuf);
/* find parent in primary tree */
n_prt = ice_lag_get_sched_parent(hw, tc); if (!n_prt) goto resume_reclaim;
if (ice_aq_move_sched_elems(&lag->pf->hw, buf, buf_size, &num_moved))
dev_warn(dev, "Failure to move VF nodes for LAG reclaim\n"); else
ice_sched_update_parent(n_prt, ctx->sched.vsi_node[tc]);
goto resume_reclaim;
reclaim_qerr:
kfree(qbuf);
resume_reclaim: /* restart traffic */ if (ice_sched_suspend_resume_elems(hw, 1, &tmp_teid, false))
dev_warn(dev, "Problem restarting traffic for LAG node reclaim\n");
}
/** * ice_lag_reclaim_vf_nodes - When interface leaving bond primary reclaims nodes * @lag: primary interface lag struct * @src_hw: HW struct for current node location
*/ staticvoid
ice_lag_reclaim_vf_nodes(struct ice_lag *lag, struct ice_hw *src_hw)
{ struct ice_pf *pf; int i, tc;
if (!lag->primary || !src_hw) return;
pf = lag->pf;
ice_for_each_vsi(pf, i) if (pf->vsi[i] && pf->vsi[i]->type == ICE_VSI_VF)
ice_for_each_traffic_class(tc)
ice_lag_reclaim_vf_tc(lag, src_hw, i, tc);
}
/** * ice_lag_link - handle LAG link event * @lag: LAG info struct
*/ staticvoid ice_lag_link(struct ice_lag *lag)
{ struct ice_pf *pf = lag->pf;
if (lag->bonded)
dev_warn(ice_pf_to_dev(pf), "%s Already part of a bond\n",
netdev_name(lag->netdev));
lag->bonded = true;
lag->role = ICE_LAG_UNSET;
netdev_info(lag->netdev, "Shared SR-IOV resources in bond are active\n");
}
/** * ice_lag_config_eswitch - configure eswitch to work with LAG * @lag: lag info struct * @netdev: active network interface device struct * * Updates all port representors in eswitch to use @netdev for Tx. * * Configures the netdev to keep dst metadata (also used in representor Tx). * This is required for an uplink without switchdev mode configured.
*/ staticvoid ice_lag_config_eswitch(struct ice_lag *lag, struct net_device *netdev)
{ struct ice_repr *repr; unsignedlong id;
/** * ice_lag_link_unlink - helper function to call lag_link/unlink * @lag: lag info struct * @ptr: opaque pointer data
*/ staticvoid ice_lag_link_unlink(struct ice_lag *lag, void *ptr)
{ struct net_device *netdev = netdev_notifier_info_to_dev(ptr); struct netdev_notifier_changeupper_info *info = ptr;
if (netdev != lag->netdev) return;
if (info->linking)
ice_lag_link(lag); else
ice_lag_unlink(lag);
}
/** * ice_lag_set_swid - set the SWID on secondary interface * @primary_swid: primary interface's SWID * @local_lag: local interfaces LAG struct * @link: Is this a linking activity * * If link is false, then primary_swid should be expected to not be valid * This function should never be called in interrupt context.
*/ staticvoid
ice_lag_set_swid(u16 primary_swid, struct ice_lag *local_lag, bool link)
{ struct ice_aqc_alloc_free_res_elem *buf; struct ice_aqc_set_port_params *cmd; struct libie_aq_desc desc;
u16 buf_len, swid; int status, i;
buf->num_elems = cpu_to_le16(1);
buf->res_type = cpu_to_le16(ICE_AQC_RES_TYPE_SWID); /* if unlinnking need to free the shared resource */ if (!link && local_lag->bond_swid) {
buf->elem[0].e.sw_resp = cpu_to_le16(local_lag->bond_swid);
status = ice_aq_alloc_free_res(&local_lag->pf->hw, buf,
buf_len, ice_aqc_opc_free_res); if (status)
dev_err(ice_pf_to_dev(local_lag->pf), "Error freeing SWID during LAG unlink\n");
local_lag->bond_swid = 0;
}
if (link) {
buf->res_type |= cpu_to_le16(ICE_LAG_RES_SHARED |
ICE_LAG_RES_VALID); /* store the primary's SWID in case it leaves bond first */
local_lag->bond_swid = primary_swid;
buf->elem[0].e.sw_resp = cpu_to_le16(local_lag->bond_swid);
} else {
buf->elem[0].e.sw_resp =
cpu_to_le16(local_lag->pf->hw.port_info->sw_id);
}
status = ice_aq_alloc_free_res(&local_lag->pf->hw, buf, buf_len,
ice_aqc_opc_alloc_res); if (status)
dev_err(ice_pf_to_dev(local_lag->pf), "Error subscribing to SWID 0x%04X\n",
local_lag->bond_swid);
kfree(buf);
/* Configure port param SWID to correct value */ if (link)
swid = primary_swid; else
swid = local_lag->pf->hw.port_info->sw_id;
cmd->swid = cpu_to_le16(ICE_AQC_PORT_SWID_VALID | swid); /* If this is happening in reset context, it is possible that the * primary interface has not finished setting its SWID to SHARED * yet. Allow retries to account for this timing issue between * interfaces.
*/ for (i = 0; i < ICE_LAG_RESET_RETRIES; i++) {
status = ice_aq_send_cmd(&local_lag->pf->hw, &desc, NULL, 0,
NULL); if (!status) break;
usleep_range(1000, 2000);
}
if (status)
dev_err(ice_pf_to_dev(local_lag->pf), "Error setting SWID in port params %d\n",
status);
}
/** * ice_lag_primary_swid - set/clear the SHARED attrib of primary's SWID * @lag: primary interface's lag struct * @link: is this a linking activity * * Implement setting primary SWID as shared using 0x020B
*/ staticvoid ice_lag_primary_swid(struct ice_lag *lag, bool link)
{ struct ice_hw *hw;
u16 swid;
hw = &lag->pf->hw;
swid = hw->port_info->sw_id;
if (ice_share_res(hw, ICE_AQC_RES_TYPE_SWID, link, swid))
dev_warn(ice_pf_to_dev(lag->pf), "Failure to set primary interface shared status\n");
}
/** * ice_lag_add_prune_list - Adds event_pf's VSI to primary's prune list * @lag: lag info struct * @event_pf: PF struct for VSI we are adding to primary's prune list
*/ staticvoid ice_lag_add_prune_list(struct ice_lag *lag, struct ice_pf *event_pf)
{
u16 num_vsi, rule_buf_sz, vsi_list_id, event_vsi_num, prim_vsi_idx; struct ice_sw_rule_vsi_list *s_rule = NULL; struct device *dev;
num_vsi = 1;
dev = ice_pf_to_dev(lag->pf);
event_vsi_num = event_pf->vsi[0]->vsi_num;
prim_vsi_idx = lag->pf->vsi[0]->idx;
if (!ice_find_vsi_list_entry(&lag->pf->hw, ICE_SW_LKUP_VLAN,
prim_vsi_idx, &vsi_list_id)) {
dev_warn(dev, "Could not locate prune list when setting up SRIOV LAG\n"); return;
}
rule_buf_sz = (u16)ICE_SW_RULE_VSI_LIST_SIZE(s_rule, num_vsi);
s_rule = kzalloc(rule_buf_sz, GFP_KERNEL); if (!s_rule) {
dev_warn(dev, "Error allocating space for prune list when configuring SRIOV LAG\n"); return;
}
dev = ice_pf_to_dev(lag->pf);
vsi_num = event_pf->vsi[0]->vsi_num;
vsi_idx = lag->pf->vsi[0]->idx;
if (!ice_find_vsi_list_entry(&lag->pf->hw, ICE_SW_LKUP_VLAN,
vsi_idx, &vsi_list_id)) {
dev_warn(dev, "Could not locate prune list when unwinding SRIOV LAG\n"); return;
}
rule_buf_sz = (u16)ICE_SW_RULE_VSI_LIST_SIZE(s_rule, num_vsi);
s_rule = kzalloc(rule_buf_sz, GFP_KERNEL); if (!s_rule) {
dev_warn(dev, "Error allocating prune list when unwinding SRIOV LAG\n"); return;
}
if (ice_aq_sw_rules(&event_pf->hw, (struct ice_aqc_sw_rules *)s_rule,
rule_buf_sz, 1, ice_aqc_opc_update_sw_rules, NULL))
dev_warn(dev, "Error clearing VSI prune list\n");
kfree(s_rule);
}
/** * ice_lag_init_feature_support_flag - Check for package and NVM support for LAG * @pf: PF struct
*/ staticvoid ice_lag_init_feature_support_flag(struct ice_pf *pf)
{ struct ice_hw_common_caps *caps;
caps = &pf->hw.dev_caps.common_cap; if (caps->roce_lag)
ice_set_feature_support(pf, ICE_F_ROCE_LAG); else
ice_clear_feature_support(pf, ICE_F_ROCE_LAG);
if (caps->sriov_lag && ice_pkg_has_lport_extract(&pf->hw))
ice_set_feature_support(pf, ICE_F_SRIOV_LAG); else
ice_clear_feature_support(pf, ICE_F_SRIOV_LAG);
}
/** * ice_lag_changeupper_event - handle LAG changeupper event * @lag: LAG info struct * @ptr: opaque pointer data
*/ staticvoid ice_lag_changeupper_event(struct ice_lag *lag, void *ptr)
{ struct netdev_notifier_changeupper_info *info; struct ice_lag *primary_lag; struct net_device *netdev;
info = ptr;
netdev = netdev_notifier_info_to_dev(ptr);
/* not for this netdev */ if (netdev != lag->netdev) return;
primary_lag = ice_lag_find_primary(lag); if (info->linking) {
lag->upper_netdev = info->upper_dev; /* If there is not already a primary interface in the LAG, * then mark this one as primary.
*/ if (!primary_lag) {
lag->primary = true; if (!ice_is_switchdev_running(lag->pf)) return;
/* Configure primary's SWID to be shared */
ice_lag_primary_swid(lag, true);
primary_lag = lag;
} else {
u16 swid;
if (!ice_is_switchdev_running(primary_lag->pf)) return;
info = (struct netdev_notifier_changeupper_info *)ptr; if (info->upper_dev != lag->upper_netdev) return;
if (!info->linking) { /* Since there are only two interfaces allowed in SRIOV+LAG, if * one port is leaving, then nodes need to be on primary * interface.
*/ if (prim_port != lag->active_port &&
lag->active_port != ICE_LAG_INVALID_PORT) {
active_hw = ice_lag_find_hw_by_lport(lag,
lag->active_port);
ice_lag_reclaim_vf_nodes(lag, active_hw);
lag->active_port = ICE_LAG_INVALID_PORT;
}
}
}
/** * ice_lag_monitor_active - main PF keep track of which port is active * @lag: lag info struct * @ptr: opaque data containing notifier event * * This function is for the primary PF to monitor changes in which port is * active and handle changes for SRIOV VF functionality
*/ staticvoid ice_lag_monitor_active(struct ice_lag *lag, void *ptr)
{ struct net_device *event_netdev, *event_upper; struct netdev_notifier_bonding_info *info; struct netdev_bonding_info *bonding_info; struct ice_netdev_priv *event_np; struct ice_pf *pf, *event_pf;
u8 prim_port, event_port;
info = (struct netdev_notifier_bonding_info *)ptr;
bonding_info = &info->bonding_info;
if (!bonding_info->slave.state) { /* if no port is currently active, then nodes and filters exist * on primary port, check if we need to move them
*/ if (lag->active_port == ICE_LAG_INVALID_PORT) { if (event_port != prim_port)
ice_lag_move_vf_nodes(lag, prim_port,
event_port);
lag->active_port = event_port;
ice_lag_config_eswitch(lag, event_netdev); return;
}
/* active port is already set and is current event port */ if (lag->active_port == event_port) return; /* new active port */
ice_lag_move_vf_nodes(lag, lag->active_port, event_port);
lag->active_port = event_port;
ice_lag_config_eswitch(lag, event_netdev);
} else { /* port not set as currently active (e.g. new active port * has already claimed the nodes and filters
*/ if (lag->active_port != event_port) return; /* This is the case when neither port is active (both link down) * Link down on the bond - set active port to invalid and move * nodes and filters back to primary if not already there
*/ if (event_port != prim_port)
ice_lag_move_vf_nodes(lag, event_port, prim_port);
lag->active_port = ICE_LAG_INVALID_PORT;
}
}
/** * ice_lag_chk_comp - evaluate bonded interface for feature support * @lag: lag info struct * @ptr: opaque data for netdev event info
*/ staticbool
ice_lag_chk_comp(struct ice_lag *lag, void *ptr)
{ struct net_device *event_netdev, *event_upper; struct netdev_notifier_bonding_info *info; struct netdev_bonding_info *bonding_info; struct list_head *tmp; struct device *dev; int count = 0;
/* only supporting switchdev mode for SRIOV VF LAG. * primary interface has to be in switchdev mode
*/ if (!ice_is_switchdev_running(lag->pf)) {
dev_info(dev, "Primary interface not in switchdev mode - VF LAG disabled\n"); returnfalse;
}
info = (struct netdev_notifier_bonding_info *)ptr;
bonding_info = &info->bonding_info;
lag->bond_mode = bonding_info->master.bond_mode; if (lag->bond_mode != BOND_MODE_ACTIVEBACKUP) {
dev_info(dev, "Bond Mode not ACTIVE-BACKUP - VF LAG disabled\n"); returnfalse;
}
entry = list_entry(tmp, struct ice_lag_netdev_list, node);
peer_netdev = entry->netdev; if (!netif_is_ice(peer_netdev)) {
dev_info(dev, "Found %s non-ice netdev in LAG - VF LAG disabled\n",
netdev_name(peer_netdev)); returnfalse;
}
count++; if (count > 2) {
dev_info(dev, "Found more than two netdevs in LAG - VF LAG disabled\n"); returnfalse;
}
peer_np = netdev_priv(peer_netdev);
vsi = ice_get_main_vsi(lag->pf);
peer_vsi = peer_np->vsi; if (lag->pf->pdev->bus != peer_vsi->back->pdev->bus ||
lag->pf->pdev->slot != peer_vsi->back->pdev->slot) {
dev_info(dev, "Found %s on different device in LAG - VF LAG disabled\n",
netdev_name(peer_netdev)); returnfalse;
}
dcb_cfg = &vsi->port_info->qos_cfg.local_dcbx_cfg;
peer_dcb_cfg = &peer_vsi->port_info->qos_cfg.local_dcbx_cfg; if (memcmp(dcb_cfg, peer_dcb_cfg, sizeof(struct ice_dcbx_cfg))) {
dev_info(dev, "Found %s with different DCB in LAG - VF LAG disabled\n",
netdev_name(peer_netdev)); returnfalse;
}
peer_pf = peer_vsi->back; if (test_bit(ICE_FLAG_FW_LLDP_AGENT, peer_pf->flags)) {
dev_warn(dev, "Found %s with FW LLDP agent active - VF LAG disabled\n",
netdev_name(peer_netdev)); returnfalse;
}
}
returntrue;
}
/** * ice_lag_unregister - handle netdev unregister events * @lag: LAG info struct * @event_netdev: netdev struct for target of notifier event
*/ staticvoid
ice_lag_unregister(struct ice_lag *lag, struct net_device *event_netdev)
{ struct ice_netdev_priv *np; struct ice_pf *event_pf; struct ice_lag *p_lag;
/* primary processing for primary */ if (lag->primary && lag->netdev == event_netdev)
ice_lag_primary_swid(lag, false);
/* primary processing for secondary */ if (lag->primary && lag->netdev != event_netdev)
ice_lag_del_prune_list(lag, event_pf);
/* secondary processing for secondary */ if (!lag->primary && lag->netdev == event_netdev)
ice_lag_set_swid(0, lag, false);
}
/** * ice_lag_monitor_rdma - set and clear rdma functionality * @lag: pointer to lag struct * @ptr: opaque data for netdev event info
*/ staticvoid
ice_lag_monitor_rdma(struct ice_lag *lag, void *ptr)
{ struct netdev_notifier_changeupper_info *info; struct net_device *netdev;
info = ptr;
netdev = netdev_notifier_info_to_dev(ptr);
if (netdev != lag->netdev) return;
if (info->linking)
ice_clear_rdma_cap(lag->pf); else
ice_set_rdma_cap(lag->pf);
}
/** * ice_lag_chk_disabled_bond - monitor interfaces entering/leaving disabled bond * @lag: lag info struct * @ptr: opaque data containing event * * as interfaces enter a bond - determine if the bond is currently * SRIOV LAG compliant and flag if not. As interfaces leave the * bond, reset their compliant status.
*/ staticvoid ice_lag_chk_disabled_bond(struct ice_lag *lag, void *ptr)
{ struct net_device *netdev = netdev_notifier_info_to_dev(ptr); struct netdev_notifier_changeupper_info *info = ptr; struct ice_lag *prim_lag;
if (netdev != lag->netdev) return;
if (info->linking) {
prim_lag = ice_lag_find_primary(lag); if (prim_lag &&
!ice_is_feature_supported(prim_lag->pf, ICE_F_SRIOV_LAG)) {
ice_clear_feature_support(lag->pf, ICE_F_SRIOV_LAG);
netdev_info(netdev, "Interface added to non-compliant SRIOV LAG aggregate\n");
}
} else {
ice_lag_init_feature_support_flag(lag->pf);
}
}
/** * ice_lag_disable_sriov_bond - set members of bond as not supporting SRIOV LAG * @lag: primary interfaces lag struct
*/ staticvoid ice_lag_disable_sriov_bond(struct ice_lag *lag)
{ struct ice_netdev_priv *np; struct ice_pf *pf;
switch (lag_work->event) { case NETDEV_CHANGEUPPER:
info = &lag_work->info.changeupper_info;
ice_lag_chk_disabled_bond(lag_work->lag, info); if (ice_is_feature_supported(pf, ICE_F_SRIOV_LAG)) {
ice_lag_monitor_link(lag_work->lag, info);
ice_lag_changeupper_event(lag_work->lag, info);
ice_lag_link_unlink(lag_work->lag, info);
}
ice_lag_monitor_rdma(lag_work->lag, info); break; case NETDEV_BONDING_INFO: if (ice_is_feature_supported(pf, ICE_F_SRIOV_LAG)) { if (!ice_lag_chk_comp(lag_work->lag,
&lag_work->info.bonding_info)) {
netdev = lag_work->info.bonding_info.info.dev;
ice_lag_disable_sriov_bond(lag_work->lag);
ice_lag_unregister(lag_work->lag, netdev); goto lag_cleanup;
}
ice_lag_monitor_active(lag_work->lag,
&lag_work->info.bonding_info);
ice_lag_cfg_pf_fltrs(lag_work->lag,
&lag_work->info.bonding_info);
}
ice_lag_info_event(lag_work->lag, &lag_work->info.bonding_info); break; case NETDEV_UNREGISTER: if (ice_is_feature_supported(pf, ICE_F_SRIOV_LAG)) {
netdev = lag_work->info.bonding_info.info.dev; if ((netdev == lag_work->lag->netdev ||
lag_work->lag->primary) && lag_work->lag->bonded)
ice_lag_unregister(lag_work->lag, netdev);
} break; default: break;
}
lag_cleanup: /* cleanup resources allocated for this work item */
list_for_each_safe(tmp, n, &lag_work->netdev_list.node) { struct ice_lag_netdev_list *entry;
/** * ice_create_lag_recipe * @hw: pointer to HW struct * @rid: pointer to u16 to pass back recipe index * @base_recipe: recipe to base the new recipe on * @prio: priority for new recipe * * function returns 0 on error
*/ staticint ice_create_lag_recipe(struct ice_hw *hw, u16 *rid, const u8 *base_recipe, u8 prio)
{ struct ice_aqc_recipe_data_elem *new_rcp; int err;
err = ice_alloc_recipe(hw, rid); if (err) return err;
new_rcp = kzalloc(ICE_RECIPE_LEN * ICE_MAX_NUM_RECIPES, GFP_KERNEL); if (!new_rcp) return -ENOMEM;
/** * ice_lag_move_vf_nodes_tc_sync - move a VF's nodes for a tc during reset * @lag: primary interfaces lag struct * @dest_hw: HW struct for destination's interface * @vsi_num: VSI index in PF space * @tc: traffic class to move
*/ staticvoid
ice_lag_move_vf_nodes_tc_sync(struct ice_lag *lag, struct ice_hw *dest_hw,
u16 vsi_num, u8 tc)
{
DEFINE_RAW_FLEX(struct ice_aqc_move_elem, buf, teid, 1); struct device *dev = ice_pf_to_dev(lag->pf);
u16 numq, valq, num_moved, qbuf_size;
u16 buf_size = __struct_size(buf); struct ice_aqc_cfg_txqs_buf *qbuf; struct ice_sched_node *n_prt;
__le32 teid, parent_teid; struct ice_vsi_ctx *ctx; struct ice_hw *hw;
u32 tmp_teid;
hw = &lag->pf->hw;
ctx = ice_get_vsi_ctx(hw, vsi_num); if (!ctx) {
dev_warn(dev, "LAG rebuild failed after reset due to VSI Context failure\n"); return;
}
if (ice_sched_suspend_resume_elems(hw, 1, &tmp_teid, true))
dev_dbg(dev, "Problem suspending traffic during reset rebuild\n");
/* reconfig queues for new port */
qbuf_size = struct_size(qbuf, queue_info, numq);
qbuf = kzalloc(qbuf_size, GFP_KERNEL); if (!qbuf) {
dev_warn(dev, "Failure allocating VF queue recfg buffer for reset rebuild\n"); goto resume_sync;
}
/* add the per queue info for the reconfigure command buffer */
valq = ice_lag_qbuf_recfg(hw, qbuf, vsi_num, numq, tc); if (!valq) {
dev_warn(dev, "Failure to reconfig queues for LAG reset rebuild\n"); goto sync_none;
}
if (ice_aq_cfg_lan_txq(hw, qbuf, qbuf_size, numq, hw->port_info->lport,
dest_hw->port_info->lport, NULL)) {
dev_warn(dev, "Failure to configure queues for LAG reset rebuild\n"); goto sync_qerr;
}
sync_none:
kfree(qbuf);
/* find parent in destination tree */
n_prt = ice_lag_get_sched_parent(dest_hw, tc); if (!n_prt) goto resume_sync;
if (ice_aq_move_sched_elems(&lag->pf->hw, buf, buf_size, &num_moved))
dev_warn(dev, "Failure to move VF nodes for LAG reset rebuild\n"); else
ice_sched_update_parent(n_prt, ctx->sched.vsi_node[tc]);
goto resume_sync;
sync_qerr:
kfree(qbuf);
resume_sync: if (ice_sched_suspend_resume_elems(hw, 1, &tmp_teid, false))
dev_warn(dev, "Problem restarting traffic for LAG node reset rebuild\n");
}
/** * ice_lag_move_vf_nodes_sync - move vf nodes to active interface * @lag: primary interfaces lag struct * @dest_hw: lport value for currently active port * * This function is used in a reset context, outside of event handling, * to move the VF nodes to the secondary interface when that interface * is the active interface during a reset rebuild
*/ staticvoid
ice_lag_move_vf_nodes_sync(struct ice_lag *lag, struct ice_hw *dest_hw)
{ struct ice_pf *pf; int i, tc;
if (!lag->primary || !dest_hw) return;
pf = lag->pf;
ice_for_each_vsi(pf, i) if (pf->vsi[i] && pf->vsi[i]->type == ICE_VSI_VF)
ice_for_each_traffic_class(tc)
ice_lag_move_vf_nodes_tc_sync(lag, dest_hw, i,
tc);
}
/** * ice_init_lag - initialize support for LAG * @pf: PF struct * * Alloc memory for LAG structs and initialize the elements. * Memory will be freed in ice_deinit_lag
*/ int ice_init_lag(struct ice_pf *pf)
{ struct device *dev = ice_pf_to_dev(pf); struct ice_lag *lag; struct ice_vsi *vsi;
u64 recipe_bits = 0; int n, err;
ice_lag_init_feature_support_flag(pf); if (!ice_is_feature_supported(pf, ICE_F_SRIOV_LAG)) return 0;
pf->lag = kzalloc(sizeof(*lag), GFP_KERNEL); if (!pf->lag) return -ENOMEM;
lag = pf->lag;
vsi = ice_get_main_vsi(pf); if (!vsi) {
dev_err(dev, "couldn't get main vsi, link aggregation init fail\n");
err = -EIO; goto lag_error;
}
err = ice_register_lag_handler(lag); if (err) {
dev_warn(dev, "INIT LAG: Failed to register event handler\n"); goto lag_error;
}
err = ice_create_lag_recipe(&pf->hw, &lag->pf_recipe,
ice_dflt_vsi_rcp, 1); if (err) goto lag_error;
err = ice_create_lag_recipe(&pf->hw, &lag->lport_recipe,
ice_lport_rcp, 3); if (err) goto free_rcp_res;
/* associate recipes to profiles */ for (n = 0; n < ICE_PROFID_IPV6_GTPU_IPV6_TCP_INNER; n++) {
err = ice_aq_get_recipe_to_profile(&pf->hw, n,
&recipe_bits, NULL); if (err) continue;
if (recipe_bits & BIT(ICE_SW_LKUP_DFLT)) {
recipe_bits |= BIT(lag->pf_recipe) |
BIT(lag->lport_recipe);
ice_aq_map_recipe_to_profile(&pf->hw, n,
recipe_bits, NULL);
}
}
/** * ice_deinit_lag - Clean up LAG * @pf: PF struct * * Clean up kernel LAG info and free memory * This function is meant to only be called on driver remove/shutdown
*/ void ice_deinit_lag(struct ice_pf *pf)
{ struct ice_lag *lag;
/** * ice_lag_rebuild - rebuild lag resources after reset * @pf: pointer to local pf struct * * PF resets are promoted to CORER resets when interface in an aggregate. This * means that we need to rebuild the PF resources for the interface. Since * this will happen outside the normal event processing, need to acquire the lag * lock. * * This function will also evaluate the VF resources if this is the primary * interface.
*/ void ice_lag_rebuild(struct ice_pf *pf)
{ struct ice_lag_netdev_list ndlist; struct ice_lag *lag, *prim_lag;
u8 act_port, loc_port;
if (!pf->lag || !pf->lag->bonded) return;
mutex_lock(&pf->lag_mutex);
lag = pf->lag; if (lag->primary) {
prim_lag = lag;
} else {
ice_lag_build_netdev_list(lag, &ndlist);
prim_lag = ice_lag_find_primary(lag);
}
if (!prim_lag) {
dev_dbg(ice_pf_to_dev(pf), "No primary interface in aggregate, can't rebuild\n"); goto lag_rebuild_out;
}
/** * ice_lag_is_switchdev_running * @pf: pointer to PF structure * * Check if switchdev is running on any of the interfaces connected to lag.
*/ bool ice_lag_is_switchdev_running(struct ice_pf *pf)
{ struct ice_lag *lag = pf->lag; struct net_device *tmp_nd;
if (!ice_is_feature_supported(pf, ICE_F_SRIOV_LAG) ||
!lag || !lag->upper_netdev) returnfalse;
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.