src/dpdk/drivers/net/i40e/base/i40e_nvm.c
enum i40e_status_code i40e_calc_nvm_checksum(struct i40e_hw *hw, u16 *checksum)
{
	enum i40e_status_code ret_code = I40E_SUCCESS;
	struct i40e_virt_mem vmem;
	u16 pcie_alt_module = 0;
	u16 checksum_local = 0;
	u16 vpd_module = 0;
	u16 *data;
	u16 i = 0;

	DEBUGFUNC("i40e_calc_nvm_checksum");

	ret_code = i40e_allocate_virt_mem(hw, &vmem,
				    I40E_SR_SECTOR_SIZE_IN_WORDS * sizeof(u16));
	if (ret_code)
		goto i40e_calc_nvm_checksum_exit;
	data = (u16 *)vmem.va;

	/* read pointer to VPD area */
	ret_code = __i40e_read_nvm_word(hw, I40E_SR_VPD_PTR, &vpd_module);
	if (ret_code != I40E_SUCCESS) {
		ret_code = I40E_ERR_NVM_CHECKSUM;
		goto i40e_calc_nvm_checksum_exit;
	}

	/* read pointer to PCIe Alt Auto-load module */
	ret_code = __i40e_read_nvm_word(hw, I40E_SR_PCIE_ALT_AUTO_LOAD_PTR,
					&pcie_alt_module);
	if (ret_code != I40E_SUCCESS) {
		ret_code = I40E_ERR_NVM_CHECKSUM;
		goto i40e_calc_nvm_checksum_exit;
	}

	/* Calculate SW checksum that covers the whole 64kB shadow RAM
	 * except the VPD and PCIe ALT Auto-load modules
	 */
	for (i = 0; i < hw->nvm.sr_size; i++) {
		/* Read SR page */
		if ((i % I40E_SR_SECTOR_SIZE_IN_WORDS) == 0) {
			u16 words = I40E_SR_SECTOR_SIZE_IN_WORDS;

			ret_code = __i40e_read_nvm_buffer(hw, i, &words, data);
			if (ret_code != I40E_SUCCESS) {
				ret_code = I40E_ERR_NVM_CHECKSUM;
				goto i40e_calc_nvm_checksum_exit;
			}
		}

		/* Skip Checksum word */
		if (i == I40E_SR_SW_CHECKSUM_WORD)
			continue;
		/* Skip VPD module (convert byte size to word count) */
		if ((i >= (u32)vpd_module) &&
		    (i < ((u32)vpd_module +
		     (I40E_SR_VPD_MODULE_MAX_SIZE / 2)))) {
			continue;
		}
		/* Skip PCIe ALT module (convert byte size to word count) */
		if ((i >= (u32)pcie_alt_module) &&
		    (i < ((u32)pcie_alt_module +
		     (I40E_SR_PCIE_ALT_MODULE_MAX_SIZE / 2)))) {
			continue;
		}

		checksum_local += data[i % I40E_SR_SECTOR_SIZE_IN_WORDS];
	}

	*checksum = (u16)I40E_SR_SW_CHECKSUM_BASE - checksum_local;

i40e_calc_nvm_checksum_exit:
	i40e_free_virt_mem(hw, &vmem);
	return ret_code;
}
/**
 * i40e_calc_nvm_checksum - Calculates and returns the checksum
 * @hw: pointer to hardware structure
 * @checksum: pointer to the checksum
 *
 * This function calculates SW Checksum that covers the whole 64kB shadow RAM
 * except the VPD and PCIe ALT Auto-load modules. The structure and size of VPD
 * is customer specific and unknown. Therefore, this function skips all maximum
 * possible size of VPD (1kB).
 **/
Calculates and returns the checksum
@hw: pointer to hardware structure
@checksum: pointer to the checksum

