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

Configure Feed

Select the types of activity you want to include in your feed.

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

Tony Nguyen says:

====================
net: implement devlink reload in ice

Michal Swiatkowski says:

This is a part of changes done in patchset [0]. Resource management is
kind of controversial part, so I split it into two patchsets.

It is the first one, covering refactor and implement reload API call.
The refactor will unblock some of the patches needed by SIOV or
subfunction.

Most of this patchset is about implementing driver reload mechanism.
Part of code from probe and rebuild is used to not duplicate code.
To allow this reuse probe and rebuild path are split into smaller
functions.

Patch "ice: split ice_vsi_setup into smaller functions" changes
boolean variable in function call to integer and adds define
for it. Instead of having the function called with true/false now it
can be called with readable defines ICE_VSI_FLAG_INIT or
ICE_VSI_FLAG_NO_INIT. It was suggested by Jacob Keller and probably this
mechanism will be implemented across ice driver in follow up patchset.

Previously the code was reviewed here [0].

[0] https://lore.kernel.org/netdev/Y3ckRWtAtZU1BdXm@unreal/T/#m3bb8feba0a62f9b4cd54cd94917b7e2143fc2ecd

====================

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

+1207 -1032
+4 -2
drivers/net/ethernet/intel/ice/ice.h
··· 353 353 354 354 struct ice_vf *vf; /* VF associated with this VSI */ 355 355 356 - u16 ethtype; /* Ethernet protocol for pause frame */ 357 356 u16 num_gfltr; 358 357 u16 num_bfltr; 359 358 ··· 888 889 int ice_up(struct ice_vsi *vsi); 889 890 int ice_down(struct ice_vsi *vsi); 890 891 int ice_down_up(struct ice_vsi *vsi); 891 - int ice_vsi_cfg(struct ice_vsi *vsi); 892 + int ice_vsi_cfg_lan(struct ice_vsi *vsi); 892 893 struct ice_vsi *ice_lb_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi); 893 894 int ice_vsi_determine_xdp_res(struct ice_vsi *vsi); 894 895 int ice_prepare_xdp_rings(struct ice_vsi *vsi, struct bpf_prog *prog); ··· 906 907 int ice_plug_aux_dev(struct ice_pf *pf); 907 908 void ice_unplug_aux_dev(struct ice_pf *pf); 908 909 int ice_init_rdma(struct ice_pf *pf); 910 + void ice_deinit_rdma(struct ice_pf *pf); 909 911 const char *ice_aq_str(enum ice_aq_err aq_err); 910 912 bool ice_is_wol_supported(struct ice_hw *hw); 911 913 void ice_fdir_del_all_fltrs(struct ice_vsi *vsi); ··· 931 931 int ice_open_internal(struct net_device *netdev); 932 932 int ice_stop(struct net_device *netdev); 933 933 void ice_service_task_schedule(struct ice_pf *pf); 934 + int ice_load(struct ice_pf *pf); 935 + void ice_unload(struct ice_pf *pf); 934 936 935 937 /** 936 938 * ice_set_rdma_cap - enable RDMA support
+4 -7
drivers/net/ethernet/intel/ice/ice_common.c
··· 1088 1088 if (status) 1089 1089 goto err_unroll_cqinit; 1090 1090 1091 - hw->port_info = devm_kzalloc(ice_hw_to_dev(hw), 1092 - sizeof(*hw->port_info), GFP_KERNEL); 1091 + if (!hw->port_info) 1092 + hw->port_info = devm_kzalloc(ice_hw_to_dev(hw), 1093 + sizeof(*hw->port_info), 1094 + GFP_KERNEL); 1093 1095 if (!hw->port_info) { 1094 1096 status = -ENOMEM; 1095 1097 goto err_unroll_cqinit; ··· 1218 1216 ice_free_seg(hw); 1219 1217 ice_free_hw_tbls(hw); 1220 1218 mutex_destroy(&hw->tnl_lock); 1221 - 1222 - if (hw->port_info) { 1223 - devm_kfree(ice_hw_to_dev(hw), hw->port_info); 1224 - hw->port_info = NULL; 1225 - } 1226 1219 1227 1220 /* Attempt to disable FW logging before shutting down control queues */ 1228 1221 ice_cfg_fw_log(hw, false);
+81 -22
drivers/net/ethernet/intel/ice/ice_devlink.c
··· 371 371 372 372 /** 373 373 * ice_devlink_reload_empr_start - Start EMP reset to activate new firmware 374 - * @devlink: pointer to the devlink instance to reload 375 - * @netns_change: if true, the network namespace is changing 376 - * @action: the action to perform. Must be DEVLINK_RELOAD_ACTION_FW_ACTIVATE 377 - * @limit: limits on what reload should do, such as not resetting 374 + * @pf: pointer to the pf instance 378 375 * @extack: netlink extended ACK structure 379 376 * 380 377 * Allow user to activate new Embedded Management Processor firmware by ··· 384 387 * any source. 385 388 */ 386 389 static int 387 - ice_devlink_reload_empr_start(struct devlink *devlink, bool netns_change, 388 - enum devlink_reload_action action, 389 - enum devlink_reload_limit limit, 390 + ice_devlink_reload_empr_start(struct ice_pf *pf, 390 391 struct netlink_ext_ack *extack) 391 392 { 392 - struct ice_pf *pf = devlink_priv(devlink); 393 393 struct device *dev = ice_pf_to_dev(pf); 394 394 struct ice_hw *hw = &pf->hw; 395 395 u8 pending; ··· 425 431 } 426 432 427 433 /** 434 + * ice_devlink_reload_down - prepare for reload 435 + * @devlink: pointer to the devlink instance to reload 436 + * @netns_change: if true, the network namespace is changing 437 + * @action: the action to perform 438 + * @limit: limits on what reload should do, such as not resetting 439 + * @extack: netlink extended ACK structure 440 + */ 441 + static int 442 + ice_devlink_reload_down(struct devlink *devlink, bool netns_change, 443 + enum devlink_reload_action action, 444 + enum devlink_reload_limit limit, 445 + struct netlink_ext_ack *extack) 446 + { 447 + struct ice_pf *pf = devlink_priv(devlink); 448 + 449 + switch (action) { 450 + case DEVLINK_RELOAD_ACTION_DRIVER_REINIT: 451 + if (ice_is_eswitch_mode_switchdev(pf)) { 452 + NL_SET_ERR_MSG_MOD(extack, 453 + "Go to legacy mode before doing reinit\n"); 454 + return -EOPNOTSUPP; 455 + } 456 + if (ice_is_adq_active(pf)) { 457 + NL_SET_ERR_MSG_MOD(extack, 458 + "Turn off ADQ before doing reinit\n"); 459 + return -EOPNOTSUPP; 460 + } 461 + if (ice_has_vfs(pf)) { 462 + NL_SET_ERR_MSG_MOD(extack, 463 + "Remove all VFs before doing reinit\n"); 464 + return -EOPNOTSUPP; 465 + } 466 + ice_unload(pf); 467 + return 0; 468 + case DEVLINK_RELOAD_ACTION_FW_ACTIVATE: 469 + return ice_devlink_reload_empr_start(pf, extack); 470 + default: 471 + WARN_ON(1); 472 + return -EOPNOTSUPP; 473 + } 474 + } 475 + 476 + /** 428 477 * ice_devlink_reload_empr_finish - Wait for EMP reset to finish 429 - * @devlink: pointer to the devlink instance reloading 430 - * @action: the action requested 431 - * @limit: limits imposed by userspace, such as not resetting 432 - * @actions_performed: on return, indicate what actions actually performed 478 + * @pf: pointer to the pf instance 433 479 * @extack: netlink extended ACK structure 434 480 * 435 481 * Wait for driver to finish rebuilding after EMP reset is completed. This ··· 477 443 * for the driver's rebuild to complete. 478 444 */ 479 445 static int 480 - ice_devlink_reload_empr_finish(struct devlink *devlink, 481 - enum devlink_reload_action action, 482 - enum devlink_reload_limit limit, 483 - u32 *actions_performed, 446 + ice_devlink_reload_empr_finish(struct ice_pf *pf, 484 447 struct netlink_ext_ack *extack) 485 448 { 486 - struct ice_pf *pf = devlink_priv(devlink); 487 449 int err; 488 - 489 - *actions_performed = BIT(DEVLINK_RELOAD_ACTION_FW_ACTIVATE); 490 450 491 451 err = ice_wait_for_reset(pf, 60 * HZ); 492 452 if (err) { ··· 1220 1192 return status; 1221 1193 } 1222 1194 1195 + /** 1196 + * ice_devlink_reload_up - do reload up after reinit 1197 + * @devlink: pointer to the devlink instance reloading 1198 + * @action: the action requested 1199 + * @limit: limits imposed by userspace, such as not resetting 1200 + * @actions_performed: on return, indicate what actions actually performed 1201 + * @extack: netlink extended ACK structure 1202 + */ 1203 + static int 1204 + ice_devlink_reload_up(struct devlink *devlink, 1205 + enum devlink_reload_action action, 1206 + enum devlink_reload_limit limit, 1207 + u32 *actions_performed, 1208 + struct netlink_ext_ack *extack) 1209 + { 1210 + struct ice_pf *pf = devlink_priv(devlink); 1211 + 1212 + switch (action) { 1213 + case DEVLINK_RELOAD_ACTION_DRIVER_REINIT: 1214 + *actions_performed = BIT(DEVLINK_RELOAD_ACTION_DRIVER_REINIT); 1215 + return ice_load(pf); 1216 + case DEVLINK_RELOAD_ACTION_FW_ACTIVATE: 1217 + *actions_performed = BIT(DEVLINK_RELOAD_ACTION_FW_ACTIVATE); 1218 + return ice_devlink_reload_empr_finish(pf, extack); 1219 + default: 1220 + WARN_ON(1); 1221 + return -EOPNOTSUPP; 1222 + } 1223 + } 1224 + 1223 1225 static const struct devlink_ops ice_devlink_ops = { 1224 1226 .supported_flash_update_params = DEVLINK_SUPPORT_FLASH_UPDATE_OVERWRITE_MASK, 1225 - .reload_actions = BIT(DEVLINK_RELOAD_ACTION_FW_ACTIVATE), 1227 + .reload_actions = BIT(DEVLINK_RELOAD_ACTION_DRIVER_REINIT) | 1228 + BIT(DEVLINK_RELOAD_ACTION_FW_ACTIVATE), 1226 1229 /* The ice driver currently does not support driver reinit */ 1227 - .reload_down = ice_devlink_reload_empr_start, 1228 - .reload_up = ice_devlink_reload_empr_finish, 1230 + .reload_down = ice_devlink_reload_down, 1231 + .reload_up = ice_devlink_reload_up, 1229 1232 .port_split = ice_devlink_port_split, 1230 1233 .port_unsplit = ice_devlink_port_unsplit, 1231 1234 .eswitch_mode_get = ice_eswitch_mode_get,
+1 -1
drivers/net/ethernet/intel/ice/ice_ethtool.c
··· 656 656 if (status) 657 657 goto err_setup_rx_ring; 658 658 659 - status = ice_vsi_cfg(vsi); 659 + status = ice_vsi_cfg_lan(vsi); 660 660 if (status) 661 661 goto err_setup_rx_ring; 662 662
+5
drivers/net/ethernet/intel/ice/ice_fltr.c
··· 208 208 void ice_fltr_remove_all(struct ice_vsi *vsi) 209 209 { 210 210 ice_remove_vsi_fltr(&vsi->back->hw, vsi->idx); 211 + /* sync netdev filters if exist */ 212 + if (vsi->netdev) { 213 + __dev_uc_unsync(vsi->netdev, NULL); 214 + __dev_mc_unsync(vsi->netdev, NULL); 215 + } 211 216 } 212 217 213 218 /**
+51 -2
drivers/net/ethernet/intel/ice/ice_idc.c
··· 6 6 #include "ice_lib.h" 7 7 #include "ice_dcb_lib.h" 8 8 9 + static DEFINE_XARRAY_ALLOC1(ice_aux_id); 10 + 9 11 /** 10 12 * ice_get_auxiliary_drv - retrieve iidc_auxiliary_drv struct 11 13 * @pf: pointer to PF struct ··· 248 246 } 249 247 250 248 /** 249 + * ice_free_rdma_qvector - free vector resources reserved for RDMA driver 250 + * @pf: board private structure to initialize 251 + */ 252 + static void ice_free_rdma_qvector(struct ice_pf *pf) 253 + { 254 + pf->num_avail_sw_msix -= pf->num_rdma_msix; 255 + ice_free_res(pf->irq_tracker, pf->rdma_base_vector, 256 + ICE_RES_RDMA_VEC_ID); 257 + } 258 + 259 + /** 251 260 * ice_adev_release - function to be mapped to AUX dev's release op 252 261 * @dev: pointer to device to free 253 262 */ ··· 344 331 struct device *dev = &pf->pdev->dev; 345 332 int ret; 346 333 334 + if (!ice_is_rdma_ena(pf)) { 335 + dev_warn(dev, "RDMA is not supported on this device\n"); 336 + return 0; 337 + } 338 + 339 + ret = xa_alloc(&ice_aux_id, &pf->aux_idx, NULL, XA_LIMIT(1, INT_MAX), 340 + GFP_KERNEL); 341 + if (ret) { 342 + dev_err(dev, "Failed to allocate device ID for AUX driver\n"); 343 + return -ENOMEM; 344 + } 345 + 347 346 /* Reserve vector resources */ 348 347 ret = ice_reserve_rdma_qvector(pf); 349 348 if (ret < 0) { 350 349 dev_err(dev, "failed to reserve vectors for RDMA\n"); 351 - return ret; 350 + goto err_reserve_rdma_qvector; 352 351 } 353 352 pf->rdma_mode |= IIDC_RDMA_PROTOCOL_ROCEV2; 354 - return ice_plug_aux_dev(pf); 353 + ret = ice_plug_aux_dev(pf); 354 + if (ret) 355 + goto err_plug_aux_dev; 356 + return 0; 357 + 358 + err_plug_aux_dev: 359 + ice_free_rdma_qvector(pf); 360 + err_reserve_rdma_qvector: 361 + pf->adev = NULL; 362 + xa_erase(&ice_aux_id, pf->aux_idx); 363 + return ret; 364 + } 365 + 366 + /** 367 + * ice_deinit_rdma - deinitialize RDMA on PF 368 + * @pf: ptr to ice_pf 369 + */ 370 + void ice_deinit_rdma(struct ice_pf *pf) 371 + { 372 + if (!ice_is_rdma_ena(pf)) 373 + return; 374 + 375 + ice_unplug_aux_dev(pf); 376 + ice_free_rdma_qvector(pf); 377 + xa_erase(&ice_aux_id, pf->aux_idx); 355 378 }
+437 -530
drivers/net/ethernet/intel/ice/ice_lib.c
··· 282 282 } 283 283 284 284 /** 285 - * ice_vsi_delete - delete a VSI from the switch 285 + * ice_vsi_delete_from_hw - delete a VSI from the switch 286 286 * @vsi: pointer to VSI being removed 287 287 */ 288 - void ice_vsi_delete(struct ice_vsi *vsi) 288 + static void ice_vsi_delete_from_hw(struct ice_vsi *vsi) 289 289 { 290 290 struct ice_pf *pf = vsi->back; 291 291 struct ice_vsi_ctx *ctxt; ··· 348 348 } 349 349 350 350 /** 351 - * ice_vsi_clear - clean up and deallocate the provided VSI 351 + * ice_vsi_free_stats - Free the ring statistics structures 352 + * @vsi: VSI pointer 353 + */ 354 + static void ice_vsi_free_stats(struct ice_vsi *vsi) 355 + { 356 + struct ice_vsi_stats *vsi_stat; 357 + struct ice_pf *pf = vsi->back; 358 + int i; 359 + 360 + if (vsi->type == ICE_VSI_CHNL) 361 + return; 362 + if (!pf->vsi_stats) 363 + return; 364 + 365 + vsi_stat = pf->vsi_stats[vsi->idx]; 366 + if (!vsi_stat) 367 + return; 368 + 369 + ice_for_each_alloc_txq(vsi, i) { 370 + if (vsi_stat->tx_ring_stats[i]) { 371 + kfree_rcu(vsi_stat->tx_ring_stats[i], rcu); 372 + WRITE_ONCE(vsi_stat->tx_ring_stats[i], NULL); 373 + } 374 + } 375 + 376 + ice_for_each_alloc_rxq(vsi, i) { 377 + if (vsi_stat->rx_ring_stats[i]) { 378 + kfree_rcu(vsi_stat->rx_ring_stats[i], rcu); 379 + WRITE_ONCE(vsi_stat->rx_ring_stats[i], NULL); 380 + } 381 + } 382 + 383 + kfree(vsi_stat->tx_ring_stats); 384 + kfree(vsi_stat->rx_ring_stats); 385 + kfree(vsi_stat); 386 + pf->vsi_stats[vsi->idx] = NULL; 387 + } 388 + 389 + /** 390 + * ice_vsi_alloc_ring_stats - Allocates Tx and Rx ring stats for the VSI 391 + * @vsi: VSI which is having stats allocated 392 + */ 393 + static int ice_vsi_alloc_ring_stats(struct ice_vsi *vsi) 394 + { 395 + struct ice_ring_stats **tx_ring_stats; 396 + struct ice_ring_stats **rx_ring_stats; 397 + struct ice_vsi_stats *vsi_stats; 398 + struct ice_pf *pf = vsi->back; 399 + u16 i; 400 + 401 + vsi_stats = pf->vsi_stats[vsi->idx]; 402 + tx_ring_stats = vsi_stats->tx_ring_stats; 403 + rx_ring_stats = vsi_stats->rx_ring_stats; 404 + 405 + /* Allocate Tx ring stats */ 406 + ice_for_each_alloc_txq(vsi, i) { 407 + struct ice_ring_stats *ring_stats; 408 + struct ice_tx_ring *ring; 409 + 410 + ring = vsi->tx_rings[i]; 411 + ring_stats = tx_ring_stats[i]; 412 + 413 + if (!ring_stats) { 414 + ring_stats = kzalloc(sizeof(*ring_stats), GFP_KERNEL); 415 + if (!ring_stats) 416 + goto err_out; 417 + 418 + WRITE_ONCE(tx_ring_stats[i], ring_stats); 419 + } 420 + 421 + ring->ring_stats = ring_stats; 422 + } 423 + 424 + /* Allocate Rx ring stats */ 425 + ice_for_each_alloc_rxq(vsi, i) { 426 + struct ice_ring_stats *ring_stats; 427 + struct ice_rx_ring *ring; 428 + 429 + ring = vsi->rx_rings[i]; 430 + ring_stats = rx_ring_stats[i]; 431 + 432 + if (!ring_stats) { 433 + ring_stats = kzalloc(sizeof(*ring_stats), GFP_KERNEL); 434 + if (!ring_stats) 435 + goto err_out; 436 + 437 + WRITE_ONCE(rx_ring_stats[i], ring_stats); 438 + } 439 + 440 + ring->ring_stats = ring_stats; 441 + } 442 + 443 + return 0; 444 + 445 + err_out: 446 + ice_vsi_free_stats(vsi); 447 + return -ENOMEM; 448 + } 449 + 450 + /** 451 + * ice_vsi_free - clean up and deallocate the provided VSI 352 452 * @vsi: pointer to VSI being cleared 353 453 * 354 454 * This deallocates the VSI's queue resources, removes it from the PF's 355 455 * VSI array if necessary, and deallocates the VSI 356 - * 357 - * Returns 0 on success, negative on failure 358 456 */ 359 - int ice_vsi_clear(struct ice_vsi *vsi) 457 + static void ice_vsi_free(struct ice_vsi *vsi) 360 458 { 361 459 struct ice_pf *pf = NULL; 362 460 struct device *dev; 363 461 364 - if (!vsi) 365 - return 0; 366 - 367 - if (!vsi->back) 368 - return -EINVAL; 462 + if (!vsi || !vsi->back) 463 + return; 369 464 370 465 pf = vsi->back; 371 466 dev = ice_pf_to_dev(pf); 372 467 373 468 if (!pf->vsi[vsi->idx] || pf->vsi[vsi->idx] != vsi) { 374 469 dev_dbg(dev, "vsi does not exist at pf->vsi[%d]\n", vsi->idx); 375 - return -EINVAL; 470 + return; 376 471 } 377 472 378 473 mutex_lock(&pf->sw_mutex); 379 474 /* updates the PF for this cleared VSI */ 380 475 381 476 pf->vsi[vsi->idx] = NULL; 382 - if (vsi->idx < pf->next_vsi && vsi->type != ICE_VSI_CTRL) 383 - pf->next_vsi = vsi->idx; 384 - if (vsi->idx < pf->next_vsi && vsi->type == ICE_VSI_CTRL && vsi->vf) 385 - pf->next_vsi = vsi->idx; 477 + pf->next_vsi = vsi->idx; 386 478 479 + ice_vsi_free_stats(vsi); 387 480 ice_vsi_free_arrays(vsi); 388 481 mutex_unlock(&pf->sw_mutex); 389 482 devm_kfree(dev, vsi); 483 + } 390 484 391 - return 0; 485 + void ice_vsi_delete(struct ice_vsi *vsi) 486 + { 487 + ice_vsi_delete_from_hw(vsi); 488 + ice_vsi_free(vsi); 392 489 } 393 490 394 491 /** ··· 558 461 if (!pf->vsi_stats) 559 462 return -ENOENT; 560 463 464 + if (pf->vsi_stats[vsi->idx]) 465 + /* realloc will happen in rebuild path */ 466 + return 0; 467 + 561 468 vsi_stat = kzalloc(sizeof(*vsi_stat), GFP_KERNEL); 562 469 if (!vsi_stat) 563 470 return -ENOMEM; ··· 592 491 } 593 492 594 493 /** 494 + * ice_vsi_alloc_def - set default values for already allocated VSI 495 + * @vsi: ptr to VSI 496 + * @vf: VF for ICE_VSI_VF and ICE_VSI_CTRL 497 + * @ch: ptr to channel 498 + */ 499 + static int 500 + ice_vsi_alloc_def(struct ice_vsi *vsi, struct ice_vf *vf, 501 + struct ice_channel *ch) 502 + { 503 + if (vsi->type != ICE_VSI_CHNL) { 504 + ice_vsi_set_num_qs(vsi, vf); 505 + if (ice_vsi_alloc_arrays(vsi)) 506 + return -ENOMEM; 507 + } 508 + 509 + switch (vsi->type) { 510 + case ICE_VSI_SWITCHDEV_CTRL: 511 + /* Setup eswitch MSIX irq handler for VSI */ 512 + vsi->irq_handler = ice_eswitch_msix_clean_rings; 513 + break; 514 + case ICE_VSI_PF: 515 + /* Setup default MSIX irq handler for VSI */ 516 + vsi->irq_handler = ice_msix_clean_rings; 517 + break; 518 + case ICE_VSI_CTRL: 519 + /* Setup ctrl VSI MSIX irq handler */ 520 + vsi->irq_handler = ice_msix_clean_ctrl_vsi; 521 + break; 522 + case ICE_VSI_CHNL: 523 + if (!ch) 524 + return -EINVAL; 525 + 526 + vsi->num_rxq = ch->num_rxq; 527 + vsi->num_txq = ch->num_txq; 528 + vsi->next_base_q = ch->base_q; 529 + break; 530 + case ICE_VSI_VF: 531 + break; 532 + default: 533 + ice_vsi_free_arrays(vsi); 534 + return -EINVAL; 535 + } 536 + 537 + return 0; 538 + } 539 + 540 + /** 595 541 * ice_vsi_alloc - Allocates the next available struct VSI in the PF 596 542 * @pf: board private structure 543 + * @pi: pointer to the port_info instance 597 544 * @vsi_type: type of VSI 598 545 * @ch: ptr to channel 599 546 * @vf: VF for ICE_VSI_VF and ICE_VSI_CTRL ··· 653 504 * returns a pointer to a VSI on success, NULL on failure. 654 505 */ 655 506 static struct ice_vsi * 656 - ice_vsi_alloc(struct ice_pf *pf, enum ice_vsi_type vsi_type, 657 - struct ice_channel *ch, struct ice_vf *vf) 507 + ice_vsi_alloc(struct ice_pf *pf, struct ice_port_info *pi, 508 + enum ice_vsi_type vsi_type, struct ice_channel *ch, 509 + struct ice_vf *vf) 658 510 { 659 511 struct device *dev = ice_pf_to_dev(pf); 660 512 struct ice_vsi *vsi = NULL; ··· 681 531 682 532 vsi->type = vsi_type; 683 533 vsi->back = pf; 534 + vsi->port_info = pi; 535 + /* For VSIs which don't have a connected VF, this will be NULL */ 536 + vsi->vf = vf; 684 537 set_bit(ICE_VSI_DOWN, vsi->state); 685 538 686 - if (vsi_type == ICE_VSI_VF) 687 - ice_vsi_set_num_qs(vsi, vf); 688 - else if (vsi_type != ICE_VSI_CHNL) 689 - ice_vsi_set_num_qs(vsi, NULL); 539 + /* fill slot and make note of the index */ 540 + vsi->idx = pf->next_vsi; 541 + pf->vsi[pf->next_vsi] = vsi; 690 542 691 - switch (vsi->type) { 692 - case ICE_VSI_SWITCHDEV_CTRL: 693 - if (ice_vsi_alloc_arrays(vsi)) 694 - goto err_rings; 543 + /* prepare pf->next_vsi for next use */ 544 + pf->next_vsi = ice_get_free_slot(pf->vsi, pf->num_alloc_vsi, 545 + pf->next_vsi); 695 546 696 - /* Setup eswitch MSIX irq handler for VSI */ 697 - vsi->irq_handler = ice_eswitch_msix_clean_rings; 698 - break; 699 - case ICE_VSI_PF: 700 - if (ice_vsi_alloc_arrays(vsi)) 701 - goto err_rings; 702 - 703 - /* Setup default MSIX irq handler for VSI */ 704 - vsi->irq_handler = ice_msix_clean_rings; 705 - break; 706 - case ICE_VSI_CTRL: 707 - if (ice_vsi_alloc_arrays(vsi)) 708 - goto err_rings; 709 - 710 - /* Setup ctrl VSI MSIX irq handler */ 711 - vsi->irq_handler = ice_msix_clean_ctrl_vsi; 712 - 713 - /* For the PF control VSI this is NULL, for the VF control VSI 714 - * this will be the first VF to allocate it. 715 - */ 716 - vsi->vf = vf; 717 - break; 718 - case ICE_VSI_VF: 719 - if (ice_vsi_alloc_arrays(vsi)) 720 - goto err_rings; 721 - vsi->vf = vf; 722 - break; 723 - case ICE_VSI_CHNL: 724 - if (!ch) 725 - goto err_rings; 726 - vsi->num_rxq = ch->num_rxq; 727 - vsi->num_txq = ch->num_txq; 728 - vsi->next_base_q = ch->base_q; 729 - break; 730 - case ICE_VSI_LB: 731 - if (ice_vsi_alloc_arrays(vsi)) 732 - goto err_rings; 733 - break; 734 - default: 735 - dev_warn(dev, "Unknown VSI type %d\n", vsi->type); 736 - goto unlock_pf; 547 + if (vsi->type == ICE_VSI_CTRL) { 548 + if (vf) { 549 + vf->ctrl_vsi_idx = vsi->idx; 550 + } else { 551 + WARN_ON(pf->ctrl_vsi_idx != ICE_NO_VSI); 552 + pf->ctrl_vsi_idx = vsi->idx; 553 + } 737 554 } 738 555 739 - if (vsi->type == ICE_VSI_CTRL && !vf) { 740 - /* Use the last VSI slot as the index for PF control VSI */ 741 - vsi->idx = pf->num_alloc_vsi - 1; 742 - pf->ctrl_vsi_idx = vsi->idx; 743 - pf->vsi[vsi->idx] = vsi; 744 - } else { 745 - /* fill slot and make note of the index */ 746 - vsi->idx = pf->next_vsi; 747 - pf->vsi[pf->next_vsi] = vsi; 748 - 749 - /* prepare pf->next_vsi for next use */ 750 - pf->next_vsi = ice_get_free_slot(pf->vsi, pf->num_alloc_vsi, 751 - pf->next_vsi); 752 - } 753 - 754 - if (vsi->type == ICE_VSI_CTRL && vf) 755 - vf->ctrl_vsi_idx = vsi->idx; 756 - 757 - /* allocate memory for Tx/Rx ring stat pointers */ 758 - if (ice_vsi_alloc_stat_arrays(vsi)) 759 - goto err_rings; 760 - 761 - goto unlock_pf; 762 - 763 - err_rings: 764 - devm_kfree(dev, vsi); 765 - vsi = NULL; 766 556 unlock_pf: 767 557 mutex_unlock(&pf->sw_mutex); 768 558 return vsi; ··· 1267 1177 /** 1268 1178 * ice_vsi_init - Create and initialize a VSI 1269 1179 * @vsi: the VSI being configured 1270 - * @init_vsi: is this call creating a VSI 1180 + * @init_vsi: flag, tell if VSI need to be initialized 1271 1181 * 1272 1182 * This initializes a VSI context depending on the VSI type to be added and 1273 1183 * passes it down to the add_vsi aq command to create a new VSI. 1274 1184 */ 1275 - static int ice_vsi_init(struct ice_vsi *vsi, bool init_vsi) 1185 + static int ice_vsi_init(struct ice_vsi *vsi, int init_vsi) 1276 1186 { 1277 1187 struct ice_pf *pf = vsi->back; 1278 1188 struct ice_hw *hw = &pf->hw; ··· 1334 1244 /* if updating VSI context, make sure to set valid_section: 1335 1245 * to indicate which section of VSI context being updated 1336 1246 */ 1337 - if (!init_vsi) 1247 + if (!(init_vsi & ICE_VSI_FLAG_INIT)) 1338 1248 ctxt->info.valid_sections |= 1339 1249 cpu_to_le16(ICE_AQ_VSI_PROP_Q_OPT_VALID); 1340 1250 } ··· 1347 1257 if (ret) 1348 1258 goto out; 1349 1259 1350 - if (!init_vsi) /* means VSI being updated */ 1260 + if (!(init_vsi & ICE_VSI_FLAG_INIT)) 1261 + /* means VSI being updated */ 1351 1262 /* must to indicate which section of VSI context are 1352 1263 * being modified 1353 1264 */ ··· 1363 1272 cpu_to_le16(ICE_AQ_VSI_PROP_SECURITY_VALID); 1364 1273 } 1365 1274 1366 - if (init_vsi) { 1275 + if (init_vsi & ICE_VSI_FLAG_INIT) { 1367 1276 ret = ice_add_vsi(hw, vsi->idx, ctxt, NULL); 1368 1277 if (ret) { 1369 1278 dev_err(dev, "Add VSI failed, err %d\n", ret); ··· 1671 1580 1672 1581 err_out: 1673 1582 ice_vsi_clear_rings(vsi); 1674 - return -ENOMEM; 1675 - } 1676 - 1677 - /** 1678 - * ice_vsi_free_stats - Free the ring statistics structures 1679 - * @vsi: VSI pointer 1680 - */ 1681 - static void ice_vsi_free_stats(struct ice_vsi *vsi) 1682 - { 1683 - struct ice_vsi_stats *vsi_stat; 1684 - struct ice_pf *pf = vsi->back; 1685 - int i; 1686 - 1687 - if (vsi->type == ICE_VSI_CHNL) 1688 - return; 1689 - if (!pf->vsi_stats) 1690 - return; 1691 - 1692 - vsi_stat = pf->vsi_stats[vsi->idx]; 1693 - if (!vsi_stat) 1694 - return; 1695 - 1696 - ice_for_each_alloc_txq(vsi, i) { 1697 - if (vsi_stat->tx_ring_stats[i]) { 1698 - kfree_rcu(vsi_stat->tx_ring_stats[i], rcu); 1699 - WRITE_ONCE(vsi_stat->tx_ring_stats[i], NULL); 1700 - } 1701 - } 1702 - 1703 - ice_for_each_alloc_rxq(vsi, i) { 1704 - if (vsi_stat->rx_ring_stats[i]) { 1705 - kfree_rcu(vsi_stat->rx_ring_stats[i], rcu); 1706 - WRITE_ONCE(vsi_stat->rx_ring_stats[i], NULL); 1707 - } 1708 - } 1709 - 1710 - kfree(vsi_stat->tx_ring_stats); 1711 - kfree(vsi_stat->rx_ring_stats); 1712 - kfree(vsi_stat); 1713 - pf->vsi_stats[vsi->idx] = NULL; 1714 - } 1715 - 1716 - /** 1717 - * ice_vsi_alloc_ring_stats - Allocates Tx and Rx ring stats for the VSI 1718 - * @vsi: VSI which is having stats allocated 1719 - */ 1720 - static int ice_vsi_alloc_ring_stats(struct ice_vsi *vsi) 1721 - { 1722 - struct ice_ring_stats **tx_ring_stats; 1723 - struct ice_ring_stats **rx_ring_stats; 1724 - struct ice_vsi_stats *vsi_stats; 1725 - struct ice_pf *pf = vsi->back; 1726 - u16 i; 1727 - 1728 - vsi_stats = pf->vsi_stats[vsi->idx]; 1729 - tx_ring_stats = vsi_stats->tx_ring_stats; 1730 - rx_ring_stats = vsi_stats->rx_ring_stats; 1731 - 1732 - /* Allocate Tx ring stats */ 1733 - ice_for_each_alloc_txq(vsi, i) { 1734 - struct ice_ring_stats *ring_stats; 1735 - struct ice_tx_ring *ring; 1736 - 1737 - ring = vsi->tx_rings[i]; 1738 - ring_stats = tx_ring_stats[i]; 1739 - 1740 - if (!ring_stats) { 1741 - ring_stats = kzalloc(sizeof(*ring_stats), GFP_KERNEL); 1742 - if (!ring_stats) 1743 - goto err_out; 1744 - 1745 - WRITE_ONCE(tx_ring_stats[i], ring_stats); 1746 - } 1747 - 1748 - ring->ring_stats = ring_stats; 1749 - } 1750 - 1751 - /* Allocate Rx ring stats */ 1752 - ice_for_each_alloc_rxq(vsi, i) { 1753 - struct ice_ring_stats *ring_stats; 1754 - struct ice_rx_ring *ring; 1755 - 1756 - ring = vsi->rx_rings[i]; 1757 - ring_stats = rx_ring_stats[i]; 1758 - 1759 - if (!ring_stats) { 1760 - ring_stats = kzalloc(sizeof(*ring_stats), GFP_KERNEL); 1761 - if (!ring_stats) 1762 - goto err_out; 1763 - 1764 - WRITE_ONCE(rx_ring_stats[i], ring_stats); 1765 - } 1766 - 1767 - ring->ring_stats = ring_stats; 1768 - } 1769 - 1770 - return 0; 1771 - 1772 - err_out: 1773 - ice_vsi_free_stats(vsi); 1774 1583 return -ENOMEM; 1775 1584 } 1776 1585 ··· 2636 2645 } 2637 2646 2638 2647 /** 2639 - * ice_vsi_setup - Set up a VSI by a given type 2640 - * @pf: board private structure 2641 - * @pi: pointer to the port_info instance 2642 - * @vsi_type: VSI type 2643 - * @vf: pointer to VF to which this VSI connects. This field is used primarily 2644 - * for the ICE_VSI_VF type. Other VSI types should pass NULL. 2645 - * @ch: ptr to channel 2648 + * ice_free_vf_ctrl_res - Free the VF control VSI resource 2649 + * @pf: pointer to PF structure 2650 + * @vsi: the VSI to free resources for 2646 2651 * 2647 - * This allocates the sw VSI structure and its queue resources. 2648 - * 2649 - * Returns pointer to the successfully allocated and configured VSI sw struct on 2650 - * success, NULL on failure. 2652 + * Check if the VF control VSI resource is still in use. If no VF is using it 2653 + * any more, release the VSI resource. Otherwise, leave it to be cleaned up 2654 + * once no other VF uses it. 2651 2655 */ 2652 - struct ice_vsi * 2653 - ice_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi, 2654 - enum ice_vsi_type vsi_type, struct ice_vf *vf, 2655 - struct ice_channel *ch) 2656 + static void ice_free_vf_ctrl_res(struct ice_pf *pf, struct ice_vsi *vsi) 2657 + { 2658 + struct ice_vf *vf; 2659 + unsigned int bkt; 2660 + 2661 + rcu_read_lock(); 2662 + ice_for_each_vf_rcu(pf, bkt, vf) { 2663 + if (vf != vsi->vf && vf->ctrl_vsi_idx != ICE_NO_VSI) { 2664 + rcu_read_unlock(); 2665 + return; 2666 + } 2667 + } 2668 + rcu_read_unlock(); 2669 + 2670 + /* No other VFs left that have control VSI. It is now safe to reclaim 2671 + * SW interrupts back to the common pool. 2672 + */ 2673 + ice_free_res(pf->irq_tracker, vsi->base_vector, 2674 + ICE_RES_VF_CTRL_VEC_ID); 2675 + pf->num_avail_sw_msix += vsi->num_q_vectors; 2676 + } 2677 + 2678 + static int ice_vsi_cfg_tc_lan(struct ice_pf *pf, struct ice_vsi *vsi) 2656 2679 { 2657 2680 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 }; 2658 2681 struct device *dev = ice_pf_to_dev(pf); 2659 - struct ice_vsi *vsi; 2660 2682 int ret, i; 2661 2683 2662 - if (vsi_type == ICE_VSI_CHNL) 2663 - vsi = ice_vsi_alloc(pf, vsi_type, ch, NULL); 2664 - else if (vsi_type == ICE_VSI_VF || vsi_type == ICE_VSI_CTRL) 2665 - vsi = ice_vsi_alloc(pf, vsi_type, NULL, vf); 2666 - else 2667 - vsi = ice_vsi_alloc(pf, vsi_type, NULL, NULL); 2684 + /* configure VSI nodes based on number of queues and TC's */ 2685 + ice_for_each_traffic_class(i) { 2686 + if (!(vsi->tc_cfg.ena_tc & BIT(i))) 2687 + continue; 2668 2688 2669 - if (!vsi) { 2670 - dev_err(dev, "could not allocate VSI\n"); 2671 - return NULL; 2689 + if (vsi->type == ICE_VSI_CHNL) { 2690 + if (!vsi->alloc_txq && vsi->num_txq) 2691 + max_txqs[i] = vsi->num_txq; 2692 + else 2693 + max_txqs[i] = pf->num_lan_tx; 2694 + } else { 2695 + max_txqs[i] = vsi->alloc_txq; 2696 + } 2672 2697 } 2673 2698 2674 - vsi->port_info = pi; 2699 + dev_dbg(dev, "vsi->tc_cfg.ena_tc = %d\n", vsi->tc_cfg.ena_tc); 2700 + ret = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc, 2701 + max_txqs); 2702 + if (ret) { 2703 + dev_err(dev, "VSI %d failed lan queue config, error %d\n", 2704 + vsi->vsi_num, ret); 2705 + return ret; 2706 + } 2707 + 2708 + return 0; 2709 + } 2710 + 2711 + /** 2712 + * ice_vsi_cfg_def - configure default VSI based on the type 2713 + * @vsi: pointer to VSI 2714 + * @vf: pointer to VF to which this VSI connects. This field is used primarily 2715 + * for the ICE_VSI_VF type. Other VSI types should pass NULL. 2716 + * @ch: ptr to channel 2717 + * @init_vsi: is this an initialization or a reconfigure of the VSI 2718 + */ 2719 + static int 2720 + ice_vsi_cfg_def(struct ice_vsi *vsi, struct ice_vf *vf, struct ice_channel *ch, 2721 + int init_vsi) 2722 + { 2723 + struct device *dev = ice_pf_to_dev(vsi->back); 2724 + struct ice_pf *pf = vsi->back; 2725 + int ret; 2726 + 2675 2727 vsi->vsw = pf->first_sw; 2676 - if (vsi->type == ICE_VSI_PF) 2677 - vsi->ethtype = ETH_P_PAUSE; 2728 + 2729 + ret = ice_vsi_alloc_def(vsi, vf, ch); 2730 + if (ret) 2731 + return ret; 2732 + 2733 + /* allocate memory for Tx/Rx ring stat pointers */ 2734 + if (ice_vsi_alloc_stat_arrays(vsi)) 2735 + goto unroll_vsi_alloc; 2678 2736 2679 2737 ice_alloc_fd_res(vsi); 2680 2738 2681 - if (vsi_type != ICE_VSI_CHNL) { 2682 - if (ice_vsi_get_qs(vsi)) { 2683 - dev_err(dev, "Failed to allocate queues. vsi->idx = %d\n", 2684 - vsi->idx); 2685 - goto unroll_vsi_alloc; 2686 - } 2739 + if (ice_vsi_get_qs(vsi)) { 2740 + dev_err(dev, "Failed to allocate queues. vsi->idx = %d\n", 2741 + vsi->idx); 2742 + goto unroll_vsi_alloc_stat; 2687 2743 } 2688 2744 2689 2745 /* set RSS capabilities */ ··· 2740 2702 ice_vsi_set_tc_cfg(vsi); 2741 2703 2742 2704 /* create the VSI */ 2743 - ret = ice_vsi_init(vsi, true); 2705 + ret = ice_vsi_init(vsi, init_vsi); 2744 2706 if (ret) 2745 2707 goto unroll_get_qs; 2746 2708 ··· 2771 2733 goto unroll_vector_base; 2772 2734 2773 2735 ice_vsi_map_rings_to_vectors(vsi); 2736 + if (ice_is_xdp_ena_vsi(vsi)) { 2737 + ret = ice_vsi_determine_xdp_res(vsi); 2738 + if (ret) 2739 + goto unroll_vector_base; 2740 + ret = ice_prepare_xdp_rings(vsi, vsi->xdp_prog); 2741 + if (ret) 2742 + goto unroll_vector_base; 2743 + } 2774 2744 2775 2745 /* ICE_VSI_CTRL does not need RSS so skip RSS processing */ 2776 2746 if (vsi->type != ICE_VSI_CTRL) ··· 2843 2797 goto unroll_vsi_init; 2844 2798 } 2845 2799 2846 - /* configure VSI nodes based on number of queues and TC's */ 2847 - ice_for_each_traffic_class(i) { 2848 - if (!(vsi->tc_cfg.ena_tc & BIT(i))) 2849 - continue; 2800 + return 0; 2850 2801 2851 - if (vsi->type == ICE_VSI_CHNL) { 2852 - if (!vsi->alloc_txq && vsi->num_txq) 2853 - max_txqs[i] = vsi->num_txq; 2854 - else 2855 - max_txqs[i] = pf->num_lan_tx; 2856 - } else { 2857 - max_txqs[i] = vsi->alloc_txq; 2858 - } 2802 + unroll_vector_base: 2803 + /* reclaim SW interrupts back to the common pool */ 2804 + ice_free_res(pf->irq_tracker, vsi->base_vector, vsi->idx); 2805 + pf->num_avail_sw_msix += vsi->num_q_vectors; 2806 + unroll_alloc_q_vector: 2807 + ice_vsi_free_q_vectors(vsi); 2808 + unroll_vsi_init: 2809 + ice_vsi_delete_from_hw(vsi); 2810 + unroll_get_qs: 2811 + ice_vsi_put_qs(vsi); 2812 + unroll_vsi_alloc_stat: 2813 + ice_vsi_free_stats(vsi); 2814 + unroll_vsi_alloc: 2815 + ice_vsi_free_arrays(vsi); 2816 + return ret; 2817 + } 2818 + 2819 + /** 2820 + * ice_vsi_cfg - configure VSI and tc on it 2821 + * @vsi: pointer to VSI 2822 + * @vf: pointer to VF to which this VSI connects. This field is used primarily 2823 + * for the ICE_VSI_VF type. Other VSI types should pass NULL. 2824 + * @ch: ptr to channel 2825 + * @init_vsi: is this an initialization or a reconfigure of the VSI 2826 + */ 2827 + int ice_vsi_cfg(struct ice_vsi *vsi, struct ice_vf *vf, struct ice_channel *ch, 2828 + int init_vsi) 2829 + { 2830 + int ret; 2831 + 2832 + ret = ice_vsi_cfg_def(vsi, vf, ch, init_vsi); 2833 + if (ret) 2834 + return ret; 2835 + 2836 + ret = ice_vsi_cfg_tc_lan(vsi->back, vsi); 2837 + if (ret) 2838 + ice_vsi_decfg(vsi); 2839 + 2840 + return ret; 2841 + } 2842 + 2843 + /** 2844 + * ice_vsi_decfg - remove all VSI configuration 2845 + * @vsi: pointer to VSI 2846 + */ 2847 + void ice_vsi_decfg(struct ice_vsi *vsi) 2848 + { 2849 + struct ice_pf *pf = vsi->back; 2850 + int err; 2851 + 2852 + /* The Rx rule will only exist to remove if the LLDP FW 2853 + * engine is currently stopped 2854 + */ 2855 + if (!ice_is_safe_mode(pf) && vsi->type == ICE_VSI_PF && 2856 + !test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags)) 2857 + ice_cfg_sw_lldp(vsi, false, false); 2858 + 2859 + ice_fltr_remove_all(vsi); 2860 + ice_rm_vsi_lan_cfg(vsi->port_info, vsi->idx); 2861 + err = ice_rm_vsi_rdma_cfg(vsi->port_info, vsi->idx); 2862 + if (err) 2863 + dev_err(ice_pf_to_dev(pf), "Failed to remove RDMA scheduler config for VSI %u, err %d\n", 2864 + vsi->vsi_num, err); 2865 + 2866 + if (ice_is_xdp_ena_vsi(vsi)) 2867 + /* return value check can be skipped here, it always returns 2868 + * 0 if reset is in progress 2869 + */ 2870 + ice_destroy_xdp_rings(vsi); 2871 + 2872 + ice_vsi_clear_rings(vsi); 2873 + ice_vsi_free_q_vectors(vsi); 2874 + ice_vsi_put_qs(vsi); 2875 + ice_vsi_free_arrays(vsi); 2876 + 2877 + /* SR-IOV determines needed MSIX resources all at once instead of per 2878 + * VSI since when VFs are spawned we know how many VFs there are and how 2879 + * many interrupts each VF needs. SR-IOV MSIX resources are also 2880 + * cleared in the same manner. 2881 + */ 2882 + if (vsi->type == ICE_VSI_CTRL && vsi->vf) { 2883 + ice_free_vf_ctrl_res(pf, vsi); 2884 + } else if (vsi->type != ICE_VSI_VF) { 2885 + /* reclaim SW interrupts back to the common pool */ 2886 + ice_free_res(pf->irq_tracker, vsi->base_vector, vsi->idx); 2887 + pf->num_avail_sw_msix += vsi->num_q_vectors; 2888 + vsi->base_vector = 0; 2859 2889 } 2860 2890 2861 - dev_dbg(dev, "vsi->tc_cfg.ena_tc = %d\n", vsi->tc_cfg.ena_tc); 2862 - ret = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc, 2863 - max_txqs); 2864 - if (ret) { 2865 - dev_err(dev, "VSI %d failed lan queue config, error %d\n", 2866 - vsi->vsi_num, ret); 2867 - goto unroll_clear_rings; 2891 + if (vsi->type == ICE_VSI_VF && 2892 + vsi->agg_node && vsi->agg_node->valid) 2893 + vsi->agg_node->num_vsis--; 2894 + if (vsi->agg_node) { 2895 + vsi->agg_node->valid = false; 2896 + vsi->agg_node->agg_id = 0; 2868 2897 } 2898 + } 2899 + 2900 + /** 2901 + * ice_vsi_setup - Set up a VSI by a given type 2902 + * @pf: board private structure 2903 + * @pi: pointer to the port_info instance 2904 + * @vsi_type: VSI type 2905 + * @vf: pointer to VF to which this VSI connects. This field is used primarily 2906 + * for the ICE_VSI_VF type. Other VSI types should pass NULL. 2907 + * @ch: ptr to channel 2908 + * 2909 + * This allocates the sw VSI structure and its queue resources. 2910 + * 2911 + * Returns pointer to the successfully allocated and configured VSI sw struct on 2912 + * success, NULL on failure. 2913 + */ 2914 + struct ice_vsi * 2915 + ice_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi, 2916 + enum ice_vsi_type vsi_type, struct ice_vf *vf, 2917 + struct ice_channel *ch) 2918 + { 2919 + struct device *dev = ice_pf_to_dev(pf); 2920 + struct ice_vsi *vsi; 2921 + int ret; 2922 + 2923 + vsi = ice_vsi_alloc(pf, pi, vsi_type, ch, vf); 2924 + if (!vsi) { 2925 + dev_err(dev, "could not allocate VSI\n"); 2926 + return NULL; 2927 + } 2928 + 2929 + ret = ice_vsi_cfg(vsi, vf, ch, ICE_VSI_FLAG_INIT); 2930 + if (ret) 2931 + goto err_vsi_cfg; 2869 2932 2870 2933 /* Add switch rule to drop all Tx Flow Control Frames, of look up 2871 2934 * type ETHERTYPE from VSIs, and restrict malicious VF from sending ··· 2985 2830 * be dropped so that VFs cannot send LLDP packets to reconfig DCB 2986 2831 * settings in the HW. 2987 2832 */ 2988 - if (!ice_is_safe_mode(pf)) 2989 - if (vsi->type == ICE_VSI_PF) { 2990 - ice_fltr_add_eth(vsi, ETH_P_PAUSE, ICE_FLTR_TX, 2991 - ICE_DROP_PACKET); 2992 - ice_cfg_sw_lldp(vsi, true, true); 2993 - } 2833 + if (!ice_is_safe_mode(pf) && vsi->type == ICE_VSI_PF) { 2834 + ice_fltr_add_eth(vsi, ETH_P_PAUSE, ICE_FLTR_TX, 2835 + ICE_DROP_PACKET); 2836 + ice_cfg_sw_lldp(vsi, true, true); 2837 + } 2994 2838 2995 2839 if (!vsi->agg_node) 2996 2840 ice_set_agg_vsi(vsi); 2841 + 2997 2842 return vsi; 2998 2843 2999 - unroll_clear_rings: 3000 - ice_vsi_clear_rings(vsi); 3001 - unroll_vector_base: 3002 - /* reclaim SW interrupts back to the common pool */ 3003 - ice_free_res(pf->irq_tracker, vsi->base_vector, vsi->idx); 3004 - pf->num_avail_sw_msix += vsi->num_q_vectors; 3005 - unroll_alloc_q_vector: 3006 - ice_vsi_free_q_vectors(vsi); 3007 - unroll_vsi_init: 3008 - ice_vsi_free_stats(vsi); 3009 - ice_vsi_delete(vsi); 3010 - unroll_get_qs: 3011 - ice_vsi_put_qs(vsi); 3012 - unroll_vsi_alloc: 2844 + err_vsi_cfg: 3013 2845 if (vsi_type == ICE_VSI_VF) 3014 2846 ice_enable_lag(pf->lag); 3015 - ice_vsi_clear(vsi); 2847 + ice_vsi_free(vsi); 3016 2848 3017 2849 return NULL; 3018 2850 } ··· 3263 3121 } 3264 3122 3265 3123 /** 3266 - * ice_free_vf_ctrl_res - Free the VF control VSI resource 3267 - * @pf: pointer to PF structure 3268 - * @vsi: the VSI to free resources for 3269 - * 3270 - * Check if the VF control VSI resource is still in use. If no VF is using it 3271 - * any more, release the VSI resource. Otherwise, leave it to be cleaned up 3272 - * once no other VF uses it. 3273 - */ 3274 - static void ice_free_vf_ctrl_res(struct ice_pf *pf, struct ice_vsi *vsi) 3275 - { 3276 - struct ice_vf *vf; 3277 - unsigned int bkt; 3278 - 3279 - rcu_read_lock(); 3280 - ice_for_each_vf_rcu(pf, bkt, vf) { 3281 - if (vf != vsi->vf && vf->ctrl_vsi_idx != ICE_NO_VSI) { 3282 - rcu_read_unlock(); 3283 - return; 3284 - } 3285 - } 3286 - rcu_read_unlock(); 3287 - 3288 - /* No other VFs left that have control VSI. It is now safe to reclaim 3289 - * SW interrupts back to the common pool. 3290 - */ 3291 - ice_free_res(pf->irq_tracker, vsi->base_vector, 3292 - ICE_RES_VF_CTRL_VEC_ID); 3293 - pf->num_avail_sw_msix += vsi->num_q_vectors; 3294 - } 3295 - 3296 - /** 3297 3124 * ice_vsi_release - Delete a VSI and free its resources 3298 3125 * @vsi: the VSI being removed 3299 3126 * ··· 3271 3160 int ice_vsi_release(struct ice_vsi *vsi) 3272 3161 { 3273 3162 struct ice_pf *pf; 3274 - int err; 3275 3163 3276 3164 if (!vsi->back) 3277 3165 return -ENODEV; ··· 3288 3178 clear_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state); 3289 3179 } 3290 3180 3181 + if (vsi->type == ICE_VSI_PF) 3182 + ice_devlink_destroy_pf_port(pf); 3183 + 3291 3184 if (test_bit(ICE_FLAG_RSS_ENA, pf->flags)) 3292 3185 ice_rss_clean(vsi); 3293 3186 3294 - /* Disable VSI and free resources */ 3295 - if (vsi->type != ICE_VSI_LB) 3296 - ice_vsi_dis_irq(vsi); 3297 3187 ice_vsi_close(vsi); 3298 - 3299 - /* SR-IOV determines needed MSIX resources all at once instead of per 3300 - * VSI since when VFs are spawned we know how many VFs there are and how 3301 - * many interrupts each VF needs. SR-IOV MSIX resources are also 3302 - * cleared in the same manner. 3303 - */ 3304 - if (vsi->type == ICE_VSI_CTRL && vsi->vf) { 3305 - ice_free_vf_ctrl_res(pf, vsi); 3306 - } else if (vsi->type != ICE_VSI_VF) { 3307 - /* reclaim SW interrupts back to the common pool */ 3308 - ice_free_res(pf->irq_tracker, vsi->base_vector, vsi->idx); 3309 - pf->num_avail_sw_msix += vsi->num_q_vectors; 3310 - } 3311 - 3312 - if (!ice_is_safe_mode(pf)) { 3313 - if (vsi->type == ICE_VSI_PF) { 3314 - ice_fltr_remove_eth(vsi, ETH_P_PAUSE, ICE_FLTR_TX, 3315 - ICE_DROP_PACKET); 3316 - ice_cfg_sw_lldp(vsi, true, false); 3317 - /* The Rx rule will only exist to remove if the LLDP FW 3318 - * engine is currently stopped 3319 - */ 3320 - if (!test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags)) 3321 - ice_cfg_sw_lldp(vsi, false, false); 3322 - } 3323 - } 3324 - 3325 - if (ice_is_vsi_dflt_vsi(vsi)) 3326 - ice_clear_dflt_vsi(vsi); 3327 - ice_fltr_remove_all(vsi); 3328 - ice_rm_vsi_lan_cfg(vsi->port_info, vsi->idx); 3329 - err = ice_rm_vsi_rdma_cfg(vsi->port_info, vsi->idx); 3330 - if (err) 3331 - dev_err(ice_pf_to_dev(vsi->back), "Failed to remove RDMA scheduler config for VSI %u, err %d\n", 3332 - vsi->vsi_num, err); 3333 - ice_vsi_delete(vsi); 3334 - ice_vsi_free_q_vectors(vsi); 3188 + ice_vsi_decfg(vsi); 3335 3189 3336 3190 if (vsi->netdev) { 3337 3191 if (test_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state)) { ··· 3309 3235 } 3310 3236 } 3311 3237 3312 - if (vsi->type == ICE_VSI_VF && 3313 - vsi->agg_node && vsi->agg_node->valid) 3314 - vsi->agg_node->num_vsis--; 3315 - ice_vsi_clear_rings(vsi); 3316 - ice_vsi_free_stats(vsi); 3317 - ice_vsi_put_qs(vsi); 3318 - 3319 3238 /* retain SW VSI data structure since it is needed to unregister and 3320 3239 * free VSI netdev when PF is not in reset recovery pending state,\ 3321 3240 * for ex: during rmmod. 3322 3241 */ 3323 3242 if (!ice_is_reset_in_progress(pf->state)) 3324 - ice_vsi_clear(vsi); 3243 + ice_vsi_delete(vsi); 3325 3244 3326 3245 return 0; 3327 3246 } ··· 3477 3410 /** 3478 3411 * ice_vsi_rebuild - Rebuild VSI after reset 3479 3412 * @vsi: VSI to be rebuild 3480 - * @init_vsi: is this an initialization or a reconfigure of the VSI 3413 + * @init_vsi: flag, tell if VSI need to be initialized 3481 3414 * 3482 3415 * Returns 0 on success and negative value on failure 3483 3416 */ 3484 - int ice_vsi_rebuild(struct ice_vsi *vsi, bool init_vsi) 3417 + int ice_vsi_rebuild(struct ice_vsi *vsi, int init_vsi) 3485 3418 { 3486 - u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 }; 3487 3419 struct ice_coalesce_stored *coalesce; 3488 - int ret, i, prev_txq, prev_rxq; 3420 + int ret, prev_txq, prev_rxq; 3489 3421 int prev_num_q_vectors = 0; 3490 - enum ice_vsi_type vtype; 3491 3422 struct ice_pf *pf; 3492 3423 3493 3424 if (!vsi) 3494 3425 return -EINVAL; 3495 3426 3496 3427 pf = vsi->back; 3497 - vtype = vsi->type; 3498 - if (WARN_ON(vtype == ICE_VSI_VF && !vsi->vf)) 3428 + if (WARN_ON(vsi->type == ICE_VSI_VF && !vsi->vf)) 3499 3429 return -EINVAL; 3500 - 3501 - ice_vsi_init_vlan_ops(vsi); 3502 3430 3503 3431 coalesce = kcalloc(vsi->num_q_vectors, 3504 3432 sizeof(struct ice_coalesce_stored), GFP_KERNEL); ··· 3505 3443 prev_txq = vsi->num_txq; 3506 3444 prev_rxq = vsi->num_rxq; 3507 3445 3508 - ice_rm_vsi_lan_cfg(vsi->port_info, vsi->idx); 3509 - ret = ice_rm_vsi_rdma_cfg(vsi->port_info, vsi->idx); 3446 + ice_vsi_decfg(vsi); 3447 + ret = ice_vsi_cfg_def(vsi, vsi->vf, vsi->ch, init_vsi); 3510 3448 if (ret) 3511 - dev_err(ice_pf_to_dev(vsi->back), "Failed to remove RDMA scheduler config for VSI %u, err %d\n", 3512 - vsi->vsi_num, ret); 3513 - ice_vsi_free_q_vectors(vsi); 3449 + goto err_vsi_cfg; 3514 3450 3515 - /* SR-IOV determines needed MSIX resources all at once instead of per 3516 - * VSI since when VFs are spawned we know how many VFs there are and how 3517 - * many interrupts each VF needs. SR-IOV MSIX resources are also 3518 - * cleared in the same manner. 3519 - */ 3520 - if (vtype != ICE_VSI_VF) { 3521 - /* reclaim SW interrupts back to the common pool */ 3522 - ice_free_res(pf->irq_tracker, vsi->base_vector, vsi->idx); 3523 - pf->num_avail_sw_msix += vsi->num_q_vectors; 3524 - vsi->base_vector = 0; 3525 - } 3526 - 3527 - if (ice_is_xdp_ena_vsi(vsi)) 3528 - /* return value check can be skipped here, it always returns 3529 - * 0 if reset is in progress 3530 - */ 3531 - ice_destroy_xdp_rings(vsi); 3532 - ice_vsi_put_qs(vsi); 3533 - ice_vsi_clear_rings(vsi); 3534 - ice_vsi_free_arrays(vsi); 3535 - if (vtype == ICE_VSI_VF) 3536 - ice_vsi_set_num_qs(vsi, vsi->vf); 3537 - else 3538 - ice_vsi_set_num_qs(vsi, NULL); 3539 - 3540 - ret = ice_vsi_alloc_arrays(vsi); 3541 - if (ret < 0) 3542 - goto err_vsi; 3543 - 3544 - ice_vsi_get_qs(vsi); 3545 - 3546 - ice_alloc_fd_res(vsi); 3547 - ice_vsi_set_tc_cfg(vsi); 3548 - 3549 - /* Initialize VSI struct elements and create VSI in FW */ 3550 - ret = ice_vsi_init(vsi, init_vsi); 3551 - if (ret < 0) 3552 - goto err_vsi; 3553 - 3554 - switch (vtype) { 3555 - case ICE_VSI_CTRL: 3556 - case ICE_VSI_SWITCHDEV_CTRL: 3557 - case ICE_VSI_PF: 3558 - ret = ice_vsi_alloc_q_vectors(vsi); 3559 - if (ret) 3560 - goto err_rings; 3561 - 3562 - ret = ice_vsi_setup_vector_base(vsi); 3563 - if (ret) 3564 - goto err_vectors; 3565 - 3566 - ret = ice_vsi_set_q_vectors_reg_idx(vsi); 3567 - if (ret) 3568 - goto err_vectors; 3569 - 3570 - ret = ice_vsi_alloc_rings(vsi); 3571 - if (ret) 3572 - goto err_vectors; 3573 - 3574 - ret = ice_vsi_alloc_ring_stats(vsi); 3575 - if (ret) 3576 - goto err_vectors; 3577 - 3578 - ice_vsi_map_rings_to_vectors(vsi); 3579 - 3580 - vsi->stat_offsets_loaded = false; 3581 - if (ice_is_xdp_ena_vsi(vsi)) { 3582 - ret = ice_vsi_determine_xdp_res(vsi); 3583 - if (ret) 3584 - goto err_vectors; 3585 - ret = ice_prepare_xdp_rings(vsi, vsi->xdp_prog); 3586 - if (ret) 3587 - goto err_vectors; 3588 - } 3589 - /* ICE_VSI_CTRL does not need RSS so skip RSS processing */ 3590 - if (vtype != ICE_VSI_CTRL) 3591 - /* Do not exit if configuring RSS had an issue, at 3592 - * least receive traffic on first queue. Hence no 3593 - * need to capture return value 3594 - */ 3595 - if (test_bit(ICE_FLAG_RSS_ENA, pf->flags)) 3596 - ice_vsi_cfg_rss_lut_key(vsi); 3597 - 3598 - /* disable or enable CRC stripping */ 3599 - if (vsi->netdev) 3600 - ice_vsi_cfg_crc_strip(vsi, !!(vsi->netdev->features & 3601 - NETIF_F_RXFCS)); 3602 - 3603 - break; 3604 - case ICE_VSI_VF: 3605 - ret = ice_vsi_alloc_q_vectors(vsi); 3606 - if (ret) 3607 - goto err_rings; 3608 - 3609 - ret = ice_vsi_set_q_vectors_reg_idx(vsi); 3610 - if (ret) 3611 - goto err_vectors; 3612 - 3613 - ret = ice_vsi_alloc_rings(vsi); 3614 - if (ret) 3615 - goto err_vectors; 3616 - 3617 - ret = ice_vsi_alloc_ring_stats(vsi); 3618 - if (ret) 3619 - goto err_vectors; 3620 - 3621 - vsi->stat_offsets_loaded = false; 3622 - break; 3623 - case ICE_VSI_CHNL: 3624 - if (test_bit(ICE_FLAG_RSS_ENA, pf->flags)) { 3625 - ice_vsi_cfg_rss_lut_key(vsi); 3626 - ice_vsi_set_rss_flow_fld(vsi); 3627 - } 3628 - break; 3629 - default: 3630 - break; 3631 - } 3632 - 3633 - /* configure VSI nodes based on number of queues and TC's */ 3634 - for (i = 0; i < vsi->tc_cfg.numtc; i++) { 3635 - /* configure VSI nodes based on number of queues and TC's. 3636 - * ADQ creates VSIs for each TC/Channel but doesn't 3637 - * allocate queues instead it reconfigures the PF queues 3638 - * as per the TC command. So max_txqs should point to the 3639 - * PF Tx queues. 3640 - */ 3641 - if (vtype == ICE_VSI_CHNL) 3642 - max_txqs[i] = pf->num_lan_tx; 3643 - else 3644 - max_txqs[i] = vsi->alloc_txq; 3645 - 3646 - if (ice_is_xdp_ena_vsi(vsi)) 3647 - max_txqs[i] += vsi->num_xdp_txq; 3648 - } 3649 - 3650 - if (test_bit(ICE_FLAG_TC_MQPRIO, pf->flags)) 3651 - /* If MQPRIO is set, means channel code path, hence for main 3652 - * VSI's, use TC as 1 3653 - */ 3654 - ret = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, 1, max_txqs); 3655 - else 3656 - ret = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, 3657 - vsi->tc_cfg.ena_tc, max_txqs); 3658 - 3451 + ret = ice_vsi_cfg_tc_lan(pf, vsi); 3659 3452 if (ret) { 3660 - dev_err(ice_pf_to_dev(pf), "VSI %d failed lan queue config, error %d\n", 3661 - vsi->vsi_num, ret); 3662 - if (init_vsi) { 3453 + if (init_vsi & ICE_VSI_FLAG_INIT) { 3663 3454 ret = -EIO; 3664 - goto err_vectors; 3455 + goto err_vsi_cfg_tc_lan; 3665 3456 } else { 3457 + kfree(coalesce); 3666 3458 return ice_schedule_reset(pf, ICE_RESET_PFR); 3667 3459 } 3668 3460 } 3669 3461 3670 3462 if (ice_vsi_realloc_stat_arrays(vsi, prev_txq, prev_rxq)) 3671 - goto err_vectors; 3463 + goto err_vsi_cfg_tc_lan; 3672 3464 3673 3465 ice_vsi_rebuild_set_coalesce(vsi, coalesce, prev_num_q_vectors); 3674 3466 kfree(coalesce); 3675 3467 3676 3468 return 0; 3677 3469 3678 - err_vectors: 3679 - ice_vsi_free_q_vectors(vsi); 3680 - err_rings: 3681 - if (vsi->netdev) { 3682 - vsi->current_netdev_flags = 0; 3683 - unregister_netdev(vsi->netdev); 3684 - free_netdev(vsi->netdev); 3685 - vsi->netdev = NULL; 3686 - } 3687 - err_vsi: 3688 - ice_vsi_clear(vsi); 3689 - set_bit(ICE_RESET_FAILED, pf->state); 3470 + err_vsi_cfg_tc_lan: 3471 + ice_vsi_decfg(vsi); 3472 + err_vsi_cfg: 3690 3473 kfree(coalesce); 3691 3474 return ret; 3692 3475 }
+6 -2
drivers/net/ethernet/intel/ice/ice_lib.h
··· 42 42 int ice_set_link(struct ice_vsi *vsi, bool ena); 43 43 44 44 void ice_vsi_delete(struct ice_vsi *vsi); 45 - int ice_vsi_clear(struct ice_vsi *vsi); 46 45 47 46 int ice_vsi_cfg_tc(struct ice_vsi *vsi, u8 ena_tc); 48 47 ··· 62 63 63 64 int ice_ena_vsi(struct ice_vsi *vsi, bool locked); 64 65 66 + void ice_vsi_decfg(struct ice_vsi *vsi); 65 67 void ice_dis_vsi(struct ice_vsi *vsi, bool locked); 66 68 67 69 int ice_free_res(struct ice_res_tracker *res, u16 index, u16 id); ··· 70 70 int 71 71 ice_get_res(struct ice_pf *pf, struct ice_res_tracker *res, u16 needed, u16 id); 72 72 73 - int ice_vsi_rebuild(struct ice_vsi *vsi, bool init_vsi); 73 + #define ICE_VSI_FLAG_INIT BIT(0) 74 + #define ICE_VSI_FLAG_NO_INIT 0 75 + int ice_vsi_rebuild(struct ice_vsi *vsi, int init_vsi); 76 + int ice_vsi_cfg(struct ice_vsi *vsi, struct ice_vf *vf, 77 + struct ice_channel *ch, int init_vsi); 74 78 75 79 bool ice_is_reset_in_progress(unsigned long *state); 76 80 int ice_wait_for_reset(struct ice_pf *pf, unsigned long timeout);
+617 -465
drivers/net/ethernet/intel/ice/ice_main.c
··· 44 44 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all)"); 45 45 #endif /* !CONFIG_DYNAMIC_DEBUG */ 46 46 47 - static DEFINE_IDA(ice_aux_ida); 48 47 DEFINE_STATIC_KEY_FALSE(ice_xdp_locking_key); 49 48 EXPORT_SYMBOL(ice_xdp_locking_key); 50 49 ··· 3423 3424 } 3424 3425 3425 3426 /** 3426 - * ice_cfg_netdev - Allocate, configure and register a netdev 3427 - * @vsi: the VSI associated with the new netdev 3428 - * 3429 - * Returns 0 on success, negative value on failure 3430 - */ 3431 - static int ice_cfg_netdev(struct ice_vsi *vsi) 3432 - { 3433 - struct ice_netdev_priv *np; 3434 - struct net_device *netdev; 3435 - u8 mac_addr[ETH_ALEN]; 3436 - 3437 - netdev = alloc_etherdev_mqs(sizeof(*np), vsi->alloc_txq, 3438 - vsi->alloc_rxq); 3439 - if (!netdev) 3440 - return -ENOMEM; 3441 - 3442 - set_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state); 3443 - vsi->netdev = netdev; 3444 - np = netdev_priv(netdev); 3445 - np->vsi = vsi; 3446 - 3447 - ice_set_netdev_features(netdev); 3448 - 3449 - ice_set_ops(netdev); 3450 - 3451 - if (vsi->type == ICE_VSI_PF) { 3452 - SET_NETDEV_DEV(netdev, ice_pf_to_dev(vsi->back)); 3453 - ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr); 3454 - eth_hw_addr_set(netdev, mac_addr); 3455 - ether_addr_copy(netdev->perm_addr, mac_addr); 3456 - } 3457 - 3458 - netdev->priv_flags |= IFF_UNICAST_FLT; 3459 - 3460 - /* Setup netdev TC information */ 3461 - ice_vsi_cfg_netdev_tc(vsi, vsi->tc_cfg.ena_tc); 3462 - 3463 - /* setup watchdog timeout value to be 5 second */ 3464 - netdev->watchdog_timeo = 5 * HZ; 3465 - 3466 - netdev->min_mtu = ETH_MIN_MTU; 3467 - netdev->max_mtu = ICE_MAX_MTU; 3468 - 3469 - return 0; 3470 - } 3471 - 3472 - /** 3473 3427 * ice_fill_rss_lut - Fill the RSS lookup table with default values 3474 3428 * @lut: Lookup table 3475 3429 * @rss_table_size: Lookup table size ··· 3642 3690 } 3643 3691 3644 3692 /** 3645 - * ice_tc_indir_block_remove - clean indirect TC block notifications 3646 - * @pf: PF structure 3647 - */ 3648 - static void ice_tc_indir_block_remove(struct ice_pf *pf) 3649 - { 3650 - struct ice_vsi *pf_vsi = ice_get_main_vsi(pf); 3651 - 3652 - if (!pf_vsi) 3653 - return; 3654 - 3655 - ice_tc_indir_block_unregister(pf_vsi); 3656 - } 3657 - 3658 - /** 3659 3693 * ice_tc_indir_block_register - Register TC indirect block notifications 3660 3694 * @vsi: VSI struct which has the netdev 3661 3695 * ··· 3658 3720 3659 3721 INIT_LIST_HEAD(&np->tc_indr_block_priv_list); 3660 3722 return flow_indr_dev_register(ice_indr_setup_tc_cb, np); 3661 - } 3662 - 3663 - /** 3664 - * ice_setup_pf_sw - Setup the HW switch on startup or after reset 3665 - * @pf: board private structure 3666 - * 3667 - * Returns 0 on success, negative value on failure 3668 - */ 3669 - static int ice_setup_pf_sw(struct ice_pf *pf) 3670 - { 3671 - struct device *dev = ice_pf_to_dev(pf); 3672 - bool dvm = ice_is_dvm_ena(&pf->hw); 3673 - struct ice_vsi *vsi; 3674 - int status; 3675 - 3676 - if (ice_is_reset_in_progress(pf->state)) 3677 - return -EBUSY; 3678 - 3679 - status = ice_aq_set_port_params(pf->hw.port_info, dvm, NULL); 3680 - if (status) 3681 - return -EIO; 3682 - 3683 - vsi = ice_pf_vsi_setup(pf, pf->hw.port_info); 3684 - if (!vsi) 3685 - return -ENOMEM; 3686 - 3687 - /* init channel list */ 3688 - INIT_LIST_HEAD(&vsi->ch_list); 3689 - 3690 - status = ice_cfg_netdev(vsi); 3691 - if (status) 3692 - goto unroll_vsi_setup; 3693 - /* netdev has to be configured before setting frame size */ 3694 - ice_vsi_cfg_frame_size(vsi); 3695 - 3696 - /* init indirect block notifications */ 3697 - status = ice_tc_indir_block_register(vsi); 3698 - if (status) { 3699 - dev_err(dev, "Failed to register netdev notifier\n"); 3700 - goto unroll_cfg_netdev; 3701 - } 3702 - 3703 - /* Setup DCB netlink interface */ 3704 - ice_dcbnl_setup(vsi); 3705 - 3706 - /* registering the NAPI handler requires both the queues and 3707 - * netdev to be created, which are done in ice_pf_vsi_setup() 3708 - * and ice_cfg_netdev() respectively 3709 - */ 3710 - ice_napi_add(vsi); 3711 - 3712 - status = ice_init_mac_fltr(pf); 3713 - if (status) 3714 - goto unroll_napi_add; 3715 - 3716 - return 0; 3717 - 3718 - unroll_napi_add: 3719 - ice_tc_indir_block_unregister(vsi); 3720 - unroll_cfg_netdev: 3721 - ice_napi_del(vsi); 3722 - if (vsi->netdev) { 3723 - clear_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state); 3724 - free_netdev(vsi->netdev); 3725 - vsi->netdev = NULL; 3726 - } 3727 - 3728 - unroll_vsi_setup: 3729 - ice_vsi_release(vsi); 3730 - return status; 3731 3723 } 3732 3724 3733 3725 /** ··· 4089 4221 4090 4222 /* set for the next time the netdev is started */ 4091 4223 if (!netif_running(vsi->netdev)) { 4092 - ice_vsi_rebuild(vsi, false); 4224 + ice_vsi_rebuild(vsi, ICE_VSI_FLAG_NO_INIT); 4093 4225 dev_dbg(ice_pf_to_dev(pf), "Link is down, queue count change happens when link is brought up\n"); 4094 4226 goto done; 4095 4227 } 4096 4228 4097 4229 ice_vsi_close(vsi); 4098 - ice_vsi_rebuild(vsi, false); 4230 + ice_vsi_rebuild(vsi, ICE_VSI_FLAG_NO_INIT); 4099 4231 ice_pf_dcb_recfg(pf, locked); 4100 4232 ice_vsi_open(vsi); 4101 4233 done: ··· 4358 4490 return err; 4359 4491 } 4360 4492 4493 + static void ice_deinit_fdir(struct ice_pf *pf) 4494 + { 4495 + struct ice_vsi *vsi = ice_get_ctrl_vsi(pf); 4496 + 4497 + if (!vsi) 4498 + return; 4499 + 4500 + ice_vsi_manage_fdir(vsi, false); 4501 + ice_vsi_release(vsi); 4502 + if (pf->ctrl_vsi_idx != ICE_NO_VSI) { 4503 + pf->vsi[pf->ctrl_vsi_idx] = NULL; 4504 + pf->ctrl_vsi_idx = ICE_NO_VSI; 4505 + } 4506 + 4507 + mutex_destroy(&(&pf->hw)->fdir_fltr_lock); 4508 + } 4509 + 4361 4510 /** 4362 4511 * ice_get_opt_fw_name - return optional firmware file name or NULL 4363 4512 * @pf: pointer to the PF instance ··· 4475 4590 4476 4591 /** 4477 4592 * ice_register_netdev - register netdev 4478 - * @pf: pointer to the PF struct 4593 + * @vsi: pointer to the VSI struct 4479 4594 */ 4480 - static int ice_register_netdev(struct ice_pf *pf) 4595 + static int ice_register_netdev(struct ice_vsi *vsi) 4481 4596 { 4482 - struct ice_vsi *vsi; 4483 - int err = 0; 4597 + int err; 4484 4598 4485 - vsi = ice_get_main_vsi(pf); 4486 4599 if (!vsi || !vsi->netdev) 4487 4600 return -EIO; 4488 4601 4489 4602 err = register_netdev(vsi->netdev); 4490 4603 if (err) 4491 - goto err_register_netdev; 4604 + return err; 4492 4605 4493 4606 set_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state); 4494 4607 netif_carrier_off(vsi->netdev); 4495 4608 netif_tx_stop_all_queues(vsi->netdev); 4496 4609 4497 4610 return 0; 4498 - err_register_netdev: 4611 + } 4612 + 4613 + static void ice_unregister_netdev(struct ice_vsi *vsi) 4614 + { 4615 + if (!vsi || !vsi->netdev) 4616 + return; 4617 + 4618 + unregister_netdev(vsi->netdev); 4619 + clear_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state); 4620 + } 4621 + 4622 + /** 4623 + * ice_cfg_netdev - Allocate, configure and register a netdev 4624 + * @vsi: the VSI associated with the new netdev 4625 + * 4626 + * Returns 0 on success, negative value on failure 4627 + */ 4628 + static int ice_cfg_netdev(struct ice_vsi *vsi) 4629 + { 4630 + struct ice_netdev_priv *np; 4631 + struct net_device *netdev; 4632 + u8 mac_addr[ETH_ALEN]; 4633 + 4634 + netdev = alloc_etherdev_mqs(sizeof(*np), vsi->alloc_txq, 4635 + vsi->alloc_rxq); 4636 + if (!netdev) 4637 + return -ENOMEM; 4638 + 4639 + set_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state); 4640 + vsi->netdev = netdev; 4641 + np = netdev_priv(netdev); 4642 + np->vsi = vsi; 4643 + 4644 + ice_set_netdev_features(netdev); 4645 + ice_set_ops(netdev); 4646 + 4647 + if (vsi->type == ICE_VSI_PF) { 4648 + SET_NETDEV_DEV(netdev, ice_pf_to_dev(vsi->back)); 4649 + ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr); 4650 + eth_hw_addr_set(netdev, mac_addr); 4651 + } 4652 + 4653 + netdev->priv_flags |= IFF_UNICAST_FLT; 4654 + 4655 + /* Setup netdev TC information */ 4656 + ice_vsi_cfg_netdev_tc(vsi, vsi->tc_cfg.ena_tc); 4657 + 4658 + netdev->max_mtu = ICE_MAX_MTU; 4659 + 4660 + return 0; 4661 + } 4662 + 4663 + static void ice_decfg_netdev(struct ice_vsi *vsi) 4664 + { 4665 + clear_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state); 4499 4666 free_netdev(vsi->netdev); 4500 4667 vsi->netdev = NULL; 4501 - clear_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state); 4668 + } 4669 + 4670 + static int ice_start_eth(struct ice_vsi *vsi) 4671 + { 4672 + int err; 4673 + 4674 + err = ice_init_mac_fltr(vsi->back); 4675 + if (err) 4676 + return err; 4677 + 4678 + rtnl_lock(); 4679 + err = ice_vsi_open(vsi); 4680 + rtnl_unlock(); 4681 + 4502 4682 return err; 4683 + } 4684 + 4685 + static int ice_init_eth(struct ice_pf *pf) 4686 + { 4687 + struct ice_vsi *vsi = ice_get_main_vsi(pf); 4688 + int err; 4689 + 4690 + if (!vsi) 4691 + return -EINVAL; 4692 + 4693 + /* init channel list */ 4694 + INIT_LIST_HEAD(&vsi->ch_list); 4695 + 4696 + err = ice_cfg_netdev(vsi); 4697 + if (err) 4698 + return err; 4699 + /* Setup DCB netlink interface */ 4700 + ice_dcbnl_setup(vsi); 4701 + 4702 + err = ice_init_mac_fltr(pf); 4703 + if (err) 4704 + goto err_init_mac_fltr; 4705 + 4706 + err = ice_devlink_create_pf_port(pf); 4707 + if (err) 4708 + goto err_devlink_create_pf_port; 4709 + 4710 + SET_NETDEV_DEVLINK_PORT(vsi->netdev, &pf->devlink_port); 4711 + 4712 + err = ice_register_netdev(vsi); 4713 + if (err) 4714 + goto err_register_netdev; 4715 + 4716 + err = ice_tc_indir_block_register(vsi); 4717 + if (err) 4718 + goto err_tc_indir_block_register; 4719 + 4720 + ice_napi_add(vsi); 4721 + 4722 + return 0; 4723 + 4724 + err_tc_indir_block_register: 4725 + ice_unregister_netdev(vsi); 4726 + err_register_netdev: 4727 + ice_devlink_destroy_pf_port(pf); 4728 + err_devlink_create_pf_port: 4729 + err_init_mac_fltr: 4730 + ice_decfg_netdev(vsi); 4731 + return err; 4732 + } 4733 + 4734 + static void ice_deinit_eth(struct ice_pf *pf) 4735 + { 4736 + struct ice_vsi *vsi = ice_get_main_vsi(pf); 4737 + 4738 + if (!vsi) 4739 + return; 4740 + 4741 + ice_vsi_close(vsi); 4742 + ice_unregister_netdev(vsi); 4743 + ice_devlink_destroy_pf_port(pf); 4744 + ice_tc_indir_block_unregister(vsi); 4745 + ice_decfg_netdev(vsi); 4746 + } 4747 + 4748 + static int ice_init_dev(struct ice_pf *pf) 4749 + { 4750 + struct device *dev = ice_pf_to_dev(pf); 4751 + struct ice_hw *hw = &pf->hw; 4752 + int err; 4753 + 4754 + err = ice_init_hw(hw); 4755 + if (err) { 4756 + dev_err(dev, "ice_init_hw failed: %d\n", err); 4757 + return err; 4758 + } 4759 + 4760 + ice_init_feature_support(pf); 4761 + 4762 + ice_request_fw(pf); 4763 + 4764 + /* if ice_request_fw fails, ICE_FLAG_ADV_FEATURES bit won't be 4765 + * set in pf->state, which will cause ice_is_safe_mode to return 4766 + * true 4767 + */ 4768 + if (ice_is_safe_mode(pf)) { 4769 + /* we already got function/device capabilities but these don't 4770 + * reflect what the driver needs to do in safe mode. Instead of 4771 + * adding conditional logic everywhere to ignore these 4772 + * device/function capabilities, override them. 4773 + */ 4774 + ice_set_safe_mode_caps(hw); 4775 + } 4776 + 4777 + err = ice_init_pf(pf); 4778 + if (err) { 4779 + dev_err(dev, "ice_init_pf failed: %d\n", err); 4780 + goto err_init_pf; 4781 + } 4782 + 4783 + pf->hw.udp_tunnel_nic.set_port = ice_udp_tunnel_set_port; 4784 + pf->hw.udp_tunnel_nic.unset_port = ice_udp_tunnel_unset_port; 4785 + pf->hw.udp_tunnel_nic.flags = UDP_TUNNEL_NIC_INFO_MAY_SLEEP; 4786 + pf->hw.udp_tunnel_nic.shared = &pf->hw.udp_tunnel_shared; 4787 + if (pf->hw.tnl.valid_count[TNL_VXLAN]) { 4788 + pf->hw.udp_tunnel_nic.tables[0].n_entries = 4789 + pf->hw.tnl.valid_count[TNL_VXLAN]; 4790 + pf->hw.udp_tunnel_nic.tables[0].tunnel_types = 4791 + UDP_TUNNEL_TYPE_VXLAN; 4792 + } 4793 + if (pf->hw.tnl.valid_count[TNL_GENEVE]) { 4794 + pf->hw.udp_tunnel_nic.tables[1].n_entries = 4795 + pf->hw.tnl.valid_count[TNL_GENEVE]; 4796 + pf->hw.udp_tunnel_nic.tables[1].tunnel_types = 4797 + UDP_TUNNEL_TYPE_GENEVE; 4798 + } 4799 + 4800 + err = ice_init_interrupt_scheme(pf); 4801 + if (err) { 4802 + dev_err(dev, "ice_init_interrupt_scheme failed: %d\n", err); 4803 + err = -EIO; 4804 + goto err_init_interrupt_scheme; 4805 + } 4806 + 4807 + /* In case of MSIX we are going to setup the misc vector right here 4808 + * to handle admin queue events etc. In case of legacy and MSI 4809 + * the misc functionality and queue processing is combined in 4810 + * the same vector and that gets setup at open. 4811 + */ 4812 + err = ice_req_irq_msix_misc(pf); 4813 + if (err) { 4814 + dev_err(dev, "setup of misc vector failed: %d\n", err); 4815 + goto err_req_irq_msix_misc; 4816 + } 4817 + 4818 + return 0; 4819 + 4820 + err_req_irq_msix_misc: 4821 + ice_clear_interrupt_scheme(pf); 4822 + err_init_interrupt_scheme: 4823 + ice_deinit_pf(pf); 4824 + err_init_pf: 4825 + ice_deinit_hw(hw); 4826 + return err; 4827 + } 4828 + 4829 + static void ice_deinit_dev(struct ice_pf *pf) 4830 + { 4831 + ice_free_irq_msix_misc(pf); 4832 + ice_clear_interrupt_scheme(pf); 4833 + ice_deinit_pf(pf); 4834 + ice_deinit_hw(&pf->hw); 4835 + } 4836 + 4837 + static void ice_init_features(struct ice_pf *pf) 4838 + { 4839 + struct device *dev = ice_pf_to_dev(pf); 4840 + 4841 + if (ice_is_safe_mode(pf)) 4842 + return; 4843 + 4844 + /* initialize DDP driven features */ 4845 + if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags)) 4846 + ice_ptp_init(pf); 4847 + 4848 + if (ice_is_feature_supported(pf, ICE_F_GNSS)) 4849 + ice_gnss_init(pf); 4850 + 4851 + /* Note: Flow director init failure is non-fatal to load */ 4852 + if (ice_init_fdir(pf)) 4853 + dev_err(dev, "could not initialize flow director\n"); 4854 + 4855 + /* Note: DCB init failure is non-fatal to load */ 4856 + if (ice_init_pf_dcb(pf, false)) { 4857 + clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags); 4858 + clear_bit(ICE_FLAG_DCB_ENA, pf->flags); 4859 + } else { 4860 + ice_cfg_lldp_mib_change(&pf->hw, true); 4861 + } 4862 + 4863 + if (ice_init_lag(pf)) 4864 + dev_warn(dev, "Failed to init link aggregation support\n"); 4865 + } 4866 + 4867 + static void ice_deinit_features(struct ice_pf *pf) 4868 + { 4869 + ice_deinit_lag(pf); 4870 + if (test_bit(ICE_FLAG_DCB_CAPABLE, pf->flags)) 4871 + ice_cfg_lldp_mib_change(&pf->hw, false); 4872 + ice_deinit_fdir(pf); 4873 + if (ice_is_feature_supported(pf, ICE_F_GNSS)) 4874 + ice_gnss_exit(pf); 4875 + if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags)) 4876 + ice_ptp_release(pf); 4877 + } 4878 + 4879 + static void ice_init_wakeup(struct ice_pf *pf) 4880 + { 4881 + /* Save wakeup reason register for later use */ 4882 + pf->wakeup_reason = rd32(&pf->hw, PFPM_WUS); 4883 + 4884 + /* check for a power management event */ 4885 + ice_print_wake_reason(pf); 4886 + 4887 + /* clear wake status, all bits */ 4888 + wr32(&pf->hw, PFPM_WUS, U32_MAX); 4889 + 4890 + /* Disable WoL at init, wait for user to enable */ 4891 + device_set_wakeup_enable(ice_pf_to_dev(pf), false); 4892 + } 4893 + 4894 + static int ice_init_link(struct ice_pf *pf) 4895 + { 4896 + struct device *dev = ice_pf_to_dev(pf); 4897 + int err; 4898 + 4899 + err = ice_init_link_events(pf->hw.port_info); 4900 + if (err) { 4901 + dev_err(dev, "ice_init_link_events failed: %d\n", err); 4902 + return err; 4903 + } 4904 + 4905 + /* not a fatal error if this fails */ 4906 + err = ice_init_nvm_phy_type(pf->hw.port_info); 4907 + if (err) 4908 + dev_err(dev, "ice_init_nvm_phy_type failed: %d\n", err); 4909 + 4910 + /* not a fatal error if this fails */ 4911 + err = ice_update_link_info(pf->hw.port_info); 4912 + if (err) 4913 + dev_err(dev, "ice_update_link_info failed: %d\n", err); 4914 + 4915 + ice_init_link_dflt_override(pf->hw.port_info); 4916 + 4917 + ice_check_link_cfg_err(pf, 4918 + pf->hw.port_info->phy.link_info.link_cfg_err); 4919 + 4920 + /* if media available, initialize PHY settings */ 4921 + if (pf->hw.port_info->phy.link_info.link_info & 4922 + ICE_AQ_MEDIA_AVAILABLE) { 4923 + /* not a fatal error if this fails */ 4924 + err = ice_init_phy_user_cfg(pf->hw.port_info); 4925 + if (err) 4926 + dev_err(dev, "ice_init_phy_user_cfg failed: %d\n", err); 4927 + 4928 + if (!test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags)) { 4929 + struct ice_vsi *vsi = ice_get_main_vsi(pf); 4930 + 4931 + if (vsi) 4932 + ice_configure_phy(vsi); 4933 + } 4934 + } else { 4935 + set_bit(ICE_FLAG_NO_MEDIA, pf->flags); 4936 + } 4937 + 4938 + return err; 4939 + } 4940 + 4941 + static int ice_init_pf_sw(struct ice_pf *pf) 4942 + { 4943 + bool dvm = ice_is_dvm_ena(&pf->hw); 4944 + struct ice_vsi *vsi; 4945 + int err; 4946 + 4947 + /* create switch struct for the switch element created by FW on boot */ 4948 + pf->first_sw = kzalloc(sizeof(*pf->first_sw), GFP_KERNEL); 4949 + if (!pf->first_sw) 4950 + return -ENOMEM; 4951 + 4952 + if (pf->hw.evb_veb) 4953 + pf->first_sw->bridge_mode = BRIDGE_MODE_VEB; 4954 + else 4955 + pf->first_sw->bridge_mode = BRIDGE_MODE_VEPA; 4956 + 4957 + pf->first_sw->pf = pf; 4958 + 4959 + /* record the sw_id available for later use */ 4960 + pf->first_sw->sw_id = pf->hw.port_info->sw_id; 4961 + 4962 + err = ice_aq_set_port_params(pf->hw.port_info, dvm, NULL); 4963 + if (err) 4964 + goto err_aq_set_port_params; 4965 + 4966 + vsi = ice_pf_vsi_setup(pf, pf->hw.port_info); 4967 + if (!vsi) { 4968 + err = -ENOMEM; 4969 + goto err_pf_vsi_setup; 4970 + } 4971 + 4972 + return 0; 4973 + 4974 + err_pf_vsi_setup: 4975 + err_aq_set_port_params: 4976 + kfree(pf->first_sw); 4977 + return err; 4978 + } 4979 + 4980 + static void ice_deinit_pf_sw(struct ice_pf *pf) 4981 + { 4982 + struct ice_vsi *vsi = ice_get_main_vsi(pf); 4983 + 4984 + if (!vsi) 4985 + return; 4986 + 4987 + ice_vsi_release(vsi); 4988 + kfree(pf->first_sw); 4989 + } 4990 + 4991 + static int ice_alloc_vsis(struct ice_pf *pf) 4992 + { 4993 + struct device *dev = ice_pf_to_dev(pf); 4994 + 4995 + pf->num_alloc_vsi = pf->hw.func_caps.guar_num_vsi; 4996 + if (!pf->num_alloc_vsi) 4997 + return -EIO; 4998 + 4999 + if (pf->num_alloc_vsi > UDP_TUNNEL_NIC_MAX_SHARING_DEVICES) { 5000 + dev_warn(dev, 5001 + "limiting the VSI count due to UDP tunnel limitation %d > %d\n", 5002 + pf->num_alloc_vsi, UDP_TUNNEL_NIC_MAX_SHARING_DEVICES); 5003 + pf->num_alloc_vsi = UDP_TUNNEL_NIC_MAX_SHARING_DEVICES; 5004 + } 5005 + 5006 + pf->vsi = devm_kcalloc(dev, pf->num_alloc_vsi, sizeof(*pf->vsi), 5007 + GFP_KERNEL); 5008 + if (!pf->vsi) 5009 + return -ENOMEM; 5010 + 5011 + pf->vsi_stats = devm_kcalloc(dev, pf->num_alloc_vsi, 5012 + sizeof(*pf->vsi_stats), GFP_KERNEL); 5013 + if (!pf->vsi_stats) { 5014 + devm_kfree(dev, pf->vsi); 5015 + return -ENOMEM; 5016 + } 5017 + 5018 + return 0; 5019 + } 5020 + 5021 + static void ice_dealloc_vsis(struct ice_pf *pf) 5022 + { 5023 + devm_kfree(ice_pf_to_dev(pf), pf->vsi_stats); 5024 + pf->vsi_stats = NULL; 5025 + 5026 + pf->num_alloc_vsi = 0; 5027 + devm_kfree(ice_pf_to_dev(pf), pf->vsi); 5028 + pf->vsi = NULL; 5029 + } 5030 + 5031 + static int ice_init_devlink(struct ice_pf *pf) 5032 + { 5033 + int err; 5034 + 5035 + err = ice_devlink_register_params(pf); 5036 + if (err) 5037 + return err; 5038 + 5039 + ice_devlink_init_regions(pf); 5040 + ice_devlink_register(pf); 5041 + 5042 + return 0; 5043 + } 5044 + 5045 + static void ice_deinit_devlink(struct ice_pf *pf) 5046 + { 5047 + ice_devlink_unregister(pf); 5048 + ice_devlink_destroy_regions(pf); 5049 + ice_devlink_unregister_params(pf); 5050 + } 5051 + 5052 + static int ice_init(struct ice_pf *pf) 5053 + { 5054 + int err; 5055 + 5056 + err = ice_init_dev(pf); 5057 + if (err) 5058 + return err; 5059 + 5060 + err = ice_alloc_vsis(pf); 5061 + if (err) 5062 + goto err_alloc_vsis; 5063 + 5064 + err = ice_init_pf_sw(pf); 5065 + if (err) 5066 + goto err_init_pf_sw; 5067 + 5068 + ice_init_wakeup(pf); 5069 + 5070 + err = ice_init_link(pf); 5071 + if (err) 5072 + goto err_init_link; 5073 + 5074 + err = ice_send_version(pf); 5075 + if (err) 5076 + goto err_init_link; 5077 + 5078 + ice_verify_cacheline_size(pf); 5079 + 5080 + if (ice_is_safe_mode(pf)) 5081 + ice_set_safe_mode_vlan_cfg(pf); 5082 + else 5083 + /* print PCI link speed and width */ 5084 + pcie_print_link_status(pf->pdev); 5085 + 5086 + /* ready to go, so clear down state bit */ 5087 + clear_bit(ICE_DOWN, pf->state); 5088 + clear_bit(ICE_SERVICE_DIS, pf->state); 5089 + 5090 + /* since everything is good, start the service timer */ 5091 + mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period)); 5092 + 5093 + return 0; 5094 + 5095 + err_init_link: 5096 + ice_deinit_pf_sw(pf); 5097 + err_init_pf_sw: 5098 + ice_dealloc_vsis(pf); 5099 + err_alloc_vsis: 5100 + ice_deinit_dev(pf); 5101 + return err; 5102 + } 5103 + 5104 + static void ice_deinit(struct ice_pf *pf) 5105 + { 5106 + set_bit(ICE_SERVICE_DIS, pf->state); 5107 + set_bit(ICE_DOWN, pf->state); 5108 + 5109 + ice_deinit_pf_sw(pf); 5110 + ice_dealloc_vsis(pf); 5111 + ice_deinit_dev(pf); 5112 + } 5113 + 5114 + /** 5115 + * ice_load - load pf by init hw and starting VSI 5116 + * @pf: pointer to the pf instance 5117 + */ 5118 + int ice_load(struct ice_pf *pf) 5119 + { 5120 + struct ice_vsi *vsi; 5121 + int err; 5122 + 5123 + err = ice_reset(&pf->hw, ICE_RESET_PFR); 5124 + if (err) 5125 + return err; 5126 + 5127 + err = ice_init_dev(pf); 5128 + if (err) 5129 + return err; 5130 + 5131 + vsi = ice_get_main_vsi(pf); 5132 + err = ice_vsi_cfg(vsi, NULL, NULL, ICE_VSI_FLAG_INIT); 5133 + if (err) 5134 + goto err_vsi_cfg; 5135 + 5136 + err = ice_start_eth(ice_get_main_vsi(pf)); 5137 + if (err) 5138 + goto err_start_eth; 5139 + 5140 + err = ice_init_rdma(pf); 5141 + if (err) 5142 + goto err_init_rdma; 5143 + 5144 + ice_init_features(pf); 5145 + ice_service_task_restart(pf); 5146 + 5147 + clear_bit(ICE_DOWN, pf->state); 5148 + 5149 + return 0; 5150 + 5151 + err_init_rdma: 5152 + ice_vsi_close(ice_get_main_vsi(pf)); 5153 + err_start_eth: 5154 + ice_vsi_decfg(ice_get_main_vsi(pf)); 5155 + err_vsi_cfg: 5156 + ice_deinit_dev(pf); 5157 + return err; 5158 + } 5159 + 5160 + /** 5161 + * ice_unload - unload pf by stopping VSI and deinit hw 5162 + * @pf: pointer to the pf instance 5163 + */ 5164 + void ice_unload(struct ice_pf *pf) 5165 + { 5166 + ice_deinit_features(pf); 5167 + ice_deinit_rdma(pf); 5168 + ice_vsi_close(ice_get_main_vsi(pf)); 5169 + ice_vsi_decfg(ice_get_main_vsi(pf)); 5170 + ice_deinit_dev(pf); 4503 5171 } 4504 5172 4505 5173 /** ··· 5066 4628 ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent) 5067 4629 { 5068 4630 struct device *dev = &pdev->dev; 5069 - struct ice_vsi *vsi; 5070 4631 struct ice_pf *pf; 5071 4632 struct ice_hw *hw; 5072 - int i, err; 4633 + int err; 5073 4634 5074 4635 if (pdev->is_virtfn) { 5075 4636 dev_err(dev, "can't probe a virtual function\n"); ··· 5115 4678 pci_save_state(pdev); 5116 4679 5117 4680 hw->back = pf; 4681 + hw->port_info = NULL; 5118 4682 hw->vendor_id = pdev->vendor; 5119 4683 hw->device_id = pdev->device; 5120 4684 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); ··· 5132 4694 hw->debug_mask = debug; 5133 4695 #endif 5134 4696 5135 - err = ice_init_hw(hw); 5136 - if (err) { 5137 - dev_err(dev, "ice_init_hw failed: %d\n", err); 5138 - err = -EIO; 5139 - goto err_exit_unroll; 5140 - } 5141 - 5142 - ice_init_feature_support(pf); 5143 - 5144 - ice_request_fw(pf); 5145 - 5146 - /* if ice_request_fw fails, ICE_FLAG_ADV_FEATURES bit won't be 5147 - * set in pf->state, which will cause ice_is_safe_mode to return 5148 - * true 5149 - */ 5150 - if (ice_is_safe_mode(pf)) { 5151 - /* we already got function/device capabilities but these don't 5152 - * reflect what the driver needs to do in safe mode. Instead of 5153 - * adding conditional logic everywhere to ignore these 5154 - * device/function capabilities, override them. 5155 - */ 5156 - ice_set_safe_mode_caps(hw); 5157 - } 5158 - 5159 - err = ice_init_pf(pf); 5160 - if (err) { 5161 - dev_err(dev, "ice_init_pf failed: %d\n", err); 5162 - goto err_init_pf_unroll; 5163 - } 5164 - 5165 - ice_devlink_init_regions(pf); 5166 - 5167 - pf->hw.udp_tunnel_nic.set_port = ice_udp_tunnel_set_port; 5168 - pf->hw.udp_tunnel_nic.unset_port = ice_udp_tunnel_unset_port; 5169 - pf->hw.udp_tunnel_nic.flags = UDP_TUNNEL_NIC_INFO_MAY_SLEEP; 5170 - pf->hw.udp_tunnel_nic.shared = &pf->hw.udp_tunnel_shared; 5171 - i = 0; 5172 - if (pf->hw.tnl.valid_count[TNL_VXLAN]) { 5173 - pf->hw.udp_tunnel_nic.tables[i].n_entries = 5174 - pf->hw.tnl.valid_count[TNL_VXLAN]; 5175 - pf->hw.udp_tunnel_nic.tables[i].tunnel_types = 5176 - UDP_TUNNEL_TYPE_VXLAN; 5177 - i++; 5178 - } 5179 - if (pf->hw.tnl.valid_count[TNL_GENEVE]) { 5180 - pf->hw.udp_tunnel_nic.tables[i].n_entries = 5181 - pf->hw.tnl.valid_count[TNL_GENEVE]; 5182 - pf->hw.udp_tunnel_nic.tables[i].tunnel_types = 5183 - UDP_TUNNEL_TYPE_GENEVE; 5184 - i++; 5185 - } 5186 - 5187 - pf->num_alloc_vsi = hw->func_caps.guar_num_vsi; 5188 - if (!pf->num_alloc_vsi) { 5189 - err = -EIO; 5190 - goto err_init_pf_unroll; 5191 - } 5192 - if (pf->num_alloc_vsi > UDP_TUNNEL_NIC_MAX_SHARING_DEVICES) { 5193 - dev_warn(&pf->pdev->dev, 5194 - "limiting the VSI count due to UDP tunnel limitation %d > %d\n", 5195 - pf->num_alloc_vsi, UDP_TUNNEL_NIC_MAX_SHARING_DEVICES); 5196 - pf->num_alloc_vsi = UDP_TUNNEL_NIC_MAX_SHARING_DEVICES; 5197 - } 5198 - 5199 - pf->vsi = devm_kcalloc(dev, pf->num_alloc_vsi, sizeof(*pf->vsi), 5200 - GFP_KERNEL); 5201 - if (!pf->vsi) { 5202 - err = -ENOMEM; 5203 - goto err_init_pf_unroll; 5204 - } 5205 - 5206 - pf->vsi_stats = devm_kcalloc(dev, pf->num_alloc_vsi, 5207 - sizeof(*pf->vsi_stats), GFP_KERNEL); 5208 - if (!pf->vsi_stats) { 5209 - err = -ENOMEM; 5210 - goto err_init_vsi_unroll; 5211 - } 5212 - 5213 - err = ice_init_interrupt_scheme(pf); 5214 - if (err) { 5215 - dev_err(dev, "ice_init_interrupt_scheme failed: %d\n", err); 5216 - err = -EIO; 5217 - goto err_init_vsi_stats_unroll; 5218 - } 5219 - 5220 - /* In case of MSIX we are going to setup the misc vector right here 5221 - * to handle admin queue events etc. In case of legacy and MSI 5222 - * the misc functionality and queue processing is combined in 5223 - * the same vector and that gets setup at open. 5224 - */ 5225 - err = ice_req_irq_msix_misc(pf); 5226 - if (err) { 5227 - dev_err(dev, "setup of misc vector failed: %d\n", err); 5228 - goto err_init_interrupt_unroll; 5229 - } 5230 - 5231 - /* create switch struct for the switch element created by FW on boot */ 5232 - pf->first_sw = devm_kzalloc(dev, sizeof(*pf->first_sw), GFP_KERNEL); 5233 - if (!pf->first_sw) { 5234 - err = -ENOMEM; 5235 - goto err_msix_misc_unroll; 5236 - } 5237 - 5238 - if (hw->evb_veb) 5239 - pf->first_sw->bridge_mode = BRIDGE_MODE_VEB; 5240 - else 5241 - pf->first_sw->bridge_mode = BRIDGE_MODE_VEPA; 5242 - 5243 - pf->first_sw->pf = pf; 5244 - 5245 - /* record the sw_id available for later use */ 5246 - pf->first_sw->sw_id = hw->port_info->sw_id; 5247 - 5248 - err = ice_setup_pf_sw(pf); 5249 - if (err) { 5250 - dev_err(dev, "probe failed due to setup PF switch: %d\n", err); 5251 - goto err_alloc_sw_unroll; 5252 - } 5253 - 5254 - clear_bit(ICE_SERVICE_DIS, pf->state); 5255 - 5256 - /* tell the firmware we are up */ 5257 - err = ice_send_version(pf); 5258 - if (err) { 5259 - dev_err(dev, "probe failed sending driver version %s. error: %d\n", 5260 - UTS_RELEASE, err); 5261 - goto err_send_version_unroll; 5262 - } 5263 - 5264 - /* since everything is good, start the service timer */ 5265 - mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period)); 5266 - 5267 - err = ice_init_link_events(pf->hw.port_info); 5268 - if (err) { 5269 - dev_err(dev, "ice_init_link_events failed: %d\n", err); 5270 - goto err_send_version_unroll; 5271 - } 5272 - 5273 - /* not a fatal error if this fails */ 5274 - err = ice_init_nvm_phy_type(pf->hw.port_info); 4697 + err = ice_init(pf); 5275 4698 if (err) 5276 - dev_err(dev, "ice_init_nvm_phy_type failed: %d\n", err); 4699 + goto err_init; 5277 4700 5278 - /* not a fatal error if this fails */ 5279 - err = ice_update_link_info(pf->hw.port_info); 4701 + err = ice_init_eth(pf); 5280 4702 if (err) 5281 - dev_err(dev, "ice_update_link_info failed: %d\n", err); 4703 + goto err_init_eth; 5282 4704 5283 - ice_init_link_dflt_override(pf->hw.port_info); 5284 - 5285 - ice_check_link_cfg_err(pf, 5286 - pf->hw.port_info->phy.link_info.link_cfg_err); 5287 - 5288 - /* if media available, initialize PHY settings */ 5289 - if (pf->hw.port_info->phy.link_info.link_info & 5290 - ICE_AQ_MEDIA_AVAILABLE) { 5291 - /* not a fatal error if this fails */ 5292 - err = ice_init_phy_user_cfg(pf->hw.port_info); 5293 - if (err) 5294 - dev_err(dev, "ice_init_phy_user_cfg failed: %d\n", err); 5295 - 5296 - if (!test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags)) { 5297 - struct ice_vsi *vsi = ice_get_main_vsi(pf); 5298 - 5299 - if (vsi) 5300 - ice_configure_phy(vsi); 5301 - } 5302 - } else { 5303 - set_bit(ICE_FLAG_NO_MEDIA, pf->flags); 5304 - } 5305 - 5306 - ice_verify_cacheline_size(pf); 5307 - 5308 - /* Save wakeup reason register for later use */ 5309 - pf->wakeup_reason = rd32(hw, PFPM_WUS); 5310 - 5311 - /* check for a power management event */ 5312 - ice_print_wake_reason(pf); 5313 - 5314 - /* clear wake status, all bits */ 5315 - wr32(hw, PFPM_WUS, U32_MAX); 5316 - 5317 - /* Disable WoL at init, wait for user to enable */ 5318 - device_set_wakeup_enable(dev, false); 5319 - 5320 - if (ice_is_safe_mode(pf)) { 5321 - ice_set_safe_mode_vlan_cfg(pf); 5322 - goto probe_done; 5323 - } 5324 - 5325 - /* initialize DDP driven features */ 5326 - if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags)) 5327 - ice_ptp_init(pf); 5328 - 5329 - if (ice_is_feature_supported(pf, ICE_F_GNSS)) 5330 - ice_gnss_init(pf); 5331 - 5332 - /* Note: Flow director init failure is non-fatal to load */ 5333 - if (ice_init_fdir(pf)) 5334 - dev_err(dev, "could not initialize flow director\n"); 5335 - 5336 - /* Note: DCB init failure is non-fatal to load */ 5337 - if (ice_init_pf_dcb(pf, false)) { 5338 - clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags); 5339 - clear_bit(ICE_FLAG_DCB_ENA, pf->flags); 5340 - } else { 5341 - ice_cfg_lldp_mib_change(&pf->hw, true); 5342 - } 5343 - 5344 - if (ice_init_lag(pf)) 5345 - dev_warn(dev, "Failed to init link aggregation support\n"); 5346 - 5347 - /* print PCI link speed and width */ 5348 - pcie_print_link_status(pf->pdev); 5349 - 5350 - probe_done: 5351 - err = ice_devlink_create_pf_port(pf); 4705 + err = ice_init_rdma(pf); 5352 4706 if (err) 5353 - goto err_create_pf_port; 4707 + goto err_init_rdma; 5354 4708 5355 - vsi = ice_get_main_vsi(pf); 5356 - if (!vsi || !vsi->netdev) { 5357 - err = -EINVAL; 5358 - goto err_netdev_reg; 5359 - } 5360 - 5361 - SET_NETDEV_DEVLINK_PORT(vsi->netdev, &pf->devlink_port); 5362 - 5363 - err = ice_register_netdev(pf); 4709 + err = ice_init_devlink(pf); 5364 4710 if (err) 5365 - goto err_netdev_reg; 4711 + goto err_init_devlink; 5366 4712 5367 - err = ice_devlink_register_params(pf); 5368 - if (err) 5369 - goto err_netdev_reg; 4713 + ice_init_features(pf); 5370 4714 5371 - /* ready to go, so clear down state bit */ 5372 - clear_bit(ICE_DOWN, pf->state); 5373 - if (ice_is_rdma_ena(pf)) { 5374 - pf->aux_idx = ida_alloc(&ice_aux_ida, GFP_KERNEL); 5375 - if (pf->aux_idx < 0) { 5376 - dev_err(dev, "Failed to allocate device ID for AUX driver\n"); 5377 - err = -ENOMEM; 5378 - goto err_devlink_reg_param; 5379 - } 5380 - 5381 - err = ice_init_rdma(pf); 5382 - if (err) { 5383 - dev_err(dev, "Failed to initialize RDMA: %d\n", err); 5384 - err = -EIO; 5385 - goto err_init_aux_unroll; 5386 - } 5387 - } else { 5388 - dev_warn(dev, "RDMA is not supported on this device\n"); 5389 - } 5390 - 5391 - ice_devlink_register(pf); 5392 4715 return 0; 5393 4716 5394 - err_init_aux_unroll: 5395 - pf->adev = NULL; 5396 - ida_free(&ice_aux_ida, pf->aux_idx); 5397 - err_devlink_reg_param: 5398 - ice_devlink_unregister_params(pf); 5399 - err_netdev_reg: 5400 - ice_devlink_destroy_pf_port(pf); 5401 - err_create_pf_port: 5402 - err_send_version_unroll: 5403 - ice_vsi_release_all(pf); 5404 - err_alloc_sw_unroll: 5405 - set_bit(ICE_SERVICE_DIS, pf->state); 5406 - set_bit(ICE_DOWN, pf->state); 5407 - devm_kfree(dev, pf->first_sw); 5408 - err_msix_misc_unroll: 5409 - ice_free_irq_msix_misc(pf); 5410 - err_init_interrupt_unroll: 5411 - ice_clear_interrupt_scheme(pf); 5412 - err_init_vsi_stats_unroll: 5413 - devm_kfree(dev, pf->vsi_stats); 5414 - pf->vsi_stats = NULL; 5415 - err_init_vsi_unroll: 5416 - devm_kfree(dev, pf->vsi); 5417 - err_init_pf_unroll: 5418 - ice_deinit_pf(pf); 5419 - ice_devlink_destroy_regions(pf); 5420 - ice_deinit_hw(hw); 5421 - err_exit_unroll: 4717 + err_init_devlink: 4718 + ice_deinit_rdma(pf); 4719 + err_init_rdma: 4720 + ice_deinit_eth(pf); 4721 + err_init_eth: 4722 + ice_deinit(pf); 4723 + err_init: 5422 4724 pci_disable_device(pdev); 5423 4725 return err; 5424 4726 } ··· 5231 5053 static void ice_remove(struct pci_dev *pdev) 5232 5054 { 5233 5055 struct ice_pf *pf = pci_get_drvdata(pdev); 5234 - struct ice_hw *hw; 5235 5056 int i; 5236 5057 5237 - hw = &pf->hw; 5238 - 5239 - ice_devlink_unregister(pf); 5240 5058 for (i = 0; i < ICE_MAX_RESET_WAIT; i++) { 5241 5059 if (!ice_is_reset_in_progress(pf->state)) 5242 5060 break; 5243 5061 msleep(100); 5244 5062 } 5245 - 5246 - ice_tc_indir_block_remove(pf); 5247 5063 5248 5064 if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags)) { 5249 5065 set_bit(ICE_VF_RESETS_DISABLED, pf->state); ··· 5245 5073 } 5246 5074 5247 5075 ice_service_task_stop(pf); 5248 - 5249 5076 ice_aq_cancel_waiting_tasks(pf); 5250 - ice_unplug_aux_dev(pf); 5251 - if (pf->aux_idx >= 0) 5252 - ida_free(&ice_aux_ida, pf->aux_idx); 5253 - ice_devlink_unregister_params(pf); 5254 5077 set_bit(ICE_DOWN, pf->state); 5255 5078 5256 - ice_deinit_lag(pf); 5257 - if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags)) 5258 - ice_ptp_release(pf); 5259 - if (ice_is_feature_supported(pf, ICE_F_GNSS)) 5260 - ice_gnss_exit(pf); 5261 5079 if (!ice_is_safe_mode(pf)) 5262 5080 ice_remove_arfs(pf); 5263 - ice_setup_mc_magic_wake(pf); 5081 + ice_deinit_features(pf); 5082 + ice_deinit_devlink(pf); 5083 + ice_deinit_rdma(pf); 5084 + ice_deinit_eth(pf); 5085 + ice_deinit(pf); 5086 + 5264 5087 ice_vsi_release_all(pf); 5265 - mutex_destroy(&hw->fdir_fltr_lock); 5266 - ice_devlink_destroy_pf_port(pf); 5088 + 5089 + ice_setup_mc_magic_wake(pf); 5267 5090 ice_set_wake(pf); 5268 - ice_free_irq_msix_misc(pf); 5269 - ice_for_each_vsi(pf, i) { 5270 - if (!pf->vsi[i]) 5271 - continue; 5272 - ice_vsi_free_q_vectors(pf->vsi[i]); 5273 - } 5274 - devm_kfree(&pdev->dev, pf->vsi_stats); 5275 - pf->vsi_stats = NULL; 5276 - ice_deinit_pf(pf); 5277 - ice_devlink_destroy_regions(pf); 5278 - ice_deinit_hw(hw); 5279 5091 5280 5092 /* Issue a PFR as part of the prescribed driver unload flow. Do not 5281 5093 * do it via ice_schedule_reset() since there is no need to rebuild 5282 5094 * and the service task is already stopped. 5283 5095 */ 5284 - ice_reset(hw, ICE_RESET_PFR); 5096 + ice_reset(&pf->hw, ICE_RESET_PFR); 5285 5097 pci_wait_for_pending_transaction(pdev); 5286 - ice_clear_interrupt_scheme(pf); 5287 5098 pci_disable_device(pdev); 5288 5099 } 5289 5100 ··· 6300 6145 } 6301 6146 6302 6147 /** 6303 - * ice_vsi_cfg - Setup the VSI 6148 + * ice_vsi_cfg_lan - Setup the VSI lan related config 6304 6149 * @vsi: the VSI being configured 6305 6150 * 6306 6151 * Return 0 on success and negative value on error 6307 6152 */ 6308 - int ice_vsi_cfg(struct ice_vsi *vsi) 6153 + int ice_vsi_cfg_lan(struct ice_vsi *vsi) 6309 6154 { 6310 6155 int err; 6311 6156 ··· 6521 6366 { 6522 6367 int err; 6523 6368 6524 - err = ice_vsi_cfg(vsi); 6369 + err = ice_vsi_cfg_lan(vsi); 6525 6370 if (!err) 6526 6371 err = ice_up_complete(vsi); 6527 6372 ··· 7089 6934 if (err) 7090 6935 goto err_setup_rx; 7091 6936 7092 - err = ice_vsi_cfg(vsi); 6937 + err = ice_vsi_cfg_lan(vsi); 7093 6938 if (err) 7094 6939 goto err_setup_rx; 7095 6940 ··· 7143 6988 if (err) 7144 6989 goto err_setup_rx; 7145 6990 7146 - err = ice_vsi_cfg(vsi); 6991 + err = ice_vsi_cfg_lan(vsi); 7147 6992 if (err) 7148 6993 goto err_setup_rx; 7149 6994 ··· 7228 7073 continue; 7229 7074 7230 7075 /* rebuild the VSI */ 7231 - err = ice_vsi_rebuild(vsi, true); 7076 + err = ice_vsi_rebuild(vsi, ICE_VSI_FLAG_INIT); 7232 7077 if (err) { 7233 7078 dev_err(dev, "rebuild VSI failed, err %d, VSI index %d, type %s\n", 7234 7079 err, vsi->idx, ice_vsi_type_str(type)); ··· 8573 8418 /* clear the VSI from scheduler tree */ 8574 8419 ice_rm_vsi_lan_cfg(ch->ch_vsi->port_info, ch->ch_vsi->idx); 8575 8420 8576 - /* Delete VSI from FW */ 8421 + /* Delete VSI from FW, PF and HW VSI arrays */ 8577 8422 ice_vsi_delete(ch->ch_vsi); 8578 - 8579 - /* Delete VSI from PF and HW VSI arrays */ 8580 - ice_vsi_clear(ch->ch_vsi); 8581 8423 8582 8424 /* free the channel */ 8583 8425 kfree(ch); ··· 8634 8482 type = vsi->type; 8635 8483 8636 8484 /* rebuild ADQ VSI */ 8637 - err = ice_vsi_rebuild(vsi, true); 8485 + err = ice_vsi_rebuild(vsi, ICE_VSI_FLAG_INIT); 8638 8486 if (err) { 8639 8487 dev_err(dev, "VSI (type:%s) at index %d rebuild failed, err %d\n", 8640 8488 ice_vsi_type_str(type), vsi->idx, err); ··· 8866 8714 cur_rxq = vsi->num_rxq; 8867 8715 8868 8716 /* proceed with rebuild main VSI using correct number of queues */ 8869 - ret = ice_vsi_rebuild(vsi, false); 8717 + ret = ice_vsi_rebuild(vsi, ICE_VSI_FLAG_NO_INIT); 8870 8718 if (ret) { 8871 8719 /* fallback to current number of queues */ 8872 8720 dev_info(dev, "Rebuild failed with new queues, try with current number of queues\n"); 8873 8721 vsi->req_txq = cur_txq; 8874 8722 vsi->req_rxq = cur_rxq; 8875 8723 clear_bit(ICE_RESET_FAILED, pf->state); 8876 - if (ice_vsi_rebuild(vsi, false)) { 8724 + if (ice_vsi_rebuild(vsi, ICE_VSI_FLAG_NO_INIT)) { 8877 8725 dev_err(dev, "Rebuild of main VSI failed again\n"); 8878 8726 return ret; 8879 8727 }
+1 -1
drivers/net/ethernet/intel/ice/ice_vf_lib.c
··· 256 256 if (WARN_ON(!vsi)) 257 257 return -EINVAL; 258 258 259 - if (ice_vsi_rebuild(vsi, true)) { 259 + if (ice_vsi_rebuild(vsi, ICE_VSI_FLAG_INIT)) { 260 260 dev_err(ice_pf_to_dev(pf), "failed to rebuild VF %d VSI\n", 261 261 vf->vf_id); 262 262 return -EIO;