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

« back to all changes in this revision

Viewing changes to raideng/scsi_obj.cpp

  • 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
//File - SCSI_OBJ.CPP
 
30
//***************************************************************************
 
31
//
 
32
//Description:
 
33
//
 
34
//    This file contains the function definitions for the dptSCSIobj_C
 
35
//class.
 
36
//
 
37
//Author:       Doug Anderson
 
38
//Date:         3/9/93
 
39
//
 
40
//Editors:
 
41
//
 
42
//Remarks:
 
43
//
 
44
//
 
45
//***************************************************************************
 
46
 
 
47
 
 
48
//Include Files -------------------------------------------------------------
 
49
 
 
50
#include        "allfiles.hpp"  // All engine include files
 
51
 
 
52
//Function - dptSCSIobj_C::dptSCSIobj_C() - start
 
53
//===========================================================================
 
54
//
 
55
//Description:
 
56
//
 
57
//    This function is the constructor for the dptSCSIobj_C class.
 
58
//
 
59
//Parameters:
 
60
//
 
61
//Return Value:
 
62
//
 
63
//Global Variables Affected:
 
64
//
 
65
//Remarks: (Side effects, Assumptions, Warnings...)
 
66
//
 
67
//
 
68
//---------------------------------------------------------------------------
 
69
 
 
70
dptSCSIobj_C::dptSCSIobj_C()
 
71
{
 
72
 
 
73
  // Initialize the pointer to this object's HBA
 
74
hba_P = NULL;
 
75
  // Clear the engine object type
 
76
engType = DPT_SCSI_DASD;
 
77
 
 
78
memcpy(descr.vendorID,"UNKNOWN",8);
 
79
memcpy(descr.productID,"--UNKNOWN--",12);
 
80
memcpy(descr.revision,"NONE",5);
 
81
memset(userBuff,0,USER_BUFF_SIZE);
 
82
 
 
83
magicNum = 0;
 
84
 
 
85
}
 
86
//dptSCSIobj_C::dptSCSIobj_C() - end
 
87
 
 
88
 
 
89
//Function - dptSCSIobj_C::updateHBAnum() - start
 
90
//===========================================================================
 
91
//
 
92
//Description:
 
93
//
 
94
//    This function updates this objets HBA number.
 
95
//
 
96
//Parameters:
 
97
//
 
98
//Return Value:
 
99
//
 
100
//Global Variables Affected:
 
101
//
 
102
//Remarks: (Side effects, Assumptions, Warnings...)
 
103
//
 
104
//
 
105
//---------------------------------------------------------------------------
 
106
 
 
107
void    dptSCSIobj_C::updateHBAnum()
 
108
{
 
109
 
 
110
if (hba_P!=NULL)
 
111
     // Set this object's HBA number
 
112
   addr.hba = hba_P->getHBA();
 
113
 
 
114
}
 
115
//dptSCSIobj_C::updateHBAnum() - end
 
116
 
 
117
 
 
118
//Function - dptSCSIobj_C::setInfo() - start
 
119
//===========================================================================
 
120
//
 
121
//Description:
 
122
//
 
123
//    This function sets SCSI object information from data in the
 
124
//specified input buffer.
 
125
//
 
126
//Parameters:
 
127
//
 
128
//Return Value:
 
129
//
 
130
//Global Variables Affected:
 
131
//
 
132
//Remarks: (Side effects, Assumptions, Warnings...)
 
133
//
 
134
//
 
135
//---------------------------------------------------------------------------
 
136
 
 
137
DPT_RTN_T       dptSCSIobj_C::setInfo(dptBuffer_S *toEng_P,uSHORT setAll)
 
