mirror of
https://github.com/edk2-porting/linux-next.git
synced 2025-01-04 03:33:58 +08:00
mwifiex: code rearrangement in pcie.c and sdio.c
Next patch in this series is going to use mwifiex_read_reg() in remove handlers. The changes here are prerequisites to avoid forward declarations. Signed-off-by: Xinming Hu <huxm@marvell.com> Signed-off-by: Amitkumar Karwar <akarwar@marvell.com> Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
This commit is contained in:
parent
3860e5e395
commit
90ff71f955
@ -80,6 +80,42 @@ static void mwifiex_unmap_pci_memory(struct mwifiex_adapter *adapter,
|
||||
pci_unmap_single(card->dev, mapping.addr, mapping.len, flags);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function writes data into PCIE card register.
|
||||
*/
|
||||
static int mwifiex_write_reg(struct mwifiex_adapter *adapter, int reg, u32 data)
|
||||
{
|
||||
struct pcie_service_card *card = adapter->card;
|
||||
|
||||
iowrite32(data, card->pci_mmap1 + reg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This function reads data from PCIE card register.
|
||||
*/
|
||||
static int mwifiex_read_reg(struct mwifiex_adapter *adapter, int reg, u32 *data)
|
||||
{
|
||||
struct pcie_service_card *card = adapter->card;
|
||||
|
||||
*data = ioread32(card->pci_mmap1 + reg);
|
||||
if (*data == 0xffffffff)
|
||||
return 0xffffffff;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This function reads u8 data from PCIE card register. */
|
||||
static int mwifiex_read_reg_byte(struct mwifiex_adapter *adapter,
|
||||
int reg, u8 *data)
|
||||
{
|
||||
struct pcie_service_card *card = adapter->card;
|
||||
|
||||
*data = ioread8(card->pci_mmap1 + reg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function reads sleep cookie and checks if FW is ready
|
||||
*/
|
||||
@ -373,43 +409,6 @@ static struct pci_driver __refdata mwifiex_pcie = {
|
||||
.err_handler = mwifiex_pcie_err_handler,
|
||||
};
|
||||
|
||||
/*
|
||||
* This function writes data into PCIE card register.
|
||||
*/
|
||||
static int mwifiex_write_reg(struct mwifiex_adapter *adapter, int reg, u32 data)
|
||||
{
|
||||
struct pcie_service_card *card = adapter->card;
|
||||
|
||||
iowrite32(data, card->pci_mmap1 + reg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function reads data from PCIE card register.
|
||||
*/
|
||||
static int mwifiex_read_reg(struct mwifiex_adapter *adapter, int reg, u32 *data)
|
||||
{
|
||||
struct pcie_service_card *card = adapter->card;
|
||||
|
||||
*data = ioread32(card->pci_mmap1 + reg);
|
||||
if (*data == 0xffffffff)
|
||||
return 0xffffffff;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This function reads u8 data from PCIE card register. */
|
||||
static int mwifiex_read_reg_byte(struct mwifiex_adapter *adapter,
|
||||
int reg, u8 *data)
|
||||
{
|
||||
struct pcie_service_card *card = adapter->card;
|
||||
|
||||
*data = ioread8(card->pci_mmap1 + reg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function adds delay loop to ensure FW is awake before proceeding.
|
||||
*/
|
||||
|
@ -215,6 +215,171 @@ static int mwifiex_sdio_resume(struct device *dev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Write data into SDIO card register. Caller claims SDIO device. */
|
||||
static int
|
||||
mwifiex_write_reg_locked(struct sdio_func *func, u32 reg, u8 data)
|
||||
{
|
||||
int ret = -1;
|
||||
|
||||
sdio_writeb(func, data, reg, &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* This function writes data into SDIO card register.
|
||||
*/
|
||||
static int
|
||||
mwifiex_write_reg(struct mwifiex_adapter *adapter, u32 reg, u8 data)
|
||||
{
|
||||
struct sdio_mmc_card *card = adapter->card;
|
||||
int ret;
|
||||
|
||||
sdio_claim_host(card->func);
|
||||
ret = mwifiex_write_reg_locked(card->func, reg, data);
|
||||
sdio_release_host(card->func);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* This function reads data from SDIO card register.
|
||||
*/
|
||||
static int
|
||||
mwifiex_read_reg(struct mwifiex_adapter *adapter, u32 reg, u8 *data)
|
||||
{
|
||||
struct sdio_mmc_card *card = adapter->card;
|
||||
int ret = -1;
|
||||
u8 val;
|
||||
|
||||
sdio_claim_host(card->func);
|
||||
val = sdio_readb(card->func, reg, &ret);
|
||||
sdio_release_host(card->func);
|
||||
|
||||
*data = val;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* This function writes multiple data into SDIO card memory.
|
||||
*
|
||||
* This does not work in suspended mode.
|
||||
*/
|
||||
static int
|
||||
mwifiex_write_data_sync(struct mwifiex_adapter *adapter,
|
||||
u8 *buffer, u32 pkt_len, u32 port)
|
||||
{
|
||||
struct sdio_mmc_card *card = adapter->card;
|
||||
int ret;
|
||||
u8 blk_mode =
|
||||
(port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE : BLOCK_MODE;
|
||||
u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1;
|
||||
u32 blk_cnt =
|
||||
(blk_mode ==
|
||||
BLOCK_MODE) ? (pkt_len /
|
||||
MWIFIEX_SDIO_BLOCK_SIZE) : pkt_len;
|
||||
u32 ioport = (port & MWIFIEX_SDIO_IO_PORT_MASK);
|
||||
|
||||
if (adapter->is_suspended) {
|
||||
mwifiex_dbg(adapter, ERROR,
|
||||
"%s: not allowed while suspended\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sdio_claim_host(card->func);
|
||||
|
||||
ret = sdio_writesb(card->func, ioport, buffer, blk_cnt * blk_size);
|
||||
|
||||
sdio_release_host(card->func);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* This function reads multiple data from SDIO card memory.
|
||||
*/
|
||||
static int mwifiex_read_data_sync(struct mwifiex_adapter *adapter, u8 *buffer,
|
||||
u32 len, u32 port, u8 claim)
|
||||
{
|
||||
struct sdio_mmc_card *card = adapter->card;
|
||||
int ret;
|
||||
u8 blk_mode = (port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE
|
||||
: BLOCK_MODE;
|
||||
u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1;
|
||||
u32 blk_cnt = (blk_mode == BLOCK_MODE) ? (len / MWIFIEX_SDIO_BLOCK_SIZE)
|
||||
: len;
|
||||
u32 ioport = (port & MWIFIEX_SDIO_IO_PORT_MASK);
|
||||
|
||||
if (claim)
|
||||
sdio_claim_host(card->func);
|
||||
|
||||
ret = sdio_readsb(card->func, buffer, ioport, blk_cnt * blk_size);
|
||||
|
||||
if (claim)
|
||||
sdio_release_host(card->func);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* This function reads the firmware status.
|
||||
*/
|
||||
static int
|
||||
mwifiex_sdio_read_fw_status(struct mwifiex_adapter *adapter, u16 *dat)
|
||||
{
|
||||
struct sdio_mmc_card *card = adapter->card;
|
||||
const struct mwifiex_sdio_card_reg *reg = card->reg;
|
||||
u8 fws0, fws1;
|
||||
|
||||
if (mwifiex_read_reg(adapter, reg->status_reg_0, &fws0))
|
||||
return -1;
|
||||
|
||||
if (mwifiex_read_reg(adapter, reg->status_reg_1, &fws1))
|
||||
return -1;
|
||||
|
||||
*dat = (u16)((fws1 << 8) | fws0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This function checks the firmware status in card.
|
||||
*/
|
||||
static int mwifiex_check_fw_status(struct mwifiex_adapter *adapter,
|
||||
u32 poll_num)
|
||||
{
|
||||
int ret = 0;
|
||||
u16 firmware_stat;
|
||||
u32 tries;
|
||||
|
||||
for (tries = 0; tries < poll_num; tries++) {
|
||||
ret = mwifiex_sdio_read_fw_status(adapter, &firmware_stat);
|
||||
if (ret)
|
||||
continue;
|
||||
if (firmware_stat == FIRMWARE_READY_SDIO) {
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
msleep(100);
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* This function checks if WLAN is the winner.
|
||||
*/
|
||||
static int mwifiex_check_winner_status(struct mwifiex_adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
u8 winner = 0;
|
||||
struct sdio_mmc_card *card = adapter->card;
|
||||
|
||||
if (mwifiex_read_reg(adapter, card->reg->status_reg_0, &winner))
|
||||
return -1;
|
||||
|
||||
if (winner)
|
||||
adapter->winner = 0;
|
||||
else
|
||||
adapter->winner = 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* SDIO remove.
|
||||
*
|
||||
@ -374,111 +539,6 @@ static struct sdio_driver mwifiex_sdio = {
|
||||
}
|
||||
};
|
||||
|
||||
/* Write data into SDIO card register. Caller claims SDIO device. */
|
||||
static int
|
||||
mwifiex_write_reg_locked(struct sdio_func *func, u32 reg, u8 data)
|
||||
{
|
||||
int ret = -1;
|
||||
sdio_writeb(func, data, reg, &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function writes data into SDIO card register.
|
||||
*/
|
||||
static int
|
||||
mwifiex_write_reg(struct mwifiex_adapter *adapter, u32 reg, u8 data)
|
||||
{
|
||||
struct sdio_mmc_card *card = adapter->card;
|
||||
int ret;
|
||||
|
||||
sdio_claim_host(card->func);
|
||||
ret = mwifiex_write_reg_locked(card->func, reg, data);
|
||||
sdio_release_host(card->func);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function reads data from SDIO card register.
|
||||
*/
|
||||
static int
|
||||
mwifiex_read_reg(struct mwifiex_adapter *adapter, u32 reg, u8 *data)
|
||||
{
|
||||
struct sdio_mmc_card *card = adapter->card;
|
||||
int ret = -1;
|
||||
u8 val;
|
||||
|
||||
sdio_claim_host(card->func);
|
||||
val = sdio_readb(card->func, reg, &ret);
|
||||
sdio_release_host(card->func);
|
||||
|
||||
*data = val;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function writes multiple data into SDIO card memory.
|
||||
*
|
||||
* This does not work in suspended mode.
|
||||
*/
|
||||
static int
|
||||
mwifiex_write_data_sync(struct mwifiex_adapter *adapter,
|
||||
u8 *buffer, u32 pkt_len, u32 port)
|
||||
{
|
||||
struct sdio_mmc_card *card = adapter->card;
|
||||
int ret;
|
||||
u8 blk_mode =
|
||||
(port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE : BLOCK_MODE;
|
||||
u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1;
|
||||
u32 blk_cnt =
|
||||
(blk_mode ==
|
||||
BLOCK_MODE) ? (pkt_len /
|
||||
MWIFIEX_SDIO_BLOCK_SIZE) : pkt_len;
|
||||
u32 ioport = (port & MWIFIEX_SDIO_IO_PORT_MASK);
|
||||
|
||||
if (adapter->is_suspended) {
|
||||
mwifiex_dbg(adapter, ERROR,
|
||||
"%s: not allowed while suspended\n", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sdio_claim_host(card->func);
|
||||
|
||||
ret = sdio_writesb(card->func, ioport, buffer, blk_cnt * blk_size);
|
||||
|
||||
sdio_release_host(card->func);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function reads multiple data from SDIO card memory.
|
||||
*/
|
||||
static int mwifiex_read_data_sync(struct mwifiex_adapter *adapter, u8 *buffer,
|
||||
u32 len, u32 port, u8 claim)
|
||||
{
|
||||
struct sdio_mmc_card *card = adapter->card;
|
||||
int ret;
|
||||
u8 blk_mode = (port & MWIFIEX_SDIO_BYTE_MODE_MASK) ? BYTE_MODE
|
||||
: BLOCK_MODE;
|
||||
u32 blk_size = (blk_mode == BLOCK_MODE) ? MWIFIEX_SDIO_BLOCK_SIZE : 1;
|
||||
u32 blk_cnt = (blk_mode == BLOCK_MODE) ? (len / MWIFIEX_SDIO_BLOCK_SIZE)
|
||||
: len;
|
||||
u32 ioport = (port & MWIFIEX_SDIO_IO_PORT_MASK);
|
||||
|
||||
if (claim)
|
||||
sdio_claim_host(card->func);
|
||||
|
||||
ret = sdio_readsb(card->func, buffer, ioport, blk_cnt * blk_size);
|
||||
|
||||
if (claim)
|
||||
sdio_release_host(card->func);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function wakes up the card.
|
||||
*
|
||||
@ -764,27 +824,6 @@ mwifiex_sdio_poll_card_status(struct mwifiex_adapter *adapter, u8 bits)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function reads the firmware status.
|
||||
*/
|
||||
static int
|
||||
mwifiex_sdio_read_fw_status(struct mwifiex_adapter *adapter, u16 *dat)
|
||||
{
|
||||
struct sdio_mmc_card *card = adapter->card;
|
||||
const struct mwifiex_sdio_card_reg *reg = card->reg;
|
||||
u8 fws0, fws1;
|
||||
|
||||
if (mwifiex_read_reg(adapter, reg->status_reg_0, &fws0))
|
||||
return -1;
|
||||
|
||||
if (mwifiex_read_reg(adapter, reg->status_reg_1, &fws1))
|
||||
return -1;
|
||||
|
||||
*dat = (u16) ((fws1 << 8) | fws0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function disables the host interrupt.
|
||||
*
|
||||
@ -1089,51 +1128,6 @@ done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function checks the firmware status in card.
|
||||
*/
|
||||
static int mwifiex_check_fw_status(struct mwifiex_adapter *adapter,
|
||||
u32 poll_num)
|
||||
{
|
||||
int ret = 0;
|
||||
u16 firmware_stat;
|
||||
u32 tries;
|
||||
|
||||
for (tries = 0; tries < poll_num; tries++) {
|
||||
ret = mwifiex_sdio_read_fw_status(adapter, &firmware_stat);
|
||||
if (ret)
|
||||
continue;
|
||||
if (firmware_stat == FIRMWARE_READY_SDIO) {
|
||||
ret = 0;
|
||||
break;
|
||||
} else {
|
||||
msleep(100);
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* This function checks if WLAN is the winner.
|
||||
*/
|
||||
static int mwifiex_check_winner_status(struct mwifiex_adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
u8 winner = 0;
|
||||
struct sdio_mmc_card *card = adapter->card;
|
||||
|
||||
if (mwifiex_read_reg(adapter, card->reg->status_reg_0, &winner))
|
||||
return -1;
|
||||
|
||||
if (winner)
|
||||
adapter->winner = 0;
|
||||
else
|
||||
adapter->winner = 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function decode sdio aggreation pkt.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user