src/dpdk/drivers/net/txgbe/base/txgbe_eeprom.c
s32 txgbe_get_eeprom_semaphore(struct txgbe_hw *hw)
{
	s32 status = TXGBE_ERR_EEPROM;
	u32 timeout = 2000;
	u32 i;
	u32 swsm;

	DEBUGFUNC("txgbe_get_eeprom_semaphore");


	/* Get SMBI software semaphore between device drivers first */
	for (i = 0; i < timeout; i++) {
		/*
		 * If the SMBI bit is 0 when we read it, then the bit will be
		 * set and we have the semaphore
		 */
		swsm = rd32(hw, TXGBE_SWSEM);
		if (!(swsm & TXGBE_SWSEM_PF)) {
			status = 0;
			break;
		}
		usec_delay(50);
	}

	if (i == timeout) {
		DEBUGOUT("Driver can't access the eeprom - SMBI Semaphore "
			 "not granted.\n");
		/*
		 * this release is particularly important because our attempts
		 * above to get the semaphore may have succeeded, and if there
		 * was a timeout, we should unconditionally clear the semaphore
		 * bits to free the driver to make progress
		 */
		txgbe_release_eeprom_semaphore(hw);

		usec_delay(50);
		/*
		 * one last try
		 * If the SMBI bit is 0 when we read it, then the bit will be
		 * set and we have the semaphore
		 */
		swsm = rd32(hw, TXGBE_SWSEM);
		if (!(swsm & TXGBE_SWSEM_PF))
			status = 0;
	}

	/* Now get the semaphore between SW/FW through the SWESMBI bit */
	if (status == 0) {
		for (i = 0; i < timeout; i++) {
			/* Set the SW EEPROM semaphore bit to request access */
			wr32m(hw, TXGBE_MNGSWSYNC,
				TXGBE_MNGSWSYNC_REQ, TXGBE_MNGSWSYNC_REQ);

			/*
			 * If we set the bit successfully then we got the
			 * semaphore.
			 */
			swsm = rd32(hw, TXGBE_MNGSWSYNC);
			if (swsm & TXGBE_MNGSWSYNC_REQ)
				break;

			usec_delay(50);
		}

		/*
		 * Release semaphores and return error if SW EEPROM semaphore
		 * was not granted because we don't have access to the EEPROM
		 */
		if (i >= timeout) {
			DEBUGOUT("SWESMBI Software EEPROM semaphore not granted.\n");
			txgbe_release_eeprom_semaphore(hw);
			status = TXGBE_ERR_EEPROM;
		}
	} else {
		DEBUGOUT("Software semaphore SMBI between device drivers "
			 "not granted.\n");
	}

	return status;
}
/**
 *  txgbe_get_eeprom_semaphore - Get hardware semaphore
 *  @hw: pointer to hardware structure
 *
 *  Sets the hardware semaphores so EEPROM access can occur for bit-bang method
 **/
Get hardware semaphore
@hw: pointer to hardware structure

Sets the hardware semaphores so EEPROM access can occur for bit-bang method
Get hardware semaphore @hw : pointer to hardware structure Sets the hardware semaphores so EEPROM access can occur for bit - bang method
s32 txgbe_get_eeprom_semaphore(struct txgbe_hw *hw)
{
	s32 status = TXGBE_ERR_EEPROM;
	u32 timeout = 2000;
	u32 i;
	u32 swsm;
	DEBUGFUNC("txgbe_get_eeprom_semaphore");
	for (i = 0; i < timeout; i++) {
		swsm = rd32(hw, TXGBE_SWSEM);
		if (!(swsm & TXGBE_SWSEM_PF)) {
			status = 0;
			break;
		}
		usec_delay(50);
	}
	if (i == timeout) {
		DEBUGOUT("Driver can't access the eeprom - SMBI Semaphore "
			 "not granted.\n");
		txgbe_release_eeprom_semaphore(hw);
		usec_delay(50);
		swsm = rd32(hw, TXGBE_SWSEM);
		if (!(swsm & TXGBE_SWSEM_PF))
			status = 0;
	}
	if (status == 0) {
		for (i = 0; i < timeout; i++) {
			wr32m(hw, TXGBE_MNGSWSYNC,
				TXGBE_MNGSWSYNC_REQ, TXGBE_MNGSWSYNC_REQ);
			swsm = rd32(hw, TXGBE_MNGSWSYNC);
			if (swsm & TXGBE_MNGSWSYNC_REQ)
				break;
			usec_delay(50);
		}
		if (i >= timeout) {
			DEBUGOUT("SWESMBI Software EEPROM semaphore not granted.\n");
			txgbe_release_eeprom_semaphore(hw);
			status = TXGBE_ERR_EEPROM;
		}
	} else {
		DEBUGOUT("Software semaphore SMBI between device drivers "
			 "not granted.\n");
	}
	return status;
}
s32 txgbe_get_eeprom_semaphore ( struct txgbe_hw * hw ) { s32 status = TXGBE_ERR_EEPROM ; u32 timeout = 2000 ; u32 i ; u32 swsm ; DEBUGFUNC ( " " ) ; for ( i = 0 ; i < timeout ; i ++ ) { swsm = rd32 ( hw , TXGBE_SWSEM ) ; if ( ! ( swsm & TXGBE_SWSEM_PF ) ) { status = 0 ; break ; } usec_delay ( 50 ) ; } if ( i == timeout ) { DEBUGOUT ( " " " \n " ) ; txgbe_release_eeprom_semaphore ( hw ) ; usec_delay ( 50 ) ; swsm = rd32 ( hw , TXGBE_SWSEM ) ; if ( ! ( swsm & TXGBE_SWSEM_PF ) ) status = 0 ; } if ( status == 0 ) { for ( i = 0 ; i < timeout ; i ++ ) { wr32m ( hw , TXGBE_MNGSWSYNC , TXGBE_MNGSWSYNC_REQ , TXGBE_MNGSWSYNC_REQ ) ; swsm = rd32 ( hw , TXGBE_MNGSWSYNC ) ; if ( swsm & TXGBE_MNGSWSYNC_REQ ) break ; usec_delay ( 50 ) ; } if ( i >= timeout ) { DEBUGOUT ( " \n " ) ; txgbe_release_eeprom_semaphore ( hw ) ; status = TXGBE_ERR_EEPROM ; } } else { DEBUGOUT ( " " " \n " ) ; } return status ; }
txgbe_get_eeprom_semaphore - Get hardware semaphore
  @hw: pointer to hardware structure
txgbe_get_eeprom_semaphore - Get hardware semaphore @hw : pointer to hardware structure
/* Get SMBI software semaphore between device drivers first */ /*
		 * If the SMBI bit is 0 when we read it, then the bit will be
		 * set and we have the semaphore
		 */ /*
		 * this release is particularly important because our attempts
		 * above to get the semaphore may have succeeded, and if there
		 * was a timeout, we should unconditionally clear the semaphore
		 * bits to free the driver to make progress
		 */ /*
		 * one last try
		 * If the SMBI bit is 0 when we read it, then the bit will be
		 * set and we have the semaphore
		 */ /* Now get the semaphore between SW/FW through the SWESMBI bit */ /* Set the SW EEPROM semaphore bit to request access */ /*
			 * If we set the bit successfully then we got the
			 * semaphore.
			 */ /*
		 * Release semaphores and return error if SW EEPROM semaphore
		 * was not granted because we don't have access to the EEPROM
		 */