vio_util.c revision b4d0458e18abef7b5e036915e96807c219ec1d58
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/sysmacros.h>
#include <sys/vio_util.h>
/*
* Create a pool of mblks from which future vio_allocb() requests
* will be serviced.
*
* NOTE: num_mblks has to non-zero and a power-of-2
*
* Returns 0 on success or EINVAL if num_mblks is zero or not
* a power of 2.
*/
int
{
int i;
*poolp = 0;
return (EINVAL);
}
/* create a queue of pointers to free vio_mblk_t's */
sizeof (vio_mblk_t *), KM_SLEEP);
continue;
/* put this vmp on the free stack */
}
return (0);
}
/*
* Destroy the pool of mblks. This can only succeed when
* all allocated mblks have been returned to the pool.
*
* It is up to the caller to ensure that no further mblks are
* requested from the pool after destroy has been invoked.
*
* Returns 0 on success, EINVAL if handle is invalid, or
* EBUSY if not all mblks reclaimed yet.
*/
int
{
uint64_t i;
return (EINVAL);
/*
* We can only destroy the pool once all the mblks have
* been reclaimed.
*/
/* some mblks still in use */
return (EBUSY);
}
/*
* Set pool flag to tell vio_freeb() which is invoked from freeb(),
* that it is being called in the context of vio_destroy_mblks().
* This results in freeing only mblk_t and dblk_t structures for
* each mp. The associated data buffers are freed below as one big
* chunk through kmem_free(vmplp->datap).
*/
for (i = 0; i < num_mblks; i++) {
}
return (0);
}
/*
* Allocate a mblk from the free pool if one is available.
* Otherwise returns NULL.
*/
mblk_t *
{
/* we have free mblks */
}
return (mp);
}
/*
* Return a mblk to the free pool. Invoked when the upper IP
* layers do freemsg() etc on the mblk they were passed.
*/
void
{
/*
* This flag indicates that freeb() is being called from
* vio_destroy_mblks().
* this data buffer, return from here and the data buffer
* itself will be freed in vio_destroy_mblks().
*/
return;
}
}
/*
* Create a multiple pools of mblks from which future vio_allocb()
* or vio_multipool_allocb() requests will be serviced.
*
* Arguments:
* vmultip -- A pointer to vio_multi_pool_t structure.
* num_pools -- Number of the pools.
* ... -- Variable arguments consisting a list of buffer sizes for
* each pool and list of number of buffers for each pool.
*
* NOTE: The restrictions of vio_create_mblks() apply to this interface also.
*
* Returns 0 on success or an error returned by vio_create_mblks().
*/
int
{
int i;
int status;
char *tbuf;
/*
* Allocate memory for all of the following in one allocation.
* bufsz_tbl -- sizeof (uint32_t) * num_pools
* nbuf_tbl -- sizeof (uint32_t) * num_pools
* vmpp -- sizeof (vio_mblk_pool_t *) * numpools
*/
(sizeof (vio_mblk_pool_t *) * num_pools);
/* initialize the array first */
for (i = 0; i < num_pools; i++) {
}
for (i = 0; i < num_pools; i++) {
}
if (status != 0) {
/* We expect to free the pools without failure here */
return (status);
}
}
return (0);
}
/*
* Destroy the multiple pools of mblks. This can only succeed when
* all allocated mblks have been returned to the pool.
*
* If a pool of mblks couldn't be destroyed, then the failed vio_mblk_pool_t
* pointers are returned via th fvmp list. Its the caller's
* responsibility to check this list and free them later at an appropriate
* time with vio_destroy_mblks().
*
* Arguments:
* vmultip -- A pointer to vio_multi_pool_t structure.
* fvmp -- A list in which the pools that couldn't be destroyed are
* returned.
*/
void
{
int i;
if (vio_destroy_mblks(vmp)) {
/*
* if we cannot reclaim all mblks, then
* return the pool in the failed vmp
* list(fvmp).
*/
}
}
}
}
/*
* Allocate an mblk from one of the free pools, but tries the pool that
* best fits size requested first.
*/
mblk_t *
{
int i;
/* Try allocating any size that fits */
continue;
}
break;
}
}
return (mp);
}