Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the Chelsio T4 Ethernet driver for Linux. |
| 3 | * |
Anish Bhatt | ce100b8b | 2014-06-19 21:37:15 -0700 | [diff] [blame] | 4 | * Copyright (c) 2003-2014 Chelsio Communications, Inc. All rights reserved. |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 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> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 42 | #include <linux/prefetch.h> |
Paul Gortmaker | ee40fa0 | 2011-05-27 16:14:23 -0400 | [diff] [blame] | 43 | #include <linux/export.h> |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 44 | #include <net/ipv6.h> |
| 45 | #include <net/tcp.h> |
Hariprasad Shenai | 3a336cb | 2015-02-04 15:32:52 +0530 | [diff] [blame] | 46 | #ifdef CONFIG_NET_RX_BUSY_POLL |
| 47 | #include <net/busy_poll.h> |
| 48 | #endif /* CONFIG_NET_RX_BUSY_POLL */ |
Varun Prakash | 84a200b | 2015-03-24 19:14:46 +0530 | [diff] [blame] | 49 | #ifdef CONFIG_CHELSIO_T4_FCOE |
| 50 | #include <scsi/fc/fc_fcoe.h> |
| 51 | #endif /* CONFIG_CHELSIO_T4_FCOE */ |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 52 | #include "cxgb4.h" |
| 53 | #include "t4_regs.h" |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 54 | #include "t4_values.h" |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 55 | #include "t4_msg.h" |
| 56 | #include "t4fw_api.h" |
| 57 | |
| 58 | /* |
| 59 | * Rx buffer size. We use largish buffers if possible but settle for single |
| 60 | * pages under memory shortage. |
| 61 | */ |
| 62 | #if PAGE_SHIFT >= 16 |
| 63 | # define FL_PG_ORDER 0 |
| 64 | #else |
| 65 | # define FL_PG_ORDER (16 - PAGE_SHIFT) |
| 66 | #endif |
| 67 | |
| 68 | /* RX_PULL_LEN should be <= RX_COPY_THRES */ |
| 69 | #define RX_COPY_THRES 256 |
| 70 | #define RX_PULL_LEN 128 |
| 71 | |
| 72 | /* |
| 73 | * Main body length for sk_buffs used for Rx Ethernet packets with fragments. |
| 74 | * Should be >= RX_PULL_LEN but possibly bigger to give pskb_may_pull some room. |
| 75 | */ |
| 76 | #define RX_PKT_SKB_LEN 512 |
| 77 | |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 78 | /* |
| 79 | * Max number of Tx descriptors we clean up at a time. Should be modest as |
| 80 | * freeing skbs isn't cheap and it happens while holding locks. We just need |
| 81 | * to free packets faster than they arrive, we eventually catch up and keep |
| 82 | * the amortized cost reasonable. Must be >= 2 * TXQ_STOP_THRES. |
| 83 | */ |
| 84 | #define MAX_TX_RECLAIM 16 |
| 85 | |
| 86 | /* |
| 87 | * Max number of Rx buffers we replenish at a time. Again keep this modest, |
| 88 | * allocating buffers isn't cheap either. |
| 89 | */ |
| 90 | #define MAX_RX_REFILL 16U |
| 91 | |
| 92 | /* |
| 93 | * Period of the Rx queue check timer. This timer is infrequent as it has |
| 94 | * something to do only when the system experiences severe memory shortage. |
| 95 | */ |
| 96 | #define RX_QCHECK_PERIOD (HZ / 2) |
| 97 | |
| 98 | /* |
| 99 | * Period of the Tx queue check timer. |
| 100 | */ |
| 101 | #define TX_QCHECK_PERIOD (HZ / 2) |
| 102 | |
| 103 | /* |
| 104 | * Max number of Tx descriptors to be reclaimed by the Tx timer. |
| 105 | */ |
| 106 | #define MAX_TIMER_TX_RECLAIM 100 |
| 107 | |
| 108 | /* |
| 109 | * Timer index used when backing off due to memory shortage. |
| 110 | */ |
| 111 | #define NOMEM_TMR_IDX (SGE_NTIMERS - 1) |
| 112 | |
| 113 | /* |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 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 | */ |
Hariprasad Shenai | 21dcfad | 2015-04-15 02:02:30 +0530 | [diff] [blame] | 131 | #define MAX_IMM_TX_PKT_LEN 256 |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 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 | |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 138 | struct tx_sw_desc { /* SW state per Tx descriptor */ |
| 139 | struct sk_buff *skb; |
| 140 | struct ulptx_sgl *sgl; |
| 141 | }; |
| 142 | |
| 143 | struct rx_sw_desc { /* SW state per Rx descriptor */ |
| 144 | struct page *page; |
| 145 | dma_addr_t dma_addr; |
| 146 | }; |
| 147 | |
| 148 | /* |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 149 | * Rx buffer sizes for "useskbs" Free List buffers (one ingress packet pe skb |
| 150 | * buffer). We currently only support two sizes for 1500- and 9000-byte MTUs. |
| 151 | * We could easily support more but there doesn't seem to be much need for |
| 152 | * that ... |
| 153 | */ |
| 154 | #define FL_MTU_SMALL 1500 |
| 155 | #define FL_MTU_LARGE 9000 |
| 156 | |
| 157 | static inline unsigned int fl_mtu_bufsize(struct adapter *adapter, |
| 158 | unsigned int mtu) |
| 159 | { |
| 160 | struct sge *s = &adapter->sge; |
| 161 | |
| 162 | return ALIGN(s->pktshift + ETH_HLEN + VLAN_HLEN + mtu, s->fl_align); |
| 163 | } |
| 164 | |
| 165 | #define FL_MTU_SMALL_BUFSIZE(adapter) fl_mtu_bufsize(adapter, FL_MTU_SMALL) |
| 166 | #define FL_MTU_LARGE_BUFSIZE(adapter) fl_mtu_bufsize(adapter, FL_MTU_LARGE) |
| 167 | |
| 168 | /* |
| 169 | * Bits 0..3 of rx_sw_desc.dma_addr have special meaning. The hardware uses |
| 170 | * these to specify the buffer size as an index into the SGE Free List Buffer |
| 171 | * Size register array. We also use bit 4, when the buffer has been unmapped |
| 172 | * for DMA, but this is of course never sent to the hardware and is only used |
| 173 | * to prevent double unmappings. All of the above requires that the Free List |
| 174 | * Buffers which we allocate have the bottom 5 bits free (0) -- i.e. are |
| 175 | * 32-byte or or a power of 2 greater in alignment. Since the SGE's minimal |
| 176 | * Free List Buffer alignment is 32 bytes, this works out for us ... |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 177 | */ |
| 178 | enum { |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 179 | RX_BUF_FLAGS = 0x1f, /* bottom five bits are special */ |
| 180 | RX_BUF_SIZE = 0x0f, /* bottom three bits are for buf sizes */ |
| 181 | RX_UNMAPPED_BUF = 0x10, /* buffer is not mapped */ |
| 182 | |
| 183 | /* |
| 184 | * XXX We shouldn't depend on being able to use these indices. |
| 185 | * XXX Especially when some other Master PF has initialized the |
| 186 | * XXX adapter or we use the Firmware Configuration File. We |
| 187 | * XXX should really search through the Host Buffer Size register |
| 188 | * XXX array for the appropriately sized buffer indices. |
| 189 | */ |
| 190 | RX_SMALL_PG_BUF = 0x0, /* small (PAGE_SIZE) page buffer */ |
| 191 | RX_LARGE_PG_BUF = 0x1, /* buffer large (FL_PG_ORDER) page buffer */ |
| 192 | |
| 193 | RX_SMALL_MTU_BUF = 0x2, /* small MTU buffer */ |
| 194 | RX_LARGE_MTU_BUF = 0x3, /* large MTU buffer */ |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 195 | }; |
| 196 | |
Hariprasad Shenai | e553ec3 | 2014-09-26 00:23:55 +0530 | [diff] [blame] | 197 | static int timer_pkt_quota[] = {1, 1, 2, 3, 4, 5}; |
| 198 | #define MIN_NAPI_WORK 1 |
| 199 | |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 200 | static inline dma_addr_t get_buf_addr(const struct rx_sw_desc *d) |
| 201 | { |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 202 | return d->dma_addr & ~(dma_addr_t)RX_BUF_FLAGS; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | static inline bool is_buf_mapped(const struct rx_sw_desc *d) |
| 206 | { |
| 207 | return !(d->dma_addr & RX_UNMAPPED_BUF); |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * txq_avail - return the number of available slots in a Tx queue |
| 212 | * @q: the Tx queue |
| 213 | * |
| 214 | * Returns the number of descriptors in a Tx queue available to write new |
| 215 | * packets. |
| 216 | */ |
| 217 | static inline unsigned int txq_avail(const struct sge_txq *q) |
| 218 | { |
| 219 | return q->size - 1 - q->in_use; |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * fl_cap - return the capacity of a free-buffer list |
| 224 | * @fl: the FL |
| 225 | * |
| 226 | * Returns the capacity of a free-buffer list. The capacity is less than |
| 227 | * the size because one descriptor needs to be left unpopulated, otherwise |
| 228 | * HW will think the FL is empty. |
| 229 | */ |
| 230 | static inline unsigned int fl_cap(const struct sge_fl *fl) |
| 231 | { |
| 232 | return fl->size - 8; /* 1 descriptor = 8 buffers */ |
| 233 | } |
| 234 | |
Hariprasad Shenai | c098b02 | 2015-04-15 02:02:31 +0530 | [diff] [blame] | 235 | /** |
| 236 | * fl_starving - return whether a Free List is starving. |
| 237 | * @adapter: pointer to the adapter |
| 238 | * @fl: the Free List |
| 239 | * |
| 240 | * Tests specified Free List to see whether the number of buffers |
| 241 | * available to the hardware has falled below our "starvation" |
| 242 | * threshold. |
| 243 | */ |
| 244 | static inline bool fl_starving(const struct adapter *adapter, |
| 245 | const struct sge_fl *fl) |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 246 | { |
Hariprasad Shenai | c098b02 | 2015-04-15 02:02:31 +0530 | [diff] [blame] | 247 | const struct sge *s = &adapter->sge; |
| 248 | |
| 249 | return fl->avail - fl->pend_cred <= s->fl_starve_thres; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | static int map_skb(struct device *dev, const struct sk_buff *skb, |
| 253 | dma_addr_t *addr) |
| 254 | { |
| 255 | const skb_frag_t *fp, *end; |
| 256 | const struct skb_shared_info *si; |
| 257 | |
| 258 | *addr = dma_map_single(dev, skb->data, skb_headlen(skb), DMA_TO_DEVICE); |
| 259 | if (dma_mapping_error(dev, *addr)) |
| 260 | goto out_err; |
| 261 | |
| 262 | si = skb_shinfo(skb); |
| 263 | end = &si->frags[si->nr_frags]; |
| 264 | |
| 265 | for (fp = si->frags; fp < end; fp++) { |
Ian Campbell | e91b0f2 | 2011-10-19 23:01:46 +0000 | [diff] [blame] | 266 | *++addr = skb_frag_dma_map(dev, fp, 0, skb_frag_size(fp), |
| 267 | DMA_TO_DEVICE); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 268 | if (dma_mapping_error(dev, *addr)) |
| 269 | goto unwind; |
| 270 | } |
| 271 | return 0; |
| 272 | |
| 273 | unwind: |
| 274 | while (fp-- > si->frags) |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 275 | dma_unmap_page(dev, *--addr, skb_frag_size(fp), DMA_TO_DEVICE); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 276 | |
| 277 | dma_unmap_single(dev, addr[-1], skb_headlen(skb), DMA_TO_DEVICE); |
| 278 | out_err: |
| 279 | return -ENOMEM; |
| 280 | } |
| 281 | |
| 282 | #ifdef CONFIG_NEED_DMA_MAP_STATE |
| 283 | static void unmap_skb(struct device *dev, const struct sk_buff *skb, |
| 284 | const dma_addr_t *addr) |
| 285 | { |
| 286 | const skb_frag_t *fp, *end; |
| 287 | const struct skb_shared_info *si; |
| 288 | |
| 289 | dma_unmap_single(dev, *addr++, skb_headlen(skb), DMA_TO_DEVICE); |
| 290 | |
| 291 | si = skb_shinfo(skb); |
| 292 | end = &si->frags[si->nr_frags]; |
| 293 | for (fp = si->frags; fp < end; fp++) |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 294 | dma_unmap_page(dev, *addr++, skb_frag_size(fp), DMA_TO_DEVICE); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | /** |
| 298 | * deferred_unmap_destructor - unmap a packet when it is freed |
| 299 | * @skb: the packet |
| 300 | * |
| 301 | * This is the packet destructor used for Tx packets that need to remain |
| 302 | * mapped until they are freed rather than until their Tx descriptors are |
| 303 | * freed. |
| 304 | */ |
| 305 | static void deferred_unmap_destructor(struct sk_buff *skb) |
| 306 | { |
| 307 | unmap_skb(skb->dev->dev.parent, skb, (dma_addr_t *)skb->head); |
| 308 | } |
| 309 | #endif |
| 310 | |
| 311 | static void unmap_sgl(struct device *dev, const struct sk_buff *skb, |
| 312 | const struct ulptx_sgl *sgl, const struct sge_txq *q) |
| 313 | { |
| 314 | const struct ulptx_sge_pair *p; |
| 315 | unsigned int nfrags = skb_shinfo(skb)->nr_frags; |
| 316 | |
| 317 | if (likely(skb_headlen(skb))) |
| 318 | dma_unmap_single(dev, be64_to_cpu(sgl->addr0), ntohl(sgl->len0), |
| 319 | DMA_TO_DEVICE); |
| 320 | else { |
| 321 | dma_unmap_page(dev, be64_to_cpu(sgl->addr0), ntohl(sgl->len0), |
| 322 | DMA_TO_DEVICE); |
| 323 | nfrags--; |
| 324 | } |
| 325 | |
| 326 | /* |
| 327 | * the complexity below is because of the possibility of a wrap-around |
| 328 | * in the middle of an SGL |
| 329 | */ |
| 330 | for (p = sgl->sge; nfrags >= 2; nfrags -= 2) { |
| 331 | if (likely((u8 *)(p + 1) <= (u8 *)q->stat)) { |
| 332 | unmap: dma_unmap_page(dev, be64_to_cpu(p->addr[0]), |
| 333 | ntohl(p->len[0]), DMA_TO_DEVICE); |
| 334 | dma_unmap_page(dev, be64_to_cpu(p->addr[1]), |
| 335 | ntohl(p->len[1]), DMA_TO_DEVICE); |
| 336 | p++; |
| 337 | } else if ((u8 *)p == (u8 *)q->stat) { |
| 338 | p = (const struct ulptx_sge_pair *)q->desc; |
| 339 | goto unmap; |
| 340 | } else if ((u8 *)p + 8 == (u8 *)q->stat) { |
| 341 | const __be64 *addr = (const __be64 *)q->desc; |
| 342 | |
| 343 | dma_unmap_page(dev, be64_to_cpu(addr[0]), |
| 344 | ntohl(p->len[0]), DMA_TO_DEVICE); |
| 345 | dma_unmap_page(dev, be64_to_cpu(addr[1]), |
| 346 | ntohl(p->len[1]), DMA_TO_DEVICE); |
| 347 | p = (const struct ulptx_sge_pair *)&addr[2]; |
| 348 | } else { |
| 349 | const __be64 *addr = (const __be64 *)q->desc; |
| 350 | |
| 351 | dma_unmap_page(dev, be64_to_cpu(p->addr[0]), |
| 352 | ntohl(p->len[0]), DMA_TO_DEVICE); |
| 353 | dma_unmap_page(dev, be64_to_cpu(addr[0]), |
| 354 | ntohl(p->len[1]), DMA_TO_DEVICE); |
| 355 | p = (const struct ulptx_sge_pair *)&addr[1]; |
| 356 | } |
| 357 | } |
| 358 | if (nfrags) { |
| 359 | __be64 addr; |
| 360 | |
| 361 | if ((u8 *)p == (u8 *)q->stat) |
| 362 | p = (const struct ulptx_sge_pair *)q->desc; |
| 363 | addr = (u8 *)p + 16 <= (u8 *)q->stat ? p->addr[0] : |
| 364 | *(const __be64 *)q->desc; |
| 365 | dma_unmap_page(dev, be64_to_cpu(addr), ntohl(p->len[0]), |
| 366 | DMA_TO_DEVICE); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * free_tx_desc - reclaims Tx descriptors and their buffers |
| 372 | * @adapter: the adapter |
| 373 | * @q: the Tx queue to reclaim descriptors from |
| 374 | * @n: the number of descriptors to reclaim |
| 375 | * @unmap: whether the buffers should be unmapped for DMA |
| 376 | * |
| 377 | * Reclaims Tx descriptors from an SGE Tx queue and frees the associated |
| 378 | * Tx buffers. Called with the Tx queue lock held. |
| 379 | */ |
| 380 | static void free_tx_desc(struct adapter *adap, struct sge_txq *q, |
| 381 | unsigned int n, bool unmap) |
| 382 | { |
| 383 | struct tx_sw_desc *d; |
| 384 | unsigned int cidx = q->cidx; |
| 385 | struct device *dev = adap->pdev_dev; |
| 386 | |
| 387 | d = &q->sdesc[cidx]; |
| 388 | while (n--) { |
| 389 | if (d->skb) { /* an SGL is present */ |
| 390 | if (unmap) |
| 391 | unmap_sgl(dev, d->skb, d->sgl, q); |
Eric W. Biederman | a752519 | 2014-03-15 16:29:49 -0700 | [diff] [blame] | 392 | dev_consume_skb_any(d->skb); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 393 | d->skb = NULL; |
| 394 | } |
| 395 | ++d; |
| 396 | if (++cidx == q->size) { |
| 397 | cidx = 0; |
| 398 | d = q->sdesc; |
| 399 | } |
| 400 | } |
| 401 | q->cidx = cidx; |
| 402 | } |
| 403 | |
| 404 | /* |
| 405 | * Return the number of reclaimable descriptors in a Tx queue. |
| 406 | */ |
| 407 | static inline int reclaimable(const struct sge_txq *q) |
| 408 | { |
Hariprasad Shenai | 632be19 | 2015-12-08 10:09:13 +0530 | [diff] [blame] | 409 | int hw_cidx = ntohs(ACCESS_ONCE(q->stat->cidx)); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 410 | hw_cidx -= q->cidx; |
| 411 | return hw_cidx < 0 ? hw_cidx + q->size : hw_cidx; |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * reclaim_completed_tx - reclaims completed Tx descriptors |
| 416 | * @adap: the adapter |
| 417 | * @q: the Tx queue to reclaim completed descriptors from |
| 418 | * @unmap: whether the buffers should be unmapped for DMA |
| 419 | * |
| 420 | * Reclaims Tx descriptors that the SGE has indicated it has processed, |
| 421 | * and frees the associated buffers if possible. Called with the Tx |
| 422 | * queue locked. |
| 423 | */ |
| 424 | static inline void reclaim_completed_tx(struct adapter *adap, struct sge_txq *q, |
| 425 | bool unmap) |
| 426 | { |
| 427 | int avail = reclaimable(q); |
| 428 | |
| 429 | if (avail) { |
| 430 | /* |
| 431 | * Limit the amount of clean up work we do at a time to keep |
| 432 | * the Tx lock hold time O(1). |
| 433 | */ |
| 434 | if (avail > MAX_TX_RECLAIM) |
| 435 | avail = MAX_TX_RECLAIM; |
| 436 | |
| 437 | free_tx_desc(adap, q, avail, unmap); |
| 438 | q->in_use -= avail; |
| 439 | } |
| 440 | } |
| 441 | |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 442 | static inline int get_buf_size(struct adapter *adapter, |
| 443 | const struct rx_sw_desc *d) |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 444 | { |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 445 | struct sge *s = &adapter->sge; |
| 446 | unsigned int rx_buf_size_idx = d->dma_addr & RX_BUF_SIZE; |
| 447 | int buf_size; |
| 448 | |
| 449 | switch (rx_buf_size_idx) { |
| 450 | case RX_SMALL_PG_BUF: |
| 451 | buf_size = PAGE_SIZE; |
| 452 | break; |
| 453 | |
| 454 | case RX_LARGE_PG_BUF: |
| 455 | buf_size = PAGE_SIZE << s->fl_pg_order; |
| 456 | break; |
| 457 | |
| 458 | case RX_SMALL_MTU_BUF: |
| 459 | buf_size = FL_MTU_SMALL_BUFSIZE(adapter); |
| 460 | break; |
| 461 | |
| 462 | case RX_LARGE_MTU_BUF: |
| 463 | buf_size = FL_MTU_LARGE_BUFSIZE(adapter); |
| 464 | break; |
| 465 | |
| 466 | default: |
| 467 | BUG_ON(1); |
| 468 | } |
| 469 | |
| 470 | return buf_size; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | /** |
| 474 | * free_rx_bufs - free the Rx buffers on an SGE free list |
| 475 | * @adap: the adapter |
| 476 | * @q: the SGE free list to free buffers from |
| 477 | * @n: how many buffers to free |
| 478 | * |
| 479 | * Release the next @n buffers on an SGE free-buffer Rx queue. The |
| 480 | * buffers must be made inaccessible to HW before calling this function. |
| 481 | */ |
| 482 | static void free_rx_bufs(struct adapter *adap, struct sge_fl *q, int n) |
| 483 | { |
| 484 | while (n--) { |
| 485 | struct rx_sw_desc *d = &q->sdesc[q->cidx]; |
| 486 | |
| 487 | if (is_buf_mapped(d)) |
| 488 | dma_unmap_page(adap->pdev_dev, get_buf_addr(d), |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 489 | get_buf_size(adap, d), |
| 490 | PCI_DMA_FROMDEVICE); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 491 | put_page(d->page); |
| 492 | d->page = NULL; |
| 493 | if (++q->cidx == q->size) |
| 494 | q->cidx = 0; |
| 495 | q->avail--; |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | /** |
| 500 | * unmap_rx_buf - unmap the current Rx buffer on an SGE free list |
| 501 | * @adap: the adapter |
| 502 | * @q: the SGE free list |
| 503 | * |
| 504 | * Unmap the current buffer on an SGE free-buffer Rx queue. The |
| 505 | * buffer must be made inaccessible to HW before calling this function. |
| 506 | * |
| 507 | * This is similar to @free_rx_bufs above but does not free the buffer. |
| 508 | * Do note that the FL still loses any further access to the buffer. |
| 509 | */ |
| 510 | static void unmap_rx_buf(struct adapter *adap, struct sge_fl *q) |
| 511 | { |
| 512 | struct rx_sw_desc *d = &q->sdesc[q->cidx]; |
| 513 | |
| 514 | if (is_buf_mapped(d)) |
| 515 | dma_unmap_page(adap->pdev_dev, get_buf_addr(d), |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 516 | get_buf_size(adap, d), PCI_DMA_FROMDEVICE); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 517 | d->page = NULL; |
| 518 | if (++q->cidx == q->size) |
| 519 | q->cidx = 0; |
| 520 | q->avail--; |
| 521 | } |
| 522 | |
| 523 | static inline void ring_fl_db(struct adapter *adap, struct sge_fl *q) |
| 524 | { |
| 525 | if (q->pend_cred >= 8) { |
Hariprasad Shenai | 3ccc6cf | 2015-06-02 13:59:39 +0530 | [diff] [blame] | 526 | u32 val = adap->params.arch.sge_fl_db; |
| 527 | |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 528 | if (is_t4(adap->params.chip)) |
Hariprasad Shenai | 3ccc6cf | 2015-06-02 13:59:39 +0530 | [diff] [blame] | 529 | val |= PIDX_V(q->pend_cred / 8); |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 530 | else |
Hariprasad Shenai | 3ccc6cf | 2015-06-02 13:59:39 +0530 | [diff] [blame] | 531 | val |= PIDX_T5_V(q->pend_cred / 8); |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 532 | |
| 533 | /* Make sure all memory writes to the Free List queue are |
| 534 | * committed before we tell the hardware about them. |
| 535 | */ |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 536 | wmb(); |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 537 | |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 538 | /* If we don't have access to the new User Doorbell (T5+), use |
| 539 | * the old doorbell mechanism; otherwise use the new BAR2 |
| 540 | * mechanism. |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 541 | */ |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 542 | if (unlikely(q->bar2_addr == NULL)) { |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 543 | t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A), |
| 544 | val | QID_V(q->cntxt_id)); |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 545 | } else { |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 546 | writel(val | QID_V(q->bar2_qid), |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 547 | q->bar2_addr + SGE_UDB_KDOORBELL); |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 548 | |
| 549 | /* This Write memory Barrier will force the write to |
| 550 | * the User Doorbell area to be flushed. |
| 551 | */ |
| 552 | wmb(); |
| 553 | } |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 554 | q->pend_cred &= 7; |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | static inline void set_rx_sw_desc(struct rx_sw_desc *sd, struct page *pg, |
| 559 | dma_addr_t mapping) |
| 560 | { |
| 561 | sd->page = pg; |
| 562 | sd->dma_addr = mapping; /* includes size low bits */ |
| 563 | } |
| 564 | |
| 565 | /** |
| 566 | * refill_fl - refill an SGE Rx buffer ring |
| 567 | * @adap: the adapter |
| 568 | * @q: the ring to refill |
| 569 | * @n: the number of new buffers to allocate |
| 570 | * @gfp: the gfp flags for the allocations |
| 571 | * |
| 572 | * (Re)populate an SGE free-buffer queue with up to @n new packet buffers, |
| 573 | * allocated with the supplied gfp flags. The caller must assure that |
| 574 | * @n does not exceed the queue's capacity. If afterwards the queue is |
| 575 | * found critically low mark it as starving in the bitmap of starving FLs. |
| 576 | * |
| 577 | * Returns the number of buffers allocated. |
| 578 | */ |
| 579 | static unsigned int refill_fl(struct adapter *adap, struct sge_fl *q, int n, |
| 580 | gfp_t gfp) |
| 581 | { |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 582 | struct sge *s = &adap->sge; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 583 | struct page *pg; |
| 584 | dma_addr_t mapping; |
| 585 | unsigned int cred = q->avail; |
| 586 | __be64 *d = &q->desc[q->pidx]; |
| 587 | struct rx_sw_desc *sd = &q->sdesc[q->pidx]; |
Hariprasad Shenai | d52ce92 | 2015-04-15 02:02:32 +0530 | [diff] [blame] | 588 | int node; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 589 | |
Hariprasad Shenai | 5b377d1 | 2015-05-27 22:30:23 +0530 | [diff] [blame] | 590 | #ifdef CONFIG_DEBUG_FS |
| 591 | if (test_bit(q->cntxt_id - adap->sge.egr_start, adap->sge.blocked_fl)) |
| 592 | goto out; |
| 593 | #endif |
| 594 | |
Alexander Duyck | aa9cd31 | 2014-11-11 09:26:42 -0800 | [diff] [blame] | 595 | gfp |= __GFP_NOWARN; |
Hariprasad Shenai | d52ce92 | 2015-04-15 02:02:32 +0530 | [diff] [blame] | 596 | node = dev_to_node(adap->pdev_dev); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 597 | |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 598 | if (s->fl_pg_order == 0) |
| 599 | goto alloc_small_pages; |
| 600 | |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 601 | /* |
| 602 | * Prefer large buffers |
| 603 | */ |
| 604 | while (n) { |
Hariprasad Shenai | d52ce92 | 2015-04-15 02:02:32 +0530 | [diff] [blame] | 605 | pg = alloc_pages_node(node, gfp | __GFP_COMP, s->fl_pg_order); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 606 | if (unlikely(!pg)) { |
| 607 | q->large_alloc_failed++; |
| 608 | break; /* fall back to single pages */ |
| 609 | } |
| 610 | |
| 611 | mapping = dma_map_page(adap->pdev_dev, pg, 0, |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 612 | PAGE_SIZE << s->fl_pg_order, |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 613 | PCI_DMA_FROMDEVICE); |
| 614 | if (unlikely(dma_mapping_error(adap->pdev_dev, mapping))) { |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 615 | __free_pages(pg, s->fl_pg_order); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 616 | goto out; /* do not try small pages for this error */ |
| 617 | } |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 618 | mapping |= RX_LARGE_PG_BUF; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 619 | *d++ = cpu_to_be64(mapping); |
| 620 | |
| 621 | set_rx_sw_desc(sd, pg, mapping); |
| 622 | sd++; |
| 623 | |
| 624 | q->avail++; |
| 625 | if (++q->pidx == q->size) { |
| 626 | q->pidx = 0; |
| 627 | sd = q->sdesc; |
| 628 | d = q->desc; |
| 629 | } |
| 630 | n--; |
| 631 | } |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 632 | |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 633 | alloc_small_pages: |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 634 | while (n--) { |
Hariprasad Shenai | d52ce92 | 2015-04-15 02:02:32 +0530 | [diff] [blame] | 635 | pg = alloc_pages_node(node, gfp, 0); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 636 | if (unlikely(!pg)) { |
| 637 | q->alloc_failed++; |
| 638 | break; |
| 639 | } |
| 640 | |
| 641 | mapping = dma_map_page(adap->pdev_dev, pg, 0, PAGE_SIZE, |
| 642 | PCI_DMA_FROMDEVICE); |
| 643 | if (unlikely(dma_mapping_error(adap->pdev_dev, mapping))) { |
Eric Dumazet | 1f2149c | 2011-11-22 10:57:41 +0000 | [diff] [blame] | 644 | put_page(pg); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 645 | goto out; |
| 646 | } |
| 647 | *d++ = cpu_to_be64(mapping); |
| 648 | |
| 649 | set_rx_sw_desc(sd, pg, mapping); |
| 650 | sd++; |
| 651 | |
| 652 | q->avail++; |
| 653 | if (++q->pidx == q->size) { |
| 654 | q->pidx = 0; |
| 655 | sd = q->sdesc; |
| 656 | d = q->desc; |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | out: cred = q->avail - cred; |
| 661 | q->pend_cred += cred; |
| 662 | ring_fl_db(adap, q); |
| 663 | |
Hariprasad Shenai | c098b02 | 2015-04-15 02:02:31 +0530 | [diff] [blame] | 664 | if (unlikely(fl_starving(adap, q))) { |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 665 | smp_wmb(); |
Dimitris Michailidis | e46dab4 | 2010-08-23 17:20:58 +0000 | [diff] [blame] | 666 | set_bit(q->cntxt_id - adap->sge.egr_start, |
| 667 | adap->sge.starving_fl); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | return cred; |
| 671 | } |
| 672 | |
| 673 | static inline void __refill_fl(struct adapter *adap, struct sge_fl *fl) |
| 674 | { |
| 675 | refill_fl(adap, fl, min(MAX_RX_REFILL, fl_cap(fl) - fl->avail), |
| 676 | GFP_ATOMIC); |
| 677 | } |
| 678 | |
| 679 | /** |
| 680 | * alloc_ring - allocate resources for an SGE descriptor ring |
| 681 | * @dev: the PCI device's core device |
| 682 | * @nelem: the number of descriptors |
| 683 | * @elem_size: the size of each descriptor |
| 684 | * @sw_size: the size of the SW state associated with each ring element |
| 685 | * @phys: the physical address of the allocated ring |
| 686 | * @metadata: address of the array holding the SW state for the ring |
| 687 | * @stat_size: extra space in HW ring for status information |
Dimitris Michailidis | ad6bad3 | 2010-12-14 21:36:55 +0000 | [diff] [blame] | 688 | * @node: preferred node for memory allocations |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 689 | * |
| 690 | * Allocates resources for an SGE descriptor ring, such as Tx queues, |
| 691 | * free buffer lists, or response queues. Each SGE ring requires |
| 692 | * space for its HW descriptors plus, optionally, space for the SW state |
| 693 | * associated with each HW entry (the metadata). The function returns |
| 694 | * three values: the virtual address for the HW ring (the return value |
| 695 | * of the function), the bus address of the HW ring, and the address |
| 696 | * of the SW ring. |
| 697 | */ |
| 698 | static void *alloc_ring(struct device *dev, size_t nelem, size_t elem_size, |
| 699 | size_t sw_size, dma_addr_t *phys, void *metadata, |
Dimitris Michailidis | ad6bad3 | 2010-12-14 21:36:55 +0000 | [diff] [blame] | 700 | size_t stat_size, int node) |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 701 | { |
| 702 | size_t len = nelem * elem_size + stat_size; |
| 703 | void *s = NULL; |
| 704 | void *p = dma_alloc_coherent(dev, len, phys, GFP_KERNEL); |
| 705 | |
| 706 | if (!p) |
| 707 | return NULL; |
| 708 | if (sw_size) { |
Dimitris Michailidis | ad6bad3 | 2010-12-14 21:36:55 +0000 | [diff] [blame] | 709 | s = kzalloc_node(nelem * sw_size, GFP_KERNEL, node); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 710 | |
| 711 | if (!s) { |
| 712 | dma_free_coherent(dev, len, p, *phys); |
| 713 | return NULL; |
| 714 | } |
| 715 | } |
| 716 | if (metadata) |
| 717 | *(void **)metadata = s; |
| 718 | memset(p, 0, len); |
| 719 | return p; |
| 720 | } |
| 721 | |
| 722 | /** |
| 723 | * sgl_len - calculates the size of an SGL of the given capacity |
| 724 | * @n: the number of SGL entries |
| 725 | * |
| 726 | * Calculates the number of flits needed for a scatter/gather list that |
| 727 | * can hold the given number of entries. |
| 728 | */ |
| 729 | static inline unsigned int sgl_len(unsigned int n) |
| 730 | { |
Hariprasad Shenai | 0aac3f5 | 2015-04-15 02:02:33 +0530 | [diff] [blame] | 731 | /* A Direct Scatter Gather List uses 32-bit lengths and 64-bit PCI DMA |
| 732 | * addresses. The DSGL Work Request starts off with a 32-bit DSGL |
| 733 | * ULPTX header, then Length0, then Address0, then, for 1 <= i <= N, |
| 734 | * repeated sequences of { Length[i], Length[i+1], Address[i], |
| 735 | * Address[i+1] } (this ensures that all addresses are on 64-bit |
| 736 | * boundaries). If N is even, then Length[N+1] should be set to 0 and |
| 737 | * Address[N+1] is omitted. |
| 738 | * |
| 739 | * The following calculation incorporates all of the above. It's |
| 740 | * somewhat hard to follow but, briefly: the "+2" accounts for the |
| 741 | * first two flits which include the DSGL header, Length0 and |
| 742 | * Address0; the "(3*(n-1))/2" covers the main body of list entries (3 |
| 743 | * flits for every pair of the remaining N) +1 if (n-1) is odd; and |
| 744 | * finally the "+((n-1)&1)" adds the one remaining flit needed if |
| 745 | * (n-1) is odd ... |
| 746 | */ |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 747 | n--; |
| 748 | return (3 * n) / 2 + (n & 1) + 2; |
| 749 | } |
| 750 | |
| 751 | /** |
| 752 | * flits_to_desc - returns the num of Tx descriptors for the given flits |
| 753 | * @n: the number of flits |
| 754 | * |
| 755 | * Returns the number of Tx descriptors needed for the supplied number |
| 756 | * of flits. |
| 757 | */ |
| 758 | static inline unsigned int flits_to_desc(unsigned int n) |
| 759 | { |
| 760 | BUG_ON(n > SGE_MAX_WR_LEN / 8); |
| 761 | return DIV_ROUND_UP(n, 8); |
| 762 | } |
| 763 | |
| 764 | /** |
| 765 | * is_eth_imm - can an Ethernet packet be sent as immediate data? |
| 766 | * @skb: the packet |
| 767 | * |
| 768 | * Returns whether an Ethernet packet is small enough to fit as |
Kumar Sanghvi | 0034b29 | 2014-02-18 17:56:14 +0530 | [diff] [blame] | 769 | * immediate data. Return value corresponds to headroom required. |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 770 | */ |
| 771 | static inline int is_eth_imm(const struct sk_buff *skb) |
| 772 | { |
Kumar Sanghvi | 0034b29 | 2014-02-18 17:56:14 +0530 | [diff] [blame] | 773 | int hdrlen = skb_shinfo(skb)->gso_size ? |
| 774 | sizeof(struct cpl_tx_pkt_lso_core) : 0; |
| 775 | |
| 776 | hdrlen += sizeof(struct cpl_tx_pkt); |
| 777 | if (skb->len <= MAX_IMM_TX_PKT_LEN - hdrlen) |
| 778 | return hdrlen; |
| 779 | return 0; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | /** |
| 783 | * calc_tx_flits - calculate the number of flits for a packet Tx WR |
| 784 | * @skb: the packet |
| 785 | * |
| 786 | * Returns the number of flits needed for a Tx WR for the given Ethernet |
| 787 | * packet, including the needed WR and CPL headers. |
| 788 | */ |
| 789 | static inline unsigned int calc_tx_flits(const struct sk_buff *skb) |
| 790 | { |
| 791 | unsigned int flits; |
Kumar Sanghvi | 0034b29 | 2014-02-18 17:56:14 +0530 | [diff] [blame] | 792 | int hdrlen = is_eth_imm(skb); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 793 | |
Hariprasad Shenai | 0aac3f5 | 2015-04-15 02:02:33 +0530 | [diff] [blame] | 794 | /* If the skb is small enough, we can pump it out as a work request |
| 795 | * with only immediate data. In that case we just have to have the |
| 796 | * TX Packet header plus the skb data in the Work Request. |
| 797 | */ |
| 798 | |
Kumar Sanghvi | 0034b29 | 2014-02-18 17:56:14 +0530 | [diff] [blame] | 799 | if (hdrlen) |
| 800 | return DIV_ROUND_UP(skb->len + hdrlen, sizeof(__be64)); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 801 | |
Hariprasad Shenai | 0aac3f5 | 2015-04-15 02:02:33 +0530 | [diff] [blame] | 802 | /* Otherwise, we're going to have to construct a Scatter gather list |
| 803 | * of the skb body and fragments. We also include the flits necessary |
| 804 | * for the TX Packet Work Request and CPL. We always have a firmware |
| 805 | * Write Header (incorporated as part of the cpl_tx_pkt_lso and |
| 806 | * cpl_tx_pkt structures), followed by either a TX Packet Write CPL |
| 807 | * message or, if we're doing a Large Send Offload, an LSO CPL message |
| 808 | * with an embedded TX Packet Write CPL message. |
| 809 | */ |
Hariprasad Shenai | fd1754f | 2015-09-08 16:25:39 +0530 | [diff] [blame] | 810 | flits = sgl_len(skb_shinfo(skb)->nr_frags + 1); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 811 | if (skb_shinfo(skb)->gso_size) |
Hariprasad Shenai | 0aac3f5 | 2015-04-15 02:02:33 +0530 | [diff] [blame] | 812 | flits += (sizeof(struct fw_eth_tx_pkt_wr) + |
| 813 | sizeof(struct cpl_tx_pkt_lso_core) + |
| 814 | sizeof(struct cpl_tx_pkt_core)) / sizeof(__be64); |
| 815 | else |
| 816 | flits += (sizeof(struct fw_eth_tx_pkt_wr) + |
| 817 | sizeof(struct cpl_tx_pkt_core)) / sizeof(__be64); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 818 | return flits; |
| 819 | } |
| 820 | |
| 821 | /** |
| 822 | * calc_tx_descs - calculate the number of Tx descriptors for a packet |
| 823 | * @skb: the packet |
| 824 | * |
| 825 | * Returns the number of Tx descriptors needed for the given Ethernet |
| 826 | * packet, including the needed WR and CPL headers. |
| 827 | */ |
| 828 | static inline unsigned int calc_tx_descs(const struct sk_buff *skb) |
| 829 | { |
| 830 | return flits_to_desc(calc_tx_flits(skb)); |
| 831 | } |
| 832 | |
| 833 | /** |
| 834 | * write_sgl - populate a scatter/gather list for a packet |
| 835 | * @skb: the packet |
| 836 | * @q: the Tx queue we are writing into |
| 837 | * @sgl: starting location for writing the SGL |
| 838 | * @end: points right after the end of the SGL |
| 839 | * @start: start offset into skb main-body data to include in the SGL |
| 840 | * @addr: the list of bus addresses for the SGL elements |
| 841 | * |
| 842 | * Generates a gather list for the buffers that make up a packet. |
| 843 | * The caller must provide adequate space for the SGL that will be written. |
| 844 | * The SGL includes all of the packet's page fragments and the data in its |
| 845 | * main body except for the first @start bytes. @sgl must be 16-byte |
| 846 | * aligned and within a Tx descriptor with available space. @end points |
| 847 | * right after the end of the SGL but does not account for any potential |
| 848 | * wrap around, i.e., @end > @sgl. |
| 849 | */ |
| 850 | static void write_sgl(const struct sk_buff *skb, struct sge_txq *q, |
| 851 | struct ulptx_sgl *sgl, u64 *end, unsigned int start, |
| 852 | const dma_addr_t *addr) |
| 853 | { |
| 854 | unsigned int i, len; |
| 855 | struct ulptx_sge_pair *to; |
| 856 | const struct skb_shared_info *si = skb_shinfo(skb); |
| 857 | unsigned int nfrags = si->nr_frags; |
| 858 | struct ulptx_sge_pair buf[MAX_SKB_FRAGS / 2 + 1]; |
| 859 | |
| 860 | len = skb_headlen(skb) - start; |
| 861 | if (likely(len)) { |
| 862 | sgl->len0 = htonl(len); |
| 863 | sgl->addr0 = cpu_to_be64(addr[0] + start); |
| 864 | nfrags++; |
| 865 | } else { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 866 | sgl->len0 = htonl(skb_frag_size(&si->frags[0])); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 867 | sgl->addr0 = cpu_to_be64(addr[1]); |
| 868 | } |
| 869 | |
Hariprasad Shenai | bdc590b | 2015-01-08 21:38:16 -0800 | [diff] [blame] | 870 | sgl->cmd_nsge = htonl(ULPTX_CMD_V(ULP_TX_SC_DSGL) | |
| 871 | ULPTX_NSGE_V(nfrags)); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 872 | if (likely(--nfrags == 0)) |
| 873 | return; |
| 874 | /* |
| 875 | * Most of the complexity below deals with the possibility we hit the |
| 876 | * end of the queue in the middle of writing the SGL. For this case |
| 877 | * only we create the SGL in a temporary buffer and then copy it. |
| 878 | */ |
| 879 | to = (u8 *)end > (u8 *)q->stat ? buf : sgl->sge; |
| 880 | |
| 881 | for (i = (nfrags != si->nr_frags); nfrags >= 2; nfrags -= 2, to++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 882 | to->len[0] = cpu_to_be32(skb_frag_size(&si->frags[i])); |
| 883 | to->len[1] = cpu_to_be32(skb_frag_size(&si->frags[++i])); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 884 | to->addr[0] = cpu_to_be64(addr[i]); |
| 885 | to->addr[1] = cpu_to_be64(addr[++i]); |
| 886 | } |
| 887 | if (nfrags) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 888 | to->len[0] = cpu_to_be32(skb_frag_size(&si->frags[i])); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 889 | to->len[1] = cpu_to_be32(0); |
| 890 | to->addr[0] = cpu_to_be64(addr[i + 1]); |
| 891 | } |
| 892 | if (unlikely((u8 *)end > (u8 *)q->stat)) { |
| 893 | unsigned int part0 = (u8 *)q->stat - (u8 *)sgl->sge, part1; |
| 894 | |
| 895 | if (likely(part0)) |
| 896 | memcpy(sgl->sge, buf, part0); |
| 897 | part1 = (u8 *)end - (u8 *)q->stat; |
| 898 | memcpy(q->desc, (u8 *)buf + part0, part1); |
| 899 | end = (void *)q->desc + part1; |
| 900 | } |
| 901 | if ((uintptr_t)end & 8) /* 0-pad to multiple of 16 */ |
Joe Perches | 6469933 | 2012-06-04 12:44:16 +0000 | [diff] [blame] | 902 | *end = 0; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 903 | } |
| 904 | |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 905 | /* This function copies 64 byte coalesced work request to |
| 906 | * memory mapped BAR2 space. For coalesced WR SGE fetches |
| 907 | * data from the FIFO instead of from Host. |
Santosh Rastapur | 22adfe0 | 2013-03-14 05:08:51 +0000 | [diff] [blame] | 908 | */ |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 909 | static void cxgb_pio_copy(u64 __iomem *dst, u64 *src) |
Santosh Rastapur | 22adfe0 | 2013-03-14 05:08:51 +0000 | [diff] [blame] | 910 | { |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 911 | int count = 8; |
Santosh Rastapur | 22adfe0 | 2013-03-14 05:08:51 +0000 | [diff] [blame] | 912 | |
| 913 | while (count) { |
| 914 | writeq(*src, dst); |
| 915 | src++; |
| 916 | dst++; |
| 917 | count--; |
| 918 | } |
| 919 | } |
| 920 | |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 921 | /** |
| 922 | * ring_tx_db - check and potentially ring a Tx queue's doorbell |
| 923 | * @adap: the adapter |
| 924 | * @q: the Tx queue |
| 925 | * @n: number of new descriptors to give to HW |
| 926 | * |
| 927 | * Ring the doorbel for a Tx queue. |
| 928 | */ |
| 929 | static inline void ring_tx_db(struct adapter *adap, struct sge_txq *q, int n) |
| 930 | { |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 931 | /* Make sure that all writes to the TX Descriptors are committed |
| 932 | * before we tell the hardware about them. |
| 933 | */ |
| 934 | wmb(); |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 935 | |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 936 | /* If we don't have access to the new User Doorbell (T5+), use the old |
| 937 | * doorbell mechanism; otherwise use the new BAR2 mechanism. |
| 938 | */ |
| 939 | if (unlikely(q->bar2_addr == NULL)) { |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 940 | u32 val = PIDX_V(n); |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 941 | unsigned long flags; |
| 942 | |
| 943 | /* For T4 we need to participate in the Doorbell Recovery |
| 944 | * mechanism. |
| 945 | */ |
| 946 | spin_lock_irqsave(&q->db_lock, flags); |
| 947 | if (!q->db_disabled) |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 948 | t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A), |
| 949 | QID_V(q->cntxt_id) | val); |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 950 | else |
| 951 | q->db_pidx_inc += n; |
| 952 | q->db_pidx = q->pidx; |
| 953 | spin_unlock_irqrestore(&q->db_lock, flags); |
| 954 | } else { |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 955 | u32 val = PIDX_T5_V(n); |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 956 | |
| 957 | /* T4 and later chips share the same PIDX field offset within |
| 958 | * the doorbell, but T5 and later shrank the field in order to |
| 959 | * gain a bit for Doorbell Priority. The field was absurdly |
| 960 | * large in the first place (14 bits) so we just use the T5 |
| 961 | * and later limits and warn if a Queue ID is too large. |
| 962 | */ |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 963 | WARN_ON(val & DBPRIO_F); |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 964 | |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 965 | /* If we're only writing a single TX Descriptor and we can use |
| 966 | * Inferred QID registers, we can use the Write Combining |
| 967 | * Gather Buffer; otherwise we use the simple doorbell. |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 968 | */ |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 969 | if (n == 1 && q->bar2_qid == 0) { |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 970 | int index = (q->pidx |
| 971 | ? (q->pidx - 1) |
| 972 | : (q->size - 1)); |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 973 | u64 *wr = (u64 *)&q->desc[index]; |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 974 | |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 975 | cxgb_pio_copy((u64 __iomem *) |
| 976 | (q->bar2_addr + SGE_UDB_WCDOORBELL), |
| 977 | wr); |
Santosh Rastapur | 22adfe0 | 2013-03-14 05:08:51 +0000 | [diff] [blame] | 978 | } else { |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 979 | writel(val | QID_V(q->bar2_qid), |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 980 | q->bar2_addr + SGE_UDB_KDOORBELL); |
Santosh Rastapur | 22adfe0 | 2013-03-14 05:08:51 +0000 | [diff] [blame] | 981 | } |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 982 | |
| 983 | /* This Write Memory Barrier will force the write to the User |
| 984 | * Doorbell area to be flushed. This is needed to prevent |
| 985 | * writes on different CPUs for the same queue from hitting |
| 986 | * the adapter out of order. This is required when some Work |
| 987 | * Requests take the Write Combine Gather Buffer path (user |
| 988 | * doorbell area offset [SGE_UDB_WCDOORBELL..+63]) and some |
| 989 | * take the traditional path where we simply increment the |
| 990 | * PIDX (User Doorbell area SGE_UDB_KDOORBELL) and have the |
| 991 | * hardware DMA read the actual Work Request. |
| 992 | */ |
| 993 | wmb(); |
| 994 | } |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | /** |
| 998 | * inline_tx_skb - inline a packet's data into Tx descriptors |
| 999 | * @skb: the packet |
| 1000 | * @q: the Tx queue where the packet will be inlined |
| 1001 | * @pos: starting position in the Tx queue where to inline the packet |
| 1002 | * |
| 1003 | * Inline a packet's contents directly into Tx descriptors, starting at |
| 1004 | * the given position within the Tx DMA ring. |
| 1005 | * Most of the complexity of this operation is dealing with wrap arounds |
| 1006 | * in the middle of the packet we want to inline. |
| 1007 | */ |
| 1008 | static void inline_tx_skb(const struct sk_buff *skb, const struct sge_txq *q, |
| 1009 | void *pos) |
| 1010 | { |
| 1011 | u64 *p; |
| 1012 | int left = (void *)q->stat - pos; |
| 1013 | |
| 1014 | if (likely(skb->len <= left)) { |
| 1015 | if (likely(!skb->data_len)) |
| 1016 | skb_copy_from_linear_data(skb, pos, skb->len); |
| 1017 | else |
| 1018 | skb_copy_bits(skb, 0, pos, skb->len); |
| 1019 | pos += skb->len; |
| 1020 | } else { |
| 1021 | skb_copy_bits(skb, 0, pos, left); |
| 1022 | skb_copy_bits(skb, left, q->desc, skb->len - left); |
| 1023 | pos = (void *)q->desc + (skb->len - left); |
| 1024 | } |
| 1025 | |
| 1026 | /* 0-pad to multiple of 16 */ |
| 1027 | p = PTR_ALIGN(pos, 8); |
| 1028 | if ((uintptr_t)p & 8) |
| 1029 | *p = 0; |
| 1030 | } |
| 1031 | |
| 1032 | /* |
| 1033 | * Figure out what HW csum a packet wants and return the appropriate control |
| 1034 | * bits. |
| 1035 | */ |
Hariprasad Shenai | 3ccc6cf | 2015-06-02 13:59:39 +0530 | [diff] [blame] | 1036 | static u64 hwcsum(enum chip_type chip, const struct sk_buff *skb) |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1037 | { |
| 1038 | int csum_type; |
| 1039 | const struct iphdr *iph = ip_hdr(skb); |
| 1040 | |
| 1041 | if (iph->version == 4) { |
| 1042 | if (iph->protocol == IPPROTO_TCP) |
| 1043 | csum_type = TX_CSUM_TCPIP; |
| 1044 | else if (iph->protocol == IPPROTO_UDP) |
| 1045 | csum_type = TX_CSUM_UDPIP; |
| 1046 | else { |
| 1047 | nocsum: /* |
| 1048 | * unknown protocol, disable HW csum |
| 1049 | * and hope a bad packet is detected |
| 1050 | */ |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 1051 | return TXPKT_L4CSUM_DIS_F; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1052 | } |
| 1053 | } else { |
| 1054 | /* |
| 1055 | * this doesn't work with extension headers |
| 1056 | */ |
| 1057 | const struct ipv6hdr *ip6h = (const struct ipv6hdr *)iph; |
| 1058 | |
| 1059 | if (ip6h->nexthdr == IPPROTO_TCP) |
| 1060 | csum_type = TX_CSUM_TCPIP6; |
| 1061 | else if (ip6h->nexthdr == IPPROTO_UDP) |
| 1062 | csum_type = TX_CSUM_UDPIP6; |
| 1063 | else |
| 1064 | goto nocsum; |
| 1065 | } |
| 1066 | |
Hariprasad Shenai | 3ccc6cf | 2015-06-02 13:59:39 +0530 | [diff] [blame] | 1067 | if (likely(csum_type >= TX_CSUM_TCPIP)) { |
| 1068 | u64 hdr_len = TXPKT_IPHDR_LEN_V(skb_network_header_len(skb)); |
| 1069 | int eth_hdr_len = skb_network_offset(skb) - ETH_HLEN; |
| 1070 | |
| 1071 | if (CHELSIO_CHIP_VERSION(chip) <= CHELSIO_T5) |
| 1072 | hdr_len |= TXPKT_ETHHDR_LEN_V(eth_hdr_len); |
| 1073 | else |
| 1074 | hdr_len |= T6_TXPKT_ETHHDR_LEN_V(eth_hdr_len); |
| 1075 | return TXPKT_CSUM_TYPE_V(csum_type) | hdr_len; |
| 1076 | } else { |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1077 | int start = skb_transport_offset(skb); |
| 1078 | |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 1079 | return TXPKT_CSUM_TYPE_V(csum_type) | |
| 1080 | TXPKT_CSUM_START_V(start) | |
| 1081 | TXPKT_CSUM_LOC_V(start + skb->csum_offset); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | static void eth_txq_stop(struct sge_eth_txq *q) |
| 1086 | { |
| 1087 | netif_tx_stop_queue(q->txq); |
| 1088 | q->q.stops++; |
| 1089 | } |
| 1090 | |
| 1091 | static inline void txq_advance(struct sge_txq *q, unsigned int n) |
| 1092 | { |
| 1093 | q->in_use += n; |
| 1094 | q->pidx += n; |
| 1095 | if (q->pidx >= q->size) |
| 1096 | q->pidx -= q->size; |
| 1097 | } |
| 1098 | |
Varun Prakash | 84a200b | 2015-03-24 19:14:46 +0530 | [diff] [blame] | 1099 | #ifdef CONFIG_CHELSIO_T4_FCOE |
| 1100 | static inline int |
| 1101 | cxgb_fcoe_offload(struct sk_buff *skb, struct adapter *adap, |
| 1102 | const struct port_info *pi, u64 *cntrl) |
| 1103 | { |
| 1104 | const struct cxgb_fcoe *fcoe = &pi->fcoe; |
| 1105 | |
| 1106 | if (!(fcoe->flags & CXGB_FCOE_ENABLED)) |
| 1107 | return 0; |
| 1108 | |
| 1109 | if (skb->protocol != htons(ETH_P_FCOE)) |
| 1110 | return 0; |
| 1111 | |
| 1112 | skb_reset_mac_header(skb); |
| 1113 | skb->mac_len = sizeof(struct ethhdr); |
| 1114 | |
| 1115 | skb_set_network_header(skb, skb->mac_len); |
| 1116 | skb_set_transport_header(skb, skb->mac_len + sizeof(struct fcoe_hdr)); |
| 1117 | |
| 1118 | if (!cxgb_fcoe_sof_eof_supported(adap, skb)) |
| 1119 | return -ENOTSUPP; |
| 1120 | |
| 1121 | /* FC CRC offload */ |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 1122 | *cntrl = TXPKT_CSUM_TYPE_V(TX_CSUM_FCOE) | |
| 1123 | TXPKT_L4CSUM_DIS_F | TXPKT_IPCSUM_DIS_F | |
| 1124 | TXPKT_CSUM_START_V(CXGB_FCOE_TXPKT_CSUM_START) | |
| 1125 | TXPKT_CSUM_END_V(CXGB_FCOE_TXPKT_CSUM_END) | |
| 1126 | TXPKT_CSUM_LOC_V(CXGB_FCOE_TXPKT_CSUM_END); |
Varun Prakash | 84a200b | 2015-03-24 19:14:46 +0530 | [diff] [blame] | 1127 | return 0; |
| 1128 | } |
| 1129 | #endif /* CONFIG_CHELSIO_T4_FCOE */ |
| 1130 | |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1131 | /** |
| 1132 | * t4_eth_xmit - add a packet to an Ethernet Tx queue |
| 1133 | * @skb: the packet |
| 1134 | * @dev: the egress net device |
| 1135 | * |
| 1136 | * Add a packet to an SGE Ethernet Tx queue. Runs with softirqs disabled. |
| 1137 | */ |
| 1138 | netdev_tx_t t4_eth_xmit(struct sk_buff *skb, struct net_device *dev) |
| 1139 | { |
Anish Bhatt | 397665d | 2015-07-17 13:12:33 -0700 | [diff] [blame] | 1140 | u32 wr_mid, ctrl0; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1141 | u64 cntrl, *end; |
| 1142 | int qidx, credits; |
| 1143 | unsigned int flits, ndesc; |
| 1144 | struct adapter *adap; |
| 1145 | struct sge_eth_txq *q; |
| 1146 | const struct port_info *pi; |
| 1147 | struct fw_eth_tx_pkt_wr *wr; |
| 1148 | struct cpl_tx_pkt_core *cpl; |
| 1149 | const struct skb_shared_info *ssi; |
| 1150 | dma_addr_t addr[MAX_SKB_FRAGS + 1]; |
Kumar Sanghvi | 0034b29 | 2014-02-18 17:56:14 +0530 | [diff] [blame] | 1151 | bool immediate = false; |
Hariprasad Shenai | 637d3e9 | 2015-05-05 14:59:56 +0530 | [diff] [blame] | 1152 | int len, max_pkt_len; |
Varun Prakash | 84a200b | 2015-03-24 19:14:46 +0530 | [diff] [blame] | 1153 | #ifdef CONFIG_CHELSIO_T4_FCOE |
| 1154 | int err; |
| 1155 | #endif /* CONFIG_CHELSIO_T4_FCOE */ |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1156 | |
| 1157 | /* |
| 1158 | * The chip min packet length is 10 octets but play safe and reject |
| 1159 | * anything shorter than an Ethernet header. |
| 1160 | */ |
| 1161 | if (unlikely(skb->len < ETH_HLEN)) { |
Eric W. Biederman | a752519 | 2014-03-15 16:29:49 -0700 | [diff] [blame] | 1162 | out_free: dev_kfree_skb_any(skb); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1163 | return NETDEV_TX_OK; |
| 1164 | } |
| 1165 | |
Hariprasad Shenai | 637d3e9 | 2015-05-05 14:59:56 +0530 | [diff] [blame] | 1166 | /* Discard the packet if the length is greater than mtu */ |
| 1167 | max_pkt_len = ETH_HLEN + dev->mtu; |
| 1168 | if (skb_vlan_tag_present(skb)) |
| 1169 | max_pkt_len += VLAN_HLEN; |
| 1170 | if (!skb_shinfo(skb)->gso_size && (unlikely(skb->len > max_pkt_len))) |
| 1171 | goto out_free; |
| 1172 | |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1173 | pi = netdev_priv(dev); |
| 1174 | adap = pi->adapter; |
| 1175 | qidx = skb_get_queue_mapping(skb); |
| 1176 | q = &adap->sge.ethtxq[qidx + pi->first_qset]; |
| 1177 | |
| 1178 | reclaim_completed_tx(adap, &q->q, true); |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 1179 | cntrl = TXPKT_L4CSUM_DIS_F | TXPKT_IPCSUM_DIS_F; |
Varun Prakash | 84a200b | 2015-03-24 19:14:46 +0530 | [diff] [blame] | 1180 | |
| 1181 | #ifdef CONFIG_CHELSIO_T4_FCOE |
| 1182 | err = cxgb_fcoe_offload(skb, adap, pi, &cntrl); |
| 1183 | if (unlikely(err == -ENOTSUPP)) |
| 1184 | goto out_free; |
| 1185 | #endif /* CONFIG_CHELSIO_T4_FCOE */ |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1186 | |
| 1187 | flits = calc_tx_flits(skb); |
| 1188 | ndesc = flits_to_desc(flits); |
| 1189 | credits = txq_avail(&q->q) - ndesc; |
| 1190 | |
| 1191 | if (unlikely(credits < 0)) { |
| 1192 | eth_txq_stop(q); |
| 1193 | dev_err(adap->pdev_dev, |
| 1194 | "%s: Tx ring %u full while queue awake!\n", |
| 1195 | dev->name, qidx); |
| 1196 | return NETDEV_TX_BUSY; |
| 1197 | } |
| 1198 | |
Kumar Sanghvi | 0034b29 | 2014-02-18 17:56:14 +0530 | [diff] [blame] | 1199 | if (is_eth_imm(skb)) |
| 1200 | immediate = true; |
| 1201 | |
| 1202 | if (!immediate && |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1203 | unlikely(map_skb(adap->pdev_dev, skb, addr) < 0)) { |
| 1204 | q->mapping_err++; |
| 1205 | goto out_free; |
| 1206 | } |
| 1207 | |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 1208 | wr_mid = FW_WR_LEN16_V(DIV_ROUND_UP(flits, 2)); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1209 | if (unlikely(credits < ETHTXQ_STOP_THRES)) { |
| 1210 | eth_txq_stop(q); |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 1211 | wr_mid |= FW_WR_EQUEQ_F | FW_WR_EQUIQ_F; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | wr = (void *)&q->q.desc[q->q.pidx]; |
| 1215 | wr->equiq_to_len16 = htonl(wr_mid); |
| 1216 | wr->r3 = cpu_to_be64(0); |
| 1217 | end = (u64 *)wr + flits; |
| 1218 | |
Kumar Sanghvi | 0034b29 | 2014-02-18 17:56:14 +0530 | [diff] [blame] | 1219 | len = immediate ? skb->len : 0; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1220 | ssi = skb_shinfo(skb); |
| 1221 | if (ssi->gso_size) { |
Dimitris Michailidis | 625ac6a | 2010-08-02 13:19:18 +0000 | [diff] [blame] | 1222 | struct cpl_tx_pkt_lso *lso = (void *)wr; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1223 | bool v6 = (ssi->gso_type & SKB_GSO_TCPV6) != 0; |
| 1224 | int l3hdr_len = skb_network_header_len(skb); |
| 1225 | int eth_xtra_len = skb_network_offset(skb) - ETH_HLEN; |
| 1226 | |
Kumar Sanghvi | 0034b29 | 2014-02-18 17:56:14 +0530 | [diff] [blame] | 1227 | len += sizeof(*lso); |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 1228 | wr->op_immdlen = htonl(FW_WR_OP_V(FW_ETH_TX_PKT_WR) | |
| 1229 | FW_WR_IMMDLEN_V(len)); |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 1230 | lso->c.lso_ctrl = htonl(LSO_OPCODE_V(CPL_TX_PKT_LSO) | |
| 1231 | LSO_FIRST_SLICE_F | LSO_LAST_SLICE_F | |
| 1232 | LSO_IPV6_V(v6) | |
| 1233 | LSO_ETHHDR_LEN_V(eth_xtra_len / 4) | |
| 1234 | LSO_IPHDR_LEN_V(l3hdr_len / 4) | |
| 1235 | LSO_TCPHDR_LEN_V(tcp_hdr(skb)->doff)); |
Dimitris Michailidis | 625ac6a | 2010-08-02 13:19:18 +0000 | [diff] [blame] | 1236 | lso->c.ipid_ofst = htons(0); |
| 1237 | lso->c.mss = htons(ssi->gso_size); |
| 1238 | lso->c.seqno_offset = htonl(0); |
Hariprasad Shenai | 7207c0d | 2014-10-09 05:48:45 +0530 | [diff] [blame] | 1239 | if (is_t4(adap->params.chip)) |
| 1240 | lso->c.len = htonl(skb->len); |
| 1241 | else |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 1242 | lso->c.len = htonl(LSO_T5_XFER_SIZE_V(skb->len)); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1243 | cpl = (void *)(lso + 1); |
Hariprasad Shenai | 3ccc6cf | 2015-06-02 13:59:39 +0530 | [diff] [blame] | 1244 | |
| 1245 | if (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5) |
| 1246 | cntrl = TXPKT_ETHHDR_LEN_V(eth_xtra_len); |
| 1247 | else |
| 1248 | cntrl = T6_TXPKT_ETHHDR_LEN_V(eth_xtra_len); |
| 1249 | |
| 1250 | cntrl |= TXPKT_CSUM_TYPE_V(v6 ? |
| 1251 | TX_CSUM_TCPIP6 : TX_CSUM_TCPIP) | |
| 1252 | TXPKT_IPHDR_LEN_V(l3hdr_len); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1253 | q->tso++; |
| 1254 | q->tx_cso += ssi->gso_segs; |
| 1255 | } else { |
Kumar Sanghvi | ca71de6 | 2014-03-13 20:50:50 +0530 | [diff] [blame] | 1256 | len += sizeof(*cpl); |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 1257 | wr->op_immdlen = htonl(FW_WR_OP_V(FW_ETH_TX_PKT_WR) | |
| 1258 | FW_WR_IMMDLEN_V(len)); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1259 | cpl = (void *)(wr + 1); |
| 1260 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Hariprasad Shenai | 3ccc6cf | 2015-06-02 13:59:39 +0530 | [diff] [blame] | 1261 | cntrl = hwcsum(adap->params.chip, skb) | |
| 1262 | TXPKT_IPCSUM_DIS_F; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1263 | q->tx_cso++; |
Varun Prakash | 84a200b | 2015-03-24 19:14:46 +0530 | [diff] [blame] | 1264 | } |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1265 | } |
| 1266 | |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 1267 | if (skb_vlan_tag_present(skb)) { |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1268 | q->vlan_ins++; |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 1269 | cntrl |= TXPKT_VLAN_VLD_F | TXPKT_VLAN_V(skb_vlan_tag_get(skb)); |
Varun Prakash | 84a200b | 2015-03-24 19:14:46 +0530 | [diff] [blame] | 1270 | #ifdef CONFIG_CHELSIO_T4_FCOE |
| 1271 | if (skb->protocol == htons(ETH_P_FCOE)) |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 1272 | cntrl |= TXPKT_VLAN_V( |
Varun Prakash | 84a200b | 2015-03-24 19:14:46 +0530 | [diff] [blame] | 1273 | ((skb->priority & 0x7) << VLAN_PRIO_SHIFT)); |
| 1274 | #endif /* CONFIG_CHELSIO_T4_FCOE */ |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
Anish Bhatt | 397665d | 2015-07-17 13:12:33 -0700 | [diff] [blame] | 1277 | ctrl0 = TXPKT_OPCODE_V(CPL_TX_PKT_XT) | TXPKT_INTF_V(pi->tx_chan) | |
| 1278 | TXPKT_PF_V(adap->pf); |
| 1279 | #ifdef CONFIG_CHELSIO_T4_DCB |
| 1280 | if (is_t4(adap->params.chip)) |
| 1281 | ctrl0 |= TXPKT_OVLAN_IDX_V(q->dcb_prio); |
| 1282 | else |
| 1283 | ctrl0 |= TXPKT_T5_OVLAN_IDX_V(q->dcb_prio); |
| 1284 | #endif |
| 1285 | cpl->ctrl0 = htonl(ctrl0); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1286 | cpl->pack = htons(0); |
| 1287 | cpl->len = htons(skb->len); |
| 1288 | cpl->ctrl1 = cpu_to_be64(cntrl); |
| 1289 | |
Kumar Sanghvi | 0034b29 | 2014-02-18 17:56:14 +0530 | [diff] [blame] | 1290 | if (immediate) { |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1291 | inline_tx_skb(skb, &q->q, cpl + 1); |
Eric W. Biederman | a752519 | 2014-03-15 16:29:49 -0700 | [diff] [blame] | 1292 | dev_consume_skb_any(skb); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1293 | } else { |
| 1294 | int last_desc; |
| 1295 | |
| 1296 | write_sgl(skb, &q->q, (struct ulptx_sgl *)(cpl + 1), end, 0, |
| 1297 | addr); |
| 1298 | skb_orphan(skb); |
| 1299 | |
| 1300 | last_desc = q->q.pidx + ndesc - 1; |
| 1301 | if (last_desc >= q->q.size) |
| 1302 | last_desc -= q->q.size; |
| 1303 | q->q.sdesc[last_desc].skb = skb; |
| 1304 | q->q.sdesc[last_desc].sgl = (struct ulptx_sgl *)(cpl + 1); |
| 1305 | } |
| 1306 | |
| 1307 | txq_advance(&q->q, ndesc); |
| 1308 | |
| 1309 | ring_tx_db(adap, &q->q, ndesc); |
| 1310 | return NETDEV_TX_OK; |
| 1311 | } |
| 1312 | |
| 1313 | /** |
| 1314 | * reclaim_completed_tx_imm - reclaim completed control-queue Tx descs |
| 1315 | * @q: the SGE control Tx queue |
| 1316 | * |
| 1317 | * This is a variant of reclaim_completed_tx() that is used for Tx queues |
| 1318 | * that send only immediate data (presently just the control queues) and |
| 1319 | * thus do not have any sk_buffs to release. |
| 1320 | */ |
| 1321 | static inline void reclaim_completed_tx_imm(struct sge_txq *q) |
| 1322 | { |
Hariprasad Shenai | 632be19 | 2015-12-08 10:09:13 +0530 | [diff] [blame] | 1323 | int hw_cidx = ntohs(ACCESS_ONCE(q->stat->cidx)); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1324 | int reclaim = hw_cidx - q->cidx; |
| 1325 | |
| 1326 | if (reclaim < 0) |
| 1327 | reclaim += q->size; |
| 1328 | |
| 1329 | q->in_use -= reclaim; |
| 1330 | q->cidx = hw_cidx; |
| 1331 | } |
| 1332 | |
| 1333 | /** |
| 1334 | * is_imm - check whether a packet can be sent as immediate data |
| 1335 | * @skb: the packet |
| 1336 | * |
| 1337 | * Returns true if a packet can be sent as a WR with immediate data. |
| 1338 | */ |
| 1339 | static inline int is_imm(const struct sk_buff *skb) |
| 1340 | { |
| 1341 | return skb->len <= MAX_CTRL_WR_LEN; |
| 1342 | } |
| 1343 | |
| 1344 | /** |
| 1345 | * ctrlq_check_stop - check if a control queue is full and should stop |
| 1346 | * @q: the queue |
| 1347 | * @wr: most recent WR written to the queue |
| 1348 | * |
| 1349 | * Check if a control queue has become full and should be stopped. |
| 1350 | * We clean up control queue descriptors very lazily, only when we are out. |
| 1351 | * If the queue is still full after reclaiming any completed descriptors |
| 1352 | * we suspend it and have the last WR wake it up. |
| 1353 | */ |
| 1354 | static void ctrlq_check_stop(struct sge_ctrl_txq *q, struct fw_wr_hdr *wr) |
| 1355 | { |
| 1356 | reclaim_completed_tx_imm(&q->q); |
| 1357 | if (unlikely(txq_avail(&q->q) < TXQ_STOP_THRES)) { |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 1358 | wr->lo |= htonl(FW_WR_EQUEQ_F | FW_WR_EQUIQ_F); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1359 | q->q.stops++; |
| 1360 | q->full = 1; |
| 1361 | } |
| 1362 | } |
| 1363 | |
| 1364 | /** |
| 1365 | * ctrl_xmit - send a packet through an SGE control Tx queue |
| 1366 | * @q: the control queue |
| 1367 | * @skb: the packet |
| 1368 | * |
| 1369 | * Send a packet through an SGE control Tx queue. Packets sent through |
| 1370 | * a control queue must fit entirely as immediate data. |
| 1371 | */ |
| 1372 | static int ctrl_xmit(struct sge_ctrl_txq *q, struct sk_buff *skb) |
| 1373 | { |
| 1374 | unsigned int ndesc; |
| 1375 | struct fw_wr_hdr *wr; |
| 1376 | |
| 1377 | if (unlikely(!is_imm(skb))) { |
| 1378 | WARN_ON(1); |
| 1379 | dev_kfree_skb(skb); |
| 1380 | return NET_XMIT_DROP; |
| 1381 | } |
| 1382 | |
| 1383 | ndesc = DIV_ROUND_UP(skb->len, sizeof(struct tx_desc)); |
| 1384 | spin_lock(&q->sendq.lock); |
| 1385 | |
| 1386 | if (unlikely(q->full)) { |
| 1387 | skb->priority = ndesc; /* save for restart */ |
| 1388 | __skb_queue_tail(&q->sendq, skb); |
| 1389 | spin_unlock(&q->sendq.lock); |
| 1390 | return NET_XMIT_CN; |
| 1391 | } |
| 1392 | |
| 1393 | wr = (struct fw_wr_hdr *)&q->q.desc[q->q.pidx]; |
| 1394 | inline_tx_skb(skb, &q->q, wr); |
| 1395 | |
| 1396 | txq_advance(&q->q, ndesc); |
| 1397 | if (unlikely(txq_avail(&q->q) < TXQ_STOP_THRES)) |
| 1398 | ctrlq_check_stop(q, wr); |
| 1399 | |
| 1400 | ring_tx_db(q->adap, &q->q, ndesc); |
| 1401 | spin_unlock(&q->sendq.lock); |
| 1402 | |
| 1403 | kfree_skb(skb); |
| 1404 | return NET_XMIT_SUCCESS; |
| 1405 | } |
| 1406 | |
| 1407 | /** |
| 1408 | * restart_ctrlq - restart a suspended control queue |
| 1409 | * @data: the control queue to restart |
| 1410 | * |
| 1411 | * Resumes transmission on a suspended Tx control queue. |
| 1412 | */ |
| 1413 | static void restart_ctrlq(unsigned long data) |
| 1414 | { |
| 1415 | struct sk_buff *skb; |
| 1416 | unsigned int written = 0; |
| 1417 | struct sge_ctrl_txq *q = (struct sge_ctrl_txq *)data; |
| 1418 | |
| 1419 | spin_lock(&q->sendq.lock); |
| 1420 | reclaim_completed_tx_imm(&q->q); |
| 1421 | BUG_ON(txq_avail(&q->q) < TXQ_STOP_THRES); /* q should be empty */ |
| 1422 | |
| 1423 | while ((skb = __skb_dequeue(&q->sendq)) != NULL) { |
| 1424 | struct fw_wr_hdr *wr; |
| 1425 | unsigned int ndesc = skb->priority; /* previously saved */ |
| 1426 | |
Hariprasad Shenai | a4011fd | 2015-08-12 16:55:07 +0530 | [diff] [blame] | 1427 | written += ndesc; |
| 1428 | /* Write descriptors and free skbs outside the lock to limit |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1429 | * wait times. q->full is still set so new skbs will be queued. |
| 1430 | */ |
Hariprasad Shenai | a4011fd | 2015-08-12 16:55:07 +0530 | [diff] [blame] | 1431 | wr = (struct fw_wr_hdr *)&q->q.desc[q->q.pidx]; |
| 1432 | txq_advance(&q->q, ndesc); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1433 | spin_unlock(&q->sendq.lock); |
| 1434 | |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1435 | inline_tx_skb(skb, &q->q, wr); |
| 1436 | kfree_skb(skb); |
| 1437 | |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1438 | if (unlikely(txq_avail(&q->q) < TXQ_STOP_THRES)) { |
| 1439 | unsigned long old = q->q.stops; |
| 1440 | |
| 1441 | ctrlq_check_stop(q, wr); |
| 1442 | if (q->q.stops != old) { /* suspended anew */ |
| 1443 | spin_lock(&q->sendq.lock); |
| 1444 | goto ringdb; |
| 1445 | } |
| 1446 | } |
| 1447 | if (written > 16) { |
| 1448 | ring_tx_db(q->adap, &q->q, written); |
| 1449 | written = 0; |
| 1450 | } |
| 1451 | spin_lock(&q->sendq.lock); |
| 1452 | } |
| 1453 | q->full = 0; |
| 1454 | ringdb: if (written) |
| 1455 | ring_tx_db(q->adap, &q->q, written); |
| 1456 | spin_unlock(&q->sendq.lock); |
| 1457 | } |
| 1458 | |
| 1459 | /** |
| 1460 | * t4_mgmt_tx - send a management message |
| 1461 | * @adap: the adapter |
| 1462 | * @skb: the packet containing the management message |
| 1463 | * |
| 1464 | * Send a management message through control queue 0. |
| 1465 | */ |
| 1466 | int t4_mgmt_tx(struct adapter *adap, struct sk_buff *skb) |
| 1467 | { |
| 1468 | int ret; |
| 1469 | |
| 1470 | local_bh_disable(); |
| 1471 | ret = ctrl_xmit(&adap->sge.ctrlq[0], skb); |
| 1472 | local_bh_enable(); |
| 1473 | return ret; |
| 1474 | } |
| 1475 | |
| 1476 | /** |
| 1477 | * is_ofld_imm - check whether a packet can be sent as immediate data |
| 1478 | * @skb: the packet |
| 1479 | * |
| 1480 | * Returns true if a packet can be sent as an offload WR with immediate |
| 1481 | * data. We currently use the same limit as for Ethernet packets. |
| 1482 | */ |
| 1483 | static inline int is_ofld_imm(const struct sk_buff *skb) |
| 1484 | { |
| 1485 | return skb->len <= MAX_IMM_TX_PKT_LEN; |
| 1486 | } |
| 1487 | |
| 1488 | /** |
| 1489 | * calc_tx_flits_ofld - calculate # of flits for an offload packet |
| 1490 | * @skb: the packet |
| 1491 | * |
| 1492 | * Returns the number of flits needed for the given offload packet. |
| 1493 | * These packets are already fully constructed and no additional headers |
| 1494 | * will be added. |
| 1495 | */ |
| 1496 | static inline unsigned int calc_tx_flits_ofld(const struct sk_buff *skb) |
| 1497 | { |
| 1498 | unsigned int flits, cnt; |
| 1499 | |
| 1500 | if (is_ofld_imm(skb)) |
| 1501 | return DIV_ROUND_UP(skb->len, 8); |
| 1502 | |
| 1503 | flits = skb_transport_offset(skb) / 8U; /* headers */ |
| 1504 | cnt = skb_shinfo(skb)->nr_frags; |
Li RongQing | 15dd16c | 2013-06-03 22:11:16 +0000 | [diff] [blame] | 1505 | if (skb_tail_pointer(skb) != skb_transport_header(skb)) |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1506 | cnt++; |
| 1507 | return flits + sgl_len(cnt); |
| 1508 | } |
| 1509 | |
| 1510 | /** |
| 1511 | * txq_stop_maperr - stop a Tx queue due to I/O MMU exhaustion |
| 1512 | * @adap: the adapter |
| 1513 | * @q: the queue to stop |
| 1514 | * |
| 1515 | * Mark a Tx queue stopped due to I/O MMU exhaustion and resulting |
| 1516 | * inability to map packets. A periodic timer attempts to restart |
| 1517 | * queues so marked. |
| 1518 | */ |
| 1519 | static void txq_stop_maperr(struct sge_ofld_txq *q) |
| 1520 | { |
| 1521 | q->mapping_err++; |
| 1522 | q->q.stops++; |
Dimitris Michailidis | e46dab4 | 2010-08-23 17:20:58 +0000 | [diff] [blame] | 1523 | set_bit(q->q.cntxt_id - q->adap->sge.egr_start, |
| 1524 | q->adap->sge.txq_maperr); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | /** |
| 1528 | * ofldtxq_stop - stop an offload Tx queue that has become full |
| 1529 | * @q: the queue to stop |
| 1530 | * @skb: the packet causing the queue to become full |
| 1531 | * |
| 1532 | * Stops an offload Tx queue that has become full and modifies the packet |
| 1533 | * being written to request a wakeup. |
| 1534 | */ |
| 1535 | static void ofldtxq_stop(struct sge_ofld_txq *q, struct sk_buff *skb) |
| 1536 | { |
| 1537 | struct fw_wr_hdr *wr = (struct fw_wr_hdr *)skb->data; |
| 1538 | |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 1539 | wr->lo |= htonl(FW_WR_EQUEQ_F | FW_WR_EQUIQ_F); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1540 | q->q.stops++; |
| 1541 | q->full = 1; |
| 1542 | } |
| 1543 | |
| 1544 | /** |
Hariprasad Shenai | 126fca6 | 2015-12-08 10:09:14 +0530 | [diff] [blame^] | 1545 | * service_ofldq - service/restart a suspended offload queue |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1546 | * @q: the offload queue |
| 1547 | * |
Hariprasad Shenai | 126fca6 | 2015-12-08 10:09:14 +0530 | [diff] [blame^] | 1548 | * Services an offload Tx queue by moving packets from its Pending Send |
| 1549 | * Queue to the Hardware TX ring. The function starts and ends with the |
| 1550 | * Send Queue locked, but drops the lock while putting the skb at the |
| 1551 | * head of the Send Queue onto the Hardware TX Ring. Dropping the lock |
| 1552 | * allows more skbs to be added to the Send Queue by other threads. |
| 1553 | * The packet being processed at the head of the Pending Send Queue is |
| 1554 | * left on the queue in case we experience DMA Mapping errors, etc. |
| 1555 | * and need to give up and restart later. |
| 1556 | * |
| 1557 | * service_ofldq() can be thought of as a task which opportunistically |
| 1558 | * uses other threads execution contexts. We use the Offload Queue |
| 1559 | * boolean "service_ofldq_running" to make sure that only one instance |
| 1560 | * is ever running at a time ... |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1561 | */ |
| 1562 | static void service_ofldq(struct sge_ofld_txq *q) |
| 1563 | { |
| 1564 | u64 *pos; |
| 1565 | int credits; |
| 1566 | struct sk_buff *skb; |
| 1567 | unsigned int written = 0; |
| 1568 | unsigned int flits, ndesc; |
| 1569 | |
Hariprasad Shenai | 126fca6 | 2015-12-08 10:09:14 +0530 | [diff] [blame^] | 1570 | /* If another thread is currently in service_ofldq() processing the |
| 1571 | * Pending Send Queue then there's nothing to do. Otherwise, flag |
| 1572 | * that we're doing the work and continue. Examining/modifying |
| 1573 | * the Offload Queue boolean "service_ofldq_running" must be done |
| 1574 | * while holding the Pending Send Queue Lock. |
| 1575 | */ |
| 1576 | if (q->service_ofldq_running) |
| 1577 | return; |
| 1578 | q->service_ofldq_running = true; |
| 1579 | |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1580 | while ((skb = skb_peek(&q->sendq)) != NULL && !q->full) { |
Hariprasad Shenai | 126fca6 | 2015-12-08 10:09:14 +0530 | [diff] [blame^] | 1581 | /* We drop the lock while we're working with the skb at the |
| 1582 | * head of the Pending Send Queue. This allows more skbs to |
| 1583 | * be added to the Pending Send Queue while we're working on |
| 1584 | * this one. We don't need to lock to guard the TX Ring |
| 1585 | * updates because only one thread of execution is ever |
| 1586 | * allowed into service_ofldq() at a time. |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1587 | */ |
| 1588 | spin_unlock(&q->sendq.lock); |
| 1589 | |
| 1590 | reclaim_completed_tx(q->adap, &q->q, false); |
| 1591 | |
| 1592 | flits = skb->priority; /* previously saved */ |
| 1593 | ndesc = flits_to_desc(flits); |
| 1594 | credits = txq_avail(&q->q) - ndesc; |
| 1595 | BUG_ON(credits < 0); |
| 1596 | if (unlikely(credits < TXQ_STOP_THRES)) |
| 1597 | ofldtxq_stop(q, skb); |
| 1598 | |
| 1599 | pos = (u64 *)&q->q.desc[q->q.pidx]; |
| 1600 | if (is_ofld_imm(skb)) |
| 1601 | inline_tx_skb(skb, &q->q, pos); |
| 1602 | else if (map_skb(q->adap->pdev_dev, skb, |
| 1603 | (dma_addr_t *)skb->head)) { |
| 1604 | txq_stop_maperr(q); |
| 1605 | spin_lock(&q->sendq.lock); |
| 1606 | break; |
| 1607 | } else { |
| 1608 | int last_desc, hdr_len = skb_transport_offset(skb); |
| 1609 | |
| 1610 | memcpy(pos, skb->data, hdr_len); |
| 1611 | write_sgl(skb, &q->q, (void *)pos + hdr_len, |
| 1612 | pos + flits, hdr_len, |
| 1613 | (dma_addr_t *)skb->head); |
| 1614 | #ifdef CONFIG_NEED_DMA_MAP_STATE |
| 1615 | skb->dev = q->adap->port[0]; |
| 1616 | skb->destructor = deferred_unmap_destructor; |
| 1617 | #endif |
| 1618 | last_desc = q->q.pidx + ndesc - 1; |
| 1619 | if (last_desc >= q->q.size) |
| 1620 | last_desc -= q->q.size; |
| 1621 | q->q.sdesc[last_desc].skb = skb; |
| 1622 | } |
| 1623 | |
| 1624 | txq_advance(&q->q, ndesc); |
| 1625 | written += ndesc; |
| 1626 | if (unlikely(written > 32)) { |
| 1627 | ring_tx_db(q->adap, &q->q, written); |
| 1628 | written = 0; |
| 1629 | } |
| 1630 | |
Hariprasad Shenai | 126fca6 | 2015-12-08 10:09:14 +0530 | [diff] [blame^] | 1631 | /* Reacquire the Pending Send Queue Lock so we can unlink the |
| 1632 | * skb we've just successfully transferred to the TX Ring and |
| 1633 | * loop for the next skb which may be at the head of the |
| 1634 | * Pending Send Queue. |
| 1635 | */ |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1636 | spin_lock(&q->sendq.lock); |
| 1637 | __skb_unlink(skb, &q->sendq); |
| 1638 | if (is_ofld_imm(skb)) |
| 1639 | kfree_skb(skb); |
| 1640 | } |
| 1641 | if (likely(written)) |
| 1642 | ring_tx_db(q->adap, &q->q, written); |
Hariprasad Shenai | 126fca6 | 2015-12-08 10:09:14 +0530 | [diff] [blame^] | 1643 | |
| 1644 | /*Indicate that no thread is processing the Pending Send Queue |
| 1645 | * currently. |
| 1646 | */ |
| 1647 | q->service_ofldq_running = false; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1648 | } |
| 1649 | |
| 1650 | /** |
| 1651 | * ofld_xmit - send a packet through an offload queue |
| 1652 | * @q: the Tx offload queue |
| 1653 | * @skb: the packet |
| 1654 | * |
| 1655 | * Send an offload packet through an SGE offload queue. |
| 1656 | */ |
| 1657 | static int ofld_xmit(struct sge_ofld_txq *q, struct sk_buff *skb) |
| 1658 | { |
| 1659 | skb->priority = calc_tx_flits_ofld(skb); /* save for restart */ |
| 1660 | spin_lock(&q->sendq.lock); |
Hariprasad Shenai | 126fca6 | 2015-12-08 10:09:14 +0530 | [diff] [blame^] | 1661 | |
| 1662 | /* Queue the new skb onto the Offload Queue's Pending Send Queue. If |
| 1663 | * that results in this new skb being the only one on the queue, start |
| 1664 | * servicing it. If there are other skbs already on the list, then |
| 1665 | * either the queue is currently being processed or it's been stopped |
| 1666 | * for some reason and it'll be restarted at a later time. Restart |
| 1667 | * paths are triggered by events like experiencing a DMA Mapping Error |
| 1668 | * or filling the Hardware TX Ring. |
| 1669 | */ |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1670 | __skb_queue_tail(&q->sendq, skb); |
| 1671 | if (q->sendq.qlen == 1) |
| 1672 | service_ofldq(q); |
Hariprasad Shenai | 126fca6 | 2015-12-08 10:09:14 +0530 | [diff] [blame^] | 1673 | |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1674 | spin_unlock(&q->sendq.lock); |
| 1675 | return NET_XMIT_SUCCESS; |
| 1676 | } |
| 1677 | |
| 1678 | /** |
| 1679 | * restart_ofldq - restart a suspended offload queue |
| 1680 | * @data: the offload queue to restart |
| 1681 | * |
| 1682 | * Resumes transmission on a suspended Tx offload queue. |
| 1683 | */ |
| 1684 | static void restart_ofldq(unsigned long data) |
| 1685 | { |
| 1686 | struct sge_ofld_txq *q = (struct sge_ofld_txq *)data; |
| 1687 | |
| 1688 | spin_lock(&q->sendq.lock); |
| 1689 | q->full = 0; /* the queue actually is completely empty now */ |
| 1690 | service_ofldq(q); |
| 1691 | spin_unlock(&q->sendq.lock); |
| 1692 | } |
| 1693 | |
| 1694 | /** |
| 1695 | * skb_txq - return the Tx queue an offload packet should use |
| 1696 | * @skb: the packet |
| 1697 | * |
| 1698 | * Returns the Tx queue an offload packet should use as indicated by bits |
| 1699 | * 1-15 in the packet's queue_mapping. |
| 1700 | */ |
| 1701 | static inline unsigned int skb_txq(const struct sk_buff *skb) |
| 1702 | { |
| 1703 | return skb->queue_mapping >> 1; |
| 1704 | } |
| 1705 | |
| 1706 | /** |
| 1707 | * is_ctrl_pkt - return whether an offload packet is a control packet |
| 1708 | * @skb: the packet |
| 1709 | * |
| 1710 | * Returns whether an offload packet should use an OFLD or a CTRL |
| 1711 | * Tx queue as indicated by bit 0 in the packet's queue_mapping. |
| 1712 | */ |
| 1713 | static inline unsigned int is_ctrl_pkt(const struct sk_buff *skb) |
| 1714 | { |
| 1715 | return skb->queue_mapping & 1; |
| 1716 | } |
| 1717 | |
| 1718 | static inline int ofld_send(struct adapter *adap, struct sk_buff *skb) |
| 1719 | { |
| 1720 | unsigned int idx = skb_txq(skb); |
| 1721 | |
Kumar Sanghvi | 4fe44dd | 2014-02-18 17:56:11 +0530 | [diff] [blame] | 1722 | if (unlikely(is_ctrl_pkt(skb))) { |
| 1723 | /* Single ctrl queue is a requirement for LE workaround path */ |
| 1724 | if (adap->tids.nsftids) |
| 1725 | idx = 0; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1726 | return ctrl_xmit(&adap->sge.ctrlq[idx], skb); |
Kumar Sanghvi | 4fe44dd | 2014-02-18 17:56:11 +0530 | [diff] [blame] | 1727 | } |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1728 | return ofld_xmit(&adap->sge.ofldtxq[idx], skb); |
| 1729 | } |
| 1730 | |
| 1731 | /** |
| 1732 | * t4_ofld_send - send an offload packet |
| 1733 | * @adap: the adapter |
| 1734 | * @skb: the packet |
| 1735 | * |
| 1736 | * Sends an offload packet. We use the packet queue_mapping to select the |
| 1737 | * appropriate Tx queue as follows: bit 0 indicates whether the packet |
| 1738 | * should be sent as regular or control, bits 1-15 select the queue. |
| 1739 | */ |
| 1740 | int t4_ofld_send(struct adapter *adap, struct sk_buff *skb) |
| 1741 | { |
| 1742 | int ret; |
| 1743 | |
| 1744 | local_bh_disable(); |
| 1745 | ret = ofld_send(adap, skb); |
| 1746 | local_bh_enable(); |
| 1747 | return ret; |
| 1748 | } |
| 1749 | |
| 1750 | /** |
| 1751 | * cxgb4_ofld_send - send an offload packet |
| 1752 | * @dev: the net device |
| 1753 | * @skb: the packet |
| 1754 | * |
| 1755 | * Sends an offload packet. This is an exported version of @t4_ofld_send, |
| 1756 | * intended for ULDs. |
| 1757 | */ |
| 1758 | int cxgb4_ofld_send(struct net_device *dev, struct sk_buff *skb) |
| 1759 | { |
| 1760 | return t4_ofld_send(netdev2adap(dev), skb); |
| 1761 | } |
| 1762 | EXPORT_SYMBOL(cxgb4_ofld_send); |
| 1763 | |
Ian Campbell | e91b0f2 | 2011-10-19 23:01:46 +0000 | [diff] [blame] | 1764 | static inline void copy_frags(struct sk_buff *skb, |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1765 | const struct pkt_gl *gl, unsigned int offset) |
| 1766 | { |
Ian Campbell | e91b0f2 | 2011-10-19 23:01:46 +0000 | [diff] [blame] | 1767 | int i; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1768 | |
| 1769 | /* usually there's just one frag */ |
Ian Campbell | e91b0f2 | 2011-10-19 23:01:46 +0000 | [diff] [blame] | 1770 | __skb_fill_page_desc(skb, 0, gl->frags[0].page, |
| 1771 | gl->frags[0].offset + offset, |
| 1772 | gl->frags[0].size - offset); |
| 1773 | skb_shinfo(skb)->nr_frags = gl->nfrags; |
| 1774 | for (i = 1; i < gl->nfrags; i++) |
| 1775 | __skb_fill_page_desc(skb, i, gl->frags[i].page, |
| 1776 | gl->frags[i].offset, |
| 1777 | gl->frags[i].size); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1778 | |
| 1779 | /* get a reference to the last page, we don't own it */ |
Ian Campbell | e91b0f2 | 2011-10-19 23:01:46 +0000 | [diff] [blame] | 1780 | get_page(gl->frags[gl->nfrags - 1].page); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | /** |
| 1784 | * cxgb4_pktgl_to_skb - build an sk_buff from a packet gather list |
| 1785 | * @gl: the gather list |
| 1786 | * @skb_len: size of sk_buff main body if it carries fragments |
| 1787 | * @pull_len: amount of data to move to the sk_buff's main body |
| 1788 | * |
| 1789 | * Builds an sk_buff from the given packet gather list. Returns the |
| 1790 | * sk_buff or %NULL if sk_buff allocation failed. |
| 1791 | */ |
| 1792 | struct sk_buff *cxgb4_pktgl_to_skb(const struct pkt_gl *gl, |
| 1793 | unsigned int skb_len, unsigned int pull_len) |
| 1794 | { |
| 1795 | struct sk_buff *skb; |
| 1796 | |
| 1797 | /* |
| 1798 | * Below we rely on RX_COPY_THRES being less than the smallest Rx buffer |
| 1799 | * size, which is expected since buffers are at least PAGE_SIZEd. |
| 1800 | * In this case packets up to RX_COPY_THRES have only one fragment. |
| 1801 | */ |
| 1802 | if (gl->tot_len <= RX_COPY_THRES) { |
| 1803 | skb = dev_alloc_skb(gl->tot_len); |
| 1804 | if (unlikely(!skb)) |
| 1805 | goto out; |
| 1806 | __skb_put(skb, gl->tot_len); |
| 1807 | skb_copy_to_linear_data(skb, gl->va, gl->tot_len); |
| 1808 | } else { |
| 1809 | skb = dev_alloc_skb(skb_len); |
| 1810 | if (unlikely(!skb)) |
| 1811 | goto out; |
| 1812 | __skb_put(skb, pull_len); |
| 1813 | skb_copy_to_linear_data(skb, gl->va, pull_len); |
| 1814 | |
Ian Campbell | e91b0f2 | 2011-10-19 23:01:46 +0000 | [diff] [blame] | 1815 | copy_frags(skb, gl, pull_len); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1816 | skb->len = gl->tot_len; |
| 1817 | skb->data_len = skb->len - pull_len; |
| 1818 | skb->truesize += skb->data_len; |
| 1819 | } |
| 1820 | out: return skb; |
| 1821 | } |
| 1822 | EXPORT_SYMBOL(cxgb4_pktgl_to_skb); |
| 1823 | |
| 1824 | /** |
| 1825 | * t4_pktgl_free - free a packet gather list |
| 1826 | * @gl: the gather list |
| 1827 | * |
| 1828 | * Releases the pages of a packet gather list. We do not own the last |
| 1829 | * page on the list and do not free it. |
| 1830 | */ |
Roland Dreier | de498c8 | 2010-04-21 08:59:17 +0000 | [diff] [blame] | 1831 | static void t4_pktgl_free(const struct pkt_gl *gl) |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1832 | { |
| 1833 | int n; |
Ian Campbell | e91b0f2 | 2011-10-19 23:01:46 +0000 | [diff] [blame] | 1834 | const struct page_frag *p; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1835 | |
| 1836 | for (p = gl->frags, n = gl->nfrags - 1; n--; p++) |
| 1837 | put_page(p->page); |
| 1838 | } |
| 1839 | |
| 1840 | /* |
| 1841 | * Process an MPS trace packet. Give it an unused protocol number so it won't |
| 1842 | * be delivered to anyone and send it to the stack for capture. |
| 1843 | */ |
| 1844 | static noinline int handle_trace_pkt(struct adapter *adap, |
| 1845 | const struct pkt_gl *gl) |
| 1846 | { |
| 1847 | struct sk_buff *skb; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1848 | |
| 1849 | skb = cxgb4_pktgl_to_skb(gl, RX_PULL_LEN, RX_PULL_LEN); |
| 1850 | if (unlikely(!skb)) { |
| 1851 | t4_pktgl_free(gl); |
| 1852 | return 0; |
| 1853 | } |
| 1854 | |
Hariprasad Shenai | d14807d | 2013-12-03 17:05:56 +0530 | [diff] [blame] | 1855 | if (is_t4(adap->params.chip)) |
Santosh Rastapur | 0a57a53 | 2013-03-14 05:08:49 +0000 | [diff] [blame] | 1856 | __skb_pull(skb, sizeof(struct cpl_trace_pkt)); |
| 1857 | else |
| 1858 | __skb_pull(skb, sizeof(struct cpl_t5_trace_pkt)); |
| 1859 | |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1860 | skb_reset_mac_header(skb); |
| 1861 | skb->protocol = htons(0xffff); |
| 1862 | skb->dev = adap->port[0]; |
| 1863 | netif_receive_skb(skb); |
| 1864 | return 0; |
| 1865 | } |
| 1866 | |
Hariprasad Shenai | 5e2a5eb | 2015-09-28 10:26:53 +0530 | [diff] [blame] | 1867 | /** |
| 1868 | * cxgb4_sgetim_to_hwtstamp - convert sge time stamp to hw time stamp |
| 1869 | * @adap: the adapter |
| 1870 | * @hwtstamps: time stamp structure to update |
| 1871 | * @sgetstamp: 60bit iqe timestamp |
| 1872 | * |
| 1873 | * Every ingress queue entry has the 60-bit timestamp, convert that timestamp |
| 1874 | * which is in Core Clock ticks into ktime_t and assign it |
| 1875 | **/ |
| 1876 | static void cxgb4_sgetim_to_hwtstamp(struct adapter *adap, |
| 1877 | struct skb_shared_hwtstamps *hwtstamps, |
| 1878 | u64 sgetstamp) |
| 1879 | { |
| 1880 | u64 ns; |
| 1881 | u64 tmp = (sgetstamp * 1000 * 1000 + adap->params.vpd.cclk / 2); |
| 1882 | |
| 1883 | ns = div_u64(tmp, adap->params.vpd.cclk); |
| 1884 | |
| 1885 | memset(hwtstamps, 0, sizeof(*hwtstamps)); |
| 1886 | hwtstamps->hwtstamp = ns_to_ktime(ns); |
| 1887 | } |
| 1888 | |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1889 | static void do_gro(struct sge_eth_rxq *rxq, const struct pkt_gl *gl, |
| 1890 | const struct cpl_rx_pkt *pkt) |
| 1891 | { |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 1892 | struct adapter *adapter = rxq->rspq.adap; |
| 1893 | struct sge *s = &adapter->sge; |
Hariprasad Shenai | 5e2a5eb | 2015-09-28 10:26:53 +0530 | [diff] [blame] | 1894 | struct port_info *pi; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1895 | int ret; |
| 1896 | struct sk_buff *skb; |
| 1897 | |
| 1898 | skb = napi_get_frags(&rxq->rspq.napi); |
| 1899 | if (unlikely(!skb)) { |
| 1900 | t4_pktgl_free(gl); |
| 1901 | rxq->stats.rx_drops++; |
| 1902 | return; |
| 1903 | } |
| 1904 | |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 1905 | copy_frags(skb, gl, s->pktshift); |
| 1906 | skb->len = gl->tot_len - s->pktshift; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1907 | skb->data_len = skb->len; |
| 1908 | skb->truesize += skb->data_len; |
| 1909 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1910 | skb_record_rx_queue(skb, rxq->rspq.idx); |
Hariprasad Shenai | 5e2a5eb | 2015-09-28 10:26:53 +0530 | [diff] [blame] | 1911 | pi = netdev_priv(skb->dev); |
| 1912 | if (pi->rxtstamp) |
| 1913 | cxgb4_sgetim_to_hwtstamp(adapter, skb_hwtstamps(skb), |
| 1914 | gl->sgetstamp); |
Dimitris Michailidis | 87b6cf5 | 2010-04-27 16:22:42 -0700 | [diff] [blame] | 1915 | if (rxq->rspq.netdev->features & NETIF_F_RXHASH) |
Tom Herbert | 8264989 | 2013-12-17 23:23:29 -0800 | [diff] [blame] | 1916 | skb_set_hash(skb, (__force u32)pkt->rsshdr.hash_val, |
| 1917 | PKT_HASH_TYPE_L3); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1918 | |
| 1919 | if (unlikely(pkt->vlan_ex)) { |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1920 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), ntohs(pkt->vlan)); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1921 | rxq->stats.vlan_ex++; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1922 | } |
| 1923 | ret = napi_gro_frags(&rxq->rspq.napi); |
Dimitris Michailidis | 19ecae2 | 2010-10-21 11:29:56 +0000 | [diff] [blame] | 1924 | if (ret == GRO_HELD) |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1925 | rxq->stats.lro_pkts++; |
| 1926 | else if (ret == GRO_MERGED || ret == GRO_MERGED_FREE) |
| 1927 | rxq->stats.lro_merged++; |
| 1928 | rxq->stats.pkts++; |
| 1929 | rxq->stats.rx_cso++; |
| 1930 | } |
| 1931 | |
| 1932 | /** |
| 1933 | * t4_ethrx_handler - process an ingress ethernet packet |
| 1934 | * @q: the response queue that received the packet |
| 1935 | * @rsp: the response queue descriptor holding the RX_PKT message |
| 1936 | * @si: the gather list of packet fragments |
| 1937 | * |
| 1938 | * Process an ingress ethernet packet and deliver it to the stack. |
| 1939 | */ |
| 1940 | int t4_ethrx_handler(struct sge_rspq *q, const __be64 *rsp, |
| 1941 | const struct pkt_gl *si) |
| 1942 | { |
| 1943 | bool csum_ok; |
| 1944 | struct sk_buff *skb; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1945 | const struct cpl_rx_pkt *pkt; |
| 1946 | struct sge_eth_rxq *rxq = container_of(q, struct sge_eth_rxq, rspq); |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 1947 | struct sge *s = &q->adap->sge; |
Hariprasad Shenai | d14807d | 2013-12-03 17:05:56 +0530 | [diff] [blame] | 1948 | int cpl_trace_pkt = is_t4(q->adap->params.chip) ? |
Santosh Rastapur | 0a57a53 | 2013-03-14 05:08:49 +0000 | [diff] [blame] | 1949 | CPL_TRACE_PKT : CPL_TRACE_PKT_T5; |
Varun Prakash | 84a200b | 2015-03-24 19:14:46 +0530 | [diff] [blame] | 1950 | struct port_info *pi; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1951 | |
Santosh Rastapur | 0a57a53 | 2013-03-14 05:08:49 +0000 | [diff] [blame] | 1952 | if (unlikely(*(u8 *)rsp == cpl_trace_pkt)) |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1953 | return handle_trace_pkt(q->adap, si); |
| 1954 | |
Dimitris Michailidis | 87b6cf5 | 2010-04-27 16:22:42 -0700 | [diff] [blame] | 1955 | pkt = (const struct cpl_rx_pkt *)rsp; |
Hariprasad Shenai | cca2822 | 2014-05-07 18:01:03 +0530 | [diff] [blame] | 1956 | csum_ok = pkt->csum_calc && !pkt->err_vec && |
| 1957 | (q->netdev->features & NETIF_F_RXCSUM); |
Hariprasad Shenai | bdc590b | 2015-01-08 21:38:16 -0800 | [diff] [blame] | 1958 | if ((pkt->l2info & htonl(RXF_TCP_F)) && |
Hariprasad Shenai | 3a336cb | 2015-02-04 15:32:52 +0530 | [diff] [blame] | 1959 | !(cxgb_poll_busy_polling(q)) && |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1960 | (q->netdev->features & NETIF_F_GRO) && csum_ok && !pkt->ip_frag) { |
| 1961 | do_gro(rxq, si, pkt); |
| 1962 | return 0; |
| 1963 | } |
| 1964 | |
| 1965 | skb = cxgb4_pktgl_to_skb(si, RX_PKT_SKB_LEN, RX_PULL_LEN); |
| 1966 | if (unlikely(!skb)) { |
| 1967 | t4_pktgl_free(si); |
| 1968 | rxq->stats.rx_drops++; |
| 1969 | return 0; |
| 1970 | } |
| 1971 | |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 1972 | __skb_pull(skb, s->pktshift); /* remove ethernet header padding */ |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1973 | skb->protocol = eth_type_trans(skb, q->netdev); |
| 1974 | skb_record_rx_queue(skb, q->idx); |
Dimitris Michailidis | 87b6cf5 | 2010-04-27 16:22:42 -0700 | [diff] [blame] | 1975 | if (skb->dev->features & NETIF_F_RXHASH) |
Tom Herbert | 8264989 | 2013-12-17 23:23:29 -0800 | [diff] [blame] | 1976 | skb_set_hash(skb, (__force u32)pkt->rsshdr.hash_val, |
| 1977 | PKT_HASH_TYPE_L3); |
Dimitris Michailidis | 87b6cf5 | 2010-04-27 16:22:42 -0700 | [diff] [blame] | 1978 | |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1979 | rxq->stats.pkts++; |
| 1980 | |
Hariprasad Shenai | 5e2a5eb | 2015-09-28 10:26:53 +0530 | [diff] [blame] | 1981 | pi = netdev_priv(skb->dev); |
| 1982 | if (pi->rxtstamp) |
| 1983 | cxgb4_sgetim_to_hwtstamp(q->adap, skb_hwtstamps(skb), |
| 1984 | si->sgetstamp); |
Hariprasad Shenai | bdc590b | 2015-01-08 21:38:16 -0800 | [diff] [blame] | 1985 | if (csum_ok && (pkt->l2info & htonl(RXF_UDP_F | RXF_TCP_F))) { |
Dimitris Michailidis | ba5d3c6 | 2010-08-02 13:19:17 +0000 | [diff] [blame] | 1986 | if (!pkt->ip_frag) { |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1987 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Dimitris Michailidis | ba5d3c6 | 2010-08-02 13:19:17 +0000 | [diff] [blame] | 1988 | rxq->stats.rx_cso++; |
Hariprasad Shenai | bdc590b | 2015-01-08 21:38:16 -0800 | [diff] [blame] | 1989 | } else if (pkt->l2info & htonl(RXF_IP_F)) { |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1990 | __sum16 c = (__force __sum16)pkt->csum; |
| 1991 | skb->csum = csum_unfold(c); |
| 1992 | skb->ip_summed = CHECKSUM_COMPLETE; |
Dimitris Michailidis | ba5d3c6 | 2010-08-02 13:19:17 +0000 | [diff] [blame] | 1993 | rxq->stats.rx_cso++; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 1994 | } |
Varun Prakash | 84a200b | 2015-03-24 19:14:46 +0530 | [diff] [blame] | 1995 | } else { |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 1996 | skb_checksum_none_assert(skb); |
Varun Prakash | 84a200b | 2015-03-24 19:14:46 +0530 | [diff] [blame] | 1997 | #ifdef CONFIG_CHELSIO_T4_FCOE |
| 1998 | #define CPL_RX_PKT_FLAGS (RXF_PSH_F | RXF_SYN_F | RXF_UDP_F | \ |
| 1999 | RXF_TCP_F | RXF_IP_F | RXF_IP6_F | RXF_LRO_F) |
| 2000 | |
Varun Prakash | 84a200b | 2015-03-24 19:14:46 +0530 | [diff] [blame] | 2001 | if (!(pkt->l2info & cpu_to_be32(CPL_RX_PKT_FLAGS))) { |
| 2002 | if ((pkt->l2info & cpu_to_be32(RXF_FCOE_F)) && |
| 2003 | (pi->fcoe.flags & CXGB_FCOE_ENABLED)) { |
| 2004 | if (!(pkt->err_vec & cpu_to_be16(RXERR_CSUM_F))) |
| 2005 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 2006 | } |
| 2007 | } |
| 2008 | |
| 2009 | #undef CPL_RX_PKT_FLAGS |
| 2010 | #endif /* CONFIG_CHELSIO_T4_FCOE */ |
| 2011 | } |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2012 | |
| 2013 | if (unlikely(pkt->vlan_ex)) { |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 2014 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), ntohs(pkt->vlan)); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2015 | rxq->stats.vlan_ex++; |
Dimitris Michailidis | 19ecae2 | 2010-10-21 11:29:56 +0000 | [diff] [blame] | 2016 | } |
Hariprasad Shenai | 3a336cb | 2015-02-04 15:32:52 +0530 | [diff] [blame] | 2017 | skb_mark_napi_id(skb, &q->napi); |
Dimitris Michailidis | 19ecae2 | 2010-10-21 11:29:56 +0000 | [diff] [blame] | 2018 | netif_receive_skb(skb); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2019 | return 0; |
| 2020 | } |
| 2021 | |
| 2022 | /** |
| 2023 | * restore_rx_bufs - put back a packet's Rx buffers |
| 2024 | * @si: the packet gather list |
| 2025 | * @q: the SGE free list |
| 2026 | * @frags: number of FL buffers to restore |
| 2027 | * |
| 2028 | * Puts back on an FL the Rx buffers associated with @si. The buffers |
| 2029 | * have already been unmapped and are left unmapped, we mark them so to |
| 2030 | * prevent further unmapping attempts. |
| 2031 | * |
| 2032 | * This function undoes a series of @unmap_rx_buf calls when we find out |
| 2033 | * that the current packet can't be processed right away afterall and we |
| 2034 | * need to come back to it later. This is a very rare event and there's |
| 2035 | * no effort to make this particularly efficient. |
| 2036 | */ |
| 2037 | static void restore_rx_bufs(const struct pkt_gl *si, struct sge_fl *q, |
| 2038 | int frags) |
| 2039 | { |
| 2040 | struct rx_sw_desc *d; |
| 2041 | |
| 2042 | while (frags--) { |
| 2043 | if (q->cidx == 0) |
| 2044 | q->cidx = q->size - 1; |
| 2045 | else |
| 2046 | q->cidx--; |
| 2047 | d = &q->sdesc[q->cidx]; |
| 2048 | d->page = si->frags[frags].page; |
| 2049 | d->dma_addr |= RX_UNMAPPED_BUF; |
| 2050 | q->avail++; |
| 2051 | } |
| 2052 | } |
| 2053 | |
| 2054 | /** |
| 2055 | * is_new_response - check if a response is newly written |
| 2056 | * @r: the response descriptor |
| 2057 | * @q: the response queue |
| 2058 | * |
| 2059 | * Returns true if a response descriptor contains a yet unprocessed |
| 2060 | * response. |
| 2061 | */ |
| 2062 | static inline bool is_new_response(const struct rsp_ctrl *r, |
| 2063 | const struct sge_rspq *q) |
| 2064 | { |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 2065 | return (r->type_gen >> RSPD_GEN_S) == q->gen; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | /** |
| 2069 | * rspq_next - advance to the next entry in a response queue |
| 2070 | * @q: the queue |
| 2071 | * |
| 2072 | * Updates the state of a response queue to advance it to the next entry. |
| 2073 | */ |
| 2074 | static inline void rspq_next(struct sge_rspq *q) |
| 2075 | { |
| 2076 | q->cur_desc = (void *)q->cur_desc + q->iqe_len; |
| 2077 | if (unlikely(++q->cidx == q->size)) { |
| 2078 | q->cidx = 0; |
| 2079 | q->gen ^= 1; |
| 2080 | q->cur_desc = q->desc; |
| 2081 | } |
| 2082 | } |
| 2083 | |
| 2084 | /** |
| 2085 | * process_responses - process responses from an SGE response queue |
| 2086 | * @q: the ingress queue to process |
| 2087 | * @budget: how many responses can be processed in this round |
| 2088 | * |
| 2089 | * Process responses from an SGE response queue up to the supplied budget. |
| 2090 | * Responses include received packets as well as control messages from FW |
| 2091 | * or HW. |
| 2092 | * |
| 2093 | * Additionally choose the interrupt holdoff time for the next interrupt |
| 2094 | * on this queue. If the system is under memory shortage use a fairly |
| 2095 | * long delay to help recovery. |
| 2096 | */ |
| 2097 | static int process_responses(struct sge_rspq *q, int budget) |
| 2098 | { |
| 2099 | int ret, rsp_type; |
| 2100 | int budget_left = budget; |
| 2101 | const struct rsp_ctrl *rc; |
| 2102 | struct sge_eth_rxq *rxq = container_of(q, struct sge_eth_rxq, rspq); |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 2103 | struct adapter *adapter = q->adap; |
| 2104 | struct sge *s = &adapter->sge; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2105 | |
| 2106 | while (likely(budget_left)) { |
| 2107 | rc = (void *)q->cur_desc + (q->iqe_len - sizeof(*rc)); |
| 2108 | if (!is_new_response(rc, q)) |
| 2109 | break; |
| 2110 | |
Alexander Duyck | 019be1c | 2015-04-08 18:49:29 -0700 | [diff] [blame] | 2111 | dma_rmb(); |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 2112 | rsp_type = RSPD_TYPE_G(rc->type_gen); |
| 2113 | if (likely(rsp_type == RSPD_TYPE_FLBUF_X)) { |
Ian Campbell | e91b0f2 | 2011-10-19 23:01:46 +0000 | [diff] [blame] | 2114 | struct page_frag *fp; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2115 | struct pkt_gl si; |
| 2116 | const struct rx_sw_desc *rsd; |
| 2117 | u32 len = ntohl(rc->pldbuflen_qid), bufsz, frags; |
| 2118 | |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 2119 | if (len & RSPD_NEWBUF_F) { |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2120 | if (likely(q->offset > 0)) { |
| 2121 | free_rx_bufs(q->adap, &rxq->fl, 1); |
| 2122 | q->offset = 0; |
| 2123 | } |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 2124 | len = RSPD_LEN_G(len); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2125 | } |
| 2126 | si.tot_len = len; |
| 2127 | |
| 2128 | /* gather packet fragments */ |
| 2129 | for (frags = 0, fp = si.frags; ; frags++, fp++) { |
| 2130 | rsd = &rxq->fl.sdesc[rxq->fl.cidx]; |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 2131 | bufsz = get_buf_size(adapter, rsd); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2132 | fp->page = rsd->page; |
Ian Campbell | e91b0f2 | 2011-10-19 23:01:46 +0000 | [diff] [blame] | 2133 | fp->offset = q->offset; |
| 2134 | fp->size = min(bufsz, len); |
| 2135 | len -= fp->size; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2136 | if (!len) |
| 2137 | break; |
| 2138 | unmap_rx_buf(q->adap, &rxq->fl); |
| 2139 | } |
| 2140 | |
Hariprasad Shenai | 5e2a5eb | 2015-09-28 10:26:53 +0530 | [diff] [blame] | 2141 | si.sgetstamp = SGE_TIMESTAMP_G( |
| 2142 | be64_to_cpu(rc->last_flit)); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2143 | /* |
| 2144 | * Last buffer remains mapped so explicitly make it |
| 2145 | * coherent for CPU access. |
| 2146 | */ |
| 2147 | dma_sync_single_for_cpu(q->adap->pdev_dev, |
| 2148 | get_buf_addr(rsd), |
Ian Campbell | e91b0f2 | 2011-10-19 23:01:46 +0000 | [diff] [blame] | 2149 | fp->size, DMA_FROM_DEVICE); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2150 | |
| 2151 | si.va = page_address(si.frags[0].page) + |
Ian Campbell | e91b0f2 | 2011-10-19 23:01:46 +0000 | [diff] [blame] | 2152 | si.frags[0].offset; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2153 | prefetch(si.va); |
| 2154 | |
| 2155 | si.nfrags = frags + 1; |
| 2156 | ret = q->handler(q, q->cur_desc, &si); |
| 2157 | if (likely(ret == 0)) |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 2158 | q->offset += ALIGN(fp->size, s->fl_align); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2159 | else |
| 2160 | restore_rx_bufs(&si, &rxq->fl, frags); |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 2161 | } else if (likely(rsp_type == RSPD_TYPE_CPL_X)) { |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2162 | ret = q->handler(q, q->cur_desc, NULL); |
| 2163 | } else { |
| 2164 | ret = q->handler(q, (const __be64 *)rc, CXGB4_MSG_AN); |
| 2165 | } |
| 2166 | |
| 2167 | if (unlikely(ret)) { |
| 2168 | /* couldn't process descriptor, back off for recovery */ |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 2169 | q->next_intr_params = QINTR_TIMER_IDX_V(NOMEM_TMR_IDX); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2170 | break; |
| 2171 | } |
| 2172 | |
| 2173 | rspq_next(q); |
| 2174 | budget_left--; |
| 2175 | } |
| 2176 | |
| 2177 | if (q->offset >= 0 && rxq->fl.size - rxq->fl.avail >= 16) |
| 2178 | __refill_fl(q->adap, &rxq->fl); |
| 2179 | return budget - budget_left; |
| 2180 | } |
| 2181 | |
Hariprasad Shenai | 3a336cb | 2015-02-04 15:32:52 +0530 | [diff] [blame] | 2182 | #ifdef CONFIG_NET_RX_BUSY_POLL |
| 2183 | int cxgb_busy_poll(struct napi_struct *napi) |
| 2184 | { |
| 2185 | struct sge_rspq *q = container_of(napi, struct sge_rspq, napi); |
| 2186 | unsigned int params, work_done; |
| 2187 | u32 val; |
| 2188 | |
| 2189 | if (!cxgb_poll_lock_poll(q)) |
| 2190 | return LL_FLUSH_BUSY; |
| 2191 | |
| 2192 | work_done = process_responses(q, 4); |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 2193 | params = QINTR_TIMER_IDX_V(TIMERREG_COUNTER0_X) | QINTR_CNT_EN_V(1); |
Hariprasad Shenai | 3a336cb | 2015-02-04 15:32:52 +0530 | [diff] [blame] | 2194 | q->next_intr_params = params; |
| 2195 | val = CIDXINC_V(work_done) | SEINTARM_V(params); |
| 2196 | |
| 2197 | /* If we don't have access to the new User GTS (T5+), use the old |
| 2198 | * doorbell mechanism; otherwise use the new BAR2 mechanism. |
| 2199 | */ |
| 2200 | if (unlikely(!q->bar2_addr)) |
| 2201 | t4_write_reg(q->adap, MYPF_REG(SGE_PF_GTS_A), |
| 2202 | val | INGRESSQID_V((u32)q->cntxt_id)); |
| 2203 | else { |
| 2204 | writel(val | INGRESSQID_V(q->bar2_qid), |
| 2205 | q->bar2_addr + SGE_UDB_GTS); |
| 2206 | wmb(); |
| 2207 | } |
| 2208 | |
| 2209 | cxgb_poll_unlock_poll(q); |
| 2210 | return work_done; |
| 2211 | } |
| 2212 | #endif /* CONFIG_NET_RX_BUSY_POLL */ |
| 2213 | |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2214 | /** |
| 2215 | * napi_rx_handler - the NAPI handler for Rx processing |
| 2216 | * @napi: the napi instance |
| 2217 | * @budget: how many packets we can process in this round |
| 2218 | * |
| 2219 | * Handler for new data events when using NAPI. This does not need any |
| 2220 | * locking or protection from interrupts as data interrupts are off at |
| 2221 | * this point and other adapter interrupts do not interfere (the latter |
| 2222 | * in not a concern at all with MSI-X as non-data interrupts then have |
| 2223 | * a separate handler). |
| 2224 | */ |
| 2225 | static int napi_rx_handler(struct napi_struct *napi, int budget) |
| 2226 | { |
| 2227 | unsigned int params; |
| 2228 | struct sge_rspq *q = container_of(napi, struct sge_rspq, napi); |
Hariprasad Shenai | 3a336cb | 2015-02-04 15:32:52 +0530 | [diff] [blame] | 2229 | int work_done; |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 2230 | u32 val; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2231 | |
Hariprasad Shenai | 3a336cb | 2015-02-04 15:32:52 +0530 | [diff] [blame] | 2232 | if (!cxgb_poll_lock_napi(q)) |
| 2233 | return budget; |
| 2234 | |
| 2235 | work_done = process_responses(q, budget); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2236 | if (likely(work_done < budget)) { |
Hariprasad Shenai | e553ec3 | 2014-09-26 00:23:55 +0530 | [diff] [blame] | 2237 | int timer_index; |
| 2238 | |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2239 | napi_complete(napi); |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 2240 | timer_index = QINTR_TIMER_IDX_G(q->next_intr_params); |
Hariprasad Shenai | e553ec3 | 2014-09-26 00:23:55 +0530 | [diff] [blame] | 2241 | |
| 2242 | if (q->adaptive_rx) { |
| 2243 | if (work_done > max(timer_pkt_quota[timer_index], |
| 2244 | MIN_NAPI_WORK)) |
| 2245 | timer_index = (timer_index + 1); |
| 2246 | else |
| 2247 | timer_index = timer_index - 1; |
| 2248 | |
| 2249 | timer_index = clamp(timer_index, 0, SGE_TIMERREGS - 1); |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 2250 | q->next_intr_params = |
| 2251 | QINTR_TIMER_IDX_V(timer_index) | |
| 2252 | QINTR_CNT_EN_V(0); |
Hariprasad Shenai | e553ec3 | 2014-09-26 00:23:55 +0530 | [diff] [blame] | 2253 | params = q->next_intr_params; |
| 2254 | } else { |
| 2255 | params = q->next_intr_params; |
| 2256 | q->next_intr_params = q->intr_params; |
| 2257 | } |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2258 | } else |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 2259 | params = QINTR_TIMER_IDX_V(7); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2260 | |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 2261 | val = CIDXINC_V(work_done) | SEINTARM_V(params); |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 2262 | |
| 2263 | /* If we don't have access to the new User GTS (T5+), use the old |
| 2264 | * doorbell mechanism; otherwise use the new BAR2 mechanism. |
| 2265 | */ |
| 2266 | if (unlikely(q->bar2_addr == NULL)) { |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 2267 | t4_write_reg(q->adap, MYPF_REG(SGE_PF_GTS_A), |
| 2268 | val | INGRESSQID_V((u32)q->cntxt_id)); |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 2269 | } else { |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 2270 | writel(val | INGRESSQID_V(q->bar2_qid), |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 2271 | q->bar2_addr + SGE_UDB_GTS); |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 2272 | wmb(); |
| 2273 | } |
Hariprasad Shenai | 3a336cb | 2015-02-04 15:32:52 +0530 | [diff] [blame] | 2274 | cxgb_poll_unlock_napi(q); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2275 | return work_done; |
| 2276 | } |
| 2277 | |
| 2278 | /* |
| 2279 | * The MSI-X interrupt handler for an SGE response queue. |
| 2280 | */ |
| 2281 | irqreturn_t t4_sge_intr_msix(int irq, void *cookie) |
| 2282 | { |
| 2283 | struct sge_rspq *q = cookie; |
| 2284 | |
| 2285 | napi_schedule(&q->napi); |
| 2286 | return IRQ_HANDLED; |
| 2287 | } |
| 2288 | |
| 2289 | /* |
| 2290 | * Process the indirect interrupt entries in the interrupt queue and kick off |
| 2291 | * NAPI for each queue that has generated an entry. |
| 2292 | */ |
| 2293 | static unsigned int process_intrq(struct adapter *adap) |
| 2294 | { |
| 2295 | unsigned int credits; |
| 2296 | const struct rsp_ctrl *rc; |
| 2297 | struct sge_rspq *q = &adap->sge.intrq; |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 2298 | u32 val; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2299 | |
| 2300 | spin_lock(&adap->sge.intrq_lock); |
| 2301 | for (credits = 0; ; credits++) { |
| 2302 | rc = (void *)q->cur_desc + (q->iqe_len - sizeof(*rc)); |
| 2303 | if (!is_new_response(rc, q)) |
| 2304 | break; |
| 2305 | |
Alexander Duyck | 019be1c | 2015-04-08 18:49:29 -0700 | [diff] [blame] | 2306 | dma_rmb(); |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 2307 | if (RSPD_TYPE_G(rc->type_gen) == RSPD_TYPE_INTR_X) { |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2308 | unsigned int qid = ntohl(rc->pldbuflen_qid); |
| 2309 | |
Dimitris Michailidis | e46dab4 | 2010-08-23 17:20:58 +0000 | [diff] [blame] | 2310 | qid -= adap->sge.ingr_start; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2311 | napi_schedule(&adap->sge.ingr_map[qid]->napi); |
| 2312 | } |
| 2313 | |
| 2314 | rspq_next(q); |
| 2315 | } |
| 2316 | |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 2317 | val = CIDXINC_V(credits) | SEINTARM_V(q->intr_params); |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 2318 | |
| 2319 | /* If we don't have access to the new User GTS (T5+), use the old |
| 2320 | * doorbell mechanism; otherwise use the new BAR2 mechanism. |
| 2321 | */ |
| 2322 | if (unlikely(q->bar2_addr == NULL)) { |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 2323 | t4_write_reg(adap, MYPF_REG(SGE_PF_GTS_A), |
| 2324 | val | INGRESSQID_V(q->cntxt_id)); |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 2325 | } else { |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 2326 | writel(val | INGRESSQID_V(q->bar2_qid), |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 2327 | q->bar2_addr + SGE_UDB_GTS); |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 2328 | wmb(); |
| 2329 | } |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2330 | spin_unlock(&adap->sge.intrq_lock); |
| 2331 | return credits; |
| 2332 | } |
| 2333 | |
| 2334 | /* |
| 2335 | * The MSI interrupt handler, which handles data events from SGE response queues |
| 2336 | * as well as error and other async events as they all use the same MSI vector. |
| 2337 | */ |
| 2338 | static irqreturn_t t4_intr_msi(int irq, void *cookie) |
| 2339 | { |
| 2340 | struct adapter *adap = cookie; |
| 2341 | |
Hariprasad Shenai | c3c7b12 | 2015-04-15 02:02:34 +0530 | [diff] [blame] | 2342 | if (adap->flags & MASTER_PF) |
| 2343 | t4_slow_intr_handler(adap); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2344 | process_intrq(adap); |
| 2345 | return IRQ_HANDLED; |
| 2346 | } |
| 2347 | |
| 2348 | /* |
| 2349 | * Interrupt handler for legacy INTx interrupts. |
| 2350 | * Handles data events from SGE response queues as well as error and other |
| 2351 | * async events as they all use the same interrupt line. |
| 2352 | */ |
| 2353 | static irqreturn_t t4_intr_intx(int irq, void *cookie) |
| 2354 | { |
| 2355 | struct adapter *adap = cookie; |
| 2356 | |
Hariprasad Shenai | f061de4 | 2015-01-05 16:30:44 +0530 | [diff] [blame] | 2357 | t4_write_reg(adap, MYPF_REG(PCIE_PF_CLI_A), 0); |
Hariprasad Shenai | c3c7b12 | 2015-04-15 02:02:34 +0530 | [diff] [blame] | 2358 | if (((adap->flags & MASTER_PF) && t4_slow_intr_handler(adap)) | |
| 2359 | process_intrq(adap)) |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2360 | return IRQ_HANDLED; |
| 2361 | return IRQ_NONE; /* probably shared interrupt */ |
| 2362 | } |
| 2363 | |
| 2364 | /** |
| 2365 | * t4_intr_handler - select the top-level interrupt handler |
| 2366 | * @adap: the adapter |
| 2367 | * |
| 2368 | * Selects the top-level interrupt handler based on the type of interrupts |
| 2369 | * (MSI-X, MSI, or INTx). |
| 2370 | */ |
| 2371 | irq_handler_t t4_intr_handler(struct adapter *adap) |
| 2372 | { |
| 2373 | if (adap->flags & USING_MSIX) |
| 2374 | return t4_sge_intr_msix; |
| 2375 | if (adap->flags & USING_MSI) |
| 2376 | return t4_intr_msi; |
| 2377 | return t4_intr_intx; |
| 2378 | } |
| 2379 | |
| 2380 | static void sge_rx_timer_cb(unsigned long data) |
| 2381 | { |
| 2382 | unsigned long m; |
Hariprasad Shenai | a3bfb61 | 2015-05-05 14:59:55 +0530 | [diff] [blame] | 2383 | unsigned int i; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2384 | struct adapter *adap = (struct adapter *)data; |
| 2385 | struct sge *s = &adap->sge; |
| 2386 | |
Hariprasad Shenai | 4b8e27a | 2015-03-26 10:04:25 +0530 | [diff] [blame] | 2387 | for (i = 0; i < BITS_TO_LONGS(s->egr_sz); i++) |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2388 | for (m = s->starving_fl[i]; m; m &= m - 1) { |
| 2389 | struct sge_eth_rxq *rxq; |
| 2390 | unsigned int id = __ffs(m) + i * BITS_PER_LONG; |
| 2391 | struct sge_fl *fl = s->egr_map[id]; |
| 2392 | |
| 2393 | clear_bit(id, s->starving_fl); |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 2394 | smp_mb__after_atomic(); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2395 | |
Hariprasad Shenai | c098b02 | 2015-04-15 02:02:31 +0530 | [diff] [blame] | 2396 | if (fl_starving(adap, fl)) { |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2397 | rxq = container_of(fl, struct sge_eth_rxq, fl); |
| 2398 | if (napi_reschedule(&rxq->rspq.napi)) |
| 2399 | fl->starving++; |
| 2400 | else |
| 2401 | set_bit(id, s->starving_fl); |
| 2402 | } |
| 2403 | } |
Hariprasad Shenai | a3bfb61 | 2015-05-05 14:59:55 +0530 | [diff] [blame] | 2404 | /* The remainder of the SGE RX Timer Callback routine is dedicated to |
| 2405 | * global Master PF activities like checking for chip ingress stalls, |
| 2406 | * etc. |
| 2407 | */ |
| 2408 | if (!(adap->flags & MASTER_PF)) |
| 2409 | goto done; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2410 | |
Hariprasad Shenai | a3bfb61 | 2015-05-05 14:59:55 +0530 | [diff] [blame] | 2411 | t4_idma_monitor(adap, &s->idma_monitor, HZ, RX_QCHECK_PERIOD); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2412 | |
Hariprasad Shenai | a3bfb61 | 2015-05-05 14:59:55 +0530 | [diff] [blame] | 2413 | done: |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2414 | mod_timer(&s->rx_timer, jiffies + RX_QCHECK_PERIOD); |
| 2415 | } |
| 2416 | |
| 2417 | static void sge_tx_timer_cb(unsigned long data) |
| 2418 | { |
| 2419 | unsigned long m; |
| 2420 | unsigned int i, budget; |
| 2421 | struct adapter *adap = (struct adapter *)data; |
| 2422 | struct sge *s = &adap->sge; |
| 2423 | |
Hariprasad Shenai | 4b8e27a | 2015-03-26 10:04:25 +0530 | [diff] [blame] | 2424 | for (i = 0; i < BITS_TO_LONGS(s->egr_sz); i++) |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2425 | for (m = s->txq_maperr[i]; m; m &= m - 1) { |
| 2426 | unsigned long id = __ffs(m) + i * BITS_PER_LONG; |
| 2427 | struct sge_ofld_txq *txq = s->egr_map[id]; |
| 2428 | |
| 2429 | clear_bit(id, s->txq_maperr); |
| 2430 | tasklet_schedule(&txq->qresume_tsk); |
| 2431 | } |
| 2432 | |
| 2433 | budget = MAX_TIMER_TX_RECLAIM; |
| 2434 | i = s->ethtxq_rover; |
| 2435 | do { |
| 2436 | struct sge_eth_txq *q = &s->ethtxq[i]; |
| 2437 | |
| 2438 | if (q->q.in_use && |
| 2439 | time_after_eq(jiffies, q->txq->trans_start + HZ / 100) && |
| 2440 | __netif_tx_trylock(q->txq)) { |
| 2441 | int avail = reclaimable(&q->q); |
| 2442 | |
| 2443 | if (avail) { |
| 2444 | if (avail > budget) |
| 2445 | avail = budget; |
| 2446 | |
| 2447 | free_tx_desc(adap, &q->q, avail, true); |
| 2448 | q->q.in_use -= avail; |
| 2449 | budget -= avail; |
| 2450 | } |
| 2451 | __netif_tx_unlock(q->txq); |
| 2452 | } |
| 2453 | |
| 2454 | if (++i >= s->ethqsets) |
| 2455 | i = 0; |
| 2456 | } while (budget && i != s->ethtxq_rover); |
| 2457 | s->ethtxq_rover = i; |
| 2458 | mod_timer(&s->tx_timer, jiffies + (budget ? TX_QCHECK_PERIOD : 2)); |
| 2459 | } |
| 2460 | |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 2461 | /** |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 2462 | * bar2_address - return the BAR2 address for an SGE Queue's Registers |
| 2463 | * @adapter: the adapter |
| 2464 | * @qid: the SGE Queue ID |
| 2465 | * @qtype: the SGE Queue Type (Egress or Ingress) |
| 2466 | * @pbar2_qid: BAR2 Queue ID or 0 for Queue ID inferred SGE Queues |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 2467 | * |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 2468 | * Returns the BAR2 address for the SGE Queue Registers associated with |
| 2469 | * @qid. If BAR2 SGE Registers aren't available, returns NULL. Also |
| 2470 | * returns the BAR2 Queue ID to be used with writes to the BAR2 SGE |
| 2471 | * Queue Registers. If the BAR2 Queue ID is 0, then "Inferred Queue ID" |
| 2472 | * Registers are supported (e.g. the Write Combining Doorbell Buffer). |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 2473 | */ |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 2474 | static void __iomem *bar2_address(struct adapter *adapter, |
| 2475 | unsigned int qid, |
| 2476 | enum t4_bar2_qtype qtype, |
| 2477 | unsigned int *pbar2_qid) |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 2478 | { |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 2479 | u64 bar2_qoffset; |
| 2480 | int ret; |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 2481 | |
Linus Torvalds | e045671 | 2015-06-24 16:49:49 -0700 | [diff] [blame] | 2482 | ret = t4_bar2_sge_qregs(adapter, qid, qtype, 0, |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 2483 | &bar2_qoffset, pbar2_qid); |
| 2484 | if (ret) |
| 2485 | return NULL; |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 2486 | |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 2487 | return adapter->bar2 + bar2_qoffset; |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 2488 | } |
| 2489 | |
Hariprasad Shenai | 145ef8a | 2015-05-05 14:59:52 +0530 | [diff] [blame] | 2490 | /* @intr_idx: MSI/MSI-X vector if >=0, -(absolute qid + 1) if < 0 |
| 2491 | * @cong: < 0 -> no congestion feedback, >= 0 -> congestion channel map |
| 2492 | */ |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2493 | int t4_sge_alloc_rxq(struct adapter *adap, struct sge_rspq *iq, bool fwevtq, |
| 2494 | struct net_device *dev, int intr_idx, |
Hariprasad Shenai | 145ef8a | 2015-05-05 14:59:52 +0530 | [diff] [blame] | 2495 | struct sge_fl *fl, rspq_handler_t hnd, int cong) |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2496 | { |
| 2497 | int ret, flsz = 0; |
| 2498 | struct fw_iq_cmd c; |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 2499 | struct sge *s = &adap->sge; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2500 | struct port_info *pi = netdev_priv(dev); |
| 2501 | |
| 2502 | /* Size needs to be multiple of 16, including status entry. */ |
| 2503 | iq->size = roundup(iq->size, 16); |
| 2504 | |
| 2505 | iq->desc = alloc_ring(adap->pdev_dev, iq->size, iq->iqe_len, 0, |
Dimitris Michailidis | ad6bad3 | 2010-12-14 21:36:55 +0000 | [diff] [blame] | 2506 | &iq->phys_addr, NULL, 0, NUMA_NO_NODE); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2507 | if (!iq->desc) |
| 2508 | return -ENOMEM; |
| 2509 | |
| 2510 | memset(&c, 0, sizeof(c)); |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 2511 | c.op_to_vfn = htonl(FW_CMD_OP_V(FW_IQ_CMD) | FW_CMD_REQUEST_F | |
| 2512 | FW_CMD_WRITE_F | FW_CMD_EXEC_F | |
Hariprasad Shenai | b261272 | 2015-05-27 22:30:24 +0530 | [diff] [blame] | 2513 | FW_IQ_CMD_PFN_V(adap->pf) | FW_IQ_CMD_VFN_V(0)); |
Hariprasad Shenai | 6e4b51a | 2014-11-21 12:52:03 +0530 | [diff] [blame] | 2514 | c.alloc_to_len16 = htonl(FW_IQ_CMD_ALLOC_F | FW_IQ_CMD_IQSTART_F | |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2515 | FW_LEN16(c)); |
Hariprasad Shenai | 6e4b51a | 2014-11-21 12:52:03 +0530 | [diff] [blame] | 2516 | c.type_to_iqandstindex = htonl(FW_IQ_CMD_TYPE_V(FW_IQ_TYPE_FL_INT_CAP) | |
| 2517 | FW_IQ_CMD_IQASYNCH_V(fwevtq) | FW_IQ_CMD_VIID_V(pi->viid) | |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 2518 | FW_IQ_CMD_IQANDST_V(intr_idx < 0) | |
| 2519 | FW_IQ_CMD_IQANUD_V(UPDATEDELIVERY_INTERRUPT_X) | |
Hariprasad Shenai | 6e4b51a | 2014-11-21 12:52:03 +0530 | [diff] [blame] | 2520 | FW_IQ_CMD_IQANDSTINDEX_V(intr_idx >= 0 ? intr_idx : |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2521 | -intr_idx - 1)); |
Hariprasad Shenai | 6e4b51a | 2014-11-21 12:52:03 +0530 | [diff] [blame] | 2522 | c.iqdroprss_to_iqesize = htons(FW_IQ_CMD_IQPCIECH_V(pi->tx_chan) | |
| 2523 | FW_IQ_CMD_IQGTSMODE_F | |
| 2524 | FW_IQ_CMD_IQINTCNTTHRESH_V(iq->pktcnt_idx) | |
| 2525 | FW_IQ_CMD_IQESIZE_V(ilog2(iq->iqe_len) - 4)); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2526 | c.iqsize = htons(iq->size); |
| 2527 | c.iqaddr = cpu_to_be64(iq->phys_addr); |
Hariprasad Shenai | 145ef8a | 2015-05-05 14:59:52 +0530 | [diff] [blame] | 2528 | if (cong >= 0) |
| 2529 | c.iqns_to_fl0congen = htonl(FW_IQ_CMD_IQFLINTCONGEN_F); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2530 | |
| 2531 | if (fl) { |
Hariprasad Shenai | 3ccc6cf | 2015-06-02 13:59:39 +0530 | [diff] [blame] | 2532 | enum chip_type chip = CHELSIO_CHIP_VERSION(adap->params.chip); |
| 2533 | |
Hariprasad Shenai | 1343299 | 2015-05-05 14:59:51 +0530 | [diff] [blame] | 2534 | /* Allocate the ring for the hardware free list (with space |
| 2535 | * for its status page) along with the associated software |
| 2536 | * descriptor ring. The free list size needs to be a multiple |
| 2537 | * of the Egress Queue Unit and at least 2 Egress Units larger |
| 2538 | * than the SGE's Egress Congrestion Threshold |
| 2539 | * (fl_starve_thres - 1). |
| 2540 | */ |
| 2541 | if (fl->size < s->fl_starve_thres - 1 + 2 * 8) |
| 2542 | fl->size = s->fl_starve_thres - 1 + 2 * 8; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2543 | fl->size = roundup(fl->size, 8); |
| 2544 | fl->desc = alloc_ring(adap->pdev_dev, fl->size, sizeof(__be64), |
| 2545 | sizeof(struct rx_sw_desc), &fl->addr, |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 2546 | &fl->sdesc, s->stat_len, NUMA_NO_NODE); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2547 | if (!fl->desc) |
| 2548 | goto fl_nomem; |
| 2549 | |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 2550 | flsz = fl->size / 8 + s->stat_len / sizeof(struct tx_desc); |
Hariprasad Shenai | 145ef8a | 2015-05-05 14:59:52 +0530 | [diff] [blame] | 2551 | c.iqns_to_fl0congen |= htonl(FW_IQ_CMD_FL0PACKEN_F | |
| 2552 | FW_IQ_CMD_FL0FETCHRO_F | |
| 2553 | FW_IQ_CMD_FL0DATARO_F | |
| 2554 | FW_IQ_CMD_FL0PADEN_F); |
| 2555 | if (cong >= 0) |
| 2556 | c.iqns_to_fl0congen |= |
| 2557 | htonl(FW_IQ_CMD_FL0CNGCHMAP_V(cong) | |
| 2558 | FW_IQ_CMD_FL0CONGCIF_F | |
| 2559 | FW_IQ_CMD_FL0CONGEN_F); |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 2560 | c.fl0dcaen_to_fl0cidxfthresh = |
| 2561 | htons(FW_IQ_CMD_FL0FBMIN_V(FETCHBURSTMIN_64B_X) | |
Hariprasad Shenai | 3ccc6cf | 2015-06-02 13:59:39 +0530 | [diff] [blame] | 2562 | FW_IQ_CMD_FL0FBMAX_V((chip <= CHELSIO_T5) ? |
| 2563 | FETCHBURSTMAX_512B_X : |
| 2564 | FETCHBURSTMAX_256B_X)); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2565 | c.fl0size = htons(flsz); |
| 2566 | c.fl0addr = cpu_to_be64(fl->addr); |
| 2567 | } |
| 2568 | |
Hariprasad Shenai | b261272 | 2015-05-27 22:30:24 +0530 | [diff] [blame] | 2569 | ret = t4_wr_mbox(adap, adap->mbox, &c, sizeof(c), &c); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2570 | if (ret) |
| 2571 | goto err; |
| 2572 | |
| 2573 | netif_napi_add(dev, &iq->napi, napi_rx_handler, 64); |
| 2574 | iq->cur_desc = iq->desc; |
| 2575 | iq->cidx = 0; |
| 2576 | iq->gen = 1; |
| 2577 | iq->next_intr_params = iq->intr_params; |
| 2578 | iq->cntxt_id = ntohs(c.iqid); |
| 2579 | iq->abs_id = ntohs(c.physiqid); |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 2580 | iq->bar2_addr = bar2_address(adap, |
| 2581 | iq->cntxt_id, |
| 2582 | T4_BAR2_QTYPE_INGRESS, |
| 2583 | &iq->bar2_qid); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2584 | iq->size--; /* subtract status entry */ |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2585 | iq->netdev = dev; |
| 2586 | iq->handler = hnd; |
| 2587 | |
| 2588 | /* set offset to -1 to distinguish ingress queues without FL */ |
| 2589 | iq->offset = fl ? 0 : -1; |
| 2590 | |
Dimitris Michailidis | e46dab4 | 2010-08-23 17:20:58 +0000 | [diff] [blame] | 2591 | adap->sge.ingr_map[iq->cntxt_id - adap->sge.ingr_start] = iq; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2592 | |
| 2593 | if (fl) { |
Roland Dreier | 62718b3 | 2010-04-21 08:09:21 +0000 | [diff] [blame] | 2594 | fl->cntxt_id = ntohs(c.fl0id); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2595 | fl->avail = fl->pend_cred = 0; |
| 2596 | fl->pidx = fl->cidx = 0; |
| 2597 | fl->alloc_failed = fl->large_alloc_failed = fl->starving = 0; |
Dimitris Michailidis | e46dab4 | 2010-08-23 17:20:58 +0000 | [diff] [blame] | 2598 | adap->sge.egr_map[fl->cntxt_id - adap->sge.egr_start] = fl; |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 2599 | |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 2600 | /* Note, we must initialize the BAR2 Free List User Doorbell |
| 2601 | * information before refilling the Free List! |
Hariprasad Shenai | d63a6dc | 2014-09-26 00:23:52 +0530 | [diff] [blame] | 2602 | */ |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 2603 | fl->bar2_addr = bar2_address(adap, |
| 2604 | fl->cntxt_id, |
| 2605 | T4_BAR2_QTYPE_EGRESS, |
| 2606 | &fl->bar2_qid); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2607 | refill_fl(adap, fl, fl_cap(fl), GFP_KERNEL); |
| 2608 | } |
Hariprasad Shenai | b8b1ae9 | 2015-05-05 14:59:53 +0530 | [diff] [blame] | 2609 | |
| 2610 | /* For T5 and later we attempt to set up the Congestion Manager values |
| 2611 | * of the new RX Ethernet Queue. This should really be handled by |
| 2612 | * firmware because it's more complex than any host driver wants to |
| 2613 | * get involved with and it's different per chip and this is almost |
| 2614 | * certainly wrong. Firmware would be wrong as well, but it would be |
| 2615 | * a lot easier to fix in one place ... For now we do something very |
| 2616 | * simple (and hopefully less wrong). |
| 2617 | */ |
| 2618 | if (!is_t4(adap->params.chip) && cong >= 0) { |
| 2619 | u32 param, val; |
| 2620 | int i; |
| 2621 | |
| 2622 | param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DMAQ) | |
| 2623 | FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DMAQ_CONM_CTXT) | |
| 2624 | FW_PARAMS_PARAM_YZ_V(iq->cntxt_id)); |
| 2625 | if (cong == 0) { |
| 2626 | val = CONMCTXT_CNGTPMODE_V(CONMCTXT_CNGTPMODE_QUEUE_X); |
| 2627 | } else { |
| 2628 | val = |
| 2629 | CONMCTXT_CNGTPMODE_V(CONMCTXT_CNGTPMODE_CHANNEL_X); |
| 2630 | for (i = 0; i < 4; i++) { |
| 2631 | if (cong & (1 << i)) |
| 2632 | val |= |
| 2633 | CONMCTXT_CNGCHMAP_V(1 << (i << 2)); |
| 2634 | } |
| 2635 | } |
Hariprasad Shenai | b261272 | 2015-05-27 22:30:24 +0530 | [diff] [blame] | 2636 | ret = t4_set_params(adap, adap->mbox, adap->pf, 0, 1, |
Hariprasad Shenai | b8b1ae9 | 2015-05-05 14:59:53 +0530 | [diff] [blame] | 2637 | ¶m, &val); |
| 2638 | if (ret) |
| 2639 | dev_warn(adap->pdev_dev, "Failed to set Congestion" |
| 2640 | " Manager Context for Ingress Queue %d: %d\n", |
| 2641 | iq->cntxt_id, -ret); |
| 2642 | } |
| 2643 | |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2644 | return 0; |
| 2645 | |
| 2646 | fl_nomem: |
| 2647 | ret = -ENOMEM; |
| 2648 | err: |
| 2649 | if (iq->desc) { |
| 2650 | dma_free_coherent(adap->pdev_dev, iq->size * iq->iqe_len, |
| 2651 | iq->desc, iq->phys_addr); |
| 2652 | iq->desc = NULL; |
| 2653 | } |
| 2654 | if (fl && fl->desc) { |
| 2655 | kfree(fl->sdesc); |
| 2656 | fl->sdesc = NULL; |
| 2657 | dma_free_coherent(adap->pdev_dev, flsz * sizeof(struct tx_desc), |
| 2658 | fl->desc, fl->addr); |
| 2659 | fl->desc = NULL; |
| 2660 | } |
| 2661 | return ret; |
| 2662 | } |
| 2663 | |
| 2664 | static void init_txq(struct adapter *adap, struct sge_txq *q, unsigned int id) |
| 2665 | { |
Santosh Rastapur | 22adfe0 | 2013-03-14 05:08:51 +0000 | [diff] [blame] | 2666 | q->cntxt_id = id; |
Hariprasad Shenai | df64e4d | 2014-12-03 19:32:53 +0530 | [diff] [blame] | 2667 | q->bar2_addr = bar2_address(adap, |
| 2668 | q->cntxt_id, |
| 2669 | T4_BAR2_QTYPE_EGRESS, |
| 2670 | &q->bar2_qid); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2671 | q->in_use = 0; |
| 2672 | q->cidx = q->pidx = 0; |
| 2673 | q->stops = q->restarts = 0; |
| 2674 | q->stat = (void *)&q->desc[q->size]; |
Vipul Pandya | 3069ee9 | 2012-05-18 15:29:26 +0530 | [diff] [blame] | 2675 | spin_lock_init(&q->db_lock); |
Dimitris Michailidis | e46dab4 | 2010-08-23 17:20:58 +0000 | [diff] [blame] | 2676 | adap->sge.egr_map[id - adap->sge.egr_start] = q; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2677 | } |
| 2678 | |
| 2679 | int t4_sge_alloc_eth_txq(struct adapter *adap, struct sge_eth_txq *txq, |
| 2680 | struct net_device *dev, struct netdev_queue *netdevq, |
| 2681 | unsigned int iqid) |
| 2682 | { |
| 2683 | int ret, nentries; |
| 2684 | struct fw_eq_eth_cmd c; |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 2685 | struct sge *s = &adap->sge; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2686 | struct port_info *pi = netdev_priv(dev); |
| 2687 | |
| 2688 | /* Add status entries */ |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 2689 | nentries = txq->q.size + s->stat_len / sizeof(struct tx_desc); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2690 | |
| 2691 | txq->q.desc = alloc_ring(adap->pdev_dev, txq->q.size, |
| 2692 | sizeof(struct tx_desc), sizeof(struct tx_sw_desc), |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 2693 | &txq->q.phys_addr, &txq->q.sdesc, s->stat_len, |
Dimitris Michailidis | ad6bad3 | 2010-12-14 21:36:55 +0000 | [diff] [blame] | 2694 | netdev_queue_numa_node_read(netdevq)); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2695 | if (!txq->q.desc) |
| 2696 | return -ENOMEM; |
| 2697 | |
| 2698 | memset(&c, 0, sizeof(c)); |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 2699 | c.op_to_vfn = htonl(FW_CMD_OP_V(FW_EQ_ETH_CMD) | FW_CMD_REQUEST_F | |
| 2700 | FW_CMD_WRITE_F | FW_CMD_EXEC_F | |
Hariprasad Shenai | b261272 | 2015-05-27 22:30:24 +0530 | [diff] [blame] | 2701 | FW_EQ_ETH_CMD_PFN_V(adap->pf) | |
Hariprasad Shenai | 6e4b51a | 2014-11-21 12:52:03 +0530 | [diff] [blame] | 2702 | FW_EQ_ETH_CMD_VFN_V(0)); |
| 2703 | c.alloc_to_len16 = htonl(FW_EQ_ETH_CMD_ALLOC_F | |
| 2704 | FW_EQ_ETH_CMD_EQSTART_F | FW_LEN16(c)); |
| 2705 | c.viid_pkd = htonl(FW_EQ_ETH_CMD_AUTOEQUEQE_F | |
| 2706 | FW_EQ_ETH_CMD_VIID_V(pi->viid)); |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 2707 | c.fetchszm_to_iqid = |
| 2708 | htonl(FW_EQ_ETH_CMD_HOSTFCMODE_V(HOSTFCMODE_STATUS_PAGE_X) | |
| 2709 | FW_EQ_ETH_CMD_PCIECHN_V(pi->tx_chan) | |
| 2710 | FW_EQ_ETH_CMD_FETCHRO_F | FW_EQ_ETH_CMD_IQID_V(iqid)); |
| 2711 | c.dcaen_to_eqsize = |
| 2712 | htonl(FW_EQ_ETH_CMD_FBMIN_V(FETCHBURSTMIN_64B_X) | |
| 2713 | FW_EQ_ETH_CMD_FBMAX_V(FETCHBURSTMAX_512B_X) | |
| 2714 | FW_EQ_ETH_CMD_CIDXFTHRESH_V(CIDXFLUSHTHRESH_32_X) | |
| 2715 | FW_EQ_ETH_CMD_EQSIZE_V(nentries)); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2716 | c.eqaddr = cpu_to_be64(txq->q.phys_addr); |
| 2717 | |
Hariprasad Shenai | b261272 | 2015-05-27 22:30:24 +0530 | [diff] [blame] | 2718 | ret = t4_wr_mbox(adap, adap->mbox, &c, sizeof(c), &c); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2719 | if (ret) { |
| 2720 | kfree(txq->q.sdesc); |
| 2721 | txq->q.sdesc = NULL; |
| 2722 | dma_free_coherent(adap->pdev_dev, |
| 2723 | nentries * sizeof(struct tx_desc), |
| 2724 | txq->q.desc, txq->q.phys_addr); |
| 2725 | txq->q.desc = NULL; |
| 2726 | return ret; |
| 2727 | } |
| 2728 | |
Hariprasad Shenai | 6e4b51a | 2014-11-21 12:52:03 +0530 | [diff] [blame] | 2729 | init_txq(adap, &txq->q, FW_EQ_ETH_CMD_EQID_G(ntohl(c.eqid_pkd))); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2730 | txq->txq = netdevq; |
| 2731 | txq->tso = txq->tx_cso = txq->vlan_ins = 0; |
| 2732 | txq->mapping_err = 0; |
| 2733 | return 0; |
| 2734 | } |
| 2735 | |
| 2736 | int t4_sge_alloc_ctrl_txq(struct adapter *adap, struct sge_ctrl_txq *txq, |
| 2737 | struct net_device *dev, unsigned int iqid, |
| 2738 | unsigned int cmplqid) |
| 2739 | { |
| 2740 | int ret, nentries; |
| 2741 | struct fw_eq_ctrl_cmd c; |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 2742 | struct sge *s = &adap->sge; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2743 | struct port_info *pi = netdev_priv(dev); |
| 2744 | |
| 2745 | /* Add status entries */ |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 2746 | nentries = txq->q.size + s->stat_len / sizeof(struct tx_desc); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2747 | |
| 2748 | txq->q.desc = alloc_ring(adap->pdev_dev, nentries, |
| 2749 | sizeof(struct tx_desc), 0, &txq->q.phys_addr, |
Hariprasad Shenai | 982b81e | 2015-05-05 14:59:54 +0530 | [diff] [blame] | 2750 | NULL, 0, dev_to_node(adap->pdev_dev)); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2751 | if (!txq->q.desc) |
| 2752 | return -ENOMEM; |
| 2753 | |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 2754 | c.op_to_vfn = htonl(FW_CMD_OP_V(FW_EQ_CTRL_CMD) | FW_CMD_REQUEST_F | |
| 2755 | FW_CMD_WRITE_F | FW_CMD_EXEC_F | |
Hariprasad Shenai | b261272 | 2015-05-27 22:30:24 +0530 | [diff] [blame] | 2756 | FW_EQ_CTRL_CMD_PFN_V(adap->pf) | |
Hariprasad Shenai | 6e4b51a | 2014-11-21 12:52:03 +0530 | [diff] [blame] | 2757 | FW_EQ_CTRL_CMD_VFN_V(0)); |
| 2758 | c.alloc_to_len16 = htonl(FW_EQ_CTRL_CMD_ALLOC_F | |
| 2759 | FW_EQ_CTRL_CMD_EQSTART_F | FW_LEN16(c)); |
| 2760 | c.cmpliqid_eqid = htonl(FW_EQ_CTRL_CMD_CMPLIQID_V(cmplqid)); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2761 | c.physeqid_pkd = htonl(0); |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 2762 | c.fetchszm_to_iqid = |
| 2763 | htonl(FW_EQ_CTRL_CMD_HOSTFCMODE_V(HOSTFCMODE_STATUS_PAGE_X) | |
| 2764 | FW_EQ_CTRL_CMD_PCIECHN_V(pi->tx_chan) | |
| 2765 | FW_EQ_CTRL_CMD_FETCHRO_F | FW_EQ_CTRL_CMD_IQID_V(iqid)); |
| 2766 | c.dcaen_to_eqsize = |
| 2767 | htonl(FW_EQ_CTRL_CMD_FBMIN_V(FETCHBURSTMIN_64B_X) | |
| 2768 | FW_EQ_CTRL_CMD_FBMAX_V(FETCHBURSTMAX_512B_X) | |
| 2769 | FW_EQ_CTRL_CMD_CIDXFTHRESH_V(CIDXFLUSHTHRESH_32_X) | |
| 2770 | FW_EQ_CTRL_CMD_EQSIZE_V(nentries)); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2771 | c.eqaddr = cpu_to_be64(txq->q.phys_addr); |
| 2772 | |
Hariprasad Shenai | b261272 | 2015-05-27 22:30:24 +0530 | [diff] [blame] | 2773 | ret = t4_wr_mbox(adap, adap->mbox, &c, sizeof(c), &c); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2774 | if (ret) { |
| 2775 | dma_free_coherent(adap->pdev_dev, |
| 2776 | nentries * sizeof(struct tx_desc), |
| 2777 | txq->q.desc, txq->q.phys_addr); |
| 2778 | txq->q.desc = NULL; |
| 2779 | return ret; |
| 2780 | } |
| 2781 | |
Hariprasad Shenai | 6e4b51a | 2014-11-21 12:52:03 +0530 | [diff] [blame] | 2782 | init_txq(adap, &txq->q, FW_EQ_CTRL_CMD_EQID_G(ntohl(c.cmpliqid_eqid))); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2783 | txq->adap = adap; |
| 2784 | skb_queue_head_init(&txq->sendq); |
| 2785 | tasklet_init(&txq->qresume_tsk, restart_ctrlq, (unsigned long)txq); |
| 2786 | txq->full = 0; |
| 2787 | return 0; |
| 2788 | } |
| 2789 | |
| 2790 | int t4_sge_alloc_ofld_txq(struct adapter *adap, struct sge_ofld_txq *txq, |
| 2791 | struct net_device *dev, unsigned int iqid) |
| 2792 | { |
| 2793 | int ret, nentries; |
| 2794 | struct fw_eq_ofld_cmd c; |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 2795 | struct sge *s = &adap->sge; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2796 | struct port_info *pi = netdev_priv(dev); |
| 2797 | |
| 2798 | /* Add status entries */ |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 2799 | nentries = txq->q.size + s->stat_len / sizeof(struct tx_desc); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2800 | |
| 2801 | txq->q.desc = alloc_ring(adap->pdev_dev, txq->q.size, |
| 2802 | sizeof(struct tx_desc), sizeof(struct tx_sw_desc), |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 2803 | &txq->q.phys_addr, &txq->q.sdesc, s->stat_len, |
Dimitris Michailidis | ad6bad3 | 2010-12-14 21:36:55 +0000 | [diff] [blame] | 2804 | NUMA_NO_NODE); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2805 | if (!txq->q.desc) |
| 2806 | return -ENOMEM; |
| 2807 | |
| 2808 | memset(&c, 0, sizeof(c)); |
Hariprasad Shenai | e2ac962 | 2014-11-07 09:35:25 +0530 | [diff] [blame] | 2809 | c.op_to_vfn = htonl(FW_CMD_OP_V(FW_EQ_OFLD_CMD) | FW_CMD_REQUEST_F | |
| 2810 | FW_CMD_WRITE_F | FW_CMD_EXEC_F | |
Hariprasad Shenai | b261272 | 2015-05-27 22:30:24 +0530 | [diff] [blame] | 2811 | FW_EQ_OFLD_CMD_PFN_V(adap->pf) | |
Hariprasad Shenai | 6e4b51a | 2014-11-21 12:52:03 +0530 | [diff] [blame] | 2812 | FW_EQ_OFLD_CMD_VFN_V(0)); |
| 2813 | c.alloc_to_len16 = htonl(FW_EQ_OFLD_CMD_ALLOC_F | |
| 2814 | FW_EQ_OFLD_CMD_EQSTART_F | FW_LEN16(c)); |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 2815 | c.fetchszm_to_iqid = |
| 2816 | htonl(FW_EQ_OFLD_CMD_HOSTFCMODE_V(HOSTFCMODE_STATUS_PAGE_X) | |
| 2817 | FW_EQ_OFLD_CMD_PCIECHN_V(pi->tx_chan) | |
| 2818 | FW_EQ_OFLD_CMD_FETCHRO_F | FW_EQ_OFLD_CMD_IQID_V(iqid)); |
| 2819 | c.dcaen_to_eqsize = |
| 2820 | htonl(FW_EQ_OFLD_CMD_FBMIN_V(FETCHBURSTMIN_64B_X) | |
| 2821 | FW_EQ_OFLD_CMD_FBMAX_V(FETCHBURSTMAX_512B_X) | |
| 2822 | FW_EQ_OFLD_CMD_CIDXFTHRESH_V(CIDXFLUSHTHRESH_32_X) | |
| 2823 | FW_EQ_OFLD_CMD_EQSIZE_V(nentries)); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2824 | c.eqaddr = cpu_to_be64(txq->q.phys_addr); |
| 2825 | |
Hariprasad Shenai | b261272 | 2015-05-27 22:30:24 +0530 | [diff] [blame] | 2826 | ret = t4_wr_mbox(adap, adap->mbox, &c, sizeof(c), &c); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2827 | if (ret) { |
| 2828 | kfree(txq->q.sdesc); |
| 2829 | txq->q.sdesc = NULL; |
| 2830 | dma_free_coherent(adap->pdev_dev, |
| 2831 | nentries * sizeof(struct tx_desc), |
| 2832 | txq->q.desc, txq->q.phys_addr); |
| 2833 | txq->q.desc = NULL; |
| 2834 | return ret; |
| 2835 | } |
| 2836 | |
Hariprasad Shenai | 6e4b51a | 2014-11-21 12:52:03 +0530 | [diff] [blame] | 2837 | init_txq(adap, &txq->q, FW_EQ_OFLD_CMD_EQID_G(ntohl(c.eqid_pkd))); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2838 | txq->adap = adap; |
| 2839 | skb_queue_head_init(&txq->sendq); |
| 2840 | tasklet_init(&txq->qresume_tsk, restart_ofldq, (unsigned long)txq); |
| 2841 | txq->full = 0; |
| 2842 | txq->mapping_err = 0; |
| 2843 | return 0; |
| 2844 | } |
| 2845 | |
| 2846 | static void free_txq(struct adapter *adap, struct sge_txq *q) |
| 2847 | { |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 2848 | struct sge *s = &adap->sge; |
| 2849 | |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2850 | dma_free_coherent(adap->pdev_dev, |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 2851 | q->size * sizeof(struct tx_desc) + s->stat_len, |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2852 | q->desc, q->phys_addr); |
| 2853 | q->cntxt_id = 0; |
| 2854 | q->sdesc = NULL; |
| 2855 | q->desc = NULL; |
| 2856 | } |
| 2857 | |
| 2858 | static void free_rspq_fl(struct adapter *adap, struct sge_rspq *rq, |
| 2859 | struct sge_fl *fl) |
| 2860 | { |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 2861 | struct sge *s = &adap->sge; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2862 | unsigned int fl_id = fl ? fl->cntxt_id : 0xffff; |
| 2863 | |
Dimitris Michailidis | e46dab4 | 2010-08-23 17:20:58 +0000 | [diff] [blame] | 2864 | adap->sge.ingr_map[rq->cntxt_id - adap->sge.ingr_start] = NULL; |
Hariprasad Shenai | b261272 | 2015-05-27 22:30:24 +0530 | [diff] [blame] | 2865 | t4_iq_free(adap, adap->mbox, adap->pf, 0, FW_IQ_TYPE_FL_INT_CAP, |
Dimitris Michailidis | 060e0c7 | 2010-08-02 13:19:21 +0000 | [diff] [blame] | 2866 | rq->cntxt_id, fl_id, 0xffff); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2867 | dma_free_coherent(adap->pdev_dev, (rq->size + 1) * rq->iqe_len, |
| 2868 | rq->desc, rq->phys_addr); |
Hariprasad Shenai | 3a336cb | 2015-02-04 15:32:52 +0530 | [diff] [blame] | 2869 | napi_hash_del(&rq->napi); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2870 | netif_napi_del(&rq->napi); |
| 2871 | rq->netdev = NULL; |
| 2872 | rq->cntxt_id = rq->abs_id = 0; |
| 2873 | rq->desc = NULL; |
| 2874 | |
| 2875 | if (fl) { |
| 2876 | free_rx_bufs(adap, fl, fl->avail); |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 2877 | dma_free_coherent(adap->pdev_dev, fl->size * 8 + s->stat_len, |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2878 | fl->desc, fl->addr); |
| 2879 | kfree(fl->sdesc); |
| 2880 | fl->sdesc = NULL; |
| 2881 | fl->cntxt_id = 0; |
| 2882 | fl->desc = NULL; |
| 2883 | } |
| 2884 | } |
| 2885 | |
| 2886 | /** |
Hariprasad Shenai | 5fa7669 | 2014-08-04 17:01:30 +0530 | [diff] [blame] | 2887 | * t4_free_ofld_rxqs - free a block of consecutive Rx queues |
| 2888 | * @adap: the adapter |
| 2889 | * @n: number of queues |
| 2890 | * @q: pointer to first queue |
| 2891 | * |
| 2892 | * Release the resources of a consecutive block of offload Rx queues. |
| 2893 | */ |
| 2894 | void t4_free_ofld_rxqs(struct adapter *adap, int n, struct sge_ofld_rxq *q) |
| 2895 | { |
| 2896 | for ( ; n; n--, q++) |
| 2897 | if (q->rspq.desc) |
| 2898 | free_rspq_fl(adap, &q->rspq, |
| 2899 | q->fl.size ? &q->fl : NULL); |
| 2900 | } |
| 2901 | |
| 2902 | /** |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2903 | * t4_free_sge_resources - free SGE resources |
| 2904 | * @adap: the adapter |
| 2905 | * |
| 2906 | * Frees resources used by the SGE queue sets. |
| 2907 | */ |
| 2908 | void t4_free_sge_resources(struct adapter *adap) |
| 2909 | { |
| 2910 | int i; |
| 2911 | struct sge_eth_rxq *eq = adap->sge.ethrxq; |
| 2912 | struct sge_eth_txq *etq = adap->sge.ethtxq; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2913 | |
| 2914 | /* clean up Ethernet Tx/Rx queues */ |
| 2915 | for (i = 0; i < adap->sge.ethqsets; i++, eq++, etq++) { |
| 2916 | if (eq->rspq.desc) |
Hariprasad Shenai | 5fa7669 | 2014-08-04 17:01:30 +0530 | [diff] [blame] | 2917 | free_rspq_fl(adap, &eq->rspq, |
| 2918 | eq->fl.size ? &eq->fl : NULL); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2919 | if (etq->q.desc) { |
Hariprasad Shenai | b261272 | 2015-05-27 22:30:24 +0530 | [diff] [blame] | 2920 | t4_eth_eq_free(adap, adap->mbox, adap->pf, 0, |
Dimitris Michailidis | 060e0c7 | 2010-08-02 13:19:21 +0000 | [diff] [blame] | 2921 | etq->q.cntxt_id); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2922 | free_tx_desc(adap, &etq->q, etq->q.in_use, true); |
| 2923 | kfree(etq->q.sdesc); |
| 2924 | free_txq(adap, &etq->q); |
| 2925 | } |
| 2926 | } |
| 2927 | |
| 2928 | /* clean up RDMA and iSCSI Rx queues */ |
Hariprasad Shenai | 5fa7669 | 2014-08-04 17:01:30 +0530 | [diff] [blame] | 2929 | t4_free_ofld_rxqs(adap, adap->sge.ofldqsets, adap->sge.ofldrxq); |
| 2930 | t4_free_ofld_rxqs(adap, adap->sge.rdmaqs, adap->sge.rdmarxq); |
| 2931 | t4_free_ofld_rxqs(adap, adap->sge.rdmaciqs, adap->sge.rdmaciq); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2932 | |
| 2933 | /* clean up offload Tx queues */ |
| 2934 | for (i = 0; i < ARRAY_SIZE(adap->sge.ofldtxq); i++) { |
| 2935 | struct sge_ofld_txq *q = &adap->sge.ofldtxq[i]; |
| 2936 | |
| 2937 | if (q->q.desc) { |
| 2938 | tasklet_kill(&q->qresume_tsk); |
Hariprasad Shenai | b261272 | 2015-05-27 22:30:24 +0530 | [diff] [blame] | 2939 | t4_ofld_eq_free(adap, adap->mbox, adap->pf, 0, |
Dimitris Michailidis | 060e0c7 | 2010-08-02 13:19:21 +0000 | [diff] [blame] | 2940 | q->q.cntxt_id); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2941 | free_tx_desc(adap, &q->q, q->q.in_use, false); |
| 2942 | kfree(q->q.sdesc); |
| 2943 | __skb_queue_purge(&q->sendq); |
| 2944 | free_txq(adap, &q->q); |
| 2945 | } |
| 2946 | } |
| 2947 | |
| 2948 | /* clean up control Tx queues */ |
| 2949 | for (i = 0; i < ARRAY_SIZE(adap->sge.ctrlq); i++) { |
| 2950 | struct sge_ctrl_txq *cq = &adap->sge.ctrlq[i]; |
| 2951 | |
| 2952 | if (cq->q.desc) { |
| 2953 | tasklet_kill(&cq->qresume_tsk); |
Hariprasad Shenai | b261272 | 2015-05-27 22:30:24 +0530 | [diff] [blame] | 2954 | t4_ctrl_eq_free(adap, adap->mbox, adap->pf, 0, |
Dimitris Michailidis | 060e0c7 | 2010-08-02 13:19:21 +0000 | [diff] [blame] | 2955 | cq->q.cntxt_id); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2956 | __skb_queue_purge(&cq->sendq); |
| 2957 | free_txq(adap, &cq->q); |
| 2958 | } |
| 2959 | } |
| 2960 | |
| 2961 | if (adap->sge.fw_evtq.desc) |
| 2962 | free_rspq_fl(adap, &adap->sge.fw_evtq, NULL); |
| 2963 | |
| 2964 | if (adap->sge.intrq.desc) |
| 2965 | free_rspq_fl(adap, &adap->sge.intrq, NULL); |
| 2966 | |
| 2967 | /* clear the reverse egress queue map */ |
Hariprasad Shenai | 4b8e27a | 2015-03-26 10:04:25 +0530 | [diff] [blame] | 2968 | memset(adap->sge.egr_map, 0, |
| 2969 | adap->sge.egr_sz * sizeof(*adap->sge.egr_map)); |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 2970 | } |
| 2971 | |
| 2972 | void t4_sge_start(struct adapter *adap) |
| 2973 | { |
| 2974 | adap->sge.ethtxq_rover = 0; |
| 2975 | mod_timer(&adap->sge.rx_timer, jiffies + RX_QCHECK_PERIOD); |
| 2976 | mod_timer(&adap->sge.tx_timer, jiffies + TX_QCHECK_PERIOD); |
| 2977 | } |
| 2978 | |
| 2979 | /** |
| 2980 | * t4_sge_stop - disable SGE operation |
| 2981 | * @adap: the adapter |
| 2982 | * |
| 2983 | * Stop tasklets and timers associated with the DMA engine. Note that |
| 2984 | * this is effective only if measures have been taken to disable any HW |
| 2985 | * events that may restart them. |
| 2986 | */ |
| 2987 | void t4_sge_stop(struct adapter *adap) |
| 2988 | { |
| 2989 | int i; |
| 2990 | struct sge *s = &adap->sge; |
| 2991 | |
| 2992 | if (in_interrupt()) /* actions below require waiting */ |
| 2993 | return; |
| 2994 | |
| 2995 | if (s->rx_timer.function) |
| 2996 | del_timer_sync(&s->rx_timer); |
| 2997 | if (s->tx_timer.function) |
| 2998 | del_timer_sync(&s->tx_timer); |
| 2999 | |
| 3000 | for (i = 0; i < ARRAY_SIZE(s->ofldtxq); i++) { |
| 3001 | struct sge_ofld_txq *q = &s->ofldtxq[i]; |
| 3002 | |
| 3003 | if (q->q.desc) |
| 3004 | tasklet_kill(&q->qresume_tsk); |
| 3005 | } |
| 3006 | for (i = 0; i < ARRAY_SIZE(s->ctrlq); i++) { |
| 3007 | struct sge_ctrl_txq *cq = &s->ctrlq[i]; |
| 3008 | |
| 3009 | if (cq->q.desc) |
| 3010 | tasklet_kill(&cq->qresume_tsk); |
| 3011 | } |
| 3012 | } |
| 3013 | |
| 3014 | /** |
Hariprasad Shenai | 0664031 | 2015-01-13 15:19:25 +0530 | [diff] [blame] | 3015 | * t4_sge_init_soft - grab core SGE values needed by SGE code |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 3016 | * @adap: the adapter |
| 3017 | * |
Hariprasad Shenai | 0664031 | 2015-01-13 15:19:25 +0530 | [diff] [blame] | 3018 | * We need to grab the SGE operating parameters that we need to have |
| 3019 | * in order to do our job and make sure we can live with them. |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 3020 | */ |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 3021 | |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 3022 | static int t4_sge_init_soft(struct adapter *adap) |
| 3023 | { |
| 3024 | struct sge *s = &adap->sge; |
| 3025 | u32 fl_small_pg, fl_large_pg, fl_small_mtu, fl_large_mtu; |
| 3026 | u32 timer_value_0_and_1, timer_value_2_and_3, timer_value_4_and_5; |
| 3027 | u32 ingress_rx_threshold; |
| 3028 | |
| 3029 | /* |
| 3030 | * Verify that CPL messages are going to the Ingress Queue for |
| 3031 | * process_responses() and that only packet data is going to the |
| 3032 | * Free Lists. |
| 3033 | */ |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 3034 | if ((t4_read_reg(adap, SGE_CONTROL_A) & RXPKTCPLMODE_F) != |
| 3035 | RXPKTCPLMODE_V(RXPKTCPLMODE_SPLIT_X)) { |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 3036 | dev_err(adap->pdev_dev, "bad SGE CPL MODE\n"); |
| 3037 | return -EINVAL; |
| 3038 | } |
| 3039 | |
| 3040 | /* |
| 3041 | * Validate the Host Buffer Register Array indices that we want to |
| 3042 | * use ... |
| 3043 | * |
| 3044 | * XXX Note that we should really read through the Host Buffer Size |
| 3045 | * XXX register array and find the indices of the Buffer Sizes which |
| 3046 | * XXX meet our needs! |
| 3047 | */ |
| 3048 | #define READ_FL_BUF(x) \ |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 3049 | t4_read_reg(adap, SGE_FL_BUFFER_SIZE0_A+(x)*sizeof(u32)) |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 3050 | |
| 3051 | fl_small_pg = READ_FL_BUF(RX_SMALL_PG_BUF); |
| 3052 | fl_large_pg = READ_FL_BUF(RX_LARGE_PG_BUF); |
| 3053 | fl_small_mtu = READ_FL_BUF(RX_SMALL_MTU_BUF); |
| 3054 | fl_large_mtu = READ_FL_BUF(RX_LARGE_MTU_BUF); |
| 3055 | |
Kumar Sanghvi | 92ddcc7 | 2014-03-13 20:50:46 +0530 | [diff] [blame] | 3056 | /* We only bother using the Large Page logic if the Large Page Buffer |
| 3057 | * is larger than our Page Size Buffer. |
| 3058 | */ |
| 3059 | if (fl_large_pg <= fl_small_pg) |
| 3060 | fl_large_pg = 0; |
| 3061 | |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 3062 | #undef READ_FL_BUF |
| 3063 | |
Kumar Sanghvi | 92ddcc7 | 2014-03-13 20:50:46 +0530 | [diff] [blame] | 3064 | /* The Page Size Buffer must be exactly equal to our Page Size and the |
| 3065 | * Large Page Size Buffer should be 0 (per above) or a power of 2. |
| 3066 | */ |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 3067 | if (fl_small_pg != PAGE_SIZE || |
Kumar Sanghvi | 92ddcc7 | 2014-03-13 20:50:46 +0530 | [diff] [blame] | 3068 | (fl_large_pg & (fl_large_pg-1)) != 0) { |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 3069 | dev_err(adap->pdev_dev, "bad SGE FL page buffer sizes [%d, %d]\n", |
| 3070 | fl_small_pg, fl_large_pg); |
| 3071 | return -EINVAL; |
| 3072 | } |
| 3073 | if (fl_large_pg) |
| 3074 | s->fl_pg_order = ilog2(fl_large_pg) - PAGE_SHIFT; |
| 3075 | |
| 3076 | if (fl_small_mtu < FL_MTU_SMALL_BUFSIZE(adap) || |
| 3077 | fl_large_mtu < FL_MTU_LARGE_BUFSIZE(adap)) { |
| 3078 | dev_err(adap->pdev_dev, "bad SGE FL MTU sizes [%d, %d]\n", |
| 3079 | fl_small_mtu, fl_large_mtu); |
| 3080 | return -EINVAL; |
| 3081 | } |
| 3082 | |
| 3083 | /* |
| 3084 | * Retrieve our RX interrupt holdoff timer values and counter |
| 3085 | * threshold values from the SGE parameters. |
| 3086 | */ |
Hariprasad Shenai | f061de4 | 2015-01-05 16:30:44 +0530 | [diff] [blame] | 3087 | timer_value_0_and_1 = t4_read_reg(adap, SGE_TIMER_VALUE_0_AND_1_A); |
| 3088 | timer_value_2_and_3 = t4_read_reg(adap, SGE_TIMER_VALUE_2_AND_3_A); |
| 3089 | timer_value_4_and_5 = t4_read_reg(adap, SGE_TIMER_VALUE_4_AND_5_A); |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 3090 | s->timer_val[0] = core_ticks_to_us(adap, |
Hariprasad Shenai | f061de4 | 2015-01-05 16:30:44 +0530 | [diff] [blame] | 3091 | TIMERVALUE0_G(timer_value_0_and_1)); |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 3092 | s->timer_val[1] = core_ticks_to_us(adap, |
Hariprasad Shenai | f061de4 | 2015-01-05 16:30:44 +0530 | [diff] [blame] | 3093 | TIMERVALUE1_G(timer_value_0_and_1)); |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 3094 | s->timer_val[2] = core_ticks_to_us(adap, |
Hariprasad Shenai | f061de4 | 2015-01-05 16:30:44 +0530 | [diff] [blame] | 3095 | TIMERVALUE2_G(timer_value_2_and_3)); |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 3096 | s->timer_val[3] = core_ticks_to_us(adap, |
Hariprasad Shenai | f061de4 | 2015-01-05 16:30:44 +0530 | [diff] [blame] | 3097 | TIMERVALUE3_G(timer_value_2_and_3)); |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 3098 | s->timer_val[4] = core_ticks_to_us(adap, |
Hariprasad Shenai | f061de4 | 2015-01-05 16:30:44 +0530 | [diff] [blame] | 3099 | TIMERVALUE4_G(timer_value_4_and_5)); |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 3100 | s->timer_val[5] = core_ticks_to_us(adap, |
Hariprasad Shenai | f061de4 | 2015-01-05 16:30:44 +0530 | [diff] [blame] | 3101 | TIMERVALUE5_G(timer_value_4_and_5)); |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 3102 | |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 3103 | ingress_rx_threshold = t4_read_reg(adap, SGE_INGRESS_RX_THRESHOLD_A); |
| 3104 | s->counter_val[0] = THRESHOLD_0_G(ingress_rx_threshold); |
| 3105 | s->counter_val[1] = THRESHOLD_1_G(ingress_rx_threshold); |
| 3106 | s->counter_val[2] = THRESHOLD_2_G(ingress_rx_threshold); |
| 3107 | s->counter_val[3] = THRESHOLD_3_G(ingress_rx_threshold); |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 3108 | |
| 3109 | return 0; |
| 3110 | } |
| 3111 | |
Hariprasad Shenai | 0664031 | 2015-01-13 15:19:25 +0530 | [diff] [blame] | 3112 | /** |
| 3113 | * t4_sge_init - initialize SGE |
| 3114 | * @adap: the adapter |
| 3115 | * |
| 3116 | * Perform low-level SGE code initialization needed every time after a |
| 3117 | * chip reset. |
| 3118 | */ |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 3119 | int t4_sge_init(struct adapter *adap) |
| 3120 | { |
| 3121 | struct sge *s = &adap->sge; |
Hariprasad Shenai | ce8f407 | 2014-11-07 17:06:30 +0530 | [diff] [blame] | 3122 | u32 sge_control, sge_control2, sge_conm_ctrl; |
| 3123 | unsigned int ingpadboundary, ingpackboundary; |
Kumar Sanghvi | c2b955e | 2014-03-13 20:50:49 +0530 | [diff] [blame] | 3124 | int ret, egress_threshold; |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 3125 | |
| 3126 | /* |
| 3127 | * Ingress Padding Boundary and Egress Status Page Size are set up by |
| 3128 | * t4_fixup_host_params(). |
| 3129 | */ |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 3130 | sge_control = t4_read_reg(adap, SGE_CONTROL_A); |
| 3131 | s->pktshift = PKTSHIFT_G(sge_control); |
| 3132 | s->stat_len = (sge_control & EGRSTATUSPAGESIZE_F) ? 128 : 64; |
Hariprasad Shenai | ce8f407 | 2014-11-07 17:06:30 +0530 | [diff] [blame] | 3133 | |
| 3134 | /* T4 uses a single control field to specify both the PCIe Padding and |
| 3135 | * Packing Boundary. T5 introduced the ability to specify these |
| 3136 | * separately. The actual Ingress Packet Data alignment boundary |
| 3137 | * within Packed Buffer Mode is the maximum of these two |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 3138 | * specifications. (Note that it makes no real practical sense to |
| 3139 | * have the Pading Boudary be larger than the Packing Boundary but you |
| 3140 | * could set the chip up that way and, in fact, legacy T4 code would |
| 3141 | * end doing this because it would initialize the Padding Boundary and |
| 3142 | * leave the Packing Boundary initialized to 0 (16 bytes).) |
Hariprasad Shenai | ce8f407 | 2014-11-07 17:06:30 +0530 | [diff] [blame] | 3143 | */ |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 3144 | ingpadboundary = 1 << (INGPADBOUNDARY_G(sge_control) + |
| 3145 | INGPADBOUNDARY_SHIFT_X); |
Hariprasad Shenai | ce8f407 | 2014-11-07 17:06:30 +0530 | [diff] [blame] | 3146 | if (is_t4(adap->params.chip)) { |
| 3147 | s->fl_align = ingpadboundary; |
| 3148 | } else { |
| 3149 | /* T5 has a different interpretation of one of the PCIe Packing |
| 3150 | * Boundary values. |
| 3151 | */ |
| 3152 | sge_control2 = t4_read_reg(adap, SGE_CONTROL2_A); |
| 3153 | ingpackboundary = INGPACKBOUNDARY_G(sge_control2); |
| 3154 | if (ingpackboundary == INGPACKBOUNDARY_16B_X) |
| 3155 | ingpackboundary = 16; |
| 3156 | else |
| 3157 | ingpackboundary = 1 << (ingpackboundary + |
| 3158 | INGPACKBOUNDARY_SHIFT_X); |
| 3159 | |
| 3160 | s->fl_align = max(ingpadboundary, ingpackboundary); |
| 3161 | } |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 3162 | |
Hariprasad Shenai | 0664031 | 2015-01-13 15:19:25 +0530 | [diff] [blame] | 3163 | ret = t4_sge_init_soft(adap); |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 3164 | if (ret < 0) |
| 3165 | return ret; |
| 3166 | |
| 3167 | /* |
| 3168 | * A FL with <= fl_starve_thres buffers is starving and a periodic |
| 3169 | * timer will attempt to refill it. This needs to be larger than the |
| 3170 | * SGE's Egress Congestion Threshold. If it isn't, then we can get |
| 3171 | * stuck waiting for new packets while the SGE is waiting for us to |
| 3172 | * give it more Free List entries. (Note that the SGE's Egress |
Kumar Sanghvi | c2b955e | 2014-03-13 20:50:49 +0530 | [diff] [blame] | 3173 | * Congestion Threshold is in units of 2 Free List pointers.) For T4, |
| 3174 | * there was only a single field to control this. For T5 there's the |
| 3175 | * original field which now only applies to Unpacked Mode Free List |
| 3176 | * buffers and a new field which only applies to Packed Mode Free List |
| 3177 | * buffers. |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 3178 | */ |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 3179 | sge_conm_ctrl = t4_read_reg(adap, SGE_CONM_CTRL_A); |
Kumar Sanghvi | c2b955e | 2014-03-13 20:50:49 +0530 | [diff] [blame] | 3180 | if (is_t4(adap->params.chip)) |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 3181 | egress_threshold = EGRTHRESHOLD_G(sge_conm_ctrl); |
Kumar Sanghvi | c2b955e | 2014-03-13 20:50:49 +0530 | [diff] [blame] | 3182 | else |
Hariprasad Shenai | f612b81 | 2015-01-05 16:30:43 +0530 | [diff] [blame] | 3183 | egress_threshold = EGRTHRESHOLDPACKING_G(sge_conm_ctrl); |
Kumar Sanghvi | c2b955e | 2014-03-13 20:50:49 +0530 | [diff] [blame] | 3184 | s->fl_starve_thres = 2*egress_threshold + 1; |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 3185 | |
Hariprasad Shenai | a3bfb61 | 2015-05-05 14:59:55 +0530 | [diff] [blame] | 3186 | t4_idma_monitor_init(adap, &s->idma_monitor); |
| 3187 | |
Hariprasad Shenai | 1ecc7b7 | 2015-05-12 04:43:43 +0530 | [diff] [blame] | 3188 | /* Set up timers used for recuring callbacks to process RX and TX |
| 3189 | * administrative tasks. |
| 3190 | */ |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 3191 | setup_timer(&s->rx_timer, sge_rx_timer_cb, (unsigned long)adap); |
| 3192 | setup_timer(&s->tx_timer, sge_tx_timer_cb, (unsigned long)adap); |
Hariprasad Shenai | a3bfb61 | 2015-05-05 14:59:55 +0530 | [diff] [blame] | 3193 | |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 3194 | spin_lock_init(&s->intrq_lock); |
Vipul Pandya | 52367a7 | 2012-09-26 02:39:38 +0000 | [diff] [blame] | 3195 | |
| 3196 | return 0; |
Dimitris Michailidis | fd3a479 | 2010-04-01 15:28:24 +0000 | [diff] [blame] | 3197 | } |