138
{
 
139
 
 
140
   DPT_RTN_T    retVal = MSG_RTN_DATA_UNDERFLOW;
 
141
   uSHORT       suggestedFlags;
 
142
   uCHAR        statFlags;
 
143
 
 
144
  // Skip this object's tag
 
145
toEng_P->skip(sizeof(DPT_TAG_T));
 
146
  // Skip the object type (already set)
 
147
toEng_P->skip(sizeof(uSHORT));
 
148
  // Set the object's flags
 
149
if (toEng_P->extract(suggestedFlags))
 
150
   setObjFlags(suggestedFlags,setAll);
 
151
 
 
152
  // Set the object's display status
 
153
toEng_P->extract(status.display);
 
154
if (status.display>3)
 
155
   status.display = DSPLY_STAT_OPTIMAL;
 
156
  // Set the object's status flags
 
157
toEng_P->extract(statFlags);
 
158
  // Only allow READY, LAP, and PAP flags to be set
 
159
status.flags = statFlags & (FLG_STAT_READY | FLG_STAT_LAP | FLG_STAT_PAP);
 
160
  // Set the object's main status
 
161
toEng_P->extract(status.main);
 
162
  // Set the object's sub status
 
163
toEng_P->extract(status.sub);
 
164
 
 
165
if (setAll)
 
166
     // Set the object's SCSI address
 
167
   toEng_P->extract(&addr,sizeof(dptAddr_S));
 
168
 
 
169
  // Skip the object's origin level
 
170
toEng_P->skip(sizeof(uSHORT));
 
171
#if defined (_DPT_STRICT_ALIGN)
 
172
toEng_P->skip(2);
 
173
#endif
 
174
  // Skip the manager that this object is attached to
 
175
toEng_P->skip(sizeof(DPT_TAG_T));
 
176
  // Set the ASCII description information
 
177
toEng_P->extract(&descr,sizeof(dptDescr_S));
 
178
descr.terminate();
 
179
descr.toUpper();
 
180
  // Set the user buffer data
 
181
if (toEng_P->extract(userBuff,USER_BUFF_SIZE))
 
182
   retVal = MSG_RTN_COMPLETED;
 
183
 
 
184
return (retVal);
 
185
 
 
186
}
 
187
//dptSCSIobj_C::setInfo() - end
 
188
 
 
189
 
 
190
//Function - dptSCSIobj_C::setInfoHandler() - start
 
191
//===========================================================================
 
192
//
 
193
//Description:
 
194
//
 
195
//    This function sets information for artificial objects.
 
196
//
 
197
//Parameters:
 
198
//
 
199
//Return Value:
 
200
//
 
201
//Global Variables Affected:
 
202
//
 
203
//Remarks: (Side effects, Assumptions, Warnings...)
 
204
//
 
205
//
 
206
//---------------------------------------------------------------------------
 
207
 
 
208
DPT_RTN_T       dptSCSIobj_C::setInfoHandler(dptBuffer_S *toEng_P)
 
209
{
 
210
 
 
211
   DPT_RTN_T    retVal = MSG_RTN_IGNORED;
 
212
 
 
213
  // Insure the object was created artificially
 
214
if (isArtificial())
 
215
     // Set object information
 
216
   retVal = setInfo(toEng_P,1);
 
217
 
 
218
return (retVal);
 
219
 
 
220
}
 
221
//dptSCSIobj_C::setInfoHandler() - end
 
222
 
 
223
 
 
224
//Function - dptSCSIobj_C::rtnInfo() - start
 
225
//===========================================================================
 
226
//
 
227
//Description:
 
228
//
 
229
//    This function returns SCSI object information to the specified
 
230
//output buffer.
 
231
//
 
232
//Parameters:
 
233
//
 
234
//Return Value:
 
235
//
 
236
//Global Variables Affected:
 
237
//
 
238
//Remarks: (Side effects, Assumptions, Warnings...)
 
239
//
 
240
//
 
241
//---------------------------------------------------------------------------
 
242
 
 
243
DPT_RTN_T       dptSCSIobj_C::rtnInfo(dptBuffer_S *fromEng_P)
 
