1*1709Smlf /* 2*1709Smlf * CDDL HEADER START 3*1709Smlf * 4*1709Smlf * The contents of this file are subject to the terms of the 5*1709Smlf * Common Development and Distribution License (the "License"). 6*1709Smlf * You may not use this file except in compliance with the License. 7*1709Smlf * 8*1709Smlf * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*1709Smlf * or http://www.opensolaris.org/os/licensing. 10*1709Smlf * See the License for the specific language governing permissions 11*1709Smlf * and limitations under the License. 12*1709Smlf * 13*1709Smlf * When distributing Covered Code, include this CDDL HEADER in each 14*1709Smlf * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*1709Smlf * If applicable, add the following below this CDDL HEADER, with the 16*1709Smlf * fields enclosed by brackets "[]" replaced with your own identifying 17*1709Smlf * information: Portions Copyright [yyyy] [name of copyright owner] 18*1709Smlf * 19*1709Smlf * CDDL HEADER END 20*1709Smlf */ 21*1709Smlf 22*1709Smlf /* 23*1709Smlf * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*1709Smlf * Use is subject to license terms. 25*1709Smlf */ 26*1709Smlf 27*1709Smlf #ifndef _GHD_WAITQ_H 28*1709Smlf #define _GHD_WAITQ_H 29*1709Smlf 30*1709Smlf #pragma ident "%Z%%M% %I% %E% SMI" 31*1709Smlf 32*1709Smlf #ifdef __cplusplus 33*1709Smlf extern "C" { 34*1709Smlf #endif 35*1709Smlf 36*1709Smlf 37*1709Smlf /* 38*1709Smlf * there's a waitq_t per target device and one per HBA 39*1709Smlf */ 40*1709Smlf 41*1709Smlf typedef struct ghd_q { 42*1709Smlf struct ghd_q *Q_nextp; /* ptr to next level of queuing */ 43*1709Smlf L2el_t Q_qhead; /* Q of waiting gcmds */ 44*1709Smlf long Q_nactive; /* current # of outstanding gcmds */ 45*1709Smlf long Q_maxactive; /* max gcmds to release concurrently */ 46*1709Smlf } Q_t; 47*1709Smlf 48*1709Smlf #define GHD_WAITQ_INIT(qp, nxtp, maxactive) \ 49*1709Smlf (L2_INIT(&(qp)->Q_qhead), \ 50*1709Smlf (qp)->Q_nextp = (nxtp), \ 51*1709Smlf (qp)->Q_nactive = 0, \ 52*1709Smlf (qp)->Q_maxactive = (maxactive)) 53*1709Smlf /* 54*1709Smlf * one per target device 55*1709Smlf */ 56*1709Smlf typedef struct ghd_device { 57*1709Smlf Q_t gd_waitq; /* the queue structure for this device */ 58*1709Smlf L1el_t gd_devlist; /* all gdevs for a HBA are linked together */ 59*1709Smlf ulong_t gd_target; /* ... and are located by searching for */ 60*1709Smlf ulong_t gd_lun; /* ... a match on the (target,lun) values */ 61*1709Smlf 62*1709Smlf L1_t gd_ilist; /* linked list of instances for this device */ 63*1709Smlf ulong_t gd_ninstances; /* # of instances for this device */ 64*1709Smlf } gdev_t; 65*1709Smlf 66*1709Smlf #define GDEV_QHEAD(gdevp) ((gdevp)->gd_waitq.Q_qhead) 67*1709Smlf #define GDEV_NACTIVE(gdevp) ((gdevp)->gd_waitq.Q_nactive) 68*1709Smlf #define GDEV_MAXACTIVE(gdevp) ((gdevp)->gd_waitq.Q_maxactive) 69*1709Smlf 70*1709Smlf /* 71*1709Smlf * Be careful, this macro assumes there's a least one 72*1709Smlf * target instance attached to this dev structure, Otherwise, l1_headp 73*1709Smlf * is NULL. 74*1709Smlf */ 75*1709Smlf #define GDEVP2GTGTP(gdevp) \ 76*1709Smlf (gtgt_t *)((gdevp)->gd_ilist.l1_headp->le_datap) 77*1709Smlf 78*1709Smlf #define GDEV_NEXTP(gdevp) \ 79*1709Smlf ((gdevp)->gd_devlist.le_nextp \ 80*1709Smlf ? (gdev_t *)((gdevp)->gd_devlist.le_nextp->le_datap) \ 81*1709Smlf : (gdev_t *)NULL) 82*1709Smlf 83*1709Smlf #define GDEV_QATTACH(gdevp, cccp, max) { \ 84*1709Smlf GHD_WAITQ_INIT(&(gdevp)->gd_waitq, &(cccp)->ccc_waitq, (max)); \ 85*1709Smlf L1EL_INIT(&gdevp->gd_devlist); \ 86*1709Smlf L1HEADER_INIT(&gdevp->gd_ilist); \ 87*1709Smlf /* add the per device structure to the HBA's device list */ \ 88*1709Smlf L1_add(&(cccp)->ccc_devs, &(gdevp)->gd_devlist, (gdevp)); \ 89*1709Smlf } 90*1709Smlf 91*1709Smlf #define GDEV_QDETACH(gdevp, cccp) \ 92*1709Smlf L1_delete(&(cccp)->ccc_devs, &(gdevp)->gd_devlist) 93*1709Smlf 94*1709Smlf /* 95*1709Smlf * GHD target structure, one per attached target driver instance 96*1709Smlf */ 97*1709Smlf typedef struct ghd_target_instance { 98*1709Smlf L1el_t gt_ilist; /* list of other instances for this device */ 99*1709Smlf gdev_t *gt_gdevp; /* ptr to info shared by all instances */ 100*1709Smlf 101*1709Smlf /* this would be ccc_t, but is circular with ghd.h. sigh. */ 102*1709Smlf struct cmd_ctl *gt_ccc; /* ptr to HBA per-instance struct */ 103*1709Smlf 104*1709Smlf ulong_t gt_maxactive; /* max gcmds to release concurrently */ 105*1709Smlf void *gt_hba_private; /* ptr to soft state of this HBA instance */ 106*1709Smlf void *gt_tgt_private; /* ptr to soft state of this target instance */ 107*1709Smlf size_t gt_size; /* size including tgt_private */ 108*1709Smlf ushort_t gt_target; /* target number of this instance */ 109*1709Smlf uchar_t gt_lun; /* LUN of this instance */ 110*1709Smlf } gtgt_t; 111*1709Smlf 112*1709Smlf #define GTGTP2TARGET(gtgtp) ((gtgtp)->gt_tgt_private) 113*1709Smlf #define GTGTP2HBA(gtgtp) ((gtgtp)->gt_hba_private) 114*1709Smlf #define GTGTP2GDEVP(gtgtp) ((gtgtp)->gt_gdevp) 115*1709Smlf 116*1709Smlf #define GTGT_INIT(gtgtp) L1EL_INIT(&(gtgtp)->gt_ilist) 117*1709Smlf 118*1709Smlf /* Add the per instance structure to the per device list */ 119*1709Smlf #define GTGT_ATTACH(gtgtp, gdevp) { \ 120*1709Smlf (gdevp)->gd_ninstances++; \ 121*1709Smlf L1_add(&(gdevp)->gd_ilist, &(gtgtp)->gt_ilist, (gtgtp)); \ 122*1709Smlf } 123*1709Smlf 124*1709Smlf 125*1709Smlf /* remove this per-instance-structure from the device list */ 126*1709Smlf #define GTGT_DEATTACH(gtgtp, gdevp) { \ 127*1709Smlf (gdevp)->gd_ninstances--; \ 128*1709Smlf L1_delete(&(gdevp)->gd_ilist, &(gtgtp)->gt_ilist); \ 129*1709Smlf } 130*1709Smlf 131*1709Smlf #ifdef __cplusplus 132*1709Smlf } 133*1709Smlf #endif 134*1709Smlf #endif /* _GHD_QUEUE_H */ 135