vendor.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // Copyright (C) 2016 Michael McMaster <michael@codesrc.com>
  2. //
  3. // This file is part of SCSI2SD.
  4. //
  5. // SCSI2SD is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // SCSI2SD is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with SCSI2SD. If not, see <http://www.gnu.org/licenses/>.
  17. #include "scsi.h"
  18. #include "vendor.h"
  19. #include "diagnostic.h"
  20. #include "toolbox.h"
  21. // Callback after the DATA OUT phase is complete.
  22. static void doAssignDiskParameters(void)
  23. {
  24. if (scsiDev.status == GOOD)
  25. {
  26. scsiDev.phase = STATUS;
  27. }
  28. }
  29. // XEBEC specific commands
  30. // http://www.bitsavers.org/pdf/xebec/104524C_S1410Man_Aug83.pdf
  31. // WD100x seems to be identical to the Xebec but calls this command "Set Parameters"
  32. // http://www.bitsavers.org/pdf/westernDigital/WD100x/79-000004_WD1002-SHD_OEM_Manual_Aug1984.pdf
  33. static void doXebecInitializeDriveCharacteristics()
  34. {
  35. if (scsiDev.status == GOOD)
  36. {
  37. scsiDev.phase = STATUS;
  38. }
  39. }
  40. int scsiVendorCommand()
  41. {
  42. int commandHandled = 1;
  43. uint8_t command = scsiDev.cdb[0];
  44. if (command == 0xC0)
  45. {
  46. // Define flexible disk format
  47. // OMTI-5204 controller
  48. // http://bitsavers.informatik.uni-stuttgart.de/pdf/sms/OMTI_5x00.pdf
  49. // Stub. Sectors-per-track should be configured by scsi2sd-util
  50. }
  51. else if (command == 0xC2)
  52. {
  53. // Assign Disk Parameters command
  54. // OMTI-5204 controller
  55. // http://bitsavers.informatik.uni-stuttgart.de/pdf/sms/OMTI_5x00.pdf
  56. // Stub to read and discard 10 bytes.
  57. scsiDev.dataLen = 10;
  58. scsiDev.phase = DATA_OUT;
  59. scsiDev.postDataOutHook = doAssignDiskParameters;
  60. }
  61. else if (command == 0x0C &&
  62. scsiDev.target->cfg->quirks == S2S_CFG_QUIRKS_XEBEC)
  63. {
  64. // XEBEC S1410: "Initialize Drive Characteristics"
  65. // WD100x: "Set Parameters"
  66. scsiDev.dataLen = 8;
  67. scsiDev.phase = DATA_OUT;
  68. scsiDev.postDataOutHook = doXebecInitializeDriveCharacteristics;
  69. }
  70. else if (command == 0x0F &&
  71. scsiDev.target->cfg->quirks == S2S_CFG_QUIRKS_XEBEC)
  72. {
  73. // XEBEC S1410, WD100x: "Write Sector Buffer"
  74. scsiDev.dataLen = scsiDev.target->liveCfg.bytesPerSector;
  75. scsiDev.phase = DATA_OUT;
  76. scsiDev.postDataOutHook = doWriteBuffer;
  77. }
  78. else if (command == 0xE0 &&
  79. scsiDev.target->cfg->quirks == S2S_CFG_QUIRKS_XEBEC)
  80. {
  81. // RAM Diagnostic
  82. // XEBEC S1410 controller
  83. // http://bitsavers.informatik.uni-stuttgart.de/pdf/xebec/104524C_S1410Man_Aug83.pdf
  84. // Stub, return success
  85. }
  86. else if (command == 0xE4 &&
  87. scsiDev.target->cfg->quirks == S2S_CFG_QUIRKS_XEBEC)
  88. {
  89. // Drive Diagnostic
  90. // XEBEC S1410 controller
  91. // Stub, return success
  92. }
  93. else if (scsiToolboxEnabled() && scsiToolboxCommand())
  94. {
  95. // already handled
  96. }
  97. else
  98. {
  99. commandHandled = 0;
  100. }
  101. return commandHandled;
  102. }
  103. void scsiVendorCommandSetLen(uint8_t command, uint8_t* command_length)
  104. {
  105. if (scsiDev.target->cfg->deviceType == S2S_CFG_OPTICAL)
  106. {
  107. // Apple CD-ROM with CD audio over the SCSI bus
  108. if (scsiDev.target->cfg->quirks == S2S_CFG_QUIRKS_APPLE && (command == 0xD8 || command == 0xD9))
  109. {
  110. scsiDev.cdbLen = 12;
  111. }
  112. // Plextor CD-ROM vendor extensions 0xD8
  113. if (unlikely(scsiDev.target->cfg->vendorExtensions & VENDOR_EXTENSION_OPTICAL_PLEXTOR) && command == 0xD8)
  114. {
  115. scsiDev.cdbLen = 12;
  116. }
  117. }
  118. if (scsiToolboxEnabled())
  119. {
  120. // Conflicts with Apple CD-ROM audio over SCSI bus and Plextor CD-ROM D8 extension
  121. // Will override those commands if enabled
  122. if (0xD0 <= command && command <= 0xDA)
  123. {
  124. *command_length = 10;
  125. }
  126. }
  127. }