i1480-wlp.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Intel 1480 Wireless UWB Link
  3. * WLP specific definitions
  4. *
  5. *
  6. * Copyright (C) 2005-2006 Intel Corporation
  7. * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License version
  11. * 2 as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  21. * 02110-1301, USA.
  22. *
  23. *
  24. * FIXME: docs
  25. */
  26. #ifndef __i1480_wlp_h__
  27. #define __i1480_wlp_h__
  28. #include <linux/spinlock.h>
  29. #include <linux/list.h>
  30. #include <linux/uwb.h>
  31. #include <linux/if_ether.h>
  32. #include <asm/byteorder.h>
  33. /* New simplified header format? */
  34. #undef WLP_HDR_FMT_2 /* FIXME: rename */
  35. /**
  36. * Values of the Delivery ID & Type field when PCA or DRP
  37. *
  38. * The Delivery ID & Type field in the WLP TX header indicates whether
  39. * the frame is PCA or DRP. This is done based on the high level bit of
  40. * this field.
  41. * We use this constant to test if the traffic is PCA or DRP as follows:
  42. * if (wlp_tx_hdr_delivery_id_type(wlp_tx_hdr) & WLP_DRP)
  43. * this is DRP traffic
  44. * else
  45. * this is PCA traffic
  46. */
  47. enum deliver_id_type_bit {
  48. WLP_DRP = 8,
  49. };
  50. /**
  51. * WLP TX header
  52. *
  53. * Indicates UWB/WLP-specific transmission parameters for a network
  54. * packet.
  55. */
  56. struct wlp_tx_hdr {
  57. /* dword 0 */
  58. struct uwb_dev_addr dstaddr;
  59. u8 key_index;
  60. u8 mac_params;
  61. /* dword 1 */
  62. u8 phy_params;
  63. #ifndef WLP_HDR_FMT_2
  64. u8 reserved;
  65. __le16 oui01; /* FIXME: not so sure if __le16 or u8[2] */
  66. /* dword 2 */
  67. u8 oui2; /* if all LE, it could be merged */
  68. __le16 prid;
  69. #endif
  70. } __attribute__((packed));
  71. static inline int wlp_tx_hdr_delivery_id_type(const struct wlp_tx_hdr *hdr)
  72. {
  73. return hdr->mac_params & 0x0f;
  74. }
  75. static inline int wlp_tx_hdr_ack_policy(const struct wlp_tx_hdr *hdr)
  76. {
  77. return (hdr->mac_params >> 4) & 0x07;
  78. }
  79. static inline int wlp_tx_hdr_rts_cts(const struct wlp_tx_hdr *hdr)
  80. {
  81. return (hdr->mac_params >> 7) & 0x01;
  82. }
  83. static inline void wlp_tx_hdr_set_delivery_id_type(struct wlp_tx_hdr *hdr, int id)
  84. {
  85. hdr->mac_params = (hdr->mac_params & ~0x0f) | id;
  86. }
  87. static inline void wlp_tx_hdr_set_ack_policy(struct wlp_tx_hdr *hdr,
  88. enum uwb_ack_pol policy)
  89. {
  90. hdr->mac_params = (hdr->mac_params & ~0x70) | (policy << 4);
  91. }
  92. static inline void wlp_tx_hdr_set_rts_cts(struct wlp_tx_hdr *hdr, int rts_cts)
  93. {
  94. hdr->mac_params = (hdr->mac_params & ~0x80) | (rts_cts << 7);
  95. }
  96. static inline enum uwb_phy_rate wlp_tx_hdr_phy_rate(const struct wlp_tx_hdr *hdr)
  97. {
  98. return hdr->phy_params & 0x0f;
  99. }
  100. static inline int wlp_tx_hdr_tx_power(const struct wlp_tx_hdr *hdr)
  101. {
  102. return (hdr->phy_params >> 4) & 0x0f;
  103. }
  104. static inline void wlp_tx_hdr_set_phy_rate(struct wlp_tx_hdr *hdr, enum uwb_phy_rate rate)
  105. {
  106. hdr->phy_params = (hdr->phy_params & ~0x0f) | rate;
  107. }
  108. static inline void wlp_tx_hdr_set_tx_power(struct wlp_tx_hdr *hdr, int pwr)
  109. {
  110. hdr->phy_params = (hdr->phy_params & ~0xf0) | (pwr << 4);
  111. }
  112. /**
  113. * WLP RX header
  114. *
  115. * Provides UWB/WLP-specific transmission data for a received
  116. * network packet.
  117. */
  118. struct wlp_rx_hdr {
  119. /* dword 0 */
  120. struct uwb_dev_addr dstaddr;
  121. struct uwb_dev_addr srcaddr;
  122. /* dword 1 */
  123. u8 LQI;
  124. s8 RSSI;
  125. u8 reserved3;
  126. #ifndef WLP_HDR_FMT_2
  127. u8 oui0;
  128. /* dword 2 */
  129. __le16 oui12;
  130. __le16 prid;
  131. #endif
  132. } __attribute__((packed));
  133. /** User configurable options for WLP */
  134. struct wlp_options {
  135. struct mutex mutex; /* access to user configurable options*/
  136. struct wlp_tx_hdr def_tx_hdr; /* default tx hdr */
  137. u8 pca_base_priority;
  138. u8 bw_alloc; /*index into bw_allocs[] for PCA/DRP reservations*/
  139. };
  140. static inline
  141. void wlp_options_init(struct wlp_options *options)
  142. {
  143. mutex_init(&options->mutex);
  144. wlp_tx_hdr_set_ack_policy(&options->def_tx_hdr, UWB_ACK_INM);
  145. wlp_tx_hdr_set_rts_cts(&options->def_tx_hdr, 1);
  146. /* FIXME: default to phy caps */
  147. wlp_tx_hdr_set_phy_rate(&options->def_tx_hdr, UWB_PHY_RATE_480);
  148. #ifndef WLP_HDR_FMT_2
  149. options->def_tx_hdr.prid = cpu_to_le16(0x0000);
  150. #endif
  151. }
  152. /* sysfs helpers */
  153. extern ssize_t uwb_pca_base_priority_store(struct wlp_options *,
  154. const char *, size_t);
  155. extern ssize_t uwb_pca_base_priority_show(const struct wlp_options *, char *);
  156. extern ssize_t uwb_bw_alloc_store(struct wlp_options *, const char *, size_t);
  157. extern ssize_t uwb_bw_alloc_show(const struct wlp_options *, char *);
  158. extern ssize_t uwb_ack_policy_store(struct wlp_options *,
  159. const char *, size_t);
  160. extern ssize_t uwb_ack_policy_show(const struct wlp_options *, char *);
  161. extern ssize_t uwb_rts_cts_store(struct wlp_options *, const char *, size_t);
  162. extern ssize_t uwb_rts_cts_show(const struct wlp_options *, char *);
  163. extern ssize_t uwb_phy_rate_store(struct wlp_options *, const char *, size_t);
  164. extern ssize_t uwb_phy_rate_show(const struct wlp_options *, char *);
  165. /** Simple bandwidth allocation (temporary and too simple) */
  166. struct wlp_bw_allocs {
  167. const char *name;
  168. struct {
  169. u8 mask, stream;
  170. } tx, rx;
  171. };
  172. #endif /* #ifndef __i1480_wlp_h__ */