cxgb3i_init.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* cxgb3i_init.c: Chelsio S3xx iSCSI driver.
  2. *
  3. * Copyright (c) 2008 Chelsio Communications, Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Written by: Karen Xie (kxie@chelsio.com)
  10. */
  11. #include "cxgb3i.h"
  12. #define DRV_MODULE_NAME "cxgb3i"
  13. #define DRV_MODULE_VERSION "1.0.1"
  14. #define DRV_MODULE_RELDATE "Jan. 2009"
  15. static char version[] =
  16. "Chelsio S3xx iSCSI Driver " DRV_MODULE_NAME
  17. " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  18. MODULE_AUTHOR("Karen Xie <kxie@chelsio.com>");
  19. MODULE_DESCRIPTION("Chelsio S3xx iSCSI Driver");
  20. MODULE_LICENSE("GPL");
  21. MODULE_VERSION(DRV_MODULE_VERSION);
  22. static void open_s3_dev(struct t3cdev *);
  23. static void close_s3_dev(struct t3cdev *);
  24. static void s3_err_handler(struct t3cdev *tdev, u32 status, u32 error);
  25. static cxgb3_cpl_handler_func cxgb3i_cpl_handlers[NUM_CPL_CMDS];
  26. static struct cxgb3_client t3c_client = {
  27. .name = "iscsi_cxgb3",
  28. .handlers = cxgb3i_cpl_handlers,
  29. .add = open_s3_dev,
  30. .remove = close_s3_dev,
  31. .err_handler = s3_err_handler,
  32. };
  33. /**
  34. * open_s3_dev - register with cxgb3 LLD
  35. * @t3dev: cxgb3 adapter instance
  36. */
  37. static void open_s3_dev(struct t3cdev *t3dev)
  38. {
  39. static int vers_printed;
  40. if (!vers_printed) {
  41. printk(KERN_INFO "%s", version);
  42. vers_printed = 1;
  43. }
  44. cxgb3i_sdev_add(t3dev, &t3c_client);
  45. cxgb3i_adapter_open(t3dev);
  46. }
  47. /**
  48. * close_s3_dev - de-register with cxgb3 LLD
  49. * @t3dev: cxgb3 adapter instance
  50. */
  51. static void close_s3_dev(struct t3cdev *t3dev)
  52. {
  53. cxgb3i_adapter_close(t3dev);
  54. cxgb3i_sdev_remove(t3dev);
  55. }
  56. static void s3_err_handler(struct t3cdev *tdev, u32 status, u32 error)
  57. {
  58. struct cxgb3i_adapter *snic = cxgb3i_adapter_find_by_tdev(tdev);
  59. cxgb3i_log_info("snic 0x%p, tdev 0x%p, status 0x%x, err 0x%x.\n",
  60. snic, tdev, status, error);
  61. if (!snic)
  62. return;
  63. switch (status) {
  64. case OFFLOAD_STATUS_DOWN:
  65. snic->flags |= CXGB3I_ADAPTER_FLAG_RESET;
  66. break;
  67. case OFFLOAD_STATUS_UP:
  68. snic->flags &= ~CXGB3I_ADAPTER_FLAG_RESET;
  69. break;
  70. }
  71. }
  72. /**
  73. * cxgb3i_init_module - module init entry point
  74. *
  75. * initialize any driver wide global data structures and register itself
  76. * with the cxgb3 module
  77. */
  78. static int __init cxgb3i_init_module(void)
  79. {
  80. int err;
  81. err = cxgb3i_sdev_init(cxgb3i_cpl_handlers);
  82. if (err < 0)
  83. return err;
  84. err = cxgb3i_iscsi_init();
  85. if (err < 0)
  86. return err;
  87. err = cxgb3i_pdu_init();
  88. if (err < 0)
  89. return err;
  90. cxgb3_register_client(&t3c_client);
  91. return 0;
  92. }
  93. /**
  94. * cxgb3i_exit_module - module cleanup/exit entry point
  95. *
  96. * go through the driver hba list and for each hba, release any resource held.
  97. * and unregisters iscsi transport and the cxgb3 module
  98. */
  99. static void __exit cxgb3i_exit_module(void)
  100. {
  101. cxgb3_unregister_client(&t3c_client);
  102. cxgb3i_pdu_cleanup();
  103. cxgb3i_iscsi_cleanup();
  104. cxgb3i_sdev_cleanup();
  105. }
  106. module_init(cxgb3i_init_module);
  107. module_exit(cxgb3i_exit_module);