/*
* 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 (c) 2010-2013, by Broadcom, Inc.
* All Rights Reserved.
*/
/*
* All rights reserved.
*/
#include "bge_impl.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 boolean_t
{
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!
*/
if (buf_item_head == NULL)
else {
}
n++;
}
if (n == 0)
return (B_FALSE);
/*
* 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).
*/
/*
* Update recycle index and free tx BD number
*/
/*
* Return tx buffers to buffer push queue
*/
txbuf_queue->count += n;
/*
* Check if we need exchange the tx buffer push and pop queue
*/
}
return (B_TRUE);
}
/*
* 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)
{
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 */
/*
* 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)
*/
return (tx_done);
}
/*
* ========== Send-side transmit routines ==========
*/
static void
{
/*
* Point it to the ip header.
*/
buf += sizeof (struct ether_header);
/*
* Calculate the pseudo-header checksum.
*/
/*
* update the checksum field.
*/
/*
* A real possibility that pointer cast is a problem.
* Should be fixed when we know the code better.
* E_BAD_PTR_CAST_ALIGN is added to make it temporarily clean.
*/
}
static bge_queue_item_t *
{
if (txbuf_queue->count == 0) {
if (txbuf_queue->count == 0) {
/* Try to allocate more tx buffers */
} else
txbuf_item = NULL;
return (txbuf_item);
}
}
txbuf_queue->count--;
return (txbuf_item);
}
/*
* Send a message by copying it into a preallocated (and premapped) buffer
*/
#pragma inline(bge_send_copy)
static void
{
char *pbuf;
continue;
}
}
/*
* Fill the Tx buffer descriptors and trigger the h/w transmission
*/
static void
{
/*
* Try to hold the tx lock:
* If we are in an interrupt context, use mutex_enter() to
* ensure quick response for tx in interrupt context;
* Otherwise, use mutex_tryenter() to serialize this h/w tx
* BD filling and transmission triggering task.
*/
if (servicing_interrupt() != 0)
return; /* already in process */
if (count == 0)
break;
}
/*
* If there are no enough BDs: try to recycle more
*/
/*
* Reserved required BDs: 1 is enough
*/
break;
}
/*
* Filling the tx BD
*/
/*
* Go straight to claiming our already-reserved places
* on the train!
*/
/*
* Setting hardware send buffer descriptor
*/
}
}
/*
* Trigger h/w to start transmission.
*/
if (count != 0) {
sizeof (bge_sbd_t),
}
goto start_tx;
}
}
mblk_t *
{
char *pbuf;
/*
* Get a s/w tx buffer first
*/
if (txbuf_item == NULL) {
/* no tx buffer available */
return (mp);
}
/*
* Copy all mp fragments to the pkt buffer
*/
/*
* Determine if the packet is VLAN tagged.
*/
/* Strip the vlan tag */
} else
vlan_tci = 0;
/*
* Retrieve checksum offloading info.
*/
/*
* Calculate pseudo checksum if needed.
*/
if ((pflags & HCK_FULLCKSUM) &&
/*
* Packet buffer is ready to send: get and fill pkt info
*/
/*
* Filling the h/w bd and trigger the h/w to start transmission
*/
/*
* We've copied the contents, the message can be freed right away
*/
return (NULL);
}
static mblk_t *
{
}
{
if (bgep->tx_resched_needed &&
bgep->tx_resched++;
}
return (DDI_INTR_CLAIMED);
}
/*
* bge_m_tx() - send a chain of packets
*/
mblk_t *
{
!(bgep->param_link_up)) {
BGE_DEBUG(("bge_m_tx: chip not running or link down"));
}
break;
}
}
return (mp);
}