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