diff options
Diffstat (limited to 'drivers/staging/vt6655/mac.c')
-rw-r--r-- | drivers/staging/vt6655/mac.c | 193 |
1 files changed, 101 insertions, 92 deletions
diff --git a/drivers/staging/vt6655/mac.c b/drivers/staging/vt6655/mac.c index 80cced7dfda8..b4ebc7d31961 100644 --- a/drivers/staging/vt6655/mac.c +++ b/drivers/staging/vt6655/mac.c @@ -10,17 +10,16 @@ * Date: May 21, 1996 * * Functions: - * MACbIsRegBitsOff - Test if All test Bits Off - * MACbIsIntDisable - Test if MAC interrupt disable - * MACvSetShortRetryLimit - Set 802.11 Short Retry limit + * vt6655_mac_is_reg_bits_off - Test if All test Bits Off + * vt6655_mac_set_short_retry_limit - Set 802.11 Short Retry limit * MACvSetLongRetryLimit - Set 802.11 Long Retry limit - * MACvSetLoopbackMode - Set MAC Loopback Mode - * MACvSaveContext - Save Context of MAC Registers - * MACvRestoreContext - Restore Context of MAC Registers + * vt6655_mac_set_loopback_mode - Set MAC Loopback Mode + * vt6655_mac_save_context - Save Context of MAC Registers + * vt6655_mac_restore_context - Restore Context of MAC Registers * MACbSoftwareReset - Software Reset MAC - * MACbSafeRxOff - Turn Off MAC Rx - * MACbSafeTxOff - Turn Off MAC Tx - * MACbSafeStop - Stop MAC function + * vt6655_mac_safe_rx_off - Turn Off MAC Rx + * vt6655_mac_safe_tx_off - Turn Off MAC Tx + * vt6655_mac_safe_stop - Stop MAC function * MACbShutdown - Shut down MAC * MACvInitialize - Initialize MAC * MACvSetCurrRxDescAddr - Set Rx Descriptors Address @@ -36,53 +35,71 @@ * */ -#include "tmacro.h" #include "mac.h" -/* - * Description: - * Test if all test bits off - * - * Parameters: - * In: - * io_base - Base Address for MAC - * byRegOfs - Offset of MAC Register - * byTestBits - Test bits - * Out: - * none - * - * Return Value: true if all test bits Off; otherwise false - * - */ -bool MACbIsRegBitsOff(struct vnt_private *priv, unsigned char byRegOfs, - unsigned char byTestBits) +void vt6655_mac_reg_bits_on(void __iomem *iobase, const u8 reg_offset, const u8 bit_mask) { - void __iomem *io_base = priv->port_offset; + unsigned char reg_value; + + reg_value = ioread8(iobase + reg_offset); + iowrite8(reg_value | bit_mask, iobase + reg_offset); +} + +void vt6655_mac_word_reg_bits_on(void __iomem *iobase, const u8 reg_offset, const u16 bit_mask) +{ + unsigned short reg_value; + + reg_value = ioread16(iobase + reg_offset); + iowrite16(reg_value | (bit_mask), iobase + reg_offset); +} + +void vt6655_mac_reg_bits_off(void __iomem *iobase, const u8 reg_offset, const u8 bit_mask) +{ + unsigned char reg_value; + + reg_value = ioread8(iobase + reg_offset); + iowrite8(reg_value & ~(bit_mask), iobase + reg_offset); +} - return !(ioread8(io_base + byRegOfs) & byTestBits); +void vt6655_mac_word_reg_bits_off(void __iomem *iobase, const u8 reg_offset, const u16 bit_mask) +{ + unsigned short reg_value; + + reg_value = ioread16(iobase + reg_offset); + iowrite16(reg_value & ~(bit_mask), iobase + reg_offset); +} + +static void vt6655_mac_clear_stck_ds(void __iomem *iobase) +{ + u8 reg_value; + + reg_value = ioread8(iobase + MAC_REG_STICKHW); + reg_value = reg_value & 0xFC; + iowrite8(reg_value, iobase + MAC_REG_STICKHW); } /* * Description: - * Test if MAC interrupt disable + * Test if all test bits off * * Parameters: * In: * io_base - Base Address for MAC + * reg_offset - Offset of MAC Register + * mask - Test bits * Out: * none * - * Return Value: true if interrupt is disable; otherwise false + * Return Value: true if all test bits Off; otherwise false * */ -bool MACbIsIntDisable(struct vnt_private *priv) +static bool vt6655_mac_is_reg_bits_off(struct vnt_private *priv, + unsigned char reg_offset, + unsigned char mask) { void __iomem *io_base = priv->port_offset; - if (ioread32(io_base + MAC_REG_IMR)) - return false; - - return true; + return !(ioread8(io_base + reg_offset) & mask); } /* @@ -92,19 +109,18 @@ bool MACbIsIntDisable(struct vnt_private *priv) * Parameters: * In: * io_base - Base Address for MAC - * byRetryLimit- Retry Limit + * retry_limit - Retry Limit * Out: * none * * Return Value: none * */ -void MACvSetShortRetryLimit(struct vnt_private *priv, - unsigned char byRetryLimit) +void vt6655_mac_set_short_retry_limit(struct vnt_private *priv, unsigned char retry_limit) { void __iomem *io_base = priv->port_offset; /* set SRT */ - iowrite8(byRetryLimit, io_base + MAC_REG_SRT); + iowrite8(retry_limit, io_base + MAC_REG_SRT); } /* @@ -136,21 +152,20 @@ void MACvSetLongRetryLimit(struct vnt_private *priv, * Parameters: * In: * io_base - Base Address for MAC - * byLoopbackMode - Loopback Mode + * loopback_mode - Loopback Mode * Out: * none * * Return Value: none * */ -void MACvSetLoopbackMode(struct vnt_private *priv, unsigned char byLoopbackMode) +static void vt6655_mac_set_loopback_mode(struct vnt_private *priv, u8 loopback_mode) { void __iomem *io_base = priv->port_offset; - byLoopbackMode <<= 6; + loopback_mode <<= 6; /* set TCR */ - iowrite8((ioread8(io_base + MAC_REG_TEST) & 0x3f) | byLoopbackMode, - io_base + MAC_REG_TEST); + iowrite8((ioread8(io_base + MAC_REG_TEST) & 0x3f) | loopback_mode, io_base + MAC_REG_TEST); } /* @@ -166,20 +181,20 @@ void MACvSetLoopbackMode(struct vnt_private *priv, unsigned char byLoopbackMode) * Return Value: none * */ -void MACvSaveContext(struct vnt_private *priv, unsigned char *cxt_buf) +static void vt6655_mac_save_context(struct vnt_private *priv, u8 *cxt_buf) { void __iomem *io_base = priv->port_offset; /* read page0 register */ memcpy_fromio(cxt_buf, io_base, MAC_MAX_CONTEXT_SIZE_PAGE0); - MACvSelectPage1(io_base); + VT6655_MAC_SELECT_PAGE1(io_base); /* read page1 register */ memcpy_fromio(cxt_buf + MAC_MAX_CONTEXT_SIZE_PAGE0, io_base, MAC_MAX_CONTEXT_SIZE_PAGE1); - MACvSelectPage0(io_base); + VT6655_MAC_SELECT_PAGE0(io_base); } /* @@ -196,16 +211,16 @@ void MACvSaveContext(struct vnt_private *priv, unsigned char *cxt_buf) * Return Value: none * */ -void MACvRestoreContext(struct vnt_private *priv, unsigned char *cxt_buf) +static void vt6655_mac_restore_context(struct vnt_private *priv, u8 *cxt_buf) { void __iomem *io_base = priv->port_offset; - MACvSelectPage1(io_base); + VT6655_MAC_SELECT_PAGE1(io_base); /* restore page1 */ memcpy_toio(io_base, cxt_buf + MAC_MAX_CONTEXT_SIZE_PAGE0, MAC_MAX_CONTEXT_SIZE_PAGE1); - MACvSelectPage0(io_base); + VT6655_MAC_SELECT_PAGE0(io_base); /* restore RCR,TCR,IMR... */ memcpy_toio(io_base + MAC_REG_RCR, cxt_buf + MAC_REG_RCR, @@ -278,23 +293,20 @@ bool MACbSoftwareReset(struct vnt_private *priv) * Return Value: true if success; otherwise false * */ -bool MACbSafeSoftwareReset(struct vnt_private *priv) +static void vt6655_mac_save_soft_reset(struct vnt_private *priv) { - unsigned char abyTmpRegData[MAC_MAX_CONTEXT_SIZE_PAGE0 + MAC_MAX_CONTEXT_SIZE_PAGE1]; - bool bRetVal; + u8 tmp_reg_data[MAC_MAX_CONTEXT_SIZE_PAGE0 + MAC_MAX_CONTEXT_SIZE_PAGE1]; /* PATCH.... * save some important register's value, then do * reset, then restore register's value */ /* save MAC context */ - MACvSaveContext(priv, abyTmpRegData); + vt6655_mac_save_context(priv, tmp_reg_data); /* do reset */ - bRetVal = MACbSoftwareReset(priv); + MACbSoftwareReset(priv); /* restore MAC context, except CR0 */ - MACvRestoreContext(priv, abyTmpRegData); - - return bRetVal; + vt6655_mac_restore_context(priv, tmp_reg_data); } /* @@ -310,7 +322,7 @@ bool MACbSafeSoftwareReset(struct vnt_private *priv) * Return Value: true if success; otherwise false * */ -bool MACbSafeRxOff(struct vnt_private *priv) +static bool vt6655_mac_safe_rx_off(struct vnt_private *priv) { void __iomem *io_base = priv->port_offset; unsigned short ww; @@ -338,7 +350,7 @@ bool MACbSafeRxOff(struct vnt_private *priv) } /* try to safe shutdown RX */ - MACvRegBitsOff(io_base, MAC_REG_HOSTCR, HOSTCR_RXON); + vt6655_mac_reg_bits_off(io_base, MAC_REG_HOSTCR, HOSTCR_RXON); /* W_MAX_TIMEOUT is the timeout period */ for (ww = 0; ww < W_MAX_TIMEOUT; ww++) { if (!(ioread8(io_base + MAC_REG_HOSTCR) & HOSTCR_RXONST)) @@ -364,7 +376,7 @@ bool MACbSafeRxOff(struct vnt_private *priv) * Return Value: true if success; otherwise false * */ -bool MACbSafeTxOff(struct vnt_private *priv) +static bool vt6655_mac_safe_tx_off(struct vnt_private *priv) { void __iomem *io_base = priv->port_offset; unsigned short ww; @@ -393,7 +405,7 @@ bool MACbSafeTxOff(struct vnt_private *priv) } /* try to safe shutdown TX */ - MACvRegBitsOff(io_base, MAC_REG_HOSTCR, HOSTCR_TXON); + vt6655_mac_reg_bits_off(io_base, MAC_REG_HOSTCR, HOSTCR_TXON); /* W_MAX_TIMEOUT is the timeout period */ for (ww = 0; ww < W_MAX_TIMEOUT; ww++) { @@ -420,24 +432,24 @@ bool MACbSafeTxOff(struct vnt_private *priv) * Return Value: true if success; otherwise false * */ -bool MACbSafeStop(struct vnt_private *priv) +static bool vt6655_mac_safe_stop(struct vnt_private *priv) { void __iomem *io_base = priv->port_offset; - MACvRegBitsOff(io_base, MAC_REG_TCR, TCR_AUTOBCNTX); + vt6655_mac_reg_bits_off(io_base, MAC_REG_TCR, TCR_AUTOBCNTX); - if (!MACbSafeRxOff(priv)) { - pr_debug(" MACbSafeRxOff == false)\n"); - MACbSafeSoftwareReset(priv); + if (!vt6655_mac_safe_rx_off(priv)) { + pr_debug(" vt6655_mac_safe_rx_off == false)\n"); + vt6655_mac_save_soft_reset(priv); return false; } - if (!MACbSafeTxOff(priv)) { - pr_debug(" MACbSafeTxOff == false)\n"); - MACbSafeSoftwareReset(priv); + if (!vt6655_mac_safe_tx_off(priv)) { + pr_debug(" vt6655_mac_safe_tx_off == false)\n"); + vt6655_mac_save_soft_reset(priv); return false; } - MACvRegBitsOff(io_base, MAC_REG_HOSTCR, HOSTCR_MACEN); + vt6655_mac_reg_bits_off(io_base, MAC_REG_HOSTCR, HOSTCR_MACEN); return true; } @@ -459,14 +471,14 @@ bool MACbShutdown(struct vnt_private *priv) { void __iomem *io_base = priv->port_offset; /* disable MAC IMR */ - MACvIntDisable(io_base); - MACvSetLoopbackMode(priv, MAC_LB_INTERNAL); + iowrite32(0, io_base + MAC_REG_IMR); + vt6655_mac_set_loopback_mode(priv, MAC_LB_INTERNAL); /* stop the adapter */ - if (!MACbSafeStop(priv)) { - MACvSetLoopbackMode(priv, MAC_LB_NONE); + if (!vt6655_mac_safe_stop(priv)) { + vt6655_mac_set_loopback_mode(priv, MAC_LB_NONE); return false; } - MACvSetLoopbackMode(priv, MAC_LB_NONE); + vt6655_mac_set_loopback_mode(priv, MAC_LB_NONE); return true; } @@ -487,7 +499,7 @@ void MACvInitialize(struct vnt_private *priv) { void __iomem *io_base = priv->port_offset; /* clear sticky bits */ - MACvClearStckDS(io_base); + vt6655_mac_clear_stck_ds(io_base); /* disable force PME-enable */ iowrite8(PME_OVR, io_base + MAC_REG_PMC1); /* only 3253 A */ @@ -515,7 +527,7 @@ void MACvInitialize(struct vnt_private *priv) * Return Value: none * */ -void MACvSetCurrRx0DescAddr(struct vnt_private *priv, u32 curr_desc_addr) +void vt6655_mac_set_curr_rx_0_desc_addr(struct vnt_private *priv, u32 curr_desc_addr) { void __iomem *io_base = priv->port_offset; unsigned short ww; @@ -549,7 +561,7 @@ void MACvSetCurrRx0DescAddr(struct vnt_private *priv, u32 curr_desc_addr) * Return Value: none * */ -void MACvSetCurrRx1DescAddr(struct vnt_private *priv, u32 curr_desc_addr) +void vt6655_mac_set_curr_rx_1_desc_addr(struct vnt_private *priv, u32 curr_desc_addr) { void __iomem *io_base = priv->port_offset; unsigned short ww; @@ -583,8 +595,7 @@ void MACvSetCurrRx1DescAddr(struct vnt_private *priv, u32 curr_desc_addr) * Return Value: none * */ -void MACvSetCurrTx0DescAddrEx(struct vnt_private *priv, - u32 curr_desc_addr) +static void vt6655_mac_set_curr_tx_0_desc_addr_ex(struct vnt_private *priv, u32 curr_desc_addr) { void __iomem *io_base = priv->port_offset; unsigned short ww; @@ -619,8 +630,7 @@ void MACvSetCurrTx0DescAddrEx(struct vnt_private *priv, * */ /* TxDMA1 = AC0DMA */ -void MACvSetCurrAC0DescAddrEx(struct vnt_private *priv, - u32 curr_desc_addr) +static void vt6655_mac_set_curr_ac_0_desc_addr_ex(struct vnt_private *priv, u32 curr_desc_addr) { void __iomem *io_base = priv->port_offset; unsigned short ww; @@ -641,13 +651,12 @@ void MACvSetCurrAC0DescAddrEx(struct vnt_private *priv, iowrite8(DMACTL_RUN, io_base + MAC_REG_AC0DMACTL); } -void MACvSetCurrTXDescAddr(int iTxType, struct vnt_private *priv, - u32 curr_desc_addr) +void vt6655_mac_set_curr_tx_desc_addr(int tx_type, struct vnt_private *priv, u32 curr_desc_addr) { - if (iTxType == TYPE_AC0DMA) - MACvSetCurrAC0DescAddrEx(priv, curr_desc_addr); - else if (iTxType == TYPE_TXDMA0) - MACvSetCurrTx0DescAddrEx(priv, curr_desc_addr); + if (tx_type == TYPE_AC0DMA) + vt6655_mac_set_curr_ac_0_desc_addr_ex(priv, curr_desc_addr); + else if (tx_type == TYPE_TXDMA0) + vt6655_mac_set_curr_tx_0_desc_addr_ex(priv, curr_desc_addr); } /* @@ -727,11 +736,11 @@ bool MACbPSWakeup(struct vnt_private *priv) void __iomem *io_base = priv->port_offset; unsigned int ww; /* Read PSCTL */ - if (MACbIsRegBitsOff(priv, MAC_REG_PSCTL, PSCTL_PS)) + if (vt6655_mac_is_reg_bits_off(priv, MAC_REG_PSCTL, PSCTL_PS)) return true; /* Disable PS */ - MACvRegBitsOff(io_base, MAC_REG_PSCTL, PSCTL_PSEN); + vt6655_mac_reg_bits_off(io_base, MAC_REG_PSCTL, PSCTL_PSEN); /* Check if SyncFlushOK */ for (ww = 0; ww < W_MAX_TIMEOUT; ww++) { |