1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2021 pureLiFi
9 #include <linux/kernel.h>
10 #include <net/mac80211.h>
14 #define PURELIFI_CCK 0x00
15 #define PURELIFI_OFDM 0x10
16 #define PURELIFI_CCK_PREA_SHORT 0x20
18 #define PURELIFI_OFDM_PLCP_RATE_6M 0xb
19 #define PURELIFI_OFDM_PLCP_RATE_9M 0xf
20 #define PURELIFI_OFDM_PLCP_RATE_12M 0xa
21 #define PURELIFI_OFDM_PLCP_RATE_18M 0xe
22 #define PURELIFI_OFDM_PLCP_RATE_24M 0x9
23 #define PURELIFI_OFDM_PLCP_RATE_36M 0xd
24 #define PURELIFI_OFDM_PLCP_RATE_48M 0x8
25 #define PURELIFI_OFDM_PLCP_RATE_54M 0xc
27 #define PURELIFI_CCK_RATE_1M (PURELIFI_CCK | 0x00)
28 #define PURELIFI_CCK_RATE_2M (PURELIFI_CCK | 0x01)
29 #define PURELIFI_CCK_RATE_5_5M (PURELIFI_CCK | 0x02)
30 #define PURELIFI_CCK_RATE_11M (PURELIFI_CCK | 0x03)
31 #define PURELIFI_OFDM_RATE_6M (PURELIFI_OFDM | PURELIFI_OFDM_PLCP_RATE_6M)
32 #define PURELIFI_OFDM_RATE_9M (PURELIFI_OFDM | PURELIFI_OFDM_PLCP_RATE_9M)
33 #define PURELIFI_OFDM_RATE_12M (PURELIFI_OFDM | PURELIFI_OFDM_PLCP_RATE_12M)
34 #define PURELIFI_OFDM_RATE_18M (PURELIFI_OFDM | PURELIFI_OFDM_PLCP_RATE_18M)
35 #define PURELIFI_OFDM_RATE_24M (PURELIFI_OFDM | PURELIFI_OFDM_PLCP_RATE_24M)
36 #define PURELIFI_OFDM_RATE_36M (PURELIFI_OFDM | PURELIFI_OFDM_PLCP_RATE_36M)
37 #define PURELIFI_OFDM_RATE_48M (PURELIFI_OFDM | PURELIFI_OFDM_PLCP_RATE_48M)
38 #define PURELIFI_OFDM_RATE_54M (PURELIFI_OFDM | PURELIFI_OFDM_PLCP_RATE_54M)
40 #define PURELIFI_RX_ERROR 0x80
41 #define PURELIFI_RX_CRC32_ERROR 0x10
43 #define PLF_REGDOMAIN_FCC 0x10
44 #define PLF_REGDOMAIN_IC 0x20
45 #define PLF_REGDOMAIN_ETSI 0x30
46 #define PLF_REGDOMAIN_SPAIN 0x31
47 #define PLF_REGDOMAIN_FRANCE 0x32
48 #define PLF_REGDOMAIN_JAPAN_2 0x40
49 #define PLF_REGDOMAIN_JAPAN 0x41
50 #define PLF_REGDOMAIN_JAPAN_3 0x49
52 #define PLF_RX_ERROR 0x80
53 #define PLF_RX_CRC32_ERROR 0x10
56 MODULATION_RATE_BPSK_1_2 = 0,
57 MODULATION_RATE_BPSK_3_4,
58 MODULATION_RATE_QPSK_1_2,
59 MODULATION_RATE_QPSK_3_4,
60 MODULATION_RATE_QAM16_1_2,
61 MODULATION_RATE_QAM16_3_4,
62 MODULATION_RATE_QAM64_1_2,
63 MODULATION_RATE_QAM64_3_4,
68 #define plfxlc_mac_dev(mac) plfxlc_chip_dev(&(mac)->chip)
70 #define PURELIFI_MAC_STATS_BUFFER_SIZE 16
71 #define PURELIFI_MAC_MAX_ACK_WAITERS 50
73 struct plfxlc_ctrlset {
74 /* id should be plf_usb_req_enum */
82 __le16 current_length;
83 __le16 next_frame_length;
85 __be32 payload_len_nw;
89 struct plfxlc_header {
90 struct plfxlc_ctrlset plf_ctrl;
106 struct delayed_work watchdog_work;
107 struct sk_buff *cur_beacon;
108 unsigned long last_update;
113 enum plfxlc_device_flags {
114 PURELIFI_DEVICE_RUNNING,
118 struct ieee80211_hw *hw;
119 struct ieee80211_vif *vif;
120 struct beacon beacon;
121 struct work_struct set_rts_cts_work;
122 struct work_struct process_intr;
123 struct plfxlc_mc_hash multicast_hash;
124 struct sk_buff_head ack_wait_queue;
125 struct ieee80211_channel channels[14];
126 struct ieee80211_rate rates[12];
127 struct ieee80211_supported_band band;
128 struct plfxlc_chip chip;
129 spinlock_t lock; /* lock for mac data */
130 u8 intr_buffer[USB_MAX_EP_INT_BUFFER];
131 char serial_number[PURELIFI_SERIAL_LEN];
132 unsigned char hw_address[ETH_ALEN];
133 u8 default_regdomain;
135 bool pass_failed_fcs;
147 static inline struct plfxlc_mac *
148 plfxlc_hw_mac(struct ieee80211_hw *hw)
153 static inline struct plfxlc_mac *
154 plfxlc_chip_to_mac(struct plfxlc_chip *chip)
156 return container_of(chip, struct plfxlc_mac, chip);
159 static inline struct plfxlc_mac *
160 plfxlc_usb_to_mac(struct plfxlc_usb *usb)
162 return plfxlc_chip_to_mac(plfxlc_usb_to_chip(usb));
165 static inline u8 *plfxlc_mac_get_perm_addr(struct plfxlc_mac *mac)
167 return mac->hw->wiphy->perm_addr;
170 struct ieee80211_hw *plfxlc_mac_alloc_hw(struct usb_interface *intf);
171 void plfxlc_mac_release(struct plfxlc_mac *mac);
173 int plfxlc_mac_preinit_hw(struct ieee80211_hw *hw, const u8 *hw_address);
174 int plfxlc_mac_init_hw(struct ieee80211_hw *hw);
176 int plfxlc_mac_rx(struct ieee80211_hw *hw, const u8 *buffer,
177 unsigned int length);
178 void plfxlc_mac_tx_failed(struct urb *urb);
179 void plfxlc_mac_tx_to_dev(struct sk_buff *skb, int error);
180 int plfxlc_op_start(struct ieee80211_hw *hw);
181 void plfxlc_op_stop(struct ieee80211_hw *hw);
182 int plfxlc_restore_settings(struct plfxlc_mac *mac);
184 #endif /* PLFXLC_MAC_H */