1285809Sscottl/*******************************************************************************
2285809Sscottl *Copyright (c) 2014 PMC-Sierra, Inc.  All rights reserved.
3285809Sscottl*
4285809Sscottl*Redistribution and use in source and binary forms, with or without modification, are permitted provided
5285809Sscottl*that the following conditions are met:
6285809Sscottl*1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
7285809Sscottl*following disclaimer.
8285809Sscottl*2. Redistributions in binary form must reproduce the above copyright notice,
9285809Sscottl*this list of conditions and the following disclaimer in the documentation and/or other materials provided
10285809Sscottl*with the distribution.
11285809Sscottl*
12285809Sscottl*THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
13285809Sscottl*WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14285809Sscottl*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
15285809Sscottl*FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16285809Sscottl*NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
17285809Sscottl*BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18285809Sscottl*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19285809Sscottl*SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
20285809Sscottl ********************************************************************************/
21285809Sscottl/*******************************************************************************/
22285809Sscottl/** \file
23285809Sscottl *
24285809Sscottl * $RCSfile: ttdinit.c,v $
25285809Sscottl *
26285809Sscottl * Copyright 2006 PMC-Sierra, Inc.
27285809Sscottl *
28285809Sscottl * $Author: vempatin $
29285809Sscottl * $Revision: 113679 $
30285809Sscottl * $Date: 2012-04-16 14:35:19 -0700 (Mon, 16 Apr 2012) $
31285809Sscottl *
32285809Sscottl * This file contains initiator IO related functions in TD layer
33285809Sscottl *
34285809Sscottl */
35285809Sscottl#include <osenv.h>
36285809Sscottl#include <ostypes.h>
37285809Sscottl#include <osdebug.h>
38285809Sscottl
39285809Sscottl#include <sa.h>
40285809Sscottl#include <saapi.h>
41285809Sscottl#include <saosapi.h>
42285809Sscottl
43285809Sscottl#include <titypes.h>
44285809Sscottl#include <ostiapi.h>
45285809Sscottl#include <tiapi.h>
46285809Sscottl#include <tiglobal.h>
47285809Sscottl
48285809Sscottl#include <tdtypes.h>
49285809Sscottl#include <osstring.h>
50285809Sscottl#include <tdutil.h>
51285809Sscottl
52285809Sscottl#ifdef INITIATOR_DRIVER
53285809Sscottl#include <itdtypes.h>
54285809Sscottl#include <itddefs.h>
55285809Sscottl#include <itdglobl.h>
56285809Sscottl#endif
57285809Sscottl
58285809Sscottl#ifdef TARGET_DRIVER
59285809Sscottl#include "ttdglobl.h"
60285809Sscottl#include "ttdtxchg.h"
61285809Sscottl#include "ttdtypes.h"
62285809Sscottl#endif
63285809Sscottl
64285809Sscottl#include <tdsatypes.h>
65285809Sscottl#include <tdproto.h>
66285809Sscottl
67285809Sscottl/* io trace only */
68285809Sscottlextern void TDTraceInit(void);
69285809Sscottl/* io trace only */
70285809Sscottl
71285809Sscottl
72285809SscottlosGLOBAL bit32
73285809SscottlttdssInit(
74285809Sscottl        tiRoot_t              *tiRoot,
75285809Sscottl        tiTargetResource_t    *targetResource,
76285809Sscottl        tiTdSharedMem_t       *tdSharedMem
77285809Sscottl)
78285809Sscottl{
79285809Sscottl    tdsaRoot_t                *tdsaRoot  = (tdsaRoot_t *)tiRoot->tdData;
80285809Sscottl    tiTargetMem_t             *tgtMem;
81285809Sscottl    ttdsaTgt_t                *Target;
82285809Sscottl    ttdssOperatingOption_t    *OperatingOption;
83285809Sscottl    char                      *buffer;
84285809Sscottl    bit32                     buffLen;
85285809Sscottl    bit32                     lenRecv = 0;
86285809Sscottl    char                      *pLastUsedChar = agNULL;
87285809Sscottl    char                      tmpBuffer[DEFAULT_KEY_BUFFER_SIZE];
88285809Sscottl    char                      globalStr[]     = "OSParms";
89285809Sscottl
90285809Sscottl    TI_DBG5(("ttdssInit: start\n"));
91285809Sscottl
92285809Sscottl    /*
93285809Sscottl     first set the values to Default values
94285809Sscottl     Then, overwrite them using ostiGetTransportParam()
95285809Sscottl     */
96285809Sscottl
97285809Sscottl    /* to remove compiler warnings */
98285809Sscottl    buffer          = &tmpBuffer[0];
99285809Sscottl    buffLen         = sizeof (tmpBuffer);
100285809Sscottl
101285809Sscottl    osti_memset(buffer, 0, buffLen);
102285809Sscottl
103285809Sscottl    tgtMem = &targetResource->targetMem;
104285809Sscottl
105285809Sscottl    /*
106285809Sscottl     * Cached mem for target Transport Dependent Layer main functionality
107285809Sscottl     */
108285809Sscottl    Target = tgtMem->tdMem[0].virtPtr;
109285809Sscottl
110285809Sscottl    OperatingOption = &Target->OperatingOption;
111285809Sscottl    /*
112285809Sscottl     * Get default parameters from the OS Specific area
113285809Sscottl     * and reads parameters from the configuration file
114285809Sscottl     */
115285809Sscottl    ttdssGetOperatingOptionParams(tiRoot, OperatingOption);
116285809Sscottl
117285809Sscottl
118285809Sscottl    /*
119285809Sscottl     * Update TD operating options
120285809Sscottl     */
121285809Sscottl    OperatingOption->UsecsPerTick =
122285809Sscottl            targetResource->targetOption.usecsPerTick;
123285809Sscottl    OperatingOption->numXchgs = tgtMem->tdMem[1].numElements;
124285809Sscottl
125285809Sscottl
126285809Sscottl    if (ttdsaXchgInit(tiRoot,
127285809Sscottl            &Target->ttdsaXchgData,
128285809Sscottl            tgtMem,
129285809Sscottl            OperatingOption->numXchgs
130285809Sscottl    ) == agFALSE)
131285809Sscottl    {
132285809Sscottl        TI_DBG1(("ttdInit: ttdsaXchgInit failed\n"));
133285809Sscottl        return tiError;
134285809Sscottl    }
135285809Sscottl
136285809Sscottl    /* Get number of AutoGoodResponse entry */
137285809Sscottl    if ((ostiGetTransportParam(
138285809Sscottl                                tiRoot,
139285809Sscottl                                globalStr,
140285809Sscottl                                agNULL,
141285809Sscottl                                agNULL,
142285809Sscottl                                agNULL,
143285809Sscottl                                agNULL,
144285809Sscottl                                agNULL,
145285809Sscottl                                "AutoGoodResponse",
146285809Sscottl                                buffer,
147285809Sscottl                                buffLen,
148285809Sscottl                                &lenRecv
149285809Sscottl                              ) == tiSuccess) && (lenRecv != 0))
150285809Sscottl    {
151285809Sscottl        if (osti_strncmp(buffer, "0x", 2) == 0)
152285809Sscottl        {
153285809Sscottl            tdsaRoot->autoGoodRSP = osti_strtoul (buffer, &pLastUsedChar, 0);
154285809Sscottl        }
155285809Sscottl        else
156285809Sscottl        {
157285809Sscottl            tdsaRoot->autoGoodRSP = osti_strtoul (buffer, &pLastUsedChar, 10);
158285809Sscottl        }
159285809Sscottl
160285809Sscottl    }
161285809Sscottl
162285809Sscottl    return tiSuccess;
163285809Sscottl}
164285809Sscottl
165285809Sscottl/*
166285809Sscottl  this combines ttdGetDefaultParams and ttdGetTargetParms
167285809Sscottl
168285809Sscottl */
169285809SscottlosGLOBAL void
170285809SscottlttdssGetOperatingOptionParams(
171285809Sscottl        tiRoot_t                *tiRoot,
172285809Sscottl        ttdssOperatingOption_t  *OperatingOption
173285809Sscottl)
174285809Sscottl{
175285809Sscottl    char    *key = agNULL;
176285809Sscottl    char    *subkey1 = agNULL;
177285809Sscottl    char    *subkey2 = agNULL;
178285809Sscottl    char    *buffer;
179285809Sscottl    bit32   buffLen;
180285809Sscottl    bit32   lenRecv = 0;
181285809Sscottl    char    *pLastUsedChar = agNULL;
182285809Sscottl    char    tmpBuffer[DEFAULT_KEY_BUFFER_SIZE];
183285809Sscottl    char    globalStr[]     = "Global";
184285809Sscottl    char    iniParmsStr[]   = "TargetParms";
185285809Sscottl
186285809Sscottl    TI_DBG5(("ttdssGetOperatingOptionParams: start\n"));
187285809Sscottl
188285809Sscottl    /*
189285809Sscottl     first set the values to Default values
190285809Sscottl     Then, overwrite them using ostiGetTransportParam()
191285809Sscottl     */
192285809Sscottl
193285809Sscottl
194285809Sscottl    /* to remove compiler warnings */
195285809Sscottl    pLastUsedChar   = pLastUsedChar;
196285809Sscottl    lenRecv         = lenRecv;
197285809Sscottl    subkey2         = subkey2;
198285809Sscottl    subkey1         = subkey1;
199285809Sscottl    key             = key;
200285809Sscottl    buffer          = &tmpBuffer[0];
201285809Sscottl    buffLen         = sizeof (tmpBuffer);
202285809Sscottl
203285809Sscottl    osti_memset(buffer, 0, buffLen);
204285809Sscottl
205285809Sscottl
206285809Sscottl    /* in ttgglobl.h */
207285809Sscottl    OperatingOption->numXchgs = DEFAULT_XCHGS;
208285809Sscottl    OperatingOption->UsecsPerTick = DEFAULT_TGT_TIMER_TICK; /* 1 sec */
209285809Sscottl    OperatingOption->MaxTargets = DEFAULT_MAX_TARGETS;
210285809Sscottl    OperatingOption->BlockSize = DEFAULT_BLOCK_SIZE;
211285809Sscottl
212285809Sscottl
213285809Sscottl    /* defaults are overwritten in the following */
214285809Sscottl    /* Get number of exchanges */
215285809Sscottl    if ((ostiGetTransportParam(
216285809Sscottl            tiRoot,
217285809Sscottl            globalStr,
218285809Sscottl            iniParmsStr,
219285809Sscottl            agNULL,
220285809Sscottl            agNULL,
221285809Sscottl            agNULL,
222285809Sscottl            agNULL,
223285809Sscottl            "NumberExchanges",
224285809Sscottl            buffer,
225285809Sscottl            buffLen,
226285809Sscottl            &lenRecv
227285809Sscottl    ) == tiSuccess) && (lenRecv != 0))
228285809Sscottl    {
229285809Sscottl        if (osti_strncmp(buffer, "0x", 2) == 0)
230285809Sscottl        {
231285809Sscottl            OperatingOption->numXchgs = osti_strtoul (buffer, &pLastUsedChar, 0);
232285809Sscottl        }
233285809Sscottl        else
234285809Sscottl        {
235285809Sscottl            OperatingOption->numXchgs = osti_strtoul (buffer, &pLastUsedChar, 10);
236285809Sscottl        }
237285809Sscottl
238285809Sscottl    }
239285809Sscottl
240285809Sscottl    osti_memset(buffer, 0, buffLen);
241285809Sscottl    lenRecv = 0;
242285809Sscottl
243285809Sscottl    /* Get number of MaxTargets */
244285809Sscottl    if ((ostiGetTransportParam(
245285809Sscottl            tiRoot,
246285809Sscottl            globalStr,
247285809Sscottl            iniParmsStr,
248285809Sscottl            agNULL,
249285809Sscottl            agNULL,
250285809Sscottl            agNULL,
251285809Sscottl            agNULL,
252285809Sscottl            "MaxTargets",
253285809Sscottl            buffer,
254285809Sscottl            buffLen,
255285809Sscottl            &lenRecv
256285809Sscottl    ) == tiSuccess) && (lenRecv != 0))
257285809Sscottl    {
258285809Sscottl        if (osti_strncmp(buffer, "0x", 2) == 0)
259285809Sscottl        {
260285809Sscottl            OperatingOption->MaxTargets = osti_strtoul (buffer, &pLastUsedChar, 0);
261285809Sscottl        }
262285809Sscottl        else
263285809Sscottl        {
264285809Sscottl            OperatingOption->MaxTargets = osti_strtoul (buffer, &pLastUsedChar, 10);
265285809Sscottl        }
266285809Sscottl
267285809Sscottl    }
268285809Sscottl    osti_memset(buffer, 0, buffLen);
269285809Sscottl    lenRecv = 0;
270285809Sscottl
271285809Sscottl    /* Get number of BlockSize */
272285809Sscottl    if ((ostiGetTransportParam(
273285809Sscottl            tiRoot,
274285809Sscottl            globalStr,
275285809Sscottl            iniParmsStr,
276285809Sscottl            agNULL,
277285809Sscottl            agNULL,
278285809Sscottl            agNULL,
279285809Sscottl            agNULL,
280285809Sscottl            "BlockSize",
281285809Sscottl            buffer,
282285809Sscottl            buffLen,
283285809Sscottl            &lenRecv
284285809Sscottl    ) == tiSuccess) && (lenRecv != 0))
285285809Sscottl    {
286285809Sscottl        if (osti_strncmp(buffer, "0x", 2) == 0)
287285809Sscottl        {
288285809Sscottl            OperatingOption->BlockSize = osti_strtoul (buffer, &pLastUsedChar, 0);
289285809Sscottl        }
290285809Sscottl        else
291285809Sscottl        {
292285809Sscottl            OperatingOption->BlockSize = osti_strtoul (buffer, &pLastUsedChar, 10);
293285809Sscottl        }
294285809Sscottl    }
295285809Sscottl    osti_memset(buffer, 0, buffLen);
296285809Sscottl    lenRecv = 0;
297285809Sscottl
298285809Sscottl
299285809Sscottl
300285809Sscottl    TI_DBG5(("ttdssGetOperatingOptionParams: NumberExchanges %d UsecsPerTick %d MaxTargets %d BlockSize %d\n", OperatingOption->numXchgs, OperatingOption->UsecsPerTick, OperatingOption->MaxTargets, OperatingOption->BlockSize));
301285809Sscottl
302285809Sscottl    return;
303285809Sscottl}
304285809Sscottl
305285809Sscottl/* not yet */
306285809SscottlosGLOBAL void
307285809SscottlttdssGetResource(
308285809Sscottl        tiRoot_t              *tiRoot,
309285809Sscottl        tiTargetResource_t    *targetResource
310285809Sscottl)
311285809Sscottl{
312285809Sscottl    tiTargetMem_t            *tgtMem;
313285809Sscottl    int i;
314285809Sscottl    ttdssOperatingOption_t   OperatingOption;
315285809Sscottl    bit32                     xchgSize;
316285809Sscottl    bit32                     respSize;
317285809Sscottl    bit32                     smprespSize;
318285809Sscottl
319285809Sscottl    TI_DBG4(("ttdssGetResource: start\n"));
320285809Sscottl
321285809Sscottl    tgtMem = &targetResource->targetMem;
322285809Sscottl
323285809Sscottl    /*
324285809Sscottl    only 4 memory descriptors are used
325285809Sscottl     */
326285809Sscottl    tgtMem->count = 4;
327285809Sscottl
328285809Sscottl    /* initiailization */
329285809Sscottl    for (i = 0 ; i < 10 ; i++)
330285809Sscottl    {
331285809Sscottl        tgtMem->tdMem[i].singleElementLength  = 0;
332285809Sscottl        tgtMem->tdMem[i].numElements          = 0;
333285809Sscottl        tgtMem->tdMem[i].totalLength          = 0;
334285809Sscottl        tgtMem->tdMem[i].alignment            = 0;
335285809Sscottl        tgtMem->tdMem[i].type                 = TI_CACHED_MEM;
336285809Sscottl        tgtMem->tdMem[i].reserved             = 0;
337285809Sscottl        tgtMem->tdMem[i].virtPtr               = agNULL;
338285809Sscottl        tgtMem->tdMem[i].osHandle              = agNULL;
339285809Sscottl        tgtMem->tdMem[i].physAddrUpper         = 0;
340285809Sscottl        tgtMem->tdMem[i].physAddrLower         = 0;
341285809Sscottl    }
342285809Sscottl
343285809Sscottl    /*
344285809Sscottl     * Get default parameters from the OS Specific area
345285809Sscottl     * and reads parameters from the configuration file
346285809Sscottl     */
347285809Sscottl    ttdssGetOperatingOptionParams(tiRoot, &OperatingOption);
348285809Sscottl
349285809Sscottl    /* target */
350285809Sscottl    tgtMem->tdMem[0].singleElementLength  = sizeof(ttdsaTgt_t);
351285809Sscottl    tgtMem->tdMem[0].numElements          = 1;
352285809Sscottl    tgtMem->tdMem[0].totalLength          =
353285809Sscottl            tgtMem->tdMem[0].singleElementLength *
354285809Sscottl            tgtMem->tdMem[0].numElements;
355285809Sscottl    tgtMem->tdMem[0].alignment            = sizeof (void *);
356285809Sscottl    tgtMem->tdMem[0].type                 = TI_CACHED_MEM;
357285809Sscottl    tgtMem->tdMem[0].reserved             = 0;
358285809Sscottl    tgtMem->tdMem[0].virtPtr               = agNULL;
359285809Sscottl    tgtMem->tdMem[0].osHandle              = agNULL;
360285809Sscottl    tgtMem->tdMem[0].physAddrUpper         = 0;
361285809Sscottl    tgtMem->tdMem[0].physAddrLower         = 0;
362285809Sscottl
363285809Sscottl    /*
364285809Sscottl     * Cached memory for I/O exchange structures
365285809Sscottl     */
366285809Sscottl    xchgSize = sizeof(ttdsaXchg_t);
367285809Sscottl    xchgSize = AG_ALIGNSIZE(xchgSize, 8);
368285809Sscottl
369285809Sscottl    tgtMem->tdMem[1].singleElementLength = xchgSize;
370285809Sscottl    tgtMem->tdMem[1].numElements         = OperatingOption.numXchgs;
371285809Sscottl    tgtMem->tdMem[1].totalLength         = tgtMem->tdMem[1].singleElementLength *
372285809Sscottl            tgtMem->tdMem[1].numElements;
373285809Sscottl    tgtMem->tdMem[1].alignment           = sizeof(void *);
374285809Sscottl    tgtMem->tdMem[1].type                = TI_CACHED_MEM;
375285809Sscottl    tgtMem->tdMem[1].reserved             = 0;
376285809Sscottl    tgtMem->tdMem[1].virtPtr               = agNULL;
377285809Sscottl    tgtMem->tdMem[1].osHandle              = agNULL;
378285809Sscottl    tgtMem->tdMem[1].physAddrUpper         = 0;
379285809Sscottl    tgtMem->tdMem[1].physAddrLower         = 0;
380285809Sscottl
381285809Sscottl    /*
382285809Sscottl     * Uncached memory for response buffer structures
383285809Sscottl     */
384285809Sscottl    TI_DBG4(("ttdssGetResource: sas_resp_t size 0x%x %d\n",
385285809Sscottl            (unsigned int)sizeof(sas_resp_t), (int)sizeof(sas_resp_t)));
386285809Sscottl
387285809Sscottl    respSize = (sizeof(sas_resp_t) + AG_WORD_ALIGN_ADD) & AG_WORD_ALIGN_MASK;
388285809Sscottl    TI_DBG4(("ttdssGetResource: response size 0x%x %d\n", respSize,respSize));
389285809Sscottl    respSize = AG_ALIGNSIZE(respSize, 8);
390285809Sscottl    TI_DBG4(("ttdssGetResource: response size 0x%x %d\n", respSize,respSize));
391285809Sscottl    tgtMem->tdMem[2].singleElementLength = 0x1000; /* respSize; 0x1000;  */
392285809Sscottl    tgtMem->tdMem[2].numElements         = OperatingOption.numXchgs;  /* Same as num of xchg */
393285809Sscottl    tgtMem->tdMem[2].totalLength         = tgtMem->tdMem[2].singleElementLength *
394285809Sscottl            tgtMem->tdMem[2].numElements;
395285809Sscottl    /* 8;4;16;256;sizeof(void *); all worked */
396285809Sscottl    tgtMem->tdMem[2].alignment           = 16;
397285809Sscottl    tgtMem->tdMem[2].type                = TI_DMA_MEM;  /* uncached memory */
398285809Sscottl    tgtMem->tdMem[2].reserved             = 0;
399285809Sscottl    tgtMem->tdMem[2].virtPtr               = agNULL;
400285809Sscottl    tgtMem->tdMem[2].osHandle              = agNULL;
401285809Sscottl    tgtMem->tdMem[2].physAddrUpper         = 0;
402285809Sscottl    tgtMem->tdMem[2].physAddrLower         = 0;
403285809Sscottl
404285809Sscottl    /*
405285809Sscottl     * Uncached memory for SMP response buffer structures
406285809Sscottl     */
407285809Sscottl    smprespSize = sizeof(smp_resp_t);
408285809Sscottl    smprespSize = AG_ALIGNSIZE(smprespSize, 8);
409285809Sscottl    TI_DBG4(("ttdssGetResource: SMP response size 0x%x %d\n", smprespSize,smprespSize));
410285809Sscottl
411285809Sscottl    tgtMem->tdMem[3].singleElementLength = smprespSize; /*0x1000; smprespSize; */
412285809Sscottl    tgtMem->tdMem[3].numElements         = OperatingOption.numXchgs;  /* Same as num of xchg */
413285809Sscottl    tgtMem->tdMem[3].totalLength
414285809Sscottl    = tgtMem->tdMem[3].singleElementLength * tgtMem->tdMem[3].numElements;
415285809Sscottl    tgtMem->tdMem[3].alignment           = 16; /* 4; 256; 16; sizeof(void *); */
416285809Sscottl    tgtMem->tdMem[3].type                = TI_DMA_MEM;  /* uncached memory */
417285809Sscottl    tgtMem->tdMem[3].reserved             = 0;
418285809Sscottl    tgtMem->tdMem[3].virtPtr               = agNULL;
419285809Sscottl    tgtMem->tdMem[3].osHandle              = agNULL;
420285809Sscottl    tgtMem->tdMem[3].physAddrUpper         = 0;
421285809Sscottl    tgtMem->tdMem[3].physAddrLower         = 0;
422285809Sscottl
423285809Sscottl
424285809Sscottl
425285809Sscottl    targetResource->targetOption.usecsPerTick = OperatingOption.UsecsPerTick;
426285809Sscottl    targetResource->targetOption.pageSize     = 0; /* not applicable to SAS/SATA */
427285809Sscottl    targetResource->targetOption.numLgns      = 0; /* not applicable to SAS/SATA */
428285809Sscottl    targetResource->targetOption.numSessions  = 0; /* not applicable to SAS/SATA */
429285809Sscottl    targetResource->targetOption.numXchgs     = OperatingOption.numXchgs;
430285809Sscottl
431285809Sscottl
432285809Sscottl    /*
433285809Sscottl    This is not used in OS like Linux which supports dynamic memeory allocation
434285809Sscottl    In short, this is for Windows
435285809Sscottl     */
436285809Sscottl    /* Estimate dynamic DMA memory */
437285809Sscottl    targetResource->targetOption.dynamicDmaMem.alignment = sizeof(void *);
438285809Sscottl
439285809Sscottl    targetResource->targetOption.dynamicDmaMem.numElements = 128;
440285809Sscottl    targetResource->targetOption.dynamicDmaMem.singleElementLength = sizeof(tdssSMPRequestBody_t);
441285809Sscottl    targetResource->targetOption.dynamicDmaMem.totalLength =
442285809Sscottl            targetResource->targetOption.dynamicDmaMem.numElements *
443285809Sscottl            targetResource->targetOption.dynamicDmaMem.singleElementLength;
444285809Sscottl
445285809Sscottl    /* Estimate dynamic cached memory */
446285809Sscottl    targetResource->targetOption.dynamicCachedMem.alignment =  sizeof(void *);
447285809Sscottl    targetResource->targetOption.dynamicCachedMem.numElements = 128;
448285809Sscottl    targetResource->targetOption.dynamicCachedMem.singleElementLength = sizeof(tdssSMPRequestBody_t);
449285809Sscottl    targetResource->targetOption.dynamicCachedMem.totalLength =
450285809Sscottl            targetResource->targetOption.dynamicCachedMem.numElements *
451285809Sscottl            targetResource->targetOption.dynamicCachedMem.singleElementLength;
452285809Sscottl
453285809Sscottl
454285809Sscottl    return;
455285809Sscottl}
456285809Sscottl
457285809Sscottl/* not in use */
458285809SscottlosGLOBAL void
459285809SscottlttdssGetTargetParams(
460285809Sscottl        tiRoot_t          *tiRoot
461285809Sscottl)
462285809Sscottl{
463285809Sscottl    TI_DBG6(("ttdssGetTargetParams: start\n"));
464285809Sscottl    return;
465285809Sscottl}
466285809Sscottl
467285809SscottlosGLOBAL agBOOLEAN
468285809SscottlttdsaXchgInit(
469285809Sscottl        tiRoot_t           *tiRoot,
470285809Sscottl        ttdsaXchgData_t    *ttdsaXchgData,
471285809Sscottl        tiTargetMem_t      *tgtMem,
472285809Sscottl        bit32              maxNumXchgs
473285809Sscottl)
474285809Sscottl{
475285809Sscottl    ttdsaXchg_t       *ttdsaXchg;
476285809Sscottl    bit32             i, respLen;
477285809Sscottl    bit8              *virtualAddr;
478285809Sscottl    bit32             phyAddrLower, phyAddrUpper;
479285809Sscottl    bit32             smprespLen;
480285809Sscottl    bit32             smpphyAddrLower, smpphyAddrUpper;
481285809Sscottl    bit8              *smpvirtualAddr;
482285809Sscottl
483285809Sscottl
484285809Sscottl
485285809Sscottl    TI_DBG5(("ttdsaXchgInit: start\n"));
486285809Sscottl    /* io trace only */
487285809Sscottl    TDTraceInit();
488285809Sscottl    /* io trace only */
489285809Sscottl
490285809Sscottl    /*
491285809Sscottl     * Set and initialize some global exchange information
492285809Sscottl     */
493285809Sscottl    TDLIST_INIT_HDR(&ttdsaXchgData->xchgFreeList);
494285809Sscottl    TDLIST_INIT_HDR(&ttdsaXchgData->xchgBusyList);
495285809Sscottl
496285809Sscottl    ttdsaXchgData->maxNumXchgs = maxNumXchgs;
497285809Sscottl
498285809Sscottl    /* Initialize exchange and response buffer structures */
499285809Sscottl    ttdsaXchg = (ttdsaXchg_t *) tgtMem->tdMem[1].virtPtr;
500285809Sscottl
501285809Sscottl    /* Initialize response buffer */
502285809Sscottl    virtualAddr  = tgtMem->tdMem[2].virtPtr;
503285809Sscottl    phyAddrUpper = tgtMem->tdMem[2].physAddrUpper;
504285809Sscottl    phyAddrLower = tgtMem->tdMem[2].physAddrLower;
505285809Sscottl    respLen      = tgtMem->tdMem[2].singleElementLength;
506285809Sscottl
507285809Sscottl    ttdsaXchg->resp.virtAddr      = virtualAddr;
508285809Sscottl    ttdsaXchg->resp.phyAddrUpper = phyAddrUpper;
509285809Sscottl    ttdsaXchg->resp.phyAddrLower = phyAddrLower;
510285809Sscottl    ttdsaXchg->resp.length = respLen;
511285809Sscottl
512285809Sscottl    /* Initialize SMP response buffer */
513285809Sscottl    smpvirtualAddr  = tgtMem->tdMem[3].virtPtr;
514285809Sscottl    smpphyAddrUpper = tgtMem->tdMem[3].physAddrUpper;
515285809Sscottl    smpphyAddrLower = tgtMem->tdMem[3].physAddrLower;
516285809Sscottl    smprespLen      = tgtMem->tdMem[3].singleElementLength;
517285809Sscottl
518285809Sscottl    ttdsaXchg->smpresp.virtAddr      = smpvirtualAddr;
519285809Sscottl    ttdsaXchg->smpresp.phyAddrUpper = smpphyAddrUpper;
520285809Sscottl    ttdsaXchg->smpresp.phyAddrLower = smpphyAddrLower;
521285809Sscottl    ttdsaXchg->smpresp.length = smprespLen;
522285809Sscottl
523285809Sscottl    /* Initialization of callback and etc */
524285809Sscottl    for (i=0;i<maxNumXchgs;i++)
525285809Sscottl    {
526285809Sscottl        ttdsaXchg->id = i;
527285809Sscottl        ttdsaXchg->usedEsgl = agFALSE;
528285809Sscottl        ttdsaXchg->io_found = agTRUE;
529285809Sscottl        ttdsaXchg->DeviceData = agNULL;
530285809Sscottl        /* callback for IO(ssp) and SMP */
531285809Sscottl        ttdsaXchg->IORequestBody.IOCompletionFunc = ttdsaIOCompleted;
532285809Sscottl        ttdsaXchg->SMPRequestBody.SMPCompletionFunc = ttdsaSMPCompleted;
533285809Sscottl
534285809Sscottl
535285809Sscottl        TDLIST_INIT_ELEMENT(&ttdsaXchg->XchgLinks );
536285809Sscottl
537285809Sscottl        ttdsaXchg->IORequestBody.agIORequest.osData = (void *)ttdsaXchg;
538285809Sscottl        ttdsaXchg->IORequestBody.tiIORequest
539285809Sscottl        = &(ttdsaXchg->IORequestBody.IOType.TargetIO.tiIORequest);
540285809Sscottl
541285809Sscottl        /* Init the tdData portion of tiIORequest context for this exchange */
542285809Sscottl        ttdsaXchg->IORequestBody.tiIORequest->tdData = ttdsaXchg;
543285809Sscottl
544285809Sscottl        /* SMP */
545285809Sscottl        ttdsaXchg->SMPRequestBody.agIORequest.osData = (void *)ttdsaXchg;
546285809Sscottl        /* ttdsaXchg->SMPRequestBody.agIORequest.osData = (void *)&ttdsaXchg->SMPRequestBody; */
547285809Sscottl        /*ttdsaXchg->SMPRequestBody.tiIORequest.tdData = (void *)&ttdsaXchg->SMPRequestBody; */
548285809Sscottl
549285809Sscottl
550285809Sscottl
551285809Sscottl
552285809Sscottl        /* Initialize the CDB and LUN addresses */
553285809Sscottl        ttdsaXchg->tiTgtScsiCmnd.reqCDB  = &(ttdsaXchg->agSSPCmndIU.cdb[0]);
554285809Sscottl        ttdsaXchg->tiTgtScsiCmnd.scsiLun = &(ttdsaXchg->agSSPCmndIU.lun[0]);
555285809Sscottl
556285809Sscottl        ttdsaXchg->index = i;
557285809Sscottl        ttdsaXchg->respLen = respLen; /* 100 */
558285809Sscottl        ttdsaXchg->smprespLen = smprespLen; /* 100 */
559285809Sscottl        ttdsaXchg->TLR = 0;
560285809Sscottl        TD_XCHG_SET_STATE(ttdsaXchg, TD_XCHG_STATE_INACTIVE);
561285809Sscottl        ttdsaXchg->retries = 0;
562285809Sscottl
563285809Sscottl        ttdsaXchgLinkInit(tiRoot,ttdsaXchg);
564285809Sscottl
565285809Sscottl        /* Save current response payload/buffer address */
566285809Sscottl        virtualAddr  = ttdsaXchg->resp.virtAddr;
567285809Sscottl        phyAddrLower = ttdsaXchg->resp.phyAddrLower;
568285809Sscottl        smpvirtualAddr  = ttdsaXchg->smpresp.virtAddr;
569285809Sscottl        smpphyAddrLower = ttdsaXchg->smpresp.phyAddrLower;
570285809Sscottl
571285809Sscottl        TI_DBG5(("ttdsaXchgInit: +1 before\n"));
572285809Sscottl        if (i == (maxNumXchgs - 1))
573285809Sscottl        {
574285809Sscottl            /* at the last one */
575285809Sscottl            TI_DBG5(("ttdsaXchgInit: last one break\n"));
576285809Sscottl            break;
577285809Sscottl        }
578285809Sscottl
579285809Sscottl        /* Advance to next exchange */
580285809Sscottl        ttdsaXchg = ttdsaXchg + 1;
581285809Sscottl        TI_DBG5(("ttdsaXchgInit: +1 after\n"));
582285809Sscottl
583285809Sscottl        /* Update response payload/buffer address */
584285809Sscottl        ttdsaXchg->resp.virtAddr      = virtualAddr + respLen;
585285809Sscottl        TI_DBG5(("ttdsaXchgInit: pos 1\n"));
586285809Sscottl        ttdsaXchg->resp.phyAddrUpper = phyAddrUpper;
587285809Sscottl        TI_DBG5(("ttdsaXchgInit: pos 2\n"));
588285809Sscottl        ttdsaXchg->resp.phyAddrLower = phyAddrLower + respLen;
589285809Sscottl        TI_DBG5(("ttdsaXchgInit: pos 3\n"));
590285809Sscottl        ttdsaXchg->resp.length = respLen;
591285809Sscottl        TI_DBG5(("ttdsaXchgInit: pos 4\n"));
592285809Sscottl
593285809Sscottl        /* Update SMP response payload/buffer address */
594285809Sscottl        ttdsaXchg->smpresp.virtAddr      = smpvirtualAddr + smprespLen;
595285809Sscottl        ttdsaXchg->smpresp.phyAddrUpper = smpphyAddrUpper;
596285809Sscottl        ttdsaXchg->smpresp.phyAddrLower = smpphyAddrLower + smprespLen;
597285809Sscottl        ttdsaXchg->smpresp.length = smprespLen;
598285809Sscottl
599285809Sscottl    }
600285809Sscottl
601285809Sscottl    /* Reinitialize counters.
602285809Sscottl     * This must be done at the end
603285809Sscottl     */
604285809Sscottl    TD_XCHG_CONTEXT_NO_USED(tiRoot)            = 0;
605285809Sscottl    TD_XCHG_CONTEXT_NO_FREED(tiRoot)           = 0;
606285809Sscottl    TD_XCHG_CONTEXT_NO_CMD_RCVD(tiRoot)        = 0;
607285809Sscottl    TD_XCHG_CONTEXT_NO_START_IO(tiRoot)        = 0;
608285809Sscottl    TD_XCHG_CONTEXT_NO_SEND_RSP(tiRoot)        = 0;
609285809Sscottl    TD_XCHG_CONTEXT_NO_IO_COMPLETED(tiRoot)    = 0;
610285809Sscottl
611285809Sscottl    TI_DBG5(("ttdsaXchgInit: end\n"));
612285809Sscottl    return agTRUE;
613285809Sscottl}
614285809Sscottl
615285809SscottlosGLOBAL void
616285809SscottlttdsaXchgLinkInit(
617285809Sscottl        tiRoot_t           *tiRoot,
618285809Sscottl        ttdsaXchg_t        *ttdsaXchg
619285809Sscottl)
620285809Sscottl{
621285809Sscottl    tdsaRoot_t        *tdsaRoot    = (tdsaRoot_t *)tiRoot->tdData;
622285809Sscottl    tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
623285809Sscottl    ttdsaTgt_t         *Target = (ttdsaTgt_t *)tdsaAllShared->ttdsaTgt;
624285809Sscottl    bit32              i;
625285809Sscottl    bit8               *data;
626285809Sscottl
627285809Sscottl    TI_DBG5(("ttdsaXchgLinkInit: start\n"));
628285809Sscottl    TI_DBG5(("ttdsaXchgLinkInit: xchg %p\n",ttdsaXchg));
629285809Sscottl    TI_DBG5(("ttdsaXchgLinkInit: resp %p\n",ttdsaXchg->resp.virtAddr));
630285809Sscottl    TI_DBG5(("ttdsaXchgLinkInit: smpresp %p\n",ttdsaXchg->smpresp.virtAddr));
631285809Sscottl
632285809Sscottl    if (TD_XCHG_GET_STATE(ttdsaXchg) == TD_XCHG_STATE_ACTIVE)
633285809Sscottl    {
634285809Sscottl        TI_DBG1(("ttdsaXchgLinkInit: active xchg *****************; wrong\n"));
635285809Sscottl        return;
636285809Sscottl    }
637285809Sscottl
638285809Sscottl    ttdsaXchg->tag = 0xFFFF;
639285809Sscottl    ttdsaXchg->IORequestBody.agIORequest.sdkData  = agNULL;
640285809Sscottl    ttdsaXchg->SMPRequestBody.agIORequest.sdkData  = agNULL;
641285809Sscottl    ttdsaXchg->statusSent        = agFALSE;
642285809Sscottl    ttdsaXchg->responseSent      = agFALSE;
643285809Sscottl    ttdsaXchg->readRspCollapsed  = agFALSE;
644285809Sscottl    ttdsaXchg->wrtRspCollapsed  = agFALSE;
645285809Sscottl    ttdsaXchg->pTMResp           = agNULL;
646285809Sscottl    ttdsaXchg->oustandingIos     = 0;
647285809Sscottl    ttdsaXchg->isAborting        = agFALSE;
648285809Sscottl    ttdsaXchg->oslayerAborting   = agFALSE;
649285809Sscottl    ttdsaXchg->isTMRequest       = agFALSE;
650285809Sscottl    ttdsaXchg->io_found          = agTRUE;
651285809Sscottl    ttdsaXchg->tiIOToBeAbortedRequest          = agNULL;
652285809Sscottl    ttdsaXchg->XchgToBeAborted          = agNULL;
653285809Sscottl
654285809Sscottl    osti_memset((void *)ttdsaXchg->resp.virtAddr, 0, ttdsaXchg->respLen);
655285809Sscottl    osti_memset((void *)ttdsaXchg->smpresp.virtAddr, 0, ttdsaXchg->smprespLen);
656285809Sscottl
657285809Sscottl    data = (bit8 *)ttdsaXchg->resp.virtAddr;
658285809Sscottl    for (i = 0; i< ttdsaXchg->respLen; i++)
659285809Sscottl    {
660285809Sscottl        if (data[i] != 0)
661285809Sscottl        {
662285809Sscottl            TI_DBG5(("!! ttdsaXchgLinkInit: data[%d] 0x%x\n", i, data[i]));
663285809Sscottl        }
664285809Sscottl    }
665285809Sscottl
666285809Sscottl    ttdsaXchg->resp.length       = 0;
667285809Sscottl
668285809Sscottl    ttdsaXchg->DeviceData = agNULL;
669285809Sscottl    TI_DBG5(("ttdsaXchgLinkInit: id %d\n", ttdsaXchg->id));
670285809Sscottl
671285809Sscottl    TD_XCHG_SET_STATE(ttdsaXchg, TD_XCHG_STATE_INACTIVE);
672285809Sscottl    tdsaSingleThreadedEnter(tiRoot, TD_TGT_LOCK);
673285809Sscottl    TDLIST_ENQUEUE_AT_TAIL( &ttdsaXchg->XchgLinks, &Target->ttdsaXchgData.xchgFreeList);
674285809Sscottl    tdsaSingleThreadedLeave(tiRoot, TD_TGT_LOCK);
675285809Sscottl
676285809Sscottl
677285809Sscottl    TD_XCHG_CONTEXT_NO_FREED(tiRoot)           = TD_XCHG_CONTEXT_NO_FREED(tiRoot) +1;
678285809Sscottl    TI_DBG5(("ttdsaXchgLinkInit: end\n"));
679285809Sscottl    return;
680285809Sscottl}
681285809Sscottl
682285809Sscottl/*
683285809Sscottl   before: ttdsaXchg is in xchgBusyList
684285809Sscottl   after: ttdsaXchg is in xchgFreeList
685285809Sscottl */
686285809SscottlosGLOBAL void
687285809SscottlttdsaXchgFreeStruct(
688285809Sscottl        tiRoot_t           *tiRoot,
689285809Sscottl        ttdsaXchg_t        *ttdsaXchg
690285809Sscottl)
691285809Sscottl{
692285809Sscottl    tdsaRoot_t        *tdsaRoot    = (tdsaRoot_t *)tiRoot->tdData;
693285809Sscottl    tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
694285809Sscottl    ttdsaTgt_t        *Target = (ttdsaTgt_t *)tdsaAllShared->ttdsaTgt;
695285809Sscottl    bit32             i;
696285809Sscottl    bit8              *data;
697285809Sscottl
698285809Sscottl    TI_DBG5(("ttdsaXchgFreeStruct: start\n"));
699285809Sscottl    TI_DBG5(("ttdsaXchgFreeStruct: xchg %p\n",ttdsaXchg));
700285809Sscottl    TI_DBG5(("ttdsaXchgFreeStruct: resp %p\n",ttdsaXchg->resp.virtAddr));
701285809Sscottl    TI_DBG5(("ttdsaXchgFreeStruct: smpresp %p\n",ttdsaXchg->smpresp.virtAddr));
702285809Sscottl
703285809Sscottl    if (TD_XCHG_GET_STATE(ttdsaXchg) == TD_XCHG_STATE_INACTIVE)
704285809Sscottl    {
705285809Sscottl        TI_DBG1(("tdsaXchgFreeStruct: INACTIVE xchg *****************, wrong\n"));
706285809Sscottl        return;
707285809Sscottl    }
708285809Sscottl
709285809Sscottl    ttdsaXchg->tag = 0xFFFF;
710285809Sscottl    ttdsaXchg->IORequestBody.agIORequest.sdkData  = agNULL;
711285809Sscottl    ttdsaXchg->SMPRequestBody.agIORequest.sdkData  = agNULL;
712285809Sscottl    ttdsaXchg->statusSent        = agFALSE;
713285809Sscottl    ttdsaXchg->responseSent      = agFALSE;
714285809Sscottl    ttdsaXchg->readRspCollapsed  = agFALSE;
715285809Sscottl    ttdsaXchg->wrtRspCollapsed  = agFALSE;
716285809Sscottl    ttdsaXchg->pTMResp           = agNULL;
717285809Sscottl    ttdsaXchg->oustandingIos     = 0;
718285809Sscottl    ttdsaXchg->isAborting        = agFALSE;
719285809Sscottl    ttdsaXchg->oslayerAborting   = agFALSE;
720285809Sscottl    ttdsaXchg->isTMRequest       = agFALSE;
721285809Sscottl    ttdsaXchg->io_found          = agTRUE;
722285809Sscottl    ttdsaXchg->tiIOToBeAbortedRequest          = agNULL;
723285809Sscottl    ttdsaXchg->XchgToBeAborted          = agNULL;
724285809Sscottl
725285809Sscottl    osti_memset((void *)ttdsaXchg->resp.virtAddr, 0, ttdsaXchg->respLen);
726285809Sscottl    osti_memset((void *)ttdsaXchg->smpresp.virtAddr, 0, ttdsaXchg->smprespLen);
727285809Sscottl
728285809Sscottl    data = (bit8 *)ttdsaXchg->resp.virtAddr;
729285809Sscottl    for (i = 0; i< ttdsaXchg->respLen; i++)
730285809Sscottl    {
731285809Sscottl        if (data[i] != 0)
732285809Sscottl        {
733285809Sscottl            TI_DBG5(("!! ttdsaXchgFreeStruct: data[%d] 0x%x\n", i, data[i]));
734285809Sscottl        }
735285809Sscottl    }
736285809Sscottl
737285809Sscottl    ttdsaXchg->resp.length       = 0;
738285809Sscottl
739285809Sscottl    ttdsaXchg->DeviceData = agNULL;
740285809Sscottl    TI_DBG5(("ttdsaXchgFreeStruct: id %d\n", ttdsaXchg->id));
741285809Sscottl
742285809Sscottl    tdsaSingleThreadedEnter(tiRoot, TD_TGT_LOCK);
743285809Sscottl    TD_XCHG_SET_STATE(ttdsaXchg, TD_XCHG_STATE_INACTIVE);
744285809Sscottl    TDLIST_DEQUEUE_THIS(&ttdsaXchg->XchgLinks);
745285809Sscottl    TDLIST_ENQUEUE_AT_TAIL( &ttdsaXchg->XchgLinks, &Target->ttdsaXchgData.xchgFreeList);
746285809Sscottl    tdsaSingleThreadedLeave(tiRoot, TD_TGT_LOCK);
747285809Sscottl
748285809Sscottl    TD_XCHG_CONTEXT_NO_FREED(tiRoot)           = TD_XCHG_CONTEXT_NO_FREED(tiRoot) +1;
749285809Sscottl    TI_DBG5(("ttdsaXchgFreeStruct: end\n"));
750285809Sscottl    return;
751285809Sscottl}
752285809Sscottl
753285809Sscottl
754285809Sscottl/*
755285809Sscottl   before: ttdsaXchg is in xchgFreeList
756285809Sscottl   after: ttdsaXchg is in xchgBusyList
757285809Sscottl */
758285809SscottlosGLOBAL ttdsaXchg_t *ttdsaXchgGetStruct(agsaRoot_t *agRoot)
759285809Sscottl{
760285809Sscottl    tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
761285809Sscottl    tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
762285809Sscottl    ttdsaTgt_t             *Target = (ttdsaTgt_t *)osData->ttdsaTgt;
763285809Sscottl    tdList_t               *Link;
764285809Sscottl    ttdsaXchg_t            *ttdsaXchg = agNULL;
765285809Sscottl
766285809Sscottl    TI_DBG3 (("ttdsaXchgGetStruct: enter\n"));
767285809Sscottl
768285809Sscottl    tdsaSingleThreadedEnter(tiRoot, TD_TGT_LOCK);
769285809Sscottl    if (TDLIST_EMPTY(&(Target->ttdsaXchgData.xchgFreeList)))
770285809Sscottl    {
771285809Sscottl        tdsaSingleThreadedLeave(tiRoot, TD_TGT_LOCK);
772285809Sscottl        TI_DBG1(("ttdsaXchgGetStruct: no free ttdsaXchgData\n"));
773285809Sscottl        //    ttdsaDumpallXchg(tiRoot);
774285809Sscottl        return agNULL;
775285809Sscottl    }
776285809Sscottl
777285809Sscottl    TDLIST_DEQUEUE_FROM_HEAD(&Link, &Target->ttdsaXchgData.xchgFreeList);
778285809Sscottl    if ( Link == agNULL )
779285809Sscottl    {
780285809Sscottl        tdsaSingleThreadedLeave(tiRoot, TD_TGT_LOCK);
781285809Sscottl        TI_DBG1(("ttdsaXchgGetStruct: Link NULL: PRBLM \n"));
782285809Sscottl        return agNULL;
783285809Sscottl    }
784285809Sscottl
785285809Sscottl    ttdsaXchg = TDLIST_OBJECT_BASE(ttdsaXchg_t, XchgLinks, Link);
786285809Sscottl
787285809Sscottl    if (TD_XCHG_GET_STATE(ttdsaXchg) == TD_XCHG_STATE_ACTIVE)
788285809Sscottl    {
789285809Sscottl        TI_DBG1(("ttdsaXchgGetStruct: ACTIVE xchg *****************, wrong\n"));
790285809Sscottl        TDLIST_DEQUEUE_THIS(&ttdsaXchg->XchgLinks);
791285809Sscottl        TDLIST_ENQUEUE_AT_TAIL(&ttdsaXchg->XchgLinks, &Target->ttdsaXchgData.xchgFreeList);
792285809Sscottl        TD_XCHG_SET_STATE(ttdsaXchg, TD_XCHG_STATE_INACTIVE);
793285809Sscottl        tdsaSingleThreadedLeave(tiRoot, TD_TGT_LOCK);
794285809Sscottl
795285809Sscottl        return agNULL;
796285809Sscottl    }
797285809Sscottl
798285809Sscottl    TDLIST_DEQUEUE_THIS(&ttdsaXchg->XchgLinks);
799285809Sscottl    TDLIST_ENQUEUE_AT_TAIL(&ttdsaXchg->XchgLinks, &Target->ttdsaXchgData.xchgBusyList);
800285809Sscottl    TD_XCHG_SET_STATE(ttdsaXchg, TD_XCHG_STATE_ACTIVE);
801285809Sscottl    tdsaSingleThreadedLeave(tiRoot, TD_TGT_LOCK);
802285809Sscottl
803285809Sscottl    TD_XCHG_CONTEXT_NO_USED(tiRoot)           = TD_XCHG_CONTEXT_NO_USED(tiRoot) +1;
804285809Sscottl    TI_DBG5(("ttdsaXchgGetStruct: id %d\n", ttdsaXchg->id));
805285809Sscottl    return ttdsaXchg;
806285809Sscottl}
807285809Sscottl
808285809Sscottl/* for debugging */
809285809SscottlosGLOBAL void
810285809SscottlttdsaDumpallXchg(tiRoot_t           *tiRoot)
811285809Sscottl{
812285809Sscottl    tdsaRoot_t        *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
813285809Sscottl    tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
814285809Sscottl    ttdsaTgt_t        *Target = (ttdsaTgt_t *)tdsaAllShared->ttdsaTgt;
815285809Sscottl    ttdsaTgt_t        *tmpTarget;
816285809Sscottl    tdList_t          *XchgList;
817285809Sscottl#ifdef TD_DEBUG_ENABLE
818285809Sscottl    ttdsaXchg_t       *ttdsaXchg = agNULL;
819285809Sscottl#endif
820285809Sscottl
821285809Sscottl    tmpTarget = Target;
822285809Sscottl
823285809Sscottl    tdsaSingleThreadedEnter(tiRoot, TD_TGT_LOCK);
824285809Sscottl    if (TDLIST_EMPTY(&(tmpTarget->ttdsaXchgData.xchgFreeList)))
825285809Sscottl    {
826285809Sscottl        tdsaSingleThreadedLeave(tiRoot, TD_TGT_LOCK);
827285809Sscottl        TI_DBG1(("ttdsaDumpallXchg: no FREE ttdsaXchgData\n"));
828285809Sscottl    }
829285809Sscottl    else
830285809Sscottl    {
831285809Sscottl        tdsaSingleThreadedLeave(tiRoot, TD_TGT_LOCK);
832285809Sscottl        XchgList = tmpTarget->ttdsaXchgData.xchgFreeList.flink;
833285809Sscottl
834285809Sscottl        while(XchgList != &(tmpTarget->ttdsaXchgData.xchgFreeList))
835285809Sscottl        {
836285809Sscottl#ifdef TD_DEBUG_ENABLE
837285809Sscottl            ttdsaXchg = TDLIST_OBJECT_BASE(ttdsaXchg_t, XchgLinks, XchgList);
838285809Sscottl#endif
839285809Sscottl            TI_DBG1(("ttdsaDumpallXchg: FREE id %d state %d\n", ttdsaXchg->id, TD_XCHG_GET_STATE(ttdsaXchg)));
840285809Sscottl            XchgList = XchgList->flink;
841285809Sscottl        }
842285809Sscottl    }
843285809Sscottl
844285809Sscottl    tdsaSingleThreadedEnter(tiRoot, TD_TGT_LOCK);
845285809Sscottl    if (TDLIST_EMPTY(&(tmpTarget->ttdsaXchgData.xchgBusyList)))
846285809Sscottl    {
847285809Sscottl        tdsaSingleThreadedLeave(tiRoot, TD_TGT_LOCK);
848285809Sscottl        TI_DBG1(("ttdsaDumpallXchg: no BUSY ttdsaXchgData\n"));
849285809Sscottl    }
850285809Sscottl    else
851285809Sscottl    {
852285809Sscottl        tdsaSingleThreadedLeave(tiRoot, TD_TGT_LOCK);
853285809Sscottl        XchgList = tmpTarget->ttdsaXchgData.xchgBusyList.flink;
854285809Sscottl
855285809Sscottl        while(XchgList != &(tmpTarget->ttdsaXchgData.xchgBusyList))
856285809Sscottl        {
857285809Sscottl#ifdef TD_DEBUG_ENABLE
858285809Sscottl            ttdsaXchg = TDLIST_OBJECT_BASE(ttdsaXchg_t, XchgLinks, XchgList);
859285809Sscottl#endif
860285809Sscottl            TI_DBG1(("ttdsaDumpallXchg: BUSY id %d state %d\n", ttdsaXchg->id, TD_XCHG_GET_STATE(ttdsaXchg)));
861285809Sscottl            XchgList = XchgList->flink;
862285809Sscottl        }
863285809Sscottl    }
864285809Sscottl
865285809Sscottl
866285809Sscottl    return;
867285809Sscottl}
868285809Sscottl
869285809Sscottl
870285809Sscottl#ifdef PASSTHROUGH
871285809Sscottl
872285809SscottlosGLOBAL bit32
873285809SscottltiTGTPassthroughCmndRegister(
874285809Sscottl        tiRoot_t                        *tiRoot,
875285809Sscottl        tiPortalContext_t               *tiportalContext,
876285809Sscottl        tiPassthroughProtocol_t        tiProtocol,
877285809Sscottl        tiPassthroughSubProtocol_t        tiSubProtocol,
878285809Sscottl        tiPassthroughFrameType_t        tiFrameType,
879285809Sscottl        ostiProcessPassthroughCmnd_t    agPasthroughCB
880285809Sscottl)
881285809Sscottl{
882285809Sscottl    tdsaRoot_t                *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
883285809Sscottl    tdsaContext_t             *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
884285809Sscottl    ttdsaTgt_t                *Target = (ttdsaTgt_t *)tdsaAllShared->ttdsaTgt;
885285809Sscottl
886285809Sscottl    TI_DBG1(("tiTGTPassthroughCmndRegister: start\n"));
887285809Sscottl    /* error checking */
888285809Sscottl    if (tiProtocol != tiSASATA)
889285809Sscottl    {
890285809Sscottl        TI_DBG1(("tiTGTPassthroughCmndRegister: not supported protocol %d\n", tiProtocol));
891285809Sscottl        return tiError;
892285809Sscottl    }
893285809Sscottl
894285809Sscottl    if (tiSubProtocol != tiSSP || tiSubProtocol != tiSTP || tiSubProtocol != tiSMP)
895285809Sscottl    {
896285809Sscottl        TI_DBG1(("tiTGTPassthroughCmndRegister: not supported sub protocol %d\n", tiSubProtocol));
897285809Sscottl        return tiError;
898285809Sscottl    }
899285809Sscottl
900285809Sscottl
901285809Sscottl    if (tiFrameType == tiSMPResponse)
902285809Sscottl    {
903285809Sscottl        TI_DBG1(("tiTGTPassthroughCmndRegister: SMP response frametype %d\n"));
904285809Sscottl        Target->PasthroughCB = agPasthroughCB;
905285809Sscottl    }
906285809Sscottl
907285809Sscottl    else if (tiFrameType == tiSSPPMC)
908285809Sscottl    {
909285809Sscottl        TI_DBG1(("tiTGTPassthroughCmndRegister: RMC response frametype %d\n"));
910285809Sscottl        Target->PasthroughCB = agPasthroughCB;
911285809Sscottl    }
912285809Sscottl    else
913285809Sscottl    {
914285809Sscottl        TI_DBG1(("tiTGTPassthroughCmndRegister: not supported frametype %d\n", tiFrameType));
915285809Sscottl        return tiError;
916285809Sscottl    }
917285809Sscottl
918285809Sscottl
919285809Sscottl    return tiSuccess;
920285809Sscottl}
921285809Sscottl
922285809Sscottl#endif
923