Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch '100GbE' of git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/next-queue

Tony Nguyen says:

====================
ice: prepare representor for SF support

Michal Swiatkowski says:

This is a series to prepare port representor for supporting also
subfunctions. We need correct devlink locking and the possibility to
update parent VSI after port representor is created.

Refactor how devlink lock is taken to suite the subfunction use case.

VSI configuration needs to be done after port representor is created.
Port representor needs only allocated VSI. It doesn't need to be
configured before.

VSI needs to be reconfigured when update function is called.

The code for this patchset was split from (too big) patchset [1].

[1] https://lore.kernel.org/netdev/20240213072724.77275-1-michal.swiatkowski@linux.intel.com/
---
Originally from https://lore.kernel.org/netdev/20240605-next-2024-06-03-intel-next-batch-v2-0-39c23963fa78@intel.com/
Changes:
- delete ice_repr_get_by_vsi() from header
- rephrase commit message in moving devlink locking
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+90 -41
-2
drivers/net/ethernet/intel/ice/devlink/devlink.c
··· 794 794 795 795 tc_node = pi->root->children[0]; 796 796 mutex_lock(&pi->sched_lock); 797 - devl_lock(devlink); 798 797 for (i = 0; i < tc_node->num_children; i++) 799 798 ice_traverse_tx_tree(devlink, tc_node->children[i], tc_node, pf); 800 - devl_unlock(devlink); 801 799 mutex_unlock(&pi->sched_lock); 802 800 803 801 return 0;
+61 -24
drivers/net/ethernet/intel/ice/ice_eswitch.c
··· 117 117 struct ice_vsi *vsi = repr->src_vsi; 118 118 struct metadata_dst *dst; 119 119 120 - ice_remove_vsi_fltr(&pf->hw, vsi->idx); 121 120 repr->dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX, 122 121 GFP_KERNEL); 123 122 if (!repr->dst) 124 - goto err_add_mac_fltr; 125 - 126 - if (ice_vsi_update_security(vsi, ice_vsi_ctx_clear_antispoof)) 127 - goto err_dst_free; 128 - 129 - if (ice_vsi_add_vlan_zero(vsi)) 130 - goto err_update_security; 123 + return -ENOMEM; 131 124 132 125 netif_keep_dst(uplink_vsi->netdev); 133 126 ··· 129 136 dst->u.port_info.lower_dev = uplink_vsi->netdev; 130 137 131 138 return 0; 139 + } 132 140 133 - err_update_security: 141 + /** 142 + * ice_eswitch_cfg_vsi - configure VSI to work in slow-path 143 + * @vsi: VSI structure of representee 144 + * @mac: representee MAC 145 + * 146 + * Return: 0 on success, non-zero on error. 147 + */ 148 + int ice_eswitch_cfg_vsi(struct ice_vsi *vsi, const u8 *mac) 149 + { 150 + int err; 151 + 152 + ice_remove_vsi_fltr(&vsi->back->hw, vsi->idx); 153 + 154 + err = ice_vsi_update_security(vsi, ice_vsi_ctx_clear_antispoof); 155 + if (err) 156 + goto err_update_security; 157 + 158 + err = ice_vsi_add_vlan_zero(vsi); 159 + if (err) 160 + goto err_vlan_zero; 161 + 162 + return 0; 163 + 164 + err_vlan_zero: 134 165 ice_vsi_update_security(vsi, ice_vsi_ctx_set_antispoof); 135 - err_dst_free: 136 - metadata_dst_free(repr->dst); 137 - repr->dst = NULL; 138 - err_add_mac_fltr: 139 - ice_fltr_add_mac_and_broadcast(vsi, repr->parent_mac, ICE_FWD_TO_VSI); 166 + err_update_security: 167 + ice_fltr_add_mac_and_broadcast(vsi, mac, ICE_FWD_TO_VSI); 140 168 141 - return -ENODEV; 169 + return err; 170 + } 171 + 172 + /** 173 + * ice_eswitch_decfg_vsi - unroll changes done to VSI for switchdev 174 + * @vsi: VSI structure of representee 175 + * @mac: representee MAC 176 + */ 177 + void ice_eswitch_decfg_vsi(struct ice_vsi *vsi, const u8 *mac) 178 + { 179 + ice_vsi_update_security(vsi, ice_vsi_ctx_set_antispoof); 180 + ice_fltr_add_mac_and_broadcast(vsi, mac, ICE_FWD_TO_VSI); 142 181 } 143 182 144 183 /** ··· 178 153 * @repr_id: representor ID 179 154 * @vsi: VSI for which port representor is configured 180 155 */ 181 - void ice_eswitch_update_repr(unsigned long repr_id, struct ice_vsi *vsi) 156 + void ice_eswitch_update_repr(unsigned long *repr_id, struct ice_vsi *vsi) 182 157 { 183 158 struct ice_pf *pf = vsi->back; 184 159 struct ice_repr *repr; 185 - int ret; 160 + int err; 186 161 187 162 if (!ice_is_switchdev_running(pf)) 188 163 return; 189 164 190 - repr = xa_load(&pf->eswitch.reprs, repr_id); 165 + repr = xa_load(&pf->eswitch.reprs, *repr_id); 191 166 if (!repr) 192 167 return; 193 168 ··· 197 172 if (repr->br_port) 198 173 repr->br_port->vsi = vsi; 199 174 200 - ret = ice_vsi_update_security(vsi, ice_vsi_ctx_clear_antispoof); 201 - if (ret) { 202 - ice_fltr_add_mac_and_broadcast(vsi, repr->parent_mac, 203 - ICE_FWD_TO_VSI); 175 + err = ice_eswitch_cfg_vsi(vsi, repr->parent_mac); 176 + if (err) 204 177 dev_err(ice_pf_to_dev(pf), "Failed to update VSI of port representor %d", 205 178 repr->id); 179 + 180 + /* The VSI number is different, reload the PR with new id */ 181 + if (repr->id != vsi->vsi_num) { 182 + xa_erase(&pf->eswitch.reprs, repr->id); 183 + repr->id = vsi->vsi_num; 184 + if (xa_insert(&pf->eswitch.reprs, repr->id, repr, GFP_KERNEL)) 185 + dev_err(ice_pf_to_dev(pf), "Failed to reload port representor %d", 186 + repr->id); 187 + *repr_id = repr->id; 206 188 } 207 189 } 208 190 ··· 455 423 int 456 424 ice_eswitch_attach(struct ice_pf *pf, struct ice_vf *vf) 457 425 { 426 + struct devlink *devlink = priv_to_devlink(pf); 458 427 struct ice_repr *repr; 459 428 int err; 460 429 ··· 470 437 471 438 ice_eswitch_stop_reprs(pf); 472 439 440 + devl_lock(devlink); 473 441 repr = ice_repr_add_vf(vf); 442 + devl_unlock(devlink); 474 443 if (IS_ERR(repr)) { 475 444 err = PTR_ERR(repr); 476 445 goto err_create_repr; ··· 495 460 err_xa_alloc: 496 461 ice_eswitch_release_repr(pf, repr); 497 462 err_setup_repr: 463 + devl_lock(devlink); 498 464 ice_repr_rem_vf(repr); 465 + devl_unlock(devlink); 499 466 err_create_repr: 500 467 if (xa_empty(&pf->eswitch.reprs)) 501 468 ice_eswitch_disable_switchdev(pf); ··· 521 484 ice_eswitch_disable_switchdev(pf); 522 485 523 486 ice_eswitch_release_repr(pf, repr); 487 + devl_lock(devlink); 524 488 ice_repr_rem_vf(repr); 525 489 526 490 if (xa_empty(&pf->eswitch.reprs)) { ··· 529 491 * no point in keeping the nodes 530 492 */ 531 493 ice_devlink_rate_clear_tx_topology(ice_get_main_vsi(pf)); 532 - devl_lock(devlink); 533 494 devl_rate_nodes_destroy(devlink); 534 - devl_unlock(devlink); 535 495 } else { 536 496 ice_eswitch_start_reprs(pf); 537 497 } 498 + devl_unlock(devlink); 538 499 } 539 500 540 501 /**
+12 -2
drivers/net/ethernet/intel/ice/ice_eswitch.h
··· 18 18 struct netlink_ext_ack *extack); 19 19 bool ice_is_eswitch_mode_switchdev(struct ice_pf *pf); 20 20 21 - void ice_eswitch_update_repr(unsigned long repr_id, struct ice_vsi *vsi); 21 + void ice_eswitch_update_repr(unsigned long *repr_id, struct ice_vsi *vsi); 22 22 23 23 void ice_eswitch_stop_all_tx_queues(struct ice_pf *pf); 24 24 ··· 28 28 ice_eswitch_port_start_xmit(struct sk_buff *skb, struct net_device *netdev); 29 29 struct net_device *ice_eswitch_get_target(struct ice_rx_ring *rx_ring, 30 30 union ice_32b_rx_flex_desc *rx_desc); 31 + 32 + int ice_eswitch_cfg_vsi(struct ice_vsi *vsi, const u8 *mac); 33 + void ice_eswitch_decfg_vsi(struct ice_vsi *vsi, const u8 *mac); 31 34 #else /* CONFIG_ICE_SWITCHDEV */ 32 35 static inline void ice_eswitch_detach(struct ice_pf *pf, struct ice_vf *vf) { } 33 36 ··· 47 44 struct ice_tx_offload_params *off) { } 48 45 49 46 static inline void 50 - ice_eswitch_update_repr(unsigned long repr_id, struct ice_vsi *vsi) { } 47 + ice_eswitch_update_repr(unsigned long *repr_id, struct ice_vsi *vsi) { } 51 48 52 49 static inline int ice_eswitch_configure(struct ice_pf *pf) 53 50 { ··· 88 85 { 89 86 return rx_ring->netdev; 90 87 } 88 + 89 + static inline int ice_eswitch_cfg_vsi(struct ice_vsi *vsi, const u8 *mac) 90 + { 91 + return -EOPNOTSUPP; 92 + } 93 + 94 + static inline void ice_eswitch_decfg_vsi(struct ice_vsi *vsi, const u8 *mac) { } 91 95 #endif /* CONFIG_ICE_SWITCHDEV */ 92 96 #endif /* _ICE_ESWITCH_H_ */
+3 -1
drivers/net/ethernet/intel/ice/ice_eswitch_br.c
··· 896 896 if (br_port->type == ICE_ESWITCH_BR_UPLINK_PORT && vsi->back) { 897 897 vsi->back->br_port = NULL; 898 898 } else { 899 - struct ice_repr *repr = ice_repr_get_by_vsi(vsi); 899 + struct ice_repr *repr = 900 + ice_repr_get(vsi->back, br_port->repr_id); 900 901 901 902 if (repr) 902 903 repr->br_port = NULL; ··· 938 937 br_port->vsi = repr->src_vsi; 939 938 br_port->vsi_idx = br_port->vsi->idx; 940 939 br_port->type = ICE_ESWITCH_BR_VF_REPR_PORT; 940 + br_port->repr_id = repr->id; 941 941 repr->br_port = br_port; 942 942 943 943 err = xa_insert(&bridge->ports, br_port->vsi_idx, br_port, GFP_KERNEL);
+1
drivers/net/ethernet/intel/ice/ice_eswitch_br.h
··· 46 46 enum ice_esw_br_port_type type; 47 47 u16 vsi_idx; 48 48 u16 pvid; 49 + u32 repr_id; 49 50 struct xarray vlans; 50 51 }; 51 52
+9 -7
drivers/net/ethernet/intel/ice/ice_repr.c
··· 285 285 286 286 static void ice_repr_remove_node(struct devlink_port *devlink_port) 287 287 { 288 - devl_lock(devlink_port->devlink); 289 288 devl_rate_leaf_destroy(devlink_port); 290 - devl_unlock(devlink_port->devlink); 291 289 } 292 290 293 291 /** ··· 306 308 void ice_repr_rem_vf(struct ice_repr *repr) 307 309 { 308 310 ice_repr_remove_node(&repr->vf->devlink_port); 311 + ice_eswitch_decfg_vsi(repr->src_vsi, repr->parent_mac); 309 312 unregister_netdev(repr->netdev); 310 313 ice_devlink_destroy_vf_port(repr->vf); 311 314 ice_virtchnl_set_dflt_ops(repr->vf); ··· 402 403 if (err) 403 404 goto err_netdev; 404 405 406 + err = ice_eswitch_cfg_vsi(repr->src_vsi, repr->parent_mac); 407 + if (err) 408 + goto err_cfg_vsi; 409 + 405 410 ice_virtchnl_set_repr_ops(vf); 406 411 ice_repr_set_tx_topology(vf->pf); 407 412 408 413 return repr; 409 414 415 + err_cfg_vsi: 416 + unregister_netdev(repr->netdev); 410 417 err_netdev: 411 418 ice_repr_rem(repr); 412 419 err_repr_add: ··· 420 415 return ERR_PTR(err); 421 416 } 422 417 423 - struct ice_repr *ice_repr_get_by_vsi(struct ice_vsi *vsi) 418 + struct ice_repr *ice_repr_get(struct ice_pf *pf, u32 id) 424 419 { 425 - if (!vsi->vf) 426 - return NULL; 427 - 428 - return xa_load(&vsi->back->eswitch.reprs, vsi->vf->repr_id); 420 + return xa_load(&pf->eswitch.reprs, id); 429 421 } 430 422 431 423 /**
+1 -2
drivers/net/ethernet/intel/ice/ice_repr.h
··· 35 35 struct ice_repr *ice_netdev_to_repr(const struct net_device *netdev); 36 36 bool ice_is_port_repr_netdev(const struct net_device *netdev); 37 37 38 - struct ice_repr *ice_repr_get_by_vsi(struct ice_vsi *vsi); 39 - 40 38 void ice_repr_inc_tx_stats(struct ice_repr *repr, unsigned int len, 41 39 int xmit_status); 42 40 void ice_repr_inc_rx_stats(struct net_device *netdev, unsigned int len); 41 + struct ice_repr *ice_repr_get(struct ice_pf *pf, u32 id); 43 42 #endif
+1 -1
drivers/net/ethernet/intel/ice/ice_vf_lib.c
··· 948 948 goto out_unlock; 949 949 } 950 950 951 - ice_eswitch_update_repr(vf->repr_id, vsi); 951 + ice_eswitch_update_repr(&vf->repr_id, vsi); 952 952 953 953 /* if the VF has been reset allow it to come up again */ 954 954 ice_mbx_clear_malvf(&vf->mbx_info);