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

« back to all changes in this revision

Viewing changes to raideng/scsi_dev.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_DEV.CPP
 
30
//***************************************************************************
 
31
//
 
32
//Description:
 
33
//
 
34
//    This file contains the function definitions for the dptSCSIdev_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
#include "allfiles.hpp"
 
50
 
 
51
//Function - dptSCSIdev_C::dptSCSIdev_C() - start
 
52
//===========================================================================
 
53
//
 
54
//Description:
 
55
//
 
56
//    This function is the constructor for the dptSCSIdev_C class.
 
57
//
 
58
//Parameters:
 
59
//
 
60
//Return Value:
 
61
//
 
62
//Global Variables Affected:
 
63
//
 
64
//Remarks: (Side effects, Assumptions, Warnings...)
 
65
//
 
66
//
 
67
//---------------------------------------------------------------------------
 
68
 
 
69
dptSCSIdev_C::dptSCSIdev_C()
 
70
{
 
71
 
 
72
  // Clear all flags
 
73
scsiFlags = 0;
 
74
scsiFlags2 = 0;
 
75
scsiFlags3 = 0;
 
76
p2Flags = 0;
 
77
  // SCSI offset
 
78
scsiOffset = 0;
 
79
  // Clear the transfer speed
 
80
xfrSpeed = 0;
 
81
 // Clear the negotiated bus speed
 
82
busSpeed = 0;
 
83
  // Default = no name
 
84
dptName[0] = 0;
 
85
  // Default = No partition table
 
86
lastPartitionBlk = 0;
 
87
  // Default = no previous max logical block
 
88
prevMaxLBA = 0;
 
89
 
 
90
phyBlockSize = 0;
 
91
 
 
92
}
 
93
//dptSCSIdev_C::dptSCSIdev_C() - end
 
94
 
 
95
 
 
96
//Function - dptSCSIdev_C::setObjFlags() - start
 
97
//===========================================================================
 
98
//
 
99
//Description:
 
100
//
 
101
//    This function sets SCSI object flags.
 
102
//
 
103
//Parameters:
 
104
//
 
105
//Return Value:
 
106
//
 
107
//Global Variables Affected:
 
108
//
 
109
//Remarks: (Side effects, Assumptions, Warnings...)
 
110
//
 
111
//
 
112
//---------------------------------------------------------------------------
 
113
 
 
114
void    dptSCSIdev_C::setObjFlags(uSHORT flg,uSHORT)
 
115
{
 
116
 
 
117
scsiFlags = 0;
 
118
 
 
119
  // If emulated...
 
120
if (flg & FLG_DEV_EMULATED)
 
121
   scsiFlags |= FLG_ENG_EMULATED;
 
122
 
 
123
  // If emulated drive 1 (D:)...
 
124
if (flg & FLG_DEV_EMU_01)
 
125
   scsiFlags |= FLG_ENG_EMU_01;
 
126
 
 
127
  // If removeable...
 
128
if (flg & FLG_DEV_REMOVEABLE)
 
129
   scsiFlags |= FLG_ENG_REMOVEABLE;
 
130
 
 
131
  // If a valid partition table exists...
 
132
if (flg & FLG_DEV_PTABLE)
 
133
   scsiFlags |= FLG_ENG_PTABLE;
 
134
 
 
135
  // If a valid DPT reserve block exists...
 
136
if (flg & FLG_DEV_RESERVE_BLOCK)
 
137
   scsiFlags |= FLG_ENG_RESERVE_BLOCK;
 
138
 
 
139
  // If downloaded FW exists on this drive...
 
140
if (flg & FLG_DEV_DFW)
 
141
   scsiFlags |= FLG_ENG_DFW;
 
142
 
 
143
  // If a valid previous SCSI address...
 
144
if (flg & FLG_DEV_PADDR_VALID)
 
145
   scsiFlags |= FLG_ENG_VALID_PADDR;
 
146
 
 
147
  // If ECC protected...
 
148
if (flg & FLG_DEV_ECC_PROTECTED)
 
149
   setECCprotected();
 
150
 
 
151
}
 
152
//dptSCSIdev_C::setObjFlags() - end
 
153
 
 
154
 
 
155
//Function - dptSCSIdev_C::setInfo() - start
 
156
//===========================================================================
 
157
//
 
158
//Description:
 
159
//
 
160
//    This function sets SCSI device information from the specified
 
161
//input buffer.
 
162
//
 
163
//Parameters:
 
164
//
 
165
//Return Value:
 
166
//
 
167
//Global Variables Affected:
 
168
//
 
169
//Remarks: (Side effects, Assumptions, Warnings...)
 
170
//
 
171
//
 
172
//---------------------------------------------------------------------------
 
173
 
 
174
DPT_RTN_T       dptSCSIdev_C::setInfo(dptBuffer_S *toEng_P,uSHORT setAll)
 
