85685dc7d710833a101ba3b91e1bb9b6770cfb42
[deb_dpdk.git] / drivers / net / liquidio / lio_rxtx.h
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2017 Cavium, Inc.. 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 Cavium, Inc. 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(S) 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 #ifndef _LIO_RXTX_H_
35 #define _LIO_RXTX_H_
36
37 #include <stdio.h>
38 #include <stdint.h>
39
40 #include <rte_spinlock.h>
41 #include <rte_memory.h>
42
43 #include "lio_struct.h"
44
45 #ifndef ROUNDUP4
46 #define ROUNDUP4(val) (((val) + 3) & 0xfffffffc)
47 #endif
48
49 #define LIO_STQUEUE_FIRST_ENTRY(ptr, type, elem)        \
50         (type *)((char *)((ptr)->stqh_first) - offsetof(type, elem))
51
52 #define lio_check_timeout(cur_time, chk_time) ((cur_time) > (chk_time))
53
54 #define lio_uptime              \
55         (size_t)(rte_get_timer_cycles() / rte_get_timer_hz())
56
57 /** Descriptor format.
58  *  The descriptor ring is made of descriptors which have 2 64-bit values:
59  *  -# Physical (bus) address of the data buffer.
60  *  -# Physical (bus) address of a lio_droq_info structure.
61  *  The device DMA's incoming packets and its information at the address
62  *  given by these descriptor fields.
63  */
64 struct lio_droq_desc {
65         /** The buffer pointer */
66         uint64_t buffer_ptr;
67
68         /** The Info pointer */
69         uint64_t info_ptr;
70 };
71
72 #define LIO_DROQ_DESC_SIZE      (sizeof(struct lio_droq_desc))
73
74 /** Information about packet DMA'ed by Octeon.
75  *  The format of the information available at Info Pointer after Octeon
76  *  has posted a packet. Not all descriptors have valid information. Only
77  *  the Info field of the first descriptor for a packet has information
78  *  about the packet.
79  */
80 struct lio_droq_info {
81         /** The Output Receive Header. */
82         union octeon_rh rh;
83
84         /** The Length of the packet. */
85         uint64_t length;
86 };
87
88 #define LIO_DROQ_INFO_SIZE      (sizeof(struct lio_droq_info))
89
90 /** Pointer to data buffer.
91  *  Driver keeps a pointer to the data buffer that it made available to
92  *  the Octeon device. Since the descriptor ring keeps physical (bus)
93  *  addresses, this field is required for the driver to keep track of
94  *  the virtual address pointers.
95  */
96 struct lio_recv_buffer {
97         /** Packet buffer, including meta data. */
98         void *buffer;
99
100         /** Data in the packet buffer. */
101         uint8_t *data;
102
103 };
104
105 #define LIO_DROQ_RECVBUF_SIZE   (sizeof(struct lio_recv_buffer))
106
107 #define LIO_DROQ_SIZE           (sizeof(struct lio_droq))
108
109 #define LIO_IQ_SEND_OK          0
110 #define LIO_IQ_SEND_STOP        1
111 #define LIO_IQ_SEND_FAILED      -1
112
113 /* conditions */
114 #define LIO_REQTYPE_NONE                0
115 #define LIO_REQTYPE_NORESP_NET          1
116 #define LIO_REQTYPE_NORESP_NET_SG       2
117 #define LIO_REQTYPE_SOFT_COMMAND        3
118
119 struct lio_request_list {
120         uint32_t reqtype;
121         void *buf;
122 };
123
124 /*----------------------  INSTRUCTION FORMAT ----------------------------*/
125
126 struct lio_instr3_64B {
127         /** Pointer where the input data is available. */
128         uint64_t dptr;
129
130         /** Instruction Header. */
131         uint64_t ih3;
132
133         /** Instruction Header. */
134         uint64_t pki_ih3;
135
136         /** Input Request Header. */
137         uint64_t irh;
138
139         /** opcode/subcode specific parameters */
140         uint64_t ossp[2];
141
142         /** Return Data Parameters */
143         uint64_t rdp;
144
145         /** Pointer where the response for a RAW mode packet will be written
146          *  by Octeon.
147          */
148         uint64_t rptr;
149
150 };
151
152 union lio_instr_64B {
153         struct lio_instr3_64B cmd3;
154 };
155
156 /** The size of each buffer in soft command buffer pool */
157 #define LIO_SOFT_COMMAND_BUFFER_SIZE    1536
158
159 /** Maximum number of buffers to allocate into soft command buffer pool */
160 #define LIO_MAX_SOFT_COMMAND_BUFFERS    255
161
162 struct lio_soft_command {
163         /** Soft command buffer info. */
164         struct lio_stailq_node node;
165         uint64_t dma_addr;
166         uint32_t size;
167
168         /** Command and return status */
169         union lio_instr_64B cmd;
170
171 #define LIO_COMPLETION_WORD_INIT        0xffffffffffffffffULL
172         uint64_t *status_word;
173
174         /** Data buffer info */
175         void *virtdptr;
176         uint64_t dmadptr;
177         uint32_t datasize;
178
179         /** Return buffer info */
180         void *virtrptr;
181         uint64_t dmarptr;
182         uint32_t rdatasize;
183
184         /** Context buffer info */
185         void *ctxptr;
186         uint32_t ctxsize;
187
188         /** Time out and callback */
189         size_t wait_time;
190         size_t timeout;
191         uint32_t iq_no;
192         void (*callback)(uint32_t, void *);
193         void *callback_arg;
194         struct rte_mbuf *mbuf;
195 };
196
197 struct lio_iq_post_status {
198         int status;
199         int index;
200 };
201
202 /*   wqe
203  *  ---------------  0
204  * |  wqe  word0-3 |
205  *  ---------------  32
206  * |    PCI IH     |
207  *  ---------------  40
208  * |     RPTR      |
209  *  ---------------  48
210  * |    PCI IRH    |
211  *  ---------------  56
212  * |    OCTEON_CMD |
213  *  ---------------  64
214  * | Addtl 8-BData |
215  * |               |
216  *  ---------------
217  */
218
219 union octeon_cmd {
220         uint64_t cmd64;
221
222         struct  {
223 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
224                 uint64_t cmd : 5;
225
226                 uint64_t more : 6; /* How many udd words follow the command */
227
228                 uint64_t reserved : 29;
229
230                 uint64_t param1 : 16;
231
232                 uint64_t param2 : 8;
233
234 #elif RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
235
236                 uint64_t param2 : 8;
237
238                 uint64_t param1 : 16;
239
240                 uint64_t reserved : 29;
241
242                 uint64_t more : 6;
243
244                 uint64_t cmd : 5;
245
246 #endif
247         } s;
248 };
249
250 #define OCTEON_CMD_SIZE (sizeof(union octeon_cmd))
251
252 /* Maximum number of 8-byte words can be
253  * sent in a NIC control message.
254  */
255 #define LIO_MAX_NCTRL_UDD       32
256
257 /* Structure of control information passed by driver to the BASE
258  * layer when sending control commands to Octeon device software.
259  */
260 struct lio_ctrl_pkt {
261         /** Command to be passed to the Octeon device software. */
262         union octeon_cmd ncmd;
263
264         /** Send buffer */
265         void *data;
266         uint64_t dmadata;
267
268         /** Response buffer */
269         void *rdata;
270         uint64_t dmardata;
271
272         /** Additional data that may be needed by some commands. */
273         uint64_t udd[LIO_MAX_NCTRL_UDD];
274
275         /** Input queue to use to send this command. */
276         uint64_t iq_no;
277
278         /** Time to wait for Octeon software to respond to this control command.
279          *  If wait_time is 0, BASE assumes no response is expected.
280          */
281         size_t wait_time;
282
283         struct lio_dev_ctrl_cmd *ctrl_cmd;
284 };
285
286 /** Structure of data information passed by driver to the BASE
287  *  layer when forwarding data to Octeon device software.
288  */
289 struct lio_data_pkt {
290         /** Pointer to information maintained by NIC module for this packet. The
291          *  BASE layer passes this as-is to the driver.
292          */
293         void *buf;
294
295         /** Type of buffer passed in "buf" above. */
296         uint32_t reqtype;
297
298         /** Total data bytes to be transferred in this command. */
299         uint32_t datasize;
300
301         /** Command to be passed to the Octeon device software. */
302         union lio_instr_64B cmd;
303
304         /** Input queue to use to send this command. */
305         uint32_t q_no;
306 };
307
308 /** Structure passed by driver to BASE layer to prepare a command to send
309  *  network data to Octeon.
310  */
311 union lio_cmd_setup {
312         struct {
313                 uint32_t iq_no : 8;
314                 uint32_t gather : 1;
315                 uint32_t timestamp : 1;
316                 uint32_t ip_csum : 1;
317                 uint32_t transport_csum : 1;
318                 uint32_t tnl_csum : 1;
319                 uint32_t rsvd : 19;
320
321                 union {
322                         uint32_t datasize;
323                         uint32_t gatherptrs;
324                 } u;
325         } s;
326
327         uint64_t cmd_setup64;
328 };
329
330 /* Instruction Header */
331 struct octeon_instr_ih3 {
332 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
333
334         /** Reserved3 */
335         uint64_t reserved3 : 1;
336
337         /** Gather indicator 1=gather*/
338         uint64_t gather : 1;
339
340         /** Data length OR no. of entries in gather list */
341         uint64_t dlengsz : 14;
342
343         /** Front Data size */
344         uint64_t fsz : 6;
345
346         /** Reserved2 */
347         uint64_t reserved2 : 4;
348
349         /** PKI port kind - PKIND */
350         uint64_t pkind : 6;
351
352         /** Reserved1 */
353         uint64_t reserved1 : 32;
354
355 #elif RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
356         /** Reserved1 */
357         uint64_t reserved1 : 32;
358
359         /** PKI port kind - PKIND */
360         uint64_t pkind : 6;
361
362         /** Reserved2 */
363         uint64_t reserved2 : 4;
364
365         /** Front Data size */
366         uint64_t fsz : 6;
367
368         /** Data length OR no. of entries in gather list */
369         uint64_t dlengsz : 14;
370
371         /** Gather indicator 1=gather*/
372         uint64_t gather : 1;
373
374         /** Reserved3 */
375         uint64_t reserved3 : 1;
376
377 #endif
378 };
379
380 /* PKI Instruction Header(PKI IH) */
381 struct octeon_instr_pki_ih3 {
382 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
383
384         /** Wider bit */
385         uint64_t w : 1;
386
387         /** Raw mode indicator 1 = RAW */
388         uint64_t raw : 1;
389
390         /** Use Tag */
391         uint64_t utag : 1;
392
393         /** Use QPG */
394         uint64_t uqpg : 1;
395
396         /** Reserved2 */
397         uint64_t reserved2 : 1;
398
399         /** Parse Mode */
400         uint64_t pm : 3;
401
402         /** Skip Length */
403         uint64_t sl : 8;
404
405         /** Use Tag Type */
406         uint64_t utt : 1;
407
408         /** Tag type */
409         uint64_t tagtype : 2;
410
411         /** Reserved1 */
412         uint64_t reserved1 : 2;
413
414         /** QPG Value */
415         uint64_t qpg : 11;
416
417         /** Tag Value */
418         uint64_t tag : 32;
419
420 #elif RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
421
422         /** Tag Value */
423         uint64_t tag : 32;
424
425         /** QPG Value */
426         uint64_t qpg : 11;
427
428         /** Reserved1 */
429         uint64_t reserved1 : 2;
430
431         /** Tag type */
432         uint64_t tagtype : 2;
433
434         /** Use Tag Type */
435         uint64_t utt : 1;
436
437         /** Skip Length */
438         uint64_t sl : 8;
439
440         /** Parse Mode */
441         uint64_t pm : 3;
442
443         /** Reserved2 */
444         uint64_t reserved2 : 1;
445
446         /** Use QPG */
447         uint64_t uqpg : 1;
448
449         /** Use Tag */
450         uint64_t utag : 1;
451
452         /** Raw mode indicator 1 = RAW */
453         uint64_t raw : 1;
454
455         /** Wider bit */
456         uint64_t w : 1;
457 #endif
458 };
459
460 /** Input Request Header */
461 struct octeon_instr_irh {
462 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
463         uint64_t opcode : 4;
464         uint64_t rflag : 1;
465         uint64_t subcode : 7;
466         uint64_t vlan : 12;
467         uint64_t priority : 3;
468         uint64_t reserved : 5;
469         uint64_t ossp : 32; /* opcode/subcode specific parameters */
470 #elif RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
471         uint64_t ossp : 32; /* opcode/subcode specific parameters */
472         uint64_t reserved : 5;
473         uint64_t priority : 3;
474         uint64_t vlan : 12;
475         uint64_t subcode : 7;
476         uint64_t rflag : 1;
477         uint64_t opcode : 4;
478 #endif
479 };
480
481 /* pkiih3 + irh + ossp[0] + ossp[1] + rdp + rptr = 40 bytes */
482 #define OCTEON_SOFT_CMD_RESP_IH3        (40 + 8)
483 /* pki_h3 + irh + ossp[0] + ossp[1] = 32 bytes */
484 #define OCTEON_PCI_CMD_O3               (24 + 8)
485
486 /** Return Data Parameters */
487 struct octeon_instr_rdp {
488 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
489         uint64_t reserved : 49;
490         uint64_t pcie_port : 3;
491         uint64_t rlen : 12;
492 #elif RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
493         uint64_t rlen : 12;
494         uint64_t pcie_port : 3;
495         uint64_t reserved : 49;
496 #endif
497 };
498
499 union octeon_packet_params {
500         uint32_t pkt_params32;
501         struct {
502 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
503                 uint32_t reserved : 24;
504                 uint32_t ip_csum : 1; /* Perform IP header checksum(s) */
505                 /* Perform Outer transport header checksum */
506                 uint32_t transport_csum : 1;
507                 /* Find tunnel, and perform transport csum. */
508                 uint32_t tnl_csum : 1;
509                 uint32_t tsflag : 1;   /* Timestamp this packet */
510                 uint32_t ipsec_ops : 4; /* IPsec operation */
511 #else
512                 uint32_t ipsec_ops : 4;
513                 uint32_t tsflag : 1;
514                 uint32_t tnl_csum : 1;
515                 uint32_t transport_csum : 1;
516                 uint32_t ip_csum : 1;
517                 uint32_t reserved : 7;
518 #endif
519         } s;
520 };
521
522 /** Utility function to prepare a 64B NIC instruction based on a setup command
523  * @param cmd - pointer to instruction to be filled in.
524  * @param setup - pointer to the setup structure
525  * @param q_no - which queue for back pressure
526  *
527  * Assumes the cmd instruction is pre-allocated, but no fields are filled in.
528  */
529 static inline void
530 lio_prepare_pci_cmd(struct lio_device *lio_dev,
531                     union lio_instr_64B *cmd,
532                     union lio_cmd_setup *setup,
533                     uint32_t tag)
534 {
535         union octeon_packet_params packet_params;
536         struct octeon_instr_pki_ih3 *pki_ih3;
537         struct octeon_instr_irh *irh;
538         struct octeon_instr_ih3 *ih3;
539         int port;
540
541         memset(cmd, 0, sizeof(union lio_instr_64B));
542
543         ih3 = (struct octeon_instr_ih3 *)&cmd->cmd3.ih3;
544         pki_ih3 = (struct octeon_instr_pki_ih3 *)&cmd->cmd3.pki_ih3;
545
546         /* assume that rflag is cleared so therefore front data will only have
547          * irh and ossp[1] and ossp[2] for a total of 24 bytes
548          */
549         ih3->pkind = lio_dev->instr_queue[setup->s.iq_no]->txpciq.s.pkind;
550         /* PKI IH */
551         ih3->fsz = OCTEON_PCI_CMD_O3;
552
553         if (!setup->s.gather) {
554                 ih3->dlengsz = setup->s.u.datasize;
555         } else {
556                 ih3->gather = 1;
557                 ih3->dlengsz = setup->s.u.gatherptrs;
558         }
559
560         pki_ih3->w = 1;
561         pki_ih3->raw = 0;
562         pki_ih3->utag = 0;
563         pki_ih3->utt = 1;
564         pki_ih3->uqpg = lio_dev->instr_queue[setup->s.iq_no]->txpciq.s.use_qpg;
565
566         port = (int)lio_dev->instr_queue[setup->s.iq_no]->txpciq.s.port;
567
568         if (tag)
569                 pki_ih3->tag = tag;
570         else
571                 pki_ih3->tag = LIO_DATA(port);
572
573         pki_ih3->tagtype = OCTEON_ORDERED_TAG;
574         pki_ih3->qpg = lio_dev->instr_queue[setup->s.iq_no]->txpciq.s.qpg;
575         pki_ih3->pm = 0x0; /* parse from L2 */
576         pki_ih3->sl = 32;  /* sl will be sizeof(pki_ih3) + irh + ossp0 + ossp1*/
577
578         irh = (struct octeon_instr_irh *)&cmd->cmd3.irh;
579
580         irh->opcode = LIO_OPCODE;
581         irh->subcode = LIO_OPCODE_NW_DATA;
582
583         packet_params.pkt_params32 = 0;
584         packet_params.s.ip_csum = setup->s.ip_csum;
585         packet_params.s.transport_csum = setup->s.transport_csum;
586         packet_params.s.tnl_csum = setup->s.tnl_csum;
587         packet_params.s.tsflag = setup->s.timestamp;
588
589         irh->ossp = packet_params.pkt_params32;
590 }
591
592 int lio_setup_sc_buffer_pool(struct lio_device *lio_dev);
593 void lio_free_sc_buffer_pool(struct lio_device *lio_dev);
594
595 struct lio_soft_command *
596 lio_alloc_soft_command(struct lio_device *lio_dev,
597                        uint32_t datasize, uint32_t rdatasize,
598                        uint32_t ctxsize);
599 void lio_prepare_soft_command(struct lio_device *lio_dev,
600                               struct lio_soft_command *sc,
601                               uint8_t opcode, uint8_t subcode,
602                               uint32_t irh_ossp, uint64_t ossp0,
603                               uint64_t ossp1);
604 int lio_send_soft_command(struct lio_device *lio_dev,
605                           struct lio_soft_command *sc);
606 void lio_free_soft_command(struct lio_soft_command *sc);
607
608 /** Send control packet to the device
609  *  @param lio_dev - lio device pointer
610  *  @param nctrl   - control structure with command, timeout, and callback info
611  *
612  *  @returns IQ_FAILED if it failed to add to the input queue. IQ_STOP if it the
613  *  queue should be stopped, and LIO_IQ_SEND_OK if it sent okay.
614  */
615 int lio_send_ctrl_pkt(struct lio_device *lio_dev,
616                       struct lio_ctrl_pkt *ctrl_pkt);
617
618 /** Maximum ordered requests to process in every invocation of
619  *  lio_process_ordered_list(). The function will continue to process requests
620  *  as long as it can find one that has finished processing. If it keeps
621  *  finding requests that have completed, the function can run for ever. The
622  *  value defined here sets an upper limit on the number of requests it can
623  *  process before it returns control to the poll thread.
624  */
625 #define LIO_MAX_ORD_REQS_TO_PROCESS     4096
626
627 /** Error codes used in Octeon Host-Core communication.
628  *
629  *   31         16 15           0
630  *   ----------------------------
631  * |            |               |
632  *   ----------------------------
633  *   Error codes are 32-bit wide. The upper 16-bits, called Major Error Number,
634  *   are reserved to identify the group to which the error code belongs. The
635  *   lower 16-bits, called Minor Error Number, carry the actual code.
636  *
637  *   So error codes are (MAJOR NUMBER << 16)| MINOR_NUMBER.
638  */
639 /** Status for a request.
640  *  If the request is successfully queued, the driver will return
641  *  a LIO_REQUEST_PENDING status. LIO_REQUEST_TIMEOUT is only returned by
642  *  the driver if the response for request failed to arrive before a
643  *  time-out period or if the request processing * got interrupted due to
644  *  a signal respectively.
645  */
646 enum {
647         /** A value of 0x00000000 indicates no error i.e. success */
648         LIO_REQUEST_DONE        = 0x00000000,
649         /** (Major number: 0x0000; Minor Number: 0x0001) */
650         LIO_REQUEST_PENDING     = 0x00000001,
651         LIO_REQUEST_TIMEOUT     = 0x00000003,
652
653 };
654
655 /*------ Error codes used by firmware (bits 15..0 set by firmware */
656 #define LIO_FIRMWARE_MAJOR_ERROR_CODE    0x0001
657 #define LIO_FIRMWARE_STATUS_CODE(status) \
658         ((LIO_FIRMWARE_MAJOR_ERROR_CODE << 16) | (status))
659
660 /** Initialize the response lists. The number of response lists to create is
661  *  given by count.
662  *  @param lio_dev - the lio device structure.
663  */
664 void lio_setup_response_list(struct lio_device *lio_dev);
665
666 /** Check the status of first entry in the ordered list. If the instruction at
667  *  that entry finished processing or has timed-out, the entry is cleaned.
668  *  @param lio_dev - the lio device structure.
669  *  @return 1 if the ordered list is empty, 0 otherwise.
670  */
671 int lio_process_ordered_list(struct lio_device *lio_dev);
672
673 #define LIO_INCR_INSTRQUEUE_PKT_COUNT(lio_dev, iq_no, field, count)     \
674         (((lio_dev)->instr_queue[iq_no]->stats.field) += count)
675
676 static inline void
677 lio_swap_8B_data(uint64_t *data, uint32_t blocks)
678 {
679         while (blocks) {
680                 *data = rte_cpu_to_be_64(*data);
681                 blocks--;
682                 data++;
683         }
684 }
685
686 static inline uint64_t
687 lio_map_ring(void *buf)
688 {
689         phys_addr_t dma_addr;
690
691         dma_addr = rte_mbuf_data_dma_addr_default(((struct rte_mbuf *)buf));
692
693         return (uint64_t)dma_addr;
694 }
695
696 static inline uint64_t
697 lio_map_ring_info(struct lio_droq *droq, uint32_t i)
698 {
699         phys_addr_t dma_addr;
700
701         dma_addr = droq->info_list_dma + (i * LIO_DROQ_INFO_SIZE);
702
703         return (uint64_t)dma_addr;
704 }
705
706 static inline int
707 lio_opcode_slow_path(union octeon_rh *rh)
708 {
709         uint16_t subcode1, subcode2;
710
711         subcode1 = LIO_OPCODE_SUBCODE(rh->r.opcode, rh->r.subcode);
712         subcode2 = LIO_OPCODE_SUBCODE(LIO_OPCODE, LIO_OPCODE_NW_DATA);
713
714         return subcode2 != subcode1;
715 }
716
717 static inline void
718 lio_add_sg_size(struct lio_sg_entry *sg_entry,
719                 uint16_t size, uint32_t pos)
720 {
721 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
722         sg_entry->u.size[pos] = size;
723 #elif RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
724         sg_entry->u.size[3 - pos] = size;
725 #endif
726 }
727
728 /* Macro to increment index.
729  * Index is incremented by count; if the sum exceeds
730  * max, index is wrapped-around to the start.
731  */
732 static inline uint32_t
733 lio_incr_index(uint32_t index, uint32_t count, uint32_t max)
734 {
735         if ((index + count) >= max)
736                 index = index + count - max;
737         else
738                 index += count;
739
740         return index;
741 }
742
743 int lio_setup_droq(struct lio_device *lio_dev, int q_no, int num_descs,
744                    int desc_size, struct rte_mempool *mpool,
745                    unsigned int socket_id);
746 uint16_t lio_dev_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
747                            uint16_t budget);
748 void lio_delete_droq_queue(struct lio_device *lio_dev, int oq_no);
749
750 void lio_delete_sglist(struct lio_instr_queue *txq);
751 int lio_setup_sglists(struct lio_device *lio_dev, int iq_no,
752                       int fw_mapped_iq, int num_descs, unsigned int socket_id);
753 uint16_t lio_dev_xmit_pkts(void *tx_queue, struct rte_mbuf **pkts,
754                            uint16_t nb_pkts);
755 int lio_wait_for_instr_fetch(struct lio_device *lio_dev);
756 int lio_setup_iq(struct lio_device *lio_dev, int q_index,
757                  union octeon_txpciq iq_no, uint32_t num_descs, void *app_ctx,
758                  unsigned int socket_id);
759 int lio_flush_iq(struct lio_device *lio_dev, struct lio_instr_queue *iq);
760 void lio_delete_instruction_queue(struct lio_device *lio_dev, int iq_no);
761 /** Setup instruction queue zero for the device
762  *  @param lio_dev which lio device to setup
763  *
764  *  @return 0 if success. -1 if fails
765  */
766 int lio_setup_instr_queue0(struct lio_device *lio_dev);
767 void lio_free_instr_queue0(struct lio_device *lio_dev);
768 void lio_dev_clear_queues(struct rte_eth_dev *eth_dev);
769 #endif  /* _LIO_RXTX_H_ */