pckt.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* 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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R4 1.10 */
/*
* Description: The pckt module packetizes messages on
* its read queue by pre-fixing an M_PROTO
* message type to certain incoming messages.
*/
/*
* This is the loadable module wrapper.
*/
/*
* Per queue instances are single-threaded since the q_ptr
* field of queues need to be shared among threads.
*/
"pckt",
&pcktinfo,
};
/*
* Module linkage information for the kernel.
*/
static struct modlstrmod modlstrmod = {
"pckt module",
&fsw
};
static struct modlinkage modlinkage = {
};
int
_init(void)
{
return (mod_install(&modlinkage));
}
int
_fini(void)
{
return (mod_remove(&modlinkage));
}
int
{
}
static void add_ctl_wkup(void *);
/*
* Stream module data structure definitions.
* Sits over the ptm module generally.
*
* Read side flow control strategy: Since we may be putting messages on
* the read q due to allocb failures, these failures must get
* reflected fairly quickly to the module below us.
* No sense in piling on messages in times of memory shortage.
* Further, for the case of upper level flow control, there is no
* compelling reason to have more buffering in this module.
* Thus use a hi-water mark of one.
* This module imposes no max packet size, there is no inherent reason
* in the code to do so.
*/
static struct module_info pcktiinfo = {
0x9898, /* module id number */
"pckt", /* module name */
0, /* minimum packet size */
INFPSZ, /* maximum packet size */
1, /* hi-water mark */
0 /* lo-water mark */
};
/*
* Write side flow control strategy: There is no write service procedure.
* The write put function is pass thru, thus there is no reason to have any
* limits on the maximum packet size.
*/
static struct module_info pcktoinfo = {
0x9898, /* module id number */
"pckt", /* module name */
0, /* minimum packet size */
INFPSZ, /* maximum packet size */
0, /* hi-water mark */
0 /* lo-water mark */
};
(int (*)())pcktrput,
(int (*)())pcktrsrv,
NULL,
};
(int (*)())pcktwput,
NULL,
NULL,
NULL,
NULL,
};
NULL,
};
/*
* Per-instance state struct for the pckt module.
*/
struct pckt_info {
#ifdef _MULTI_DATAMODEL
#endif /* _MULTI_DATAMODEL */
};
/*
* Dummy qbufcall callback routine used by open and close.
* The framework will wake up qwait_sig when we return from
* this routine (as part of leaving the perimeters.)
* (The framework enters the perimeters before calling the qbufcall() callback
* and leaves the perimeters after the callback routine has executed. The
* when it leaves the perimeter. See qwait(9E).)
*/
/* ARGSUSED */
static void
dummy_callback(void *arg)
{}
/*
* pcktopen - open routine gets called when the
* module gets pushed onto the stream.
*/
/*ARGSUSED*/
static int
queue_t *q, /* pointer to the read side queue */
int oflag, /* the user open(2) supplied flags */
int sflag, /* open state flag */
{
struct stroptions *sop;
return (EINVAL);
/* It's already attached. */
return (0);
}
/*
* Allocate state structure.
*/
#ifdef _MULTI_DATAMODEL
#endif /* _MULTI_DATAMODEL */
/*
* Cross-link.
*/
qprocson(q);
/*
* stream head read queue.
*/
if (!qwait_sig(q)) {
qunbufcall(q, id);
qprocsoff(q);
return (EINTR);
}
qunbufcall(q, id);
}
/*
* Is there any reason in this code to do so?
*/
/*
* Commit to the open and send the M_SETOPTS off to the stream head.
*/
return (0);
}
/*
* pcktclose - This routine gets called when the module
* gets popped off of the stream.
*/
/*ARGSUSED*/
static int
queue_t *q, /* Pointer to the read queue */
int flag,
{
qprocsoff(q);
/*
* Cancel outstanding qbufcall
*/
if (pip->pi_bufcall_id) {
pip->pi_bufcall_id = 0;
}
/*
* Do not worry about msgs queued on the q, the framework
* will free them up.
*/
return (0);
}
/*
* pcktrput - Module read queue put procedure.
* This is called from the module or
* driver downstream.
*/
static void
queue_t *q, /* Pointer to the read queue */
{
case M_FLUSH:
/*
* The PTS driver swaps the FLUSHR and FLUSHW flags
* we need to swap them back to reflect the actual
* slave side FLUSH mode.
*/
/*
* In the packet model we are not allowing
* flushes of the master's stream head read
* side queue. This is because all packet
* state information is stored there and
* a flush could destroy this data before
* it is read.
*/
} else {
/*
* Free messages that only flush the
* master's read queue.
*/
}
break;
/*
* Prefix M_PROTO and putnext.
*/
goto prefix_head;
case M_DATA:
case M_IOCTL:
case M_PROTO:
/*
* For non-priority messages, follow flow-control rules.
* Also, if there are messages on the q already, keep
* queueing them since they need to be processed in order.
*/
if (!canputnext(q) || (qsize(q) > 0)) {
break;
}
/* FALLTHROUGH */
/*
* For high priority messages, skip flow control checks.
*/
case M_PCPROTO:
case M_READ:
case M_STOP:
case M_START:
case M_STARTI:
case M_STOPI:
/*
* Prefix an M_PROTO header to message and pass upstream.
*/
break;
default:
/*
* For data messages, queue them back on the queue if
* there are messages on the queue already. This is
* done to preserve the order of messages.
* For high priority messages or for no messages on the
* q, simply putnext() and pass it on.
*/
else
break;
}
}
/*
* pcktrsrv - module read service procedure
* This function deals with messages left in the queue due to
* (a) not enough memory to allocate the header M_PROTO message
* (b) flow control reasons
* The function will attempt to get the messages off the queue and
* process them.
*/
static void
{
if (!canputnext(q)) {
/*
* For high priority messages, make sure there is no
* infinite loop. Disable the queue for this case.
* High priority messages get here only for buffer
* allocation failures. Thus the bufcall callout
* will reenable the q.
* XXX bug alert - nooenable will *not* prevent
* putbq of a hipri messages frm enabling the queue.
*/
noenable(q);
return;
}
/*
* M_FLUSH msgs may also be here if there was a memory
* failure.
*/
case M_FLUSH:
case M_PROTO:
case M_PCPROTO:
case M_STOP:
case M_START:
case M_IOCTL:
case M_DATA:
case M_READ:
case M_STARTI:
case M_STOPI:
/*
* Prefix an M_PROTO header to msg and pass upstream.
*/
/*
* Running into memory or flow ctl problems.
*/
return;
}
/* FALL THROUGH */
default:
break;
}
}
}
/*
* pcktwput - Module write queue put procedure.
* All messages are send downstream unchanged
*/
static void
queue_t *q, /* Pointer to the read queue */
{
}
#ifdef _MULTI_DATAMODEL
/*
* reallocb - copy the data block from the given message block into a new block.
* This function is used in case data block had another message block
* pointing to it (and hence we just copy this one data block).
*
* Returns new message block if successful. On failure it returns NULL.
* It also tries to do a qbufcall and if that also fails,
* it frees the message block.
*/
static mblk_t *
queue_t *q, /* Pointer to the read queue */
)
{
/*
* No reallocation is needed if there is only one reference
* to this data block.
*/
return (mp);
noenable(q);
BPRI_MED, add_ctl_wkup, q)) {
/*
* Put the message back onto the q.
*/
} else {
/*
* Things are pretty bad and serious if bufcall fails!
* Drop the message in this case.
*/
}
return ((mblk_t *)0);
}
return (nmp);
}
#endif /* _MULTI_DATAMODEL */
/*
* add_ctl_info: add message control information to in coming
* message.
*/
static mblk_t *
queue_t *q, /* pointer to the read queue */
{
/*
* Waiting on space for previous message?
*/
if (pip->pi_bufcall_id) {
/*
* Chain this message on to q for later processing.
*/
return (NULL);
}
/*
* Need to add the message block header as
* an M_PROTO type message.
*/
/*
* There are two reasons to disable the q:
* (1) Flow control reasons should not wake up the q.
* (2) High priority messages will wakeup the q
* immediately. Disallow this.
*/
noenable(q);
add_ctl_wkup, q)) {
/*
* Add the message to the q.
*/
} else {
/*
* Things are pretty bad and serious if bufcall fails!
* Drop the message in this case.
*/
}
return (NULL);
}
/*
* Copy the message type information to this message.
*/
#ifdef _MULTI_DATAMODEL
/*
* Check the datamodel and if the calling program is
* an ILP32 application then we covert the M_IOCTLs and M_READs
* into the native ILP32 format before passing them upstream
* to user mode.
*/
case DDI_MODEL_ILP32:
/*
* This structure must have the same shape as
* the * ILP32 compilation of `struct iocblk'
*/
struct iocblk32 {
} niocblk_32;
case M_IOCTL:
return ((mblk_t *)0);
/* Leave the pointer to cred_t structure as it is. */
/* Copy the iocblk structure for ILP32 back */
break;
case M_READ:
return ((mblk_t *)0);
/* change the size_t to size32_t for ILP32 */
break;
}
break;
case DATAMODEL_NONE:
break;
}
#endif /* _MULTI_DATAMODEL */
/*
* Now change the orginal message type to M_DATA and tie them up.
*/
return (bp);
}
static void
add_ctl_wkup(void *arg)
{
pip->pi_bufcall_id = 0;
/*
* Allow enabling of the q to allow the service
* function to do its job.
*
* Also, qenable() to schedule the q immediately.
* This is to ensure timely processing of high priority
* messages if they are on the q.
*/
enableok(q);
qenable(q);
}