1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 // Software and any modification/derivatives thereof.
18 // No right, ownership, or interest to MStar Software and any
19 // modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 // supplied together with third party`s software and the use of MStar
23 // Software may require additional licenses from third parties.
24 // Therefore, you hereby agree it is your sole responsibility to separately
25 // obtain any and all third party right and license necessary for your use of
26 // such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 // MStar`s confidential information and you agree to keep MStar`s
30 // confidential information in strictest confidence and not disclose to any
31 // third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 // kind. Any warranties are hereby expressly disclaimed by MStar, including
35 // without limitation, any warranties of merchantability, non-infringement of
36 // intellectual property rights, fitness for a particular purpose, error free
37 // and in conformity with any international standard. You agree to waive any
38 // claim against MStar for any loss, damage, cost or expense that you may
39 // incur related to your use of MStar Software.
40 // In no event shall MStar be liable for any direct, indirect, incidental or
41 // consequential damages, including without limitation, lost of profit or
42 // revenues, lost or damage of data, and unauthorized system use.
43 // You agree that this Section 4 shall still apply without being affected
44 // even if MStar Software has been modified by MStar in accordance with your
45 // request or instruction for your use, except otherwise agreed by both
46 // parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 // services in relation with MStar Software to you for your use of
50 // MStar Software in conjunction with your or your customer`s product
51 // ("Services").
52 // You understand and agree that, except otherwise agreed by both parties in
53 // writing, Services are provided on an "AS IS" basis and the warranty
54 // disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 // or otherwise:
58 // (a) conferring any license or right to use MStar name, trademark, service
59 // mark, symbol or any other identification;
60 // (b) obligating MStar or any of its affiliates to furnish any person,
61 // including without limitation, you and your customers, any assistance
62 // of any kind whatsoever, or any information; or
63 // (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 // of Taiwan, R.O.C., excluding its conflict of law rules.
67 // Any and all dispute arising out hereof or related hereto shall be finally
68 // settled by arbitration referred to the Chinese Arbitration Association,
69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 // Rules of the Association by three (3) arbitrators appointed in accordance
71 // with the said Rules.
72 // The place of arbitration shall be in Taipei, Taiwan and the language shall
73 // be English.
74 // The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78
79
80 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
81 #ifndef _USB_H_
82 #define _USB_H_
83
84 #include <MsTypes.h>
85 #include "include/drvUSB.h"
86 #include "include/drvCompletion.h"
87 #include "drvUsbHostConfig.h"
88 #include "drvSCSI.h"
89
90 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
91
92 struct us_data;
93
94 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
95 struct us_unusual_dev
96 {
97 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
98 const char* vendorName;
99 const char* productName;
100 unsigned char useProtocol;
101 unsigned char useTransport;
102 int (*initFunction)(struct us_data *);
103 U32 flags;
104
105 };
106
107 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
108 #define US_FL_SINGLE_LUN 0x00000001
109 #define US_FL_MODE_XLATE 0
110 #define US_FL_IGNORE_SER 0
111 #define US_FL_SCM_MULT_TARG 0x00000020
112 #define US_FL_FIX_INQUIRY 0x00000040
113 #define US_FL_FIX_CAPACITY 0x00000080
114 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
115 #define US_FLIDX_URB_ACTIVE 18
116 #define US_FLIDX_SG_ACTIVE 19
117 #define US_FLIDX_ABORTING 20
118 #define US_FLIDX_DISCONNECTING 21
119 #define DONT_SUBMIT ((1UL << US_FLIDX_ABORTING) | \
120 (1UL << US_FLIDX_DISCONNECTING))
121 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
122 #define US_STATE_IDLE 1
123 #define US_STATE_RUNNING 2
124 #define US_STATE_RESETTING 3
125 #define US_STATE_ABORTING 4
126 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
127 #define MAX_USB_STOR_LUNS 8 //USB_2
128 //#define USB_STOR_STRING_LEN 32
129 #define US_IOBUF_SIZE 64
130 typedef int (*trans_cmnd)(Scsi_Cmnd*, struct us_data*);
131 typedef int (*trans_reset)(struct us_data*);
132 typedef void (*proto_cmnd)(Scsi_Cmnd*, struct us_data*);
133 typedef void (*extra_data_destructor)(void *);
134 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
135 struct us_data {
136 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
137 // struct semaphore dev_semaphore;
138 struct usb_device *pusb_dev;
139 struct usb_interface *pusb_intf;
140 struct us_unusual_dev *unusual_dev;
141 U32 flags;
142 U32 send_bulk_pipe;
143 U32 recv_bulk_pipe;
144 U32 send_ctrl_pipe;
145 U32 recv_ctrl_pipe;
146 U32 recv_intr_pipe;
147
148 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
149 char vendor[USB_STOR_STRING_LEN];
150 char product[USB_STOR_STRING_LEN];
151 char serial[USB_STOR_STRING_LEN];
152 char *transport_name;
153 char *protocol_name;
154 unsigned char subclass;
155 unsigned char protocol;
156 unsigned char max_lun;
157
158 unsigned char ifnum;
159 unsigned char ep_bInterval;
160
161 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
162 trans_cmnd transport;
163 trans_reset transport_reset;
164 proto_cmnd proto_handler;
165
166 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
167 // struct Scsi_Host *host;
168 Scsi_Cmnd srb;
169 Scsi_Device device;
170
171 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
172 // int pid;
173 int sm_state;
174
175 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
176 struct urb *current_urb;
177 struct urb *data_urb;
178 struct urb *status_urb;
179 struct usb_ctrlrequest *cr;
180 // struct usb_sg_request current_sg;
181 unsigned char *iobuf;
182 dma_addr_t cr_dma;
183 dma_addr_t iobuf_dma;
184
185 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
186 // struct semaphore sema;
187 struct completion notify;
188
189 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
190 void *extra;
191 extra_data_destructor extra_destructor;
192
193 // For one Device but have many LUN
194 BOOL bDevInit;
195 struct LUN_Device* Mass_stor_device;
196
197 unsigned char ustor_id;
198 unsigned char host_id;
199 };
200
201 struct LUN_Device
202 {
203 unsigned char u8LunNum;
204
205 unsigned char u8DevType;
206
207 // Get by READ CAPACITY command
208 U32 u32BlockSize;
209 U32 u32BlockSize_log2;
210 U32 u32BlockTotalNum;
211
212 // Get by TEST UNIT READY command
213 BOOL bDeviceReady;
214
215 // Save Write Protection information
216 BOOL bWriteProtect;
217
218 // Is File system mounted
219 BOOL bFSInit;
220 };
221
222
223 /* The structure which defines our driver */
224 extern struct usb_driver usb_storage_driver;
225
226 /* Function to fill an inquiry response. See usb.c for details */
227 // YPING : this function fill USB information into scsi inquiry data.
228 extern void fill_inquiry_response(struct us_data *us,
229 unsigned char *data, U32 data_len);
230
231 /* The scsi_lock() and scsi_unlock() macros protect the sm_state and the
232 * single queue element srb for write access */
233 #define scsi_unlock(host) spin_unlock_irq(host->host_lock)
234 #define scsi_lock(host) spin_lock_irq(host->host_lock)
235 #define sg_address(psg) (page_address((psg).page) + (psg).offset)
236
237 ///////////// YPING add define //////////////
238 #define SupportOtherDevice 1
239
240 /**
241 * test_and_clear_bit - Clear a bit and return its old value
242 * @nr: Bit to set
243 * @addr: Address to count from
244 *
245 * This operation is atomic and cannot be reordered.
246 * It also implies a memory barrier.
247 */
248 /*
249 extern int Test_and_Clear_Bit(int nr, void *addr);
250 extern int Test_Bit(int nr, long * addr);
251 */
252 extern int usb_stor_control_thread(void * __us);
253 extern int usb_stor_init(void);
254 extern void usb_stor_exit(void);
255 extern void vChk_USB_LUNs(U8 uPort);
256 extern void usb_stor_release_resources(struct us_data *us);
257 /* The structure which use to save data for mass stor */
258
259 extern struct us_data *Mass_stor_us[NUM_OF_ROOT_HUB*MAX_USTOR]; //USB_2
260
Clr_Stor_Dev_Info(MS_U8 uPort)261 static inline void Clr_Stor_Dev_Info(MS_U8 uPort)
262 {
263 Mass_stor_us[uPort] = NULL;
264 }
265
Is_Stor_Dev_Info_Valid(MS_U8 uPort)266 static inline BOOL Is_Stor_Dev_Info_Valid(MS_U8 uPort)
267 {
268 return (Mass_stor_us[uPort] != NULL);
269 }
270
Is_Stor_Dev_Init(MS_U8 uPort)271 static inline BOOL Is_Stor_Dev_Init(MS_U8 uPort)
272 {
273 return (Mass_stor_us[uPort]->bDevInit);
274 }
275
Set_Stor_Dev_Init(MS_U8 uPort,BOOL bInit)276 static inline void Set_Stor_Dev_Init(MS_U8 uPort, BOOL bInit)
277 {
278 Mass_stor_us[uPort]->bDevInit = bInit;
279 }
280
Get_Stor_Max_Lun(MS_U8 uPort)281 static inline unsigned char Get_Stor_Max_Lun(MS_U8 uPort)
282 {
283 return (Mass_stor_us[uPort]->max_lun);
284 }
285
286 ///////////// drvKernel.h /////////////
287 #define KERN_EMERG "KERN_EMERG" /* system is unusable */
288 #define KERN_ALERT "KERN_ALERT" /* action must be taken immediately */
289 #define KERN_CRIT "KERN_CRIT" /* critical conditions */
290 #define KERN_NOTICE "KERN_NOTICE" /* normal but significant condition */
291
292
293
294 #endif
295