1210006Srdivacky/*******************************************************************************
2210006Srdivacky*Copyright (c) 2014 PMC-Sierra, Inc.  All rights reserved.
3210006Srdivacky*
4210006Srdivacky*Redistribution and use in source and binary forms, with or without modification, are permitted provided
5210006Srdivacky*that the following conditions are met:
6210006Srdivacky*1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
7210006Srdivacky*following disclaimer.
8210006Srdivacky*2. Redistributions in binary form must reproduce the above copyright notice,
9210006Srdivacky*this list of conditions and the following disclaimer in the documentation and/or other materials provided
10210006Srdivacky*with the distribution.
11210006Srdivacky*
12210006Srdivacky*THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
13210006Srdivacky*WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14210006Srdivacky*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
15210006Srdivacky*FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16210006Srdivacky*NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
17210006Srdivacky*BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18210006Srdivacky*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19210006Srdivacky*SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
20210006Srdivacky*
21210006Srdivacky* $FreeBSD$
22221345Sdim*
23210006Srdivacky********************************************************************************/
24210006Srdivacky/*******************************************************************************/
25210006Srdivacky/*! \file satypes.h
26210006Srdivacky *  \brief The file defines the internal data structure types used by LL layer
27210006Srdivacky *
28221345Sdim */
29221345Sdim/*******************************************************************************/
30210006Srdivacky
31210006Srdivacky#ifndef  __SATYPES_H__
32210006Srdivacky
33221345Sdim#define __SATYPES_H__
34210006Srdivacky
35210006Srdivacky/** \brief the callback function of an timer
36210006Srdivacky *
37210006Srdivacky * the definition of the timer callback function
38210006Srdivacky */
39210006Srdivackytypedef bit32 (* agsaCallback_t) (agsaRoot_t *agRoot,
40218893Sdim                                  bit32      Event,
41218893Sdim                                  void       *Parm);
42210006Srdivacky
43210006Srdivacky/** \brief the data structure of a timer
44210006Srdivacky *
45210006Srdivacky * use to describe timer
46210006Srdivacky *
47210006Srdivacky */
48210006Srdivackytypedef struct agsaTimerDesc_s
49210006Srdivacky{
50221345Sdim  SALINK          linkNode; /**< the link node data structure of the timer */
51210006Srdivacky  bit32           valid;  /**< the valid bit of the timer descriptor */
52210006Srdivacky  bit32           timeoutTick; /**< the timeout tick of the timer */
53210006Srdivacky  agsaCallback_t  pfnTimeout; /**< the callback function fo the timer */
54210006Srdivacky  bit32           Event; /**< the event paramter of the timer callback function */
55210006Srdivacky  void *          pParm; /**< the point to the paramter passed to callback function */
56210006Srdivacky} agsaTimerDesc_t;
57218893Sdim
58218893Sdim/** \brief the port
59218893Sdim *
60210006Srdivacky * describe port data structure
61210006Srdivacky *
62210006Srdivacky */
63210006Srdivackytypedef struct agsaPort_s
64210006Srdivacky{
65210006Srdivacky  SALINK              linkNode;     /**< the link node data structure of the port */
66210006Srdivacky  agsaPortContext_t   portContext; /**< the port context of the port */
67210006Srdivacky  SALINK_LIST         listSASATADevices; /**< SAS/SATA devices list of the port */
68210006Srdivacky  bit32               phyMap[AGSA_MAX_VALID_PHYS]; /**< Boolean arrar: the Phys included in the port. */
69210006Srdivacky  bit32               status;  /**< port state */
70218893Sdim  bit32               tobedeleted;  /**< mark for deletetion after callback  */
71210006Srdivacky  bit32               portId; /** Port Id from SPC */
72210006Srdivacky  bit8                portIdx; /**< the Index of the port */
73210006Srdivacky  bit8                reserved[3];
74210006Srdivacky} agsaPort_t;
75218893Sdim
76210006Srdivacky/** \brief the phy
77210006Srdivacky *
78210006Srdivacky * phy data structure
79210006Srdivacky *
80210006Srdivacky */
81210006Srdivackytypedef struct agsaPhy_s
82210006Srdivacky{
83210006Srdivacky  agsaPort_t          *pPort; /**< pointer to the port includes the phy */
84210006Srdivacky  agsaSASIdentify_t   sasIdentify; /**< the SAS identify of the phy */
85210006Srdivacky  agsaContext_t       *agContext; /**< agContext for the Phy */
86210006Srdivacky  bit32               status; /**< the status of the phy */
87210006Srdivacky  bit8                phyId; /**< the Id of the phy */
88218893Sdim  bit8                linkstatus; /**< the link status of the phy */
89210006Srdivacky  bit8                reserved[2];
90210006Srdivacky#if defined(SALLSDK_DEBUG)
91210006Srdivacky  bit8                remoteSignature[8]; /* the remote signature of the phy is the phy is in native SATA mode */
92210006Srdivacky#endif
93210006Srdivacky} agsaPhy_t;
94210006Srdivacky
95210006Srdivacky/** \brief the LL defined SAS/SATA device information
96210006Srdivacky *
97210006Srdivacky * LL defined SAS/SATA device information
98210006Srdivacky *
99210006Srdivacky */
100210006Srdivackytypedef union agsaSASSATADevInfo_s
101210006Srdivacky{
102218893Sdim  agsaSASDeviceInfo_t   sasDeviceInfo;  /**< SAS device information of the device */
103210006Srdivacky  agsaSATADeviceInfo_t  sataDeviceInfo; /**< SATA device information of the device */
104210006Srdivacky} agsaSASSATADevInfo_t;
105210006Srdivacky
106210006Srdivacky/** \brief the LL defined device descriptor
107218893Sdim *
108210006Srdivacky * LL defined device descriptor
109210006Srdivacky *
110210006Srdivacky */
111210006Srdivackytypedef struct agsaDeviceDesc_s
112210006Srdivacky{
113210006Srdivacky  SALINK                linkNode; /**< the link node data structure of the device */
114210006Srdivacky  agsaDevHandle_t       initiatorDevHandle; /**< the device handle of an initiator device */
115210006Srdivacky  agsaDevHandle_t       targetDevHandle; /**< the device handle of a target device */
116210006Srdivacky  SALINK_LIST           pendingIORequests; /**< the pending IO requests, for SSP or SATA */
117210006Srdivacky  agsaPort_t            *pPort; /**< the port discovered the device */
118210006Srdivacky  bit8                  deviceType; /**< the device type */
119210006Srdivacky  bit8                  reserved[3];
120218893Sdim  bit32                 option;
121210006Srdivacky  bit32                 param;
122210006Srdivacky  agsaSASSATADevInfo_t  devInfo; /**< SAS/SATA device information */
123210006Srdivacky  bit32                 DeviceMapIndex;  /**< device index for device handle */
124210006Srdivacky} agsaDeviceDesc_t;
125218893Sdim
126210006Srdivacky/** \brief the LL defined IO request descriptor
127210006Srdivacky *
128210006Srdivacky * LL defined IO Request descriptor
129210006Srdivacky *
130210006Srdivacky */
131210006Srdivackytypedef struct agsaIORequestDesc_s
132210006Srdivacky{
133210006Srdivacky  SALINK            linkNode;          /**< the link node data structure of the IO request */
134218893Sdim  agsaIORequest_t   *pIORequestContext;/**< the IO request context */
135210006Srdivacky  agsaDeviceDesc_t  *pDevice;          /**< the pointer to the device, to which the request is sent */
136210006Srdivacky  agsaPort_t        *pPort;            /**< the pointer to the port - using by HW_EVENT_ACK with PHY_DOWN event */
137210006Srdivacky  ossaSSPCompletedCB_t completionCB;   /**< completion callback to be called */
138210006Srdivacky  bit32             requestType;       /**< the request type */
139218893Sdim  bit16             HwAckType;         /**< Track HW_acks */
140210006Srdivacky  bit16             SOP;               /**< SetPhyProfile page not returned in reply */
141210006Srdivacky  bit32             startTick;         /**< start time for this IO */
142210006Srdivacky  bit32             HTag;              /**< the host tag to index into the IORequest array */
143210006Srdivacky  bit8              valid;             /**< boolean flag: the request is valid */
144218893Sdim  bit8              IRmode;            /**< indirect smp response mode */
145210006Srdivacky  bit8              modePageContext;   /**< request is for security mode change */
146210006Srdivacky  bit8              DeviceInfoCmdOption;/**<  */
147210006Srdivacky#ifdef FAST_IO_TEST
148210006Srdivacky  SALINK            fastLink; /* Fast I/O's chain */
149210006Srdivacky#endif
150210006Srdivacky} agsaIORequestDesc_t;
151210006Srdivacky
152210006Srdivacky/** \brief the LL defined SMP Response Frame header and payload
153210006Srdivacky *
154210006Srdivacky * LL defined SMP Response Frame header and payload
155210006Srdivacky *
156218893Sdim */
157210006Srdivackytypedef struct agsaSMPRspFrame_s
158210006Srdivacky{
159210006Srdivacky  agsaSMPFrameHeader_t smpHeader;
160210006Srdivacky  bit8                 smpPayload[1020];
161221345Sdim} agsaSMPRspFrame_t;
162210006Srdivacky
163210006Srdivacky/** \brief the agsaIOMap_t
164210006Srdivacky *
165210006Srdivacky * data storage for IO Request Mapping
166210006Srdivacky *
167210006Srdivacky */
168210006Srdivackytypedef struct agsaIOMap_s
169210006Srdivacky{
170218893Sdim  bit32 Tag;
171210006Srdivacky  agsaIORequestDesc_t *IORequest;
172210006Srdivacky  agsaContext_t *agContext;
173210006Srdivacky} agsaIOMap_t;
174218893Sdim
175210006Srdivacky/** \brief the agsaPortMap_t
176210006Srdivacky *
177210006Srdivacky * data storage for Port Context Mapping
178210006Srdivacky *
179 */
180typedef struct agsaPortMap_s
181{
182  bit32 PortID;
183  bit32 PortStatus;
184  void  *PortContext;
185} agsaPortMap_t;
186
187/** \brief the agsaDeviceMap_t
188 *
189 * data storage for Device Handle Mapping
190 *
191 */
192typedef struct agsaDeviceMap_s
193{
194  bit32 DeviceIdFromFW;
195  void  *DeviceHandle;
196} agsaDeviceMap_t;
197
198#ifdef FAST_IO_TEST
199/* interleaved Fast IO's are not allowed */
200#define LL_FAST_IO_SIZE  1
201#endif
202
203/** \brief the LLRoot
204 *
205 * root data structure
206 *
207 */
208typedef struct agsaLLRoot_s
209{
210  agsaMem_t       deviceLinkMem; /**< Device Link System Memory */
211  SALINK_LIST     freeDevicesList; /**< List of free IO device handles */
212
213  agsaMem_t       IORequestMem; /**< IO Request Link System Memory */
214  SALINK_LIST     freeIORequests; /**< List of free IORequests */
215  SALINK_LIST     freeReservedRequests; /**< List of reserved IORequests not for normal IO! */
216
217  agsaMem_t       timerLinkMem; /**< Timer Link System Memory */
218  SALINK_LIST     freeTimers; /**< List of free timers */
219  SALINK_LIST     validTimers; /**< List of valid timers */
220
221  agsaPhy_t       phys[AGSA_MAX_VALID_PHYS]; /**< Phys */
222
223  agsaPort_t      ports[AGSA_MAX_VALID_PORTS]; /**< Ports */
224  SALINK_LIST     freePorts; /**< List of free ports */
225  SALINK_LIST     validPorts; /**< List of valid ports */
226
227  bit8            phyCount; /**< number of phys */
228  bit8            portCount; /**< number of ports */
229  bit8            sysIntsActive; /**< whether interrupt is enabled */
230  bit8            reserved; /**< reserved */
231
232  bit32           usecsPerTick; /**< timer tick unit */
233  bit32           minStallusecs; /**< shorest available stall */
234  bit32           timeTick; /**< the current timer tick */
235  bit32           ResetStartTick; /* Reset StartTick */
236  bit32           chipStatus; /**< chip status */
237
238  bit32           interruptVecIndexBitMap[MAX_NUM_VECTOR]; /**< Interrupt Vector Index BitMap */
239  bit32           interruptVecIndexBitMap1[MAX_NUM_VECTOR]; /**< Interrupt Vector Index BitMap1 */
240
241  agsaBarOffset_t SpcBarOffset[60];
242  bit32           ChipId; /* Subversion PCI ID */
243
244  agsaPortMap_t   PortMap[AGSA_MAX_VALID_PORTS]; /**< Port Mapping for PortContext */
245  agsaDeviceMap_t DeviceMap[MAX_IO_DEVICE_ENTRIES]; /**< Device Map for Device Handle */
246  agsaIOMap_t     IOMap[MAX_ACTIVE_IO_REQUESTS]; /**< IO MAP for IO Request */
247  agsaDevHandle_t *DeviceHandle[MAX_IO_DEVICE_ENTRIES]; /**< used for get device handles */
248  agsaDevHandle_t *pDeviceHandle; /**< used for get device handles */
249
250  agsaMemoryRequirement_t memoryAllocated; /**< SAS LL memory Allocation */
251  agsaHwConfig_t          hwConfig; /**< copy of hwConfig */
252  agsaSwConfig_t          swConfig; /**< copy of swConfig */
253  agsaQueueConfig_t       QueueConfig; /* copy of MPI IBQ/OBQ configuration */
254
255  mpiConfig_t     mpiConfig; /**< MPI Configuration */
256  mpiMemReq_t     mpiMemoryAllocated; /**< MPI memory */
257  mpiICQueue_t    inboundQueue[AGSA_MAX_INBOUND_Q];   /**< Outbound queue descriptor array */
258  mpiOCQueue_t    outboundQueue[AGSA_MAX_OUTBOUND_Q]; /**< Outbound queue descriptor array */
259  mpiHostLLConfigDescriptor_t    mainConfigTable; /**< LL main Configuration Table */
260
261  ossaDeviceRegistrationCB_t     DeviceRegistrationCB; /**< Device Registration CB */
262  ossaDeregisterDeviceHandleCB_t DeviceDeregistrationCB;/**< Device DeRegistration CB */
263
264  bit32           numInterruptVectors; /**< Number of Interrupt Vectors configured from OS */
265  bit32           Use64bit;            /**< Only write upper bits if needed */
266
267  EnadDisabHandler_t DisableInterrupts;              /*Interrupt type dependant function pointer to disable interrupts */
268  EnadDisabHandler_t ReEnableInterrupts;             /*Interrupt type dependant reenable  */
269  InterruptOurs_t OurInterrupt;                      /*Interrupt type dependant check for our interrupt */
270
271#ifdef SA_FW_TEST_BUNCH_STARTS
272  /**
273   * Following variables are needed to handle Bunch Starts (bulk update of PI)
274   * - saRoot (agsaLLRoot_t): Global Flags, apply to all queues
275   *   1. BunchStarts_Enable
276   *   2. BunchStarts_Threshold
277   *   3. BunchStarts_Pending
278   *   4. BunchStarts_TimeoutTicks
279   *
280   * - Circular Q (mpiICQueue_s): Queue specific flags
281   *   1. BunchStarts_QPending
282   *   2. BunchStarts_QPendingTick
283   */
284  bit32           BunchStarts_Enable;       // enables/disables whole feature
285  bit32           BunchStarts_Threshold;    // global min number of IOs to bunch per queue.
286  bit32           BunchStarts_Pending;      // global counter collects all Q->BunchStarts_QPending
287  bit32           BunchStarts_TimeoutTicks; // global time out value beyond which bunched IOs will be started even below BunchStarts_Threshold.
288#endif /* SA_FW_TEST_BUNCH_STARTS */
289
290#ifdef SA_FW_TIMER_READS_STATUS
291  spc_GSTableDescriptor_t  mpiGSTable;
292  bit32    MsguTcnt_last;             /**< DW3 - MSGU Tick count */
293  bit32    IopTcnt_last;              /**< DW4 - IOP Tick count */
294  bit32    Iop1Tcnt_last;              /**< DW4 - IOP Tick count */
295
296#endif /* SA_FW_TIMER_READS_STATUS */
297
298  agsaControllerInfo_t ControllerInfo;
299  agsaIOErrorEventStats_t   IoErrorCount;
300  agsaIOErrorEventStats_t   IoEventCount;
301
302  bit32           ResetFailed;
303  //bit32           FatalDone;
304  bit32           ForensicLastOffset;
305  //bit32           FatalAccumLen;
306  //bit32           NonFatalForensicLastOffset;
307  //bit32           FatalCurrentLength;
308  bit32           FatalForensicStep;
309  bit32           FatalForensicShiftOffset;
310  bit32           FatalBarLoc;
311
312#ifdef HIALEAH_ENCRYPTION
313  agsaEncryptGeneralPage_t EncGenPage;
314#endif /* HIALEAH_ENCRYPTION */
315#ifdef SA_ENABLE_TRACE_FUNCTIONS
316  bit8  traceBuffLookup[16];
317
318  bit32           TraceDestination;
319  bit32           TraceMask;
320
321  bit32           TraceBufferLength;
322  bit32           CurrentTraceIndexWrapCount;
323  bit32           CurrentTraceIndex;
324  bit32           traceLineFeedCnt;
325  bit8            *TraceBuffer;
326  bit32           TraceBlockReInit;
327
328#endif /*SA_ENABLE_TRACE_FUNCTIONS*/
329
330  bit32           registerDump0[REGISTER_DUMP_BUFF_SIZE/4];  /**< register dump buffer 0 */
331  bit32           registerDump1[REGISTER_DUMP_BUFF_SIZE/4];  /**< register dump buffer 1 */
332
333  bit32           autoDeregDeviceflag[AGSA_MAX_VALID_PORTS];
334
335#ifdef SA_FW_TEST_INTERRUPT_REASSERT
336  bit32           CheckAll;
337  bit32           OldPi[64];
338  bit32           OldCi[64];
339  bit32           OldFlag[64];
340#endif /* SA_FW_TEST_INTERRUPT_REASSERT */
341
342
343#ifdef SALL_API_TEST
344  agsaLLCountInfo_t LLCounters;
345#endif
346#ifdef FAST_IO_TEST
347  void            *freeFastReq[LL_FAST_IO_SIZE]; /* saFastRequest_t* */
348  int             freeFastIdx;
349#endif
350} agsaLLRoot_t;
351
352#ifdef FAST_IO_TEST
353/*
354  one struct per all prepared Fast IO's;
355  freed after all IO's are posted to FW and interrupt is triggered;
356  maintained for error rollback or cancel functionality
357*/
358typedef struct saFastRequest_s
359{
360  bit32       beforePI[AGSA_MAX_INBOUND_Q];
361  bit32       inqList[AGSA_MAX_INBOUND_Q];
362  bit32       inqMax;
363  SALINK_LIST requests; /* List of all Fast IORequests */
364  void        *agRoot;  /* agsaRoot_t * */
365  bit8        valid;    /* to avoid usage when the struct is freed */
366} saFastRequest_t;
367#endif
368
369#endif  /*__SATYPES_H__ */
370