2022-06-08 23:46:35 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
|
|
|
|
/* Copyright(c) 2007 - 2011 Realtek Corporation. */
|
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
#ifndef __OSDEP_SERVICE_H_
|
|
|
|
#define __OSDEP_SERVICE_H_
|
|
|
|
|
2017-03-08 16:17:24 +00:00
|
|
|
#include <linux/sched/signal.h>
|
2022-06-08 23:46:35 +00:00
|
|
|
#include "basic_types.h"
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#define _FAIL 0
|
|
|
|
#define _SUCCESS 1
|
|
|
|
#define RTW_RX_HANDLED 2
|
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/compiler.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kref.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/circ_buf.h>
|
2013-08-15 03:03:17 +00:00
|
|
|
#include <linux/uaccess.h>
|
2013-05-26 03:02:10 +00:00
|
|
|
#include <asm/byteorder.h>
|
2014-02-12 17:05:30 +00:00
|
|
|
#include <asm/atomic.h>
|
2013-08-15 03:03:17 +00:00
|
|
|
#include <linux/io.h>
|
2013-05-26 03:02:10 +00:00
|
|
|
#include <linux/semaphore.h>
|
|
|
|
#include <linux/sem.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/wireless.h>
|
|
|
|
#include <net/iw_handler.h>
|
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <linux/rtnetlink.h>
|
|
|
|
#include <linux/delay.h>
|
2013-08-12 04:36:23 +00:00
|
|
|
#include <linux/proc_fs.h> /* Necessary because we use the proc fs */
|
|
|
|
#include <linux/interrupt.h> /* for struct tasklet_struct */
|
2013-05-26 03:02:10 +00:00
|
|
|
#include <linux/ip.h>
|
|
|
|
#include <linux/kthread.h>
|
2022-06-08 23:46:35 +00:00
|
|
|
#include <linux/vmalloc.h>
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-05-26 03:02:10 +00:00
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <linux/usb/ch9.h>
|
2013-10-19 17:45:47 +00:00
|
|
|
|
2013-08-15 03:03:17 +00:00
|
|
|
struct __queue {
|
|
|
|
struct list_head queue;
|
|
|
|
spinlock_t lock;
|
|
|
|
};
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-08-15 03:03:17 +00:00
|
|
|
static inline struct list_head *get_list_head(struct __queue *queue)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
return (&(queue->queue));
|
|
|
|
}
|
|
|
|
|
2013-08-15 03:03:17 +00:00
|
|
|
static inline void _set_timer(struct timer_list *ptimer,u32 delay_time)
|
2013-05-19 04:28:07 +00:00
|
|
|
{
|
2022-06-08 23:46:35 +00:00
|
|
|
mod_timer(ptimer, jiffies + msecs_to_jiffies(delay_time));
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int rtw_netif_queue_stopped(struct net_device *pnetdev)
|
|
|
|
{
|
2013-10-19 17:45:47 +00:00
|
|
|
return netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 0)) &&
|
2013-05-08 21:45:39 +00:00
|
|
|
netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 1)) &&
|
|
|
|
netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 2)) &&
|
2013-10-19 17:45:47 +00:00
|
|
|
netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 3));
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern int RTW_STATUS_CODE(int error_code);
|
|
|
|
|
2013-10-19 17:45:47 +00:00
|
|
|
void *rtw_malloc2d(int h, int w, int size);
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2022-06-08 23:46:35 +00:00
|
|
|
#define rtw_init_queue(q) \
|
|
|
|
do { \
|
|
|
|
INIT_LIST_HEAD(&((q)->queue)); \
|
|
|
|
spin_lock_init(&((q)->lock)); \
|
|
|
|
} while (0)
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-10-19 17:45:47 +00:00
|
|
|
u32 rtw_systime_to_ms(u32 systime);
|
|
|
|
u32 rtw_ms_to_systime(u32 ms);
|
|
|
|
s32 rtw_get_passing_time_ms(u32 start);
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-10-19 17:45:47 +00:00
|
|
|
void rtw_usleep_os(int us);
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-08-15 03:03:17 +00:00
|
|
|
static inline unsigned char _cancel_timer_ex(struct timer_list *ptimer)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
return del_timer_sync(ptimer);
|
|
|
|
}
|
|
|
|
|
2013-08-15 03:03:17 +00:00
|
|
|
static inline void flush_signals_thread(void)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-05-19 04:28:07 +00:00
|
|
|
if (signal_pending (current))
|
2013-05-08 21:45:39 +00:00
|
|
|
flush_signals(current);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define _RND(sz, r) ((((sz)+((r)-1))/(r))*(r))
|
|
|
|
#define RND4(x) (((x >> 2) + (((x & 3) == 0) ? 0: 1)) << 2)
|
|
|
|
|
2013-08-15 03:03:17 +00:00
|
|
|
static inline u32 _RND4(u32 sz)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
val = ((sz >> 2) + ((sz & 3) ? 1: 0)) << 2;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2013-08-15 03:03:17 +00:00
|
|
|
static inline u32 _RND8(u32 sz)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
val = ((sz >> 3) + ((sz & 7) ? 1: 0)) << 3;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2013-08-15 03:03:17 +00:00
|
|
|
static inline u32 _RND128(u32 sz)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
val = ((sz >> 7) + ((sz & 127) ? 1: 0)) << 7;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2013-08-15 03:03:17 +00:00
|
|
|
static inline u32 _RND256(u32 sz)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
val = ((sz >> 8) + ((sz & 255) ? 1: 0)) << 8;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2013-08-15 03:03:17 +00:00
|
|
|
static inline u32 _RND512(u32 sz)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
val = ((sz >> 9) + ((sz & 511) ? 1: 0)) << 9;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct rtw_netdev_priv_indicator {
|
|
|
|
void *priv;
|
|
|
|
u32 sizeof_priv;
|
|
|
|
};
|
2013-08-15 03:03:17 +00:00
|
|
|
struct net_device *rtw_alloc_etherdev_with_old_priv(int sizeof_priv,
|
|
|
|
void *old_priv);
|
|
|
|
struct net_device *rtw_alloc_etherdev(int sizeof_priv);
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-08-15 03:03:17 +00:00
|
|
|
#define rtw_netdev_priv(netdev) \
|
|
|
|
(((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv)
|
|
|
|
void rtw_free_netdev(struct net_device *netdev);
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#define NDEV_FMT "%s"
|
|
|
|
#define NDEV_ARG(ndev) ndev->name
|
|
|
|
#define ADPT_FMT "%s"
|
|
|
|
#define ADPT_ARG(adapter) adapter->pnetdev->name
|
|
|
|
#define FUNC_NDEV_FMT "%s(%s)"
|
|
|
|
#define FUNC_NDEV_ARG(ndev) __func__, ndev->name
|
|
|
|
#define FUNC_ADPT_FMT "%s(%s)"
|
|
|
|
#define FUNC_ADPT_ARG(adapter) __func__, adapter->pnetdev->name
|
|
|
|
|
|
|
|
#define rtw_signal_process(pid, sig) kill_pid(find_vpid((pid)),(sig), 1)
|
|
|
|
|
|
|
|
/* Macros for handling unaligned memory accesses */
|
|
|
|
|
|
|
|
#define RTW_GET_BE16(a) ((u16) (((a)[0] << 8) | (a)[1]))
|
|
|
|
#define RTW_PUT_BE16(a, val) \
|
|
|
|
do { \
|
|
|
|
(a)[0] = ((u16) (val)) >> 8; \
|
|
|
|
(a)[1] = ((u16) (val)) & 0xff; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define RTW_PUT_LE16(a, val) \
|
|
|
|
do { \
|
|
|
|
(a)[1] = ((u16) (val)) >> 8; \
|
|
|
|
(a)[0] = ((u16) (val)) & 0xff; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define RTW_GET_BE24(a) ((((u32) (a)[0]) << 16) | (((u32) (a)[1]) << 8) | \
|
2013-05-19 04:28:07 +00:00
|
|
|
((u32) (a)[2]))
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#define RTW_PUT_BE32(a, val) \
|
|
|
|
do { \
|
|
|
|
(a)[0] = (u8) ((((u32) (val)) >> 24) & 0xff); \
|
|
|
|
(a)[1] = (u8) ((((u32) (val)) >> 16) & 0xff); \
|
|
|
|
(a)[2] = (u8) ((((u32) (val)) >> 8) & 0xff); \
|
|
|
|
(a)[3] = (u8) (((u32) (val)) & 0xff); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len);
|
|
|
|
|
|
|
|
struct rtw_cbuf {
|
|
|
|
u32 write;
|
|
|
|
u32 read;
|
|
|
|
u32 size;
|
2022-06-08 23:46:35 +00:00
|
|
|
void *bufs[];
|
2013-05-08 21:45:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bool rtw_cbuf_empty(struct rtw_cbuf *cbuf);
|
|
|
|
void *rtw_cbuf_pop(struct rtw_cbuf *cbuf);
|
|
|
|
struct rtw_cbuf *rtw_cbuf_alloc(u32 size);
|
2013-10-19 17:45:47 +00:00
|
|
|
int wifirate2_ratetbl_inx(unsigned char rate);
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#endif
|