1/*******************************************************************************
2**Copyright (c) 2014 PMC-Sierra, Inc.  All rights reserved.
3 *
4*Redistribution and use in source and binary forms, with or without modification, are permitted provided
5*that the following conditions are met:
6*1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7*2. Redistributions in binary form must reproduce the above copyright notice,
8*this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9*
10*THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
11*
12*INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
13*ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
14*SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
15*OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
16*WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
17*THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
18**
19**
20*******************************************************************************/
21
22//void agtiapi_cam_init(struct agtiapi_softc *sc);
23//void agtiapi_cam_poll( struct cam_sim *asim );
24int agtiapi_QueueCmnd_(struct agtiapi_softc *, union ccb * );
25int agtiapi_alloc_ostimem(struct agtiapi_softc *);
26int agtiapi_alloc_requests(struct agtiapi_softc *);
27static int agtiapi_PrepareSGList(struct agtiapi_softc *, ccb_t *);
28static void agtiapi_PrepareSGListCB( void *arg,
29                                     bus_dma_segment_t *dm_segs,
30                                     int nseg,
31                                     int error );
32static int agtiapi_PrepareSMPSGList(struct agtiapi_softc *pmcsc, ccb_t *);
33static void agtiapi_PrepareSMPSGListCB( void *arg,
34                                        bus_dma_segment_t *dm_segs,
35                                        int nsegs,
36                                        int error );
37int agtiapi_eh_HostReset( struct agtiapi_softc *pmcsc, union ccb *cmnd );
38STATIC void agtiapi_FreeCCB(struct agtiapi_softc *pmcsc, pccb_t pccb);
39STATIC void agtiapi_FreeSMPCCB(struct agtiapi_softc *pmcsc, pccb_t pccb);
40STATIC void agtiapi_FreeTMCCB(struct agtiapi_softc *pmcsc, pccb_t pccb);
41STATIC pccb_t agtiapi_GetCCB(struct agtiapi_softc *pmcsc);
42void agtiapi_SetLunField( ccb_t *pccb );
43STATIC void agtiapi_QueueCCB( struct agtiapi_softc *pmcsc,
44                              pccb_t *phead,
45                              pccb_t *ptail,
46#ifdef AGTIAPI_LOCAL_LOCK
47                              struct mtx *mutex,
48#endif
49                              ccb_t *pccb );
50static int agtiapi_QueueSMP(struct agtiapi_softc *, union ccb * );
51STATIC void agtiapi_StartIO(struct agtiapi_softc *pmcsc);
52STATIC void agtiapi_StartSMP(struct agtiapi_softc *pmcsc);
53STATIC void agtiapi_DumpCCB(ccb_t *pccb);
54STATIC void agtiapi_Done(struct agtiapi_softc *pmcsc, ccb_t *pccb);
55STATIC void agtiapi_SMPDone(struct agtiapi_softc *pmcsc, ccb_t *pccb);
56// void agtiapi_LogEvent(ag_card_t *, U16, U16, U32 *, U08, S08 *, ...);
57STATIC U32 agtiapi_CheckError(struct agtiapi_softc *pmcsc, ccb_t *pccb);
58STATIC U32 agtiapi_CheckSMPError(struct agtiapi_softc *pmcsc, ccb_t *pccb);
59STATIC void agtiapi_Retry(struct agtiapi_softc *pmcsc, ccb_t *pccb);
60static void agtiapi_scan(struct agtiapi_softc *pmcsc);
61STATIC int agtiapi_FindWWNListNext( ag_tgt_map_t  * pWWNList, int lstMax );
62STATIC U32 agtiapi_GetDevHandle(struct agtiapi_softc *pmcsc,
63				ag_portal_info_t *pPortalInfo,
64				U32 eType, U32 eStatus);
65
66int agtiapi_StartTM(struct agtiapi_softc *pCard, ccb_t *pccb);
67
68STATIC void wwnprintk(unsigned char *name, int len);
69STATIC int wwncpy(ag_device_t      *pDevice);
70
71STATIC void agtiapi_DiscoverTgt(struct agtiapi_softc *pCard);
72agBOOLEAN agtiapi_CheckCB( struct agtiapi_softc *pCard,
73                           U32 milisec,
74                           U32 flag,
75                           volatile U32 *pStatus );
76STATIC agBOOLEAN  agtiapi_DeQueueCCB( struct agtiapi_softc *,
77                                      pccb_t *,
78                                      pccb_t *,
79#ifdef AGTIAPI_LOCAL_LOCK
80                                      struct mtx *,
81#endif
82                                      ccb_t * );
83
84void agtiapi_CheckAllVectors( struct agtiapi_softc *pCard, bit32 context );
85
86STATIC U32 agtiapi_InitCCBs( struct agtiapi_softc *pCard,
87                             int tgtCount,
88                             int tid );
89STATIC void agtiapi_PrepCCBs( struct agtiapi_softc *pCard,
90                              ccb_hdr_t *hdr,
91                              U32 size,
92                              U32 max_ccb,
93                              int tid );
94
95
96#ifdef LINUX_PERBI_SUPPORT
97void  agtiapi_GetWWNMappings( struct agtiapi_softc *, ag_mapping_t * );
98//#ifndef HOTPLUG_SUPPORT
99STATIC void agtiapi_MapWWNList( struct agtiapi_softc *pCard );
100//#endif
101#endif
102
103STATIC void agtiapi_ReleaseCCBs( struct agtiapi_softc *pCard );
104STATIC void agtiapi_clrRmScan(   struct agtiapi_softc *pCard );
105STATIC void agtiapi_TITimer(    void *data );
106STATIC void agtiapi_devRmCheck( void *data );
107
108int agtiapi_ReleaseHBA( device_t dev );
109
110void agtiapi_IntrHandler0(  void *arg );
111void agtiapi_IntrHandler1(  void *arg );
112void agtiapi_IntrHandler2(  void *arg );
113void agtiapi_IntrHandler3(  void *arg );
114void agtiapi_IntrHandler4(  void *arg );
115void agtiapi_IntrHandler5(  void *arg );
116void agtiapi_IntrHandler6(  void *arg );
117void agtiapi_IntrHandler7(  void *arg );
118void agtiapi_IntrHandler8(  void *arg );
119void agtiapi_IntrHandler9(  void *arg );
120void agtiapi_IntrHandler10( void *arg );
121void agtiapi_IntrHandler11( void *arg );
122void agtiapi_IntrHandler12( void *arg );
123void agtiapi_IntrHandler13( void *arg );
124void agtiapi_IntrHandler14( void *arg );
125void agtiapi_IntrHandler15( void *arg );
126void agtiapi_IntrHandlerx_( void *arg, int index );
127STATIC agBOOLEAN agtiapi_InitCardSW( struct agtiapi_softc *pmsc );
128STATIC agBOOLEAN agtiapi_InitCardHW( struct agtiapi_softc *pmsc );
129STATIC void agtiapi_DumpCDB( const char *ptitle, ccb_t *pccb );
130void agtiapi_hexdump( const char *ptitle, bit8 *pbuf, int len );
131static void agtiapi_SglMemoryCB( void *arg,
132                                 bus_dma_segment_t *dm_segs,
133                                 int nseg,
134                                 int error );
135static void agtiapi_MemoryCB( void *arg,
136                              bus_dma_segment_t *dm_segs,
137                              int nseg,
138                              int error );
139U32 agtiapi_ResetCard( struct agtiapi_softc *pCard, unsigned long *flags );
140int agtiapi_DoSoftReset( struct agtiapi_softc *pmcsc );
141
142STATIC void agtiapi_FlushCCBs(   struct agtiapi_softc *pCard, U32 flag );
143
144