ums.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /*
  10. * mass storage transport protocols and subclasses,
  11. * from usb mass storage class specification overview rev 1.2
  12. */
  13. typedef struct Umsc Umsc;
  14. typedef struct Ums Ums;
  15. typedef struct Cbw Cbw; /* command block wrapper */
  16. typedef struct Csw Csw; /* command status wrapper */
  17. enum
  18. {
  19. Protocbi = 0, /* control/bulk/interrupt; mainly floppies */
  20. Protocb = 1, /* " with no interrupt; mainly floppies */
  21. Protobulk = 0x50, /* bulk only */
  22. Subrbc = 1, /* reduced blk cmds */
  23. Subatapi = 2, /* cd/dvd using sff-8020i or mmc-2 cmd blks */
  24. Subqic = 3, /* QIC-157 tapes */
  25. Subufi = 4, /* floppy */
  26. Sub8070 = 5, /* removable media, atapi-like */
  27. Subscsi = 6, /* scsi transparent cmd set */
  28. Subisd200 = 7, /* ISD200 ATA */
  29. Subdev = 0xff, /* use device's value */
  30. Umsreset = 0xFF,
  31. Getmaxlun = 0xFE,
  32. // Maxlun = 256,
  33. Maxlun = 32,
  34. CMreset = 1,
  35. Pcmd = 0,
  36. Pdata,
  37. Pstatus,
  38. CbwLen = 31,
  39. CbwDataIn = 0x80,
  40. CbwDataOut = 0x00,
  41. CswLen = 13,
  42. CswOk = 0,
  43. CswFailed = 1,
  44. CswPhaseErr = 2,
  45. };
  46. /*
  47. * corresponds to a lun.
  48. * these are ~600+Maxiosize bytes each; ScsiReq is not tiny.
  49. */
  50. struct Umsc
  51. {
  52. ScsiReq;
  53. uint64_t blocks;
  54. int64_t capacity;
  55. /* from setup */
  56. char *bufp;
  57. long off; /* offset within a block */
  58. long nb; /* byte count */
  59. uint8_t rawcmd[16];
  60. uint8_t phase;
  61. char *inq;
  62. Ums *ums;
  63. Usbfs fs;
  64. char buf[Maxiosize];
  65. };
  66. struct Ums
  67. {
  68. QLock;
  69. Dev *dev;
  70. Dev *epin;
  71. Dev *epout;
  72. Umsc *lun;
  73. uint8_t maxlun;
  74. int seq;
  75. int nerrs;
  76. int wrongresidues;
  77. };
  78. /*
  79. * USB transparent SCSI devices
  80. */
  81. struct Cbw
  82. {
  83. char signature[4]; /* "USBC" */
  84. long tag;
  85. long datalen;
  86. uint8_t flags;
  87. uint8_t lun;
  88. uint8_t len;
  89. char command[16];
  90. };
  91. struct Csw
  92. {
  93. char signature[4]; /* "USBS" */
  94. long tag;
  95. long dataresidue;
  96. uint8_t status;
  97. };
  98. int diskmain(Dev*, int, char**);