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 #ifndef _USB_H_
80 #define _USB_H_
81
82 #include <MsTypes.h>
83 #include "include/drvUSBHost.h"
84 #include "include/drvCompletion.h"
85 #include "include/drvBitops.h"
86 #include "drvUsbHostConfig.h"
87 #include "drvMSC.h"
88
89 struct ms_usdata;
90 struct stUnusual_dev
91 {
92 const char* vendorName;
93 const char* productName;
94 unsigned char useProtocol;
95 unsigned char useTransport;
96 int (*initFunction)(struct ms_usdata *);
97 U32 flags;
98 };
99
100 /* usb storage flag, bit indicator */
101 #define MS_SINGLE_LUN 0x00000001
102 #define MS_SCM_MULT_TARG 0x00000020
103 #define MS_FIX_INQUIRY 0x00000040
104 #define MS_FIX_CAPACITY 0x00000080
105
106 /* usb storage flag, bit indicator shift */
107 #define MS_IDX_URB_ACTIVE 18
108 #define MS_IDX_ABORTING 20
109 #define MS_IDX_DISCONNECTING 21
110 #define MS_IDX_RESETTING 22
111
112 #define NO_SUBMIT ((1UL << MS_IDX_ABORTING) | \
113 (1UL << MS_IDX_DISCONNECTING) | (1UL << MS_IDX_RESETTING))
114
115 /* usb storage current operating state */
116 //#define IDLE_STATE 1 // there is the same copy in the drvKernel.h
117 //#define RUNNING_STATE 2
118 //#define RESETTING_STATE 3
119 //#define ABORTING_STATE 4
120
121 #define MAX_USB_MSC_LUNS 8
122
123 #define MS_IOBUF_SIZE 64 // there is the same copy in the drvKernel.h
124
125 typedef int (*trans_cmnd)(stCmd_scsi*, struct ms_usdata*);
126 typedef int (*trans_reset)(struct ms_usdata*);
127 typedef void (*proto_cmnd)(stCmd_scsi*, struct ms_usdata*);
128 typedef void (*extra_data_destructor)(void *);
129
130 struct ms_usdata
131 {
132 S32 dev_mutex;
133 struct usb_device *pusb_dev;
134 struct usb_interface *pusb_intf;
135 struct stUnusual_dev *unusual_dev;
136 U32 flags;
137 U32 bulk_send_pipe;
138 U32 bulk_recv_pipe;
139 U32 ctrl_send_pipe;
140 U32 ctrl_recv_pipe;
141 U32 int_recv_pipe;
142 char vendor[MSC_STRING_LEN];
143 char product[MSC_STRING_LEN];
144 char serial[MSC_STRING_LEN];
145 unsigned char subclass;
146 unsigned char protocol;
147 unsigned char max_lun;
148 unsigned char ifnum; //interface number
149 unsigned char bInterval_ep;
150 trans_cmnd transport;
151 trans_reset transport_reset;
152 proto_cmnd proto_handler;
153 stCmd_scsi srb;
154 Scsi_Device device;
155 //int usb_state; // NUSED
156 struct urb *current_urb;
157 //struct urb *data_urb; // NUSED
158 //struct urb *status_urb; // NUSED
159 struct usb_ctrlrequest *cr;
160 unsigned char *iobuf;
161 dma_addr_t cr_dma;
162 dma_addr_t iobuf_dma;
163 //struct stCompletion notify; // NUSED
164 void *extra;
165 extra_data_destructor extra_destructor;
166
167 BOOL bDevInit;
168 struct LUN_Device* msc_device;
169
170 unsigned char ustor_id;
171 unsigned char host_id;
172 };
173
174 struct LUN_Device
175 {
176 unsigned char u8LunNum;
177 unsigned char u8DevType;
178 U32 u32BlockSize;
179 U32 u32BlockSize_log2;
180 U32 u32BlockTotalNum;
181 BOOL bDeviceReady;
182 BOOL bWriteProtect;
183 BOOL bFSInit;
184 };
185
186 extern struct usb_driver usb_storage_driver;
187
188 #define SupportOtherDevice 1
189
190 extern int ms_usb_msc_control_thread(void * __us);
191 extern struct ms_usdata *Mass_stor_us[NUM_OF_ROOT_HUB*MAX_USTOR];
192
Clr_Stor_Dev_Info(MS_U8 us_id)193 static inline void Clr_Stor_Dev_Info(MS_U8 us_id)
194 {
195 Mass_stor_us[us_id] = NULL;
196 }
197
Is_Stor_Dev_Info_Valid(MS_U8 us_id)198 static inline BOOL Is_Stor_Dev_Info_Valid(MS_U8 us_id)
199 {
200 return (Mass_stor_us[us_id] != NULL);
201 }
202
Is_Stor_Dev_Init(MS_U8 us_id)203 static inline BOOL Is_Stor_Dev_Init(MS_U8 us_id)
204 {
205 return (Mass_stor_us[us_id] != NULL ? Mass_stor_us[us_id]->bDevInit : FALSE);
206 }
207
Set_Stor_Dev_Init(MS_U8 us_id,BOOL bInit)208 static inline void Set_Stor_Dev_Init(MS_U8 us_id, BOOL bInit)
209 {
210 if (Mass_stor_us[us_id])
211 Mass_stor_us[us_id]->bDevInit = bInit;
212 }
213
Get_Stor_Max_Lun(MS_U8 us_id)214 static inline unsigned char Get_Stor_Max_Lun(MS_U8 us_id)
215 {
216 return (Mass_stor_us[us_id] != NULL ? Mass_stor_us[us_id]->max_lun : 0);
217 }
218
219 int ms_ioctl_issue_ctrl(struct ms_usdata *ms_us, void *pData);
220 int ms_ioctl_issue_bulk(struct ms_usdata *ms_us, void *pData);
221 bool quirk_bypass_stage(struct ms_usdata *ms_us, U32 stage_flag);
222 void quirk_list_init(void);
223 int quirk_list_add_3g(U32 vid_pid);
224
225 #define QUIRK_IGNORE_TUR (BIT0)
226 #define QUIRK_IGNORE_CD_ROM (BIT1)
227 #define QUIRK_IGNORE_RD_CAP (BIT2)
228 #define QUIRK_IGNORE_MOD_SENSE (BIT3)
229
230 #endif
231