1
/* Copyright (c) 1996-2004, Adaptec Corporation
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* - Redistributions of source code must retain the above copyright notice, this
8
* list of conditions and the following disclaimer.
9
* - Redistributions in binary form must reproduce the above copyright notice,
10
* this list of conditions and the following disclaimer in the documentation
11
* and/or other materials provided with the distribution.
12
* - Neither the name of the Adaptec Corporation nor the names of its
13
* contributors may be used to endorse or promote products derived from this
14
* software without specific prior written permission.
16
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
* POSSIBILITY OF SUCH DAMAGE.
33
//***************************************************************************
37
// This file contains the class definitions for all the DPT object
40
//Author: Doug Anderson
48
//***************************************************************************
51
//Class - dptCoreObj_C - start
52
//===========================================================================
56
// This class is the base class for all engine manageable classes.
58
//Remarks: (Side effects, Assumptions, Warnings...)
61
//---------------------------------------------------------------------------
64
// 1=The object is a manager, 0=The object is a device
65
const uSHORT FLG_OBJ_TYPE = 0x0001;
67
class dptCoreObj_C : public dptCore_C
70
// Friends............................................
72
// The connection's handleMessage must call object handle message
73
friend DPT_RTN_T dptCoreCon_C::handleMessage(DPT_MSG_T,DPT_TAG_T,
74
dptBuffer_S *,dptBuffer_S *,uLONG
76
// Needs to set conn_P
77
friend uSHORT dptCoreCon_C::createMgrZero();
78
// Needs to access attachedTo_P
79
friend class dptCoreMgr_C;
80
// Needs to access conn_P
81
friend class dptRAIDmgr_C;
82
friend class dptManager_C;
84
// Data...............................................
86
// The manager that this object is attached to
87
dptCoreMgr_C *attachedTo_P;
88
// A pointer to the object's connection
93
// Data...............................................
95
// Miscellaneous flags - see bit definitions above
98
// Virtual Functions..................................
100
// Handles message processing for this class
101
virtual DPT_RTN_T handleMessage(DPT_MSG_T,dptBuffer_S *,dptBuffer_S *) {
102
return (MSG_RTN_IGNORED);
104
// Set Flags..........................................
106
// Indicates that this object is a device
107
void setDevice() { objFlags &= ~FLG_OBJ_TYPE; }
108
// Indicates that this object is a device
109
void setMgr() { objFlags |= FLG_OBJ_TYPE; }
113
// Constructor/Destructor.............................
117
// Virtual Functions..................................
119
// Called prior to removing this object from the engine core.
121
// 0 = Take no action
122
// 1 = Remove from engine core and free from memory
123
// 2 = Remove from engine core but do not free from memory
124
// (The object must be maintained at a higher level)
125
virtual uSHORT preDelete() { return (1); }
127
// Boolean Functions..................................
129
// Determines if the object is a device
130
uSHORT isDevice() { return (!(objFlags & FLG_OBJ_TYPE)); }
131
// Determines if the object is a manager
132
uSHORT isManager() { return (objFlags & FLG_OBJ_TYPE); }
133
// Determines if the object is attached to the specified manager
134
uSHORT isMyObject(dptCoreMgr_C *);
136
// Return private data................................
138
// Returns a pointer to the manager this object is attached to
139
dptManager_C * myMgr_P() {
140
return ((dptManager_C *)attachedTo_P);
142
// Returns a pointer to this object's connection
143
dptConnection_C * myConn_P() {
144
return ((dptConnection_C *)conn_P);
147
// Return this object's origin level
148
virtual uSHORT getLevel() {return (0);} //PV
154
//Class - dptSCSIobj_C - start
155
//===========================================================================
159
// This class is the base class for all SCSI classes. The information
160
//contained in this class is common to all SCSI classes.
162
//Remarks: (Side effects, Assumptions, Warnings...)
164
//---------------------------------------------------------------------------
166
// Macros for easy printing scsi address during debug (see debug.h)
167
#define PRT_ADDR "(" << (int)getHBA() << "," \
168
<< (int)getChan() << "," \
169
<< (int)getID() << "," \
170
<< (int)getLUN() << "): "
172
#define PRT_DADDR(dev) "(" << (int)(dev)->getHBA() << "," \
173
<< (int)(dev)->getChan() << "," \
174
<< (int)(dev)->getID() << "," \
175
<< (int)(dev)->getLUN() << "): "
177
#define PRT_SADDR(dev) "(" << (int)(dev)->addr.hba << "," \
178
<< (int)(dev)->addr.chan << "," \
179
<< (int)(dev)->addr.id << "," \
180
<< (int)(dev)->addr.lun << "): "
182
// Macros for easy printing device status during debug (see debug.h)
183
#define PRT_STAT " Dis=" << hex << (int)status.display << \
184
" Main=" << (int)status.main << \
185
" Sub=" << (int)status.sub << \
186
" Flg=" << (int)status.flags << dec << " "
188
#define PRT_DSTAT(dev) " Dis=" << hex << (int)(dev)->status.display << \
189
" Main=" << (int)(dev)->status.main << \
190
" Sub=" << (int)(dev)->status.sub << \
191
" Flg=" << (int)(dev)->status.flags << dec << " "
193
class dptSCSIobj_C : public dptCoreObj_C
196
// Friends............................................
198
// Needs access to hba_P
199
friend class dptSCSImgr_C;
200
// Needs to access engType
201
friend class dptManager_C;
202
// Needs access to hba_P
203
friend class dptSCSIdrvr_C;
204
// Needs access to hba_P
205
friend class dptSCSIhba_C;
206
// Needs to access addr
207
friend class dptHBA_C;
208
// Needs to access descr && status
209
friend class dptSCSIcon_C;
210
// Needs to access status
211
friend class dptConnection_C;
212
// Needs to access descr
213
friend class dptDriver_C;
214
// Needs access to addr
215
friend class dptSCSIbcd_C;
216
// Needs access to addr & status
217
friend class dptRAIDmgr_C;
218
// Needs access to addr
219
friend class dptRAIDdrvr_C;
220
// Needs access to addr
221
friend class dptRAIDbcd_C;
222
// Needs access to addr
223
friend class dptRAIDdev_C;
225
// Data...............................................
227
// The object's SCSI address
229
// Pointer to this object's HBA
232
// Buffer for externaluser to store information
233
uCHAR userBuff[USER_BUFF_SIZE];
237
// Data...............................................
239
// Type of engine object
241
// The object's status
243
// The object's SCSI Inquiry information
245
// DPT RAID magic number (only used by devices)
248
// Virtual Functions..................................
250
// Return object information in the specified output buffer
251
virtual DPT_RTN_T rtnInfo(dptBuffer_S *);
252
// Set removeable media flag
253
virtual void setRemoveable() {}
256
virtual void setSAFTE() {};
258
// Set SCSI-3 Enclosure Services flag
259
virtual void setSES() {};
261
// Handles message processing for this class
262
virtual DPT_RTN_T handleMessage(DPT_MSG_T,dptBuffer_S *,dptBuffer_S *);
264
// Set absent object information from the specified input buffer
265
virtual DPT_RTN_T setInfo(dptBuffer_S *,uSHORT);
266
// Set the various object flags
267
virtual void setObjFlags(uSHORT,uSHORT) {}
269
// Message Handlers...................................
271
// Message handler to set artificial object information
272
DPT_RTN_T setInfoHandler(dptBuffer_S *);
277
// Constructor/Destructor.............................
281
// Virtual Functions..................................
283
// Return the size of this object's information structure
284
virtual uLONG infoSize() { return (0); }
285
// Return object info for system config. file
286
virtual DPT_RTN_T rtnConfigInfo(dptBuffer_S *);
287
// Get this object's flags
288
virtual void getObjFlags(uSHORT &) {}
290
// Return private data................................
292
// Return this object's SCSI address
293
dptAddr_S getAddr() { return (addr); }
294
uLONG getAddrL() { return (addr.getLong()); }
295
uCHAR getHBA() { return (addr.hba); }
296
uCHAR getChan() { return (addr.chan); }
297
uCHAR getID() { return (addr.id); }
298
uCHAR getLUN() { return (addr.lun); }
300
// Return a pointer to this object's HBA
301
dptHBA_C * myHBA_P() {
302
return ((dptHBA_C *)hba_P);
305
// Return the object type (HBA, BCD, Device...)
306
uSHORT getObjType() { return (engType); }
308
// Return the object's RAID magic #
309
uLONG getMagicNum() { return (magicNum); }
311
// Boolean Functions..................................
313
// Set/Clear the application level diagnostic flag
314
void setUserDiagFlag() { status.flags |= FLG_STAT_DIAGNOSTICS; }
315
void clrUserDiagFlag() { status.flags &= ~FLG_STAT_DIAGNOSTICS; }
317
// Determines if an object is ready (passed test unit ready)
319
return (status.flags & FLG_STAT_READY);
321
// Determines if an object was artificially created
322
uSHORT isArtificial() {
323
return (status.flags & FLG_STAT_ARTIFICIAL);
325
// Determines if an object really exists in hardware
327
return (status.flags & FLG_STAT_REAL);
329
// Determines if this device is an absent device
331
return (status.display==DSPLY_STAT_ABSENT);
333
// Determines if this device is a missing device
335
return (status.display==DSPLY_STAT_MISSING);
338
// Other Functions....................................
340
// Generate a unique magic number for a RAID component device
341
uLONG genMagicNum() { return (myConn_P()->genMagicNum()); }
342
// Updates this object's HBA number
344
// Returns this objects ID
345
DPT_RTN_T returnID(dptBuffer_S *);
352
//Class - dptObject_C - start
353
//===========================================================================
357
// This class is the highest level DPT object class.
359
//Remarks: (Side effects, Assumptions, Warnings...)
361
//---------------------------------------------------------------------------
363
class dptObject_C : public dptSCSIobj_C
368
// Entry point to send a CCB to hardware
369
virtual DPT_RTN_T launchCCB(engCCB_C *) {return (MSG_RTN_FAILED);} //PV
370
// Get a CCB to perform I/O
371
engCCB_C * getCCB() {
372
return (myConn_P()->acquireCCB());
374
// Performs a SCSI inquiry to initialize this device
375
uSHORT selfInquiry();
376
// Get read/write stats and add them to the specified buffer
377
DPT_RTN_T addRWstats(DPT_UNALIGNED uLONG *,uCHAR);
379
// Handles message processing for this class
380
virtual DPT_RTN_T handleMessage(DPT_MSG_T,dptBuffer_S *,dptBuffer_S *);
381
// Issue a SCSI mode sense or log sense to this object
382
DPT_RTN_T modeLogSense(dptBuffer_S *,dptBuffer_S *,uSHORT);
383
// Issue a SCSI log sense to this object
384
DPT_RTN_T doLogSense(dptBuffer_S *,uCHAR,uCHAR=0,uLONG=0,uSHORT=0,uCHAR=0);
385
// Issue a SCSI mode sense to this object
386
DPT_RTN_T doModeSense(dptBuffer_S *,uCHAR,uCHAR=0);
387
// Issue a SCSI mode select to this object
388
DPT_RTN_T doModeSelect(dptBuffer_S *);
389
// Sends the specified SCSI command to this object
390
DPT_RTN_T scsiPassThru(dptBuffer_S *,dptBuffer_S *);
391
// Sends a SCSI reserve command to this object
392
DPT_RTN_T reserveDevice();
393
// Sends a SCSI release command to this object
394
DPT_RTN_T releaseDevice();
398
// Initializes this object using the specified SCSI inquiry data
399
uSHORT inquiryInit(sdInquiry_S *);
400
// Performs initialization of a real object (SCSI Inquiry...)
401
virtual void realInit() {}