bge_send.c revision 381a2a9a387f449fab7d0c7e97c4184c26963abf
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs/*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * CDDL HEADER START
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs *
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * The contents of this file are subject to the terms of the
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Common Development and Distribution License (the "License").
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * You may not use this file except in compliance with the License.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs *
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * or http://www.opensolaris.org/os/licensing.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * See the License for the specific language governing permissions
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * and limitations under the License.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs *
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * When distributing Covered Code, include this CDDL HEADER in each
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * If applicable, add the following below this CDDL HEADER, with the
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * fields enclosed by brackets "[]" replaced with your own identifying
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * information: Portions Copyright [yyyy] [name of copyright owner]
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs *
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * CDDL HEADER END
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer/*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Use is subject to license terms.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs#pragma ident "%Z%%M% %I% %E% SMI"
6ffca240bba331a8b22ff3ce47de58da6a205843Michael Speer
6ffca240bba331a8b22ff3ce47de58da6a205843Michael Speer#include "bge_impl.h"
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
b83cd2c35abe58abb09c73f2ef35426f1384ad46Michael Speer
b83cd2c35abe58abb09c73f2ef35426f1384ad46Michael Speer/*
b83cd2c35abe58abb09c73f2ef35426f1384ad46Michael Speer * The transmit-side code uses an allocation process which is similar
b83cd2c35abe58abb09c73f2ef35426f1384ad46Michael Speer * to some theme park roller-coaster rides, where riders sit in cars
676f04004b15fc2872dfb0b7349d2d821a6eaa31Michael Speer * that can go individually, but work better in a train.
b83cd2c35abe58abb09c73f2ef35426f1384ad46Michael Speer *
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * 1) RESERVE a place - this doesn't refer to any specific car or
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * seat, just that you will get a ride. The attempt to RESERVE a
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * place can fail if all spaces in all cars are already committed.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs *
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * 2) Prepare yourself; this may take an arbitrary (but not unbounded)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * time, and you can back out at this stage, in which case you must
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * give up (RENOUNCE) your place.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs *
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * 3) CLAIM your space - a specific car (the next sequentially
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * numbered one) is allocated at this stage, and is guaranteed
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * to be part of the next train to depart. Once you've done
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * this, you can't back out, nor wait for any external event
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * or resource.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs *
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * 4) Occupy your car - when all CLAIMED cars are OCCUPIED, they
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * all depart together as a single train!
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs *
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * 5) At the end of the ride, you climb out of the car and RENOUNCE
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * your right to it, so that it can be recycled for another rider.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs *
b83cd2c35abe58abb09c73f2ef35426f1384ad46Michael Speer * For each rider, these have to occur in this order, but the riders
b83cd2c35abe58abb09c73f2ef35426f1384ad46Michael Speer * don't have to stay in the same order at each stage. In particular,
b83cd2c35abe58abb09c73f2ef35426f1384ad46Michael Speer * they may overtake each other between RESERVING a place and CLAIMING
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * it, or between CLAIMING and OCCUPYING a space.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs *
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Once a car is CLAIMED, the train currently being assembled can't go
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * without that car (this guarantees that the cars in a single train
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * make up a consecutively-numbered set). Therefore, when any train
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * leaves, we know there can't be any riders in transit between CLAIMING
8ad8db65d4781f61f1fd519144f555e6045100e1Michael Speer * and OCCUPYING their cars. There can be some who have RESERVED but
8ad8db65d4781f61f1fd519144f555e6045100e1Michael Speer * not yet CLAIMED their places. That's OK, though, because they'll go
8ad8db65d4781f61f1fd519144f555e6045100e1Michael Speer * into the next train.
8ad8db65d4781f61f1fd519144f555e6045100e1Michael Speer */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs#define BGE_DBG BGE_DBG_SEND /* debug flag for this code */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
8ad8db65d4781f61f1fd519144f555e6045100e1Michael Speer
8ad8db65d4781f61f1fd519144f555e6045100e1Michael Speer/*
8ad8db65d4781f61f1fd519144f555e6045100e1Michael Speer * ========== Send-side recycle routines ==========
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs/*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Recycle all the completed buffers in the specified send ring up to
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * (but not including) the consumer index in the status block.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs *
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * This function must advance (srp->tc_next) AND adjust (srp->tx_free)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * to account for the packets it has recycled.
fd9489cef0e9b7d8a708339e560d453f230af2cfQiyan Sun - Sun Microsystems - San Diego United States *
fd9489cef0e9b7d8a708339e560d453f230af2cfQiyan Sun - Sun Microsystems - San Diego United States * This is a trivial version that just does that and nothing more, but
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * it suffices while there's only one method for sending messages (by
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * copying) and that method doesn't need any special per-buffer action
1ed830817782694e7259ee818a2f8eee72233f1eMichael Speer * for recycling.
41307000fb6264427cd9b68419c13b879e83e7d3Qiyan Sun - Sun Microsystems - San Diego United States */
41307000fb6264427cd9b68419c13b879e83e7d3Qiyan Sun - Sun Microsystems - San Diego United Statesstatic void bge_recycle_ring(bge_t *bgep, send_ring_t *srp);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs#pragma inline(bge_recycle_ring)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
fe930412c257f961ae67039de3b164b83717976aqsstatic void
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qsbge_recycle_ring(bge_t *bgep, send_ring_t *srp)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs{
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs uint64_t slot;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs uint64_t n;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs _NOTE(ARGUNUSED(bgep))
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs ASSERT(mutex_owned(srp->tc_lock));
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs slot = *srp->cons_index_p; /* volatile */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs n = slot - srp->tc_next;
1c29f7e382074ff2792b7f30c9be898ead487a30Qiyan Sun - Sun Microsystems - San Diego United States if (slot < srp->tc_next)
1c29f7e382074ff2792b7f30c9be898ead487a30Qiyan Sun - Sun Microsystems - San Diego United States n += srp->desc.nslots;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs /*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * We're about to release one or more places :-)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * These ASSERTions check that our invariants still hold:
fe930412c257f961ae67039de3b164b83717976aqs * there must always be at least one free place
fe930412c257f961ae67039de3b164b83717976aqs * at this point, there must be at least one place NOT free
676f04004b15fc2872dfb0b7349d2d821a6eaa31Michael Speer * we're not about to free more places than were claimed!
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs ASSERT(srp->tx_free > 0);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
676f04004b15fc2872dfb0b7349d2d821a6eaa31Michael Speer srp->tc_next = slot;
676f04004b15fc2872dfb0b7349d2d821a6eaa31Michael Speer bge_atomic_renounce(&srp->tx_free, n);
676f04004b15fc2872dfb0b7349d2d821a6eaa31Michael Speer
fe930412c257f961ae67039de3b164b83717976aqs /*
fe930412c257f961ae67039de3b164b83717976aqs * Reset the watchdog count: to 0 if all buffers are
fe930412c257f961ae67039de3b164b83717976aqs * now free, or to 1 if some are still outstanding.
fe930412c257f961ae67039de3b164b83717976aqs * Note: non-synchonised access here means we may get
fe930412c257f961ae67039de3b164b83717976aqs * the "wrong" answer, but only in a harmless fashion
fe930412c257f961ae67039de3b164b83717976aqs * (i.e. we deactivate the watchdog because all buffers
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * are apparently free, even though another thread may
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * have claimed one before we leave here; in this case
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * the watchdog will restart on the next send() call).
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bgep->watchdog = srp->tx_free == srp->desc.nslots ? 0 : 1;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs}
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs/*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Recycle all returned slots in all rings.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs *
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * To give priority to low-numbered rings, whenever we have recycled any
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * slots in any ring except 0, we restart scanning again from ring 0.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Thus, for example, if rings 0, 3, and 10 are carrying traffic, the
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * pattern of recycles might go 0, 3, 10, 3, 0, 10, 0:
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs *
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * 0 found some - recycle them
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * 1..2 none found
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * 3 found some - recycle them and restart scan
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * 0..9 none found
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * 10 found some - recycle them and restart scan
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * 0..2 none found
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * 3 found some more - recycle them and restart scan
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * 0 found some more - recycle them
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * 0..9 none found
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * 10 found some more - recycle them and restart scan
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * 0 found some more - recycle them
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * 1..15 none found
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs *
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * The routine returns only when a complete scan has been performed
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * without finding any slots to recycle.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs *
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Note: the expression (BGE_SEND_RINGS_USED > 1) yields a compile-time
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * constant and allows the compiler to optimise away the outer do-loop
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * if only one send ring is being used.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qsvoid bge_recycle(bge_t *bgep, bge_status_t *bsp);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs#pragma no_inline(bge_recycle)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qsvoid
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qsbge_recycle(bge_t *bgep, bge_status_t *bsp)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs{
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs send_ring_t *srp;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs uint64_t ring;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs uint64_t tx_rings = bgep->chipid.tx_rings;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qsrestart:
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs ring = 0;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs srp = &bgep->send[ring];
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs do {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs /*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * For each ring, (srp->cons_index_p) points to the
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * proper index within the status block (which has
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * already been sync'd by the caller).
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs ASSERT(srp->cons_index_p == SEND_INDEX_P(bsp, ring));
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
fd9489cef0e9b7d8a708339e560d453f230af2cfQiyan Sun - Sun Microsystems - San Diego United States if (*srp->cons_index_p == srp->tc_next)
fd9489cef0e9b7d8a708339e560d453f230af2cfQiyan Sun - Sun Microsystems - San Diego United States continue; /* no slots to recycle */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs mutex_enter(srp->tc_lock);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bge_recycle_ring(bgep, srp);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs mutex_exit(srp->tc_lock);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if (bgep->resched_needed && !bgep->resched_running) {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bgep->resched_running = B_TRUE;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs ddi_trigger_softintr(bgep->resched_id);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs }
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs /*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Restart from ring 0, if we're not on ring 0 already.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * As H/W selects send BDs totally based on priority and
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * available BDs on the higher priority ring are always
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * selected first, driver should keep consistence with H/W
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * and gives lower-numbered ring with higher priority.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if (tx_rings > 1 && ring > 0)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs goto restart;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs /*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Loop over all rings (if there *are* multiple rings)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs } while (++srp, ++ring < tx_rings);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs}
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs/*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * ========== Send-side transmit routines ==========
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs/*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * CLAIM an already-reserved place on the next train
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs *
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * This is the point of no return!
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qsstatic uint64_t bge_send_claim(bge_t *bgep, send_ring_t *srp);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs#pragma inline(bge_send_claim)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qsstatic uint64_t
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qsbge_send_claim(bge_t *bgep, send_ring_t *srp)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs{
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs uint64_t slot;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs mutex_enter(srp->tx_lock);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs atomic_add_64(&srp->tx_flow, 1);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs slot = bge_atomic_claim(&srp->tx_next, srp->desc.nslots);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs mutex_exit(srp->tx_lock);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs /*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Bump the watchdog counter, thus guaranteeing that it's
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * nonzero (watchdog activated). Note that non-synchonised
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * access here means we may race with the reclaim() code
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * above, but the outcome will be harmless. At worst, the
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * counter may not get reset on a partial reclaim; but the
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * large trigger threshold makes false positives unlikely
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bgep->watchdog += 1;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs return (slot);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs}
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs#define TCP_CKSUM_OFFSET 16
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs#define UDP_CKSUM_OFFSET 6
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qsstatic void
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qsbge_pseudo_cksum(uint8_t *buf)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs{
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs uint32_t cksum;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs uint16_t iphl;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs uint16_t proto;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs /*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Point it to the ip header.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs buf += sizeof (struct ether_header);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs /*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Calculate the pseudo-header checksum.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3a109ad9413b360a5bfa6fa5ddfacef5fd64fe5bQiyan Sun - Sun Microsystems - San Diego United States iphl = 4 * (buf[0] & 0xF);
fd9489cef0e9b7d8a708339e560d453f230af2cfQiyan Sun - Sun Microsystems - San Diego United States cksum = (((uint16_t)buf[2])<<8) + buf[3] - iphl;
dc10a9c2a5a49452cc30c6a110b64e5e074e37b3Michael Speer cksum += proto = buf[9];
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs cksum += (((uint16_t)buf[12])<<8) + buf[13];
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs cksum += (((uint16_t)buf[14])<<8) + buf[15];
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs cksum += (((uint16_t)buf[16])<<8) + buf[17];
6ffca240bba331a8b22ff3ce47de58da6a205843Michael Speer cksum += (((uint16_t)buf[18])<<8) + buf[19];
6ffca240bba331a8b22ff3ce47de58da6a205843Michael Speer cksum = (cksum>>16) + (cksum & 0xFFFF);
6ffca240bba331a8b22ff3ce47de58da6a205843Michael Speer cksum = (cksum>>16) + (cksum & 0xFFFF);
6ffca240bba331a8b22ff3ce47de58da6a205843Michael Speer
6ffca240bba331a8b22ff3ce47de58da6a205843Michael Speer /*
6ffca240bba331a8b22ff3ce47de58da6a205843Michael Speer * Point it to the TCP/UDP header, and
6ffca240bba331a8b22ff3ce47de58da6a205843Michael Speer * update the checksum field.
6ffca240bba331a8b22ff3ce47de58da6a205843Michael Speer */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs buf += iphl + ((proto == IPPROTO_TCP) ?
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs TCP_CKSUM_OFFSET : UDP_CKSUM_OFFSET);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs *(uint16_t *)buf = htons((uint16_t)cksum);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs}
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs/*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Send a message by copying it into a preallocated (and premapped) buffer
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qsstatic enum send_status bge_send_copy(bge_t *bgep, mblk_t *mp,
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs send_ring_t *srp, uint16_t tci);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs#pragma inline(bge_send_copy)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qsstatic enum send_status
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qsbge_send_copy(bge_t *bgep, mblk_t *mp, send_ring_t *srp, uint16_t tci)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs{
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bge_sbd_t *hw_sbd_p;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs sw_sbd_t *ssbdp;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs mblk_t *bp;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs char *txb;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs uint64_t slot;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs size_t totlen;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs size_t mblen;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs uint32_t pflags;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs BGE_TRACE(("bge_send_copy($%p, $%p, $%p, 0x%x)",
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs (void *)bgep, (void *)mp, (void *)srp));
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs /*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * IMPORTANT:
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Up to the point where it claims a place, a send_msg()
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * routine can indicate failure by returning SEND_FAIL.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Once it's claimed a place, it mustn't fail.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs *
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * In this version, there's no setup to be done here, and there's
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * nothing that can fail, so we can go straight to claiming our
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * already-reserved place on the train.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs *
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * This is the point of no return!
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs slot = bge_send_claim(bgep, srp);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs ssbdp = &srp->sw_sbds[slot];
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs /*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Copy the data into a pre-mapped buffer, which avoids the
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * overhead (and complication) of mapping/unmapping STREAMS
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * buffers and keeping hold of them until the DMA has completed.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs *
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Because all buffers are the same size, and larger than the
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * longest single valid message, we don't have to bother about
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * splitting the message across multiple buffers either.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs txb = DMA_VPTR(ssbdp->pbuf);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs totlen = 0;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bp = mp;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if (tci != 0) {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs mblen = bp->b_wptr - bp->b_rptr;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs ASSERT(mblen >= 2 * ETHERADDRL + VLAN_TAGSZ);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bcopy(bp->b_rptr, txb, 2 * ETHERADDRL);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs txb += 2 * ETHERADDRL;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs totlen = 2 * ETHERADDRL;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if (mblen -= 2 * ETHERADDRL + VLAN_TAGSZ) {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if ((totlen += mblen) <= bgep->chipid.ethmax_size) {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bcopy(bp->b_wptr-mblen, txb, mblen);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs txb += mblen;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs }
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs }
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bp = bp->b_cont;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs }
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs for (; bp != NULL; bp = bp->b_cont) {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs mblen = bp->b_wptr - bp->b_rptr;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if ((totlen += mblen) <= bgep->chipid.ethmax_size) {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bcopy(bp->b_rptr, txb, mblen);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs txb += mblen;
fe930412c257f961ae67039de3b164b83717976aqs }
fe930412c257f961ae67039de3b164b83717976aqs }
fe930412c257f961ae67039de3b164b83717976aqs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs /*
fe930412c257f961ae67039de3b164b83717976aqs * We've reached the end of the chain; and we should have
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * collected no more than ETHERMAX bytes into our buffer.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs ASSERT(bp == NULL);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs ASSERT(totlen <= bgep->chipid.ethmax_size);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs DMA_SYNC(ssbdp->pbuf, DDI_DMA_SYNC_FORDEV);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs /*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Update the hardware send buffer descriptor; then we're done.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * The return status indicates that the message can be freed
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * right away, as we've already copied the contents ...
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs hw_sbd_p = DMA_VPTR(ssbdp->desc);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs hw_sbd_p->host_buf_addr = ssbdp->pbuf.cookie.dmac_laddress;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs hw_sbd_p->len = totlen;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs hw_sbd_p->flags = SBD_FLAG_PACKET_END;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if (tci != 0) {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs hw_sbd_p->vlan_tci = tci;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs hw_sbd_p->flags |= SBD_FLAG_VLAN_TAG;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs }
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs hcksum_retrieve(mp, NULL, NULL, NULL, NULL, NULL, NULL, &pflags);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if (pflags & HCK_IPV4_HDRCKSUM)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs hw_sbd_p->flags |= SBD_FLAG_IP_CKSUM;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if (pflags & HCK_FULLCKSUM) {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs hw_sbd_p->flags |= SBD_FLAG_TCP_UDP_CKSUM;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if (bgep->chipid.flags & CHIP_FLAG_PARTIAL_CSUM)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bge_pseudo_cksum((uint8_t *)DMA_VPTR(ssbdp->pbuf));
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs }
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs return (SEND_FREE);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs}
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qsstatic boolean_t
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qsbge_send(bge_t *bgep, mblk_t *mp)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs{
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs send_ring_t *srp;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs enum send_status status;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs struct ether_vlan_header *ehp;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs boolean_t need_strip = B_FALSE;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bge_status_t *bsp;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs uint16_t tci;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs uint_t ring = 0;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs ASSERT(mp->b_next == NULL);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs /*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Determine if the packet is VLAN tagged.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs ASSERT(MBLKL(mp) >= sizeof (struct ether_header));
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs ehp = (struct ether_vlan_header *)mp->b_rptr;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if (ehp->ether_tpid == htons(ETHERTYPE_VLAN)) {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if (MBLKL(mp) < sizeof (struct ether_vlan_header)) {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if (!pullupmsg(mp,
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs sizeof (struct ether_vlan_header))) {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs BGE_DEBUG(("bge_send: pullup failure"));
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bgep->resched_needed = B_TRUE;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs return (B_FALSE);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs }
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs }
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs ehp = (struct ether_vlan_header *)mp->b_rptr;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs need_strip = B_TRUE;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs }
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs /*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Try to reserve a place in the chosen ring. Shouldn't try next
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * higher-numbered (lower-priority) ring, if there aren't any
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * available. Otherwise, packets with same priority may get
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * transmission starvation.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs srp = &bgep->send[ring];
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if (!bge_atomic_reserve(&srp->tx_free, 1)) {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs BGE_DEBUG(("bge_send: no free slots"));
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bgep->resched_needed = B_TRUE;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs return (B_FALSE);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs }
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs /*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Now that we know that there is space to transmit the packet
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * strip any VLAN tag that is present.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if (need_strip) {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs tci = ntohs(ehp->ether_tci);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs } else {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs tci = 0;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs }
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if (srp->tx_free <= 16) {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bsp = DMA_VPTR(bgep->status_block);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bge_recycle(bgep, bsp);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs }
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs /*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * We've reserved a place :-)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * These ASSERTions check that our invariants still hold:
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * there must still be at least one free place
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * there must be at least one place NOT free (ours!)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs ASSERT(srp->tx_free > 0);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if ((status = bge_send_copy(bgep, mp, srp, tci)) == SEND_FAIL) {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs /*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * The send routine failed :( So we have to renounce
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * our reservation before returning the error.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bge_atomic_renounce(&srp->tx_free, 1);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bgep->resched_needed = B_TRUE;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs return (B_FALSE);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs }
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs /*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * The send routine succeeded; it will have updated the
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * h/w ring descriptor, and the <tx_next> and <tx_flow>
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * counters.
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs *
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * Because there can be multiple concurrent threads in
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * transit through this code, we only want to prod the
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * hardware once the last one is departing ...
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs mutex_enter(srp->tx_lock);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if (--srp->tx_flow == 0) {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs DMA_SYNC(srp->desc, DDI_DMA_SYNC_FORDEV);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bge_mbx_put(bgep, srp->chip_mbx_reg, srp->tx_next);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bgep->bge_chip_state = BGE_CHIP_ERROR;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs }
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs mutex_exit(srp->tx_lock);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if (status == SEND_FREE)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs freemsg(mp);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs return (B_TRUE);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs}
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qsuint_t
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qsbge_reschedule(caddr_t arg)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs{
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bge_t *bgep;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bgep = (bge_t *)arg;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs BGE_TRACE(("bge_reschedule($%p)", (void *)bgep));
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if (bgep->bge_mac_state == BGE_MAC_STARTED && bgep->resched_needed) {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs mac_tx_update(bgep->mh);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bgep->resched_needed = B_FALSE;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bgep->resched_running = B_FALSE;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs }
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs return (DDI_INTR_CLAIMED);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs}
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs/*
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs * bge_m_tx() - send a chain of packets
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qsmblk_t *
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qsbge_m_tx(void *arg, mblk_t *mp)
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs{
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs bge_t *bgep = arg; /* private device info */
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs mblk_t *next;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs BGE_TRACE(("bge_m_tx($%p, $%p)", arg, (void *)mp));
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs ASSERT(mp != NULL);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs ASSERT(bgep->bge_mac_state == BGE_MAC_STARTED);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if (bgep->bge_chip_state != BGE_CHIP_RUNNING) {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs BGE_DEBUG(("bge_m_tx: chip not running"));
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs return (mp);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs }
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs rw_enter(bgep->errlock, RW_READER);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs while (mp != NULL) {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs next = mp->b_next;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs mp->b_next = NULL;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs if (!bge_send(bgep, mp)) {
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs mp->b_next = next;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs break;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs }
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs mp = next;
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs }
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs rw_exit(bgep->errlock);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs return (mp);
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs}
3dec9fcdd56adf1b4a563137b4915c8f2d83b881qs