scsi_dh_hp_sw.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Basic HP/COMPAQ MSA 1000 support. This is only needed if your HW cannot be
  3. * upgraded.
  4. *
  5. * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
  6. * Copyright (C) 2006 Mike Christie
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2, or (at your option)
  11. * any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; see the file COPYING. If not, write to
  20. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <scsi/scsi.h>
  23. #include <scsi/scsi_dbg.h>
  24. #include <scsi/scsi_eh.h>
  25. #include <scsi/scsi_dh.h>
  26. #define HP_SW_NAME "hp_sw"
  27. #define HP_SW_TIMEOUT (60 * HZ)
  28. #define HP_SW_RETRIES 3
  29. struct hp_sw_dh_data {
  30. unsigned char sense[SCSI_SENSE_BUFFERSIZE];
  31. int retries;
  32. };
  33. static inline struct hp_sw_dh_data *get_hp_sw_data(struct scsi_device *sdev)
  34. {
  35. struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data;
  36. BUG_ON(scsi_dh_data == NULL);
  37. return ((struct hp_sw_dh_data *) scsi_dh_data->buf);
  38. }
  39. static int hp_sw_done(struct scsi_device *sdev)
  40. {
  41. struct hp_sw_dh_data *h = get_hp_sw_data(sdev);
  42. struct scsi_sense_hdr sshdr;
  43. int rc;
  44. sdev_printk(KERN_INFO, sdev, "hp_sw_done\n");
  45. rc = scsi_normalize_sense(h->sense, SCSI_SENSE_BUFFERSIZE, &sshdr);
  46. if (!rc)
  47. goto done;
  48. switch (sshdr.sense_key) {
  49. case NOT_READY:
  50. if ((sshdr.asc == 0x04) && (sshdr.ascq == 3)) {
  51. rc = SCSI_DH_RETRY;
  52. h->retries++;
  53. break;
  54. }
  55. /* fall through */
  56. default:
  57. h->retries++;
  58. rc = SCSI_DH_IMM_RETRY;
  59. }
  60. done:
  61. if (rc == SCSI_DH_OK || rc == SCSI_DH_IO)
  62. h->retries = 0;
  63. else if (h->retries > HP_SW_RETRIES) {
  64. h->retries = 0;
  65. rc = SCSI_DH_IO;
  66. }
  67. return rc;
  68. }
  69. static int hp_sw_activate(struct scsi_device *sdev)
  70. {
  71. struct hp_sw_dh_data *h = get_hp_sw_data(sdev);
  72. struct request *req;
  73. int ret = SCSI_DH_RES_TEMP_UNAVAIL;
  74. req = blk_get_request(sdev->request_queue, WRITE, GFP_ATOMIC);
  75. if (!req)
  76. goto done;
  77. sdev_printk(KERN_INFO, sdev, "sending START_STOP.");
  78. req->cmd_type = REQ_TYPE_BLOCK_PC;
  79. req->cmd_flags |= REQ_FAILFAST;
  80. req->cmd_len = COMMAND_SIZE(START_STOP);
  81. memset(req->cmd, 0, MAX_COMMAND_SIZE);
  82. req->cmd[0] = START_STOP;
  83. req->cmd[4] = 1; /* Start spin cycle */
  84. req->timeout = HP_SW_TIMEOUT;
  85. req->sense = h->sense;
  86. memset(req->sense, 0, SCSI_SENSE_BUFFERSIZE);
  87. req->sense_len = 0;
  88. ret = blk_execute_rq(req->q, NULL, req, 1);
  89. if (!ret) /* SUCCESS */
  90. ret = hp_sw_done(sdev);
  91. else
  92. ret = SCSI_DH_IO;
  93. done:
  94. return ret;
  95. }
  96. static const struct {
  97. char *vendor;
  98. char *model;
  99. } hp_sw_dh_data_list[] = {
  100. {"COMPAQ", "MSA"},
  101. {"HP", "HSV"},
  102. {"DEC", "HSG80"},
  103. {NULL, NULL},
  104. };
  105. static int hp_sw_bus_notify(struct notifier_block *, unsigned long, void *);
  106. static struct scsi_device_handler hp_sw_dh = {
  107. .name = HP_SW_NAME,
  108. .module = THIS_MODULE,
  109. .nb.notifier_call = hp_sw_bus_notify,
  110. .activate = hp_sw_activate,
  111. };
  112. static int hp_sw_bus_notify(struct notifier_block *nb,
  113. unsigned long action, void *data)
  114. {
  115. struct device *dev = data;
  116. struct scsi_device *sdev;
  117. struct scsi_dh_data *scsi_dh_data;
  118. int i, found = 0;
  119. unsigned long flags;
  120. if (!scsi_is_sdev_device(dev))
  121. return 0;
  122. sdev = to_scsi_device(dev);
  123. if (action == BUS_NOTIFY_ADD_DEVICE) {
  124. for (i = 0; hp_sw_dh_data_list[i].vendor; i++) {
  125. if (!strncmp(sdev->vendor, hp_sw_dh_data_list[i].vendor,
  126. strlen(hp_sw_dh_data_list[i].vendor)) &&
  127. !strncmp(sdev->model, hp_sw_dh_data_list[i].model,
  128. strlen(hp_sw_dh_data_list[i].model))) {
  129. found = 1;
  130. break;
  131. }
  132. }
  133. if (!found)
  134. goto out;
  135. scsi_dh_data = kzalloc(sizeof(struct scsi_device_handler *)
  136. + sizeof(struct hp_sw_dh_data) , GFP_KERNEL);
  137. if (!scsi_dh_data) {
  138. sdev_printk(KERN_ERR, sdev, "Attach Failed %s.\n",
  139. HP_SW_NAME);
  140. goto out;
  141. }
  142. scsi_dh_data->scsi_dh = &hp_sw_dh;
  143. spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
  144. sdev->scsi_dh_data = scsi_dh_data;
  145. spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
  146. try_module_get(THIS_MODULE);
  147. sdev_printk(KERN_NOTICE, sdev, "Attached %s.\n", HP_SW_NAME);
  148. } else if (action == BUS_NOTIFY_DEL_DEVICE) {
  149. if (sdev->scsi_dh_data == NULL ||
  150. sdev->scsi_dh_data->scsi_dh != &hp_sw_dh)
  151. goto out;
  152. spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
  153. scsi_dh_data = sdev->scsi_dh_data;
  154. sdev->scsi_dh_data = NULL;
  155. spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
  156. module_put(THIS_MODULE);
  157. sdev_printk(KERN_NOTICE, sdev, "Dettached %s.\n", HP_SW_NAME);
  158. kfree(scsi_dh_data);
  159. }
  160. out:
  161. return 0;
  162. }
  163. static int __init hp_sw_init(void)
  164. {
  165. return scsi_register_device_handler(&hp_sw_dh);
  166. }
  167. static void __exit hp_sw_exit(void)
  168. {
  169. scsi_unregister_device_handler(&hp_sw_dh);
  170. }
  171. module_init(hp_sw_init);
  172. module_exit(hp_sw_exit);
  173. MODULE_DESCRIPTION("HP MSA 1000");
  174. MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu");
  175. MODULE_LICENSE("GPL");