scsi_module.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (C) 2003 Christoph Hellwig.
  3. * Released under GPL v2.
  4. *
  5. * Support for old-style host templates.
  6. *
  7. * NOTE: Do not use this for new drivers ever.
  8. */
  9. #include <linux/init.h>
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <scsi/scsi_host.h>
  13. static int __init init_this_scsi_driver(void)
  14. {
  15. struct scsi_host_template *sht = &driver_template;
  16. struct Scsi_Host *shost;
  17. struct list_head *l;
  18. int error;
  19. if (!sht->release) {
  20. printk(KERN_ERR
  21. "scsi HBA driver %s didn't set a release method.\n",
  22. sht->name);
  23. return -EINVAL;
  24. }
  25. sht->module = THIS_MODULE;
  26. INIT_LIST_HEAD(&sht->legacy_hosts);
  27. sht->detect(sht);
  28. if (list_empty(&sht->legacy_hosts))
  29. return -ENODEV;
  30. list_for_each_entry(shost, &sht->legacy_hosts, sht_legacy_list) {
  31. error = scsi_add_host(shost, NULL);
  32. if (error)
  33. goto fail;
  34. scsi_scan_host(shost);
  35. }
  36. return 0;
  37. fail:
  38. l = &shost->sht_legacy_list;
  39. while ((l = l->prev) != &sht->legacy_hosts)
  40. scsi_remove_host(list_entry(l, struct Scsi_Host, sht_legacy_list));
  41. return error;
  42. }
  43. static void __exit exit_this_scsi_driver(void)
  44. {
  45. struct scsi_host_template *sht = &driver_template;
  46. struct Scsi_Host *shost, *s;
  47. list_for_each_entry(shost, &sht->legacy_hosts, sht_legacy_list)
  48. scsi_remove_host(shost);
  49. list_for_each_entry_safe(shost, s, &sht->legacy_hosts, sht_legacy_list)
  50. sht->release(shost);
  51. if (list_empty(&sht->legacy_hosts))
  52. return;
  53. printk(KERN_WARNING "%s did not call scsi_unregister\n", sht->name);
  54. dump_stack();
  55. list_for_each_entry_safe(shost, s, &sht->legacy_hosts, sht_legacy_list)
  56. scsi_unregister(shost);
  57. }
  58. module_init(init_this_scsi_driver);
  59. module_exit(exit_this_scsi_driver);