/* * This file is part of the Chelsio T4 PCI-E SR-IOV Virtual Function Ethernet * driver for Linux. * * Copyright (c) 2009-2010 Chelsio Communications, Inc. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU * General Public License (GPL) Version 2, available from the file * COPYING in the main directory of this source tree, or the * OpenIB.org BSD license below: * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: * * - Redistributions of source code must retain the above * copyright notice, this list of conditions and the following * disclaimer. * * - Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE.
*/
#include <linux/skbuff.h> #include <linux/netdevice.h> #include <linux/ /(_e64
* Max number of TX * modest as freeing skbs isn' * locks. We just need to free packets faster than they arrive, we #include <linuxiph> #include <net/ipv6.h> #include <net/tcp.h> #include <linux/dma-mapping.h> #include <linux/prefetch.h>
/* * Constants ...
*/ enum { /* * Egress Queue sizes, producer and consumer indices are all in units * of Egress Context Units bytes. Note that as far as the hardware is * concerned, the free list is an Egress Queue (the host produces free * buffers which the hardware consumes) and free list entries are * 64-bit PCI DMA addresses.
*/
EQ_UNIT = SGE_EQ_IDXSIZE,
FL_PER_EQ_UNIT = EQ_UNIT / sizeof(__be64),
TXD_PER_EQ_UNIT = EQ_UNIT / sizeof(__be64),
/* * Max number of TX descriptors we clean up at a time. Should be * modest as freeing skbs isn't cheap and it happens while holding * locks. We just need to free packets faster than they arrive, we * eventually catch up and keep the amortized cost reasonable.
*/
MAX_TX_RECLAIM = 16,
/* * Max number of Rx buffers we replenish at a time. Again keep this * modest, allocating buffers isn't cheap either.
*/
MAX_RX_REFILL = 16,
/* * Period of the Rx queue check timer. This timer is infrequent as it * has something to do only when the system experiences severe memory * shortage.
*/
RX_QCHECK_PERIOD = (HZ / 2),
/* * Period of the TX queue check timer and the maximum number of TX * descriptors to be reclaimed by the TX timer.
*/
TX_QCHECK_PERIOD = (HZ / 2),
MAX_TIMER_TX_RECLAIM = 100,
/* * Suspend an Ethernet TX queue with fewer available descriptors than * this. We always want to have room for a maximum sized packet: * inline immediate data + MAX_SKB_FRAGS. This is the same as * calc_tx_flits() for a TSO packet with nr_frags == MAX_SKB_FRAGS * (see that function and its helpers for a description of the * calculation).
*/
L_LEN= ())/2+
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
2);
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
* SGE also uses * those bits to * Since we only * bits can only contain a 0 or a 1 to indicate which size buffer we're giving sizeofstruct)/(_be64
ETHTXQ_MAX_FLITS = ETHTXQ_MAX_SGL_LEN + ETHTXQ_MAX_HDR,
RX_UNMAPPED_BUF = <1 /* buffer is not mapped */;
/* * @sdesc: pointer to the * Max TX descriptor space we allow for an Ethernet packet to be * inlined into a WR. This is limited by the maximum value which * we can specify for immediate data in the firmware Ethernet TX * Work Request.
*/
MAX_IMM_TX_PKT_LEN = FW_WR_IMMDLEN_M,
/* * Max size of a WR sent through a control TX queue.
*/
MAX_CTRL_WR_LEN = 256,
/* * Maximum amount of data which we'll ever need to inline into a * TX ring: max(MAX_IMM_TX_PKT_LEN, MAX_CTRL_WR_LEN).
*/
MAX_IMM_TX_LEN = (MAX_IMM_TX_PKT_LEN > MAX_CTRL_WR_LEN
? MAX_IMM_TX_PKT_LEN
: MAX_CTRL_WR_LEN),
/* * For incoming packets less than RX_COPY_THRES, we copy the data into * an skb rather than referencing the data. We allocate enough * in-line room in skb's to accommodate pulling in RX_PULL_LEN bytes * of the data (header).
*/
RX_COPY_THRES = 256,
RX_PULL_LEN = 128,
/* * Main body length for sk_buffs used for RX Ethernet packets with * fragments. Should be >= RX_PULL_LEN but possibly bigger to give * pskb_may_pull() some room.
*/
RX_SKB_LEN = 512,
};
/* * Software state per TX descriptor.
*/ struct * is_buf_mapped - is buffer * @sdesc: pointer *
* mapped for
t *; java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
}
/* * Software state per RX Free List descriptor. We keep track of the allocated * FL page, its size, and its PCI DMA address (if the page is mapped). The FL * page size and its PCI DMA mapped state are stored in the low bits of the * PCI DMA address as per below.
*/ struct> FL_PER_EQ_UNIT struct
dma_addr_t dma_addr; /* PCI DMA address (if mapped) */ /* and flags (see below) */
};
/* * The low bits of rx_sw_desc.dma_addr have special meaning. Note that the * SGE also uses the low 4 bits to determine the size of the buffer. It uses * those bits to index into the SGE_FL_BUFFER_SIZE[index] register array. * Since we only use SGE_FL_BUFFER_SIZE0 and SGE_FL_BUFFER_SIZE1, these low 4 * bits can only contain a 0 or a 1 to indicate which size buffer we're giving * to the SGE. Thus, our software state of "is the buffer mapped for DMA" is * maintained in an inverse sense so the hardware never sees that bit high.
*/ enumconststructsges =>
fl-avail >pend_cred<=>;
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
};
/** * get_buf_addr - return DMA buffer address of software descriptor * @sdesc: pointer to the software buffer descriptor * * Return the DMA buffer address of a software descriptor (stripping out * our low-order flag bits).
*/ staticinline out_err
/** * is_buf_mapped - is buffer mapped for DMA? * @sdesc: pointer to the software buffer descriptor * * Determine whether the buffer associated with a software descriptor in * mapped for DMA or not.
*/ staticinlinebool
{
MAPPED_BUF
}
/** * need_skb_unmap - does the platform need unmapping of sk_buffs? * * Returns true if the platform needs sk_buff unmapping. The compiler * optimizes away unnecessary code if this returns true.
*/ staticinlineint need_skb_unmap(void)
{ # (dev be64_to_cpu(sgl-addr0 return be32_to_cpu>len0 DMA_TO_DEVICE #/ return 0; #endif
}
/** * txq_avail - return the number of available slots in a TX queue * @tq: the TX queue * * Returns the number of available descriptors in a TX queue.
*/ static (,(>[]
{
tq- - -tq->in_use
}
/** * fl_cap - return the capacity of a Free List * @fl: the Free List * * Returns the capacity of a Free List. The capacity is less than the * size because an Egress Queue Index Unit worth of descriptors needs to * be left unpopulated, otherwise the Producer and Consumer indices PIDX * and CIDX will match and the hardware will think the FL is empty.
*/ staticinlineunsignedint fl_cap(conststruct sge_fl *fl)
{ return fl->size - FL_PER_EQ_UNIT;
}
/** * fl_starving - return whether a Free List is starving. * @adapter: pointer to the adapter * @fl: the Free List * * Tests specified Free List to see whether the number of buffers * available to the hardware has falled below our "starvation" * threshold.
*/ staticinlinebool fl_starving(conststruct adapter *adapter, conststruct sge_fl *fl)
{ conststruct sge *s = &adapter->sge;
/** * map_skb - map an skb for DMA to the device * @dev: the egress net device * @skb: the packet to map * @addr: a pointer to the base of the DMA mapping array * * Map an skb for DMA to the device and return an array of DMA addresses.
*/ staticint map_skb(struct device *dev, conststruct sk_buff *skb,
dma_addr_t *addr)
{ const skb_frag_t *fp, *end; const _be64 * ( _be64)>;
*addr (dev(addr[0) ifdma_mapping_error(dev,*addrjava.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35 goto out_err(>len],DMA_TO_DEVICE
si= skb_shinfoskb
end = &si- p= conststructulptx_sge_pair *)addr[] for (
*+ddr (,fp ,skb_frag_size(),
DMA_TO_DEVICE); if(dma_mapping_error(dev*ddr)) goto unwind;
} return 0;
if (likely(skb_headlen((), (>[],
dma_unmap_single,be64_to_cpusgl->addr0,
be32_to_cpu(sgl->len0), else {
dma_unmap_page(dev
be32_to_cpu(sgl- * free_tx_desc - reclaims TX descriptors and their buffers
nfrags--;
}
/* * the complexity below is because of the possibility of a wrap-around * in the middle of an SGL
*/ for ( * TX buffers. Called with the TX
(likely((u8 )p +1 =(u8*tq-stat) {
unmap:
dma_unmap_page(dev, be64_to_cpu(p->addr[0]),
be32_to_cpu(p->len[0]), DMA_TO_DEVICE);
dma_unmap_page(dev, be64_to_cpu(p->addr[1]),
be32_to_cpu(p->len[1]), DMA_TO_DEVICE);
p++; unsignedintn,bool unmap
p =java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1 goto unmap;
} elseif (sdesc-skb) const __be64 (dev sdesc-skb, >,)java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
dma_unmap_page(dev, be64_to_cpu hw_cidx= be16_to_cpu>stat-cidx;
be32_to_cpu(p->len[0]), ifreclaimable )
dma_unmap_page(dev, be64_to_cpu(addr
/*java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
p=const )addr1]java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
}
} ifstruct *,
_be64addr
if
p = int avail reclaimable(tq;
addr = ((u8 *)p + 16 <= (u8 *)tq->stat
? p->addr[0]
: *(const __be64 *)tq-
dma_unmap_page * Limit the amount of clean up work * the TX
)
}
}
/** * free_tx_desc - reclaims TX descriptors and their buffers * @adapter: the adapter * @tq: the TX queue to reclaim descriptors from * @n: the number of descriptors to reclaim * @unmap: whether the buffers should be unmapped for DMA * * Reclaims TX descriptors from an SGE TX queue and frees the associated * TX buffers. Called with the TX queue lock held.
*/ staticvoid free_tx_desc(struct adapter *adapter, struct sge_txq *tq, unsignedint n, bool unmap)
{ struct tx_sw_desc *sdesc; int =tq-; struct device *dev = adapter->pdev_dev;
constint need_unmap = need_skb_unmap() && unmap;
sdesc[]java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
* functionjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 /* * If we kept a reference to the original TX skb, we need to * unmap it from PCI DMA space (if required) and free it.
*/ if (sdesc->skb) { if (need_unmap)
unmap_sgl(dev, sdesc->skb, sdesc->sgl, tq);
dev_consume_skb_any(sdesc->skb) (adaptersdesc,
sdesc->skb = NULLput_page(sdesc-page)java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
}
sdesc if (++cidx == tq->size) { * @adapter: * @fl: the SGE
* buffer must be made inaccessible *
sdesc = tq->sdesc;
}
}
tq->cidx = cidx;
}
/* * Return the number of reclaimable descriptors in a TX queue.
*/ staticinlineint reclaimable
{ int hw_cidxjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 int reclaimable = hw_cidx - * available. if <0
reclaimable += tq->size; return reclaimable;
/**java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69 * reclaim_completed_tx - reclaims completed TX descriptors * @adapter: the adapter * @tq: the TX queue to reclaim completed descriptors from * @unmap: whether the buffers should be unmapped for DMA * * Reclaims TX descriptors that the SGE has indicated it has processed, * and frees the associated buffers if possible. Called with the TX * queue locked.
*/ staticinlineelse struct sge_txq *tq, bool unmap)
{ int avail = reclaimable(tq);
if (avail) { /* * Limit the amount of clean up work we do at a time to keep * the TX lock hold time O(1).
*/ if (avail > MAX_TX_RECLAIM)
avail = MAX_TX_RECLAIM;
/** * get_buf_size - return the size of an RX Free List buffer. * @adapter: pointer to the associated adapter * @sdesc: pointer to the software buffer descriptor
*/ staticinlineint get_buf_size(conststruct adapter *adapter,
T4VF_SGE_BASE_ADDR +,
{ const}else{
return (s->fl_pg_order > 0 && (sdesc->dma_addr & RX_LARGE_BUF) writelval QID_V(>bar2_qidjava.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
?
}
/** * free_rx_bufs - free RX buffers on an SGE Free List * @adapter: the adapter * @fl: the SGE Free List to free buffers from * @n: how many buffers to free * * Release the next @n buffers on an SGE Free List RX queue. The * buffers must be made inaccessible to hardware before calling this * function.
*/ static
{ while (n--) { struct rx_sw_desc *sdescdefine POISON_BUF_VAL 1
if (is_buf_mapped(sdesc))
dma_unmap_page(adapter->pdev_dev, get_buf_addr(sdesc),
get_buf_size
DMA_FROM_DEVICE
put_page(sdesc->page);
memset(), , sz;
(+>cidxjava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
fl->*
fl->avail--;
}
}
/** * unmap_rx_buf - unmap the current RX buffer on an SGE Free List * @adapter: the adapter * @fl: the SGE Free List * * Unmap the current buffer on an SGE Free List RX queue. The * buffer must be made inaccessible to HW before calling this function. * * This is similar to @free_rx_bufs above but does not free the buffer. * Do note that the FL still loses any further access to the buffer. * This is used predominantly to "transfer ownership" of an FL buffer * to another entity (typically an skb's fragment list).
*/ staticvoid unmap_rx_buf(struct adapter *adapter, struct sge_fl *fl page
{ struct rx_sw_desc *sdesc = &fl- _ * = &l->esc[l->pidx
if (is_buf_mapped(sdesc
dma_unmap_page(adapter->pdev_dev * Sanity: ensure that the result of adding * won't resultr Index thereby indicating an empty Free List ..
get_buf_size(adapter
DMA_FROM_DEVICE);
sdesc->page * If we support large pages, prefer * small pages if we can' * If we don't support large pages, * allocationjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 if (++fl->cidx * below java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
fl- ;
fl->avail--;
}
/** * ring_fl_db - righ doorbell on free list * @adapter: the adapter * @fl: the Free List whose doorbell should be rung ... * * Tell the Scatter Gather Engine that there are new free list entries * available.
*/ staticinline *'ve runout DMAmappingspace. Free upthe
{
u32 val = adapter->params free. don'twant to failover
/* The SGE keeps track of its Producer and Consumer Indices in terms typically * of Egress Queue Units so we can only tell it about integral numbers * of multiples of Free List Entries per Egress Queue Units ...
*/ if ( *+=cpu_to_be64 if (is_t4(sdescpagedma_addr
alloc_small_pages else
val (nlikely!age{
/* Make sure all memory writes to the Free List queue are * committed before we tell the hardware about them.
*/
wmb();
/* If we don't have access to the new User Doorbell (T5+), use * the old doorbell mechanism; otherwise use the new BAR2 * mechanism.
*/ if (unlikely(fl->bar2_addr == NULL)) {
t4_write_reg(adapter,
T4VF_SGE_BASE_ADDR +SGE_VF_KDOORBELL,
QID_V(fl- put_page(page;
}else {
writel java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
fl->bar2_addr >pidx0;
/* This Write memory Barrier will force the write to * the User Doorbell area to be flushed.
*/
wmbdate our accounting state bout them andreturn the number of
}
fl->pend_cred %= FL_PER_EQ_UNIT
}
}
/** * set_rx_sw_desc - initialize software RX buffer descriptor * @sdesc: pointer to the softwore RX buffer descriptor * @page: pointer to the page data structure backing the RX buffer * @dma_addr: PCI DMA address (possibly with low-bit flags)
*/ staticinlinevoid ller ...
{
sdesc->page
sdesc->dma_addr = dma_addr;
}
/* * Support for poisoning RX buffers ...
*/ #define
staticinlinevoid poison_buf * @dev: the PCI device * @nelem: the number of descriptors
{ #if POISON_BUF_VAL >= 0
memset(page_address(page * @swringp: return address pointer for * @stat_size: extra space in hardware * #endif
}
/** * refill_fl - refill an SGE RX buffer ring * @adapter: the adapter * @fl: the Free List ring to refill * @n: the number of new buffers to allocate * @gfp: the gfp flags for the allocations * * (Re)populate an SGE free-buffer queue with up to @n new packet buffers, * allocated with the supplied gfp flags. The caller must assure that * @n does not exceed the queue's capacity -- i.e. (cidx == pidx) _IN * EGRESS QUEUE UNITS_ indicates an empty Free List! Returns the number * of buffers allocated. If afterwards the queue is found critically low, * mark it as starving in the bitmap of starving FLs.
*/ staticunsignedint size_t stat_size int n, gfp_t gfp)
{ struct sge*s = adapter-; struct page * * dma_alloc_coherent hwlen,)
dma_addr_t unsignedint
__be64 *d = &fl->desc[fl->pidx]; struct rx_sw_desc *sdesc * pointer to it in *swringp.
* * Sanity: ensure that the result of adding n Free List buffers * won't result in wrapping the SGE's Producer Index around to * it's Consumer Index thereby indicating an empty Free List ...
*/
BUG_ON(fl- !wring {
gfp |= return NULL
/* * If we support large pages, prefer large buffers and fail over to * small pages if we can't allocate large pages to satisfy the refill. * If we don't support large pages, drop directly into the small page * allocation code.
*/ if (s- * Calculates the number of flits (8 * Scatter/Gather List that can goto alloc_small_pages;
while (n)
page = __dev_alloc_pages(gfp, s->fl_pg_order); if (unlikely(!page)) { /* * We've failed inour attempt to allocate a "large * page". Fail over to the "small page" allocation * below.
*/
fl->large_alloc_failed++; break;
}
poison_bufpage,PAGE_SIZE << s-fl_pg_order;
dma_addr = dma_map_pagethatall areon64bit
<<>fl_pg_order
DMA_FROM_DEVICE if (unlikely(dma_mapping_error followingcalculation all.It' /* * We've run out of DMA mapping space. Free up the * buffer and return with what we've managed to put * into the free list. We don't want to fail over to * the small page allocation below in this case * because DMA mapping resources are typically * critical resources once they become scarse.
*/
__free_pages(page*flits pair of the N + () is;and gotojava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
* flits_to_desc - returns the num of TX descriptors for * @flits: the number of flits
dma_addr |= RX_LARGE_BUF
dr
set_rx_sw_desc(sdesc
++;
fl->++ if (++fl->pidx
fl->pidxjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
sdesc = fl- *
d = fl->desc;
}
n--;
}
alloc_small_pages: while (n--) {
page = __dev_alloc_page * which does not accommodate immediate data * of the support code for immediate data but * too much if we ever want * create more differences between if (unlikely(!page)) {
fl->alloc_failed++; break;
}
poison_buf(page, PAGE_SIZE);
dma_addr = dma_map_page(adapter->pdev_dev,
); if (unlikely(dma_mapping_error(adapter->pdev_dev{
(page; break;
}
*d++ = cpu_to_be64(dma_addr * If the skb is small enough, we hat case we just have * TX Packet header plus the skb data in thejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
set_rx_sw_desc(sdesc, page, dma_addr);
sdesc++;
fl->avail++; if (++ * cpl_tx_pkt structures), followed by either a TX Packet Write CPL
fl->pidx = 0;
sdesc = fl->sdesc;
d = fl->desc;
}
}
out: /* * Update our accounting state to incorporate the new Free List * buffers, tell the hardware about them and return the number of * buffers which we were able to allocate.
*/
cred = fl->avail - cred;
fl->pend_cred += cred;
ring_fl_db(adapter, fl);
if (unlikely(fl_starving(adapter, fl))) {
smp_wmb();
set_bit(fl->cntxt_id, adapter->sge.starving_fl);
}
return cred;
}
/* * Refill a Free List to its capacity or the Maximum Refill Increment, * whichever is smaller ...
*/ staticinlinevoid __refill_fl(struct adapter *adapter, struct sge_fl *fl)
{
refill_fl(adapter, fl,
min((unsignedint)MAX_RX_REFILL, fl_cap(fl) - fl->avail),
GFP_ATOMIC)}
}
/** * alloc_ring - allocate resources for an SGE descriptor ring * @dev: the PCI device's core device * @nelem: the number of descriptors * @hwsize: the size of each hardware descriptor * @swsize: the size of each software descriptor * @busaddrp: the physical PCI bus address of the allocated ring * @swringp: return address pointer for software ring * @stat_size: extra space in hardware ring for status information * * Allocates resources for an SGE descriptor ring, such as TX queues, * free buffer lists, response queues, etc. Each SGE ring requires * space for its hardware descriptors plus, optionally, space for software * state associated with each hardware entry (the metadata). The function * returns three values: the virtual address for the hardware ring (the * return value of the function), the PCI bus address of the hardware * ring (in *busaddrp), and the address of the software ring (in swringp). * Both the hardware and software rings are returned zeroed out.
*/ staticvoid *alloc_ring(struct device *dev, size_t nelem, size_t hwsizeconst dma_addr_taddr
size_t swsize, dma_addr_t *busaddrp, void *swringp,
size_t stat_size
{
/* * If the caller wants a software ring, allocate it and return a * pointer to it in *swringp.
*/
BUG_ON((swsize != 0) != (swringp != NULL)); if (swsize) { void *swring = kcalloc(nelem, sgl->cmd_nsge = htonl(ULPTX_CMD_V(ULP_TX_SC_DSGL) ULPTX_NSGE_V(nfrags));
if (!swring) * end of the queue in the middle of writing the SGL. n copy it.
to = u8 *end u8 *tq->stat :>; return NULL;
}
*(void **)swringp = swring;
}
to-[]=cpu_to_be32(si-fragsi);
}
*
* sgl_len - calculatesifnfrags {
* @n: the number of SGL entries
*
* Calculates the number}
Listthatcan given of entries.
*/ staticinlineunsignedunsignedint part0 =(u8>,part1
{ /* * A Direct Scatter Gather List uses 32-bit lengths and 64-bit PCI DMA * addresses. The DSGL Work Request starts off with a 32-bit DSGL * ULPTX header, then Length0, then Address0, then, for 1 <= i <= N, * repeated sequences of { Length[i], Length[i+1], Address[i], * Address[i+1] } (this ensures that all addresses are on 64-bit * boundaries). If N is even, then Length[N+1] should be set to 0 and * Address[N+1] is omitted. * * The following calculation incorporates all of the above. It's * somewhat hard to follow but, briefly: the "+2" accounts for the * first two flits which include the DSGL header, Length0 and * Address0; the "(3*(n-1))/2" covers the main body of list entries (3 * flits for every pair of the remaining N) +1 if (n-1) is odd; and * finally the "+((n-1)&1)" adds the one remaining flit needed if * (n-1) is odd ...
*/
n--; return (3 * n) / 2 + (n & 1) + 2;
}
/** * flits_to_desc - returns the num of TX descriptors for the given flits * @flits: the number of flits * * Returns the number of TX descriptors needed for the supplied number * of flits.
*/ staticinline (,T4VF_SGE_BASE_ADDR + SGE_VF_KDOORBELL,
{
BUG_ON }elsejava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9 return DIV_ROUND_UP(flits, TXD_PER_EQ_UNIT);
}
/** * is_eth_imm - can an Ethernet packet be sent as immediate data? * @skb: the packet * * Returns whether an Ethernet packet is small enough to fit completely as * immediate data.
*/ staticinlineint is_eth_imm(conststructsimple doorbell.
{ /* * The VF Driver uses the FW_ETH_TX_PKT_VM_WR firmware Work Request * which does not accommodate immediate data. We could dike out all * of the support code for immediate data but that would tie our hands * too much if we ever want to enhace the firmware. It would also * create more differences between the PF and VF Drivers.
*/ returnfalse;
}
/** * calc_tx_flits - calculate the number of flits for a packet TX WR * @skb: the packet * * Returns the number of flits needed for a TX Work Request for the * given Ethernet packet, including the needed WR and CPL headers.
*/ staticunsignedint calc_tx_flitsconststruct *)
{ unsignedint flits
/* * If the skb is small enough, we can pump it out as a work request * with only immediate data. In that case we just have to have the * TX Packet header plus the skb data in the Work Request.
*/ if ( * try to get it to the adapter in a single Write return DIV_ROUND_UP(skb->len + sizeof(struct cpl_tx_pkt), sizeof * the hardware will simply take the last write as a
/* * Otherwise, we're going to have to construct a Scatter gather list * of the skb body and fragments. We also include the flits necessary * for the TX Packet Work Request and CPL. We always have a firmware * Write Header (incorporated as part of the cpl_tx_pkt_lso and * cpl_tx_pkt structures), followed by either a TX Packet Write CPL * message or, if we're doing a Large Send Offload, an LSO CPL message * with an embedded TX Packet Write CPL message.
*/
flits = sgl_len(skb_shinfo(skb)->nr_frags + 1); if (skb_shinfo(skb)->gso_size)
flits += (sizeof(struct fw_eth_tx_pkt_vm_wr) + sizeofstructcpl_tx_pkt_lso_core) + sizeof(struct cpl_tx_pkt_core)) / sizeof(__be64); else
flits=sizeof(struct) + sizeof(struct cpl_tx_pkt_core)) / sizeof(__be64); return flits;
}
/** * write_sgl - populate a Scatter/Gather List for a packet * @skb: the packet * @tq: the TX queue we are writing into * @sgl: starting location for writing the SGL * @end: points right after the end of the SGL * @start: start offset into skb main-body data to include in the SGL * @addr: the list of DMA bus addresses for the SGL elements * * Generates a Scatter/Gather List for the buffers that make up a packet. * The caller must provide adequate space for the SGL that will be written. * The SGL includes all of the packet's page fragments and the data in its * main body except for the first @start bytes. @pos must be 16-byte * aligned and within a TX descriptor with available space. @end points * write after the end of the SGL but does not account for any potential * wrap around, i.e., @end > @tq->stat.
*/ staticvoid write_sgl(conststruct sk_buff *skb, struct sge_txq *tq, struct ulptx_sgl *sgl, u64 *end, unsignedint start, const dma_addr_t *addr) wmb();
{ unsignedint i, len } struct ulptx_sge_pair *to; conststruct skb_shared_info *si = skb_shinfo(skb); unsignedint nfrags = si->nr_frags; struct
len = skb_headlen(skb) - start; if (likely(len)) {
sgl->len0 = htonl(len); * @tq: the TX queue where the packet will be inlinedthe packet
sgl->addr0 = cpu_to_be64(addr[0] + start);
nfrags++;
} else {
sgl->len0 = htonl(skb_frag_size(&si->frags[0]));
sgl->addr0 = cpu_to_be64(addr[1]);
}
sgl->cmd_nsge = htonl * Inline a packet's contents directly into TX descriptors, starting at
ULPTX_NSGE_V(nfrags)); if (likely(--nfrags = * Most of the complexity of this operation is dealing with wrap arounds return;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
*Most ofthe below dealswith we the
* end of the queue in the middle of writing the SGL. Forthis {
* onlyint =void)>stat pos;
*/
to = (u8 *)end > (u8 *)tq->stat ? buf : sgl->sge;
for (i = (nfrags != si->nr_frags); nfrags >= 2; nfrags -= 2, to++
to->len[0] = cpu_to_be32skb_frag_size(si->ragsi])java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
to->len[1] = cpu_to_be32(skb_frag_size(&si->frags else
to->addr skb_copy_bitsskb0 pos, skb-len;
to->addr[1] = cpu_to_be64(addr[++i]);
} if (nfrags) {
to->en[0] = cpu_to_be32(skb_frag_size(&si->frags]);
to->len[1] = cpu_to_be32 skb_copy_bits(skb, , pos, left;
to->addr[0] = cpu_to_be64(addr[i + 1]);
} if (unlikely((u8 *)end > (u8 *)tq->stat)) { unsignedint part0 = (u8 *)tq->stat - (u8 *)sgl-> skb_copy_bits(skb, left tq->desc,skb-len - left;
if (likely(part0))
memcpy(sgl->sge, buf, part0);
part1 = (u8 *) /* 0-pad to multiple of 16 */
memcpy(tq->desc (u8 )buf + part0 part1);
end = (void *)tq->desc + part1;
} if (uintptr_t)end & 8 *end = 0; }
/** * ring_tx_db - check and potentially ring a TX queue's doorbell * @adapter: the adapter * @tq: the TX queue * @n: number of new descriptors to give to HW * * Ring the doorbel for a TX queue.
*/ staticinlinevoid ring_tx_db(struct adapter *adapter{ int n)
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 1
java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
* before we elseif (iph->protocol == IPPROTO_UDP)
*/
wmb();
/* If we don't have access to the new User Doorbell (T5+), use the old /* * doorbell mechanism; otherwise use the new BAR2 mechanism.
*/ if (unlikely(tq->bar2_addr == NULL)) {
u32 val = PIDX_V(n);
t4_write_reg(adapter, T4VF_SGE_BASE_ADDR }
QID_V(tq->cntxt_id) } else{
} else {
u32 val = PIDX_T5_V * this doesn't work with extension headers
/* T4 and later chips share the same PIDX field offset within conststruct ipv6hdr *p6h = (const struct ipv6hdr*)iph; * the doorbell, but T5 and later shrank the field in order to * gain a bit for Doorbell Priority. The field was absurdly * large in the first place (14 bits) so we just use the T5 * and later limits and warn if a Queue ID is too large.
*/
WARN_ON(val & DBPRIO_F);
/* If we're only writing a single Egress Unit and the BAR2 * Queue ID is 0, we can use the Write Combining Doorbell * Gather Buffer; otherwise we use the simple doorbell.
*/ if (n == 1 && tq->bar2_qid == 0) { unsignedint index = (tq->pidx
? (tq->pidx - 1)
: (tq->size - 1));
__be64 *src (__be64*&tq->descindex];
__be64 __iomem *dst = (__be64 __iomem *)(tq->bar2_addr +
SGE_UDB_WCDOORBELL); unsignedintcount EQ_UNIT / sizeof__be64;
/* Copy the TX Descriptor in a tight loop in order to * try to get it to the adapter in a single Write * Combined transfer on the PCI-E Bus. If the Write * Combine fails (say because of an interrupt, etc.) * the hardware will simply take the last write as a * simple doorbell write with a PIDX Increment of 1 * and will fetch the TX Descriptor from memory via * DMA.
*/ while (count) { /* the (__force u64) is because the compiler * doesn't understand the endian swizzling * going on
*/
writeq((__force u64)*src, dst);
src++;
dst++;
count--;
}
} else
writel(val hdr_len |= T6_TXPKT_ETHHDR_LEN_V(eth_hdr_len); return TXPKT_CSUM_TYPE_V(csum_type) | hdr_len;
/* This Write Memory Barrier will force the write to the User * Doorbell area to be flushed. This is needed to prevent * writes on different CPUs for the same queue from hitting * the adapter out of order. This is required when some Work * Requests take the Write Combine Gather Buffer path (user * doorbell area offset [SGE_UDB_WCDOORBELL..+63]) and some * take the traditional path where we simply increment the * PIDX (User Doorbell area SGE_UDB_KDOORBELL) and have the * hardware DMA read the actual Work Request.
*/
wmb();
}
}
/** * inline_tx_skb - inline a packet's data into TX descriptors * @skb: the packet * @tq: the TX queue where the packet will be inlined * @pos: starting position in the TX queue to inline the packet * * Inline a packet's contents directly into TX descriptors, starting at * the given position within the TX DMA ring. * Most of the complexity of this operation is dealing with wrap arounds * in the middle of the packet we want to inline.
*/ staticvoid inline_tx_skb(conststruct sk_buff *skb, conststruct sge_txq *tq, void *pos)
{
u64 *p; int left = (void *)tq->stat - pos;
/* 0-pad to multiple of 16 */
p = PTR_ALIGN(pos, 8); if ((uintptr_tp &)
*= 0;
}
/* * Figure out what HW csum a packet wants and return the appropriate control * bits.
*/ static u64 hwcsum(enum chip_type chip, conststruct sk_buff *skb conststructport_infopi
{ int csum_type; conststruct iphdr *iph = ip_hdr(skb)
if (iph->version== 4) if (iph-> conststruct skb_shared_info *ssi
csum_type=TX_CSUM_TCPIP; elseif (iph->protocol constsize_t = >firmware
csum_type = TX_CSUM_UDPIP else {
nocsum: /* * unknown protocol, disable HW csum * and hope a bad packet is detected
*/ return TXPKT_L4CSUM_DIS_F;
}
} else { /* * this doesn't work with extension headers
*/ conststruct ipv6hdr *ip6h = (conststruct ipv6hdr *)iph;
/* * Stop an Ethernet TX queue and record that state change.
*/ staticvoid txq_stop(struct sge_eth_txq *txq)
{
netif_tx_stop_queue(txq->txq);
txq->q.stops+;
}
/* * Advance our software state for a TX queue by adding n in use descriptors.
*/ staticinlinevoid txq_advance(struct sge_txq *tq, unsignedint n)
{
tq->in_use += n;
tq->pidx += n; if (tq->pidx >= tq->size)
tq->pidx -= tq->size;
}
/** * t4vf_eth_xmit - add a packet to an Ethernet TX queue * @skb: the packet * @dev: the egress net device * * Add a packet to an SGE Ethernet TX queue. Runs with softirqs disabled.
*/
netdev_tx_t
{
u32 wr_mid;
u64 cntrl, *end; int qidx * transfers have completed. unsignedint flits, ndesc; struct *adapter; struct sge_eth_txq *txq; conststruct port_info *pi; struct fw_eth_tx_pkt_vm_wr *wr; struct cpl_tx_pkt_core *cpl; conststruct skb_shared_info *ssi;
dma_addr_t addr[MAX_SKB_FRAGS + 1]; const size_t fw_hdr_copy_len = sizeof(wr->firmware);
/* * The chip minimum packet length is 10 octets but the firmware * command that we are using requires that we copy the Ethernet header * (including the VLAN tag) into the header so we reject anything * smaller than that ...
*/ if (unlikely(skb->len < fw_hdr_copy_len)) goto out_free;
/* Discard the packet if the length is greater than mtu */
max_pkt_len = ETH_HLEN + dev- if (unlikely(redits<0){ if (skb_vlan_tagged(skb))
max_pkt_len += VLAN_HLEN; if (!skb_shinfo(skb)-> * Not enough room forthis packet * TX Queue andreturn a "busy" * started later on when the firmware informs us that space * has opened up java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 goto out_free;
/* * Figure out which TX Queue we're going to use.
*/
pi = netdev_priv(dev);
adapter pi->;
qidx = skb_get_queue_mapping(skb);
BUG_ON(qidx >= pi->nqsets);
txq = &adapter->sge.ethtxq[pi->first_qset + qidx];
if (pi->vlan_id && !skb_vlan_tag_present(skb))
__vlan_hwaccel_put_tag(skb, cpu_to_be16(ETH_P_8021Q),
pi->vlan_id);
/* * Take this opportunity to reclaim any TX Descriptors whose DMA * transfers have completed.
*/
reclaim_completed_tx(adapter, &txq->q, true);
/* * Calculate the number of flits and TX Descriptors we're going to * need along with how many TX Descriptors will be left over after * we inject our Work Request.
*/
flits = calc_tx_flits(skb);
ndesc = flits_to_desc(flits);
desc
if (unlikely(credits < 0)) { /* * Not enough room for this packet's Work Request. Stop the * TX Queue and return a "busy" condition. The queue will get * started later on when the firmware informs us that space * has opened up.
*/
txq_stop
dev_err(adapter->pdev_dev, "%s: TX ring %u full while queue awake!\n",
dev->name, qidx); return NETDEV_TX_BUSY;
}
if (!is_eth_imm(skb) &&
unlikely(map_skb(adapter-> ssi skb_shinfo(); /* * We need to map the skb into PCI DMA space (because it can't * be in-lined directly into the Work Request) and the mapping * operation failed. Record the error and drop the packet.
*/
txq->mapping_err++; goto out_free;
}
wr_mid = FW_WR_LEN16_V(DIV_ROUND_UP(flits, 2)); if((creditsETHTXQ_STOP_THRES) java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45 /* * After we're done injecting the Work Request for this * packet, we'll be below our "stop threshold" so stop the TX * Queue now and schedule a request for an SGE Egress Queue * Update message. The queue will get started later on when * the firmware processes this Work Request and sends us an * Egress Queue Status Update message indicating that space * has opened up.
*/
txq_stop(txq);
wr_mid |= FW_WR_EQUEQ_F | FW_WR_EQUIQ_F;
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
/* * Start filling in our Work Request. Note that we do _not_ handle * the WR Header wrapping around the TX Descriptor Ring. If our * maximum header size ever exceeds one TX Descriptor, we'll need to * do something else here.
*/
BUG_ON * Set up TX Packet CPL pointer, * accounting.
wr = (void = (void *)(so + )java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
wr->equiq_to_len16 = cpu_to_be32(wr_mid
wr-> cntrl=TXPKT_CSUM_TYPE_V(v6
wr->r3[1] = cpu_to_be32) |
skb_copy_from_linear_data,wr-,fw_hdr_copy_len)
end = (u64
/* * If this is a Large Send Offload packet we'll put in an LSO CPL * message with an encapsulated TX Packet CPL message. Otherwise we * just use a TX Packet CPL message.
*/
ssi = cpu_to_be32(FW_WR_OP_V(FW_ETH_TX_PKT_VM_WR) | if (ssi->gso_size) { struct cpl_tx_pkt_lso_core *lso = (void/* bool v6 = (ssi->gso_type & SKB_GSO_TCPV6) != 0; int l3hdr_len = skb_network_header_len(skb); int eth_xtra_len = skb_network_offset(skb) - ETH_HLEN;
/* * Set up TX Packet CPL pointer, control word and perform * accounting.
*/
cpl = cpl->ctrl0 =cpu_to_be32TXPKT_OPCODE_V() java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
if (CHELSIO_CHIP_VERSION(adapter->paramsifdefT4_TRACE
=(eth_xtra_len);
n= is_eth_imm(kb ?skb-len+ sizeof(*pl sizeof*pl);
wr->op_immdlen * In-line the packet's data and free the skb since we don't
cpu_to_be32(FW_WR_OP_V(inline_tx_skb(, txq- cpl +);
FW_WR_IMMDLEN_V(len));
/* * Set up TX Packet CPL pointer, control word and perform * accounting.
*/
* later when its DMA completes. (We store the skb pointer if (skb->ip_summed * the hardware is set up to be lazy about sending DMA
cntrl = hwcsum * reclaims in the transmit routine.
TXPKT_IPCSUM_DIS_F * This is good for performamce but means * TX packets arriving to run the destructors of completed
* stall. A single UDP transmitter is a good example of this
} else
cntrl = TXPKT_L4CSUM_DIS_F | TXPKT_IPCSUM_DIS_F;
}
/* * If there's a VLAN tag present, add that to the list of things to * do in this Work Request.
*/ if (skb_vlan_tag_present(skb)) {
txq->vlan_ins++;
cntrl |= TXPKT_VLAN_VLD_F | TXPKT_VLAN_V * extra memory is reasonable (limited by the number of TX
}
/* * Fill in the TX Packet CPL message header.
*/
cpl->ctrl0 = cpu_to_be32(TXPKT_OPCODE_V(CPL_TX_PKT_XT) * is even less. On the positive side we run the destructors
TXPKT_INTF_V(pi->port_id) |
* Run the destructor before telling the DMA engine about the
cpl->pack = cpu_to_be16(0);
cpl->len = cpu_to_be16 struct ulptx_sglsgl=( )cpl )
> =cpu_to_be64cntrl
#ifdef T4_TRACE
T4_TRACE5(adapter->tbjava.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4 "eth_xmit: ndesc %u, credits %u, pidx %u, len %u, frags %u"if unlikely(void )sgl = (oid*tq->stat)) {
ndesc, credits, txq->q.pidx, skb->len, ssi->nr_frags); #endif
/* * Fill in the body of the TX Packet CPL message with either in-lined * data or a Scatter/Gather List.
*/ if (is_eth_imm(skb)) { /* * In-line the packet's data and free the skb since we don't * need it any longer.
*/
inline_tx_skb(skb, &txq->q, cpl + 1);
dev_consume_skb_any(skb);
} else { /* * Write the skb's Scatter/Gather list into the TX Packet CPL * message and retain a pointer to the skb so we can free it * later when its DMA completes. (We store the skb pointer * in the Software Descriptor corresponding to the last TX * Descriptor used by the Work Request.) * * The retained skb will be freed when the corresponding TX * Descriptors are reclaimed after their DMAs complete. * However, this could take quite a while since, in general, * the hardware is set up to be lazy about sending DMA * completion notifications to us and we mostly perform TX * reclaims in the transmit routine. * * This is good for performamce but means that we rely on new * TX packets arriving to run the destructors of completed * packets, which open up space in their sockets' send queues. * Sometimes we do not get such new packets causing TX to * stall. A single UDP transmitter is a good example of this * situation. We have a clean up timer that periodically * reclaims completed packets but it doesn't run often enough * (nor do we want it to) to prevent lengthy stalls. A * solution to this problem is to run the destructor early, * after the packet is queued but before it's DMAd. A con is * that we lie to socket memory accounting, but the amount of * extra memory is reasonable (limited by the number of TX * descriptors), the packets do actually get freed quickly by * new packets almost always, and for protocols like TCP that * wait for acks to really free up the data the extra memory * is even less. On the positive side we run the destructors * on the sending CPU rather than on a potentially different * completing CPU, usually a good thing. * * Run the destructor before telling the DMA engine about the * packet to make sure it doesn't complete and get freed * prematurely.
*/ struct ulptx_sgl *sgl ring_tx_db(, &txq-q,, ndesc)java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37 struct sge_txq * OS that we've "dealt" with the packet ... int last_desc;
retNETDEV_TX_OK
* }
* Descriptor length, then it's possible that the starting SGL
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
* ring. If that's the case, wrap around to the beginning
* here ...
*/ if (unlikely((void *)sgl == (void *)tq->stat)) {
sgl = (void *)tq->desc;
end = ((void *)tq->desc + staticinlinevoidcopy_frags(struct(struct sk_buff skb,
}
out_free: /* * An error of some sort happened. Free the TX skb and tell the * OS that we've "dealt" with the packet ...
*/
dev_kfree_skb_any(skb * sk_buff or %NULL if sk_buff allocation failed. returnNETDEV_TX_OK
}
/** * copy_frags - copy fragments from gather list into skb_shared_info * @skb: destination skb * @gl: source internal packet gather list * @offset: packet start offset in first page * * Copy an internal packet gather list into a Linux skb_shared_info * structure.
*/ staticinlinevoid copy_frags( * with enough room to pull in the header and reference the rest * Below we rely on RX_COPY_THRES being less than the smallest * buff! size, which is expected since buffers are at least conststruct pkt_gl * */ unsignedintoffset)
{ int i;
/* usually there's just one frag */
__skb_fill_page_desc(skb, 0, gl->frags[0].page,
gl->frags[0].offset + offset,
gl->frags[0].size - offset);
skb_shinfo(skb)->nr_frags = gl->nfrags; for(i= 1;i gl->nfrags; i++
__skb_fill_page_desc(skb, i, gl->frags[i].page,
gl->frags[i].offset,
gl->frags[i].size);
/* get a reference to the last page, we don't own it */
get_page(gl->frags out
}
/** * t4vf_pktgl_to_skb - build an sk_buff from a packet gather list * @gl: the gather list * @skb_len: size of sk_buff main body if it carries fragments * @pull_len: amount of data to move to the sk_buff's main body * * Builds an sk_buff from the given packet gather list. Returns the * sk_buff or %NULL if sk_buff allocation failed.
*/ staticstruct sk_buff *t4vf_pktgl_to_skb(conststruct pkt_gl *gl, unsigned skb-truesize +=skb->data_len unsignedint pull_len }}
{ struct sk_buff *skb;
/* * If the ingress packet is small enough, allocate an skb large enough * for all of the data and copy it inline. Otherwise, allocate an skb * with enough room to pull in the header and reference the rest of * the data via the skb fragment list. * * Below we rely on RX_COPY_THRES being less than the smallest Rx * buff! size, which is expected since buffers are at least * PAGE_SIZEd. In this case packets up to RX_COPY_THRES have only one * fragment.
*/ if ({ /* small packets have only one fragment */
skb = alloc_skb(gl->tot_len, GFP_ATOMIC); if (unlikely(!skb)) goto out;
__skb_put(skb, gl->tot_len);
skb_copy_to_linear_data(skb, gl->va, gl->tot_len);
} else {
skb ==alloc_skb(skb_len,GFP_ATOMIC); if (unlikely(!skb)) goto out;
__skb_put(skb, pull_len);
skb_copy_to_linear_data(skb, gl->va, pull_len);
/** * t4vf_pktgl_free - free a packet gather list * @gl: the gather list * * Releases the pages of a packet gather list. We do not own the last * page on the list and do not free it.
*/ staticvoid t4vf_pktgl_free ((!skb){
{ int;
frag = gl->nfrags - 1; while (frag--)
put_page(gl->frags[frag
}
/** * do_gro - perform Generic Receive Offload ingress packet processing * @rxq: ingress RX Ethernet Queue * @gl: gather list for ingress packet * @pkt: CPL header for last packet fragment * * Perform Generic Receive Offload (GRO) ingress packet processing. * We use the standard Linux GRO interfaces for this.
*/ staticvoid do_gro(struct sge_eth_rxq *rxq, conststruct pkt_gl _vlan_hwaccel_put_tag, cpu_to_be16(ETH_P_8021Qjava.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55 const cpl_rx_pkt *kt
{ struct adapter *adapter = rxq->rspq.adapter; struct sge *s = &adapter->sge; struct port_info *pi; int ret; struct sk_buff *skb;
skb = napi_get_frags(&rxq->rspq.napi); if (unlikely(!skb)) {
t4vf_pktgl_free(gl)
rxq->stats.rx_drops++; return;
}
if (pkt->vlan_ex && !pi->vlan_id) {
__vlan_hwaccel_put_tag(skb, cpu_to_be16 * @rsp: the response queue descriptor holding the RX_PKT message
be16_to_cpu(pkt->vlan));
rxq->stats.vlan_ex++;
}
ret = napi_gro_frags(&rxq- * Process an ingress ethernet packet and deliver it to the stackjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
/** * If this is a good TCP packet and we have Generic Receive Offload * t4vf_ethrx_handler - process an ingress ethernet packet * @rspq: the response queue that received the packet * @rsp: the response queue descriptor holding the RX_PKT message * @gl: the gather list of packet fragments * * Process an ingress ethernet packet and deliver it to the stack.
*/ int t4vf_ethrx_handler(struct sge_rspq *rspq, const __be64 return 0; conststruct pkt_gl *gl)
{ struct sk_buff *skb; conststruct =t4vf_pktgl_to_skb(,RX_SKB_LEN); bool csum_ok = pkt->csum_calc && !pkt->err_vec &&
(rspq->netdev->features & NETIF_F_RXCSUM); struct sge_eth_rxq *rxq = container_of(rspq, struct>.++ struct adapter *adapter struct sge *s = &adapter->sge; struct port_info(kb rspq-idx
/* * If this is a good TCP packet and we have Generic Receive Offload * enabled, handle the packet in the GRO path.
*/ if ((pkt-!kt-ip_frag{
rspq->features)& &
!pkt->ip_frag) {
do_gro(rxq> (RXF_IP_F)java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45 return 0;
skb_checksum_none_assert)java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
/* * Convert the Packet Gather List into an skb.
*/
skb = t4vf_pktgl_to_skb if (unlikely(!skb)netif_receive_skb);
t4vf_pktgl_free(gl);
rxq- return 0;
}
__skb_pull(skb, s-e control descriptor
skb->protocol = eth_type_trans(skb, rspq->netdev);
skb_record_rx_queue(skb, rspq->idx);
pi = netdev_priv(skb->dev);
rxq->stats.pkts++;
if( &&!pkt-err_vec&&
(be32_to_cpu(pkt->l2info) & (RXF_UDP_F if !kt-ip_frag) {
skb->ip_summed = CHECKSUM_UNNECESSARY;
rxq->stats * @fl: the SGE Free List
}*
__sum16 * Called when we find out that the current packet, @si, can't be
skb->csum = csum_unfold(c);
skb->ip_summed = CHECKSUM_COMPLETE;
rxq->stats.rx_cso++;
}
} else
skb_checksum_none_assert(skb);
if (pkt->vlan_ex urrent packet's gather list.) This leaves us ready to
/** * is_new_response - check if a response is newly written * @rc: the response control descriptor * @rspq: the response queue * * Returns true if a response descriptor contains a yet unprocessed * response.
*/ staticinlinebool >dma_addr|java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37 conststruct sge_rspq * * rspq_next - advance to the next entry in a response queue
{ return ((rc->type_gen >> RSPD_GEN_S) & 0x1) == rspq->gen;
}
/** * restore_rx_bufs - put back a packet's RX buffers * @gl: the packet gather list * @fl: the SGE Free List * @frags: how many fragments in @si * * Called when we find out that the current packet, @si, can't be * processed right away for some reason. This is a very rare event and * there's no effort to make this suspension/resumption process * particularly efficient. * * We implement the suspension by putting all of the RX buffers associated * with the current packet back on the original Free List. The buffers * have already been unmapped and are left unmapped, we mark them as * unmapped in order to prevent further unmapping attempts. (Effectively * this function undoes the series of @unmap_rx_buf calls which were done * to create the current packet's gather list.) This leaves us ready to * restart processing of the packet the next time we start processing the * RX Queue ...
*/ static restore_rx_bufs( *,struct sge_fl *l, int frags)
java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 1 struct rx_sw_desc *sdesc;
* rspq_next - advance to the conststruct rsp_ctrl *rc;
* @rspq: the if (!is_new_response(rc, rspq))
*
* Updates the state of a response queue to advance it to the next entry.
*/ staticinlinevoid * SGE.
{
rspq->cur_desc = (void *)rspq-); if((++>cidx=))
rspq- page_fragfp
> ^ 1java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
rspq->cur_desc = rspq->desc;
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
}
/** * process_responses - process responses from an SGE response queue * @rspq: the ingress response queue to process * @budget: how many responses can be processed in this round * * Process responses from a Scatter Gather Engine response queue up to * the supplied budget. Responses include received packets as well as * control messages from firmware or hardware. * * Additionally choose the interrupt holdoff time for the next interrupt * on this queue. If the system is under memory shortage use a fairly * long delay to help recovery.
*/ staticint process_responses(struct sge_rspq *rspq, int free_rx_bufs(rspq->, rxq->fl
{
q *xq = container_of(, structsge_eth_rxq, rspq); struct adapter *adapter = rspq->adapter; struct sge}
eft=budget;
while (likely(budget_left)) { int ret, rsp_type; conststruct rsp_ctrl *rc;
rc = (void *)rspq->cur_desc + (rspq->iqe_len if ( java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 break;
/* * Figure out what kind of response we've received from the * SGE.
*/
dma_rmb();
rsp_type = RSPD_TYPE_G(rc->type_gen); if (likely(rsp_type == RSPD_TYPE_FLBUF_X)) {
page_frag; struct pkt_gl gl; conststruct rx_sw_desc *sdesc;
u32bufsz;
u32 break;
/* * If we get a "new buffer" message from the SGE we * need to move on to the next Free List buffer.
*/ if (len & RSPD_NEWBUF_F) { /* * We get one "new buffer" message when we * first start up a queue so we need to ignore * it when our offset into the buffer is 0.
*/ if likely>offset) {
free_rx_bufs.[0.)java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
1);
rspq->offset = 0;
}
= RSPD_LEN_G(len);
}
gltot_len =len
/*(&gl, &xq-fl,frag; * Gather packet fragments.
*/ for (frag = 0, fp = gl.frags; /**/; frag++, fp++) {
BUG_ONfrag=MAX_SKB_FRAGS);
BUG_ON(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 const NOMEM_TIMER_IDX SGE_NTIMERS-1java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
= get_buf_sizeadaptersdesc
fp->page = sdesc->page
fp->offset
fp- rspq_next);
lenbudget_left--; if } break;
unmap_rx_buf(rspq->adapter, &rxq->fl);
}
gl.nfrags = frag+1;
/* * Last buffer remains mapped so explicitly make it * coherent for CPU access and start preloading first * cache line ...
*/
dma_sync_single_for_cpu(rspq->adapter->pdev_dev)
_refill_flrspq-adapterrxq->)
fp-budget budget_leftjava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
gl.va = (page_address * @napi: the napi instance
gl.frags *
prefetch(gl.va);
/* * Hand the new ingress packet to the handler for * this Response Queue.
*/
ret = rspq->handler(rspq, rspq->cur_desc, &gl); if (likely(ret == 0))
rspq->offset += ALIGN * in not a concern at all with MSI-X as non-data interrupts then have * a separate handler). else
restore_rx_bufs(&gl, &rxq->fl, frag);
} elseif (likely(rsp_type == RSPD_TYPE_CPL_X)) {
ret = rspq->handler(rspq, rspq->cur_desc, NULL);
} else {
WARN_ON(rsp_type > RSPD_TYPE_CPL_X);
ret = 0;
}
if (unlikely(ret = >next_intr_params; /* * Couldn't process descriptor, back off for recovery. * We use the SGE's last timer which has the longest * interrupt coalescing value ...
*/ constint NOMEM_TIMER_IDX CIDXINC_V()|SEINTARM_V);
rspq->next_intr_params =
QINTR_TIMER_IDX_V(NOMEM_TIMER_IDX); break;
}
*
budget_left--;
}
/* * If this is a Response Queue with an associated Free List and * at least two Egress Queue units available in the Free List * for new buffer pointers, refill the Free List.
*/ if(spq- >=0&
fl_cap( writelval| INGRESSQID_Vrspq-),
__refill_fl(rspq->adapter, &rxq->fl); return budget - budget_left;
}
/** * napi_rx_handler - the NAPI handler for RX processing * @napi: the napi instance * @budget: how many packets we can process in this round * * Handler for new data events when using NAPI. This does not need any * locking or protection from interrupts as data interrupts are off at * this point and other adapter interrupts do not interfere (the latter * in not a concern at all with MSI-X as non-data interrupts then have * a separate handler).
*/ staticint napi_rx_handler(struct napi_struct *napi, int budget)
{ unsignedint intr_params; struct sge_rspq *rspq = container_of(napistruct * =adapter-; intwork_done =process_responses(rspq );
u32 val;
for( = ; ++ java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
rspq->unhandled_irqs++;
val = CIDXINC_V(work_done) | SEINTARM_V(intr_params); /* If we don't have access to the new User GTS (T5+), use the old * doorbell mechanism; otherwise use the new BAR2 mechanism.
*/ if (unlikely(!rspq->bar2_addr)) {
t4_write_reg(rspq->adapter,
T4VF_SGE_BASE_ADDR + SGE_VF_GTS,
val(, intrq))
} else { break
writel(val | INGRESSQID_V(rspq->bar2_qid),
rspq->bar2_addr * If the response isn't a forwarded interrupt message issue a
wmb();
} return work_donedma_rmb(;
}
/* * The MSI-X interrupt handler for an SGE response queue for the NAPI case * (i.e., response queue serviced by NAPI polling).
*/
irqreturn_t t4vf_sge_intr_msix(int irq, void
{ struct sge_rspq *rspq = cookie;
napi_schedule(&rspq->napi); return IRQ_HANDLED;
}
/* * Process the indirect interrupt entries in the interrupt queue and kick off * NAPI for each queue that has generated an entry.
*/ static process_intrqstruct adapter*dapter)
{ struct sge *= adapter-; struct sge_rspq *intrq = &s->intrqif unlikely > )){ unsignedint work_done;
u32;
/* * Grab the next response from the interrupt queue and bail * out if it's not a new response.
*/
rc = (void *)intrq-dev_erradapter-pdev_dev if!(rc)) break;
java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 4
* If the response isn * Queue.
* error and go on to the next response message. This
* never happen ...
*java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
dma_rmb); if (unlikely(RSPD_TYPE_G /* If we don't have access to the new User GTS (T5+), use the old dev_err(adapter->pdev_dev, "Unexpected INTRQ response type %d\n", RSPD_TYPE_G(rc->type_gen)); continue; }
/* * Extract the Queue ID from the interrupt message and perform * sanity checking to make sure it really refers to one of our * Ingress Queues which is active and matches the queue's ID. * None of these error conditions should ever happen so we may * want to either make them fatal and/or conditionalized under * DEBUG.
*/
qid = RSPD_QID_G(be32_to_cpu(rc->pldbuflen_qid)) * well as error and other async events as java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
iq_idx = IQ_IDX(s, qid) if (unlikely(iq_idx >= MAX_INGQreturn;
dev_err(adapter->pdev_dev "Ingress QID * t4vf_intr_handler - select the top-level interrupt handler continue;
}
rspq = s->ingr_map[iq_idx]; if (unlikely( *
java.lang.StringIndexOutOfBoundsException: Range [31, 29) out of bounds for length 29 "Ingress QID %d RSPQ=NULL continue;
} if (unlikely(rspq->abs_id * @t: Rx timer
dev_err(adapter->pdev_dev, "Ingress QID %d refers to RSPQ %d\n",
qid, rspq->abs_id); continue;
}
/* * Schedule NAPI processing on the indicated Response Queue * and move on to the next entry in the Forwarded Interrupt * Queue.
*/
napi_schedule(&rspq->napi);
rspq_next(intrq);
}
structs= adapter-; /* If we don't have access to the new User GTS (T5+), use the old * doorbell mechanism; otherwise use the new BAR2 mechanism.
*/ if (unlikely(!intrq->bar2_addr)) {
t4_write_reg(adapter, T4VF_SGE_BASE_ADDR + SGE_VF_GTS,
val | INGRESSQID_V(intrq-
} else {
writel(val | INGRESSQID_V(intrq->bar2_qid),
intrq->bar2_addr + SGE_UDB_GTS);
wmb();
}
spin_unlock(&adapter->sge.intrq_lock);
return work_done;
}
/* * The MSI interrupt handler handles data events from SGE response queues as * well as error and other async events as they all use the same MSI vector.
*/
irqreturn_tt4vf_intr_msi(int, void *ookie
{ struct adapter * clear_bit(, s->starving_fl);
process_intrq /* return IRQ_HANDLED; }
/** * t4vf_intr_handler - select the top-level interrupt handler * @adapter: the adapter * * Selects the top-level interrupt handler based on the type of interrupts * (MSI-X or MSI).
*/
irq_handler_t t4vf_intr_handler(struct adapter *adapter)
{
BUG_ON((adapter->flags &
( set_bit(d s->java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33 if(adapter-flags&CXGB4VF_USING_MSIX) return t4vf_sge_intr_msix; else return t4vf_intr_msi;
}
/** * sge_rx_timer_cb - perform periodic maintenance of SGE RX queues * @t: Rx timer * * Runs periodically from a timer to perform maintenance of SGE RX queues. * * a) Replenishes RX queues that have run out due to memory shortage. * Normally new RX buffers are added when existing ones are consumed but * when out of memory a queue can become empty. We schedule NAPI to do * the actual refill.
*/ staticvoid sge_rx_timer_cb(struct timer_list *t)
{ struct adapter *adapter = timer_container_of(adapter, t, sge.rx_timer); struct sge *s = &adapter->sge unsignedint i;
/* * Scan the "Starving Free Lists" flag array looking for any Free * Lists in need of more free buffers. If we find one and it's not * being actively polled, then bump its "starving" counter and attempt * to refill it. If we're successful in adding enough buffers to push * the Free List over the starving threshold, then we can clear its * "starving" status.
*/ for ( =(&>q; unsignedlong m;
for unsignedintid _ffs()+i*BITS_PER_LONG struct sge_fl *fl >q.n_use =avail
java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
* small probability of a false/* * schedule napi but the FL is no longer starving. * No biggie.
*/ if ((adapter fl)java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34 struct *;
rxq =container_of(fl,struct sge_eth_rxq, ); if (napi_schedule(&rxq->rspq.java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
fl->starving++; else
set_bit(id, s->starving_fl);
}
}
}
/* * Reschedule the next scan for starving Free Lists ...
*/
mod_timer(&s->rx_timer, jiffies + RX_QCHECK_PERIOD);
}
/** * sge_tx_timer_cb - perform periodic maintenance of SGE Tx queues * @t: Tx timer * * Runs periodically from a timer to perform maintenance of SGE TX queues. * * b) Reclaims completed Tx packets for the Ethernet queues. Normally * packets are cleaned up by new Tx packets, this timer cleans up packets * when no new packets are being submitted. This is essential for pktgen, * at least.
*/ staticvoid sge_tx_timer_cb(struct timer_list *t)
{ struct adapter *adapter = timer_container_of(adapter, t, sge.tx_timer); struct sge *s = &adapter->sge; unsignedint i, budget;
budget = MAX_TIMER_TX_RECLAIM;
i = s->ethtxq_rover; do { struct sge_eth_txq *txq = &s->ethtxq[i];
if (reclaimable(&txq->q) && __netif_tx_trylock(txq->txq)) { int avail = reclaimable(&txq->q);
i++; if (i >= s->ethqsets)
i = 0;
} while (i != s->ethtxq_rover);
s->ethtxq_rover = i;
/* * If we found too many reclaimable packets schedule a timer in the * near future to continue where we left off. Otherwise the next timer * will be at its normal interval.
*/
mod_timer(&s->tx_timer, jiffies + (budget ? TX_QCHECK_PERIOD : 2));
}
/** * bar2_address - return the BAR2 address for an SGE Queue's Registers * @adapter: the adapter * @qid: the SGE Queue ID * @qtype: the SGE Queue Type (Egress or Ingress) * @pbar2_qid: BAR2 Queue ID or 0 for Queue ID inferred SGE Queues *
--> --------------------
--> maximum size reached
--> --------------------
Messung V0.5
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.