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