Imported Upstream version 16.04
[deb_dpdk.git] / drivers / net / fm10k / fm10k_rxtx.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <inttypes.h>
35
36 #include <rte_ethdev.h>
37 #include <rte_common.h>
38 #include "fm10k.h"
39 #include "base/fm10k_type.h"
40
41 #ifdef RTE_PMD_PACKET_PREFETCH
42 #define rte_packet_prefetch(p)  rte_prefetch1(p)
43 #else
44 #define rte_packet_prefetch(p)  do {} while (0)
45 #endif
46
47 #ifdef RTE_LIBRTE_FM10K_DEBUG_RX
48 static inline void dump_rxd(union fm10k_rx_desc *rxd)
49 {
50         PMD_RX_LOG(DEBUG, "+----------------|----------------+");
51         PMD_RX_LOG(DEBUG, "|     GLORT      | PKT HDR & TYPE |");
52         PMD_RX_LOG(DEBUG, "|   0x%08x   |   0x%08x   |", rxd->d.glort,
53                         rxd->d.data);
54         PMD_RX_LOG(DEBUG, "+----------------|----------------+");
55         PMD_RX_LOG(DEBUG, "|   VLAN & LEN   |     STATUS     |");
56         PMD_RX_LOG(DEBUG, "|   0x%08x   |   0x%08x   |", rxd->d.vlan_len,
57                         rxd->d.staterr);
58         PMD_RX_LOG(DEBUG, "+----------------|----------------+");
59         PMD_RX_LOG(DEBUG, "|    RESERVED    |    RSS_HASH    |");
60         PMD_RX_LOG(DEBUG, "|   0x%08x   |   0x%08x   |", 0, rxd->d.rss);
61         PMD_RX_LOG(DEBUG, "+----------------|----------------+");
62         PMD_RX_LOG(DEBUG, "|            TIME TAG             |");
63         PMD_RX_LOG(DEBUG, "|       0x%016"PRIx64"        |", rxd->q.timestamp);
64         PMD_RX_LOG(DEBUG, "+----------------|----------------+");
65 }
66 #endif
67
68 /* @note: When this function is changed, make corresponding change to
69  * fm10k_dev_supported_ptypes_get()
70  */
71 static inline void
72 rx_desc_to_ol_flags(struct rte_mbuf *m, const union fm10k_rx_desc *d)
73 {
74         static const uint32_t
75                 ptype_table[FM10K_RXD_PKTTYPE_MASK >> FM10K_RXD_PKTTYPE_SHIFT]
76                         __rte_cache_aligned = {
77                 [FM10K_PKTTYPE_OTHER] = RTE_PTYPE_L2_ETHER,
78                 [FM10K_PKTTYPE_IPV4] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4,
79                 [FM10K_PKTTYPE_IPV4_EX] = RTE_PTYPE_L2_ETHER |
80                         RTE_PTYPE_L3_IPV4_EXT,
81                 [FM10K_PKTTYPE_IPV6] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6,
82                 [FM10K_PKTTYPE_IPV6_EX] = RTE_PTYPE_L2_ETHER |
83                         RTE_PTYPE_L3_IPV6_EXT,
84                 [FM10K_PKTTYPE_IPV4 | FM10K_PKTTYPE_TCP] = RTE_PTYPE_L2_ETHER |
85                         RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP,
86                 [FM10K_PKTTYPE_IPV6 | FM10K_PKTTYPE_TCP] = RTE_PTYPE_L2_ETHER |
87                         RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_TCP,
88                 [FM10K_PKTTYPE_IPV4 | FM10K_PKTTYPE_UDP] = RTE_PTYPE_L2_ETHER |
89                         RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_UDP,
90                 [FM10K_PKTTYPE_IPV6 | FM10K_PKTTYPE_UDP] = RTE_PTYPE_L2_ETHER |
91                         RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_UDP,
92         };
93
94         m->packet_type = ptype_table[(d->w.pkt_info & FM10K_RXD_PKTTYPE_MASK)
95                                                 >> FM10K_RXD_PKTTYPE_SHIFT];
96
97         if (d->w.pkt_info & FM10K_RXD_RSSTYPE_MASK)
98                 m->ol_flags |= PKT_RX_RSS_HASH;
99
100         if (unlikely((d->d.staterr &
101                 (FM10K_RXD_STATUS_IPCS | FM10K_RXD_STATUS_IPE)) ==
102                 (FM10K_RXD_STATUS_IPCS | FM10K_RXD_STATUS_IPE)))
103                 m->ol_flags |= PKT_RX_IP_CKSUM_BAD;
104
105         if (unlikely((d->d.staterr &
106                 (FM10K_RXD_STATUS_L4CS | FM10K_RXD_STATUS_L4E)) ==
107                 (FM10K_RXD_STATUS_L4CS | FM10K_RXD_STATUS_L4E)))
108                 m->ol_flags |= PKT_RX_L4_CKSUM_BAD;
109
110         if (unlikely(d->d.staterr & FM10K_RXD_STATUS_HBO))
111                 m->ol_flags |= PKT_RX_HBUF_OVERFLOW;
112
113         if (unlikely(d->d.staterr & FM10K_RXD_STATUS_RXE))
114                 m->ol_flags |= PKT_RX_RECIP_ERR;
115 }
116
117 uint16_t
118 fm10k_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
119         uint16_t nb_pkts)
120 {
121         struct rte_mbuf *mbuf;
122         union fm10k_rx_desc desc;
123         struct fm10k_rx_queue *q = rx_queue;
124         uint16_t count = 0;
125         int alloc = 0;
126         uint16_t next_dd;
127         int ret;
128
129         next_dd = q->next_dd;
130
131         nb_pkts = RTE_MIN(nb_pkts, q->alloc_thresh);
132         for (count = 0; count < nb_pkts; ++count) {
133                 mbuf = q->sw_ring[next_dd];
134                 desc = q->hw_ring[next_dd];
135                 if (!(desc.d.staterr & FM10K_RXD_STATUS_DD))
136                         break;
137 #ifdef RTE_LIBRTE_FM10K_DEBUG_RX
138                 dump_rxd(&desc);
139 #endif
140                 rte_pktmbuf_pkt_len(mbuf) = desc.w.length;
141                 rte_pktmbuf_data_len(mbuf) = desc.w.length;
142
143                 mbuf->ol_flags = 0;
144 #ifdef RTE_LIBRTE_FM10K_RX_OLFLAGS_ENABLE
145                 rx_desc_to_ol_flags(mbuf, &desc);
146 #endif
147
148                 mbuf->hash.rss = desc.d.rss;
149                 /**
150                  * Packets in fm10k device always carry at least one VLAN tag.
151                  * For those packets coming in without VLAN tag,
152                  * the port default VLAN tag will be used.
153                  * So, always PKT_RX_VLAN_PKT flag is set and vlan_tci
154                  * is valid for each RX packet's mbuf.
155                  */
156                 mbuf->ol_flags |= PKT_RX_VLAN_PKT;
157                 mbuf->vlan_tci = desc.w.vlan;
158                 /**
159                  * mbuf->vlan_tci_outer is an idle field in fm10k driver,
160                  * so it can be selected to store sglort value.
161                  */
162                 if (q->rx_ftag_en)
163                         mbuf->vlan_tci_outer = rte_le_to_cpu_16(desc.w.sglort);
164
165                 rx_pkts[count] = mbuf;
166                 if (++next_dd == q->nb_desc) {
167                         next_dd = 0;
168                         alloc = 1;
169                 }
170
171                 /* Prefetch next mbuf while processing current one. */
172                 rte_prefetch0(q->sw_ring[next_dd]);
173
174                 /*
175                  * When next RX descriptor is on a cache-line boundary,
176                  * prefetch the next 4 RX descriptors and the next 8 pointers
177                  * to mbufs.
178                  */
179                 if ((next_dd & 0x3) == 0) {
180                         rte_prefetch0(&q->hw_ring[next_dd]);
181                         rte_prefetch0(&q->sw_ring[next_dd]);
182                 }
183         }
184
185         q->next_dd = next_dd;
186
187         if ((q->next_dd > q->next_trigger) || (alloc == 1)) {
188                 ret = rte_mempool_get_bulk(q->mp,
189                                         (void **)&q->sw_ring[q->next_alloc],
190                                         q->alloc_thresh);
191
192                 if (unlikely(ret != 0)) {
193                         uint8_t port = q->port_id;
194                         PMD_RX_LOG(ERR, "Failed to alloc mbuf");
195                         /*
196                          * Need to restore next_dd if we cannot allocate new
197                          * buffers to replenish the old ones.
198                          */
199                         q->next_dd = (q->next_dd + q->nb_desc - count) %
200                                                                 q->nb_desc;
201                         rte_eth_devices[port].data->rx_mbuf_alloc_failed++;
202                         return 0;
203                 }
204
205                 for (; q->next_alloc <= q->next_trigger; ++q->next_alloc) {
206                         mbuf = q->sw_ring[q->next_alloc];
207
208                         /* setup static mbuf fields */
209                         fm10k_pktmbuf_reset(mbuf, q->port_id);
210
211                         /* write descriptor */
212                         desc.q.pkt_addr = MBUF_DMA_ADDR_DEFAULT(mbuf);
213                         desc.q.hdr_addr = MBUF_DMA_ADDR_DEFAULT(mbuf);
214                         q->hw_ring[q->next_alloc] = desc;
215                 }
216                 FM10K_PCI_REG_WRITE(q->tail_ptr, q->next_trigger);
217                 q->next_trigger += q->alloc_thresh;
218                 if (q->next_trigger >= q->nb_desc) {
219                         q->next_trigger = q->alloc_thresh - 1;
220                         q->next_alloc = 0;
221                 }
222         }
223
224         return count;
225 }
226
227 uint16_t
228 fm10k_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
229                                 uint16_t nb_pkts)
230 {
231         struct rte_mbuf *mbuf;
232         union fm10k_rx_desc desc;
233         struct fm10k_rx_queue *q = rx_queue;
234         uint16_t count = 0;
235         uint16_t nb_rcv, nb_seg;
236         int alloc = 0;
237         uint16_t next_dd;
238         struct rte_mbuf *first_seg = q->pkt_first_seg;
239         struct rte_mbuf *last_seg = q->pkt_last_seg;
240         int ret;
241
242         next_dd = q->next_dd;
243         nb_rcv = 0;
244
245         nb_seg = RTE_MIN(nb_pkts, q->alloc_thresh);
246         for (count = 0; count < nb_seg; count++) {
247                 mbuf = q->sw_ring[next_dd];
248                 desc = q->hw_ring[next_dd];
249                 if (!(desc.d.staterr & FM10K_RXD_STATUS_DD))
250                         break;
251 #ifdef RTE_LIBRTE_FM10K_DEBUG_RX
252                 dump_rxd(&desc);
253 #endif
254
255                 if (++next_dd == q->nb_desc) {
256                         next_dd = 0;
257                         alloc = 1;
258                 }
259
260                 /* Prefetch next mbuf while processing current one. */
261                 rte_prefetch0(q->sw_ring[next_dd]);
262
263                 /*
264                  * When next RX descriptor is on a cache-line boundary,
265                  * prefetch the next 4 RX descriptors and the next 8 pointers
266                  * to mbufs.
267                  */
268                 if ((next_dd & 0x3) == 0) {
269                         rte_prefetch0(&q->hw_ring[next_dd]);
270                         rte_prefetch0(&q->sw_ring[next_dd]);
271                 }
272
273                 /* Fill data length */
274                 rte_pktmbuf_data_len(mbuf) = desc.w.length;
275
276                 /*
277                  * If this is the first buffer of the received packet,
278                  * set the pointer to the first mbuf of the packet and
279                  * initialize its context.
280                  * Otherwise, update the total length and the number of segments
281                  * of the current scattered packet, and update the pointer to
282                  * the last mbuf of the current packet.
283                  */
284                 if (!first_seg) {
285                         first_seg = mbuf;
286                         first_seg->pkt_len = desc.w.length;
287                 } else {
288                         first_seg->pkt_len =
289                                         (uint16_t)(first_seg->pkt_len +
290                                         rte_pktmbuf_data_len(mbuf));
291                         first_seg->nb_segs++;
292                         last_seg->next = mbuf;
293                 }
294
295                 /*
296                  * If this is not the last buffer of the received packet,
297                  * update the pointer to the last mbuf of the current scattered
298                  * packet and continue to parse the RX ring.
299                  */
300                 if (!(desc.d.staterr & FM10K_RXD_STATUS_EOP)) {
301                         last_seg = mbuf;
302                         continue;
303                 }
304
305                 first_seg->ol_flags = 0;
306 #ifdef RTE_LIBRTE_FM10K_RX_OLFLAGS_ENABLE
307                 rx_desc_to_ol_flags(first_seg, &desc);
308 #endif
309                 first_seg->hash.rss = desc.d.rss;
310                 /**
311                  * Packets in fm10k device always carry at least one VLAN tag.
312                  * For those packets coming in without VLAN tag,
313                  * the port default VLAN tag will be used.
314                  * So, always PKT_RX_VLAN_PKT flag is set and vlan_tci
315                  * is valid for each RX packet's mbuf.
316                  */
317                 first_seg->ol_flags |= PKT_RX_VLAN_PKT;
318                 first_seg->vlan_tci = desc.w.vlan;
319                 /**
320                  * mbuf->vlan_tci_outer is an idle field in fm10k driver,
321                  * so it can be selected to store sglort value.
322                  */
323                 if (q->rx_ftag_en)
324                         first_seg->vlan_tci_outer =
325                                 rte_le_to_cpu_16(desc.w.sglort);
326
327                 /* Prefetch data of first segment, if configured to do so. */
328                 rte_packet_prefetch((char *)first_seg->buf_addr +
329                         first_seg->data_off);
330
331                 /*
332                  * Store the mbuf address into the next entry of the array
333                  * of returned packets.
334                  */
335                 rx_pkts[nb_rcv++] = first_seg;
336
337                 /*
338                  * Setup receipt context for a new packet.
339                  */
340                 first_seg = NULL;
341         }
342
343         q->next_dd = next_dd;
344
345         if ((q->next_dd > q->next_trigger) || (alloc == 1)) {
346                 ret = rte_mempool_get_bulk(q->mp,
347                                         (void **)&q->sw_ring[q->next_alloc],
348                                         q->alloc_thresh);
349
350                 if (unlikely(ret != 0)) {
351                         uint8_t port = q->port_id;
352                         PMD_RX_LOG(ERR, "Failed to alloc mbuf");
353                         /*
354                          * Need to restore next_dd if we cannot allocate new
355                          * buffers to replenish the old ones.
356                          */
357                         q->next_dd = (q->next_dd + q->nb_desc - count) %
358                                                                 q->nb_desc;
359                         rte_eth_devices[port].data->rx_mbuf_alloc_failed++;
360                         return 0;
361                 }
362
363                 for (; q->next_alloc <= q->next_trigger; ++q->next_alloc) {
364                         mbuf = q->sw_ring[q->next_alloc];
365
366                         /* setup static mbuf fields */
367                         fm10k_pktmbuf_reset(mbuf, q->port_id);
368
369                         /* write descriptor */
370                         desc.q.pkt_addr = MBUF_DMA_ADDR_DEFAULT(mbuf);
371                         desc.q.hdr_addr = MBUF_DMA_ADDR_DEFAULT(mbuf);
372                         q->hw_ring[q->next_alloc] = desc;
373                 }
374                 FM10K_PCI_REG_WRITE(q->tail_ptr, q->next_trigger);
375                 q->next_trigger += q->alloc_thresh;
376                 if (q->next_trigger >= q->nb_desc) {
377                         q->next_trigger = q->alloc_thresh - 1;
378                         q->next_alloc = 0;
379                 }
380         }
381
382         q->pkt_first_seg = first_seg;
383         q->pkt_last_seg = last_seg;
384
385         return nb_rcv;
386 }
387
388 int
389 fm10k_dev_rx_descriptor_done(void *rx_queue, uint16_t offset)
390 {
391         volatile union fm10k_rx_desc *rxdp;
392         struct fm10k_rx_queue *rxq = rx_queue;
393         uint16_t desc;
394         int ret;
395
396         if (unlikely(offset >= rxq->nb_desc)) {
397                 PMD_DRV_LOG(ERR, "Invalid RX descriptor offset %u", offset);
398                 return 0;
399         }
400
401         desc = rxq->next_dd + offset;
402         if (desc >= rxq->nb_desc)
403                 desc -= rxq->nb_desc;
404
405         rxdp = &rxq->hw_ring[desc];
406
407         ret = !!(rxdp->w.status &
408                         rte_cpu_to_le_16(FM10K_RXD_STATUS_DD));
409
410         return ret;
411 }
412
413 /*
414  * Free multiple TX mbuf at a time if they are in the same pool
415  *
416  * @txep: software desc ring index that starts to free
417  * @num: number of descs to free
418  *
419  */
420 static inline void tx_free_bulk_mbuf(struct rte_mbuf **txep, int num)
421 {
422         struct rte_mbuf *m, *free[RTE_FM10K_TX_MAX_FREE_BUF_SZ];
423         int i;
424         int nb_free = 0;
425
426         if (unlikely(num == 0))
427                 return;
428
429         m = __rte_pktmbuf_prefree_seg(txep[0]);
430         if (likely(m != NULL)) {
431                 free[0] = m;
432                 nb_free = 1;
433                 for (i = 1; i < num; i++) {
434                         m = __rte_pktmbuf_prefree_seg(txep[i]);
435                         if (likely(m != NULL)) {
436                                 if (likely(m->pool == free[0]->pool))
437                                         free[nb_free++] = m;
438                                 else {
439                                         rte_mempool_put_bulk(free[0]->pool,
440                                                         (void *)free, nb_free);
441                                         free[0] = m;
442                                         nb_free = 1;
443                                 }
444                         }
445                         txep[i] = NULL;
446                 }
447                 rte_mempool_put_bulk(free[0]->pool, (void **)free, nb_free);
448         } else {
449                 for (i = 1; i < num; i++) {
450                         m = __rte_pktmbuf_prefree_seg(txep[i]);
451                         if (m != NULL)
452                                 rte_mempool_put(m->pool, m);
453                         txep[i] = NULL;
454                 }
455         }
456 }
457
458 static inline void tx_free_descriptors(struct fm10k_tx_queue *q)
459 {
460         uint16_t next_rs, count = 0;
461
462         next_rs = fifo_peek(&q->rs_tracker);
463         if (!(q->hw_ring[next_rs].flags & FM10K_TXD_FLAG_DONE))
464                 return;
465
466         /* the DONE flag is set on this descriptor so remove the ID
467          * from the RS bit tracker and free the buffers */
468         fifo_remove(&q->rs_tracker);
469
470         /* wrap around? if so, free buffers from last_free up to but NOT
471          * including nb_desc */
472         if (q->last_free > next_rs) {
473                 count = q->nb_desc - q->last_free;
474                 tx_free_bulk_mbuf(&q->sw_ring[q->last_free], count);
475                 q->last_free = 0;
476         }
477
478         /* adjust free descriptor count before the next loop */
479         q->nb_free += count + (next_rs + 1 - q->last_free);
480
481         /* free buffers from last_free, up to and including next_rs */
482         if (q->last_free <= next_rs) {
483                 count = next_rs - q->last_free + 1;
484                 tx_free_bulk_mbuf(&q->sw_ring[q->last_free], count);
485                 q->last_free += count;
486         }
487
488         if (q->last_free == q->nb_desc)
489                 q->last_free = 0;
490 }
491
492 static inline void tx_xmit_pkt(struct fm10k_tx_queue *q, struct rte_mbuf *mb)
493 {
494         uint16_t last_id;
495         uint8_t flags, hdrlen;
496
497         /* always set the LAST flag on the last descriptor used to
498          * transmit the packet */
499         flags = FM10K_TXD_FLAG_LAST;
500         last_id = q->next_free + mb->nb_segs - 1;
501         if (last_id >= q->nb_desc)
502                 last_id = last_id - q->nb_desc;
503
504         /* but only set the RS flag on the last descriptor if rs_thresh
505          * descriptors will be used since the RS flag was last set */
506         if ((q->nb_used + mb->nb_segs) >= q->rs_thresh) {
507                 flags |= FM10K_TXD_FLAG_RS;
508                 fifo_insert(&q->rs_tracker, last_id);
509                 q->nb_used = 0;
510         } else {
511                 q->nb_used = q->nb_used + mb->nb_segs;
512         }
513
514         q->nb_free -= mb->nb_segs;
515
516         q->hw_ring[q->next_free].flags = 0;
517         if (q->tx_ftag_en)
518                 q->hw_ring[q->next_free].flags |= FM10K_TXD_FLAG_FTAG;
519         /* set checksum flags on first descriptor of packet. SCTP checksum
520          * offload is not supported, but we do not explicitly check for this
521          * case in favor of greatly simplified processing. */
522         if (mb->ol_flags & (PKT_TX_IP_CKSUM | PKT_TX_L4_MASK | PKT_TX_TCP_SEG))
523                 q->hw_ring[q->next_free].flags |= FM10K_TXD_FLAG_CSUM;
524
525         /* set vlan if requested */
526         if (mb->ol_flags & PKT_TX_VLAN_PKT)
527                 q->hw_ring[q->next_free].vlan = mb->vlan_tci;
528
529         q->sw_ring[q->next_free] = mb;
530         q->hw_ring[q->next_free].buffer_addr =
531                         rte_cpu_to_le_64(MBUF_DMA_ADDR(mb));
532         q->hw_ring[q->next_free].buflen =
533                         rte_cpu_to_le_16(rte_pktmbuf_data_len(mb));
534
535         if (mb->ol_flags & PKT_TX_TCP_SEG) {
536                 hdrlen = mb->outer_l2_len + mb->outer_l3_len + mb->l2_len +
537                         mb->l3_len + mb->l4_len;
538                 if (q->hw_ring[q->next_free].flags & FM10K_TXD_FLAG_FTAG)
539                         hdrlen += sizeof(struct fm10k_ftag);
540
541                 if (likely((hdrlen >= FM10K_TSO_MIN_HEADERLEN) &&
542                                 (hdrlen <= FM10K_TSO_MAX_HEADERLEN) &&
543                                 (mb->tso_segsz >= FM10K_TSO_MINMSS))) {
544                         q->hw_ring[q->next_free].mss = mb->tso_segsz;
545                         q->hw_ring[q->next_free].hdrlen = hdrlen;
546                 }
547         }
548
549         if (++q->next_free == q->nb_desc)
550                 q->next_free = 0;
551
552         /* fill up the rings */
553         for (mb = mb->next; mb != NULL; mb = mb->next) {
554                 q->sw_ring[q->next_free] = mb;
555                 q->hw_ring[q->next_free].buffer_addr =
556                                 rte_cpu_to_le_64(MBUF_DMA_ADDR(mb));
557                 q->hw_ring[q->next_free].buflen =
558                                 rte_cpu_to_le_16(rte_pktmbuf_data_len(mb));
559                 q->hw_ring[q->next_free].flags = 0;
560                 if (++q->next_free == q->nb_desc)
561                         q->next_free = 0;
562         }
563
564         q->hw_ring[last_id].flags |= flags;
565 }
566
567 uint16_t
568 fm10k_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
569         uint16_t nb_pkts)
570 {
571         struct fm10k_tx_queue *q = tx_queue;
572         struct rte_mbuf *mb;
573         uint16_t count;
574
575         for (count = 0; count < nb_pkts; ++count) {
576                 mb = tx_pkts[count];
577
578                 /* running low on descriptors? try to free some... */
579                 if (q->nb_free < q->free_thresh)
580                         tx_free_descriptors(q);
581
582                 /* make sure there are enough free descriptors to transmit the
583                  * entire packet before doing anything */
584                 if (q->nb_free < mb->nb_segs)
585                         break;
586
587                 /* sanity check to make sure the mbuf is valid */
588                 if ((mb->nb_segs == 0) ||
589                     ((mb->nb_segs > 1) && (mb->next == NULL)))
590                         break;
591
592                 /* process the packet */
593                 tx_xmit_pkt(q, mb);
594         }
595
596         /* update the tail pointer if any packets were processed */
597         if (likely(count > 0))
598                 FM10K_PCI_REG_WRITE(q->tail_ptr, q->next_free);
599
600         return count;
601 }