rsi_common.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * Copyright (c) 2014 Redpine Signals Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef __RSI_COMMON_H__
  17. #define __RSI_COMMON_H__
  18. #include <linux/kthread.h>
  19. #define EVENT_WAIT_FOREVER 0
  20. #define TA_LOAD_ADDRESS 0x00
  21. #define FIRMWARE_RSI9113 "rsi_91x.fw"
  22. #define QUEUE_NOT_FULL 1
  23. #define QUEUE_FULL 0
  24. static inline int rsi_init_event(struct rsi_event *pevent)
  25. {
  26. atomic_set(&pevent->event_condition, 1);
  27. init_waitqueue_head(&pevent->event_queue);
  28. return 0;
  29. }
  30. static inline int rsi_wait_event(struct rsi_event *event, u32 timeout)
  31. {
  32. int status = 0;
  33. if (!timeout)
  34. status = wait_event_interruptible(event->event_queue,
  35. (atomic_read(&event->event_condition) == 0));
  36. else
  37. status = wait_event_interruptible_timeout(event->event_queue,
  38. (atomic_read(&event->event_condition) == 0),
  39. timeout);
  40. return status;
  41. }
  42. static inline void rsi_set_event(struct rsi_event *event)
  43. {
  44. atomic_set(&event->event_condition, 0);
  45. wake_up_interruptible(&event->event_queue);
  46. }
  47. static inline void rsi_reset_event(struct rsi_event *event)
  48. {
  49. atomic_set(&event->event_condition, 1);
  50. }
  51. static inline int rsi_create_kthread(struct rsi_common *common,
  52. struct rsi_thread *thread,
  53. void *func_ptr,
  54. u8 *name)
  55. {
  56. init_completion(&thread->completion);
  57. thread->task = kthread_run(func_ptr, common, "%s", name);
  58. if (IS_ERR(thread->task))
  59. return (int)PTR_ERR(thread->task);
  60. return 0;
  61. }
  62. static inline int rsi_kill_thread(struct rsi_thread *handle)
  63. {
  64. atomic_inc(&handle->thread_done);
  65. rsi_set_event(&handle->event);
  66. return kthread_stop(handle->task);
  67. }
  68. void rsi_mac80211_detach(struct rsi_hw *hw);
  69. u16 rsi_get_connected_channel(struct rsi_hw *adapter);
  70. struct rsi_hw *rsi_91x_init(void);
  71. void rsi_91x_deinit(struct rsi_hw *adapter);
  72. int rsi_read_pkt(struct rsi_common *common, s32 rcv_pkt_len);
  73. #endif