/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1999-2000 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This implements a timed double linked list.
* This list supports:
* - addition of node to the end of the list
* - atomic deletion of node anywhere in list
* - get and remove node from head of list
* - timeout feature, if enabled, will remove each node on the list which
* has been on the list for > timeout. The callback provided will be
* called for each node removed. The worst case time is around
* timer_resolution after the timeout has occurred (i.e. if you set the
* timer resolution to 50uS and the timeout to 100uS, you could get the
* callback anywhere from 100uS to 150uS from when you added the node to
* the list. This is a general statement and ignores things like
* interrupt latency, context switching, etc. So if you see a time
* around 155uS, don't complain :-)
* - The timer is only used when something is on the list
*/
static void hci1394_tlist_callback(void *tlist_handle);
/*
* hci1394_tlist_init()
* Initialize the tlist. The list will be protected by a mutex at the
* iblock_cookie passed in. init() returns a handle to be used for the rest
* of the functions. If you do not wish to use the timeout feature, set
* (hci1394_timer_t *) to null.
*/
void
{
/* try to alloc the space to keep track of the list */
/* setup the return parameter */
*tlist_handle = list;
/* initialize the list structure */
} else {
}
}
/*
* hci1394_tlist_fini()
* Frees up the space allocated in init(). Notice that a pointer to the
* handle is used for the parameter. fini() will set your handle to NULL
* before returning. Make sure that any pending timeouts are canceled.
*/
void
{
/* set handle to null. This helps catch bugs. */
*tlist_handle = NULL;
}
/*
* hci1394_tlist_add()
* Add the node to the tail of the linked list. The list is protected by a
* mutex at the iblock_cookie passed in during init.
*/
void
{
/* add's always go at the end of the list */
/* Set state that this node is currently on the tlist */
/* enter in the expire time (in uS) */
}
/* if there is nothing in the list */
/* turn the timer on */
}
} else {
/* put the node on the end of the list */
/*
* if timeouts are enabled, we don't have to call
* timeout() because the timer is already on.
*/
}
}
/*
* hci1394_tlist_delete()
* Remove the node from the list. The node can be anywhere in the list. Make
* sure that the node is only removed once since different threads maybe
* trying to delete the same node at the same time.
*/
int
{
HCI1394_TNF_HAL_STACK, "");
/*
* check for race condition. Someone else may have already removed this
* node from the list. hci1394_tlist_delete() supports two threads
* trying to delete the node at the same time. The "losing" thread will
* have DDI_FAILURE returned.
*/
HCI1394_TNF_HAL_STACK, "");
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/*
* hci1394_tlist_get()
* get the node at the head of the linked list. This function also removes
* the node from the list.
*/
void
{
/* set the return parameter */
/* remove the node from the tlist */
}
}
/*
* hci1394_tlist_peek()
* get the node at the head of the linked list. This function does not
* remove the node from the list.
*/
void
{
}
/*
* hci1394_tlist_timeout_update()
* update the timeout to a different value. timeout is in uS. The update
* does not happen immediately. The new timeout will not take effect until
* the all of nodes currently present in the list are gone. It only makes
* sense to call this function when you have the timeout feature enabled.
*/
void
{
HCI1394_TNF_HAL_STACK, "");
/* set timeout to the new timeout */
HCI1394_TNF_HAL_STACK, "");
}
/*
* hci1394_tlist_timeout_cancel()
* cancel any scheduled timeouts. This should be called after the list is
* empty and there is no chance for any other nodes to be placed on the list.
* This function is meant to be called during a suspend or detach.
*/
void
{
HCI1394_TNF_HAL_STACK, "");
/*
* Cancel the timeout. Do NOT use the tlist mutex here. It could cause a
* deadlock.
*/
}
HCI1394_TNF_HAL_STACK, "");
}
/*
* hci1394_tlist_callback()
* The callback we use for the timeout() function. See if there are any nodes
* on the list which have timed out. If so, call the registered callback for
* each timed out node. We always start looking at the top of the list since
* the list is time sorted (oldest at the top).
*/
static void
{
HCI1394_TNF_HAL_STACK, "");
/*
* if there is something on the list, check to see if the oldest has
* expired. If there is nothing on the list, there is no reason to
* renew the timeout.
*/
current_time = gethrtime();
/*
* if current time is greater than the time the command expires,
* AND, the expire time has not rolled over, then the command
* has timed out.
*/
if (((uint64_t)current_time >=
/* remove the node from the tlist */
/*
* Call the timeout callback. We unlock the the mutex
* around the callback so that other transactions will
* not be blocked while the callback is running. This
* is OK to do here because we have already removed this
* entry from our list. This code should not reference
* "node" again after the callback! After the callback
* returns, we need to resync node to the head of the
* the callback.
*/
/*
* else, if current time is greater than the time the command
* expires, AND, current_time is not about to rollover. (this
* works since it is in the else and we periodically sample
* well below the rollover time)
*/
} else if ((uint64_t)(current_time >=
(((uint64_t)current_time +
(uint64_t)current_time)) {
/* remove the node from the tlist */
/*
* Call the timeout callback. We unlock the the mutex
* around the callback so that other transactions will
* not be blocked while the callback is running. This
* is OK to do here because we have already removed this
* entry from our list. This code should not reference
* "node" again after the callback! After the callback
* returns, we need to resync node to the head of the
* the callback.
*/
} else {
/*
* this command has not timed out.
* Since this list is time sorted, we are
* done looking for nodes that have expired
*/
break;
}
}
/*
* if there are nodes still on the pending list, kick
* off the timer again.
*/
} else {
}
HCI1394_TNF_HAL_STACK, "");
}
/*
* hci1394_tlist_remove()
* This is an internal function which removes the given node from the list.
* The list MUST be locked before calling this function.
*/
static void
{
HCI1394_TNF_HAL_STACK, "");
/* if this is the only node on the list */
/* if the node is at the head of the list */
/* if the node is at the tail of the list */
/* if the node is in the middle of the list */
} else {
}
/* Set state that this node has been removed from the list */
/* cleanup the node's link pointers */
}
/*
* t1394_tlist_nsectohz()
* Convert nS to hz. This allows us to call timeout() but keep our time
* reference in nS.
*/
{
}