2013-05-08 21:45:39 +00:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
|
2013-05-19 04:28:07 +00:00
|
|
|
*
|
2013-05-08 21:45:39 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
|
|
|
|
*
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#define _OSDEP_SERVICE_C_
|
|
|
|
|
|
|
|
#include <osdep_service.h>
|
2014-11-16 00:18:30 +00:00
|
|
|
#include <osdep_intf.h>
|
2013-05-08 21:45:39 +00:00
|
|
|
#include <drv_types.h>
|
|
|
|
#include <recv_osdep.h>
|
|
|
|
#include <linux/vmalloc.h>
|
2013-06-03 19:52:18 +00:00
|
|
|
#include <rtw_ioctl_set.h>
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Translate the OS dependent @param error_code to OS independent RTW_STATUS_CODE
|
|
|
|
* @return: one of RTW_STATUS_CODE
|
|
|
|
*/
|
2013-08-10 17:57:27 +00:00
|
|
|
inline int RTW_STATUS_CODE(int error_code)
|
|
|
|
{
|
|
|
|
if (error_code >= 0)
|
2013-05-08 21:45:39 +00:00
|
|
|
return _SUCCESS;
|
2013-08-10 17:57:27 +00:00
|
|
|
return _FAIL;
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
2013-08-10 17:57:27 +00:00
|
|
|
u8 *_rtw_malloc(u32 sz)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-08-10 17:57:27 +00:00
|
|
|
u8 *pbuf = NULL;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-08-10 17:57:27 +00:00
|
|
|
pbuf = kmalloc(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
|
2013-05-19 04:28:07 +00:00
|
|
|
return pbuf;
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
2013-08-10 17:57:27 +00:00
|
|
|
void *rtw_malloc2d(int h, int w, int size)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
2014-11-28 17:08:37 +00:00
|
|
|
void **a = (void **)kzalloc(h*sizeof(void *) + h*w*size, GFP_KERNEL);
|
2013-05-26 02:17:38 +00:00
|
|
|
if (a == NULL) {
|
|
|
|
pr_info("%s: alloc memory fail!\n", __func__);
|
2013-05-08 21:45:39 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-08-10 17:57:27 +00:00
|
|
|
for (j = 0; j < h; j++)
|
2013-05-08 21:45:39 +00:00
|
|
|
a[j] = ((char *)(a+h)) + j*w*size;
|
|
|
|
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-07-24 19:17:51 +00:00
|
|
|
u32 _rtw_down_sema(struct semaphore *sema)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
if (down_interruptible(sema))
|
|
|
|
return _FAIL;
|
|
|
|
else
|
|
|
|
return _SUCCESS;
|
|
|
|
}
|
|
|
|
|
2013-07-24 22:55:38 +00:00
|
|
|
void _rtw_init_queue(struct __queue *pqueue)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2014-11-16 00:18:30 +00:00
|
|
|
INIT_LIST_HEAD(&(pqueue->queue));
|
|
|
|
spin_lock_init(&(pqueue->lock));
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
2014-11-16 00:18:30 +00:00
|
|
|
/* the input parameter start must be in jiffies */
|
2013-05-08 21:45:39 +00:00
|
|
|
inline s32 rtw_get_passing_time_ms(u32 start)
|
|
|
|
{
|
2014-11-16 00:18:30 +00:00
|
|
|
return jiffies_to_msecs(jiffies-start);
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
2013-08-10 17:57:27 +00:00
|
|
|
struct net_device *rtw_alloc_etherdev_with_old_priv(int sizeof_priv,
|
|
|
|
void *old_priv)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
struct net_device *pnetdev;
|
|
|
|
struct rtw_netdev_priv_indicator *pnpi;
|
|
|
|
|
2013-10-19 17:45:47 +00:00
|
|
|
pnetdev = alloc_etherdev_mq(sizeof(struct rtw_netdev_priv_indicator), 4);
|
2013-05-08 21:45:39 +00:00
|
|
|
if (!pnetdev)
|
|
|
|
goto RETURN;
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
pnpi = netdev_priv(pnetdev);
|
2013-08-10 17:57:27 +00:00
|
|
|
pnpi->priv = old_priv;
|
|
|
|
pnpi->sizeof_priv = sizeof_priv;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
RETURN:
|
|
|
|
return pnetdev;
|
|
|
|
}
|
|
|
|
|
2013-08-10 17:57:27 +00:00
|
|
|
void rtw_free_netdev(struct net_device *netdev)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
struct rtw_netdev_priv_indicator *pnpi;
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-05-09 04:04:25 +00:00
|
|
|
if (!netdev)
|
2013-05-08 21:45:39 +00:00
|
|
|
goto RETURN;
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
pnpi = netdev_priv(netdev);
|
|
|
|
|
2013-05-09 04:04:25 +00:00
|
|
|
if (!pnpi->priv)
|
2013-05-08 21:45:39 +00:00
|
|
|
goto RETURN;
|
|
|
|
|
2014-11-16 00:18:30 +00:00
|
|
|
vfree(pnpi->priv);
|
2013-05-08 21:45:39 +00:00
|
|
|
free_netdev(netdev);
|
|
|
|
|
|
|
|
RETURN:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 rtw_modular64(u64 x, u64 y)
|
|
|
|
{
|
|
|
|
return do_div(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rtw_buf_free(u8 **buf, u32 *buf_len)
|
|
|
|
{
|
2013-10-19 17:45:47 +00:00
|
|
|
*buf_len = 0;
|
|
|
|
kfree(*buf);
|
|
|
|
*buf = NULL;
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len)
|
|
|
|
{
|
|
|
|
u32 ori_len = 0, dup_len = 0;
|
|
|
|
u8 *ori = NULL;
|
|
|
|
u8 *dup = NULL;
|
|
|
|
|
|
|
|
if (!buf || !buf_len)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!src || !src_len)
|
|
|
|
goto keep_ori;
|
|
|
|
|
|
|
|
/* duplicate src */
|
|
|
|
dup = rtw_malloc(src_len);
|
|
|
|
if (dup) {
|
|
|
|
dup_len = src_len;
|
2013-10-19 17:45:47 +00:00
|
|
|
memcpy(dup, src, dup_len);
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
keep_ori:
|
|
|
|
ori = *buf;
|
|
|
|
ori_len = *buf_len;
|
|
|
|
|
|
|
|
/* replace buf with dup */
|
|
|
|
*buf_len = 0;
|
|
|
|
*buf = dup;
|
|
|
|
*buf_len = dup_len;
|
|
|
|
|
|
|
|
/* free ori */
|
2013-10-19 17:45:47 +00:00
|
|
|
kfree(ori);
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|