blob: 833dbfa3f88a7164a4161682a9e4c8a902ec3800 [file] [log] [blame]
Karen Xiec3673462008-12-09 14:15:32 -08001/* 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 Xieb7e7bd32009-02-13 21:39:09 -080015#define DRV_MODULE_VERSION "1.0.1"
16#define DRV_MODULE_RELDATE "Jan. 2009"
Karen Xiec3673462008-12-09 14:15:32 -080017
18static char version[] =
19 "Chelsio S3xx iSCSI Driver " DRV_MODULE_NAME
20 " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
21
22MODULE_AUTHOR("Karen Xie <kxie@chelsio.com>");
23MODULE_DESCRIPTION("Chelsio S3xx iSCSI Driver");
24MODULE_LICENSE("GPL");
25MODULE_VERSION(DRV_MODULE_VERSION);
26
27static void open_s3_dev(struct t3cdev *);
28static void close_s3_dev(struct t3cdev *);
Karen Xie515f1c82009-04-01 13:11:23 -050029static void s3_err_handler(struct t3cdev *tdev, u32 status, u32 error);
Karen Xiec3673462008-12-09 14:15:32 -080030
31static cxgb3_cpl_handler_func cxgb3i_cpl_handlers[NUM_CPL_CMDS];
32static struct cxgb3_client t3c_client = {
33 .name = "iscsi_cxgb3",
34 .handlers = cxgb3i_cpl_handlers,
35 .add = open_s3_dev,
36 .remove = close_s3_dev,
Karen Xie515f1c82009-04-01 13:11:23 -050037 .err_handler = s3_err_handler,
Karen Xiec3673462008-12-09 14:15:32 -080038};
39
40/**
41 * open_s3_dev - register with cxgb3 LLD
42 * @t3dev: cxgb3 adapter instance
43 */
44static 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
53 cxgb3i_sdev_add(t3dev, &t3c_client);
Karen Xie515f1c82009-04-01 13:11:23 -050054 cxgb3i_adapter_open(t3dev);
Karen Xiec3673462008-12-09 14:15:32 -080055}
56
57/**
58 * close_s3_dev - de-register with cxgb3 LLD
59 * @t3dev: cxgb3 adapter instance
60 */
61static void close_s3_dev(struct t3cdev *t3dev)
62{
Karen Xie515f1c82009-04-01 13:11:23 -050063 cxgb3i_adapter_close(t3dev);
Karen Xiec3673462008-12-09 14:15:32 -080064 cxgb3i_sdev_remove(t3dev);
65}
66
Karen Xie515f1c82009-04-01 13:11:23 -050067static void s3_err_handler(struct t3cdev *tdev, u32 status, u32 error)
68{
69 struct cxgb3i_adapter *snic = cxgb3i_adapter_find_by_tdev(tdev);
70
71 cxgb3i_log_info("snic 0x%p, tdev 0x%p, status 0x%x, err 0x%x.\n",
72 snic, tdev, status, error);
73 if (!snic)
74 return;
75
76 switch (status) {
77 case OFFLOAD_STATUS_DOWN:
78 snic->flags |= CXGB3I_ADAPTER_FLAG_RESET;
79 break;
80 case OFFLOAD_STATUS_UP:
81 snic->flags &= ~CXGB3I_ADAPTER_FLAG_RESET;
82 break;
83 }
84}
85
Karen Xiec3673462008-12-09 14:15:32 -080086/**
87 * cxgb3i_init_module - module init entry point
88 *
89 * initialize any driver wide global data structures and register itself
90 * with the cxgb3 module
91 */
92static int __init cxgb3i_init_module(void)
93{
94 int err;
95
96 err = cxgb3i_sdev_init(cxgb3i_cpl_handlers);
97 if (err < 0)
98 return err;
99
100 err = cxgb3i_iscsi_init();
101 if (err < 0)
102 return err;
103
104 err = cxgb3i_pdu_init();
105 if (err < 0)
106 return err;
107
108 cxgb3_register_client(&t3c_client);
109
110 return 0;
111}
112
113/**
114 * cxgb3i_exit_module - module cleanup/exit entry point
115 *
116 * go through the driver hba list and for each hba, release any resource held.
117 * and unregisters iscsi transport and the cxgb3 module
118 */
119static void __exit cxgb3i_exit_module(void)
120{
121 cxgb3_unregister_client(&t3c_client);
122 cxgb3i_pdu_cleanup();
123 cxgb3i_iscsi_cleanup();
124 cxgb3i_sdev_cleanup();
125}
126
127module_init(cxgb3i_init_module);
128module_exit(cxgb3i_exit_module);