FreeBSD kernel pms device code
dmport.c
Go to the documentation of this file.
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__FBSDID("$FreeBSD$");
24#include <dev/pms/config.h>
25
29
33
34#ifdef FDS_DM
38
42
43/*****************************************************************************/
57/*****************************************************************************/
60 dmRoot_t *dmRoot,
61 dmPortContext_t *dmPortContext,
62 dmPortInfo_t *dmPortInfo)
63{
64 dmIntRoot_t *dmIntRoot = agNULL;
65 dmIntContext_t *dmAllShared = agNULL;
66 dmIntPortContext_t *onePortContext = agNULL;
67 dmList_t *PortContextList = agNULL;
68
69 DM_DBG3(("dmCreatePort: start\n"));
70
71 if (dmRoot == agNULL)
72 {
73 DM_DBG1(("dmCreatePort: dmRoot is NULL, wrong!!!\n"));
74 return DM_RC_FAILURE;
75 }
76
77 if (dmPortContext == agNULL)
78 {
79 DM_DBG1(("dmCreatePort: dmPortContext is NULL, wrong!!!\n"));
80 return DM_RC_FAILURE;
81 }
82
83 /* the duplicacy of a port is checked */
84 if (dmPortContext->dmData != agNULL)
85 {
86 DM_DBG1(("dmCreatePort: dmPortContext->dmData is not NULL, wrong, Already created!!!\n"));
87 return DM_RC_FAILURE;
88 }
89
90 if (dmPortInfo == agNULL)
91 {
92 DM_DBG1(("dmCreatePort: dmPortInfo is NULL, wrong!!!\n"));
93 return DM_RC_FAILURE;
94 }
95
96 dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
97
98 if (dmIntRoot == agNULL)
99 {
100 DM_DBG1(("dmCreatePort: dmIntRoot is NULL, wrong!!!\n"));
101 return DM_RC_FAILURE;
102 }
103
104 dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
105
106 if (dmAllShared == agNULL)
107 {
108 DM_DBG1(("dmCreatePort: dmAllShared is NULL, wrong!!!\n"));
109 return DM_RC_FAILURE;
110 }
111
113 if (DMLIST_NOT_EMPTY(&(dmAllShared->FreePortContextList)))
114 {
115 DMLIST_DEQUEUE_FROM_HEAD(&PortContextList, &(dmAllShared->FreePortContextList));
117 onePortContext = DMLIST_OBJECT_BASE(dmIntPortContext_t, FreeLink, PortContextList);
118 if (onePortContext == agNULL)
119 {
120 DM_DBG1(("dmCreatePort: onePortContext is NULL in allocation, wrong!!!\n"));
121 return DM_RC_FAILURE;
122 }
123
124 dmPortContext->dmData = onePortContext;
125 onePortContext->DiscoveryState = DM_DSTATE_NOT_STARTED;
127
128 onePortContext->dmRoot = dmRoot;
129 onePortContext->dmPortContext = dmPortContext;
130 onePortContext->valid = agTRUE;
131 onePortContext->RegFailed = agFALSE;
132
133 onePortContext->LinkRate = DM_GET_LINK_RATE(dmPortInfo->flag);
134 DM_DBG3(("dmCreatePort: linkrate %0x\n", onePortContext->LinkRate));
135
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));
143
145 DMLIST_ENQUEUE_AT_TAIL(&(onePortContext->MainLink), &(dmAllShared->MainPortContextList));
147 }
148 else
149 {
151 DM_DBG1(("dmCreatePort: Attention. no more free PortContext!!!\n"));
152 return DM_RC_FAILURE;
153 }
154
155 return DM_RC_SUCCESS;
156}
157
158/*****************************************************************************/
172/*****************************************************************************/
175 dmRoot_t *dmRoot,
176 dmPortContext_t *dmPortContext,
177 dmPortInfo_t *dmPortInfo)
178{
179 dmIntRoot_t *dmIntRoot = agNULL;
180 dmIntContext_t *dmAllShared = agNULL;
181 dmIntPortContext_t *onePortContext = agNULL;
182
183 DM_DBG1(("dmDestroyPort: start\n"));
184 if (dmRoot == agNULL)
185 {
186 DM_DBG1(("dmDestroyPort: dmRoot is NULL, wrong!!!\n"));
187 return DM_RC_FAILURE;
188 }
189
190 if (dmPortContext == agNULL)
191 {
192 DM_DBG1(("dmDestroyPort: dmPortContext is NULL, wrong!!!\n"));
193 return DM_RC_FAILURE;
194 }
195
196 if (dmPortInfo == agNULL)
197 {
198 DM_DBG1(("dmDestroyPort: dmPortInfo is NULL, wrong!!!\n"));
199 return DM_RC_FAILURE;
200 }
201
202 dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
203
204 if (dmIntRoot == agNULL)
205 {
206 DM_DBG1(("dmDestroyPort: dmIntRoot is NULL, wrong!!!\n"));
207 return DM_RC_FAILURE;
208 }
209
210 dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
211
212 if (dmAllShared == agNULL)
213 {
214 DM_DBG1(("dmDestroyPort: dmAllShared is NULL, wrong!!!\n"));
215 return DM_RC_FAILURE;
216 }
217
218 /*
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
222 */
223 onePortContext = (dmIntPortContext_t *)dmPortContext->dmData;
224
225 if (onePortContext == agNULL)
226 {
227 DM_DBG1(("dmDestroyPort: onePortContext is NULL, wrong!!!\n"));
228 return DM_RC_FAILURE;
229 }
230
231#if 1
232 if (onePortContext->DiscoveryState != DM_DSTATE_COMPLETED)
233 {
234 dmDiscoverAbort(dmRoot, onePortContext);
235 }
236 else
237 {
238 /* move devices from dmAllShared->MainDeviceList to dmAllShared->FreeDeviceList; dmDiscoveryDeviceCleanUp()
239 move from dmAllShared->mainExpanderList to dmAllShared->freeExpanderList; dmDiscoveryExpanderCleanUp()
240 */
241 }
242#endif
243
244 if (onePortContext->DiscoveryState != DM_DSTATE_COMPLETED)
245 {
246 /* move from dmAllShared->discoveringExpanderList to dmAllShared->mainExpanderList
247 move from dmAllShared->UpdiscoveringExpanderList to dmAllShared->mainExpanderList
248 */
249 dmCleanAllExp(dmRoot, onePortContext);
250 }
251
252 /* move mainExpanderList then MainDeviceList */
253 DM_DBG3(("dmDestroyPort: before dmDiscoveryExpanderCleanUp\n"));
254 dmDumpAllMainExp(dmRoot, onePortContext);
255
256 /* move from dmAllShared->mainExpanderList to dmAllShared->freeExpanderList */
257 dmDiscoveryExpanderCleanUp(dmRoot, onePortContext);
258
259 DM_DBG3(("dmDestroyPort: after dmDiscoveryExpanderCleanUp\n"));
260 dmDumpAllMainExp(dmRoot, onePortContext);
261
262 DM_DBG3(("dmDestroyPort: before dmDiscoveryDeviceCleanUp\n"));
263 dmDumpAllMainDevice(dmRoot, onePortContext);
264 /* move devices from dmAllShared->MainDeviceList to dmAllShared->FreeDeviceList */
265 dmDiscoveryDeviceCleanUp(dmRoot, onePortContext);
266
267 DM_DBG3(("dmDestroyPort: after dmDiscoveryDeviceCleanUp\n"));
268 dmDumpAllMainDevice(dmRoot, onePortContext);
269
270 dmPortContextReInit(dmRoot, onePortContext);
271
273
274 if (DMLIST_NOT_EMPTY(&(onePortContext->MainLink)))
275 {
276 DMLIST_DEQUEUE_THIS(&(onePortContext->MainLink));
277 }
278 else
279 {
280 DM_DBG1(("dmDestroyPort: onePortContext->MainLink is NULL, wrong!!!\n"));
281 }
282
283 if (DMLIST_NOT_EMPTY(&(onePortContext->FreeLink)) && DMLIST_NOT_EMPTY(&(dmAllShared->FreePortContextList)))
284 {
285 DMLIST_ENQUEUE_AT_TAIL(&(onePortContext->FreeLink), &(dmAllShared->FreePortContextList));
286 }
287 else
288 {
289 DM_DBG1(("dmDestroyPort: onePortContext->FreeLink or dmAllShared->FreePortContextList is NULL, wrong!!!\n"));
290 }
291
293
294 return DM_RC_SUCCESS;
295}
296#endif /* FDS_ DM */
297
298
299
300
301
302
303
304
#define DM_RC_FAILURE
Definition: dm.h:49
#define DM_RC_SUCCESS
Definition: dm.h:48
#define DM_DISCOVERY_OPTION_FULL_START
Definition: dm.h:59
osGLOBAL bit32 dmCreatePort(dmRoot_t *dmRoot, dmPortContext_t *dmPortContext, dmPortInfo_t *dmPortInfo)
osGLOBAL bit32 dmDestroyPort(dmRoot_t *dmRoot, dmPortContext_t *dmPortContext, dmPortInfo_t *dmPortInfo)
#define DM_DSTATE_COMPLETED
Definition: dmdefs.h:139
@ DM_PORT_LOCK
Definition: dmdefs.h:64
#define DM_DSTATE_NOT_STARTED
Definition: dmdefs.h:137
#define DM_GET_SAS_ADDRESSLO(sasAddressLo)
Definition: dmdefs.h:1068
#define DM_GET_SAS_ADDRESSHI(sasAddressHi)
Definition: dmdefs.h:1071
#define DM_DBG1(format)
Definition: dmdefs.h:124
#define DM_GET_LINK_RATE(input)
Definition: dmdefs.h:1075
#define DM_DBG3(format)
Definition: dmdefs.h:126
#define DMLIST_DEQUEUE_FROM_HEAD(atHeadHdr, listHdr)
Definition: dmlist.h:84
#define DMLIST_NOT_EMPTY(listHdr)
Definition: dmlist.h:67
#define DMLIST_DEQUEUE_THIS(hdr)
Definition: dmlist.h:70
#define DMLIST_OBJECT_BASE(baseType, fieldName, fieldPtr)
Definition: dmlist.h:152
#define DMLIST_ENQUEUE_AT_TAIL(toAddHdr, listHdr)
Definition: dmlist.h:56
__FBSDID("$FreeBSD$")
osGLOBAL void dmPortContextReInit(dmRoot_t *dmRoot, dmIntPortContext_t *onePortContext)
osGLOBAL void dmDumpAllMainExp(dmRoot_t *dmRoot, dmIntPortContext_t *onePortContext)
osGLOBAL void dmDiscoveryDeviceCleanUp(dmRoot_t *dmRoot, dmIntPortContext_t *onePortContext)
osGLOBAL void dmDiscoveryExpanderCleanUp(dmRoot_t *dmRoot, dmIntPortContext_t *onePortContext)
osGLOBAL void dmDumpAllMainDevice(dmRoot_t *dmRoot, dmIntPortContext_t *onePortContext)
osGLOBAL void dmCleanAllExp(dmRoot_t *dmRoot, dmIntPortContext_t *onePortContext)
osGLOBAL void dmDiscoverAbort(dmRoot_t *dmRoot, dmIntPortContext_t *onePortContext)
#define osGLOBAL
Definition: ostypes.h:147
#define agNULL
Definition: ostypes.h:151
unsigned int bit32
Definition: ostypes.h:99
#define agFALSE
Definition: ostypes.h:150
#define agTRUE
Definition: ostypes.h:149
The file defines the constants, data structure, and functions defined by LL API.
The file defines the declaration of tSDK APIs.
The file defines the declaration of OS APIs.
Definition: dm.h:91
void * dmData
Definition: dm.h:93
dmList_t FreePortContextList
Definition: dmtypes.h:394
dmList_t MainPortContextList
Definition: dmtypes.h:395
dmList_t FreeLink
Definition: dmtypes.h:153
dmList_t MainLink
Definition: dmtypes.h:154
bit32 sasRemoteAddressHi
Definition: dmtypes.h:156
bit32 sasRemoteAddressLo
Definition: dmtypes.h:157
bit32 DiscoveryState
Definition: dmtypes.h:137
dmPortContext_t * dmPortContext
Definition: dmtypes.h:168
bit32 discoveryOptions
Definition: dmtypes.h:142
dmRoot_t * dmRoot
Definition: dmtypes.h:169
bit32 sasLocalAddressLo
Definition: dmtypes.h:163
bit32 sasLocalAddressHi
Definition: dmtypes.h:162
dmIntContext_t dmAllShared
Definition: dmtypes.h:424
bit32 flag
Definition: dm.h:159
bit8 sasRemoteAddressHi[4]
Definition: dm.h:155
bit8 sasRemoteAddressLo[4]
Definition: dm.h:156
bit8 sasLocalAddressHi[4]
Definition: dm.h:157
bit8 sasLocalAddressLo[4]
Definition: dm.h:158
osGLOBAL void tddmSingleThreadedLeave(dmRoot_t *dmRoot, bit32 syncLockId)
osGLOBAL void tddmSingleThreadedEnter(dmRoot_t *dmRoot, bit32 syncLockId)