src/dpdk/drivers/net/igc/base/igc_mac.c
s32 igc_get_hw_semaphore_generic(struct igc_hw *hw)
{
	u32 swsm;
	s32 timeout = hw->nvm.word_size + 1;
	s32 i = 0;

	DEBUGFUNC("igc_get_hw_semaphore_generic");

	/* Get the SW semaphore */
	while (i < timeout) {
		swsm = IGC_READ_REG(hw, IGC_SWSM);
		if (!(swsm & IGC_SWSM_SMBI))
			break;

		usec_delay(50);
		i++;
	}

	if (i == timeout) {
		DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
		return -IGC_ERR_NVM;
	}

	/* Get the FW semaphore. */
	for (i = 0; i < timeout; i++) {
		swsm = IGC_READ_REG(hw, IGC_SWSM);
		IGC_WRITE_REG(hw, IGC_SWSM, swsm | IGC_SWSM_SWESMBI);

		/* Semaphore acquired if bit latched */
		if (IGC_READ_REG(hw, IGC_SWSM) & IGC_SWSM_SWESMBI)
			break;

		usec_delay(50);
	}

	if (i == timeout) {
		/* Release semaphores */
		igc_put_hw_semaphore_generic(hw);
		DEBUGOUT("Driver can't access the NVM\n");
		return -IGC_ERR_NVM;
	}

	return IGC_SUCCESS;
}
/**
 *  igc_get_hw_semaphore_generic - Acquire hardware semaphore
 *  @hw: pointer to the HW structure
 *
 *  Acquire the HW semaphore to access the PHY or NVM
 **/
Acquire hardware semaphore
@hw: pointer to the HW structure

Acquire the HW semaphore to access the PHY or NVM
Acquire hardware semaphore @hw : pointer to the HW structure Acquire the HW semaphore to access the PHY or NVM
s32 igc_get_hw_semaphore_generic(struct igc_hw *hw)
{
	u32 swsm;
	s32 timeout = hw->nvm.word_size + 1;
	s32 i = 0;
	DEBUGFUNC("igc_get_hw_semaphore_generic");
	while (i < timeout) {
		swsm = IGC_READ_REG(hw, IGC_SWSM);
		if (!(swsm & IGC_SWSM_SMBI))
			break;
		usec_delay(50);
		i++;
	}
	if (i == timeout) {
		DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
		return -IGC_ERR_NVM;
	}
	for (i = 0; i < timeout; i++) {
		swsm = IGC_READ_REG(hw, IGC_SWSM);
		IGC_WRITE_REG(hw, IGC_SWSM, swsm | IGC_SWSM_SWESMBI);
		if (IGC_READ_REG(hw, IGC_SWSM) & IGC_SWSM_SWESMBI)
			break;
		usec_delay(50);
	}
	if (i == timeout) {
		igc_put_hw_semaphore_generic(hw);
		DEBUGOUT("Driver can't access the NVM\n");
		return -IGC_ERR_NVM;
	}
	return IGC_SUCCESS;
}
s32 igc_get_hw_semaphore_generic ( struct igc_hw * hw ) { u32 swsm ; s32 timeout = hw -> nvm . word_size + 1 ; s32 i = 0 ; DEBUGFUNC ( " " ) ; while ( i < timeout ) { swsm = IGC_READ_REG ( hw , IGC_SWSM ) ; if ( ! ( swsm & IGC_SWSM_SMBI ) ) break ; usec_delay ( 50 ) ; i ++ ; } if ( i == timeout ) { DEBUGOUT ( " \n " ) ; return - IGC_ERR_NVM ; } for ( i = 0 ; i < timeout ; i ++ ) { swsm = IGC_READ_REG ( hw , IGC_SWSM ) ; IGC_WRITE_REG ( hw , IGC_SWSM , swsm | IGC_SWSM_SWESMBI ) ; if ( IGC_READ_REG ( hw , IGC_SWSM ) & IGC_SWSM_SWESMBI ) break ; usec_delay ( 50 ) ; } if ( i == timeout ) { igc_put_hw_semaphore_generic ( hw ) ; DEBUGOUT ( " \n " ) ; return - IGC_ERR_NVM ; } return IGC_SUCCESS ; }
igc_get_hw_semaphore_generic - Acquire hardware semaphore
  @hw: pointer to the HW structure
igc_get_hw_semaphore_generic - Acquire hardware semaphore @hw : pointer to the HW structure
/* Get the SW semaphore */ /* Get the FW semaphore. */ /* Semaphore acquired if bit latched */ /* Release semaphores */