src/dpdk/drivers/net/igc/base/igc_nvm.c
s32 igc_read_pba_string_generic(struct igc_hw *hw, u8 *pba_num,
				  u32 pba_num_size)
{
	s32 ret_val;
	u16 nvm_data;
	u16 pba_ptr;
	u16 offset;
	u16 length;

	DEBUGFUNC("igc_read_pba_string_generic");

	if (pba_num == NULL) {
		DEBUGOUT("PBA string buffer was null\n");
		return -IGC_ERR_INVALID_ARGUMENT;
	}

	ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
	if (ret_val) {
		DEBUGOUT("NVM Read Error\n");
		return ret_val;
	}

	ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &pba_ptr);
	if (ret_val) {
		DEBUGOUT("NVM Read Error\n");
		return ret_val;
	}

	/* if nvm_data is not ptr guard the PBA must be in legacy format which
	 * means pba_ptr is actually our second data word for the PBA number
	 * and we can decode it into an ascii string
	 */
	if (nvm_data != NVM_PBA_PTR_GUARD) {
		DEBUGOUT("NVM PBA number is not stored as string\n");

		/* make sure callers buffer is big enough to store the PBA */
		if (pba_num_size < IGC_PBANUM_LENGTH) {
			DEBUGOUT("PBA string buffer too small\n");
			return IGC_ERR_NO_SPACE;
		}

		/* extract hex string from data and pba_ptr */
		pba_num[0] = (nvm_data >> 12) & 0xF;
		pba_num[1] = (nvm_data >> 8) & 0xF;
		pba_num[2] = (nvm_data >> 4) & 0xF;
		pba_num[3] = nvm_data & 0xF;
		pba_num[4] = (pba_ptr >> 12) & 0xF;
		pba_num[5] = (pba_ptr >> 8) & 0xF;
		pba_num[6] = '-';
		pba_num[7] = 0;
		pba_num[8] = (pba_ptr >> 4) & 0xF;
		pba_num[9] = pba_ptr & 0xF;

		/* put a null character on the end of our string */
		pba_num[10] = '\0';

		/* switch all the data but the '-' to hex char */
		for (offset = 0; offset < 10; offset++) {
			if (pba_num[offset] < 0xA)
				pba_num[offset] += '0';
			else if (pba_num[offset] < 0x10)
				pba_num[offset] += 'A' - 0xA;
		}

		return IGC_SUCCESS;
	}

	ret_val = hw->nvm.ops.read(hw, pba_ptr, 1, &length);
	if (ret_val) {
		DEBUGOUT("NVM Read Error\n");
		return ret_val;
	}

	if (length == 0xFFFF || length == 0) {
		DEBUGOUT("NVM PBA number section invalid length\n");
		return -IGC_ERR_NVM_PBA_SECTION;
	}
	/* check if pba_num buffer is big enough */
	if (pba_num_size < (((u32)length * 2) - 1)) {
		DEBUGOUT("PBA string buffer too small\n");
		return -IGC_ERR_NO_SPACE;
	}

	/* trim pba length from start of string */
	pba_ptr++;
	length--;

	for (offset = 0; offset < length; offset++) {
		ret_val = hw->nvm.ops.read(hw, pba_ptr + offset, 1, &nvm_data);
		if (ret_val) {
			DEBUGOUT("NVM Read Error\n");
			return ret_val;
		}
		pba_num[offset * 2] = (u8)(nvm_data >> 8);
		pba_num[(offset * 2) + 1] = (u8)(nvm_data & 0xFF);
	}
	pba_num[offset * 2] = '\0';

	return IGC_SUCCESS;
}
/**
 *  igc_read_pba_string_generic - Read device part number
 *  @hw: pointer to the HW structure
 *  @pba_num: pointer to device part number
 *  @pba_num_size: size of part number buffer
 *
 *  Reads the product board assembly (PBA) number from the EEPROM and stores
 *  the value in pba_num.
 **/
Read device part number
@hw: pointer to the HW structure
@pba_num: pointer to device part number
@pba_num_size: size of part number buffer

