1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1999-2000 by Sun Microsystems, Inc. 24*7c478bd9Sstevel@tonic-gate * All rights reserved. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _SYS_1394_ADAPTERS_HCI1394_TLIST_H 28*7c478bd9Sstevel@tonic-gate #define _SYS_1394_ADAPTERS_HCI1394_TLIST_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate /* 31*7c478bd9Sstevel@tonic-gate * hci1394_tlist.h 32*7c478bd9Sstevel@tonic-gate * This implements a timed double linked list. 33*7c478bd9Sstevel@tonic-gate * This list supports: 34*7c478bd9Sstevel@tonic-gate * - addition of node to the end of the list 35*7c478bd9Sstevel@tonic-gate * - atomic deletion of node anywhere in list 36*7c478bd9Sstevel@tonic-gate * - get and remove node from head of list 37*7c478bd9Sstevel@tonic-gate * - enable/disable of timeout feature 38*7c478bd9Sstevel@tonic-gate * - timeout feature, if enabled, will remove each node on the list which 39*7c478bd9Sstevel@tonic-gate * has been on the list for > timeout. The callback provided will be 40*7c478bd9Sstevel@tonic-gate * called for each node removed. The worst case time is around 41*7c478bd9Sstevel@tonic-gate * timer_resolution after the timeout has occurred (i.e. if you set the 42*7c478bd9Sstevel@tonic-gate * timer resolution to 50uS and the timeout to 100uS, you could get the 43*7c478bd9Sstevel@tonic-gate * callback anywhere from 100uS to 150uS from when you added the node to 44*7c478bd9Sstevel@tonic-gate * the list. This is a general statement and ignores things like 45*7c478bd9Sstevel@tonic-gate * interrupt latency, context switching, etc. So if you see a time 46*7c478bd9Sstevel@tonic-gate * around 155uS, don't complain :-) 47*7c478bd9Sstevel@tonic-gate * - The timer is only used when something is on the list 48*7c478bd9Sstevel@tonic-gate */ 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 51*7c478bd9Sstevel@tonic-gate extern "C" { 52*7c478bd9Sstevel@tonic-gate #endif 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 55*7c478bd9Sstevel@tonic-gate #include <sys/conf.h> 56*7c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 57*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 58*7c478bd9Sstevel@tonic-gate #include <sys/time.h> 59*7c478bd9Sstevel@tonic-gate #include <sys/note.h> 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate /* 62*7c478bd9Sstevel@tonic-gate * Node Information 63*7c478bd9Sstevel@tonic-gate * This structure is used to track the information for a given node in the 64*7c478bd9Sstevel@tonic-gate * linked list. The node is added to the end of the linked list be calling 65*7c478bd9Sstevel@tonic-gate * tlist_add(). 66*7c478bd9Sstevel@tonic-gate */ 67*7c478bd9Sstevel@tonic-gate typedef struct hci1394_tlist_node_s { 68*7c478bd9Sstevel@tonic-gate /* 69*7c478bd9Sstevel@tonic-gate * Public Members 70*7c478bd9Sstevel@tonic-gate * addr 71*7c478bd9Sstevel@tonic-gate * generic address pointer. This should be set to point to 72*7c478bd9Sstevel@tonic-gate * whatever information you are using this node to track. 73*7c478bd9Sstevel@tonic-gate */ 74*7c478bd9Sstevel@tonic-gate void *tln_addr; 75*7c478bd9Sstevel@tonic-gate 76*7c478bd9Sstevel@tonic-gate /* 77*7c478bd9Sstevel@tonic-gate * Private Members 78*7c478bd9Sstevel@tonic-gate * These are private. They are only to be used in the tlist 79*7c478bd9Sstevel@tonic-gate * implementation. They are included in the header file so that we 80*7c478bd9Sstevel@tonic-gate * do not have to alloc/free memory when something is added/deleted 81*7c478bd9Sstevel@tonic-gate * from the tlist. 82*7c478bd9Sstevel@tonic-gate */ 83*7c478bd9Sstevel@tonic-gate boolean_t tln_on_list; 84*7c478bd9Sstevel@tonic-gate hrtime_t tln_expire_time; 85*7c478bd9Sstevel@tonic-gate struct hci1394_tlist_node_s *tln_prev; 86*7c478bd9Sstevel@tonic-gate struct hci1394_tlist_node_s *tln_next; 87*7c478bd9Sstevel@tonic-gate } hci1394_tlist_node_t; 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate /* 91*7c478bd9Sstevel@tonic-gate * callback used in hci1394_tlist_timer_t. This will be called when a node on 92*7c478bd9Sstevel@tonic-gate * the list expires. 93*7c478bd9Sstevel@tonic-gate */ 94*7c478bd9Sstevel@tonic-gate typedef 95*7c478bd9Sstevel@tonic-gate void (*hci1394_tlist_callback_t)(hci1394_tlist_node_t *node, void *arg); 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate /* 99*7c478bd9Sstevel@tonic-gate * This structure is used if you are using the timeout feature of the linked 100*7c478bd9Sstevel@tonic-gate * list. 101*7c478bd9Sstevel@tonic-gate * timeout 102*7c478bd9Sstevel@tonic-gate * time in nS when a node should be considered to haved timed out. 103*7c478bd9Sstevel@tonic-gate * 104*7c478bd9Sstevel@tonic-gate * timer_resolution 105*7c478bd9Sstevel@tonic-gate * time in nS when the list should be checked for timeouts. It can be 106*7c478bd9Sstevel@tonic-gate * varied from timeout to reduce the jitter in the callback. 107*7c478bd9Sstevel@tonic-gate * 108*7c478bd9Sstevel@tonic-gate * callback 109*7c478bd9Sstevel@tonic-gate * function to call on timeout. 110*7c478bd9Sstevel@tonic-gate * 111*7c478bd9Sstevel@tonic-gate * callback_arg 112*7c478bd9Sstevel@tonic-gate * user specified argument passed in callback 113*7c478bd9Sstevel@tonic-gate * 114*7c478bd9Sstevel@tonic-gate */ 115*7c478bd9Sstevel@tonic-gate typedef struct hci1394_tlist_timer_s { 116*7c478bd9Sstevel@tonic-gate hrtime_t tlt_timeout; 117*7c478bd9Sstevel@tonic-gate hrtime_t tlt_timer_resolution; 118*7c478bd9Sstevel@tonic-gate hci1394_tlist_callback_t tlt_callback; 119*7c478bd9Sstevel@tonic-gate void *tlt_callback_arg; 120*7c478bd9Sstevel@tonic-gate } hci1394_tlist_timer_t; 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate /* State to determine if timeout is scheduled or not */ 124*7c478bd9Sstevel@tonic-gate typedef enum { 125*7c478bd9Sstevel@tonic-gate HCI1394_TLIST_TIMEOUT_OFF, 126*7c478bd9Sstevel@tonic-gate HCI1394_TLIST_TIMEOUT_ON 127*7c478bd9Sstevel@tonic-gate } hci1394_tlist_timeout_state_t; 128*7c478bd9Sstevel@tonic-gate 129*7c478bd9Sstevel@tonic-gate 130*7c478bd9Sstevel@tonic-gate /* private structure used to keep track of the tlist */ 131*7c478bd9Sstevel@tonic-gate typedef struct hci1394_tlist_s { 132*7c478bd9Sstevel@tonic-gate /* head and tail of linked list */ 133*7c478bd9Sstevel@tonic-gate hci1394_tlist_node_t *tl_head; 134*7c478bd9Sstevel@tonic-gate hci1394_tlist_node_t *tl_tail; 135*7c478bd9Sstevel@tonic-gate 136*7c478bd9Sstevel@tonic-gate /* are we using timeout feature */ 137*7c478bd9Sstevel@tonic-gate boolean_t tl_timer_enabled; 138*7c478bd9Sstevel@tonic-gate 139*7c478bd9Sstevel@tonic-gate /* has timeout() been called */ 140*7c478bd9Sstevel@tonic-gate hci1394_tlist_timeout_state_t tl_state; 141*7c478bd9Sstevel@tonic-gate 142*7c478bd9Sstevel@tonic-gate /* id returned from timeout() */ 143*7c478bd9Sstevel@tonic-gate timeout_id_t tl_timeout_id; 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate /* local copy of timer_info */ 146*7c478bd9Sstevel@tonic-gate hci1394_tlist_timer_t tl_timer_info; 147*7c478bd9Sstevel@tonic-gate 148*7c478bd9Sstevel@tonic-gate hci1394_drvinfo_t *tl_drvinfo; 149*7c478bd9Sstevel@tonic-gate kmutex_t tl_mutex; 150*7c478bd9Sstevel@tonic-gate } hci1394_tlist_t; 151*7c478bd9Sstevel@tonic-gate 152*7c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("Single thread modifies", \ 153*7c478bd9Sstevel@tonic-gate hci1394_tlist_s::tl_state \ 154*7c478bd9Sstevel@tonic-gate hci1394_tlist_s::tl_timeout_id \ 155*7c478bd9Sstevel@tonic-gate hci1394_tlist_s::tl_timer_info.tlt_timeout)) 156*7c478bd9Sstevel@tonic-gate 157*7c478bd9Sstevel@tonic-gate /* handle passed back from init() and used for rest of functions */ 158*7c478bd9Sstevel@tonic-gate typedef struct hci1394_tlist_s *hci1394_tlist_handle_t; 159*7c478bd9Sstevel@tonic-gate 160*7c478bd9Sstevel@tonic-gate 161*7c478bd9Sstevel@tonic-gate 162*7c478bd9Sstevel@tonic-gate void hci1394_tlist_init(hci1394_drvinfo_t *drvinfo, 163*7c478bd9Sstevel@tonic-gate hci1394_tlist_timer_t *timer, hci1394_tlist_handle_t *tlist_handle); 164*7c478bd9Sstevel@tonic-gate void hci1394_tlist_fini(hci1394_tlist_handle_t *tlist_handle); 165*7c478bd9Sstevel@tonic-gate 166*7c478bd9Sstevel@tonic-gate 167*7c478bd9Sstevel@tonic-gate void hci1394_tlist_add(hci1394_tlist_handle_t tlist_handle, 168*7c478bd9Sstevel@tonic-gate hci1394_tlist_node_t *node); 169*7c478bd9Sstevel@tonic-gate int hci1394_tlist_delete(hci1394_tlist_handle_t tlist_handle, 170*7c478bd9Sstevel@tonic-gate hci1394_tlist_node_t *node); 171*7c478bd9Sstevel@tonic-gate void hci1394_tlist_get(hci1394_tlist_handle_t tlist_handle, 172*7c478bd9Sstevel@tonic-gate hci1394_tlist_node_t **node); 173*7c478bd9Sstevel@tonic-gate void hci1394_tlist_peek(hci1394_tlist_handle_t tlist_handle, 174*7c478bd9Sstevel@tonic-gate hci1394_tlist_node_t **node); 175*7c478bd9Sstevel@tonic-gate 176*7c478bd9Sstevel@tonic-gate void hci1394_tlist_timeout_update(hci1394_tlist_handle_t tlist_handle, 177*7c478bd9Sstevel@tonic-gate hrtime_t timeout); 178*7c478bd9Sstevel@tonic-gate void hci1394_tlist_timeout_cancel(hci1394_tlist_handle_t tlist_handle); 179*7c478bd9Sstevel@tonic-gate 180*7c478bd9Sstevel@tonic-gate 181*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 182*7c478bd9Sstevel@tonic-gate } 183*7c478bd9Sstevel@tonic-gate #endif 184*7c478bd9Sstevel@tonic-gate 185*7c478bd9Sstevel@tonic-gate #endif /* _SYS_1394_ADAPTERS_HCI1394_TLIST_H */ 186