1 /*******************************************************************************
2 *Copyright (c) 2014 PMC-Sierra, Inc. All rights reserved.
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
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.
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
21 ********************************************************************************/
22 /*******************************************************************************/
26 * This file contains initiator initialization functions
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31 #include <dev/pms/config.h>
33 #include <dev/pms/freebsd/driver/common/osenv.h>
34 #include <dev/pms/freebsd/driver/common/ostypes.h>
35 #include <dev/pms/freebsd/driver/common/osdebug.h>
37 #include <dev/pms/RefTisa/sallsdk/api/sa.h>
38 #include <dev/pms/RefTisa/sallsdk/api/saapi.h>
39 #include <dev/pms/RefTisa/sallsdk/api/saosapi.h>
41 #include <dev/pms/RefTisa/tisa/api/titypes.h>
42 #include <dev/pms/RefTisa/tisa/api/ostiapi.h>
43 #include <dev/pms/RefTisa/tisa/api/tiapi.h>
44 #include <dev/pms/RefTisa/tisa/api/tiglobal.h>
47 #include <dev/pms/RefTisa/sat/api/sm.h>
48 #include <dev/pms/RefTisa/sat/api/smapi.h>
49 #include <dev/pms/RefTisa/sat/api/tdsmapi.h>
53 #include <dev/pms/RefTisa/discovery/api/dm.h>
54 #include <dev/pms/RefTisa/discovery/api/dmapi.h>
55 #include <dev/pms/RefTisa/discovery/api/tddmapi.h>
58 #include <dev/pms/RefTisa/tisa/sassata/sas/common/tdtypes.h>
59 #include <dev/pms/freebsd/driver/common/osstring.h>
60 #include <dev/pms/RefTisa/tisa/sassata/common/tdutil.h>
62 #ifdef INITIATOR_DRIVER
63 #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itdtypes.h>
64 #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itddefs.h>
65 #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itdglobl.h>
69 #include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdglobl.h>
70 #include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdxchg.h>
71 #include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdtypes.h>
74 #include <dev/pms/RefTisa/tisa/sassata/common/tdsatypes.h>
75 #include <dev/pms/RefTisa/tisa/sassata/common/tdproto.h>
77 /*****************************************************************************
78 *! \brief itdssGetResource
80 * Purpose: This function is called to determine the Transport
81 * Dependent Layer internal resource requirement for the initiator
84 * /param tiRoot: Pointer to driver/port instance.
85 * /param initiatorResource: Pointer to initiator functionality memory and
90 * /note - This function only return the memory requirement in the tiMem_t
91 * structure in initiatorResource. It does not allocated memory, so the
92 * address fields in tiMem_t are not used.
94 *****************************************************************************/
98 tiInitiatorResource_t * initiatorResource
101 itdssOperatingOption_t OperatingOption;
102 tiInitiatorMem_t *iniMem;
105 iniMem = &initiatorResource->initiatorMem;
106 iniMem->count = 1; /* Only 1 memory descriptors are used */
108 TI_DBG6(("itdssGetResource: start\n"));
110 /* other than [0], nothing is used
111 * tdCachedMem[0]: cached mem for initiator TD Layer main functionality :
113 * tdCachedMem[1-5]: is availalbe
117 * Get default parameters from the OS Specific area
118 * and reads parameters from the configuration file
120 itdssGetOperatingOptionParams(tiRoot, &OperatingOption);
123 * Cached mem for initiator Transport Dependent Layer main functionality
126 iniMem->tdCachedMem[0].singleElementLength = sizeof(itdsaIni_t);
127 iniMem->tdCachedMem[0].numElements = 1;
128 iniMem->tdCachedMem[0].totalLength =
129 iniMem->tdCachedMem[0].singleElementLength *
130 iniMem->tdCachedMem[0].numElements;
131 iniMem->tdCachedMem[0].alignment = sizeof (void *); /* 4 bytes */
132 iniMem->tdCachedMem[0].type = TI_CACHED_MEM;
133 iniMem->tdCachedMem[0].reserved = 0;
134 iniMem->tdCachedMem[0].virtPtr = agNULL;
135 iniMem->tdCachedMem[0].osHandle = agNULL;
136 iniMem->tdCachedMem[0].physAddrUpper = 0;
137 iniMem->tdCachedMem[0].physAddrLower = 0;
141 * Not used mem structure. Initialize them.
143 for (i = iniMem->count; i < 6; i++)
145 iniMem->tdCachedMem[i].singleElementLength = 0;
146 iniMem->tdCachedMem[i].numElements = 0;
147 iniMem->tdCachedMem[i].totalLength = 0;
148 iniMem->tdCachedMem[i].alignment = 0;
149 iniMem->tdCachedMem[i].type = TI_CACHED_MEM;
150 iniMem->tdCachedMem[i].reserved = 0;
152 iniMem->tdCachedMem[i].virtPtr = agNULL;
153 iniMem->tdCachedMem[i].osHandle = agNULL;
154 iniMem->tdCachedMem[i].physAddrUpper = 0;
155 iniMem->tdCachedMem[i].physAddrLower = 0;
160 * Operating option of TISA
161 * fills in tiInitiatorOption
163 initiatorResource->initiatorOption.usecsPerTick = OperatingOption.UsecsPerTick; /* default value 1 sec*/
165 initiatorResource->initiatorOption.pageSize = 0;
168 initiatorResource->initiatorOption.dynamicDmaMem.numElements = 0;
169 initiatorResource->initiatorOption.dynamicDmaMem.singleElementLength = 0;
170 initiatorResource->initiatorOption.dynamicDmaMem.totalLength = 0;
171 initiatorResource->initiatorOption.dynamicDmaMem.alignment = 0;
174 initiatorResource->initiatorOption.dynamicCachedMem.numElements = 0;
175 initiatorResource->initiatorOption.dynamicCachedMem.singleElementLength = 0;
176 initiatorResource->initiatorOption.dynamicCachedMem.totalLength = 0;
177 initiatorResource->initiatorOption.dynamicCachedMem.alignment = 0;
180 /* This is not used in OS like Linux which supports dynamic memeory allocation
181 In short, this is for Windows, which does not support dynamic memory allocation */
182 /* ostiallocmemory(..... ,agFALSE) is supported by the following code eg) sat.c
183 The memory is DMA capable(uncached)
185 #ifdef CCBUILD_EncryptionDriver
186 /* extend the DMA memory for supporting two encryption DEK tables */
187 initiatorResource->initiatorOption.dynamicDmaMem.numElements = 128 + DEK_MAX_TABLE_ENTRIES / 2;
189 initiatorResource->initiatorOption.dynamicDmaMem.numElements = 128;
192 initiatorResource->initiatorOption.dynamicDmaMem.singleElementLength = sizeof(tdIORequestBody_t);
194 initiatorResource->initiatorOption.dynamicDmaMem.singleElementLength = 512;
195 initiatorResource->initiatorOption.dynamicDmaMem.totalLength =
196 initiatorResource->initiatorOption.dynamicDmaMem.numElements *
197 initiatorResource->initiatorOption.dynamicDmaMem.singleElementLength;
198 initiatorResource->initiatorOption.dynamicDmaMem.alignment = sizeof(void *);
201 /* This is not used in OS like Linux which supports dynamic memeory allocation
202 In short, this is for Windows, which does not support dynamic memory allocation */
203 /* ostiallocmemory(..... ,agTRUE) is supported by the following code eg) sat.c
204 The memory is DMA incapable(cached)
206 initiatorResource->initiatorOption.dynamicCachedMem.numElements = 1024 + 256;
208 initiatorResource->initiatorOption.dynamicCachedMem.singleElementLength = sizeof(tdIORequestBody_t);
209 initiatorResource->initiatorOption.dynamicCachedMem.singleElementLength = sizeof(tdssSMPRequestBody_t);
211 initiatorResource->initiatorOption.dynamicCachedMem.singleElementLength = 512;
212 initiatorResource->initiatorOption.dynamicCachedMem.totalLength =
213 initiatorResource->initiatorOption.dynamicCachedMem.numElements *
214 initiatorResource->initiatorOption.dynamicCachedMem.singleElementLength;
215 initiatorResource->initiatorOption.dynamicCachedMem.alignment = sizeof(void *);
218 * set the I/O request body size
220 initiatorResource->initiatorOption.ioRequestBodySize = sizeof(tdIORequestBody_t);
221 TI_DBG6(("itdssGetResource: sizeof(tdssSMPRequestBody_t) %d\n", (int)sizeof(tdssSMPRequestBody_t)));
222 TI_DBG6(("itdssGetResource: end\n"));
228 /*****************************************************************************
229 *! \brief itdssGetOperatingOptionParams
231 * Purpose: This function is called to get default parameters from the
232 * OS Specific area. This function is called in the context of
233 * tiCOMGetResource() and tiCOMInit().
236 * \param tiRoot: Pointer to initiator driver/port instance.
237 * \param option: Pointer to the Transport Dependent options.
243 *****************************************************************************/
245 itdssGetOperatingOptionParams(
247 itdssOperatingOption_t *OperatingOption
251 char *subkey1 = agNULL;
252 char *subkey2 = agNULL;
256 char *pLastUsedChar = agNULL;
257 char tmpBuffer[DEFAULT_KEY_BUFFER_SIZE];
258 char globalStr[] = "Global";
259 char iniParmsStr[] = "InitiatorParms";
261 TI_DBG6(("itdssGetOperatingOptionParams: start\n"));
264 first set the values to Default values
265 Then, overwrite them using ostiGetTransportParam()
269 /* to remove compiler warnings */
270 pLastUsedChar = pLastUsedChar;
275 buffer = &tmpBuffer[0];
276 buffLen = sizeof (tmpBuffer);
278 osti_memset(buffer, 0, buffLen);
283 OperatingOption->MaxTargets = DEFAULT_MAX_DEV; /* DEFAULT_MAX_TARGETS; */ /* 256 */
284 OperatingOption->UsecsPerTick = DEFAULT_INI_TIMER_TICK; /* 1 sec */
286 osti_memset(buffer, 0, buffLen);
289 /* defaults are overwritten in the following */
291 if ((ostiGetTransportParam(
303 ) == tiSuccess) && (lenRecv != 0))
305 if (osti_strncmp(buffer, "0x", 2) == 0)
307 OperatingOption->MaxTargets = osti_strtoul (buffer, &pLastUsedChar, 0);
311 OperatingOption->MaxTargets = osti_strtoul (buffer, &pLastUsedChar, 10);
313 TI_DBG2(("itdssGetOperatingOptionParams: MaxTargets %d\n", OperatingOption->MaxTargets ));
317 /* get UsecsPerTick */
318 if ((ostiGetTransportParam(
330 ) == tiSuccess) && (lenRecv != 0))
332 if (osti_strncmp(buffer, "0x", 2) == 0)
334 OperatingOption->UsecsPerTick = osti_strtoul (buffer, &pLastUsedChar, 0);
338 OperatingOption->UsecsPerTick = osti_strtoul (buffer, &pLastUsedChar, 10);
341 osti_memset(buffer, 0, buffLen);
349 /*****************************************************************************
352 * Purpose: This function is called to initialize the initiator specific
353 * Transport Dependent Layer.
354 * This function is not directly called by OS Specific module,
355 * as it is internally called by tiCOMInit().
357 * /param tiRoot: Pointer to driver/port instance.
358 * /param initiatorResource: Pointer to initiator functionality memory
359 * and option requirement.
360 * /param tdSharedMem: Pointer to cached memory required by the
361 * target/initiator shared functionality.
369 *****************************************************************************/
373 tiInitiatorResource_t *initiatorResource,
374 tiTdSharedMem_t *tdSharedMem
377 tiInitiatorMem_t *iniMem;
378 itdsaIni_t *Initiator;
379 itdssOperatingOption_t *OperatingOption;
380 tdsaRoot_t *tdsaRoot;
382 TI_DBG6(("itdssInit: start\n"));
383 iniMem = &initiatorResource->initiatorMem;
384 tdsaRoot = (tdsaRoot_t *)tiRoot->tdData;
386 * Cached mem for initiator Transport Dependent Layer main functionality
388 Initiator = iniMem->tdCachedMem[0].virtPtr;
391 * Get default parameters from the OS Specific area
393 OperatingOption = &Initiator->OperatingOption;
396 * Get default parameters from the OS Specific area
397 * and reads parameters from the configuration file
400 itdssGetOperatingOptionParams(tiRoot, OperatingOption);
402 * Update TD operating options with OS-layer-saved value
403 * Only UsecsPerTick is updated
405 OperatingOption->UsecsPerTick =
406 initiatorResource->initiatorOption.usecsPerTick;
408 Initiator->NumIOsActive = 0;
411 * tdCachedMem[0]: cached mem for initiator TD Layer main functionality :
413 * tdCachedMem[1-5]: not in use
416 /* initialize the timerlist */
417 itdssInitTimers(tiRoot);
420 /* Initialize the tdsaAllShared, tdssSASShared pointers */
422 Initiator->tdsaAllShared = &(tdsaRoot->tdsaAllShared);
424 TI_DBG6(("itdssInit: end\n"));
429 /*****************************************************************************
433 * Purpose: This function is called to initialize the timers
436 * \param tiRoot: pointer to the driver instance
442 *****************************************************************************/
448 tdsaRoot_t *tdsaRoot = (tdsaRoot_t *)(tiRoot->tdData);
449 tdsaContext_t *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
450 itdsaIni_t *Initiator = (itdsaIni_t *)tdsaAllShared->itdsaIni;
452 /* initialize the timerlist */
453 TDLIST_INIT_HDR(&(Initiator->timerlist));