@@ -186,7 +186,7 @@ void HyperVStorage::setHBAInfo() {
186186 propString->release ();
187187 }
188188
189- propString = OSString::withCString (kHyperVStorageProduct );
189+ propString = OSString::withCString (_isIDE ? kHyperVStorageProductIDE : kHyperVStorageProductSCSI );
190190 if (propString != nullptr ) {
191191 SetHBAProperty (kIOPropertyProductNameKey , propString);
192192 propString->release ();
@@ -208,6 +208,18 @@ void HyperVStorage::setHBAInfo() {
208208IOReturn HyperVStorage::connectStorage () {
209209 IOReturn status;
210210 HyperVStoragePacket storPkt;
211+
212+ //
213+ // Check if we are actually an IDE controller.
214+ // IDE supports one device only, and requires the target to be non-zero when communicating with Hyper-V.
215+ //
216+ _isIDE = (strcmp (_hvDevice->getTypeIdString (), kHyperVStorageGuidIDE )) == 0 ;
217+ if (_isIDE) {
218+ UInt8 *instanceId = (UInt8*)_hvDevice->getInstanceId ();
219+ _maxLuns = kHyperVStorageMaxLunsIDE ;
220+ _targetId = (instanceId[5 ] << 8 ) | instanceId[4 ];
221+ HVDBGLOG (" Storage controller is IDE, using target ID %u" , _targetId);
222+ }
211223
212224 //
213225 // Begin controller initialization.
@@ -285,43 +297,42 @@ IOReturn HyperVStorage::connectStorage() {
285297
286298bool HyperVStorage::checkSCSIDiskPresent (UInt8 diskId) {
287299 IOReturn status;
288- HyperVStoragePacket packet = { };
300+ HyperVStoragePacket storPkt = { };
289301
290302 //
291303 // Prepare SCSI request packet and flags.
292304 //
293- packet.operation = kHyperVStoragePacketOperationExecuteSRB ;
294- packet.flags = kHyperVStoragePacketFlagRequestCompletion ;
305+ storPkt.operation = kHyperVStoragePacketOperationExecuteSRB ;
295306
296- packet .scsiRequest .targetID = 0 ;
297- packet .scsiRequest .lun = diskId;
298- packet .scsiRequest .win8Extension .srbFlags |= 0x00000008 ;
299- packet .scsiRequest .length = sizeof (packet .scsiRequest );
300- packet .scsiRequest .senseInfoLength = _senseBufferSize;
301- packet .scsiRequest .dataIn = kHyperVStorageSCSIRequestTypeUnknown ;
307+ storPkt .scsiRequest .targetID = _targetId ;
308+ storPkt .scsiRequest .lun = diskId;
309+ storPkt .scsiRequest .win8Extension .srbFlags |= 0x00000008 ;
310+ storPkt .scsiRequest .length = sizeof (storPkt .scsiRequest ) - _packetSizeDelta ;
311+ storPkt .scsiRequest .senseInfoLength = _senseBufferSize;
312+ storPkt .scsiRequest .dataIn = kHyperVStorageSCSIRequestTypeUnknown ;
302313
303314 //
304315 // Set CDB to TEST UNIT READY command.
305316 //
306- packet .scsiRequest .cdb [0 ] = kSCSICmd_TEST_UNIT_READY ;
307- packet .scsiRequest .cdb [1 ] = 0x00 ;
308- packet .scsiRequest .cdb [2 ] = 0x00 ;
309- packet .scsiRequest .cdb [3 ] = 0x00 ;
310- packet .scsiRequest .cdb [4 ] = 0x00 ;
311- packet .scsiRequest .cdb [5 ] = 0x00 ;
312- packet .scsiRequest .cdbLength = 6 ;
317+ storPkt .scsiRequest .cdb [0 ] = kSCSICmd_TEST_UNIT_READY ;
318+ storPkt .scsiRequest .cdb [1 ] = 0x00 ;
319+ storPkt .scsiRequest .cdb [2 ] = 0x00 ;
320+ storPkt .scsiRequest .cdb [3 ] = 0x00 ;
321+ storPkt .scsiRequest .cdb [4 ] = 0x00 ;
322+ storPkt .scsiRequest .cdb [5 ] = 0x00 ;
323+ storPkt .scsiRequest .cdbLength = 6 ;
313324
314325 //
315326 // Send SCSI packet and check result to see if disk is present.
316327 //
317- status = _hvDevice-> writeInbandPacket (&packet, sizeof (packet) - _packetSizeDelta, true , &packet, sizeof (packet) );
328+ status = sendStorageCommand (&storPkt, false );
318329 if (status != kIOReturnSuccess ) {
319330 HVDBGLOG (" Failed to send TEST UNIT READY SCSI packet with status 0x%X" , status);
320331 return false ;
321332 }
322333
323- HVDBGLOG (" Disk %u status: 0x%X SRB status: 0x%X" , diskId, packet .scsiRequest .scsiStatus , packet .scsiRequest .srbStatus );
324- return packet .scsiRequest .srbStatus == kHyperVSRBStatusSuccess ;
334+ HVDBGLOG (" Disk %u status: 0x%X SRB status: 0x%X" , diskId, storPkt .scsiRequest .scsiStatus , storPkt .scsiRequest .srbStatus );
335+ return storPkt .scsiRequest .srbStatus == kHyperVSRBStatusSuccess ;
325336}
326337
327338void HyperVStorage::startDiskEnumeration () {
@@ -333,9 +344,9 @@ void HyperVStorage::startDiskEnumeration() {
333344}
334345
335346void HyperVStorage::scanSCSIDisks () {
336- HVDBGLOG (" Starting disk scan of %u disks" , kHyperVStorageMaxTargets );
347+ HVDBGLOG (" Starting disk scan of %u disks" , _maxLuns );
337348
338- for (UInt32 lun = 0 ; lun < kHyperVStorageMaxTargets ; lun++) {
349+ for (UInt32 lun = 0 ; lun < _maxLuns ; lun++) {
339350 if (checkSCSIDiskPresent (lun)) {
340351 if (GetTargetForID (lun) == nullptr ) {
341352 HVDBGLOG (" Disk %u is newly added" , lun);
0 commit comments