bge_recv2.c revision 67f02347ff26da3909c580115d4ba535ab72078c
/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "sys/bge_impl2.h"
/*
* ========== RX side routines ==========
*/
#pragma inline(bge_refill)
/*
* Return the specified buffer (srbdp) to the ring it came from (brp).
*
* Note:
* If the driver is compiled with only one buffer ring *and* one
* return ring, then the buffers must be returned in sequence.
* In this case, we don't have to consider anything about the
* buffer at all; we can simply advance the cyclic counter. And
* we don't even need the refill mutex <rf_lock>, as the caller
* will already be holding the (one-and-only) <rx_lock>.
*
* If the driver supports multiple buffer rings, but only one
* return ring, the same still applies (to each buffer ring
* separately).
*/
static void
{
}
#pragma inline(bge_receive_packet)
static mblk_t *
{
default:
/* error, this shouldn't happen */
goto error;
case RBD_FLAG_JUMBO_RING:
break;
#if (BGE_BUFF_RINGS_USED > 2)
case RBD_FLAG_MINI_RING:
break;
#endif /* BGE_BUFF_RINGS_USED > 2 */
case 0:
break;
}
/* error, this shouldn't happen */
goto error;
}
/* bogus, drop the packet */
goto refill;
}
/* bogus, drop the packet */
goto refill;
}
/* bogus, drop the packet */
goto refill;
}
#ifdef BGE_IPMI_ASF
/*
*/
else
#endif
/*
* H/W will not strip the VLAN tag from incoming packet
* now, as RECEIVE_MODE_KEEP_VLAN_TAG bit is set in
* RECEIVE_MAC_MODE_REG register.
*/
/* bogus, drop the packet */
goto refill;
}
#ifdef BGE_IPMI_ASF
else
#endif
/* bogus, drop the packet */
goto refill;
}
/*
* Packet looks good; get a buffer to copy it into.
* We want to leave some space at the front of the allocated
* buffer in case any upstream modules want to prepend some
* sort of header. This also has the side-effect of making
* the packet *contents* 4-byte aligned, as required by NCA!
*/
#ifdef BGE_IPMI_ASF
} else {
#endif
#ifdef BGE_IPMI_ASF
}
#endif
/* Nothing to do but drop the packet */
goto refill;
}
/*
* Sync the data and copy it to the STREAMS buffer.
*/
#ifdef BGE_IPMI_ASF
/*
* As VLAN tag has been stripped from incoming packet in ASF
* scenario, we insert it into this packet again.
*/
struct ether_vlan_header *ehp;
} else {
#endif
#ifdef BGE_IPMI_ASF
}
} else
#endif
/*
* Special check for one specific type of data corruption;
* in a good packet, the first 8 bytes are *very* unlikely
* to be the same as the second 8 bytes ... but we let the
* packet through just in case.
*/
pflags = 0;
pflags |= HCK_FULLCKSUM;
if (pflags != 0)
/*
* Replace the buffer in the ring it came from ...
*/
return (mp);
/*
* We come here if the integrity of the ring descriptors
* (rather than merely packet data) appears corrupted.
* The factotum will attempt to reset-and-recover.
*/
return (NULL);
}
/*
* Accept the packets received in the specified ring up to
* (but not including) the producer index in the status block.
*
* Returns a chain of mblks containing the received data, to be
* passed up to gld_recv() (we can't call gld_recv() from here,
* 'cos we're holding the per-ring receive lock at this point).
*
* This function must advance (rrp->rx_next) and write it back to
* the chip to indicate the packets it has accepted from the ring.
*/
#pragma inline(bge_receive_ring)
static mblk_t *
{
/*
* Sync (all) the receive ring descriptors
* before accepting the packets they describe
*/
}
}
return (head);
}
/*
* Receive all packets in all rings.
*
* To give priority to low-numbered rings, whenever we have received any
* packets in any ring except 0, we restart scanning again from ring 0.
* Thus, for example, if rings 0, 3, and 10 are carrying traffic, the
* pattern of receives might go 0, 3, 10, 3, 0, 10, 0:
*
* 0 found some - receive them
* 1..2 none found
* 3 found some - receive them and restart scan
* 0..9 none found
* 10 found some - receive them and restart scan
* 0..2 none found
* 3 found some more - receive them and restart scan
* 0 found some more - receive them
* 1..9 none found
* 10 found some more - receive them and restart scan
* 0 found some more - receive them
* 1..15 none found
*
* The routine returns only when a complete scan has been performed
* without finding any packets to receive.
*
* Note that driver-defined locks may *NOT* be held across calls
* to gld_recv().
*
* Note: the expression (BGE_RECV_RINGS_USED > 1), yields a compile-time
* constant and allows the compiler to optimise away the outer do-loop
* if only one receive ring is being used.
*/
#pragma no_inline(bge_receive)
void
{
ring = 0;
do {
/*
* For each ring, (rrp->prod_index_p) points to the
* proper index within the status block (which has
* already been sync'd by the caller)
*/
continue; /* no packets */
continue; /* already in process */
/*
* Restart from ring 0, if the driver is compiled
* with multiple rings and we're not on ring 0 now
*/
goto restart;
}
/*
* Loop over all rings (if there *are* multiple rings)
*/
}