software/drivers/sd8887/src/wlan/mlinux/moal_priv.c
/**
 *  @brief Cmd53 read/write register
 *
 *  @param priv         A pointer to moal_private structure
 *  @param wrq          A pointer to iwreq structure
 *  @return             MLAN_STATUS_SUCCESS --success, otherwise fail
 */
@brief Cmd53 read/write register
@param priv         A pointer to moal_private structure
@param wrq          A pointer to iwreq structure
@return             MLAN_STATUS_SUCCESS --success, otherwise fail
@brief Cmd53 read / write register @param priv A pointer to moal_private structure @param wrq A pointer to iwreq structure @return MLAN_STATUS_SUCCESS -- success otherwise fail
static int
woal_cmd53rdwr_ioctl(moal_private *priv, struct iwreq *wrq)
{
	t_u8 *buf = NULL;
	t_u8 rw, func, mode;
	t_u16 blklen = 0, blknum = 0;
	int reg = 0, pattern_len = 0, pos = 0, ret = MLAN_STATUS_SUCCESS;
	t_u32 total_len = 0;
	t_u8 *data = NULL;
	ENTER();
	buf = kmalloc(WOAL_2K_BYTES, GFP_KERNEL);
	if (!buf) {
		PRINTM(MERROR, "Cannot allocate buffer for command!\n");
		ret = -EFAULT;
		goto done;
	}
	data = kmalloc(WOAL_2K_BYTES, GFP_KERNEL);
	if (!data) {
		PRINTM(MERROR, "Cannot allocate buffer for command!\n");
		ret = -EFAULT;
		goto done;
	}
	if (wrq->u.data.length > WOAL_2K_BYTES) {
		PRINTM(MERROR, "Data lengh is too large!\n");
		ret = -EINVAL;
		goto done;
	}
	if (copy_from_user(buf, wrq->u.data.pointer, wrq->u.data.length)) {
		PRINTM(MINFO, "Copy from user failed\n");
		ret = -EFAULT;
		goto done;
	}
	rw = buf[0];		
	func = buf[1];		
	reg = buf[5];		
	reg = (reg << 8) + buf[4];
	reg = (reg << 8) + buf[3];
	reg = (reg << 8) + buf[2];
	mode = buf[6];		
	blklen = buf[8];	
	blklen = (blklen << 8) + buf[7];
	blknum = buf[10];	
	blknum = (blknum << 8) + buf[9];
	if (mode != BYTE_MODE)
		mode = BLOCK_MODE;
	total_len = (mode == BLOCK_MODE) ? blknum * blklen : blknum;
	if (total_len > WOAL_2K_BYTES) {
		PRINTM(MERROR, "Total data length is too large!\n");
		ret = -EINVAL;
		goto done;
	}
	PRINTM(MINFO,
	       "CMD53 read/write, func = %d, addr = %#x, mode = %d, block size = %d, block(byte) number = %d\n",
	       func, reg, mode, blklen, blknum);
	if (!rw) {
		sdio_claim_host(((struct sdio_mmc_card *)priv->phandle->card)->
				func);
		if (sdio_readsb
		    (((struct sdio_mmc_card *)priv->phandle->card)->func, data,
		     reg, total_len))
			PRINTM(MERROR,
			       "sdio_readsb: reading memory 0x%x failed\n",
			       reg);
		sdio_release_host(((struct sdio_mmc_card *)priv->phandle->
				   card)->func);
		if (copy_to_user(wrq->u.data.pointer, data, total_len)) {
			PRINTM(MINFO, "Copy to user failed\n");
			ret = -EFAULT;
			goto done;
		}
		wrq->u.data.length = total_len;
	} else {
		pattern_len = wrq->u.data.length - 11;
		if (pattern_len > total_len)
			pattern_len = total_len;
		memset(data, 0, WOAL_2K_BYTES);
		for (pos = 0; pos < total_len; pos++)
			data[pos] = buf[11 + (pos % pattern_len)];
		sdio_claim_host(((struct sdio_mmc_card *)priv->phandle->card)->
				func);
		if (sdio_writesb
		    (((struct sdio_mmc_card *)priv->phandle->card)->func, reg,
		     data, total_len))
			PRINTM(MERROR,
			       "sdio_writesb: writing memory 0x%x failed\n",
			       reg);
		sdio_release_host(((struct sdio_mmc_card *)priv->phandle->
				   card)->func);
	}
done:
	kfree(buf);
	kfree(data);
	LEAVE();
	return ret;
}
static int woal_cmd53rdwr_ioctl ( moal_private * priv , struct iwreq * wrq ) { t_u8 * buf = NULL ; t_u8 rw , func , mode ; t_u16 blklen = 0 , blknum = 0 ; int reg = 0 , pattern_len = 0 , pos = 0 , ret = MLAN_STATUS_SUCCESS ; t_u32 total_len = 0 ; t_u8 * data = NULL ; ENTER ( ) ; buf = kmalloc ( WOAL_2K_BYTES , GFP_KERNEL ) ; if ( ! buf ) { PRINTM ( MERROR , " \n " ) ; ret = - EFAULT ; goto done ; } data = kmalloc ( WOAL_2K_BYTES , GFP_KERNEL ) ; if ( ! data ) { PRINTM ( MERROR , " \n " ) ; ret = - EFAULT ; goto done ; } if ( wrq -> u . data . length > WOAL_2K_BYTES ) { PRINTM ( MERROR , " \n " ) ; ret = - EINVAL ; goto done ; } if ( copy_from_user ( buf , wrq -> u . data . pointer , wrq -> u . data . length ) ) { PRINTM ( MINFO , " \n " ) ; ret = - EFAULT ; goto done ; } rw = buf [ 0 ] ; func = buf [ 1 ] ; reg = buf [ 5 ] ; reg = ( reg << 8 ) + buf [ 4 ] ; reg = ( reg << 8 ) + buf [ 3 ] ; reg = ( reg << 8 ) + buf [ 2 ] ; mode = buf [ 6 ] ; blklen = buf [ 8 ] ; blklen = ( blklen << 8 ) + buf [ 7 ] ; blknum = buf [ 10 ] ; blknum = ( blknum << 8 ) + buf [ 9 ] ; if ( mode != BYTE_MODE ) mode = BLOCK_MODE ; total_len = ( mode == BLOCK_MODE ) ? blknum * blklen : blknum ; if ( total_len > WOAL_2K_BYTES ) { PRINTM ( MERROR , " \n " ) ; ret = - EINVAL ; goto done ; } PRINTM ( MINFO , " \n " , func , reg , mode , blklen , blknum ) ; if ( ! rw ) { sdio_claim_host ( ( ( struct sdio_mmc_card * ) priv -> phandle -> card ) -> func ) ; if ( sdio_readsb ( ( ( struct sdio_mmc_card * ) priv -> phandle -> card ) -> func , data , reg , total_len ) ) PRINTM ( MERROR , " \n " , reg ) ; sdio_release_host ( ( ( struct sdio_mmc_card * ) priv -> phandle -> card ) -> func ) ; if ( copy_to_user ( wrq -> u . data . pointer , data , total_len ) ) { PRINTM ( MINFO , " \n " ) ; ret = - EFAULT ; goto done ; } wrq -> u . data . length = total_len ; } else { pattern_len = wrq -> u . data . length - 11 ; if ( pattern_len > total_len ) pattern_len = total_len ; memset ( data , 0 , WOAL_2K_BYTES ) ; for ( pos = 0 ; pos < total_len ; pos ++ ) data [ pos ] = buf [ 11 + ( pos % pattern_len ) ] ; sdio_claim_host ( ( ( struct sdio_mmc_card * ) priv -> phandle -> card ) -> func ) ; if ( sdio_writesb ( ( ( struct sdio_mmc_card * ) priv -> phandle -> card ) -> func , reg , data , total_len ) ) PRINTM ( MERROR , " \n " , reg ) ; sdio_release_host ( ( ( struct sdio_mmc_card * ) priv -> phandle -> card ) -> func ) ; } done : kfree ( buf ) ; kfree ( data ) ; LEAVE ( ) ; return ret ; }
@brief Cmd53 read/write register
  @param priv         A pointer to moal_private structure
  @param wrq          A pointer to iwreq structure
  @return             MLAN_STATUS_SUCCESS --success, otherwise fail
@brief Cmd53 read / write register @param priv A pointer to moal_private structure @param wrq A pointer to iwreq structure @return MLAN_STATUS_SUCCESS -- success otherwise fail
/* read/write (0/1) */ /* func (0/1/2) */ /* address */ /* byte mode/block mode (0/1) */ /* block size */ /* block number or byte number */ /* Copy/duplicate the pattern to data buffer */