xref: /utopia/UTPA2-700.0.x/modules/usb/drv/usb_ecos/newhost/drvMassStor.h (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1*53ee8cc1Swenshuai.xi //<MStar Software>
2*53ee8cc1Swenshuai.xi //******************************************************************************
3*53ee8cc1Swenshuai.xi // MStar Software
4*53ee8cc1Swenshuai.xi // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5*53ee8cc1Swenshuai.xi // All software, firmware and related documentation herein ("MStar Software") are
6*53ee8cc1Swenshuai.xi // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7*53ee8cc1Swenshuai.xi // law, including, but not limited to, copyright law and international treaties.
8*53ee8cc1Swenshuai.xi // Any use, modification, reproduction, retransmission, or republication of all
9*53ee8cc1Swenshuai.xi // or part of MStar Software is expressly prohibited, unless prior written
10*53ee8cc1Swenshuai.xi // permission has been granted by MStar.
11*53ee8cc1Swenshuai.xi //
12*53ee8cc1Swenshuai.xi // By accessing, browsing and/or using MStar Software, you acknowledge that you
13*53ee8cc1Swenshuai.xi // have read, understood, and agree, to be bound by below terms ("Terms") and to
14*53ee8cc1Swenshuai.xi // comply with all applicable laws and regulations:
15*53ee8cc1Swenshuai.xi //
16*53ee8cc1Swenshuai.xi // 1. MStar shall retain any and all right, ownership and interest to MStar
17*53ee8cc1Swenshuai.xi //    Software and any modification/derivatives thereof.
18*53ee8cc1Swenshuai.xi //    No right, ownership, or interest to MStar Software and any
19*53ee8cc1Swenshuai.xi //    modification/derivatives thereof is transferred to you under Terms.
20*53ee8cc1Swenshuai.xi //
21*53ee8cc1Swenshuai.xi // 2. You understand that MStar Software might include, incorporate or be
22*53ee8cc1Swenshuai.xi //    supplied together with third party`s software and the use of MStar
23*53ee8cc1Swenshuai.xi //    Software may require additional licenses from third parties.
24*53ee8cc1Swenshuai.xi //    Therefore, you hereby agree it is your sole responsibility to separately
25*53ee8cc1Swenshuai.xi //    obtain any and all third party right and license necessary for your use of
26*53ee8cc1Swenshuai.xi //    such third party`s software.
27*53ee8cc1Swenshuai.xi //
28*53ee8cc1Swenshuai.xi // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29*53ee8cc1Swenshuai.xi //    MStar`s confidential information and you agree to keep MStar`s
30*53ee8cc1Swenshuai.xi //    confidential information in strictest confidence and not disclose to any
31*53ee8cc1Swenshuai.xi //    third party.
32*53ee8cc1Swenshuai.xi //
33*53ee8cc1Swenshuai.xi // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34*53ee8cc1Swenshuai.xi //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35*53ee8cc1Swenshuai.xi //    without limitation, any warranties of merchantability, non-infringement of
36*53ee8cc1Swenshuai.xi //    intellectual property rights, fitness for a particular purpose, error free
37*53ee8cc1Swenshuai.xi //    and in conformity with any international standard.  You agree to waive any
38*53ee8cc1Swenshuai.xi //    claim against MStar for any loss, damage, cost or expense that you may
39*53ee8cc1Swenshuai.xi //    incur related to your use of MStar Software.
40*53ee8cc1Swenshuai.xi //    In no event shall MStar be liable for any direct, indirect, incidental or
41*53ee8cc1Swenshuai.xi //    consequential damages, including without limitation, lost of profit or
42*53ee8cc1Swenshuai.xi //    revenues, lost or damage of data, and unauthorized system use.
43*53ee8cc1Swenshuai.xi //    You agree that this Section 4 shall still apply without being affected
44*53ee8cc1Swenshuai.xi //    even if MStar Software has been modified by MStar in accordance with your
45*53ee8cc1Swenshuai.xi //    request or instruction for your use, except otherwise agreed by both
46*53ee8cc1Swenshuai.xi //    parties in writing.
47*53ee8cc1Swenshuai.xi //
48*53ee8cc1Swenshuai.xi // 5. If requested, MStar may from time to time provide technical supports or
49*53ee8cc1Swenshuai.xi //    services in relation with MStar Software to you for your use of
50*53ee8cc1Swenshuai.xi //    MStar Software in conjunction with your or your customer`s product
51*53ee8cc1Swenshuai.xi //    ("Services").
52*53ee8cc1Swenshuai.xi //    You understand and agree that, except otherwise agreed by both parties in
53*53ee8cc1Swenshuai.xi //    writing, Services are provided on an "AS IS" basis and the warranty
54*53ee8cc1Swenshuai.xi //    disclaimer set forth in Section 4 above shall apply.
55*53ee8cc1Swenshuai.xi //
56*53ee8cc1Swenshuai.xi // 6. Nothing contained herein shall be construed as by implication, estoppels
57*53ee8cc1Swenshuai.xi //    or otherwise:
58*53ee8cc1Swenshuai.xi //    (a) conferring any license or right to use MStar name, trademark, service
59*53ee8cc1Swenshuai.xi //        mark, symbol or any other identification;
60*53ee8cc1Swenshuai.xi //    (b) obligating MStar or any of its affiliates to furnish any person,
61*53ee8cc1Swenshuai.xi //        including without limitation, you and your customers, any assistance
62*53ee8cc1Swenshuai.xi //        of any kind whatsoever, or any information; or
63*53ee8cc1Swenshuai.xi //    (c) conferring any license or right under any intellectual property right.
64*53ee8cc1Swenshuai.xi //
65*53ee8cc1Swenshuai.xi // 7. These terms shall be governed by and construed in accordance with the laws
66*53ee8cc1Swenshuai.xi //    of Taiwan, R.O.C., excluding its conflict of law rules.
67*53ee8cc1Swenshuai.xi //    Any and all dispute arising out hereof or related hereto shall be finally
68*53ee8cc1Swenshuai.xi //    settled by arbitration referred to the Chinese Arbitration Association,
69*53ee8cc1Swenshuai.xi //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70*53ee8cc1Swenshuai.xi //    Rules of the Association by three (3) arbitrators appointed in accordance
71*53ee8cc1Swenshuai.xi //    with the said Rules.
72*53ee8cc1Swenshuai.xi //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73*53ee8cc1Swenshuai.xi //    be English.
74*53ee8cc1Swenshuai.xi //    The arbitration award shall be final and binding to both parties.
75*53ee8cc1Swenshuai.xi //
76*53ee8cc1Swenshuai.xi //******************************************************************************
77*53ee8cc1Swenshuai.xi //<MStar Software>
78*53ee8cc1Swenshuai.xi 
79*53ee8cc1Swenshuai.xi #ifndef _USB_H_
80*53ee8cc1Swenshuai.xi #define _USB_H_
81*53ee8cc1Swenshuai.xi 
82*53ee8cc1Swenshuai.xi #include <MsTypes.h>
83*53ee8cc1Swenshuai.xi #include "include/drvUSBHost.h"
84*53ee8cc1Swenshuai.xi #include "include/drvCompletion.h"
85*53ee8cc1Swenshuai.xi #include "include/drvBitops.h"
86*53ee8cc1Swenshuai.xi #include "drvUsbHostConfig.h"
87*53ee8cc1Swenshuai.xi #include "drvMSC.h"
88*53ee8cc1Swenshuai.xi 
89*53ee8cc1Swenshuai.xi struct ms_usdata;
90*53ee8cc1Swenshuai.xi struct stUnusual_dev
91*53ee8cc1Swenshuai.xi {
92*53ee8cc1Swenshuai.xi     const char* vendorName;
93*53ee8cc1Swenshuai.xi     const char* productName;
94*53ee8cc1Swenshuai.xi     unsigned char  useProtocol;
95*53ee8cc1Swenshuai.xi     unsigned char  useTransport;
96*53ee8cc1Swenshuai.xi     int (*initFunction)(struct ms_usdata *);
97*53ee8cc1Swenshuai.xi     U32 flags;
98*53ee8cc1Swenshuai.xi };
99*53ee8cc1Swenshuai.xi 
100*53ee8cc1Swenshuai.xi /* usb storage flag, bit indicator */
101*53ee8cc1Swenshuai.xi #define MS_SINGLE_LUN      0x00000001
102*53ee8cc1Swenshuai.xi #define MS_SCM_MULT_TARG   0x00000020
103*53ee8cc1Swenshuai.xi #define MS_FIX_INQUIRY     0x00000040
104*53ee8cc1Swenshuai.xi #define MS_FIX_CAPACITY    0x00000080
105*53ee8cc1Swenshuai.xi 
106*53ee8cc1Swenshuai.xi /* usb storage flag, bit indicator shift */
107*53ee8cc1Swenshuai.xi #define MS_IDX_URB_ACTIVE	    18
108*53ee8cc1Swenshuai.xi #define MS_IDX_ABORTING             20
109*53ee8cc1Swenshuai.xi #define MS_IDX_DISCONNECTING        21
110*53ee8cc1Swenshuai.xi #define MS_IDX_RESETTING            22
111*53ee8cc1Swenshuai.xi 
112*53ee8cc1Swenshuai.xi #define NO_SUBMIT   ((1UL << MS_IDX_ABORTING) | \
113*53ee8cc1Swenshuai.xi             (1UL << MS_IDX_DISCONNECTING) | (1UL << MS_IDX_RESETTING))
114*53ee8cc1Swenshuai.xi 
115*53ee8cc1Swenshuai.xi /* usb storage current operating state */
116*53ee8cc1Swenshuai.xi //#define IDLE_STATE          1 // there is the same copy in the drvKernel.h
117*53ee8cc1Swenshuai.xi //#define RUNNING_STATE       2
118*53ee8cc1Swenshuai.xi //#define RESETTING_STATE     3
119*53ee8cc1Swenshuai.xi //#define ABORTING_STATE      4
120*53ee8cc1Swenshuai.xi 
121*53ee8cc1Swenshuai.xi #define MAX_USB_MSC_LUNS    8
122*53ee8cc1Swenshuai.xi 
123*53ee8cc1Swenshuai.xi #define MS_IOBUF_SIZE   64 // there is the same copy in the drvKernel.h
124*53ee8cc1Swenshuai.xi 
125*53ee8cc1Swenshuai.xi typedef int (*trans_cmnd)(stCmd_scsi*, struct ms_usdata*);
126*53ee8cc1Swenshuai.xi typedef int (*trans_reset)(struct ms_usdata*);
127*53ee8cc1Swenshuai.xi typedef void (*proto_cmnd)(stCmd_scsi*, struct ms_usdata*);
128*53ee8cc1Swenshuai.xi typedef void (*extra_data_destructor)(void *);
129*53ee8cc1Swenshuai.xi 
130*53ee8cc1Swenshuai.xi struct ms_usdata
131*53ee8cc1Swenshuai.xi {
132*53ee8cc1Swenshuai.xi     S32     dev_mutex;
133*53ee8cc1Swenshuai.xi     struct usb_device   *pusb_dev;
134*53ee8cc1Swenshuai.xi     struct usb_interface    *pusb_intf;
135*53ee8cc1Swenshuai.xi     struct stUnusual_dev   *unusual_dev;
136*53ee8cc1Swenshuai.xi     U32     flags;
137*53ee8cc1Swenshuai.xi     U32     bulk_send_pipe;
138*53ee8cc1Swenshuai.xi     U32     bulk_recv_pipe;
139*53ee8cc1Swenshuai.xi     U32     ctrl_send_pipe;
140*53ee8cc1Swenshuai.xi     U32     ctrl_recv_pipe;
141*53ee8cc1Swenshuai.xi     U32     int_recv_pipe;
142*53ee8cc1Swenshuai.xi     char            vendor[MSC_STRING_LEN];
143*53ee8cc1Swenshuai.xi     char            product[MSC_STRING_LEN];
144*53ee8cc1Swenshuai.xi     char            serial[MSC_STRING_LEN];
145*53ee8cc1Swenshuai.xi     unsigned char           subclass;
146*53ee8cc1Swenshuai.xi     unsigned char           protocol;
147*53ee8cc1Swenshuai.xi     unsigned char           max_lun;
148*53ee8cc1Swenshuai.xi     unsigned char           ifnum;  //interface number
149*53ee8cc1Swenshuai.xi     unsigned char           bInterval_ep;
150*53ee8cc1Swenshuai.xi     trans_cmnd      transport;
151*53ee8cc1Swenshuai.xi     trans_reset     transport_reset;
152*53ee8cc1Swenshuai.xi     proto_cmnd      proto_handler;
153*53ee8cc1Swenshuai.xi     stCmd_scsi      srb;
154*53ee8cc1Swenshuai.xi     Scsi_Device     device;
155*53ee8cc1Swenshuai.xi     //int             usb_state; // NUSED
156*53ee8cc1Swenshuai.xi     struct urb      *current_urb;
157*53ee8cc1Swenshuai.xi     //struct urb      *data_urb; // NUSED
158*53ee8cc1Swenshuai.xi     //struct urb      *status_urb; // NUSED
159*53ee8cc1Swenshuai.xi     struct usb_ctrlrequest  *cr;
160*53ee8cc1Swenshuai.xi     unsigned char   *iobuf;
161*53ee8cc1Swenshuai.xi     dma_addr_t      cr_dma;
162*53ee8cc1Swenshuai.xi     dma_addr_t      iobuf_dma;
163*53ee8cc1Swenshuai.xi     //struct stCompletion   notify; // NUSED
164*53ee8cc1Swenshuai.xi     void            *extra;
165*53ee8cc1Swenshuai.xi     extra_data_destructor	extra_destructor;
166*53ee8cc1Swenshuai.xi 
167*53ee8cc1Swenshuai.xi     BOOL bDevInit;
168*53ee8cc1Swenshuai.xi     struct LUN_Device* msc_device;
169*53ee8cc1Swenshuai.xi 
170*53ee8cc1Swenshuai.xi     unsigned char   ustor_id;
171*53ee8cc1Swenshuai.xi     unsigned char   host_id;
172*53ee8cc1Swenshuai.xi };
173*53ee8cc1Swenshuai.xi 
174*53ee8cc1Swenshuai.xi struct LUN_Device
175*53ee8cc1Swenshuai.xi {
176*53ee8cc1Swenshuai.xi     unsigned char u8LunNum;
177*53ee8cc1Swenshuai.xi     unsigned char u8DevType;
178*53ee8cc1Swenshuai.xi     U32 u32BlockSize;
179*53ee8cc1Swenshuai.xi     U32 u32BlockSize_log2;
180*53ee8cc1Swenshuai.xi     U32 u32BlockTotalNum;
181*53ee8cc1Swenshuai.xi     BOOL bDeviceReady;
182*53ee8cc1Swenshuai.xi     BOOL bWriteProtect;
183*53ee8cc1Swenshuai.xi     BOOL bFSInit;
184*53ee8cc1Swenshuai.xi };
185*53ee8cc1Swenshuai.xi 
186*53ee8cc1Swenshuai.xi extern struct usb_driver usb_storage_driver;
187*53ee8cc1Swenshuai.xi 
188*53ee8cc1Swenshuai.xi #define SupportOtherDevice	1
189*53ee8cc1Swenshuai.xi 
190*53ee8cc1Swenshuai.xi extern int ms_usb_msc_control_thread(void * __us);
191*53ee8cc1Swenshuai.xi extern struct ms_usdata *Mass_stor_us[NUM_OF_ROOT_HUB*MAX_USTOR];
192*53ee8cc1Swenshuai.xi 
Clr_Stor_Dev_Info(MS_U8 us_id)193*53ee8cc1Swenshuai.xi static inline   void Clr_Stor_Dev_Info(MS_U8 us_id)
194*53ee8cc1Swenshuai.xi {
195*53ee8cc1Swenshuai.xi     Mass_stor_us[us_id] = NULL;
196*53ee8cc1Swenshuai.xi }
197*53ee8cc1Swenshuai.xi 
Is_Stor_Dev_Info_Valid(MS_U8 us_id)198*53ee8cc1Swenshuai.xi static inline BOOL Is_Stor_Dev_Info_Valid(MS_U8 us_id)
199*53ee8cc1Swenshuai.xi {
200*53ee8cc1Swenshuai.xi     return (Mass_stor_us[us_id] != NULL);
201*53ee8cc1Swenshuai.xi }
202*53ee8cc1Swenshuai.xi 
Is_Stor_Dev_Init(MS_U8 us_id)203*53ee8cc1Swenshuai.xi static inline BOOL Is_Stor_Dev_Init(MS_U8 us_id)
204*53ee8cc1Swenshuai.xi {
205*53ee8cc1Swenshuai.xi     return (Mass_stor_us[us_id] != NULL ? Mass_stor_us[us_id]->bDevInit : FALSE);
206*53ee8cc1Swenshuai.xi }
207*53ee8cc1Swenshuai.xi 
Set_Stor_Dev_Init(MS_U8 us_id,BOOL bInit)208*53ee8cc1Swenshuai.xi static inline void Set_Stor_Dev_Init(MS_U8 us_id, BOOL bInit)
209*53ee8cc1Swenshuai.xi {
210*53ee8cc1Swenshuai.xi     if (Mass_stor_us[us_id])
211*53ee8cc1Swenshuai.xi         Mass_stor_us[us_id]->bDevInit = bInit;
212*53ee8cc1Swenshuai.xi }
213*53ee8cc1Swenshuai.xi 
Get_Stor_Max_Lun(MS_U8 us_id)214*53ee8cc1Swenshuai.xi static inline unsigned char Get_Stor_Max_Lun(MS_U8 us_id)
215*53ee8cc1Swenshuai.xi {
216*53ee8cc1Swenshuai.xi     return (Mass_stor_us[us_id] != NULL ? Mass_stor_us[us_id]->max_lun : 0);
217*53ee8cc1Swenshuai.xi }
218*53ee8cc1Swenshuai.xi 
219*53ee8cc1Swenshuai.xi int ms_ioctl_issue_ctrl(struct ms_usdata *ms_us, void *pData);
220*53ee8cc1Swenshuai.xi int ms_ioctl_issue_bulk(struct ms_usdata *ms_us, void *pData);
221*53ee8cc1Swenshuai.xi bool quirk_bypass_stage(struct ms_usdata *ms_us, U32 stage_flag);
222*53ee8cc1Swenshuai.xi void quirk_list_init(void);
223*53ee8cc1Swenshuai.xi int quirk_list_add_3g(U32 vid_pid);
224*53ee8cc1Swenshuai.xi 
225*53ee8cc1Swenshuai.xi #define QUIRK_IGNORE_TUR        (BIT0)
226*53ee8cc1Swenshuai.xi #define QUIRK_IGNORE_CD_ROM     (BIT1)
227*53ee8cc1Swenshuai.xi #define QUIRK_IGNORE_RD_CAP     (BIT2)
228*53ee8cc1Swenshuai.xi #define QUIRK_IGNORE_MOD_SENSE  (BIT3)
229*53ee8cc1Swenshuai.xi 
230*53ee8cc1Swenshuai.xi #endif
231