FreeBSD/sys/dev/nxge/xgehal/xgehal-mgmt.c
/*
 * xge_hal_write_eeprom - actually writes the relevant part of the data
 value.
 * @devh: HAL device handle.
 * @off: offset at which the data must be written
 * @data : The data that is to be written
 * @cnt : Number of bytes of the data that are actually to be written into
 * the Eeprom. (max of 3)
 *
 * Actually writes the relevant part of the data value into the Eeprom
 * through the I2C bus.
 * Return value:
 * 0 on success, -1 on failure.
 */
actually writes the relevant part of the data
value.
@devh: HAL device handle.
@off: offset at which the data must be written
@data : The data that is to be written
@cnt : Number of bytes of the data that are actually to be written into
the Eeprom.

Actually writes the relevant part of the data value into the Eeprom
through the I2C bus.
Return value:
0 on success, -1 on failure.
actually writes the relevant part of the data value . @devh : HAL device handle . @off : offset at which the data must be written @data : The data that is to be written @cnt : Number of bytes of the data that are actually to be written into the Eeprom . Actually writes the relevant part of the data value into the Eeprom through the I2C bus . Return value : 0 on success - 1 on failure .
xge_hal_status_e
xge_hal_write_eeprom(xge_hal_device_h devh, int off, u32 data, int cnt)
{
	xge_hal_device_t *hldev = (xge_hal_device_t*)devh;
	xge_hal_status_e ret = XGE_HAL_FAIL;
	u32 exit_cnt = 0;
	u64 val64;
	xge_hal_pci_bar0_t *bar0 = (xge_hal_pci_bar0_t *)hldev->bar0;
	val64 = XGE_HAL_I2C_CONTROL_DEV_ID(XGE_DEV_ID) |
	    XGE_HAL_I2C_CONTROL_ADDR(off) |
	    XGE_HAL_I2C_CONTROL_BYTE_CNT(cnt) |
	    XGE_HAL_I2C_CONTROL_SET_DATA(data) |
	    XGE_HAL_I2C_CONTROL_CNTL_START;
	__hal_serial_mem_write64(hldev, val64, &bar0->i2c_control);
	while (exit_cnt < 5) {
	    val64 = __hal_serial_mem_read64(hldev, &bar0->i2c_control);
	    if (XGE_HAL_I2C_CONTROL_CNTL_END(val64)) {
	        if (!(val64 & XGE_HAL_I2C_CONTROL_NACK))
	            ret = XGE_HAL_OK;
	        break;
	    }
	    exit_cnt++;
	}
	return ret;
}
xge_hal_status_e xge_hal_write_eeprom ( xge_hal_device_h devh , int off , u32 data , int cnt ) { xge_hal_device_t * hldev = ( xge_hal_device_t * ) devh ; xge_hal_status_e ret = XGE_HAL_FAIL ; u32 exit_cnt = 0 ; u64 val64 ; xge_hal_pci_bar0_t * bar0 = ( xge_hal_pci_bar0_t * ) hldev -> bar0 ; val64 = XGE_HAL_I2C_CONTROL_DEV_ID ( XGE_DEV_ID ) | XGE_HAL_I2C_CONTROL_ADDR ( off ) | XGE_HAL_I2C_CONTROL_BYTE_CNT ( cnt ) | XGE_HAL_I2C_CONTROL_SET_DATA ( data ) | XGE_HAL_I2C_CONTROL_CNTL_START ; __hal_serial_mem_write64 ( hldev , val64 , & bar0 -> i2c_control ) ; while ( exit_cnt < 5 ) { val64 = __hal_serial_mem_read64 ( hldev , & bar0 -> i2c_control ) ; if ( XGE_HAL_I2C_CONTROL_CNTL_END ( val64 ) ) { if ( ! ( val64 & XGE_HAL_I2C_CONTROL_NACK ) ) ret = XGE_HAL_OK ; break ; } exit_cnt ++ ; } return ret ; }
xge_hal_write_eeprom - actually writes the relevant part of the data
value.
xge_hal_write_eeprom - actually writes the relevant part of the data value .