osdep_service_bsd.h 22 KB

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