fm10k: enable FTAG based forwarding
[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 static inline void
69 rx_desc_to_ol_flags(struct rte_mbuf *m, const union fm10k_rx_desc *d)
70 {
71         static const uint32_t
72                 ptype_table[FM10K_RXD_PKTTYPE_MASK >> FM10K_RXD_PKTTYPE_SHIFT]
73                         __rte_cache_aligned = {
74                 [FM10K_PKTTYPE_OTHER] = RTE_PTYPE_L2_ETHER,
75                 [FM10K_PKTTYPE_IPV4] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4,
76                 [FM10K_PKTTYPE_IPV4_EX] = RTE_PTYPE_L2_ETHER |
77                         RTE_PTYPE_L3_IPV4_EXT,
78                 [FM10K_PKTTYPE_IPV6] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6,
79                 [FM10K_PKTTYPE_IPV6_EX] = RTE_PTYPE_L2_ETHER |
80                         RTE_PTYPE_L3_IPV6_EXT,
81                 [FM10K_PKTTYPE_IPV4 | FM10K_PKTTYPE_TCP] = RTE_PTYPE_L2_ETHER |
82                         RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP,
83                 [FM10K_PKTTYPE_IPV6 | FM10K_PKTTYPE_TCP] = RTE_PTYPE_L2_ETHER |
84                         RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_TCP,
85                 [FM10K_PKTTYPE_IPV4 | FM10K_PKTTYPE_UDP] = RTE_PTYPE_L2_ETHER |
86                         RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_UDP,
87                 [FM10K_PKTTYPE_IPV6 | FM10K_PKTTYPE_UDP] = RTE_PTYPE_L2_ETHER |
88                         RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_UDP,
89         };
90
91         m->packet_type = ptype_table[(d->w.pkt_info & FM10K_RXD_PKTTYPE_MASK)
92                                                 >> FM10K_RXD_PKTTYPE_SHIFT];
93
94         if (d->w.pkt_info & FM10K_RXD_RSSTYPE_MASK)
95                 m->ol_flags |= PKT_RX_RSS_HASH;
96
97         if (unlikely((d->d.staterr &
98                 (FM10K_RXD_STATUS_IPCS | FM10K_RXD_STATUS_IPE)) ==
99                 (FM10K_RXD_STATUS_IPCS | FM10K_RXD_STATUS_IPE)))
100                 m->ol_flags |= PKT_RX_IP_CKSUM_BAD;
101
102         if (unlikely((d->d.staterr &
103                 (FM10K_RXD_STATUS_L4CS | FM10K_RXD_STATUS_L4E)) ==
104                 (FM10K_RXD_STATUS_L4CS | FM10K_RXD_STATUS_L4E)))
105                 m->ol_flags |= PKT_RX_L4_CKSUM_BAD;
106
107         if (unlikely(d->d.staterr & FM10K_RXD_STATUS_HBO))
108                 m->ol_flags |= PKT_RX_HBUF_OVERFLOW;
109
110         if (unlikely(d->d.staterr & FM10K_RXD_STATUS_RXE))
111                 m->ol_flags |= PKT_RX_RECIP_ERR;
112 }
113
114 uint16_t
115 fm10k_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
116         uint16_t nb_pkts)
117 {
118         struct rte_mbuf *mbuf;
119         union fm10k_rx_desc desc;
120         struct fm10k_rx_queue *q = rx_queue;
121         uint16_t count = 0;
122         int alloc = 0;
123         uint16_t next_dd;
124         int ret;
125
126         next_dd = q->next_dd;
127
128         nb_pkts = RTE_MIN(nb_pkts, q->alloc_thresh);
129         for (count = 0; count < nb_pkts; ++count) {
130                 mbuf = q->sw_ring[next_dd];
131                 desc = q->hw_ring[next_dd];
132                 if (!(desc.d.staterr & FM10K_RXD_STATUS_DD))
133                         break;
134 #ifdef RTE_LIBRTE_FM10K_DEBUG_RX
135                 dump_rxd(&desc);
136 #endif
137                 rte_pktmbuf_pkt_len(mbuf) = desc.w.length;
138                 rte_pktmbuf_data_len(mbuf) = desc.w.length;
139
140                 mbuf->ol_flags = 0;
141 #ifdef RTE_LIBRTE_FM10K_RX_OLFLAGS_ENABLE
142                 rx_desc_to_ol_flags(mbuf, &desc);
143 #endif
144
145                 mbuf->hash.rss = desc.d.rss;
146                 /**
147                  * Packets in fm10k device always carry at least one VLAN tag.
148                  * For those packets coming in without VLAN tag,
149                  * the port default VLAN tag will be used.
150                  * So, always PKT_RX_VLAN_PKT flag is set and vlan_tci
151                  * is valid for each RX packet's mbuf.
152                  */
153                 mbuf->ol_flags |= PKT_RX_VLAN_PKT;
154                 mbuf->vlan_tci = desc.w.vlan;
155                 /**
156                  * mbuf->vlan_tci_outer is an idle field in fm10k driver,
157                  * so it can be selected to store sglort value.
158                  */
159                 if (q->rx_ftag_en)
160                         mbuf->vlan_tci_outer = rte_le_to_cpu_16(desc.w.sglort);
161
162                 rx_pkts[count] = mbuf;
163                 if (++next_dd == q->nb_desc) {
164                         next_dd = 0;
165                         alloc = 1;
166                 }
167
168                 /* Prefetch next mbuf while processing current one. */
169                 rte_prefetch0(q->sw_ring[next_dd]);
170
171                 /*
172                  * When next RX descriptor is on a cache-line boundary,
173                  * prefetch the next 4 RX descriptors and the next 8 pointers
174                  * to mbufs.
175                  */
176                 if ((next_dd & 0x3) == 0) {
177                         rte_prefetch0(&q->hw_ring[next_dd]);
178                         rte_prefetch0(&q->sw_ring[next_dd]);
179                 }
180         }
181
182         q->next_dd = next_dd;
183
184         if ((q->next_dd > q->next_trigger) || (alloc == 1)) {
185                 ret = rte_mempool_get_bulk(q->mp,
186                                         (void **)&q->sw_ring[q->next_alloc],
187                                         q->alloc_thresh);
188
189                 if (unlikely(ret != 0)) {
190                         uint8_t port = q->port_id;
191                         PMD_RX_LOG(ERR, "Failed to alloc mbuf");
192                         /*
193                          * Need to restore next_dd if we cannot allocate new
194                          * buffers to replenish the old ones.
195                          */
196                         q->next_dd = (q->next_dd + q->nb_desc - count) %
197                                                                 q->nb_desc;
198                         rte_eth_devices[port].data->rx_mbuf_alloc_failed++;
199                         return 0;
200                 }
201
202                 for (; q->next_alloc <= q->next_trigger; ++q->next_alloc) {
203                         mbuf = q->sw_ring[q->next_alloc];
204
205                         /* setup static mbuf fields */
206                         fm10k_pktmbuf_reset(mbuf, q->port_id);
207
208                         /* write descriptor */
209                         desc.q.pkt_addr = MBUF_DMA_ADDR_DEFAULT(mbuf);
210                         desc.q.hdr_addr = MBUF_DMA_ADDR_DEFAULT(mbuf);
211                         q->hw_ring[q->next_alloc] = desc;
212                 }
213                 FM10K_PCI_REG_WRITE(q->tail_ptr, q->next_trigger);
214                 q->next_trigger += q->alloc_thresh;
215                 if (q->next_trigger >= q->nb_desc) {
216                         q->next_trigger = q->alloc_thresh - 1;
217                         q->next_alloc = 0;
218                 }
219         }
220
221         return count;
222 }
223
224 uint16_t
225 fm10k_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
226                                 uint16_t nb_pkts)
227 {
228         struct rte_mbuf *mbuf;
229         union fm10k_rx_desc desc;
230         struct fm10k_rx_queue *q = rx_queue;
231         uint16_t count = 0;
232         uint16_t nb_rcv, nb_seg;
233         int alloc = 0;
234         uint16_t next_dd;
235         struct rte_mbuf *first_seg = q->pkt_first_seg;
236         struct rte_mbuf *last_seg = q->pkt_last_seg;
237         int ret;
238
239         next_dd = q->next_dd;
240         nb_rcv = 0;
241
242         nb_seg = RTE_MIN(nb_pkts, q->alloc_thresh);
243         for (count = 0; count < nb_seg; count++) {
244                 mbuf = q->sw_ring[next_dd];
245                 desc = q->hw_ring[next_dd];
246                 if (!(desc.d.staterr & FM10K_RXD_STATUS_DD))
247                         break;
248 #ifdef RTE_LIBRTE_FM10K_DEBUG_RX
249                 dump_rxd(&desc);
250 #endif
251
252                 if (++next_dd == q->nb_desc) {
253                         next_dd = 0;
254                         alloc = 1;
255                 }
256
257                 /* Prefetch next mbuf while processing current one. */
258                 rte_prefetch0(q->sw_ring[next_dd]);
259
260                 /*
261                  * When next RX descriptor is on a cache-line boundary,
262                  * prefetch the next 4 RX descriptors and the next 8 pointers
263                  * to mbufs.
264                  */
265                 if ((next_dd & 0x3) == 0) {
266                         rte_prefetch0(&q->hw_ring[next_dd]);
267                         rte_prefetch0(&q->sw_ring[next_dd]);
268                 }
269
270                 /* Fill data length */
271                 rte_pktmbuf_data_len(mbuf) = desc.w.length;
272
273                 /*
274                  * If this is the first buffer of the received packet,
275                  * set the pointer to the first mbuf of the packet and
276                  * initialize its context.
277                  * Otherwise, update the total length and the number of segments
278                  * of the current scattered packet, and update the pointer to
279                  * the last mbuf of the current packet.
280                  */
281                 if (!first_seg) {
282                         first_seg = mbuf;
283                         first_seg->pkt_len = desc.w.length;
284                 } else {
285                         first_seg->pkt_len =
286                                         (uint16_t)(first_seg->pkt_len +
287                                         rte_pktmbuf_data_len(mbuf));
288                         first_seg->nb_segs++;
289                         last_seg->next = mbuf;
290                 }
291
292                 /*
293                  * If this is not the last buffer of the received packet,
294                  * update the pointer to the last mbuf of the current scattered
295                  * packet and continue to parse the RX ring.
296                  */
297                 if (!(desc.d.staterr & FM10K_RXD_STATUS_EOP)) {
298                         last_seg = mbuf;
299                         continue;
300                 }
301
302                 first_seg->ol_flags = 0;
303 #ifdef RTE_LIBRTE_FM10K_RX_OLFLAGS_ENABLE
304                 rx_desc_to_ol_flags(first_seg, &desc);
305 #endif
306                 first_seg->hash.rss = desc.d.rss;
307                 /**
308                  * Packets in fm10k device always carry at least one VLAN tag.
309                  * For those packets coming in without VLAN tag,
310                  * the port default VLAN tag will be used.
311                  * So, always PKT_RX_VLAN_PKT flag is set and vlan_tci
312                  * is valid for each RX packet's mbuf.
313                  */
314                 first_seg->ol_flags |= PKT_RX_VLAN_PKT;
315                 first_seg->vlan_tci = desc.w.vlan;
316                 /**
317                  * mbuf->vlan_tci_outer is an idle field in fm10k driver,
318                  * so it can be selected to store sglort value.
319                  */
320                 if (q->rx_ftag_en)
321                         first_seg->vlan_tci_outer =
322                                 rte_le_to_cpu_16(desc.w.sglort);
323
324                 /* Prefetch data of first segment, if configured to do so. */
325                 rte_packet_prefetch((char *)first_seg->buf_addr +
326                         first_seg->data_off);
327
328                 /*
329                  * Store the mbuf address into the next entry of the array
330                  * of returned packets.
331                  */
332                 rx_pkts[nb_rcv++] = first_seg;
333
334                 /*
335                  * Setup receipt context for a new packet.
336                  */
337                 first_seg = NULL;
338         }
339
340         q->next_dd = next_dd;
341
342         if ((q->next_dd > q->next_trigger) || (alloc == 1)) {
343                 ret = rte_mempool_get_bulk(q->mp,
344                                         (void **)&q->sw_ring[q->next_alloc],
345                                         q->alloc_thresh);
346
347                 if (unlikely(ret != 0)) {
348                         uint8_t port = q->port_id;
349                         PMD_RX_LOG(ERR, "Failed to alloc mbuf");
350                         /*
351                          * Need to restore next_dd if we cannot allocate new
352                          * buffers to replenish the old ones.
353                          */
354                         q->next_dd = (q->next_dd + q->nb_desc - count) %
355                                                                 q->nb_desc;
356                         rte_eth_devices[port].data->rx_mbuf_alloc_failed++;
357                         return 0;
358                 }
359
360                 for (; q->next_alloc <= q->next_trigger; ++q->next_alloc) {
361                         mbuf = q->sw_ring[q->next_alloc];
362
363                         /* setup static mbuf fields */
364                         fm10k_pktmbuf_reset(mbuf, q->port_id);
365
366                         /* write descriptor */
367                         desc.q.pkt_addr = MBUF_DMA_ADDR_DEFAULT(mbuf);
368                         desc.q.hdr_addr = MBUF_DMA_ADDR_DEFAULT(mbuf);
369                         q->hw_ring[q->next_alloc] = desc;
370                 }
371                 FM10K_PCI_REG_WRITE(q->tail_ptr, q->next_trigger);
372                 q->next_trigger += q->alloc_thresh;
373                 if (q->next_trigger >= q->nb_desc) {
374                         q->next_trigger = q->alloc_thresh - 1;
375                         q->next_alloc = 0;
376                 }
377         }
378
379         q->pkt_first_seg = first_seg;
380         q->pkt_last_seg = last_seg;
381
382         return nb_rcv;
383 }
384
385 int
386 fm10k_dev_rx_descriptor_done(void *rx_queue, uint16_t offset)
387 {
388         volatile union fm10k_rx_desc *rxdp;
389         struct fm10k_rx_queue *rxq = rx_queue;
390         uint16_t desc;
391         int ret;
392
393         if (unlikely(offset >= rxq->nb_desc)) {
394                 PMD_DRV_LOG(ERR, "Invalid RX descriptor offset %u", offset);
395                 return 0;
396         }
397
398         desc = rxq->next_dd + offset;
399         if (desc >= rxq->nb_desc)
400                 desc -= rxq->nb_desc;
401
402         rxdp = &rxq->hw_ring[desc];
403
404         ret = !!(rxdp->w.status &
405                         rte_cpu_to_le_16(FM10K_RXD_STATUS_DD));
406
407         return ret;
408 }
409
410 /*
411  * Free multiple TX mbuf at a time if they are in the same pool
412  *
413  * @txep: software desc ring index that starts to free
414  * @num: number of descs to free
415  *
416  */
417 static inline void tx_free_bulk_mbuf(struct rte_mbuf **txep, int num)
418 {
419         struct rte_mbuf *m, *free[RTE_FM10K_TX_MAX_FREE_BUF_SZ];
420         int i;
421         int nb_free = 0;
422
423         if (unlikely(num == 0))
424                 return;
425
426         m = __rte_pktmbuf_prefree_seg(txep[0]);
427         if (likely(m != NULL)) {
428                 free[0] = m;
429                 nb_free = 1;
430                 for (i = 1; i < num; i++) {
431                         m = __rte_pktmbuf_prefree_seg(txep[i]);
432                         if (likely(m != NULL)) {
433                                 if (likely(m->pool == free[0]->pool))
434                                         free[nb_free++] = m;
435                                 else {
436                                         rte_mempool_put_bulk(free[0]->pool,
437                                                         (void *)free, nb_free);
438                                         free[0] = m;
439                                         nb_free = 1;
440                                 }
441                         }
442                         txep[i] = NULL;
443                 }
444                 rte_mempool_put_bulk(free[0]->pool, (void **)free, nb_free);
445         } else {
446                 for (i = 1; i < num; i++) {
447                         m = __rte_pktmbuf_prefree_seg(txep[i]);
448                         if (m != NULL)
449                                 rte_mempool_put(m->pool, m);
450                         txep[i] = NULL;
451                 }
452         }
453 }
454
455 static inline void tx_free_descriptors(struct fm10k_tx_queue *q)
456 {
457         uint16_t next_rs, count = 0;
458
459         next_rs = fifo_peek(&q->rs_tracker);
460         if (!(q->hw_ring[next_rs].flags & FM10K_TXD_FLAG_DONE))
461                 return;
462
463         /* the DONE flag is set on this descriptor so remove the ID
464          * from the RS bit tracker and free the buffers */
465         fifo_remove(&q->rs_tracker);
466
467         /* wrap around? if so, free buffers from last_free up to but NOT
468          * including nb_desc */
469         if (q->last_free > next_rs) {
470                 count = q->nb_desc - q->last_free;
471                 tx_free_bulk_mbuf(&q->sw_ring[q->last_free], count);
472                 q->last_free = 0;
473         }
474
475         /* adjust free descriptor count before the next loop */
476         q->nb_free += count + (next_rs + 1 - q->last_free);
477
478         /* free buffers from last_free, up to and including next_rs */
479         if (q->last_free <= next_rs) {
480                 count = next_rs - q->last_free + 1;
481                 tx_free_bulk_mbuf(&q->sw_ring[q->last_free], count);
482                 q->last_free += count;
483         }
484
485         if (q->last_free == q->nb_desc)
486                 q->last_free = 0;
487 }
488
489 static inline void tx_xmit_pkt(struct fm10k_tx_queue *q, struct rte_mbuf *mb)
490 {
491         uint16_t last_id;
492         uint8_t flags, hdrlen;
493
494         /* always set the LAST flag on the last descriptor used to
495          * transmit the packet */
496         flags = FM10K_TXD_FLAG_LAST;
497         last_id = q->next_free + mb->nb_segs - 1;
498         if (last_id >= q->nb_desc)
499                 last_id = last_id - q->nb_desc;
500
501         /* but only set the RS flag on the last descriptor if rs_thresh
502          * descriptors will be used since the RS flag was last set */
503         if ((q->nb_used + mb->nb_segs) >= q->rs_thresh) {
504                 flags |= FM10K_TXD_FLAG_RS;
505                 fifo_insert(&q->rs_tracker, last_id);
506                 q->nb_used = 0;
507         } else {
508                 q->nb_used = q->nb_used + mb->nb_segs;
509         }
510
511         q->nb_free -= mb->nb_segs;
512
513         q->hw_ring[q->next_free].flags = 0;
514         if (q->tx_ftag_en)
515                 q->hw_ring[q->next_free].flags |= FM10K_TXD_FLAG_FTAG;
516         /* set checksum flags on first descriptor of packet. SCTP checksum
517          * offload is not supported, but we do not explicitly check for this
518          * case in favor of greatly simplified processing. */
519         if (mb->ol_flags & (PKT_TX_IP_CKSUM | PKT_TX_L4_MASK | PKT_TX_TCP_SEG))
520                 q->hw_ring[q->next_free].flags |= FM10K_TXD_FLAG_CSUM;
521
522         /* set vlan if requested */
523         if (mb->ol_flags & PKT_TX_VLAN_PKT)
524                 q->hw_ring[q->next_free].vlan = mb->vlan_tci;
525
526         q->sw_ring[q->next_free] = mb;
527         q->hw_ring[q->next_free].buffer_addr =
528                         rte_cpu_to_le_64(MBUF_DMA_ADDR(mb));
529         q->hw_ring[q->next_free].buflen =
530                         rte_cpu_to_le_16(rte_pktmbuf_data_len(mb));
531
532         if (mb->ol_flags & PKT_TX_TCP_SEG) {
533                 hdrlen = mb->outer_l2_len + mb->outer_l3_len + mb->l2_len +
534                         mb->l3_len + mb->l4_len;
535                 if (q->hw_ring[q->next_free].flags & FM10K_TXD_FLAG_FTAG)
536                         hdrlen += sizeof(struct fm10k_ftag);
537
538                 if (likely((hdrlen >= FM10K_TSO_MIN_HEADERLEN) &&
539                                 (hdrlen <= FM10K_TSO_MAX_HEADERLEN) &&
540                                 (mb->tso_segsz >= FM10K_TSO_MINMSS))) {
541                         q->hw_ring[q->next_free].mss = mb->tso_segsz;
542                         q->hw_ring[q->next_free].hdrlen = hdrlen;
543                 }
544         }
545
546         if (++q->next_free == q->nb_desc)
547                 q->next_free = 0;
548
549         /* fill up the rings */
550         for (mb = mb->next; mb != NULL; mb = mb->next) {
551                 q->sw_ring[q->next_free] = mb;
552                 q->hw_ring[q->next_free].buffer_addr =
553                                 rte_cpu_to_le_64(MBUF_DMA_ADDR(mb));
554                 q->hw_ring[q->next_free].buflen =
555                                 rte_cpu_to_le_16(rte_pktmbuf_data_len(mb));
556                 q->hw_ring[q->next_free].flags = 0;
557                 if (++q->next_free == q->nb_desc)
558                         q->next_free = 0;
559         }
560
561         q->hw_ring[last_id].flags |= flags;
562 }
563
564 uint16_t
565 fm10k_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
566         uint16_t nb_pkts)
567 {
568         struct fm10k_tx_queue *q = tx_queue;
569         struct rte_mbuf *mb;
570         uint16_t count;
571
572         for (count = 0; count < nb_pkts; ++count) {
573                 mb = tx_pkts[count];
574
575                 /* running low on descriptors? try to free some... */
576                 if (q->nb_free < q->free_thresh)
577                         tx_free_descriptors(q);
578
579                 /* make sure there are enough free descriptors to transmit the
580                  * entire packet before doing anything */
581                 if (q->nb_free < mb->nb_segs)
582                         break;
583
584                 /* sanity check to make sure the mbuf is valid */
585                 if ((mb->nb_segs == 0) ||
586                     ((mb->nb_segs > 1) && (mb->next == NULL)))
587                         break;
588
589                 /* process the packet */
590                 tx_xmit_pkt(q, mb);
591         }
592
593         /* update the tail pointer if any packets were processed */
594         if (likely(count > 0))
595                 FM10K_PCI_REG_WRITE(q->tail_ptr, q->next_free);
596
597         return count;
598 }