2 * Copyright (c) 2003, 2004, 2005, 2008 Silicon Graphics International Corp.
3 * Copyright (c) 2014-2015 Alexander Motin <mav@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer,
11 * without modification.
12 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
13 * substantially similar to the "NO WARRANTY" disclaimer below
14 * ("Disclaimer") and any redistribution must be conditioned upon
15 * including a substantially similar Disclaimer requirement for further
16 * binary redistribution.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGES.
31 * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_private.h#7 $
35 * CAM Target Layer driver private data structures/definitions.
37 * Author: Ken Merry <ken@FreeBSD.org>
40 #ifndef _CTL_PRIVATE_H_
41 #define _CTL_PRIVATE_H_
44 * SCSI vendor and product names.
46 #define CTL_VENDOR "FREEBSD "
47 #define CTL_DIRECT_PRODUCT "CTLDISK "
48 #define CTL_PROCESSOR_PRODUCT "CTLPROCESSOR "
49 #define CTL_CDROM_PRODUCT "CTLCDROM "
50 #define CTL_UNKNOWN_PRODUCT "CTLDEVICE "
52 #define CTL_POOL_ENTRIES_OTHER_SC 200
57 struct ctl_softc *ctl_softc;
58 struct uma_zone *zone;
69 } ctl_serialize_action;
74 CTL_ACTION_OVERLAP_TAG,
81 * WARNING: Keep the bottom nibble here free, we OR in the data direction
82 * flags for each command.
84 * Note: "OK_ON_NO_LUN" == we don't have to have a lun configured
85 * "OK_ON_BOTH" == we have to have a lun configured
86 * "SA5" == command has 5-bit service action at byte 1
89 CTL_CMD_FLAG_NONE = 0x0000,
90 CTL_CMD_FLAG_NO_SENSE = 0x0010,
91 CTL_CMD_FLAG_ALLOW_ON_RESV = 0x0020,
92 CTL_CMD_FLAG_ALLOW_ON_PR_RESV = 0x0040,
93 CTL_CMD_FLAG_ALLOW_ON_PR_WRESV = 0x0080,
94 CTL_CMD_FLAG_OK_ON_PROC = 0x0100,
95 CTL_CMD_FLAG_OK_ON_DIRECT = 0x0200,
96 CTL_CMD_FLAG_OK_ON_CDROM = 0x0400,
97 CTL_CMD_FLAG_OK_ON_BOTH = 0x0700,
98 CTL_CMD_FLAG_OK_ON_NO_LUN = 0x0800,
99 CTL_CMD_FLAG_OK_ON_NO_MEDIA = 0x1000,
100 CTL_CMD_FLAG_OK_ON_STANDBY = 0x2000,
101 CTL_CMD_FLAG_OK_ON_UNAVAIL = 0x4000,
102 CTL_CMD_FLAG_SA5 = 0x8000,
103 CTL_CMD_FLAG_RUN_HERE = 0x10000
121 /* TBD: others to be filled in as needed */
122 CTL_SERIDX_COUNT, /* LAST, not a normal code, provides # codes */
123 CTL_SERIDX_INVLD = CTL_SERIDX_COUNT
126 typedef int ctl_opfunc(struct ctl_scsiio *ctsio);
128 struct ctl_cmd_entry {
132 ctl_lun_error_pattern pattern;
133 uint8_t length; /* CDB length */
134 uint8_t usage[15]; /* Mask of allowed CDB bits
135 * after the opcode byte. */
139 CTL_LUN_NONE = 0x000,
140 CTL_LUN_CONTROL = 0x001,
141 CTL_LUN_RESERVED = 0x002,
142 CTL_LUN_INVALID = 0x004,
143 CTL_LUN_DISABLED = 0x008,
144 CTL_LUN_MALLOCED = 0x010,
145 CTL_LUN_STOPPED = 0x020,
146 CTL_LUN_NO_MEDIA = 0x040,
147 CTL_LUN_EJECTED = 0x080,
148 CTL_LUN_PR_RESERVED = 0x100,
149 CTL_LUN_PRIMARY_SC = 0x200,
150 CTL_LUN_SENSE_DESC = 0x400,
151 CTL_LUN_READONLY = 0x800,
152 CTL_LUN_PEER_SC_PRIMARY = 0x1000,
153 CTL_LUN_REMOVABLE = 0x2000
157 CTLBLOCK_FLAG_NONE = 0x00,
158 CTLBLOCK_FLAG_INVALID = 0x01
162 struct ctl_softc *ctl_softc;
163 struct ctlblock_softc *ctlblock_softc;
167 * Mode page defaults.
171 * These values make Solaris trim off some of the capacity.
173 #define CTL_DEFAULT_SECTORS_PER_TRACK 63
174 #define CTL_DEFAULT_HEADS 255
176 * These values seem to work okay.
178 #define CTL_DEFAULT_SECTORS_PER_TRACK 63
179 #define CTL_DEFAULT_HEADS 16
181 * These values work reasonably well.
183 #define CTL_DEFAULT_SECTORS_PER_TRACK 512
184 #define CTL_DEFAULT_HEADS 64
188 * Solaris is somewhat picky about how many heads and sectors per track you
189 * have defined in mode pages 3 and 4. These values seem to cause Solaris
190 * to get the capacity more or less right when you run the format tool.
191 * They still have problems when dealing with devices larger than 1TB,
192 * but there isn't anything we can do about that.
194 * For smaller LUN sizes, this ends up causing the number of cylinders to
195 * work out to 0. Solaris actually recognizes that and comes up with its
196 * own bogus geometry to fit the actual capacity of the drive. They really
197 * should just give up on geometry and stick to the read capacity
198 * information alone for modern disk drives.
200 * One thing worth mentioning about Solaris' mkfs command is that it
201 * doesn't like sectors per track values larger than 256. 512 seems to
202 * work okay for format, but causes problems when you try to make a
205 * Another caveat about these values: the product of these two values
206 * really should be a power of 2. This is because of the simplistic
207 * shift-based calculation that we have to use on the i386 platform to
208 * calculate the number of cylinders here. (If you use a divide, you end
209 * up calling __udivdi3(), which is a hardware FP call on the PC. On the
210 * XScale, it is done in software, so you can do that from inside the
213 * So for the current values (256 S/T, 128 H), we get 32768, which works
214 * very nicely for calculating cylinders.
216 * If you want to change these values so that their product is no longer a
217 * power of 2, re-visit the calculation in ctl_init_page_index(). You may
218 * need to make it a bit more complicated to get the number of cylinders
221 #define CTL_DEFAULT_SECTORS_PER_TRACK 256
222 #define CTL_DEFAULT_HEADS 128
224 #define CTL_DEFAULT_ROTATION_RATE SVPD_NON_ROTATING
226 struct ctl_page_index;
228 typedef int ctl_modesen_handler(struct ctl_scsiio *ctsio,
229 struct ctl_page_index *page_index,
231 typedef int ctl_modesel_handler(struct ctl_scsiio *ctsio,
232 struct ctl_page_index *page_index,
236 CTL_PAGE_FLAG_NONE = 0x00,
237 CTL_PAGE_FLAG_DIRECT = 0x01,
238 CTL_PAGE_FLAG_PROC = 0x02,
239 CTL_PAGE_FLAG_CDROM = 0x04,
240 CTL_PAGE_FLAG_ALL = 0x07
243 struct ctl_page_index {
248 ctl_page_flags page_flags;
249 ctl_modesen_handler *sense_handler;
250 ctl_modesel_handler *select_handler;
253 #define CTL_PAGE_CURRENT 0x00
254 #define CTL_PAGE_CHANGEABLE 0x01
255 #define CTL_PAGE_DEFAULT 0x02
256 #define CTL_PAGE_SAVED 0x03
258 #define CTL_NUM_LBP_PARAMS 4
259 #define CTL_NUM_LBP_THRESH 4
260 #define CTL_LBP_EXPONENT 11 /* 2048 sectors */
261 #define CTL_LBP_PERIOD 10 /* 10 seconds */
262 #define CTL_LBP_UA_PERIOD 300 /* 5 minutes */
264 struct ctl_logical_block_provisioning_page {
265 struct scsi_logical_block_provisioning_page main;
266 struct scsi_logical_block_provisioning_page_descr descr[CTL_NUM_LBP_THRESH];
269 static const struct ctl_page_index page_index_template[] = {
270 {SMS_RW_ERROR_RECOVERY_PAGE, 0, sizeof(struct scsi_da_rw_recovery_page), NULL,
271 CTL_PAGE_FLAG_DIRECT | CTL_PAGE_FLAG_CDROM, NULL, NULL},
272 {SMS_FORMAT_DEVICE_PAGE, 0, sizeof(struct scsi_format_page), NULL,
273 CTL_PAGE_FLAG_DIRECT, NULL, NULL},
274 {SMS_RIGID_DISK_PAGE, 0, sizeof(struct scsi_rigid_disk_page), NULL,
275 CTL_PAGE_FLAG_DIRECT, NULL, NULL},
276 {SMS_CACHING_PAGE, 0, sizeof(struct scsi_caching_page), NULL,
277 CTL_PAGE_FLAG_DIRECT | CTL_PAGE_FLAG_CDROM,
278 NULL, ctl_caching_sp_handler},
279 {SMS_CONTROL_MODE_PAGE, 0, sizeof(struct scsi_control_page), NULL,
280 CTL_PAGE_FLAG_ALL, NULL, ctl_control_page_handler},
281 {SMS_CONTROL_MODE_PAGE | SMPH_SPF, 0x01,
282 sizeof(struct scsi_control_ext_page), NULL,
283 CTL_PAGE_FLAG_ALL, NULL, NULL},
284 {SMS_INFO_EXCEPTIONS_PAGE, 0, sizeof(struct scsi_info_exceptions_page), NULL,
285 CTL_PAGE_FLAG_ALL, NULL, NULL},
286 {SMS_INFO_EXCEPTIONS_PAGE | SMPH_SPF, 0x02,
287 sizeof(struct ctl_logical_block_provisioning_page), NULL,
288 CTL_PAGE_FLAG_DIRECT, NULL, NULL},
289 {SMS_VENDOR_SPECIFIC_PAGE | SMPH_SPF, DBGCNF_SUBPAGE_CODE,
290 sizeof(struct copan_debugconf_subpage), NULL, CTL_PAGE_FLAG_ALL,
291 ctl_debugconf_sp_sense_handler, ctl_debugconf_sp_select_handler},
294 #define CTL_NUM_MODE_PAGES sizeof(page_index_template)/ \
295 sizeof(page_index_template[0])
297 struct ctl_mode_pages {
298 struct scsi_da_rw_recovery_page rw_er_page[4];
299 struct scsi_format_page format_page[4];
300 struct scsi_rigid_disk_page rigid_disk_page[4];
301 struct scsi_caching_page caching_page[4];
302 struct scsi_control_page control_page[4];
303 struct scsi_control_ext_page control_ext_page[4];
304 struct scsi_info_exceptions_page ie_page[4];
305 struct ctl_logical_block_provisioning_page lbp_page[4];
306 struct copan_debugconf_subpage debugconf_subpage[4];
307 struct ctl_page_index index[CTL_NUM_MODE_PAGES];
310 static const struct ctl_page_index log_page_index_template[] = {
311 {SLS_SUPPORTED_PAGES_PAGE, 0, 0, NULL,
312 CTL_PAGE_FLAG_ALL, NULL, NULL},
313 {SLS_SUPPORTED_PAGES_PAGE, SLS_SUPPORTED_SUBPAGES_SUBPAGE, 0, NULL,
314 CTL_PAGE_FLAG_ALL, NULL, NULL},
315 {SLS_LOGICAL_BLOCK_PROVISIONING, 0, 0, NULL,
316 CTL_PAGE_FLAG_DIRECT, ctl_lbp_log_sense_handler, NULL},
317 {SLS_STAT_AND_PERF, 0, 0, NULL,
318 CTL_PAGE_FLAG_ALL, ctl_sap_log_sense_handler, NULL},
321 #define CTL_NUM_LOG_PAGES sizeof(log_page_index_template)/ \
322 sizeof(log_page_index_template[0])
324 struct ctl_log_pages {
325 uint8_t pages_page[CTL_NUM_LOG_PAGES];
326 uint8_t subpages_page[CTL_NUM_LOG_PAGES * 2];
327 uint8_t lbp_page[12*CTL_NUM_LBP_PARAMS];
329 struct scsi_log_stat_and_perf sap;
330 struct scsi_log_idle_time it;
331 struct scsi_log_time_interval ti;
333 struct ctl_page_index index[CTL_NUM_LOG_PAGES];
336 struct ctl_lun_delay_info {
337 ctl_delay_type datamove_type;
338 uint32_t datamove_delay;
339 ctl_delay_type done_type;
343 #define CTL_PR_ALL_REGISTRANTS 0xFFFFFFFF
344 #define CTL_PR_NO_RESERVATION 0xFFFFFFF0
352 * For report target port groups.
354 #define NUM_TARGET_PORT_GROUPS 2
356 #define CTL_WRITE_BUFFER_SIZE 262144
363 STAILQ_HEAD(,ctl_error_desc) error_list;
364 uint64_t error_serial;
365 struct ctl_softc *ctl_softc;
366 struct ctl_be_lun *be_lun;
367 struct ctl_backend_driver *backend;
368 struct ctl_lun_delay_info delay_info;
370 sbintime_t idle_time;
371 sbintime_t last_busy;
373 TAILQ_HEAD(ctl_ooaq, ctl_io_hdr) ooa_queue;
374 TAILQ_HEAD(ctl_blockq,ctl_io_hdr) blocked_queue;
375 STAILQ_ENTRY(ctl_lun) links;
377 uint32_t have_ca[CTL_MAX_INITIATORS >> 5];
378 struct scsi_sense_data pending_sense[CTL_MAX_INITIATORS];
380 ctl_ua_type *pending_ua[CTL_MAX_PORTS];
381 uint8_t ua_tpt_info[8];
383 struct ctl_mode_pages mode_pages;
384 struct ctl_log_pages log_pages;
385 struct ctl_lun_io_stats stats;
387 unsigned int PRGeneration;
388 uint64_t *pr_keys[CTL_MAX_PORTS];
392 uint8_t *write_buffer;
393 struct ctl_devid *lun_devid;
394 TAILQ_HEAD(tpc_lists, tpc_list) tpc_lists;
398 CTL_FLAG_ACTIVE_SHELF = 0x04
401 #define CTL_MAX_THREADS 16
404 struct mtx_padalign queue_lock;
405 struct ctl_softc *ctl_softc;
406 struct thread *thread;
407 STAILQ_HEAD(, ctl_io_hdr) incoming_queue;
408 STAILQ_HEAD(, ctl_io_hdr) rtr_queue;
409 STAILQ_HEAD(, ctl_io_hdr) done_queue;
410 STAILQ_HEAD(, ctl_io_hdr) isc_queue;
422 ctl_ha_link_state ha_link;
428 struct sysctl_ctx_list sysctl_ctx;
429 struct sysctl_oid *sysctl_tree;
431 struct proc *ctl_proc;
432 uint32_t ctl_lun_mask[(CTL_MAX_LUNS + 31) / 32];
433 struct ctl_lun *ctl_luns[CTL_MAX_LUNS];
434 uint32_t ctl_port_mask[(CTL_MAX_PORTS + 31) / 32];
435 STAILQ_HEAD(, ctl_lun) lun_list;
436 STAILQ_HEAD(, ctl_be_lun) pending_lun_queue;
437 uint32_t num_frontends;
438 STAILQ_HEAD(, ctl_frontend) fe_list;
440 STAILQ_HEAD(, ctl_port) port_list;
441 struct ctl_port *ctl_ports[CTL_MAX_PORTS];
442 uint32_t num_backends;
443 STAILQ_HEAD(, ctl_backend_driver) be_list;
444 struct uma_zone *io_zone;
445 uint32_t cur_pool_id;
446 struct ctl_thread threads[CTL_MAX_THREADS];
447 TAILQ_HEAD(tpc_tokens, tpc_token) tpc_tokens;
448 struct callout tpc_timeout;
454 extern const struct ctl_cmd_entry ctl_cmd_table[256];
456 uint32_t ctl_get_initindex(struct ctl_nexus *nexus);
457 int ctl_lun_map_init(struct ctl_port *port);
458 int ctl_lun_map_deinit(struct ctl_port *port);
459 int ctl_lun_map_set(struct ctl_port *port, uint32_t plun, uint32_t glun);
460 int ctl_lun_map_unset(struct ctl_port *port, uint32_t plun);
461 uint32_t ctl_lun_map_from_port(struct ctl_port *port, uint32_t plun);
462 uint32_t ctl_lun_map_to_port(struct ctl_port *port, uint32_t glun);
463 int ctl_pool_create(struct ctl_softc *ctl_softc, const char *pool_name,
464 uint32_t total_ctl_io, void **npool);
465 void ctl_pool_free(struct ctl_io_pool *pool);
466 int ctl_scsi_release(struct ctl_scsiio *ctsio);
467 int ctl_scsi_reserve(struct ctl_scsiio *ctsio);
468 int ctl_start_stop(struct ctl_scsiio *ctsio);
469 int ctl_prevent_allow(struct ctl_scsiio *ctsio);
470 int ctl_sync_cache(struct ctl_scsiio *ctsio);
471 int ctl_format(struct ctl_scsiio *ctsio);
472 int ctl_read_buffer(struct ctl_scsiio *ctsio);
473 int ctl_write_buffer(struct ctl_scsiio *ctsio);
474 int ctl_write_same(struct ctl_scsiio *ctsio);
475 int ctl_unmap(struct ctl_scsiio *ctsio);
476 int ctl_mode_select(struct ctl_scsiio *ctsio);
477 int ctl_mode_sense(struct ctl_scsiio *ctsio);
478 int ctl_log_sense(struct ctl_scsiio *ctsio);
479 int ctl_read_capacity(struct ctl_scsiio *ctsio);
480 int ctl_read_capacity_16(struct ctl_scsiio *ctsio);
481 int ctl_read_defect(struct ctl_scsiio *ctsio);
482 int ctl_read_toc(struct ctl_scsiio *ctsio);
483 int ctl_read_write(struct ctl_scsiio *ctsio);
484 int ctl_cnw(struct ctl_scsiio *ctsio);
485 int ctl_report_luns(struct ctl_scsiio *ctsio);
486 int ctl_request_sense(struct ctl_scsiio *ctsio);
487 int ctl_tur(struct ctl_scsiio *ctsio);
488 int ctl_verify(struct ctl_scsiio *ctsio);
489 int ctl_inquiry(struct ctl_scsiio *ctsio);
490 int ctl_get_config(struct ctl_scsiio *ctsio);
491 int ctl_get_event_status(struct ctl_scsiio *ctsio);
492 int ctl_mechanism_status(struct ctl_scsiio *ctsio);
493 int ctl_persistent_reserve_in(struct ctl_scsiio *ctsio);
494 int ctl_persistent_reserve_out(struct ctl_scsiio *ctsio);
495 int ctl_report_tagret_port_groups(struct ctl_scsiio *ctsio);
496 int ctl_report_supported_opcodes(struct ctl_scsiio *ctsio);
497 int ctl_report_supported_tmf(struct ctl_scsiio *ctsio);
498 int ctl_report_timestamp(struct ctl_scsiio *ctsio);
499 int ctl_get_lba_status(struct ctl_scsiio *ctsio);
501 void ctl_tpc_init(struct ctl_softc *softc);
502 void ctl_tpc_shutdown(struct ctl_softc *softc);
503 void ctl_tpc_lun_init(struct ctl_lun *lun);
504 void ctl_tpc_lun_shutdown(struct ctl_lun *lun);
505 int ctl_inquiry_evpd_tpc(struct ctl_scsiio *ctsio, int alloc_len);
506 int ctl_receive_copy_status_lid1(struct ctl_scsiio *ctsio);
507 int ctl_receive_copy_failure_details(struct ctl_scsiio *ctsio);
508 int ctl_receive_copy_status_lid4(struct ctl_scsiio *ctsio);
509 int ctl_receive_copy_operating_parameters(struct ctl_scsiio *ctsio);
510 int ctl_extended_copy_lid1(struct ctl_scsiio *ctsio);
511 int ctl_extended_copy_lid4(struct ctl_scsiio *ctsio);
512 int ctl_copy_operation_abort(struct ctl_scsiio *ctsio);
513 int ctl_populate_token(struct ctl_scsiio *ctsio);
514 int ctl_write_using_token(struct ctl_scsiio *ctsio);
515 int ctl_receive_rod_token_information(struct ctl_scsiio *ctsio);
516 int ctl_report_all_rod_tokens(struct ctl_scsiio *ctsio);
520 #endif /* _CTL_PRIVATE_H_ */