1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#ifndef __RTS51X_H
28#define __RTS51X_H
29
30#include <linux/usb.h>
31#include <linux/usb_usual.h>
32#include <linux/blkdev.h>
33#include <linux/completion.h>
34#include <linux/mutex.h>
35#include <linux/cdrom.h>
36#include <linux/kernel.h>
37
38#include <scsi/scsi.h>
39#include <scsi/scsi_cmnd.h>
40#include <scsi/scsi_device.h>
41#include <scsi/scsi_devinfo.h>
42#include <scsi/scsi_eh.h>
43#include <scsi/scsi_host.h>
44
45#define DRIVER_VERSION "v1.04"
46
47#define RTS51X_DESC "Realtek RTS5139/29 USB card reader driver"
48#define RTS51X_NAME "rts5139"
49#define RTS51X_CTL_THREAD "rts5139-control"
50#define RTS51X_POLLING_THREAD "rts5139-polling"
51
52#define POLLING_IN_THREAD
53#define SUPPORT_FILE_OP
54
55#define wait_timeout_x(task_state, msecs) \
56do { \
57 set_current_state((task_state)); \
58 schedule_timeout((msecs) * HZ / 1000); \
59} while (0)
60
61#define wait_timeout(msecs) wait_timeout_x(TASK_INTERRUPTIBLE, (msecs))
62
63#define SCSI_LUN(srb) ((srb)->device->lun)
64
65
66#define RTS51X_IOBUF_SIZE 1024
67
68
69#define FLIDX_URB_ACTIVE 0
70#define FLIDX_SG_ACTIVE 1
71#define FLIDX_ABORTING 2
72#define FLIDX_DISCONNECTING 3
73#define FLIDX_RESETTING 4
74#define FLIDX_TIMED_OUT 5
75
76struct rts51x_chip;
77
78struct rts51x_usb {
79
80
81
82
83 struct mutex dev_mutex;
84 struct usb_device *pusb_dev;
85 struct usb_interface *pusb_intf;
86
87 unsigned long dflags;
88
89 unsigned int send_bulk_pipe;
90 unsigned int recv_bulk_pipe;
91 unsigned int send_ctrl_pipe;
92 unsigned int recv_ctrl_pipe;
93 unsigned int recv_intr_pipe;
94
95 u8 ifnum;
96 u8 ep_bInterval;
97
98
99 struct urb *current_urb;
100 struct urb *intr_urb;
101 struct usb_ctrlrequest *cr;
102 struct usb_sg_request current_sg;
103 unsigned char *iobuf;
104 dma_addr_t cr_dma;
105 dma_addr_t iobuf_dma;
106 struct task_struct *ctl_thread;
107 struct task_struct *polling_thread;
108
109
110 struct completion cmnd_ready;
111 struct completion control_exit;
112 struct completion polling_exit;
113 struct completion notify;
114};
115
116extern struct usb_driver rts51x_driver;
117
118static inline void get_current_time(u8 *timeval_buf, int buf_len)
119{
120 struct timeval tv;
121
122 if (!timeval_buf || (buf_len < 8))
123 return;
124
125 do_gettimeofday(&tv);
126
127 timeval_buf[0] = (u8) (tv.tv_sec >> 24);
128 timeval_buf[1] = (u8) (tv.tv_sec >> 16);
129 timeval_buf[2] = (u8) (tv.tv_sec >> 8);
130 timeval_buf[3] = (u8) (tv.tv_sec);
131 timeval_buf[4] = (u8) (tv.tv_usec >> 24);
132 timeval_buf[5] = (u8) (tv.tv_usec >> 16);
133 timeval_buf[6] = (u8) (tv.tv_usec >> 8);
134 timeval_buf[7] = (u8) (tv.tv_usec);
135}
136
137#define SND_CTRL_PIPE(chip) ((chip)->usb->send_ctrl_pipe)
138#define RCV_CTRL_PIPE(chip) ((chip)->usb->recv_ctrl_pipe)
139#define SND_BULK_PIPE(chip) ((chip)->usb->send_bulk_pipe)
140#define RCV_BULK_PIPE(chip) ((chip)->usb->recv_bulk_pipe)
141#define RCV_INTR_PIPE(chip) ((chip)->usb->recv_intr_pipe)
142
143
144
145#define scsi_unlock(host) spin_unlock_irq(host->host_lock)
146#define scsi_lock(host) spin_lock_irq(host->host_lock)
147
148#define GET_PM_USAGE_CNT(chip) \
149 atomic_read(&((chip)->usb->pusb_intf->pm_usage_cnt))
150#define SET_PM_USAGE_CNT(chip, cnt) \
151 atomic_set(&((chip)->usb->pusb_intf->pm_usage_cnt), (cnt))
152
153
154static inline void *usb_buffer_alloc(struct usb_device *dev, size_t size,
155 gfp_t mem_flags, dma_addr_t *dma)
156{
157 return usb_alloc_coherent(dev, size, mem_flags, dma);
158}
159
160static inline void usb_buffer_free(struct usb_device *dev, size_t size,
161 void *addr, dma_addr_t dma)
162{
163 return usb_free_coherent(dev, size, addr, dma);
164}
165
166
167static inline struct Scsi_Host *rts51x_to_host(struct rts51x_chip *chip)
168{
169 return container_of((void *)chip, struct Scsi_Host, hostdata);
170}
171
172static inline struct rts51x_chip *host_to_rts51x(struct Scsi_Host *host)
173{
174 return (struct rts51x_chip *)(host->hostdata);
175}
176
177
178enum xfer_buf_dir { TO_XFER_BUF, FROM_XFER_BUF };
179
180
181#ifdef CONFIG_PM
182void rts51x_try_to_exit_ss(struct rts51x_chip *chip);
183int rts51x_suspend(struct usb_interface *iface, pm_message_t message);
184int rts51x_resume(struct usb_interface *iface);
185int rts51x_reset_resume(struct usb_interface *iface);
186#else
187#define rts51x_suspend NULL
188#define rts51x_resume NULL
189#define rts51x_reset_resume NULL
190#endif
191
192extern struct scsi_host_template rts51x_host_template;
193
194#endif
195