win-pvdrivers

changeset 1002:c454b24f92b8

testing UNMAP
author James Harper <james.harper@bendigoit.com.au>
date Fri Dec 14 21:27:05 2012 +1100 (2012-12-14)
parents c21dd04d3ae6
children f9248a3eac32
files xenvbd/xenvbd_storport.c xenvbd/xenvbd_storport.h
line diff
     1.1 --- a/xenvbd/xenvbd_storport.c	Fri Dec 14 21:26:22 2012 +1100
     1.2 +++ b/xenvbd/xenvbd_storport.c	Fri Dec 14 21:27:05 2012 +1100
     1.3 @@ -1402,17 +1402,13 @@ XenVbd_HwStorStartIo(PVOID DeviceExtensi
     1.4        switch (xvdd->device_type)
     1.5        {
     1.6        case XENVBD_DEVICETYPE_DISK:
     1.7 -        if ((srb->Cdb[1] & 1) == 0)
     1.8 -        {
     1.9 -          if (srb->Cdb[2])
    1.10 -          {
    1.11 +        if ((srb->Cdb[1] & 1) == 0) {
    1.12 +          if (srb->Cdb[2]) {
    1.13              srb_status = SRB_STATUS_ERROR;
    1.14 -          }
    1.15 -          else
    1.16 -          {
    1.17 +          } else {
    1.18              PINQUIRYDATA id = (PINQUIRYDATA)data_buffer;
    1.19              id->DeviceType = DIRECT_ACCESS_DEVICE;
    1.20 -            id->Versions = 4; /* minimum that WHQL says we must support */
    1.21 +            id->Versions = 5; /* SPC-3 */
    1.22              id->ResponseDataFormat = 2; /* not sure about this but WHQL complains otherwise */
    1.23              id->HiSupport = 1; /* WHQL test says we should set this */
    1.24              //id->AdditionalLength = FIELD_OFFSET(INQUIRYDATA, VendorSpecific) - FIELD_OFFSET(INQUIRYDATA, AdditionalLength);
    1.25 @@ -1423,21 +1419,22 @@ XenVbd_HwStorStartIo(PVOID DeviceExtensi
    1.26              memcpy(id->ProductRevisionLevel, "0000", 4); // product revision level
    1.27              data_transfer_length = FIELD_OFFSET(INQUIRYDATA, VendorSpecific);
    1.28            }
    1.29 -        }
    1.30 -        else
    1.31 -        {
    1.32 -          switch (srb->Cdb[2])
    1.33 -          {
    1.34 +        } else {
    1.35 +          switch (srb->Cdb[2]) {
    1.36            case VPD_SUPPORTED_PAGES: /* list of pages we support */
    1.37 +            FUNCTION_MSG("VPD_SUPPORTED_PAGES\n");
    1.38              data_buffer[0] = DIRECT_ACCESS_DEVICE;
    1.39              data_buffer[1] = VPD_SUPPORTED_PAGES;
    1.40              data_buffer[2] = 0x00;
    1.41 -            data_buffer[3] = 2;
    1.42 -            data_buffer[4] = 0x00;
    1.43 -            data_buffer[5] = 0x80;
    1.44 -            data_transfer_length = 6;
    1.45 +            data_buffer[3] = 4;
    1.46 +            data_buffer[4] = VPD_SUPPORTED_PAGES;
    1.47 +            data_buffer[5] = VPD_SERIAL_NUMBER;
    1.48 +            data_buffer[6] = VPD_DEVICE_IDENTIFIERS;
    1.49 +            data_buffer[7] = VPD_BLOCK_LIMITS;
    1.50 +            data_transfer_length = 8;
    1.51              break;
    1.52            case VPD_SERIAL_NUMBER: /* serial number */
    1.53 +            FUNCTION_MSG("VPD_SERIAL_NUMBER\n");
    1.54              data_buffer[0] = DIRECT_ACCESS_DEVICE;
    1.55              data_buffer[1] = VPD_SERIAL_NUMBER;
    1.56              data_buffer[2] = 0x00;
    1.57 @@ -1446,6 +1443,7 @@ XenVbd_HwStorStartIo(PVOID DeviceExtensi
    1.58              data_transfer_length = 12;
    1.59              break;
    1.60            case VPD_DEVICE_IDENTIFIERS: /* identification - we don't support any so just return zero */
    1.61 +            FUNCTION_MSG("VPD_DEVICE_IDENTIFIERS\n");
    1.62              data_buffer[0] = DIRECT_ACCESS_DEVICE;
    1.63              data_buffer[1] = VPD_DEVICE_IDENTIFIERS;
    1.64              data_buffer[2] = 0x00;
    1.65 @@ -1457,8 +1455,16 @@ XenVbd_HwStorStartIo(PVOID DeviceExtensi
    1.66              memcpy(&data_buffer[8], xvdd->vectors.path, strlen(xvdd->vectors.path));
    1.67              data_transfer_length = (ULONG)(8 + strlen(xvdd->vectors.path));
    1.68              break;
    1.69 +          case VPD_BLOCK_LIMITS: /* to indicate support for UNMAP (TRIM/DISCARD) */
    1.70 +            FUNCTION_MSG("VPD_BLOCK_LIMITS\n");
    1.71 +            // max descriptors = 1
    1.72 +            // max sectors = 0xFFFFFFFF
    1.73 +            // granularity = from xenbus
    1.74 +            // alignment = from xenbus(?)
    1.75 +            srb_status = SRB_STATUS_ERROR;
    1.76 +            break;
    1.77            default:
    1.78 -            //KdPrint((__DRIVER_NAME "     Unknown Page %02x requested\n", srb->Cdb[2]));
    1.79 +            FUNCTION_MSG("Unknown Page %02x requested\n", srb->Cdb[2]);
    1.80              srb_status = SRB_STATUS_ERROR;
    1.81              break;
    1.82            }
    1.83 @@ -1521,7 +1527,7 @@ XenVbd_HwStorStartIo(PVOID DeviceExtensi
    1.84        }
    1.85        break;
    1.86      case SCSIOP_READ_CAPACITY:
    1.87 -      if (dump_mode)
    1.88 +      //if (dump_mode)
    1.89          KdPrint((__DRIVER_NAME "     Command = READ_CAPACITY\n"));
    1.90        //KdPrint((__DRIVER_NAME "       LUN = %d, RelAdr = %d\n", srb->Cdb[1] >> 4, srb->Cdb[1] & 1));
    1.91        //KdPrint((__DRIVER_NAME "       LBA = %02x%02x%02x%02x\n", srb->Cdb[2], srb->Cdb[3], srb->Cdb[4], srb->Cdb[5]));
    1.92 @@ -1552,8 +1558,8 @@ XenVbd_HwStorStartIo(PVOID DeviceExtensi
    1.93        srb_status = SRB_STATUS_SUCCESS;
    1.94        break;
    1.95      case SCSIOP_READ_CAPACITY16:
    1.96 -      if (dump_mode)
    1.97 -        KdPrint((__DRIVER_NAME "     Command = READ_CAPACITY\n"));
    1.98 +      //if (dump_mode)
    1.99 +        KdPrint((__DRIVER_NAME "     Command = READ_CAPACITY16\n"));
   1.100        //KdPrint((__DRIVER_NAME "       LUN = %d, RelAdr = %d\n", srb->Cdb[1] >> 4, srb->Cdb[1] & 1));
   1.101        //KdPrint((__DRIVER_NAME "       LBA = %02x%02x%02x%02x\n", srb->Cdb[2], srb->Cdb[3], srb->Cdb[4], srb->Cdb[5]));
   1.102        //KdPrint((__DRIVER_NAME "       PMI = %d\n", srb->Cdb[8] & 1));
   1.103 @@ -1583,14 +1589,14 @@ XenVbd_HwStorStartIo(PVOID DeviceExtensi
   1.104          data_buffer[13] = 2; /* 2048 byte hardware sectors */
   1.105          break;
   1.106        case 4:
   1.107 -        data_buffer[13] = 2; /* 4096 byte hardware sectors */
   1.108 +        data_buffer[13] = 3; /* 4096 byte hardware sectors */
   1.109          break;
   1.110        default:
   1.111          data_buffer[13] = 0; /* 512 byte hardware sectors */
   1.112          KdPrint((__DRIVER_NAME "     Unknown logical blocks per physical block %d (%d / %d)\n", xvdd->hw_bytes_per_sector / xvdd->bytes_per_sector, xvdd->hw_bytes_per_sector, xvdd->bytes_per_sector));
   1.113          break;
   1.114        }
   1.115 -      data_buffer[14] = 0;
   1.116 +      data_buffer[14] = 0xC0; //0;
   1.117        data_buffer[15] = 0;
   1.118        data_transfer_length = 16;
   1.119        srb->ScsiStatus = 0;
   1.120 @@ -1611,6 +1617,15 @@ XenVbd_HwStorStartIo(PVOID DeviceExtensi
   1.121        XenVbd_PutSrbOnList(xvdd, srb);
   1.122        XenVbd_PutQueuedSrbsOnRing(xvdd);
   1.123        break;
   1.124 +    case SCSIOP_WRITE_SAME:
   1.125 +    case SCSIOP_WRITE_SAME16:
   1.126 +      /* not yet supported */
   1.127 +      FUNCTION_MSG("WRITE_SAME\n");
   1.128 +      break;
   1.129 +    case SCSIOP_UNMAP:
   1.130 +      /* not yet supported */
   1.131 +      FUNCTION_MSG("UNMAP\n");
   1.132 +      break;
   1.133      case SCSIOP_VERIFY:
   1.134      case SCSIOP_VERIFY16:
   1.135        // Should we do more here?
   1.136 @@ -1618,16 +1633,26 @@ XenVbd_HwStorStartIo(PVOID DeviceExtensi
   1.137          KdPrint((__DRIVER_NAME "     Command = VERIFY\n"));
   1.138        srb_status = SRB_STATUS_SUCCESS;
   1.139        break;
   1.140 -#if 0
   1.141      case SCSIOP_REPORT_LUNS:
   1.142 -      if (dump_mode)
   1.143 -        KdPrint((__DRIVER_NAME "     Command = REPORT_LUNS\n"));
   1.144 -      switch (srb->Cdb[1])
   1.145 -      {
   1.146 +      //if (dump_mode)
   1.147 +        FUNCTION_MSG("Command = REPORT_LUNS\n");
   1.148 +      switch (srb->Cdb[2]) {
   1.149 +      case 1:
   1.150 +        FUNCTION_MSG(" SELECT REPORT = %d\n", srb->Cdb[2] & 255);
   1.151 +        break;
   1.152 +      default:
   1.153 +        FUNCTION_MSG(" SELECT REPORT = %d\n", srb->Cdb[2] & 255);
   1.154 +        break;
   1.155        }
   1.156 -      srb_status = SRB_STATUS_SUCCESS;;
   1.157 +      FUNCTION_MSG(" ALLOCATION LENGTH = %d\n", (srb->Cdb[6] << 24)|(srb->Cdb[7] << 16)|(srb->Cdb[8] << 8)|(srb->Cdb[9]));
   1.158 +      data_buffer = srb->DataBuffer;
   1.159 +      RtlZeroMemory(data_buffer, srb->DataTransferLength);
   1.160 +      data_buffer[3] = 8; /* 1 lun */
   1.161 +      /* rest of the data is blank */
   1.162 +      data_transfer_length = 16;
   1.163 +      srb->ScsiStatus = 0;
   1.164 +      srb_status = SRB_STATUS_SUCCESS;
   1.165        break;
   1.166 -#endif
   1.167      case SCSIOP_REQUEST_SENSE:
   1.168        if (dump_mode)
   1.169          KdPrint((__DRIVER_NAME "     Command = REQUEST_SENSE\n"));
   1.170 @@ -1695,6 +1720,7 @@ XenVbd_HwStorStartIo(PVOID DeviceExtensi
   1.171        break;
   1.172      default:
   1.173        KdPrint((__DRIVER_NAME "     Unhandled EXECUTE_SCSI Command = %02X\n", srb->Cdb[0]));
   1.174 +      xvdd->last_sense_key = SCSI_SENSE_ILLEGAL_REQUEST;
   1.175        srb_status = SRB_STATUS_ERROR;
   1.176        break;
   1.177      }
   1.178 @@ -1883,7 +1909,11 @@ XenVbd_HwStorStartIo(PVOID DeviceExtensi
   1.179      srb->SrbStatus = SRB_STATUS_SUCCESS;
   1.180      StorPortNotification(RequestComplete, DeviceExtension, srb);    
   1.181      break;
   1.182 -  
   1.183 +  case SRB_FUNCTION_WMI:
   1.184 +    srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
   1.185 +    StorPortNotification(RequestComplete, DeviceExtension, srb);
   1.186 +    break;
   1.187 +
   1.188    default:
   1.189      KdPrint((__DRIVER_NAME "     Unhandled srb->Function = %08X\n", srb->Function));
   1.190      srb->SrbStatus = SRB_STATUS_INVALID_REQUEST;
     2.1 --- a/xenvbd/xenvbd_storport.h	Fri Dec 14 21:26:22 2012 +1100
     2.2 +++ b/xenvbd/xenvbd_storport.h	Fri Dec 14 21:27:05 2012 +1100
     2.3 @@ -49,6 +49,10 @@ Foundation, Inc., 51 Franklin Street, Fi
     2.4  #define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, PAGE_SIZE)
     2.5  #define BLK_OTHER_RING_SIZE __RING_SIZE((blkif_other_sring_t *)0, PAGE_SIZE)
     2.6  
     2.7 +#define SCSIOP_UNMAP 0x42
     2.8 +
     2.9 +#define VPD_BLOCK_LIMITS 0xB0
    2.10 +
    2.11  #if defined(__x86_64__)
    2.12  #pragma pack(push, 4)
    2.13  #endif