Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (c) 2021 pureLiFi
0004  */
0005 
0006 #ifndef PLFXLC_USB_H
0007 #define PLFXLC_USB_H
0008 
0009 #include <linux/completion.h>
0010 #include <linux/netdevice.h>
0011 #include <linux/spinlock.h>
0012 #include <linux/skbuff.h>
0013 #include <linux/usb.h>
0014 
0015 #include "intf.h"
0016 
0017 #define USB_BULK_MSG_TIMEOUT_MS 2000
0018 
0019 #define PURELIFI_X_VENDOR_ID_0   0x16C1
0020 #define PURELIFI_X_PRODUCT_ID_0  0x1CDE
0021 #define PURELIFI_XC_VENDOR_ID_0  0x2EF5
0022 #define PURELIFI_XC_PRODUCT_ID_0 0x0008
0023 #define PURELIFI_XL_VENDOR_ID_0  0x2EF5
0024 #define PURELIFI_XL_PRODUCT_ID_0 0x000A /* Station */
0025 
0026 #define PLF_FPGA_STATUS_LEN 2
0027 #define PLF_FPGA_STATE_LEN 9
0028 #define PLF_BULK_TLEN 16384
0029 #define PLF_FPGA_MG 6 /* Magic check */
0030 #define PLF_XL_BUF_LEN 64
0031 #define PLF_MSG_STATUS_OFFSET 7
0032 
0033 #define PLF_USB_TIMEOUT 1000
0034 #define PLF_MSLEEP_TIME 200
0035 
0036 #define PURELIFI_URB_RETRY_MAX 5
0037 
0038 #define plfxlc_usb_dev(usb) (&(usb)->intf->dev)
0039 
0040 /* Tx retry backoff timer (in milliseconds) */
0041 #define TX_RETRY_BACKOFF_MS 10
0042 #define STA_QUEUE_CLEANUP_MS 5000
0043 
0044 /* Tx retry backoff timer (in jiffies) */
0045 #define TX_RETRY_BACKOFF_JIFF ((TX_RETRY_BACKOFF_MS * HZ) / 1000)
0046 #define STA_QUEUE_CLEANUP_JIFF ((STA_QUEUE_CLEANUP_MS * HZ) / 1000)
0047 
0048 /* Ensures that MAX_TRANSFER_SIZE is even. */
0049 #define MAX_TRANSFER_SIZE (USB_MAX_TRANSFER_SIZE & ~1)
0050 #define plfxlc_urb_dev(urb) (&(urb)->dev->dev)
0051 
0052 #define STATION_FIFO_ALMOST_FULL_MESSAGE     0
0053 #define STATION_FIFO_ALMOST_FULL_NOT_MESSAGE 1
0054 #define STATION_CONNECT_MESSAGE              2
0055 #define STATION_DISCONNECT_MESSAGE           3
0056 
0057 int plfxlc_usb_wreq(struct usb_interface *ez_usb, void *buffer, int buffer_len,
0058             enum plf_usb_req_enum usb_req_id);
0059 void plfxlc_tx_urb_complete(struct urb *urb);
0060 
0061 enum {
0062     USB_MAX_RX_SIZE       = 4800,
0063     USB_MAX_EP_INT_BUFFER = 64,
0064 };
0065 
0066 struct plfxlc_usb_interrupt {
0067     spinlock_t lock; /* spin lock for usb interrupt buffer */
0068     struct urb *urb;
0069     void *buffer;
0070     int interval;
0071 };
0072 
0073 #define RX_URBS_COUNT 5
0074 
0075 struct plfxlc_usb_rx {
0076     spinlock_t lock; /* spin lock for rx urb */
0077     struct mutex setup_mutex; /* mutex lockt for rx urb */
0078     u8 fragment[2 * USB_MAX_RX_SIZE];
0079     unsigned int fragment_length;
0080     unsigned int usb_packet_size;
0081     struct urb **urbs;
0082     int urbs_count;
0083 };
0084 
0085 struct plf_station {
0086    /*  7...3    |    2      |     1     |     0     |
0087     * Reserved  | Heartbeat | FIFO full | Connected |
0088     */
0089     unsigned char flag;
0090     unsigned char mac[ETH_ALEN];
0091     struct sk_buff_head data_list;
0092 };
0093 
0094 struct plfxlc_firmware_file {
0095     u32 total_files;
0096     u32 total_size;
0097     u32 size;
0098     u32 start_addr;
0099     u32 control_packets;
0100 } __packed;
0101 
0102 #define STATION_CONNECTED_FLAG 0x1
0103 #define STATION_FIFO_FULL_FLAG 0x2
0104 #define STATION_HEARTBEAT_FLAG 0x4
0105 #define STATION_ACTIVE_FLAG    0xFD
0106 
0107 #define PURELIFI_SERIAL_LEN 256
0108 #define STA_BROADCAST_INDEX (AP_USER_LIMIT)
0109 #define MAX_STA_NUM         (AP_USER_LIMIT + 1)
0110 
0111 struct plfxlc_usb_tx {
0112     unsigned long enabled;
0113     spinlock_t lock; /* spinlock for USB tx */
0114     u8 mac_fifo_full;
0115     struct sk_buff_head submitted_skbs;
0116     struct usb_anchor submitted;
0117     int submitted_urbs;
0118     bool stopped;
0119     struct timer_list tx_retry_timer;
0120     struct plf_station station[MAX_STA_NUM];
0121 };
0122 
0123 /* Contains the usb parts. The structure doesn't require a lock because intf
0124  * will not be changed after initialization.
0125  */
0126 struct plfxlc_usb {
0127     struct timer_list sta_queue_cleanup;
0128     struct plfxlc_usb_rx rx;
0129     struct plfxlc_usb_tx tx;
0130     struct usb_interface *intf;
0131     struct usb_interface *ez_usb;
0132     u8 req_buf[64]; /* plfxlc_usb_iowrite16v needs 62 bytes */
0133     u8 sidx; /* store last served */
0134     bool rx_usb_enabled;
0135     bool initialized;
0136     bool was_running;
0137     bool link_up;
0138 };
0139 
0140 enum endpoints {
0141     EP_DATA_IN  = 2,
0142     EP_DATA_OUT = 8,
0143 };
0144 
0145 enum devicetype {
0146     DEVICE_LIFI_X  = 0,
0147     DEVICE_LIFI_XC  = 1,
0148     DEVICE_LIFI_XL  = 1,
0149 };
0150 
0151 enum {
0152     PLF_BIT_ENABLED = 1,
0153     PLF_BIT_MAX = 2,
0154 };
0155 
0156 int plfxlc_usb_wreq_async(struct plfxlc_usb *usb, const u8 *buffer,
0157               int buffer_len, enum plf_usb_req_enum usb_req_id,
0158               usb_complete_t complete_fn, void *context);
0159 
0160 static inline struct usb_device *
0161 plfxlc_usb_to_usbdev(struct plfxlc_usb *usb)
0162 {
0163     return interface_to_usbdev(usb->intf);
0164 }
0165 
0166 static inline struct ieee80211_hw *
0167 plfxlc_intf_to_hw(struct usb_interface *intf)
0168 {
0169     return usb_get_intfdata(intf);
0170 }
0171 
0172 static inline struct ieee80211_hw *
0173 plfxlc_usb_to_hw(struct plfxlc_usb *usb)
0174 {
0175     return plfxlc_intf_to_hw(usb->intf);
0176 }
0177 
0178 void plfxlc_usb_init(struct plfxlc_usb *usb, struct ieee80211_hw *hw,
0179              struct usb_interface *intf);
0180 void plfxlc_send_packet_from_data_queue(struct plfxlc_usb *usb);
0181 void plfxlc_usb_release(struct plfxlc_usb *usb);
0182 void plfxlc_usb_disable_rx(struct plfxlc_usb *usb);
0183 void plfxlc_usb_enable_tx(struct plfxlc_usb *usb);
0184 void plfxlc_usb_disable_tx(struct plfxlc_usb *usb);
0185 int plfxlc_usb_tx(struct plfxlc_usb *usb, struct sk_buff *skb);
0186 int plfxlc_usb_enable_rx(struct plfxlc_usb *usb);
0187 int plfxlc_usb_init_hw(struct plfxlc_usb *usb);
0188 const char *plfxlc_speed(enum usb_device_speed speed);
0189 
0190 /* Firmware declarations */
0191 int plfxlc_download_xl_firmware(struct usb_interface *intf);
0192 int plfxlc_download_fpga(struct usb_interface *intf);
0193 
0194 int plfxlc_upload_mac_and_serial(struct usb_interface *intf,
0195                  unsigned char *hw_address,
0196                  unsigned char *serial_number);
0197 
0198 #endif /* PLFXLC_USB_H */