software/drivers/sd8887/src/wlan/mlan/mlan_sdio.c
/**
 *  @brief This function reads data from the card.
 *
 *  @param pmadapter A pointer to mlan_adapter structure
 *  @param type     A pointer to keep type as data or command
 *  @param nb       A pointer to keep the data/cmd length returned in buffer
 *  @param pmbuf    A pointer to the SDIO data/cmd buffer
 *  @param npayload the length of data/cmd buffer
 *  @param ioport   the SDIO ioport
 *  @return         MLAN_STATUS_SUCCESS or MLAN_STATUS_FAILURE
 */
@brief This function reads data from the card.
@brief This function reads data from the card .
static mlan_status
wlan_sdio_card_to_host(mlan_adapter *pmadapter,
		       t_u32 *type, t_u32 *nb, pmlan_buffer pmbuf,
		       t_u32 npayload, t_u32 ioport)
{
	mlan_status ret = MLAN_STATUS_SUCCESS;
	pmlan_callbacks pcb = &pmadapter->callbacks;
	t_u32 i = 0;
	ENTER();
	if (!pmbuf) {
		PRINTM(MWARN, "pmbuf is NULL!\n");
		ret = MLAN_STATUS_FAILURE;
		goto exit;
	}
	do {
		ret = pcb->moal_read_data_sync(pmadapter->pmoal_handle, pmbuf,
					       ioport, 0);
		if (ret != MLAN_STATUS_SUCCESS) {
			PRINTM(MERROR,
			       "wlan: cmd53 read failed: %d ioport=0x%x retry=%d\n",
			       ret, ioport, i);
			i++;
			if (MLAN_STATUS_SUCCESS !=
			    pcb->moal_write_reg(pmadapter->pmoal_handle,
						HOST_TO_CARD_EVENT_REG,
						HOST_TERM_CMD53)) {
				PRINTM(MERROR, "Set Term cmd53 failed\n");
			}
			if (i > MAX_WRITE_IOMEM_RETRY) {
				pmbuf->status_code = MLAN_ERROR_DATA_RX_FAIL;
				ret = MLAN_STATUS_FAILURE;
				goto exit;
			}
		}
	} while (ret == MLAN_STATUS_FAILURE);
	*nb = wlan_le16_to_cpu(*(t_u16 *)(pmbuf->pbuf + pmbuf->data_offset));
	if (*nb > npayload) {
		PRINTM(MERROR, "invalid packet, *nb=%d, npayload=%d\n", *nb,
		       npayload);
		pmbuf->status_code = MLAN_ERROR_PKT_SIZE_INVALID;
		ret = MLAN_STATUS_FAILURE;
		goto exit;
	}
	DBG_HEXDUMP(MIF_D, "SDIO Blk Rd", pmbuf->pbuf + pmbuf->data_offset,
		    MIN(*nb, MAX_DATA_DUMP_LEN));
	*type = wlan_le16_to_cpu(*(t_u16 *)
				 (pmbuf->pbuf + pmbuf->data_offset + 2));
exit:
	LEAVE();
	return ret;
}
static mlan_status wlan_sdio_card_to_host ( mlan_adapter * pmadapter , t_u32 * type , t_u32 * nb , pmlan_buffer pmbuf , t_u32 npayload , t_u32 ioport ) { mlan_status ret = MLAN_STATUS_SUCCESS ; pmlan_callbacks pcb = & pmadapter -> callbacks ; t_u32 i = 0 ; ENTER ( ) ; if ( ! pmbuf ) { PRINTM ( MWARN , " \n " ) ; ret = MLAN_STATUS_FAILURE ; goto exit ; } do { ret = pcb -> moal_read_data_sync ( pmadapter -> pmoal_handle , pmbuf , ioport , 0 ) ; if ( ret != MLAN_STATUS_SUCCESS ) { PRINTM ( MERROR , " \n " , ret , ioport , i ) ; i ++ ; if ( MLAN_STATUS_SUCCESS != pcb -> moal_write_reg ( pmadapter -> pmoal_handle , HOST_TO_CARD_EVENT_REG , HOST_TERM_CMD53 ) ) { PRINTM ( MERROR , " \n " ) ; } if ( i > MAX_WRITE_IOMEM_RETRY ) { pmbuf -> status_code = MLAN_ERROR_DATA_RX_FAIL ; ret = MLAN_STATUS_FAILURE ; goto exit ; } } } while ( ret == MLAN_STATUS_FAILURE ) ; * nb = wlan_le16_to_cpu ( * ( t_u16 * ) ( pmbuf -> pbuf + pmbuf -> data_offset ) ) ; if ( * nb > npayload ) { PRINTM ( MERROR , " \n " , * nb , npayload ) ; pmbuf -> status_code = MLAN_ERROR_PKT_SIZE_INVALID ; ret = MLAN_STATUS_FAILURE ; goto exit ; } DBG_HEXDUMP ( MIF_D , " " , pmbuf -> pbuf + pmbuf -> data_offset , MIN ( * nb , MAX_DATA_DUMP_LEN ) ) ; * type = wlan_le16_to_cpu ( * ( t_u16 * ) ( pmbuf -> pbuf + pmbuf -> data_offset + 2 ) ) ; exit : LEAVE ( ) ; return ret ; }
@brief This function reads data from the card.
@brief This function reads data from the card .