13f7d54a6SGarrett D'Amore /* 23f7d54a6SGarrett D'Amore * CDDL HEADER START 33f7d54a6SGarrett D'Amore * 43f7d54a6SGarrett D'Amore * The contents of this file are subject to the terms of the 53f7d54a6SGarrett D'Amore * Common Development and Distribution License (the "License"). 63f7d54a6SGarrett D'Amore * You may not use this file except in compliance with the License. 73f7d54a6SGarrett D'Amore * 83f7d54a6SGarrett D'Amore * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 93f7d54a6SGarrett D'Amore * or http://www.opensolaris.org/os/licensing. 103f7d54a6SGarrett D'Amore * See the License for the specific language governing permissions 113f7d54a6SGarrett D'Amore * and limitations under the License. 123f7d54a6SGarrett D'Amore * 133f7d54a6SGarrett D'Amore * When distributing Covered Code, include this CDDL HEADER in each 143f7d54a6SGarrett D'Amore * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 153f7d54a6SGarrett D'Amore * If applicable, add the following below this CDDL HEADER, with the 163f7d54a6SGarrett D'Amore * fields enclosed by brackets "[]" replaced with your own identifying 173f7d54a6SGarrett D'Amore * information: Portions Copyright [yyyy] [name of copyright owner] 183f7d54a6SGarrett D'Amore * 193f7d54a6SGarrett D'Amore * CDDL HEADER END 203f7d54a6SGarrett D'Amore */ 213f7d54a6SGarrett D'Amore /* 2259d8f100SGarrett D'Amore * Copyright 2012 DEY Storage Systems, Inc. All rights reserved. 23*fa27e351SHans Rosenfeld * Copyright 2016 Nexenta Systems, Inc. All rights reserved. 243f7d54a6SGarrett D'Amore * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 253f7d54a6SGarrett D'Amore */ 263f7d54a6SGarrett D'Amore 273f7d54a6SGarrett D'Amore #ifndef _SYS_BLKDEV_H 283f7d54a6SGarrett D'Amore #define _SYS_BLKDEV_H 293f7d54a6SGarrett D'Amore 303f7d54a6SGarrett D'Amore #include <sys/types.h> 313f7d54a6SGarrett D'Amore #include <sys/ksynch.h> 323f7d54a6SGarrett D'Amore #include <sys/ddi.h> 333f7d54a6SGarrett D'Amore #include <sys/sunddi.h> 343f7d54a6SGarrett D'Amore 353f7d54a6SGarrett D'Amore #ifdef __cplusplus 363f7d54a6SGarrett D'Amore extern "C" { 373f7d54a6SGarrett D'Amore #endif 383f7d54a6SGarrett D'Amore 393f7d54a6SGarrett D'Amore /* 403f7d54a6SGarrett D'Amore * This describes a fairly simple block device. The idea here is that 413f7d54a6SGarrett D'Amore * these things want to take advantage of the common labelling support, 423f7d54a6SGarrett D'Amore * but do not need all the capabilities of SCSA. So we make quite a few 433f7d54a6SGarrett D'Amore * simplifications: 443f7d54a6SGarrett D'Amore * 4532ce6b81SHans Rosenfeld * 1) Device block size is a power of 2 greater or equal to 512 bytes. 4632ce6b81SHans Rosenfeld * An optional physical block size can be reported if the underlying 4732ce6b81SHans Rosenfeld * device uses larger block sizes internally, so that writes can be 4832ce6b81SHans Rosenfeld * aligned properly. 493f7d54a6SGarrett D'Amore * 503f7d54a6SGarrett D'Amore * 2) Non-rotating media. We assume a simple linear layout. 513f7d54a6SGarrett D'Amore * 523f7d54a6SGarrett D'Amore * 3) Fixed queue depth, for each device. The adapter driver reports 533f7d54a6SGarrett D'Amore * the queue depth at registration. We don't have any form of 543f7d54a6SGarrett D'Amore * dynamic flow control. 553f7d54a6SGarrett D'Amore * 563f7d54a6SGarrett D'Amore * 4) Negligible power management support. The framework does not support 573f7d54a6SGarrett D'Amore * fine grained power management. If the adapter driver wants to use 583f7d54a6SGarrett D'Amore * such, it will need to manage power on its own. 593f7d54a6SGarrett D'Amore * 603f7d54a6SGarrett D'Amore * 5) Suspend/resume support managed by the adapter driver. We don't 613f7d54a6SGarrett D'Amore * support suspend/resume directly. The adapter device driver will 623f7d54a6SGarrett D'Amore * need to manage this on its own behalf. 633f7d54a6SGarrett D'Amore * 643f7d54a6SGarrett D'Amore * 6) No request priorities. Transfers are assumed to execute in 653f7d54a6SGarrett D'Amore * roughly FIFO order. The adapter driver may reorder them, but the 663f7d54a6SGarrett D'Amore * submitter has no control over that. 673f7d54a6SGarrett D'Amore * 683f7d54a6SGarrett D'Amore * 7) No request cancellation. Once submitted, the job completes or 693f7d54a6SGarrett D'Amore * fails. It cannot be canceled. 703f7d54a6SGarrett D'Amore * 713f7d54a6SGarrett D'Amore * 8) Limited support for removable media. There is no support for 723f7d54a6SGarrett D'Amore * locking bay doors or mechanised media bays. This could be 733f7d54a6SGarrett D'Amore * added, but at present the only such interesting devices are 743f7d54a6SGarrett D'Amore * covered by the SCSI disk driver. 753f7d54a6SGarrett D'Amore */ 763f7d54a6SGarrett D'Amore 773f7d54a6SGarrett D'Amore typedef struct bd_handle *bd_handle_t; 783f7d54a6SGarrett D'Amore typedef struct bd_xfer bd_xfer_t; 793f7d54a6SGarrett D'Amore typedef struct bd_drive bd_drive_t; 803f7d54a6SGarrett D'Amore typedef struct bd_media bd_media_t; 813f7d54a6SGarrett D'Amore typedef struct bd_ops bd_ops_t; 823f7d54a6SGarrett D'Amore 833f7d54a6SGarrett D'Amore 843f7d54a6SGarrett D'Amore struct bd_xfer { 853f7d54a6SGarrett D'Amore /* 863f7d54a6SGarrett D'Amore * NB: If using DMA the br_ndmac will be non-zero. Otherwise 873f7d54a6SGarrett D'Amore * the br_kaddr will be non-NULL. 883f7d54a6SGarrett D'Amore */ 893f7d54a6SGarrett D'Amore diskaddr_t x_blkno; 903f7d54a6SGarrett D'Amore size_t x_nblks; 913f7d54a6SGarrett D'Amore ddi_dma_handle_t x_dmah; 923f7d54a6SGarrett D'Amore ddi_dma_cookie_t x_dmac; 933f7d54a6SGarrett D'Amore unsigned x_ndmac; 943f7d54a6SGarrett D'Amore caddr_t x_kaddr; 9586e3bca6SGarrett D'Amore unsigned x_flags; 963f7d54a6SGarrett D'Amore }; 973f7d54a6SGarrett D'Amore 983f7d54a6SGarrett D'Amore #define BD_XFER_POLL (1U << 0) /* no interrupts (dump) */ 993f7d54a6SGarrett D'Amore 1003f7d54a6SGarrett D'Amore struct bd_drive { 1013f7d54a6SGarrett D'Amore uint32_t d_qsize; 1023f7d54a6SGarrett D'Amore uint32_t d_maxxfer; 1033f7d54a6SGarrett D'Amore boolean_t d_removable; 1043f7d54a6SGarrett D'Amore boolean_t d_hotpluggable; 1053f7d54a6SGarrett D'Amore int d_target; 1063f7d54a6SGarrett D'Amore int d_lun; 107510a6847SHans Rosenfeld size_t d_vendor_len; 108510a6847SHans Rosenfeld char *d_vendor; 109510a6847SHans Rosenfeld size_t d_product_len; 110510a6847SHans Rosenfeld char *d_product; 111bef9e21aSHans Rosenfeld size_t d_model_len; 112bef9e21aSHans Rosenfeld char *d_model; 113510a6847SHans Rosenfeld size_t d_serial_len; 114510a6847SHans Rosenfeld char *d_serial; 115510a6847SHans Rosenfeld size_t d_revision_len; 116510a6847SHans Rosenfeld char *d_revision; 117*fa27e351SHans Rosenfeld uint8_t d_eui64[8]; 1183f7d54a6SGarrett D'Amore }; 1193f7d54a6SGarrett D'Amore 1203f7d54a6SGarrett D'Amore struct bd_media { 1213f7d54a6SGarrett D'Amore /* 1223f7d54a6SGarrett D'Amore * NB: The block size must be a power of two not less than 1233f7d54a6SGarrett D'Amore * DEV_BSIZE (512). Other values of the block size will 1243f7d54a6SGarrett D'Amore * simply not function and the media will be rejected. 1253f7d54a6SGarrett D'Amore * 1263f7d54a6SGarrett D'Amore * The block size must also divide evenly into the device's 1273f7d54a6SGarrett D'Amore * d_maxxfer field. If the maxxfer is a power of two larger 1283f7d54a6SGarrett D'Amore * than the block size, then this will automatically be 1293f7d54a6SGarrett D'Amore * satisfied. 13032ce6b81SHans Rosenfeld * 13132ce6b81SHans Rosenfeld * The physical block size (m_pblksize) must be 0 or a power 13232ce6b81SHans Rosenfeld * of two not less than the block size. 1333f7d54a6SGarrett D'Amore */ 1343f7d54a6SGarrett D'Amore uint64_t m_nblks; 1353f7d54a6SGarrett D'Amore uint32_t m_blksize; 1363f7d54a6SGarrett D'Amore boolean_t m_readonly; 13759d8f100SGarrett D'Amore boolean_t m_solidstate; 13832ce6b81SHans Rosenfeld uint32_t m_pblksize; 1393f7d54a6SGarrett D'Amore }; 1403f7d54a6SGarrett D'Amore 1413f7d54a6SGarrett D'Amore #define BD_INFO_FLAG_REMOVABLE (1U << 0) 1423f7d54a6SGarrett D'Amore #define BD_INFO_FLAG_HOTPLUGGABLE (1U << 1) 1433f7d54a6SGarrett D'Amore #define BD_INFO_FLAG_READ_ONLY (1U << 2) 1443f7d54a6SGarrett D'Amore 1453f7d54a6SGarrett D'Amore struct bd_ops { 1463f7d54a6SGarrett D'Amore int o_version; 1473f7d54a6SGarrett D'Amore void (*o_drive_info)(void *, bd_drive_t *); 1483f7d54a6SGarrett D'Amore int (*o_media_info)(void *, bd_media_t *); 1493f7d54a6SGarrett D'Amore int (*o_devid_init)(void *, dev_info_t *, ddi_devid_t *); 1503f7d54a6SGarrett D'Amore int (*o_sync_cache)(void *, bd_xfer_t *); 1513f7d54a6SGarrett D'Amore int (*o_read)(void *, bd_xfer_t *); 1523f7d54a6SGarrett D'Amore int (*o_write)(void *, bd_xfer_t *); 1533f7d54a6SGarrett D'Amore }; 1543f7d54a6SGarrett D'Amore 1553f7d54a6SGarrett D'Amore #define BD_OPS_VERSION_0 0 1563f7d54a6SGarrett D'Amore 157bef9e21aSHans Rosenfeld struct bd_errstats { 158bef9e21aSHans Rosenfeld /* these are managed by blkdev itself */ 159bef9e21aSHans Rosenfeld kstat_named_t bd_softerrs; 160bef9e21aSHans Rosenfeld kstat_named_t bd_harderrs; 161bef9e21aSHans Rosenfeld kstat_named_t bd_transerrs; 162bef9e21aSHans Rosenfeld kstat_named_t bd_model; 163bef9e21aSHans Rosenfeld kstat_named_t bd_vid; 164bef9e21aSHans Rosenfeld kstat_named_t bd_pid; 165bef9e21aSHans Rosenfeld kstat_named_t bd_revision; 166bef9e21aSHans Rosenfeld kstat_named_t bd_serial; 167bef9e21aSHans Rosenfeld kstat_named_t bd_capacity; 168bef9e21aSHans Rosenfeld 169bef9e21aSHans Rosenfeld /* the following are updated on behalf of the HW driver */ 170bef9e21aSHans Rosenfeld kstat_named_t bd_rq_media_err; 171bef9e21aSHans Rosenfeld kstat_named_t bd_rq_ntrdy_err; 172bef9e21aSHans Rosenfeld kstat_named_t bd_rq_nodev_err; 173bef9e21aSHans Rosenfeld kstat_named_t bd_rq_recov_err; 174bef9e21aSHans Rosenfeld kstat_named_t bd_rq_illrq_err; 175bef9e21aSHans Rosenfeld kstat_named_t bd_rq_pfa_err; 176bef9e21aSHans Rosenfeld }; 177bef9e21aSHans Rosenfeld 178bef9e21aSHans Rosenfeld #define BD_ERR_MEDIA 0 179bef9e21aSHans Rosenfeld #define BD_ERR_NTRDY 1 180bef9e21aSHans Rosenfeld #define BD_ERR_NODEV 2 181bef9e21aSHans Rosenfeld #define BD_ERR_RECOV 3 182bef9e21aSHans Rosenfeld #define BD_ERR_ILLRQ 4 183bef9e21aSHans Rosenfeld #define BD_ERR_PFA 5 184bef9e21aSHans Rosenfeld 1853f7d54a6SGarrett D'Amore /* 1863f7d54a6SGarrett D'Amore * Note, one handler *per* address. Drivers with multiple targets at 1873f7d54a6SGarrett D'Amore * different addresses must use separate handles. 1883f7d54a6SGarrett D'Amore */ 1893f7d54a6SGarrett D'Amore bd_handle_t bd_alloc_handle(void *, bd_ops_t *, ddi_dma_attr_t *, int); 1903f7d54a6SGarrett D'Amore void bd_free_handle(bd_handle_t); 1913f7d54a6SGarrett D'Amore int bd_attach_handle(dev_info_t *, bd_handle_t); 1923f7d54a6SGarrett D'Amore int bd_detach_handle(bd_handle_t); 1933f7d54a6SGarrett D'Amore void bd_state_change(bd_handle_t); 1943f7d54a6SGarrett D'Amore void bd_xfer_done(bd_xfer_t *, int); 195bef9e21aSHans Rosenfeld void bd_error(bd_xfer_t *, int); 1963f7d54a6SGarrett D'Amore void bd_mod_init(struct dev_ops *); 1973f7d54a6SGarrett D'Amore void bd_mod_fini(struct dev_ops *); 1983f7d54a6SGarrett D'Amore 1993f7d54a6SGarrett D'Amore #ifdef __cplusplus 2003f7d54a6SGarrett D'Amore } 2013f7d54a6SGarrett D'Amore #endif 2023f7d54a6SGarrett D'Amore 2033f7d54a6SGarrett D'Amore #endif /* _SYS_BLKDEV_H */ 204