244
{
 
245
 
 
246
   DPT_RTN_T    retVal = MSG_RTN_DATA_OVERFLOW;
 
247
   uSHORT       myFlags;
 
248
#if defined (_DPT_STRICT_ALIGN)
 
249
   uSHORT       shortFill = 0;
 
250
#endif
 
251
 
 
252
  // Return this object's tag
 
253
fromEng_P->insert(tag());
 
254
  // Return the engine object type
 
255
fromEng_P->insert(engType);
 
256
  // Return the object flags
 
257
myFlags = 0;
 
258
getObjFlags(myFlags);
 
259
fromEng_P->insert(myFlags);
 
260
  // Return the object status
 
261
fromEng_P->insert(&status,sizeof(dptStatus_S));
 
262
  // Update this object's HBA #
 
263
updateHBAnum();
 
264
  // Return the object's SCSI address
 
265
fromEng_P->insert(&addr,sizeof(dptAddr_S));
 
266
  // Return the object's origin level
 
267
fromEng_P->insert(getLevel());
 
268
#if defined (_DPT_STRICT_ALIGN)
 
269
fromEng_P->insert(shortFill);
 
270
#endif
 
271
  // Return the manager that this object is attached to
 
272
if (myMgr_P()==NULL)
 
273
   fromEng_P->insert((DPT_TAG_T)0);
 
274
else if (myMgr_P()->myMgr_P()==NULL) {
 
275
        // If a dual level array on an I2O board...
 
276
        if (isDevice() && myHBA_P()->isI2O())
 
277
                fromEng_P->insert(myHBA_P()->tag());
 
278
        else
 
279
                fromEng_P->insert((DPT_TAG_T)0);
 
280
}
 
281
else
 
282
   fromEng_P->insert(myMgr_P()->tag());
 
283
  // Return the ASCII description information
 
284
fromEng_P->insert(&descr,sizeof(dptDescr_S));
 
285
  // Return the user buffer data
 
286
if (fromEng_P->insert(userBuff,USER_BUFF_SIZE))
 
287
   retVal = MSG_RTN_COMPLETED;
 
288
 
 
289
return (retVal);
 
290
 
 
291
}
 
292
//dptSCSIobj_C::rtnInfo() - end
 
293
 
 
294
 
 
295
//Function - dptSCSIobj_C::returnID() - start
 
296
//===========================================================================
 
297
//
 
298
//Description:
 
299
//
 
300
//    This function returns this object's ID information in the specified
 
301
//output buffer.
 
302
//
 
303
//Parameters:
 
304
//
 
305
//Return Value:
 
306
//
 
307
//Global Variables Affected:
 
308
//
 
309
//Remarks: (Side effects, Assumptions, Warnings...)
 
310
//
 
311
//
 
312
//---------------------------------------------------------------------------
 
313
 
 
314
DPT_RTN_T       dptSCSIobj_C::returnID(dptBuffer_S *fromEng_P)
 
315
{
 
316
 
 
317
   DPT_RTN_T    retVal = MSG_RTN_DATA_OVERFLOW;
 
318
 
 
319
  // Return this object's tag
 
320
fromEng_P->insert(tag());
 
321
  // Return the engine object type
 
322
if (fromEng_P->insert(engType))
 
323
   retVal = MSG_RTN_COMPLETED;
 
324
 
 
325
return (retVal);
 
326
 
 
327
}
 
328
//dptSCSIobj_C::returnID() - end
 
329
 
 
330
 
 
331
//Function - dptSCSIobj_C::handleMessage() - start
 
332
//===========================================================================
 
333
//
 
334
//Description:
 
335
//
 
336
//    This routine handles DPT events for this class.
 
337
//
 
338
//Parameters:
 
339
//
 
340
//Return Value:
 
341
//
 
342
//Global Variables Affected:
 
343
//
 
344
//Remarks: (Side effects, Assumptions, Warnings...)
 
345
//
 
346
//
 
347
//---------------------------------------------------------------------------
 
348
 
 
349
DPT_RTN_T       dptSCSIobj_C::handleMessage(DPT_MSG_T   message,
 
350
                                            dptBuffer_S *fromEng_P,
 
351
                                            dptBuffer_S *toEng_P
 
352
                                           )
 
