bge_send.c revision 6238702328a326e0be83e4bdb62f3311b2e062a8
/*
* 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"
/*
* The transmit-side code uses an allocation process which is similar
* to some theme park roller-coaster rides, where riders sit in cars
* that can go individually, but work better in a train.
*
* 1) RESERVE a place - this doesn't refer to any specific car or
* seat, just that you will get a ride. The attempt to RESERVE a
* place can fail if all spaces in all cars are already committed.
*
* 2) Prepare yourself; this may take an arbitrary (but not unbounded)
* time, and you can back out at this stage, in which case you must
* give up (RENOUNCE) your place.
*
* 3) CLAIM your space - a specific car (the next sequentially
* numbered one) is allocated at this stage, and is guaranteed
* to be part of the next train to depart. Once you've done
* this, you can't back out, nor wait for any external event
* or resource.
*
* 4) Occupy your car - when all CLAIMED cars are OCCUPIED, they
* all depart together as a single train!
*
* 5) At the end of the ride, you climb out of the car and RENOUNCE
* your right to it, so that it can be recycled for another rider.
*
* For each rider, these have to occur in this order, but the riders
* don't have to stay in the same order at each stage. In particular,
* they may overtake each other between RESERVING a place and CLAIMING
* it, or between CLAIMING and OCCUPYING a space.
*
* Once a car is CLAIMED, the train currently being assembled can't go
* without that car (this guarantees that the cars in a single train
* make up a consecutively-numbered set). Therefore, when any train
* leaves, we know there can't be any riders in transit between CLAIMING
* and OCCUPYING their cars. There can be some who have RESERVED but
* not yet CLAIMED their places. That's OK, though, because they'll go
* into the next train.
*/
/*
* ========== Send-side recycle routines ==========
*/
/*
* Recycle all the completed buffers in the specified send ring up to
* (but not including) the consumer index in the status block.
*
* This function must advance (srp->tc_next) AND adjust (srp->tx_free)
* to account for the packets it has recycled.
*
* This is a trivial version that just does that and nothing more, but
* it suffices while there's only one method for sending messages (by
* copying) and that method doesn't need any special per-buffer action
* for recycling.
*/
#pragma inline(bge_recycle_ring)
static void
{
uint64_t n;
/*
* We're about to release one or more places :-)
* These ASSERTions check that our invariants still hold:
* there must always be at least one free place
* at this point, there must be at least one place NOT free
* we're not about to free more places than were claimed!
*/
/*
* Reset the watchdog count: to 0 if all buffers are
* now free, or to 1 if some are still outstanding.
* Note: non-synchonised access here means we may get
* the "wrong" answer, but only in a harmless fashion
* (i.e. we deactivate the watchdog because all buffers
* are apparently free, even though another thread may
* have claimed one before we leave here; in this case
* the watchdog will restart on the next send() call).
*/
}
/*
* Recycle all returned slots in all rings.
*
* To give priority to low-numbered rings, whenever we have recycled any
* slots 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 recycles might go 0, 3, 10, 3, 0, 10, 0:
*
* 0 found some - recycle them
* 1..2 none found
* 3 found some - recycle them and restart scan
* 0..9 none found
* 10 found some - recycle them and restart scan
* 0..2 none found
* 3 found some more - recycle them and restart scan
* 0 found some more - recycle them
* 0..9 none found
* 10 found some more - recycle them and restart scan
* 0 found some more - recycle them
* 1..15 none found
*
* The routine returns only when a complete scan has been performed
* without finding any slots to recycle.
*
* Note: the expression (BGE_SEND_RINGS_USED > 1) yields a compile-time
* constant and allows the compiler to optimise away the outer do-loop
* if only one send ring is being used.
*/
#pragma no_inline(bge_recycle)
void
{
ring = 0;
do {
/*
* For each ring, (srp->cons_index_p) points to the
* proper index within the status block (which has
* already been sync'd by the caller).
*/
continue; /* no slots to recycle */
continue; /* already in process */
if (bgep->resched_needed)
/*
* Restart from ring 0, if we're not on ring 0 already.
* As H/W selects send BDs totally based on priority and
* available BDs on the higher priority ring are always
* selected first, driver should keep consistence with H/W
* and gives lower-numbered ring with higher priority.
*/
goto restart;
/*
* Loop over all rings (if there *are* multiple rings)
*/
}
/*
* ========== Send-side transmit routines ==========
*/
/*
* CLAIM an already-reserved place on the next train
*
* This is the point of no return!
*/
#pragma inline(bge_send_claim)
static uint64_t
{
/*
* Bump the watchdog counter, thus guaranteeing that it's
* nonzero (watchdog activated). Note that non-synchonised
* access here means we may race with the reclaim() code
* above, but the outcome will be harmless. At worst, the
* counter may not get reset on a partial reclaim; but the
* large trigger threshold makes false positives unlikely
*/
return (slot);
}
/*
* Send a message by copying it into a preallocated (and premapped) buffer
*/
#pragma inline(bge_send_copy)
static enum send_status
{
char *txb;
BGE_TRACE(("bge_send_copy($%p, $%p, $%p, 0x%x)",
/*
* IMPORTANT:
* Up to the point where it claims a place, a send_msg()
* routine can indicate failure by returning SEND_FAIL.
* Once it's claimed a place, it mustn't fail.
*
* In this version, there's no setup to be done here, and there's
* nothing that can fail, so we can go straight to claiming our
* already-reserved place on the train.
*
* This is the point of no return!
*/
/*
* Copy the data into a pre-mapped buffer, which avoids the
* buffers and keeping hold of them until the DMA has completed.
*
* Because all buffers are the same size, and larger than the
* longest single valid message, we don't have to bother about
* splitting the message across multiple buffers either.
*/
}
}
/*
* We'e reached the end of the chain; and we should have
* collected no more than ETHERMAX bytes into our buffer.
*/
/*
* Update the hardware send buffer descriptor; then we're done.
* The return status indicates that the message can be freed
* right away, as we've already copied the contents ...
*/
if (tci != 0) {
}
if (pflags & HCK_IPV4_HDRCKSUM)
if (pflags & HCK_FULLCKSUM)
return (SEND_FREE);
}
static boolean_t
{
enum send_status status;
struct ether_vlan_header *ehp;
/*
* Determine if the packet is VLAN tagged.
*/
/*
* Need to preserve checksum flags across pullup.
*/
sizeof (struct ether_vlan_header))) {
BGE_DEBUG(("bge_send: pullup failure"));
return (B_FALSE);
}
}
need_strip = B_TRUE;
}
/*
* Try to reserve a place in the chosen ring. Shouldn't try next
* higher-numbered (lower-priority) ring, if there aren't any
* available. Otherwise, packets with same priority may get
* transmission starvation.
*/
BGE_DEBUG(("bge_send: no free slots"));
return (B_FALSE);
}
/*
* Now that we know that there is space to transmit the packet
* strip any VLAN tag that is present.
*/
if (need_strip) {
2 * ETHERADDRL);
} else {
tci = 0;
}
/*
* We've reserved a place :-)
* These ASSERTions check that our invariants still hold:
* there must still be at least one free place
* there must be at least one place NOT free (ours!)
*/
/*
* The send routine failed :( So we have to renounce
* our reservation before returning the error.
*/
return (B_FALSE);
}
/*
* The send routine succeeded; it will have updated the
* h/w ring descriptor, and the <tx_next> and <tx_flow>
* counters.
*
* Because there can be multiple concurrent threads in
* transit through this code, we only want to prod the
* hardware once the last one is departing ...
*/
}
return (B_TRUE);
}
{
}
return (DDI_INTR_CLAIMED);
}
/*
* bge_m_tx() - send a chain of packets
*/
mblk_t *
{
BGE_DEBUG(("bge_m_tx: chip not running"));
return (mp);
}
break;
}
}
return (mp);
}