pluto.c 8.8 KB

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