Commit | Line | Data |
---|---|---|
4318e08c CS |
1 | /* |
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 | ||
9d05ce2c | 13 | #include <scsi/fc/fc_els.h> |
4318e08c | 14 | #include <scsi/fc/fc_fcp.h> |
dbf5dfe9 | 15 | #include <scsi/fc/fc_ns.h> |
4318e08c CS |
16 | #include <scsi/scsi_cmnd.h> |
17 | #include <scsi/scsi_tcq.h> | |
7c7dc196 | 18 | #include "zfcp_fsf.h" |
4318e08c | 19 | |
dbf5dfe9 CS |
20 | #define ZFCP_FC_CT_SIZE_PAGE (PAGE_SIZE - sizeof(struct fc_ct_hdr)) |
21 | #define ZFCP_FC_GPN_FT_ENT_PAGE (ZFCP_FC_CT_SIZE_PAGE \ | |
22 | / sizeof(struct fc_gpn_ft_resp)) | |
23 | #define ZFCP_FC_GPN_FT_NUM_BUFS 4 /* memory pages */ | |
24 | ||
25 | #define ZFCP_FC_GPN_FT_MAX_SIZE (ZFCP_FC_GPN_FT_NUM_BUFS * PAGE_SIZE \ | |
26 | - sizeof(struct fc_ct_hdr)) | |
27 | #define ZFCP_FC_GPN_FT_MAX_ENT (ZFCP_FC_GPN_FT_NUM_BUFS * \ | |
28 | (ZFCP_FC_GPN_FT_ENT_PAGE + 1)) | |
29 | ||
51375ee8 SS |
30 | #define ZFCP_FC_CTELS_TMO (2 * FC_DEF_R_A_TOV / 1000) |
31 | ||
2d1e547f SS |
32 | /** |
33 | * struct zfcp_fc_event - FC HBAAPI event for internal queueing from irq context | |
34 | * @code: Event code | |
35 | * @data: Event data | |
36 | * @list: list_head for zfcp_fc_events list | |
37 | */ | |
38 | struct zfcp_fc_event { | |
39 | enum fc_host_event_code code; | |
40 | u32 data; | |
41 | struct list_head list; | |
42 | }; | |
43 | ||
44 | /** | |
45 | * struct zfcp_fc_events - Infrastructure for posting FC events from irq context | |
46 | * @list: List for queueing of events from irq context to workqueue | |
47 | * @list_lock: Lock for event list | |
48 | * @work: work_struct for forwarding events in workqueue | |
49 | */ | |
50 | struct zfcp_fc_events { | |
51 | struct list_head list; | |
52 | spinlock_t list_lock; | |
53 | struct work_struct work; | |
54 | }; | |
55 | ||
dbf5dfe9 CS |
56 | /** |
57 | * struct zfcp_fc_gid_pn_req - container for ct header plus gid_pn request | |
58 | * @ct_hdr: FC GS common transport header | |
59 | * @gid_pn: GID_PN request | |
60 | */ | |
61 | struct zfcp_fc_gid_pn_req { | |
62 | struct fc_ct_hdr ct_hdr; | |
63 | struct fc_ns_gid_pn gid_pn; | |
64 | } __packed; | |
65 | ||
66 | /** | |
67 | * struct zfcp_fc_gid_pn_resp - container for ct header plus gid_pn response | |
68 | * @ct_hdr: FC GS common transport header | |
69 | * @gid_pn: GID_PN response | |
70 | */ | |
71 | struct zfcp_fc_gid_pn_resp { | |
72 | struct fc_ct_hdr ct_hdr; | |
73 | struct fc_gid_pn_resp gid_pn; | |
74 | } __packed; | |
75 | ||
76 | /** | |
77 | * struct zfcp_fc_gid_pn - everything required in zfcp for gid_pn request | |
78 | * @ct: data passed to zfcp_fsf for issuing fsf request | |
79 | * @sg_req: scatterlist entry for request data | |
80 | * @sg_resp: scatterlist entry for response data | |
81 | * @gid_pn_req: GID_PN request data | |
82 | * @gid_pn_resp: GID_PN response data | |
83 | */ | |
84 | struct zfcp_fc_gid_pn { | |
7c7dc196 | 85 | struct zfcp_fsf_ct_els ct; |
dbf5dfe9 CS |
86 | struct scatterlist sg_req; |
87 | struct scatterlist sg_resp; | |
88 | struct zfcp_fc_gid_pn_req gid_pn_req; | |
89 | struct zfcp_fc_gid_pn_resp gid_pn_resp; | |
90 | struct zfcp_port *port; | |
91 | }; | |
92 | ||
93 | /** | |
94 | * struct zfcp_fc_gpn_ft - container for ct header plus gpn_ft request | |
95 | * @ct_hdr: FC GS common transport header | |
96 | * @gpn_ft: GPN_FT request | |
97 | */ | |
98 | struct zfcp_fc_gpn_ft_req { | |
99 | struct fc_ct_hdr ct_hdr; | |
100 | struct fc_ns_gid_ft gpn_ft; | |
101 | } __packed; | |
102 | ||
103 | /** | |
104 | * struct zfcp_fc_gpn_ft_resp - container for ct header plus gpn_ft response | |
105 | * @ct_hdr: FC GS common transport header | |
106 | * @gpn_ft: Array of gpn_ft response data to fill one memory page | |
107 | */ | |
108 | struct zfcp_fc_gpn_ft_resp { | |
109 | struct fc_ct_hdr ct_hdr; | |
110 | struct fc_gpn_ft_resp gpn_ft[ZFCP_FC_GPN_FT_ENT_PAGE]; | |
111 | } __packed; | |
112 | ||
113 | /** | |
114 | * struct zfcp_fc_gpn_ft - zfcp data for gpn_ft request | |
115 | * @ct: data passed to zfcp_fsf for issuing fsf request | |
116 | * @sg_req: scatter list entry for gpn_ft request | |
117 | * @sg_resp: scatter list entries for gpn_ft responses (per memory page) | |
118 | */ | |
119 | struct zfcp_fc_gpn_ft { | |
7c7dc196 | 120 | struct zfcp_fsf_ct_els ct; |
dbf5dfe9 CS |
121 | struct scatterlist sg_req; |
122 | struct scatterlist sg_resp[ZFCP_FC_GPN_FT_NUM_BUFS]; | |
123 | }; | |
124 | ||
9d05ce2c CS |
125 | /** |
126 | * struct zfcp_fc_els_adisc - everything required in zfcp for issuing ELS ADISC | |
127 | * @els: data required for issuing els fsf command | |
128 | * @req: scatterlist entry for ELS ADISC request | |
129 | * @resp: scatterlist entry for ELS ADISC response | |
130 | * @adisc_req: ELS ADISC request data | |
131 | * @adisc_resp: ELS ADISC response data | |
132 | */ | |
133 | struct zfcp_fc_els_adisc { | |
7c7dc196 | 134 | struct zfcp_fsf_ct_els els; |
9d05ce2c CS |
135 | struct scatterlist req; |
136 | struct scatterlist resp; | |
137 | struct fc_els_adisc adisc_req; | |
138 | struct fc_els_adisc adisc_resp; | |
139 | }; | |
140 | ||
bd0072ec CS |
141 | /** |
142 | * enum zfcp_fc_wka_status - FC WKA port status in zfcp | |
143 | * @ZFCP_FC_WKA_PORT_OFFLINE: Port is closed and not in use | |
144 | * @ZFCP_FC_WKA_PORT_CLOSING: The FSF "close port" request is pending | |
145 | * @ZFCP_FC_WKA_PORT_OPENING: The FSF "open port" request is pending | |
146 | * @ZFCP_FC_WKA_PORT_ONLINE: The port is open and the port handle is valid | |
147 | */ | |
148 | enum zfcp_fc_wka_status { | |
149 | ZFCP_FC_WKA_PORT_OFFLINE, | |
150 | ZFCP_FC_WKA_PORT_CLOSING, | |
151 | ZFCP_FC_WKA_PORT_OPENING, | |
152 | ZFCP_FC_WKA_PORT_ONLINE, | |
153 | }; | |
154 | ||
155 | /** | |
156 | * struct zfcp_fc_wka_port - representation of well-known-address (WKA) FC port | |
157 | * @adapter: Pointer to adapter structure this WKA port belongs to | |
158 | * @completion_wq: Wait for completion of open/close command | |
159 | * @status: Current status of WKA port | |
160 | * @refcount: Reference count to keep port open as long as it is in use | |
161 | * @d_id: FC destination id or well-known-address | |
162 | * @handle: FSF handle for the open WKA port | |
163 | * @mutex: Mutex used during opening/closing state changes | |
164 | * @work: For delaying the closing of the WKA port | |
165 | */ | |
166 | struct zfcp_fc_wka_port { | |
167 | struct zfcp_adapter *adapter; | |
168 | wait_queue_head_t completion_wq; | |
169 | enum zfcp_fc_wka_status status; | |
170 | atomic_t refcount; | |
171 | u32 d_id; | |
172 | u32 handle; | |
173 | struct mutex mutex; | |
174 | struct delayed_work work; | |
175 | }; | |
176 | ||
177 | /** | |
178 | * struct zfcp_fc_wka_ports - Data structures for FC generic services | |
179 | * @ms: FC Management service | |
180 | * @ts: FC time service | |
181 | * @ds: FC directory service | |
182 | * @as: FC alias service | |
183 | */ | |
184 | struct zfcp_fc_wka_ports { | |
185 | struct zfcp_fc_wka_port ms; | |
186 | struct zfcp_fc_wka_port ts; | |
187 | struct zfcp_fc_wka_port ds; | |
188 | struct zfcp_fc_wka_port as; | |
189 | }; | |
190 | ||
4318e08c CS |
191 | /** |
192 | * zfcp_fc_scsi_to_fcp - setup FCP command with data from scsi_cmnd | |
193 | * @fcp: fcp_cmnd to setup | |
194 | * @scsi: scsi_cmnd where to get LUN, task attributes/flags and CDB | |
195 | */ | |
196 | static inline | |
197 | void zfcp_fc_scsi_to_fcp(struct fcp_cmnd *fcp, struct scsi_cmnd *scsi) | |
198 | { | |
199 | char tag[2]; | |
200 | ||
201 | int_to_scsilun(scsi->device->lun, (struct scsi_lun *) &fcp->fc_lun); | |
202 | ||
203 | if (scsi_populate_tag_msg(scsi, tag)) { | |
204 | switch (tag[0]) { | |
205 | case MSG_ORDERED_TAG: | |
206 | fcp->fc_pri_ta |= FCP_PTA_ORDERED; | |
207 | break; | |
208 | case MSG_SIMPLE_TAG: | |
209 | fcp->fc_pri_ta |= FCP_PTA_SIMPLE; | |
210 | break; | |
211 | }; | |
212 | } else | |
213 | fcp->fc_pri_ta = FCP_PTA_SIMPLE; | |
214 | ||
215 | if (scsi->sc_data_direction == DMA_FROM_DEVICE) | |
216 | fcp->fc_flags |= FCP_CFL_RDDATA; | |
217 | if (scsi->sc_data_direction == DMA_TO_DEVICE) | |
218 | fcp->fc_flags |= FCP_CFL_WRDATA; | |
219 | ||
220 | memcpy(fcp->fc_cdb, scsi->cmnd, scsi->cmd_len); | |
221 | ||
222 | fcp->fc_dl = scsi_bufflen(scsi); | |
ef3eb71d FB |
223 | |
224 | if (scsi_get_prot_type(scsi) == SCSI_PROT_DIF_TYPE1) | |
225 | fcp->fc_dl += fcp->fc_dl / scsi->device->sector_size * 8; | |
4318e08c CS |
226 | } |
227 | ||
228 | /** | |
229 | * zfcp_fc_fcp_tm - setup FCP command as task management command | |
230 | * @fcp: fcp_cmnd to setup | |
231 | * @dev: scsi_device where to send the task management command | |
232 | * @tm: task management flags to setup tm command | |
233 | */ | |
234 | static inline | |
235 | void zfcp_fc_fcp_tm(struct fcp_cmnd *fcp, struct scsi_device *dev, u8 tm_flags) | |
236 | { | |
237 | int_to_scsilun(dev->lun, (struct scsi_lun *) &fcp->fc_lun); | |
238 | fcp->fc_tm_flags |= tm_flags; | |
239 | } | |
240 | ||
241 | /** | |
242 | * zfcp_fc_evap_fcp_rsp - evaluate FCP RSP IU and update scsi_cmnd accordingly | |
243 | * @fcp_rsp: FCP RSP IU to evaluate | |
244 | * @scsi: SCSI command where to update status and sense buffer | |
245 | */ | |
246 | static inline | |
247 | void zfcp_fc_eval_fcp_rsp(struct fcp_resp_with_ext *fcp_rsp, | |
248 | struct scsi_cmnd *scsi) | |
249 | { | |
250 | struct fcp_resp_rsp_info *rsp_info; | |
251 | char *sense; | |
252 | u32 sense_len, resid; | |
253 | u8 rsp_flags; | |
254 | ||
255 | set_msg_byte(scsi, COMMAND_COMPLETE); | |
256 | scsi->result |= fcp_rsp->resp.fr_status; | |
257 | ||
258 | rsp_flags = fcp_rsp->resp.fr_flags; | |
259 | ||
260 | if (unlikely(rsp_flags & FCP_RSP_LEN_VAL)) { | |
261 | rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1]; | |
262 | if (rsp_info->rsp_code == FCP_TMF_CMPL) | |
263 | set_host_byte(scsi, DID_OK); | |
264 | else { | |
265 | set_host_byte(scsi, DID_ERROR); | |
266 | return; | |
267 | } | |
268 | } | |
269 | ||
270 | if (unlikely(rsp_flags & FCP_SNS_LEN_VAL)) { | |
271 | sense = (char *) &fcp_rsp[1]; | |
272 | if (rsp_flags & FCP_RSP_LEN_VAL) | |
fb5a6389 | 273 | sense += fcp_rsp->ext.fr_rsp_len; |
4318e08c CS |
274 | sense_len = min(fcp_rsp->ext.fr_sns_len, |
275 | (u32) SCSI_SENSE_BUFFERSIZE); | |
276 | memcpy(scsi->sense_buffer, sense, sense_len); | |
277 | } | |
278 | ||
279 | if (unlikely(rsp_flags & FCP_RESID_UNDER)) { | |
280 | resid = fcp_rsp->ext.fr_resid; | |
281 | scsi_set_resid(scsi, resid); | |
282 | if (scsi_bufflen(scsi) - resid < scsi->underflow && | |
283 | !(rsp_flags & FCP_SNS_LEN_VAL) && | |
284 | fcp_rsp->resp.fr_status == SAM_STAT_GOOD) | |
285 | set_host_byte(scsi, DID_ERROR); | |
286 | } | |
287 | } | |
288 | ||
289 | #endif |