~ubuntu-branches/ubuntu/intrepid/raidutils/intrepid

« back to all changes in this revision

Viewing changes to raideng/object.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Barak Pearlmutter
  • Date: 2004-05-18 11:33:42 UTC
  • Revision ID: james.westby@ubuntu.com-20040518113342-tyqavmso5q351xi2
Tags: upstream-0.0.4
ImportĀ upstreamĀ versionĀ 0.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 1996-2004, Adaptec Corporation
 
2
 * All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions are met:
 
6
 *
 
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.
 
15
 *
 
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.
 
27
 */
 
28
 
 
29
#ifndef         __OBJECT_HPP
 
30
#define         __OBJECT_HPP
 
31
 
 
32
//File - OBJECT.HPP
 
33
//***************************************************************************
 
34
//
 
35
//Description:
 
36
//
 
37
//    This file contains the class definitions for all the DPT object
 
38
//classes.
 
39
//
 
40
//Author:       Doug Anderson
 
41
//Date:         3/25/93
 
42
//
 
43
//Editors:
 
44
//
 
45
//Remarks:
 
46
//
 
47
//
 
48
//***************************************************************************
 
49
 
 
50
 
 
51
//Class - dptCoreObj_C - start
 
52
//===========================================================================
 
53
//
 
54
//Description:
 
55
//
 
56
//    This class is the base class for all engine manageable classes.
 
57
//
 
58
//Remarks: (Side effects, Assumptions, Warnings...)
 
59
//
 
60
//
 
61
//---------------------------------------------------------------------------
 
62
 
 
63
//objFlags
 
64
  // 1=The object is a manager, 0=The object is a device
 
65
const uSHORT    FLG_OBJ_TYPE    = 0x0001;
 
66
 
 
67
class   dptCoreObj_C : public dptCore_C
 
68
{
 
69
 
 
70
// Friends............................................
 
71
 
 
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
 
75
                                                   );
 
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;
 
83
 
 
84
// Data...............................................
 
85
 
 
86
     // The manager that this object is attached to
 
87
   dptCoreMgr_C         *attachedTo_P;
 
88
     // A pointer to the object's connection
 
89
   dptCoreCon_C         *conn_P;
 
90
 
 
91
protected:
 
92
 
 
93
// Data...............................................
 
94
 
 
95
     // Miscellaneous flags - see bit definitions above
 
96
   uSHORT               objFlags;
 
97
 
 
98
// Virtual Functions..................................
 
99
 
 
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);
 
103
                        }
 
104
// Set Flags..........................................
 
105
 
 
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; }
 
110
 
 
111
public:
 
112
 
 
113
// Constructor/Destructor.............................
 
114
 
 
115
                        dptCoreObj_C();
 
116
 
 
117
// Virtual Functions..................................
 
118
 
 
119
     // Called prior to removing this object from the engine core.
 
120
     // Return values:
 
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); }
 
126
 
 
127
// Boolean Functions..................................
 
128
 
 
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 *);
 
135
 
 
136
// Return private data................................
 
137
 
 
138
     // Returns a pointer to the manager this object is attached to
 
139
   dptManager_C *       myMgr_P() {
 
140
                           return ((dptManager_C *)attachedTo_P);
 
141
                        }
 
142
     // Returns a pointer to this object's connection
 
143
   dptConnection_C *    myConn_P() {
 
144
                           return ((dptConnection_C *)conn_P);
 
145
                        }
 
146
 
 
147
     // Return this object's origin level
 
148
   virtual uSHORT       getLevel() {return (0);} //PV
 
149
 
 
150
};
 
151
//dptCoreObj_C - end
 
152
 
 
153
 
 
154
//Class - dptSCSIobj_C - start
 
155
//===========================================================================
 
156
//
 
157
//Description:
 
158
//
 
159
//   This class is the base class for all SCSI classes.  The information
 
160
//contained in this class is common to all SCSI classes.
 
161
//
 
162
//Remarks: (Side effects, Assumptions, Warnings...)
 
163
//
 
164
//---------------------------------------------------------------------------
 
165
 
 
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()  << "): "
 
171
 
 
172
#define PRT_DADDR(dev)  "(" << (int)(dev)->getHBA()  << "," \
 
173
                            << (int)(dev)->getChan() << "," \
 
174
                            << (int)(dev)->getID()   << "," \
 
175
                            << (int)(dev)->getLUN()  << "): "
 
176
 
 
177
#define PRT_SADDR(dev)  "(" << (int)(dev)->addr.hba  << "," \
 
178
                            << (int)(dev)->addr.chan << "," \
 
179
                            << (int)(dev)->addr.id   << "," \
 
180
                            << (int)(dev)->addr.lun  << "): "
 
181
 
 
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 << " "
 
187
 
 
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 << " "
 
192
 
 
193
class   dptSCSIobj_C : public dptCoreObj_C
 