175
{
 
176
 
 
177
   DPT_RTN_T    retVal = MSG_RTN_DATA_UNDERFLOW;
 
178
 
 
179
  // Set base class information
 
180
dptSCSIobj_C::setInfo(toEng_P,setAll);
 
181
 
 
182
  // Set the device's SCSI offset
 
183
toEng_P->extract(scsiOffset);
 
184
  // Set the device's transfer speed
 
185
toEng_P->extract(xfrSpeed);
 
186
  // Set the device's capacity information
 
187
toEng_P->extract(&capacity,sizeof(dptCapacity_S));
 
188
  // Set the device's emulation parameters
 
189
toEng_P->extract(&emulation,dptEmuParam_size);
 
190
  // If loading a configuration...
 
191
if (setAll>=2)
 
192
     // Set the DPT name
 
193
   toEng_P->extract(dptName,DPT_NAME_SIZE+2);
 
194
  // Skip the DPT name field
 
195
else
 
196
   toEng_P->skip(DPT_NAME_SIZE+2);
 
197
  // Set the last partition block used
 
198
if (toEng_P->extract(lastPartitionBlk))
 
199
   retVal = MSG_RTN_COMPLETED;
 
200
 
 
201
return (retVal);
 
202
 
 
203
}
 
204
//dptSCSIdev_C::setInfo() - end
 
205
 
 
206
 
 
207
//Function - dptSCSIdev_C::rtnInfo() - start
 
208
//===========================================================================
 
209
//
 
210
//Description:
 
211
//
 
212
//    This function returns SCSI device information to the specified
 
213
//output buffer.
 
214
//
 
215
//Parameters:
 
216
//
 
217
//Return Value:
 
218
//
 
219
//Global Variables Affected:
 
220
//
 
221
//Remarks: (Side effects, Assumptions, Warnings...)
 
222
//
 
223
//
 
224
//---------------------------------------------------------------------------
 
225
 
 
226
DPT_RTN_T       dptSCSIdev_C::rtnInfo(dptBuffer_S *fromEng_P)
 
227
{
 
228
 
 
229
   DPT_RTN_T    retVal = MSG_RTN_DATA_OVERFLOW;
 
230
 
 
231
  // Return base class information
 
232
dptSCSIobj_C::rtnInfo(fromEng_P);
 
233
 
 
234
  // Return the device's SCSI offset
 
235
fromEng_P->insert(scsiOffset);
 
236
  // Return the device's transfer speed
 
237
fromEng_P->insert(xfrSpeed);
 
238
  // Return the device's capacity information
 
239
fromEng_P->insert(&capacity,sizeof(dptCapacity_S));
 
240
  // Return the device's emulation paramters
 
241
fromEng_P->insert(&emulation,dptEmuParam_size);
 
242
  // Return the device's DPT specific name
 
243
fromEng_P->insert(dptName,DPT_NAME_SIZE+2);
 
244
  // Return the last block used by a partition
 
245
if (fromEng_P->insert(lastPartitionBlk))
 
246
   retVal = MSG_RTN_COMPLETED;
 
247
 
 
248
return (retVal);
 
249
 
 
250
}
 
251
//dptSCSIdev_C::rtnInfo() - end
 
252
 
 
253
 
 
254
//Function - dptSCSIdev_C::getObjFlags() - start
 
255
//===========================================================================
 
256
//
 
257
//Description:
 
258
//
 
259
//    This function sets SCSI device flags.
 
260
//
 
261
//Parameters:
 
262
//
 
263
//Return Value:
 
264
//
 
265
//Global Variables Affected:
 
266
//
 
267
//Remarks: (Side effects, Assumptions, Warnings...)
 
268
//
 
269
//
 
270
//---------------------------------------------------------------------------
 
271
 
 
272
void    dptSCSIdev_C::getObjFlags(uSHORT &flg)
 
273
{
 
274
 
 
275
  // Set the appropriate flags
 
276
if (isSuppressed())
 
277
   flg |= FLG_DEV_SUPPRESSED;
 
278
if (isSupDesired())
 
279
   flg |= FLG_DEV_SUP_DESIRED;
 
280
if (isEmulated())
 
281
   flg |= FLG_DEV_EMULATED;
 
282
if (scsiFlags & FLG_ENG_EMU_01)
 
283
   flg |= FLG_DEV_EMU_01;
 
284
if (isRemoveable())
 
285
   flg |= FLG_DEV_REMOVEABLE;
 
286
if (isLogical())
 
287
   flg |= FLG_DEV_LOGICAL;
 
288
if (scsiFlags & FLG_ENG_PTABLE)
 
289
   flg |= FLG_DEV_PTABLE;
 
290
if (scsiFlags & FLG_ENG_RESERVE_BLOCK)
 
291
   flg |= FLG_DEV_RESERVE_BLOCK;
 
292
if (myHBA_P()->is512kCache())
 
293
   flg |= FLG_DEV_HBA_CACHE;
 
294
if (scsiFlags & FLG_ENG_DFW)
 
295
   flg |= FLG_DEV_DFW;
 
296
if (scsiFlags & FLG_ENG_VALID_PADDR)
 
297
   flg |= FLG_DEV_PADDR_VALID;
 
298
if (isECCprotected())
 
299
   flg |= FLG_DEV_ECC_PROTECTED;
 
300
 
 
301
}
 
