]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/lib/scsi/scsi_internal.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / lib / scsi / scsi_internal.h
CommitLineData
7c673cae
FG
1/*-
2 * BSD LICENSE
3 *
4 * Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
5 * Copyright (c) Intel Corporation.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * * Neither the name of Intel Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#ifndef SPDK_SCSI_INTERNAL_H
36#define SPDK_SCSI_INTERNAL_H
37
11fdf7f2 38#include "spdk/stdinc.h"
7c673cae
FG
39
40#include "spdk/bdev.h"
41#include "spdk/scsi.h"
42#include "spdk/scsi_spec.h"
43#include "spdk/trace.h"
9f95a23c 44#include "spdk/dif.h"
7c673cae
FG
45
46#include "spdk_internal/log.h"
47
7c673cae
FG
48enum {
49 SPDK_SCSI_TASK_UNKNOWN = -1,
50 SPDK_SCSI_TASK_COMPLETE,
51 SPDK_SCSI_TASK_PENDING,
52};
53
11fdf7f2
TL
54struct spdk_scsi_port {
55 uint8_t is_used;
56 uint64_t id;
57 uint16_t index;
9f95a23c
TL
58 uint16_t transport_id_len;
59 char transport_id[SPDK_SCSI_MAX_TRANSPORT_ID_LENGTH];
11fdf7f2
TL
60 char name[SPDK_SCSI_PORT_MAX_NAME_LENGTH];
61};
62
9f95a23c
TL
63/* Registrant with I_T nextus */
64struct spdk_scsi_pr_registrant {
65 uint64_t rkey;
66 uint16_t relative_target_port_id;
67 uint16_t transport_id_len;
68 char transport_id[SPDK_SCSI_MAX_TRANSPORT_ID_LENGTH];
69 char initiator_port_name[SPDK_SCSI_PORT_MAX_NAME_LENGTH];
70 char target_port_name[SPDK_SCSI_PORT_MAX_NAME_LENGTH];
71 struct spdk_scsi_port *initiator_port;
72 struct spdk_scsi_port *target_port;
73 TAILQ_ENTRY(spdk_scsi_pr_registrant) link;
74};
75
f67539c2
TL
76#define SCSI_SPC2_RESERVE 0x00000001U
77
9f95a23c
TL
78/* Reservation with LU_SCOPE */
79struct spdk_scsi_pr_reservation {
f67539c2 80 uint32_t flags;
9f95a23c
TL
81 struct spdk_scsi_pr_registrant *holder;
82 enum spdk_scsi_pr_type_code rtype;
83 uint64_t crkey;
84};
85
11fdf7f2 86struct spdk_scsi_dev {
9f95a23c
TL
87 int id;
88 int is_allocated;
89 bool removed;
90 spdk_scsi_dev_destruct_cb_t remove_cb;
91 void *remove_ctx;
11fdf7f2 92
9f95a23c 93 char name[SPDK_SCSI_DEV_MAX_NAME + 1];
11fdf7f2 94
9f95a23c 95 struct spdk_scsi_lun *lun[SPDK_SCSI_DEV_MAX_LUN];
11fdf7f2 96
9f95a23c
TL
97 int num_ports;
98 struct spdk_scsi_port port[SPDK_SCSI_DEV_MAX_PORTS];
11fdf7f2 99
9f95a23c 100 uint8_t protocol_id;
11fdf7f2
TL
101};
102
9f95a23c 103struct spdk_scsi_lun_desc {
11fdf7f2 104 struct spdk_scsi_lun *lun;
9f95a23c 105 spdk_scsi_lun_remove_cb_t hotremove_cb;
11fdf7f2 106 void *hotremove_ctx;
9f95a23c 107 TAILQ_ENTRY(spdk_scsi_lun_desc) link;
11fdf7f2
TL
108};
109
110struct spdk_scsi_lun {
111 /** LUN id for this logical unit. */
112 int id;
113
114 /** Pointer to the SCSI device containing this LUN. */
115 struct spdk_scsi_dev *dev;
116
117 /** The bdev associated with this LUN. */
118 struct spdk_bdev *bdev;
119
120 /** Descriptor for opened block device. */
121 struct spdk_bdev_desc *bdev_desc;
122
f67539c2
TL
123 /** The thread which opens this LUN. */
124 struct spdk_thread *thread;
125
11fdf7f2
TL
126 /** I/O channel for the bdev associated with this LUN. */
127 struct spdk_io_channel *io_channel;
128
129 /** The reference number for this LUN, thus we can correctly free the io_channel */
130 uint32_t ref;
131
132 /** Poller to release the resource of the lun when it is hot removed */
133 struct spdk_poller *hotremove_poller;
134
135 /** The LUN is removed */
136 bool removed;
137
138 /** Callback to be fired when LUN removal is first triggered. */
139 void (*hotremove_cb)(const struct spdk_scsi_lun *lun, void *arg);
140
141 /** Argument for hotremove_cb */
142 void *hotremove_ctx;
143
9f95a23c
TL
144 /** Registrant head for I_T nexus */
145 TAILQ_HEAD(, spdk_scsi_pr_registrant) reg_head;
146 /** Persistent Reservation Generation */
147 uint32_t pr_generation;
148 /** Reservation for the LUN */
149 struct spdk_scsi_pr_reservation reservation;
f67539c2
TL
150 /** Reservation holder for SPC2 RESERVE(6) and RESERVE(10) */
151 struct spdk_scsi_pr_registrant scsi2_holder;
9f95a23c 152
11fdf7f2 153 /** List of open descriptors for this LUN. */
9f95a23c 154 TAILQ_HEAD(, spdk_scsi_lun_desc) open_descs;
11fdf7f2 155
9f95a23c 156 /** submitted tasks */
11fdf7f2 157 TAILQ_HEAD(tasks, spdk_scsi_task) tasks;
9f95a23c
TL
158
159 /** pending tasks */
160 TAILQ_HEAD(pending_tasks, spdk_scsi_task) pending_tasks;
161
162 /** submitted management tasks */
163 TAILQ_HEAD(mgmt_tasks, spdk_scsi_task) mgmt_tasks;
164
165 /** pending management tasks */
166 TAILQ_HEAD(pending_mgmt_tasks, spdk_scsi_task) pending_mgmt_tasks;
167
168 /** poller to check completion of tasks prior to reset */
169 struct spdk_poller *reset_poller;
11fdf7f2
TL
170};
171
f67539c2
TL
172struct spdk_scsi_lun *scsi_lun_construct(struct spdk_bdev *bdev,
173 void (*hotremove_cb)(const struct spdk_scsi_lun *, void *),
174 void *hotremove_ctx);
175void scsi_lun_destruct(struct spdk_scsi_lun *lun);
7c673cae 176
f67539c2
TL
177void scsi_lun_execute_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task);
178void scsi_lun_execute_mgmt_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task);
179bool scsi_lun_has_pending_mgmt_tasks(const struct spdk_scsi_lun *lun,
180 const struct spdk_scsi_port *initiator_port);
181void scsi_lun_complete_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task);
182void scsi_lun_complete_reset_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task);
183bool scsi_lun_has_pending_tasks(const struct spdk_scsi_lun *lun,
184 const struct spdk_scsi_port *initiator_port);
185int scsi_lun_allocate_io_channel(struct spdk_scsi_lun *lun);
186void scsi_lun_free_io_channel(struct spdk_scsi_lun *lun);
7c673cae 187
f67539c2 188struct spdk_scsi_dev *scsi_dev_get_list(void);
7c673cae 189
f67539c2
TL
190int scsi_port_construct(struct spdk_scsi_port *port, uint64_t id,
191 uint16_t index, const char *name);
192void scsi_port_destruct(struct spdk_scsi_port *port);
7c673cae 193
f67539c2
TL
194int bdev_scsi_execute(struct spdk_scsi_task *task);
195void bdev_scsi_reset(struct spdk_scsi_task *task);
7c673cae 196
f67539c2
TL
197bool bdev_scsi_get_dif_ctx(struct spdk_bdev *bdev, struct spdk_scsi_task *task,
198 struct spdk_dif_ctx *dif_ctx);
7c673cae 199
f67539c2
TL
200int scsi_pr_out(struct spdk_scsi_task *task, uint8_t *cdb, uint8_t *data, uint16_t data_len);
201int scsi_pr_in(struct spdk_scsi_task *task, uint8_t *cdb, uint8_t *data, uint16_t data_len);
202int scsi_pr_check(struct spdk_scsi_task *task);
9f95a23c 203
f67539c2
TL
204int scsi2_reserve(struct spdk_scsi_task *task, uint8_t *cdb);
205int scsi2_release(struct spdk_scsi_task *task);
206int scsi2_reserve_check(struct spdk_scsi_task *task);
9f95a23c 207
7c673cae
FG
208struct spdk_scsi_globals {
209 pthread_mutex_t mutex;
7c673cae
FG
210};
211
f67539c2 212extern struct spdk_scsi_globals g_scsi;
7c673cae
FG
213
214#endif /* SPDK_SCSI_INTERNAL_H */