src/dpdk/drivers/net/igc/base/igc_nvm.c
s32 igc_write_nvm_spi(struct igc_hw *hw, u16 offset, u16 words, u16 *data)
{
	struct igc_nvm_info *nvm = &hw->nvm;
	s32 ret_val = -IGC_ERR_NVM;
	u16 widx = 0;

	DEBUGFUNC("igc_write_nvm_spi");

	/* A check for invalid values:  offset too large, too many words,
	 * and not enough words.
	 */
	if (offset >= nvm->word_size || words > (nvm->word_size - offset) ||
			words == 0) {
		DEBUGOUT("nvm parameter(s) out of bounds\n");
		return -IGC_ERR_NVM;
	}

	while (widx < words) {
		u8 write_opcode = NVM_WRITE_OPCODE_SPI;

		ret_val = nvm->ops.acquire(hw);
		if (ret_val)
			return ret_val;

		ret_val = igc_ready_nvm_eeprom(hw);
		if (ret_val) {
			nvm->ops.release(hw);
			return ret_val;
		}

		igc_standby_nvm(hw);

		/* Send the WRITE ENABLE command (8 bit opcode) */
		igc_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI,
					 nvm->opcode_bits);

		igc_standby_nvm(hw);

		/* Some SPI eeproms use the 8th address bit embedded in the
		 * opcode
		 */
		if (nvm->address_bits == 8 && offset >= 128)
			write_opcode |= NVM_A8_OPCODE_SPI;

		/* Send the Write command (8-bit opcode + addr) */
		igc_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits);
		igc_shift_out_eec_bits(hw, (u16)((offset + widx) * 2),
					 nvm->address_bits);

		/* Loop to allow for up to whole page write of eeprom */
		while (widx < words) {
			u16 word_out = data[widx];
			word_out = (word_out >> 8) | (word_out << 8);
			igc_shift_out_eec_bits(hw, word_out, 16);
			widx++;

			if ((((offset + widx) * 2) % nvm->page_size) == 0) {
				igc_standby_nvm(hw);
				break;
			}
		}
		msec_delay(10);
		nvm->ops.release(hw);
	}

	return ret_val;
}
/**
 *  igc_write_nvm_spi - Write to EEPROM using SPI
 *  @hw: pointer to the HW structure
 *  @offset: offset within the EEPROM to be written to
 *  @words: number of words to write
 *  @data: 16 bit word(s) to be written to the EEPROM
 *
 *  Writes data to EEPROM at offset using SPI interface.
 *
 *  If igc_update_nvm_checksum is not called after this function , the
 *  EEPROM will most likely contain an invalid checksum.
 **/
Write to EEPROM using SPI
@hw: pointer to the HW structure
@offset: offset within the EEPROM to be written to
@words: number of words to write
@data: 16 bit word(s) to be written to the EEPROM

Writes data to EEPROM at offset using SPI interface.

