2 * Copyright (c) 2003, 2004, 2005, 2008 Silicon Graphics International Corp.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions, and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * substantially similar to the "NO WARRANTY" disclaimer below
13 * ("Disclaimer") and any redistribution must be conditioned upon
14 * including a substantially similar Disclaimer requirement for further
15 * binary redistribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGES.
30 * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl_private.h#7 $
34 * CAM Target Layer driver private data structures/definitions.
36 * Author: Ken Merry <ken@FreeBSD.org>
39 #ifndef _CTL_PRIVATE_H_
40 #define _CTL_PRIVATE_H_
43 * SCSI vendor and product names.
45 #define CTL_VENDOR "FREEBSD "
46 #define CTL_DIRECT_PRODUCT "CTLDISK "
47 #define CTL_PROCESSOR_PRODUCT "CTLPROCESSOR "
48 #define CTL_UNKNOWN_PRODUCT "CTLDEVICE "
50 struct ctl_fe_ioctl_startstop_info {
52 struct ctl_hard_startstop_info hs_info;
55 struct ctl_fe_ioctl_bbrread_info {
57 struct ctl_bbrread_info *bbr_info;
68 struct ctl_fe_ioctl_params {
71 ctl_fe_ioctl_state state;
74 #define CTL_POOL_ENTRIES_INTERNAL 200
75 #define CTL_POOL_ENTRIES_EMERGENCY 300
76 #define CTL_POOL_ENTRIES_OTHER_SC 200
86 CTL_POOL_FLAG_NONE = 0x00,
87 CTL_POOL_FLAG_INVALID = 0x01
94 struct ctl_softc *ctl_softc;
96 uint64_t total_allocated;
100 STAILQ_HEAD(, ctl_io_hdr) free_queue;
101 STAILQ_ENTRY(ctl_io_pool) links;
105 CTL_IOCTL_FLAG_NONE = 0x00,
106 CTL_IOCTL_FLAG_ENABLED = 0x01
109 struct ctl_ioctl_info {
110 ctl_ioctl_flags flags;
111 uint32_t cur_tag_num;
112 struct ctl_port port;
123 } ctl_serialize_action;
128 CTL_ACTION_OVERLAP_TAG,
135 * WARNING: Keep the bottom nibble here free, we OR in the data direction
136 * flags for each command.
138 * Note: "OK_ON_ALL_LUNS" == we don't have to have a lun configured
139 * "OK_ON_BOTH" == we have to have a lun configured
140 * "SA5" == command has 5-bit service action at byte 1
143 CTL_CMD_FLAG_NONE = 0x0000,
144 CTL_CMD_FLAG_NO_SENSE = 0x0010,
145 CTL_CMD_FLAG_OK_ON_ALL_LUNS = 0x0020,
146 CTL_CMD_FLAG_ALLOW_ON_RESV = 0x0040,
147 CTL_CMD_FLAG_ALLOW_ON_PR_WRESV = 0x0080,
148 CTL_CMD_FLAG_OK_ON_PROC = 0x0100,
149 CTL_CMD_FLAG_OK_ON_SLUN = 0x0200,
150 CTL_CMD_FLAG_OK_ON_BOTH = 0x0300,
151 CTL_CMD_FLAG_OK_ON_STOPPED = 0x0400,
152 CTL_CMD_FLAG_OK_ON_INOPERABLE = 0x0800,
153 CTL_CMD_FLAG_OK_ON_OFFLINE = 0x1000,
154 CTL_CMD_FLAG_OK_ON_SECONDARY = 0x2000,
155 CTL_CMD_FLAG_ALLOW_ON_PR_RESV = 0x4000,
156 CTL_CMD_FLAG_SA5 = 0x8000
173 /* TBD: others to be filled in as needed */
174 CTL_SERIDX_COUNT, /* LAST, not a normal code, provides # codes */
175 CTL_SERIDX_INVLD = CTL_SERIDX_COUNT
178 typedef int ctl_opfunc(struct ctl_scsiio *ctsio);
180 struct ctl_cmd_entry {
184 ctl_lun_error_pattern pattern;
185 uint8_t length; /* CDB length */
186 uint8_t usage[15]; /* Mask of allowed CDB bits
187 * after the opcode byte. */
191 CTL_LUN_NONE = 0x000,
192 CTL_LUN_CONTROL = 0x001,
193 CTL_LUN_RESERVED = 0x002,
194 CTL_LUN_INVALID = 0x004,
195 CTL_LUN_DISABLED = 0x008,
196 CTL_LUN_MALLOCED = 0x010,
197 CTL_LUN_STOPPED = 0x020,
198 CTL_LUN_INOPERABLE = 0x040,
199 CTL_LUN_OFFLINE = 0x080,
200 CTL_LUN_PR_RESERVED = 0x100,
201 CTL_LUN_PRIMARY_SC = 0x200,
202 CTL_LUN_SENSE_DESC = 0x400,
203 CTL_LUN_READONLY = 0x800
207 CTLBLOCK_FLAG_NONE = 0x00,
208 CTLBLOCK_FLAG_INVALID = 0x01
212 struct ctl_softc *ctl_softc;
213 struct ctlblock_softc *ctlblock_softc;
217 * Mode page defaults.
221 * These values make Solaris trim off some of the capacity.
223 #define CTL_DEFAULT_SECTORS_PER_TRACK 63
224 #define CTL_DEFAULT_HEADS 255
226 * These values seem to work okay.
228 #define CTL_DEFAULT_SECTORS_PER_TRACK 63
229 #define CTL_DEFAULT_HEADS 16
231 * These values work reasonably well.
233 #define CTL_DEFAULT_SECTORS_PER_TRACK 512
234 #define CTL_DEFAULT_HEADS 64
238 * Solaris is somewhat picky about how many heads and sectors per track you
239 * have defined in mode pages 3 and 4. These values seem to cause Solaris
240 * to get the capacity more or less right when you run the format tool.
241 * They still have problems when dealing with devices larger than 1TB,
242 * but there isn't anything we can do about that.
244 * For smaller LUN sizes, this ends up causing the number of cylinders to
245 * work out to 0. Solaris actually recognizes that and comes up with its
246 * own bogus geometry to fit the actual capacity of the drive. They really
247 * should just give up on geometry and stick to the read capacity
248 * information alone for modern disk drives.
250 * One thing worth mentioning about Solaris' mkfs command is that it
251 * doesn't like sectors per track values larger than 256. 512 seems to
252 * work okay for format, but causes problems when you try to make a
255 * Another caveat about these values: the product of these two values
256 * really should be a power of 2. This is because of the simplistic
257 * shift-based calculation that we have to use on the i386 platform to
258 * calculate the number of cylinders here. (If you use a divide, you end
259 * up calling __udivdi3(), which is a hardware FP call on the PC. On the
260 * XScale, it is done in software, so you can do that from inside the
263 * So for the current values (256 S/T, 128 H), we get 32768, which works
264 * very nicely for calculating cylinders.
266 * If you want to change these values so that their product is no longer a
267 * power of 2, re-visit the calculation in ctl_init_page_index(). You may
268 * need to make it a bit more complicated to get the number of cylinders
271 #define CTL_DEFAULT_SECTORS_PER_TRACK 256
272 #define CTL_DEFAULT_HEADS 128
274 #define CTL_DEFAULT_ROTATION_RATE SVPD_NON_ROTATING
276 struct ctl_page_index;
278 typedef int ctl_modesen_handler(struct ctl_scsiio *ctsio,
279 struct ctl_page_index *page_index,
281 typedef int ctl_modesel_handler(struct ctl_scsiio *ctsio,
282 struct ctl_page_index *page_index,
286 CTL_PAGE_FLAG_NONE = 0x00,
287 CTL_PAGE_FLAG_DISK_ONLY = 0x01
290 struct ctl_page_index {
295 ctl_page_flags page_flags;
296 ctl_modesen_handler *sense_handler;
297 ctl_modesel_handler *select_handler;
300 #define CTL_PAGE_CURRENT 0x00
301 #define CTL_PAGE_CHANGEABLE 0x01
302 #define CTL_PAGE_DEFAULT 0x02
303 #define CTL_PAGE_SAVED 0x03
305 #define CTL_NUM_LBP_PARAMS 4
306 #define CTL_NUM_LBP_THRESH 4
307 #define CTL_LBP_EXPONENT 11 /* 2048 sectors */
308 #define CTL_LBP_PERIOD 10 /* 10 seconds */
309 #define CTL_LBP_UA_PERIOD 300 /* 5 minutes */
311 struct ctl_logical_block_provisioning_page {
312 struct scsi_logical_block_provisioning_page main;
313 struct scsi_logical_block_provisioning_page_descr descr[CTL_NUM_LBP_THRESH];
316 static const struct ctl_page_index page_index_template[] = {
317 {SMS_RW_ERROR_RECOVERY_PAGE, 0, sizeof(struct scsi_da_rw_recovery_page), NULL,
318 CTL_PAGE_FLAG_DISK_ONLY, NULL, NULL},
319 {SMS_FORMAT_DEVICE_PAGE, 0, sizeof(struct scsi_format_page), NULL,
320 CTL_PAGE_FLAG_DISK_ONLY, NULL, NULL},
321 {SMS_RIGID_DISK_PAGE, 0, sizeof(struct scsi_rigid_disk_page), NULL,
322 CTL_PAGE_FLAG_DISK_ONLY, NULL, NULL},
323 {SMS_CACHING_PAGE, 0, sizeof(struct scsi_caching_page), NULL,
324 CTL_PAGE_FLAG_DISK_ONLY, NULL, ctl_caching_sp_handler},
325 {SMS_CONTROL_MODE_PAGE, 0, sizeof(struct scsi_control_page), NULL,
326 CTL_PAGE_FLAG_NONE, NULL, ctl_control_page_handler},
327 {SMS_INFO_EXCEPTIONS_PAGE, 0, sizeof(struct scsi_info_exceptions_page), NULL,
328 CTL_PAGE_FLAG_NONE, NULL, NULL},
329 {SMS_INFO_EXCEPTIONS_PAGE | SMPH_SPF, 0x02,
330 sizeof(struct ctl_logical_block_provisioning_page), NULL,
331 CTL_PAGE_FLAG_DISK_ONLY, NULL, NULL},
332 {SMS_VENDOR_SPECIFIC_PAGE | SMPH_SPF, DBGCNF_SUBPAGE_CODE,
333 sizeof(struct copan_debugconf_subpage), NULL, CTL_PAGE_FLAG_NONE,
334 ctl_debugconf_sp_sense_handler, ctl_debugconf_sp_select_handler},
337 #define CTL_NUM_MODE_PAGES sizeof(page_index_template)/ \
338 sizeof(page_index_template[0])
340 struct ctl_mode_pages {
341 struct scsi_da_rw_recovery_page rw_er_page[4];
342 struct scsi_format_page format_page[4];
343 struct scsi_rigid_disk_page rigid_disk_page[4];
344 struct scsi_caching_page caching_page[4];
345 struct scsi_control_page control_page[4];
346 struct scsi_info_exceptions_page ie_page[4];
347 struct ctl_logical_block_provisioning_page lbp_page[4];
348 struct copan_debugconf_subpage debugconf_subpage[4];
349 struct ctl_page_index index[CTL_NUM_MODE_PAGES];
352 static const struct ctl_page_index log_page_index_template[] = {
353 {SLS_SUPPORTED_PAGES_PAGE, 0, 0, NULL,
354 CTL_PAGE_FLAG_NONE, NULL, NULL},
355 {SLS_SUPPORTED_PAGES_PAGE, SLS_SUPPORTED_SUBPAGES_SUBPAGE, 0, NULL,
356 CTL_PAGE_FLAG_NONE, NULL, NULL},
357 {SLS_LOGICAL_BLOCK_PROVISIONING, 0, 0, NULL,
358 CTL_PAGE_FLAG_NONE, ctl_lbp_log_sense_handler, NULL},
361 #define CTL_NUM_LOG_PAGES sizeof(log_page_index_template)/ \
362 sizeof(log_page_index_template[0])
364 struct ctl_log_pages {
365 uint8_t pages_page[CTL_NUM_LOG_PAGES];
366 uint8_t subpages_page[CTL_NUM_LOG_PAGES * 2];
367 uint8_t lbp_page[12*CTL_NUM_LBP_PARAMS];
368 struct ctl_page_index index[CTL_NUM_LOG_PAGES];
371 struct ctl_lun_delay_info {
372 ctl_delay_type datamove_type;
373 uint32_t datamove_delay;
374 ctl_delay_type done_type;
379 CTL_ERR_INJ_NONE = 0x00,
380 CTL_ERR_INJ_ABORTED = 0x01
381 } ctl_err_inject_flags;
384 CTL_PR_FLAG_NONE = 0x00,
385 CTL_PR_FLAG_REGISTERED = 0x01,
386 CTL_PR_FLAG_ACTIVE_RES = 0x02
389 #define CTL_PR_ALL_REGISTRANTS 0xFFFFFFFF
390 #define CTL_PR_NO_RESERVATION 0xFFFFFFF0
398 * For report target port groups.
400 #define NUM_TARGET_PORT_GROUPS 2
402 #define CTL_WRITE_BUFFER_SIZE 262144
407 struct ctl_id target;
410 STAILQ_HEAD(,ctl_error_desc) error_list;
411 uint64_t error_serial;
412 struct ctl_softc *ctl_softc;
413 struct ctl_be_lun *be_lun;
414 struct ctl_backend_driver *backend;
416 struct ctl_lun_delay_info delay_info;
419 TAILQ_HEAD(ctl_ooaq, ctl_io_hdr) ooa_queue;
420 TAILQ_HEAD(ctl_blockq,ctl_io_hdr) blocked_queue;
421 STAILQ_ENTRY(ctl_lun) links;
422 STAILQ_ENTRY(ctl_lun) run_links;
424 uint32_t have_ca[CTL_MAX_INITIATORS >> 5];
425 struct scsi_sense_data pending_sense[CTL_MAX_INITIATORS];
427 ctl_ua_type pending_ua[CTL_MAX_INITIATORS];
429 struct ctl_mode_pages mode_pages;
430 struct ctl_log_pages log_pages;
431 struct ctl_lun_io_stats stats;
433 unsigned int PRGeneration;
434 uint64_t pr_keys[2*CTL_MAX_INITIATORS];
438 uint8_t *write_buffer;
439 struct ctl_devid *lun_devid;
440 TAILQ_HEAD(tpc_lists, tpc_list) tpc_lists;
444 CTL_FLAG_REAL_SYNC = 0x02,
445 CTL_FLAG_MASTER_SHELF = 0x04
448 #define CTL_MAX_THREADS 16
451 struct mtx_padalign queue_lock;
452 struct ctl_softc *ctl_softc;
453 struct thread *thread;
454 STAILQ_HEAD(, ctl_io_hdr) incoming_queue;
455 STAILQ_HEAD(, ctl_io_hdr) rtr_queue;
456 STAILQ_HEAD(, ctl_io_hdr) done_queue;
457 STAILQ_HEAD(, ctl_io_hdr) isc_queue;
465 struct ctl_id target;
470 int inquiry_pq_no_lun;
471 struct sysctl_ctx_list sysctl_ctx;
472 struct sysctl_oid *sysctl_tree;
473 struct ctl_ioctl_info ioctl_info;
474 struct ctl_io_pool *internal_pool;
475 struct ctl_io_pool *emergency_pool;
476 struct ctl_io_pool *othersc_pool;
477 struct proc *ctl_proc;
479 uint32_t ctl_lun_mask[(CTL_MAX_LUNS + 31) / 32];
480 struct ctl_lun *ctl_luns[CTL_MAX_LUNS];
481 uint32_t ctl_port_mask[(CTL_MAX_PORTS + 31) / 32];
482 STAILQ_HEAD(, ctl_lun) lun_list;
483 STAILQ_HEAD(, ctl_be_lun) pending_lun_queue;
484 uint32_t num_frontends;
485 STAILQ_HEAD(, ctl_frontend) fe_list;
487 STAILQ_HEAD(, ctl_port) port_list;
488 struct ctl_port *ctl_ports[CTL_MAX_PORTS];
489 uint32_t num_backends;
490 STAILQ_HEAD(, ctl_backend_driver) be_list;
491 struct mtx pool_lock;
493 uint32_t cur_pool_id;
494 STAILQ_HEAD(, ctl_io_pool) io_pools;
495 struct ctl_thread threads[CTL_MAX_THREADS];
496 TAILQ_HEAD(tpc_tokens, tpc_token) tpc_tokens;
497 struct callout tpc_timeout;
502 extern const struct ctl_cmd_entry ctl_cmd_table[256];
504 uint32_t ctl_get_initindex(struct ctl_nexus *nexus);
505 uint32_t ctl_get_resindex(struct ctl_nexus *nexus);
506 uint32_t ctl_port_idx(int port_num);
507 int ctl_pool_create(struct ctl_softc *ctl_softc, ctl_pool_type pool_type,
508 uint32_t total_ctl_io, struct ctl_io_pool **npool);
509 void ctl_pool_free(struct ctl_io_pool *pool);
510 int ctl_scsi_release(struct ctl_scsiio *ctsio);
511 int ctl_scsi_reserve(struct ctl_scsiio *ctsio);
512 int ctl_start_stop(struct ctl_scsiio *ctsio);
513 int ctl_sync_cache(struct ctl_scsiio *ctsio);
514 int ctl_format(struct ctl_scsiio *ctsio);
515 int ctl_read_buffer(struct ctl_scsiio *ctsio);
516 int ctl_write_buffer(struct ctl_scsiio *ctsio);
517 int ctl_write_same(struct ctl_scsiio *ctsio);
518 int ctl_unmap(struct ctl_scsiio *ctsio);
519 int ctl_mode_select(struct ctl_scsiio *ctsio);
520 int ctl_mode_sense(struct ctl_scsiio *ctsio);
521 int ctl_log_sense(struct ctl_scsiio *ctsio);
522 int ctl_read_capacity(struct ctl_scsiio *ctsio);
523 int ctl_read_capacity_16(struct ctl_scsiio *ctsio);
524 int ctl_read_defect(struct ctl_scsiio *ctsio);
525 int ctl_read_write(struct ctl_scsiio *ctsio);
526 int ctl_cnw(struct ctl_scsiio *ctsio);
527 int ctl_report_luns(struct ctl_scsiio *ctsio);
528 int ctl_request_sense(struct ctl_scsiio *ctsio);
529 int ctl_tur(struct ctl_scsiio *ctsio);
530 int ctl_verify(struct ctl_scsiio *ctsio);
531 int ctl_inquiry(struct ctl_scsiio *ctsio);
532 int ctl_persistent_reserve_in(struct ctl_scsiio *ctsio);
533 int ctl_persistent_reserve_out(struct ctl_scsiio *ctsio);
534 int ctl_report_tagret_port_groups(struct ctl_scsiio *ctsio);
535 int ctl_report_supported_opcodes(struct ctl_scsiio *ctsio);
536 int ctl_report_supported_tmf(struct ctl_scsiio *ctsio);
537 int ctl_report_timestamp(struct ctl_scsiio *ctsio);
538 int ctl_isc(struct ctl_scsiio *ctsio);
540 void ctl_tpc_init(struct ctl_softc *softc);
541 void ctl_tpc_shutdown(struct ctl_softc *softc);
542 void ctl_tpc_lun_init(struct ctl_lun *lun);
543 void ctl_tpc_lun_shutdown(struct ctl_lun *lun);
544 int ctl_inquiry_evpd_tpc(struct ctl_scsiio *ctsio, int alloc_len);
545 int ctl_receive_copy_status_lid1(struct ctl_scsiio *ctsio);
546 int ctl_receive_copy_failure_details(struct ctl_scsiio *ctsio);
547 int ctl_receive_copy_status_lid4(struct ctl_scsiio *ctsio);
548 int ctl_receive_copy_operating_parameters(struct ctl_scsiio *ctsio);
549 int ctl_extended_copy_lid1(struct ctl_scsiio *ctsio);
550 int ctl_extended_copy_lid4(struct ctl_scsiio *ctsio);
551 int ctl_copy_operation_abort(struct ctl_scsiio *ctsio);
552 int ctl_populate_token(struct ctl_scsiio *ctsio);
553 int ctl_write_using_token(struct ctl_scsiio *ctsio);
554 int ctl_receive_rod_token_information(struct ctl_scsiio *ctsio);
555 int ctl_report_all_rod_tokens(struct ctl_scsiio *ctsio);
559 #endif /* _CTL_PRIVATE_H_ */