194
{
 
195
 
 
196
// Friends............................................
 
197
 
 
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;
 
224
 
 
225
// Data...............................................
 
226
 
 
227
     // The object's SCSI address
 
228
   dptAddr_S            addr;
 
229
     // Pointer to this object's HBA
 
230
   dptSCSIhba_C         *hba_P;
 
231
 
 
232
     // Buffer for externaluser to store information
 
233
   uCHAR                userBuff[USER_BUFF_SIZE];
 
234
 
 
235
protected:
 
236
 
 
237
// Data...............................................
 
238
 
 
239
     // Type of engine object
 
240
   uSHORT               engType;
 
241
     // The object's status
 
242
   dptStatus_S          status;
 
243
     // The object's SCSI Inquiry information
 
244
   dptDescr_S           descr;
 
245
     // DPT RAID magic number (only used by devices)
 
246
   uLONG                magicNum;
 
247
 
 
248
// Virtual Functions..................................
 
249
 
 
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() {}
 
254
 
 
255
     // Set SAFTE flag
 
256
   virtual void         setSAFTE() {};
 
257
 
 
258
     // Set SCSI-3 Enclosure Services flag
 
259
   virtual void         setSES() {};
 
260
 
 
261
     // Handles message processing for this class
 
262
   virtual DPT_RTN_T    handleMessage(DPT_MSG_T,dptBuffer_S *,dptBuffer_S *);
 
263
 
 
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) {}
 
268
 
 
269
// Message Handlers...................................
 
270
 
 
271
     // Message handler to set artificial object information
 
272
   DPT_RTN_T            setInfoHandler(dptBuffer_S *);
 
273
 
 
274
public:
 
275
 
 
276
 
 
277
// Constructor/Destructor.............................
 
278
 
 
279
                        dptSCSIobj_C();
 
280
 
 
281
// Virtual Functions..................................
 
282
 
 
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 &) {}
 
289
 
 
290
// Return private data................................
 
291
 
 
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);  }
 
299
 
 
300
     // Return a pointer to this object's HBA
 
301
   dptHBA_C *           myHBA_P() {
 
302
                           return ((dptHBA_C *)hba_P);
 
303
                        }
 
304
 
 
305
     // Return the object type (HBA, BCD, Device...)
 
306
   uSHORT               getObjType() { return (engType); }
 
307
 
 
308
     // Return the object's RAID magic #
 
309
   uLONG                getMagicNum() { return (magicNum); }
 
310
 
 
311
// Boolean Functions..................................
 
312
 
 
313
     // Set/Clear the application level diagnostic flag
 
314
   void                 setUserDiagFlag() { status.flags |= FLG_STAT_DIAGNOSTICS; }
 
315
   void                 clrUserDiagFlag() { status.flags &= ~FLG_STAT_DIAGNOSTICS; }
 
316
 
 
317
     // Determines if an object is ready (passed test unit ready)
 
318
   uSHORT               isReady() {
 
319
                           return (status.flags & FLG_STAT_READY);
 
320
                        }
 
321
     // Determines if an object was artificially created
 
322
   uSHORT               isArtificial() {
 
323
                           return (status.flags & FLG_STAT_ARTIFICIAL);
 
324
                        }
 
325
     // Determines if an object really exists in hardware
 
326
   uSHORT               isReal() {
 
327
                           return (status.flags & FLG_STAT_REAL);
 
328
                        }
 
329
     // Determines if this device is an absent device
 
330
   uSHORT               isAbsent() {
 
331
                           return (status.display==DSPLY_STAT_ABSENT);
 
332
                        }
 
333
     // Determines if this device is a missing device
 
334
   uSHORT               isMissing() {
 
335
                           return (status.display==DSPLY_STAT_MISSING);
 
336
                        }
 
337
 
 
338
// Other Functions....................................
 
339
 
 
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
 
343
   void                 updateHBAnum();
 
344
     // Returns this objects ID
 
345
   DPT_RTN_T            returnID(dptBuffer_S *);
 
346
 
 
347
};
 
348
 
 
349
//dptSCSIobj_C - end
 
350
 
 
351
 
 
352
//Class - dptObject_C - start
 
353
//===========================================================================
 
354
//
 
355
//Description:
 
356
//
 
357
//    This class is the highest level DPT object class.
 
358
//
 
359
//Remarks: (Side effects, Assumptions, Warnings...)
 
360
//
 
361
//---------------------------------------------------------------------------
 
362
 
 
363
class   dptObject_C : public dptSCSIobj_C
 
364
{
 
365
 
 
366
protected:
 
367
 
 
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());
 
373
                        }
 
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);
 
378
 
 
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();
 
395
 
 
396
public:
 
397
 
 
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() {}
 
402
 
 
403
};
 
404
//dptObject_C - end
 
405
 
 
406
 
 
407
#endif