sd.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. * Storage Device.
  11. */
  12. typedef struct SDev SDev;
  13. typedef struct SDifc SDifc;
  14. typedef struct SDpart SDpart;
  15. typedef struct SDperm SDperm;
  16. typedef struct SDreq SDreq;
  17. typedef struct SDunit SDunit;
  18. struct SDperm {
  19. char* name;
  20. char* user;
  21. uint32_t perm;
  22. };
  23. struct SDpart {
  24. uvlong start;
  25. uvlong end;
  26. SDperm;
  27. int valid;
  28. uint32_t vers;
  29. };
  30. struct SDunit {
  31. SDev* dev;
  32. int subno;
  33. uchar inquiry[255]; /* format follows SCSI spec */
  34. uchar sense[18]; /* format follows SCSI spec */
  35. SDperm;
  36. QLock ctl;
  37. uvlong sectors;
  38. uint32_t secsize;
  39. SDpart* part; /* nil or array of size npart */
  40. int npart;
  41. uint32_t vers;
  42. SDperm ctlperm;
  43. QLock raw; /* raw read or write in progress */
  44. uint32_t rawinuse; /* really just a test-and-set */
  45. int state;
  46. SDreq* req;
  47. SDperm rawperm;
  48. };
  49. /*
  50. * Each controller is represented by a SDev.
  51. */
  52. struct SDev {
  53. Ref r; /* Number of callers using device */
  54. SDifc* ifc; /* pnp/legacy */
  55. void* ctlr;
  56. int idno;
  57. char name[8];
  58. SDev* next;
  59. QLock; /* enable/disable */
  60. int enabled;
  61. int nunit; /* Number of units */
  62. QLock unitlock; /* `Loading' of units */
  63. int* unitflg; /* Unit flags */
  64. SDunit**unit;
  65. };
  66. struct SDifc {
  67. char* name;
  68. SDev* (*pnp)(void);
  69. SDev* (*legacy)(int, int);
  70. int (*enable)(SDev*);
  71. int (*disable)(SDev*);
  72. int (*verify)(SDunit*);
  73. int (*online)(SDunit*);
  74. int (*rio)(SDreq*);
  75. int (*rctl)(SDunit*, char*, int);
  76. int (*wctl)(SDunit*, Cmdbuf*);
  77. long (*bio)(SDunit*, int, int, void*, long, vlong);
  78. SDev* (*probe)(DevConf*);
  79. void (*clear)(SDev*);
  80. char* (*rtopctl)(SDev*, char*, char*);
  81. int (*wtopctl)(SDev*, Cmdbuf*);
  82. };
  83. struct SDreq {
  84. SDunit* unit;
  85. int lun;
  86. int write;
  87. uchar cmd[16];
  88. int clen;
  89. void* data;
  90. int dlen;
  91. int flags;
  92. int status;
  93. long rlen;
  94. uchar sense[256];
  95. };
  96. enum {
  97. SDnosense = 0x00000001,
  98. SDvalidsense = 0x00010000,
  99. };
  100. enum {
  101. SDretry = -5, /* internal to controllers */
  102. SDmalloc = -4,
  103. SDeio = -3,
  104. SDtimeout = -2,
  105. SDnostatus = -1,
  106. SDok = 0,
  107. SDcheck = 0x02, /* check condition */
  108. SDbusy = 0x08, /* busy */
  109. SDmaxio = 2048*1024,
  110. SDnpart = 16,
  111. };
  112. #define sdmalloc(n) malloc(n)
  113. #define sdfree(p) free(p)
  114. /* devsd.c */
  115. extern void sdadddevs(SDev*);
  116. extern int sdsetsense(SDreq*, int, int, int, int);
  117. extern int sdmodesense(SDreq*, uchar*, void*, int);
  118. extern int sdfakescsi(SDreq*, void*, int);
  119. /* sdscsi.c */
  120. extern int scsiverify(SDunit*);
  121. extern int scsionline(SDunit*);
  122. extern long scsibio(SDunit*, int, int, void*, long, vlong);
  123. extern SDev* scsiid(SDev*, SDifc*);
  124. /*
  125. * hardware info about a device
  126. */
  127. typedef struct {
  128. uint32_t port;
  129. int size;
  130. } Devport;
  131. struct DevConf
  132. {
  133. uint32_t intnum; /* interrupt number */
  134. char *type; /* card type, malloced */
  135. int nports; /* Number of ports */
  136. Devport *ports; /* The ports themselves */
  137. };