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