18c2ecf20Sopenharmony_ci/**********************************************************************
28c2ecf20Sopenharmony_ci * Author: Cavium, Inc.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Contact: support@cavium.com
58c2ecf20Sopenharmony_ci *          Please include "LiquidIO" in the subject.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Copyright (c) 2003-2016 Cavium, Inc.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * This file is free software; you can redistribute it and/or modify
108c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License, Version 2, as
118c2ecf20Sopenharmony_ci * published by the Free Software Foundation.
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * This file is distributed in the hope that it will be useful, but
148c2ecf20Sopenharmony_ci * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
158c2ecf20Sopenharmony_ci * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
168c2ecf20Sopenharmony_ci * NONINFRINGEMENT.  See the GNU General Public License for more details.
178c2ecf20Sopenharmony_ci ***********************************************************************/
188c2ecf20Sopenharmony_ci/*!  \file  octeon_droq.h
198c2ecf20Sopenharmony_ci *   \brief Implementation of Octeon Output queues. "Output" is with
208c2ecf20Sopenharmony_ci *   respect to the Octeon device on the NIC. From this driver's point of
218c2ecf20Sopenharmony_ci *   view they are ingress queues.
228c2ecf20Sopenharmony_ci */
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#ifndef __OCTEON_DROQ_H__
258c2ecf20Sopenharmony_ci#define __OCTEON_DROQ_H__
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/* Default number of packets that will be processed in one iteration. */
288c2ecf20Sopenharmony_ci#define MAX_PACKET_BUDGET 0xFFFFFFFF
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/** Octeon descriptor format.
318c2ecf20Sopenharmony_ci *  The descriptor ring is made of descriptors which have 2 64-bit values:
328c2ecf20Sopenharmony_ci *  -# Physical (bus) address of the data buffer.
338c2ecf20Sopenharmony_ci *  -# Physical (bus) address of a octeon_droq_info structure.
348c2ecf20Sopenharmony_ci *  The Octeon device DMA's incoming packets and its information at the address
358c2ecf20Sopenharmony_ci *  given by these descriptor fields.
368c2ecf20Sopenharmony_ci */
378c2ecf20Sopenharmony_cistruct octeon_droq_desc {
388c2ecf20Sopenharmony_ci	/** The buffer pointer */
398c2ecf20Sopenharmony_ci	u64 buffer_ptr;
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	/** The Info pointer */
428c2ecf20Sopenharmony_ci	u64 info_ptr;
438c2ecf20Sopenharmony_ci};
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#define OCT_DROQ_DESC_SIZE    (sizeof(struct octeon_droq_desc))
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci/** Information about packet DMA'ed by Octeon.
488c2ecf20Sopenharmony_ci *  The format of the information available at Info Pointer after Octeon
498c2ecf20Sopenharmony_ci *  has posted a packet. Not all descriptors have valid information. Only
508c2ecf20Sopenharmony_ci *  the Info field of the first descriptor for a packet has information
518c2ecf20Sopenharmony_ci *  about the packet.
528c2ecf20Sopenharmony_ci */
538c2ecf20Sopenharmony_cistruct octeon_droq_info {
548c2ecf20Sopenharmony_ci	/** The Length of the packet. */
558c2ecf20Sopenharmony_ci	u64 length;
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	/** The Output Receive Header. */
588c2ecf20Sopenharmony_ci	union octeon_rh rh;
598c2ecf20Sopenharmony_ci};
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci#define OCT_DROQ_INFO_SIZE   (sizeof(struct octeon_droq_info))
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cistruct octeon_skb_page_info {
648c2ecf20Sopenharmony_ci	/* DMA address for the page */
658c2ecf20Sopenharmony_ci	dma_addr_t dma;
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	/* Page for the rx dma  **/
688c2ecf20Sopenharmony_ci	struct page *page;
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci	/** which offset into page */
718c2ecf20Sopenharmony_ci	unsigned int page_offset;
728c2ecf20Sopenharmony_ci};
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci/** Pointer to data buffer.
758c2ecf20Sopenharmony_ci *  Driver keeps a pointer to the data buffer that it made available to
768c2ecf20Sopenharmony_ci *  the Octeon device. Since the descriptor ring keeps physical (bus)
778c2ecf20Sopenharmony_ci *  addresses, this field is required for the driver to keep track of
788c2ecf20Sopenharmony_ci *  the virtual address pointers.
798c2ecf20Sopenharmony_ci */
808c2ecf20Sopenharmony_cistruct octeon_recv_buffer {
818c2ecf20Sopenharmony_ci	/** Packet buffer, including metadata. */
828c2ecf20Sopenharmony_ci	void *buffer;
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci	/** Data in the packet buffer.  */
858c2ecf20Sopenharmony_ci	u8 *data;
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci	/** pg_info **/
888c2ecf20Sopenharmony_ci	struct octeon_skb_page_info pg_info;
898c2ecf20Sopenharmony_ci};
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci#define OCT_DROQ_RECVBUF_SIZE    (sizeof(struct octeon_recv_buffer))
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/** Output Queue statistics. Each output queue has four stats fields. */
948c2ecf20Sopenharmony_cistruct oct_droq_stats {
958c2ecf20Sopenharmony_ci	/** Number of packets received in this queue. */
968c2ecf20Sopenharmony_ci	u64 pkts_received;
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci	/** Bytes received by this queue. */
998c2ecf20Sopenharmony_ci	u64 bytes_received;
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci	/** Packets dropped due to no dispatch function. */
1028c2ecf20Sopenharmony_ci	u64 dropped_nodispatch;
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci	/** Packets dropped due to no memory available. */
1058c2ecf20Sopenharmony_ci	u64 dropped_nomem;
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	/** Packets dropped due to large number of pkts to process. */
1088c2ecf20Sopenharmony_ci	u64 dropped_toomany;
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	/** Number of packets  sent to stack from this queue. */
1118c2ecf20Sopenharmony_ci	u64 rx_pkts_received;
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci	/** Number of Bytes sent to stack from this queue. */
1148c2ecf20Sopenharmony_ci	u64 rx_bytes_received;
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci	/** Num of Packets dropped due to receive path failures. */
1178c2ecf20Sopenharmony_ci	u64 rx_dropped;
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci	u64 rx_vxlan;
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci	/** Num of failures of recv_buffer_alloc() */
1228c2ecf20Sopenharmony_ci	u64 rx_alloc_failure;
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci};
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci/* The maximum number of buffers that can be dispatched from the
1278c2ecf20Sopenharmony_ci * output/dma queue. Set to 64 assuming 1K buffers in DROQ and the fact that
1288c2ecf20Sopenharmony_ci * max packet size from DROQ is 64K.
1298c2ecf20Sopenharmony_ci */
1308c2ecf20Sopenharmony_ci#define    MAX_RECV_BUFS    64
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci/** Receive Packet format used when dispatching output queue packets
1338c2ecf20Sopenharmony_ci *  with non-raw opcodes.
1348c2ecf20Sopenharmony_ci *  The received packet will be sent to the upper layers using this
1358c2ecf20Sopenharmony_ci *  structure which is passed as a parameter to the dispatch function
1368c2ecf20Sopenharmony_ci */
1378c2ecf20Sopenharmony_cistruct octeon_recv_pkt {
1388c2ecf20Sopenharmony_ci	/**  Number of buffers in this received packet */
1398c2ecf20Sopenharmony_ci	u16 buffer_count;
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	/** Id of the device that is sending the packet up */
1428c2ecf20Sopenharmony_ci	u16 octeon_id;
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci	/** Length of data in the packet buffer */
1458c2ecf20Sopenharmony_ci	u32 length;
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci	/** The receive header */
1488c2ecf20Sopenharmony_ci	union octeon_rh rh;
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci	/** Pointer to the OS-specific packet buffer */
1518c2ecf20Sopenharmony_ci	void *buffer_ptr[MAX_RECV_BUFS];
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci	/** Size of the buffers pointed to by ptr's in buffer_ptr */
1548c2ecf20Sopenharmony_ci	u32 buffer_size[MAX_RECV_BUFS];
1558c2ecf20Sopenharmony_ci};
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci#define OCT_RECV_PKT_SIZE    (sizeof(struct octeon_recv_pkt))
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci/** The first parameter of a dispatch function.
1608c2ecf20Sopenharmony_ci *  For a raw mode opcode, the driver dispatches with the device
1618c2ecf20Sopenharmony_ci *  pointer in this structure.
1628c2ecf20Sopenharmony_ci *  For non-raw mode opcode, the driver dispatches the recv_pkt
1638c2ecf20Sopenharmony_ci *  created to contain the buffers with data received from Octeon.
1648c2ecf20Sopenharmony_ci *  ---------------------
1658c2ecf20Sopenharmony_ci *  |     *recv_pkt ----|---
1668c2ecf20Sopenharmony_ci *  |-------------------|   |
1678c2ecf20Sopenharmony_ci *  | 0 or more bytes   |   |
1688c2ecf20Sopenharmony_ci *  | reserved by driver|   |
1698c2ecf20Sopenharmony_ci *  |-------------------|<-/
1708c2ecf20Sopenharmony_ci *  | octeon_recv_pkt   |
1718c2ecf20Sopenharmony_ci *  |                   |
1728c2ecf20Sopenharmony_ci *  |___________________|
1738c2ecf20Sopenharmony_ci */
1748c2ecf20Sopenharmony_cistruct octeon_recv_info {
1758c2ecf20Sopenharmony_ci	void *rsvd;
1768c2ecf20Sopenharmony_ci	struct octeon_recv_pkt *recv_pkt;
1778c2ecf20Sopenharmony_ci};
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci#define  OCT_RECV_INFO_SIZE    (sizeof(struct octeon_recv_info))
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci/** Allocate a recv_info structure. The recv_pkt pointer in the recv_info
1828c2ecf20Sopenharmony_ci *  structure is filled in before this call returns.
1838c2ecf20Sopenharmony_ci *  @param extra_bytes - extra bytes to be allocated at the end of the recv info
1848c2ecf20Sopenharmony_ci *                       structure.
1858c2ecf20Sopenharmony_ci *  @return - pointer to a newly allocated recv_info structure.
1868c2ecf20Sopenharmony_ci */
1878c2ecf20Sopenharmony_cistatic inline struct octeon_recv_info *octeon_alloc_recv_info(int extra_bytes)
1888c2ecf20Sopenharmony_ci{
1898c2ecf20Sopenharmony_ci	struct octeon_recv_info *recv_info;
1908c2ecf20Sopenharmony_ci	u8 *buf;
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci	buf = kmalloc(OCT_RECV_PKT_SIZE + OCT_RECV_INFO_SIZE +
1938c2ecf20Sopenharmony_ci		      extra_bytes, GFP_ATOMIC);
1948c2ecf20Sopenharmony_ci	if (!buf)
1958c2ecf20Sopenharmony_ci		return NULL;
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci	recv_info = (struct octeon_recv_info *)buf;
1988c2ecf20Sopenharmony_ci	recv_info->recv_pkt =
1998c2ecf20Sopenharmony_ci		(struct octeon_recv_pkt *)(buf + OCT_RECV_INFO_SIZE);
2008c2ecf20Sopenharmony_ci	recv_info->rsvd = NULL;
2018c2ecf20Sopenharmony_ci	if (extra_bytes)
2028c2ecf20Sopenharmony_ci		recv_info->rsvd = buf + OCT_RECV_INFO_SIZE + OCT_RECV_PKT_SIZE;
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci	return recv_info;
2058c2ecf20Sopenharmony_ci}
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci/** Free a recv_info structure.
2088c2ecf20Sopenharmony_ci *  @param recv_info - Pointer to receive_info to be freed
2098c2ecf20Sopenharmony_ci */
2108c2ecf20Sopenharmony_cistatic inline void octeon_free_recv_info(struct octeon_recv_info *recv_info)
2118c2ecf20Sopenharmony_ci{
2128c2ecf20Sopenharmony_ci	kfree(recv_info);
2138c2ecf20Sopenharmony_ci}
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_citypedef int (*octeon_dispatch_fn_t)(struct octeon_recv_info *, void *);
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci/** Used by NIC module to register packet handler and to get device
2188c2ecf20Sopenharmony_ci * information for each octeon device.
2198c2ecf20Sopenharmony_ci */
2208c2ecf20Sopenharmony_cistruct octeon_droq_ops {
2218c2ecf20Sopenharmony_ci	/** This registered function will be called by the driver with
2228c2ecf20Sopenharmony_ci	 *  the octeon id, pointer to buffer from droq and length of
2238c2ecf20Sopenharmony_ci	 *  data in the buffer. The receive header gives the port
2248c2ecf20Sopenharmony_ci	 *  number to the caller.  Function pointer is set by caller.
2258c2ecf20Sopenharmony_ci	 */
2268c2ecf20Sopenharmony_ci	void (*fptr)(u32, void *, u32, union octeon_rh *, void *, void *);
2278c2ecf20Sopenharmony_ci	void *farg;
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci	/* This function will be called by the driver for all NAPI related
2308c2ecf20Sopenharmony_ci	 * events. The first param is the octeon id. The second param is the
2318c2ecf20Sopenharmony_ci	 * output queue number. The third is the NAPI event that occurred.
2328c2ecf20Sopenharmony_ci	 */
2338c2ecf20Sopenharmony_ci	void (*napi_fn)(void *);
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci	u32 poll_mode;
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci	/** Flag indicating if the DROQ handler should drop packets that
2388c2ecf20Sopenharmony_ci	 *  it cannot handle in one iteration. Set by caller.
2398c2ecf20Sopenharmony_ci	 */
2408c2ecf20Sopenharmony_ci	u32 drop_on_max;
2418c2ecf20Sopenharmony_ci};
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci/** The Descriptor Ring Output Queue structure.
2448c2ecf20Sopenharmony_ci *  This structure has all the information required to implement a
2458c2ecf20Sopenharmony_ci *  Octeon DROQ.
2468c2ecf20Sopenharmony_ci */
2478c2ecf20Sopenharmony_cistruct octeon_droq {
2488c2ecf20Sopenharmony_ci	u32 q_no;
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci	u32 pkt_count;
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci	struct octeon_droq_ops ops;
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci	struct octeon_device *oct_dev;
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci	/** The 8B aligned descriptor ring starts at this address. */
2578c2ecf20Sopenharmony_ci	struct octeon_droq_desc *desc_ring;
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci	/** Index in the ring where the driver should read the next packet */
2608c2ecf20Sopenharmony_ci	u32 read_idx;
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci	/** Index in the ring where Octeon will write the next packet */
2638c2ecf20Sopenharmony_ci	u32 write_idx;
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci	/** Index in the ring where the driver will refill the descriptor's
2668c2ecf20Sopenharmony_ci	 * buffer
2678c2ecf20Sopenharmony_ci	 */
2688c2ecf20Sopenharmony_ci	u32 refill_idx;
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci	/** Packets pending to be processed */
2718c2ecf20Sopenharmony_ci	atomic_t pkts_pending;
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci	/** Number of  descriptors in this ring. */
2748c2ecf20Sopenharmony_ci	u32 max_count;
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci	/** The number of descriptors pending refill. */
2778c2ecf20Sopenharmony_ci	u32 refill_count;
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci	u32 pkts_per_intr;
2808c2ecf20Sopenharmony_ci	u32 refill_threshold;
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci	/** The max number of descriptors in DROQ without a buffer.
2838c2ecf20Sopenharmony_ci	 * This field is used to keep track of empty space threshold. If the
2848c2ecf20Sopenharmony_ci	 * refill_count reaches this value, the DROQ cannot accept a max-sized
2858c2ecf20Sopenharmony_ci	 * (64K) packet.
2868c2ecf20Sopenharmony_ci	 */
2878c2ecf20Sopenharmony_ci	u32 max_empty_descs;
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci	/** The receive buffer list. This list has the virtual addresses of the
2908c2ecf20Sopenharmony_ci	 * buffers.
2918c2ecf20Sopenharmony_ci	 */
2928c2ecf20Sopenharmony_ci	struct octeon_recv_buffer *recv_buf_list;
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci	/** The size of each buffer pointed by the buffer pointer. */
2958c2ecf20Sopenharmony_ci	u32 buffer_size;
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ci	/** Pointer to the mapped packet credit register.
2988c2ecf20Sopenharmony_ci	 * Host writes number of info/buffer ptrs available to this register
2998c2ecf20Sopenharmony_ci	 */
3008c2ecf20Sopenharmony_ci	void  __iomem *pkts_credit_reg;
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci	/** Pointer to the mapped packet sent register.
3038c2ecf20Sopenharmony_ci	 * Octeon writes the number of packets DMA'ed to host memory
3048c2ecf20Sopenharmony_ci	 * in this register.
3058c2ecf20Sopenharmony_ci	 */
3068c2ecf20Sopenharmony_ci	void __iomem *pkts_sent_reg;
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ci	struct list_head dispatch_list;
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_ci	/** Statistics for this DROQ. */
3118c2ecf20Sopenharmony_ci	struct oct_droq_stats stats;
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ci	/** DMA mapped address of the DROQ descriptor ring. */
3148c2ecf20Sopenharmony_ci	size_t desc_ring_dma;
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci	/** application context */
3178c2ecf20Sopenharmony_ci	void *app_ctx;
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci	struct napi_struct napi;
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_ci	u32 cpu_id;
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci	call_single_data_t csd;
3248c2ecf20Sopenharmony_ci};
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_ci#define OCT_DROQ_SIZE   (sizeof(struct octeon_droq))
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci/**
3298c2ecf20Sopenharmony_ci *  Allocates space for the descriptor ring for the droq and sets the
3308c2ecf20Sopenharmony_ci *   base addr, num desc etc in Octeon registers.
3318c2ecf20Sopenharmony_ci *
3328c2ecf20Sopenharmony_ci * @param  oct_dev    - pointer to the octeon device structure
3338c2ecf20Sopenharmony_ci * @param  q_no       - droq no. ranges from 0 - 3.
3348c2ecf20Sopenharmony_ci * @param app_ctx     - pointer to application context
3358c2ecf20Sopenharmony_ci * @return Success: 0    Failure: 1
3368c2ecf20Sopenharmony_ci */
3378c2ecf20Sopenharmony_ciint octeon_init_droq(struct octeon_device *oct_dev,
3388c2ecf20Sopenharmony_ci		     u32 q_no,
3398c2ecf20Sopenharmony_ci		     u32 num_descs,
3408c2ecf20Sopenharmony_ci		     u32 desc_size,
3418c2ecf20Sopenharmony_ci		     void *app_ctx);
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci/**
3448c2ecf20Sopenharmony_ci *  Frees the space for descriptor ring for the droq.
3458c2ecf20Sopenharmony_ci *
3468c2ecf20Sopenharmony_ci *  @param oct_dev - pointer to the octeon device structure
3478c2ecf20Sopenharmony_ci *  @param q_no    - droq no. ranges from 0 - 3.
3488c2ecf20Sopenharmony_ci *  @return:    Success: 0    Failure: 1
3498c2ecf20Sopenharmony_ci */
3508c2ecf20Sopenharmony_ciint octeon_delete_droq(struct octeon_device *oct_dev, u32 q_no);
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_ci/** Register a change in droq operations. The ops field has a pointer to a
3538c2ecf20Sopenharmony_ci * function which will called by the DROQ handler for all packets arriving
3548c2ecf20Sopenharmony_ci * on output queues given by q_no irrespective of the type of packet.
3558c2ecf20Sopenharmony_ci * The ops field also has a flag which if set tells the DROQ handler to
3568c2ecf20Sopenharmony_ci * drop packets if it receives more than what it can process in one
3578c2ecf20Sopenharmony_ci * invocation of the handler.
3588c2ecf20Sopenharmony_ci * @param oct       - octeon device
3598c2ecf20Sopenharmony_ci * @param q_no      - octeon output queue number (0 <= q_no <= MAX_OCTEON_DROQ-1
3608c2ecf20Sopenharmony_ci * @param ops       - the droq_ops settings for this queue
3618c2ecf20Sopenharmony_ci * @return          - 0 on success, -ENODEV or -EINVAL on error.
3628c2ecf20Sopenharmony_ci */
3638c2ecf20Sopenharmony_ciint
3648c2ecf20Sopenharmony_ciocteon_register_droq_ops(struct octeon_device *oct,
3658c2ecf20Sopenharmony_ci			 u32 q_no,
3668c2ecf20Sopenharmony_ci			 struct octeon_droq_ops *ops);
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_ci/** Resets the function pointer and flag settings made by
3698c2ecf20Sopenharmony_ci * octeon_register_droq_ops(). After this routine is called, the DROQ handler
3708c2ecf20Sopenharmony_ci * will lookup dispatch function for each arriving packet on the output queue
3718c2ecf20Sopenharmony_ci * given by q_no.
3728c2ecf20Sopenharmony_ci * @param oct       - octeon device
3738c2ecf20Sopenharmony_ci * @param q_no      - octeon output queue number (0 <= q_no <= MAX_OCTEON_DROQ-1
3748c2ecf20Sopenharmony_ci * @return          - 0 on success, -ENODEV or -EINVAL on error.
3758c2ecf20Sopenharmony_ci */
3768c2ecf20Sopenharmony_ciint octeon_unregister_droq_ops(struct octeon_device *oct, u32 q_no);
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_ci/**   Register a dispatch function for a opcode/subcode. The driver will call
3798c2ecf20Sopenharmony_ci *    this dispatch function when it receives a packet with the given
3808c2ecf20Sopenharmony_ci *    opcode/subcode in its output queues along with the user specified
3818c2ecf20Sopenharmony_ci *    argument.
3828c2ecf20Sopenharmony_ci *    @param  oct        - the octeon device to register with.
3838c2ecf20Sopenharmony_ci *    @param  opcode     - the opcode for which the dispatch will be registered.
3848c2ecf20Sopenharmony_ci *    @param  subcode    - the subcode for which the dispatch will be registered
3858c2ecf20Sopenharmony_ci *    @param  fn         - the dispatch function.
3868c2ecf20Sopenharmony_ci *    @param  fn_arg     - user specified that will be passed along with the
3878c2ecf20Sopenharmony_ci *                         dispatch function by the driver.
3888c2ecf20Sopenharmony_ci *    @return Success: 0; Failure: 1
3898c2ecf20Sopenharmony_ci */
3908c2ecf20Sopenharmony_ciint octeon_register_dispatch_fn(struct octeon_device *oct,
3918c2ecf20Sopenharmony_ci				u16 opcode,
3928c2ecf20Sopenharmony_ci				u16 subcode,
3938c2ecf20Sopenharmony_ci				octeon_dispatch_fn_t fn, void *fn_arg);
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_civoid *octeon_get_dispatch_arg(struct octeon_device *oct,
3968c2ecf20Sopenharmony_ci			      u16 opcode, u16 subcode);
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_civoid octeon_droq_print_stats(void);
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ciu32 octeon_droq_check_hw_for_pkts(struct octeon_droq *droq);
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_ciint octeon_create_droq(struct octeon_device *oct, u32 q_no,
4038c2ecf20Sopenharmony_ci		       u32 num_descs, u32 desc_size, void *app_ctx);
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ciint octeon_droq_process_packets(struct octeon_device *oct,
4068c2ecf20Sopenharmony_ci				struct octeon_droq *droq,
4078c2ecf20Sopenharmony_ci				u32 budget);
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_ciint octeon_droq_process_poll_pkts(struct octeon_device *oct,
4108c2ecf20Sopenharmony_ci				  struct octeon_droq *droq, u32 budget);
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_ciint octeon_enable_irq(struct octeon_device *oct, u32 q_no);
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ciint octeon_retry_droq_refill(struct octeon_droq *droq);
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_ci#endif	/*__OCTEON_DROQ_H__ */
417