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)
46 pbuf = kmalloc(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
50 void *rtw_malloc2d(int h, int w, int size)
54 void **a = kzalloc(h*sizeof(void *) + h*w*size, GFP_KERNEL);
56 pr_info("%s: alloc memory fail!\n", __func__);
60 for (j = 0; j < h; j++)
61 a[j] = ((char *)(a+h)) + j*w*size;
66 u32 _rtw_down_sema(struct semaphore *sema)
68 if (down_interruptible(sema))
74 void _rtw_init_queue(struct __queue *pqueue)
76 INIT_LIST_HEAD(&(pqueue->queue));
77 spin_lock_init(&(pqueue->lock));
80 /* the input parameter start must be in jiffies */
81 inline s32 rtw_get_passing_time_ms(u32 start)
83 return jiffies_to_msecs(jiffies-start);
86 struct net_device *rtw_alloc_etherdev_with_old_priv(int sizeof_priv,
89 struct net_device *pnetdev;
90 struct rtw_netdev_priv_indicator *pnpi;
92 pnetdev = alloc_etherdev_mq(sizeof(struct rtw_netdev_priv_indicator), 4);
96 pnpi = netdev_priv(pnetdev);
97 pnpi->priv = old_priv;
98 pnpi->sizeof_priv = sizeof_priv;
104 void rtw_free_netdev(struct net_device *netdev)
106 struct rtw_netdev_priv_indicator *pnpi;
111 pnpi = netdev_priv(netdev);
123 u64 rtw_modular64(u64 x, u64 y)
128 void rtw_buf_free(u8 **buf, u32 *buf_len)
135 void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len)
141 if (!buf || !buf_len)
144 if (!src || !src_len)
148 dup = rtw_malloc(src_len);
151 memcpy(dup, src, dup_len);
157 /* replace buf with dup */