blob: 231e231b7fd72959dd29eb893a56f125e706231c [file] [log] [blame]
Christof Schmitt4318e082009-11-24 16:54:08 +01001/*
2 * zfcp device driver
3 *
4 * Fibre Channel related definitions and inline functions for the zfcp
5 * device driver
6 *
7 * Copyright IBM Corporation 2009
8 */
9
10#ifndef ZFCP_FC_H
11#define ZFCP_FC_H
12
Christof Schmitt9d05ce22009-11-24 16:54:09 +010013#include <scsi/fc/fc_els.h>
Christof Schmitt4318e082009-11-24 16:54:08 +010014#include <scsi/fc/fc_fcp.h>
15#include <scsi/scsi_cmnd.h>
16#include <scsi/scsi_tcq.h>
17
18/**
Christof Schmitt9d05ce22009-11-24 16:54:09 +010019 * struct zfcp_fc_els_adisc - everything required in zfcp for issuing ELS ADISC
20 * @els: data required for issuing els fsf command
21 * @req: scatterlist entry for ELS ADISC request
22 * @resp: scatterlist entry for ELS ADISC response
23 * @adisc_req: ELS ADISC request data
24 * @adisc_resp: ELS ADISC response data
25 */
26struct zfcp_fc_els_adisc {
27 struct zfcp_send_els els;
28 struct scatterlist req;
29 struct scatterlist resp;
30 struct fc_els_adisc adisc_req;
31 struct fc_els_adisc adisc_resp;
32};
33
34/**
Christof Schmitt4318e082009-11-24 16:54:08 +010035 * zfcp_fc_scsi_to_fcp - setup FCP command with data from scsi_cmnd
36 * @fcp: fcp_cmnd to setup
37 * @scsi: scsi_cmnd where to get LUN, task attributes/flags and CDB
38 */
39static inline
40void zfcp_fc_scsi_to_fcp(struct fcp_cmnd *fcp, struct scsi_cmnd *scsi)
41{
42 char tag[2];
43
44 int_to_scsilun(scsi->device->lun, (struct scsi_lun *) &fcp->fc_lun);
45
46 if (scsi_populate_tag_msg(scsi, tag)) {
47 switch (tag[0]) {
48 case MSG_ORDERED_TAG:
49 fcp->fc_pri_ta |= FCP_PTA_ORDERED;
50 break;
51 case MSG_SIMPLE_TAG:
52 fcp->fc_pri_ta |= FCP_PTA_SIMPLE;
53 break;
54 };
55 } else
56 fcp->fc_pri_ta = FCP_PTA_SIMPLE;
57
58 if (scsi->sc_data_direction == DMA_FROM_DEVICE)
59 fcp->fc_flags |= FCP_CFL_RDDATA;
60 if (scsi->sc_data_direction == DMA_TO_DEVICE)
61 fcp->fc_flags |= FCP_CFL_WRDATA;
62
63 memcpy(fcp->fc_cdb, scsi->cmnd, scsi->cmd_len);
64
65 fcp->fc_dl = scsi_bufflen(scsi);
66}
67
68/**
69 * zfcp_fc_fcp_tm - setup FCP command as task management command
70 * @fcp: fcp_cmnd to setup
71 * @dev: scsi_device where to send the task management command
72 * @tm: task management flags to setup tm command
73 */
74static inline
75void zfcp_fc_fcp_tm(struct fcp_cmnd *fcp, struct scsi_device *dev, u8 tm_flags)
76{
77 int_to_scsilun(dev->lun, (struct scsi_lun *) &fcp->fc_lun);
78 fcp->fc_tm_flags |= tm_flags;
79}
80
81/**
82 * zfcp_fc_evap_fcp_rsp - evaluate FCP RSP IU and update scsi_cmnd accordingly
83 * @fcp_rsp: FCP RSP IU to evaluate
84 * @scsi: SCSI command where to update status and sense buffer
85 */
86static inline
87void zfcp_fc_eval_fcp_rsp(struct fcp_resp_with_ext *fcp_rsp,
88 struct scsi_cmnd *scsi)
89{
90 struct fcp_resp_rsp_info *rsp_info;
91 char *sense;
92 u32 sense_len, resid;
93 u8 rsp_flags;
94
95 set_msg_byte(scsi, COMMAND_COMPLETE);
96 scsi->result |= fcp_rsp->resp.fr_status;
97
98 rsp_flags = fcp_rsp->resp.fr_flags;
99
100 if (unlikely(rsp_flags & FCP_RSP_LEN_VAL)) {
101 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
102 if (rsp_info->rsp_code == FCP_TMF_CMPL)
103 set_host_byte(scsi, DID_OK);
104 else {
105 set_host_byte(scsi, DID_ERROR);
106 return;
107 }
108 }
109
110 if (unlikely(rsp_flags & FCP_SNS_LEN_VAL)) {
111 sense = (char *) &fcp_rsp[1];
112 if (rsp_flags & FCP_RSP_LEN_VAL)
113 sense += fcp_rsp->ext.fr_sns_len;
114 sense_len = min(fcp_rsp->ext.fr_sns_len,
115 (u32) SCSI_SENSE_BUFFERSIZE);
116 memcpy(scsi->sense_buffer, sense, sense_len);
117 }
118
119 if (unlikely(rsp_flags & FCP_RESID_UNDER)) {
120 resid = fcp_rsp->ext.fr_resid;
121 scsi_set_resid(scsi, resid);
122 if (scsi_bufflen(scsi) - resid < scsi->underflow &&
123 !(rsp_flags & FCP_SNS_LEN_VAL) &&
124 fcp_rsp->resp.fr_status == SAM_STAT_GOOD)
125 set_host_byte(scsi, DID_ERROR);
126 }
127}
128
129#endif