/*
* 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
*/
/*
*/
#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
* EINVAL if num_mblks is zero or not a power of 2.
* ENOSPC if the pool could not be created due to alloc failures.
*/
int
{
int i;
int rv;
*poolp = 0;
return (EINVAL);
}
if (mblk_datap == NULL) {
} else {
}
/* create a queue of pointers to free vio_mblk_t's */
sizeof (vio_mblk_t *), KM_SLEEP);
/* reset tail */
/*
* vio_destroy_mblks() frees mblks that have been
* allocated so far and then destroys the pool.
*/
return (ENOSPC);
}
/* 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;
int pool_cleanup_retries = 0;
return (EINVAL);
/*
* We can only destroy the pool once all the mblks have
* been reclaimed.
*/
do {
break;
}
/* some mblks still in use */
} while (++pool_cleanup_retries < vio_pool_cleanup_retries);
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++) {
/*
* It is possible that mblks have been allocated only upto
* a certain index and the entire quelen has not been
* initialized. This might happen due to desballoc() failure
* while creating the pool. The below check handles this
* condition.
*/
}
}
return (0);
}
/*
* Allocate a vio_mblk from the free pool if one is available.
* Otherwise returns NULL.
*/
{
/* we have free mblks */
}
return (vmp);
}
/*
* 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;
}
}
/*
* This function searches the given mblk pool for mblks that are in the
* BOUND state and moves them to the FREE state. Note that only clients that
* are operating in RxDringData mode use this function. This allows such
* clients to reclaim buffers that are provided to the peer as shared memory,
* before calling vio_destroy_mblks(). We don't need this in other cases
* as the buffer is locally managed.
*/
void
{
uint64_t i;
for (i = 0; i < num_mblks; i++) {
/* put this vmp on the free stack */
}
}
}
/*
* 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 vio_mblk from one of the free pools, but tries the pool that
* best fits size requested first.
*/
{
int i;
/* Try allocating any size that fits */
continue;
}
break;
}
}
return (vmp);
}
/*
* -----------------------------------------------------------------------------
* LDoms versioning functions
*
* Future work: the version negotiating code in the various VIO drivers
* could be made common and placed here.
*/
/*
* Description:
* This function checks to see if the supplied version tuple (major,minor)
* is supported by the version 'ver', negotiated during the handshake
* between the client and the server (ver).
*
* Assumption:
* This function assumes that backward compatability is not broken in
* newer minor versions of the protocol (e.g. v1.5 & v1.1 support v1.0)
*
* Return Value:
* B_TRUE - The (major,minor) version is supported
* B_FALSE - not supported
*/
{
return (B_TRUE);
return (B_FALSE);
}