302
//dptSCSIdev_C::getObjFlags() - end
 
303
 
 
304
 
 
305
//Function - dptSCSIdev_C::handleMessage() - start
 
306
//===========================================================================
 
307
//
 
308
//Description:
 
309
//
 
310
//    This routine handles DPT events for the dptRAIDdev_C class.
 
311
//
 
312
//Parameters:
 
313
//
 
314
//Return Value:
 
315
//
 
316
//Global Variables Affected:
 
317
//
 
318
//Remarks: (Side effects, Assumptions, Warnings...)
 
319
//
 
320
//
 
321
//---------------------------------------------------------------------------
 
322
 
 
323
DPT_RTN_T       dptSCSIdev_C::handleMessage(DPT_MSG_T   message,
 
324
                                            dptBuffer_S *fromEng_P,
 
325
                                            dptBuffer_S *toEng_P
 
326
                                           )
 
327
{
 
328
 
 
329
   DPT_RTN_T    retVal = MSG_RTN_IGNORED;
 
330
 
 
331
switch (message) {
 
332
 
 
333
     // Attempt to set the device's DPT name
 
334
   case MSG_SET_DPT_NAME:
 
335
        retVal = setDPTname(toEng_P);
 
336
        break;
 
337
 
 
338
     // Return the device's DPT name
 
339
   case MSG_GET_DPT_NAME:
 
340
        if (fromEng_P->insert(dptName,DPT_NAME_SIZE+1))
 
341
           retVal = MSG_RTN_COMPLETED;
 
342
        else
 
343
           retVal = MSG_RTN_DATA_OVERFLOW;
 
344
        break;
 
345
 
 
346
   default:
 
347
          // Call base class event handler
 
348
        retVal = dptObject_C::handleMessage(message,fromEng_P,toEng_P);
 
349
        break;
 
350
 
 
351
 
 
352
} // end switch
 
353
 
 
354
return (retVal);
 
355
 
 
356
}
 
357
//dptSCSIdev_C::handleMessage() - end
 
358
 
 
359
 
 
360
//Function - dptSCSIdev_C::setDPTname() - start
 
361
//===========================================================================
 
362
//
 
363
//Description:
 
364
//
 
365
//    This function attempts to set the DPT name field.
 
366
//
 
367
//Parameters:
 
368
//
 
369
//Return Value:
 
370
//
 
371
//Global Variables Affected:
 
372
//
 
373
//Remarks: (Side effects, Assumptions, Warnings...)
 
374
//
 
375
//
 
376
//---------------------------------------------------------------------------
 
377
 
 
378
DPT_RTN_T       dptSCSIdev_C::setDPTname(dptBuffer_S *toEng_P)
 
379
{
 
380
 
 
381
    DPT_RTN_T   retVal = MSG_RTN_IGNORED;
 
382
 
 
383
if ( (getLevel()<=1) && isLogical() ) {
 
384
   retVal = MSG_RTN_DATA_UNDERFLOW;
 
385
     // If any data was placed in the buffer...
 
386
   if (toEng_P->writeIndex>0) {
 
387
        // If the name is used by another device...
 
388
      if ( (toEng_P->data[0]!=0) &&
 
389
           myConn_P()->isDupName(toEng_P->data,(uSHORT)toEng_P->writeIndex)) {
 
390
         retVal = MSG_RTN_FAILED | ERR_DUPLICATE_NAME;
 
391
      }
 
392
      else {
 
393
           // Indicate that a new DPT name has been specified
 
394
         scsiFlags |= FLG_ENG_NEW_NAME;
 
395
           // Set the new DPT name
 
396
         if (toEng_P->extract(dptName,DPT_NAME_SIZE))
 
397
            retVal = MSG_RTN_COMPLETED;
 
398
      }
 
399
   }
 
400
     // Insure that the name is NULL terminated
 
401
   dptName[toEng_P->readIndex] = 0;
 
402
     // Convert to all uppercase
 
403
   upperCase(dptName);
 
404
} // end if (getLevel<=1)...
 
405
 
 
406
 
 
407
return (retVal);
 
408
 
 
409
}
 
410
//dptSCSIdev_C::setDPTname() - end
 
411
 
 
412
 
 
413
//Function - dptSCSIdev_C::~dptSCSIdev_C() - start
 
414
//===========================================================================
 
415
//
 
416
//Description:
 
417
//
 
418
//    This function is the destructor for the dptSCSIdev_C class.
 
419
//
 
420
//Parameters:
 
421
//
 
422
//Return Value:
 
423
//
 
424
//Global Variables Affected:
 
425
//
 
426
//Remarks: (Side effects, Assumptions, Warnings...)
 
427
//
 
428
//
 
429
//---------------------------------------------------------------------------
 
430
 
 
431
dptSCSIdev_C::~dptSCSIdev_C()
 
432
{
 
433
 
 
434
 
 
435
 
 
436
}
 
437
//dptSCSIdev_C::~dptSCSIdev_C() - end
 
438
 
 
439