blob: 01022113950af9081d9341c8220b6e085dd7f330 [file] [log] [blame]
/******************************************************************************
*
* Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
******************************************************************************/
/*
The purpose of rtw_io.c
a. provides the API
b. provides the protocol engine
c. provides the software interface between caller and the hardware interface
Compiler Flag Option:
1. For USB:
a. USE_ASYNC_IRP: Both sync/async operations are provided.
Only sync read/rtw_write_mem operations are provided.
jackson@realtek.com.tw
*/
#define _RTW_IO_C_
#include <osdep_service.h>
#include <drv_types.h>
#include <rtw_io.h>
#include <osdep_intf.h>
#include <usb_ops.h>
u8 _rtw_read823a(struct rtw_adapter *adapter, u32 addr)
{
u8 r_val;
struct _io_ops *io_ops = &adapter->io_ops;
r_val = io_ops->_read8(adapter, addr);
return r_val;
}
u16 _rtw_read1623a(struct rtw_adapter *adapter, u32 addr)
{
u16 r_val;
struct _io_ops *io_ops = &adapter->io_ops;
r_val = io_ops->_read16(adapter, addr);
return le16_to_cpu(r_val);
}
u32 _rtw_read3223a(struct rtw_adapter *adapter, u32 addr)
{
u32 r_val;
struct _io_ops *io_ops = &adapter->io_ops;
r_val = io_ops->_read32(adapter, addr);
return le32_to_cpu(r_val);
}
int _rtw_write823a(struct rtw_adapter *adapter, u32 addr, u8 val)
{
struct _io_ops *io_ops = &adapter->io_ops;
int ret;
ret = io_ops->_write8(adapter, addr, val);
return RTW_STATUS_CODE23a(ret);
}
int _rtw_write1623a(struct rtw_adapter *adapter, u32 addr, u16 val)
{
struct _io_ops *io_ops = &adapter->io_ops;
int ret;
val = cpu_to_le16(val);
ret = io_ops->_write16(adapter, addr, val);
return RTW_STATUS_CODE23a(ret);
}
int _rtw_write3223a(struct rtw_adapter *adapter, u32 addr, u32 val)
{
struct _io_ops *io_ops = &adapter->io_ops;
int ret;
val = cpu_to_le32(val);
ret = io_ops->_write32(adapter, addr, val);
return RTW_STATUS_CODE23a(ret);
}
int _rtw_writeN23a(struct rtw_adapter *adapter, u32 addr , u32 length , u8 *pdata)
{
struct _io_ops *io_ops = &adapter->io_ops;
int ret;
ret = io_ops->_writeN(adapter, addr, length, pdata);
return RTW_STATUS_CODE23a(ret);
}
void _rtw_read_mem23a(struct rtw_adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
{
struct _io_ops *io_ops = &adapter->io_ops;
if ((adapter->bDriverStopped == true) ||
(adapter->bSurpriseRemoved == true)) {
RT_TRACE(_module_rtl871x_io_c_, _drv_info_,
("rtw_read_mem:bDriverStopped(%d) OR "
"bSurpriseRemoved(%d)", adapter->bDriverStopped,
adapter->bSurpriseRemoved));
return;
}
io_ops->_read_mem(adapter, addr, cnt, pmem);
}
void _rtw_write_mem23a(struct rtw_adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
{
struct _io_ops *io_ops = &adapter->io_ops;
io_ops->_write_mem(adapter, addr, cnt, pmem);
}
void _rtw_read_port23a(struct rtw_adapter *adapter, u32 addr, u32 cnt,
struct recv_buf *rbuf)
{
struct _io_ops *io_ops = &adapter->io_ops;
if ((adapter->bDriverStopped == true) ||
(adapter->bSurpriseRemoved == true)) {
RT_TRACE(_module_rtl871x_io_c_, _drv_info_,
("rtw_read_port:bDriverStopped(%d) OR "
"bSurpriseRemoved(%d)", adapter->bDriverStopped,
adapter->bSurpriseRemoved));
return;
}
io_ops->_read_port(adapter, addr, cnt, rbuf);
}
void _rtw_read_port23a_cancel(struct rtw_adapter *adapter)
{
void (*_read_port_cancel)(struct rtw_adapter *adapter);
struct _io_ops *io_ops = &adapter->io_ops;
_read_port_cancel = io_ops->_read_port_cancel;
if (_read_port_cancel)
_read_port_cancel(adapter);
}
u32 _rtw_write_port23a(struct rtw_adapter *adapter, u32 addr, u32 cnt,
struct xmit_buf *xbuf)
{
struct _io_ops *io_ops = &adapter->io_ops;
u32 ret = _SUCCESS;
ret = io_ops->_write_port(adapter, addr, cnt, xbuf);
return ret;
}
void _rtw_write_port23a_cancel(struct rtw_adapter *adapter)
{
void (*_write_port_cancel)(struct rtw_adapter *adapter);
struct _io_ops *io_ops = &adapter->io_ops;
_write_port_cancel = io_ops->_write_port_cancel;
if (_write_port_cancel)
_write_port_cancel(adapter);
}