gld.c revision e2e51e72fa94168d404e10f89c186842a85f4179
/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* gld - Generic LAN Driver Version 2, PSARC/1997/382
*
* This is a utility module that provides generic facilities for
* LAN drivers. The DLPI protocol and most STREAMS interfaces
* are handled here.
*
* It no longer provides compatibility with drivers
* implemented according to the GLD v0 documentation published
* in 1993. (See PSARC 2003/728)
*/
#include <sys/sysmacros.h>
#include <sys/byteorder.h>
#include <sys/ethernet.h>
#include <sys/multidata.h>
/*
* Macros to increment statistics.
*/
/*
* Increase kstats. Note this operation is not atomic. It can be used when
* GLDM_LOCK_HELD_WRITE(macinfo).
*/
} while (0)
} \
} while (0)
(delta)); \
} \
} while (0)
if ((pktinfo).isBroadcast) { \
glds_brdcstxmt, (delta)); \
} else if ((pktinfo).isMulticast) { \
} \
}
#ifdef GLD_DEBUG
#endif
/* called from gld_register */
static int gld_initstats(gld_mac_info_t *);
/* called from kstat mechanism, and from wsrv's get_statistics */
static int gld_update_kstat(kstat_t *, int);
/* statistics for additional vlans */
static int gld_init_vlan_stats(gld_vlan_t *);
static int gld_update_vlan_kstat(kstat_t *, int);
/* called from gld_getinfo */
/* called from wput, wsrv, unidata, and v0_sched to send a packet */
/* also from the source routing stuff for sending RDE protocol packets */
/* called from gld_start[_mdt] to loopback packet(s) in promiscuous mode */
/* receive group: called from gld_recv and gld_precv* with maclock held */
int (*)());
static int gld_multicast(unsigned char *, gld_t *);
/* wsrv group: called from wsrv, single threaded per queue */
/* misc utilities, some requiring various mutexes held */
static int gld_start_mac(gld_mac_info_t *);
static void gld_stop_mac(gld_mac_info_t *);
static void gld_set_ipq(gld_t *);
static void gld_flushqueue(queue_t *);
static glddev_t *gld_devlookup(int);
static int gld_findminor(glddev_t *);
static void gldinsque(void *, void *);
static void gldremque(void *);
char *gld_macaddr_sprintf(char *, unsigned char *, int);
static void gld_rem_vlan(gld_vlan_t *);
#ifdef GLD_DEBUG
static void gld_check_assertions(void);
extern void gld_sr_dump(gld_mac_info_t *);
#endif
/*
* Allocate and zero-out "number" structures each of type "structure" in
* kernel memory.
*/
#define abs(a) ((a) < 0 ? -(a) : a)
/*
* The device is of DL_ETHER type and is able to support VLAN by itself.
*/
#define VLAN_CAPABLE(macinfo) \
/*
* The set of notifications generatable by GLD itself, the additional
* set that can be generated if the MAC driver provide the link-state
* tracking callback capability, and the set supported by the GLD
* notification code below.
*
* PLEASE keep these in sync with what the code actually does!
*/
/* Media must correspond to #defines in gld.h */
static char *gld_media[] = {
"unknown", /* GLDM_UNKNOWN - driver cannot determine media */
"aui", /* GLDM_AUI */
"bnc", /* GLDM_BNC */
"twpair", /* GLDM_TP */
"fiber", /* GLDM_FIBER */
"100baseT", /* GLDM_100BT */
"100vgAnyLan", /* GLDM_VGANYLAN */
"10baseT", /* GLDM_10BT */
"ring4", /* GLDM_RING4 */
"ring16", /* GLDM_RING16 */
"100baseTX", /* GLDM_100BTX */
"100baseT4", /* GLDM_100BT4 */
"unknown", /* skip */
"ipib", /* GLDM_IB */
};
/* Must correspond to #defines in gld.h */
static char *gld_duplex[] = {
"unknown", /* GLD_DUPLEX_UNKNOWN - not known or not applicable */
"half", /* GLD_DUPLEX_HALF */
"full" /* GLD_DUPLEX_FULL */
};
/*
* Interface types currently supported by GLD.
* If you add new types, you must check all "XXX" strings in the GLD source
* for implementation issues that may affect the support of your new type.
* In particular, any type with gldm_addrlen > 6, or gldm_saplen != -2, will
* require generalizing this GLD source to handle the new cases. In other
* words there are assumptions built into the code in a few places that must
*/
static gld_interface_t interfaces[] = {
/* Ethernet Bus */
{
(uint_t)-1,
sizeof (struct ether_header),
NULL,
"ether"
},
/* Fiber Distributed data interface */
{
4352,
sizeof (struct fddi_mac_frm),
NULL,
"fddi"
},
/* Token Ring interface */
{
17914,
-1, /* variable header size */
NULL,
"tpr"
},
/* Infiniband */
{
4092,
sizeof (struct ipoib_header),
"ipib"
},
};
/*
* bit reversal lookup table.
*/
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0,
0x30, 0xb0, 0x70, 0xf0, 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, 0x04, 0x84, 0x44, 0xc4,
0x24, 0xa4, 0x64, 0xe4, 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, 0x1c, 0x9c, 0x5c, 0xdc,
0x3c, 0xbc, 0x7c, 0xfc, 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, 0x0a, 0x8a, 0x4a, 0xca,
0x2a, 0xaa, 0x6a, 0xea, 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, 0x16, 0x96, 0x56, 0xd6,
0x36, 0xb6, 0x76, 0xf6, 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, 0x01, 0x81, 0x41, 0xc1,
0x21, 0xa1, 0x61, 0xe1, 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, 0x19, 0x99, 0x59, 0xd9,
0x39, 0xb9, 0x79, 0xf9, 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, 0x0d, 0x8d, 0x4d, 0xcd,
0x2d, 0xad, 0x6d, 0xed, 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, 0x13, 0x93, 0x53, 0xd3,
0x33, 0xb3, 0x73, 0xf3, 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, 0x07, 0x87, 0x47, 0xc7,
0x27, 0xa7, 0x67, 0xe7, 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf,
0x3f, 0xbf, 0x7f, 0xff,
};
/*
* User priorities, mapped from b_band.
*/
static uint32_t user_priority[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
};
/*
* Module linkage information for the kernel.
*/
&mod_miscops, /* Type of module - a utility provider */
#ifdef GLD_DEBUG
" DEBUG"
#endif
};
static struct modlinkage modlinkage = {
};
int
_init(void)
{
int e;
/* initialize gld_device_list mutex */
/* initialize device driver (per-major) list */
if ((e = mod_install(&modlinkage)) != 0)
return (e);
}
int
_fini(void)
{
int e;
if ((e = mod_remove(&modlinkage)) != 0)
return (e);
return (e);
}
int
{
}
/*
* GLD service routines
*/
/* So this gld binary maybe can be forward compatible with future v2 drivers */
/*ARGSUSED*/
{
KM_SLEEP);
/*
* The setting of gldm_driver_version will not be documented or allowed
* until a future release.
*/
/*
* GLD's version. This also is undocumented for now, but will be
* available if needed in the future.
*/
return (macinfo);
}
/*
* gld_mac_free must be called after the driver has removed interrupts
* and completely stopped calling gld_recv() and gld_sched(). At that
* point the interrupt routine is guaranteed by the system to have been
* exited and the maclock is no longer needed. Of course, it is
* expected (required) that (assuming gld_register() succeeded),
* gld_unregister() was called before gld_mac_free().
*/
void
{
/*
* Assert that if we made it through gld_register, then we must
* have unregistered.
*/
}
/*
* gld_register -- called once per device instance (PPA)
*
* During its attach routine, a real device driver will register with GLD
* so that later opens and dl_attach_reqs will work. The arguments are the
* devinfo pointer, the device name, and a macinfo structure describing the
* physical device instance.
*/
int
{
int mediatype;
char minordev[32];
return (DDI_FAILURE);
/*
* Entry points should be ready for us.
* ioctl is optional.
* set_multicast and get_stats are optional in v0.
* intr is only required if you add an interrupt.
*/
return (DDI_FAILURE);
}
/*
* GLD only functions properly with saplen == -2
*/
return (DDI_FAILURE);
}
/* see gld_rsrv() */
/*
* Allocate per-driver (major) data structure if necessary
*/
/* first occurrence of this device name (major number) */
return (DDI_FAILURE);
}
/* allow increase of number of supported multicast addrs */
/*
* Optionally restrict DLPI provider style
*
* -1 - don't create style 1 nodes
* -2 - don't create style 2 nodes
*/
"gld-provider-styles", 0);
/* Stuff that's needed before any PPA gets attached */
KM_SLEEP);
}
glddev->gld_ndevice++;
/* Now glddev can't go away until we unregister this mac (or fail) */
/*
* Per-instance initialization
*/
/*
* Initialize per-mac structure that is private to GLD.
* Set up interface pointer. These are device class specific pointers
*/
for (i = 0; i < sizeof (interfaces)/sizeof (*interfaces); i++) {
continue;
KM_SLEEP);
&interfaces[i];
break;
}
goto failure;
}
/*
* Driver can only register MTU within legal media range.
*/
devname);
goto failure;
}
/*
* Correct margin size if it is not set.
*/
/*
* For now, only Infiniband drivers can use MDT. Do not add
* support for Ethernet, FDDI or TR.
*/
goto failure;
}
/*
* Validate entry points.
*/
goto failure;
}
}
/*
* XXX Do bit-reversed devices store gldm_vendor in canonical
* format or in wire format? Also gldm_broadcast. For now
* we are assuming canonical, but I'm not sure that makes the
* most sense for ease of driver implementation.
*/
/*
* The available set of notifications is those generatable by GLD
* itself, plus those corresponding to the capabilities of the MAC
* driver, intersected with those supported by gld_notify_ind() above.
*/
/*
* Now atomically get a PPA and put ourselves on the mac list.
*/
#ifdef DEBUG
#endif
/*
* Create style 2 node (gated by gld-provider-styles property).
*
* NOTE: When the CLONE_DEV flag is specified to
* ddi_create_minor_node() the minor number argument is
* immaterial. Opens of that node will go via the clone
* driver and gld_open() will always be passed a dev_t with
* minor of zero.
*/
goto late_failure;
}
}
/*
* Create style 1 node (gated by gld-provider-styles property)
*/
0) != DDI_SUCCESS) {
goto late_failure;
}
}
/* add ourselves to this major device's linked list of instances */
/*
* Unfortunately we need the ppa before we call gld_initstats();
* otherwise we would like to do this just above the mutex_enter
* above. In which case we could have set MAC_READY inside the
* mutex and we wouldn't have needed to check it in open and
* DL_ATTACH. We wouldn't like to do the initstats/kstat_create
* inside the mutex because it might get taken in our kstat_update
* routine and cause a deadlock with kstat_chain_lock.
*/
/* gld_initstats() calls (*ifp->init)() */
goto late_failure;
}
/*
* Need to indicate we are NOW ready to process interrupts;
* any interrupt before this is set is for someone else.
* This flag is also now used to tell open, et. al. that this
* mac is now fully ready and available for use.
*/
/* log local ethernet address -- XXX not DDI compliant */
(void) localetheraddr(
/* now put announcement into the message buffer */
macinfo->gldm_addrlen));
return (DDI_SUCCESS);
glddev->gld_ndevice--;
/*
* Note that just because this goes to zero here does not necessarily
* mean that we were the one who added the glddev above. It's
* possible that the first mac unattached while were were in here
* failing to attach the second mac. But we're now the last.
*/
if (glddev->gld_ndevice == 0) {
/* There should be no macinfos left */
/*
* There should be no DL_UNATTACHED streams: the system
* should not have detached the "first" devinfo which has
* all the open style 2 streams.
*
* XXX This is not clear. See gld_getinfo and Bug 1165519
*/
}
return (DDI_FAILURE);
}
/*
* gld_unregister (macinfo)
* remove the macinfo structure from local structures
* this is cleanup for a driver to be unloaded
*/
int
{
return (DDI_FAILURE);
}
#ifdef GLD_DEBUG
{
int i;
for (i = 0; i < VLAN_HASHSZ; i++) {
"%s, line %d: "
"mac_pvt->vlan_hash[%d] != NULL",
}
}
#endif
/* Delete this mac */
/* Disallow further entries to gld_recv() and gld_sched() */
/* We now have one fewer instance for this major device */
glddev->gld_ndevice--;
if (glddev->gld_ndevice == 0) {
/* There should be no macinfos left */
/*
* There should be no DL_UNATTACHED streams: the system
* should not have detached the "first" devinfo which has
* all the open style 2 streams.
*
* XXX This is not clear. See gld_getinfo and Bug 1165519
*/
}
return (DDI_SUCCESS);
}
/*
* gld_initstats
* called from gld_register
*/
static int
{
"GLD: failed to create kstat structure for %s%d",
return (GLD_FAILURE);
}
return (GLD_SUCCESS);
}
/* called from kstat mechanism, and from wsrv's get_statistics_req */
static int
{
if (rw == KSTAT_WRITE)
return (EACCES);
return (EIO); /* this one's not ready yet */
}
return (EIO); /* this one's not ready any more */
}
if (macinfo->gldm_get_stats)
else if (mac_pvt->nprom_multi)
else
? stats->glds_media : 0]);
case DL_ETHER:
stats->glds_duplex <
sizeof (gld_duplex) / sizeof (gld_duplex[0]) ?
stats->glds_duplex : 0]);
break;
case DL_TPR:
break;
case DL_FDDI:
break;
case DL_IB:
break;
default:
break;
}
#ifdef GLD_DEBUG
#endif
return (0);
}
static int
{
char *name;
int instance;
"GLD: failed to create kstat structure for %s%d",
return (GLD_FAILURE);
}
return (GLD_SUCCESS);
}
static int
{
if (rw == KSTAT_WRITE)
return (EACCES);
media : 0]);
return (0);
}
/*
* The device dependent driver specifies gld_getinfo as its getinfo routine.
*/
/*ARGSUSED*/
int
{
int rc = DDI_FAILURE;
switch (cmd) {
case DDI_INFO_DEVT2DEVINFO:
rc = DDI_SUCCESS;
}
break;
case DDI_INFO_DEVT2INSTANCE:
/* Need static mapping for deferred attach */
if (minor == GLD_USE_STYLE2) {
/*
* Style 2: this minor number does not correspond to
* any particular instance number.
*/
rc = DDI_FAILURE;
} else if (minor <= GLD_MAX_STYLE1_MINOR) {
/* Style 1: calculate the PPA from the minor */
rc = DDI_SUCCESS;
} else {
/* Clone: look for it. Not a static mapping */
rc = DDI_SUCCESS;
}
}
break;
}
return (rc);
}
/* called from gld_getinfo */
{
int i;
if (minor == GLD_USE_STYLE2) {
/*
* Style 2: this minor number does not correspond to
* any particular instance number.
*
* XXX We don't know what to say. See Bug 1165519.
*/
return (NULL);
}
/* There are no attached instances of this device */
return (NULL);
}
/*
* Search all attached macs and streams.
*
* XXX We don't bother checking the DL_UNATTACHED streams since
* we don't know what devinfo we should report back even if we
* found the minor. Maybe we should associate streams that are
* not currently attached to a PPA with the "first" devinfo node
* of the major device to attach -- the one that created the
* minor node for the generic device.
*/
continue; /* this one's not ready yet */
if (minor <= GLD_MAX_STYLE1_MINOR) {
/* Style 1 -- look for the corresponding PPA */
goto out; /* found it! */
} else
continue; /* not this PPA */
}
/* We are looking for a clone */
for (i = 0; i < VLAN_HASHSZ; i++) {
goto out;
}
}
}
}
}
out:
return (devinfo);
}
/*
* STREAMS open routine. The device dependent driver specifies this as its
* open entry point.
*/
/*ARGSUSED2*/
int
{
if (minor > GLD_MAX_STYLE1_MINOR)
return (ENXIO);
/* Find our per-major glddev_t structure */
/*
* This glddev will hang around since detach (and therefore
* gld_unregister) can't run while we're here in the open routine.
*/
return (ENXIO);
#ifdef GLD_DEBUG
if (minor == GLD_USE_STYLE2)
else
(void *)q, minor);
}
#endif
/*
* get a per-stream structure and link things together so we
* can easily find them later.
*/
/*
* fill in the structure and state info
*/
/*
* we must atomically find a free minor number and add the stream
* to a list, because gld_findminor has to traverse the lists to
* determine which minor numbers are free.
*/
/* find a free minor device number for the clone */
return (ENOSR);
}
#ifdef GLD_VERBOSE_DEBUG
#endif
if (minor == GLD_USE_STYLE2) {
#ifdef GLD_VERBOSE_DEBUG
#endif
(void) qassociate(q, -1);
goto done;
}
/* the PPA is actually 1 less than the minordev */
continue;
continue; /* this one's not ready yet */
/*
* we found the correct PPA
*/
else
/* now ready for action */
return (EIO);
}
return (EIO);
}
}
vlan->gldv_nstreams++;
#ifdef GLD_VERBOSE_DEBUG
"GLDstruct added to instance list");
#endif
break;
}
return (ENXIO);
}
done:
qprocson(q); /* start the queues running */
return (0);
}
/*
* normal stream close call checks current status and cleans up
* data structures that were dynamically allocated
*/
/*ARGSUSED1*/
int
{
ASSERT(q);
#ifdef GLD_DEBUG
}
#endif
/* Hold all device streams lists still while we check for a macinfo */
/* If there's a macinfo, block recv while we change state */
} else {
/* no mac DL_ATTACHED right now */
}
/*
* qprocsoff before we call gld_unbind/gldunattach, so that
* we know wsrv isn't in there trying to undo what we're doing.
*/
qprocsoff(q);
/* Need to unbind */
}
/*
* Need to unattach
* For style 2 stream, gldunattach also
* associate queue with NULL dip
*/
}
/* disassociate the stream from the device */
/*
* Since we unattached above (if necessary), we know that we're
* on the per-major list of unattached streams, rather than a
* per-PPA list. So we know we should hold the devlock.
*/
return (0);
}
/*
* gld_rsrv (q)
* simple read service procedure
* purpose is to avoid the time it takes for packets
* to move through IP so we can get them off the board
* as fast as possible due to limited PC resources.
*
* This is not normally used in the current implementation. It
* can be selected with the undocumented property "fast_recv".
* If that property is set, gld_recv will send the packet
* upstream with a putq() rather than a putnext(), thus causing
* this routine to be scheduled.
*/
int
{
if (canputnext(q)) {
} else {
}
}
return (0);
}
/*
* gld_wput (q, mp)
* general gld stream write put routine. Receives fastpath data from upper
* queued for later processing by the service procedure.
*/
int
{
int rc;
#ifdef GLD_DEBUG
#endif
case M_DATA:
/* fast data / raw support */
/* we must be DL_ATTACHED and DL_BOUND to do this */
/* Tricky to access memory without taking the mutex */
break;
}
/*
* Cleanup MBLK_VTAG in case it is set by other
* modules. MBLK_VTAG is used to save the vtag information.
*/
/* LINTED: E_CASE_FALLTHRU */
case M_MULTIDATA:
/* Only call gld_start() directly if nothing queued ahead */
/* No guarantees about ordering with different threads */
if (q->q_first)
goto use_wsrv;
/*
* This can happen if wsrv has taken off the last mblk but
* is still processing it.
*/
if (gld->gld_in_wsrv)
goto use_wsrv;
/*
* Keep a count of current wput calls to start.
* Nonzero count delays any attempted DL_UNBIND.
* See comments above gld_start().
*/
membar_enter();
/* Recheck state now wput_count is set to prevent DL_UNBIND */
/* If this Q is in process of DL_UNBIND, don't call start */
/* Extremely unlikely */
goto use_wsrv;
}
/*
* Get the priority value. Note that in raw mode, the
* per-packet priority value kept in b_band is ignored.
*/
/* Allow DL_UNBIND again */
membar_exit();
if (rc == GLD_NORESOURCES)
qenable(q);
break; /* Done with this packet */
/* Q not empty, in DL_DETACH, or start gave NORESOURCES */
qenable(q);
break;
case M_IOCTL:
/* ioctl relies on wsrv single threading per queue */
qenable(q);
break;
case M_CTL:
qenable(q);
break;
case M_FLUSH: /* canonical flush handling */
/* XXX Should these be FLUSHALL? */
flushq(q, 0);
} else
break;
case M_PROTO:
case M_PCPROTO:
/* these rely on wsrv single threading per queue */
qenable(q);
break;
default:
#ifdef GLD_DEBUG
"gld: Unexpected packet type from queue: 0x%x",
#endif
}
return (0);
}
/*
* gld_wsrv - Incoming messages are processed according to the DLPI protocol
* specification.
*
* wsrv is single-threaded per Q. We make use of this to avoid taking the
* lock for reading data items that are only ever written by us.
*/
int
{
union DL_primitives *prim;
int err;
#ifdef GLD_DEBUG
#endif
return (0);
/*
* Help wput avoid a call to gld_start if there might be a message
* previously queued by that thread being processed here.
*/
membar_enter();
case M_DATA:
case M_MULTIDATA:
/*
* retry of a previously processed UNITDATA_REQ
* or is a RAW or FAST message from above.
*/
/* No longer attached to a PPA, drop packet */
break;
}
membar_enter();
/*
* Get the priority value. Note that in raw mode, the
* per-packet priority value kept in b_band is ignored.
*/
if (err == GLD_NORESOURCES) {
/* gld_sched will qenable us later */
membar_enter();
/*
* v2: we're not holding the lock; it's
* possible that the driver could have already
* called gld_sched (following up on its
* return of GLD_NORESOURCES), before we got a
* chance to do the putbq() and set gld_xwait.
* So if we saw a call to gld_sched that
* examined this queue, since our call to
* gld_start() above, then it's possible we've
* already seen the only call to gld_sched()
* we're ever going to see. So we better retry
* transmitting this packet right now.
*/
if (gld->gld_sched_ran) {
#ifdef GLD_DEBUG
"sched was called");
#endif
break; /* try again right now */
}
return (0);
}
break;
case M_IOCTL:
break;
case M_CTL:
break;
}
} else {
/* This driver doesn't recognize, just drop */
}
break;
case M_PROTO: /* Will be an DLPI message of some type */
case M_PCPROTO:
if (err == GLDE_RETRY) {
return (0); /* quit while we're ahead */
}
}
break;
default:
/* This should never happen */
#ifdef GLD_DEBUG
"gld_wsrv: db_type(%x) not supported",
#endif
break;
}
}
membar_exit();
return (0);
}
/*
* gld_start() can get called from gld_wput(), gld_wsrv(), or gld_unitdata().
*
* We only come directly from wput() in the GLD_FAST (fastpath) or RAW case.
*
* In particular, we must avoid calling gld_precv*() if we came from wput().
* gld_precv*() is where we, on the transmit side, loop back our outgoing
* packets to the receive side if we are in physical promiscuous mode.
* Since the receive side holds a lock across its call to the upstream
* putnext, and that upstream module could well have looped back to our
* wput() routine on the same thread, we cannot call gld_precv* from here
* for fear of causing a recursive lock entry in our receive code.
*
* There is a problem here when coming from gld_wput(). While wput
* only comes here if the queue is attached to a PPA and bound to a SAP
* and there are no messages on the queue ahead of the M_DATA that could
* change that, it is theoretically possible that another thread could
* now wput a DL_UNBIND and a DL_DETACH message, and the wsrv() routine
* could wake up and process them, before we finish processing this
* send of the M_DATA. This can only possibly happen on a Style 2 RAW or
* and Style 1 streams only DL_DETACH in the close routine, where
* qprocsoff() protects us. If this happens we could end up calling
* gldm_send() after we have detached the stream and possibly called
* gldm_stop(). Worse, once the number of attached streams goes to zero,
* detach/unregister could be called, and the macinfo could go away entirely.
*
* No one has ever seen this happen.
*
* It is some trouble to fix this, and we would rather not add any mutex
* logic into the wput() routine, which is supposed to be a "fast"
* path.
*
* What I've done is use an atomic counter to keep a count of the number
* of threads currently calling gld_start() from wput() on this stream.
* If DL_DETACH sees this as nonzero, it putbqs the request back onto
* the queue and qenables, hoping to have better luck next time. Since
* people shouldn't be trying to send after they've asked to DL_DETACH,
* hopefully very soon all the wput=>start threads should have returned
* and the DL_DETACH will succeed. It's hard to test this since the odds
* of the failure even trying to happen are so small. I probably could
* have ignored the whole issue and never been the worse for it.
*
* Because some GLDv2 Ethernet drivers do not allow the size of transmitted
* packet to be greater than ETHERMAX, we must first strip the VLAN tag
* from a tagged packet before passing it to the driver's gld_send() entry
* point function, and pass the VLAN tag as a separate argument. The
* gld_send() function may fail. In that case, the packet will need to be
* queued in order to be processed again in GLD's service routine. As the
* VTAG has already been stripped at that time, we save the VTAG information
* in (the unused fields of) dblk using GLD_SAVE_MBLK_VTAG(), so that the
* VTAG can also be queued and be able to be got when gld_start() is called
* next time from gld_wsrv().
*
* Some rules to use GLD_{CLEAR|SAVE}_MBLK_VTAG macros:
*
* - GLD_SAVE_MBLK_VTAG() must be called to save the VTAG information each time
* the message is queued by putbq().
*
* - GLD_CLEAR_MBLK_VTAG() must be called to clear the bogus VTAG information
* (if any) in dblk before the message is passed to the gld_start() function.
*/
static int
{
int rc;
/*
* If this interface is a VLAN, the kstats of corresponding
* "VLAN 0" should also be updated. Note that the gld_vlan_t
* structure for VLAN 0 might not exist if there are no DLPI
* consumers attaching on VLAN 0. Fortunately we can directly
* access VLAN 0's kstats from macinfo.
*
* Therefore, stats0 (VLAN 0's kstats) must always be
* updated, and stats must to be updated if it is not NULL.
*/
if (vid != VLAN_VID_NONE)
#ifdef GLD_DEBUG
"gld_start: failed to interpret outbound packet");
#endif
goto badarg;
}
if (GLD_VTAG_TCI(raw_vtag) != 0) {
/*
* Tagged packet.
*/
/*
* In raw mode, we only expect untagged packets or
* special priority-tagged packets on a VLAN stream.
* Drop the packet if its VID is not zero.
*/
goto badarg;
/*
* If it is raw mode, use the per-stream priority if
* the priority is not specified in the packet.
* Otherwise, ignore the priority bits in the packet.
*/
}
/*
* This link is a physical link but the packet is
* a VLAN tagged packet, the kstats of corresponding
* VLAN (if any) should also be updated.
*/
}
} else {
/*
* Untagged packet:
* Get vtag from the attached PPA of this stream.
*/
if ((vid != VLAN_VID_NONE) ||
}
}
/*
* We're not holding the lock for this check. If the promiscuous
* state is in flux it doesn't matter much if we get this wrong.
*/
/*
* We want to loopback to the receive side, but to avoid
* recursive lock entry: if we came from wput(), which
* could have looped back via IP from our own receive
* interrupt thread, we decline this request. wput()
* will then queue the packet for wsrv(). This means
* that when snoop is running we don't get the advantage
* of the wput() multithreaded direct entry to the
* driver's send routine.
*/
return (GLD_NORESOURCES);
}
else
} else
macinfo->gldm_maxpkt) {
if (nmp)
#ifdef GLD_DEBUG
"gld_start: oversize outbound packet, size %d,"
#endif
goto badarg;
}
if (rc != GLD_SUCCESS) {
if (rc == GLD_NORESOURCES) {
} else {
/* transmit error; drop the packet */
/* We're supposed to count failed attempts as well */
#ifdef GLD_DEBUG
"gld_start: gldm_send failed %d", rc);
#endif
}
if (nmp)
return (rc);
}
/*
* Loopback case. The message needs to be returned back on
* the read side. This would silently fail if the dupmsg fails
* above. This is probably OK, if there is no memory to dup the
* block, then there isn't much we could do anyway.
*/
if (nmp) {
}
return (GLD_SUCCESS);
return (GLD_BADARG);
}
/*
* With MDT V.2 a single message mp can have one header area and multiple
* payload areas. A packet is described by dl_pkt_info, and each packet can
* span multiple payload areas (currently with TCP, each packet will have one
* header and at the most two payload areas). MACs might have a limit on the
* number of payload segments (i.e. per packet scatter-gather limit), and
* MDT V.2 has a way of specifying that with mdt_span_limit; the MAC driver
* might also have a limit on the total number of payloads in a message, and
* that is specified by mdt_max_pld.
*/
static int
{
void *cookie;
/*
* We're not holding the lock for this check. If the promiscuous
* state is in flux it doesn't matter much if we get this wrong.
*/
/*
* We want to loopback to the receive side, but to avoid
* recursive lock entry: if we came from wput(), which
* could have looped back via IP from our own receive
* interrupt thread, we decline this request. wput()
* will then queue the packet for wsrv(). This means
* that when snoop is running we don't get the advantage
* of the wput() multithreaded direct entry to the
* driver's send routine.
*/
return (GLD_NORESOURCES);
}
/*
* unlike the M_DATA case, we don't have to call
* dupmsg_noloan here because mmd_transform
* (called by gld_precv_mdt) will make a copy of
* each dblk.
*/
}
/*
* The lower layer driver only gets a single multidata
* message; this also makes it easier to handle noresources.
*/
/*
* Get number of packets in this message; if nothing
* to transmit, go to next message.
*/
continue;
}
/*
* Run interpreter to populate media specific pktinfo fields.
* This collects per MDT message information like sap,
*/
if (numpacks > 0) {
/*
* Driver indicates it can transmit at least 1, and
* possibly all, packets in MDT message.
*/
/*
* Format this packet by adding link header and
* adjusting pdescinfo to include it; get
* packet length.
*/
/*
* Loop back packet before handing to the
* driver.
*/
if (doloop &&
}
/*
* And send off to driver.
*/
&pinfo);
/*
* Be careful not to invoke getnextpdesc if we
* already sent the last packet, since driver
* might have posted it to hardware causing a
* completion and freemsg() so the MDT data
* structures might not be valid anymore.
*/
if (--count == 0)
break;
}
/*
* In the noresources case (when driver indicates it
* can not transmit all packets in the MDT message),
* adjust to skip the first few packets on retrial.
*/
/*
* Release already processed packet descriptors.
*/
&pinfo);
}
glds_xmtretry, 1);
return (GLD_NORESOURCES);
}
} else if (numpacks == 0) {
/*
* Driver indicates it can not transmit any packets
* currently and will request retrial later.
*/
return (GLD_NORESOURCES);
} else {
/*
* We're supposed to count failed attempts as well.
*/
/*
* Call interpreter to determine total packet
* bytes that are being dropped.
*/
}
/*
* Transmit error; drop the message, move on
* to the next one.
*/
}
/*
* Process the next multidata block, if there is one.
*/
}
return (GLD_SUCCESS);
}
/*
* gld_intr (macinfo)
*/
{
return (DDI_INTR_UNCLAIMED);
}
/*
* gld_sched (macinfo)
*
* This routine scans the streams that refer to a specific macinfo
* structure and causes the STREAMS scheduler to try to run them if
* they are marked as waiting for the transmit buffer.
*/
void
{
int i;
/* We're probably being called from a leftover interrupt */
return;
}
for (i = 0; i < VLAN_HASHSZ; i++) {
membar_enter();
}
}
}
}
}
/*
* gld_precv (macinfo, mp, vtag, stats)
* called from gld_start to loopback a packet when in promiscuous mode
*
* VLAN 0's statistics need to be updated. If stats is not NULL,
* it needs to be updated as well.
*/
static void
{
/*
* call the media specific packet interpreter routine
*/
#ifdef GLD_DEBUG
"gld_precv: interpreter failed");
#endif
return;
}
/*
* Update the vtag information.
*/
}
/*
* Called from gld_start_mdt to loopback packet(s) when in promiscuous mode.
* Note that 'vlan' is always a physical link, because MDT can only be
* enabled on non-VLAN streams.
*/
/*ARGSUSED*/
static void
{
/*
* Get source/destination.
*/
}
/*
* gld_recv (macinfo, mp)
* called with an mac-level packet in a mblock; take the maclock,
* try the ip4q and ip6q hack, and otherwise call gld_sendup.
*
* V0 drivers already are holding the mutex when they call us.
*/
void
{
}
void
{
int err;
/* We're probably being called from a leftover interrupt */
goto done;
}
/*
* If this packet is a VLAN tagged packet, the kstats of corresponding
* "VLAN 0" should also be updated. We can directly access VLAN 0's
* kstats from macinfo.
*
* Further, the packets needs to be passed to VLAN 0 if there is
* any DLPI consumer on VLAN 0 who is interested in tagged packets
* (DL_PROMISC_SAP is on or is bounded to ETHERTYPE_VLAN SAP).
*/
if (vid != VLAN_VID_NONE) {
/*
* If there are no physical DLPI consumers interested in the
* VLAN packet, clear vlan0.
*/
/*
* vlann is the VLAN with the same VID as the VLAN packet.
*/
}
goto done;
}
/*
* Check whether underlying media code supports the IPQ hack:
*
* - the interpreter could quickly parse the packet
* - the device type supports IPQ (ethernet and IPoIB)
* - there is one, and only one, IP stream bound (to this VLAN)
* - that stream is a "fastpath" stream
* - the packet is of type ETHERTYPE_IP or ETHERTYPE_IPV6
* - there are no streams in promiscuous mode (on this VLAN)
* - if this packet is tagged, there is no need to send this
* packet to physical streams
*/
case ETHERTYPE_IP:
break;
case ETHERTYPE_IPV6:
break;
}
}
/*
* Special case for IP; we can simply do the putnext here, if:
* o The IPQ hack is possible (ipq != NULL).
* o the packet is specifically for me, and therefore:
* - the packet is not multicast or broadcast (fastpath only
* wants unicast packets).
*
* o the stream is not asserting flow control.
*/
canputnext(ipq)) {
/*
* in this packet
*/
goto done;
}
/*
* call the media specific packet interpreter routine
*/
#ifdef GLD_DEBUG
"gld_recv_tagged: interpreter failed");
#endif
goto done;
}
/*
* This is safe even if vtag is VLAN_VTAG_NONE
*/
#ifdef GLD_DEBUG
#endif
#ifdef GLD_DEBUG
"Hdr: %d,%d isMulticast: %s\n",
}
#endif
done:
}
/* =================================================================== */
/* receive group: called from gld_recv and gld_precv* with maclock held */
/* =================================================================== */
/*
* Search all the streams attached to the specified VLAN looking for
* those eligible to receive the packet.
* Note that in order to avoid an extra dupmsg(), if this is the first
* eligible stream, remember it (in fgldp) so that we can send up the
* message after this function.
*
* Return errno if fails. Currently the only error is ENOMEM.
*/
static int
{
int err = 0;
#ifdef GLD_VERBOSE_DEBUG
#endif
continue; /* not eligible to receive */
continue; /* not eligible to receive */
#ifdef GLD_DEBUG
"gld_sendup: queue sap: %4x promis: %s %s %s",
#endif
/*
* The accept function differs depending on whether this is
* a packet that we received from the wire or a loopback.
*/
/* sap matches */
/*
* Upper stream is not accepting messages, i.e.
* it is flow controlled, therefore we will
* forgo sending the message up this stream.
*/
#ifdef GLD_DEBUG
"gld_sendup: canput failed");
#endif
continue;
}
/*
* In order to avoid an extra dupmsg(), remember this
* gld if this is the first eligible stream.
*/
continue;
}
/* duplicate the packet for this stream */
glds_gldnorcvbuf, 1);
#ifdef GLD_DEBUG
"gld_sendup: dupmsg failed");
#endif
/* couldn't get resources; drop it */
break;
}
/* pass the message up the stream */
}
}
return (err);
}
/*
* gld_sendup (macinfo, pktinfo, mp, acceptfunc)
* called with an ethernet packet in an mblk; must decide whether
* packet is for us and which streams to queue it to.
*/
static void
{
int err = 0;
#ifdef GLD_DEBUG
(void *)macinfo);
#endif
/*
* The tagged packets should also be looped back (transmit-side)
* or sent up (receive-side) to VLAN 0 if VLAN 0 is set to
* DL_PROMISC_SAP or there is any DLPI consumer bind to the
* ETHERTYPE_VLAN SAP. The kstats of VLAN 0 needs to be updated
* as well.
*/
}
/*
* The "fast" in "GLDOPT_FAST_RECV" refers to the speed at which
* gld_recv returns to the caller's interrupt routine. The total
* network throughput would normally be lower when selecting this
* option, because we putq the messages and process them later,
* instead of sending them with putnext now. Some time critical
* device might need this, so it's here but undocumented.
*/
} else {
}
/*
* Send the packets for all eligible streams.
*/
}
}
/* send the original dup of the packet up the first stream found */
if (fgld)
else
/* We do not count looped back packets */
if (acceptfunc == gld_paccept)
return; /* transmit loopback case */
if (pktinfo->isBroadcast)
else if (pktinfo->isMulticast)
/* No stream accepted this packet */
if (!pktinfo->wasAccepted)
}
#define GLD_IS_PHYS(gld) \
/*
* A packet matches a stream if:
* The stream's VLAN id is the same as the one in the packet.
* and the stream accepts EtherType encoded packets and the type matches
* or the stream accepts LLC packets and the packet is an LLC packet
*/
/*
* This function validates a packet for sending up a particular
* stream. The message header has been parsed and its characteristic
* are recorded in the pktinfo data structure. The streams stack info
* are presented in gld data structures.
*/
static int
{
/*
* if there is no match do not bother checking further.
* Note that it is okay to examine gld_vlan because
* macinfo->gldm_lock is held.
*
* Because all tagged packets have SAP value ETHERTYPE_VLAN,
* these packets will pass the SAP filter check if the stream
* is a ETHERTYPE_VLAN listener.
*/
return (0);
/*
* We don't accept any packet from the hardware if we originated it.
* (Contrast gld_paccept, the send-loopback accept function.)
*/
return (0);
/*
* If the packet is broadcast or sent to us directly we will accept it.
* Also we will accept multicast packets requested by the stream.
*/
return (1);
/*
* Finally, accept anything else if we're in promiscuous mode
*/
return (1);
return (0);
}
/*
* Return TRUE if the given multicast address is one
* of those that this particular Stream is interested in.
*/
static int
{
/*
* Return FALSE if not a multicast address.
*/
if (!pktinfo->isMulticast)
return (0);
/*
* Check if all multicasts have been enabled for this Stream
*/
return (1);
/*
* Return FALSE if no multicast addresses enabled for this Stream.
*/
return (0);
/*
* Otherwise, look for it in the table.
*/
}
/*
* gld_multicast determines if the address is a multicast address for
* this stream.
*/
static int
{
int i;
return (0);
for (i = 0; i < gld->gld_multicnt; i++) {
return (1);
}
}
return (0);
}
/*
* accept function for looped back packets
*/
static int
{
/*
* Note that it is okay to examine gld_vlan because macinfo->gldm_lock
* is held.
*
* If a stream is a ETHERTYPE_VLAN listener, it must
* accept all tagged packets as those packets have SAP value
* ETHERTYPE_VLAN.
*/
}
static void
{
int skiplen;
#ifdef GLD_DEBUG
#endif
/*
* Figure out how much of the packet header to throw away.
*
* DL_UNITDATA_IND M_PROTO message block prepended to the M_DATA.
*/
/*
* The packet will be tagged in the following cases:
* - if priority is not 0
* - a tagged packet sent on a physical link
*/
skiplen = 0;
} else {
/*
* The packet will be tagged if it meets all below conditions:
* - this is a physical stream
* - this packet is tagged packet
* - the stream is either a DL_PROMISC_SAP listener or a
* ETHERTYPE_VLAN listener
*/
}
if (gld->gld_ethertype)
}
/*
* If the interpreter did its job right, then it cannot be
* asking us to skip more bytes than are in the packet!
* However, there could be zero data bytes left after the
* amount to skip. DLPI specifies that passed M_DATA blocks
* should contain at least one byte of data, so if we have
* none we just drop it.
*/
return;
}
if (addtag) {
return;
}
}
/*
* Skip over the header(s), taking care to possibly handle message
* fragments shorter than the amount we need to skip. Hopefully
* the driver will put the entire packet, or at least the entire
* header, into a single message block. But we handle it if not.
*/
}
/* Add M_PROTO if necessary, and pass upstream */
} else {
/* everybody else wants to see a unitdata_ind structure */
if (mp)
/* if it failed, gld_addudind already bumped statistic */
}
}
/*
* gld_addudind(gld, mp, pktinfo)
* format a DL_UNITDATA_IND message to be sent upstream to the user
*/
static mblk_t *
{
int size;
int type;
#ifdef GLD_DEBUG
#endif
/*
* Allocate the DL_UNITDATA_IND M_PROTO header, if allocation fails
* might as well discard since we can't go further
*/
size = sizeof (dl_unitdata_ind_t) +
#ifdef GLD_DEBUG
"gld_addudind: allocb failed");
#endif
}
if (tagged)
else
/*
* now setup the DL_UNITDATA_IND header
*
* XXX This looks broken if the saps aren't two bytes.
*/
return (nmp);
}
/* ======================================================= */
/* wsrv group: called from wsrv, single threaded per queue */
/* ======================================================= */
/*
* We go to some trouble to avoid taking the same lock during normal
* transmit processing as we do during normal receive processing.
*
* Elements of the per-instance macinfo and per-stream gld_t structures
* (Elements of the gld_mac_pvt_t structure are considered part of the
* macinfo structure for purposes of this discussion).
*
* However, it is more complicated than that:
*
* Elements of the macinfo structure that are set before the macinfo
* structure is added to its device list by gld_register(), and never
* thereafter modified, are accessed without requiring taking the lock.
* A similar rule applies to those elements of the gld_t structure that
* are written by gld_open() before the stream is added to any list.
*
* Most other elements of the macinfo structure may only be read or
* written while holding the maclock.
*
* Most writable elements of the gld_t structure are written only
* within the single-threaded domain of wsrv() and subsidiaries.
* The maclock need not be taken while within that domain
* simply to read those elements. Writing to them, even within
* that domain, or reading from it outside that domain, requires
* holding the maclock. Exception: if the stream is not
* presently attached to a PPA, there is no associated macinfo,
* and no maclock need be taken.
*
* The curr_macaddr element of the mac private structure is also
* of that structure. However, there are a few instances in the
* transmit path where we choose to forgo lock protection when
* reading this variable. This is to avoid lock contention between
* threads executing the DL_UNITDATA_REQ case and receive threads.
* In doing so we will take a small risk or a few corrupted packets
* during the short an rare times when someone is changing the interface's
* physical address. We consider the small cost in this rare case to be
* worth the benefit of reduced lock contention under normal operating
* 1. there is no guarantee at this layer of uncorrupted delivery.
* 2. the physaddr doesn't change very often - no performance hit.
* 3. if the physaddr changes, other stuff is going to be screwed
* up for a while anyway, while other sites refigure ARP, etc.,
* so losing a couple of packets is the least of our worries.
*
* The list of streams associated with a macinfo is protected by
* two locks: the per-macinfo maclock, and the per-major-device
* gld_devlock. Both must be held to modify the list, but either
* may be held to protect the list during reading/traversing. This
* allows independent locking for multiple instances in the receive
* path (using macinfo), while facilitating routines that must search
* the entire set of streams associated with a major device, such as
* gld_findminor(), gld_finddevinfo(), close(). The "nstreams"
* macinfo element, and the gld_mac_info gld_t element, are similarly
* protected, since they change at exactly the same time macinfo
* streams list does.
*
* The list of macinfo structures associated with a major device
* structure is protected by the gld_devlock, as is the per-major
* list of Style 2 streams in the DL_UNATTACHED state.
*
* The list of major devices is kept on a module-global list
* gld_device_list, which has its own lock to protect the list.
*
* When it is necessary to hold more than one lock at a time, they
* are acquired in this "outside in" order:
* gld_device_list.gld_devlock
* glddev->gld_devlock
* GLDM_LOCK(macinfo)
*
* Finally, there are some "volatile" elements of the gld_t structure
* used for synchronization between various routines that don't share
* the same mutexes. See the routines for details. These are:
* gld_xwait between gld_wsrv() and gld_sched()
* gld_sched_ran between gld_wsrv() and gld_sched()
* gld_in_unbind between gld_wput() and wsrv's gld_unbind()
* gld_wput_count between gld_wput() and wsrv's gld_unbind()
* gld_in_wsrv between gld_wput() and gld_wsrv()
* (used in conjunction with q->q_first)
*/
/*
* gld_ioctl (q, mp)
* handles all ioctl requests passed downstream. This routine is
* passed a pointer to the message block with the ioctl request in it, and a
* pointer to the queue so it can respond to the ioctl request with an ack.
*/
int
{
#ifdef GLD_DEBUG
#endif
case DLIOCRAW: /* raw M_DATA mode */
break;
case DL_IOC_HDR_INFO: /* fastpath */
/*
* DL_IOC_HDR_INFO should only come from IP. The one
* initiated from user-land should not be allowed.
*/
if ((gld_global_options & GLD_OPT_NO_FASTPATH) ||
break;
}
break;
case DLIOCMARGININFO: { /* margin size */
int err;
break;
}
break;
}
break;
}
default:
break;
}
break;
}
return (0);
}
/*
* Since the rules for "fastpath" mode don't seem to be documented
* anywhere, I will describe GLD's rules for fastpath users here:
*
* Once in this mode you remain there until close.
* You must be bound (DL_IDLE) to transmit.
* There are other rules not listed above.
*/
static void
{
int error;
return;
}
if (error != 0) {
return;
}
return;
}
/*
* We take his fastpath request as a declaration that he will accept
* M_DATA messages from us, whether or not we are willing to accept
* them from him. This allows us to have fastpath in one direction
* (flow upstream) even on media with Source Routing, where we are
* unable to provide a fixed MAC header to be prepended to downstream
* flowing packets. So we set GLD_FAST whether or not we decide to
* allow him to send M_DATA down to us.
*/
/* This will fail for Source Routing media */
/* Also on Ethernet on 802.2 SAPs */
return;
}
/*
* Link new mblk in after the "request" mblks.
*/
}
/*
* gld_cmds (q, mp)
* process the DL commands as defined in dlpi.h
* note that the primitives return status which is passed back
* to the service procedure. If the value is GLDE_RETRY, then
* it is assumed that processing must stop and the primitive has
* been put back onto the queue. If the value is any other error,
* then an error ack is generated by the service procedure.
*/
static int
{
int result = DL_BADPRIM;
/* Make sure we have at least dlp->dl_primitive */
return (DL_BADPRIM);
#ifdef GLD_DEBUG
"gld_cmds(%p, %p):dlp=%p, dlp->dl_primitive=%d",
#endif
switch (dlreq) {
case DL_UDQOS_REQ:
if (mblkl < DL_UDQOS_REQ_SIZE)
break;
break;
case DL_BIND_REQ:
if (mblkl < DL_BIND_REQ_SIZE)
break;
break;
case DL_UNBIND_REQ:
if (mblkl < DL_UNBIND_REQ_SIZE)
break;
break;
case DL_UNITDATA_REQ:
if (mblkl < DL_UNITDATA_REQ_SIZE)
break;
break;
case DL_INFO_REQ:
if (mblkl < DL_INFO_REQ_SIZE)
break;
break;
case DL_ATTACH_REQ:
if (mblkl < DL_ATTACH_REQ_SIZE)
break;
else
break;
case DL_DETACH_REQ:
if (mblkl < DL_DETACH_REQ_SIZE)
break;
else
break;
case DL_ENABMULTI_REQ:
if (mblkl < DL_ENABMULTI_REQ_SIZE)
break;
break;
case DL_DISABMULTI_REQ:
if (mblkl < DL_DISABMULTI_REQ_SIZE)
break;
break;
case DL_PHYS_ADDR_REQ:
if (mblkl < DL_PHYS_ADDR_REQ_SIZE)
break;
break;
case DL_SET_PHYS_ADDR_REQ:
if (mblkl < DL_SET_PHYS_ADDR_REQ_SIZE)
break;
break;
case DL_PROMISCON_REQ:
if (mblkl < DL_PROMISCON_REQ_SIZE)
break;
break;
case DL_PROMISCOFF_REQ:
if (mblkl < DL_PROMISCOFF_REQ_SIZE)
break;
break;
case DL_GET_STATISTICS_REQ:
if (mblkl < DL_GET_STATISTICS_REQ_SIZE)
break;
break;
case DL_CAPABILITY_REQ:
if (mblkl < DL_CAPABILITY_REQ_SIZE)
break;
break;
case DL_NOTIFY_REQ:
if (mblkl < DL_NOTIFY_REQ_SIZE)
break;
break;
case DL_XID_REQ:
case DL_XID_RES:
case DL_TEST_REQ:
case DL_TEST_RES:
case DL_CONTROL_REQ:
case DL_PASSIVE_REQ:
break;
default:
#ifdef GLD_DEBUG
"gld_cmds: unknown M_PROTO message: %d",
dlreq);
#endif
result = DL_BADPRIM;
}
return (result);
}
static int
{
return (DL_OUTSTATE);
if (dlp->dl_sub_length == 0)
return (gld_cap_ack(q, mp));
return (gld_cap_enable(q, mp));
}
static int
{
subsize += sizeof (dl_capability_sub_t) +
sizeof (dl_capab_hcksum_t);
subsize += sizeof (dl_capability_sub_t) +
sizeof (dl_capab_zerocopy_t);
subsize += (sizeof (dl_capability_sub_t) +
sizeof (dl_capab_mdt_t));
DL_CAPABILITY_ACK)) == NULL)
return (GLDE_OK);
dlap->dl_sub_offset = 0;
dlhp->hcksum_txflags = 0;
}
}
dlmp->mdt_hdr_tail = 0;
}
return (GLDE_OK);
}
static int
{
return (DL_BADPRIM);
return (DL_BADPRIM);
case DL_CAPAB_HCKSUM:
/* nothing useful we can do with the contents */
break;
default:
break;
}
}
return (GLDE_OK);
}
/*
* Send a copy of the DL_NOTIFY_IND message <mp> to each stream that has
* requested the specific <notification> that the message carries AND is
* eligible and ready to receive the notification immediately.
*
* This routine ignores flow control. Notifications will be sent regardless.
*
* In all cases, the original message passed in is freed at the end of
* the routine.
*/
static void
{
int i;
/*
* Search all the streams attached to this macinfo looking
* for those eligible to receive the present notification.
*/
for (i = 0; i < VLAN_HASHSZ; i++) {
continue; /* not eligible - skip */
continue; /* not wanted - skip */
continue; /* can't copy - skip */
/*
* All OK; send dup'd notification up this
* stream
*/
}
}
}
/*
* Drop the original message block now
*/
}
/*
* For each (understood) bit in the <notifications> argument, contruct
* a DL_NOTIFY_IND message and send it to the specified <q>, or to all
* eligible queues if <q> is NULL.
*/
static void
{
/*
* The following cases shouldn't happen, but just in case the
* MAC driver calls gld_linkstate() at an inappropriate time, we
* check anyway ...
*/
return; /* not ready yet */
}
return; /* not ready anymore */
}
/*
* Make sure the kstats are up to date, 'cos we use some of
* the kstat values below, specifically the link speed ...
*/
if (macinfo->gldm_get_stats)
if ((notifications & bit) == 0)
continue;
notifications &= ~bit;
if (bit == DL_NOTE_PHYS_ADDR)
continue;
dlnip->dl_notification = 0;
dlnip->dl_addr_length = 0;
dlnip->dl_addr_offset = 0;
switch (bit) {
case DL_NOTE_PROMISC_ON_PHYS:
case DL_NOTE_PROMISC_OFF_PHYS:
break;
case DL_NOTE_LINK_DOWN:
break;
case DL_NOTE_LINK_UP:
break;
case DL_NOTE_SPEED:
/*
* Conversion required here:
* GLD keeps the speed in bit/s in a uint64
* DLPI wants it in kb/s in a uint32
* Fortunately this is still big enough for 10Gb/s!
*/
break;
case DL_NOTE_PHYS_ADDR:
break;
default:
break;
}
if (dlnip->dl_notification == 0)
else if (q != NULL)
else
}
}
/*
* gld_notify_req - handle a DL_NOTIFY_REQ message
*/
static int
{
#ifdef GLD_DEBUG
(void *)q, (void *)mp);
#endif
#ifdef GLD_DEBUG
#endif
return (DL_OUTSTATE);
}
/*
* Remember what notifications are required by this stream
*/
/*
* The return DL_NOTIFY_ACK carries the bitset of notifications
* that this driver can provide, independently of which ones have
* previously been or are now being requested.
*/
DL_NOTIFY_ACK)) == NULL)
return (DL_SYSERR);
/*
* A side effect of a DL_NOTIFY_REQ is that after the DL_NOTIFY_ACK
* reply, the the requestor gets zero or more DL_NOTIFY_IND messages
* that provide the current status.
*/
return (GLDE_OK);
}
/*
* gld_linkstate()
* Called by driver to tell GLD the state of the physical link.
* As a side effect, sends a DL_NOTE_LINK_UP or DL_NOTE_LINK_DOWN
* notification to each client that has previously requested such
* notifications
*/
void
{
switch (newstate) {
default:
return;
case GLD_LINKSTATE_DOWN:
break;
case GLD_LINKSTATE_UP:
break;
case GLD_LINKSTATE_UNKNOWN:
notification = 0;
break;
}
notification = 0;
else
if (notification)
}
/*
* gld_udqos - set the current QoS parameters (priority only at the moment).
*/
static int
{
int off;
int len;
#ifdef GLD_DEBUG
#endif
#ifdef GLD_DEBUG
#endif
return (DL_OUTSTATE);
}
return (DL_BADQOSTYPE);
return (DL_BADQOSTYPE);
if (selp->dl_trans_delay != 0 &&
return (DL_BADQOSPARAM);
if (selp->dl_protection != 0 &&
return (DL_BADQOSPARAM);
if (selp->dl_residual_error != 0 &&
return (DL_BADQOSPARAM);
return (DL_BADQOSPARAM);
return (GLDE_OK);
}
static mblk_t *
{
return (NULL);
dlp->dl_max_conind = 0;
dlp->dl_xidtest_flg = 0;
return (mp);
}
/*
* gld_bind - determine if a SAP is already allocated and whether it is legal
* to do the bind at this time
*/
static int
{
#ifdef GLD_DEBUG
#endif
#ifdef GLD_DEBUG
#endif
#ifdef GLD_DEBUG
#endif
return (DL_OUTSTATE);
}
return (DL_UNSUPPORTED);
}
return (DL_NOAUTO);
}
/*
* Check sap validity and decide whether this stream accepts
* IEEE 802.2 (LLC) packets.
*/
if (sap > ETHERTYPE_MAX)
return (DL_BADSAP);
/*
* For compatibility with monolithic ethernet drivers, the range of
* SAP values is different for DL_ETHER media.
*/
case DL_ETHER:
break;
default:
break;
}
/* if we get to here, then the SAP is legal enough */
#ifdef GLD_DEBUG
#endif
/* ACK the BIND */
return (GLDE_OK);
}
return (DL_SYSERR);
}
/*
* gld_unbind - perform an unbind of an LSAP or ether type on the stream.
* The stream is still open and can be re-bound.
*/
static int
{
#ifdef GLD_DEBUG
#endif
#ifdef GLD_DEBUG
#endif
return (DL_OUTSTATE);
}
/*
* See comments above gld_start().
*/
membar_enter();
if (gld->gld_wput_count != 0) {
#ifdef GLD_DEBUG
#endif
qenable(q); /* try again soon */
return (GLDE_RETRY);
}
}
membar_exit();
/* mp is NULL if we came from close */
if (mp) {
gld_flushqueue(q); /* flush the queues */
}
return (GLDE_OK);
}
/*
* gld_inforeq - generate the response to an info request
*/
static int
{
int bufsize;
int sel_offset = 0;
int range_offset = 0;
int addr_offset;
int addr_length;
int sap_length;
int brdcst_offset;
int brdcst_length;
#ifdef GLD_DEBUG
#endif
} else {
}
bufsize = sizeof (dl_info_ack_t);
bufsize += addr_length;
bufsize += brdcst_length;
}
return (GLDE_OK); /* nothing more to be done */
if (sel_offset != 0) {
ASSERT(range_offset != 0);
}
/*
* If we are bound to a non-LLC SAP on any medium
* other than Ethernet, then we need room for a
* SNAP header. So we have to adjust the MTU size
* accordingly. XXX I suppose this should be done
* in gldutil.c, but it seems likely that this will
* always be true for everything GLD supports but
* Ethernet. Check this if you add another medium.
*/
/* copy macaddr and sap */
} else {
dlp->dl_addr_offset = 0;
}
/* copy broadcast addr */
} else {
/*
* No PPA is attached.
* The best we can do is use the values provided
* by the first mac that called gld_register.
*/
dlp->dl_addr_offset = 0;
}
return (GLDE_OK);
}
/*
* gld_unitdata (q, mp)
* message (first mblock), data is in remainder of message.
*
*/
static int
{
#ifdef GLD_DEBUG
#endif
#ifdef GLD_DEBUG
#endif
return (GLDE_OK);
}
return (GLDE_OK);
}
#ifdef GLD_DEBUG
(int)msglen);
#endif
return (GLDE_OK);
}
/* grab any checksum information that may be present */
/*
* Prepend a valid header for transmission
*/
#ifdef GLD_DEBUG
#endif
return (GLDE_OK);
}
/* apply any checksum information to the first block in the chain */
flags, 0);
qenable(q);
return (GLDE_RETRY);
}
return (GLDE_OK);
}
/*
* gldattach(q, mp)
* DLPI DL_ATTACH_REQ
* this attaches the stream to a PPA
*/
static int
{
return (DL_OUTSTATE);
if (vid > VLAN_VID_MAX)
return (DL_BADPPA);
int inst;
continue;
continue; /* this one's not ready yet */
/*
* VLAN sanity check
*/
return (DL_BADPPA);
}
/*
* We found the correct PPA, hold the instance
*/
return (DL_BADPPA);
}
/* Take the stream off the per-driver-class list */
/*
* We must hold the lock to prevent multiple calls
* to the reset and start routines.
*/
else
(void) qassociate(q, -1);
return (DL_BADPPA);
}
EIO);
(void) qassociate(q, -1);
return (GLDE_OK);
}
}
vlan->gldv_nstreams++;
#ifdef GLD_DEBUG
}
#endif
return (GLDE_OK);
}
return (DL_BADPPA);
}
/*
* gldunattach(q, mp)
* DLPI DL_DETACH_REQ
* detaches the mac layer from the stream
*/
int
{
int i;
int op = GLD_MAC_PROMISC_NOOP;
if (state != DL_UNBOUND)
return (DL_OUTSTATE);
#ifdef GLD_DEBUG
}
#endif
for (i = 0; i < gld->gld_multicnt; i++) {
}
}
gld->gld_multicnt = 0;
}
/* decide if we need to turn off any promiscuity */
--mac_pvt->nprom_multi == 0);
if (phys_off) {
} else if (mult_off) {
GLD_MAC_PROMISC_NOOP; /* phys overrides multi */
}
if (op != GLD_MAC_PROMISC_NOOP)
vlan->gldv_nprom--;
vlan->gldv_nprom--;
vlan->gldv_nprom--;
vlan->gldv_nvlan_sap--;
}
if (phys_off)
/*
* We need to hold both locks when modifying the mac stream list
* to protect findminor as well as everyone else.
*/
/* disassociate this stream with its vlan and underlying mac */
if (--vlan->gldv_nstreams == 0) {
}
/* cleanup mac layer if last vlan */
}
/* make sure no references to this gld for gld_v0_sched */
/* put the stream on the unattached Style 2 list */
/* There will be no mp if we were called from close */
if (mp) {
}
(void) qassociate(q, -1);
return (GLDE_OK);
}
/*
* gld_enable_multi (q, mp)
* Enables multicast address on the stream. If the mac layer
* isn't enabled for this address, enable at that level as well.
*/
static int
{
unsigned char *maddr;
int i, rc;
#ifdef GLD_DEBUG
(void *)mp);
}
#endif
return (DL_OUTSTATE);
return (DL_UNSUPPORTED);
}
return (DL_BADADDR);
/* request appears to be valid */
/*
* The multicast addresses live in a per-device table, along
* with a reference count. Each stream has a table that
* points to entries in the device table, with the reference
* count reflecting the number of streams pointing at it. If
* this multicast address is already in the per-device table,
* all we have to do is point at it.
*/
/* does this address appear in current table? */
/* no mcast addresses -- allocate table */
return (GLDE_OK);
}
} else {
for (i = 0; i < gld->gld_multicnt; i++) {
/* this is a match -- just succeed */
return (GLDE_OK);
}
}
}
/*
* it wasn't in the stream so check to see if the mac layer has it
*/
return (GLDE_OK);
}
} else {
for (i = 0; i < glddev->gld_multisize; i++) {
break;
}
}
}
/* not in mac layer -- find an empty mac slot to fill in */
for (i = 0; i < glddev->gld_multisize; i++) {
break;
}
}
}
/* couldn't get a mac layer slot */
return (DL_TOOMANY);
}
/* now we have a mac layer slot in mcast -- get a stream slot */
for (i = 0; i < gld->gld_multicnt; i++) {
continue;
/* found an empty slot */
if (!mcast->gldm_refcnt) {
/* set mcast in hardware */
unsigned char cmaddr[GLD_MAX_ADDRLEN];
if (rc == GLD_NOTSUPPORTED) {
return (DL_NOTSUPPORTED);
} else if (rc == GLD_NORESOURCES) {
return (DL_TOOMANY);
} else if (rc == GLD_BADARG) {
return (DL_BADADDR);
/*
* The putbq and gld_xwait must be
* within the lock to prevent races
* with gld_sched.
*/
return (GLDE_RETRY);
} else if (rc != GLD_SUCCESS) {
return (GLDE_OK);
}
}
mcast->gldm_refcnt++;
return (GLDE_OK);
}
/* couldn't get a stream slot */
return (DL_TOOMANY);
}
/*
* gld_disable_multi (q, mp)
* Disable the multicast address on the stream. If last
* reference for the mac layer, disable there as well.
*/
static int
{
unsigned char *maddr;
int i;
#ifdef GLD_DEBUG
(void *)mp);
}
#endif
return (DL_OUTSTATE);
return (DL_UNSUPPORTED);
}
return (DL_BADADDR);
/* request appears to be valid */
/* does this address appear in current table? */
for (i = 0; i < gld->gld_multicnt; i++)
return (GLDE_OK);
}
}
return (DL_NOTENAB); /* not an enabled address */
}
/*
* gld_send_disable_multi(macinfo, mcast)
* this function is used to disable a multicast address if the reference
* count goes to zero. The disable request will then be forwarded to the
* lower stream.
*/
static void
{
if (!mcast->gldm_refcnt) {
return; /* "cannot happen" */
}
if (--mcast->gldm_refcnt > 0) {
return;
}
/*
* This must be converted from canonical form to device form.
* The refcnt is now zero so we can trash the data.
*/
/* XXX Ought to check for GLD_NORESOURCES or GLD_FAILURE */
(void) (*macinfo->gldm_set_multicast)
}
/*
* gld_promisc (q, mp, req, on)
* enable or disable the use of promiscuous mode with the hardware
*/
static int
{
union DL_primitives *prim;
int macrc = GLD_SUCCESS;
int op = GLD_MAC_PROMISC_NOOP;
#ifdef GLD_DEBUG
#endif
/* XXX I think spec allows promisc in unattached state */
return (DL_OUTSTATE);
/*
* Work out what request (if any) has to be made to the MAC layer
*/
if (on) {
default:
break;
case DL_PROMISC_PHYS:
break;
case DL_PROMISC_MULTI:
if (mac_pvt->nprom_multi == 0)
break;
case DL_PROMISC_SAP:
/* We can do this without reference to the MAC */
break;
}
} else {
default:
break;
case DL_PROMISC_PHYS:
dlerr = DL_NOTENAB;
if (mac_pvt->nprom_multi)
else
break;
case DL_PROMISC_MULTI:
dlerr = DL_NOTENAB;
break;
case DL_PROMISC_SAP:
dlerr = DL_NOTENAB;
/* We can do this without reference to the MAC */
break;
}
}
/*
* The request was invalid in some way so no need to continue.
*/
return (dlerr);
}
/*
* Issue the request to the MAC layer, if required
*/
if (op != GLD_MAC_PROMISC_NOOP) {
}
/*
* On success, update the appropriate flags & refcounts
*/
if (macrc == GLD_SUCCESS) {
if (on) {
case DL_PROMISC_PHYS:
vlan->gldv_nprom++;
break;
case DL_PROMISC_MULTI:
mac_pvt->nprom_multi++;
vlan->gldv_nprom++;
break;
case DL_PROMISC_SAP:
vlan->gldv_nprom++;
vlan->gldv_nvlan_sap++;
break;
default:
break;
}
} else {
case DL_PROMISC_PHYS:
vlan->gldv_nprom--;
break;
case DL_PROMISC_MULTI:
mac_pvt->nprom_multi--;
vlan->gldv_nprom--;
break;
case DL_PROMISC_SAP:
vlan->gldv_nvlan_sap--;
vlan->gldv_nprom--;
break;
default:
break;
}
}
/*
* The putbq and gld_xwait must be within the lock to
* prevent races with gld_sched.
*/
}
/*
* Finally, decide how to reply.
*
* If <macrc> is not GLD_SUCCESS, the request was put to the MAC
* layer but failed. In such cases, we can return a DL_* error
* code and let the caller send an error-ack reply upstream, or
* we can send a reply here and then return GLDE_OK so that the
* caller doesn't also respond.
*
* If physical-promiscuous mode was (successfully) switched on or
* off, send a notification (DL_NOTIFY_IND) to anyone interested.
*/
switch (macrc) {
case GLD_NOTSUPPORTED:
return (DL_NOTSUPPORTED);
case GLD_NORESOURCES:
return (GLDE_OK);
case GLD_RETRY:
return (GLDE_RETRY);
default:
return (GLDE_OK);
case GLD_SUCCESS:
break;
}
switch (op) {
case GLD_MAC_PROMISC_NOOP:
break;
case GLD_MAC_PROMISC_PHYS:
break;
default:
break;
}
return (GLDE_OK);
}
/*
* gld_physaddr()
* get the current or factory physical address value
*/
static int
{
unsigned char addr[GLD_MAX_ADDRLEN];
return (DL_OUTSTATE);
case DL_FACT_PHYS_ADDR:
break;
case DL_CURR_PHYS_ADDR:
/* make a copy so we don't hold the lock across qreply */
break;
default:
return (DL_BADPRIM);
}
return (GLDE_OK);
}
/*
* gld_setaddr()
* change the hardware's physical address to a user specified value
*/
static int
{
unsigned char *addr;
unsigned char cmaddr[GLD_MAX_ADDRLEN];
int rc;
return (DL_OUTSTATE);
return (DL_NOTSUPPORTED);
return (DL_BADADDR);
/* now do the set at the hardware level */
if (rc == GLD_SUCCESS)
switch (rc) {
case GLD_SUCCESS:
break;
case GLD_NOTSUPPORTED:
return (DL_NOTSUPPORTED);
case GLD_BADARG:
return (DL_BADADDR);
case GLD_NORESOURCES:
return (GLDE_OK);
default:
return (GLDE_OK);
}
return (GLDE_OK);
}
int
{
return (DL_OUTSTATE);
return (GLDE_OK); /* mexchange already sent merror */
sizeof (struct gldkstats));
return (GLDE_OK);
}
/* =================================================== */
/* misc utilities, some requiring various mutexes held */
/* =================================================== */
/*
* Initialize and start the driver.
*/
static int
{
int rc;
unsigned char cmaddr[GLD_MAX_ADDRLEN];
if (rc != GLD_SUCCESS)
return (GLD_FAILURE);
/* set the addr after we reset the device */
return (GLD_FAILURE);
if (rc != GLD_SUCCESS)
return (GLD_FAILURE);
return (GLD_SUCCESS);
}
/*
* Stop the driver.
*/
static void
{
}
/*
* gld_set_ipq will set a pointer to the queue which is bound to the
* IP sap if:
* o the device type is ethernet or IPoIB.
* o there is no stream in SAP promiscuous mode.
* o there is exactly one stream bound to the IP sap.
* o the stream is in "fastpath" mode.
*/
static void
{
uint_t ipq_candidates = 0;
uint_t ipv6q_candidates = 0;
return;
/* clear down any previously defined ipqs */
/* Try to find a single stream eligible to receive IP packets */
continue; /* not eligible to receive */
continue; /* not eligible to receive */
}
}
}
if (ipq_candidates == 1) {
}
if (ipv6q_candidates == 1) {
}
}
/*
* gld_flushqueue (q)
* used by DLPI primitives that require flushing the queues.
* essentially, this is DL_UNBIND_REQ.
*/
static void
{
/* flush all data in both queues */
/* XXX Should these be FLUSHALL? */
/* flush all the queues upstream */
}
/*
* gld_devlookup (major)
* search the device table for the device with specified
* major number and return a pointer to it if it exists
*/
static glddev_t *
gld_devlookup(int major)
{
dev != &gld_device_list;
return (dev);
}
return (NULL);
}
/*
* gld_findminor(device)
* Returns a minor number currently unused by any stream in the current
* device class (major) list.
*/
static int
{
int minor;
int i;
/* The fast way */
return (device->gld_nextminor++);
/* The steady way */
minor++) {
/* Search all unattached streams */
goto nextminor;
}
/* Search all attached streams; we don't need maclock because */
/* mac stream list is protected by devlock as well as maclock */
gld_mac_pvt_t *pvt =
continue; /* this one's not ready yet */
for (i = 0; i < VLAN_HASHSZ; i++) {
next !=
goto nextminor;
}
}
}
}
return (minor);
/* don't need to do anything */
;
}
return (0);
}
/*
*/
struct qelem {
/* rest of structure */
};
static void
{
}
static void
{
}
static gld_vlan_t *
{
gld_vlan_t **pp;
gld_vlan_t *p;
}
return (NULL);
if (vid == VLAN_VID_NONE) {
p->gldv_ptag = VLAN_VTAG_NONE;
p->gldv_kstatp = NULL;
} else {
KM_SLEEP);
if (gld_init_vlan_stats(p) != GLD_SUCCESS) {
kmem_free(p, sizeof (gld_vlan_t));
return (NULL);
}
}
*pp = p;
return (p);
}
static void
{
gld_vlan_t **pp;
gld_vlan_t *p;
break;
}
if (p->gldv_id != VLAN_VID_NONE) {
kstat_delete(p->gldv_kstatp);
}
kmem_free(p, sizeof (gld_vlan_t));
}
{
gld_vlan_t *p;
while (p != NULL) {
return (p);
p = p->gldv_next;
}
return (NULL);
}
{
return (vlan);
}
/*
* gld_bitrevcopy()
* This is essentially bcopy, with the ability to bit reverse the
* the source bytes. The MAC addresses bytes as transmitted by FDDI
* interfaces are bit reversed.
*/
void
{
while (n--)
}
/*
* gld_bitreverse()
* Convert the bit order by swaping all the bits, using a
* lookup table.
*/
void
{
while (n--) {
rptr++;
}
}
char *
{
int i;
static char digits[] = "0123456789abcdef";
for (i = 0; i < len; i++) {
*cp++ = ':';
}
*--cp = 0;
return (etherbuf);
}
#ifdef GLD_DEBUG
static void
{
int i;
}
int nvlan = 0;
continue; /* this one's not ready yet */
for (i = 0; i < VLAN_HASHSZ; i++) {
int nstr = 0;
str !=
mac);
str->gld_multicnt == 0 ||
nstr++;
}
nvlan++;
}
}
}
}
}
#endif