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 #include <sys/cdefs.h>
23 #include <dev/pms/config.h>
24
25 #include <dev/pms/freebsd/driver/common/osenv.h>
26 #include <dev/pms/freebsd/driver/common/ostypes.h>
27 #include <dev/pms/freebsd/driver/common/osdebug.h>
28
29 #include <dev/pms/RefTisa/tisa/api/titypes.h>
30 #include <dev/pms/RefTisa/tisa/api/ostiapi.h>
31 #include <dev/pms/RefTisa/tisa/api/tiapi.h>
32 /* for TIDEBUG_MSG */
33 #include <dev/pms/RefTisa/tisa/api/tiglobal.h>
34
35 #ifdef FDS_DM
36
37 #include <dev/pms/RefTisa/discovery/api/dm.h>
38 #include <dev/pms/RefTisa/discovery/api/dmapi.h>
39 #include <dev/pms/RefTisa/discovery/api/tddmapi.h>
40
41 #ifdef FDS_SM
42 #include <dev/pms/RefTisa/sat/api/sm.h>
43 #include <dev/pms/RefTisa/sat/api/smapi.h>
44 #endif
45
46 #ifdef INITIATOR_DRIVER
47 #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itdtypes.h>
48 #endif
49
50 #include <dev/pms/RefTisa/tisa/sassata/sas/common/tdtypes.h>
51 #include <dev/pms/RefTisa/tisa/sassata/common/tdsatypes.h>
52 #include <dev/pms/RefTisa/tisa/sassata/common/tdproto.h>
53
54 #if defined(DM_DEBUG)
55 extern bit32 gDMDebugLevel;
56 #endif
57
58 osGLOBAL bit32
tddmRotateQnumber(dmRoot_t * dmRoot,agsaDevHandle_t * agDevHandle)59 tddmRotateQnumber(
60 dmRoot_t *dmRoot,
61 agsaDevHandle_t *agDevHandle
62 )
63 {
64 tdsaRoot_t *tdsaRoot;
65 tdsaContext_t *tdsaAllShared;
66 tiRoot_t *tiRoot;
67 tdsaDeviceData_t *oneDeviceData = agNULL;
68 TI_DBG1(("tddmRotateQnumber: start\n"));
69 if (agDevHandle == agNULL)
70 {
71 TI_DBG1(("tddmRotateQnumber: agDevHandle is NULL!!!\n"));
72 return 0;
73 }
74 oneDeviceData = (tdsaDeviceData_t *)agDevHandle->osData;
75 if (oneDeviceData == agNULL)
76 {
77 TI_DBG1(("tddmRotateQnumber: oneDeviceData is NULL!!!\n"));
78 return 0;
79 }
80 tdsaRoot = (tdsaRoot_t *)dmRoot->tdData;
81 if (tdsaRoot == agNULL)
82 {
83 TI_DBG1(("tddmRotateQnumber: tdsaRoot is NULL\n"));
84 return 0;
85 }
86 tdsaAllShared = &(tdsaRoot->tdsaAllShared);
87 if (tdsaAllShared == agNULL)
88 {
89 TI_DBG1(("tddmRotateQnumber: tdsaAllShared is NULL\n"));
90 return 0;
91 }
92 tiRoot = tdsaAllShared->agRootOsDataForInt.tiRoot;
93 if (tiRoot == agNULL)
94 {
95 TI_DBG1(("tddmRotateQnumber: tiRoot is NULL\n"));
96 return 0;
97 }
98 return tdsaRotateQnumber(tiRoot, oneDeviceData);
99 }
100 osGLOBAL bit32
tdsaFindLocalMCN(tiRoot_t * tiRoot,tdsaPortContext_t * onePortContext)101 tdsaFindLocalMCN(
102 tiRoot_t *tiRoot,
103 tdsaPortContext_t *onePortContext
104 )
105 {
106 bit32 i, localMCN = 0;
107
108 TI_DBG2(("tdsaFindLocalMCN: start\n"));
109
110 if (onePortContext->valid == agFALSE)
111 {
112 TI_DBG1(("tdsaFindLocalMCN: invalid portcontext id %d\n", onePortContext->id));
113 return 0;
114 }
115
116 for(i=0;i<TD_MAX_NUM_PHYS;i++)
117 {
118 if (onePortContext->PhyIDList[i] == agTRUE)
119 {
120 localMCN++;
121 }
122 }
123
124 return localMCN;
125 }
126
127
128 /*
129 on success,
130 ostiInitiatorEvent(
131 tiRoot,
132 onePortContext->tiPortalContext,
133 agNULL,
134 tiIntrEventTypeDiscovery,
135 tiDiscOK,
136 agNULL
137 );
138 else
139 remove(de-register) all devices
140 ostiInitiatorEvent(
141 tiRoot,
142 onePortContext->tiPortalContext,
143 agNULL,
144 tiIntrEventTypeDiscovery,
145 tiDiscFailed,
146 agNULL
147 );
148
149
150 dmRoot->tdData is tdsaRoot_t (just like current TD layer)
151 dmPortContext->tdData is tdsaPortContext_t
152
153 */
154 osGLOBAL void
tddmDiscoverCB(dmRoot_t * dmRoot,dmPortContext_t * dmPortContext,bit32 eventStatus)155 tddmDiscoverCB(
156 dmRoot_t *dmRoot,
157 dmPortContext_t *dmPortContext,
158 bit32 eventStatus
159 )
160 {
161 tdsaRoot_t *tdsaRoot;
162 tdsaContext_t *tdsaAllShared;
163 tiRoot_t *tiRoot;
164 tdsaPortContext_t *onePortContext;
165 agsaRoot_t *agRoot;
166 agsaPortContext_t *agPortContext;
167
168 TI_DBG1(("tddmDiscoverCB: start\n"));
169 tdsaRoot = (tdsaRoot_t *)dmRoot->tdData;
170 if (tdsaRoot == agNULL)
171 {
172 TI_DBG1(("tddmDiscoverCB: tdsaRoot is NULL\n"));
173 return;
174 }
175
176 tdsaAllShared = &(tdsaRoot->tdsaAllShared);
177 if (tdsaAllShared == agNULL)
178 {
179 TI_DBG1(("tddmDiscoverCB: tdsaAllShared is NULL\n"));
180 return;
181 }
182
183 tiRoot = tdsaAllShared->agRootOsDataForInt.tiRoot;
184 if (tiRoot == agNULL)
185 {
186 TI_DBG1(("tddmDiscoverCB: tiRoot is NULL\n"));
187 return;
188 }
189
190 onePortContext = (tdsaPortContext_t *)dmPortContext->tdData;
191 if (onePortContext == agNULL)
192 {
193 TI_DBG1(("tddmDiscoverCB: onePortContext is NULL\n"));
194 return;
195 }
196
197 TI_DBG2(("tddmDiscoverCB: localMCN 0x%x\n", tdsaFindLocalMCN(tiRoot, onePortContext)));
198
199 if (eventStatus == dmDiscCompleted)
200 {
201 TI_DBG1(("tddmDiscoverCB: dmDiscCompleted\n"));
202 onePortContext->DiscoveryState = ITD_DSTATE_COMPLETED;
203 onePortContext->DMDiscoveryState = dmDiscCompleted;
204 TI_DBG1(("tddmDiscoverCB: pid %d tiPortalContext %p\n", onePortContext->id, onePortContext->tiPortalContext));
205
206 /* update onePortContext->UpdateMCN = agFALSE */
207 if ( onePortContext->UpdateMCN == agTRUE)
208 {
209 TI_DBG2(("tddmDiscoverCB: calling tdsaUpdateMCN\n"));
210 onePortContext->UpdateMCN = agFALSE;
211 tdsaUpdateMCN(dmRoot, onePortContext);
212 }
213
214 ostiInitiatorEvent(
215 tiRoot,
216 onePortContext->tiPortalContext,
217 agNULL,
218 tiIntrEventTypeDiscovery,
219 tiDiscOK,
220 agNULL
221 );
222 }
223 else if (eventStatus == dmDiscFailed )
224 {
225 TI_DBG1(("tddmDiscoverCB: dmDiscFailed \n"));
226 onePortContext->DiscoveryState = ITD_DSTATE_COMPLETED;
227 onePortContext->DMDiscoveryState = dmDiscFailed;
228 TI_DBG1(("tddmDiscoverCB: pid %d tiPortalContext %p\n", onePortContext->id, onePortContext->tiPortalContext));
229 agRoot = &(tdsaAllShared->agRootNonInt);
230 if (agRoot == agNULL)
231 {
232 TI_DBG1(("tddmDiscoverCB: agRoot is NULL\n"));
233 return;
234 }
235 agPortContext = onePortContext->agPortContext;
236 if (agPortContext == agNULL)
237 {
238 TI_DBG1(("tddmDiscoverCB: agPortContext is NULL\n"));
239 return;
240 }
241 /*
242 invalidate all devices in this port
243 */
244 tddmInvalidateDevicesInPort(tiRoot, onePortContext);
245
246 saPortControl(agRoot,
247 agNULL,
248 0,
249 agPortContext,
250 AGSA_PORT_IO_ABORT,
251 0 /*quarantine */,
252 0 /* unused */);
253
254
255 ostiInitiatorEvent(
256 tiRoot,
257 onePortContext->tiPortalContext,
258 agNULL,
259 tiIntrEventTypeDiscovery,
260 tiDiscFailed,
261 agNULL
262 );
263 }
264 else if (eventStatus == dmDiscAborted )
265 {
266 TI_DBG1(("tddmDiscoverCB: dmDiscAborted \n"));
267 onePortContext->DMDiscoveryState = dmDiscAborted;
268 }
269 else if (eventStatus == dmDiscAbortFailed )
270 {
271 TI_DBG1(("tddmDiscoverCB: dmDiscAbortFailed \n"));
272 onePortContext->DMDiscoveryState = dmDiscAbortFailed;
273 }
274 else if (eventStatus == dmDiscAbortInvalid )
275 {
276 TI_DBG1(("tddmDiscoverCB: dmDiscAbortInvalid \n"));
277 onePortContext->DMDiscoveryState = dmDiscAbortInvalid;
278 }
279 else if (eventStatus == dmDiscAbortInProgress )
280 {
281 TI_DBG1(("tddmDiscoverCB: dmDiscAbortInProgress \n"));
282 onePortContext->DMDiscoveryState = dmDiscAbortInProgress;
283 }
284 else
285 {
286 TI_DBG1(("tddmDiscoverCB: undefined eventStatus 0x%x\n", eventStatus));
287 onePortContext->DMDiscoveryState = dmDiscFailed;
288 }
289
290 return;
291 }
292
293
294 osGLOBAL void
tddmQueryDiscoveryCB(dmRoot_t * dmRoot,dmPortContext_t * dmPortContext,bit32 discType,bit32 discState)295 tddmQueryDiscoveryCB(
296 dmRoot_t *dmRoot,
297 dmPortContext_t *dmPortContext,
298 bit32 discType,
299 bit32 discState
300 )
301 {
302 tdsaPortContext_t *onePortContext = agNULL;
303
304 TI_DBG2(("tddmQueryDiscoveryCB: start\n"));
305 onePortContext = (tdsaPortContext_t *)dmPortContext->tdData;
306 if (onePortContext == agNULL)
307 {
308 TI_DBG1(("tddmQueryDiscoveryCB: onePortContext is NULL\n"));
309 return;
310 }
311 TI_DBG2(("tddmQueryDiscoveryCB: discType %d discState %d\n", discType, discState));
312
313 onePortContext->DMDiscoveryState = discState;
314 return;
315 }
316
317 osGLOBAL void
tddmInvalidateDevicesInPort(tiRoot_t * tiRoot,tdsaPortContext_t * onePortContext)318 tddmInvalidateDevicesInPort(
319 tiRoot_t *tiRoot,
320 tdsaPortContext_t *onePortContext
321 )
322 {
323 tdsaRoot_t *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
324 tdsaContext_t *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
325 tdsaDeviceData_t *oneDeviceData = agNULL;
326 tdList_t *DeviceListList;
327
328 TI_DBG1(("tddmInvalidateDevicesInPort: start\n"));
329
330 /* find a device's existence */
331 DeviceListList = tdsaAllShared->MainDeviceList.flink;
332 while (DeviceListList != &(tdsaAllShared->MainDeviceList))
333 {
334 oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
335 if (oneDeviceData == agNULL)
336 {
337 TI_DBG1(("tddmInvalidateDevicesInPort: oneDeviceData is NULL!!!\n"));
338 return;
339 }
340 if ((oneDeviceData->registered == agTRUE) &&
341 (oneDeviceData->tdPortContext == onePortContext)
342 )
343 {
344
345 TI_DBG3(("tddmInvalidateDevicesInPort: Found pid %d did %d\n", onePortContext->id, oneDeviceData->id));
346 if (oneDeviceData->SASAddressID.sasAddressHi == onePortContext->sasRemoteAddressHi &&
347 oneDeviceData->SASAddressID.sasAddressLo == onePortContext->sasRemoteAddressLo
348 )
349 {
350 TI_DBG1(("tddmInvalidateDevicesInPort: keeping\n"));
351 oneDeviceData->valid = agTRUE;
352 oneDeviceData->valid2 = agFALSE;
353 }
354 else if (oneDeviceData->valid == agTRUE)
355 {
356 oneDeviceData->valid = agFALSE;
357 oneDeviceData->valid2 = agFALSE;
358 oneDeviceData->registered = agFALSE;
359 }
360 }
361 DeviceListList = DeviceListList->flink;
362 }
363
364 TI_DBG3(("tddmInvalidateDevicesInPort: end\n"));
365
366 return;
367 }
368
369 osGLOBAL bit32
tddmNewSASorNot(tiRoot_t * tiRoot,tdsaPortContext_t * onePortContext,tdsaSASSubID_t * agSASSubID)370 tddmNewSASorNot(
371 tiRoot_t *tiRoot,
372 tdsaPortContext_t *onePortContext,
373 tdsaSASSubID_t *agSASSubID
374 )
375 {
376 tdsaRoot_t *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
377 tdsaContext_t *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
378 tdsaDeviceData_t *oneDeviceData = agNULL;
379 tdList_t *DeviceListList;
380 bit32 ret = agTRUE;
381
382 TI_DBG3(("tddmNewSASorNot: start\n"));
383
384 /* find a device's existence */
385 DeviceListList = tdsaAllShared->MainDeviceList.flink;
386 while (DeviceListList != &(tdsaAllShared->MainDeviceList))
387 {
388 oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
389 if (oneDeviceData == agNULL)
390 {
391 TI_DBG1(("tddmNewSASorNot: oneDeviceData is NULL!!!\n"));
392 return agFALSE;
393 }
394 if ((oneDeviceData->SASAddressID.sasAddressHi == agSASSubID->sasAddressHi) &&
395 (oneDeviceData->SASAddressID.sasAddressLo == agSASSubID->sasAddressLo) &&
396 (oneDeviceData->registered == agTRUE) &&
397 (oneDeviceData->tdPortContext == onePortContext)
398 )
399 {
400 TI_DBG3(("tddmNewSASorNot: Found pid %d did %d\n", onePortContext->id, oneDeviceData->id));
401 ret = agFALSE;
402 break;
403 }
404 DeviceListList = DeviceListList->flink;
405 }
406
407
408
409 TI_DBG3(("tddmNewSASorNot: end\n"));
410
411 return ret;
412 }
413
414 osGLOBAL tdsaDeviceData_t *
tddmPortSASDeviceFind(tiRoot_t * tiRoot,tdsaPortContext_t * onePortContext,bit32 sasAddrLo,bit32 sasAddrHi)415 tddmPortSASDeviceFind(
416 tiRoot_t *tiRoot,
417 tdsaPortContext_t *onePortContext,
418 bit32 sasAddrLo,
419 bit32 sasAddrHi
420 )
421 {
422 tdsaRoot_t *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
423 tdsaContext_t *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
424 tdsaDeviceData_t *oneDeviceData, *RetDeviceData=agNULL;
425 tdList_t *DeviceListList;
426
427 TI_DBG2(("tddmPortSASDeviceFind: start\n"));
428
429 TD_ASSERT((agNULL != tiRoot), "");
430 TD_ASSERT((agNULL != onePortContext), "");
431
432 tdsaSingleThreadedEnter(tiRoot, TD_DEVICE_LOCK);
433
434 /* find a device's existence */
435 DeviceListList = tdsaAllShared->MainDeviceList.flink;
436 while (DeviceListList != &(tdsaAllShared->MainDeviceList))
437 {
438 oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
439 if (oneDeviceData == agNULL)
440 {
441 TI_DBG1(("tddmPortSASDeviceFind: oneDeviceData is NULL!!!\n"));
442 return agNULL;
443 }
444 if ((oneDeviceData->SASAddressID.sasAddressHi == sasAddrHi) &&
445 (oneDeviceData->SASAddressID.sasAddressLo == sasAddrLo) &&
446 (oneDeviceData->valid == agTRUE) &&
447 (oneDeviceData->tdPortContext == onePortContext)
448 )
449 {
450 TI_DBG2(("tddmPortSASDeviceFind: Found pid %d did %d\n", onePortContext->id, oneDeviceData->id));
451 TI_DBG2(("tddmPortSASDeviceFind: sasAddressHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
452 TI_DBG2(("tddmPortSASDeviceFind: sasAddressLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
453 RetDeviceData = oneDeviceData;
454 break;
455 }
456 DeviceListList = DeviceListList->flink;
457 }
458
459 tdsaSingleThreadedLeave(tiRoot, TD_DEVICE_LOCK);
460
461 return RetDeviceData;
462 }
463
464 /* not in use yet */
465 osGLOBAL tdsaDeviceData_t *
tddmAddToSharedcontext(agsaRoot_t * agRoot,tdsaPortContext_t * onePortContext,tdsaSASSubID_t * agSASSubID,tdsaDeviceData_t * oneExpDeviceData,bit8 phyID)466 tddmAddToSharedcontext(
467 agsaRoot_t *agRoot,
468 tdsaPortContext_t *onePortContext,
469 tdsaSASSubID_t *agSASSubID,
470 tdsaDeviceData_t *oneExpDeviceData,
471 bit8 phyID
472 )
473 {
474 tdsaDeviceData_t *oneDeviceData = agNULL;
475 tdList_t *DeviceListList;
476 tdsaRootOsData_t *osData = (tdsaRootOsData_t *)agRoot->osData;
477 tiRoot_t *tiRoot = (tiRoot_t *)osData->tiRoot;
478 tdsaRoot_t *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
479 tdsaContext_t *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
480 bit32 new_device = agTRUE;
481
482 TI_DBG1(("tddmAddToSharedcontext: start\n"));
483
484 TI_DBG1(("tddmAddToSharedcontext: oneportContext ID %d\n", onePortContext->id));
485 /* find a device's existence */
486 DeviceListList = tdsaAllShared->MainDeviceList.flink;
487 while (DeviceListList != &(tdsaAllShared->MainDeviceList))
488 {
489 oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
490 if (oneDeviceData == agNULL)
491 {
492 TI_DBG1(("tddmAddToSharedcontext: oneDeviceData is NULL!!!\n"));
493 return agNULL;
494 }
495 if ((oneDeviceData->SASAddressID.sasAddressHi == agSASSubID->sasAddressHi) &&
496 (oneDeviceData->SASAddressID.sasAddressLo == agSASSubID->sasAddressLo) &&
497 (oneDeviceData->tdPortContext == onePortContext)
498 )
499 {
500 TI_DBG1(("tddmAddToSharedcontext: pid %dtddmAddToSharedcontext did %d\n", onePortContext->id, oneDeviceData->id));
501 new_device = agFALSE;
502 break;
503 }
504 DeviceListList = DeviceListList->flink;
505 }
506
507 /* new device */
508 if (new_device == agTRUE)
509 {
510 TI_DBG1(("tddmAddToSharedcontext: new device\n"));
511 tdsaSingleThreadedEnter(tiRoot, TD_DEVICE_LOCK);
512 if (!TDLIST_NOT_EMPTY(&(tdsaAllShared->FreeDeviceList)))
513 {
514 tdsaSingleThreadedLeave(tiRoot, TD_DEVICE_LOCK);
515 TI_DBG1(("tddmAddToSharedcontext: empty DeviceData FreeLink\n"));
516 return agNULL;
517 }
518
519 TDLIST_DEQUEUE_FROM_HEAD(&DeviceListList, &(tdsaAllShared->FreeDeviceList));
520 tdsaSingleThreadedLeave(tiRoot, TD_DEVICE_LOCK);
521 oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, FreeLink, DeviceListList);
522
523 TI_DBG1(("tddmAddToSharedcontext: oneDeviceData %p did %d\n", oneDeviceData, oneDeviceData->id));
524
525 onePortContext->Count++;
526 oneDeviceData->agRoot = agRoot;
527 /* saving sas address */
528 oneDeviceData->SASAddressID.sasAddressLo = agSASSubID->sasAddressLo;
529 oneDeviceData->SASAddressID.sasAddressHi = agSASSubID->sasAddressHi;
530 oneDeviceData->initiator_ssp_stp_smp = agSASSubID->initiator_ssp_stp_smp;
531 oneDeviceData->target_ssp_stp_smp = agSASSubID->target_ssp_stp_smp;
532 oneDeviceData->tdPortContext = onePortContext;
533 /* handles both SAS target and STP-target, SATA-device */
534 if (!DEVICE_IS_SATA_DEVICE(oneDeviceData) && !DEVICE_IS_STP_TARGET(oneDeviceData))
535 {
536 oneDeviceData->DeviceType = TD_SAS_DEVICE;
537 }
538 else
539 {
540 oneDeviceData->DeviceType = TD_SATA_DEVICE;
541 }
542
543 oneDeviceData->ExpDevice = oneExpDeviceData;
544 /* set phyID only when it has initial value of 0xFF */
545 if (oneDeviceData->phyID == 0xFF)
546 {
547 oneDeviceData->phyID = phyID;
548 }
549
550 oneDeviceData->valid = agTRUE;
551
552 /* add the devicedata to the portcontext */
553 tdsaSingleThreadedEnter(tiRoot, TD_DEVICE_LOCK);
554 TDLIST_ENQUEUE_AT_TAIL(&(oneDeviceData->MainLink), &(tdsaAllShared->MainDeviceList));
555 tdsaSingleThreadedLeave(tiRoot, TD_DEVICE_LOCK);
556 TI_DBG1(("tddmAddToSharedcontext: one case pid %d did %d \n", onePortContext->id, oneDeviceData->id));
557 TI_DBG1(("tddmAddToSharedcontext: new case pid %d did %d phyID %d\n", onePortContext->id, oneDeviceData->id, oneDeviceData->phyID));
558 }
559 else /* old device */
560 {
561 TI_DBG1(("tddmAddToSharedcontext: old device\n"));
562 TI_DBG1(("tddmAddToSharedcontext: oneDeviceData %p did %d\n", oneDeviceData, oneDeviceData->id));
563
564 oneDeviceData->agRoot = agRoot;
565 /* saving sas address */
566 oneDeviceData->SASAddressID.sasAddressLo = agSASSubID->sasAddressLo;
567 oneDeviceData->SASAddressID.sasAddressHi = agSASSubID->sasAddressHi;
568 oneDeviceData->initiator_ssp_stp_smp = agSASSubID->initiator_ssp_stp_smp;
569 oneDeviceData->target_ssp_stp_smp = agSASSubID->target_ssp_stp_smp;
570 oneDeviceData->tdPortContext = onePortContext;
571 /* handles both SAS target and STP-target, SATA-device */
572 if (!DEVICE_IS_SATA_DEVICE(oneDeviceData) && !DEVICE_IS_STP_TARGET(oneDeviceData))
573 {
574 oneDeviceData->DeviceType = TD_SAS_DEVICE;
575 }
576 else
577 {
578 oneDeviceData->DeviceType = TD_SATA_DEVICE;
579 }
580
581 oneDeviceData->ExpDevice = oneExpDeviceData;
582 /* set phyID only when it has initial value of 0xFF */
583 if (oneDeviceData->phyID == 0xFF)
584 {
585 oneDeviceData->phyID = phyID;
586 }
587
588 oneDeviceData->valid = agTRUE;
589 TI_DBG1(("tddmAddToSharedcontext: old case pid %d did %d phyID %d\n", onePortContext->id, oneDeviceData->id, oneDeviceData->phyID));
590
591 }
592 return oneDeviceData;
593
594 }
595
596
597 /*
598 calls saRegisterNewDevice()
599 in ossaDeviceRegistrationCB(), if an expander, register to DM
600 #define DEVICE_IS_SMP_TARGET(DeviceData) \
601 (((DeviceData)->target_ssp_stp_smp & DEVICE_SMP_BIT) == DEVICE_SMP_BIT)
602 */
603 osGLOBAL tdsaDeviceData_t *
tddmPortDeviceAdd(tiRoot_t * tiRoot,tdsaPortContext_t * onePortContext,dmDeviceInfo_t * dmDeviceInfo,tdsaDeviceData_t * oneExpDeviceData)604 tddmPortDeviceAdd(
605 tiRoot_t *tiRoot,
606 tdsaPortContext_t *onePortContext,
607 dmDeviceInfo_t *dmDeviceInfo,
608 tdsaDeviceData_t *oneExpDeviceData
609 )
610 {
611 tdsaRoot_t *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
612 tdsaContext_t *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
613 tdsaDeviceData_t *oneDeviceData = agNULL;
614 tdsaSASSubID_t agSASSubID;
615 bit8 phyID;
616
617 TI_DBG2(("tddmPortDeviceAdd: start\n"));
618
619
620 agSASSubID.sasAddressHi = TD_GET_SAS_ADDRESSHI(dmDeviceInfo->sasAddressHi);
621 agSASSubID.sasAddressLo = TD_GET_SAS_ADDRESSLO(dmDeviceInfo->sasAddressLo);
622 agSASSubID.initiator_ssp_stp_smp = dmDeviceInfo->initiator_ssp_stp_smp;
623 agSASSubID.target_ssp_stp_smp = dmDeviceInfo->target_ssp_stp_smp;
624 phyID = (dmDeviceInfo->ext) & 0xFF;
625
626 /* old device and already registered to LL; added by link-up event */
627 if ( agFALSE == tdssNewSASorNot(
628 onePortContext->agRoot,
629 onePortContext,
630 &agSASSubID
631 )
632 )
633 {
634 /* old device and already registered to LL; added by link-up event */
635 TI_DBG2(("tddmPortDeviceAdd: OLD qqqq initiator_ssp_stp_smp %d target_ssp_stp_smp %d\n", agSASSubID.initiator_ssp_stp_smp, agSASSubID.target_ssp_stp_smp));
636 /* find the old device */
637 oneDeviceData = tdssNewAddSASToSharedcontext(
638 onePortContext->agRoot,
639 onePortContext,
640 &agSASSubID,
641 oneExpDeviceData,
642 phyID
643 );
644
645 if (oneDeviceData == agNULL)
646 {
647 TI_DBG1(("tddmPortDeviceAdd: no more device!!! oneDeviceData is null\n"));
648 }
649
650 /* If a device is allocated */
651 if ( oneDeviceData != agNULL )
652 {
653
654 TI_DBG2(("tddmPortDeviceAdd: sasAddressHi 0x%08x\n", agSASSubID.sasAddressHi));
655 TI_DBG2(("tddmPortDeviceAdd: sasAddressLo 0x%08x\n", agSASSubID.sasAddressLo));
656 TI_DBG2(("tddmPortDeviceAdd: phyID 0x%x\n", phyID));
657
658 /* copy dmDeviceInfo to oneDeviceData->agDeviceInfo except ext field */
659 oneDeviceData->agDeviceInfo.smpTimeout = dmDeviceInfo->smpTimeout;
660 oneDeviceData->agDeviceInfo.it_NexusTimeout = dmDeviceInfo->it_NexusTimeout;
661 oneDeviceData->agDeviceInfo.firstBurstSize = dmDeviceInfo->firstBurstSize;
662 oneDeviceData->agDeviceInfo.devType_S_Rate = dmDeviceInfo->devType_S_Rate;
663 osti_memcpy(&(oneDeviceData->agDeviceInfo.sasAddressHi), &(dmDeviceInfo->sasAddressHi), 4);
664 osti_memcpy(&(oneDeviceData->agDeviceInfo.sasAddressLo), &(dmDeviceInfo->sasAddressLo), 4);
665 if (dmDeviceInfo->sataDeviceType == SATA_ATAPI_DEVICE)
666 {
667 oneDeviceData->agDeviceInfo.flag |= ATAPI_DEVICE_FLAG;
668 }
669
670 oneDeviceData->satDevData.satDeviceType = dmDeviceInfo->sataDeviceType;
671
672
673
674 oneDeviceData->agContext.osData = oneDeviceData;
675 oneDeviceData->agContext.sdkData = agNULL;
676
677 }
678 return oneDeviceData;
679 } /* old device */
680
681 /* new device */
682
683 TI_DBG2(("tddmPortDeviceAdd: NEW qqqq initiator_ssp_stp_smp %d target_ssp_stp_smp %d\n", agSASSubID.initiator_ssp_stp_smp, agSASSubID.target_ssp_stp_smp));
684
685 /* allocate a new device and set the valid bit */
686 oneDeviceData = tdssNewAddSASToSharedcontext(
687 onePortContext->agRoot,
688 onePortContext,
689 &agSASSubID,
690 oneExpDeviceData,
691 phyID
692 );
693
694 if (oneDeviceData == agNULL)
695 {
696 TI_DBG1(("tddmPortDeviceAdd: no more device!!! oneDeviceData is null\n"));
697 }
698
699 /* If a device is allocated */
700 if ( oneDeviceData != agNULL )
701 {
702
703 TI_DBG2(("tddmPortDeviceAdd: sasAddressHi 0x%08x\n", agSASSubID.sasAddressHi));
704 TI_DBG2(("tddmPortDeviceAdd: sasAddressLo 0x%08x\n", agSASSubID.sasAddressLo));
705 TI_DBG2(("tddmPortDeviceAdd: phyID 0x%x\n", phyID));
706
707 /* copy dmDeviceInfo to oneDeviceData->agDeviceInfo except ext field */
708 oneDeviceData->agDeviceInfo.smpTimeout = dmDeviceInfo->smpTimeout;
709 oneDeviceData->agDeviceInfo.it_NexusTimeout = dmDeviceInfo->it_NexusTimeout;
710 oneDeviceData->agDeviceInfo.firstBurstSize = dmDeviceInfo->firstBurstSize;
711 oneDeviceData->agDeviceInfo.devType_S_Rate = dmDeviceInfo->devType_S_Rate;
712 osti_memcpy(&(oneDeviceData->agDeviceInfo.sasAddressHi), &(dmDeviceInfo->sasAddressHi), 4);
713 osti_memcpy(&(oneDeviceData->agDeviceInfo.sasAddressLo), &(dmDeviceInfo->sasAddressLo), 4);
714
715 oneDeviceData->satDevData.satDeviceType = dmDeviceInfo->sataDeviceType;
716 if (dmDeviceInfo->sataDeviceType == SATA_ATAPI_DEVICE)
717 {
718 oneDeviceData->agDeviceInfo.flag |= ATAPI_DEVICE_FLAG;
719 }
720
721 oneDeviceData->agContext.osData = oneDeviceData;
722 oneDeviceData->agContext.sdkData = agNULL;
723
724 TI_DBG2(("tddmPortDeviceAdd: did %d\n", oneDeviceData->id));
725
726 /* don't add and register initiator for T2D */
727 if ( (((oneDeviceData->initiator_ssp_stp_smp & DEVICE_SSP_BIT) == DEVICE_SSP_BIT) &&
728 ((oneDeviceData->target_ssp_stp_smp & DEVICE_SSP_BIT) != DEVICE_SSP_BIT))
729 ||
730 (((oneDeviceData->initiator_ssp_stp_smp & DEVICE_STP_BIT) == DEVICE_STP_BIT) &&
731 ((oneDeviceData->target_ssp_stp_smp & DEVICE_SSP_BIT) != DEVICE_SSP_BIT))
732 )
733 {
734 TI_DBG1(("tddmPortDeviceAdd: initiator. no add and registration\n"));
735 TI_DBG1(("tddmPortDeviceAdd: sasAddressHi 0x%08x\n", agSASSubID.sasAddressHi));
736 TI_DBG1(("tddmPortDeviceAdd: sasAddressLo 0x%08x\n", agSASSubID.sasAddressLo));
737
738 }
739 else
740 {
741 if (oneDeviceData->registered == agFALSE)
742 {
743 #ifdef REMOVED
744 //temp; setting MCN to tdsaAllShared->MCN
745 oneDeviceData->agDeviceInfo.flag = oneDeviceData->agDeviceInfo.flag | (tdsaAllShared->MCN << 16);
746 //end temp
747 #endif
748 if( tdsaAllShared->sflag )
749 {
750 if( ! DEVICE_IS_SMP_TARGET(oneDeviceData))
751 {
752 TI_DBG1(("tddmPortDeviceAdd: saRegisterNewDevice sflag %d\n", tdsaAllShared->sflag));
753 oneDeviceData->agDeviceInfo.flag = oneDeviceData->agDeviceInfo.flag | TD_XFER_RDY_PRIORTY_DEVICE_FLAG;
754 }
755 }
756 saRegisterNewDevice( /* tddmPortDeviceAdd */
757 onePortContext->agRoot,
758 &oneDeviceData->agContext,
759 0,
760 &oneDeviceData->agDeviceInfo,
761 onePortContext->agPortContext,
762 0
763 );
764 }
765 }
766 }
767
768 return oneDeviceData;
769 }
770
771
772 /*
773 each call, add the device to the device list
774 typedef struct{
775 bit16 smpTimeout;
776 bit16 it_NexusTimeout;
777 bit16 firstBurstSize;
778 bit8 flag;
779 bit8 devType_S_Rate;
780 bit8 sasAddressHi[4];
781 bit8 sasAddressLo[4];
782 } dmDeviceInfo_t;
783
784 find oneExpDeviceData (expander device data) from dmExpDeviceInfo and
785 pass it to tddmPortDeviceAdd()
786 start here - change spec from bit32 to void
787
788 phyID = ((dmDeviceInfo->flag) & 0xFC) >> 2;
789 Initiators are not registered
790 */
791 //start here
792 osGLOBAL void
tddmReportDevice(dmRoot_t * dmRoot,dmPortContext_t * dmPortContext,dmDeviceInfo_t * dmDeviceInfo,dmDeviceInfo_t * dmExpDeviceInfo,bit32 flag)793 tddmReportDevice(
794 dmRoot_t *dmRoot,
795 dmPortContext_t *dmPortContext,
796 dmDeviceInfo_t *dmDeviceInfo, /* device */
797 dmDeviceInfo_t *dmExpDeviceInfo, /* expander the device is attached to */
798 bit32 flag
799
800 )
801 {
802 agsaRoot_t *agRoot;
803 tdsaRoot_t *tdsaRoot;
804 tdsaContext_t *tdsaAllShared;
805 tiRoot_t *tiRoot;
806 tdsaDeviceData_t *oneExpDeviceData = agNULL;
807 bit32 sasAddressHi, sasAddressLo;
808 tdsaPortContext_t *onePortContext;
809 tdsaDeviceData_t *oneDeviceData = agNULL;
810 bit32 localMCN = 0, finalMCN = 0;
811 bit32 devMCN = 1;
812 bit32 DLR = 0xA;
813 bit32 option;
814 bit32 param;
815
816 #ifdef FDS_SM
817 smRoot_t *smRoot;
818 #endif
819
820 TI_DBG2(("tddmReportDevice: start\n"));
821 tdsaRoot = (tdsaRoot_t *)dmRoot->tdData;
822 if (tdsaRoot == agNULL)
823 {
824 TI_DBG1(("tddmReportDevice: tdsaRoot is NULL\n"));
825 return;
826 }
827
828 tdsaAllShared = &(tdsaRoot->tdsaAllShared);
829 if (tdsaAllShared == agNULL)
830 {
831 TI_DBG1(("tddmReportDevice: tdsaAllShared is NULL\n"));
832 return;
833 }
834
835 tiRoot = tdsaAllShared->agRootOsDataForInt.tiRoot;
836 if (tiRoot == agNULL)
837 {
838 TI_DBG1(("tddmReportDevice: tiRoot is NULL\n"));
839 return;
840 }
841
842 onePortContext = (tdsaPortContext_t *)dmPortContext->tdData;
843 if (onePortContext == agNULL)
844 {
845 TI_DBG1(("tddmReportDevice: onePortContext is NULL\n"));
846 return;
847 }
848
849 #ifdef FDS_SM
850 smRoot = &(tdsaAllShared->smRoot);
851 #endif
852
853 TI_DBG2(("tddmReportDevice: device addrHi 0x%08x addrLo 0x%08x\n",
854 TD_GET_SAS_ADDRESSHI(dmDeviceInfo->sasAddressHi), TD_GET_SAS_ADDRESSHI(dmDeviceInfo->sasAddressLo)));
855
856 if (dmExpDeviceInfo != agNULL)
857 {
858 TI_DBG2(("tddmReportDevice: attached expander addrHi 0x%08x addrLo 0x%08x\n",
859 TD_GET_SAS_ADDRESSHI(dmExpDeviceInfo->sasAddressHi), TD_GET_SAS_ADDRESSLO(dmExpDeviceInfo->sasAddressLo)));
860 }
861 else
862 {
863 TI_DBG2(("tddmReportDevice: No attached expander\n"));
864 }
865
866 /* initiators only (e.g. SPC or SPCv) are discarded */
867 if ( (dmDeviceInfo->target_ssp_stp_smp == 0) &&
868 ( DEVICE_IS_SSP_INITIATOR(dmDeviceInfo) || DEVICE_IS_STP_INITIATOR(dmDeviceInfo) || DEVICE_IS_SMP_INITIATOR(dmDeviceInfo))
869 )
870 {
871 TI_DBG3(("tddmReportDevice: Initiators are not added\n"));
872 TI_DBG3(("tddmReportDevice: device addrHi 0x%08x addrLo 0x%08x\n",
873 TD_GET_SAS_ADDRESSHI(dmDeviceInfo->sasAddressHi), TD_GET_SAS_ADDRESSHI(dmDeviceInfo->sasAddressLo)));
874 return;
875 }
876
877 if (flag == dmDeviceArrival)
878 {
879 TI_DBG2(("tddmReportDevice: arrival\n"));
880 if (dmExpDeviceInfo != agNULL)
881 {
882 sasAddressHi = TD_GET_SAS_ADDRESSHI(dmExpDeviceInfo->sasAddressHi);
883 sasAddressLo = TD_GET_SAS_ADDRESSLO(dmExpDeviceInfo->sasAddressLo);
884
885 oneExpDeviceData = tddmPortSASDeviceFind(tiRoot, onePortContext, sasAddressLo, sasAddressHi);
886 }
887
888 tddmPortDeviceAdd(tiRoot, onePortContext, dmDeviceInfo, oneExpDeviceData);
889
890 }
891 else if (flag == dmDeviceRemoval)
892 {
893 TI_DBG2(("tddmReportDevice: removal\n"));
894 sasAddressHi = TD_GET_SAS_ADDRESSHI(dmDeviceInfo->sasAddressHi);
895 sasAddressLo = TD_GET_SAS_ADDRESSLO(dmDeviceInfo->sasAddressLo);
896 oneDeviceData = tddmPortSASDeviceFind(tiRoot, onePortContext, sasAddressLo, sasAddressHi);
897 if (oneDeviceData == agNULL)
898 {
899 TI_DBG2(("tddmReportDevice: oneDeviceData is NULL!!!\n"));
900 }
901 else
902 {
903 /* invalidate device */
904 TI_DBG2(("tddmReportDevice: invalidating\n"));
905 TI_DBG2(("tddmReportDevice: agDevHandle %p\n", oneDeviceData->agDevHandle));
906 if ( oneDeviceData->agDevHandle != agNULL)
907 {
908 TI_DBG2(("tddmReportDevice: agDevHandle->sdkData %p\n", oneDeviceData->agDevHandle->sdkData));
909 }
910 else
911 {
912 TI_DBG2(("tddmReportDevice: agDevHandle->sdkData is NULL\n"));
913 }
914 oneDeviceData->valid = agFALSE;
915 //to do; to be tested
916 agRoot = oneDeviceData->agRoot;
917 if ( (oneDeviceData->registered == agTRUE) &&
918 ( DEVICE_IS_SSP_TARGET(oneDeviceData) || DEVICE_IS_STP_TARGET(oneDeviceData)
919 || DEVICE_IS_SATA_DEVICE(oneDeviceData) || DEVICE_IS_SMP_TARGET(oneDeviceData) )
920 )
921 {
922 if ( !( DEVICE_IS_SMP_TARGET(oneDeviceData) && oneDeviceData->directlyAttached == agTRUE))
923 {
924 tdsaAbortAll(tiRoot, agRoot, oneDeviceData);
925 oneDeviceData->registered = agFALSE;
926 }
927 else
928 {
929 TI_DBG2(("tddmReportDevice: keeping\n"));
930 oneDeviceData->registered = agTRUE;
931 }
932 }
933 else if (oneDeviceData->registered == agTRUE)
934 {
935 if ( oneDeviceData->agDevHandle == agNULL)
936 {
937 TI_DBG1(("tddmReportDevice: agDevHandle->sdkData is NULL. Error!!! \n"));
938 }
939 saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
940 oneDeviceData->registered = agFALSE;
941 }
942 //to do remove
943 #ifdef FDS_SM_WRONG
944 if (DEVICE_IS_SATA_DEVICE(oneDeviceData))
945 {
946 TI_DBG2(("tddmReportDevice: smDeregisterDevice\n"));
947 smDeregisterDevice(smRoot, agNULL, oneDeviceData->agDevHandle, &(oneDeviceData->smDeviceHandle));
948 oneDeviceData->satDevData.IDDeviceValid = agFALSE;
949 }
950 #endif
951 }
952 }
953 else if (flag == dmDeviceNoChange)
954 {
955 TI_DBG2(("tddmReportDevice: no change; do nothing \n"));
956 #ifdef FDS_SM
957 sasAddressHi = TD_GET_SAS_ADDRESSHI(dmDeviceInfo->sasAddressHi);
958 sasAddressLo = TD_GET_SAS_ADDRESSLO(dmDeviceInfo->sasAddressLo);
959 oneDeviceData = tddmPortSASDeviceFind(tiRoot, onePortContext, sasAddressLo, sasAddressHi);
960 if (oneDeviceData == agNULL)
961 {
962 TI_DBG2(("tddmReportDevice: oneDeviceData is NULL!!!\n"));
963 }
964 else
965 {
966 agRoot = oneDeviceData->agRoot;
967 if ( (DEVICE_IS_SATA_DEVICE(oneDeviceData) || DEVICE_IS_STP_TARGET(oneDeviceData))
968 &&
969 oneDeviceData->satDevData.IDDeviceValid == agFALSE)
970 {
971 tdIDStart(tiRoot, agRoot, smRoot, oneDeviceData, onePortContext);
972 }
973 }
974 #endif
975 }
976 else if (flag == dmDeviceMCNChange)
977 {
978 TI_DBG2(("tddmReportDevice: dmDeviceMCNChange \n"));
979 localMCN = tdsaFindLocalMCN(tiRoot, onePortContext);
980 devMCN = DEVINFO_GET_EXT_MCN(dmDeviceInfo);
981 TI_DBG2(("tddmReportDevice: devMCN 0x%08x localMCN 0x%08x\n", devMCN, localMCN));
982
983 sasAddressHi = TD_GET_SAS_ADDRESSHI(dmDeviceInfo->sasAddressHi);
984 sasAddressLo = TD_GET_SAS_ADDRESSLO(dmDeviceInfo->sasAddressLo);
985 oneDeviceData = tddmPortSASDeviceFind(tiRoot, onePortContext, sasAddressLo, sasAddressHi);
986 if (oneDeviceData == agNULL)
987 {
988 TI_DBG1(("tddmReportDevice: oneDeviceData is NULL!!!\n"));
989 }
990 else
991 {
992 agRoot = oneDeviceData->agRoot;
993 oneDeviceData->devMCN = devMCN;
994 TI_DBG2(("tddmReportDevice: sasAddrHi 0x%08x sasAddrLo 0x%08x\n", sasAddressHi, sasAddressLo));
995 if (oneDeviceData->directlyAttached == agTRUE)
996 {
997 finalMCN = localMCN;
998 TI_DBG2(("tddmReportDevice: directlyAttached, Final MCN 0x%08x\n", finalMCN));
999 }
1000 else
1001 {
1002 finalMCN = MIN(devMCN, localMCN);
1003 TI_DBG2(("tddmReportDevice: Not directlyAttached, Final MCN 0x%08x\n", finalMCN));
1004 }
1005 if ( oneDeviceData->registered == agTRUE)
1006 {
1007 /* saSetDeviceInfo to change MCN, using finalMCN */
1008 option = 8; /* setting only MCN 1000b */
1009 param = finalMCN << 24;
1010 TI_DBG2(("tddmReportDevice: option 0x%x param 0x%x MCN 0x%x\n", option, param, finalMCN));
1011 saSetDeviceInfo(agRoot, agNULL, 0, oneDeviceData->agDevHandle, option, param, ossaSetDeviceInfoCB);
1012 }
1013 else
1014 {
1015 TI_DBG1(("tddmReportDevice: oneDeviceData is not yet registered !!!\n"));
1016 }
1017 oneDeviceData->finalMCN = finalMCN;
1018 }
1019 }
1020 else if (flag == dmDeviceRateChange)
1021 {
1022 TI_DBG1(("tddmReportDevice: dmDeviceRateChange \n"));
1023 sasAddressHi = TD_GET_SAS_ADDRESSHI(dmDeviceInfo->sasAddressHi);
1024 sasAddressLo = TD_GET_SAS_ADDRESSLO(dmDeviceInfo->sasAddressLo);
1025 oneDeviceData = tddmPortSASDeviceFind(tiRoot, onePortContext, sasAddressLo, sasAddressHi);
1026 if (oneDeviceData == agNULL)
1027 {
1028 TI_DBG1(("tddmReportDevice: oneDeviceData is NULL!!!\n"));
1029 }
1030 else
1031 {
1032 agRoot = oneDeviceData->agRoot;
1033 if ( oneDeviceData->registered == agTRUE)
1034 {
1035 option = 0x20; /* bit 5 */
1036 DLR = DEVINFO_GET_LINKRATE(dmDeviceInfo);
1037 param = DLR << 28;
1038 TI_DBG1(("tddmReportDevice: option 0x%x param 0x%x DLR 0x%x\n", option, param, DLR));
1039 saSetDeviceInfo(agRoot, agNULL, 0, oneDeviceData->agDevHandle, option, param, ossaSetDeviceInfoCB);
1040
1041 }
1042 else
1043 {
1044 TI_DBG1(("tddmReportDevice: oneDeviceData is not yet registered !!!\n"));
1045 }
1046
1047 }
1048 }
1049 else
1050 {
1051 TI_DBG1(("tddmReportDevice: unknown flag 0x%x, wrong\n", flag));
1052 }
1053
1054 return;
1055 }
1056
1057 osGLOBAL void
tdsaUpdateMCN(dmRoot_t * dmRoot,tdsaPortContext_t * onePortContext)1058 tdsaUpdateMCN(
1059 dmRoot_t *dmRoot,
1060 tdsaPortContext_t *onePortContext
1061 )
1062 {
1063 tdsaRoot_t *tdsaRoot;
1064 tdsaContext_t *tdsaAllShared;
1065 tiRoot_t *tiRoot;
1066 tdsaDeviceData_t *oneDeviceData = agNULL;
1067 tdList_t *DeviceListList;
1068 bit32 localMCN = 0, finalMCN = 0;
1069 bit32 devMCN = 1;
1070 bit32 option;
1071 bit32 param;
1072
1073 TI_DBG3(("tdsaUpdateMCN: start\n"));
1074 tdsaRoot = (tdsaRoot_t *)dmRoot->tdData;
1075 if (tdsaRoot == agNULL)
1076 {
1077 TI_DBG1(("tdsaUpdateMCN: tdsaRoot is NULL\n"));
1078 return;
1079 }
1080
1081 tdsaAllShared = &(tdsaRoot->tdsaAllShared);
1082 if (tdsaAllShared == agNULL)
1083 {
1084 TI_DBG1(("tdsaUpdateMCN: tdsaAllShared is NULL\n"));
1085 return;
1086 }
1087
1088 tiRoot = tdsaAllShared->agRootOsDataForInt.tiRoot;
1089 if (tiRoot == agNULL)
1090 {
1091 TI_DBG1(("tdsaUpdateMCN: tiRoot is NULL\n"));
1092 return;
1093 }
1094
1095 if (onePortContext->valid == agFALSE)
1096 {
1097 TI_DBG1(("tdsaUpdateMCN: onePortContext is invalid\n"));
1098 return;
1099 }
1100
1101 TI_DBG3(("tdsaUpdateMCN: pid %d\n", onePortContext->id));
1102
1103 localMCN = tdsaFindLocalMCN(tiRoot, onePortContext);
1104
1105 if (TDLIST_EMPTY(&(tdsaAllShared->MainDeviceList)))
1106 {
1107 TI_DBG1(("tdsaUpdateMCN: empty device list\n"));
1108 return;
1109 }
1110
1111 /* update directly and behind expander device */
1112 DeviceListList = tdsaAllShared->MainDeviceList.flink;
1113 while (DeviceListList != &(tdsaAllShared->MainDeviceList))
1114 {
1115 oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
1116 if (oneDeviceData == agNULL)
1117 {
1118 TI_DBG1(("tdsaUpdateMCN: oneDeviceData is NULL!!!\n"));
1119 return;
1120 }
1121 TI_DBG3(("tdsaUpdateMCN: loop did %d\n", oneDeviceData->id));
1122 TI_DBG3(("tdsaUpdateMCN: sasAddrHi 0x%08x sasAddrLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi, oneDeviceData->SASAddressID.sasAddressLo));
1123 devMCN = oneDeviceData->devMCN;
1124 if ( oneDeviceData->tdPortContext == onePortContext)
1125 {
1126 if (oneDeviceData->valid == agTRUE && oneDeviceData->registered == agTRUE && oneDeviceData->directlyAttached == agTRUE)
1127 {
1128 TI_DBG3(("tdsaUpdateMCN: found directly attached\n"));
1129 finalMCN = localMCN;
1130 TI_DBG3(("tdsaUpdateMCN: devMCN 0x%08x localMCN 0x%08x\n", devMCN, localMCN));
1131 TI_DBG3(("tdsaUpdateMCN: finalMCN 0x%08x\n", finalMCN));
1132 if (oneDeviceData->finalMCN != finalMCN)
1133 {
1134 /* saSetDeviceInfo using finalMCN */
1135 option = 8; /* setting only MCN 1000b */
1136 param = finalMCN << 24;
1137 TI_DBG3(("tdsaUpdateMCN: option 0x%x param 0x%x MCN 0x%x\n", option, param, finalMCN));
1138 saSetDeviceInfo(oneDeviceData->agRoot, agNULL, 0, oneDeviceData->agDevHandle, option, param, ossaSetDeviceInfoCB);
1139 oneDeviceData->finalMCN = finalMCN;
1140 }
1141
1142 }
1143 else if (oneDeviceData->valid == agTRUE && oneDeviceData->registered == agTRUE && oneDeviceData->directlyAttached == agFALSE)
1144 {
1145 TI_DBG3(("tdsaUpdateMCN: found behind expander device\n"));
1146 finalMCN = MIN(localMCN, devMCN);
1147 TI_DBG3(("tdsaUpdateMCN: devMCN 0x%08x localMCN 0x%08x\n", devMCN, localMCN));
1148 TI_DBG3(("tdsaUpdateMCN: finalMCN 0x%08x\n", finalMCN));
1149 if (oneDeviceData->finalMCN != finalMCN)
1150 {
1151 /* saSetDeviceInfo using finalMCN */
1152 option = 8; /* setting only MCN 1000b */
1153 param = finalMCN << 24;
1154 TI_DBG3(("tdsaUpdateMCN: option 0x%x param 0x%x MCN 0x%x\n", option, param, finalMCN));
1155 saSetDeviceInfo(oneDeviceData->agRoot, agNULL, 0, oneDeviceData->agDevHandle, option, param, ossaSetDeviceInfoCB);
1156 oneDeviceData->finalMCN = finalMCN;
1157 }
1158
1159 }
1160 DeviceListList = DeviceListList->flink;
1161 }
1162 else
1163 {
1164 if (oneDeviceData->tdPortContext != agNULL)
1165 {
1166 TI_DBG3(("tdsaUpdateMCN: different portcontext; oneDeviceData->tdPortContext pid %d oneportcontext pid %d\n", oneDeviceData->tdPortContext->id, onePortContext->id));
1167 }
1168 else
1169 {
1170 TI_DBG3(("tdsaUpdateMCN: different portcontext; oneDeviceData->tdPortContext pid NULL oneportcontext pid %d\n", onePortContext->id));
1171 }
1172 DeviceListList = DeviceListList->flink;
1173 }
1174 } /* while */
1175
1176 return;
1177 }
1178
1179 osGLOBAL bit8
tddmSATADeviceTypeDecode(bit8 * pSignature)1180 tddmSATADeviceTypeDecode(bit8 * pSignature)
1181 {
1182 return (bit8)tdssSATADeviceTypeDecode(pSignature);
1183 }
1184
1185
1186 osGLOBAL void
tddmSingleThreadedEnter(dmRoot_t * dmRoot,bit32 syncLockId)1187 tddmSingleThreadedEnter(
1188 dmRoot_t *dmRoot,
1189 bit32 syncLockId
1190 )
1191 {
1192 tdsaRoot_t *tdsaRoot;
1193 tdsaContext_t *tdsaAllShared;
1194 tiRoot_t *tiRoot;
1195 bit32 offset = 0;
1196
1197 TI_DBG7(("tddmSingleThreadedEnter: start\n"));
1198
1199 tdsaRoot = (tdsaRoot_t *)dmRoot->tdData;
1200 if (tdsaRoot == agNULL)
1201 {
1202 TI_DBG1(("tddmSingleThreadedEnter: tdsaRoot is NULL\n"));
1203 return;
1204 }
1205
1206 tdsaAllShared = &(tdsaRoot->tdsaAllShared);
1207 if (tdsaAllShared == agNULL)
1208 {
1209 TI_DBG1(("tddmSingleThreadedEnter: tdsaAllShared is NULL\n"));
1210 return;
1211 }
1212
1213 tiRoot = tdsaAllShared->agRootOsDataForInt.tiRoot;
1214 if (tiRoot == agNULL)
1215 {
1216 TI_DBG1(("tddmSingleThreadedEnter: tiRoot is NULL\n"));
1217 return;
1218 }
1219 offset = tdsaAllShared->MaxNumLLLocks + tdsaAllShared->MaxNumOSLocks + TD_MAX_LOCKS;
1220
1221 ostiSingleThreadedEnter(tiRoot, syncLockId + offset);
1222 return;
1223 }
1224
1225 osGLOBAL void
tddmSingleThreadedLeave(dmRoot_t * dmRoot,bit32 syncLockId)1226 tddmSingleThreadedLeave(
1227 dmRoot_t *dmRoot,
1228 bit32 syncLockId
1229 )
1230 {
1231 tdsaRoot_t *tdsaRoot;
1232 tdsaContext_t *tdsaAllShared;
1233 tiRoot_t *tiRoot;
1234 bit32 offset = 0;
1235
1236 TI_DBG7(("tddmSingleThreadedLeave: start\n"));
1237
1238 tdsaRoot = (tdsaRoot_t *)dmRoot->tdData;
1239 if (tdsaRoot == agNULL)
1240 {
1241 TI_DBG1(("tddmSingleThreadedLeave: tdsaRoot is NULL\n"));
1242 return;
1243 }
1244
1245 tdsaAllShared = &(tdsaRoot->tdsaAllShared);
1246 if (tdsaAllShared == agNULL)
1247 {
1248 TI_DBG1(("tddmSingleThreadedLeave: tdsaAllShared is NULL\n"));
1249 return;
1250 }
1251
1252 tiRoot = tdsaAllShared->agRootOsDataForInt.tiRoot;
1253 if (tiRoot == agNULL)
1254 {
1255 TI_DBG1(("tddmSingleThreadedLeave: tiRoot is NULL\n"));
1256 return;
1257 }
1258 offset = tdsaAllShared->MaxNumLLLocks + tdsaAllShared->MaxNumOSLocks + TD_MAX_LOCKS;
1259
1260 ostiSingleThreadedLeave(tiRoot, syncLockId + offset);
1261
1262 return;
1263 }
1264
tddmGetTransportParam(dmRoot_t * dmRoot,char * key,char * subkey1,char * subkey2,char * subkey3,char * subkey4,char * subkey5,char * valueName,char * buffer,bit32 bufferLen,bit32 * lenReceived)1265 osGLOBAL bit32 tddmGetTransportParam(
1266 dmRoot_t *dmRoot,
1267 char *key,
1268 char *subkey1,
1269 char *subkey2,
1270 char *subkey3,
1271 char *subkey4,
1272 char *subkey5,
1273 char *valueName,
1274 char *buffer,
1275 bit32 bufferLen,
1276 bit32 *lenReceived
1277 )
1278 {
1279 bit32 ret = tiError;
1280
1281 TI_DBG7(("tddmGetTransportParam: start\n"));
1282 ret = ostiGetTransportParam(agNULL,
1283 key,
1284 subkey1,
1285 subkey2,
1286 subkey3,
1287 subkey4,
1288 subkey5,
1289 valueName,
1290 buffer,
1291 bufferLen,
1292 lenReceived
1293 );
1294
1295 return ret;
1296 }
1297
1298 #endif /* FDS_DM */
1299
1300