1843e1988Sjohnlev /* 2843e1988Sjohnlev * CDDL HEADER START 3843e1988Sjohnlev * 4843e1988Sjohnlev * The contents of this file are subject to the terms of the 5843e1988Sjohnlev * Common Development and Distribution License (the "License"). 6843e1988Sjohnlev * You may not use this file except in compliance with the License. 7843e1988Sjohnlev * 8843e1988Sjohnlev * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9843e1988Sjohnlev * or http://www.opensolaris.org/os/licensing. 10843e1988Sjohnlev * See the License for the specific language governing permissions 11843e1988Sjohnlev * and limitations under the License. 12843e1988Sjohnlev * 13843e1988Sjohnlev * When distributing Covered Code, include this CDDL HEADER in each 14843e1988Sjohnlev * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15843e1988Sjohnlev * If applicable, add the following below this CDDL HEADER, with the 16843e1988Sjohnlev * fields enclosed by brackets "[]" replaced with your own identifying 17843e1988Sjohnlev * information: Portions Copyright [yyyy] [name of copyright owner] 18843e1988Sjohnlev * 19843e1988Sjohnlev * CDDL HEADER END 20843e1988Sjohnlev */ 21843e1988Sjohnlev 22843e1988Sjohnlev /* 237f0b8309SEdward Pilatowicz * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24843e1988Sjohnlev * Use is subject to license terms. 25843e1988Sjohnlev */ 26843e1988Sjohnlev 27843e1988Sjohnlev 28843e1988Sjohnlev #ifndef _SYS_XDB_H 29843e1988Sjohnlev #define _SYS_XDB_H 30843e1988Sjohnlev 31843e1988Sjohnlev #ifdef __cplusplus 32843e1988Sjohnlev extern "C" { 33843e1988Sjohnlev #endif 34843e1988Sjohnlev 35843e1988Sjohnlev #define XDB_DBG_ALL 0xf 36843e1988Sjohnlev #define XDB_DBG_IO 0x1 37843e1988Sjohnlev #define XDB_DBG_INFO 0x2 38843e1988Sjohnlev #define XDB_DBPRINT(lvl, fmt) { if (xdb_debug & lvl) cmn_err fmt; } 39843e1988Sjohnlev 40843e1988Sjohnlev /* 41843e1988Sjohnlev * Info of the exported blk device 42843e1988Sjohnlev */ 437f0b8309SEdward Pilatowicz #define XDB_DEV_RO (1 << 0) /* backend and frontend are read-only */ 447f0b8309SEdward Pilatowicz #define XDB_DEV_BE_LOFI (1 << 1) /* backend device is a lofi device */ 457f0b8309SEdward Pilatowicz #define XDB_DEV_BE_RMB (1 << 2) /* backend device is removable */ 467f0b8309SEdward Pilatowicz #define XDB_DEV_BE_CD (1 << 3) /* backend device is cdrom */ 477f0b8309SEdward Pilatowicz #define XDB_DEV_FE_CD (1 << 4) /* frontend device is cdrom */ 487f0b8309SEdward Pilatowicz 49843e1988Sjohnlev #define XDB_IS_RO(vdp) ((vdp)->xs_type & XDB_DEV_RO) 507f0b8309SEdward Pilatowicz #define XDB_IS_BE_LOFI(vdp) ((vdp)->xs_type & XDB_DEV_BE_LOFI) 517f0b8309SEdward Pilatowicz #define XDB_IS_BE_RMB(vdp) ((vdp)->xs_type & XDB_DEV_BE_RMB) 527f0b8309SEdward Pilatowicz #define XDB_IS_BE_CD(vdp) ((vdp)->xs_type & XDB_DEV_BE_CD) 537f0b8309SEdward Pilatowicz #define XDB_IS_FE_CD(vdp) ((vdp)->xs_type & XDB_DEV_FE_CD) 54843e1988Sjohnlev 55843e1988Sjohnlev /* 56843e1988Sjohnlev * Other handy macrosx 57843e1988Sjohnlev */ 58843e1988Sjohnlev #define XDB_MINOR2INST(m) (int)(m) 59843e1988Sjohnlev #define XDB_INST2MINOR(i) (minor_t)(i) 60843e1988Sjohnlev #define XDB_INST2SOFTS(instance) \ 61843e1988Sjohnlev ((xdb_t *)ddi_get_soft_state(xdb_statep, (instance))) 62a576ab5bSrab #define XDB_MAX_IO_PAGES(v) ((v)->xs_nentry * BLKIF_MAX_SEGMENTS_PER_REQUEST) 63843e1988Sjohnlev /* get kva of a mapped-in page coresponding to (xreq-index, seg) pair */ 64843e1988Sjohnlev #define XDB_IOPAGE_VA(_pagebase, _xreqidx, _seg) \ 65843e1988Sjohnlev ((_pagebase) + ((_xreqidx) \ 66843e1988Sjohnlev * BLKIF_MAX_SEGMENTS_PER_REQUEST \ 67843e1988Sjohnlev + (_seg)) * PAGESIZE) 68843e1988Sjohnlev #define XDB_XREQ2BP(xreq) (&(xreq)->xr_buf) 69843e1988Sjohnlev #define XDB_BP2XREQ(bp) \ 70843e1988Sjohnlev ((xdb_request_t *)((char *)(bp) - offsetof(xdb_request_t, xr_buf))) 71843e1988Sjohnlev 72843e1988Sjohnlev /* describe one blkif segment */ 73843e1988Sjohnlev typedef struct xdb_seg { 74843e1988Sjohnlev uint8_t fs; /* start sector # within this page (segment) */ 75843e1988Sjohnlev uint8_t ls; /* end sector # within this page (segment) */ 76843e1988Sjohnlev } xdb_seg_t; 77843e1988Sjohnlev 78843e1988Sjohnlev typedef struct xdb xdb_t; 79843e1988Sjohnlev 80843e1988Sjohnlev /* one blkif_request_t matches one xdb_request_t */ 81843e1988Sjohnlev typedef struct xdb_request { 82843e1988Sjohnlev /* buf associated with this I/O request */ 83843e1988Sjohnlev buf_t xr_buf; 84843e1988Sjohnlev /* softstate instance associated with this I/O request */ 85843e1988Sjohnlev xdb_t *xr_vdp; 86843e1988Sjohnlev /* the next segment we're going to process */ 87843e1988Sjohnlev int xr_curseg; 88843e1988Sjohnlev /* index of this xdb_request_t in vdp->xs_req */ 89843e1988Sjohnlev int xr_idx; 90843e1988Sjohnlev /* next index for a statical linked list */ 91843e1988Sjohnlev int xr_next; 92843e1988Sjohnlev /* 'id' copied from blkif_request_t */ 93843e1988Sjohnlev uint64_t xr_id; 94843e1988Sjohnlev /* 'operation' copied from blkif_request_t */ 95843e1988Sjohnlev uint8_t xr_op; 96843e1988Sjohnlev /* how many pages(segments) in this I/O request */ 97843e1988Sjohnlev uint8_t xr_buf_pages; 98843e1988Sjohnlev /* all segments of this I/O request */ 99843e1988Sjohnlev xdb_seg_t xr_segs[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 100843e1988Sjohnlev /* all grant table handles used in this I/O request */ 101843e1988Sjohnlev grant_handle_t xr_page_hdls[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 102843e1988Sjohnlev struct page xr_plist[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 103843e1988Sjohnlev struct page *xr_pplist[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 104843e1988Sjohnlev } xdb_request_t; 105843e1988Sjohnlev 106843e1988Sjohnlev /* Soft state data structure for each backend vbd */ 107843e1988Sjohnlev struct xdb { 108843e1988Sjohnlev /* devinfo node pointer of this xdb */ 109843e1988Sjohnlev dev_info_t *xs_dip; 110843e1988Sjohnlev /* coresponding frontend domain id */ 111843e1988Sjohnlev domid_t xs_peer; 112843e1988Sjohnlev /* read-only, removable, cdrom? */ 113843e1988Sjohnlev uint32_t xs_type; 114843e1988Sjohnlev /* # of total sectors */ 115843e1988Sjohnlev uint64_t xs_sectors; 116*65908c77Syu, larry liu - Sun Microsystems - Beijing China /* sector size if existed */ 117*65908c77Syu, larry liu - Sun Microsystems - Beijing China uint_t xs_sec_size; 118843e1988Sjohnlev /* blkif I/O request ring buffer */ 119843e1988Sjohnlev xendev_ring_t *xs_ring; 120843e1988Sjohnlev /* handle to access the ring buffer */ 121843e1988Sjohnlev ddi_acc_handle_t xs_ring_hdl; 122843e1988Sjohnlev ldi_ident_t xs_ldi_li; 123843e1988Sjohnlev ldi_handle_t xs_ldi_hdl; 124843e1988Sjohnlev /* base kva for mapped-in I/O page from frontend domain */ 125843e1988Sjohnlev caddr_t xs_iopage_va; 126843e1988Sjohnlev /* mutex lock for I/O related code path */ 127843e1988Sjohnlev kmutex_t xs_iomutex; 128843e1988Sjohnlev /* 129843e1988Sjohnlev * mutex lock for event handling related code path 130843e1988Sjohnlev * need to be grabbed before xs_iomutex 131843e1988Sjohnlev */ 132843e1988Sjohnlev kmutex_t xs_cbmutex; 133843e1988Sjohnlev /* # of on-going I/O buf in backend domain */ 134843e1988Sjohnlev uint_t xs_ionum; 135843e1988Sjohnlev /* task thread for pushing buf to underlying target driver */ 136843e1988Sjohnlev ddi_taskq_t *xs_iotaskq; 137843e1988Sjohnlev /* cv used in I/O code path, protected by xs_iomutex */ 138843e1988Sjohnlev kcondvar_t xs_iocv; 139843e1988Sjohnlev kcondvar_t xs_ionumcv; 140843e1988Sjohnlev /* 141843e1988Sjohnlev * head and tail of linked list for I/O bufs need to be pushed to 142843e1988Sjohnlev * underlying target driver 143843e1988Sjohnlev */ 144843e1988Sjohnlev buf_t *xs_f_iobuf; 145843e1988Sjohnlev buf_t *xs_l_iobuf; 146843e1988Sjohnlev /* head of free list of xdb_request_t */ 147843e1988Sjohnlev int xs_free_req; 148843e1988Sjohnlev /* pre-allocated xdb_request_t pool */ 149a576ab5bSrab xdb_request_t *xs_req; 150843e1988Sjohnlev kstat_t *xs_kstats; 151843e1988Sjohnlev uint64_t xs_stat_req_reads; 152843e1988Sjohnlev uint64_t xs_stat_req_writes; 153843e1988Sjohnlev uint64_t xs_stat_req_barriers; 154843e1988Sjohnlev uint64_t xs_stat_req_flushes; 155a576ab5bSrab enum blkif_protocol xs_blk_protocol; 156a576ab5bSrab size_t xs_nentry; 157a576ab5bSrab size_t xs_entrysize; 1587f0b8309SEdward Pilatowicz 1597f0b8309SEdward Pilatowicz /* Protected by xs_cbmutex */ 1607f0b8309SEdward Pilatowicz boolean_t xs_hp_connected; /* hot plug scripts have run */ 1617f0b8309SEdward Pilatowicz boolean_t xs_fe_initialised; /* frontend is initialized */ 1627f0b8309SEdward Pilatowicz char *xs_lofi_path; 1637f0b8309SEdward Pilatowicz char *xs_params_path; 1647f0b8309SEdward Pilatowicz struct xenbus_watch *xs_watch_params; 1657f0b8309SEdward Pilatowicz struct xenbus_watch *xs_watch_media_req; 1667f0b8309SEdward Pilatowicz ddi_taskq_t *xs_watch_taskq; 1677f0b8309SEdward Pilatowicz int xs_watch_taskq_count; 1687f0b8309SEdward Pilatowicz 1697f0b8309SEdward Pilatowicz /* Protected by xs_cbmutex and xs_iomutex */ 1707f0b8309SEdward Pilatowicz boolean_t xs_if_connected; /* connected to frontend */ 1717f0b8309SEdward Pilatowicz 1727f0b8309SEdward Pilatowicz /* Protected by xs_iomutex */ 1737f0b8309SEdward Pilatowicz boolean_t xs_send_buf; 1747f0b8309SEdward Pilatowicz 175843e1988Sjohnlev #ifdef DEBUG 176a576ab5bSrab uint64_t *page_addrs; /* for debug aid */ 177843e1988Sjohnlev #endif /* DEBUG */ 178843e1988Sjohnlev }; 179843e1988Sjohnlev 180843e1988Sjohnlev #ifdef __cplusplus 181843e1988Sjohnlev } 182843e1988Sjohnlev #endif 183843e1988Sjohnlev 184843e1988Sjohnlev #endif /* _SYS_XDB_H */ 185