Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rts51x.h
Go to the documentation of this file.
1 /* Driver for Realtek RTS51xx USB card reader
2  * Header file
3  *
4  * Copyright(c) 2009 Realtek Semiconductor Corp. All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation; either version 2, or (at your option) any
9  * later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, see <http://www.gnu.org/licenses/>.
18  *
19  * Author:
20  * wwang ([email protected])
21  * No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China
22  * Maintainer:
23  * Edwin Rong ([email protected])
24  * No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China
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) \
56 do { \
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 /* Size of the DMA-mapped I/O buffer */
66 #define RTS51X_IOBUF_SIZE 1024
67 
68 /* Dynamic bitflag definitions (dflags): used in set_bit() etc. */
69 #define FLIDX_URB_ACTIVE 0 /* current_urb is in use */
70 #define FLIDX_SG_ACTIVE 1 /* current_sg is in use */
71 #define FLIDX_ABORTING 2 /* abort is in progress */
72 #define FLIDX_DISCONNECTING 3 /* disconnect in progress */
73 #define FLIDX_RESETTING 4 /* device reset in progress */
74 #define FLIDX_TIMED_OUT 5 /* SCSI midlayer timed out */
75 
76 struct rts51x_chip;
77 
78 struct rts51x_usb {
79  /* The device we're working with
80  * It's important to note:
81  * (o) you must hold dev_mutex to change pusb_dev
82  */
83  struct mutex dev_mutex; /* protect pusb_dev */
84  struct usb_device *pusb_dev; /* this usb_device */
85  struct usb_interface *pusb_intf; /* this interface */
86 
87  unsigned long dflags; /* dynamic atomic bitflags */
88 
89  unsigned int send_bulk_pipe; /* cached pipe values */
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; /* interface number */
96  u8 ep_bInterval; /* interrupt interval */
97 
98  /* control and bulk communications data */
99  struct urb *current_urb; /* USB requests */
100  struct urb *intr_urb; /* Interrupt USB request */
101  struct usb_ctrlrequest *cr; /* control requests */
102  struct usb_sg_request current_sg; /* scatter-gather req. */
103  unsigned char *iobuf; /* I/O buffer */
104  dma_addr_t cr_dma; /* buffer DMA addresses */
106  struct task_struct *ctl_thread; /* the control thread */
107  struct task_struct *polling_thread; /* the polling thread */
108 
109  /* mutual exclusion and synchronization structures */
110  struct completion cmnd_ready; /* to sleep thread on */
111  struct completion control_exit; /* control thread exit */
112  struct completion polling_exit; /* polling thread exit */
113  struct completion notify; /* thread begin/end */
114 };
115 
116 extern struct usb_driver rts51x_driver;
117 
118 static 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 /* The scsi_lock() and scsi_unlock() macros protect the sm_state and the
144  * single queue element srb for write access */
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 /* Compatible macros while we switch over */
154 static 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 
160 static 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 /* Convert between us_data and the corresponding Scsi_Host */
167 static inline struct Scsi_Host *rts51x_to_host(struct rts51x_chip *chip)
168 {
169  return container_of((void *)chip, struct Scsi_Host, hostdata);
170 }
171 
172 static inline struct rts51x_chip *host_to_rts51x(struct Scsi_Host *host)
173 {
174  return (struct rts51x_chip *)(host->hostdata);
175 }
176 
177 /* struct scsi_cmnd transfer buffer access utilities */
179 
180 /* General routines provided by the usb-storage standard core */
181 #ifdef CONFIG_PM
182 void rts51x_try_to_exit_ss(struct rts51x_chip *chip);
184 int rts51x_resume(struct usb_interface *iface);
185 int 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 
193 
194 #endif /* __RTS51X_H */