If igc_update_nvm_checksum is not called after this function , the
EEPROM will most likely contain an invalid checksum.
Write to EEPROM using SPI @hw : pointer to the HW structure @offset : offset within the EEPROM to be written to @words : number of words to write @data : 16 bit word ( s ) to be written to the EEPROM Writes data to EEPROM at offset using SPI interface . If igc_update_nvm_checksum is not called after this function the EEPROM will most likely contain an invalid checksum .
s32 igc_write_nvm_spi(struct igc_hw *hw, u16 offset, u16 words, u16 *data)
{
	struct igc_nvm_info *nvm = &hw->nvm;
	s32 ret_val = -IGC_ERR_NVM;
	u16 widx = 0;
	DEBUGFUNC("igc_write_nvm_spi");
	if (offset >= nvm->word_size || words > (nvm->word_size - offset) ||
			words == 0) {
		DEBUGOUT("nvm parameter(s) out of bounds\n");
		return -IGC_ERR_NVM;
	}
	while (widx < words) {
		u8 write_opcode = NVM_WRITE_OPCODE_SPI;
		ret_val = nvm->ops.acquire(hw);
		if (ret_val)
			return ret_val;
		ret_val = igc_ready_nvm_eeprom(hw);
		if (ret_val) {
			nvm->ops.release(hw);
			return ret_val;
		}
		igc_standby_nvm(hw);
		igc_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI,
					 nvm->opcode_bits);
		igc_standby_nvm(hw);
		if (nvm->address_bits == 8 && offset >= 128)
			write_opcode |= NVM_A8_OPCODE_SPI;
		igc_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits);
		igc_shift_out_eec_bits(hw, (u16)((offset + widx) * 2),
					 nvm->address_bits);
		while (widx < words) {
			u16 word_out = data[widx];
			word_out = (word_out >> 8) | (word_out << 8);
			igc_shift_out_eec_bits(hw, word_out, 16);
			widx++;
			if ((((offset + widx) * 2) % nvm->page_size) == 0) {
				igc_standby_nvm(hw);
				break;
			}
		}
		msec_delay(10);
		nvm->ops.release(hw);
	}
	return ret_val;
}
s32 igc_write_nvm_spi ( struct igc_hw * hw , u16 offset , u16 words , u16 * data ) { struct igc_nvm_info * nvm = & hw -> nvm ; s32 ret_val = - IGC_ERR_NVM ; u16 widx = 0 ; DEBUGFUNC ( " " ) ; if ( offset >= nvm -> word_size || words > ( nvm -> word_size - offset ) || words == 0 ) { DEBUGOUT ( " \n " ) ; return - IGC_ERR_NVM ; } while ( widx < words ) { u8 write_opcode = NVM_WRITE_OPCODE_SPI ; ret_val = nvm -> ops . acquire ( hw ) ; if ( ret_val ) return ret_val ; ret_val = igc_ready_nvm_eeprom ( hw ) ; if ( ret_val ) { nvm -> ops . release ( hw ) ; return ret_val ; } igc_standby_nvm ( hw ) ; igc_shift_out_eec_bits ( hw , NVM_WREN_OPCODE_SPI , nvm -> opcode_bits ) ; igc_standby_nvm ( hw ) ; if ( nvm -> address_bits == 8 && offset >= 128 ) write_opcode |= NVM_A8_OPCODE_SPI ; igc_shift_out_eec_bits ( hw , write_opcode , nvm -> opcode_bits ) ; igc_shift_out_eec_bits ( hw , ( u16 ) ( ( offset + widx ) * 2 ) , nvm -> address_bits ) ; while ( widx < words ) { u16 word_out = data [ widx ] ; word_out = ( word_out >> 8 ) | ( word_out << 8 ) ; igc_shift_out_eec_bits ( hw , word_out , 16 ) ; widx ++ ; if ( ( ( ( offset + widx ) * 2 ) % nvm -> page_size ) == 0 ) { igc_standby_nvm ( hw ) ; break ; } } msec_delay ( 10 ) ; nvm -> ops . release ( hw ) ; } return ret_val ; }
igc_write_nvm_spi - Write to EEPROM using SPI
  @hw: pointer to the HW structure
  @offset: offset within the EEPROM to be written to
  @words: number of words to write
  @data: 16 bit word(s) to be written to the EEPROM
igc_write_nvm_spi - Write to EEPROM using SPI @hw : pointer to the HW structure @offset : offset within the EEPROM to be written to @words : number of words to write @data : 16 bit word ( s ) to be written to the EEPROM
/* A check for invalid values:  offset too large, too many words,
	 * and not enough words.
	 */ /* Send the WRITE ENABLE command (8 bit opcode) */ /* Some SPI eeproms use the 8th address bit embedded in the
		 * opcode
		 */ /* Send the Write command (8-bit opcode + addr) */ /* Loop to allow for up to whole page write of eeprom */