0001
0002
0003
0004
0005
0006
0007
0008 #ifndef _ZD_USB_H
0009 #define _ZD_USB_H
0010
0011 #include <linux/completion.h>
0012 #include <linux/netdevice.h>
0013 #include <linux/spinlock.h>
0014 #include <linux/skbuff.h>
0015 #include <linux/usb.h>
0016
0017 #include "zd_def.h"
0018
0019 #define ZD_USB_TX_HIGH 5
0020 #define ZD_USB_TX_LOW 2
0021
0022 #define ZD_TX_TIMEOUT (HZ * 5)
0023 #define ZD_TX_WATCHDOG_INTERVAL round_jiffies_relative(HZ)
0024 #define ZD_RX_IDLE_INTERVAL round_jiffies_relative(30 * HZ)
0025
0026 enum devicetype {
0027 DEVICE_ZD1211 = 0,
0028 DEVICE_ZD1211B = 1,
0029 DEVICE_INSTALLER = 2,
0030 };
0031
0032 enum endpoints {
0033 EP_CTRL = 0,
0034 EP_DATA_OUT = 1,
0035 EP_DATA_IN = 2,
0036 EP_INT_IN = 3,
0037 EP_REGS_OUT = 4,
0038 };
0039
0040 enum {
0041 USB_MAX_TRANSFER_SIZE = 4096,
0042
0043
0044
0045
0046 USB_MAX_RX_SIZE = 4800,
0047 USB_MAX_IOWRITE16_COUNT = 15,
0048 USB_MAX_IOWRITE32_COUNT = USB_MAX_IOWRITE16_COUNT/2,
0049 USB_MAX_IOREAD16_COUNT = 15,
0050 USB_MAX_IOREAD32_COUNT = USB_MAX_IOREAD16_COUNT/2,
0051 USB_MIN_RFWRITE_BIT_COUNT = 16,
0052 USB_MAX_RFWRITE_BIT_COUNT = 28,
0053 USB_MAX_EP_INT_BUFFER = 64,
0054 USB_ZD1211B_BCD_DEVICE = 0x4810,
0055 };
0056
0057 enum control_requests {
0058 USB_REQ_WRITE_REGS = 0x21,
0059 USB_REQ_READ_REGS = 0x22,
0060 USB_REQ_WRITE_RF = 0x23,
0061 USB_REQ_PROG_FLASH = 0x24,
0062 USB_REQ_EEPROM_START = 0x0128,
0063 USB_REQ_EEPROM_MID = 0x28,
0064 USB_REQ_EEPROM_END = 0x0228,
0065 USB_REQ_FIRMWARE_DOWNLOAD = 0x30,
0066 USB_REQ_FIRMWARE_CONFIRM = 0x31,
0067 USB_REQ_FIRMWARE_READ_DATA = 0x32,
0068 };
0069
0070 struct usb_req_read_regs {
0071 __le16 id;
0072 __le16 addr[];
0073 } __packed;
0074
0075 struct reg_data {
0076 __le16 addr;
0077 __le16 value;
0078 } __packed;
0079
0080 struct usb_req_write_regs {
0081 __le16 id;
0082 struct reg_data reg_writes[];
0083 } __packed;
0084
0085 enum {
0086 RF_IF_LE = 0x02,
0087 RF_CLK = 0x04,
0088 RF_DATA = 0x08,
0089 };
0090
0091 struct usb_req_rfwrite {
0092 __le16 id;
0093 __le16 value;
0094
0095
0096 __le16 bits;
0097
0098 __le16 bit_values[];
0099
0100 } __packed;
0101
0102
0103
0104 enum usb_int_id {
0105 USB_INT_TYPE = 0x01,
0106 USB_INT_ID_REGS = 0x90,
0107 USB_INT_ID_RETRY_FAILED = 0xa0,
0108 };
0109
0110 enum usb_int_flags {
0111 USB_INT_READ_REGS_EN = 0x01,
0112 };
0113
0114 struct usb_int_header {
0115 u8 type;
0116 u8 id;
0117 } __packed;
0118
0119 struct usb_int_regs {
0120 struct usb_int_header hdr;
0121 struct reg_data regs[];
0122 } __packed;
0123
0124 struct usb_int_retry_fail {
0125 struct usb_int_header hdr;
0126 u8 new_rate;
0127 u8 _dummy;
0128 u8 addr[ETH_ALEN];
0129 u8 ibss_wakeup_dest;
0130 } __packed;
0131
0132 struct read_regs_int {
0133 struct completion completion;
0134 struct usb_req_read_regs *req;
0135 unsigned int req_count;
0136
0137
0138
0139 u8 buffer[USB_MAX_EP_INT_BUFFER];
0140 int length;
0141 __le16 cr_int_addr;
0142 };
0143
0144 struct zd_ioreq16 {
0145 zd_addr_t addr;
0146 u16 value;
0147 };
0148
0149 struct zd_ioreq32 {
0150 zd_addr_t addr;
0151 u32 value;
0152 };
0153
0154 struct zd_usb_interrupt {
0155 struct read_regs_int read_regs;
0156 spinlock_t lock;
0157 struct urb *urb;
0158 void *buffer;
0159 dma_addr_t buffer_dma;
0160 int interval;
0161 atomic_t read_regs_enabled;
0162 u8 read_regs_int_overridden:1;
0163 };
0164
0165 static inline struct usb_int_regs *get_read_regs(struct zd_usb_interrupt *intr)
0166 {
0167 return (struct usb_int_regs *)intr->read_regs.buffer;
0168 }
0169
0170 #define RX_URBS_COUNT 5
0171
0172 struct zd_usb_rx {
0173 spinlock_t lock;
0174 struct mutex setup_mutex;
0175 struct delayed_work idle_work;
0176 struct tasklet_struct reset_timer_tasklet;
0177 u8 fragment[2 * USB_MAX_RX_SIZE];
0178 unsigned int fragment_length;
0179 unsigned int usb_packet_size;
0180 struct urb **urbs;
0181 int urbs_count;
0182 };
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193 struct zd_usb_tx {
0194 atomic_t enabled;
0195 spinlock_t lock;
0196 struct delayed_work watchdog_work;
0197 struct sk_buff_head submitted_skbs;
0198 struct usb_anchor submitted;
0199 int submitted_urbs;
0200 u8 stopped:1, watchdog_enabled:1;
0201 };
0202
0203
0204
0205
0206 struct zd_usb {
0207 struct zd_usb_interrupt intr;
0208 struct zd_usb_rx rx;
0209 struct zd_usb_tx tx;
0210 struct usb_interface *intf;
0211 struct usb_anchor submitted_cmds;
0212 struct urb *urb_async_waiting;
0213 int cmd_error;
0214 u8 req_buf[64];
0215 u8 is_zd1211b:1, initialized:1, was_running:1, in_async:1;
0216 };
0217
0218 #define zd_usb_dev(usb) (&usb->intf->dev)
0219
0220 static inline struct usb_device *zd_usb_to_usbdev(struct zd_usb *usb)
0221 {
0222 return interface_to_usbdev(usb->intf);
0223 }
0224
0225 static inline struct ieee80211_hw *zd_intf_to_hw(struct usb_interface *intf)
0226 {
0227 return usb_get_intfdata(intf);
0228 }
0229
0230 static inline struct ieee80211_hw *zd_usb_to_hw(struct zd_usb *usb)
0231 {
0232 return zd_intf_to_hw(usb->intf);
0233 }
0234
0235 void zd_usb_init(struct zd_usb *usb, struct ieee80211_hw *hw,
0236 struct usb_interface *intf);
0237 int zd_usb_init_hw(struct zd_usb *usb);
0238 void zd_usb_clear(struct zd_usb *usb);
0239
0240 int zd_usb_scnprint_id(struct zd_usb *usb, char *buffer, size_t size);
0241
0242 void zd_tx_watchdog_enable(struct zd_usb *usb);
0243 void zd_tx_watchdog_disable(struct zd_usb *usb);
0244
0245 int zd_usb_enable_int(struct zd_usb *usb);
0246 void zd_usb_disable_int(struct zd_usb *usb);
0247
0248 int zd_usb_enable_rx(struct zd_usb *usb);
0249 void zd_usb_disable_rx(struct zd_usb *usb);
0250
0251 void zd_usb_reset_rx_idle_timer(struct zd_usb *usb);
0252
0253 void zd_usb_enable_tx(struct zd_usb *usb);
0254 void zd_usb_disable_tx(struct zd_usb *usb);
0255
0256 int zd_usb_tx(struct zd_usb *usb, struct sk_buff *skb);
0257
0258 int zd_usb_ioread16v(struct zd_usb *usb, u16 *values,
0259 const zd_addr_t *addresses, unsigned int count);
0260
0261 static inline int zd_usb_ioread16(struct zd_usb *usb, u16 *value,
0262 const zd_addr_t addr)
0263 {
0264 return zd_usb_ioread16v(usb, value, &addr, 1);
0265 }
0266
0267 void zd_usb_iowrite16v_async_start(struct zd_usb *usb);
0268 int zd_usb_iowrite16v_async_end(struct zd_usb *usb, unsigned int timeout);
0269 int zd_usb_iowrite16v_async(struct zd_usb *usb, const struct zd_ioreq16 *ioreqs,
0270 unsigned int count);
0271 int zd_usb_iowrite16v(struct zd_usb *usb, const struct zd_ioreq16 *ioreqs,
0272 unsigned int count);
0273
0274 int zd_usb_rfwrite(struct zd_usb *usb, u32 value, u8 bits);
0275
0276 int zd_usb_read_fw(struct zd_usb *usb, zd_addr_t addr, u8 *data, u16 len);
0277
0278 extern struct workqueue_struct *zd_workqueue;
0279
0280 #endif