32 #define SDIO_VERSION "1.0"
51 static struct semaphore add_remove_card_sem;
53 static int mwifiex_sdio_resume(
struct device *
dev);
69 pr_debug(
"info: vendor=0x%4.04X device=0x%4.04X class=%d function=%d\n",
85 pr_err(
"%s: failed to enable function\n", __func__);
92 pr_err(
"%s: add card failed\n", __func__);
109 mwifiex_sdio_remove(
struct sdio_func *func)
131 mwifiex_sdio_resume(adapter->
dev);
133 for (i = 0; i < adapter->
priv_num; i++)
136 adapter->
priv[i]->media_connected)
158 static int mwifiex_sdio_suspend(
struct device *
dev)
169 pr_debug(
"cmd: %s: suspend: PM flag = 0x%x\n",
172 pr_err(
"%s: cannot remain alive while host is"
179 pr_err(
"suspend: invalid card or adapter\n");
183 pr_err(
"suspend: sdio_func is not specified\n");
191 dev_err(adapter->
dev,
"cmd: failed to suspend\n");
195 dev_dbg(adapter->
dev,
"cmd: suspend with MMC_PM_KEEP_POWER\n");
201 for (i = 0; i < adapter->
priv_num; i++)
217 static int mwifiex_sdio_resume(
struct device *dev)
229 pr_err(
"resume: invalid card or adapter\n");
233 pr_err(
"resume: sdio_func is not specified\n");
240 dev_warn(adapter->
dev,
"device already resumed\n");
246 for (i = 0; i < adapter->
priv_num; i++)
247 if (adapter->
priv[i]->media_connected)
258 #define SDIO_DEVICE_ID_MARVELL_8786 (0x9116)
260 #define SDIO_DEVICE_ID_MARVELL_8787 (0x9119)
262 #define SDIO_DEVICE_ID_MARVELL_8797 (0x9129)
274 static const struct dev_pm_ops mwifiex_sdio_pm_ops = {
275 .suspend = mwifiex_sdio_suspend,
276 .resume = mwifiex_sdio_resume,
280 .name =
"mwifiex_sdio",
281 .id_table = mwifiex_ids,
282 .probe = mwifiex_sdio_probe,
283 .remove = mwifiex_sdio_remove,
286 .pm = &mwifiex_sdio_pm_ops,
347 "%s: not allowed while suspended\n", __func__);
396 dev_dbg(adapter->
dev,
"event: wakeup device...\n");
406 static int mwifiex_pm_wakeup_card_complete(
struct mwifiex_adapter *adapter)
408 dev_dbg(adapter->
dev,
"cmd: wakeup device completed\n");
429 adapter->
ioport |= (reg & 0xff);
434 adapter->
ioport |= ((reg & 0xff) << 8);
439 adapter->
ioport |= ((reg & 0xff) << 16);
472 ret = mwifiex_write_data_sync(adapter, payload, pkt_len, port);
475 dev_err(adapter->
dev,
"host_to_card, write iomem"
476 " (%d) failed: %d\n", i, ret);
478 dev_err(adapter->
dev,
"write CFG reg failed\n");
502 dev_dbg(adapter->
dev,
"data: mp_rd_bitmap=0x%04x\n", rd_bitmap);
510 dev_dbg(adapter->
dev,
"data: port=%d mp_rd_bitmap=0x%04x\n",
525 "data: port=%d mp_rd_bitmap=0x%04x -> 0x%04x\n",
543 dev_dbg(adapter->
dev,
"data: mp_wr_bitmap=0x%04x\n", wr_bitmap);
559 dev_err(adapter->
dev,
"invalid data port=%d cur port=%d"
560 " mp_wr_bitmap=0x%04x -> 0x%04x\n",
566 dev_dbg(adapter->
dev,
"data: port=%d mp_wr_bitmap=0x%04x -> 0x%04x\n",
584 else if ((cs & bits) == bits)
590 dev_err(adapter->
dev,
"poll card status failed, tries = %d\n", tries);
609 *dat = (
u16) ((fws1 << 8) | fws0);
620 static int mwifiex_sdio_disable_host_int(
struct mwifiex_adapter *adapter)
632 dev_err(adapter->
dev,
"disable host interrupt failed\n");
645 static int mwifiex_sdio_enable_host_int(
struct mwifiex_adapter *adapter)
649 dev_err(adapter->
dev,
"enable host interrupt failed\n");
666 dev_err(adapter->
dev,
"%s: buffer is NULL\n", __func__);
670 ret = mwifiex_read_data_sync(adapter, buffer, npayload, ioport, 1);
673 dev_err(adapter->
dev,
"%s: read iomem failed: %d\n", __func__,
680 dev_err(adapter->
dev,
"%s: invalid packet, nb=%d npayload=%d\n",
681 __func__, nb, npayload);
712 "firmware image not found! Terminating download\n");
716 dev_dbg(adapter->
dev,
"info: downloading FW image (%d bytes)\n",
723 "unable to alloc buffer for FW. Terminating dnld\n");
734 dev_err(adapter->
dev,
"FW download with helper:"
735 " poll status timeout @ %d\n", offset);
740 if (offset >= firmware_len)
748 "dev BASE0 register read failed: "
749 "base0=%#04X(%d). Terminating dnld\n",
757 "dev BASE1 register read failed: "
758 "base1=%#04X(%d). Terminating dnld\n",
762 len = (
u16) (((base1 & 0xff) << 8) | (base0 & 0xff));
774 "FW dnld failed @ %d, invalid length %d\n",
786 "FW dnld failed @ %d, over max retry\n",
791 dev_err(adapter->
dev,
"CRC indicated by the helper:"
792 " len = 0x%04X, txlen = %d\n", len, txlen);
801 if (firmware_len - offset < txlen)
802 txlen = firmware_len -
offset;
808 memmove(fwbuf, &firmware[offset], txlen);
811 ret = mwifiex_write_data_sync(adapter, fwbuf, tx_blocks *
816 "FW download, write iomem (%d) failed @ %d\n",
819 dev_err(adapter->
dev,
"write CFG reg failed\n");
828 dev_dbg(adapter->
dev,
"info: FW download over, size %d bytes\n",
851 for (tries = 0; tries < poll_num; tries++) {
852 ret = mwifiex_sdio_read_fw_status(adapter, &firmware_stat);
889 dev_err(adapter->
dev,
"read mp_regs failed\n");
899 dev_dbg(adapter->
dev,
"int: sdio_ireg = %#x\n", sdio_ireg);
902 spin_unlock_irqrestore(&adapter->
int_lock, flags);
913 mwifiex_sdio_interrupt(
struct sdio_func *func)
920 pr_debug(
"int: func=%p card=%p adapter=%p\n",
932 mwifiex_interrupt_status(adapter);
952 dev_dbg(adapter->
dev,
"info: --- Rx: Data packet ---\n");
957 dev_dbg(adapter->
dev,
"info: --- Rx: Cmd Response ---\n");
979 dev_dbg(adapter->
dev,
"info: --- Rx: Event ---\n");
994 dev_err(adapter->
dev,
"unknown upload type %#x\n", upld_typ);
1011 static int mwifiex_sdio_card_to_host_mp_aggr(
struct mwifiex_adapter *adapter,
1015 s32 f_do_rx_aggr = 0;
1016 s32 f_do_rx_cur = 0;
1026 dev_dbg(adapter->
dev,
"info: %s: no aggregation for cmd "
1027 "response\n", __func__);
1030 goto rx_curr_single;
1033 if (!card->
mpa_rx.enabled) {
1034 dev_dbg(adapter->
dev,
"info: %s: rx aggregation disabled\n",
1038 goto rx_curr_single;
1043 dev_dbg(adapter->
dev,
"info: %s: not last packet\n", __func__);
1060 dev_dbg(adapter->
dev,
"info: %s: last packet\n", __func__);
1075 dev_dbg(adapter->
dev,
"info: current packet aggregation\n");
1081 dev_dbg(adapter->
dev,
"info: %s: aggregated packet "
1082 "limit reached\n", __func__);
1090 dev_dbg(adapter->
dev,
"info: do_rx_aggr: num of packets: %d\n",
1093 if (mwifiex_read_data_sync(adapter, card->
mpa_rx.buf,
1095 (adapter->
ioport | 0x1000 |
1096 (card->
mpa_rx.ports << 4)) +
1097 card->
mpa_rx.start_port, 1))
1100 curr_ptr = card->
mpa_rx.buf;
1102 for (pind = 0; pind < card->
mpa_rx.pkt_cnt; pind++) {
1105 pkt_len = *(
u16 *) &curr_ptr[0];
1106 pkt_type = *(
u16 *) &curr_ptr[2];
1109 skb_deaggr = card->
mpa_rx.skb_arr[pind];
1112 card->
mpa_rx.len_arr[pind])) {
1119 mwifiex_decode_rx_packet(adapter, skb_deaggr,
1123 " type=%d len=%d max_len=%d\n",
1125 card->
mpa_rx.len_arr[pind]);
1128 curr_ptr += card->
mpa_rx.len_arr[pind];
1135 dev_dbg(adapter->
dev,
"info: RX: port: %d, rx_len: %d\n",
1138 if (mwifiex_sdio_card_to_host(adapter, &pkt_type,
1143 mwifiex_decode_rx_packet(adapter, skb, pkt_type);
1151 for (pind = 0; pind < card->
mpa_rx.pkt_cnt; pind++) {
1153 skb_deaggr = card->
mpa_rx.skb_arr[pind];
1181 static int mwifiex_process_int_status(
struct mwifiex_adapter *adapter)
1188 u32 len_reg_l, len_reg_u;
1191 unsigned long flags;
1196 spin_unlock_irqrestore(&adapter->
int_lock, flags);
1204 dev_dbg(adapter->
dev,
"int: DNLD: wr_bitmap=0x%04x\n",
1209 "info: <--- Tx DONE Interrupt --->\n");
1226 dev_dbg(adapter->
dev,
"info: cmd_sent=%d data_sent=%d\n",
1231 dev_dbg(adapter->
dev,
"int: UPLD: rd_bitmap=0x%04x\n",
1235 ret = mwifiex_get_rd_port(adapter, &port);
1238 "info: no more rd_port available\n");
1243 rx_len = ((
u16) card->
mp_regs[len_reg_u]) << 8;
1245 dev_dbg(adapter->
dev,
"info: RX: port=%d rx_len=%u\n",
1257 rx_len = (
u16) (rx_blocks * MWIFIEX_SDIO_BLOCK_SIZE);
1259 skb = dev_alloc_skb(rx_len);
1262 dev_err(adapter->
dev,
"%s: failed to alloc skb",
1269 dev_dbg(adapter->
dev,
"info: rx_len = %d skb->len = %d\n",
1272 if (mwifiex_sdio_card_to_host_mp_aggr(adapter, skb,
1276 dev_err(adapter->
dev,
"card_to_host_mpa failed:"
1277 " int status=%#x\n", sdio_ireg);
1278 if (mwifiex_read_reg(adapter,
1281 "read CFG reg failed\n");
1284 "info: CFG reg val = %d\n", cr);
1285 if (mwifiex_write_reg(adapter,
1289 "write CFG reg failed\n");
1291 dev_dbg(adapter->
dev,
"info: write success\n");
1292 if (mwifiex_read_reg(adapter,
1295 "read CFG reg failed\n");
1298 "info: CFG reg val =%x\n", cr);
1321 static int mwifiex_host_to_card_mp_aggr(
struct mwifiex_adapter *adapter,
1322 u8 *payload,
u32 pkt_len,
u8 port,
1327 s32 f_send_aggr_buf = 0;
1328 s32 f_send_cur_buf = 0;
1329 s32 f_precopy_cur_buf = 0;
1330 s32 f_postcopy_cur_buf = 0;
1333 dev_dbg(adapter->
dev,
"info: %s: tx aggregation disabled\n",
1337 goto tx_curr_single;
1342 dev_dbg(adapter->
dev,
"info: %s: more packets in queue.\n",
1348 f_precopy_cur_buf = 1;
1353 card, pkt_len + next_pkt_len))
1354 f_send_aggr_buf = 1;
1357 f_send_aggr_buf = 1;
1364 f_postcopy_cur_buf = 1;
1369 f_precopy_cur_buf = 1;
1375 dev_dbg(adapter->
dev,
"info: %s: Last packet in Tx Queue.\n",
1380 f_send_aggr_buf = 1;
1383 f_precopy_cur_buf = 1;
1392 if (f_precopy_cur_buf) {
1393 dev_dbg(adapter->
dev,
"data: %s: precopy current buffer\n",
1400 f_send_aggr_buf = 1;
1403 if (f_send_aggr_buf) {
1404 dev_dbg(adapter->
dev,
"data: %s: send aggr buffer: %d %d\n",
1407 ret = mwifiex_write_data_to_card(adapter, card->
mpa_tx.buf,
1409 (adapter->
ioport | 0x1000 |
1410 (card->
mpa_tx.ports << 4)) +
1411 card->
mpa_tx.start_port);
1417 if (f_send_cur_buf) {
1418 dev_dbg(adapter->
dev,
"data: %s: send current buffer %d\n",
1420 ret = mwifiex_write_data_to_card(adapter, payload, pkt_len,
1424 if (f_postcopy_cur_buf) {
1425 dev_dbg(adapter->
dev,
"data: %s: postcopy current buffer\n",
1456 blk_size = MWIFIEX_SDIO_BLOCK_SIZE;
1457 buf_block_len = (pkt_len + blk_size - 1) /
blk_size;
1459 *(
u16 *) &payload[2] = type;
1468 ret = mwifiex_get_wr_port_data(adapter, &port);
1470 dev_err(adapter->
dev,
"%s: no wr_port available\n",
1480 dev_err(adapter->
dev,
"%s: payload=%p, nb=%d\n",
1481 __func__, payload, pkt_len);
1485 pkt_len = buf_block_len *
blk_size;
1488 ret = mwifiex_host_to_card_mp_aggr(adapter, payload, pkt_len,
1492 ret = mwifiex_host_to_card_mp_aggr(adapter, payload, pkt_len,
1515 static int mwifiex_alloc_sdio_mpa_buffers(
struct mwifiex_adapter *adapter,
1516 u32 mpa_tx_buf_size,
u32 mpa_rx_buf_size)
1523 dev_err(adapter->
dev,
"could not alloc buffer for MP-A TX\n");
1528 card->
mpa_tx.buf_size = mpa_tx_buf_size;
1532 dev_err(adapter->
dev,
"could not alloc buffer for MP-A RX\n");
1537 card->
mpa_rx.buf_size = mpa_rx_buf_size;
1559 if (adapter->
card) {
1588 pr_err(
"claim irq failed: ret=%d\n", ret);
1595 pr_err(
"cannot set SDIO block size\n");
1603 adapter->
dev = &func->
dev;
1656 mwifiex_sdio_disable_host_int(adapter);
1659 mwifiex_init_sdio_ioport(adapter);
1669 card->
mpa_tx.buf_len = 0;
1670 card->
mpa_tx.pkt_cnt = 0;
1671 card->
mpa_tx.start_port = 0;
1673 card->
mpa_tx.enabled = 1;
1676 card->
mpa_rx.buf_len = 0;
1677 card->
mpa_rx.pkt_cnt = 0;
1678 card->
mpa_rx.start_port = 0;
1680 card->
mpa_rx.enabled = 1;
1686 dev_err(adapter->
dev,
"failed to alloc mp_regs\n");
1690 ret = mwifiex_alloc_sdio_mpa_buffers(adapter,
1694 dev_err(adapter->
dev,
"failed to alloc sdio mp-a buffers\n");
1748 dev_dbg(adapter->
dev,
"cmd: mp_end_port %d, data port mask 0x%x\n",
1753 .init_if = mwifiex_init_sdio,
1754 .cleanup_if = mwifiex_cleanup_sdio,
1755 .check_fw_status = mwifiex_check_fw_status,
1756 .prog_fw = mwifiex_prog_fw_w_helper,
1757 .register_dev = mwifiex_register_dev,
1758 .unregister_dev = mwifiex_unregister_dev,
1759 .enable_int = mwifiex_sdio_enable_host_int,
1760 .process_int_status = mwifiex_process_int_status,
1761 .host_to_card = mwifiex_sdio_host_to_card,
1762 .wakeup = mwifiex_pm_wakeup_card,
1763 .wakeup_complete = mwifiex_pm_wakeup_card_complete,
1766 .update_mp_end_port = mwifiex_update_mp_end_port,
1767 .cleanup_mpa_buf = mwifiex_cleanup_mpa_buf,
1768 .cmdrsp_complete = mwifiex_sdio_cmdrsp_complete,
1769 .event_complete = mwifiex_sdio_event_complete,
1779 mwifiex_sdio_init_module(
void)
1781 sema_init(&add_remove_card_sem, 1);
1799 mwifiex_sdio_cleanup_module(
void)
1802 up(&add_remove_card_sem);