@@ -371,57 +371,105 @@ static int ice_devlink_info_get(struct devlink *devlink,
371371}
372372
373373/**
374- * ice_devlink_flash_update - Update firmware stored in flash on the device
375- * @devlink: pointer to devlink associated with device to update
376- * @params: flash update parameters
374+ * ice_devlink_reload_empr_start - Start EMP reset to activate new firmware
375+ * @devlink: pointer to the devlink instance to reload
376+ * @netns_change: if true, the network namespace is changing
377+ * @action: the action to perform. Must be DEVLINK_RELOAD_ACTION_FW_ACTIVATE
378+ * @limit: limits on what reload should do, such as not resetting
377379 * @extack: netlink extended ACK structure
378380 *
379- * Perform a device flash update. The bulk of the update logic is contained
380- * within the ice_flash_pldm_image function.
381+ * Allow user to activate new Embedded Management Processor firmware by
382+ * issuing device specific EMP reset. Called in response to
383+ * a DEVLINK_CMD_RELOAD with the DEVLINK_RELOAD_ACTION_FW_ACTIVATE.
381384 *
382- * Returns: zero on success, or an error code on failure.
385+ * Note that teardown and rebuild of the driver state happens automatically as
386+ * part of an interrupt and watchdog task. This is because all physical
387+ * functions on the device must be able to reset when an EMP reset occurs from
388+ * any source.
383389 */
384390static int
385- ice_devlink_flash_update (struct devlink * devlink ,
386- struct devlink_flash_update_params * params ,
387- struct netlink_ext_ack * extack )
391+ ice_devlink_reload_empr_start (struct devlink * devlink , bool netns_change ,
392+ enum devlink_reload_action action ,
393+ enum devlink_reload_limit limit ,
394+ struct netlink_ext_ack * extack )
388395{
389396 struct ice_pf * pf = devlink_priv (devlink );
397+ struct device * dev = ice_pf_to_dev (pf );
390398 struct ice_hw * hw = & pf -> hw ;
391- u8 preservation ;
399+ u8 pending ;
392400 int err ;
393401
394- if (!params -> overwrite_mask ) {
395- /* preserve all settings and identifiers */
396- preservation = ICE_AQC_NVM_PRESERVE_ALL ;
397- } else if (params -> overwrite_mask == DEVLINK_FLASH_OVERWRITE_SETTINGS ) {
398- /* overwrite settings, but preserve the vital device identifiers */
399- preservation = ICE_AQC_NVM_PRESERVE_SELECTED ;
400- } else if (params -> overwrite_mask == (DEVLINK_FLASH_OVERWRITE_SETTINGS |
401- DEVLINK_FLASH_OVERWRITE_IDENTIFIERS )) {
402- /* overwrite both settings and identifiers, preserve nothing */
403- preservation = ICE_AQC_NVM_NO_PRESERVATION ;
404- } else {
405- NL_SET_ERR_MSG_MOD (extack , "Requested overwrite mask is not supported" );
406- return - EOPNOTSUPP ;
402+ err = ice_get_pending_updates (pf , & pending , extack );
403+ if (err )
404+ return err ;
405+
406+ /* pending is a bitmask of which flash banks have a pending update,
407+ * including the main NVM bank, the Option ROM bank, and the netlist
408+ * bank. If any of these bits are set, then there is a pending update
409+ * waiting to be activated.
410+ */
411+ if (!pending ) {
412+ NL_SET_ERR_MSG_MOD (extack , "No pending firmware update" );
413+ return - ECANCELED ;
407414 }
408415
409- if (! hw -> dev_caps . common_cap . nvm_unified_update ) {
410- NL_SET_ERR_MSG_MOD (extack , "Current firmware does not support unified update " );
411- return - EOPNOTSUPP ;
416+ if (pf -> fw_emp_reset_disabled ) {
417+ NL_SET_ERR_MSG_MOD (extack , "EMP reset is not available. To activate firmware, a reboot or power cycle is needed " );
418+ return - ECANCELED ;
412419 }
413420
414- err = ice_check_for_pending_update (pf , NULL , extack );
415- if (err )
421+ dev_dbg (dev , "Issuing device EMP reset to activate firmware\n" );
422+
423+ err = ice_aq_nvm_update_empr (hw );
424+ if (err ) {
425+ dev_err (dev , "Failed to trigger EMP device reset to reload firmware, err %d aq_err %s\n" ,
426+ err , ice_aq_str (hw -> adminq .sq_last_status ));
427+ NL_SET_ERR_MSG_MOD (extack , "Failed to trigger EMP device reset to reload firmware" );
416428 return err ;
429+ }
417430
418- devlink_flash_update_status_notify (devlink , "Preparing to flash" , NULL , 0 , 0 );
431+ return 0 ;
432+ }
419433
420- return ice_flash_pldm_image (pf , params -> fw , preservation , extack );
434+ /**
435+ * ice_devlink_reload_empr_finish - Wait for EMP reset to finish
436+ * @devlink: pointer to the devlink instance reloading
437+ * @action: the action requested
438+ * @limit: limits imposed by userspace, such as not resetting
439+ * @actions_performed: on return, indicate what actions actually performed
440+ * @extack: netlink extended ACK structure
441+ *
442+ * Wait for driver to finish rebuilding after EMP reset is completed. This
443+ * includes time to wait for both the actual device reset as well as the time
444+ * for the driver's rebuild to complete.
445+ */
446+ static int
447+ ice_devlink_reload_empr_finish (struct devlink * devlink ,
448+ enum devlink_reload_action action ,
449+ enum devlink_reload_limit limit ,
450+ u32 * actions_performed ,
451+ struct netlink_ext_ack * extack )
452+ {
453+ struct ice_pf * pf = devlink_priv (devlink );
454+ int err ;
455+
456+ * actions_performed = BIT (DEVLINK_RELOAD_ACTION_FW_ACTIVATE );
457+
458+ err = ice_wait_for_reset (pf , 60 * HZ );
459+ if (err ) {
460+ NL_SET_ERR_MSG_MOD (extack , "Device still resetting after 1 minute" );
461+ return err ;
462+ }
463+
464+ return 0 ;
421465}
422466
423467static const struct devlink_ops ice_devlink_ops = {
424468 .supported_flash_update_params = DEVLINK_SUPPORT_FLASH_UPDATE_OVERWRITE_MASK ,
469+ .reload_actions = BIT (DEVLINK_RELOAD_ACTION_FW_ACTIVATE ),
470+ /* The ice driver currently does not support driver reinit */
471+ .reload_down = ice_devlink_reload_empr_start ,
472+ .reload_up = ice_devlink_reload_empr_finish ,
425473 .eswitch_mode_get = ice_eswitch_mode_get ,
426474 .eswitch_mode_set = ice_eswitch_mode_set ,
427475 .info_get = ice_devlink_info_get ,
@@ -582,6 +630,7 @@ void ice_devlink_register(struct ice_pf *pf)
582630{
583631 struct devlink * devlink = priv_to_devlink (pf );
584632
633+ devlink_set_features (devlink , DEVLINK_F_RELOAD );
585634 devlink_register (devlink );
586635}
587636
@@ -739,16 +788,20 @@ void ice_devlink_destroy_vf_port(struct ice_vf *vf)
739788}
740789
741790/**
742- * ice_devlink_nvm_snapshot - Capture a snapshot of the Shadow RAM contents
791+ * ice_devlink_nvm_snapshot - Capture a snapshot of the NVM flash contents
743792 * @devlink: the devlink instance
744793 * @ops: the devlink region being snapshotted
745794 * @extack: extended ACK response structure
746795 * @data: on exit points to snapshot data buffer
747796 *
748797 * This function is called in response to the DEVLINK_CMD_REGION_TRIGGER for
749- * the shadow-ram devlink region. It captures a snapshot of the shadow ram
750- * contents. This snapshot can later be viewed via the devlink-region
751- * interface.
798+ * the nvm-flash devlink region. It captures a snapshot of the full NVM flash
799+ * contents, including both banks of flash. This snapshot can later be viewed
800+ * via the devlink-region interface.
801+ *
802+ * It captures the flash using the FLASH_ONLY bit set when reading via
803+ * firmware, so it does not read the current Shadow RAM contents. For that,
804+ * use the shadow-ram region.
752805 *
753806 * @returns zero on success, and updates the data pointer. Returns a non-zero
754807 * error code on failure.
@@ -795,6 +848,66 @@ static int ice_devlink_nvm_snapshot(struct devlink *devlink,
795848 return 0 ;
796849}
797850
851+ /**
852+ * ice_devlink_sram_snapshot - Capture a snapshot of the Shadow RAM contents
853+ * @devlink: the devlink instance
854+ * @ops: the devlink region being snapshotted
855+ * @extack: extended ACK response structure
856+ * @data: on exit points to snapshot data buffer
857+ *
858+ * This function is called in response to the DEVLINK_CMD_REGION_TRIGGER for
859+ * the shadow-ram devlink region. It captures a snapshot of the shadow ram
860+ * contents. This snapshot can later be viewed via the devlink-region
861+ * interface.
862+ *
863+ * @returns zero on success, and updates the data pointer. Returns a non-zero
864+ * error code on failure.
865+ */
866+ static int
867+ ice_devlink_sram_snapshot (struct devlink * devlink ,
868+ const struct devlink_region_ops __always_unused * ops ,
869+ struct netlink_ext_ack * extack , u8 * * data )
870+ {
871+ struct ice_pf * pf = devlink_priv (devlink );
872+ struct device * dev = ice_pf_to_dev (pf );
873+ struct ice_hw * hw = & pf -> hw ;
874+ u8 * sram_data ;
875+ u32 sram_size ;
876+ int err ;
877+
878+ sram_size = hw -> flash .sr_words * 2u ;
879+ sram_data = vzalloc (sram_size );
880+ if (!sram_data )
881+ return - ENOMEM ;
882+
883+ err = ice_acquire_nvm (hw , ICE_RES_READ );
884+ if (err ) {
885+ dev_dbg (dev , "ice_acquire_nvm failed, err %d aq_err %d\n" ,
886+ err , hw -> adminq .sq_last_status );
887+ NL_SET_ERR_MSG_MOD (extack , "Failed to acquire NVM semaphore" );
888+ vfree (sram_data );
889+ return err ;
890+ }
891+
892+ /* Read from the Shadow RAM, rather than directly from NVM */
893+ err = ice_read_flat_nvm (hw , 0 , & sram_size , sram_data , true);
894+ if (err ) {
895+ dev_dbg (dev , "ice_read_flat_nvm failed after reading %u bytes, err %d aq_err %d\n" ,
896+ sram_size , err , hw -> adminq .sq_last_status );
897+ NL_SET_ERR_MSG_MOD (extack ,
898+ "Failed to read Shadow RAM contents" );
899+ ice_release_nvm (hw );
900+ vfree (sram_data );
901+ return err ;
902+ }
903+
904+ ice_release_nvm (hw );
905+
906+ * data = sram_data ;
907+
908+ return 0 ;
909+ }
910+
798911/**
799912 * ice_devlink_devcaps_snapshot - Capture snapshot of device capabilities
800913 * @devlink: the devlink instance
@@ -845,6 +958,12 @@ static const struct devlink_region_ops ice_nvm_region_ops = {
845958 .snapshot = ice_devlink_nvm_snapshot ,
846959};
847960
961+ static const struct devlink_region_ops ice_sram_region_ops = {
962+ .name = "shadow-ram" ,
963+ .destructor = vfree ,
964+ .snapshot = ice_devlink_sram_snapshot ,
965+ };
966+
848967static const struct devlink_region_ops ice_devcaps_region_ops = {
849968 .name = "device-caps" ,
850969 .destructor = vfree ,
@@ -862,7 +981,7 @@ void ice_devlink_init_regions(struct ice_pf *pf)
862981{
863982 struct devlink * devlink = priv_to_devlink (pf );
864983 struct device * dev = ice_pf_to_dev (pf );
865- u64 nvm_size ;
984+ u64 nvm_size , sram_size ;
866985
867986 nvm_size = pf -> hw .flash .flash_size ;
868987 pf -> nvm_region = devlink_region_create (devlink , & ice_nvm_region_ops , 1 ,
@@ -873,6 +992,15 @@ void ice_devlink_init_regions(struct ice_pf *pf)
873992 pf -> nvm_region = NULL ;
874993 }
875994
995+ sram_size = pf -> hw .flash .sr_words * 2u ;
996+ pf -> sram_region = devlink_region_create (devlink , & ice_sram_region_ops ,
997+ 1 , sram_size );
998+ if (IS_ERR (pf -> sram_region )) {
999+ dev_err (dev , "failed to create shadow-ram devlink region, err %ld\n" ,
1000+ PTR_ERR (pf -> sram_region ));
1001+ pf -> sram_region = NULL ;
1002+ }
1003+
8761004 pf -> devcaps_region = devlink_region_create (devlink ,
8771005 & ice_devcaps_region_ops , 10 ,
8781006 ICE_AQ_MAX_BUF_LEN );
@@ -893,6 +1021,10 @@ void ice_devlink_destroy_regions(struct ice_pf *pf)
8931021{
8941022 if (pf -> nvm_region )
8951023 devlink_region_destroy (pf -> nvm_region );
1024+
1025+ if (pf -> sram_region )
1026+ devlink_region_destroy (pf -> sram_region );
1027+
8961028 if (pf -> devcaps_region )
8971029 devlink_region_destroy (pf -> devcaps_region );
8981030}
0 commit comments