1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2021 pureLiFi
9 #include <linux/completion.h>
10 #include <linux/netdevice.h>
11 #include <linux/spinlock.h>
12 #include <linux/skbuff.h>
13 #include <linux/usb.h>
17 #define USB_BULK_MSG_TIMEOUT_MS 2000
19 #define PURELIFI_X_VENDOR_ID_0 0x16C1
20 #define PURELIFI_X_PRODUCT_ID_0 0x1CDE
21 #define PURELIFI_XC_VENDOR_ID_0 0x2EF5
22 #define PURELIFI_XC_PRODUCT_ID_0 0x0008
23 #define PURELIFI_XL_VENDOR_ID_0 0x2EF5
24 #define PURELIFI_XL_PRODUCT_ID_0 0x000A /* Station */
26 #define PLF_FPGA_STATUS_LEN 2
27 #define PLF_FPGA_STATE_LEN 9
28 #define PLF_BULK_TLEN 16384
29 #define PLF_FPGA_MG 6 /* Magic check */
30 #define PLF_XL_BUF_LEN 64
31 #define PLF_MSG_STATUS_OFFSET 7
33 #define PLF_USB_TIMEOUT 1000
34 #define PLF_MSLEEP_TIME 200
36 #define PURELIFI_URB_RETRY_MAX 5
38 #define plfxlc_usb_dev(usb) (&(usb)->intf->dev)
40 /* Tx retry backoff timer (in milliseconds) */
41 #define TX_RETRY_BACKOFF_MS 10
42 #define STA_QUEUE_CLEANUP_MS 5000
44 /* Tx retry backoff timer (in jiffies) */
45 #define TX_RETRY_BACKOFF_JIFF ((TX_RETRY_BACKOFF_MS * HZ) / 1000)
46 #define STA_QUEUE_CLEANUP_JIFF ((STA_QUEUE_CLEANUP_MS * HZ) / 1000)
48 /* Ensures that MAX_TRANSFER_SIZE is even. */
49 #define MAX_TRANSFER_SIZE (USB_MAX_TRANSFER_SIZE & ~1)
50 #define plfxlc_urb_dev(urb) (&(urb)->dev->dev)
52 #define STATION_FIFO_ALMOST_FULL_MESSAGE 0
53 #define STATION_FIFO_ALMOST_FULL_NOT_MESSAGE 1
54 #define STATION_CONNECT_MESSAGE 2
55 #define STATION_DISCONNECT_MESSAGE 3
57 int plfxlc_usb_wreq(struct usb_interface *ez_usb, void *buffer, int buffer_len,
58 enum plf_usb_req_enum usb_req_id);
59 void plfxlc_tx_urb_complete(struct urb *urb);
62 USB_MAX_RX_SIZE = 4800,
63 USB_MAX_EP_INT_BUFFER = 64,
66 struct plfxlc_usb_interrupt {
67 spinlock_t lock; /* spin lock for usb interrupt buffer */
73 #define RX_URBS_COUNT 5
75 struct plfxlc_usb_rx {
76 spinlock_t lock; /* spin lock for rx urb */
77 struct mutex setup_mutex; /* mutex lockt for rx urb */
78 u8 fragment[2 * USB_MAX_RX_SIZE];
79 unsigned int fragment_length;
80 unsigned int usb_packet_size;
86 /* 7...3 | 2 | 1 | 0 |
87 * Reserved | Heartbeat | FIFO full | Connected |
90 unsigned char mac[ETH_ALEN];
91 struct sk_buff_head data_list;
94 struct plfxlc_firmware_file {
102 #define STATION_CONNECTED_FLAG 0x1
103 #define STATION_FIFO_FULL_FLAG 0x2
104 #define STATION_HEARTBEAT_FLAG 0x4
105 #define STATION_ACTIVE_FLAG 0xFD
107 #define PURELIFI_SERIAL_LEN 256
108 #define STA_BROADCAST_INDEX (AP_USER_LIMIT)
109 #define MAX_STA_NUM (AP_USER_LIMIT + 1)
111 struct plfxlc_usb_tx {
112 unsigned long enabled;
113 spinlock_t lock; /* spinlock for USB tx */
115 struct sk_buff_head submitted_skbs;
116 struct usb_anchor submitted;
119 struct timer_list tx_retry_timer;
120 struct plf_station station[MAX_STA_NUM];
123 /* Contains the usb parts. The structure doesn't require a lock because intf
124 * will not be changed after initialization.
127 struct timer_list sta_queue_cleanup;
128 struct plfxlc_usb_rx rx;
129 struct plfxlc_usb_tx tx;
130 struct usb_interface *intf;
131 struct usb_interface *ez_usb;
132 u8 req_buf[64]; /* plfxlc_usb_iowrite16v needs 62 bytes */
133 u8 sidx; /* store last served */
156 int plfxlc_usb_wreq_async(struct plfxlc_usb *usb, const u8 *buffer,
157 int buffer_len, enum plf_usb_req_enum usb_req_id,
158 usb_complete_t complete_fn, void *context);
160 static inline struct usb_device *
161 plfxlc_usb_to_usbdev(struct plfxlc_usb *usb)
163 return interface_to_usbdev(usb->intf);
166 static inline struct ieee80211_hw *
167 plfxlc_intf_to_hw(struct usb_interface *intf)
169 return usb_get_intfdata(intf);
172 static inline struct ieee80211_hw *
173 plfxlc_usb_to_hw(struct plfxlc_usb *usb)
175 return plfxlc_intf_to_hw(usb->intf);
178 void plfxlc_usb_init(struct plfxlc_usb *usb, struct ieee80211_hw *hw,
179 struct usb_interface *intf);
180 void plfxlc_send_packet_from_data_queue(struct plfxlc_usb *usb);
181 void plfxlc_usb_release(struct plfxlc_usb *usb);
182 void plfxlc_usb_disable_rx(struct plfxlc_usb *usb);
183 void plfxlc_usb_enable_tx(struct plfxlc_usb *usb);
184 void plfxlc_usb_disable_tx(struct plfxlc_usb *usb);
185 int plfxlc_usb_tx(struct plfxlc_usb *usb, struct sk_buff *skb);
186 int plfxlc_usb_enable_rx(struct plfxlc_usb *usb);
187 int plfxlc_usb_init_hw(struct plfxlc_usb *usb);
188 const char *plfxlc_speed(enum usb_device_speed speed);
190 /* Firmware declarations */
191 int plfxlc_download_xl_firmware(struct usb_interface *intf);
192 int plfxlc_download_fpga(struct usb_interface *intf);
194 int plfxlc_upload_mac_and_serial(struct usb_interface *intf,
195 unsigned char *hw_address,
196 unsigned char *serial_number);
198 #endif /* PLFXLC_USB_H */