4 * Copyright (C) 2004-2006 Vladislav Bolkhovitin <vst@vlnb.net>
7 * SCSI raid(controller) (type 0xC) dev handler
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation, version 2
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 #define LOG_PREFIX "dev_raid"
21 #include "scst_debug.h"
23 #include "scst_dev_handler.h"
25 #include "scst_debug.c"
27 #define RAID_NAME "dev_raid"
33 /* dev_done_atomic: 1,*/ \
34 attach: raid_attach, \
35 /* detach: raid_detach,*/ \
37 /* dev_done: raid_done*/ \
40 #define RAID_RETRIES 2
41 #define RAID_TIMEOUT (3 * HZ)
42 #define RAID_LONG_TIMEOUT (14000 * HZ)
43 #define READ_CAP_LEN 8
45 int raid_attach(struct scst_device *);
46 void raid_detach(struct scst_device *);
47 int raid_parse(struct scst_cmd *, const struct scst_info_cdb *);
48 int raid_done(struct scst_cmd *);
50 #if defined(DEBUG) || defined(TRACING)
51 unsigned long trace_flag = SCST_DEFAULT_DEV_LOG_FLAGS;
54 static struct scst_dev_type raid_devtype = RAID_TYPE;
56 /**************************************************************
57 * Function: raid_attach
61 * Returns : 1 if attached, error code otherwise
64 *************************************************************/
65 int raid_attach(struct scst_device *dev)
72 if (dev->scsi_dev == NULL ||
73 dev->scsi_dev->type != dev->handler->type) {
74 PRINT_ERROR_PR("%s", "SCSI device not define or illegal type");
80 * If the device is offline, don't try to read capacity or any
83 if (dev->scsi_dev->sdev_state == SDEV_OFFLINE)
85 TRACE_DBG("%s", "Device is offline");
90 retries = SCST_DEV_UA_RETRIES;
92 TRACE_DBG("%s", "Doing TEST_UNIT_READY");
93 res = scsi_test_unit_ready(dev->scsi_dev, RAID_TIMEOUT,
95 TRACE_DBG("TEST_UNIT_READY done: %x", res);
96 } while ((--retries > 0) && res);
105 /************************************************************
106 * Function: raid_detach
112 * Description: Called to detach this device type driver
113 ************************************************************/
114 void raid_detach(struct scst_device *dev)
122 /********************************************************************
123 * Function: raid_parse
127 * Returns : The state of the command
129 * Description: This does the parsing of the command
131 * Note: Not all states are allowed on return
132 ********************************************************************/
133 int raid_parse(struct scst_cmd *cmd, const struct scst_info_cdb *info_cdb)
135 int res = SCST_CMD_STATE_DEFAULT;
140 * SCST sets good defaults for cmd->data_direction and cmd->bufflen
141 * based on info_cdb, therefore change them only if necessary
146 if (info_cdb->flags & SCST_LONG_TIMEOUT) {
147 cmd->timeout = RAID_LONG_TIMEOUT;
149 cmd->timeout = RAID_TIMEOUT;
152 TRACE_DBG("op_name <%s> direct %d flags %d transfer_len %d",
154 info_cdb->direction, info_cdb->flags, info_cdb->transfer_len);
156 switch (cmd->cdb[0]) {
162 TRACE_DBG("res %d bufflen %zd direct %d",
163 res, cmd->bufflen, cmd->data_direction);
170 /********************************************************************
171 * Function: raid_done
177 * Description: This is the completion routine for the command,
178 * it is used to extract any necessary information
180 ********************************************************************/
181 int raid_done(struct scst_cmd *cmd)
183 int res = SCST_CMD_STATE_DEFAULT;
187 if (unlikely(cmd->sg == NULL))
191 * SCST sets good defaults for cmd->tgt_resp_flags and cmd->resp_data_len
192 * based on cmd->masked_status and cmd->data_direction, therefore change
193 * them only if necessary
197 switch (cmd->cdb[0]) {
209 static int __init raid_init(void)
215 raid_devtype.module = THIS_MODULE;
216 if (scst_register_dev_driver(&raid_devtype) < 0) {
221 res = scst_dev_handler_build_std_proc(&raid_devtype);
230 scst_unregister_dev_driver(&raid_devtype);
234 static void __exit raid_exit(void)
237 scst_dev_handler_destroy_std_proc(&raid_devtype);
238 scst_unregister_dev_driver(&raid_devtype);
243 module_init(raid_init);
244 module_exit(raid_exit);
246 MODULE_LICENSE("GPL");