pluto.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /* pluto.c: SparcSTORAGE Array SCSI host adapter driver.
  2. *
  3. * Copyright (C) 1997,1998,1999 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  4. *
  5. */
  6. #include <linux/completion.h>
  7. #include <linux/kernel.h>
  8. #include <linux/delay.h>
  9. #include <linux/types.h>
  10. #include <linux/string.h>
  11. #include <linux/slab.h>
  12. #include <linux/blkdev.h>
  13. #include <linux/proc_fs.h>
  14. #include <linux/stat.h>
  15. #include <linux/init.h>
  16. #ifdef CONFIG_KMOD
  17. #include <linux/kmod.h>
  18. #endif
  19. #include <asm/irq.h>
  20. #include "scsi.h"
  21. #include <scsi/scsi_host.h>
  22. #include "../fc4/fcp_impl.h"
  23. #include "pluto.h"
  24. #include <linux/module.h>
  25. #define RQ_SCSI_BUSY 0xffff
  26. #define RQ_SCSI_DONE 0xfffe
  27. /* #define PLUTO_DEBUG */
  28. #define pluto_printk printk ("PLUTO %s: ", fc->name); printk
  29. #ifdef PLUTO_DEBUG
  30. #define PLD(x) pluto_printk x;
  31. #define PLND(x) printk ("PLUTO: "); printk x;
  32. #else
  33. #define PLD(x)
  34. #define PLND(x)
  35. #endif
  36. static struct ctrl_inquiry {
  37. struct Scsi_Host host;
  38. struct pluto pluto;
  39. Scsi_Cmnd cmd;
  40. char inquiry[256];
  41. fc_channel *fc;
  42. } *fcs __initdata;
  43. static int fcscount __initdata = 0;
  44. static atomic_t fcss __initdata = ATOMIC_INIT(0);
  45. static DECLARE_COMPLETION(fc_detect_complete);
  46. static int pluto_encode_addr(Scsi_Cmnd *SCpnt, u16 *addr, fc_channel *fc, fcp_cmnd *fcmd);
  47. static void __init pluto_detect_done(Scsi_Cmnd *SCpnt)
  48. {
  49. /* Do nothing */
  50. }
  51. static void __init pluto_detect_scsi_done(Scsi_Cmnd *SCpnt)
  52. {
  53. PLND(("Detect done %08lx\n", (long)SCpnt))
  54. if (atomic_dec_and_test (&fcss))
  55. complete(&fc_detect_complete);
  56. }
  57. int pluto_slave_configure(struct scsi_device *device)
  58. {
  59. int depth_to_use;
  60. if (device->tagged_supported)
  61. depth_to_use = /* 254 */ 8;
  62. else
  63. depth_to_use = 2;
  64. scsi_adjust_queue_depth(device,
  65. (device->tagged_supported ?
  66. MSG_SIMPLE_TAG : 0),
  67. depth_to_use);
  68. return 0;
  69. }
  70. /* Detect all SSAs attached to the machine.
  71. To be fast, do it on all online FC channels at the same time. */
  72. int __init pluto_detect(struct scsi_host_template *tpnt)
  73. {
  74. int i, retry, nplutos;
  75. fc_channel *fc;
  76. struct scsi_device dev;
  77. tpnt->proc_name = "pluto";
  78. fcscount = 0;
  79. for_each_online_fc_channel(fc) {
  80. if (!fc->posmap)
  81. fcscount++;
  82. }
  83. PLND(("%d channels online\n", fcscount))
  84. if (!fcscount) {
  85. #if defined(MODULE) && defined(CONFIG_FC4_SOC_MODULE) && defined(CONFIG_KMOD)
  86. request_module("soc");
  87. for_each_online_fc_channel(fc) {
  88. if (!fc->posmap)
  89. fcscount++;
  90. }
  91. if (!fcscount)
  92. #endif
  93. return 0;
  94. }
  95. fcs = kcalloc(fcscount, sizeof (struct ctrl_inquiry), GFP_DMA);
  96. if (!fcs) {
  97. printk ("PLUTO: Not enough memory to probe\n");
  98. return 0;
  99. }
  100. memset (&dev, 0, sizeof(dev));
  101. atomic_set (&fcss, fcscount);
  102. i = 0;
  103. for_each_online_fc_channel(fc) {
  104. Scsi_Cmnd *SCpnt;
  105. struct Scsi_Host *host;
  106. struct pluto *pluto;
  107. if (i == fcscount) break;
  108. if (fc->posmap) continue;
  109. PLD(("trying to find SSA\n"))
  110. /* If this is already registered to some other SCSI host, then it cannot be pluto */
  111. if (fc->scsi_name[0]) continue;
  112. memcpy (fc->scsi_name, "SSA", 4);
  113. fcs[i].fc = fc;
  114. fc->can_queue = PLUTO_CAN_QUEUE;
  115. fc->rsp_size = 64;
  116. fc->encode_addr = pluto_encode_addr;
  117. fc->fcp_register(fc, TYPE_SCSI_FCP, 0);
  118. SCpnt = &(fcs[i].cmd);
  119. host = &(fcs[i].host);
  120. pluto = (struct pluto *)host->hostdata;
  121. pluto->fc = fc;
  122. SCpnt->cmnd[0] = INQUIRY;
  123. SCpnt->cmnd[4] = 255;
  124. /* FC layer requires this, so that SCpnt->device->tagged_supported is initially 0 */
  125. SCpnt->device = &dev;
  126. dev.host = host;
  127. SCpnt->cmd_len = COMMAND_SIZE(INQUIRY);
  128. SCpnt->request->cmd_flags &= ~REQ_STARTED;
  129. SCpnt->request_bufflen = 256;
  130. SCpnt->request_buffer = fcs[i].inquiry;
  131. PLD(("set up %d %08lx\n", i, (long)SCpnt))
  132. i++;
  133. }
  134. for (retry = 0; retry < 5; retry++) {
  135. for (i = 0; i < fcscount; i++) {
  136. if (!fcs[i].fc) break;
  137. if (!(fcs[i].cmd.request->cmd_flags & REQ_STARTED)) {
  138. fcs[i].cmd.request->cmd_flags |= REQ_STARTED;
  139. disable_irq(fcs[i].fc->irq);
  140. PLND(("queuecommand %d %d\n", retry, i))
  141. fcp_scsi_queuecommand (&(fcs[i].cmd),
  142. pluto_detect_scsi_done);
  143. enable_irq(fcs[i].fc->irq);
  144. }
  145. }
  146. wait_for_completion_timeout(&fc_detect_complete, 10 * HZ);
  147. PLND(("Woken up\n"))
  148. if (!atomic_read(&fcss))
  149. break; /* All fc channels have answered us */
  150. }
  151. PLND(("Finished search\n"))
  152. for (i = 0, nplutos = 0; i < fcscount; i++) {
  153. Scsi_Cmnd *SCpnt;
  154. if (!(fc = fcs[i].fc)) break;
  155. SCpnt = &(fcs[i].cmd);
  156. /* Let FC mid-level free allocated resources */
  157. pluto_detect_scsi_done(SCpnt);
  158. if (!SCpnt->result) {
  159. struct pluto_inquiry *inq;
  160. struct pluto *pluto;
  161. struct Scsi_Host *host;
  162. inq = (struct pluto_inquiry *)fcs[i].inquiry;
  163. if ((inq->dtype & 0x1f) == TYPE_PROCESSOR &&
  164. !strncmp (inq->vendor_id, "SUN", 3) &&
  165. !strncmp (inq->product_id, "SSA", 3)) {
  166. char *p;
  167. long *ages;
  168. ages = kcalloc((inq->channels + 1) * inq->targets, sizeof(long), GFP_KERNEL);
  169. if (!ages) continue;
  170. host = scsi_register (tpnt, sizeof (struct pluto));
  171. if(!host)
  172. {
  173. kfree(ages);
  174. continue;
  175. }
  176. if (!try_module_get(fc->module)) {
  177. kfree(ages);
  178. scsi_unregister(host);
  179. continue;
  180. }
  181. nplutos++;
  182. pluto = (struct pluto *)host->hostdata;
  183. host->max_id = inq->targets;
  184. host->max_channel = inq->channels;
  185. host->irq = fc->irq;
  186. fc->channels = inq->channels + 1;
  187. fc->targets = inq->targets;
  188. fc->ages = ages;
  189. pluto->fc = fc;
  190. memcpy (pluto->rev_str, inq->revision, 4);
  191. pluto->rev_str[4] = 0;
  192. p = strchr (pluto->rev_str, ' ');
  193. if (p) *p = 0;
  194. memcpy (pluto->fw_rev_str, inq->fw_revision, 4);
  195. pluto->fw_rev_str[4] = 0;
  196. p = strchr (pluto->fw_rev_str, ' ');
  197. if (p) *p = 0;
  198. memcpy (pluto->serial_str, inq->serial, 12);
  199. pluto->serial_str[12] = 0;
  200. p = strchr (pluto->serial_str, ' ');
  201. if (p) *p = 0;
  202. PLD(("Found SSA rev %s fw rev %s serial %s %dx%d\n", pluto->rev_str, pluto->fw_rev_str, pluto->serial_str, host->max_channel, host->max_id))
  203. } else
  204. fc->fcp_register(fc, TYPE_SCSI_FCP, 1);
  205. } else
  206. fc->fcp_register(fc, TYPE_SCSI_FCP, 1);
  207. }
  208. kfree(fcs);
  209. if (nplutos)
  210. printk ("PLUTO: Total of %d SparcSTORAGE Arrays found\n", nplutos);
  211. return nplutos;
  212. }
  213. int pluto_release(struct Scsi_Host *host)
  214. {
  215. struct pluto *pluto = (struct pluto *)host->hostdata;
  216. fc_channel *fc = pluto->fc;
  217. module_put(fc->module);
  218. fc->fcp_register(fc, TYPE_SCSI_FCP, 1);
  219. PLND((" releasing pluto.\n"));
  220. kfree (fc->ages);
  221. PLND(("released pluto!\n"));
  222. return 0;
  223. }
  224. const char *pluto_info(struct Scsi_Host *host)
  225. {
  226. static char buf[128], *p;
  227. struct pluto *pluto = (struct pluto *) host->hostdata;
  228. sprintf(buf, "SUN SparcSTORAGE Array %s fw %s serial %s %dx%d on %s",
  229. pluto->rev_str, pluto->fw_rev_str, pluto->serial_str,
  230. host->max_channel, host->max_id, pluto->fc->name);
  231. #ifdef __sparc__
  232. p = strchr(buf, 0);
  233. sprintf(p, " PROM node %x", pluto->fc->dev->prom_node);
  234. #endif
  235. return buf;
  236. }
  237. /* SSA uses this FC4S addressing:
  238. switch (addr[0])
  239. {
  240. case 0: CONTROLLER - All of addr[1]..addr[3] has to be 0
  241. case 1: SINGLE DISK - addr[1] channel, addr[2] id, addr[3] 0
  242. case 2: DISK GROUP - ???
  243. }
  244. So that SCSI mid-layer can access to these, we reserve
  245. channel 0 id 0 lun 0 for CONTROLLER
  246. and channels 1 .. max_channel are normal single disks.
  247. */
  248. static int pluto_encode_addr(Scsi_Cmnd *SCpnt, u16 *addr, fc_channel *fc, fcp_cmnd *fcmd)
  249. {
  250. PLND(("encode addr %d %d %d\n", SCpnt->device->channel, SCpnt->device->id, SCpnt->cmnd[1] & 0xe0))
  251. /* We don't support LUNs - neither does SSA :) */
  252. if (SCpnt->cmnd[1] & 0xe0)
  253. return -EINVAL;
  254. if (!SCpnt->device->channel) {
  255. if (SCpnt->device->id)
  256. return -EINVAL;
  257. memset (addr, 0, 4 * sizeof(u16));
  258. } else {
  259. addr[0] = 1;
  260. addr[1] = SCpnt->device->channel - 1;
  261. addr[2] = SCpnt->device->id;
  262. addr[3] = 0;
  263. }
  264. /* We're Point-to-Point, so target it to the default DID */
  265. fcmd->did = fc->did;
  266. PLND(("trying %04x%04x%04x%04x\n", addr[0], addr[1], addr[2], addr[3]))
  267. return 0;
  268. }
  269. static struct scsi_host_template driver_template = {
  270. .name = "Sparc Storage Array 100/200",
  271. .detect = pluto_detect,
  272. .release = pluto_release,
  273. .info = pluto_info,
  274. .queuecommand = fcp_scsi_queuecommand,
  275. .slave_configure = pluto_slave_configure,
  276. .can_queue = PLUTO_CAN_QUEUE,
  277. .this_id = -1,
  278. .sg_tablesize = 1,
  279. .cmd_per_lun = 1,
  280. .use_clustering = ENABLE_CLUSTERING,
  281. .eh_abort_handler = fcp_scsi_abort,
  282. .eh_device_reset_handler = fcp_scsi_dev_reset,
  283. .eh_host_reset_handler = fcp_scsi_host_reset,
  284. };
  285. #include "scsi_module.c"
  286. MODULE_LICENSE("GPL");