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 #include <sys/cdefs.h>
23 __FBSDID("$FreeBSD$");
24 #include <dev/pms/config.h>
26 #include <dev/pms/freebsd/driver/common/osenv.h>
27 #include <dev/pms/freebsd/driver/common/ostypes.h>
28 #include <dev/pms/freebsd/driver/common/osdebug.h>
30 #include <dev/pms/RefTisa/sallsdk/api/sa.h>
31 #include <dev/pms/RefTisa/sallsdk/api/saapi.h>
32 #include <dev/pms/RefTisa/sallsdk/api/saosapi.h>
35 #include <dev/pms/RefTisa/discovery/api/dm.h>
36 #include <dev/pms/RefTisa/discovery/api/dmapi.h>
37 #include <dev/pms/RefTisa/discovery/api/tddmapi.h>
39 #include <dev/pms/RefTisa/discovery/dm/dmdefs.h>
40 #include <dev/pms/RefTisa/discovery/dm/dmtypes.h>
41 #include <dev/pms/RefTisa/discovery/dm/dmproto.h>
43 /*****************************************************************************/
44 /*! \brief dmCreatePort
47 * Purpose: A port context is created by this function
49 * \param dmRoot: DM context handle.
50 * \param dmPortContext: Pointer to this instance of port context
57 /*****************************************************************************/
61 dmPortContext_t *dmPortContext,
62 dmPortInfo_t *dmPortInfo)
64 dmIntRoot_t *dmIntRoot = agNULL;
65 dmIntContext_t *dmAllShared = agNULL;
66 dmIntPortContext_t *onePortContext = agNULL;
67 dmList_t *PortContextList = agNULL;
69 DM_DBG3(("dmCreatePort: start\n"));
73 DM_DBG1(("dmCreatePort: dmRoot is NULL, wrong!!!\n"));
77 if (dmPortContext == agNULL)
79 DM_DBG1(("dmCreatePort: dmPortContext is NULL, wrong!!!\n"));
83 /* the duplicacy of a port is checked */
84 if (dmPortContext->dmData != agNULL)
86 DM_DBG1(("dmCreatePort: dmPortContext->dmData is not NULL, wrong, Already created!!!\n"));
90 if (dmPortInfo == agNULL)
92 DM_DBG1(("dmCreatePort: dmPortInfo is NULL, wrong!!!\n"));
96 dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
98 if (dmIntRoot == agNULL)
100 DM_DBG1(("dmCreatePort: dmIntRoot is NULL, wrong!!!\n"));
101 return DM_RC_FAILURE;
104 dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
106 if (dmAllShared == agNULL)
108 DM_DBG1(("dmCreatePort: dmAllShared is NULL, wrong!!!\n"));
109 return DM_RC_FAILURE;
112 tddmSingleThreadedEnter(dmRoot, DM_PORT_LOCK);
113 if (DMLIST_NOT_EMPTY(&(dmAllShared->FreePortContextList)))
115 DMLIST_DEQUEUE_FROM_HEAD(&PortContextList, &(dmAllShared->FreePortContextList));
116 tddmSingleThreadedLeave(dmRoot, DM_PORT_LOCK);
117 onePortContext = DMLIST_OBJECT_BASE(dmIntPortContext_t, FreeLink, PortContextList);
118 if (onePortContext == agNULL)
120 DM_DBG1(("dmCreatePort: onePortContext is NULL in allocation, wrong!!!\n"));
121 return DM_RC_FAILURE;
124 dmPortContext->dmData = onePortContext;
125 onePortContext->DiscoveryState = DM_DSTATE_NOT_STARTED;
126 onePortContext->discoveryOptions = DM_DISCOVERY_OPTION_FULL_START;
128 onePortContext->dmRoot = dmRoot;
129 onePortContext->dmPortContext = dmPortContext;
130 onePortContext->valid = agTRUE;
131 onePortContext->RegFailed = agFALSE;
133 onePortContext->LinkRate = DM_GET_LINK_RATE(dmPortInfo->flag);
134 DM_DBG3(("dmCreatePort: linkrate %0x\n", onePortContext->LinkRate));
136 onePortContext->sasRemoteAddressHi = DM_GET_SAS_ADDRESSHI(dmPortInfo->sasRemoteAddressHi);
137 onePortContext->sasRemoteAddressLo = DM_GET_SAS_ADDRESSLO(dmPortInfo->sasRemoteAddressLo);
138 onePortContext->sasLocalAddressHi = DM_GET_SAS_ADDRESSHI(dmPortInfo->sasLocalAddressHi);
139 onePortContext->sasLocalAddressLo = DM_GET_SAS_ADDRESSLO(dmPortInfo->sasLocalAddressLo);
140 DM_DBG3(("dmCreatePort: pid %d\n", onePortContext->id));
141 DM_DBG3(("dmCreatePort: RemoteAddrHi 0x%08x RemoteAddrLo 0x%08x\n", onePortContext->sasRemoteAddressHi, onePortContext->sasRemoteAddressLo));
142 DM_DBG3(("dmCreatePort: LocalAddrHi 0x%08x LocaAddrLo 0x%08x\n", onePortContext->sasLocalAddressHi, onePortContext->sasLocalAddressLo));
144 tddmSingleThreadedEnter(dmRoot, DM_PORT_LOCK);
145 DMLIST_ENQUEUE_AT_TAIL(&(onePortContext->MainLink), &(dmAllShared->MainPortContextList));
146 tddmSingleThreadedLeave(dmRoot, DM_PORT_LOCK);
150 tddmSingleThreadedLeave(dmRoot, DM_PORT_LOCK);
151 DM_DBG1(("dmCreatePort: Attention. no more free PortContext!!!\n"));
152 return DM_RC_FAILURE;
155 return DM_RC_SUCCESS;
158 /*****************************************************************************/
159 /*! \brief dmDestroyPort
162 * Purpose: A port context is destroyed by this function
164 * \param dmRoot: DM context handle.
165 * \param dmPortContext: Pointer to this instance of port context
172 /*****************************************************************************/
176 dmPortContext_t *dmPortContext,
177 dmPortInfo_t *dmPortInfo)
179 dmIntRoot_t *dmIntRoot = agNULL;
180 dmIntContext_t *dmAllShared = agNULL;
181 dmIntPortContext_t *onePortContext = agNULL;
183 DM_DBG1(("dmDestroyPort: start\n"));
184 if (dmRoot == agNULL)
186 DM_DBG1(("dmDestroyPort: dmRoot is NULL, wrong!!!\n"));
187 return DM_RC_FAILURE;
190 if (dmPortContext == agNULL)
192 DM_DBG1(("dmDestroyPort: dmPortContext is NULL, wrong!!!\n"));
193 return DM_RC_FAILURE;
196 if (dmPortInfo == agNULL)
198 DM_DBG1(("dmDestroyPort: dmPortInfo is NULL, wrong!!!\n"));
199 return DM_RC_FAILURE;
202 dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
204 if (dmIntRoot == agNULL)
206 DM_DBG1(("dmDestroyPort: dmIntRoot is NULL, wrong!!!\n"));
207 return DM_RC_FAILURE;
210 dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
212 if (dmAllShared == agNULL)
214 DM_DBG1(("dmDestroyPort: dmAllShared is NULL, wrong!!!\n"));
215 return DM_RC_FAILURE;
219 no device(expander) to be removed since all devices should
220 be in freelist at the end of discovery
221 But if the discovery is in progress, abort it and clean up
223 onePortContext = (dmIntPortContext_t *)dmPortContext->dmData;
225 if (onePortContext == agNULL)
227 DM_DBG1(("dmDestroyPort: onePortContext is NULL, wrong!!!\n"));
228 return DM_RC_FAILURE;
232 if (onePortContext->DiscoveryState != DM_DSTATE_COMPLETED)
234 dmDiscoverAbort(dmRoot, onePortContext);
238 /* move devices from dmAllShared->MainDeviceList to dmAllShared->FreeDeviceList; dmDiscoveryDeviceCleanUp()
239 move from dmAllShared->mainExpanderList to dmAllShared->freeExpanderList; dmDiscoveryExpanderCleanUp()
244 if (onePortContext->DiscoveryState != DM_DSTATE_COMPLETED)
246 /* move from dmAllShared->discoveringExpanderList to dmAllShared->mainExpanderList
247 move from dmAllShared->UpdiscoveringExpanderList to dmAllShared->mainExpanderList
249 dmCleanAllExp(dmRoot, onePortContext);
252 /* move mainExpanderList then MainDeviceList */
253 DM_DBG3(("dmDestroyPort: before dmDiscoveryExpanderCleanUp\n"));
254 dmDumpAllMainExp(dmRoot, onePortContext);
256 /* move from dmAllShared->mainExpanderList to dmAllShared->freeExpanderList */
257 dmDiscoveryExpanderCleanUp(dmRoot, onePortContext);
259 DM_DBG3(("dmDestroyPort: after dmDiscoveryExpanderCleanUp\n"));
260 dmDumpAllMainExp(dmRoot, onePortContext);
262 DM_DBG3(("dmDestroyPort: before dmDiscoveryDeviceCleanUp\n"));
263 dmDumpAllMainDevice(dmRoot, onePortContext);
264 /* move devices from dmAllShared->MainDeviceList to dmAllShared->FreeDeviceList */
265 dmDiscoveryDeviceCleanUp(dmRoot, onePortContext);
267 DM_DBG3(("dmDestroyPort: after dmDiscoveryDeviceCleanUp\n"));
268 dmDumpAllMainDevice(dmRoot, onePortContext);
270 dmPortContextReInit(dmRoot, onePortContext);
272 tddmSingleThreadedEnter(dmRoot, DM_PORT_LOCK);
274 if (DMLIST_NOT_EMPTY(&(onePortContext->MainLink)))
276 DMLIST_DEQUEUE_THIS(&(onePortContext->MainLink));
280 DM_DBG1(("dmDestroyPort: onePortContext->MainLink is NULL, wrong!!!\n"));
283 if (DMLIST_NOT_EMPTY(&(onePortContext->FreeLink)) && DMLIST_NOT_EMPTY(&(dmAllShared->FreePortContextList)))
285 DMLIST_ENQUEUE_AT_TAIL(&(onePortContext->FreeLink), &(dmAllShared->FreePortContextList));
289 DM_DBG1(("dmDestroyPort: onePortContext->FreeLink or dmAllShared->FreePortContextList is NULL, wrong!!!\n"));
292 tddmSingleThreadedLeave(dmRoot, DM_PORT_LOCK);
294 return DM_RC_SUCCESS;