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 );
24 int agtiapi_QueueCmnd_(struct agtiapi_softc *, union ccb * );
25 int agtiapi_alloc_ostimem(struct agtiapi_softc *);
26 int agtiapi_alloc_requests(struct agtiapi_softc *);
27 static int agtiapi_PrepareSGList(struct agtiapi_softc *, ccb_t *);
28 static void agtiapi_PrepareSGListCB( void *arg,
29                                      bus_dma_segment_t *dm_segs,
30                                      int nseg,
31                                      int error );
32 static int agtiapi_PrepareSMPSGList(struct agtiapi_softc *pmcsc, ccb_t *);
33 static void agtiapi_PrepareSMPSGListCB( void *arg,
34                                         bus_dma_segment_t *dm_segs,
35                                         int nsegs,
36                                         int error );
37 int agtiapi_eh_HostReset( struct agtiapi_softc *pmcsc, union ccb *cmnd );
38 STATIC void agtiapi_FreeCCB(struct agtiapi_softc *pmcsc, pccb_t pccb);
39 STATIC void agtiapi_FreeSMPCCB(struct agtiapi_softc *pmcsc, pccb_t pccb);
40 STATIC void agtiapi_FreeTMCCB(struct agtiapi_softc *pmcsc, pccb_t pccb);
41 STATIC pccb_t agtiapi_GetCCB(struct agtiapi_softc *pmcsc);
42 void agtiapi_SetLunField( ccb_t *pccb );
43 STATIC 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 );
50 static int agtiapi_QueueSMP(struct agtiapi_softc *, union ccb * );
51 STATIC void agtiapi_StartIO(struct agtiapi_softc *pmcsc);
52 STATIC void agtiapi_StartSMP(struct agtiapi_softc *pmcsc);
53 STATIC void agtiapi_DumpCCB(ccb_t *pccb);
54 STATIC void agtiapi_Done(struct agtiapi_softc *pmcsc, ccb_t *pccb);
55 STATIC void agtiapi_SMPDone(struct agtiapi_softc *pmcsc, ccb_t *pccb);
56 // void agtiapi_LogEvent(ag_card_t *, U16, U16, U32 *, U08, S08 *, ...);
57 STATIC U32 agtiapi_CheckError(struct agtiapi_softc *pmcsc, ccb_t *pccb);
58 STATIC U32 agtiapi_CheckSMPError(struct agtiapi_softc *pmcsc, ccb_t *pccb);
59 STATIC void agtiapi_Retry(struct agtiapi_softc *pmcsc, ccb_t *pccb);
60 static void agtiapi_scan(struct agtiapi_softc *pmcsc);
61 STATIC int agtiapi_FindWWNListNext( ag_tgt_map_t  * pWWNList, int lstMax );
62 STATIC U32 agtiapi_GetDevHandle(struct agtiapi_softc *pmcsc,
63 				ag_portal_info_t *pPortalInfo,
64 				U32 eType, U32 eStatus);
65 
66 int agtiapi_StartTM(struct agtiapi_softc *pCard, ccb_t *pccb);
67 
68 STATIC void wwnprintk(unsigned char *name, int len);
69 STATIC int wwncpy(ag_device_t      *pDevice);
70 
71 STATIC void agtiapi_DiscoverTgt(struct agtiapi_softc *pCard);
72 agBOOLEAN agtiapi_CheckCB( struct agtiapi_softc *pCard,
73                            U32 milisec,
74                            U32 flag,
75                            volatile U32 *pStatus );
76 STATIC 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 
84 void agtiapi_CheckAllVectors( struct agtiapi_softc *pCard, bit32 context );
85 
86 STATIC U32 agtiapi_InitCCBs( struct agtiapi_softc *pCard,
87                              int tgtCount,
88                              int tid );
89 STATIC 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
97 void  agtiapi_GetWWNMappings( struct agtiapi_softc *, ag_mapping_t * );
98 //#ifndef HOTPLUG_SUPPORT
99 STATIC void agtiapi_MapWWNList( struct agtiapi_softc *pCard );
100 //#endif
101 #endif
102 
103 STATIC void agtiapi_ReleaseCCBs( struct agtiapi_softc *pCard );
104 STATIC void agtiapi_clrRmScan(   struct agtiapi_softc *pCard );
105 STATIC void agtiapi_TITimer(    void *data );
106 STATIC void agtiapi_devRmCheck( void *data );
107 
108 int agtiapi_ReleaseHBA( device_t dev );
109 
110 void agtiapi_IntrHandler0(  void *arg );
111 void agtiapi_IntrHandler1(  void *arg );
112 void agtiapi_IntrHandler2(  void *arg );
113 void agtiapi_IntrHandler3(  void *arg );
114 void agtiapi_IntrHandler4(  void *arg );
115 void agtiapi_IntrHandler5(  void *arg );
116 void agtiapi_IntrHandler6(  void *arg );
117 void agtiapi_IntrHandler7(  void *arg );
118 void agtiapi_IntrHandler8(  void *arg );
119 void agtiapi_IntrHandler9(  void *arg );
120 void agtiapi_IntrHandler10( void *arg );
121 void agtiapi_IntrHandler11( void *arg );
122 void agtiapi_IntrHandler12( void *arg );
123 void agtiapi_IntrHandler13( void *arg );
124 void agtiapi_IntrHandler14( void *arg );
125 void agtiapi_IntrHandler15( void *arg );
126 void agtiapi_IntrHandlerx_( void *arg, int index );
127 STATIC agBOOLEAN agtiapi_InitCardSW( struct agtiapi_softc *pmsc );
128 STATIC agBOOLEAN agtiapi_InitCardHW( struct agtiapi_softc *pmsc );
129 STATIC void agtiapi_DumpCDB( const char *ptitle, ccb_t *pccb );
130 void agtiapi_hexdump( const char *ptitle, bit8 *pbuf, int len );
131 static void agtiapi_SglMemoryCB( void *arg,
132                                  bus_dma_segment_t *dm_segs,
133                                  int nseg,
134                                  int error );
135 static void agtiapi_MemoryCB( void *arg,
136                               bus_dma_segment_t *dm_segs,
137                               int nseg,
138                               int error );
139 U32 agtiapi_ResetCard( struct agtiapi_softc *pCard, unsigned long *flags );
140 int agtiapi_DoSoftReset( struct agtiapi_softc *pmcsc );
141 
142 STATIC void agtiapi_FlushCCBs(   struct agtiapi_softc *pCard, U32 flag );
143 
144