/* Acquires the SWFW semaphore thought the GSSR register for the specified function (CSR, PHY0, PHY1, EEPROM, Flash)  */
s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
/* Acquires the SWFW semaphore thought the GSSR register for the specified function (CSR, PHY0, PHY1, EEPROM, Flash)  */
s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
{
	u32 gssr;
	u32 swmask = mask;
	u32 fwmask = mask << 5;
	s32 timeout = 200;
	while (timeout) {
		if (ixgbe_get_eeprom_semaphore(hw))
			return IXGBE_ERR_SWFW_SYNC;
		gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
		if (!(gssr & (fwmask | swmask)))
			break;
		ixgbe_release_eeprom_semaphore(hw);
		msleep(5);
		timeout--;
	}
	if (!timeout) {
		hw_dbg(hw, "Driver can't access resource, GSSR timeout.\n");
		return IXGBE_ERR_SWFW_SYNC;
	}
	gssr |= swmask;
	IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
	ixgbe_release_eeprom_semaphore(hw);
	return 0;
}