]>
Commit | Line | Data |
---|---|---|
d6d20012 JS |
1 | /* |
2 | * Copyright (c) 2016, Avago Technologies | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify it | |
5 | * under the terms and conditions of the GNU General Public License, | |
6 | * version 2, as published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope it will be useful, but WITHOUT | |
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
11 | * more details. | |
12 | */ | |
13 | ||
14 | #ifndef _NVME_FC_DRIVER_H | |
15 | #define _NVME_FC_DRIVER_H 1 | |
16 | ||
17 | ||
18 | /* | |
19 | * ********************** LLDD FC-NVME Host API ******************** | |
20 | * | |
21 | * For FC LLDD's that are the NVME Host role. | |
22 | * | |
23 | * ****************************************************************** | |
24 | */ | |
25 | ||
26 | ||
27 | ||
28 | /* FC Port role bitmask - can merge with FC Port Roles in fc transport */ | |
29 | #define FC_PORT_ROLE_NVME_INITIATOR 0x10 | |
41231090 JS |
30 | #define FC_PORT_ROLE_NVME_TARGET 0x20 |
31 | #define FC_PORT_ROLE_NVME_DISCOVERY 0x40 | |
d6d20012 JS |
32 | |
33 | ||
34 | /** | |
35 | * struct nvme_fc_port_info - port-specific ids and FC connection-specific | |
36 | * data element used during NVME Host role | |
37 | * registrations | |
38 | * | |
39 | * Static fields describing the port being registered: | |
40 | * @node_name: FC WWNN for the port | |
41 | * @port_name: FC WWPN for the port | |
42 | * @port_role: What NVME roles are supported (see FC_PORT_ROLE_xxx) | |
ac7fe82b JS |
43 | * @dev_loss_tmo: maximum delay for reconnects to an association on |
44 | * this device. Used only on a remoteport. | |
d6d20012 JS |
45 | * |
46 | * Initialization values for dynamic port fields: | |
47 | * @port_id: FC N_Port_ID currently assigned the port. Upper 8 bits must | |
48 | * be set to 0. | |
49 | */ | |
50 | struct nvme_fc_port_info { | |
51 | u64 node_name; | |
52 | u64 port_name; | |
53 | u32 port_role; | |
54 | u32 port_id; | |
ac7fe82b | 55 | u32 dev_loss_tmo; |
d6d20012 JS |
56 | }; |
57 | ||
58 | ||
59 | /** | |
60 | * struct nvmefc_ls_req - Request structure passed from NVME-FC transport | |
61 | * to LLDD in order to perform a NVME FC-4 LS | |
62 | * request and obtain a response. | |
63 | * | |
64 | * Values set by the NVME-FC layer prior to calling the LLDD ls_req | |
65 | * entrypoint. | |
66 | * @rqstaddr: pointer to request buffer | |
67 | * @rqstdma: PCI DMA address of request buffer | |
68 | * @rqstlen: Length, in bytes, of request buffer | |
69 | * @rspaddr: pointer to response buffer | |
70 | * @rspdma: PCI DMA address of response buffer | |
71 | * @rsplen: Length, in bytes, of response buffer | |
72 | * @timeout: Maximum amount of time, in seconds, to wait for the LS response. | |
73 | * If timeout exceeded, LLDD to abort LS exchange and complete | |
74 | * LS request with error status. | |
75 | * @private: pointer to memory allocated alongside the ls request structure | |
76 | * that is specifically for the LLDD to use while processing the | |
77 | * request. The length of the buffer corresponds to the | |
78 | * lsrqst_priv_sz value specified in the nvme_fc_port_template | |
79 | * supplied by the LLDD. | |
80 | * @done: The callback routine the LLDD is to invoke upon completion of | |
81 | * the LS request. req argument is the pointer to the original LS | |
82 | * request structure. Status argument must be 0 upon success, a | |
83 | * negative errno on failure (example: -ENXIO). | |
84 | */ | |
85 | struct nvmefc_ls_req { | |
86 | void *rqstaddr; | |
87 | dma_addr_t rqstdma; | |
88 | u32 rqstlen; | |
89 | void *rspaddr; | |
90 | dma_addr_t rspdma; | |
91 | u32 rsplen; | |
92 | u32 timeout; | |
93 | ||
94 | void *private; | |
95 | ||
96 | void (*done)(struct nvmefc_ls_req *req, int status); | |
97 | ||
98 | } __aligned(sizeof(u64)); /* alignment for other things alloc'd with */ | |
99 | ||
100 | ||
101 | enum nvmefc_fcp_datadir { | |
102 | NVMEFC_FCP_NODATA, /* payload_length and sg_cnt will be zero */ | |
103 | NVMEFC_FCP_WRITE, | |
104 | NVMEFC_FCP_READ, | |
105 | }; | |
106 | ||
107 | ||
d6d20012 JS |
108 | /** |
109 | * struct nvmefc_fcp_req - Request structure passed from NVME-FC transport | |
110 | * to LLDD in order to perform a NVME FCP IO operation. | |
111 | * | |
112 | * Values set by the NVME-FC layer prior to calling the LLDD fcp_io | |
113 | * entrypoint. | |
114 | * @cmdaddr: pointer to the FCP CMD IU buffer | |
115 | * @rspaddr: pointer to the FCP RSP IU buffer | |
116 | * @cmddma: PCI DMA address of the FCP CMD IU buffer | |
117 | * @rspdma: PCI DMA address of the FCP RSP IU buffer | |
118 | * @cmdlen: Length, in bytes, of the FCP CMD IU buffer | |
119 | * @rsplen: Length, in bytes, of the FCP RSP IU buffer | |
120 | * @payload_length: Length of DATA_IN or DATA_OUT payload data to transfer | |
121 | * @sg_table: scatter/gather structure for payload data | |
122 | * @first_sgl: memory for 1st scatter/gather list segment for payload data | |
123 | * @sg_cnt: number of elements in the scatter/gather list | |
124 | * @io_dir: direction of the FCP request (see NVMEFC_FCP_xxx) | |
125 | * @sqid: The nvme SQID the command is being issued on | |
126 | * @done: The callback routine the LLDD is to invoke upon completion of | |
127 | * the FCP operation. req argument is the pointer to the original | |
128 | * FCP IO operation. | |
129 | * @private: pointer to memory allocated alongside the FCP operation | |
130 | * request structure that is specifically for the LLDD to use | |
131 | * while processing the operation. The length of the buffer | |
132 | * corresponds to the fcprqst_priv_sz value specified in the | |
133 | * nvme_fc_port_template supplied by the LLDD. | |
134 | * | |
135 | * Values set by the LLDD indicating completion status of the FCP operation. | |
136 | * Must be set prior to calling the done() callback. | |
137 | * @transferred_length: amount of payload data, in bytes, that were | |
138 | * transferred. Should equal payload_length on success. | |
139 | * @rcv_rsplen: length, in bytes, of the FCP RSP IU received. | |
140 | * @status: Completion status of the FCP operation. must be 0 upon success, | |
62eeacb0 JS |
141 | * negative errno value upon failure (ex: -EIO). Note: this is |
142 | * NOT a reflection of the NVME CQE completion status. Only the | |
143 | * status of the FCP operation at the NVME-FC level. | |
d6d20012 JS |
144 | */ |
145 | struct nvmefc_fcp_req { | |
146 | void *cmdaddr; | |
147 | void *rspaddr; | |
148 | dma_addr_t cmddma; | |
149 | dma_addr_t rspdma; | |
150 | u16 cmdlen; | |
151 | u16 rsplen; | |
152 | ||
153 | u32 payload_length; | |
154 | struct sg_table sg_table; | |
155 | struct scatterlist *first_sgl; | |
156 | int sg_cnt; | |
157 | enum nvmefc_fcp_datadir io_dir; | |
158 | ||
159 | __le16 sqid; | |
160 | ||
161 | void (*done)(struct nvmefc_fcp_req *req); | |
162 | ||
163 | void *private; | |
164 | ||
165 | u32 transferred_length; | |
166 | u16 rcv_rsplen; | |
167 | u32 status; | |
168 | } __aligned(sizeof(u64)); /* alignment for other things alloc'd with */ | |
169 | ||
170 | ||
171 | /* | |
172 | * Direct copy of fc_port_state enum. For later merging | |
173 | */ | |
174 | enum nvme_fc_obj_state { | |
175 | FC_OBJSTATE_UNKNOWN, | |
176 | FC_OBJSTATE_NOTPRESENT, | |
177 | FC_OBJSTATE_ONLINE, | |
178 | FC_OBJSTATE_OFFLINE, /* User has taken Port Offline */ | |
179 | FC_OBJSTATE_BLOCKED, | |
180 | FC_OBJSTATE_BYPASSED, | |
181 | FC_OBJSTATE_DIAGNOSTICS, | |
182 | FC_OBJSTATE_LINKDOWN, | |
183 | FC_OBJSTATE_ERROR, | |
184 | FC_OBJSTATE_LOOPBACK, | |
185 | FC_OBJSTATE_DELETED, | |
186 | }; | |
187 | ||
188 | ||
189 | /** | |
190 | * struct nvme_fc_local_port - structure used between NVME-FC transport and | |
191 | * a LLDD to reference a local NVME host port. | |
192 | * Allocated/created by the nvme_fc_register_localport() | |
193 | * transport interface. | |
194 | * | |
195 | * Fields with static values for the port. Initialized by the | |
196 | * port_info struct supplied to the registration call. | |
197 | * @port_num: NVME-FC transport host port number | |
198 | * @port_role: NVME roles are supported on the port (see FC_PORT_ROLE_xxx) | |
199 | * @node_name: FC WWNN for the port | |
200 | * @port_name: FC WWPN for the port | |
201 | * @private: pointer to memory allocated alongside the local port | |
202 | * structure that is specifically for the LLDD to use. | |
203 | * The length of the buffer corresponds to the local_priv_sz | |
204 | * value specified in the nvme_fc_port_template supplied by | |
205 | * the LLDD. | |
ac7fe82b JS |
206 | * @dev_loss_tmo: maximum delay for reconnects to an association on |
207 | * this device. To modify, lldd must call | |
208 | * nvme_fc_set_remoteport_devloss(). | |
d6d20012 JS |
209 | * |
210 | * Fields with dynamic values. Values may change base on link state. LLDD | |
211 | * may reference fields directly to change them. Initialized by the | |
212 | * port_info struct supplied to the registration call. | |
213 | * @port_id: FC N_Port_ID currently assigned the port. Upper 8 bits must | |
214 | * be set to 0. | |
215 | * @port_state: Operational state of the port. | |
216 | */ | |
217 | struct nvme_fc_local_port { | |
218 | /* static/read-only fields */ | |
219 | u32 port_num; | |
220 | u32 port_role; | |
221 | u64 node_name; | |
222 | u64 port_name; | |
223 | ||
224 | void *private; | |
225 | ||
226 | /* dynamic fields */ | |
227 | u32 port_id; | |
228 | enum nvme_fc_obj_state port_state; | |
229 | } __aligned(sizeof(u64)); /* alignment for other things alloc'd with */ | |
230 | ||
231 | ||
232 | /** | |
233 | * struct nvme_fc_remote_port - structure used between NVME-FC transport and | |
234 | * a LLDD to reference a remote NVME subsystem port. | |
235 | * Allocated/created by the nvme_fc_register_remoteport() | |
236 | * transport interface. | |
237 | * | |
238 | * Fields with static values for the port. Initialized by the | |
239 | * port_info struct supplied to the registration call. | |
240 | * @port_num: NVME-FC transport remote subsystem port number | |
241 | * @port_role: NVME roles are supported on the port (see FC_PORT_ROLE_xxx) | |
242 | * @node_name: FC WWNN for the port | |
243 | * @port_name: FC WWPN for the port | |
244 | * @localport: pointer to the NVME-FC local host port the subsystem is | |
245 | * connected to. | |
246 | * @private: pointer to memory allocated alongside the remote port | |
247 | * structure that is specifically for the LLDD to use. | |
248 | * The length of the buffer corresponds to the remote_priv_sz | |
249 | * value specified in the nvme_fc_port_template supplied by | |
250 | * the LLDD. | |
251 | * | |
252 | * Fields with dynamic values. Values may change base on link or login | |
253 | * state. LLDD may reference fields directly to change them. Initialized by | |
254 | * the port_info struct supplied to the registration call. | |
255 | * @port_id: FC N_Port_ID currently assigned the port. Upper 8 bits must | |
256 | * be set to 0. | |
257 | * @port_state: Operational state of the remote port. Valid values are | |
258 | * ONLINE or UNKNOWN. | |
259 | */ | |
260 | struct nvme_fc_remote_port { | |
261 | /* static fields */ | |
262 | u32 port_num; | |
263 | u32 port_role; | |
264 | u64 node_name; | |
265 | u64 port_name; | |
d6d20012 | 266 | struct nvme_fc_local_port *localport; |
d6d20012 | 267 | void *private; |
ac7fe82b | 268 | u32 dev_loss_tmo; |
d6d20012 JS |
269 | |
270 | /* dynamic fields */ | |
271 | u32 port_id; | |
272 | enum nvme_fc_obj_state port_state; | |
273 | } __aligned(sizeof(u64)); /* alignment for other things alloc'd with */ | |
274 | ||
275 | ||
276 | /** | |
277 | * struct nvme_fc_port_template - structure containing static entrypoints and | |
278 | * operational parameters for an LLDD that supports NVME host | |
279 | * behavior. Passed by reference in port registrations. | |
280 | * NVME-FC transport remembers template reference and may | |
281 | * access it during runtime operation. | |
282 | * | |
283 | * Host/Initiator Transport Entrypoints/Parameters: | |
284 | * | |
8c30c08b JS |
285 | * @module: The LLDD module using the interface |
286 | * | |
d6d20012 JS |
287 | * @localport_delete: The LLDD initiates deletion of a localport via |
288 | * nvme_fc_deregister_localport(). However, the teardown is | |
289 | * asynchronous. This routine is called upon the completion of the | |
290 | * teardown to inform the LLDD that the localport has been deleted. | |
291 | * Entrypoint is Mandatory. | |
292 | * | |
293 | * @remoteport_delete: The LLDD initiates deletion of a remoteport via | |
294 | * nvme_fc_deregister_remoteport(). However, the teardown is | |
295 | * asynchronous. This routine is called upon the completion of the | |
296 | * teardown to inform the LLDD that the remoteport has been deleted. | |
297 | * Entrypoint is Mandatory. | |
298 | * | |
299 | * @create_queue: Upon creating a host<->controller association, queues are | |
300 | * created such that they can be affinitized to cpus/cores. This | |
301 | * callback into the LLDD to notify that a controller queue is being | |
302 | * created. The LLDD may choose to allocate an associated hw queue | |
303 | * or map it onto a shared hw queue. Upon return from the call, the | |
304 | * LLDD specifies a handle that will be given back to it for any | |
305 | * command that is posted to the controller queue. The handle can | |
306 | * be used by the LLDD to map quickly to the proper hw queue for | |
307 | * command execution. The mask of cpu's that will map to this queue | |
308 | * at the block-level is also passed in. The LLDD should use the | |
309 | * queue id and/or cpu masks to ensure proper affinitization of the | |
310 | * controller queue to the hw queue. | |
311 | * Entrypoint is Optional. | |
312 | * | |
313 | * @delete_queue: This is the inverse of the crete_queue. During | |
314 | * host<->controller association teardown, this routine is called | |
315 | * when a controller queue is being terminated. Any association with | |
316 | * a hw queue should be termined. If there is a unique hw queue, the | |
317 | * hw queue should be torn down. | |
318 | * Entrypoint is Optional. | |
319 | * | |
320 | * @poll_queue: Called to poll for the completion of an io on a blk queue. | |
321 | * Entrypoint is Optional. | |
322 | * | |
323 | * @ls_req: Called to issue a FC-NVME FC-4 LS service request. | |
324 | * The nvme_fc_ls_req structure will fully describe the buffers for | |
325 | * the request payload and where to place the response payload. The | |
326 | * LLDD is to allocate an exchange, issue the LS request, obtain the | |
327 | * LS response, and call the "done" routine specified in the request | |
328 | * structure (argument to done is the ls request structure itself). | |
329 | * Entrypoint is Mandatory. | |
330 | * | |
331 | * @fcp_io: called to issue a FC-NVME I/O request. The I/O may be for | |
332 | * an admin queue or an i/o queue. The nvmefc_fcp_req structure will | |
333 | * fully describe the io: the buffer containing the FC-NVME CMD IU | |
334 | * (which contains the SQE), the sg list for the payload if applicable, | |
335 | * and the buffer to place the FC-NVME RSP IU into. The LLDD will | |
336 | * complete the i/o, indicating the amount of data transferred or | |
337 | * any transport error, and call the "done" routine specified in the | |
338 | * request structure (argument to done is the fcp request structure | |
339 | * itself). | |
340 | * Entrypoint is Mandatory. | |
341 | * | |
342 | * @ls_abort: called to request the LLDD to abort the indicated ls request. | |
343 | * The call may return before the abort has completed. After aborting | |
344 | * the request, the LLDD must still call the ls request done routine | |
345 | * indicating an FC transport Aborted status. | |
346 | * Entrypoint is Mandatory. | |
347 | * | |
348 | * @fcp_abort: called to request the LLDD to abort the indicated fcp request. | |
349 | * The call may return before the abort has completed. After aborting | |
350 | * the request, the LLDD must still call the fcp request done routine | |
351 | * indicating an FC transport Aborted status. | |
352 | * Entrypoint is Mandatory. | |
353 | * | |
354 | * @max_hw_queues: indicates the maximum number of hw queues the LLDD | |
355 | * supports for cpu affinitization. | |
356 | * Value is Mandatory. Must be at least 1. | |
357 | * | |
358 | * @max_sgl_segments: indicates the maximum number of sgl segments supported | |
359 | * by the LLDD | |
360 | * Value is Mandatory. Must be at least 1. Recommend at least 256. | |
361 | * | |
362 | * @max_dif_sgl_segments: indicates the maximum number of sgl segments | |
363 | * supported by the LLDD for DIF operations. | |
364 | * Value is Mandatory. Must be at least 1. Recommend at least 256. | |
365 | * | |
366 | * @dma_boundary: indicates the dma address boundary where dma mappings | |
367 | * will be split across. | |
368 | * Value is Mandatory. Typical value is 0xFFFFFFFF to split across | |
369 | * 4Gig address boundarys | |
370 | * | |
371 | * @local_priv_sz: The LLDD sets this field to the amount of additional | |
372 | * memory that it would like fc nvme layer to allocate on the LLDD's | |
373 | * behalf whenever a localport is allocated. The additional memory | |
374 | * area solely for the of the LLDD and its location is specified by | |
375 | * the localport->private pointer. | |
376 | * Value is Mandatory. Allowed to be zero. | |
377 | * | |
378 | * @remote_priv_sz: The LLDD sets this field to the amount of additional | |
379 | * memory that it would like fc nvme layer to allocate on the LLDD's | |
380 | * behalf whenever a remoteport is allocated. The additional memory | |
381 | * area solely for the of the LLDD and its location is specified by | |
382 | * the remoteport->private pointer. | |
383 | * Value is Mandatory. Allowed to be zero. | |
384 | * | |
385 | * @lsrqst_priv_sz: The LLDD sets this field to the amount of additional | |
386 | * memory that it would like fc nvme layer to allocate on the LLDD's | |
387 | * behalf whenever a ls request structure is allocated. The additional | |
388 | * memory area solely for the of the LLDD and its location is | |
389 | * specified by the ls_request->private pointer. | |
390 | * Value is Mandatory. Allowed to be zero. | |
391 | * | |
392 | * @fcprqst_priv_sz: The LLDD sets this field to the amount of additional | |
393 | * memory that it would like fc nvme layer to allocate on the LLDD's | |
394 | * behalf whenever a fcp request structure is allocated. The additional | |
395 | * memory area solely for the of the LLDD and its location is | |
396 | * specified by the fcp_request->private pointer. | |
397 | * Value is Mandatory. Allowed to be zero. | |
398 | */ | |
399 | struct nvme_fc_port_template { | |
8c30c08b JS |
400 | struct module *module; |
401 | ||
d6d20012 JS |
402 | /* initiator-based functions */ |
403 | void (*localport_delete)(struct nvme_fc_local_port *); | |
404 | void (*remoteport_delete)(struct nvme_fc_remote_port *); | |
405 | int (*create_queue)(struct nvme_fc_local_port *, | |
406 | unsigned int qidx, u16 qsize, | |
407 | void **handle); | |
408 | void (*delete_queue)(struct nvme_fc_local_port *, | |
409 | unsigned int qidx, void *handle); | |
410 | void (*poll_queue)(struct nvme_fc_local_port *, void *handle); | |
411 | int (*ls_req)(struct nvme_fc_local_port *, | |
412 | struct nvme_fc_remote_port *, | |
413 | struct nvmefc_ls_req *); | |
414 | int (*fcp_io)(struct nvme_fc_local_port *, | |
415 | struct nvme_fc_remote_port *, | |
416 | void *hw_queue_handle, | |
417 | struct nvmefc_fcp_req *); | |
418 | void (*ls_abort)(struct nvme_fc_local_port *, | |
419 | struct nvme_fc_remote_port *, | |
420 | struct nvmefc_ls_req *); | |
421 | void (*fcp_abort)(struct nvme_fc_local_port *, | |
422 | struct nvme_fc_remote_port *, | |
423 | void *hw_queue_handle, | |
424 | struct nvmefc_fcp_req *); | |
425 | ||
426 | u32 max_hw_queues; | |
427 | u16 max_sgl_segments; | |
428 | u16 max_dif_sgl_segments; | |
429 | u64 dma_boundary; | |
430 | ||
431 | /* sizes of additional private data for data structures */ | |
432 | u32 local_priv_sz; | |
433 | u32 remote_priv_sz; | |
434 | u32 lsrqst_priv_sz; | |
435 | u32 fcprqst_priv_sz; | |
436 | }; | |
437 | ||
438 | ||
439 | /* | |
440 | * Initiator/Host functions | |
441 | */ | |
442 | ||
443 | int nvme_fc_register_localport(struct nvme_fc_port_info *pinfo, | |
444 | struct nvme_fc_port_template *template, | |
445 | struct device *dev, | |
446 | struct nvme_fc_local_port **lport_p); | |
447 | ||
448 | int nvme_fc_unregister_localport(struct nvme_fc_local_port *localport); | |
449 | ||
450 | int nvme_fc_register_remoteport(struct nvme_fc_local_port *localport, | |
451 | struct nvme_fc_port_info *pinfo, | |
452 | struct nvme_fc_remote_port **rport_p); | |
453 | ||
454 | int nvme_fc_unregister_remoteport(struct nvme_fc_remote_port *remoteport); | |
455 | ||
eaefd5ab JS |
456 | void nvme_fc_rescan_remoteport(struct nvme_fc_remote_port *remoteport); |
457 | ||
ac7fe82b JS |
458 | int nvme_fc_set_remoteport_devloss(struct nvme_fc_remote_port *remoteport, |
459 | u32 dev_loss_tmo); | |
d6d20012 JS |
460 | |
461 | ||
462 | /* | |
463 | * *************** LLDD FC-NVME Target/Subsystem API *************** | |
464 | * | |
465 | * For FC LLDD's that are the NVME Subsystem role | |
466 | * | |
467 | * ****************************************************************** | |
468 | */ | |
469 | ||
470 | /** | |
471 | * struct nvmet_fc_port_info - port-specific ids and FC connection-specific | |
472 | * data element used during NVME Subsystem role | |
473 | * registrations | |
474 | * | |
475 | * Static fields describing the port being registered: | |
476 | * @node_name: FC WWNN for the port | |
477 | * @port_name: FC WWPN for the port | |
478 | * | |
479 | * Initialization values for dynamic port fields: | |
480 | * @port_id: FC N_Port_ID currently assigned the port. Upper 8 bits must | |
481 | * be set to 0. | |
482 | */ | |
483 | struct nvmet_fc_port_info { | |
484 | u64 node_name; | |
485 | u64 port_name; | |
486 | u32 port_id; | |
487 | }; | |
488 | ||
489 | ||
490 | /** | |
491 | * struct nvmefc_tgt_ls_req - Structure used between LLDD and NVMET-FC | |
492 | * layer to represent the exchange context for | |
493 | * a FC-NVME Link Service (LS). | |
494 | * | |
495 | * The structure is allocated by the LLDD whenever a LS Request is received | |
496 | * from the FC link. The address of the structure is passed to the nvmet-fc | |
497 | * layer via the nvmet_fc_rcv_ls_req() call. The address of the structure | |
498 | * will be passed back to the LLDD when the response is to be transmit. | |
499 | * The LLDD is to use the address to map back to the LLDD exchange structure | |
500 | * which maintains information such as the targetport the LS was received | |
501 | * on, the remote FC NVME initiator that sent the LS, and any FC exchange | |
502 | * context. Upon completion of the LS response transmit, the address of the | |
503 | * structure will be passed back to the LS rsp done() routine, allowing the | |
504 | * nvmet-fc layer to release dma resources. Upon completion of the done() | |
505 | * routine, no further access will be made by the nvmet-fc layer and the | |
506 | * LLDD can de-allocate the structure. | |
507 | * | |
508 | * Field initialization: | |
509 | * At the time of the nvmet_fc_rcv_ls_req() call, there is no content that | |
510 | * is valid in the structure. | |
511 | * | |
512 | * When the structure is used for the LLDD->xmt_ls_rsp() call, the nvmet-fc | |
513 | * layer will fully set the fields in order to specify the response | |
514 | * payload buffer and its length as well as the done routine to be called | |
515 | * upon compeletion of the transmit. The nvmet-fc layer will also set a | |
516 | * private pointer for its own use in the done routine. | |
517 | * | |
518 | * Values set by the NVMET-FC layer prior to calling the LLDD xmt_ls_rsp | |
519 | * entrypoint. | |
520 | * @rspbuf: pointer to the LS response buffer | |
521 | * @rspdma: PCI DMA address of the LS response buffer | |
522 | * @rsplen: Length, in bytes, of the LS response buffer | |
523 | * @done: The callback routine the LLDD is to invoke upon completion of | |
524 | * transmitting the LS response. req argument is the pointer to | |
525 | * the original ls request. | |
526 | * @nvmet_fc_private: pointer to an internal NVMET-FC layer structure used | |
527 | * as part of the NVMET-FC processing. The LLDD is not to access | |
528 | * this pointer. | |
529 | */ | |
530 | struct nvmefc_tgt_ls_req { | |
531 | void *rspbuf; | |
532 | dma_addr_t rspdma; | |
533 | u16 rsplen; | |
534 | ||
535 | void (*done)(struct nvmefc_tgt_ls_req *req); | |
536 | void *nvmet_fc_private; /* LLDD is not to access !! */ | |
537 | }; | |
538 | ||
539 | /* Operations that NVME-FC layer may request the LLDD to perform for FCP */ | |
540 | enum { | |
541 | NVMET_FCOP_READDATA = 1, /* xmt data to initiator */ | |
542 | NVMET_FCOP_WRITEDATA = 2, /* xmt data from initiator */ | |
543 | NVMET_FCOP_READDATA_RSP = 3, /* xmt data to initiator and send | |
544 | * rsp as well | |
545 | */ | |
546 | NVMET_FCOP_RSP = 4, /* send rsp frame */ | |
d6d20012 JS |
547 | }; |
548 | ||
549 | /** | |
550 | * struct nvmefc_tgt_fcp_req - Structure used between LLDD and NVMET-FC | |
551 | * layer to represent the exchange context and | |
552 | * the specific FC-NVME IU operation(s) to perform | |
553 | * for a FC-NVME FCP IO. | |
554 | * | |
555 | * Structure used between LLDD and nvmet-fc layer to represent the exchange | |
556 | * context for a FC-NVME FCP I/O operation (e.g. a nvme sqe, the sqe-related | |
557 | * memory transfers, and its assocated cqe transfer). | |
558 | * | |
559 | * The structure is allocated by the LLDD whenever a FCP CMD IU is received | |
560 | * from the FC link. The address of the structure is passed to the nvmet-fc | |
561 | * layer via the nvmet_fc_rcv_fcp_req() call. The address of the structure | |
562 | * will be passed back to the LLDD for the data operations and transmit of | |
563 | * the response. The LLDD is to use the address to map back to the LLDD | |
564 | * exchange structure which maintains information such as the targetport | |
565 | * the FCP I/O was received on, the remote FC NVME initiator that sent the | |
566 | * FCP I/O, and any FC exchange context. Upon completion of the FCP target | |
567 | * operation, the address of the structure will be passed back to the FCP | |
568 | * op done() routine, allowing the nvmet-fc layer to release dma resources. | |
569 | * Upon completion of the done() routine for either RSP or ABORT ops, no | |
570 | * further access will be made by the nvmet-fc layer and the LLDD can | |
571 | * de-allocate the structure. | |
572 | * | |
573 | * Field initialization: | |
574 | * At the time of the nvmet_fc_rcv_fcp_req() call, there is no content that | |
575 | * is valid in the structure. | |
576 | * | |
577 | * When the structure is used for an FCP target operation, the nvmet-fc | |
578 | * layer will fully set the fields in order to specify the scattergather | |
579 | * list, the transfer length, as well as the done routine to be called | |
580 | * upon compeletion of the operation. The nvmet-fc layer will also set a | |
581 | * private pointer for its own use in the done routine. | |
582 | * | |
d6d20012 JS |
583 | * Values set by the NVMET-FC layer prior to calling the LLDD fcp_op |
584 | * entrypoint. | |
585 | * @op: Indicates the FCP IU operation to perform (see NVMET_FCOP_xxx) | |
586 | * @hwqid: Specifies the hw queue index (0..N-1, where N is the | |
587 | * max_hw_queues value from the LLD's nvmet_fc_target_template) | |
588 | * that the operation is to use. | |
589 | * @offset: Indicates the DATA_OUT/DATA_IN payload offset to be tranferred. | |
590 | * Field is only valid on WRITEDATA, READDATA, or READDATA_RSP ops. | |
591 | * @timeout: amount of time, in seconds, to wait for a response from the NVME | |
592 | * host. A value of 0 is an infinite wait. | |
593 | * Valid only for the following ops: | |
594 | * WRITEDATA: caps the wait for data reception | |
595 | * READDATA_RSP & RSP: caps wait for FCP_CONF reception (if used) | |
596 | * @transfer_length: the length, in bytes, of the DATA_OUT or DATA_IN payload | |
597 | * that is to be transferred. | |
598 | * Valid only for the WRITEDATA, READDATA, or READDATA_RSP ops. | |
599 | * @ba_rjt: Contains the BA_RJT payload that is to be transferred. | |
600 | * Valid only for the NVMET_FCOP_BA_RJT op. | |
601 | * @sg: Scatter/gather list for the DATA_OUT/DATA_IN payload data. | |
602 | * Valid only for the WRITEDATA, READDATA, or READDATA_RSP ops. | |
603 | * @sg_cnt: Number of valid entries in the scatter/gather list. | |
604 | * Valid only for the WRITEDATA, READDATA, or READDATA_RSP ops. | |
605 | * @rspaddr: pointer to the FCP RSP IU buffer to be transmit | |
606 | * Used by RSP and READDATA_RSP ops | |
607 | * @rspdma: PCI DMA address of the FCP RSP IU buffer | |
608 | * Used by RSP and READDATA_RSP ops | |
609 | * @rsplen: Length, in bytes, of the FCP RSP IU buffer | |
610 | * Used by RSP and READDATA_RSP ops | |
611 | * @done: The callback routine the LLDD is to invoke upon completion of | |
612 | * the operation. req argument is the pointer to the original | |
613 | * FCP subsystem op request. | |
614 | * @nvmet_fc_private: pointer to an internal NVMET-FC layer structure used | |
615 | * as part of the NVMET-FC processing. The LLDD is not to | |
616 | * reference this field. | |
617 | * | |
618 | * Values set by the LLDD indicating completion status of the FCP operation. | |
619 | * Must be set prior to calling the done() callback. | |
620 | * @transferred_length: amount of DATA_OUT payload data received by a | |
621 | * a WRITEDATA operation. If not a WRITEDATA operation, value must | |
622 | * be set to 0. Should equal transfer_length on success. | |
623 | * @fcp_error: status of the FCP operation. Must be 0 on success; on failure | |
624 | * must be a NVME_SC_FC_xxxx value. | |
625 | */ | |
626 | struct nvmefc_tgt_fcp_req { | |
627 | u8 op; | |
628 | u16 hwqid; | |
629 | u32 offset; | |
630 | u32 timeout; | |
631 | u32 transfer_length; | |
632 | struct fc_ba_rjt ba_rjt; | |
48fa362b | 633 | struct scatterlist *sg; |
d6d20012 JS |
634 | int sg_cnt; |
635 | void *rspaddr; | |
636 | dma_addr_t rspdma; | |
637 | u16 rsplen; | |
638 | ||
639 | void (*done)(struct nvmefc_tgt_fcp_req *); | |
640 | ||
641 | void *nvmet_fc_private; /* LLDD is not to access !! */ | |
642 | ||
643 | u32 transferred_length; | |
644 | int fcp_error; | |
645 | }; | |
646 | ||
647 | ||
648 | /* Target Features (Bit fields) LLDD supports */ | |
649 | enum { | |
650 | NVMET_FCTGTFEAT_READDATA_RSP = (1 << 0), | |
651 | /* Bit 0: supports the NVMET_FCPOP_READDATA_RSP op, which | |
652 | * sends (the last) Read Data sequence followed by the RSP | |
653 | * sequence in one LLDD operation. Errors during Data | |
654 | * sequence transmit must not allow RSP sequence to be sent. | |
655 | */ | |
4b8ba5fa | 656 | NVMET_FCTGTFEAT_CMD_IN_ISR = (1 << 1), |
39498fae JS |
657 | /* Bit 2: When 0, the LLDD is calling the cmd rcv handler |
658 | * in a non-isr context, allowing the transport to finish | |
659 | * op completion in the calling context. When 1, the LLDD | |
660 | * is calling the cmd rcv handler in an ISR context, | |
661 | * requiring the transport to transition to a workqueue | |
662 | * for op completion. | |
663 | */ | |
4b8ba5fa | 664 | NVMET_FCTGTFEAT_OPDONE_IN_ISR = (1 << 2), |
39498fae JS |
665 | /* Bit 3: When 0, the LLDD is calling the op done handler |
666 | * in a non-isr context, allowing the transport to finish | |
667 | * op completion in the calling context. When 1, the LLDD | |
668 | * is calling the op done handler in an ISR context, | |
669 | * requiring the transport to transition to a workqueue | |
670 | * for op completion. | |
671 | */ | |
d6d20012 JS |
672 | }; |
673 | ||
674 | ||
675 | /** | |
676 | * struct nvmet_fc_target_port - structure used between NVME-FC transport and | |
677 | * a LLDD to reference a local NVME subsystem port. | |
678 | * Allocated/created by the nvme_fc_register_targetport() | |
679 | * transport interface. | |
680 | * | |
681 | * Fields with static values for the port. Initialized by the | |
682 | * port_info struct supplied to the registration call. | |
683 | * @port_num: NVME-FC transport subsytem port number | |
684 | * @node_name: FC WWNN for the port | |
685 | * @port_name: FC WWPN for the port | |
686 | * @private: pointer to memory allocated alongside the local port | |
687 | * structure that is specifically for the LLDD to use. | |
688 | * The length of the buffer corresponds to the target_priv_sz | |
689 | * value specified in the nvme_fc_target_template supplied by | |
690 | * the LLDD. | |
691 | * | |
692 | * Fields with dynamic values. Values may change base on link state. LLDD | |
693 | * may reference fields directly to change them. Initialized by the | |
694 | * port_info struct supplied to the registration call. | |
695 | * @port_id: FC N_Port_ID currently assigned the port. Upper 8 bits must | |
696 | * be set to 0. | |
697 | * @port_state: Operational state of the port. | |
698 | */ | |
699 | struct nvmet_fc_target_port { | |
700 | /* static/read-only fields */ | |
701 | u32 port_num; | |
702 | u64 node_name; | |
703 | u64 port_name; | |
704 | ||
705 | void *private; | |
706 | ||
707 | /* dynamic fields */ | |
708 | u32 port_id; | |
709 | enum nvme_fc_obj_state port_state; | |
710 | } __aligned(sizeof(u64)); /* alignment for other things alloc'd with */ | |
711 | ||
712 | ||
713 | /** | |
714 | * struct nvmet_fc_target_template - structure containing static entrypoints | |
715 | * and operational parameters for an LLDD that supports NVME | |
716 | * subsystem behavior. Passed by reference in port | |
717 | * registrations. NVME-FC transport remembers template | |
718 | * reference and may access it during runtime operation. | |
719 | * | |
720 | * Subsystem/Target Transport Entrypoints/Parameters: | |
721 | * | |
722 | * @targetport_delete: The LLDD initiates deletion of a targetport via | |
723 | * nvmet_fc_unregister_targetport(). However, the teardown is | |
724 | * asynchronous. This routine is called upon the completion of the | |
725 | * teardown to inform the LLDD that the targetport has been deleted. | |
726 | * Entrypoint is Mandatory. | |
727 | * | |
728 | * @xmt_ls_rsp: Called to transmit the response to a FC-NVME FC-4 LS service. | |
729 | * The nvmefc_tgt_ls_req structure is the same LLDD-supplied exchange | |
730 | * structure specified in the nvmet_fc_rcv_ls_req() call made when | |
731 | * the LS request was received. The structure will fully describe | |
732 | * the buffers for the response payload and the dma address of the | |
733 | * payload. The LLDD is to transmit the response (or return a non-zero | |
734 | * errno status), and upon completion of the transmit, call the | |
735 | * "done" routine specified in the nvmefc_tgt_ls_req structure | |
736 | * (argument to done is the ls reqwuest structure itself). | |
737 | * After calling the done routine, the LLDD shall consider the | |
738 | * LS handling complete and the nvmefc_tgt_ls_req structure may | |
739 | * be freed/released. | |
740 | * Entrypoint is Mandatory. | |
741 | * | |
19b58d94 JS |
742 | * @fcp_op: Called to perform a data transfer or transmit a response. |
743 | * The nvmefc_tgt_fcp_req structure is the same LLDD-supplied | |
744 | * exchange structure specified in the nvmet_fc_rcv_fcp_req() call | |
745 | * made when the FCP CMD IU was received. The op field in the | |
746 | * structure shall indicate the operation for the LLDD to perform | |
747 | * relative to the io. | |
d6d20012 JS |
748 | * NVMET_FCOP_READDATA operation: the LLDD is to send the |
749 | * payload data (described by sglist) to the host in 1 or | |
750 | * more FC sequences (preferrably 1). Note: the fc-nvme layer | |
751 | * may call the READDATA operation multiple times for longer | |
752 | * payloads. | |
753 | * NVMET_FCOP_WRITEDATA operation: the LLDD is to receive the | |
754 | * payload data (described by sglist) from the host via 1 or | |
755 | * more FC sequences (preferrably 1). The LLDD is to generate | |
756 | * the XFER_RDY IU(s) corresponding to the data being requested. | |
757 | * Note: the FC-NVME layer may call the WRITEDATA operation | |
758 | * multiple times for longer payloads. | |
759 | * NVMET_FCOP_READDATA_RSP operation: the LLDD is to send the | |
760 | * payload data (described by sglist) to the host in 1 or | |
761 | * more FC sequences (preferrably 1). If an error occurs during | |
762 | * payload data transmission, the LLDD is to set the | |
763 | * nvmefc_tgt_fcp_req fcp_error and transferred_length field, then | |
764 | * consider the operation complete. On error, the LLDD is to not | |
765 | * transmit the FCP_RSP iu. If all payload data is transferred | |
766 | * successfully, the LLDD is to update the nvmefc_tgt_fcp_req | |
767 | * transferred_length field and may subsequently transmit the | |
768 | * FCP_RSP iu payload (described by rspbuf, rspdma, rsplen). | |
19b58d94 JS |
769 | * If FCP_CONF is supported, the LLDD is to await FCP_CONF |
770 | * reception to confirm the RSP reception by the host. The LLDD | |
771 | * may retramsit the FCP_RSP iu if necessary per FC-NVME. Upon | |
772 | * transmission of the FCP_RSP iu if FCP_CONF is not supported, | |
773 | * or upon success/failure of FCP_CONF if it is supported, the | |
774 | * LLDD is to set the nvmefc_tgt_fcp_req fcp_error field and | |
775 | * consider the operation complete. | |
d6d20012 | 776 | * NVMET_FCOP_RSP: the LLDD is to transmit the FCP_RSP iu payload |
19b58d94 JS |
777 | * (described by rspbuf, rspdma, rsplen). If FCP_CONF is |
778 | * supported, the LLDD is to await FCP_CONF reception to confirm | |
779 | * the RSP reception by the host. The LLDD may retramsit the | |
780 | * FCP_RSP iu if FCP_CONF is not received per FC-NVME. Upon | |
781 | * transmission of the FCP_RSP iu if FCP_CONF is not supported, | |
782 | * or upon success/failure of FCP_CONF if it is supported, the | |
d6d20012 | 783 | * LLDD is to set the nvmefc_tgt_fcp_req fcp_error field and |
19b58d94 | 784 | * consider the operation complete. |
d6d20012 JS |
785 | * Upon completing the indicated operation, the LLDD is to set the |
786 | * status fields for the operation (tranferred_length and fcp_error | |
19b58d94 JS |
787 | * status) in the request, then call the "done" routine |
788 | * indicated in the fcp request. After the operation completes, | |
789 | * regardless of whether the FCP_RSP iu was successfully transmit, | |
790 | * the LLDD-supplied exchange structure must remain valid until the | |
791 | * transport calls the fcp_req_release() callback to return ownership | |
792 | * of the exchange structure back to the LLDD so that it may be used | |
793 | * for another fcp command. | |
d6d20012 JS |
794 | * Note: when calling the done routine for READDATA or WRITEDATA |
795 | * operations, the fc-nvme layer may immediate convert, in the same | |
796 | * thread and before returning to the LLDD, the fcp operation to | |
797 | * the next operation for the fcp io and call the LLDDs fcp_op | |
798 | * call again. If fields in the fcp request are to be accessed post | |
799 | * the done call, the LLDD should save their values prior to calling | |
800 | * the done routine, and inspect the save values after the done | |
801 | * routine. | |
802 | * Returns 0 on success, -<errno> on failure (Ex: -EIO) | |
803 | * Entrypoint is Mandatory. | |
804 | * | |
a97ec51b JS |
805 | * @fcp_abort: Called by the transport to abort an active command. |
806 | * The command may be in-between operations (nothing active in LLDD) | |
807 | * or may have an active WRITEDATA operation pending. The LLDD is to | |
808 | * initiate the ABTS process for the command and return from the | |
809 | * callback. The ABTS does not need to be complete on the command. | |
810 | * The fcp_abort callback inherently cannot fail. After the | |
811 | * fcp_abort() callback completes, the transport will wait for any | |
812 | * outstanding operation (if there was one) to complete, then will | |
813 | * call the fcp_req_release() callback to return the command's | |
814 | * exchange context back to the LLDD. | |
6b71f9e1 | 815 | * Entrypoint is Mandatory. |
a97ec51b | 816 | * |
19b58d94 JS |
817 | * @fcp_req_release: Called by the transport to return a nvmefc_tgt_fcp_req |
818 | * to the LLDD after all operations on the fcp operation are complete. | |
819 | * This may be due to the command completing or upon completion of | |
820 | * abort cleanup. | |
6b71f9e1 JS |
821 | * Entrypoint is Mandatory. |
822 | * | |
823 | * @defer_rcv: Called by the transport to signal the LLLD that it has | |
824 | * begun processing of a previously received NVME CMD IU. The LLDD | |
825 | * is now free to re-use the rcv buffer associated with the | |
826 | * nvmefc_tgt_fcp_req. | |
827 | * Entrypoint is Optional. | |
19b58d94 | 828 | * |
d6d20012 JS |
829 | * @max_hw_queues: indicates the maximum number of hw queues the LLDD |
830 | * supports for cpu affinitization. | |
831 | * Value is Mandatory. Must be at least 1. | |
832 | * | |
833 | * @max_sgl_segments: indicates the maximum number of sgl segments supported | |
834 | * by the LLDD | |
835 | * Value is Mandatory. Must be at least 1. Recommend at least 256. | |
836 | * | |
837 | * @max_dif_sgl_segments: indicates the maximum number of sgl segments | |
838 | * supported by the LLDD for DIF operations. | |
839 | * Value is Mandatory. Must be at least 1. Recommend at least 256. | |
840 | * | |
841 | * @dma_boundary: indicates the dma address boundary where dma mappings | |
842 | * will be split across. | |
843 | * Value is Mandatory. Typical value is 0xFFFFFFFF to split across | |
844 | * 4Gig address boundarys | |
845 | * | |
846 | * @target_features: The LLDD sets bits in this field to correspond to | |
847 | * optional features that are supported by the LLDD. | |
848 | * Refer to the NVMET_FCTGTFEAT_xxx values. | |
849 | * Value is Mandatory. Allowed to be zero. | |
850 | * | |
851 | * @target_priv_sz: The LLDD sets this field to the amount of additional | |
852 | * memory that it would like fc nvme layer to allocate on the LLDD's | |
853 | * behalf whenever a targetport is allocated. The additional memory | |
854 | * area solely for the of the LLDD and its location is specified by | |
855 | * the targetport->private pointer. | |
856 | * Value is Mandatory. Allowed to be zero. | |
857 | */ | |
858 | struct nvmet_fc_target_template { | |
859 | void (*targetport_delete)(struct nvmet_fc_target_port *tgtport); | |
860 | int (*xmt_ls_rsp)(struct nvmet_fc_target_port *tgtport, | |
861 | struct nvmefc_tgt_ls_req *tls_req); | |
862 | int (*fcp_op)(struct nvmet_fc_target_port *tgtport, | |
19b58d94 | 863 | struct nvmefc_tgt_fcp_req *fcpreq); |
a97ec51b JS |
864 | void (*fcp_abort)(struct nvmet_fc_target_port *tgtport, |
865 | struct nvmefc_tgt_fcp_req *fcpreq); | |
19b58d94 JS |
866 | void (*fcp_req_release)(struct nvmet_fc_target_port *tgtport, |
867 | struct nvmefc_tgt_fcp_req *fcpreq); | |
0fb228d3 JS |
868 | void (*defer_rcv)(struct nvmet_fc_target_port *tgtport, |
869 | struct nvmefc_tgt_fcp_req *fcpreq); | |
d6d20012 JS |
870 | |
871 | u32 max_hw_queues; | |
872 | u16 max_sgl_segments; | |
873 | u16 max_dif_sgl_segments; | |
874 | u64 dma_boundary; | |
875 | ||
876 | u32 target_features; | |
877 | ||
878 | u32 target_priv_sz; | |
879 | }; | |
880 | ||
881 | ||
882 | int nvmet_fc_register_targetport(struct nvmet_fc_port_info *portinfo, | |
883 | struct nvmet_fc_target_template *template, | |
884 | struct device *dev, | |
885 | struct nvmet_fc_target_port **tgtport_p); | |
886 | ||
887 | int nvmet_fc_unregister_targetport(struct nvmet_fc_target_port *tgtport); | |
888 | ||
889 | int nvmet_fc_rcv_ls_req(struct nvmet_fc_target_port *tgtport, | |
890 | struct nvmefc_tgt_ls_req *lsreq, | |
891 | void *lsreqbuf, u32 lsreqbuf_len); | |
892 | ||
893 | int nvmet_fc_rcv_fcp_req(struct nvmet_fc_target_port *tgtport, | |
894 | struct nvmefc_tgt_fcp_req *fcpreq, | |
895 | void *cmdiubuf, u32 cmdiubuf_len); | |
896 | ||
a97ec51b JS |
897 | void nvmet_fc_rcv_fcp_abort(struct nvmet_fc_target_port *tgtport, |
898 | struct nvmefc_tgt_fcp_req *fcpreq); | |
899 | ||
d6d20012 | 900 | #endif /* _NVME_FC_DRIVER_H */ |