Skip to content

Commit 78ad87d

Browse files
jacob-kelleranguy11
authored andcommitted
ice: devlink: add shadow-ram region to snapshot Shadow RAM
We have a region for reading the contents of the NVM flash as a snapshot. This region does not allow reading the Shadow RAM, as it always passes the FLASH_ONLY bit to the low level firmware interface. Add a separate shadow-ram region which will allow snapshot of the current contents of the Shadow RAM. This data is built from the NVM contents but is distinct as the device builds up the Shadow RAM during initialization, so being able to snapshot its contents can be useful when attempting to debug flash related issues. Fix the comment description of the nvm-flash region which incorrectly stated that it filled the shadow-ram region, and add a comment explaining that the nvm-flash region does not actually read the Shadow RAM. Signed-off-by: Jacob Keller <[email protected]> Tested-by: Gurucharan G <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 3bc14ea commit 78ad87d

File tree

2 files changed

+89
-5
lines changed

2 files changed

+89
-5
lines changed

drivers/net/ethernet/intel/ice/ice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ struct ice_pf {
503503
struct pci_dev *pdev;
504504

505505
struct devlink_region *nvm_region;
506+
struct devlink_region *sram_region;
506507
struct devlink_region *devcaps_region;
507508

508509
/* devlink port data */

drivers/net/ethernet/intel/ice/ice_devlink.c

Lines changed: 88 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -739,16 +739,20 @@ void ice_devlink_destroy_vf_port(struct ice_vf *vf)
739739
}
740740

741741
/**
742-
* ice_devlink_nvm_snapshot - Capture a snapshot of the Shadow RAM contents
742+
* ice_devlink_nvm_snapshot - Capture a snapshot of the NVM flash contents
743743
* @devlink: the devlink instance
744744
* @ops: the devlink region being snapshotted
745745
* @extack: extended ACK response structure
746746
* @data: on exit points to snapshot data buffer
747747
*
748748
* 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.
749+
* the nvm-flash devlink region. It captures a snapshot of the full NVM flash
750+
* contents, including both banks of flash. This snapshot can later be viewed
751+
* via the devlink-region interface.
752+
*
753+
* It captures the flash using the FLASH_ONLY bit set when reading via
754+
* firmware, so it does not read the current Shadow RAM contents. For that,
755+
* use the shadow-ram region.
752756
*
753757
* @returns zero on success, and updates the data pointer. Returns a non-zero
754758
* error code on failure.
@@ -795,6 +799,66 @@ static int ice_devlink_nvm_snapshot(struct devlink *devlink,
795799
return 0;
796800
}
797801

802+
/**
803+
* ice_devlink_sram_snapshot - Capture a snapshot of the Shadow RAM contents
804+
* @devlink: the devlink instance
805+
* @ops: the devlink region being snapshotted
806+
* @extack: extended ACK response structure
807+
* @data: on exit points to snapshot data buffer
808+
*
809+
* This function is called in response to the DEVLINK_CMD_REGION_TRIGGER for
810+
* the shadow-ram devlink region. It captures a snapshot of the shadow ram
811+
* contents. This snapshot can later be viewed via the devlink-region
812+
* interface.
813+
*
814+
* @returns zero on success, and updates the data pointer. Returns a non-zero
815+
* error code on failure.
816+
*/
817+
static int
818+
ice_devlink_sram_snapshot(struct devlink *devlink,
819+
const struct devlink_region_ops __always_unused *ops,
820+
struct netlink_ext_ack *extack, u8 **data)
821+
{
822+
struct ice_pf *pf = devlink_priv(devlink);
823+
struct device *dev = ice_pf_to_dev(pf);
824+
struct ice_hw *hw = &pf->hw;
825+
u8 *sram_data;
826+
u32 sram_size;
827+
int err;
828+
829+
sram_size = hw->flash.sr_words * 2u;
830+
sram_data = vzalloc(sram_size);
831+
if (!sram_data)
832+
return -ENOMEM;
833+
834+
err = ice_acquire_nvm(hw, ICE_RES_READ);
835+
if (err) {
836+
dev_dbg(dev, "ice_acquire_nvm failed, err %d aq_err %d\n",
837+
err, hw->adminq.sq_last_status);
838+
NL_SET_ERR_MSG_MOD(extack, "Failed to acquire NVM semaphore");
839+
vfree(sram_data);
840+
return err;
841+
}
842+
843+
/* Read from the Shadow RAM, rather than directly from NVM */
844+
err = ice_read_flat_nvm(hw, 0, &sram_size, sram_data, true);
845+
if (err) {
846+
dev_dbg(dev, "ice_read_flat_nvm failed after reading %u bytes, err %d aq_err %d\n",
847+
sram_size, err, hw->adminq.sq_last_status);
848+
NL_SET_ERR_MSG_MOD(extack,
849+
"Failed to read Shadow RAM contents");
850+
ice_release_nvm(hw);
851+
vfree(sram_data);
852+
return err;
853+
}
854+
855+
ice_release_nvm(hw);
856+
857+
*data = sram_data;
858+
859+
return 0;
860+
}
861+
798862
/**
799863
* ice_devlink_devcaps_snapshot - Capture snapshot of device capabilities
800864
* @devlink: the devlink instance
@@ -845,6 +909,12 @@ static const struct devlink_region_ops ice_nvm_region_ops = {
845909
.snapshot = ice_devlink_nvm_snapshot,
846910
};
847911

912+
static const struct devlink_region_ops ice_sram_region_ops = {
913+
.name = "shadow-ram",
914+
.destructor = vfree,
915+
.snapshot = ice_devlink_sram_snapshot,
916+
};
917+
848918
static const struct devlink_region_ops ice_devcaps_region_ops = {
849919
.name = "device-caps",
850920
.destructor = vfree,
@@ -862,7 +932,7 @@ void ice_devlink_init_regions(struct ice_pf *pf)
862932
{
863933
struct devlink *devlink = priv_to_devlink(pf);
864934
struct device *dev = ice_pf_to_dev(pf);
865-
u64 nvm_size;
935+
u64 nvm_size, sram_size;
866936

867937
nvm_size = pf->hw.flash.flash_size;
868938
pf->nvm_region = devlink_region_create(devlink, &ice_nvm_region_ops, 1,
@@ -873,6 +943,15 @@ void ice_devlink_init_regions(struct ice_pf *pf)
873943
pf->nvm_region = NULL;
874944
}
875945

946+
sram_size = pf->hw.flash.sr_words * 2u;
947+
pf->sram_region = devlink_region_create(devlink, &ice_sram_region_ops,
948+
1, sram_size);
949+
if (IS_ERR(pf->sram_region)) {
950+
dev_err(dev, "failed to create shadow-ram devlink region, err %ld\n",
951+
PTR_ERR(pf->sram_region));
952+
pf->sram_region = NULL;
953+
}
954+
876955
pf->devcaps_region = devlink_region_create(devlink,
877956
&ice_devcaps_region_ops, 10,
878957
ICE_AQ_MAX_BUF_LEN);
@@ -893,6 +972,10 @@ void ice_devlink_destroy_regions(struct ice_pf *pf)
893972
{
894973
if (pf->nvm_region)
895974
devlink_region_destroy(pf->nvm_region);
975+
976+
if (pf->sram_region)
977+
devlink_region_destroy(pf->sram_region);
978+
896979
if (pf->devcaps_region)
897980
devlink_region_destroy(pf->devcaps_region);
898981
}

0 commit comments

Comments
 (0)