/*
* 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/socketvar.h>
/*
* we use a consolidation private KAPI to allow the protocol to start
* an asynchronous copyout to a user-land receive-side buffer (uioa)
* when a blocking socket read (e.g. read, recv, ...) is pending.
*
* In some broad strokes, this is what happens. When recv is called,
* we first determine whether it would be beneficial to use uioa, and
* if so set up the required state (all done by sod_rcv_init()).
* The protocol can only initiate asynchronous copyout if the receive
* queue is empty, so the first thing we do is drain any previously
* queued data (using sod_uioa_so_init()). Once the copyouts (if any)
* have been scheduled we wait for the receive to be satisfied. During
* that time any new mblks that are enqueued will be scheduled to be
* copied out asynchronously (sod_uioa_mblk_init()). When the receive
* has been satisfied we wait for all scheduled copyout operations to
* complete before we return to the user (sod_rcv_done())
*/
/*
* This function is called at the beginning of recvmsg().
*
* with state UIOA_ALLOC.
*/
uio_t *
{
return (NULL);
/*
* Big enough I/O for uioa min setup and an sodirect socket
* and sodirect enabled and uioa enabled and I/O will be done
* and not EOF so initialize the sodirect_t uioa_t with "uiop".
*/
/*
* Successful uioainit() so the uio_t part of the
* uioa_t will be used for all uio_t work to follow,
* we return the original "uiop" in "suiop".
*/
/*
* Before returning to the caller the passed in uio_t
* "uiop" will be updated via a call to uioafini()
* below.
*
* Note, the uioa.uioa_state isn't set to UIOA_ENABLED
* here as first we have to uioamove() any currently
* queued M_DATA mblk_t(s) so it will be done later.
*/
}
}
return (suiop);
}
/*
* operations, and reset the uioa state to UIOA_ALLOC.
*/
int
{
int error = 0;
return (0);
}
/* Finish any sodirect and uioa processing */
/* Finish any uioa_t processing */
}
}
return (error);
}
/*
* Schedule a uioamove() on a mblk. This is done as mblks are enqueued
* by the protocol on the socket's rcv queue.
*
* Caller must be holding so_lock.
*/
void
{
/* Uioa is enabled */
/*
* There isn't enough uio space for the mblk_t chain
* so disable uioa such that this and any additional
* mblk_t data is handled by the socket and schedule
* the socket for wakeup to finish this uioa.
*/
return;
}
do {
/* Scheduled, mark dblk_t as such */
} else {
/* Error, turn off async processing */
break;
}
/* Break the mblk chain if neccessary. */
}
}
}
}
/*
* This function is called on a mblk that thas been successfully uioamoved().
*/
void
{
/*
* A uioa flaged mblk_t chain, already uio processed,
* add it to the sodirect uioa pending free list.
*
* Note, a b_cont chain headed by a DBLK_UIOA enable
* mblk_t must have all mblk_t(s) DBLK_UIOA enabled.
*/
/*
* Add first mblk_t of "bp" chain to current sodirect uioa
* free list tail mblk_t, if any, else empty list so new head.
*/
else
/*
* Walk mblk_t "bp" chain to find tail and adjust rptr of
* each to reflect that uioamove() has consumed all data.
*/
for (;;) {
break;
}
/* New sodirect uioa free list tail */
/* Only dequeue once with data returned per uioa_t */
}
}
}
/*
* When transit from UIOA_INIT state to UIOA_ENABLE state in recvmsg(), call
* this function on a non-STREAMS socket to schedule uioamove() on the data
* that has already queued in this socket.
*/
void
{
int len;
int error;
/*
* Walk first b_cont chain in sod_q
* and schedule any M_DATA mblk_t's for uio asynchronous move.
*/
/* Walk the chain */
do {
break;
/* Not M_DATA, no more uioa */
goto nouioa;
}
/* Have a M_DATA mblk_t with data */
/* Not enough uio sapce, or beyond oobmark */
goto nouioa;
}
if (!error) {
/* Scheduled, mark dblk_t as such */
} else {
/* Break the mblk chain */
goto nouioa;
}
}
/* Save last wbp processed */
/*
* We get here only once to process the sonode dump area
* if so_rcv_q_head is NULL or all the mblks have been
* successfully uioamoved()ed.
*/
/* move to dump area */
goto again;
}
return;
/* No more uioa */
/*
* If we processed 1 or more mblk_t(s) then we need to split the
* current mblk_t chain in 2 so that all the uioamove()ed mblk_t(s)
* are in the current chain and the rest are in the following new
* chain.
*/
/* New end of current chain */
/* Insert new chain wbp after bp */
if (in_rcv_q)
else
}
}
}
/*
* Initialize sodirect data structures on a socket.
*/
void
{
/*
* Remainder of the sod_uioa members are left uninitialized
* but will be initialized later by uioainit() before uioa
* is enabled.
*/
}
void
{
}
/*
* Init the sodirect kmem cache while sockfs is loading.
*/
int
sod_init()
{
/* Allocate sodirect_t kmem_cache */
return (0);
}
{
}
}
/* more arrived */
}
#ifdef DEBUG
while (m != NULL) {
" in so_rcv_q_head.\n", (void *)m);
}
m = m->b_next;
}
}
while (m != NULL) {
" in so_rcv_head.\n", (void *)m);
}
m = m->b_next;
}
}
#endif
}