File: scsi_hba.cpp

package info (click to toggle)
raidutils 0.0.6-23
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 10,840 kB
  • sloc: cpp: 39,794; ansic: 22,774; sh: 8,306; makefile: 19
file content (618 lines) | stat: -rw-r--r-- 15,844 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
/* Copyright (c) 1996-2004, Adaptec Corporation
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 * - Neither the name of the Adaptec Corporation nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

//File - SCSI_HBA.CPP
//***************************************************************************
//
//Description:
//
//    This file contains the function definitions for the dptSCSIhba_C
//class.
//
//Author:	Doug Anderson
//Date:		3/9/93
//
//Editors:
//
//Remarks:
//
//
//***************************************************************************


//Include Files -------------------------------------------------------------

#include	"allfiles.hpp"	// All engine include files


//Function - dptSCSIhba_C::dptSCSIhba_C() - start
//===========================================================================
//
//Description:
//
//    This function is the constructor for the dptSCSIhba_C class.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

dptSCSIhba_C::dptSCSIhba_C()
{

hba_P = this;

  // Set the engine object type
engType = DPT_SCSI_HBA;

  // Clear all flags
flags = 0;
  // Zero all data
ioAddr.pci	= 0;
drvrRefNum	= 0;
drqNum		= 0xffff;
irqNum		= 0xffff;
modules		= 0;
totalMem	= 0;

eventLogCtl	= 0;

for (cpuSpeed=0;cpuSpeed<=3;cpuSpeed++) {
   busSpeed[cpuSpeed]	= 0;
   memBank[cpuSpeed]	= 0;
   id.eisaPAL[cpuSpeed]	= 0;
   extMemBank[cpuSpeed]	= 0;
}
busType		= HBA_BUS_ISA;
scsiBusSpeed	= 0;
cpuSpeed	= 0;
cpuType		= 0;

  // Set the default SCSI ID, Channel, & LUN
addr.id = 7;
addr.chan = 0;
addr.lun = 0;

  // Initialize the flash write counter
flashWriteCnt	= 0;

  // Initialize the FW type to zero
fwType		= 0;
  // Initialize the flags
hbaFlags2	= 0;

  // Initialize the PCI bus and device #
busNum		= 0;
devFnNum	= 0;

  // Initialize the HBA's RAID and Slot ID #s
raidSWid	= 0;
raidSlotID	= 0;

  // Initialize the SCSI channel information
memset(chanInfo,0,sizeof(chanInfo));

  // Initialize the HBA's background task exclusion period
excludeStart	= 0;
excludeEnd	= 0;

  // Initialize the current voltage and temperature
currVoltage = 0;
currTemperature = 0;

  // Initialize the maximum major stripe size
maxMajorStripe = 0;
  // Initialize the maximum number of components per array
maxRaidComponents = 64;
  // Initialize the maximum number of objects per array (includes physical & logical objects)
maxRaidDiskEntries = 127;
  // Initialize the maximum number of RAID entries
maxRaidMemEntries = 128;
 // Initialize the number of RAID entries currently used
numRaidEntriesUsed = 0;

  // Initialize the battery status info
batteryStatus = 0;
batteryFlags = 0;
batteryReserved = 0;

  // Flags from log page 0x33 parameter code 0x02
fwFlags = 0;
  // Host bus info from log page 0x33 parameter code 0x07
hostBusInfo = 0;

}
//dptSCSIhba_C::dptSCSIhba_C() - end


//Function - dptSCSIhba_C::setBaseFromRAIDid() - start
//===========================================================================
//
//Description:
//
//    This function sets this HBA's base address using the specified
//RAID ID #.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

void	dptSCSIhba_C::setBaseFromRAIDid(uSHORT inID)
{

  // If the index is an EISA slot #...
if ((inID>=1) && (inID<=0xf))
     // Set the EISA slot #
   ioAddr.std.eisa = (inID << 12) + 0xc88;
  // Check for known ISA addresses
else if (inID==0x10)
   ioAddr.std.isa = 0x1f0;
else if (inID==0x11)
   ioAddr.std.isa = 0x170;
else if (inID==0x12)
   ioAddr.std.isa = 0x330;
else if (inID==0x13)
   ioAddr.std.isa = 0x230;
else
   ioAddr.pci = (0xfff0 - inID) << 8;

}
//dptSCSIhba_C::setBaseFromRAIDid() - end


//Function - dptSCSIhba_C::isValidAbsentObj() - start
//===========================================================================
//
//Description:
//
//	This function determines if an artificial engine object of the
//specified type can be added to this manager's device list.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

uSHORT	dptSCSIhba_C::isValidAbsentObj(uSHORT objType)
{

uSHORT	isValid = 0;

  // If a SCSI device or bridge controller...
if ((objType<=0xff) || (objType==DPT_SCSI_BCD) || (objType!=DPT_RAID_BCD))
     // Indicate a valid artificial object type
   isValid = 1;

return (isValid);

}
//dptSCSIhba_C::isValidAbsentObj() - end


//Function - dptSCSIhba_C::setObjFlags() - start
//===========================================================================
//
//Description:
//
//    This function sets SCSI object flags.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

void	dptSCSIhba_C::setObjFlags(uSHORT flg,uSHORT setAll)
{


if (!setAll) {
     // Don't allow the primary status to be set
   flg &= ~FLG_HBA_PRIMARY;
     // Clear everything except...
   flags &= FLG_HBA_PRIMARY;
}
else
   flags = 0;

flags |= flg;

  // Never allow to be set...
flags &= ~(FLG_HBA_RAID_CAPABLE | FLG_HBA_RAID_READY);

}
//dptSCSIhba_C::setObjFlags() - end


//Function - dptSCSIhba_C::setInfo() - start
//===========================================================================
//
//Description:
//
//    This function sets SCSI HBA information from the specified
//input buffer.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T	dptSCSIhba_C::setInfo(dptBuffer_S *toEng_P,
				      uSHORT setAll
				     )
{

   DPT_RTN_T	retVal = MSG_RTN_DATA_UNDERFLOW;
#ifdef _SINIX
   uSHORT       extractStart = toEng_P->readIndex;
#endif // _SINIX

  // Set base class information
dptSCSImgr_C::setInfo(toEng_P,setAll);

if (setAll) {
     // Set the HBA's I/O address
   toEng_P->extract(ioAddr.pci);
}
else
   toEng_P->skip(4);

  // Set the # by which the driver references this HBA
toEng_P->extract(drvrRefNum);
#if defined (_DPT_STRICT_ALIGN)
toEng_P->skip(2);
#endif
  // Set the HBA's ID bytes
toEng_P->extract(id.eisaPAL,4);
  // Set the HBA's DRQ #
toEng_P->extract(drqNum);
  // Set the HBA's IRQ #
toEng_P->extract(irqNum);
  // Set the modules attached to this HBA
toEng_P->extract(modules);
#if defined (_DPT_STRICT_ALIGN)
toEng_P->skip(2);
#endif
  // Set the total amount of memory on the HBA (in bytes)
toEng_P->extract(totalMem);
  // Set the event log control word
toEng_P->extract(eventLogCtl);
  // Set the Host to HBA bus speed
toEng_P->extract(busSpeed,4);
busSpeed[3] = 0;
  // Set the Host to HBA bus type
toEng_P->extract(busType);
  // Set the maximum SCSI bus speed supported
toEng_P->extract(scsiBusSpeed);
  // Set the HBA's CPU speed
toEng_P->extract(cpuSpeed);
  // Set the CPU type
toEng_P->extract(cpuType);
  // Set the size of each memory bank
toEng_P->extract(memBank,4);
  // Set the FW type
toEng_P->extract(fwType);
#if defined (_DPT_STRICT_ALIGN)
toEng_P->skip(2);
#endif
  // Set the flags
toEng_P->extract(hbaFlags2);
  // Set the PCI bus #
toEng_P->extract(busNum);
  // Set the PCI slot #
toEng_P->extract(devFnNum);
  // Set the HBA #s used by S/W arrays
toEng_P->extract(raidSWid);
toEng_P->extract(raidSlotID);
  // Set the SCSI channel information
toEng_P->extract(chanInfo,18);

  // Set the HBA's background task exclusion period
toEng_P->extract(excludeStart);
toEng_P->extract(excludeEnd);

  // Set the current voltage and temperature
toEng_P->extract(currVoltage);
toEng_P->extract(currTemperature);

  // Set the maximum major stripe size
toEng_P->extract(maxMajorStripe);
  // Skip the number of available RAID entries for array creation
  // since this number is not stored directly in the engine
toEng_P->skip(2);

  // Set the battery status
toEng_P->extract(batteryStatus);
toEng_P->extract(batteryFlags);
toEng_P->extract(batteryReserved);

  // Return the maximum number of components per array
toEng_P->extract(maxRaidComponents);

  // Return info for channel #4
toEng_P->extract(chanInfo+3,6);

  // Skip channel #5 info
toEng_P->skip(6);

toEng_P->extract(hostBusInfo); // Host bus info from log page 0x33 parameter code 0x07
toEng_P->extract(fwFlags); // Flags from log page 0x33 parameter code 0x02

  // Skip the extra bytes
if (toEng_P->skip(4))
   retVal = MSG_RTN_COMPLETED;

return (retVal);

}
//dptSCSIhba_C::setInfo() - end


//Function - dptSCSIhba_C::rtnInfo() - start
//===========================================================================
//
//Description:
//
//    This function returns SCSI HBA information to the specified
//output buffer.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

DPT_RTN_T	dptSCSIhba_C::rtnInfo(dptBuffer_S *fromEng_P)
{

   DPT_RTN_T	retVal = MSG_RTN_DATA_OVERFLOW;
   uLONG	insertStart = fromEng_P->writeIndex;
   uSHORT	tempShort = 0;
   uSHORT	availableRaidEntries = 0;

  // Return base class information
dptSCSImgr_C::rtnInfo(fromEng_P);

  // Return the HBA's I/O address(es)
fromEng_P->insert(ioAddr.pci);
  // Return the # by which the driver references this HBA
fromEng_P->insert(drvrRefNum);
#if defined (_DPT_STRICT_ALIGN)
fromEng_P->insert(tempShort);
#endif
  // Return the HBA's ID bytes
fromEng_P->insert(id.eisaPAL,4);
  // Return the HBA's DRQ #
fromEng_P->insert(drqNum);
  // Return the HBA's IRQ #
fromEng_P->insert(irqNum);
  // Return the modules attached to this HBA
fromEng_P->insert(modules);
#if defined (_DPT_STRICT_ALIGN)
fromEng_P->insert(tempShort);
#endif
  // Return the total amount of memory on the HBA (in bytes)
fromEng_P->insert(totalMem);
  // Return the event log control word
fromEng_P->insert(eventLogCtl);
  // Return the Host to HBA bus speed
fromEng_P->insert(busSpeed,4);
  // Return the Host to HBA bus type
fromEng_P->insert(busType);
  // Return the maximum SCSI bus speed supported
fromEng_P->insert(scsiBusSpeed);
  // Return the HBA's CPU speed
fromEng_P->insert(cpuSpeed);
  // Return the CPU type
fromEng_P->insert(cpuType);
  // Return the size of each memory bank
fromEng_P->insert(memBank,4);
  // Return the FW type
fromEng_P->insert(fwType);
#if defined (_DPT_STRICT_ALIGN)
fromEng_P->insert(tempShort);
#endif
  // Return more flags
fromEng_P->insert(hbaFlags2);

  // Return the PCI bus #
fromEng_P->insert(busNum);
  // Return the PCI slot #
fromEng_P->insert(devFnNum);

  // Return the HBA #s used by S/W arrays
fromEng_P->insert(raidSWid);
fromEng_P->insert(raidSlotID);

  // Return the SCSI channel information for the first three channels
fromEng_P->insert(chanInfo,18);

  // Return the HBA's background task exclusion period
fromEng_P->insert(excludeStart);
fromEng_P->insert(excludeEnd);

  // Return the current voltage and temperature
fromEng_P->insert(currVoltage);
fromEng_P->insert(currTemperature);

  // Return the maximum major stripe size
fromEng_P->insert(maxMajorStripe);
  // Return the current number of available RAID entries
availableRaidEntries = maxRaidMemEntries - numRaidEntriesUsed;
if (availableRaidEntries > maxRaidDiskEntries)
	availableRaidEntries = maxRaidDiskEntries;
fromEng_P->insert(availableRaidEntries);

  // Return the battery status
fromEng_P->insert(batteryStatus);
fromEng_P->insert(batteryFlags);
fromEng_P->insert(batteryReserved);

  // Return the maximum number of components per array
fromEng_P->insert(maxRaidComponents);

  // Return info for channel #4
fromEng_P->insert(chanInfo+3,6);

  // Channel #5 info (extra bytes)
fromEng_P->insert(tempShort);
fromEng_P->insert(tempShort);
fromEng_P->insert(tempShort);

fromEng_P->insert(hostBusInfo); // Host bus info from log page 0x33 parameter code 0x07
fromEng_P->insert(fwFlags); // Flags from log page 0x33 parameter code 0x02

  // The extra bytes
fromEng_P->insert(tempShort);
if (fromEng_P->insert(tempShort))
   retVal = MSG_RTN_COMPLETED;

return (retVal);

}
//dptSCSIhba_C::rtnInfo() - end


//Function - dptSCSIhba_C::getObjFlags() - start
//===========================================================================
//
//Description:
//
//    This function sets SCSI object flags.
//
//Parameters:
//
//Return Value:
//
//Global Variables Affected:
//
//Remarks: (Side effects, Assumptions, Warnings...)
//
//
//---------------------------------------------------------------------------

void	dptSCSIhba_C::getObjFlags(uSHORT &flg)
{

  // Set the appropriate flags
flg |= flags;

}
//dptSCSIhba_C::getObjFlags() - end


//Function - dptSCSIhba_C::rtnMembankCapacities() - start
//===========================================================================
//Description:
//    This function returns the extended memory bank capacity information.
//---------------------------------------------------------------------------

DPT_RTN_T    dptSCSIhba_C::rtnMembankCapacities(dptBuffer_S *fromEng_P)
{

	DPT_RTN_T	retVal = MSG_RTN_DATA_OVERFLOW;

	fromEng_P->insert(extMemBank[0]);
	fromEng_P->insert(extMemBank[1]);
	fromEng_P->insert(extMemBank[2]);
	if (fromEng_P->insert(extMemBank[3])) {
		retVal = MSG_RTN_COMPLETED;
	}

	return retVal;

}
//dptSCSIhba_C::rtnMembankCapacities() - end


//Function - dptSCSIhba_C::decRaidEntries() - start
//===========================================================================
//Description:
//    This decrements the number of RAID entries used.
//---------------------------------------------------------------------------

void	dptSCSIhba_C::decRaidEntries()
{

	if (numRaidEntriesUsed)
		--numRaidEntriesUsed;

}
//dptSCSIhba_C::decRaidEntries() - end


//Function - dptSCSIhba_C::incRaidEntries() - start
//===========================================================================
//Description:
//    This increments the number of RAID entries used.
//---------------------------------------------------------------------------

void	dptSCSIhba_C::incRaidEntries()
{

	++numRaidEntriesUsed;

}
//dptSCSIhba_C::incRaidEntries() - end