This function calculates SW Checksum that covers the whole 64kB shadow RAM
except the VPD and PCIe ALT Auto-load modules. The structure and size of VPD
is customer specific and unknown. Therefore, this function skips all maximum
possible size of VPD (1kB).
Calculates and returns the checksum @hw : pointer to hardware structure @checksum : pointer to the checksum This function calculates SW Checksum that covers the whole 64kB shadow RAM except the VPD and PCIe ALT Auto - load modules . The structure and size of VPD is customer specific and unknown . Therefore this function skips all maximum possible size of VPD ( 1kB ) .
enum i40e_status_code i40e_calc_nvm_checksum(struct i40e_hw *hw, u16 *checksum)
{
	enum i40e_status_code ret_code = I40E_SUCCESS;
	struct i40e_virt_mem vmem;
	u16 pcie_alt_module = 0;
	u16 checksum_local = 0;
	u16 vpd_module = 0;
	u16 *data;
	u16 i = 0;
	DEBUGFUNC("i40e_calc_nvm_checksum");
	ret_code = i40e_allocate_virt_mem(hw, &vmem,
				    I40E_SR_SECTOR_SIZE_IN_WORDS * sizeof(u16));
	if (ret_code)
		goto i40e_calc_nvm_checksum_exit;
	data = (u16 *)vmem.va;
	ret_code = __i40e_read_nvm_word(hw, I40E_SR_VPD_PTR, &vpd_module);
	if (ret_code != I40E_SUCCESS) {
		ret_code = I40E_ERR_NVM_CHECKSUM;
		goto i40e_calc_nvm_checksum_exit;
	}
	ret_code = __i40e_read_nvm_word(hw, I40E_SR_PCIE_ALT_AUTO_LOAD_PTR,
					&pcie_alt_module);
	if (ret_code != I40E_SUCCESS) {
		ret_code = I40E_ERR_NVM_CHECKSUM;
		goto i40e_calc_nvm_checksum_exit;
	}
	for (i = 0; i < hw->nvm.sr_size; i++) {
		if ((i % I40E_SR_SECTOR_SIZE_IN_WORDS) == 0) {
			u16 words = I40E_SR_SECTOR_SIZE_IN_WORDS;
			ret_code = __i40e_read_nvm_buffer(hw, i, &words, data);
			if (ret_code != I40E_SUCCESS) {
				ret_code = I40E_ERR_NVM_CHECKSUM;
				goto i40e_calc_nvm_checksum_exit;
			}
		}
		if (i == I40E_SR_SW_CHECKSUM_WORD)
			continue;
		if ((i >= (u32)vpd_module) &&
		    (i < ((u32)vpd_module +
		     (I40E_SR_VPD_MODULE_MAX_SIZE / 2)))) {
			continue;
		}
		if ((i >= (u32)pcie_alt_module) &&
		    (i < ((u32)pcie_alt_module +
		     (I40E_SR_PCIE_ALT_MODULE_MAX_SIZE / 2)))) {
			continue;
		}
		checksum_local += data[i % I40E_SR_SECTOR_SIZE_IN_WORDS];
	}
	*checksum = (u16)I40E_SR_SW_CHECKSUM_BASE - checksum_local;
i40e_calc_nvm_checksum_exit:
	i40e_free_virt_mem(hw, &vmem);
	return ret_code;
}
enum i40e_status_code i40e_calc_nvm_checksum ( struct i40e_hw * hw , u16 * checksum ) { enum i40e_status_code ret_code = I40E_SUCCESS ; struct i40e_virt_mem vmem ; u16 pcie_alt_module = 0 ; u16 checksum_local = 0 ; u16 vpd_module = 0 ; u16 * data ; u16 i = 0 ; DEBUGFUNC ( " " ) ; ret_code = i40e_allocate_virt_mem ( hw , & vmem , I40E_SR_SECTOR_SIZE_IN_WORDS * sizeof ( u16 ) ) ; if ( ret_code ) goto i40e_calc_nvm_checksum_exit ; data = ( u16 * ) vmem . va ; ret_code = __i40e_read_nvm_word ( hw , I40E_SR_VPD_PTR , & vpd_module ) ; if ( ret_code != I40E_SUCCESS ) { ret_code = I40E_ERR_NVM_CHECKSUM ; goto i40e_calc_nvm_checksum_exit ; } ret_code = __i40e_read_nvm_word ( hw , I40E_SR_PCIE_ALT_AUTO_LOAD_PTR , & pcie_alt_module ) ; if ( ret_code != I40E_SUCCESS ) { ret_code = I40E_ERR_NVM_CHECKSUM ; goto i40e_calc_nvm_checksum_exit ; } for ( i = 0 ; i < hw -> nvm . sr_size ; i ++ ) { if ( ( i % I40E_SR_SECTOR_SIZE_IN_WORDS ) == 0 ) { u16 words = I40E_SR_SECTOR_SIZE_IN_WORDS ; ret_code = __i40e_read_nvm_buffer ( hw , i , & words , data ) ; if ( ret_code != I40E_SUCCESS ) { ret_code = I40E_ERR_NVM_CHECKSUM ; goto i40e_calc_nvm_checksum_exit ; } } if ( i == I40E_SR_SW_CHECKSUM_WORD ) continue ; if ( ( i >= ( u32 ) vpd_module ) && ( i < ( ( u32 ) vpd_module + ( I40E_SR_VPD_MODULE_MAX_SIZE / 2 ) ) ) ) { continue ; } if ( ( i >= ( u32 ) pcie_alt_module ) && ( i < ( ( u32 ) pcie_alt_module + ( I40E_SR_PCIE_ALT_MODULE_MAX_SIZE / 2 ) ) ) ) { continue ; } checksum_local += data [ i % I40E_SR_SECTOR_SIZE_IN_WORDS ] ; } * checksum = ( u16 ) I40E_SR_SW_CHECKSUM_BASE - checksum_local ; i40e_calc_nvm_checksum_exit : i40e_free_virt_mem ( hw , & vmem ) ; return ret_code ; }
i40e_calc_nvm_checksum - Calculates and returns the checksum
 @hw: pointer to hardware structure
 @checksum: pointer to the checksum
i40e_calc_nvm_checksum - Calculates and returns the checksum @hw : pointer to hardware structure @checksum : pointer to the checksum
/* read pointer to VPD area */ /* read pointer to PCIe Alt Auto-load module */ /* Calculate SW checksum that covers the whole 64kB shadow RAM
	 * except the VPD and PCIe ALT Auto-load modules
	 */ /* Read SR page */ /* Skip Checksum word */ /* Skip VPD module (convert byte size to word count) */ /* Skip PCIe ALT module (convert byte size to word count) */