353
{
 
354
 
 
355
   DPT_RTN_T    retVal = MSG_RTN_IGNORED;
 
356
 
 
357
switch (message) {
 
358
 
 
359
     // Set absent object information
 
360
   case MSG_ABS_SET_INFO:
 
361
        retVal = setInfoHandler(toEng_P);
 
362
        break;
 
363
 
 
364
     // Return object information
 
365
   case MSG_GET_INFO:
 
366
        retVal = rtnInfo(fromEng_P);
 
367
        break;
 
368
 
 
369
     // Set the user buffer with the specified input data
 
370
   case MSG_SET_USER_BUFF:
 
371
        if (toEng_P->extract(userBuff,USER_BUFF_SIZE))
 
372
           retVal = MSG_RTN_COMPLETED;
 
373
        else
 
374
           retVal = MSG_RTN_DATA_UNDERFLOW;
 
375
        break;
 
376
 
 
377
     // Return the user buffer to the specified output buffer
 
378
   case MSG_GET_USER_BUFF:
 
379
        if (fromEng_P->insert(userBuff,USER_BUFF_SIZE))
 
380
           retVal = MSG_RTN_COMPLETED;
 
381
        else
 
382
           retVal = MSG_RTN_DATA_OVERFLOW;
 
383
        break;
 
384
 
 
385
   default:
 
386
          // Call base class event handler
 
387
        retVal = dptCoreObj_C::handleMessage(message,fromEng_P,toEng_P);
 
388
        break;
 
389
 
 
390
 
 
391
} // end switch
 
392
 
 
393
return (retVal);
 
394
 
 
395
}
 
396
//dptSCSIobj_C::handleMessage() - end
 
397
 
 
398
 
 
399
//Function - dptSCSIobj_C::rtnConfigInfo() - start
 
400
//===========================================================================
 
401
//
 
402
//Description:
 
403
//
 
404
//    This function returns this object's configuration information.
 
405
//This information is stored in the system configuration file.
 
406
//
 
407
//Parameters:
 
408
//
 
409
//Return Value:
 
410
//
 
411
//Global Variables Affected:
 
412
//
 
413
//Remarks: (Side effects, Assumptions, Warnings...)
 
414
//
 
415
//
 
416
//---------------------------------------------------------------------------
 
417
 
 
418
DPT_RTN_T       dptSCSIobj_C::rtnConfigInfo(dptBuffer_S *fromEng_P)
 
419
{
 
420
 
 
421
   DPT_RTN_T    retVal = MSG_RTN_DATA_OVERFLOW;
 
422
   uLONG        bytesLeft;
 
423
   dptBasic_S   *basic_P;
 
424
 
 
425
 
 
426
   int          oldidx;
 
427
   DEBUG_BEGIN(6, dptSCSIobj_C::rtnConfigInfo());
 
428
 
 
429
  // Get the # of bytes remaining in the buffer
 
430
bytesLeft   = fromEng_P->allocSize - fromEng_P->writeIndex;
 
431
  // If there is enough space to return this object's information...
 
432
if (bytesLeft >= (infoSize()+sizeof(uLONG))) {
 
433
     // Return the size of the object info
 
434
   fromEng_P->insert(infoSize());
 
435
 
 
436
   DEBUG(6, "infoSize=" << (int)infoSize() << " data addr=0x" << hex << \
 
437
            fromEng_P->data << " writeIndex=" << dec << fromEng_P->writeIndex << \
 
438
            " left=" << (int)bytesLeft);
 
439
 
 
440
     // Get a pointer to this object's config. info
 
441
   basic_P = (dptBasic_S *) (fromEng_P->data+fromEng_P->writeIndex);
 
442
   if (basic_P->attachedTo!=0) {
 
443
        // Return this object's manager SCSI ID instead of tag
 
444
      basic_P->attachedTo = myMgr_P()->getAddrL();
 
445
        // Reverse the SCSI address bytes
 
446
      reverseBytes(basic_P->attachedTo);
 
447
 
 
448
   DEBUG(6, PRT_SADDR(basic_P) << "new attachedTo=0x" << hex << \
 
449
            basic_P->attachedTo << " is set");
 
450
 
 
451
   }
 
452
 
 
453
   oldidx = fromEng_P->writeIndex;
 
454
 
 
455
     // Return this object's information
 
456
   retVal = rtnInfo(fromEng_P);
 
457
 
 
458
   DEBUG(6, PRT_SADDR(basic_P) << "rtnInfo() returned " << \
 
459
            (int)fromEng_P->writeIndex-oldidx << "Byte Tag=" \
 
460
            << (int)basic_P->myTag << " attachedTo=0x" << hex \
 
461
            << basic_P->attachedTo);
 
462
}
 
463
 
 
464
return (retVal);
 
465
 
 
466
}
 
467
//dptSCSIobj_C::rtnConfigInfo() - end
 
468
 
 
469