mac.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2021 pureLiFi
  4. */
  5. #ifndef PLFXLC_MAC_H
  6. #define PLFXLC_MAC_H
  7. #include <linux/kernel.h>
  8. #include <net/mac80211.h>
  9. #include "chip.h"
  10. #define PURELIFI_CCK 0x00
  11. #define PURELIFI_OFDM 0x10
  12. #define PURELIFI_CCK_PREA_SHORT 0x20
  13. #define PURELIFI_OFDM_PLCP_RATE_6M 0xb
  14. #define PURELIFI_OFDM_PLCP_RATE_9M 0xf
  15. #define PURELIFI_OFDM_PLCP_RATE_12M 0xa
  16. #define PURELIFI_OFDM_PLCP_RATE_18M 0xe
  17. #define PURELIFI_OFDM_PLCP_RATE_24M 0x9
  18. #define PURELIFI_OFDM_PLCP_RATE_36M 0xd
  19. #define PURELIFI_OFDM_PLCP_RATE_48M 0x8
  20. #define PURELIFI_OFDM_PLCP_RATE_54M 0xc
  21. #define PURELIFI_CCK_RATE_1M (PURELIFI_CCK | 0x00)
  22. #define PURELIFI_CCK_RATE_2M (PURELIFI_CCK | 0x01)
  23. #define PURELIFI_CCK_RATE_5_5M (PURELIFI_CCK | 0x02)
  24. #define PURELIFI_CCK_RATE_11M (PURELIFI_CCK | 0x03)
  25. #define PURELIFI_OFDM_RATE_6M (PURELIFI_OFDM | PURELIFI_OFDM_PLCP_RATE_6M)
  26. #define PURELIFI_OFDM_RATE_9M (PURELIFI_OFDM | PURELIFI_OFDM_PLCP_RATE_9M)
  27. #define PURELIFI_OFDM_RATE_12M (PURELIFI_OFDM | PURELIFI_OFDM_PLCP_RATE_12M)
  28. #define PURELIFI_OFDM_RATE_18M (PURELIFI_OFDM | PURELIFI_OFDM_PLCP_RATE_18M)
  29. #define PURELIFI_OFDM_RATE_24M (PURELIFI_OFDM | PURELIFI_OFDM_PLCP_RATE_24M)
  30. #define PURELIFI_OFDM_RATE_36M (PURELIFI_OFDM | PURELIFI_OFDM_PLCP_RATE_36M)
  31. #define PURELIFI_OFDM_RATE_48M (PURELIFI_OFDM | PURELIFI_OFDM_PLCP_RATE_48M)
  32. #define PURELIFI_OFDM_RATE_54M (PURELIFI_OFDM | PURELIFI_OFDM_PLCP_RATE_54M)
  33. #define PURELIFI_RX_ERROR 0x80
  34. #define PURELIFI_RX_CRC32_ERROR 0x10
  35. #define PLF_REGDOMAIN_FCC 0x10
  36. #define PLF_REGDOMAIN_IC 0x20
  37. #define PLF_REGDOMAIN_ETSI 0x30
  38. #define PLF_REGDOMAIN_SPAIN 0x31
  39. #define PLF_REGDOMAIN_FRANCE 0x32
  40. #define PLF_REGDOMAIN_JAPAN_2 0x40
  41. #define PLF_REGDOMAIN_JAPAN 0x41
  42. #define PLF_REGDOMAIN_JAPAN_3 0x49
  43. #define PLF_RX_ERROR 0x80
  44. #define PLF_RX_CRC32_ERROR 0x10
  45. enum {
  46. MODULATION_RATE_BPSK_1_2 = 0,
  47. MODULATION_RATE_BPSK_3_4,
  48. MODULATION_RATE_QPSK_1_2,
  49. MODULATION_RATE_QPSK_3_4,
  50. MODULATION_RATE_QAM16_1_2,
  51. MODULATION_RATE_QAM16_3_4,
  52. MODULATION_RATE_QAM64_1_2,
  53. MODULATION_RATE_QAM64_3_4,
  54. MODULATION_RATE_AUTO,
  55. MODULATION_RATE_NUM
  56. };
  57. #define plfxlc_mac_dev(mac) plfxlc_chip_dev(&(mac)->chip)
  58. #define PURELIFI_MAC_STATS_BUFFER_SIZE 16
  59. #define PURELIFI_MAC_MAX_ACK_WAITERS 50
  60. struct plfxlc_ctrlset {
  61. /* id should be plf_usb_req_enum */
  62. __be32 id;
  63. __be32 len;
  64. u8 modulation;
  65. u8 control;
  66. u8 service;
  67. u8 pad;
  68. __le16 packet_length;
  69. __le16 current_length;
  70. __le16 next_frame_length;
  71. __le16 tx_length;
  72. __be32 payload_len_nw;
  73. } __packed;
  74. /* overlay */
  75. struct plfxlc_header {
  76. struct plfxlc_ctrlset plf_ctrl;
  77. u32 frametype;
  78. u8 *dmac;
  79. } __packed;
  80. struct tx_status {
  81. u8 type;
  82. u8 id;
  83. u8 rate;
  84. u8 pad;
  85. u8 mac[ETH_ALEN];
  86. u8 retry;
  87. u8 failure;
  88. } __packed;
  89. struct beacon {
  90. struct delayed_work watchdog_work;
  91. struct sk_buff *cur_beacon;
  92. unsigned long last_update;
  93. u16 interval;
  94. u8 period;
  95. };
  96. enum plfxlc_device_flags {
  97. PURELIFI_DEVICE_RUNNING,
  98. };
  99. struct plfxlc_mac {
  100. struct ieee80211_hw *hw;
  101. struct ieee80211_vif *vif;
  102. struct beacon beacon;
  103. struct work_struct set_rts_cts_work;
  104. struct work_struct process_intr;
  105. struct plfxlc_mc_hash multicast_hash;
  106. struct sk_buff_head ack_wait_queue;
  107. struct ieee80211_channel channels[14];
  108. struct ieee80211_rate rates[12];
  109. struct ieee80211_supported_band band;
  110. struct plfxlc_chip chip;
  111. spinlock_t lock; /* lock for mac data */
  112. u8 intr_buffer[USB_MAX_EP_INT_BUFFER];
  113. char serial_number[PURELIFI_SERIAL_LEN];
  114. unsigned char hw_address[ETH_ALEN];
  115. u8 default_regdomain;
  116. unsigned long flags;
  117. bool pass_failed_fcs;
  118. bool pass_ctrl;
  119. bool ack_pending;
  120. int ack_signal;
  121. int associated;
  122. u8 regdomain;
  123. u8 channel;
  124. int type;
  125. u64 crc_errors;
  126. u64 rssi;
  127. };
  128. static inline struct plfxlc_mac *
  129. plfxlc_hw_mac(struct ieee80211_hw *hw)
  130. {
  131. return hw->priv;
  132. }
  133. static inline struct plfxlc_mac *
  134. plfxlc_chip_to_mac(struct plfxlc_chip *chip)
  135. {
  136. return container_of(chip, struct plfxlc_mac, chip);
  137. }
  138. static inline struct plfxlc_mac *
  139. plfxlc_usb_to_mac(struct plfxlc_usb *usb)
  140. {
  141. return plfxlc_chip_to_mac(plfxlc_usb_to_chip(usb));
  142. }
  143. static inline u8 *plfxlc_mac_get_perm_addr(struct plfxlc_mac *mac)
  144. {
  145. return mac->hw->wiphy->perm_addr;
  146. }
  147. struct ieee80211_hw *plfxlc_mac_alloc_hw(struct usb_interface *intf);
  148. void plfxlc_mac_release(struct plfxlc_mac *mac);
  149. int plfxlc_mac_preinit_hw(struct ieee80211_hw *hw, const u8 *hw_address);
  150. int plfxlc_mac_init_hw(struct ieee80211_hw *hw);
  151. int plfxlc_mac_rx(struct ieee80211_hw *hw, const u8 *buffer,
  152. unsigned int length);
  153. void plfxlc_mac_tx_failed(struct urb *urb);
  154. void plfxlc_mac_tx_to_dev(struct sk_buff *skb, int error);
  155. int plfxlc_op_start(struct ieee80211_hw *hw);
  156. void plfxlc_op_stop(struct ieee80211_hw *hw);
  157. int plfxlc_restore_settings(struct plfxlc_mac *mac);
  158. #endif /* PLFXLC_MAC_H */