cxgb3i_init.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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.2"
  14. #define DRV_MODULE_RELDATE "Mar. 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_event_handler(struct t3cdev *tdev, u32 event, u32 port);
  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. .event_handler = s3_event_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_ddp_init(t3dev);
  45. cxgb3i_sdev_add(t3dev, &t3c_client);
  46. cxgb3i_adapter_open(t3dev);
  47. }
  48. /**
  49. * close_s3_dev - de-register with cxgb3 LLD
  50. * @t3dev: cxgb3 adapter instance
  51. */
  52. static void close_s3_dev(struct t3cdev *t3dev)
  53. {
  54. cxgb3i_adapter_close(t3dev);
  55. cxgb3i_sdev_remove(t3dev);
  56. cxgb3i_ddp_cleanup(t3dev);
  57. }
  58. static void s3_event_handler(struct t3cdev *tdev, u32 event, u32 port)
  59. {
  60. struct cxgb3i_adapter *snic = cxgb3i_adapter_find_by_tdev(tdev);
  61. cxgb3i_log_info("snic 0x%p, tdev 0x%p, event 0x%x, port 0x%x.\n",
  62. snic, tdev, event, port);
  63. if (!snic)
  64. return;
  65. switch (event) {
  66. case OFFLOAD_STATUS_DOWN:
  67. snic->flags |= CXGB3I_ADAPTER_FLAG_RESET;
  68. break;
  69. case OFFLOAD_STATUS_UP:
  70. snic->flags &= ~CXGB3I_ADAPTER_FLAG_RESET;
  71. break;
  72. }
  73. }
  74. /**
  75. * cxgb3i_init_module - module init entry point
  76. *
  77. * initialize any driver wide global data structures and register itself
  78. * with the cxgb3 module
  79. */
  80. static int __init cxgb3i_init_module(void)
  81. {
  82. int err;
  83. err = cxgb3i_sdev_init(cxgb3i_cpl_handlers);
  84. if (err < 0)
  85. return err;
  86. err = cxgb3i_iscsi_init();
  87. if (err < 0)
  88. return err;
  89. err = cxgb3i_pdu_init();
  90. if (err < 0)
  91. return err;
  92. cxgb3_register_client(&t3c_client);
  93. return 0;
  94. }
  95. /**
  96. * cxgb3i_exit_module - module cleanup/exit entry point
  97. *
  98. * go through the driver hba list and for each hba, release any resource held.
  99. * and unregisters iscsi transport and the cxgb3 module
  100. */
  101. static void __exit cxgb3i_exit_module(void)
  102. {
  103. cxgb3_unregister_client(&t3c_client);
  104. cxgb3i_pdu_cleanup();
  105. cxgb3i_iscsi_cleanup();
  106. cxgb3i_sdev_cleanup();
  107. }
  108. module_init(cxgb3i_init_module);
  109. module_exit(cxgb3i_exit_module);