diff options
| author | Dimitris Michailidis <dm@chelsio.com> | 2010-04-01 11:28:24 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2010-04-01 22:29:15 -0400 |
| commit | fd3a47900b6f9fa72a4074ecb630f9dae62f1a95 (patch) | |
| tree | 31936b85f82a198efb103a173b9e776753ad4678 | |
| parent | 56d36be4dd5fc7b33bff7986737aff79c790184a (diff) | |
cxgb4: Add packet queues and packet DMA code
Signed-off-by: Dimitris Michailidis <dm@chelsio.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
| -rw-r--r-- | drivers/net/cxgb4/sge.c | 2431 |
1 files changed, 2431 insertions, 0 deletions
diff --git a/drivers/net/cxgb4/sge.c b/drivers/net/cxgb4/sge.c new file mode 100644 index 000000000000..14adc58e71c3 --- /dev/null +++ b/drivers/net/cxgb4/sge.c | |||
| @@ -0,0 +1,2431 @@ | |||
| 1 | /* | ||
| 2 | * This file is part of the Chelsio T4 Ethernet driver for Linux. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2003-2010 Chelsio Communications, Inc. All rights reserved. | ||
| 5 | * | ||
| 6 | * This software is available to you under a choice of one of two | ||
| 7 | * licenses. You may choose to be licensed under the terms of the GNU | ||
| 8 | * General Public License (GPL) Version 2, available from the file | ||
| 9 | * COPYING in the main directory of this source tree, or the | ||
| 10 | * OpenIB.org BSD license below: | ||
| 11 | * | ||
| 12 | * Redistribution and use in source and binary forms, with or | ||
| 13 | * without modification, are permitted provided that the following | ||
| 14 | * conditions are met: | ||
| 15 | * | ||
| 16 | * - Redistributions of source code must retain the above | ||
| 17 | * copyright notice, this list of conditions and the following | ||
| 18 | * disclaimer. | ||
| 19 | * | ||
| 20 | * - Redistributions in binary form must reproduce the above | ||
| 21 | * copyright notice, this list of conditions and the following | ||
| 22 | * disclaimer in the documentation and/or other materials | ||
| 23 | * provided with the distribution. | ||
| 24 | * | ||
| 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
| 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
| 29 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
| 30 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 31 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| 32 | * SOFTWARE. | ||
| 33 | */ | ||
| 34 | |||
| 35 | #include <linux/skbuff.h> | ||
| 36 | #include <linux/netdevice.h> | ||
| 37 | #include <linux/etherdevice.h> | ||
| 38 | #include <linux/if_vlan.h> | ||
| 39 | #include <linux/ip.h> | ||
| 40 | #include <linux/dma-mapping.h> | ||
| 41 | #include <linux/jiffies.h> | ||
| 42 | #include <net/ipv6.h> | ||
| 43 | #include <net/tcp.h> | ||
| 44 | #include "cxgb4.h" | ||
| 45 | #include "t4_regs.h" | ||
| 46 | #include "t4_msg.h" | ||
| 47 | #include "t4fw_api.h" | ||
| 48 | |||
| 49 | /* | ||
| 50 | * Rx buffer size. We use largish buffers if possible but settle for single | ||
| 51 | * pages under memory shortage. | ||
| 52 | */ | ||
| 53 | #if PAGE_SHIFT >= 16 | ||
| 54 | # define FL_PG_ORDER 0 | ||
| 55 | #else | ||
| 56 | # define FL_PG_ORDER (16 - PAGE_SHIFT) | ||
| 57 | #endif | ||
| 58 | |||
| 59 | /* RX_PULL_LEN should be <= RX_COPY_THRES */ | ||
| 60 | #define RX_COPY_THRES 256 | ||
| 61 | #define RX_PULL_LEN 128 | ||
| 62 | |||
| 63 | /* | ||
| 64 | * Main body length for sk_buffs used for Rx Ethernet packets with fragments. | ||
| 65 | * Should be >= RX_PULL_LEN but possibly bigger to give pskb_may_pull some room. | ||
| 66 | */ | ||
| 67 | #define RX_PKT_SKB_LEN 512 | ||
| 68 | |||
| 69 | /* Ethernet header padding prepended to RX_PKTs */ | ||
| 70 | #define RX_PKT_PAD 2 | ||
| 71 | |||
| 72 | /* | ||
| 73 | * Max number of Tx descriptors we clean up at a time. Should be modest as | ||
| 74 | * freeing skbs isn't cheap and it happens while holding locks. We just need | ||
| 75 | * to free packets faster than they arrive, we eventually catch up and keep | ||
| 76 | * the amortized cost reasonable. Must be >= 2 * TXQ_STOP_THRES. | ||
| 77 | */ | ||
| 78 | #define MAX_TX_RECLAIM 16 | ||
| 79 | |||
| 80 | /* | ||
| 81 | * Max number of Rx buffers we replenish at a time. Again keep this modest, | ||
| 82 | * allocating buffers isn't cheap either. | ||
| 83 | */ | ||
| 84 | #define MAX_RX_REFILL 16U | ||
| 85 | |||
| 86 | /* | ||
| 87 | * Period of the Rx queue check timer. This timer is infrequent as it has | ||
| 88 | * something to do only when the system experiences severe memory shortage. | ||
| 89 | */ | ||
| 90 | #define RX_QCHECK_PERIOD (HZ / 2) | ||
| 91 | |||
| 92 | /* | ||
| 93 | * Period of the Tx queue check timer. | ||
| 94 | */ | ||
| 95 | #define TX_QCHECK_PERIOD (HZ / 2) | ||
| 96 | |||
| 97 | /* | ||
| 98 | * Max number of Tx descriptors to be reclaimed by the Tx timer. | ||
| 99 | */ | ||
| 100 | #define MAX_TIMER_TX_RECLAIM 100 | ||
| 101 | |||
| 102 | /* | ||
| 103 | * Timer index used when backing off due to memory shortage. | ||
| 104 | */ | ||
| 105 | #define NOMEM_TMR_IDX (SGE_NTIMERS - 1) | ||
| 106 | |||
| 107 | /* | ||
| 108 | * An FL with <= FL_STARVE_THRES buffers is starving and a periodic timer will | ||
| 109 | * attempt to refill it. | ||
| 110 | */ | ||
| 111 | #define FL_STARVE_THRES 4 | ||
| 112 | |||
| 113 | /* | ||
| 114 | * Suspend an Ethernet Tx queue with fewer available descriptors than this. | ||
| 115 | * This is the same as calc_tx_descs() for a TSO packet with | ||
| 116 | * nr_frags == MAX_SKB_FRAGS. | ||
| 117 | */ | ||
| 118 | #define ETHTXQ_STOP_THRES \ | ||
| 119 | (1 + DIV_ROUND_UP((3 * MAX_SKB_FRAGS) / 2 + (MAX_SKB_FRAGS & 1), 8)) | ||
| 120 | |||
| 121 | /* | ||
| 122 | * Suspension threshold for non-Ethernet Tx queues. We require enough room | ||
| 123 | * for a full sized WR. | ||
| 124 | */ | ||
| 125 | #define TXQ_STOP_THRES (SGE_MAX_WR_LEN / sizeof(struct tx_desc)) | ||
| 126 | |||
| 127 | /* | ||
| 128 | * Max Tx descriptor space we allow for an Ethernet packet to be inlined | ||
| 129 | * into a WR. | ||
| 130 | */ | ||
| 131 | #define MAX_IMM_TX_PKT_LEN 128 | ||
| 132 | |||
| 133 | /* | ||
| 134 | * Max size of a WR sent through a control Tx queue. | ||
| 135 | */ | ||
| 136 | #define MAX_CTRL_WR_LEN SGE_MAX_WR_LEN | ||
| 137 | |||
| 138 | enum { | ||
| 139 | /* packet alignment in FL buffers */ | ||
| 140 | FL_ALIGN = L1_CACHE_BYTES < 32 ? 32 : L1_CACHE_BYTES, | ||
| 141 | /* egress status entry size */ | ||
| 142 | STAT_LEN = L1_CACHE_BYTES > 64 ? 128 : 64 | ||
| 143 | }; | ||
| 144 | |||
| 145 | struct tx_sw_desc { /* SW state per Tx descriptor */ | ||
| 146 | struct sk_buff *skb; | ||
| 147 | struct ulptx_sgl *sgl; | ||
| 148 | }; | ||
| 149 | |||
| 150 | struct rx_sw_desc { /* SW state per Rx descriptor */ | ||
| 151 | struct page *page; | ||
| 152 | dma_addr_t dma_addr; | ||
| 153 | }; | ||
| 154 | |||
| 155 | /* | ||
| 156 | * The low bits of rx_sw_desc.dma_addr have special meaning. | ||
| 157 | */ | ||
| 158 | enum { | ||
| 159 | RX_LARGE_BUF = 1 << 0, /* buffer is larger than PAGE_SIZE */ | ||
| 160 | RX_UNMAPPED_BUF = 1 << 1, /* buffer is not mapped */ | ||
| 161 | }; | ||
| 162 | |||
| 163 | static inline dma_addr_t get_buf_addr(const struct rx_sw_desc *d) | ||
| 164 | { | ||
| 165 | return d->dma_addr & ~(dma_addr_t)(RX_LARGE_BUF | RX_UNMAPPED_BUF); | ||
| 166 | } | ||
| 167 | |||
| 168 | static inline bool is_buf_mapped(const struct rx_sw_desc *d) | ||
| 169 | { | ||
| 170 | return !(d->dma_addr & RX_UNMAPPED_BUF); | ||
| 171 | } | ||
| 172 | |||
| 173 | /** | ||
| 174 | * txq_avail - return the number of available slots in a Tx queue | ||
| 175 | * @q: the Tx queue | ||
| 176 | * | ||
| 177 | * Returns the number of descriptors in a Tx queue available to write new | ||
| 178 | * packets. | ||
| 179 | */ | ||
| 180 | static inline unsigned int txq_avail(const struct sge_txq *q) | ||
| 181 | { | ||
| 182 | return q->size - 1 - q->in_use; | ||
| 183 | } | ||
| 184 | |||
| 185 | /** | ||
| 186 | * fl_cap - return the capacity of a free-buffer list | ||
| 187 | * @fl: the FL | ||
| 188 | * | ||
| 189 | * Returns the capacity of a free-buffer list. The capacity is less than | ||
| 190 | * the size because one descriptor needs to be left unpopulated, otherwise | ||
| 191 | * HW will think the FL is empty. | ||
| 192 | */ | ||
| 193 | static inline unsigned int fl_cap(const struct sge_fl *fl) | ||
| 194 | { | ||
| 195 | return fl->size - 8; /* 1 descriptor = 8 buffers */ | ||
| 196 | } | ||
| 197 | |||
| 198 | static inline bool fl_starving(const struct sge_fl *fl) | ||
| 199 | { | ||
| 200 | return fl->avail - fl->pend_cred <= FL_STARVE_THRES; | ||
| 201 | } | ||
| 202 | |||
| 203 | static int map_skb(struct device *dev, const struct sk_buff *skb, | ||
| 204 | dma_addr_t *addr) | ||