Reads the product board assembly (PBA) number from the EEPROM and stores
the value in pba_num.
Read device part number @hw : pointer to the HW structure @pba_num : pointer to device part number @pba_num_size : size of part number buffer Reads the product board assembly ( PBA ) number from the EEPROM and stores the value in pba_num .
s32 igc_read_pba_string_generic(struct igc_hw *hw, u8 *pba_num,
				  u32 pba_num_size)
{
	s32 ret_val;
	u16 nvm_data;
	u16 pba_ptr;
	u16 offset;
	u16 length;
	DEBUGFUNC("igc_read_pba_string_generic");
	if (pba_num == NULL) {
		DEBUGOUT("PBA string buffer was null\n");
		return -IGC_ERR_INVALID_ARGUMENT;
	}
	ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
	if (ret_val) {
		DEBUGOUT("NVM Read Error\n");
		return ret_val;
	}
	ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &pba_ptr);
	if (ret_val) {
		DEBUGOUT("NVM Read Error\n");
		return ret_val;
	}
	if (nvm_data != NVM_PBA_PTR_GUARD) {
		DEBUGOUT("NVM PBA number is not stored as string\n");
		if (pba_num_size < IGC_PBANUM_LENGTH) {
			DEBUGOUT("PBA string buffer too small\n");
			return IGC_ERR_NO_SPACE;
		}
		pba_num[0] = (nvm_data >> 12) & 0xF;
		pba_num[1] = (nvm_data >> 8) & 0xF;
		pba_num[2] = (nvm_data >> 4) & 0xF;
		pba_num[3] = nvm_data & 0xF;
		pba_num[4] = (pba_ptr >> 12) & 0xF;
		pba_num[5] = (pba_ptr >> 8) & 0xF;
		pba_num[6] = '-';
		pba_num[7] = 0;
		pba_num[8] = (pba_ptr >> 4) & 0xF;
		pba_num[9] = pba_ptr & 0xF;
		pba_num[10] = '\0';
		for (offset = 0; offset < 10; offset++) {
			if (pba_num[offset] < 0xA)
				pba_num[offset] += '0';
			else if (pba_num[offset] < 0x10)
				pba_num[offset] += 'A' - 0xA;
		}
		return IGC_SUCCESS;
	}
	ret_val = hw->nvm.ops.read(hw, pba_ptr, 1, &length);
	if (ret_val) {
		DEBUGOUT("NVM Read Error\n");
		return ret_val;
	}
	if (length == 0xFFFF || length == 0) {
		DEBUGOUT("NVM PBA number section invalid length\n");
		return -IGC_ERR_NVM_PBA_SECTION;
	}
	if (pba_num_size < (((u32)length * 2) - 1)) {
		DEBUGOUT("PBA string buffer too small\n");
		return -IGC_ERR_NO_SPACE;
	}
	pba_ptr++;
	length--;
	for (offset = 0; offset < length; offset++) {
		ret_val = hw->nvm.ops.read(hw, pba_ptr + offset, 1, &nvm_data);
		if (ret_val) {
			DEBUGOUT("NVM Read Error\n");
			return ret_val;
		}
		pba_num[offset * 2] = (u8)(nvm_data >> 8);
		pba_num[(offset * 2) + 1] = (u8)(nvm_data & 0xFF);
	}
	pba_num[offset * 2] = '\0';
	return IGC_SUCCESS;
}
s32 igc_read_pba_string_generic ( struct igc_hw * hw , u8 * pba_num , u32 pba_num_size ) { s32 ret_val ; u16 nvm_data ; u16 pba_ptr ; u16 offset ; u16 length ; DEBUGFUNC ( " " ) ; if ( pba_num == NULL ) { DEBUGOUT ( " \n " ) ; return - IGC_ERR_INVALID_ARGUMENT ; } ret_val = hw -> nvm . ops . read ( hw , NVM_PBA_OFFSET_0 , 1 , & nvm_data ) ; if ( ret_val ) { DEBUGOUT ( " \n " ) ; return ret_val ; } ret_val = hw -> nvm . ops . read ( hw , NVM_PBA_OFFSET_1 , 1 , & pba_ptr ) ; if ( ret_val ) { DEBUGOUT ( " \n " ) ; return ret_val ; } if ( nvm_data != NVM_PBA_PTR_GUARD ) { DEBUGOUT ( " \n " ) ; if ( pba_num_size < IGC_PBANUM_LENGTH ) { DEBUGOUT ( " \n " ) ; return IGC_ERR_NO_SPACE ; } pba_num [ 0 ] = ( nvm_data >> 12 ) & 0xF ; pba_num [ 1 ] = ( nvm_data >> 8 ) & 0xF ; pba_num [ 2 ] = ( nvm_data >> 4 ) & 0xF ; pba_num [ 3 ] = nvm_data & 0xF ; pba_num [ 4 ] = ( pba_ptr >> 12 ) & 0xF ; pba_num [ 5 ] = ( pba_ptr >> 8 ) & 0xF ; pba_num [ 6 ] = ' ' ; pba_num [ 7 ] = 0 ; pba_num [ 8 ] = ( pba_ptr >> 4 ) & 0xF ; pba_num [ 9 ] = pba_ptr & 0xF ; pba_num [ 10 ] = ' \0 ' ; for ( offset = 0 ; offset < 10 ; offset ++ ) { if ( pba_num [ offset ] < 0xA ) pba_num [ offset ] += ' ' ; else if ( pba_num [ offset ] < 0x10 ) pba_num [ offset ] += ' ' - 0xA ; } return IGC_SUCCESS ; } ret_val = hw -> nvm . ops . read ( hw , pba_ptr , 1 , & length ) ; if ( ret_val ) { DEBUGOUT ( " \n " ) ; return ret_val ; } if ( length == 0xFFFF || length == 0 ) { DEBUGOUT ( " \n " ) ; return - IGC_ERR_NVM_PBA_SECTION ; } if ( pba_num_size < ( ( ( u32 ) length * 2 ) - 1 ) ) { DEBUGOUT ( " \n " ) ; return - IGC_ERR_NO_SPACE ; } pba_ptr ++ ; length -- ; for ( offset = 0 ; offset < length ; offset ++ ) { ret_val = hw -> nvm . ops . read ( hw , pba_ptr + offset , 1 , & nvm_data ) ; if ( ret_val ) { DEBUGOUT ( " \n " ) ; return ret_val ; } pba_num [ offset * 2 ] = ( u8 ) ( nvm_data >> 8 ) ; pba_num [ ( offset * 2 ) + 1 ] = ( u8 ) ( nvm_data & 0xFF ) ; } pba_num [ offset * 2 ] = ' \0 ' ; return IGC_SUCCESS ; }
igc_read_pba_string_generic - Read device part number
  @hw: pointer to the HW structure
  @pba_num: pointer to device part number
  @pba_num_size: size of part number buffer
igc_read_pba_string_generic - Read device part number @hw : pointer to the HW structure @pba_num : pointer to device part number @pba_num_size : size of part number buffer
/* if nvm_data is not ptr guard the PBA must be in legacy format which
	 * means pba_ptr is actually our second data word for the PBA number
	 * and we can decode it into an ascii string
	 */ /* make sure callers buffer is big enough to store the PBA */ /* extract hex string from data and pba_ptr */ /* put a null character on the end of our string */ /* switch all the data but the '-' to hex char */ /* check if pba_num buffer is big enough */ /* trim pba length from start of string */