Karen Xie | c367346 | 2008-12-09 14:15:32 -0800 | [diff] [blame] | 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 | |
| 12 | #include "cxgb3i.h" |
| 13 | |
| 14 | #define DRV_MODULE_NAME "cxgb3i" |
Karen Xie | 0d0c27f | 2009-04-01 13:11:27 -0500 | [diff] [blame] | 15 | #define DRV_MODULE_VERSION "1.0.2" |
| 16 | #define DRV_MODULE_RELDATE "Mar. 2009" |
Karen Xie | c367346 | 2008-12-09 14:15:32 -0800 | [diff] [blame] | 17 | |
| 18 | static char version[] = |
| 19 | "Chelsio S3xx iSCSI Driver " DRV_MODULE_NAME |
| 20 | " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; |
| 21 | |
| 22 | MODULE_AUTHOR("Karen Xie <kxie@chelsio.com>"); |
| 23 | MODULE_DESCRIPTION("Chelsio S3xx iSCSI Driver"); |
| 24 | MODULE_LICENSE("GPL"); |
| 25 | MODULE_VERSION(DRV_MODULE_VERSION); |
| 26 | |
| 27 | static void open_s3_dev(struct t3cdev *); |
| 28 | static void close_s3_dev(struct t3cdev *); |
Steve Wise | fa0d4c1 | 2009-09-05 20:22:38 -0700 | [diff] [blame] | 29 | static void s3_event_handler(struct t3cdev *tdev, u32 event, u32 port); |
Karen Xie | c367346 | 2008-12-09 14:15:32 -0800 | [diff] [blame] | 30 | |
| 31 | static cxgb3_cpl_handler_func cxgb3i_cpl_handlers[NUM_CPL_CMDS]; |
| 32 | static struct cxgb3_client t3c_client = { |
| 33 | .name = "iscsi_cxgb3", |
| 34 | .handlers = cxgb3i_cpl_handlers, |
| 35 | .add = open_s3_dev, |
| 36 | .remove = close_s3_dev, |
Steve Wise | fa0d4c1 | 2009-09-05 20:22:38 -0700 | [diff] [blame] | 37 | .event_handler = s3_event_handler, |
Karen Xie | c367346 | 2008-12-09 14:15:32 -0800 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | /** |
| 41 | * open_s3_dev - register with cxgb3 LLD |
| 42 | * @t3dev: cxgb3 adapter instance |
| 43 | */ |
| 44 | static void open_s3_dev(struct t3cdev *t3dev) |
| 45 | { |
| 46 | static int vers_printed; |
| 47 | |
| 48 | if (!vers_printed) { |
| 49 | printk(KERN_INFO "%s", version); |
| 50 | vers_printed = 1; |
| 51 | } |
| 52 | |
Karen Xie | 0d0c27f | 2009-04-01 13:11:27 -0500 | [diff] [blame] | 53 | cxgb3i_ddp_init(t3dev); |
Karen Xie | c367346 | 2008-12-09 14:15:32 -0800 | [diff] [blame] | 54 | cxgb3i_sdev_add(t3dev, &t3c_client); |
Karen Xie | 515f1c8 | 2009-04-01 13:11:23 -0500 | [diff] [blame] | 55 | cxgb3i_adapter_open(t3dev); |
Karen Xie | c367346 | 2008-12-09 14:15:32 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /** |
| 59 | * close_s3_dev - de-register with cxgb3 LLD |
| 60 | * @t3dev: cxgb3 adapter instance |
| 61 | */ |
| 62 | static void close_s3_dev(struct t3cdev *t3dev) |
| 63 | { |
Karen Xie | 515f1c8 | 2009-04-01 13:11:23 -0500 | [diff] [blame] | 64 | cxgb3i_adapter_close(t3dev); |
Karen Xie | c367346 | 2008-12-09 14:15:32 -0800 | [diff] [blame] | 65 | cxgb3i_sdev_remove(t3dev); |
Karen Xie | 0d0c27f | 2009-04-01 13:11:27 -0500 | [diff] [blame] | 66 | cxgb3i_ddp_cleanup(t3dev); |
Karen Xie | c367346 | 2008-12-09 14:15:32 -0800 | [diff] [blame] | 67 | } |
| 68 | |
Steve Wise | fa0d4c1 | 2009-09-05 20:22:38 -0700 | [diff] [blame] | 69 | static void s3_event_handler(struct t3cdev *tdev, u32 event, u32 port) |
Karen Xie | 515f1c8 | 2009-04-01 13:11:23 -0500 | [diff] [blame] | 70 | { |
| 71 | struct cxgb3i_adapter *snic = cxgb3i_adapter_find_by_tdev(tdev); |
| 72 | |
Steve Wise | fa0d4c1 | 2009-09-05 20:22:38 -0700 | [diff] [blame] | 73 | cxgb3i_log_info("snic 0x%p, tdev 0x%p, event 0x%x, port 0x%x.\n", |
| 74 | snic, tdev, event, port); |
Karen Xie | 515f1c8 | 2009-04-01 13:11:23 -0500 | [diff] [blame] | 75 | if (!snic) |
| 76 | return; |
| 77 | |
Steve Wise | fa0d4c1 | 2009-09-05 20:22:38 -0700 | [diff] [blame] | 78 | switch (event) { |
Karen Xie | 515f1c8 | 2009-04-01 13:11:23 -0500 | [diff] [blame] | 79 | case OFFLOAD_STATUS_DOWN: |
| 80 | snic->flags |= CXGB3I_ADAPTER_FLAG_RESET; |
| 81 | break; |
| 82 | case OFFLOAD_STATUS_UP: |
| 83 | snic->flags &= ~CXGB3I_ADAPTER_FLAG_RESET; |
| 84 | break; |
| 85 | } |
| 86 | } |
| 87 | |
Karen Xie | c367346 | 2008-12-09 14:15:32 -0800 | [diff] [blame] | 88 | /** |
| 89 | * cxgb3i_init_module - module init entry point |
| 90 | * |
| 91 | * initialize any driver wide global data structures and register itself |
| 92 | * with the cxgb3 module |
| 93 | */ |
| 94 | static int __init cxgb3i_init_module(void) |
| 95 | { |
| 96 | int err; |
| 97 | |
| 98 | err = cxgb3i_sdev_init(cxgb3i_cpl_handlers); |
| 99 | if (err < 0) |
| 100 | return err; |
| 101 | |
| 102 | err = cxgb3i_iscsi_init(); |
| 103 | if (err < 0) |
| 104 | return err; |
| 105 | |
| 106 | err = cxgb3i_pdu_init(); |
Roland Dreier | 3487d9e | 2010-04-27 22:39:22 -0700 | [diff] [blame] | 107 | if (err < 0) { |
| 108 | cxgb3i_iscsi_cleanup(); |
Karen Xie | c367346 | 2008-12-09 14:15:32 -0800 | [diff] [blame] | 109 | return err; |
Roland Dreier | 3487d9e | 2010-04-27 22:39:22 -0700 | [diff] [blame] | 110 | } |
Karen Xie | c367346 | 2008-12-09 14:15:32 -0800 | [diff] [blame] | 111 | |
| 112 | cxgb3_register_client(&t3c_client); |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * cxgb3i_exit_module - module cleanup/exit entry point |
| 119 | * |
| 120 | * go through the driver hba list and for each hba, release any resource held. |
| 121 | * and unregisters iscsi transport and the cxgb3 module |
| 122 | */ |
| 123 | static void __exit cxgb3i_exit_module(void) |
| 124 | { |
| 125 | cxgb3_unregister_client(&t3c_client); |
| 126 | cxgb3i_pdu_cleanup(); |
| 127 | cxgb3i_iscsi_cleanup(); |
| 128 | cxgb3i_sdev_cleanup(); |
| 129 | } |
| 130 | |
| 131 | module_init(cxgb3i_init_module); |
| 132 | module_exit(cxgb3i_exit_module); |