15084Sjohnlev /* 25084Sjohnlev * CDDL HEADER START 35084Sjohnlev * 45084Sjohnlev * The contents of this file are subject to the terms of the 55084Sjohnlev * Common Development and Distribution License (the "License"). 65084Sjohnlev * You may not use this file except in compliance with the License. 75084Sjohnlev * 85084Sjohnlev * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95084Sjohnlev * or http://www.opensolaris.org/os/licensing. 105084Sjohnlev * See the License for the specific language governing permissions 115084Sjohnlev * and limitations under the License. 125084Sjohnlev * 135084Sjohnlev * When distributing Covered Code, include this CDDL HEADER in each 145084Sjohnlev * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155084Sjohnlev * If applicable, add the following below this CDDL HEADER, with the 165084Sjohnlev * fields enclosed by brackets "[]" replaced with your own identifying 175084Sjohnlev * information: Portions Copyright [yyyy] [name of copyright owner] 185084Sjohnlev * 195084Sjohnlev * CDDL HEADER END 205084Sjohnlev */ 215084Sjohnlev 225084Sjohnlev /* 238863SEdward.Pilatowicz@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 245084Sjohnlev * Use is subject to license terms. 255084Sjohnlev */ 265084Sjohnlev 275084Sjohnlev 285084Sjohnlev #ifndef _SYS_XDB_H 295084Sjohnlev #define _SYS_XDB_H 305084Sjohnlev 315084Sjohnlev #ifdef __cplusplus 325084Sjohnlev extern "C" { 335084Sjohnlev #endif 345084Sjohnlev 355084Sjohnlev #define XDB_DBG_ALL 0xf 365084Sjohnlev #define XDB_DBG_IO 0x1 375084Sjohnlev #define XDB_DBG_INFO 0x2 385084Sjohnlev #define XDB_DBPRINT(lvl, fmt) { if (xdb_debug & lvl) cmn_err fmt; } 395084Sjohnlev 405084Sjohnlev /* 415084Sjohnlev * Info of the exported blk device 425084Sjohnlev */ 438863SEdward.Pilatowicz@Sun.COM #define XDB_DEV_RO (1 << 0) /* backend and frontend are read-only */ 448863SEdward.Pilatowicz@Sun.COM #define XDB_DEV_BE_LOFI (1 << 1) /* backend device is a lofi device */ 458863SEdward.Pilatowicz@Sun.COM #define XDB_DEV_BE_RMB (1 << 2) /* backend device is removable */ 468863SEdward.Pilatowicz@Sun.COM #define XDB_DEV_BE_CD (1 << 3) /* backend device is cdrom */ 478863SEdward.Pilatowicz@Sun.COM #define XDB_DEV_FE_CD (1 << 4) /* frontend device is cdrom */ 485084Sjohnlev 498863SEdward.Pilatowicz@Sun.COM #define XDB_IS_RO(vdp) ((vdp)->xs_type & XDB_DEV_RO) 508863SEdward.Pilatowicz@Sun.COM #define XDB_IS_BE_LOFI(vdp) ((vdp)->xs_type & XDB_DEV_BE_LOFI) 518863SEdward.Pilatowicz@Sun.COM #define XDB_IS_BE_RMB(vdp) ((vdp)->xs_type & XDB_DEV_BE_RMB) 528863SEdward.Pilatowicz@Sun.COM #define XDB_IS_BE_CD(vdp) ((vdp)->xs_type & XDB_DEV_BE_CD) 538863SEdward.Pilatowicz@Sun.COM #define XDB_IS_FE_CD(vdp) ((vdp)->xs_type & XDB_DEV_FE_CD) 545084Sjohnlev 555084Sjohnlev /* 565084Sjohnlev * Other handy macrosx 575084Sjohnlev */ 585084Sjohnlev #define XDB_MINOR2INST(m) (int)(m) 595084Sjohnlev #define XDB_INST2MINOR(i) (minor_t)(i) 605084Sjohnlev #define XDB_INST2SOFTS(instance) \ 615084Sjohnlev ((xdb_t *)ddi_get_soft_state(xdb_statep, (instance))) 626144Srab #define XDB_MAX_IO_PAGES(v) ((v)->xs_nentry * BLKIF_MAX_SEGMENTS_PER_REQUEST) 635084Sjohnlev /* get kva of a mapped-in page coresponding to (xreq-index, seg) pair */ 645084Sjohnlev #define XDB_IOPAGE_VA(_pagebase, _xreqidx, _seg) \ 655084Sjohnlev ((_pagebase) + ((_xreqidx) \ 665084Sjohnlev * BLKIF_MAX_SEGMENTS_PER_REQUEST \ 675084Sjohnlev + (_seg)) * PAGESIZE) 685084Sjohnlev #define XDB_XREQ2BP(xreq) (&(xreq)->xr_buf) 695084Sjohnlev #define XDB_BP2XREQ(bp) \ 705084Sjohnlev ((xdb_request_t *)((char *)(bp) - offsetof(xdb_request_t, xr_buf))) 715084Sjohnlev 725084Sjohnlev /* describe one blkif segment */ 735084Sjohnlev typedef struct xdb_seg { 745084Sjohnlev uint8_t fs; /* start sector # within this page (segment) */ 755084Sjohnlev uint8_t ls; /* end sector # within this page (segment) */ 765084Sjohnlev } xdb_seg_t; 775084Sjohnlev 785084Sjohnlev typedef struct xdb xdb_t; 795084Sjohnlev 805084Sjohnlev /* one blkif_request_t matches one xdb_request_t */ 815084Sjohnlev typedef struct xdb_request { 825084Sjohnlev /* buf associated with this I/O request */ 835084Sjohnlev buf_t xr_buf; 845084Sjohnlev /* softstate instance associated with this I/O request */ 855084Sjohnlev xdb_t *xr_vdp; 865084Sjohnlev /* the next segment we're going to process */ 875084Sjohnlev int xr_curseg; 885084Sjohnlev /* index of this xdb_request_t in vdp->xs_req */ 895084Sjohnlev int xr_idx; 905084Sjohnlev /* next index for a statical linked list */ 915084Sjohnlev int xr_next; 925084Sjohnlev /* 'id' copied from blkif_request_t */ 935084Sjohnlev uint64_t xr_id; 945084Sjohnlev /* 'operation' copied from blkif_request_t */ 955084Sjohnlev uint8_t xr_op; 965084Sjohnlev /* how many pages(segments) in this I/O request */ 975084Sjohnlev uint8_t xr_buf_pages; 985084Sjohnlev /* all segments of this I/O request */ 995084Sjohnlev xdb_seg_t xr_segs[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 1005084Sjohnlev /* all grant table handles used in this I/O request */ 1015084Sjohnlev grant_handle_t xr_page_hdls[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 1025084Sjohnlev struct page xr_plist[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 1035084Sjohnlev struct page *xr_pplist[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 1045084Sjohnlev } xdb_request_t; 1055084Sjohnlev 1065084Sjohnlev /* Soft state data structure for each backend vbd */ 1075084Sjohnlev struct xdb { 1085084Sjohnlev /* devinfo node pointer of this xdb */ 1095084Sjohnlev dev_info_t *xs_dip; 1105084Sjohnlev /* coresponding frontend domain id */ 1115084Sjohnlev domid_t xs_peer; 1125084Sjohnlev /* read-only, removable, cdrom? */ 1135084Sjohnlev uint32_t xs_type; 1145084Sjohnlev /* # of total sectors */ 1155084Sjohnlev uint64_t xs_sectors; 116*9889SLarry.Liu@Sun.COM /* sector size if existed */ 117*9889SLarry.Liu@Sun.COM uint_t xs_sec_size; 1185084Sjohnlev /* blkif I/O request ring buffer */ 1195084Sjohnlev xendev_ring_t *xs_ring; 1205084Sjohnlev /* handle to access the ring buffer */ 1215084Sjohnlev ddi_acc_handle_t xs_ring_hdl; 1225084Sjohnlev ldi_ident_t xs_ldi_li; 1235084Sjohnlev ldi_handle_t xs_ldi_hdl; 1245084Sjohnlev /* base kva for mapped-in I/O page from frontend domain */ 1255084Sjohnlev caddr_t xs_iopage_va; 1265084Sjohnlev /* mutex lock for I/O related code path */ 1275084Sjohnlev kmutex_t xs_iomutex; 1285084Sjohnlev /* 1295084Sjohnlev * mutex lock for event handling related code path 1305084Sjohnlev * need to be grabbed before xs_iomutex 1315084Sjohnlev */ 1325084Sjohnlev kmutex_t xs_cbmutex; 1335084Sjohnlev /* # of on-going I/O buf in backend domain */ 1345084Sjohnlev uint_t xs_ionum; 1355084Sjohnlev /* task thread for pushing buf to underlying target driver */ 1365084Sjohnlev ddi_taskq_t *xs_iotaskq; 1375084Sjohnlev /* cv used in I/O code path, protected by xs_iomutex */ 1385084Sjohnlev kcondvar_t xs_iocv; 1395084Sjohnlev kcondvar_t xs_ionumcv; 1405084Sjohnlev /* 1415084Sjohnlev * head and tail of linked list for I/O bufs need to be pushed to 1425084Sjohnlev * underlying target driver 1435084Sjohnlev */ 1445084Sjohnlev buf_t *xs_f_iobuf; 1455084Sjohnlev buf_t *xs_l_iobuf; 1465084Sjohnlev /* head of free list of xdb_request_t */ 1475084Sjohnlev int xs_free_req; 1485084Sjohnlev /* pre-allocated xdb_request_t pool */ 1496144Srab xdb_request_t *xs_req; 1505084Sjohnlev kstat_t *xs_kstats; 1515084Sjohnlev uint64_t xs_stat_req_reads; 1525084Sjohnlev uint64_t xs_stat_req_writes; 1535084Sjohnlev uint64_t xs_stat_req_barriers; 1545084Sjohnlev uint64_t xs_stat_req_flushes; 1556144Srab enum blkif_protocol xs_blk_protocol; 1566144Srab size_t xs_nentry; 1576144Srab size_t xs_entrysize; 1588863SEdward.Pilatowicz@Sun.COM 1598863SEdward.Pilatowicz@Sun.COM /* Protected by xs_cbmutex */ 1608863SEdward.Pilatowicz@Sun.COM boolean_t xs_hp_connected; /* hot plug scripts have run */ 1618863SEdward.Pilatowicz@Sun.COM boolean_t xs_fe_initialised; /* frontend is initialized */ 1628863SEdward.Pilatowicz@Sun.COM char *xs_lofi_path; 1638863SEdward.Pilatowicz@Sun.COM char *xs_params_path; 1648863SEdward.Pilatowicz@Sun.COM struct xenbus_watch *xs_watch_params; 1658863SEdward.Pilatowicz@Sun.COM struct xenbus_watch *xs_watch_media_req; 1668863SEdward.Pilatowicz@Sun.COM ddi_taskq_t *xs_watch_taskq; 1678863SEdward.Pilatowicz@Sun.COM int xs_watch_taskq_count; 1688863SEdward.Pilatowicz@Sun.COM 1698863SEdward.Pilatowicz@Sun.COM /* Protected by xs_cbmutex and xs_iomutex */ 1708863SEdward.Pilatowicz@Sun.COM boolean_t xs_if_connected; /* connected to frontend */ 1718863SEdward.Pilatowicz@Sun.COM 1728863SEdward.Pilatowicz@Sun.COM /* Protected by xs_iomutex */ 1738863SEdward.Pilatowicz@Sun.COM boolean_t xs_send_buf; 1748863SEdward.Pilatowicz@Sun.COM 1755084Sjohnlev #ifdef DEBUG 1766144Srab uint64_t *page_addrs; /* for debug aid */ 1775084Sjohnlev #endif /* DEBUG */ 1785084Sjohnlev }; 1795084Sjohnlev 1805084Sjohnlev #ifdef __cplusplus 1815084Sjohnlev } 1825084Sjohnlev #endif 1835084Sjohnlev 1845084Sjohnlev #endif /* _SYS_XDB_H */ 185