osdep_service_bsd.h 22 KB

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