dld_proto.c revision c08e5e1a6b0518eb8f644673c26e1d3f22a773b0
/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Data-Link Driver
*/
#include <sys/sysmacros.h>
#include <sys/dld_impl.h>
#include <sys/dls_soft_ring.h>
static void proto_poll_disable(dld_str_t *);
static void proto_soft_ring_disable(dld_str_t *);
static void proto_change_soft_ring_fanout(dld_str_t *, int);
#define DL_ACK_PENDING(state) \
((state) == DL_ATTACH_PENDING || \
(state) == DL_DETACH_PENDING || \
(state) == DL_BIND_PENDING || \
(state) == DL_UNBIND_PENDING)
/*
* Process a DLPI protocol message.
* The primitives DL_BIND_REQ, DL_ENABMULTI_REQ, DL_PROMISCON_REQ,
* DL_SET_PHYS_ADDR_REQ put the data link below our dld_str_t into an
* 'active' state. The primitive DL_PASSIVE_REQ marks our dld_str_t
* as 'passive' and forbids it from being subsequently made 'active'
* by the above primitives.
*/
void
{
union DL_primitives *udlp;
switch (prim) {
case DL_INFO_REQ:
break;
case DL_BIND_REQ:
break;
case DL_UNBIND_REQ:
break;
case DL_UDQOS_REQ:
break;
case DL_ATTACH_REQ:
break;
case DL_DETACH_REQ:
break;
case DL_ENABMULTI_REQ:
break;
case DL_DISABMULTI_REQ:
break;
case DL_PROMISCON_REQ:
break;
case DL_PROMISCOFF_REQ:
break;
case DL_PHYS_ADDR_REQ:
break;
case DL_SET_PHYS_ADDR_REQ:
break;
case DL_NOTIFY_REQ:
break;
case DL_CAPABILITY_REQ:
break;
case DL_PASSIVE_REQ:
break;
default:
break;
}
}
#define NEG(x) -(x)
typedef struct dl_info_ack_wrapper {
/*
* DL_INFO_REQ
*/
/*ARGSUSED*/
static boolean_t
{
/*
* Swap the request message for one large enough to contain the
* wrapper structure defined above.
*/
return (B_FALSE);
/*
* Set up the sub-structure pointers.
*/
/*
* This driver supports only version 2 connectionless DLPI provider
* nodes.
*/
/*
* Set the style of the provider
*/
/*
* Set the current DLPI state.
*/
/*
* Gratuitously set the media type. This is to deal with modules
* that assume the media type is known prior to DL_ATTACH_REQ
* being completed.
*/
/*
* If the stream is not at least attached we try to retrieve the
* mac_info using mac_info_get()
*/
/*
* Cannot find mac_info. giving up.
*/
goto done;
}
} else {
/* We can only get the sdu if we're attached. */
}
/*
* Set the media type (properly this time).
*/
else
/*
* Set the DLSAP length. We only support 16 bit values and they
* appear after the MAC address portion of DLSAP addresses.
*/
sap_length = sizeof (uint16_t);
/*
* Copy in the media broadcast address.
*/
}
/*
* Specify the supported range of priorities.
*/
/*
* Specify the current priority (which can be changed by
* the DL_UDQOS_REQ primitive).
*/
/*
* The stream is bound. Therefore we can formulate a valid
* DLSAP address.
*/
if (addr_length > 0)
}
done:
dlp->dl_qos_range_length != 0));
dlp->dl_brdcst_addr_length != 0));
return (B_TRUE);
}
/*
* DL_ATTACH_REQ
*/
static boolean_t
{
int err = 0;
dl_err = DL_BADPRIM;
goto failed;
}
goto failed;
}
if (err != 0) {
switch (err) {
case ENOENT:
err = 0;
break;
default:
break;
}
goto failed;
}
return (B_TRUE);
return (B_FALSE);
}
/*ARGSUSED*/
static boolean_t
{
dl_err = DL_BADPRIM;
goto failed;
}
goto failed;
}
dl_err = DL_BADPRIM;
goto failed;
}
return (B_TRUE);
return (B_FALSE);
}
/*
* DL_BIND_REQ
*/
static boolean_t
{
int err = 0;
/*
* Because control message processing is serialized, we don't need
* to hold any locks to read any fields of dsp; we only need ds_lock
* to update the ds_dlstate, ds_sap and ds_passivestate fields.
*/
dl_err = DL_BADPRIM;
goto failed;
}
if (dlp->dl_xidtest_flg != 0) {
goto failed;
}
goto failed;
}
goto failed;
}
goto failed;
}
/*
* Set the receive callback.
*/
/*
* Bind the channel such that it can receive packets.
*/
if (err != 0) {
switch (err) {
case EINVAL:
dl_err = DL_BADADDR;
err = 0;
break;
default:
break;
}
goto failed;
}
/*
* Copy in MAC address.
*/
/*
* Copy in the SAP.
*/
dlsap_addr_length += sizeof (uint16_t);
return (B_TRUE);
return (B_FALSE);
}
/*
* DL_UNBIND_REQ
*/
/*ARGSUSED*/
static boolean_t
{
dl_err = DL_BADPRIM;
goto failed;
}
goto failed;
}
/*
* Flush any remaining packets scheduled for transmission.
*/
/*
* Unbind the channel to stop packets being received.
*/
/*
* Clear the receive callback.
*/
/*
* Disable polling mode, if it is enabled.
*/
/*
* If soft rings were enabled, the workers should be quiesced.
*/
/*
* Clear LSO flags.
*/
dsp->ds_lso_max = 0;
/*
* Set the mode back to the default (unitdata).
*/
return (B_TRUE);
return (B_FALSE);
}
/*
* DL_PROMISCON_REQ
*/
static boolean_t
{
int err = 0;
/*
* Because control message processing is serialized, we don't need
* to hold any locks to read any fields of dsp; we only need ds_lock
* to update the ds_promisc and ds_passivestate fields.
*/
dl_err = DL_BADPRIM;
goto failed;
}
goto failed;
}
case DL_PROMISC_SAP:
break;
case DL_PROMISC_MULTI:
break;
case DL_PROMISC_PHYS:
break;
default:
goto failed;
}
goto failed;
}
/*
* Adjust channel promiscuity.
*/
if (err != 0) {
goto failed;
}
return (B_TRUE);
return (B_FALSE);
}
/*
* DL_PROMISCOFF_REQ
*/
static boolean_t
{
int err = 0;
/*
* Because control messages processing is serialized, we don't need
* to hold any lock to read any field of dsp; we hold ds_lock to
* update the ds_promisc field.
*/
dl_err = DL_BADPRIM;
goto failed;
}
goto failed;
}
case DL_PROMISC_SAP:
break;
case DL_PROMISC_MULTI:
break;
case DL_PROMISC_PHYS:
break;
default:
goto failed;
}
dl_err = DL_NOTENAB;
goto failed;
}
if (err != 0) {
goto failed;
}
return (B_TRUE);
return (B_FALSE);
}
/*
* DL_ENABMULTI_REQ
*/
static boolean_t
{
int err = 0;
/*
* Because control messages processing is serialized, we don't need
* to hold any lock to read any field of dsp; we hold ds_lock to
* update the ds_passivestate field.
*/
goto failed;
}
dl_err = DL_BADPRIM;
goto failed;
}
goto failed;
}
if (err != 0) {
switch (err) {
case EINVAL:
dl_err = DL_BADADDR;
err = 0;
break;
case ENOSPC:
dl_err = DL_TOOMANY;
err = 0;
break;
default:
break;
}
goto failed;
}
return (B_TRUE);
return (B_FALSE);
}
/*
* DL_DISABMULTI_REQ
*/
static boolean_t
{
int err = 0;
/*
* Because control messages processing is serialized, we don't need
* to hold any lock to read any field of dsp.
*/
goto failed;
}
dl_err = DL_BADPRIM;
goto failed;
}
if (err != 0) {
switch (err) {
case EINVAL:
dl_err = DL_BADADDR;
err = 0;
break;
case ENOENT:
dl_err = DL_NOTENAB;
err = 0;
break;
default:
break;
}
goto failed;
}
return (B_TRUE);
return (B_FALSE);
}
/*
* DL_PHYS_ADDR_REQ
*/
static boolean_t
{
char *addr;
dl_err = DL_BADPRIM;
goto failed;
}
goto failed;
}
goto failed;
}
if (addr_length > 0) {
return (B_FALSE);
}
/*
* Copy out the address before we drop the lock; we don't
* want to call dlphysaddrack() while holding ds_lock.
*/
} else {
}
return (B_TRUE);
return (B_FALSE);
}
/*
* DL_SET_PHYS_ADDR_REQ
*/
static boolean_t
{
int err = 0;
/*
* Because control message processing is serialized, we don't need
* to hold any locks to read any fields of dsp; we only need ds_lock
* to update the ds_passivestate field.
*/
goto failed;
}
dl_err = DL_BADPRIM;
goto failed;
}
goto failed;
}
if (err != 0) {
switch (err) {
case EINVAL:
dl_err = DL_BADADDR;
err = 0;
break;
default:
break;
}
goto failed;
}
return (B_TRUE);
return (B_FALSE);
}
/*
* DL_UDQOS_REQ
*/
static boolean_t
{
dl_err = DL_BADPRIM;
goto failed;
}
goto failed;
}
selp->dl_priority < 0) {
goto failed;
}
goto failed;
}
return (B_TRUE);
return (B_FALSE);
}
static boolean_t
{
claimstr(q);
releasestr(q);
return (ret);
}
/*
* DL_CAPABILITY_REQ
*/
/*ARGSUSED*/
static boolean_t
{
dl_err = DL_BADPRIM;
goto failed;
}
goto failed;
}
/*
* This request is overloaded. If there are no requested capabilities
* then we just want to acknowledge with all the capabilities we
* support. Otherwise we enable the set of capabilities requested.
*/
if (dlp->dl_sub_length == 0) {
/* callee drops lock */
}
dl_err = DL_BADPRIM;
goto failed;
}
/*
* Walk the list of capabilities to be enabled.
*/
dl_err = DL_BADPRIM;
goto failed;
}
/*
*/
case DL_CAPAB_HCKSUM: {
/*
* Copy for alignment.
*/
break;
}
/*
* Large segment offload. (LSO)
*/
case DL_CAPAB_LSO: {
/*
* Copy for alignment.
*/
break;
}
/*
* IP polling interface.
*/
case DL_CAPAB_POLL: {
/*
* Copy for alignment.
*/
default:
/*FALLTHRU*/
case POLL_DISABLE:
break;
case POLL_ENABLE:
/*
* Make sure polling is disabled.
*/
/*
* Note that only IP should enable POLL.
*/
} else {
}
break;
}
break;
}
case DL_CAPAB_SOFT_RING: {
/*
* Copy for alignment.
*/
sizeof (dl_capab_dls_t));
default:
/*FALLTHRU*/
case SOFT_RING_DISABLE:
break;
case SOFT_RING_ENABLE:
/*
* Make sure soft_ring is disabled.
*/
/*
* Note that only IP can enable soft ring.
*/
sizeof (dl_capab_dls_t));
} else {
sizeof (dl_capab_dls_t));
}
break;
}
sizeof (dl_capab_dls_t));
break;
}
default:
break;
}
}
return (B_TRUE);
return (B_FALSE);
}
/*
* DL_NOTIFY_REQ
*/
static boolean_t
{
dl_err = DL_BADPRIM;
goto failed;
}
goto failed;
}
/*
* Cache the notifications that are being enabled.
*/
/*
* The ACK carries all notifications regardless of which set is
* being enabled.
*/
/*
* Solicit DL_NOTIFY_IND messages for each enabled notification.
*/
if (dsp->ds_notifications != 0) {
} else {
}
return (B_TRUE);
return (B_FALSE);
}
/*
* DL_UNITDATA_REQ
*/
void
{
dl_err = DL_BADPRIM;
goto failed;
}
dl_err = DL_BADPRIM;
goto failed;
}
dl_err = DL_BADADDR;
goto failed;
}
/*
* Check the length of the packet and the block types.
*/
size = 0;
goto baddata;
}
goto baddata;
/*
* Build a packet header.
*/
dl_err = DL_BADADDR;
goto failed;
}
/*
* We no longer need the M_PROTO header, so free it.
*/
/*
* Transfer the checksum offload information if it is present.
*/
&flags);
/*
* Link the payload onto the new header.
*/
return;
return;
}
/*
* DL_PASSIVE_REQ
*/
/* ARGSUSED */
static boolean_t
{
/*
* READER lock is enough because ds_passivestate can only be changed
* as the result of non-data message processing.
*/
/*
* If we've already become active by issuing an active primitive,
* then it's too late to try to become passive.
*/
goto failed;
}
dl_err = DL_BADPRIM;
goto failed;
}
return (B_TRUE);
return (B_FALSE);
}
/*
* Catch-all handler.
*/
static boolean_t
{
return (B_FALSE);
}
static void
{
if (!dsp->ds_polling)
return;
/*
* It should be impossible to enable raw mode if polling is turned on.
*/
/*
* Reset the resource_add callback.
*/
/*
* Set receive function back to default.
*/
/*
* Note that polling is disabled.
*/
}
static boolean_t
{
/*
* We cannot enable polling if raw mode
* has been enabled.
*/
return (B_FALSE);
/*
* Register resources.
*/
(void *)pollp->dls_rx_handle);
/*
* Set the upstream receive function.
*/
(void *)pollp->dls_rx_handle);
/*
* Note that polling is enabled. This prevents further DLIOCHDRINFO
* ioctls from overwriting the receive function pointer.
*/
return (B_TRUE);
}
static void
{
if (!dsp->ds_soft_ring)
return;
/*
* It should be impossible to enable raw mode if soft_ring is turned on.
*/
/*
* Note that fanout is disabled.
*/
}
static boolean_t
{
/*
* We cannot enable soft_ring if raw mode
* has been enabled.
*/
return (B_FALSE);
return (B_FALSE);
return (B_TRUE);
}
static void
{
if (type == SOFT_RING_NONE) {
} else if (type != SOFT_RING_NONE) {
}
}
/*
*/
static boolean_t
{
/*
* Initially assume no capabilities.
*/
subsize = 0;
/*
* Check if soft ring can be enabled on this interface. Note that we
* do not enable softring on any legacy drivers, because doing that
* would hurt the performance if the legacy driver has its own taskq
* implementation. Further, most high-performance legacy drivers do
* have their own taskq implementation.
*
* If advertising DL_CAPAB_SOFT_RING has not been explicitly disabled,
* reserve space for that capability.
*/
subsize += sizeof (dl_capability_sub_t) +
sizeof (dl_capab_dls_t);
}
/*
* Check if polling can be enabled on this interface.
* If advertising DL_CAPAB_POLL has not been explicitly disabled
* then reserve space for that capability.
*/
subsize += sizeof (dl_capability_sub_t) +
sizeof (dl_capab_dls_t);
}
/*
* Check if checksum offload is supported on this MAC. Don't
* advertise DL_CAPAB_HCKSUM if the underlying MAC is VLAN incapable,
* since it might not be able to do the hardware checksum offload
* with the correct offset.
*/
&hcksum.hcksum_txflags)) {
if (hcksum.hcksum_txflags != 0) {
subsize += sizeof (dl_capability_sub_t) +
sizeof (dl_capab_hcksum_t);
}
}
/*
* Check if LSO is supported on this MAC, then reserve space for
* the DL_CAPAB_LSO capability.
*/
subsize += sizeof (dl_capability_sub_t) +
sizeof (dl_capab_lso_t);
}
/*
* Check if zerocopy is supported on this interface.
* If advertising DL_CAPAB_ZEROCOPY has not been explicitly disabled
* then reserve space for that capability.
*/
!(dld_opt & DLD_OPT_NO_ZEROCOPY)) {
subsize += sizeof (dl_capability_sub_t) +
sizeof (dl_capab_zerocopy_t);
}
/*
* If there are no capabilities to advertise or if we
* can't allocate a response, send a DL_ERROR_ACK.
*/
return (B_FALSE);
}
/*
* IP polling interface.
*/
if (poll_capable) {
/*
* Attempt to disable just in case this is a re-negotiation;
* READER lock is enough because ds_polling can only be
* changed as the result of non-data message processing.
*/
ptr += sizeof (dl_capability_sub_t);
ptr += sizeof (dl_capab_dls_t);
}
if (soft_ring_capable) {
ptr += sizeof (dl_capability_sub_t);
ptr += sizeof (dl_capab_dls_t);
}
/*
*/
if (hcksum_capable) {
ptr += sizeof (dl_capability_sub_t);
ptr += sizeof (dl_capab_hcksum_t);
}
/*
* Large segment offload. (LSO)
*/
if (lso_capable) {
ptr += sizeof (dl_capability_sub_t);
/* Simply enable LSO with DLD */
ptr += sizeof (dl_capab_lso_t);
} else {
dsp->ds_lso_max = 0;
}
/*
* Zero copy
*/
if (zcopy_capable) {
ptr += sizeof (dl_capability_sub_t);
ptr += sizeof (dl_capab_zerocopy_t);
}
return (B_TRUE);
}
/*
* Disable any enabled capabilities.
*/
void
{
if (dsp->ds_polling)
if (dsp->ds_soft_ring)
}