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
7*following disclaimer.
8*2. Redistributions in binary form must reproduce the above copyright notice,
9*this list of conditions and the following disclaimer in the documentation and/or other materials provided
10*with the distribution.
11*
12*THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
13*WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
15*FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16*NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
17*BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19*SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
20*
21*
22********************************************************************************/
23#ifndef __DMTYPES_H__
24#define __DMTYPES_H__
25
26#include <dev/pms/freebsd/driver/common/osenv.h>
27#include <dev/pms/freebsd/driver/common/ostypes.h>
28#include <dev/pms/freebsd/driver/common/osdebug.h>
29
30#include <dev/pms/RefTisa/sallsdk/api/sa.h>
31#include <dev/pms/RefTisa/sallsdk/api/saapi.h>
32#include <dev/pms/RefTisa/sallsdk/api/saosapi.h>
33
34#include <dev/pms/RefTisa/discovery/api/dm.h>
35#include <dev/pms/RefTisa/discovery/api/dmapi.h>
36#include <dev/pms/RefTisa/discovery/api/tddmapi.h>
37
38#include <dev/pms/RefTisa/discovery/dm/dmlist.h>
39#ifdef TBD
40#include <dev/pms/RefTisa/tisa/api/tiscsi.h>
41#endif
42
43
44/* for SMP only */
45typedef void (*dmSMPCompleted_t) (
46                                    agsaRoot_t            *,
47                                    agsaIORequest_t       *,
48                                    bit32                 ,
49                                    bit32                 ,
50                                    agsaFrameHandle_t
51                                    );
52
53
54/* timer functions ; both I and T */
55typedef void (*dmTimerCBFunc_t)(dmRoot_t *dmRoot, void *timerData1, void *timerData2, void *timerData3);
56
57
58/** \brief data structure for timer request
59 *  Timer requests are enqueued and dequeued using dmList_t
60 *  and have a callback function
61 */
62typedef struct dmTimerRequest_s {
63  /* the number of ticks */
64  bit32             timeout;
65  void              *timerData1;
66  void              *timerData2;
67  void              *timerData3;
68  dmTimerCBFunc_t   timerCBFunc;
69  dmList_t          timerLink;
70  bit32             timerRunning;
71}  dmTimerRequest_t;
72
73typedef struct dmRootOsData_s {
74  dmRoot_t  *dmRoot;            /**< Pointer back to dmRoot                 */
75  void      *dmAllShared;       /**< Pointer to dmContext_t               */
76  void      *dmIni;             /**< Pointer to SAS/SATA initiator               */
77}  dmRootOsData_t;
78
79typedef struct DMSASAddressID_s
80{
81  bit32   sasAddressLo;     /**< HOST SAS address lower part */
82  bit32   sasAddressHi;     /**< HOST SAS address higher part */
83  bit8    phyIdentifier;    /**< PHY IDENTIFIER of the PHY */
84} DMSASAddressID_t;
85
86struct dmExpander_s;
87
88typedef struct dmDiscovery_s
89{
90  dmList_t                   discoveringExpanderList;
91  dmList_t                   UpdiscoveringExpanderList;
92  //  tdList_t                   freeExpanderList;
93  bit32                   status;
94  DMSASAddressID_t        sasAddressIDDiscoverError;
95  agsaSATAIdentifyData_t  *pSataIdentifyData;
96  struct dmExpander_s     *RootExp; /* Root expander of discovery */
97  bit32                   NumOfUpExp;
98  bit32                   type; /* discovery type: TDSA_DISCOVERY_OPTION_FULL_START
99                                   or TDSA_DISCOVERY_OPTION_INCREMENTAL_START*/
100  bit32                   retries;
101  bit32                   configureRouteRetries;
102  bit32                   deviceRetistrationRetries;
103  dmTimerRequest_t        discoveryTimer;
104  dmTimerRequest_t        configureRouteTimer;
105  dmTimerRequest_t        deviceRegistrationTimer;
106  dmTimerRequest_t        BCTimer; /* Broadcast Change timer for ResetTriggerred */
107  smpRespDiscover_t       SMPDiscoverResp;
108  smpRespDiscover2_t      SMPDiscover2Resp;
109  bit32                   pendingSMP; /* the number of pending SMP for this discovery */
110  bit32                   SeenBC; /* received Broadcast change */
111  bit32                   forcedOK; /* report DiscOK when chance is missed */
112  dmTimerRequest_t        SMPBusyTimer; /* SMP retry timer for saSMPStart busy */
113  bit32                   SMPRetries; /* number of SMP retries when LL returns busy for saSMPStart*/
114  bit32                   ResetTriggerred; /* Hard/Link reset triggerred by discovery */
115  dmTimerRequest_t        DiscoverySMPTimer; /* discovery-related SMP application Timer */
116  /* For SAS 2 */
117  bit32                   DeferredError; /* Deferred Error for SAS 2 */
118  bit32                   ConfiguresOthers; /* exp configures others; no routing configuration */
119} dmDiscovery_t;
120
121typedef struct dmSASSubID_s
122{
123  bit32        sasAddressHi;
124  bit32        sasAddressLo;
125  bit8         initiator_ssp_stp_smp;
126  bit8         target_ssp_stp_smp;
127
128} dmSASSubID_t;
129
130struct dmDeviceData_s;
131
132typedef struct dmIntPortContext_s
133{
134  /**< current number of devices in this PortContext */
135  bit32                         Count;
136  bit32                   DiscoveryState;
137  bit32                   DiscoveryAbortInProgress;
138  /* passed by tiINIDiscoverTargets()
139     eg) discovery or rediscovery ....
140  */
141  bit32                   discoveryOptions;
142  /* Discovery ready is given? */
143  bit32                   DiscoveryRdyGiven;
144  /* Port has received link up */
145  bit32                   SeenLinkUp;
146  /* statistics */
147  bit32                   numAvailableTargets;
148  /* flag: indicates that discovery is trigggered by tiINIDiscoverTargets */
149  bit32                   osInitiatedDiscovery;
150
151  bit32                         id; /* for debugging only */
152  dmList_t                      FreeLink; /**< free portcontext list */
153  dmList_t                      MainLink; /**< in-use portcontext list */
154  /**< SAS address of the remote device */
155  bit32                         sasRemoteAddressHi; /**< SAS address high part */
156  bit32                         sasRemoteAddressLo; /**< SAS address low part */
157  /**< SAS ID frame of the remote device */
158  agsaSASIdentify_t             sasIDframe;
159
160  /**< SAS address of the local device*/
161  bit32                         sasLocalAddressHi; /**< SAS address high part */
162  bit32                         sasLocalAddressLo; /**< SAS address low part */
163#ifdef TBD
164  /**< the list of PhyID belonging to this port */
165  bit8                          PhyIDList[DM_MAX_NUM_PHYS];
166#endif
167  dmPortContext_t               *dmPortContext;
168  dmRoot_t                      *dmRoot;
169
170#ifdef TBD
171  /* used in tiINIDiscoverTarget() */
172  agsaRoot_t                    *agRoot;
173  agsaPortContext_t             *agPortContext;
174  /* maybe needs timers for saPhyStart() */
175
176  bit8                  nativeSATAMode; /* boolean flag: whether the port is in Native SATA mode */
177  bit8                remoteSignature[8]; /* the remote signature of the port is the port is in native SATA mode */
178#endif
179  bit8                 directAttatchedSAS; /* boolean flag: whether the port connected directly to SAS end device*/
180  /* SAS/SATA discovery information such as discoveringExpanderList */
181  dmDiscovery_t              discovery;
182  bit32                      valid;
183  bit8                       LinkRate;
184  bit32                      RegisteredDevNums; /* registered number of devices */
185  bit32                      eventPhyID; /* used for saHwEventAck() */
186  bit32                      Transient; /* transient period between link up and link down/port recovery */
187  bit32                      RegFailed; /* Registration of expander belonging to this port failure */
188
189}  dmIntPortContext_t;
190
191typedef struct dmDeviceData_s  {
192
193  dmList_t                FreeLink; /* free dev list */
194  dmList_t                MainLink; /* main(in use) dev list */
195  dmList_t                IncDisLink; /* Used for incremental Discovery only */
196  bit32                   id; /* for debugging only */
197  bit8                    DeviceType;
198  /* used in tiINIIOStart() */
199  dmRoot_t                *dmRoot;
200//  agsaDevHandle_t         *agDevHandle;
201
202  /* for SAS; remote device */
203  //  agsaSASDeviceInfo_t     agSASDeviceInfo;
204  /* device's sas address */
205  DMSASAddressID_t        SASAddressID;
206  bit8                    initiator_ssp_stp_smp;
207  bit8                    target_ssp_stp_smp;
208  bit8                    numOfPhys;
209
210  /* SATA specific data */
211  bit8                    satSignature[8];          /* SATA device Signature*/
212
213  /**< pointer to tdsaPortcontext which the device belongs to */
214  struct dmIntPortContext_s *dmPortContext;
215  /* validity of device */
216  bit8                    valid;
217  bit8                    valid2;
218  bit8                    processed; /* used in TD discovery */
219#ifdef AGTIAPI_CTL
220  bit8                    discovered;
221#endif
222  agsaDeviceInfo_t        agDeviceInfo;
223  dmDeviceInfo_t          dmDeviceInfo;
224  agsaContext_t           agContext; /* used in saRegisterNewDevice()*/
225  /**< pointer to dmExpander if Device is expander */
226  struct dmExpander_s     *dmExpander;
227  struct dmDeviceData_s   *ExpDevice; /* Expander device which this device is attached to */
228
229  bit8                    phyID;      /* PhyID this device is attached to SPC or expander */
230  agsaSASIdentify_t     sasIdentify; /* used only in TD discovery */
231  bit8                  connectionRate;
232//  bit8                  registered;
233  bit8                  directlyAttached;
234  bit8                  SASSpecDeviceType; /* 0 - 3; SAS_NO_DEVICE - SAS_FANOUT_EXPANDER_DEVICE */
235  bit32                 IOStart;
236  bit32                 IOResponse;
237  agsaContext_t         agDeviceResetContext; /* used in saLocalPhyControl() */
238  bit32                 TRflag; /* transport recovery flag; used only for tiINITransportRecovery */
239  bit32                 ResetCnt; /* number of reset to the device */
240  bit32                 registered; /* registered to LL */
241  bit32                 reported; /* reproted to TDM */
242  bit32                 MCN; /* MCN; initialized to 0; current value in discovery */
243  bit32                 MCNDone; /* done in updating MCN */
244  bit32                 PrevMCN; /* MCN; initialized to 0; previous value in discovery */
245
246}  dmDeviceData_t;
247
248
249typedef struct dmExpander_s
250{
251  /* start of dmDeviceData */
252#ifdef TBD
253  dmList_t                FreeLink; /* free dev list */
254  dmList_t                MainLink; /* main(in use) dev list */
255#endif
256  bit32                   id; /* for debugging only */
257  bit32                   InQID; /* Inbound queue ID */
258  bit32                   OutQID; /* Outbound queue ID */
259  bit8                    DeviceType;
260  /* used in tiINIIOStart() */
261  dmRoot_t                *dmRoot;
262  agsaDevHandle_t         *agDevHandle;
263
264  dmList_t                  linkNode; /**< the link node data structure of the expander */
265  dmList_t                  upNode; /**< the link node data structure of the expander */
266  dmDeviceData_t            *dmDevice; /**< the pointer to the device data */
267  struct dmExpander_s       *dmUpStreamExpander; /**< the pointer to the upstream expander device */
268  bit8                      hasUpStreamDevice;
269  bit8                      discoveringPhyId;
270  bit16                     routingIndex; /* maximum routing table index reported by expander */
271  bit16                     currentIndex[DM_MAX_EXPANDER_PHYS]; /* routing table index in use */
272  /*ReportPhySataSend in DM */
273  dmDeviceData_t            *dmDeviceToProcess;    /* on some callbacks, this is a link to the device of interest */
274
275  bit32                     configSASAddressHi;
276  bit32                     configSASAddressLo;
277  struct dmExpander_s       *dmCurrentDownStreamExpander;
278  bit8                      upStreamPhys[DM_MAX_EXPANDER_PHYS];
279  bit16                     numOfUpStreamPhys;
280  bit16                     currentUpStreamPhyIndex;
281  bit32                     upStreamSASAddressHi;
282  bit32                     upStreamSASAddressLo;
283  bit32                     underDiscovering;
284  bit32                     configRouteTable: 1;
285  bit32                     configuring: 1;
286  bit32                     configReserved: 30;
287#ifdef TBD
288  bit32                   id; /* for debugging */
289#endif
290  struct dmExpander_s       *dmReturnginExpander;
291  bit8                      downStreamPhys[DM_MAX_EXPANDER_PHYS];
292  bit16                     numOfDownStreamPhys;
293  bit8                      currentDownStreamPhyIndex;
294  bit32                     discoverSMPAllowed; /* used only for configurable routers */
295  bit8                      routingAttribute[DM_MAX_EXPANDER_PHYS];
296  bit32                     configSASAddressHiTable[DM_MAX_DEV];
297  bit32                     configSASAddressLoTable[DM_MAX_DEV];
298  bit32                     configSASAddrTableIndex;
299  /* for SAS 2 */
300  bit32                     SAS2; /* supports SAS2 spec of not. The value of LONG RESPONSE
301                                     in report general response */
302  bit32                     TTTSupported; /* Table to Table is supported */
303  bit32                     UndoDueToTTTSupported; /* flag that indicates undo exp, device, route
304                                                      configuration due to TTT */
305
306} dmExpander_t;
307
308typedef struct dmIndirectSMPRequestBody_s {
309  dmList_t                     Link;
310  bit32                        id;
311
312}  dmIndirectSMPRequestBody_t;
313
314/*
315  should DM allocate a pool of SMP and manages it
316  or
317  depend on ostiAllocMemory()
318*/
319typedef struct dmSMPRequestBody_s {
320  dmList_t                     Link;
321  dmSMPCompleted_t             SMPCompletionFunc;/* must be the second */
322
323#ifdef TBD
324  tiDeviceHandle_t               *tiDevHandle;    /* not used for TD generated SMP */
325#endif
326  agsaIORequest_t                agIORequest;
327  agsaSASRequestBody_t           agSASRequestBody;
328  agsaSATAInitiatorRequest_t     agSATARequestBody;
329  /**< SMP response */
330  //agsaSMPFrame_t                 SMPRsp;
331  dmDeviceData_t                 *dmDevice;
332
333#ifdef TBD
334  void                           *osMemHandle;
335  // can this be simply dmExpander_t
336  dmDeviceData_t                 *dmDevice;
337  tiIORequest_t                  *CurrentTaskTag; /* SMP is used for simulate target reset */
338#endif
339  dmRoot_t                       *dmRoot;
340//  dmExpander_t                   *dmExpander;
341  dmIntPortContext_t             *dmPortContext; /* portcontext where SMP is sent from */
342  bit8                           smpPayload[SMP_DIRECT_PAYLOAD_LIMIT]; /* for smp retries;
343                                                                          only for direct SMP */
344  bit32                          retries; /* number of retries */
345  /* for indirect SMP req/rsp */
346  void                           *IndirectSMP;
347  bit32                          IndirectSMPUpper32;
348  bit32                          IndirectSMPLower32;
349  /* used only when SMP is INDIRECT SMP request. On SMP completion,
350     this is used to free up INDIRECT SMP response
351  */
352  void                           *IndirectSMPResponse; /* dmSMPRequestBody_t */
353
354
355
356#ifdef TBD
357  void                           *IndirectSMPReqosMemHandle;
358  void                           *IndirectSMPReq;
359  bit32                          IndirectSMPReqLen;
360  bit32                          IndirectSMPReqUpper32;
361  bit32                          IndirectSMPReqLower32;
362  void                           *IndirectSMPResposMemHandle;
363  void                           *IndirectSMPResp;
364  bit32                          IndirectSMPRespLen;
365  bit32                          IndirectSMPRespUpper32;
366  bit32                          IndirectSMPRespLower32;
367#endif
368  bit32                          id;
369  agsaContext_t                  agContext;
370}  dmSMPRequestBody_t;
371
372
373typedef struct dmIntContext_s {
374  /**< agsaRoot_t->osData points to this */
375  struct dmRootOsData_s      dmRootOsData;
376
377  bit32               usecsPerTick;
378#ifdef TBD
379  dmRoot_t            dmRootInt;          /* for interrupt */
380  dmRoot_t            dmRootNonInt;       /* for non-interrupt */
381#endif
382
383  agsaRoot_t          *agRoot;
384
385  /**< software-related initialization params used in saInitialize() */
386  dmSwConfig_t        SwConfig;
387
388  /**< timers used commonly in SAS/SATA */
389  dmList_t                      timerlist;
390  /**< pointer to PortContext memory;  */
391  dmIntPortContext_t          *PortContextMem;
392
393  dmList_t                   FreePortContextList;
394  dmList_t                   MainPortContextList;
395
396  /**< pointer to Device memory */
397  dmDeviceData_t             *DeviceMem;
398  dmList_t                   FreeDeviceList;
399  dmList_t                   MainDeviceList;
400
401  /**< pointer to Expander memory */
402  dmExpander_t               *ExpanderMem;
403  dmList_t                   freeExpanderList;
404  dmList_t                   mainExpanderList;
405
406  /**< pointer to SMP command memory */
407  dmSMPRequestBody_t         *SMPMem;
408  dmList_t                   freeSMPList;
409
410  /**< pointer to Indirect SMP request/repsonse memory */
411  bit8                       *IndirectSMPMem;
412  bit32                      IndirectSMPUpper32;
413  bit32                      IndirectSMPLower32;
414  bit32                      itNexusTimeout;
415  bit32                      MaxRetryDiscovery;
416  bit32                      RateAdjust;
417
418}  dmIntContext_t;
419
420typedef struct dmIntRoot_s
421{
422  /**<< common data structure for SAS/SATA */
423  dmIntContext_t          dmAllShared;
424} dmIntRoot_t;
425
426#endif                          /* __DMTYPES_H__ */
427
428