blob: 7b31e3f403f9060b2af3955e8f306538206ff486 [file] [log] [blame]
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001/*
Christof Schmitt553448f2008-06-10 18:20:58 +02002 * zfcp device driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Christof Schmitt553448f2008-06-10 18:20:58 +02004 * Interface to Linux SCSI midlayer.
Swen Schillig41fa2ad2007-09-07 09:15:31 +02005 *
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02006 * Copyright IBM Corp. 2002, 2010
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
Christof Schmittecf39d42008-12-25 13:39:53 +01009#define KMSG_COMPONENT "zfcp"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
Heiko Carstens3a4c5d52011-07-30 09:25:15 +020012#include <linux/module.h>
Christof Schmitt4318e082009-11-24 16:54:08 +010013#include <linux/types.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
Christof Schmitt4318e082009-11-24 16:54:08 +010015#include <scsi/fc/fc_fcp.h>
Felix Beckef3eb712010-07-16 15:37:42 +020016#include <scsi/scsi_eh.h>
Arun Sharma600634972011-07-26 16:09:06 -070017#include <linux/atomic.h>
Christof Schmittdcd20e22009-08-18 15:43:08 +020018#include "zfcp_ext.h"
19#include "zfcp_dbf.h"
Christof Schmitt7c7dc192009-11-24 16:54:13 +010020#include "zfcp_fc.h"
Christof Schmittb6bd2fb2010-02-17 11:18:50 +010021#include "zfcp_reqlist.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Christof Schmitta40a1ba2009-05-15 13:18:16 +020023static unsigned int default_depth = 32;
24module_param_named(queue_depth, default_depth, uint, 0600);
25MODULE_PARM_DESC(queue_depth, "Default queue depth for new SCSI devices");
26
Felix Beckef3eb712010-07-16 15:37:42 +020027static bool enable_dif;
Steffen Maiercc405ac2011-08-15 14:40:30 +020028module_param_named(dif, enable_dif, bool, 0400);
Felix Beckef3eb712010-07-16 15:37:42 +020029MODULE_PARM_DESC(dif, "Enable DIF/DIX data integrity support");
Felix Beckef3eb712010-07-16 15:37:42 +020030
Christof Schmitt0d81b4e2010-12-08 17:30:46 +010031static bool allow_lun_scan = 1;
32module_param(allow_lun_scan, bool, 0600);
33MODULE_PARM_DESC(allow_lun_scan, "For NPIV, scan and attach all storage LUNs");
34
Mike Christiee881a172009-10-15 17:46:39 -070035static int zfcp_scsi_change_queue_depth(struct scsi_device *sdev, int depth,
36 int reason)
Christof Schmitta40a1ba2009-05-15 13:18:16 +020037{
Christof Schmitt42e62a72009-10-15 17:47:11 -070038 switch (reason) {
39 case SCSI_QDEPTH_DEFAULT:
40 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
41 break;
42 case SCSI_QDEPTH_QFULL:
43 scsi_track_queue_full(sdev, depth);
44 break;
45 case SCSI_QDEPTH_RAMP_UP:
46 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
47 break;
48 default:
Mike Christiee881a172009-10-15 17:46:39 -070049 return -EOPNOTSUPP;
Christof Schmitt42e62a72009-10-15 17:47:11 -070050 }
Christof Schmitta40a1ba2009-05-15 13:18:16 +020051 return sdev->queue_depth;
52}
53
Christof Schmittb62a8d92010-09-08 14:39:55 +020054static void zfcp_scsi_slave_destroy(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
Christof Schmittb62a8d92010-09-08 14:39:55 +020056 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
57
Steffen Maier44f747f2011-11-18 20:00:40 +010058 /* if previous slave_alloc returned early, there is nothing to do */
59 if (!zfcp_sdev->port)
60 return;
61
Christof Schmittb62a8d92010-09-08 14:39:55 +020062 zfcp_erp_lun_shutdown_wait(sdev, "scssd_1");
63 put_device(&zfcp_sdev->port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064}
65
Martin Petermannf76af7d72008-07-02 10:56:36 +020066static int zfcp_scsi_slave_configure(struct scsi_device *sdp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
68 if (sdp->tagged_supported)
Christof Schmitta40a1ba2009-05-15 13:18:16 +020069 scsi_adjust_queue_depth(sdp, MSG_SIMPLE_TAG, default_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 else
71 scsi_adjust_queue_depth(sdp, 0, 1);
72 return 0;
73}
74
Martin Petermannf76af7d72008-07-02 10:56:36 +020075static void zfcp_scsi_command_fail(struct scsi_cmnd *scpnt, int result)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
Martin Petermannfeac6a02008-07-02 10:56:35 +020077 set_host_byte(scpnt, result);
Swen Schillig250a1352010-12-02 15:16:15 +010078 zfcp_dbf_scsi_fail_send(scpnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 scpnt->scsi_done(scpnt);
80}
81
Christof Schmitte55f8752010-11-18 14:53:18 +010082static
83int zfcp_scsi_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scpnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Christof Schmittb62a8d92010-09-08 14:39:55 +020085 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scpnt->device);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +010086 struct fc_rport *rport = starget_to_rport(scsi_target(scpnt->device));
Christof Schmittb62a8d92010-09-08 14:39:55 +020087 int status, scsi_result, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89 /* reset the status for this request */
90 scpnt->result = 0;
91 scpnt->host_scribble = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Christof Schmitta2fa0ae2009-03-02 13:09:08 +010093 scsi_result = fc_remote_port_chkready(rport);
94 if (unlikely(scsi_result)) {
95 scpnt->result = scsi_result;
Swen Schillig250a1352010-12-02 15:16:15 +010096 zfcp_dbf_scsi_fail_send(scpnt);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +010097 scpnt->scsi_done(scpnt);
98 return 0;
99 }
100
Christof Schmittb62a8d92010-09-08 14:39:55 +0200101 status = atomic_read(&zfcp_sdev->status);
Christof Schmitt88302712009-11-24 16:54:07 +0100102 if (unlikely(status & ZFCP_STATUS_COMMON_ERP_FAILED) &&
Christof Schmittb62a8d92010-09-08 14:39:55 +0200103 !(atomic_read(&zfcp_sdev->port->status) &
Christof Schmitt88302712009-11-24 16:54:07 +0100104 ZFCP_STATUS_COMMON_ERP_FAILED)) {
Christof Schmittb62a8d92010-09-08 14:39:55 +0200105 /* only LUN access denied, but port is good
Christof Schmitt88302712009-11-24 16:54:07 +0100106 * not covered by FC transport, have to fail here */
Martin Petermannf76af7d72008-07-02 10:56:36 +0200107 zfcp_scsi_command_fail(scpnt, DID_ERROR);
Joe Perchesa419aef2009-08-18 11:18:35 -0700108 return 0;
Martin Petermannf76af7d72008-07-02 10:56:36 +0200109 }
110
Christof Schmitt88302712009-11-24 16:54:07 +0100111 if (unlikely(!(status & ZFCP_STATUS_COMMON_UNBLOCKED))) {
112 /* This could be either
Christof Schmittb62a8d92010-09-08 14:39:55 +0200113 * open LUN pending: this is temporary, will result in
114 * open LUN or ERP_FAILED, so retry command
Christof Schmitt88302712009-11-24 16:54:07 +0100115 * call to rport_delete pending: mimic retry from
116 * fc_remote_port_chkready until rport is BLOCKED
117 */
118 zfcp_scsi_command_fail(scpnt, DID_IMM_RETRY);
119 return 0;
120 }
121
Christof Schmittb62a8d92010-09-08 14:39:55 +0200122 ret = zfcp_fsf_fcp_cmnd(scpnt);
Martin Petermannf76af7d72008-07-02 10:56:36 +0200123 if (unlikely(ret == -EBUSY))
Swen Schilligf7a65e92008-11-27 11:44:07 +0100124 return SCSI_MLQUEUE_DEVICE_BUSY;
Martin Petermannf76af7d72008-07-02 10:56:36 +0200125 else if (unlikely(ret < 0))
126 return SCSI_MLQUEUE_HOST_BUSY;
127
128 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
Christof Schmittb62a8d92010-09-08 14:39:55 +0200131static int zfcp_scsi_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
Christof Schmittb62a8d92010-09-08 14:39:55 +0200133 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
134 struct zfcp_adapter *adapter =
135 (struct zfcp_adapter *) sdev->host->hostdata[0];
136 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 struct zfcp_port *port;
Martin Petermannf76af7d72008-07-02 10:56:36 +0200138 struct zfcp_unit *unit;
Christof Schmitt0d81b4e2010-12-08 17:30:46 +0100139 int npiv = adapter->connection_features & FSF_FEATURE_NPIV_MODE;
Martin Petermannf76af7d72008-07-02 10:56:36 +0200140
Christof Schmittb62a8d92010-09-08 14:39:55 +0200141 port = zfcp_get_port_by_wwpn(adapter, rport->port_name);
142 if (!port)
143 return -ENXIO;
Martin Petermannf76af7d72008-07-02 10:56:36 +0200144
Christof Schmittb62a8d92010-09-08 14:39:55 +0200145 unit = zfcp_unit_find(port, zfcp_scsi_dev_lun(sdev));
146 if (unit)
147 put_device(&unit->dev);
Christof Schmittf8210e32010-09-08 14:39:56 +0200148
Christof Schmitt0d81b4e2010-12-08 17:30:46 +0100149 if (!unit && !(allow_lun_scan && npiv)) {
Christof Schmittb62a8d92010-09-08 14:39:55 +0200150 put_device(&port->dev);
151 return -ENXIO;
Martin Petermannf76af7d72008-07-02 10:56:36 +0200152 }
Christof Schmittb62a8d92010-09-08 14:39:55 +0200153
154 zfcp_sdev->port = port;
155 zfcp_sdev->latencies.write.channel.min = 0xFFFFFFFF;
156 zfcp_sdev->latencies.write.fabric.min = 0xFFFFFFFF;
157 zfcp_sdev->latencies.read.channel.min = 0xFFFFFFFF;
158 zfcp_sdev->latencies.read.fabric.min = 0xFFFFFFFF;
159 zfcp_sdev->latencies.cmd.channel.min = 0xFFFFFFFF;
160 zfcp_sdev->latencies.cmd.fabric.min = 0xFFFFFFFF;
161 spin_lock_init(&zfcp_sdev->latencies.lock);
162
Swen Schilligedaed852010-09-08 14:40:01 +0200163 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_RUNNING);
Swen Schilligea4a3a62010-12-02 15:16:16 +0100164 zfcp_erp_lun_reopen(sdev, 0, "scsla_1");
Christof Schmittb62a8d92010-09-08 14:39:55 +0200165 zfcp_erp_wait(port->adapter);
166
167 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168}
169
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100170static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
Christof Schmitt63caf362009-03-02 13:09:00 +0100172 struct Scsi_Host *scsi_host = scpnt->device->host;
173 struct zfcp_adapter *adapter =
174 (struct zfcp_adapter *) scsi_host->hostdata[0];
Christof Schmitt63caf362009-03-02 13:09:00 +0100175 struct zfcp_fsf_req *old_req, *abrt_req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 unsigned long flags;
Christof Schmitta11a52b2009-07-13 15:06:14 +0200177 unsigned long old_reqid = (unsigned long) scpnt->host_scribble;
Christof Schmitta1dbfdd2010-03-24 16:50:31 +0100178 int retval = SUCCESS, ret;
Christof Schmitt63caf362009-03-02 13:09:00 +0100179 int retry = 3;
Christof Schmitta11a52b2009-07-13 15:06:14 +0200180 char *dbf_tag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200182 /* avoid race condition between late normal completion and abort */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 write_lock_irqsave(&adapter->abort_lock, flags);
184
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100185 old_req = zfcp_reqlist_find(adapter->req_list, old_reqid);
Christof Schmitt63caf362009-03-02 13:09:00 +0100186 if (!old_req) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 write_unlock_irqrestore(&adapter->abort_lock, flags);
Swen Schillig250a1352010-12-02 15:16:15 +0100188 zfcp_dbf_scsi_abort("abrt_or", scpnt, NULL);
Christof Schmittc6936e72009-04-17 15:08:11 +0200189 return FAILED; /* completion could be in progress */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 }
Christof Schmitt63caf362009-03-02 13:09:00 +0100191 old_req->data = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Andreas Herrmann4eff4a32006-09-18 22:29:20 +0200193 /* don't access old fsf_req after releasing the abort_lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 write_unlock_irqrestore(&adapter->abort_lock, flags);
Andreas Herrmann4eff4a32006-09-18 22:29:20 +0200195
Christof Schmitt63caf362009-03-02 13:09:00 +0100196 while (retry--) {
Christof Schmittb62a8d92010-09-08 14:39:55 +0200197 abrt_req = zfcp_fsf_abort_fcp_cmnd(scpnt);
Christof Schmitt63caf362009-03-02 13:09:00 +0100198 if (abrt_req)
199 break;
200
201 zfcp_erp_wait(adapter);
Christof Schmitta1dbfdd2010-03-24 16:50:31 +0100202 ret = fc_block_scsi_eh(scpnt);
Swen Schillig250a1352010-12-02 15:16:15 +0100203 if (ret) {
204 zfcp_dbf_scsi_abort("abrt_bl", scpnt, NULL);
Christof Schmitta1dbfdd2010-03-24 16:50:31 +0100205 return ret;
Swen Schillig250a1352010-12-02 15:16:15 +0100206 }
Christof Schmitt63caf362009-03-02 13:09:00 +0100207 if (!(atomic_read(&adapter->status) &
208 ZFCP_STATUS_COMMON_RUNNING)) {
Swen Schillig250a1352010-12-02 15:16:15 +0100209 zfcp_dbf_scsi_abort("abrt_ru", scpnt, NULL);
Christof Schmitt63caf362009-03-02 13:09:00 +0100210 return SUCCESS;
211 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 }
Swen Schillig250a1352010-12-02 15:16:15 +0100213 if (!abrt_req) {
214 zfcp_dbf_scsi_abort("abrt_ar", scpnt, NULL);
Christof Schmitt63caf362009-03-02 13:09:00 +0100215 return FAILED;
Swen Schillig250a1352010-12-02 15:16:15 +0100216 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
Swen Schillig058b8642009-08-18 15:43:14 +0200218 wait_for_completion(&abrt_req->completion);
Andreas Herrmann059c97d2005-09-13 21:47:52 +0200219
Christof Schmitt63caf362009-03-02 13:09:00 +0100220 if (abrt_req->status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED)
Swen Schillig250a1352010-12-02 15:16:15 +0100221 dbf_tag = "abrt_ok";
Christof Schmitt63caf362009-03-02 13:09:00 +0100222 else if (abrt_req->status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED)
Swen Schillig250a1352010-12-02 15:16:15 +0100223 dbf_tag = "abrt_nn";
Christof Schmitt63caf362009-03-02 13:09:00 +0100224 else {
Swen Schillig250a1352010-12-02 15:16:15 +0100225 dbf_tag = "abrt_fa";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 retval = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 }
Swen Schillig250a1352010-12-02 15:16:15 +0100228 zfcp_dbf_scsi_abort(dbf_tag, scpnt, abrt_req);
Christof Schmitt63caf362009-03-02 13:09:00 +0100229 zfcp_fsf_req_free(abrt_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 return retval;
231}
232
Christof Schmitt63caf362009-03-02 13:09:00 +0100233static int zfcp_task_mgmt_function(struct scsi_cmnd *scpnt, u8 tm_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234{
Christof Schmittb62a8d92010-09-08 14:39:55 +0200235 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scpnt->device);
236 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
Swen Schillig564e1c82009-08-18 15:43:19 +0200237 struct zfcp_fsf_req *fsf_req = NULL;
Christof Schmitta1dbfdd2010-03-24 16:50:31 +0100238 int retval = SUCCESS, ret;
Christof Schmitt63caf362009-03-02 13:09:00 +0100239 int retry = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Christof Schmitt63caf362009-03-02 13:09:00 +0100241 while (retry--) {
Christof Schmittb62a8d92010-09-08 14:39:55 +0200242 fsf_req = zfcp_fsf_fcp_task_mgmt(scpnt, tm_flags);
Christof Schmitt63caf362009-03-02 13:09:00 +0100243 if (fsf_req)
244 break;
245
246 zfcp_erp_wait(adapter);
Christof Schmitta1dbfdd2010-03-24 16:50:31 +0100247 ret = fc_block_scsi_eh(scpnt);
248 if (ret)
249 return ret;
250
Christof Schmitt63caf362009-03-02 13:09:00 +0100251 if (!(atomic_read(&adapter->status) &
252 ZFCP_STATUS_COMMON_RUNNING)) {
Christof Schmittb62a8d92010-09-08 14:39:55 +0200253 zfcp_dbf_scsi_devreset("nres", scpnt, tm_flags);
Christof Schmitt63caf362009-03-02 13:09:00 +0100254 return SUCCESS;
255 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 }
Christof Schmitt63caf362009-03-02 13:09:00 +0100257 if (!fsf_req)
258 return FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Swen Schillig058b8642009-08-18 15:43:14 +0200260 wait_for_completion(&fsf_req->completion);
Andreas Herrmann77eb1692005-09-13 21:48:33 +0200261
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200262 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED) {
Christof Schmittb62a8d92010-09-08 14:39:55 +0200263 zfcp_dbf_scsi_devreset("fail", scpnt, tm_flags);
Martin Petermannf76af7d72008-07-02 10:56:36 +0200264 retval = FAILED;
Maxim Shchetynin8a36e452005-09-13 21:50:38 +0200265 } else
Christof Schmittb62a8d92010-09-08 14:39:55 +0200266 zfcp_dbf_scsi_devreset("okay", scpnt, tm_flags);
Andreas Herrmann77eb1692005-09-13 21:48:33 +0200267
268 zfcp_fsf_req_free(fsf_req);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 return retval;
270}
271
Martin Petermannf76af7d72008-07-02 10:56:36 +0200272static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt)
273{
Christof Schmitt4318e082009-11-24 16:54:08 +0100274 return zfcp_task_mgmt_function(scpnt, FCP_TMF_LUN_RESET);
Martin Petermannf76af7d72008-07-02 10:56:36 +0200275}
276
277static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd *scpnt)
278{
Christof Schmitt4318e082009-11-24 16:54:08 +0100279 return zfcp_task_mgmt_function(scpnt, FCP_TMF_TGT_RESET);
Martin Petermannf76af7d72008-07-02 10:56:36 +0200280}
281
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100282static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Christof Schmittb62a8d92010-09-08 14:39:55 +0200284 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scpnt->device);
285 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
Christof Schmitta1dbfdd2010-03-24 16:50:31 +0100286 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Swen Schilligea4a3a62010-12-02 15:16:16 +0100288 zfcp_erp_adapter_reopen(adapter, 0, "schrh_1");
Andreas Herrmann81654282006-09-18 22:30:36 +0200289 zfcp_erp_wait(adapter);
Christof Schmitta1dbfdd2010-03-24 16:50:31 +0100290 ret = fc_block_scsi_eh(scpnt);
291 if (ret)
292 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Andreas Herrmann810f1e3e2005-09-13 21:49:52 +0200294 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295}
296
Christof Schmitt1947c722011-02-22 19:54:46 +0100297struct scsi_transport_template *zfcp_scsi_transport_template;
298
299static struct scsi_host_template zfcp_scsi_host_template = {
300 .module = THIS_MODULE,
301 .name = "zfcp",
302 .queuecommand = zfcp_scsi_queuecommand,
303 .eh_abort_handler = zfcp_scsi_eh_abort_handler,
304 .eh_device_reset_handler = zfcp_scsi_eh_device_reset_handler,
305 .eh_target_reset_handler = zfcp_scsi_eh_target_reset_handler,
306 .eh_host_reset_handler = zfcp_scsi_eh_host_reset_handler,
307 .slave_alloc = zfcp_scsi_slave_alloc,
308 .slave_configure = zfcp_scsi_slave_configure,
309 .slave_destroy = zfcp_scsi_slave_destroy,
310 .change_queue_depth = zfcp_scsi_change_queue_depth,
311 .proc_name = "zfcp",
312 .can_queue = 4096,
313 .this_id = -1,
Swen Schillig86a96682011-08-15 14:40:32 +0200314 .sg_tablesize = 1, /* adjusted later */
315 .max_sectors = 8, /* adjusted later */
Christof Schmitt1947c722011-02-22 19:54:46 +0100316 .dma_boundary = ZFCP_QDIO_SBALE_LEN - 1,
317 .cmd_per_lun = 1,
318 .use_clustering = 1,
319 .shost_attrs = zfcp_sysfs_shost_attrs,
320 .sdev_attrs = zfcp_sysfs_sdev_attrs,
321};
322
323/**
324 * zfcp_scsi_adapter_register - Register SCSI and FC host with SCSI midlayer
325 * @adapter: The zfcp adapter to register with the SCSI midlayer
326 */
327int zfcp_scsi_adapter_register(struct zfcp_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328{
Martin Petermannf76af7d72008-07-02 10:56:36 +0200329 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Michael Loehr9f287452007-05-09 11:01:24 +0200331 if (adapter->scsi_host)
Martin Petermannf76af7d72008-07-02 10:56:36 +0200332 return 0;
Michael Loehr9f287452007-05-09 11:01:24 +0200333
Martin Petermannf76af7d72008-07-02 10:56:36 +0200334 ccw_device_get_id(adapter->ccw_device, &dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 /* register adapter as SCSI host with mid layer of SCSI stack */
Christof Schmitt1947c722011-02-22 19:54:46 +0100336 adapter->scsi_host = scsi_host_alloc(&zfcp_scsi_host_template,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 sizeof (struct zfcp_adapter *));
338 if (!adapter->scsi_host) {
Christof Schmitt553448f2008-06-10 18:20:58 +0200339 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +0200340 "Registering the FCP device with the "
341 "SCSI stack failed\n");
Martin Petermannf76af7d72008-07-02 10:56:36 +0200342 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
345 /* tell the SCSI stack some characteristics of this adapter */
Christof Schmittf8210e32010-09-08 14:39:56 +0200346 adapter->scsi_host->max_id = 511;
347 adapter->scsi_host->max_lun = 0xFFFFFFFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 adapter->scsi_host->max_channel = 0;
Martin Petermannf76af7d72008-07-02 10:56:36 +0200349 adapter->scsi_host->unique_id = dev_id.devno;
Christof Schmitt4318e082009-11-24 16:54:08 +0100350 adapter->scsi_host->max_cmd_len = 16; /* in struct fcp_cmnd */
Christof Schmitt1947c722011-02-22 19:54:46 +0100351 adapter->scsi_host->transportt = zfcp_scsi_transport_template;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 adapter->scsi_host->hostdata[0] = (unsigned long) adapter;
354
355 if (scsi_add_host(adapter->scsi_host, &adapter->ccw_device->dev)) {
356 scsi_host_put(adapter->scsi_host);
Martin Petermannf76af7d72008-07-02 10:56:36 +0200357 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 }
Martin Petermannf76af7d72008-07-02 10:56:36 +0200359
360 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361}
362
Christof Schmitt1947c722011-02-22 19:54:46 +0100363/**
364 * zfcp_scsi_adapter_unregister - Unregister SCSI and FC host from SCSI midlayer
365 * @adapter: The zfcp adapter to unregister.
366 */
367void zfcp_scsi_adapter_unregister(struct zfcp_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
369 struct Scsi_Host *shost;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200370 struct zfcp_port *port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
372 shost = adapter->scsi_host;
373 if (!shost)
374 return;
Martin Petermannf76af7d72008-07-02 10:56:36 +0200375
Swen Schilligecf0c772009-11-24 16:53:58 +0100376 read_lock_irq(&adapter->port_list_lock);
377 list_for_each_entry(port, &adapter->port_list, list)
Swen Schilligf3450c72009-11-24 16:53:59 +0100378 port->rport = NULL;
Swen Schilligecf0c772009-11-24 16:53:58 +0100379 read_unlock_irq(&adapter->port_list_lock);
Martin Petermannf76af7d72008-07-02 10:56:36 +0200380
Andreas Herrmann3859f6a2005-08-27 11:07:54 -0700381 fc_remove_host(shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 scsi_remove_host(shost);
383 scsi_host_put(shost);
384 adapter->scsi_host = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385}
386
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100387static struct fc_host_statistics*
388zfcp_init_fc_host_stats(struct zfcp_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389{
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100390 struct fc_host_statistics *fc_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100392 if (!adapter->fc_stats) {
393 fc_stats = kmalloc(sizeof(*fc_stats), GFP_KERNEL);
394 if (!fc_stats)
395 return NULL;
Swen Schilligf3450c72009-11-24 16:53:59 +0100396 adapter->fc_stats = fc_stats; /* freed in adapter_release */
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100397 }
398 memset(adapter->fc_stats, 0, sizeof(*adapter->fc_stats));
399 return adapter->fc_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400}
401
Martin Petermannf76af7d72008-07-02 10:56:36 +0200402static void zfcp_adjust_fc_host_stats(struct fc_host_statistics *fc_stats,
403 struct fsf_qtcb_bottom_port *data,
404 struct fsf_qtcb_bottom_port *old)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405{
Martin Petermannf76af7d72008-07-02 10:56:36 +0200406 fc_stats->seconds_since_last_reset =
407 data->seconds_since_last_reset - old->seconds_since_last_reset;
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100408 fc_stats->tx_frames = data->tx_frames - old->tx_frames;
409 fc_stats->tx_words = data->tx_words - old->tx_words;
410 fc_stats->rx_frames = data->rx_frames - old->rx_frames;
411 fc_stats->rx_words = data->rx_words - old->rx_words;
412 fc_stats->lip_count = data->lip - old->lip;
413 fc_stats->nos_count = data->nos - old->nos;
414 fc_stats->error_frames = data->error_frames - old->error_frames;
415 fc_stats->dumped_frames = data->dumped_frames - old->dumped_frames;
416 fc_stats->link_failure_count = data->link_failure - old->link_failure;
417 fc_stats->loss_of_sync_count = data->loss_of_sync - old->loss_of_sync;
Martin Petermannf76af7d72008-07-02 10:56:36 +0200418 fc_stats->loss_of_signal_count =
419 data->loss_of_signal - old->loss_of_signal;
420 fc_stats->prim_seq_protocol_err_count =
421 data->psp_error_counts - old->psp_error_counts;
422 fc_stats->invalid_tx_word_count =
423 data->invalid_tx_words - old->invalid_tx_words;
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100424 fc_stats->invalid_crc_count = data->invalid_crcs - old->invalid_crcs;
Martin Petermannf76af7d72008-07-02 10:56:36 +0200425 fc_stats->fcp_input_requests =
426 data->input_requests - old->input_requests;
427 fc_stats->fcp_output_requests =
428 data->output_requests - old->output_requests;
429 fc_stats->fcp_control_requests =
430 data->control_requests - old->control_requests;
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100431 fc_stats->fcp_input_megabytes = data->input_mb - old->input_mb;
432 fc_stats->fcp_output_megabytes = data->output_mb - old->output_mb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433}
434
Martin Petermannf76af7d72008-07-02 10:56:36 +0200435static void zfcp_set_fc_host_stats(struct fc_host_statistics *fc_stats,
436 struct fsf_qtcb_bottom_port *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437{
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100438 fc_stats->seconds_since_last_reset = data->seconds_since_last_reset;
439 fc_stats->tx_frames = data->tx_frames;
440 fc_stats->tx_words = data->tx_words;
441 fc_stats->rx_frames = data->rx_frames;
442 fc_stats->rx_words = data->rx_words;
443 fc_stats->lip_count = data->lip;
444 fc_stats->nos_count = data->nos;
445 fc_stats->error_frames = data->error_frames;
446 fc_stats->dumped_frames = data->dumped_frames;
447 fc_stats->link_failure_count = data->link_failure;
448 fc_stats->loss_of_sync_count = data->loss_of_sync;
449 fc_stats->loss_of_signal_count = data->loss_of_signal;
450 fc_stats->prim_seq_protocol_err_count = data->psp_error_counts;
451 fc_stats->invalid_tx_word_count = data->invalid_tx_words;
452 fc_stats->invalid_crc_count = data->invalid_crcs;
453 fc_stats->fcp_input_requests = data->input_requests;
454 fc_stats->fcp_output_requests = data->output_requests;
455 fc_stats->fcp_control_requests = data->control_requests;
456 fc_stats->fcp_input_megabytes = data->input_mb;
457 fc_stats->fcp_output_megabytes = data->output_mb;
458}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
Martin Petermannf76af7d72008-07-02 10:56:36 +0200460static struct fc_host_statistics *zfcp_get_fc_host_stats(struct Scsi_Host *host)
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100461{
462 struct zfcp_adapter *adapter;
463 struct fc_host_statistics *fc_stats;
464 struct fsf_qtcb_bottom_port *data;
465 int ret;
466
Martin Petermannf76af7d72008-07-02 10:56:36 +0200467 adapter = (struct zfcp_adapter *)host->hostdata[0];
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100468 fc_stats = zfcp_init_fc_host_stats(adapter);
469 if (!fc_stats)
470 return NULL;
471
Andreas Herrmannec4081c2006-05-22 18:17:30 +0200472 data = kzalloc(sizeof(*data), GFP_KERNEL);
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100473 if (!data)
474 return NULL;
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100475
Swen Schillig564e1c82009-08-18 15:43:19 +0200476 ret = zfcp_fsf_exchange_port_data_sync(adapter->qdio, data);
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100477 if (ret) {
478 kfree(data);
Martin Petermannf76af7d72008-07-02 10:56:36 +0200479 return NULL;
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100480 }
481
482 if (adapter->stats_reset &&
483 ((jiffies/HZ - adapter->stats_reset) <
Martin Petermannf76af7d72008-07-02 10:56:36 +0200484 data->seconds_since_last_reset))
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100485 zfcp_adjust_fc_host_stats(fc_stats, data,
486 adapter->stats_reset_data);
Martin Petermannf76af7d72008-07-02 10:56:36 +0200487 else
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100488 zfcp_set_fc_host_stats(fc_stats, data);
489
490 kfree(data);
491 return fc_stats;
492}
493
Martin Petermannf76af7d72008-07-02 10:56:36 +0200494static void zfcp_reset_fc_host_stats(struct Scsi_Host *shost)
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100495{
496 struct zfcp_adapter *adapter;
Martin Petermannf76af7d72008-07-02 10:56:36 +0200497 struct fsf_qtcb_bottom_port *data;
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100498 int ret;
499
500 adapter = (struct zfcp_adapter *)shost->hostdata[0];
Andreas Herrmannec4081c2006-05-22 18:17:30 +0200501 data = kzalloc(sizeof(*data), GFP_KERNEL);
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100502 if (!data)
503 return;
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100504
Swen Schillig564e1c82009-08-18 15:43:19 +0200505 ret = zfcp_fsf_exchange_port_data_sync(adapter->qdio, data);
Martin Petermannf76af7d72008-07-02 10:56:36 +0200506 if (ret)
Heiko Carstens83f6d6d2007-08-08 10:47:02 +0200507 kfree(data);
Martin Petermannf76af7d72008-07-02 10:56:36 +0200508 else {
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100509 adapter->stats_reset = jiffies/HZ;
Martin Petermannf76af7d72008-07-02 10:56:36 +0200510 kfree(adapter->stats_reset_data);
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100511 adapter->stats_reset_data = data; /* finally freed in
Swen Schilligf3450c72009-11-24 16:53:59 +0100512 adapter_release */
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100513 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514}
515
Sven Schuetz85a82392008-06-10 18:20:59 +0200516static void zfcp_get_host_port_state(struct Scsi_Host *shost)
517{
518 struct zfcp_adapter *adapter =
519 (struct zfcp_adapter *)shost->hostdata[0];
520 int status = atomic_read(&adapter->status);
521
522 if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
523 !(status & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED))
524 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
525 else if (status & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
526 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
527 else if (status & ZFCP_STATUS_COMMON_ERP_FAILED)
528 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
529 else
530 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
531}
532
Andreas Herrmann338151e2006-05-22 18:25:56 +0200533static void zfcp_set_rport_dev_loss_tmo(struct fc_rport *rport, u32 timeout)
534{
535 rport->dev_loss_tmo = timeout;
536}
537
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100538/**
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100539 * zfcp_scsi_terminate_rport_io - Terminate all I/O on a rport
540 * @rport: The FC rport where to teminate I/O
541 *
542 * Abort all pending SCSI commands for a port by closing the
Christof Schmitt835dc292010-07-08 09:53:08 +0200543 * port. Using a reopen avoids a conflict with a shutdown
544 * overwriting a reopen. The "forced" ensures that a disappeared port
545 * is not opened again as valid due to the cached plogi data in
546 * non-NPIV mode.
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100547 */
548static void zfcp_scsi_terminate_rport_io(struct fc_rport *rport)
549{
Christof Schmitt70932932009-04-17 15:08:15 +0200550 struct zfcp_port *port;
Swen Schilligea945ff2009-08-18 15:43:24 +0200551 struct Scsi_Host *shost = rport_to_shost(rport);
552 struct zfcp_adapter *adapter =
553 (struct zfcp_adapter *)shost->hostdata[0];
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100554
Swen Schilligea945ff2009-08-18 15:43:24 +0200555 port = zfcp_get_port_by_wwpn(adapter, rport->port_name);
Christof Schmitt70932932009-04-17 15:08:15 +0200556
557 if (port) {
Swen Schilligea4a3a62010-12-02 15:16:16 +0100558 zfcp_erp_port_forced_reopen(port, 0, "sctrpi1");
Christof Schmitt615f59e2010-02-17 11:18:56 +0100559 put_device(&port->dev);
Christof Schmitt70932932009-04-17 15:08:15 +0200560 }
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100561}
562
563static void zfcp_scsi_rport_register(struct zfcp_port *port)
564{
565 struct fc_rport_identifiers ids;
566 struct fc_rport *rport;
567
Christof Schmitt379d6bf2009-07-13 15:06:11 +0200568 if (port->rport)
569 return;
570
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100571 ids.node_name = port->wwnn;
572 ids.port_name = port->wwpn;
573 ids.port_id = port->d_id;
574 ids.roles = FC_RPORT_ROLE_FCP_TARGET;
575
576 rport = fc_remote_port_add(port->adapter->scsi_host, 0, &ids);
577 if (!rport) {
578 dev_err(&port->adapter->ccw_device->dev,
579 "Registering port 0x%016Lx failed\n",
580 (unsigned long long)port->wwpn);
581 return;
582 }
583
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100584 rport->maxframe_size = port->maxframe_size;
585 rport->supported_classes = port->supported_classes;
586 port->rport = rport;
Christof Schmitt1bf3ff02010-07-16 15:37:35 +0200587 port->starget_id = rport->scsi_target_id;
Christof Schmitt5a7de552010-07-08 09:53:07 +0200588
Christof Schmitt1daa4eb2010-09-08 14:39:52 +0200589 zfcp_unit_queue_scsi_scan(port);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100590}
591
592static void zfcp_scsi_rport_block(struct zfcp_port *port)
593{
Christof Schmitt70932932009-04-17 15:08:15 +0200594 struct fc_rport *rport = port->rport;
595
Christof Schmitt379d6bf2009-07-13 15:06:11 +0200596 if (rport) {
Christof Schmitt70932932009-04-17 15:08:15 +0200597 fc_remote_port_delete(rport);
Christof Schmitt379d6bf2009-07-13 15:06:11 +0200598 port->rport = NULL;
599 }
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100600}
601
602void zfcp_scsi_schedule_rport_register(struct zfcp_port *port)
603{
Christof Schmitt615f59e2010-02-17 11:18:56 +0100604 get_device(&port->dev);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100605 port->rport_task = RPORT_ADD;
606
Swen Schillig45446832009-08-18 15:43:17 +0200607 if (!queue_work(port->adapter->work_queue, &port->rport_work))
Christof Schmitt615f59e2010-02-17 11:18:56 +0100608 put_device(&port->dev);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100609}
610
611void zfcp_scsi_schedule_rport_block(struct zfcp_port *port)
612{
Christof Schmitt615f59e2010-02-17 11:18:56 +0100613 get_device(&port->dev);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100614 port->rport_task = RPORT_DEL;
615
Swen Schillig45446832009-08-18 15:43:17 +0200616 if (port->rport && queue_work(port->adapter->work_queue,
617 &port->rport_work))
Swen Schilliga67417a2009-08-18 15:43:06 +0200618 return;
619
Christof Schmitt615f59e2010-02-17 11:18:56 +0100620 put_device(&port->dev);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100621}
622
623void zfcp_scsi_schedule_rports_block(struct zfcp_adapter *adapter)
624{
Swen Schilligecf0c772009-11-24 16:53:58 +0100625 unsigned long flags;
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100626 struct zfcp_port *port;
627
Swen Schilligecf0c772009-11-24 16:53:58 +0100628 read_lock_irqsave(&adapter->port_list_lock, flags);
629 list_for_each_entry(port, &adapter->port_list, list)
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100630 zfcp_scsi_schedule_rport_block(port);
Swen Schilligecf0c772009-11-24 16:53:58 +0100631 read_unlock_irqrestore(&adapter->port_list_lock, flags);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100632}
633
634void zfcp_scsi_rport_work(struct work_struct *work)
635{
636 struct zfcp_port *port = container_of(work, struct zfcp_port,
637 rport_work);
638
639 while (port->rport_task) {
640 if (port->rport_task == RPORT_ADD) {
641 port->rport_task = RPORT_NONE;
642 zfcp_scsi_rport_register(port);
643 } else {
644 port->rport_task = RPORT_NONE;
645 zfcp_scsi_rport_block(port);
646 }
647 }
648
Christof Schmitt615f59e2010-02-17 11:18:56 +0100649 put_device(&port->dev);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100650}
651
Christof Schmitt5a7de552010-07-08 09:53:07 +0200652/**
Felix Beckef3eb712010-07-16 15:37:42 +0200653 * zfcp_scsi_set_prot - Configure DIF/DIX support in scsi_host
654 * @adapter: The adapter where to configure DIF/DIX for the SCSI host
655 */
656void zfcp_scsi_set_prot(struct zfcp_adapter *adapter)
657{
658 unsigned int mask = 0;
659 unsigned int data_div;
660 struct Scsi_Host *shost = adapter->scsi_host;
661
662 data_div = atomic_read(&adapter->status) &
663 ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED;
664
665 if (enable_dif &&
666 adapter->adapter_features & FSF_FEATURE_DIF_PROT_TYPE1)
667 mask |= SHOST_DIF_TYPE1_PROTECTION;
668
669 if (enable_dif && data_div &&
670 adapter->adapter_features & FSF_FEATURE_DIX_PROT_TCPIP) {
671 mask |= SHOST_DIX_TYPE1_PROTECTION;
672 scsi_host_set_guard(shost, SHOST_DIX_GUARD_IP);
Swen Schillig86a96682011-08-15 14:40:32 +0200673 shost->sg_prot_tablesize = adapter->qdio->max_sbale_per_req / 2;
674 shost->sg_tablesize = adapter->qdio->max_sbale_per_req / 2;
675 shost->max_sectors = shost->sg_tablesize * 8;
Felix Beckef3eb712010-07-16 15:37:42 +0200676 }
677
678 scsi_host_set_prot(shost, mask);
679}
680
681/**
682 * zfcp_scsi_dif_sense_error - Report DIF/DIX error as driver sense error
683 * @scmd: The SCSI command to report the error for
684 * @ascq: The ASCQ to put in the sense buffer
685 *
686 * See the error handling in sd_done for the sense codes used here.
687 * Set DID_SOFT_ERROR to retry the request, if possible.
688 */
689void zfcp_scsi_dif_sense_error(struct scsi_cmnd *scmd, int ascq)
690{
691 scsi_build_sense_buffer(1, scmd->sense_buffer,
692 ILLEGAL_REQUEST, 0x10, ascq);
693 set_driver_byte(scmd, DRIVER_SENSE);
694 scmd->result |= SAM_STAT_CHECK_CONDITION;
695 set_host_byte(scmd, DID_SOFT_ERROR);
696}
697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698struct fc_function_template zfcp_transport_functions = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 .show_starget_port_id = 1,
700 .show_starget_port_name = 1,
701 .show_starget_node_name = 1,
Andreas Herrmann3859f6a2005-08-27 11:07:54 -0700702 .show_rport_supported_classes = 1,
Ralph Wuerthner75bfc282006-05-22 18:24:33 +0200703 .show_rport_maxframe_size = 1,
Andreas Herrmann338151e2006-05-22 18:25:56 +0200704 .show_rport_dev_loss_tmo = 1,
Andreas Herrmann3859f6a2005-08-27 11:07:54 -0700705 .show_host_node_name = 1,
706 .show_host_port_name = 1,
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100707 .show_host_permanent_port_name = 1,
Andreas Herrmann3859f6a2005-08-27 11:07:54 -0700708 .show_host_supported_classes = 1,
Christof Schmitt0fdd2132009-11-24 16:54:17 +0100709 .show_host_supported_fc4s = 1,
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100710 .show_host_supported_speeds = 1,
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200711 .show_host_maxframe_size = 1,
Andreas Herrmann3859f6a2005-08-27 11:07:54 -0700712 .show_host_serial_number = 1,
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100713 .get_fc_host_stats = zfcp_get_fc_host_stats,
714 .reset_fc_host_stats = zfcp_reset_fc_host_stats,
Andreas Herrmann338151e2006-05-22 18:25:56 +0200715 .set_rport_dev_loss_tmo = zfcp_set_rport_dev_loss_tmo,
Sven Schuetz85a82392008-06-10 18:20:59 +0200716 .get_host_port_state = zfcp_get_host_port_state,
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100717 .terminate_rport_io = zfcp_scsi_terminate_rport_io,
Sven Schuetz85a82392008-06-10 18:20:59 +0200718 .show_host_port_state = 1,
Christof Schmitt0fdd2132009-11-24 16:54:17 +0100719 .show_host_active_fc4s = 1,
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100720 .bsg_request = zfcp_fc_exec_bsg_job,
Swen Schillig491ca442010-01-14 17:19:01 +0100721 .bsg_timeout = zfcp_fc_timeout_bsg_job,
Andreas Herrmannf6cd94b2006-01-05 09:59:34 +0100722 /* no functions registered for following dynamic attributes but
723 directly set by LLDD */
Andreas Herrmannad757cd2006-01-13 02:26:11 +0100724 .show_host_port_type = 1,
Christof Schmitt038d9442011-02-22 19:54:48 +0100725 .show_host_symbolic_name = 1,
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200726 .show_host_speed = 1,
727 .show_host_port_id = 1,
Christof Schmitt7c7dc192009-11-24 16:54:13 +0100728 .dd_bsg_size = sizeof(struct zfcp_fsf_ct_els),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729};