1 /******************************************************************************
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
22 #define _OSDEP_SERVICE_C_
24 #include <osdep_service.h>
25 #include <osdep_intf.h>
26 #include <drv_types.h>
27 #include <recv_osdep.h>
28 #include <linux/vmalloc.h>
29 #include <rtw_ioctl_set.h>
32 * Translate the OS dependent @param error_code to OS independent RTW_STATUS_CODE
33 * @return: one of RTW_STATUS_CODE
35 inline int RTW_STATUS_CODE(int error_code)
42 u8 *_rtw_malloc(u32 sz)
44 return kmalloc(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
47 void *rtw_malloc2d(int h, int w, int size)
51 void **a = kzalloc(h*sizeof(void *) + h*w*size, GFP_KERNEL);
53 pr_info("%s: alloc memory fail!\n", __func__);
57 for (j = 0; j < h; j++)
58 a[j] = ((char *)(a+h)) + j*w*size;
63 u32 _rtw_down_sema(struct semaphore *sema)
65 if (down_interruptible(sema))
71 void _rtw_init_queue(struct __queue *pqueue)
73 INIT_LIST_HEAD(&(pqueue->queue));
74 spin_lock_init(&(pqueue->lock));
77 struct net_device *rtw_alloc_etherdev_with_old_priv(int sizeof_priv,
80 struct net_device *pnetdev;
81 struct rtw_netdev_priv_indicator *pnpi;
83 pnetdev = alloc_etherdev_mq(sizeof(struct rtw_netdev_priv_indicator), 4);
87 pnpi = netdev_priv(pnetdev);
88 pnpi->priv = old_priv;
89 pnpi->sizeof_priv = sizeof_priv;
95 void rtw_free_netdev(struct net_device *netdev)
97 struct rtw_netdev_priv_indicator *pnpi;
102 pnpi = netdev_priv(netdev);
114 u64 rtw_modular64(u64 x, u64 y)
119 void rtw_buf_free(u8 **buf, u32 *buf_len)
126 void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len)
132 if (!buf || !buf_len)
135 if (!src || !src_len)
139 dup = rtw_malloc(src_len);
142 memcpy(dup, src, dup_len);
148 /* replace buf with dup */