osdep_service_bsd.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2017 Realtek Corporation.
  4. *
  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.
  8. *
  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
  12. * more details.
  13. *
  14. *****************************************************************************/
  15. #ifndef __OSDEP_BSD_SERVICE_H_
  16. #define __OSDEP_BSD_SERVICE_H_
  17. #include <sys/cdefs.h>
  18. #include <sys/types.h>
  19. #include <sys/systm.h>
  20. #include <sys/param.h>
  21. #include <sys/sockio.h>
  22. #include <sys/sysctl.h>
  23. #include <sys/lock.h>
  24. #include <sys/mutex.h>
  25. #include <sys/mbuf.h>
  26. #include <sys/kernel.h>
  27. #include <sys/socket.h>
  28. #include <sys/systm.h>
  29. #include <sys/malloc.h>
  30. #include <sys/module.h>
  31. #include <sys/bus.h>
  32. #include <sys/endian.h>
  33. #include <sys/kdb.h>
  34. #include <sys/kthread.h>
  35. #include <sys/malloc.h>
  36. #include <sys/time.h>
  37. #include <machine/atomic.h>
  38. #include <machine/bus.h>
  39. #include <machine/resource.h>
  40. #include <sys/rman.h>
  41. #include <net/bpf.h>
  42. #include <net/if.h>
  43. #include <net/if_arp.h>
  44. #include <net/ethernet.h>
  45. #include <net/if_dl.h>
  46. #include <net/if_media.h>
  47. #include <net/if_types.h>
  48. #include <net/route.h>
  49. #include <netinet/in.h>
  50. #include <netinet/in_systm.h>
  51. #include <netinet/in_var.h>
  52. #include <netinet/if_ether.h>
  53. #include <if_ether.h>
  54. #include <net80211/ieee80211_var.h>
  55. #include <net80211/ieee80211_regdomain.h>
  56. #include <net80211/ieee80211_radiotap.h>
  57. #include <net80211/ieee80211_ratectl.h>
  58. #include <dev/usb/usb.h>
  59. #include <dev/usb/usbdi.h>
  60. #include "usbdevs.h"
  61. #define USB_DEBUG_VAR rum_debug
  62. #include <dev/usb/usb_debug.h>
  63. #if 1 //Baron porting from linux, it's all temp solution, needs to check again
  64. #include <sys/sema.h>
  65. #include <sys/pcpu.h> /* XXX for PCPU_GET */
  66. // typedef struct semaphore _sema;
  67. typedef struct sema _sema;
  68. // typedef spinlock_t _lock;
  69. typedef struct mtx _lock;
  70. typedef struct mtx _mutex;
  71. typedef struct rtw_timer_list _timer;
  72. struct list_head {
  73. struct list_head *next, *prev;
  74. };
  75. struct __queue {
  76. struct list_head queue;
  77. _lock lock;
  78. };
  79. typedef struct mbuf _pkt;
  80. typedef struct mbuf _buffer;
  81. typedef struct __queue _queue;
  82. typedef struct list_head _list;
  83. typedef int _OS_STATUS;
  84. //typedef u32 _irqL;
  85. typedef unsigned long _irqL;
  86. typedef struct ifnet * _nic_hdl;
  87. typedef pid_t _thread_hdl_;
  88. // typedef struct thread _thread_hdl_;
  89. typedef void thread_return;
  90. typedef void* thread_context;
  91. typedef void timer_hdl_return;
  92. typedef void* timer_hdl_context;
  93. typedef struct work_struct _workitem;
  94. #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
  95. /* emulate a modern version */
  96. #define LINUX_VERSION_CODE KERNEL_VERSION(2, 6, 35)
  97. #define WIRELESS_EXT -1
  98. #define HZ hz
  99. #define spin_lock_irqsave mtx_lock_irqsave
  100. #define spin_lock_bh mtx_lock_irqsave
  101. #define mtx_lock_irqsave(lock, x) mtx_lock(lock)//{local_irq_save((x)); mtx_lock_spin((lock));}
  102. //#define IFT_RTW 0xf9 //ifnet allocate type for RTW
  103. #define free_netdev if_free
  104. #define LIST_CONTAINOR(ptr, type, member) \
  105. ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
  106. #define container_of(p,t,n) (t*)((p)-&(((t*)0)->n))
  107. /*
  108. * Linux timers are emulated using FreeBSD callout functions
  109. * (and taskqueue functionality).
  110. *
  111. * Currently no timer stats functionality.
  112. *
  113. * See (linux_compat) processes.c
  114. *
  115. */
  116. struct rtw_timer_list {
  117. struct callout callout;
  118. void (*function)(void *);
  119. void *arg;
  120. };
  121. struct workqueue_struct;
  122. struct work_struct;
  123. typedef void (*work_func_t)(struct work_struct *work);
  124. /* Values for the state of an item of work (work_struct) */
  125. typedef enum work_state {
  126. WORK_STATE_UNSET = 0,
  127. WORK_STATE_CALLOUT_PENDING = 1,
  128. WORK_STATE_TASK_PENDING = 2,
  129. WORK_STATE_WORK_CANCELLED = 3
  130. } work_state_t;
  131. struct work_struct {
  132. struct task task; /* FreeBSD task */
  133. work_state_t state; /* the pending or otherwise state of work. */
  134. work_func_t func;
  135. };
  136. #define spin_unlock_irqrestore mtx_unlock_irqrestore
  137. #define spin_unlock_bh mtx_unlock_irqrestore
  138. #define mtx_unlock_irqrestore(lock,x) mtx_unlock(lock);
  139. extern void _rtw_spinlock_init(_lock *plock);
  140. //modify private structure to match freebsd
  141. #define BITS_PER_LONG 32
  142. union ktime {
  143. s64 tv64;
  144. #if BITS_PER_LONG != 64 && !defined(CONFIG_KTIME_SCALAR)
  145. struct {
  146. #ifdef __BIG_ENDIAN
  147. s32 sec, nsec;
  148. #else
  149. s32 nsec, sec;
  150. #endif
  151. } tv;
  152. #endif
  153. };
  154. #define kmemcheck_bitfield_begin(name)
  155. #define kmemcheck_bitfield_end(name)
  156. #define CHECKSUM_NONE 0
  157. typedef unsigned char *sk_buff_data_t;
  158. typedef union ktime ktime_t; /* Kill this */
  159. void rtw_mtx_lock(_lock *plock);
  160. void rtw_mtx_unlock(_lock *plock);
  161. /**
  162. * struct sk_buff - socket buffer
  163. * @next: Next buffer in list
  164. * @prev: Previous buffer in list
  165. * @sk: Socket we are owned by
  166. * @tstamp: Time we arrived
  167. * @dev: Device we arrived on/are leaving by
  168. * @transport_header: Transport layer header
  169. * @network_header: Network layer header
  170. * @mac_header: Link layer header
  171. * @_skb_refdst: destination entry (with norefcount bit)
  172. * @sp: the security path, used for xfrm
  173. * @cb: Control buffer. Free for use by every layer. Put private vars here
  174. * @len: Length of actual data
  175. * @data_len: Data length
  176. * @mac_len: Length of link layer header
  177. * @hdr_len: writable header length of cloned skb
  178. * @csum: Checksum (must include start/offset pair)
  179. * @csum_start: Offset from skb->head where checksumming should start
  180. * @csum_offset: Offset from csum_start where checksum should be stored
  181. * @local_df: allow local fragmentation
  182. * @cloned: Head may be cloned (check refcnt to be sure)
  183. * @nohdr: Payload reference only, must not modify header
  184. * @pkt_type: Packet class
  185. * @fclone: skbuff clone status
  186. * @ip_summed: Driver fed us an IP checksum
  187. * @priority: Packet queueing priority
  188. * @users: User count - see {datagram,tcp}.c
  189. * @protocol: Packet protocol from driver
  190. * @truesize: Buffer size
  191. * @head: Head of buffer
  192. * @data: Data head pointer
  193. * @tail: Tail pointer
  194. * @end: End pointer
  195. * @destructor: Destruct function
  196. * @mark: Generic packet mark
  197. * @nfct: Associated connection, if any
  198. * @ipvs_property: skbuff is owned by ipvs
  199. * @peeked: this packet has been seen already, so stats have been
  200. * done for it, don't do them again
  201. * @nf_trace: netfilter packet trace flag
  202. * @nfctinfo: Relationship of this skb to the connection
  203. * @nfct_reasm: netfilter conntrack re-assembly pointer
  204. * @nf_bridge: Saved data about a bridged frame - see br_netfilter.c
  205. * @skb_iif: ifindex of device we arrived on
  206. * @rxhash: the packet hash computed on receive
  207. * @queue_mapping: Queue mapping for multiqueue devices
  208. * @tc_index: Traffic control index
  209. * @tc_verd: traffic control verdict
  210. * @ndisc_nodetype: router type (from link layer)
  211. * @dma_cookie: a cookie to one of several possible DMA operations
  212. * done by skb DMA functions
  213. * @secmark: security marking
  214. * @vlan_tci: vlan tag control information
  215. */
  216. struct sk_buff {
  217. /* These two members must be first. */
  218. struct sk_buff *next;
  219. struct sk_buff *prev;
  220. ktime_t tstamp;
  221. struct sock *sk;
  222. //struct net_device *dev;
  223. struct ifnet *dev;
  224. /*
  225. * This is the control buffer. It is free to use for every
  226. * layer. Please put your private variables there. If you
  227. * want to keep them across layers you have to do a skb_clone()
  228. * first. This is owned by whoever has the skb queued ATM.
  229. */
  230. char cb[48] __aligned(8);
  231. unsigned long _skb_refdst;
  232. #ifdef CONFIG_XFRM
  233. struct sec_path *sp;
  234. #endif
  235. unsigned int len,
  236. data_len;
  237. u16 mac_len,
  238. hdr_len;
  239. union {
  240. u32 csum;
  241. struct {
  242. u16 csum_start;
  243. u16 csum_offset;
  244. }smbol2;
  245. }smbol1;
  246. u32 priority;
  247. kmemcheck_bitfield_begin(flags1);
  248. u8 local_df:1,
  249. cloned:1,
  250. ip_summed:2,
  251. nohdr:1,
  252. nfctinfo:3;
  253. u8 pkt_type:3,
  254. fclone:2,
  255. ipvs_property:1,
  256. peeked:1,
  257. nf_trace:1;
  258. kmemcheck_bitfield_end(flags1);
  259. u16 protocol;
  260. void (*destructor)(struct sk_buff *skb);
  261. #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
  262. struct nf_conntrack *nfct;
  263. struct sk_buff *nfct_reasm;
  264. #endif
  265. #ifdef CONFIG_BRIDGE_NETFILTER
  266. struct nf_bridge_info *nf_bridge;
  267. #endif
  268. int skb_iif;
  269. #ifdef CONFIG_NET_SCHED
  270. u16 tc_index; /* traffic control index */
  271. #ifdef CONFIG_NET_CLS_ACT
  272. u16 tc_verd; /* traffic control verdict */
  273. #endif
  274. #endif
  275. u32 rxhash;
  276. kmemcheck_bitfield_begin(flags2);
  277. u16 queue_mapping:16;
  278. #ifdef CONFIG_IPV6_NDISC_NODETYPE
  279. u8 ndisc_nodetype:2,
  280. deliver_no_wcard:1;
  281. #else
  282. u8 deliver_no_wcard:1;
  283. #endif
  284. kmemcheck_bitfield_end(flags2);
  285. /* 0/14 bit hole */
  286. #ifdef CONFIG_NET_DMA
  287. dma_cookie_t dma_cookie;
  288. #endif
  289. #ifdef CONFIG_NETWORK_SECMARK
  290. u32 secmark;
  291. #endif
  292. union {
  293. u32 mark;
  294. u32 dropcount;
  295. }symbol3;
  296. u16 vlan_tci;
  297. sk_buff_data_t transport_header;
  298. sk_buff_data_t network_header;
  299. sk_buff_data_t mac_header;
  300. /* These elements must be at the end, see alloc_skb() for details. */
  301. sk_buff_data_t tail;
  302. sk_buff_data_t end;
  303. unsigned char *head,
  304. *data;
  305. unsigned int truesize;
  306. atomic_t users;
  307. };
  308. struct sk_buff_head {
  309. /* These two members must be first. */
  310. struct sk_buff *next;
  311. struct sk_buff *prev;
  312. u32 qlen;
  313. _lock lock;
  314. };
  315. #define skb_tail_pointer(skb) skb->tail
  316. static inline unsigned char *skb_put(struct sk_buff *skb, unsigned int len)
  317. {
  318. unsigned char *tmp = skb_tail_pointer(skb);
  319. //SKB_LINEAR_ASSERT(skb);
  320. skb->tail += len;
  321. skb->len += len;
  322. return tmp;
  323. }
  324. static inline unsigned char *__skb_pull(struct sk_buff *skb, unsigned int len)
  325. {
  326. skb->len -= len;
  327. if(skb->len < skb->data_len)
  328. printf("%s(),%d,error!\n",__FUNCTION__,__LINE__);
  329. return skb->data += len;
  330. }
  331. static inline unsigned char *skb_pull(struct sk_buff *skb, unsigned int len)
  332. {
  333. #ifdef PLATFORM_FREEBSD
  334. return __skb_pull(skb, len);
  335. #else
  336. return unlikely(len > skb->len) ? NULL : __skb_pull(skb, len);
  337. #endif //PLATFORM_FREEBSD
  338. }
  339. static inline u32 skb_queue_len(const struct sk_buff_head *list_)
  340. {
  341. return list_->qlen;
  342. }
  343. static inline void __skb_insert(struct sk_buff *newsk,
  344. struct sk_buff *prev, struct sk_buff *next,
  345. struct sk_buff_head *list)
  346. {
  347. newsk->next = next;
  348. newsk->prev = prev;
  349. next->prev = prev->next = newsk;
  350. list->qlen++;
  351. }
  352. static inline void __skb_queue_before(struct sk_buff_head *list,
  353. struct sk_buff *next,
  354. struct sk_buff *newsk)
  355. {
  356. __skb_insert(newsk, next->prev, next, list);
  357. }
  358. static inline void skb_queue_tail(struct sk_buff_head *list,
  359. struct sk_buff *newsk)
  360. {
  361. mtx_lock(&list->lock);
  362. __skb_queue_before(list, (struct sk_buff *)list, newsk);
  363. mtx_unlock(&list->lock);
  364. }
  365. static inline struct sk_buff *skb_peek(struct sk_buff_head *list_)
  366. {
  367. struct sk_buff *list = ((struct sk_buff *)list_)->next;
  368. if (list == (struct sk_buff *)list_)
  369. list = NULL;
  370. return list;
  371. }
  372. static inline void __skb_unlink(struct sk_buff *skb, struct sk_buff_head *list)
  373. {
  374. struct sk_buff *next, *prev;
  375. list->qlen--;
  376. next = skb->next;
  377. prev = skb->prev;
  378. skb->next = skb->prev = NULL;
  379. next->prev = prev;
  380. prev->next = next;
  381. }
  382. static inline struct sk_buff *skb_dequeue(struct sk_buff_head *list)
  383. {
  384. mtx_lock(&list->lock);
  385. struct sk_buff *skb = skb_peek(list);
  386. if (skb)
  387. __skb_unlink(skb, list);
  388. mtx_unlock(&list->lock);
  389. return skb;
  390. }
  391. static inline void skb_reserve(struct sk_buff *skb, int len)
  392. {
  393. skb->data += len;
  394. skb->tail += len;
  395. }
  396. static inline void __skb_queue_head_init(struct sk_buff_head *list)
  397. {
  398. list->prev = list->next = (struct sk_buff *)list;
  399. list->qlen = 0;
  400. }
  401. /*
  402. * This function creates a split out lock class for each invocation;
  403. * this is needed for now since a whole lot of users of the skb-queue
  404. * infrastructure in drivers have different locking usage (in hardirq)
  405. * than the networking core (in softirq only). In the long run either the
  406. * network layer or drivers should need annotation to consolidate the
  407. * main types of usage into 3 classes.
  408. */
  409. static inline void skb_queue_head_init(struct sk_buff_head *list)
  410. {
  411. _rtw_spinlock_init(&list->lock);
  412. __skb_queue_head_init(list);
  413. }
  414. unsigned long copy_from_user(void *to, const void *from, unsigned long n);
  415. unsigned long copy_to_user(void *to, const void *from, unsigned long n);
  416. struct sk_buff * dev_alloc_skb(unsigned int size);
  417. struct sk_buff *skb_clone(const struct sk_buff *skb);
  418. void dev_kfree_skb_any(struct sk_buff *skb);
  419. #endif //Baron porting from linux, it's all temp solution, needs to check again
  420. #if 1 // kenny add Linux compatibility code for Linux USB driver
  421. #include <dev/usb/usb_compat_linux.h>
  422. #define __init // __attribute ((constructor))
  423. #define __exit // __attribute ((destructor))
  424. /*
  425. * Definitions for module_init and module_exit macros.
  426. *
  427. * These macros will use the SYSINIT framework to call a specified
  428. * function (with no arguments) on module loading or unloading.
  429. *
  430. */
  431. void module_init_exit_wrapper(void *arg);
  432. #define module_init(initfn) \
  433. SYSINIT(mod_init_ ## initfn, \
  434. SI_SUB_KLD, SI_ORDER_FIRST, \
  435. module_init_exit_wrapper, initfn)
  436. #define module_exit(exitfn) \
  437. SYSUNINIT(mod_exit_ ## exitfn, \
  438. SI_SUB_KLD, SI_ORDER_ANY, \
  439. module_init_exit_wrapper, exitfn)
  440. /*
  441. * The usb_register and usb_deregister functions are used to register
  442. * usb drivers with the usb subsystem.
  443. */
  444. int usb_register(struct usb_driver *driver);
  445. int usb_deregister(struct usb_driver *driver);
  446. /*
  447. * usb_get_dev and usb_put_dev - increment/decrement the reference count
  448. * of the usb device structure.
  449. *
  450. * Original body of usb_get_dev:
  451. *
  452. * if (dev)
  453. * get_device(&dev->dev);
  454. * return dev;
  455. *
  456. * Reference counts are not currently used in this compatibility
  457. * layer. So these functions will do nothing.
  458. */
  459. static inline struct usb_device *
  460. usb_get_dev(struct usb_device *dev)
  461. {
  462. return dev;
  463. }
  464. static inline void
  465. usb_put_dev(struct usb_device *dev)
  466. {
  467. return;
  468. }
  469. // rtw_usb_compat_linux
  470. int rtw_usb_submit_urb(struct urb *urb, uint16_t mem_flags);
  471. int rtw_usb_unlink_urb(struct urb *urb);
  472. int rtw_usb_clear_halt(struct usb_device *dev, struct usb_host_endpoint *uhe);
  473. int rtw_usb_control_msg(struct usb_device *dev, struct usb_host_endpoint *uhe,
  474. uint8_t request, uint8_t requesttype,
  475. uint16_t value, uint16_t index, void *data,
  476. uint16_t size, usb_timeout_t timeout);
  477. int rtw_usb_set_interface(struct usb_device *dev, uint8_t iface_no, uint8_t alt_index);
  478. int rtw_usb_setup_endpoint(struct usb_device *dev,
  479. struct usb_host_endpoint *uhe, usb_size_t bufsize);
  480. struct urb *rtw_usb_alloc_urb(uint16_t iso_packets, uint16_t mem_flags);
  481. struct usb_host_endpoint *rtw_usb_find_host_endpoint(struct usb_device *dev, uint8_t type, uint8_t ep);
  482. struct usb_host_interface *rtw_usb_altnum_to_altsetting(const struct usb_interface *intf, uint8_t alt_index);
  483. struct usb_interface *rtw_usb_ifnum_to_if(struct usb_device *dev, uint8_t iface_no);
  484. void *rtw_usbd_get_intfdata(struct usb_interface *intf);
  485. void rtw_usb_linux_register(void *arg);
  486. void rtw_usb_linux_deregister(void *arg);
  487. void rtw_usb_linux_free_device(struct usb_device *dev);
  488. void rtw_usb_free_urb(struct urb *urb);
  489. void rtw_usb_init_urb(struct urb *urb);
  490. void rtw_usb_kill_urb(struct urb *urb);
  491. void rtw_usb_set_intfdata(struct usb_interface *intf, void *data);
  492. void rtw_usb_fill_bulk_urb(struct urb *urb, struct usb_device *udev,
  493. struct usb_host_endpoint *uhe, void *buf,
  494. int length, usb_complete_t callback, void *arg);
  495. int rtw_usb_bulk_msg(struct usb_device *udev, struct usb_host_endpoint *uhe,
  496. void *data, int len, uint16_t *pactlen, usb_timeout_t timeout);
  497. void *usb_get_intfdata(struct usb_interface *intf);
  498. int usb_linux_init_endpoints(struct usb_device *udev);
  499. typedef struct urb * PURB;
  500. typedef unsigned gfp_t;
  501. #define __GFP_WAIT ((gfp_t)0x10u) /* Can wait and reschedule? */
  502. #define __GFP_HIGH ((gfp_t)0x20u) /* Should access emergency pools? */
  503. #define __GFP_IO ((gfp_t)0x40u) /* Can start physical IO? */
  504. #define __GFP_FS ((gfp_t)0x80u) /* Can call down to low-level FS? */
  505. #define __GFP_COLD ((gfp_t)0x100u) /* Cache-cold page required */
  506. #define __GFP_NOWARN ((gfp_t)0x200u) /* Suppress page allocation failure warning */
  507. #define __GFP_REPEAT ((gfp_t)0x400u) /* Retry the allocation. Might fail */
  508. #define __GFP_NOFAIL ((gfp_t)0x800u) /* Retry for ever. Cannot fail */
  509. #define __GFP_NORETRY ((gfp_t)0x1000u)/* Do not retry. Might fail */
  510. #define __GFP_NO_GROW ((gfp_t)0x2000u)/* Slab internal usage */
  511. #define __GFP_COMP ((gfp_t)0x4000u)/* Add compound page metadata */
  512. #define __GFP_ZERO ((gfp_t)0x8000u)/* Return zeroed page on success */
  513. #define __GFP_NOMEMALLOC ((gfp_t)0x10000u) /* Don't use emergency reserves */
  514. #define __GFP_HARDWALL ((gfp_t)0x20000u) /* Enforce hardwall cpuset memory allocs */
  515. /* This equals 0, but use constants in case they ever change */
  516. #define GFP_NOWAIT (GFP_ATOMIC & ~__GFP_HIGH)
  517. /* GFP_ATOMIC means both !wait (__GFP_WAIT not set) and use emergency pool */
  518. #define GFP_ATOMIC (__GFP_HIGH)
  519. #define GFP_NOIO (__GFP_WAIT)
  520. #define GFP_NOFS (__GFP_WAIT | __GFP_IO)
  521. #define GFP_KERNEL (__GFP_WAIT | __GFP_IO | __GFP_FS)
  522. #define GFP_USER (__GFP_WAIT | __GFP_IO | __GFP_FS | __GFP_HARDWALL)
  523. #define GFP_HIGHUSER (__GFP_WAIT | __GFP_IO | __GFP_FS | __GFP_HARDWALL | \
  524. __GFP_HIGHMEM)
  525. #endif // kenny add Linux compatibility code for Linux USB
  526. __inline static _list *get_next(_list *list)
  527. {
  528. return list->next;
  529. }
  530. __inline static _list *get_list_head(_queue *queue)
  531. {
  532. return (&(queue->queue));
  533. }
  534. #define LIST_CONTAINOR(ptr, type, member) \
  535. ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
  536. __inline static void _enter_critical(_lock *plock, _irqL *pirqL)
  537. {
  538. spin_lock_irqsave(plock, *pirqL);
  539. }
  540. __inline static void _exit_critical(_lock *plock, _irqL *pirqL)
  541. {
  542. spin_unlock_irqrestore(plock, *pirqL);
  543. }
  544. __inline static void _enter_critical_ex(_lock *plock, _irqL *pirqL)
  545. {
  546. spin_lock_irqsave(plock, *pirqL);
  547. }
  548. __inline static void _exit_critical_ex(_lock *plock, _irqL *pirqL)
  549. {
  550. spin_unlock_irqrestore(plock, *pirqL);
  551. }
  552. __inline static void _enter_critical_bh(_lock *plock, _irqL *pirqL)
  553. {
  554. spin_lock_bh(plock, *pirqL);
  555. }
  556. __inline static void _exit_critical_bh(_lock *plock, _irqL *pirqL)
  557. {
  558. spin_unlock_bh(plock, *pirqL);
  559. }
  560. __inline static void _enter_critical_mutex(_mutex *pmutex, _irqL *pirqL)
  561. {
  562. mtx_lock(pmutex);
  563. }
  564. __inline static void _exit_critical_mutex(_mutex *pmutex, _irqL *pirqL)
  565. {
  566. mtx_unlock(pmutex);
  567. }
  568. static inline void __list_del(struct list_head * prev, struct list_head * next)
  569. {
  570. next->prev = prev;
  571. prev->next = next;
  572. }
  573. static inline void INIT_LIST_HEAD(struct list_head *list)
  574. {
  575. list->next = list;
  576. list->prev = list;
  577. }
  578. __inline static void rtw_list_delete(_list *plist)
  579. {
  580. __list_del(plist->prev, plist->next);
  581. INIT_LIST_HEAD(plist);
  582. }
  583. static inline void timer_hdl(void *ctx)
  584. {
  585. _timer *timer = (_timer *)ctx;
  586. rtw_mtx_lock(NULL);
  587. if (callout_pending(&timer->callout)) {
  588. /* callout was reset */
  589. rtw_mtx_unlock(NULL);
  590. return;
  591. }
  592. if (!callout_active(&timer->callout)) {
  593. /* callout was stopped */
  594. rtw_mtx_unlock(NULL);
  595. return;
  596. }
  597. callout_deactivate(&timer->callout);
  598. timer->function(timer->arg);
  599. rtw_mtx_unlock(NULL);
  600. }
  601. static inline void _init_timer(_timer *ptimer, _nic_hdl padapter, void *pfunc, void *cntx)
  602. {
  603. ptimer->function = pfunc;
  604. ptimer->arg = cntx;
  605. callout_init(&ptimer->callout, CALLOUT_MPSAFE);
  606. }
  607. __inline static void _set_timer(_timer *ptimer,u32 delay_time)
  608. {
  609. if (ptimer->function && ptimer->arg) {
  610. rtw_mtx_lock(NULL);
  611. callout_reset(&ptimer->callout, delay_time, timer_hdl, ptimer);
  612. rtw_mtx_unlock(NULL);
  613. }
  614. }
  615. __inline static void _cancel_timer(_timer *ptimer,u8 *bcancelled)
  616. {
  617. rtw_mtx_lock(NULL);
  618. callout_drain(&ptimer->callout);
  619. rtw_mtx_unlock(NULL);
  620. *bcancelled = 1; /* assume an pending timer to be canceled */
  621. }
  622. __inline static void _init_workitem(_workitem *pwork, void *pfunc, PVOID cntx)
  623. {
  624. printf("%s Not implement yet! \n",__FUNCTION__);
  625. }
  626. __inline static void _set_workitem(_workitem *pwork)
  627. {
  628. printf("%s Not implement yet! \n",__FUNCTION__);
  629. // schedule_work(pwork);
  630. }
  631. //
  632. // Global Mutex: can only be used at PASSIVE level.
  633. //
  634. #define ACQUIRE_GLOBAL_MUTEX(_MutexCounter) \
  635. { \
  636. }
  637. #define RELEASE_GLOBAL_MUTEX(_MutexCounter) \
  638. { \
  639. }
  640. #define ATOMIC_INIT(i) { (i) }
  641. static __inline void thread_enter(char *name);
  642. //Atomic integer operations
  643. typedef uint32_t ATOMIC_T ;
  644. #define rtw_netdev_priv(netdev) (((struct ifnet *)netdev)->if_softc)
  645. #define rtw_free_netdev(netdev) if_free((netdev))
  646. #define NDEV_FMT "%s"
  647. #define NDEV_ARG(ndev) ""
  648. #define ADPT_FMT "%s"
  649. #define ADPT_ARG(adapter) ""
  650. #define FUNC_NDEV_FMT "%s"
  651. #define FUNC_NDEV_ARG(ndev) __func__
  652. #define FUNC_ADPT_FMT "%s"
  653. #define FUNC_ADPT_ARG(adapter) __func__
  654. #define STRUCT_PACKED
  655. #endif